Subversion Repositories HelenOS

Rev

Rev 1909 | Rev 2071 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1909 Rev 1973
Line 67... Line 67...
67
 
67
 
68
/** Transfer information from one OpenFirmware node into its memory representation.
68
/** Transfer information from one OpenFirmware node into its memory representation.
69
 *
69
 *
70
 * Transfer entire information from the OpenFirmware device tree 'current' node to
70
 * Transfer entire information from the OpenFirmware device tree 'current' node to
71
 * its memory representation in 'current_node'. This function recursively processes
71
 * its memory representation in 'current_node'. This function recursively processes
-
 
72
 * all node's children. Node's peers are processed iteratively in order to prevent
72
 * all node's peers and children.
73
 * stack from overflowing.
73
 *
74
 *
74
 * @param current_node  Pointer to uninitialized ofw_tree_node structure that will
75
 * @param current_node  Pointer to uninitialized ofw_tree_node structure that will
75
 *          become the memory represenation of 'current'.
76
 *          become the memory represenation of 'current'.
76
 * @param parent_node   Parent ofw_tree_node structure or NULL in case of root node.
77
 * @param parent_node   Parent ofw_tree_node structure or NULL in case of root node.
77
 * @param current   OpenFirmware phandle to the current device tree node.
78
 * @param current   OpenFirmware phandle to the current device tree node.
Line 81... Line 82...
81
{
82
{
82
    static char path[MAX_PATH_LEN+1];
83
    static char path[MAX_PATH_LEN+1];
83
    static char name[OFW_TREE_PROPERTY_MAX_NAMELEN];
84
    static char name[OFW_TREE_PROPERTY_MAX_NAMELEN];
84
    phandle peer;
85
    phandle peer;
85
    phandle child;
86
    phandle child;
86
    unsigned properties = 0;
-
 
87
    size_t len;
87
    size_t len;
88
    int i;
88
    int i;
89
 
89
 
-
 
90
    while (current_node) {
90
    /*
91
        /*
91
     * Initialize node.
92
         * Initialize node.
92
     */
93
         */
93
    current_node->parent = parent_node;
94
        current_node->parent = parent_node;
94
    current_node->peer = NULL;
95
        current_node->peer = NULL;
Line 109... Line 110...
109
    for (i = len - 1; i >= 0 && path[i] != '/'; i--)
110
        for (i = len - 1; i >= 0 && path[i] != '/'; i--)
110
        ;
111
            ;
111
    i++;                                /* do not include '/' */
112
        i++;    /* do not include '/' */
112
   
113
   
113
    len -= i;
114
        len -= i;
-
 
115
 
-
 
116
        /* add space for trailing '\0' */
114
    current_node->da_name = ofw_tree_space_alloc(len + 1);      /* add space for trailing '\0' */
117
        current_node->da_name = ofw_tree_space_alloc(len + 1);
115
    if (!current_node->da_name)
118
        if (!current_node->da_name)
116
        return;
119
            return;
117
   
120
   
118
    memcpy(current_node->da_name, &path[i], len);
121
        memcpy(current_node->da_name, &path[i], len);
119
    current_node->da_name[len] = '\0';
122
        current_node->da_name[len] = '\0';
120
   
123
   
121
    /*
-
 
122
     * Recursively process the potential peer node.
-
 
123
     */
-
 
124
    peer = ofw_get_peer_node(current);
-
 
125
    if (peer != 0 && peer != -1) {
-
 
126
        ofw_tree_node_t *peer_node;
-
 
127
       
-
 
128
        peer_node = ofw_tree_node_alloc();
-
 
129
        if (peer_node) {
-
 
130
            ofw_tree_node_process(peer_node, parent_node, peer);
-
 
131
            current_node->peer = peer_node;
-
 
132
        }
-
 
133
    }
-
 
134
   
124
   
135
    /*
125
        /*
136
     * Recursively process the potential child node.
126
         * Recursively process the potential child node.
137
     */
127
         */
138
    child = ofw_get_child_node(current);
128
        child = ofw_get_child_node(current);
Line 168... Line 158...
168
        size_t size;
158
            size_t size;
169
       
159
       
170
        if (i == current_node->properties)
160
            if (i == current_node->properties)
171
            break;
161
                break;
172
       
162
       
173
        memcpy(current_node->property[i].name, name, OFW_TREE_PROPERTY_MAX_NAMELEN);
163
            memcpy(current_node->property[i].name, name,
-
 
164
                OFW_TREE_PROPERTY_MAX_NAMELEN);
174
        current_node->property[i].name[OFW_TREE_PROPERTY_MAX_NAMELEN] = '\0';
165
            current_node->property[i].name[OFW_TREE_PROPERTY_MAX_NAMELEN] = '\0';
175
 
166
 
176
        size = ofw_get_proplen(current, name);
167
            size = ofw_get_proplen(current, name);
177
        current_node->property[i].size = size;
168
            current_node->property[i].size = size;
178
        if (size) {
169
            if (size) {
Line 189... Line 180...
189
            current_node->property[i].value = NULL;
180
                current_node->property[i].value = NULL;
190
        }
181
            }
191
    }
182
        }
192
       
183
 
193
    current_node->properties = i;   /* Just in case we ran out of memory. */
184
        current_node->properties = i;   /* Just in case we ran out of memory. */
-
 
185
 
-
 
186
        /*
-
 
187
         * Iteratively process the next peer node.
-
 
188
         * Note that recursion is a bad idea here.
-
 
189
         * Due to the topology of the OpenFirmware device tree,
-
 
190
         * the nesting of peer nodes could be to wide and the
-
 
191
         * risk of overflowing the stack is too real.
-
 
192
         */
-
 
193
        peer = ofw_get_peer_node(current);
-
 
194
        if (peer != 0 && peer != -1) {
-
 
195
            ofw_tree_node_t *peer_node;
-
 
196
       
-
 
197
            peer_node = ofw_tree_node_alloc();
-
 
198
            if (peer_node) {
-
 
199
                current_node->peer = peer_node;
-
 
200
                current_node = peer_node;
-
 
201
                current = peer;
-
 
202
                /*
-
 
203
                 * Process the peer in next iteration.
-
 
204
                 */
-
 
205
                continue;
-
 
206
            }
-
 
207
        }
-
 
208
        /*
-
 
209
         * No more peers on this level.
-
 
210
         */
-
 
211
        break;
-
 
212
    }
194
}
213
}
195
 
214
 
196
/** Construct memory representation of OpenFirmware device tree.
215
/** Construct memory representation of OpenFirmware device tree.
197
 *
216
 *
198
 * @return NULL on failure or pointer to the root node.
217
 * @return NULL on failure or pointer to the root node.