OSDN Git Service

mm: vmalloc: show number of vmalloc pages in /proc/meminfo
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / linux / of_address.h
1 #ifndef __OF_ADDRESS_H
2 #define __OF_ADDRESS_H
3 #include <linux/ioport.h>
4 #include <linux/errno.h>
5 #include <linux/of.h>
6
7 struct 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
15 struct 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
26 /* Translate a DMA address from device space to CPU space */
27 extern u64 of_translate_dma_address(struct device_node *dev,
28                                     const __be32 *in_addr);
29
30 #ifdef CONFIG_OF_ADDRESS
31 extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
32 extern int of_address_to_resource(struct device_node *dev, int index,
33                                   struct resource *r);
34 extern 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);
38 extern void __iomem *of_iomap(struct device_node *device, int index);
39 extern void __iomem *of_iomap_by_name(struct device_node *device,
40                                         const char *name);
41
42 /* Extract an address from a device, returns the region size and
43  * the address space flags too. The PCI version uses a BAR number
44  * instead of an absolute index
45  */
46 extern const __be32 *of_get_address(struct device_node *dev, int index,
47                            u64 *size, unsigned int *flags);
48 extern const __be32 *of_get_address_by_name(struct device_node *dev,
49                            const char *name, u64 *size, unsigned int *flags);
50
51 extern int pci_register_io_range(phys_addr_t addr, resource_size_t size);
52 extern unsigned long pci_address_to_pio(phys_addr_t addr);
53 extern phys_addr_t pci_pio_to_address(unsigned long pio);
54
55 extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
56                         struct device_node *node);
57 extern struct of_pci_range *of_pci_range_parser_one(
58                                         struct of_pci_range_parser *parser,
59                                         struct of_pci_range *range);
60 extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
61                                 u64 *paddr, u64 *size);
62 extern bool of_dma_is_coherent(struct device_node *np);
63 #else /* CONFIG_OF_ADDRESS */
64
65 static inline u64 of_translate_address(struct device_node *np,
66                                        const __be32 *addr)
67 {
68         return OF_BAD_ADDR;
69 }
70
71 static inline struct device_node *of_find_matching_node_by_address(
72                                         struct device_node *from,
73                                         const struct of_device_id *matches,
74                                         u64 base_address)
75 {
76         return NULL;
77 }
78
79 static inline const __be32 *of_get_address(struct device_node *dev, int index,
80                                         u64 *size, unsigned int *flags)
81 {
82         return NULL;
83 }
84
85 static inline phys_addr_t pci_pio_to_address(unsigned long pio)
86 {
87         return 0;
88 }
89
90 static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
91                         struct device_node *node)
92 {
93         return -1;
94 }
95
96 static inline struct of_pci_range *of_pci_range_parser_one(
97                                         struct of_pci_range_parser *parser,
98                                         struct of_pci_range *range)
99 {
100         return NULL;
101 }
102
103 static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
104                                 u64 *paddr, u64 *size)
105 {
106         return -ENODEV;
107 }
108
109 static inline bool of_dma_is_coherent(struct device_node *np)
110 {
111         return false;
112 }
113 #endif /* CONFIG_OF_ADDRESS */
114
115 #ifdef CONFIG_OF
116 extern int of_address_to_resource(struct device_node *dev, int index,
117                                   struct resource *r);
118 void __iomem *of_iomap(struct device_node *node, int index);
119 void __iomem *of_io_request_and_map(struct device_node *device,
120                                         int index, const char *name);
121 #else
122
123 #include <linux/io.h>
124
125 static inline int of_address_to_resource(struct device_node *dev, int index,
126                                          struct resource *r)
127 {
128         return -EINVAL;
129 }
130
131 static inline void __iomem *of_iomap(struct device_node *device, int index)
132 {
133         return NULL;
134 }
135
136 static inline void __iomem *of_io_request_and_map(struct device_node *device,
137                                         int index, const char *name)
138 {
139         return IOMEM_ERR_PTR(-EINVAL);
140 }
141 #endif
142
143 #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
144 extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
145                                u64 *size, unsigned int *flags);
146 extern int of_pci_address_to_resource(struct device_node *dev, int bar,
147                                       struct resource *r);
148 extern int of_pci_range_to_resource(struct of_pci_range *range,
149                                     struct device_node *np,
150                                     struct resource *res);
151 #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
152 static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
153                                              struct resource *r)
154 {
155         return -ENOSYS;
156 }
157
158 static inline const __be32 *of_get_pci_address(struct device_node *dev,
159                 int bar_no, u64 *size, unsigned int *flags)
160 {
161         return NULL;
162 }
163 static inline int of_pci_range_to_resource(struct of_pci_range *range,
164                                            struct device_node *np,
165                                            struct resource *res)
166 {
167         return -ENOSYS;
168 }
169 #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
170
171 #endif /* __OF_ADDRESS_H */
172