Rev 1894 | Rev 1896 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1894 | Rev 1895 | ||
---|---|---|---|
Line 29... | Line 29... | ||
29 | #include <ofw_tree.h> |
29 | #include <ofw_tree.h> |
30 | #include <ofw.h> |
30 | #include <ofw.h> |
31 | #include <types.h> |
31 | #include <types.h> |
32 | #include <string.h> |
32 | #include <string.h> |
33 | #include <balloc.h> |
33 | #include <balloc.h> |
- | 34 | #include <asm.h> |
|
- | 35 | ||
- | 36 | #define MAX_PATH_LEN 256 |
|
34 | 37 | ||
35 | static ofw_tree_node_t *ofw_tree_node_alloc(void) |
38 | static ofw_tree_node_t *ofw_tree_node_alloc(void) |
36 | { |
39 | { |
37 | return balloc(sizeof(ofw_tree_node_t), sizeof(ofw_tree_node_t)); |
40 | return balloc(sizeof(ofw_tree_node_t), sizeof(ofw_tree_node_t)); |
38 | } |
41 | } |
Line 59... | Line 62... | ||
59 | * @param current OpenFirmware phandle to the current device tree node. |
62 | * @param current OpenFirmware phandle to the current device tree node. |
60 | */ |
63 | */ |
61 | static void ofw_tree_node_process(ofw_tree_node_t *current_node, |
64 | static void ofw_tree_node_process(ofw_tree_node_t *current_node, |
62 | ofw_tree_node_t *parent_node, phandle current) |
65 | ofw_tree_node_t *parent_node, phandle current) |
63 | { |
66 | { |
- | 67 | static char path[MAX_PATH_LEN+1]; |
|
- | 68 | static char name[OFW_TREE_PROPERTY_MAX_NAMELEN]; |
|
64 | phandle peer; |
69 | phandle peer; |
65 | phandle child; |
70 | phandle child; |
66 | unsigned properties = 0; |
71 | unsigned properties = 0; |
67 | char name[OFW_TREE_PROPERTY_MAX_NAMELEN]; |
72 | size_t len; |
- | 73 | int i; |
|
68 | 74 | ||
69 | /* |
75 | /* |
70 | * Initialize node. |
76 | * Initialize node. |
71 | */ |
77 | */ |
72 | current_node->parent = parent_node; |
78 | current_node->parent = parent_node; |
Line 74... | Line 80... | ||
74 | current_node->child = NULL; |
80 | current_node->child = NULL; |
75 | current_node->properties = 0; |
81 | current_node->properties = 0; |
76 | current_node->property = NULL; |
82 | current_node->property = NULL; |
77 | 83 | ||
78 | /* |
84 | /* |
- | 85 | * Get the disambigued name. |
|
- | 86 | */ |
|
- | 87 | len = ofw_package_to_path(current, path, MAX_PATH_LEN); |
|
- | 88 | if (len == -1) |
|
- | 89 | return; |
|
- | 90 | ||
- | 91 | path[len] = '\0'; |
|
- | 92 | for (i = len - 1; i >= 0 && path[i] != '/'; i--) |
|
- | 93 | ; |
|
- | 94 | i++; /* do not include '/' */ |
|
- | 95 | ||
- | 96 | len -= i; |
|
- | 97 | current_node->da_name = ofw_tree_space_alloc(len + 1); /* add space for trailing '\0' */ |
|
- | 98 | if (!current_node->da_name) |
|
- | 99 | return; |
|
- | 100 | ||
- | 101 | memcpy(current_node->da_name, &path[i], len); |
|
- | 102 | current_node->da_name[len] = '\0'; |
|
- | 103 | ||
- | 104 | /* |
|
79 | * Recursively process the potential peer node. |
105 | * Recursively process the potential peer node. |
80 | */ |
106 | */ |
81 | peer = ofw_get_peer_node(current); |
107 | peer = ofw_get_peer_node(current); |
82 | if (peer != 0 && peer != -1) { |
108 | if (peer != 0 && peer != -1) { |
83 | ofw_tree_node_t *peer_node; |
109 | ofw_tree_node_t *peer_node; |
84 | 110 | ||
85 | peer_node = ofw_tree_node_alloc(); |
111 | peer_node = ofw_tree_node_alloc(); |
86 | if (peer_node) { |
112 | if (peer_node) { |
87 | ofw_tree_node_process(peer_node, current_node, peer); |
113 | ofw_tree_node_process(peer_node, parent_node, peer); |
88 | current_node->peer = peer_node; |
114 | current_node->peer = peer_node; |
89 | } |
115 | } |
90 | } |
116 | } |
91 | 117 | ||
92 | /* |
118 | /* |
Line 118... | Line 144... | ||
118 | */ |
144 | */ |
119 | current_node->property = ofw_tree_properties_alloc(current_node->properties); |
145 | current_node->property = ofw_tree_properties_alloc(current_node->properties); |
120 | if (!current_node->property) |
146 | if (!current_node->property) |
121 | return; |
147 | return; |
122 | 148 | ||
123 | int i = 0; |
- | |
124 | - | ||
125 | name[0] = '\0'; |
149 | name[0] = '\0'; |
126 | for (i = 0; ofw_next_property(current, name, name) == 1; i++) { |
150 | for (i = 0; ofw_next_property(current, name, name) == 1; i++) { |
127 | size_t size; |
151 | size_t size; |
128 | 152 | ||
129 | if (i == current_node->properties) |
153 | if (i == current_node->properties) |