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