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