1 #ifndef __OF_ADDRESS_H 2 #define __OF_ADDRESS_H 3 #include <linux/ioport.h> 4 #include <linux/errno.h> 5 #include <linux/of.h> 6 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 37 #ifdef CONFIG_OF_ADDRESS 38 extern u64 of_translate_address(struct device_node *np, const __be32 *addr); 39 extern bool of_can_translate_address(struct device_node *dev); 40 extern int of_address_to_resource(struct device_node *dev, int index, 41 struct resource *r); 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); 46 extern void __iomem *of_iomap(struct device_node *device, int index); 47 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 */ 52 extern const __be32 *of_get_address(struct device_node *dev, int index, 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 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); 65 #else /* CONFIG_OF_ADDRESS */ 66 #ifndef of_address_to_resource 67 static inline int of_address_to_resource(struct device_node *dev, int index, 68 struct resource *r) 69 { 70 return -EINVAL; 71 } 72 #endif 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 } 80 #ifndef of_iomap 81 static inline void __iomem *of_iomap(struct device_node *device, int index) 82 { 83 return NULL; 84 } 85 #endif 86 static inline const __be32 *of_get_address(struct device_node *dev, int index, 87 u64 *size, unsigned int *flags) 88 { 89 return NULL; 90 } 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 } 104 #endif /* CONFIG_OF_ADDRESS */ 105 106 107 #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI) 108 extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no, 109 u64 *size, unsigned int *flags); 110 extern int of_pci_address_to_resource(struct device_node *dev, int bar, 111 struct resource *r); 112 #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */ 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 119 static inline const __be32 *of_get_pci_address(struct device_node *dev, 120 int bar_no, u64 *size, unsigned int *flags) 121 { 122 return NULL; 123 } 124 #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */ 125 126 #endif /* __OF_ADDRESS_H */ 127 128