Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __OF_ADDRESS_H
3#define __OF_ADDRESS_H
4#include <linux/ioport.h>
5#include <linux/errno.h>
6#include <linux/of.h>
7#include <linux/io.h>
8
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 bool dma;
16};
17
18struct of_pci_range {
19 u32 pci_space;
20 u64 pci_addr;
21 u64 cpu_addr;
22 u64 size;
23 u32 flags;
24};
25
26#define for_each_of_pci_range(parser, range) \
27 for (; of_pci_range_parser_one(parser, range);)
28
29/* Translate a DMA address from device space to CPU space */
30extern u64 of_translate_dma_address(struct device_node *dev,
31 const __be32 *in_addr);
32
33#ifdef CONFIG_OF_ADDRESS
34extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
35extern int of_address_to_resource(struct device_node *dev, int index,
36 struct resource *r);
37extern void __iomem *of_iomap(struct device_node *device, int index);
38void __iomem *of_io_request_and_map(struct device_node *device,
39 int index, const char *name);
40
41/* Extract an address from a device, returns the region size and
42 * the address space flags too. The PCI version uses a BAR number
43 * instead of an absolute index
44 */
45extern const __be32 *of_get_address(struct device_node *dev, int index,
46 u64 *size, unsigned int *flags);
47
48extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
49 struct device_node *node);
50extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
51 struct device_node *node);
52extern struct of_pci_range *of_pci_range_parser_one(
53 struct of_pci_range_parser *parser,
54 struct of_pci_range *range);
55extern bool of_dma_is_coherent(struct device_node *np);
56#else /* CONFIG_OF_ADDRESS */
57static inline void __iomem *of_io_request_and_map(struct device_node *device,
58 int index, const char *name)
59{
60 return IOMEM_ERR_PTR(-EINVAL);
61}
62
63static inline u64 of_translate_address(struct device_node *np,
64 const __be32 *addr)
65{
66 return OF_BAD_ADDR;
67}
68
69static inline const __be32 *of_get_address(struct device_node *dev, int index,
70 u64 *size, unsigned int *flags)
71{
72 return NULL;
73}
74
75static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
76 struct device_node *node)
77{
78 return -ENOSYS;
79}
80
81static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
82 struct device_node *node)
83{
84 return -ENOSYS;
85}
86
87static inline struct of_pci_range *of_pci_range_parser_one(
88 struct of_pci_range_parser *parser,
89 struct of_pci_range *range)
90{
91 return NULL;
92}
93
94static inline bool of_dma_is_coherent(struct device_node *np)
95{
96 return false;
97}
98#endif /* CONFIG_OF_ADDRESS */
99
100#ifdef CONFIG_OF
101extern int of_address_to_resource(struct device_node *dev, int index,
102 struct resource *r);
103void __iomem *of_iomap(struct device_node *node, int index);
104#else
105static inline int of_address_to_resource(struct device_node *dev, int index,
106 struct resource *r)
107{
108 return -EINVAL;
109}
110
111static inline void __iomem *of_iomap(struct device_node *device, int index)
112{
113 return NULL;
114}
115#endif
116
117#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
118extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
119 u64 *size, unsigned int *flags);
120extern int of_pci_address_to_resource(struct device_node *dev, int bar,
121 struct resource *r);
122extern int of_pci_range_to_resource(struct of_pci_range *range,
123 struct device_node *np,
124 struct resource *res);
125#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
126static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
127 struct resource *r)
128{
129 return -ENOSYS;
130}
131
132static inline const __be32 *of_get_pci_address(struct device_node *dev,
133 int bar_no, u64 *size, unsigned int *flags)
134{
135 return NULL;
136}
137static inline int of_pci_range_to_resource(struct of_pci_range *range,
138 struct device_node *np,
139 struct resource *res)
140{
141 return -ENOSYS;
142}
143#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
144
145#endif /* __OF_ADDRESS_H */
146