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); |
Stephen Warren | 5d61b16 | 2012-07-25 17:34:37 -0600 | [diff] [blame] | 43 | extern bool of_can_translate_address(struct device_node *dev); |
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 | 90e33f6 | 2011-07-05 23:42:28 -0600 | [diff] [blame] | 46 | extern struct device_node *of_find_matching_node_by_address( |
| 47 | struct device_node *from, |
| 48 | const struct of_device_id *matches, |
| 49 | u64 base_address); |
Grant Likely | 6b884a8 | 2010-06-08 07:48:09 -0600 | [diff] [blame] | 50 | extern void __iomem *of_iomap(struct device_node *device, int index); |
| 51 | |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 52 | /* Extract an address from a device, returns the region size and |
| 53 | * the address space flags too. The PCI version uses a BAR number |
| 54 | * instead of an absolute index |
| 55 | */ |
Kim Phillips | 47b1e68 | 2012-10-08 19:41:58 -0500 | [diff] [blame] | 56 | extern const __be32 *of_get_address(struct device_node *dev, int index, |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 57 | u64 *size, unsigned int *flags); |
| 58 | |
Rob Herring | 25ff794 | 2013-09-07 14:07:11 -0500 | [diff] [blame] | 59 | extern unsigned long pci_address_to_pio(phys_addr_t addr); |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 60 | |
Andrew Murray | 29b635c | 2013-05-16 17:55:17 +0200 | [diff] [blame] | 61 | extern int of_pci_range_parser_init(struct of_pci_range_parser *parser, |
| 62 | struct device_node *node); |
| 63 | extern struct of_pci_range *of_pci_range_parser_one( |
| 64 | struct of_pci_range_parser *parser, |
| 65 | struct of_pci_range *range); |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 66 | #else /* CONFIG_OF_ADDRESS */ |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 67 | static inline struct device_node *of_find_matching_node_by_address( |
| 68 | struct device_node *from, |
| 69 | const struct of_device_id *matches, |
| 70 | u64 base_address) |
| 71 | { |
| 72 | return NULL; |
| 73 | } |
Rob Herring | 4acf4b9 | 2013-09-16 21:03:24 -0500 | [diff] [blame] | 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 | { |
| 84 | return -1; |
| 85 | } |
| 86 | |
| 87 | static inline struct of_pci_range *of_pci_range_parser_one( |
| 88 | struct of_pci_range_parser *parser, |
| 89 | struct of_pci_range *range) |
| 90 | { |
| 91 | return NULL; |
| 92 | } |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 93 | #endif /* CONFIG_OF_ADDRESS */ |
| 94 | |
Rob Herring | 4acf4b9 | 2013-09-16 21:03:24 -0500 | [diff] [blame] | 95 | #ifdef CONFIG_OF |
| 96 | extern int of_address_to_resource(struct device_node *dev, int index, |
| 97 | struct resource *r); |
| 98 | void __iomem *of_iomap(struct device_node *node, int index); |
| 99 | #else |
| 100 | static inline int of_address_to_resource(struct device_node *dev, int index, |
| 101 | struct resource *r) |
| 102 | { |
| 103 | return -EINVAL; |
| 104 | } |
| 105 | |
| 106 | static inline void __iomem *of_iomap(struct device_node *device, int index) |
| 107 | { |
| 108 | return NULL; |
| 109 | } |
| 110 | #endif |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 111 | |
| 112 | #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI) |
Sebastian Andrzej Siewior | 0131d89 | 2010-12-01 10:54:46 +0100 | [diff] [blame] | 113 | 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] | 114 | u64 *size, unsigned int *flags); |
| 115 | extern int of_pci_address_to_resource(struct device_node *dev, int bar, |
| 116 | struct resource *r); |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 117 | #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */ |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 118 | static inline int of_pci_address_to_resource(struct device_node *dev, int bar, |
| 119 | struct resource *r) |
| 120 | { |
| 121 | return -ENOSYS; |
| 122 | } |
| 123 | |
Sebastian Andrzej Siewior | 0131d89 | 2010-12-01 10:54:46 +0100 | [diff] [blame] | 124 | static inline const __be32 *of_get_pci_address(struct device_node *dev, |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 125 | int bar_no, u64 *size, unsigned int *flags) |
| 126 | { |
| 127 | return NULL; |
| 128 | } |
Grant Likely | a850a75 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 129 | #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */ |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 130 | |
Grant Likely | 6b884a8 | 2010-06-08 07:48:09 -0600 | [diff] [blame] | 131 | #endif /* __OF_ADDRESS_H */ |
| 132 | |