Commit | Line | Data |
---|---|---|
9d24c888 | 1 | #include <linux/of.h> /* linux/of.h gets to determine #include ordering */ |
9b6b563c PM |
2 | #ifndef _POWERPC_PROM_H |
3 | #define _POWERPC_PROM_H | |
4 | #ifdef __KERNEL__ | |
5 | ||
6 | /* | |
7 | * Definitions for talking to the Open Firmware PROM on | |
8 | * Power Macintosh computers. | |
9 | * | |
10 | * Copyright (C) 1996-2005 Paul Mackerras. | |
11 | * | |
12 | * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp. | |
13 | * | |
14 | * This program is free software; you can redistribute it and/or | |
15 | * modify it under the terms of the GNU General Public License | |
16 | * as published by the Free Software Foundation; either version | |
17 | * 2 of the License, or (at your option) any later version. | |
18 | */ | |
19 | #include <linux/types.h> | |
d8678b58 | 20 | #include <linux/of_fdt.h> |
9b6b563c | 21 | #include <linux/proc_fs.h> |
a9b14973 | 22 | #include <linux/platform_device.h> |
99ddef9b | 23 | #include <asm/irq.h> |
9b6b563c PM |
24 | #include <asm/atomic.h> |
25 | ||
97e873e5 SR |
26 | #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1 |
27 | #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 | |
28 | ||
804ace88 | 29 | #define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2)) |
581b605a | 30 | #define of_prop_cmp(s1, s2) strcmp((s1), (s2)) |
1ef4d424 | 31 | #define of_node_cmp(s1, s2) strcasecmp((s1), (s2)) |
0081cbc3 | 32 | |
9b6b563c PM |
33 | extern struct device_node *of_chosen; |
34 | ||
9b6b563c PM |
35 | #define HAVE_ARCH_DEVTREE_FIXUPS |
36 | ||
40ef8cbc | 37 | #ifdef CONFIG_PPC32 |
9b6b563c PM |
38 | /* |
39 | * PCI <-> OF matching functions | |
40 | * (XXX should these be here?) | |
41 | */ | |
42 | struct pci_bus; | |
43 | struct pci_dev; | |
44 | extern int pci_device_from_OF_node(struct device_node *node, | |
45 | u8* bus, u8* devfn); | |
46 | extern struct device_node* pci_busdev_to_OF_node(struct pci_bus *, int); | |
47 | extern struct device_node* pci_device_to_OF_node(struct pci_dev *); | |
48 | extern void pci_create_OF_bus_map(void); | |
40ef8cbc PM |
49 | #endif |
50 | ||
9b6b563c PM |
51 | extern struct resource *request_OF_resource(struct device_node* node, |
52 | int index, const char* name_postfix); | |
53 | extern int release_OF_resource(struct device_node* node, int index); | |
54 | ||
d2dd482b | 55 | |
d1405b86 | 56 | /* |
d2dd482b BH |
57 | * OF address retreival & translation |
58 | */ | |
59 | ||
d2dd482b | 60 | /* Translate an OF address block into a CPU physical address |
d1405b86 | 61 | */ |
a7f67bdf | 62 | extern u64 of_translate_address(struct device_node *np, const u32 *addr); |
d1405b86 | 63 | |
837c54db BH |
64 | /* Translate a DMA address from device space to CPU space */ |
65 | extern u64 of_translate_dma_address(struct device_node *dev, | |
66 | const u32 *in_addr); | |
67 | ||
d2dd482b BH |
68 | /* Extract an address from a device, returns the region size and |
69 | * the address space flags too. The PCI version uses a BAR number | |
70 | * instead of an absolute index | |
71 | */ | |
a7f67bdf | 72 | extern const u32 *of_get_address(struct device_node *dev, int index, |
d2dd482b | 73 | u64 *size, unsigned int *flags); |
ff1f4ee9 | 74 | #ifdef CONFIG_PCI |
a7f67bdf | 75 | extern const u32 *of_get_pci_address(struct device_node *dev, int bar_no, |
d2dd482b | 76 | u64 *size, unsigned int *flags); |
ff1f4ee9 AV |
77 | #else |
78 | static inline const u32 *of_get_pci_address(struct device_node *dev, | |
79 | int bar_no, u64 *size, unsigned int *flags) | |
80 | { | |
81 | return NULL; | |
82 | } | |
83 | #endif /* CONFIG_PCI */ | |
d2dd482b BH |
84 | |
85 | /* Get an address as a resource. Note that if your address is | |
86 | * a PIO address, the conversion will fail if the physical address | |
87 | * can't be internally converted to an IO token with | |
88 | * pci_address_to_pio(), that is because it's either called to early | |
89 | * or it can't be matched to any host bridge IO space | |
90 | */ | |
91 | extern int of_address_to_resource(struct device_node *dev, int index, | |
92 | struct resource *r); | |
ff1f4ee9 | 93 | #ifdef CONFIG_PCI |
d2dd482b BH |
94 | extern int of_pci_address_to_resource(struct device_node *dev, int bar, |
95 | struct resource *r); | |
ff1f4ee9 AV |
96 | #else |
97 | static inline int of_pci_address_to_resource(struct device_node *dev, int bar, | |
98 | struct resource *r) | |
99 | { | |
100 | return -ENOSYS; | |
101 | } | |
102 | #endif /* CONFIG_PCI */ | |
d1405b86 | 103 | |
d4ad66fa JK |
104 | /* Parse the ibm,dma-window property of an OF node into the busno, phys and |
105 | * size parameters. | |
106 | */ | |
a7f67bdf | 107 | void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop, |
d4ad66fa JK |
108 | unsigned long *busno, unsigned long *phys, unsigned long *size); |
109 | ||
b68239ee ME |
110 | extern void kdump_move_device_tree(void); |
111 | ||
acf7d768 BH |
112 | /* CPU OF node matching */ |
113 | struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); | |
114 | ||
e523f723 NL |
115 | /* cache lookup */ |
116 | struct device_node *of_find_next_cache_node(struct device_node *np); | |
117 | ||
29cfe6f4 TT |
118 | /* Get the MAC address */ |
119 | extern const void *of_get_mac_address(struct device_node *np); | |
cc9fd71c BH |
120 | |
121 | /* | |
122 | * OF interrupt mapping | |
123 | */ | |
124 | ||
125 | /* This structure is returned when an interrupt is mapped. The controller | |
126 | * field needs to be put() after use | |
127 | */ | |
128 | ||
129 | #define OF_MAX_IRQ_SPEC 4 /* We handle specifiers of at most 4 cells */ | |
130 | ||
131 | struct of_irq { | |
132 | struct device_node *controller; /* Interrupt controller node */ | |
133 | u32 size; /* Specifier size */ | |
134 | u32 specifier[OF_MAX_IRQ_SPEC]; /* Specifier copy */ | |
135 | }; | |
136 | ||
40681b95 | 137 | /** |
cc9fd71c BH |
138 | * of_irq_map_init - Initialize the irq remapper |
139 | * @flags: flags defining workarounds to enable | |
140 | * | |
141 | * Some machines have bugs in the device-tree which require certain workarounds | |
142 | * to be applied. Call this before any interrupt mapping attempts to enable | |
143 | * those workarounds. | |
144 | */ | |
145 | #define OF_IMAP_OLDWORLD_MAC 0x00000001 | |
146 | #define OF_IMAP_NO_PHANDLE 0x00000002 | |
147 | ||
148 | extern void of_irq_map_init(unsigned int flags); | |
149 | ||
40681b95 | 150 | /** |
cc9fd71c BH |
151 | * of_irq_map_raw - Low level interrupt tree parsing |
152 | * @parent: the device interrupt parent | |
153 | * @intspec: interrupt specifier ("interrupts" property of the device) | |
006b64de | 154 | * @ointsize: size of the passed in interrupt specifier |
cc9fd71c BH |
155 | * @addr: address specifier (start of "reg" property of the device) |
156 | * @out_irq: structure of_irq filled by this function | |
157 | * | |
158 | * Returns 0 on success and a negative number on error | |
159 | * | |
160 | * This function is a low-level interrupt tree walking function. It | |
161 | * can be used to do a partial walk with synthetized reg and interrupts | |
162 | * properties, for example when resolving PCI interrupts when no device | |
163 | * node exist for the parent. | |
164 | * | |
165 | */ | |
166 | ||
a7f67bdf | 167 | extern int of_irq_map_raw(struct device_node *parent, const u32 *intspec, |
aa43f779 | 168 | u32 ointsize, const u32 *addr, |
cc9fd71c BH |
169 | struct of_irq *out_irq); |
170 | ||
171 | ||
40681b95 | 172 | /** |
cc9fd71c BH |
173 | * of_irq_map_one - Resolve an interrupt for a device |
174 | * @device: the device whose interrupt is to be resolved | |
175 | * @index: index of the interrupt to resolve | |
176 | * @out_irq: structure of_irq filled by this function | |
177 | * | |
178 | * This function resolves an interrupt, walking the tree, for a given | |
179 | * device-tree node. It's the high level pendant to of_irq_map_raw(). | |
180 | * It also implements the workarounds for OldWolrd Macs. | |
181 | */ | |
182 | extern int of_irq_map_one(struct device_node *device, int index, | |
183 | struct of_irq *out_irq); | |
184 | ||
40681b95 | 185 | /** |
cc9fd71c BH |
186 | * of_irq_map_pci - Resolve the interrupt for a PCI device |
187 | * @pdev: the device whose interrupt is to be resolved | |
188 | * @out_irq: structure of_irq filled by this function | |
189 | * | |
190 | * This function resolves the PCI interrupt for a given PCI device. If a | |
191 | * device-node exists for a given pci_dev, it will use normal OF tree | |
192 | * walking. If not, it will implement standard swizzling and walk up the | |
193 | * PCI tree until an device-node is found, at which point it will finish | |
194 | * resolving using the OF tree walking. | |
195 | */ | |
196 | struct pci_dev; | |
197 | extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq); | |
198 | ||
c0b3ae14 MD |
199 | extern int of_irq_to_resource(struct device_node *dev, int index, |
200 | struct resource *r); | |
a9b14973 | 201 | |
c3e8011a CK |
202 | /** |
203 | * of_iomap - Maps the memory mapped IO for a given device_node | |
204 | * @device: the device whose io range will be mapped | |
205 | * @index: index of the io range | |
206 | * | |
207 | * Returns a pointer to the mapped memory | |
208 | */ | |
209 | extern void __iomem *of_iomap(struct device_node *device, int index); | |
cc9fd71c | 210 | |
9b6b563c PM |
211 | #endif /* __KERNEL__ */ |
212 | #endif /* _POWERPC_PROM_H */ |