OSDN Git Service

of: Drop struct of_pci_range.pci_space field
[tomoyo/tomoyo-test1.git] / include / linux / of_address.h
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
9 struct 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
18 struct of_pci_range {
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
28 /* Translate a DMA address from device space to CPU space */
29 extern u64 of_translate_dma_address(struct device_node *dev,
30                                     const __be32 *in_addr);
31
32 #ifdef CONFIG_OF_ADDRESS
33 extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
34 extern int of_address_to_resource(struct device_node *dev, int index,
35                                   struct resource *r);
36 extern void __iomem *of_iomap(struct device_node *device, int index);
37 void __iomem *of_io_request_and_map(struct device_node *device,
38                                     int index, const char *name);
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  */
44 extern const __be32 *of_get_address(struct device_node *dev, int index,
45                            u64 *size, unsigned int *flags);
46
47 extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
48                         struct device_node *node);
49 extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
50                         struct device_node *node);
51 extern struct of_pci_range *of_pci_range_parser_one(
52                                         struct of_pci_range_parser *parser,
53                                         struct of_pci_range *range);
54 extern bool of_dma_is_coherent(struct device_node *np);
55 #else /* CONFIG_OF_ADDRESS */
56 static inline void __iomem *of_io_request_and_map(struct device_node *device,
57                                                   int index, const char *name)
58 {
59         return IOMEM_ERR_PTR(-EINVAL);
60 }
61
62 static inline u64 of_translate_address(struct device_node *np,
63                                        const __be32 *addr)
64 {
65         return OF_BAD_ADDR;
66 }
67
68 static inline const __be32 *of_get_address(struct device_node *dev, int index,
69                                         u64 *size, unsigned int *flags)
70 {
71         return NULL;
72 }
73
74 static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
75                         struct device_node *node)
76 {
77         return -ENOSYS;
78 }
79
80 static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
81                         struct device_node *node)
82 {
83         return -ENOSYS;
84 }
85
86 static inline struct of_pci_range *of_pci_range_parser_one(
87                                         struct of_pci_range_parser *parser,
88                                         struct of_pci_range *range)
89 {
90         return NULL;
91 }
92
93 static inline bool of_dma_is_coherent(struct device_node *np)
94 {
95         return false;
96 }
97 #endif /* CONFIG_OF_ADDRESS */
98
99 #ifdef CONFIG_OF
100 extern int of_address_to_resource(struct device_node *dev, int index,
101                                   struct resource *r);
102 void __iomem *of_iomap(struct device_node *node, int index);
103 #else
104 static inline int of_address_to_resource(struct device_node *dev, int index,
105                                          struct resource *r)
106 {
107         return -EINVAL;
108 }
109
110 static inline void __iomem *of_iomap(struct device_node *device, int index)
111 {
112         return NULL;
113 }
114 #endif
115
116 #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
117 extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
118                                u64 *size, unsigned int *flags);
119 extern int of_pci_address_to_resource(struct device_node *dev, int bar,
120                                       struct resource *r);
121 extern int of_pci_range_to_resource(struct of_pci_range *range,
122                                     struct device_node *np,
123                                     struct resource *res);
124 #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
125 static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
126                                              struct resource *r)
127 {
128         return -ENOSYS;
129 }
130
131 static inline const __be32 *of_get_pci_address(struct device_node *dev,
132                 int bar_no, u64 *size, unsigned int *flags)
133 {
134         return NULL;
135 }
136 static inline int of_pci_range_to_resource(struct of_pci_range *range,
137                                            struct device_node *np,
138                                            struct resource *res)
139 {
140         return -ENOSYS;
141 }
142 #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
143
144 #endif /* __OF_ADDRESS_H */
145