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