Commit | Line | Data |
---|---|---|
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 |
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 | static 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 */ |
38 | extern u64 of_translate_dma_address(struct device_node *dev, | |
39 | const __be32 *in_addr); | |
40 | ||
a850a755 | 41 | #ifdef CONFIG_OF_ADDRESS |
0131d897 | 42 | extern u64 of_translate_address(struct device_node *np, const __be32 *addr); |
5d61b165 | 43 | extern bool of_can_translate_address(struct device_node *dev); |
1f5bef30 GL |
44 | extern int of_address_to_resource(struct device_node *dev, int index, |
45 | struct resource *r); | |
90e33f62 GL |
46 | extern struct device_node *of_find_matching_node_by_address( |
47 | struct device_node *from, | |
48 | const struct of_device_id *matches, | |
49 | u64 base_address); | |
6b884a8d GL |
50 | extern void __iomem *of_iomap(struct device_node *device, int index); |
51 | ||
22ae782f GL |
52 | /* Extract an address from a device, returns the region size and |
53 | * the address space flags too. The PCI version uses a BAR number | |
54 | * instead of an absolute index | |
55 | */ | |
47b1e689 | 56 | extern const __be32 *of_get_address(struct device_node *dev, int index, |
22ae782f GL |
57 | u64 *size, unsigned int *flags); |
58 | ||
25ff7944 | 59 | extern unsigned long pci_address_to_pio(phys_addr_t addr); |
22ae782f | 60 | |
29b635c0 AM |
61 | extern int of_pci_range_parser_init(struct of_pci_range_parser *parser, |
62 | struct device_node *node); | |
63 | extern struct of_pci_range *of_pci_range_parser_one( | |
64 | struct of_pci_range_parser *parser, | |
65 | struct of_pci_range *range); | |
a850a755 | 66 | #else /* CONFIG_OF_ADDRESS */ |
a850a755 GL |
67 | static inline struct device_node *of_find_matching_node_by_address( |
68 | struct device_node *from, | |
69 | const struct of_device_id *matches, | |
70 | u64 base_address) | |
71 | { | |
72 | return NULL; | |
73 | } | |
4acf4b9c | 74 | |
47b1e689 | 75 | static inline const __be32 *of_get_address(struct device_node *dev, int index, |
a850a755 GL |
76 | u64 *size, unsigned int *flags) |
77 | { | |
78 | return NULL; | |
79 | } | |
29b635c0 AM |
80 | |
81 | static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser, | |
82 | struct device_node *node) | |
83 | { | |
84 | return -1; | |
85 | } | |
86 | ||
87 | static 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 | } | |
a850a755 GL |
93 | #endif /* CONFIG_OF_ADDRESS */ |
94 | ||
4acf4b9c RH |
95 | #ifdef CONFIG_OF |
96 | extern int of_address_to_resource(struct device_node *dev, int index, | |
97 | struct resource *r); | |
98 | void __iomem *of_iomap(struct device_node *node, int index); | |
99 | #else | |
100 | static inline int of_address_to_resource(struct device_node *dev, int index, | |
101 | struct resource *r) | |
102 | { | |
103 | return -EINVAL; | |
104 | } | |
105 | ||
106 | static inline void __iomem *of_iomap(struct device_node *device, int index) | |
107 | { | |
108 | return NULL; | |
109 | } | |
110 | #endif | |
a850a755 GL |
111 | |
112 | #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI) | |
0131d897 | 113 | extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no, |
22ae782f GL |
114 | u64 *size, unsigned int *flags); |
115 | extern int of_pci_address_to_resource(struct device_node *dev, int bar, | |
116 | struct resource *r); | |
a850a755 | 117 | #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */ |
22ae782f GL |
118 | static inline int of_pci_address_to_resource(struct device_node *dev, int bar, |
119 | struct resource *r) | |
120 | { | |
121 | return -ENOSYS; | |
122 | } | |
123 | ||
0131d897 | 124 | static inline const __be32 *of_get_pci_address(struct device_node *dev, |
22ae782f GL |
125 | int bar_no, u64 *size, unsigned int *flags) |
126 | { | |
127 | return NULL; | |
128 | } | |
a850a755 | 129 | #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */ |
22ae782f | 130 | |
6b884a8d GL |
131 | #endif /* __OF_ADDRESS_H */ |
132 |