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> |
| 6 | |
Andrew Murray | 29b635c | 2013-05-16 17:55:17 +0200 | [diff] [blame] | 7 | struct 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 | |
| 15 | struct 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 Herring | d0dfa16 | 2013-09-16 21:05:05 -0500 | [diff] [blame] | 26 | /* Translate a DMA address from device space to CPU space */ |
| 27 | extern u64 of_translate_dma_address(struct device_node *dev, |
| 28 | const __be32 *in_addr); |
| 29 | |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 30 | #ifdef CONFIG_OF_ADDRESS |
Sebastian Andrzej Siewior | 0131d89 | 2010-12-01 10:54:46 +0100 | [diff] [blame] | 31 | extern u64 of_translate_address(struct device_node *np, const __be32 *addr); |
Grant Likely | 1f5bef3 | 2010-06-08 07:48:09 -0600 | [diff] [blame] | 32 | extern int of_address_to_resource(struct device_node *dev, int index, |
| 33 | struct resource *r); |
Grant Likely | 90e33f6 | 2011-07-05 23:42:28 -0600 | [diff] [blame] | 34 | extern 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 Likely | 6b884a8 | 2010-06-08 07:48:09 -0600 | [diff] [blame] | 38 | extern void __iomem *of_iomap(struct device_node *device, int index); |
| 39 | |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 40 | /* 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 Phillips | 47b1e68 | 2012-10-08 19:41:58 -0500 | [diff] [blame] | 44 | extern const __be32 *of_get_address(struct device_node *dev, int index, |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 45 | u64 *size, unsigned int *flags); |
| 46 | |
Liviu Dudau | 41f8bba | 2014-09-29 15:29:21 +0100 | [diff] [blame] | 47 | extern int pci_register_io_range(phys_addr_t addr, resource_size_t size); |
Rob Herring | 25ff794 | 2013-09-07 14:07:11 -0500 | [diff] [blame] | 48 | extern unsigned long pci_address_to_pio(phys_addr_t addr); |
Liviu Dudau | 41f8bba | 2014-09-29 15:29:21 +0100 | [diff] [blame] | 49 | extern phys_addr_t pci_pio_to_address(unsigned long pio); |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 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); |
| 53 | extern struct of_pci_range *of_pci_range_parser_one( |
| 54 | struct of_pci_range_parser *parser, |
| 55 | struct of_pci_range *range); |
Grygorii Strashko | 18308c9 | 2014-04-24 11:30:02 -0400 | [diff] [blame] | 56 | extern int of_dma_get_range(struct device_node *np, u64 *dma_addr, |
| 57 | u64 *paddr, u64 *size); |
Santosh Shilimkar | 92ea637 | 2014-04-24 11:30:03 -0400 | [diff] [blame] | 58 | extern bool of_dma_is_coherent(struct device_node *np); |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 59 | #else /* CONFIG_OF_ADDRESS */ |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 60 | static inline struct device_node *of_find_matching_node_by_address( |
| 61 | struct device_node *from, |
| 62 | const struct of_device_id *matches, |
| 63 | u64 base_address) |
| 64 | { |
| 65 | return NULL; |
| 66 | } |
Rob Herring | 4acf4b9 | 2013-09-16 21:03:24 -0500 | [diff] [blame] | 67 | |
Kim Phillips | 47b1e68 | 2012-10-08 19:41:58 -0500 | [diff] [blame] | 68 | 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] | 69 | u64 *size, unsigned int *flags) |
| 70 | { |
| 71 | return NULL; |
| 72 | } |
Andrew Murray | 29b635c | 2013-05-16 17:55:17 +0200 | [diff] [blame] | 73 | |
Liviu Dudau | 41f8bba | 2014-09-29 15:29:21 +0100 | [diff] [blame] | 74 | static inline phys_addr_t pci_pio_to_address(unsigned long pio) |
| 75 | { |
| 76 | return 0; |
| 77 | } |
| 78 | |
Andrew Murray | 29b635c | 2013-05-16 17:55:17 +0200 | [diff] [blame] | 79 | static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser, |
| 80 | struct device_node *node) |
| 81 | { |
| 82 | return -1; |
| 83 | } |
| 84 | |
| 85 | static inline struct of_pci_range *of_pci_range_parser_one( |
| 86 | struct of_pci_range_parser *parser, |
| 87 | struct of_pci_range *range) |
| 88 | { |
| 89 | return NULL; |
| 90 | } |
Grygorii Strashko | 18308c9 | 2014-04-24 11:30:02 -0400 | [diff] [blame] | 91 | |
| 92 | static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr, |
| 93 | u64 *paddr, u64 *size) |
| 94 | { |
| 95 | return -ENODEV; |
| 96 | } |
Santosh Shilimkar | 92ea637 | 2014-04-24 11:30:03 -0400 | [diff] [blame] | 97 | |
| 98 | static inline bool of_dma_is_coherent(struct device_node *np) |
| 99 | { |
| 100 | return false; |
| 101 | } |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 102 | #endif /* CONFIG_OF_ADDRESS */ |
| 103 | |
Rob Herring | 4acf4b9 | 2013-09-16 21:03:24 -0500 | [diff] [blame] | 104 | #ifdef CONFIG_OF |
| 105 | extern int of_address_to_resource(struct device_node *dev, int index, |
| 106 | struct resource *r); |
| 107 | void __iomem *of_iomap(struct device_node *node, int index); |
Matthias Brugger | efd342f | 2014-07-18 11:36:39 +0200 | [diff] [blame] | 108 | void __iomem *of_io_request_and_map(struct device_node *device, |
| 109 | int index, char *name); |
Rob Herring | 4acf4b9 | 2013-09-16 21:03:24 -0500 | [diff] [blame] | 110 | #else |
Matthias Brugger | efd342f | 2014-07-18 11:36:39 +0200 | [diff] [blame] | 111 | |
| 112 | #include <linux/io.h> |
| 113 | |
Rob Herring | 4acf4b9 | 2013-09-16 21:03:24 -0500 | [diff] [blame] | 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 | } |
Matthias Brugger | efd342f | 2014-07-18 11:36:39 +0200 | [diff] [blame] | 124 | |
| 125 | static inline void __iomem *of_io_request_and_map(struct device_node *device, |
| 126 | int index, char *name) |
| 127 | { |
| 128 | return IOMEM_ERR_PTR(-EINVAL); |
| 129 | } |
Rob Herring | 4acf4b9 | 2013-09-16 21:03:24 -0500 | [diff] [blame] | 130 | #endif |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 131 | |
| 132 | #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI) |
Sebastian Andrzej Siewior | 0131d89 | 2010-12-01 10:54:46 +0100 | [diff] [blame] | 133 | 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] | 134 | u64 *size, unsigned int *flags); |
| 135 | extern int of_pci_address_to_resource(struct device_node *dev, int bar, |
| 136 | struct resource *r); |
Liviu Dudau | 0b0b089 | 2014-09-29 15:29:25 +0100 | [diff] [blame] | 137 | extern int of_pci_range_to_resource(struct of_pci_range *range, |
| 138 | struct device_node *np, |
| 139 | struct resource *res); |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 140 | #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */ |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 141 | static inline int of_pci_address_to_resource(struct device_node *dev, int bar, |
| 142 | struct resource *r) |
| 143 | { |
| 144 | return -ENOSYS; |
| 145 | } |
| 146 | |
Sebastian Andrzej Siewior | 0131d89 | 2010-12-01 10:54:46 +0100 | [diff] [blame] | 147 | static inline const __be32 *of_get_pci_address(struct device_node *dev, |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 148 | int bar_no, u64 *size, unsigned int *flags) |
| 149 | { |
| 150 | return NULL; |
| 151 | } |
Liviu Dudau | 0b0b089 | 2014-09-29 15:29:25 +0100 | [diff] [blame] | 152 | static inline int of_pci_range_to_resource(struct of_pci_range *range, |
| 153 | struct device_node *np, |
| 154 | struct resource *res) |
Liviu Dudau | 83bbde1 | 2014-09-29 15:29:24 +0100 | [diff] [blame] | 155 | { |
| 156 | return -ENOSYS; |
| 157 | } |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 158 | #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */ |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 159 | |
Grant Likely | 6b884a8 | 2010-06-08 07:48:09 -0600 | [diff] [blame] | 160 | #endif /* __OF_ADDRESS_H */ |
| 161 | |