]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/of_address.h
Merge tag 'stericsson-fixes-v4.1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-bionic-kernel.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
GL
5#include <linux/of.h>
6
29b635c0
AM
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
d0dfa16a
RH
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
a850a755 30#ifdef CONFIG_OF_ADDRESS
0131d897 31extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
1f5bef30
GL
32extern int of_address_to_resource(struct device_node *dev, int index,
33 struct resource *r);
90e33f62
GL
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);
6b884a8d
GL
38extern void __iomem *of_iomap(struct device_node *device, int index);
39
22ae782f
GL
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 */
47b1e689 44extern const __be32 *of_get_address(struct device_node *dev, int index,
22ae782f
GL
45 u64 *size, unsigned int *flags);
46
41f8bba7 47extern int pci_register_io_range(phys_addr_t addr, resource_size_t size);
25ff7944 48extern unsigned long pci_address_to_pio(phys_addr_t addr);
41f8bba7 49extern phys_addr_t pci_pio_to_address(unsigned long pio);
22ae782f 50
29b635c0
AM
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);
18308c94
GS
56extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
57 u64 *paddr, u64 *size);
92ea637e 58extern bool of_dma_is_coherent(struct device_node *np);
a850a755 59#else /* CONFIG_OF_ADDRESS */
a850a755
GL
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}
4acf4b9c 67
47b1e689 68static inline const __be32 *of_get_address(struct device_node *dev, int index,
a850a755
GL
69 u64 *size, unsigned int *flags)
70{
71 return NULL;
72}
29b635c0 73
41f8bba7
LD
74static inline phys_addr_t pci_pio_to_address(unsigned long pio)
75{
76 return 0;
77}
78
29b635c0
AM
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}
18308c94
GS
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}
92ea637e
SS
97
98static inline bool of_dma_is_coherent(struct device_node *np)
99{
100 return false;
101}
a850a755
GL
102#endif /* CONFIG_OF_ADDRESS */
103
4acf4b9c
RH
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);
efd342fb 108void __iomem *of_io_request_and_map(struct device_node *device,
b75b276b 109 int index, const char *name);
4acf4b9c 110#else
efd342fb
MB
111
112#include <linux/io.h>
113
4acf4b9c
RH
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}
efd342fb
MB
124
125static inline void __iomem *of_io_request_and_map(struct device_node *device,
b75b276b 126 int index, const char *name)
efd342fb
MB
127{
128 return IOMEM_ERR_PTR(-EINVAL);
129}
4acf4b9c 130#endif
a850a755
GL
131
132#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
0131d897 133extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
22ae782f
GL
134 u64 *size, unsigned int *flags);
135extern int of_pci_address_to_resource(struct device_node *dev, int bar,
136 struct resource *r);
0b0b0893
LD
137extern int of_pci_range_to_resource(struct of_pci_range *range,
138 struct device_node *np,
139 struct resource *res);
a850a755 140#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
22ae782f
GL
141static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
142 struct resource *r)
143{
144 return -ENOSYS;
145}
146
0131d897 147static inline const __be32 *of_get_pci_address(struct device_node *dev,
22ae782f
GL
148 int bar_no, u64 *size, unsigned int *flags)
149{
150 return NULL;
151}
0b0b0893
LD
152static inline int of_pci_range_to_resource(struct of_pci_range *range,
153 struct device_node *np,
154 struct resource *res)
83bbde1c
LD
155{
156 return -ENOSYS;
157}
a850a755 158#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
22ae782f 159
6b884a8d
GL
160#endif /* __OF_ADDRESS_H */
161