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