Merge tag 'f2fs-for-3.18' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk...
[deliverable/linux.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
26static inline void of_pci_range_to_resource(struct of_pci_range *range,
27 struct device_node *np,
28 struct resource *res)
29{
30 res->flags = range->flags;
31 res->start = range->cpu_addr;
32 res->end = range->cpu_addr + range->size - 1;
33 res->parent = res->child = res->sibling = NULL;
34 res->name = np->full_name;
35}
36
d0dfa16a
RH
37/* Translate a DMA address from device space to CPU space */
38extern u64 of_translate_dma_address(struct device_node *dev,
39 const __be32 *in_addr);
40
a850a755 41#ifdef CONFIG_OF_ADDRESS
0131d897 42extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
1f5bef30
GL
43extern int of_address_to_resource(struct device_node *dev, int index,
44 struct resource *r);
90e33f62
GL
45extern struct device_node *of_find_matching_node_by_address(
46 struct device_node *from,
47 const struct of_device_id *matches,
48 u64 base_address);
6b884a8d
GL
49extern void __iomem *of_iomap(struct device_node *device, int index);
50
22ae782f
GL
51/* Extract an address from a device, returns the region size and
52 * the address space flags too. The PCI version uses a BAR number
53 * instead of an absolute index
54 */
47b1e689 55extern const __be32 *of_get_address(struct device_node *dev, int index,
22ae782f
GL
56 u64 *size, unsigned int *flags);
57
25ff7944 58extern unsigned long pci_address_to_pio(phys_addr_t addr);
22ae782f 59
29b635c0
AM
60extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
61 struct device_node *node);
62extern struct of_pci_range *of_pci_range_parser_one(
63 struct of_pci_range_parser *parser,
64 struct of_pci_range *range);
18308c94
GS
65extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
66 u64 *paddr, u64 *size);
92ea637e 67extern bool of_dma_is_coherent(struct device_node *np);
a850a755 68#else /* CONFIG_OF_ADDRESS */
a850a755
GL
69static inline struct device_node *of_find_matching_node_by_address(
70 struct device_node *from,
71 const struct of_device_id *matches,
72 u64 base_address)
73{
74 return NULL;
75}
4acf4b9c 76
47b1e689 77static inline const __be32 *of_get_address(struct device_node *dev, int index,
a850a755
GL
78 u64 *size, unsigned int *flags)
79{
80 return NULL;
81}
29b635c0
AM
82
83static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
84 struct device_node *node)
85{
86 return -1;
87}
88
89static inline struct of_pci_range *of_pci_range_parser_one(
90 struct of_pci_range_parser *parser,
91 struct of_pci_range *range)
92{
93 return NULL;
94}
18308c94
GS
95
96static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
97 u64 *paddr, u64 *size)
98{
99 return -ENODEV;
100}
92ea637e
SS
101
102static inline bool of_dma_is_coherent(struct device_node *np)
103{
104 return false;
105}
a850a755
GL
106#endif /* CONFIG_OF_ADDRESS */
107
4acf4b9c
RH
108#ifdef CONFIG_OF
109extern int of_address_to_resource(struct device_node *dev, int index,
110 struct resource *r);
111void __iomem *of_iomap(struct device_node *node, int index);
efd342fb
MB
112void __iomem *of_io_request_and_map(struct device_node *device,
113 int index, char *name);
4acf4b9c 114#else
efd342fb
MB
115
116#include <linux/io.h>
117
4acf4b9c
RH
118static inline int of_address_to_resource(struct device_node *dev, int index,
119 struct resource *r)
120{
121 return -EINVAL;
122}
123
124static inline void __iomem *of_iomap(struct device_node *device, int index)
125{
126 return NULL;
127}
efd342fb
MB
128
129static inline void __iomem *of_io_request_and_map(struct device_node *device,
130 int index, char *name)
131{
132 return IOMEM_ERR_PTR(-EINVAL);
133}
4acf4b9c 134#endif
a850a755
GL
135
136#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
0131d897 137extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
22ae782f
GL
138 u64 *size, unsigned int *flags);
139extern int of_pci_address_to_resource(struct device_node *dev, int bar,
140 struct resource *r);
a850a755 141#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
22ae782f
GL
142static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
143 struct resource *r)
144{
145 return -ENOSYS;
146}
147
0131d897 148static inline const __be32 *of_get_pci_address(struct device_node *dev,
22ae782f
GL
149 int bar_no, u64 *size, unsigned int *flags)
150{
151 return NULL;
152}
a850a755 153#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
22ae782f 154
6b884a8d
GL
155#endif /* __OF_ADDRESS_H */
156
This page took 0.357354 seconds and 5 git commands to generate.