Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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/* Translate a DMA address from device space to CPU space */
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/* Extract an address from a device, returns the region size and
41 * the address space flags too. The PCI version uses a BAR number
42 * instead of an absolute index
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 /* CONFIG_OF_ADDRESS */
60
61static inline u64 of_translate_address(struct device_node *np,
62 const __be32 *addr)
63{
64 return OF_BAD_ADDR;
65}
66
67static 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}
74
75static inline const __be32 *of_get_address(struct device_node *dev, int index,
76 u64 *size, unsigned int *flags)
77{
78 return NULL;
79}
80
81static inline phys_addr_t pci_pio_to_address(unsigned long pio)
82{
83 return 0;
84}
85
86static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
87 struct device_node *node)
88{
89 return -1;
90}
91
92static inline struct of_pci_range *of_pci_range_parser_one(
93 struct of_pci_range_parser *parser,
94 struct of_pci_range *range)
95{
96 return NULL;
97}
98
99static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
100 u64 *paddr, u64 *size)
101{
102 return -ENODEV;
103}
104
105static inline bool of_dma_is_coherent(struct device_node *np)
106{
107 return false;
108}
109#endif /* CONFIG_OF_ADDRESS */
110
111#ifdef CONFIG_OF
112extern int of_address_to_resource(struct device_node *dev, int index,
113 struct resource *r);
114void __iomem *of_iomap(struct device_node *node, int index);
115void __iomem *of_io_request_and_map(struct device_node *device,
116 int index, const char *name);
117#else
118
119#include <linux/io.h>
120
121static inline int of_address_to_resource(struct device_node *dev, int index,
122 struct resource *r)
123{
124 return -EINVAL;
125}
126
127static inline void __iomem *of_iomap(struct device_node *device, int index)
128{
129 return NULL;
130}
131
132static inline void __iomem *of_io_request_and_map(struct device_node *device,
133 int index, const char *name)
134{
135 return IOMEM_ERR_PTR(-EINVAL);
136}
137#endif
138
139#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
140extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
141 u64 *size, unsigned int *flags);
142extern int of_pci_address_to_resource(struct device_node *dev, int bar,
143 struct resource *r);
144extern int of_pci_range_to_resource(struct of_pci_range *range,
145 struct device_node *np,
146 struct resource *res);
147#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
148static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
149 struct resource *r)
150{
151 return -ENOSYS;
152}
153
154static inline const __be32 *of_get_pci_address(struct device_node *dev,
155 int bar_no, u64 *size, unsigned int *flags)
156{
157 return NULL;
158}
159static inline int of_pci_range_to_resource(struct of_pci_range *range,
160 struct device_node *np,
161 struct resource *res)
162{
163 return -ENOSYS;
164}
165#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
166
167#endif /* __OF_ADDRESS_H */
168