Merge branches 'acpica-fixes' and 'device-properties-fixes'
[deliverable/linux.git] / include / linux / of_address.h
CommitLineData
6b884a8d
GL
1#ifndef __OF_ADDRESS_H
2#define __OF_ADDRESS_H
3#include <linux/ioport.h>
99ce39e3 4#include <linux/errno.h>
6b884a8d 5#include <linux/of.h>
fcd71d9c 6#include <linux/io.h>
6b884a8d 7
29b635c0
AM
8struct of_pci_range_parser {
9 struct device_node *node;
10 const __be32 *range;
11 const __be32 *end;
12 int np;
13 int pna;
14};
15
16struct of_pci_range {
17 u32 pci_space;
18 u64 pci_addr;
19 u64 cpu_addr;
20 u64 size;
21 u32 flags;
22};
23
24#define for_each_of_pci_range(parser, range) \
25 for (; of_pci_range_parser_one(parser, range);)
26
d0dfa16a
RH
27/* Translate a DMA address from device space to CPU space */
28extern u64 of_translate_dma_address(struct device_node *dev,
29 const __be32 *in_addr);
30
a850a755 31#ifdef CONFIG_OF_ADDRESS
0131d897 32extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
1f5bef30
GL
33extern int of_address_to_resource(struct device_node *dev, int index,
34 struct resource *r);
90e33f62
GL
35extern struct device_node *of_find_matching_node_by_address(
36 struct device_node *from,
37 const struct of_device_id *matches,
38 u64 base_address);
6b884a8d 39extern void __iomem *of_iomap(struct device_node *device, int index);
fcd71d9c
SM
40void __iomem *of_io_request_and_map(struct device_node *device,
41 int index, const char *name);
6b884a8d 42
22ae782f
GL
43/* Extract an address from a device, returns the region size and
44 * the address space flags too. The PCI version uses a BAR number
45 * instead of an absolute index
46 */
47b1e689 47extern const __be32 *of_get_address(struct device_node *dev, int index,
22ae782f
GL
48 u64 *size, unsigned int *flags);
49
41f8bba7 50extern int pci_register_io_range(phys_addr_t addr, resource_size_t size);
25ff7944 51extern unsigned long pci_address_to_pio(phys_addr_t addr);
41f8bba7 52extern phys_addr_t pci_pio_to_address(unsigned long pio);
22ae782f 53
29b635c0
AM
54extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
55 struct device_node *node);
56extern struct of_pci_range *of_pci_range_parser_one(
57 struct of_pci_range_parser *parser,
58 struct of_pci_range *range);
18308c94
GS
59extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
60 u64 *paddr, u64 *size);
92ea637e 61extern bool of_dma_is_coherent(struct device_node *np);
a850a755 62#else /* CONFIG_OF_ADDRESS */
fcd71d9c
SM
63static inline void __iomem *of_io_request_and_map(struct device_node *device,
64 int index, const char *name)
65{
66 return IOMEM_ERR_PTR(-EINVAL);
67}
b1d06b60
GR
68
69static inline u64 of_translate_address(struct device_node *np,
70 const __be32 *addr)
71{
72 return OF_BAD_ADDR;
73}
74
a850a755
GL
75static inline struct device_node *of_find_matching_node_by_address(
76 struct device_node *from,
77 const struct of_device_id *matches,
78 u64 base_address)
79{
80 return NULL;
81}
4acf4b9c 82
47b1e689 83static inline const __be32 *of_get_address(struct device_node *dev, int index,
a850a755
GL
84 u64 *size, unsigned int *flags)
85{
86 return NULL;
87}
29b635c0 88
41f8bba7
LD
89static inline phys_addr_t pci_pio_to_address(unsigned long pio)
90{
91 return 0;
92}
93
29b635c0
AM
94static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
95 struct device_node *node)
96{
97 return -1;
98}
99
100static inline struct of_pci_range *of_pci_range_parser_one(
101 struct of_pci_range_parser *parser,
102 struct of_pci_range *range)
103{
104 return NULL;
105}
18308c94
GS
106
107static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
108 u64 *paddr, u64 *size)
109{
110 return -ENODEV;
111}
92ea637e
SS
112
113static inline bool of_dma_is_coherent(struct device_node *np)
114{
115 return false;
116}
a850a755
GL
117#endif /* CONFIG_OF_ADDRESS */
118
4acf4b9c
RH
119#ifdef CONFIG_OF
120extern int of_address_to_resource(struct device_node *dev, int index,
121 struct resource *r);
122void __iomem *of_iomap(struct device_node *node, int index);
123#else
124static inline int of_address_to_resource(struct device_node *dev, int index,
125 struct resource *r)
126{
127 return -EINVAL;
128}
129
130static inline void __iomem *of_iomap(struct device_node *device, int index)
131{
132 return NULL;
133}
134#endif
a850a755
GL
135
136#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
0131d897 137extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
22ae782f
GL
138 u64 *size, unsigned int *flags);
139extern int of_pci_address_to_resource(struct device_node *dev, int bar,
140 struct resource *r);
0b0b0893
LD
141extern int of_pci_range_to_resource(struct of_pci_range *range,
142 struct device_node *np,
143 struct resource *res);
a850a755 144#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
22ae782f
GL
145static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
146 struct resource *r)
147{
148 return -ENOSYS;
149}
150
0131d897 151static inline const __be32 *of_get_pci_address(struct device_node *dev,
22ae782f
GL
152 int bar_no, u64 *size, unsigned int *flags)
153{
154 return NULL;
155}
0b0b0893
LD
156static inline int of_pci_range_to_resource(struct of_pci_range *range,
157 struct device_node *np,
158 struct resource *res)
83bbde1c
LD
159{
160 return -ENOSYS;
161}
a850a755 162#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
22ae782f 163
6b884a8d
GL
164#endif /* __OF_ADDRESS_H */
165
This page took 0.441094 seconds and 5 git commands to generate.