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