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