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 | |
Rob Herring | 25ff794 | 2013-09-07 14:07:11 -0500 | [diff] [blame] | 58 | extern unsigned long pci_address_to_pio(phys_addr_t addr); |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 59 | |
Andrew Murray | 29b635c | 2013-05-16 17:55:17 +0200 | [diff] [blame] | 60 | extern int of_pci_range_parser_init(struct of_pci_range_parser *parser, |
| 61 | struct device_node *node); |
| 62 | extern struct of_pci_range *of_pci_range_parser_one( |
| 63 | struct of_pci_range_parser *parser, |
| 64 | struct of_pci_range *range); |
Grygorii Strashko | 18308c9 | 2014-04-24 11:30:02 -0400 | [diff] [blame] | 65 | extern int of_dma_get_range(struct device_node *np, u64 *dma_addr, |
| 66 | u64 *paddr, u64 *size); |
Santosh Shilimkar | 92ea637 | 2014-04-24 11:30:03 -0400 | [diff] [blame] | 67 | extern bool of_dma_is_coherent(struct device_node *np); |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 68 | #else /* CONFIG_OF_ADDRESS */ |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 69 | static inline struct device_node *of_find_matching_node_by_address( |
| 70 | struct device_node *from, |
| 71 | const struct of_device_id *matches, |
| 72 | u64 base_address) |
| 73 | { |
| 74 | return NULL; |
| 75 | } |
Rob Herring | 4acf4b9 | 2013-09-16 21:03:24 -0500 | [diff] [blame] | 76 | |
Kim Phillips | 47b1e68 | 2012-10-08 19:41:58 -0500 | [diff] [blame] | 77 | 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] | 78 | u64 *size, unsigned int *flags) |
| 79 | { |
| 80 | return NULL; |
| 81 | } |
Andrew Murray | 29b635c | 2013-05-16 17:55:17 +0200 | [diff] [blame] | 82 | |
| 83 | static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser, |
| 84 | struct device_node *node) |
| 85 | { |
| 86 | return -1; |
| 87 | } |
| 88 | |
| 89 | static inline struct of_pci_range *of_pci_range_parser_one( |
| 90 | struct of_pci_range_parser *parser, |
| 91 | struct of_pci_range *range) |
| 92 | { |
| 93 | return NULL; |
| 94 | } |
Grygorii Strashko | 18308c9 | 2014-04-24 11:30:02 -0400 | [diff] [blame] | 95 | |
| 96 | static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr, |
| 97 | u64 *paddr, u64 *size) |
| 98 | { |
| 99 | return -ENODEV; |
| 100 | } |
Santosh Shilimkar | 92ea637 | 2014-04-24 11:30:03 -0400 | [diff] [blame] | 101 | |
| 102 | static inline bool of_dma_is_coherent(struct device_node *np) |
| 103 | { |
| 104 | return false; |
| 105 | } |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 106 | #endif /* CONFIG_OF_ADDRESS */ |
| 107 | |
Rob Herring | 4acf4b9 | 2013-09-16 21:03:24 -0500 | [diff] [blame] | 108 | #ifdef CONFIG_OF |
| 109 | extern int of_address_to_resource(struct device_node *dev, int index, |
| 110 | struct resource *r); |
| 111 | void __iomem *of_iomap(struct device_node *node, int index); |
| 112 | #else |
| 113 | static inline int of_address_to_resource(struct device_node *dev, int index, |
| 114 | struct resource *r) |
| 115 | { |
| 116 | return -EINVAL; |
| 117 | } |
| 118 | |
| 119 | static inline void __iomem *of_iomap(struct device_node *device, int index) |
| 120 | { |
| 121 | return NULL; |
| 122 | } |
| 123 | #endif |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 124 | |
| 125 | #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI) |
Sebastian Andrzej Siewior | 0131d89 | 2010-12-01 10:54:46 +0100 | [diff] [blame] | 126 | 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] | 127 | u64 *size, unsigned int *flags); |
| 128 | extern int of_pci_address_to_resource(struct device_node *dev, int bar, |
| 129 | struct resource *r); |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 130 | #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */ |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 131 | static inline int of_pci_address_to_resource(struct device_node *dev, int bar, |
| 132 | struct resource *r) |
| 133 | { |
| 134 | return -ENOSYS; |
| 135 | } |
| 136 | |
Sebastian Andrzej Siewior | 0131d89 | 2010-12-01 10:54:46 +0100 | [diff] [blame] | 137 | static inline const __be32 *of_get_pci_address(struct device_node *dev, |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 138 | int bar_no, u64 *size, unsigned int *flags) |
| 139 | { |
| 140 | return NULL; |
| 141 | } |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 142 | #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */ |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 143 | |
Grant Likely | 6b884a8 | 2010-06-08 07:48:09 -0600 | [diff] [blame] | 144 | #endif /* __OF_ADDRESS_H */ |
| 145 | |