1#ifndef _POWERPC_PROM_H
2#define _POWERPC_PROM_H
3#ifdef __KERNEL__
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/types.h>
19#include <linux/proc_fs.h>
20#include <linux/platform_device.h>
21#include <asm/irq.h>
22#include <asm/atomic.h>
23
24#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
25#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
26
27#define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2))
28#define of_prop_cmp(s1, s2) strcmp((s1), (s2))
29#define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
30
31
32#define OF_DT_HEADER 0xd00dfeed
33#define OF_DT_BEGIN_NODE 0x1
34#define OF_DT_END_NODE 0x2
35#define OF_DT_PROP 0x3
36
37#define OF_DT_NOP 0x4
38#define OF_DT_END 0x9
39
40#define OF_DT_VERSION 0x10
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56struct boot_param_header
57{
58 u32 magic;
59 u32 totalsize;
60 u32 off_dt_struct;
61 u32 off_dt_strings;
62 u32 off_mem_rsvmap;
63 u32 version;
64 u32 last_comp_version;
65
66 u32 boot_cpuid_phys;
67
68 u32 dt_strings_size;
69
70 u32 dt_struct_size;
71};
72
73
74
75typedef u32 phandle;
76typedef u32 ihandle;
77
78struct property {
79 char *name;
80 int length;
81 void *value;
82 struct property *next;
83};
84
85struct device_node {
86 const char *name;
87 const char *type;
88 phandle node;
89 phandle linux_phandle;
90 char *full_name;
91
92 struct property *properties;
93 struct property *deadprops;
94 struct device_node *parent;
95 struct device_node *child;
96 struct device_node *sibling;
97 struct device_node *next;
98 struct device_node *allnext;
99 struct proc_dir_entry *pde;
100 struct kref kref;
101 unsigned long _flags;
102 void *data;
103};
104
105extern struct device_node *of_chosen;
106
107static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
108{
109 return test_bit(flag, &n->_flags);
110}
111
112static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
113{
114 set_bit(flag, &n->_flags);
115}
116
117
118#define HAVE_ARCH_DEVTREE_FIXUPS
119
120static inline void set_node_proc_entry(struct device_node *dn, struct proc_dir_entry *de)
121{
122 dn->pde = de;
123}
124
125
126extern struct device_node *of_find_all_nodes(struct device_node *prev);
127extern struct device_node *of_node_get(struct device_node *node);
128extern void of_node_put(struct device_node *node);
129
130
131extern int __init of_scan_flat_dt(int (*it)(unsigned long node,
132 const char *uname, int depth,
133 void *data),
134 void *data);
135extern void* __init of_get_flat_dt_prop(unsigned long node, const char *name,
136 unsigned long *size);
137extern int __init of_flat_dt_is_compatible(unsigned long node, const char *name);
138extern unsigned long __init of_get_flat_dt_root(void);
139
140
141extern void of_attach_node(struct device_node *);
142extern void of_detach_node(struct device_node *);
143
144
145extern void finish_device_tree(void);
146extern void unflatten_device_tree(void);
147extern void early_init_devtree(void *);
148extern int machine_is_compatible(const char *compat);
149extern void print_properties(struct device_node *node);
150extern int prom_n_intr_cells(struct device_node* np);
151extern void prom_get_irq_senses(unsigned char *senses, int off, int max);
152extern int prom_add_property(struct device_node* np, struct property* prop);
153extern int prom_remove_property(struct device_node *np, struct property *prop);
154extern int prom_update_property(struct device_node *np,
155 struct property *newprop,
156 struct property *oldprop);
157
158#ifdef CONFIG_PPC32
159
160
161
162
163struct pci_bus;
164struct pci_dev;
165extern int pci_device_from_OF_node(struct device_node *node,
166 u8* bus, u8* devfn);
167extern struct device_node* pci_busdev_to_OF_node(struct pci_bus *, int);
168extern struct device_node* pci_device_to_OF_node(struct pci_dev *);
169extern void pci_create_OF_bus_map(void);
170#endif
171
172extern struct resource *request_OF_resource(struct device_node* node,
173 int index, const char* name_postfix);
174extern int release_OF_resource(struct device_node* node, int index);
175
176
177
178
179
180
181
182
183static inline u64 of_read_number(const u32 *cell, int size)
184{
185 u64 r = 0;
186 while (size--)
187 r = (r << 32) | *(cell++);
188 return r;
189}
190
191
192#ifdef CONFIG_PPC32
193static inline unsigned long of_read_ulong(const u32 *cell, int size)
194{
195 return cell[size-1];
196}
197#else
198#define of_read_ulong(cell, size) of_read_number(cell, size)
199#endif
200
201
202
203extern u64 of_translate_address(struct device_node *np, const u32 *addr);
204
205
206extern u64 of_translate_dma_address(struct device_node *dev,
207 const u32 *in_addr);
208
209
210
211
212
213extern const u32 *of_get_address(struct device_node *dev, int index,
214 u64 *size, unsigned int *flags);
215#ifdef CONFIG_PCI
216extern const u32 *of_get_pci_address(struct device_node *dev, int bar_no,
217 u64 *size, unsigned int *flags);
218#else
219static inline const u32 *of_get_pci_address(struct device_node *dev,
220 int bar_no, u64 *size, unsigned int *flags)
221{
222 return NULL;
223}
224#endif
225
226
227
228
229
230
231
232extern int of_address_to_resource(struct device_node *dev, int index,
233 struct resource *r);
234#ifdef CONFIG_PCI
235extern int of_pci_address_to_resource(struct device_node *dev, int bar,
236 struct resource *r);
237#else
238static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
239 struct resource *r)
240{
241 return -ENOSYS;
242}
243#endif
244
245
246
247
248void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
249 unsigned long *busno, unsigned long *phys, unsigned long *size);
250
251extern void kdump_move_device_tree(void);
252
253
254struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
255
256
257struct device_node *of_find_next_cache_node(struct device_node *np);
258
259
260extern const void *of_get_mac_address(struct device_node *np);
261
262
263
264
265
266
267
268
269
270#define OF_MAX_IRQ_SPEC 4
271
272struct of_irq {
273 struct device_node *controller;
274 u32 size;
275 u32 specifier[OF_MAX_IRQ_SPEC];
276};
277
278
279
280
281
282
283
284
285
286#define OF_IMAP_OLDWORLD_MAC 0x00000001
287#define OF_IMAP_NO_PHANDLE 0x00000002
288
289extern void of_irq_map_init(unsigned int flags);
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308extern int of_irq_map_raw(struct device_node *parent, const u32 *intspec,
309 u32 ointsize, const u32 *addr,
310 struct of_irq *out_irq);
311
312
313
314
315
316
317
318
319
320
321
322
323extern int of_irq_map_one(struct device_node *device, int index,
324 struct of_irq *out_irq);
325
326
327
328
329
330
331
332
333
334
335
336
337struct pci_dev;
338extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq);
339
340extern int of_irq_to_resource(struct device_node *dev, int index,
341 struct resource *r);
342
343
344
345
346
347
348
349
350extern void __iomem *of_iomap(struct device_node *device, int index);
351
352
353
354
355
356#include <linux/of.h>
357
358#endif
359#endif
360