blob: 507daad0bc8d5d7e49dde6f5ef8ca353f56e02f0 [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
Rob Herringd0dfa162013-09-16 21:05:05 -050026/* Translate a DMA address from device space to CPU space */
27extern u64 of_translate_dma_address(struct device_node *dev,
28 const __be32 *in_addr);
29
Grant Likelya850a752012-02-14 14:06:55 -070030#ifdef CONFIG_OF_ADDRESS
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +010031extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
Grant Likely1f5bef32010-06-08 07:48:09 -060032extern int of_address_to_resource(struct device_node *dev, int index,
33 struct resource *r);
Grant Likely90e33f62011-07-05 23:42:28 -060034extern struct device_node *of_find_matching_node_by_address(
35 struct device_node *from,
36 const struct of_device_id *matches,
37 u64 base_address);
Grant Likely6b884a82010-06-08 07:48:09 -060038extern void __iomem *of_iomap(struct device_node *device, int index);
39
Grant Likely22ae7822010-07-29 11:49:01 -060040/* Extract an address from a device, returns the region size and
41 * the address space flags too. The PCI version uses a BAR number
42 * instead of an absolute index
43 */
Kim Phillips47b1e682012-10-08 19:41:58 -050044extern const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likely22ae7822010-07-29 11:49:01 -060045 u64 *size, unsigned int *flags);
46
Liviu Dudau41f8bba2014-09-29 15:29:21 +010047extern int pci_register_io_range(phys_addr_t addr, resource_size_t size);
Rob Herring25ff7942013-09-07 14:07:11 -050048extern unsigned long pci_address_to_pio(phys_addr_t addr);
Liviu Dudau41f8bba2014-09-29 15:29:21 +010049extern phys_addr_t pci_pio_to_address(unsigned long pio);
Grant Likely22ae7822010-07-29 11:49:01 -060050
Andrew Murray29b635c2013-05-16 17:55:17 +020051extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
52 struct device_node *node);
53extern struct of_pci_range *of_pci_range_parser_one(
54 struct of_pci_range_parser *parser,
55 struct of_pci_range *range);
Grygorii Strashko18308c92014-04-24 11:30:02 -040056extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
57 u64 *paddr, u64 *size);
Santosh Shilimkar92ea6372014-04-24 11:30:03 -040058extern bool of_dma_is_coherent(struct device_node *np);
Grant Likelya850a752012-02-14 14:06:55 -070059#else /* CONFIG_OF_ADDRESS */
Guenter Roeckb1d06b62015-11-06 19:28:22 -080060
61static inline u64 of_translate_address(struct device_node *np,
62 const __be32 *addr)
63{
64 return OF_BAD_ADDR;
65}
66
Grant Likelya850a752012-02-14 14:06:55 -070067static inline struct device_node *of_find_matching_node_by_address(
68 struct device_node *from,
69 const struct of_device_id *matches,
70 u64 base_address)
71{
72 return NULL;
73}
Rob Herring4acf4b92013-09-16 21:03:24 -050074
Kim Phillips47b1e682012-10-08 19:41:58 -050075static inline const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likelya850a752012-02-14 14:06:55 -070076 u64 *size, unsigned int *flags)
77{
78 return NULL;
79}
Andrew Murray29b635c2013-05-16 17:55:17 +020080
Liviu Dudau41f8bba2014-09-29 15:29:21 +010081static inline phys_addr_t pci_pio_to_address(unsigned long pio)
82{
83 return 0;
84}
85
Andrew Murray29b635c2013-05-16 17:55:17 +020086static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
87 struct device_node *node)
88{
89 return -1;
90}
91
92static inline struct of_pci_range *of_pci_range_parser_one(
93 struct of_pci_range_parser *parser,
94 struct of_pci_range *range)
95{
96 return NULL;
97}
Grygorii Strashko18308c92014-04-24 11:30:02 -040098
99static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
100 u64 *paddr, u64 *size)
101{
102 return -ENODEV;
103}
Santosh Shilimkar92ea6372014-04-24 11:30:03 -0400104
105static inline bool of_dma_is_coherent(struct device_node *np)
106{
107 return false;
108}
Grant Likelya850a752012-02-14 14:06:55 -0700109#endif /* CONFIG_OF_ADDRESS */
110
Rob Herring4acf4b92013-09-16 21:03:24 -0500111#ifdef CONFIG_OF
112extern int of_address_to_resource(struct device_node *dev, int index,
113 struct resource *r);
114void __iomem *of_iomap(struct device_node *node, int index);
Matthias Bruggerefd342f2014-07-18 11:36:39 +0200115void __iomem *of_io_request_and_map(struct device_node *device,
Matthias Bruggerb75b2762014-10-21 18:27:25 +0200116 int index, const char *name);
Rob Herring4acf4b92013-09-16 21:03:24 -0500117#else
Matthias Bruggerefd342f2014-07-18 11:36:39 +0200118
119#include <linux/io.h>
120
Rob Herring4acf4b92013-09-16 21:03:24 -0500121static inline int of_address_to_resource(struct device_node *dev, int index,
122 struct resource *r)
123{
124 return -EINVAL;
125}
126
127static inline void __iomem *of_iomap(struct device_node *device, int index)
128{
129 return NULL;
130}
Matthias Bruggerefd342f2014-07-18 11:36:39 +0200131
132static inline void __iomem *of_io_request_and_map(struct device_node *device,
Matthias Bruggerb75b2762014-10-21 18:27:25 +0200133 int index, const char *name)
Matthias Bruggerefd342f2014-07-18 11:36:39 +0200134{
135 return IOMEM_ERR_PTR(-EINVAL);
136}
Rob Herring4acf4b92013-09-16 21:03:24 -0500137#endif
Grant Likelya850a752012-02-14 14:06:55 -0700138
139#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100140extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
Grant Likely22ae7822010-07-29 11:49:01 -0600141 u64 *size, unsigned int *flags);
142extern int of_pci_address_to_resource(struct device_node *dev, int bar,
143 struct resource *r);
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100144extern int of_pci_range_to_resource(struct of_pci_range *range,
145 struct device_node *np,
146 struct resource *res);
Grant Likelya850a752012-02-14 14:06:55 -0700147#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600148static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
149 struct resource *r)
150{
151 return -ENOSYS;
152}
153
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100154static inline const __be32 *of_get_pci_address(struct device_node *dev,
Grant Likely22ae7822010-07-29 11:49:01 -0600155 int bar_no, u64 *size, unsigned int *flags)
156{
157 return NULL;
158}
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100159static inline int of_pci_range_to_resource(struct of_pci_range *range,
160 struct device_node *np,
161 struct resource *res)
Liviu Dudau83bbde12014-09-29 15:29:24 +0100162{
163 return -ENOSYS;
164}
Grant Likelya850a752012-02-14 14:06:55 -0700165#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600166
Grant Likely6b884a82010-06-08 07:48:09 -0600167#endif /* __OF_ADDRESS_H */
168