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
7struct 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
15struct 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
27extern u64 of_translate_dma_address(struct device_node *dev,
28 const __be32 *in_addr);
29
30#ifdef CONFIG_OF_ADDRESS
31extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
32extern int of_address_to_resource(struct device_node *dev, int index,
33 struct resource *r);
34extern struct device_node *of_find_matching_node_by_address(
35 struct device_node *from,
36 const struct of_device_id *matches,
37 u64 base_address);
38extern void __iomem *of_iomap(struct device_node *device, int index);
39
40
41
42
43
44extern const __be32 *of_get_address(struct device_node *dev, int index,
45 u64 *size, unsigned int *flags);
46
47extern int pci_register_io_range(phys_addr_t addr, resource_size_t size);
48extern unsigned long pci_address_to_pio(phys_addr_t addr);
49extern phys_addr_t pci_pio_to_address(unsigned long pio);
50
51extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
52 struct device_node *node);
53extern struct of_pci_range *of_pci_range_parser_one(
54 struct of_pci_range_parser *parser,
55 struct of_pci_range *range);
56extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
57 u64 *paddr, u64 *size);
58extern bool of_dma_is_coherent(struct device_node *np);
59#else
60static inline struct device_node *of_find_matching_node_by_address(
61 struct device_node *from,
62 const struct of_device_id *matches,
63 u64 base_address)
64{
65 return NULL;
66}
67
68static inline const __be32 *of_get_address(struct device_node *dev, int index,
69 u64 *size, unsigned int *flags)
70{
71 return NULL;
72}
73
74static inline phys_addr_t pci_pio_to_address(unsigned long pio)
75{
76 return 0;
77}
78
79static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
80 struct device_node *node)
81{
82 return -1;
83}
84
85static inline struct of_pci_range *of_pci_range_parser_one(
86 struct of_pci_range_parser *parser,
87 struct of_pci_range *range)
88{
89 return NULL;
90}
91
92static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
93 u64 *paddr, u64 *size)
94{
95 return -ENODEV;
96}
97
98static inline bool of_dma_is_coherent(struct device_node *np)
99{
100 return false;
101}
102#endif
103
104#ifdef CONFIG_OF
105extern int of_address_to_resource(struct device_node *dev, int index,
106 struct resource *r);
107void __iomem *of_iomap(struct device_node *node, int index);
108void __iomem *of_io_request_and_map(struct device_node *device,
109 int index, const char *name);
110#else
111
112#include <linux/io.h>
113
114static inline int of_address_to_resource(struct device_node *dev, int index,
115 struct resource *r)
116{
117 return -EINVAL;
118}
119
120static inline void __iomem *of_iomap(struct device_node *device, int index)
121{
122 return NULL;
123}
124
125static inline void __iomem *of_io_request_and_map(struct device_node *device,
126 int index, const char *name)
127{
128 return IOMEM_ERR_PTR(-EINVAL);
129}
130#endif
131
132#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
133extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
134 u64 *size, unsigned int *flags);
135extern int of_pci_address_to_resource(struct device_node *dev, int bar,
136 struct resource *r);
137extern int of_pci_range_to_resource(struct of_pci_range *range,
138 struct device_node *np,
139 struct resource *res);
140#else
141static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
142 struct resource *r)
143{
144 return -ENOSYS;
145}
146
147static inline const __be32 *of_get_pci_address(struct device_node *dev,
148 int bar_no, u64 *size, unsigned int *flags)
149{
150 return NULL;
151}
152static inline int of_pci_range_to_resource(struct of_pci_range *range,
153 struct device_node *np,
154 struct resource *res)
155{
156 return -ENOSYS;
157}
158#endif
159
160#endif
161
162