diff options
Diffstat (limited to 'include/linux/of.h')
| -rw-r--r-- | include/linux/of.h | 72 |
1 files changed, 54 insertions, 18 deletions
diff --git a/include/linux/of.h b/include/linux/of.h index e7facd8fbce8..cad7cf0ab278 100644 --- a/include/linux/of.h +++ b/include/linux/of.h | |||
| @@ -19,6 +19,11 @@ | |||
| 19 | #include <linux/bitops.h> | 19 | #include <linux/bitops.h> |
| 20 | #include <linux/kref.h> | 20 | #include <linux/kref.h> |
| 21 | #include <linux/mod_devicetable.h> | 21 | #include <linux/mod_devicetable.h> |
| 22 | #include <linux/spinlock.h> | ||
| 23 | |||
| 24 | #include <asm/byteorder.h> | ||
| 25 | |||
| 26 | #ifdef CONFIG_OF | ||
| 22 | 27 | ||
| 23 | typedef u32 phandle; | 28 | typedef u32 phandle; |
| 24 | typedef u32 ihandle; | 29 | typedef u32 ihandle; |
| @@ -39,10 +44,7 @@ struct of_irq_controller; | |||
| 39 | struct device_node { | 44 | struct device_node { |
| 40 | const char *name; | 45 | const char *name; |
| 41 | const char *type; | 46 | const char *type; |
| 42 | phandle node; | 47 | phandle phandle; |
| 43 | #if !defined(CONFIG_SPARC) | ||
| 44 | phandle linux_phandle; | ||
| 45 | #endif | ||
| 46 | char *full_name; | 48 | char *full_name; |
| 47 | 49 | ||
| 48 | struct property *properties; | 50 | struct property *properties; |
| @@ -63,6 +65,16 @@ struct device_node { | |||
| 63 | #endif | 65 | #endif |
| 64 | }; | 66 | }; |
| 65 | 67 | ||
| 68 | /* Pointer for first entry in chain of all nodes. */ | ||
| 69 | extern struct device_node *allnodes; | ||
| 70 | extern struct device_node *of_chosen; | ||
| 71 | extern rwlock_t devtree_lock; | ||
| 72 | |||
| 73 | static inline bool of_node_is_root(const struct device_node *node) | ||
| 74 | { | ||
| 75 | return node && (node->parent == NULL); | ||
| 76 | } | ||
| 77 | |||
| 66 | static inline int of_node_check_flag(struct device_node *n, unsigned long flag) | 78 | static inline int of_node_check_flag(struct device_node *n, unsigned long flag) |
| 67 | { | 79 | { |
| 68 | return test_bit(flag, &n->_flags); | 80 | return test_bit(flag, &n->_flags); |
| @@ -73,12 +85,6 @@ static inline void of_node_set_flag(struct device_node *n, unsigned long flag) | |||
| 73 | set_bit(flag, &n->_flags); | 85 | set_bit(flag, &n->_flags); |
| 74 | } | 86 | } |
| 75 | 87 | ||
| 76 | static inline void | ||
| 77 | set_node_proc_entry(struct device_node *dn, struct proc_dir_entry *de) | ||
| 78 | { | ||
| 79 | dn->pde = de; | ||
| 80 | } | ||
| 81 | |||
| 82 | extern struct device_node *of_find_all_nodes(struct device_node *prev); | 88 | extern struct device_node *of_find_all_nodes(struct device_node *prev); |
| 83 | 89 | ||
| 84 | #if defined(CONFIG_SPARC) | 90 | #if defined(CONFIG_SPARC) |
| @@ -101,26 +107,36 @@ extern void of_node_put(struct device_node *node); | |||
| 101 | */ | 107 | */ |
| 102 | 108 | ||
| 103 | /* Helper to read a big number; size is in cells (not bytes) */ | 109 | /* Helper to read a big number; size is in cells (not bytes) */ |
| 104 | static inline u64 of_read_number(const u32 *cell, int size) | 110 | static inline u64 of_read_number(const __be32 *cell, int size) |
| 105 | { | 111 | { |
| 106 | u64 r = 0; | 112 | u64 r = 0; |
| 107 | while (size--) | 113 | while (size--) |
| 108 | r = (r << 32) | *(cell++); | 114 | r = (r << 32) | be32_to_cpu(*(cell++)); |
| 109 | return r; | 115 | return r; |
| 110 | } | 116 | } |
| 111 | 117 | ||
| 112 | /* Like of_read_number, but we want an unsigned long result */ | 118 | /* Like of_read_number, but we want an unsigned long result */ |
| 113 | #ifdef CONFIG_PPC32 | 119 | static inline unsigned long of_read_ulong(const __be32 *cell, int size) |
| 114 | static inline unsigned long of_read_ulong(const u32 *cell, int size) | ||
| 115 | { | 120 | { |
| 116 | return cell[size-1]; | 121 | /* toss away upper bits if unsigned long is smaller than u64 */ |
| 122 | return of_read_number(cell, size); | ||
| 117 | } | 123 | } |
| 118 | #else | ||
| 119 | #define of_read_ulong(cell, size) of_read_number(cell, size) | ||
| 120 | #endif | ||
| 121 | 124 | ||
| 122 | #include <asm/prom.h> | 125 | #include <asm/prom.h> |
| 123 | 126 | ||
| 127 | /* Default #address and #size cells. Allow arch asm/prom.h to override */ | ||
| 128 | #if !defined(OF_ROOT_NODE_ADDR_CELLS_DEFAULT) | ||
| 129 | #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1 | ||
| 130 | #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 | ||
| 131 | #endif | ||
| 132 | |||
| 133 | /* Default string compare functions, Allow arch asm/prom.h to override */ | ||
| 134 | #if !defined(of_compat_cmp) | ||
| 135 | #define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2)) | ||
| 136 | #define of_prop_cmp(s1, s2) strcmp((s1), (s2)) | ||
| 137 | #define of_node_cmp(s1, s2) strcasecmp((s1), (s2)) | ||
| 138 | #endif | ||
| 139 | |||
| 124 | /* flag descriptions */ | 140 | /* flag descriptions */ |
| 125 | #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */ | 141 | #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */ |
| 126 | #define OF_DETACHED 2 /* node has been detached from the device tree */ | 142 | #define OF_DETACHED 2 /* node has been detached from the device tree */ |
| @@ -130,6 +146,11 @@ static inline unsigned long of_read_ulong(const u32 *cell, int size) | |||
| 130 | 146 | ||
| 131 | #define OF_BAD_ADDR ((u64)-1) | 147 | #define OF_BAD_ADDR ((u64)-1) |
| 132 | 148 | ||
| 149 | #ifndef of_node_to_nid | ||
| 150 | static inline int of_node_to_nid(struct device_node *np) { return -1; } | ||
| 151 | #define of_node_to_nid of_node_to_nid | ||
| 152 | #endif | ||
| 153 | |||
| 133 | extern struct device_node *of_find_node_by_name(struct device_node *from, | 154 | extern struct device_node *of_find_node_by_name(struct device_node *from, |
| 134 | const char *name); | 155 | const char *name); |
| 135 | #define for_each_node_by_name(dn, name) \ | 156 | #define for_each_node_by_name(dn, name) \ |
| @@ -187,4 +208,19 @@ extern int of_parse_phandles_with_args(struct device_node *np, | |||
| 187 | const char *list_name, const char *cells_name, int index, | 208 | const char *list_name, const char *cells_name, int index, |
| 188 | struct device_node **out_node, const void **out_args); | 209 | struct device_node **out_node, const void **out_args); |
| 189 | 210 | ||
| 211 | extern int of_machine_is_compatible(const char *compat); | ||
| 212 | |||
| 213 | extern int prom_add_property(struct device_node* np, struct property* prop); | ||
| 214 | extern int prom_remove_property(struct device_node *np, struct property *prop); | ||
| 215 | extern int prom_update_property(struct device_node *np, | ||
| 216 | struct property *newprop, | ||
| 217 | struct property *oldprop); | ||
| 218 | |||
| 219 | #if defined(CONFIG_OF_DYNAMIC) | ||
| 220 | /* For updating the device tree at runtime */ | ||
| 221 | extern void of_attach_node(struct device_node *); | ||
| 222 | extern void of_detach_node(struct device_node *); | ||
| 223 | #endif | ||
| 224 | |||
| 225 | #endif /* CONFIG_OF */ | ||
| 190 | #endif /* _LINUX_OF_H */ | 226 | #endif /* _LINUX_OF_H */ |
