blob: 497a04356ff8df334a6c1b302bfb5dd6a710e031 [file] [log] [blame]
Grant Likely6b884a82010-06-08 07:48:09 -06001#ifndef __OF_ADDRESS_H
2#define __OF_ADDRESS_H
3#include <linux/ioport.h>
Grant Likely99ce39e2011-07-05 23:42:37 -06004#include <linux/errno.h>
Grant Likely6b884a82010-06-08 07:48:09 -06005#include <linux/of.h>
6
Andrew Murray29b635c2013-05-16 17:55:17 +02007struct of_pci_range_parser {
8 struct device_node *node;
9 const __be32 *range;
10 const __be32 *end;
11 int np;
12 int pna;
13};
14
15struct of_pci_range {
16 u32 pci_space;
17 u64 pci_addr;
18 u64 cpu_addr;
19 u64 size;
20 u32 flags;
21};
22
23#define for_each_of_pci_range(parser, range) \
24 for (; of_pci_range_parser_one(parser, range);)
25
26static inline void of_pci_range_to_resource(struct of_pci_range *range,
27 struct device_node *np,
28 struct resource *res)
29{
30 res->flags = range->flags;
31 res->start = range->cpu_addr;
32 res->end = range->cpu_addr + range->size - 1;
33 res->parent = res->child = res->sibling = NULL;
34 res->name = np->full_name;
35}
36
Rob Herringd0dfa162013-09-16 21:05:05 -050037/* Translate a DMA address from device space to CPU space */
38extern u64 of_translate_dma_address(struct device_node *dev,
39 const __be32 *in_addr);
40
Grant Likelya850a752012-02-14 14:06:55 -070041#ifdef CONFIG_OF_ADDRESS
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +010042extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
Grant Likely1f5bef32010-06-08 07:48:09 -060043extern int of_address_to_resource(struct device_node *dev, int index,
44 struct resource *r);
Grant Likely90e33f62011-07-05 23:42:28 -060045extern struct device_node *of_find_matching_node_by_address(
46 struct device_node *from,
47 const struct of_device_id *matches,
48 u64 base_address);
Grant Likely6b884a82010-06-08 07:48:09 -060049extern void __iomem *of_iomap(struct device_node *device, int index);
50
Grant Likely22ae7822010-07-29 11:49:01 -060051/* Extract an address from a device, returns the region size and
52 * the address space flags too. The PCI version uses a BAR number
53 * instead of an absolute index
54 */
Kim Phillips47b1e682012-10-08 19:41:58 -050055extern const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likely22ae7822010-07-29 11:49:01 -060056 u64 *size, unsigned int *flags);
57
Liviu Dudau41f8bba2014-09-29 15:29:21 +010058extern int pci_register_io_range(phys_addr_t addr, resource_size_t size);
Rob Herring25ff7942013-09-07 14:07:11 -050059extern unsigned long pci_address_to_pio(phys_addr_t addr);
Liviu Dudau41f8bba2014-09-29 15:29:21 +010060extern phys_addr_t pci_pio_to_address(unsigned long pio);
Grant Likely22ae7822010-07-29 11:49:01 -060061
Andrew Murray29b635c2013-05-16 17:55:17 +020062extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
63 struct device_node *node);
64extern struct of_pci_range *of_pci_range_parser_one(
65 struct of_pci_range_parser *parser,
66 struct of_pci_range *range);
Grygorii Strashko18308c92014-04-24 11:30:02 -040067extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
68 u64 *paddr, u64 *size);
Santosh Shilimkar92ea6372014-04-24 11:30:03 -040069extern bool of_dma_is_coherent(struct device_node *np);
Grant Likelya850a752012-02-14 14:06:55 -070070#else /* CONFIG_OF_ADDRESS */
Grant Likelya850a752012-02-14 14:06:55 -070071static inline struct device_node *of_find_matching_node_by_address(
72 struct device_node *from,
73 const struct of_device_id *matches,
74 u64 base_address)
75{
76 return NULL;
77}
Rob Herring4acf4b92013-09-16 21:03:24 -050078
Kim Phillips47b1e682012-10-08 19:41:58 -050079static inline const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likelya850a752012-02-14 14:06:55 -070080 u64 *size, unsigned int *flags)
81{
82 return NULL;
83}
Andrew Murray29b635c2013-05-16 17:55:17 +020084
Liviu Dudau41f8bba2014-09-29 15:29:21 +010085static inline phys_addr_t pci_pio_to_address(unsigned long pio)
86{
87 return 0;
88}
89
Andrew Murray29b635c2013-05-16 17:55:17 +020090static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
91 struct device_node *node)
92{
93 return -1;
94}
95
96static inline struct of_pci_range *of_pci_range_parser_one(
97 struct of_pci_range_parser *parser,
98 struct of_pci_range *range)
99{
100 return NULL;
101}
Grygorii Strashko18308c92014-04-24 11:30:02 -0400102
103static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
104 u64 *paddr, u64 *size)
105{
106 return -ENODEV;
107}
Santosh Shilimkar92ea6372014-04-24 11:30:03 -0400108
109static inline bool of_dma_is_coherent(struct device_node *np)
110{
111 return false;
112}
Grant Likelya850a752012-02-14 14:06:55 -0700113#endif /* CONFIG_OF_ADDRESS */
114
Rob Herring4acf4b92013-09-16 21:03:24 -0500115#ifdef CONFIG_OF
116extern int of_address_to_resource(struct device_node *dev, int index,
117 struct resource *r);
118void __iomem *of_iomap(struct device_node *node, int index);
Matthias Bruggerefd342f2014-07-18 11:36:39 +0200119void __iomem *of_io_request_and_map(struct device_node *device,
120 int index, char *name);
Rob Herring4acf4b92013-09-16 21:03:24 -0500121#else
Matthias Bruggerefd342f2014-07-18 11:36:39 +0200122
123#include <linux/io.h>
124
Rob Herring4acf4b92013-09-16 21:03:24 -0500125static inline int of_address_to_resource(struct device_node *dev, int index,
126 struct resource *r)
127{
128 return -EINVAL;
129}
130
131static inline void __iomem *of_iomap(struct device_node *device, int index)
132{
133 return NULL;
134}
Matthias Bruggerefd342f2014-07-18 11:36:39 +0200135
136static inline void __iomem *of_io_request_and_map(struct device_node *device,
137 int index, char *name)
138{
139 return IOMEM_ERR_PTR(-EINVAL);
140}
Rob Herring4acf4b92013-09-16 21:03:24 -0500141#endif
Grant Likelya850a752012-02-14 14:06:55 -0700142
143#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100144extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
Grant Likely22ae7822010-07-29 11:49:01 -0600145 u64 *size, unsigned int *flags);
146extern int of_pci_address_to_resource(struct device_node *dev, int bar,
147 struct resource *r);
Grant Likelya850a752012-02-14 14:06:55 -0700148#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600149static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
150 struct resource *r)
151{
152 return -ENOSYS;
153}
154
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100155static inline const __be32 *of_get_pci_address(struct device_node *dev,
Grant Likely22ae7822010-07-29 11:49:01 -0600156 int bar_no, u64 *size, unsigned int *flags)
157{
158 return NULL;
159}
Grant Likelya850a752012-02-14 14:06:55 -0700160#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600161
Grant Likely6b884a82010-06-08 07:48:09 -0600162#endif /* __OF_ADDRESS_H */
163