]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/of_address.h
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-bionic-kernel.git] / include / linux / of_address.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
6b884a8d
GL
2#ifndef __OF_ADDRESS_H
3#define __OF_ADDRESS_H
4#include <linux/ioport.h>
99ce39e3 5#include <linux/errno.h>
6b884a8d 6#include <linux/of.h>
fcd71d9c 7#include <linux/io.h>
6b884a8d 8
29b635c0
AM
9struct of_pci_range_parser {
10 struct device_node *node;
11 const __be32 *range;
12 const __be32 *end;
13 int np;
14 int pna;
15};
16
17struct of_pci_range {
18 u32 pci_space;
19 u64 pci_addr;
20 u64 cpu_addr;
21 u64 size;
22 u32 flags;
23};
24
25#define for_each_of_pci_range(parser, range) \
26 for (; of_pci_range_parser_one(parser, range);)
27
d0dfa16a
RH
28/* Translate a DMA address from device space to CPU space */
29extern u64 of_translate_dma_address(struct device_node *dev,
30 const __be32 *in_addr);
31
a850a755 32#ifdef CONFIG_OF_ADDRESS
0131d897 33extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
1f5bef30
GL
34extern int of_address_to_resource(struct device_node *dev, int index,
35 struct resource *r);
90e33f62
GL
36extern struct device_node *of_find_matching_node_by_address(
37 struct device_node *from,
38 const struct of_device_id *matches,
39 u64 base_address);
6b884a8d 40extern void __iomem *of_iomap(struct device_node *device, int index);
fcd71d9c
SM
41void __iomem *of_io_request_and_map(struct device_node *device,
42 int index, const char *name);
6b884a8d 43
22ae782f
GL
44/* Extract an address from a device, returns the region size and
45 * the address space flags too. The PCI version uses a BAR number
46 * instead of an absolute index
47 */
47b1e689 48extern const __be32 *of_get_address(struct device_node *dev, int index,
22ae782f
GL
49 u64 *size, unsigned int *flags);
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 */
fcd71d9c
SM
60static inline void __iomem *of_io_request_and_map(struct device_node *device,
61 int index, const char *name)
62{
63 return IOMEM_ERR_PTR(-EINVAL);
64}
b1d06b60
GR
65
66static inline u64 of_translate_address(struct device_node *np,
67 const __be32 *addr)
68{
69 return OF_BAD_ADDR;
70}
71
a850a755
GL
72static inline struct device_node *of_find_matching_node_by_address(
73 struct device_node *from,
74 const struct of_device_id *matches,
75 u64 base_address)
76{
77 return NULL;
78}
4acf4b9c 79
47b1e689 80static inline const __be32 *of_get_address(struct device_node *dev, int index,
a850a755
GL
81 u64 *size, unsigned int *flags)
82{
83 return NULL;
84}
29b635c0
AM
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}
18308c94
GS
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}
92ea637e
SS
104
105static inline bool of_dma_is_coherent(struct device_node *np)
106{
107 return false;
108}
a850a755
GL
109#endif /* CONFIG_OF_ADDRESS */
110
4acf4b9c
RH
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);
115#else
116static inline int of_address_to_resource(struct device_node *dev, int index,
117 struct resource *r)
118{
119 return -EINVAL;
120}
121
122static inline void __iomem *of_iomap(struct device_node *device, int index)
123{
124 return NULL;
125}
126#endif
a850a755
GL
127
128#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
0131d897 129extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
22ae782f
GL
130 u64 *size, unsigned int *flags);
131extern int of_pci_address_to_resource(struct device_node *dev, int bar,
132 struct resource *r);
0b0b0893
LD
133extern int of_pci_range_to_resource(struct of_pci_range *range,
134 struct device_node *np,
135 struct resource *res);
a850a755 136#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
22ae782f
GL
137static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
138 struct resource *r)
139{
140 return -ENOSYS;
141}
142
0131d897 143static inline const __be32 *of_get_pci_address(struct device_node *dev,
22ae782f
GL
144 int bar_no, u64 *size, unsigned int *flags)
145{
146 return NULL;
147}
0b0b0893
LD
148static inline int of_pci_range_to_resource(struct of_pci_range *range,
149 struct device_node *np,
150 struct resource *res)
83bbde1c
LD
151{
152 return -ENOSYS;
153}
a850a755 154#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
22ae782f 155
6b884a8d
GL
156#endif /* __OF_ADDRESS_H */
157