1 /*
2 * Device Tree
3 *
4 * Copyright (C) 2012 Citrix Systems, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10 #ifndef __XEN_DEVICE_TREE_H__
11 #define __XEN_DEVICE_TREE_H__
12
13 #include <asm/byteorder.h>
14 #include <asm/device.h>
15 #include <public/xen.h>
16 #include <public/device_tree_defs.h>
17 #include <xen/kernel.h>
18 #include <xen/string.h>
19 #include <xen/types.h>
20 #include <xen/list.h>
21
22 #define DEVICE_TREE_MAX_DEPTH 16
23
24 /*
25 * Struct used for matching a device
26 */
27 struct dt_device_match {
28 const char *path;
29 const char *type;
30 const char *compatible;
31 const bool_t not_available;
32 /*
33 * Property name to search for. We only search for the property's
34 * existence.
35 */
36 const char *prop;
37 const void *data;
38 };
39
40 #define __DT_MATCH_PATH(p) .path = p
41 #define __DT_MATCH_TYPE(typ) .type = typ
42 #define __DT_MATCH_COMPATIBLE(compat) .compatible = compat
43 #define __DT_MATCH_NOT_AVAILABLE() .not_available = 1
44 #define __DT_MATCH_PROP(p) .prop = p
45
46 #define DT_MATCH_PATH(p) { __DT_MATCH_PATH(p) }
47 #define DT_MATCH_TYPE(typ) { __DT_MATCH_TYPE(typ) }
48 #define DT_MATCH_COMPATIBLE(compat) { __DT_MATCH_COMPATIBLE(compat) }
49 #define DT_MATCH_NOT_AVAILABLE() { __DT_MATCH_NOT_AVAILABLE() }
50 #define DT_MATCH_PROP(p) { __DT_MATCH_PROP(p) }
51
52 typedef u32 dt_phandle;
53
54 /**
55 * dt_property - describe a property for a device
56 * @name: name of the property
57 * @length: size of the value
58 * @value: pointer to data contained in the property
59 * @next: pointer to the next property of a specific node
60 */
61 struct dt_property {
62 const char *name;
63 u32 length;
64 void *value;
65 struct dt_property *next;
66 };
67
68 /**
69 * dt_device_node - describe a node in the device tree
70 * @name: name of the node
71 * @type: type of the node (ie: memory, cpu, ...)
72 * @full_name: full name, it's composed of all the ascendant name separate by /
73 * @used_by: who owns the node? (ie: xen, dom0...)
74 * @properties: list of properties for the node
75 * @child: pointer to the first child
76 * @sibling: pointer to the next sibling
77 * @allnext: pointer to the next in list of all nodes
78 */
79 struct dt_device_node {
80 const char *name;
81 const char *type;
82 dt_phandle phandle;
83 char *full_name;
84 domid_t used_by; /* By default it's used by dom0 */
85
86 struct dt_property *properties;
87 struct dt_device_node *parent;
88 struct dt_device_node *child;
89 struct dt_device_node *sibling;
90 struct dt_device_node *next; /* TODO: Remove it. Only use to know the last children */
91 struct dt_device_node *allnext;
92
93 /* IOMMU specific fields */
94 bool is_protected;
95 /*
96 * The main purpose of this list is to link the structure in the list
97 * of devices assigned to domain.
98 *
99 * Boot code (iommu_hardware_setup) re-uses this list to link the structure
100 * in the list of devices for which driver requested deferred probing.
101 */
102 struct list_head domain_list;
103
104 struct device dev;
105 };
106
107 #define dt_to_dev(dt_node) (&(dt_node)->dev)
108
dev_to_dt(struct device * dev)109 static inline struct dt_device_node *dev_to_dt(struct device *dev)
110 {
111 ASSERT(dev->type == DEV_DT);
112
113 return container_of(dev, struct dt_device_node, dev);
114 }
115
116 #define MAX_PHANDLE_ARGS 16
117 struct dt_phandle_args {
118 struct dt_device_node *np;
119 int args_count;
120 uint32_t args[MAX_PHANDLE_ARGS];
121 };
122
123 /**
124 * dt_irq - describe an IRQ in the device tree
125 * @irq: IRQ number
126 * @type: IRQ type (see DT_IRQ_TYPE_*)
127 *
128 * This structure is returned when an interrupt is mapped.
129 */
130 struct dt_irq {
131 unsigned int irq;
132 unsigned int type;
133 };
134
135 /* If type == DT_IRQ_TYPE_NONE, assume we use level triggered */
dt_irq_is_level_triggered(const struct dt_irq * irq)136 static inline bool_t dt_irq_is_level_triggered(const struct dt_irq *irq)
137 {
138 unsigned int type = irq->type;
139
140 return (type & DT_IRQ_TYPE_LEVEL_MASK) || (type == DT_IRQ_TYPE_NONE);
141 }
142
143 /**
144 * dt_raw_irq - container for device_node/irq_specifier for an irq controller
145 * @controller: pointer to interrupt controller deivce tree node
146 * @size: size of interrupt specifier
147 * @specifier: array of cells @size long specifying the specific interrupt
148 *
149 * This structure is returned when an interrupt is mapped but not translated.
150 */
151 #define DT_MAX_IRQ_SPEC 4 /* We handle specifiers of at most 4 cells */
152 struct dt_raw_irq {
153 const struct dt_device_node *controller;
154 u32 size;
155 u32 specifier[DT_MAX_IRQ_SPEC];
156 };
157
158 #define dt_irq(irq) ((irq)->irq)
159 #define dt_irq_flags(irq) ((irq)->flags)
160
161 typedef int (*device_tree_node_func)(const void *fdt,
162 int node, const char *name, int depth,
163 u32 address_cells, u32 size_cells,
164 void *data);
165
166 extern const void *device_tree_flattened;
167
168 int device_tree_for_each_node(const void *fdt, int node,
169 device_tree_node_func func,
170 void *data);
171
172 /**
173 * dt_unflatten_host_device_tree - Unflatten the host device tree
174 *
175 * Create a hierarchical device tree for the host DTB to be able
176 * to retrieve parents.
177 */
178 void dt_unflatten_host_device_tree(void);
179
180 /**
181 * IRQ translation callback
182 * TODO: For the moment we assume that we only have ONE
183 * interrupt-controller.
184 */
185 typedef int (*dt_irq_xlate_func)(const u32 *intspec, unsigned int intsize,
186 unsigned int *out_hwirq,
187 unsigned int *out_type);
188 extern dt_irq_xlate_func dt_irq_xlate;
189
190 /**
191 * Host device tree
192 * DO NOT modify it!
193 */
194 extern struct dt_device_node *dt_host;
195
196 /**
197 * Primary interrupt controller
198 * Exynos SOC has an interrupt combiner, interrupt has no physical
199 * meaning when it's not connected to the primary controller.
200 * We will only map interrupt whose parent controller is
201 * dt_interrupt_controller. It should always be a GIC.
202 * TODO: Handle multiple GIC
203 */
204 extern const struct dt_device_node *dt_interrupt_controller;
205
206 /**
207 * Find the interrupt controller
208 * For the moment we handle only one interrupt controller: the first
209 * one without parent which is compatible with the string "compat".
210 *
211 * If found, return the interrupt controller device node.
212 */
213 struct dt_device_node *
214 dt_find_interrupt_controller(const struct dt_device_match *matches);
215
216 #define dt_prop_cmp(s1, s2) strcmp((s1), (s2))
217 #define dt_node_cmp(s1, s2) strcasecmp((s1), (s2))
218 #define dt_compat_cmp(s1, s2) strcasecmp((s1), (s2))
219
220 /* Default #address and #size cells */
221 #define DT_ROOT_NODE_ADDR_CELLS_DEFAULT 2
222 #define DT_ROOT_NODE_SIZE_CELLS_DEFAULT 1
223
224 #define dt_for_each_property_node(dn, pp) \
225 for ( pp = dn->properties; pp != NULL; pp = pp->next )
226
227 #define dt_for_each_device_node(dt, dn) \
228 for ( dn = dt; dn != NULL; dn = dn->allnext )
229
230 #define dt_for_each_child_node(dt, dn) \
231 for ( dn = dt->child; dn != NULL; dn = dn->sibling )
232
233 /* Helper to read a big number; size is in cells (not bytes) */
dt_read_number(const __be32 * cell,int size)234 static inline u64 dt_read_number(const __be32 *cell, int size)
235 {
236 u64 r = 0;
237
238 while ( size-- )
239 r = (r << 32) | be32_to_cpu(*(cell++));
240 return r;
241 }
242
243 /* Helper to convert a number of cells to bytes */
dt_cells_to_size(int size)244 static inline int dt_cells_to_size(int size)
245 {
246 return (size * sizeof (u32));
247 }
248
249 /* Helper to convert a number of bytes to cells, rounds down */
dt_size_to_cells(int bytes)250 static inline int dt_size_to_cells(int bytes)
251 {
252 return (bytes / sizeof(u32));
253 }
254
dt_next_cell(int s,const __be32 ** cellp)255 static inline u64 dt_next_cell(int s, const __be32 **cellp)
256 {
257 const __be32 *p = *cellp;
258
259 *cellp = p + s;
260 return dt_read_number(p, s);
261 }
262
dt_node_full_name(const struct dt_device_node * np)263 static inline const char *dt_node_full_name(const struct dt_device_node *np)
264 {
265 return (np && np->full_name) ? np->full_name : "<no-node>";
266 }
267
dt_node_name(const struct dt_device_node * np)268 static inline const char *dt_node_name(const struct dt_device_node *np)
269 {
270 return (np && np->name) ? np->name : "<no-node>";
271 }
272
dt_node_name_is_equal(const struct dt_device_node * np,const char * name)273 static inline bool_t dt_node_name_is_equal(const struct dt_device_node *np,
274 const char *name)
275 {
276 return !dt_node_cmp(np->name, name);
277 }
278
dt_node_path_is_equal(const struct dt_device_node * np,const char * path)279 static inline bool_t dt_node_path_is_equal(const struct dt_device_node *np,
280 const char *path)
281 {
282 return !dt_node_cmp(np->full_name, path);
283 }
284
285 static inline bool_t
dt_device_type_is_equal(const struct dt_device_node * device,const char * type)286 dt_device_type_is_equal(const struct dt_device_node *device,
287 const char *type)
288 {
289 return !dt_node_cmp(device->type, type);
290 }
291
dt_device_set_used_by(struct dt_device_node * device,domid_t used_by)292 static inline void dt_device_set_used_by(struct dt_device_node *device,
293 domid_t used_by)
294 {
295 /* TODO: children must inherit to the used_by thing */
296 device->used_by = used_by;
297 }
298
dt_device_used_by(const struct dt_device_node * device)299 static inline domid_t dt_device_used_by(const struct dt_device_node *device)
300 {
301 return device->used_by;
302 }
303
dt_device_set_protected(struct dt_device_node * device)304 static inline void dt_device_set_protected(struct dt_device_node *device)
305 {
306 device->is_protected = true;
307 }
308
dt_device_is_protected(const struct dt_device_node * device)309 static inline bool dt_device_is_protected(const struct dt_device_node *device)
310 {
311 return device->is_protected;
312 }
313
dt_property_name_is_equal(const struct dt_property * pp,const char * name)314 static inline bool_t dt_property_name_is_equal(const struct dt_property *pp,
315 const char *name)
316 {
317 return !dt_prop_cmp(pp->name, name);
318 }
319
320 /**
321 * dt_find_compatible_node - Find a node based on type and one of the
322 * tokens in its "compatible" property
323 * @from: The node to start searching from or NULL, the node
324 * you pass will not be searched, only the next one
325 * will; typically, you pass what the previous call
326 * returned.
327 * @type: The type string to match "device_type" or NULL to ignore
328 * @compatible: The string to match to one of the tokens in the device
329 * "compatible" list.
330 *
331 * Returns a node pointer.
332 */
333 struct dt_device_node *dt_find_compatible_node(struct dt_device_node *from,
334 const char *type,
335 const char *compatible);
336
337 /**
338 * Find a property with a given name for a given node
339 * and return the value.
340 */
341 const void *dt_get_property(const struct dt_device_node *np,
342 const char *name, u32 *lenp);
343
344 const struct dt_property *dt_find_property(const struct dt_device_node *np,
345 const char *name, u32 *lenp);
346
347
348 /**
349 * dt_property_read_u32 - Helper to read a u32 property.
350 * @np: node to get the value
351 * @name: name of the property
352 * @out_value: pointer to return value
353 *
354 * Return true if get the desired value.
355 */
356 bool_t dt_property_read_u32(const struct dt_device_node *np,
357 const char *name, u32 *out_value);
358 /**
359 * dt_property_read_u64 - Helper to read a u64 property.
360 * @np: node to get the value
361 * @name: name of the property
362 * @out_value: pointer to return value
363 *
364 * Return true if get the desired value.
365 */
366 bool_t dt_property_read_u64(const struct dt_device_node *np,
367 const char *name, u64 *out_value);
368
369 /**
370 * dt_property_read_bool - Check if a property exists
371 * @np: node to get the value
372 * @name: name of the property
373 *
374 * Search for a property in a device node.
375 * Return true if the property exists false otherwise.
376 */
dt_property_read_bool(const struct dt_device_node * np,const char * name)377 static inline bool_t dt_property_read_bool(const struct dt_device_node *np,
378 const char *name)
379 {
380 const struct dt_property *prop = dt_find_property(np, name, NULL);
381
382 return prop ? true : false;
383 }
384
385 /**
386 * dt_property_read_string - Find and read a string from a property
387 * @np: Device node from which the property value is to be read
388 * @propname: Name of the property to be searched
389 * @out_string: Pointer to null terminated return string, modified only
390 * if return value if 0.
391 *
392 * Search for a property in a device tree node and retrieve a null
393 * terminated string value (pointer to data, not a copy). Returns 0 on
394 * success, -EINVAL if the property does not exist, -ENODATA if property
395 * doest not have value, and -EILSEQ if the string is not
396 * null-terminated with the length of the property data.
397 *
398 * The out_string pointer is modified only if a valid string can be decoded.
399 */
400 int dt_property_read_string(const struct dt_device_node *np,
401 const char *propname, const char **out_string);
402
403 /**
404 * Checks if the given "compat" string matches one of the strings in
405 * the device's "compatible" property
406 */
407 bool_t dt_device_is_compatible(const struct dt_device_node *device,
408 const char *compat);
409
410 /**
411 * dt_machine_is_compatible - Test root of device tree for a given compatible value
412 * @compat: compatible string to look for in root node's compatible property.
413 *
414 * Returns true if the root node has the given value in its
415 * compatible property.
416 */
417 bool_t dt_machine_is_compatible(const char *compat);
418
419 /**
420 * dt_find_node_by_name - Find a node by its "name" property
421 * @from: The node to start searching from or NULL, the node
422 * you pass will not be searched, only the next one
423 * will; typically, you pass what the previous call
424 * returned. of_node_put() will be called on it
425 * @name: The name string to match against
426 *
427 * Returns a node pointer with refcount incremented, use
428 * of_node_put() on it when done.
429 */
430 struct dt_device_node *dt_find_node_by_name(struct dt_device_node *node,
431 const char *name);
432
433 /**
434 * dt_find_node_by_type - Find a node by its "type" property
435 */
436 struct dt_device_node *dt_find_node_by_type(struct dt_device_node *from,
437 const char *type);
438
439 /**
440 * df_find_node_by_alias - Find a node matching an alias
441 * @alias: The alias to match
442 *
443 * Returns a node pointer.
444 */
445 struct dt_device_node *dt_find_node_by_alias(const char *alias);
446
447 /**
448 * dt_find_node_by_path - Find a node matching a full DT path
449 * @path: The full path to match
450 *
451 * Returns a node pointer.
452 */
453 struct dt_device_node *dt_find_node_by_path(const char *path);
454
455
456 /**
457 * dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the
458 * path from the guest
459 *
460 * @u_path: Xen Guest handle to the buffer containing the path
461 * @u_plen: Length of the buffer
462 * @node: TODO
463 *
464 * Return 0 if succeed otherwise -errno
465 */
466 int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen,
467 struct dt_device_node **node);
468
469 /**
470 * dt_get_parent - Get a node's parent if any
471 * @node: Node to get parent
472 *
473 * Returns a node pointer.
474 */
475 const struct dt_device_node *dt_get_parent(const struct dt_device_node *node);
476
477 /**
478 * dt_device_get_address - Resolve an address for a device
479 * @device: the device whose address is to be resolved
480 * @index: index of the address to resolve
481 * @addr: address filled by this function
482 * @size: size filled by this function
483 *
484 * This function resolves an address, walking the tree, for a give
485 * device-tree node. It returns 0 on success.
486 */
487 int dt_device_get_address(const struct dt_device_node *dev, unsigned int index,
488 u64 *addr, u64 *size);
489
490 /**
491 * dt_number_of_irq - Get the number of IRQ for a device
492 * @device: the device whose number of interrupt is to be retrieved
493 *
494 * Return the number of irq for this device or 0 if there is no
495 * interrupt or an error occurred.
496 */
497 unsigned int dt_number_of_irq(const struct dt_device_node *device);
498
499 /**
500 * dt_number_of_address - Get the number of addresses for a device
501 * @device: the device whose number of address is to be retrieved
502 *
503 * Return the number of address for this device or 0 if there is no
504 * address or an error occurred.
505 */
506 unsigned int dt_number_of_address(const struct dt_device_node *device);
507
508 /**
509 * dt_device_get_irq - Resolve an interrupt for a device
510 * @device: the device whose interrupt is to be resolved
511 * @index: index of the interrupt to resolve
512 * @out_irq: structure dt_irq filled by this function
513 *
514 * This function resolves an interrupt, walking the tree, for a given
515 * device-tree node. It's the high level pendant to dt_device_get_raw_irq().
516 */
517 int dt_device_get_irq(const struct dt_device_node *device, unsigned int index,
518 struct dt_irq *irq);
519
520 /**
521 * dt_device_get_raw_irq - Resolve an interrupt for a device without translation
522 * @device: the device whose interrupt is to be resolved
523 * @index: index of the interrupt to resolve
524 * @out_irq: structure dt_raw_irq filled by this function
525 *
526 * This function resolves an interrupt for a device, no translation is
527 * made. dt_irq_translate can be called after.
528 */
529 int dt_device_get_raw_irq(const struct dt_device_node *device,
530 unsigned int index,
531 struct dt_raw_irq *irq);
532
533 /**
534 * dt_irq_translate - Translate an irq
535 * @raw: IRQ to translate (raw format)
536 * @out_irq: structure dt_irq filled by this function
537 */
538 int dt_irq_translate(const struct dt_raw_irq *raw, struct dt_irq *out_irq);
539
540 /**
541 * dt_for_each_irq_map - Iterate over a nodes interrupt-map property
542 * @dev: The node whose interrupt-map property should be iterated over
543 * @cb: Call back to call for each entry
544 * @data: Caller data passed to callback
545 */
546 int dt_for_each_irq_map(const struct dt_device_node *dev,
547 int (*cb)(const struct dt_device_node *,
548 const struct dt_irq *,
549 void *),
550 void *data);
551
552 /**
553 * dt_for_each_range - Iterate over a nodes ranges property
554 * @dev: The node whose interrupt-map property should be iterated over
555 * @cb: Call back to call for each entry
556 * @data: Caller data passed to callback
557 */
558 int dt_for_each_range(const struct dt_device_node *dev,
559 int (*cb)(const struct dt_device_node *,
560 u64 addr, u64 length,
561 void *),
562 void *data);
563
564 /**
565 * dt_n_size_cells - Helper to retrieve the number of cell for the size
566 * @np: node to get the value
567 *
568 * This function retrieves for a give device-tree node the number of
569 * cell for the size field.
570 */
571 int dt_n_size_cells(const struct dt_device_node *np);
572
573 /**
574 * dt_n_addr_cells - Helper to retrieve the number of cell for the address
575 * @np: node to get the value
576 *
577 * This function retrieves for a give device-tree node the number of
578 * cell for the address field.
579 */
580 int dt_n_addr_cells(const struct dt_device_node *np);
581
582 /**
583 * dt_child_n_size_cells - Helper to retrieve the number of cell for the size
584 * @parent: parent of the child to get the value
585 *
586 * This function retrieves for a given device-tree node the number of
587 * cell for the size field of there child
588 */
589 int dt_child_n_size_cells(const struct dt_device_node *parent);
590
591 /**
592 * dt_child_n_addr_cells - Helper to retrieve the number of cell for the
593 * address
594 * @parent: parent of the child to get the value
595 *
596 * This function retrieves for a given device-tree node the number of
597 * cell for the address field of there child
598 */
599 int dt_child_n_addr_cells(const struct dt_device_node *parent);
600
601 /**
602 * dt_device_is_available - Check if a device is available for use
603 *
604 * @device: Node to check for availability
605 *
606 * Returns true if the status property is absent or set to "okay" or "ok",
607 * false otherwise.
608 */
609 bool_t dt_device_is_available(const struct dt_device_node *device);
610
611 /**
612 * dt_device_for_passthrough - Check if a device will be used for
613 * passthrough later
614 *
615 * @device: Node to check
616 *
617 * Return true if the property "xen,passthrough" is present in the node,
618 * false otherwise.
619 */
620 bool_t dt_device_for_passthrough(const struct dt_device_node *device);
621
622 /**
623 * dt_match_node - Tell if a device_node has a matching of dt_device_match
624 * @matches: array of dt_device_match structures to search in
625 * @node: the dt_device_node structure to match against
626 *
627 * Returns true if the device node match one of dt_device_match.
628 */
629 const struct dt_device_match *
630 dt_match_node(const struct dt_device_match *matches,
631 const struct dt_device_node *node);
632
633 /**
634 * dt_find_matching_node - Find a node based on an dt_device_match match table
635 * @from: The node to start searching from or NULL, the node you pass
636 * will not be searched, only the next one will; typically, you pass
637 * what the returned call returned
638 * @matches: array of dt_device_match structures to search in
639 *
640 * Returns a node pointer.
641 */
642 struct dt_device_node *
643 dt_find_matching_node(struct dt_device_node *from,
644 const struct dt_device_match *matches);
645
646 /**
647 * dt_set_cell - Write a value into a series of cells
648 *
649 * @cellp: Pointer to cells
650 * @size: number of cells to write the value
651 * @value: number to write
652 *
653 * Write a value into a series of cells and update cellp to point to the
654 * cell just after.
655 */
656 void dt_set_cell(__be32 **cellp, int size, u64 val);
657
658 /**
659 * dt_set_range - Write range into a series of cells
660 *
661 * @cellp: Pointer to cells
662 * @np: Node which contains the encoding for the address and the size
663 * @address: Start of range
664 * @size: Size of the range
665 *
666 * Write a range into a series of cells and update cellp to point to the
667 * cell just after.
668 */
669 void dt_set_range(__be32 **cellp, const struct dt_device_node *np,
670 u64 address, u64 size);
671
672 /**
673 * dt_child_set_range - Write range into a series of cells
674 *
675 * @cellp: Pointer to cells
676 * @parent: Parent node which contains the encode for the address and the size
677 * @address: Start of range
678 * @size: Size of the range
679 *
680 * Write a range into a series of cells and update cellp to point to the
681 * cell just after.
682 */
683 void dt_child_set_range(__be32 **cellp, int addrcells, int sizecells,
684 u64 address, u64 size);
685
686 /**
687 * dt_get_range - Read a range (address/size) from a series of cells
688 *
689 * @cellp: Pointer to cells
690 * @np Node which contains the encoding for the addresss and the size
691 * @address: Address filled by this function
692 * @size: Size filled by this function
693 *
694 * WARNING: This function should not be used to decode an address
695 * This function reads a range (address/size) from a series of cells and
696 * update cellp to point to the cell just after.
697 */
698 void dt_get_range(const __be32 **cellp, const struct dt_device_node *np,
699 u64 *address, u64 *size);
700
701 /**
702 * dt_parse_phandle - Resolve a phandle property to a device_node pointer
703 * @np: Pointer to device node holding phandle property
704 * @phandle_name: Name of property holding a phandle value
705 * @index: For properties holding a table of phandles, this is the index into
706 * the table
707 *
708 * Returns the device_node pointer.
709 */
710 struct dt_device_node *dt_parse_phandle(const struct dt_device_node *np,
711 const char *phandle_name,
712 int index);
713
714 /**
715 * dt_parse_phandle_with_args() - Find a node pointed by phandle in a list
716 * @np: pointer to a device tree node containing a list
717 * @list_name: property name that contains a list
718 * @cells_name: property name that specifies phandles' arguments count
719 * @index: index of a phandle to parse out
720 * @out_args: optional pointer to output arguments structure (will be filled)
721 *
722 * This function is useful to parse lists of phandles and their arguments.
723 * Returns 0 on success and fills out_args, on error returns appropriate
724 * errno value.
725 *
726 * Example:
727 *
728 * phandle1: node1 {
729 * #list-cells = <2>;
730 * }
731 *
732 * phandle2: node2 {
733 * #list-cells = <1>;
734 * }
735 *
736 * node3 {
737 * list = <&phandle1 1 2 &phandle2 3>;
738 * }
739 *
740 * To get a device_node of the `node2' node you may call this:
741 * dt_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
742 */
743 int dt_parse_phandle_with_args(const struct dt_device_node *np,
744 const char *list_name,
745 const char *cells_name, int index,
746 struct dt_phandle_args *out_args);
747
748 /**
749 * dt_count_phandle_with_args() - Find the number of phandles references in a property
750 * @np: pointer to a device tree node containing a list
751 * @list_name: property name that contains a list
752 * @cells_name: property name that specifies phandles' arguments count
753 *
754 * Returns the number of phandle + argument tuples within a property. It
755 * is a typical pattern to encode a list of phandle and variable
756 * arguments into a single property. The number of arguments is encoded
757 * by a property in the phandle-target node. For example, a gpios
758 * property would contain a list of GPIO specifies consisting of a
759 * phandle and 1 or more arguments. The number of arguments are
760 * determined by the #gpio-cells property in the node pointed to by the
761 * phandle.
762 */
763 int dt_count_phandle_with_args(const struct dt_device_node *np,
764 const char *list_name,
765 const char *cells_name);
766
767 #ifdef CONFIG_DEVICE_TREE_DEBUG
768 #define dt_dprintk(fmt, args...) \
769 printk(XENLOG_DEBUG fmt, ## args)
770 #else
771 static inline void
772 __attribute__ ((__format__ (__printf__, 1, 2)))
dt_dprintk(const char * fmt,...)773 dt_dprintk(const char *fmt, ...) {}
774 #endif
775
776 #endif /* __XEN_DEVICE_TREE_H */
777
778 /*
779 * Local variables:
780 * mode: C
781 * c-file-style: "BSD"
782 * c-basic-offset: 4
783 * indent-tabs-mode: nil
784 * End:
785 */
786