Grant Likely | 6b884a8 | 2010-06-08 07:48:09 -0600 | [diff] [blame] | 1 | #ifndef __OF_ADDRESS_H |
| 2 | #define __OF_ADDRESS_H |
| 3 | #include <linux/ioport.h> |
Grant Likely | 99ce39e | 2011-07-05 23:42:37 -0600 | [diff] [blame] | 4 | #include <linux/errno.h> |
Grant Likely | 6b884a8 | 2010-06-08 07:48:09 -0600 | [diff] [blame] | 5 | #include <linux/of.h> |
Sudip Mukherjee | fcd71d9cc | 2015-12-08 14:17:55 +0530 | [diff] [blame] | 6 | #include <linux/io.h> |
Grant Likely | 6b884a8 | 2010-06-08 07:48:09 -0600 | [diff] [blame] | 7 | |
Andrew Murray | 29b635c | 2013-05-16 17:55:17 +0200 | [diff] [blame] | 8 | struct of_pci_range_parser { |
| 9 | struct device_node *node; |
| 10 | const __be32 *range; |
| 11 | const __be32 *end; |
| 12 | int np; |
| 13 | int pna; |
| 14 | }; |
| 15 | |
| 16 | struct of_pci_range { |
| 17 | u32 pci_space; |
| 18 | u64 pci_addr; |
| 19 | u64 cpu_addr; |
| 20 | u64 size; |
| 21 | u32 flags; |
| 22 | }; |
| 23 | |
| 24 | #define for_each_of_pci_range(parser, range) \ |
| 25 | for (; of_pci_range_parser_one(parser, range);) |
| 26 | |
Rob Herring | d0dfa16 | 2013-09-16 21:05:05 -0500 | [diff] [blame] | 27 | /* Translate a DMA address from device space to CPU space */ |
| 28 | extern u64 of_translate_dma_address(struct device_node *dev, |
| 29 | const __be32 *in_addr); |
| 30 | |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 31 | #ifdef CONFIG_OF_ADDRESS |
Sebastian Andrzej Siewior | 0131d89 | 2010-12-01 10:54:46 +0100 | [diff] [blame] | 32 | extern u64 of_translate_address(struct device_node *np, const __be32 *addr); |
Grant Likely | 1f5bef3 | 2010-06-08 07:48:09 -0600 | [diff] [blame] | 33 | extern int of_address_to_resource(struct device_node *dev, int index, |
| 34 | struct resource *r); |
Grant Likely | 90e33f6 | 2011-07-05 23:42:28 -0600 | [diff] [blame] | 35 | extern struct device_node *of_find_matching_node_by_address( |
| 36 | struct device_node *from, |
| 37 | const struct of_device_id *matches, |
| 38 | u64 base_address); |
Grant Likely | 6b884a8 | 2010-06-08 07:48:09 -0600 | [diff] [blame] | 39 | extern void __iomem *of_iomap(struct device_node *device, int index); |
Sudip Mukherjee | fcd71d9cc | 2015-12-08 14:17:55 +0530 | [diff] [blame] | 40 | void __iomem *of_io_request_and_map(struct device_node *device, |
| 41 | int index, const char *name); |
Grant Likely | 6b884a8 | 2010-06-08 07:48:09 -0600 | [diff] [blame] | 42 | |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 43 | /* Extract an address from a device, returns the region size and |
| 44 | * the address space flags too. The PCI version uses a BAR number |
| 45 | * instead of an absolute index |
| 46 | */ |
Kim Phillips | 47b1e68 | 2012-10-08 19:41:58 -0500 | [diff] [blame] | 47 | extern const __be32 *of_get_address(struct device_node *dev, int index, |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 48 | u64 *size, unsigned int *flags); |
| 49 | |
Andrew Murray | 29b635c | 2013-05-16 17:55:17 +0200 | [diff] [blame] | 50 | extern int of_pci_range_parser_init(struct of_pci_range_parser *parser, |
| 51 | struct device_node *node); |
Marc Gonzalez | a060c21 | 2017-09-26 12:22:54 +0200 | [diff] [blame^] | 52 | extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser, |
| 53 | struct device_node *node); |
Andrew Murray | 29b635c | 2013-05-16 17:55:17 +0200 | [diff] [blame] | 54 | extern struct of_pci_range *of_pci_range_parser_one( |
| 55 | struct of_pci_range_parser *parser, |
| 56 | struct of_pci_range *range); |
Grygorii Strashko | 18308c9 | 2014-04-24 11:30:02 -0400 | [diff] [blame] | 57 | extern int of_dma_get_range(struct device_node *np, u64 *dma_addr, |
| 58 | u64 *paddr, u64 *size); |
Santosh Shilimkar | 92ea637 | 2014-04-24 11:30:03 -0400 | [diff] [blame] | 59 | extern bool of_dma_is_coherent(struct device_node *np); |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 60 | #else /* CONFIG_OF_ADDRESS */ |
Sudip Mukherjee | fcd71d9cc | 2015-12-08 14:17:55 +0530 | [diff] [blame] | 61 | static inline void __iomem *of_io_request_and_map(struct device_node *device, |
| 62 | int index, const char *name) |
| 63 | { |
| 64 | return IOMEM_ERR_PTR(-EINVAL); |
| 65 | } |
Guenter Roeck | b1d06b6 | 2015-11-06 19:28:22 -0800 | [diff] [blame] | 66 | |
| 67 | static inline u64 of_translate_address(struct device_node *np, |
| 68 | const __be32 *addr) |
| 69 | { |
| 70 | return OF_BAD_ADDR; |
| 71 | } |
| 72 | |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 73 | static inline struct device_node *of_find_matching_node_by_address( |
| 74 | struct device_node *from, |
| 75 | const struct of_device_id *matches, |
| 76 | u64 base_address) |
| 77 | { |
| 78 | return NULL; |
| 79 | } |
Rob Herring | 4acf4b9 | 2013-09-16 21:03:24 -0500 | [diff] [blame] | 80 | |
Kim Phillips | 47b1e68 | 2012-10-08 19:41:58 -0500 | [diff] [blame] | 81 | static inline const __be32 *of_get_address(struct device_node *dev, int index, |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 82 | u64 *size, unsigned int *flags) |
| 83 | { |
| 84 | return NULL; |
| 85 | } |
Andrew Murray | 29b635c | 2013-05-16 17:55:17 +0200 | [diff] [blame] | 86 | |
| 87 | static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser, |
| 88 | struct device_node *node) |
| 89 | { |
Marc Gonzalez | a060c21 | 2017-09-26 12:22:54 +0200 | [diff] [blame^] | 90 | return -ENOSYS; |
| 91 | } |
| 92 | |
| 93 | static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser, |
| 94 | struct device_node *node) |
| 95 | { |
| 96 | return -ENOSYS; |
Andrew Murray | 29b635c | 2013-05-16 17:55:17 +0200 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | static inline struct of_pci_range *of_pci_range_parser_one( |
| 100 | struct of_pci_range_parser *parser, |
| 101 | struct of_pci_range *range) |
| 102 | { |
| 103 | return NULL; |
| 104 | } |
Grygorii Strashko | 18308c9 | 2014-04-24 11:30:02 -0400 | [diff] [blame] | 105 | |
| 106 | static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr, |
| 107 | u64 *paddr, u64 *size) |
| 108 | { |
| 109 | return -ENODEV; |
| 110 | } |
Santosh Shilimkar | 92ea637 | 2014-04-24 11:30:03 -0400 | [diff] [blame] | 111 | |
| 112 | static inline bool of_dma_is_coherent(struct device_node *np) |
| 113 | { |
| 114 | return false; |
| 115 | } |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 116 | #endif /* CONFIG_OF_ADDRESS */ |
| 117 | |
Rob Herring | 4acf4b9 | 2013-09-16 21:03:24 -0500 | [diff] [blame] | 118 | #ifdef CONFIG_OF |
| 119 | extern int of_address_to_resource(struct device_node *dev, int index, |
| 120 | struct resource *r); |
| 121 | void __iomem *of_iomap(struct device_node *node, int index); |
| 122 | #else |
| 123 | static inline int of_address_to_resource(struct device_node *dev, int index, |
| 124 | struct resource *r) |
| 125 | { |
| 126 | return -EINVAL; |
| 127 | } |
| 128 | |
| 129 | static inline void __iomem *of_iomap(struct device_node *device, int index) |
| 130 | { |
| 131 | return NULL; |
| 132 | } |
| 133 | #endif |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 134 | |
| 135 | #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI) |
Sebastian Andrzej Siewior | 0131d89 | 2010-12-01 10:54:46 +0100 | [diff] [blame] | 136 | extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no, |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 137 | u64 *size, unsigned int *flags); |
| 138 | extern int of_pci_address_to_resource(struct device_node *dev, int bar, |
| 139 | struct resource *r); |
Liviu Dudau | 0b0b089 | 2014-09-29 15:29:25 +0100 | [diff] [blame] | 140 | extern int of_pci_range_to_resource(struct of_pci_range *range, |
| 141 | struct device_node *np, |
| 142 | struct resource *res); |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 143 | #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */ |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 144 | static inline int of_pci_address_to_resource(struct device_node *dev, int bar, |
| 145 | struct resource *r) |
| 146 | { |
| 147 | return -ENOSYS; |
| 148 | } |
| 149 | |
Sebastian Andrzej Siewior | 0131d89 | 2010-12-01 10:54:46 +0100 | [diff] [blame] | 150 | static inline const __be32 *of_get_pci_address(struct device_node *dev, |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 151 | int bar_no, u64 *size, unsigned int *flags) |
| 152 | { |
| 153 | return NULL; |
| 154 | } |
Liviu Dudau | 0b0b089 | 2014-09-29 15:29:25 +0100 | [diff] [blame] | 155 | static inline int of_pci_range_to_resource(struct of_pci_range *range, |
| 156 | struct device_node *np, |
| 157 | struct resource *res) |
Liviu Dudau | 83bbde1 | 2014-09-29 15:29:24 +0100 | [diff] [blame] | 158 | { |
| 159 | return -ENOSYS; |
| 160 | } |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 161 | #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */ |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 162 | |
Grant Likely | 6b884a8 | 2010-06-08 07:48:09 -0600 | [diff] [blame] | 163 | #endif /* __OF_ADDRESS_H */ |
| 164 | |