0001
0002 #ifndef __OF_ADDRESS_H
0003 #define __OF_ADDRESS_H
0004 #include <linux/ioport.h>
0005 #include <linux/errno.h>
0006 #include <linux/of.h>
0007 #include <linux/io.h>
0008
0009 struct of_bus;
0010
0011 struct of_pci_range_parser {
0012 struct device_node *node;
0013 struct of_bus *bus;
0014 const __be32 *range;
0015 const __be32 *end;
0016 int na;
0017 int ns;
0018 int pna;
0019 bool dma;
0020 };
0021 #define of_range_parser of_pci_range_parser
0022
0023 struct of_pci_range {
0024 union {
0025 u64 pci_addr;
0026 u64 bus_addr;
0027 };
0028 u64 cpu_addr;
0029 u64 size;
0030 u32 flags;
0031 };
0032 #define of_range of_pci_range
0033
0034 #define for_each_of_pci_range(parser, range) \
0035 for (; of_pci_range_parser_one(parser, range);)
0036 #define for_each_of_range for_each_of_pci_range
0037
0038
0039 extern u64 of_translate_dma_address(struct device_node *dev,
0040 const __be32 *in_addr);
0041
0042 #ifdef CONFIG_OF_ADDRESS
0043 extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
0044 extern int of_address_to_resource(struct device_node *dev, int index,
0045 struct resource *r);
0046 extern void __iomem *of_iomap(struct device_node *device, int index);
0047 void __iomem *of_io_request_and_map(struct device_node *device,
0048 int index, const char *name);
0049
0050
0051
0052
0053
0054 extern const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no,
0055 u64 *size, unsigned int *flags);
0056
0057 extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
0058 struct device_node *node);
0059 extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
0060 struct device_node *node);
0061 extern struct of_pci_range *of_pci_range_parser_one(
0062 struct of_pci_range_parser *parser,
0063 struct of_pci_range *range);
0064 extern int of_pci_address_to_resource(struct device_node *dev, int bar,
0065 struct resource *r);
0066 extern int of_pci_range_to_resource(struct of_pci_range *range,
0067 struct device_node *np,
0068 struct resource *res);
0069 extern bool of_dma_is_coherent(struct device_node *np);
0070 #else
0071 static inline void __iomem *of_io_request_and_map(struct device_node *device,
0072 int index, const char *name)
0073 {
0074 return IOMEM_ERR_PTR(-EINVAL);
0075 }
0076
0077 static inline u64 of_translate_address(struct device_node *np,
0078 const __be32 *addr)
0079 {
0080 return OF_BAD_ADDR;
0081 }
0082
0083 static inline const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no,
0084 u64 *size, unsigned int *flags)
0085 {
0086 return NULL;
0087 }
0088
0089 static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
0090 struct device_node *node)
0091 {
0092 return -ENOSYS;
0093 }
0094
0095 static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
0096 struct device_node *node)
0097 {
0098 return -ENOSYS;
0099 }
0100
0101 static inline struct of_pci_range *of_pci_range_parser_one(
0102 struct of_pci_range_parser *parser,
0103 struct of_pci_range *range)
0104 {
0105 return NULL;
0106 }
0107
0108 static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
0109 struct resource *r)
0110 {
0111 return -ENOSYS;
0112 }
0113
0114 static inline int of_pci_range_to_resource(struct of_pci_range *range,
0115 struct device_node *np,
0116 struct resource *res)
0117 {
0118 return -ENOSYS;
0119 }
0120
0121 static inline bool of_dma_is_coherent(struct device_node *np)
0122 {
0123 return false;
0124 }
0125 #endif
0126
0127 #ifdef CONFIG_OF
0128 extern int of_address_to_resource(struct device_node *dev, int index,
0129 struct resource *r);
0130 void __iomem *of_iomap(struct device_node *node, int index);
0131 #else
0132 static inline int of_address_to_resource(struct device_node *dev, int index,
0133 struct resource *r)
0134 {
0135 return -EINVAL;
0136 }
0137
0138 static inline void __iomem *of_iomap(struct device_node *device, int index)
0139 {
0140 return NULL;
0141 }
0142 #endif
0143 #define of_range_parser_init of_pci_range_parser_init
0144
0145 static inline const __be32 *of_get_address(struct device_node *dev, int index,
0146 u64 *size, unsigned int *flags)
0147 {
0148 return __of_get_address(dev, index, -1, size, flags);
0149 }
0150
0151 static inline const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
0152 u64 *size, unsigned int *flags)
0153 {
0154 return __of_get_address(dev, -1, bar_no, size, flags);
0155 }
0156
0157 #endif