Changeset c6588ce in mainline for kernel/genarch/src/ofw/ofw_tree.c


Ignore:
Timestamp:
2012-05-05T08:12:17Z (12 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ee04c28
Parents:
2cc7f16 (diff), d21e935c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/ofw/ofw_tree.c

    r2cc7f16 rc6588ce  
    3838#include <genarch/ofw/ofw_tree.h>
    3939#include <mm/slab.h>
     40#include <sysinfo/sysinfo.h>
    4041#include <memstr.h>
    4142#include <str.h>
     
    6566    const char *name)
    6667{
    67         size_t i;
    68        
    69         for (i = 0; i < node->properties; i++) {
     68        for (size_t i = 0; i < node->properties; i++) {
    7069                if (str_cmp(node->property[i].name, name) == 0)
    7170                        return &node->property[i];
     
    104103    const char *name)
    105104{
    106         ofw_tree_node_t *cur;
    107        
    108105        /*
    109106         * Try to find the disambigued name.
    110107         */
    111         for (cur = node->child; cur; cur = cur->peer) {
     108        for (ofw_tree_node_t *cur = node->child; cur; cur = cur->peer) {
    112109                if (str_cmp(cur->da_name, name) == 0)
    113110                        return cur;
     
    121118         * are not always fully-qualified.
    122119         */
    123         for (cur = node->child; cur; cur = cur->peer) {
     120        for (ofw_tree_node_t *cur = node->child; cur; cur = cur->peer) {
    124121                if (str_cmp(ofw_tree_node_name(cur), name) == 0)
    125122                        return cur;
     
    141138    const char *dtype)
    142139{
    143         ofw_tree_node_t *cur;
    144        
    145         for (cur = node->child; cur; cur = cur->peer) {
     140        for (ofw_tree_node_t *cur = node->child; cur; cur = cur->peer) {
    146141                ofw_tree_property_t *prop =
    147142                    ofw_tree_getprop(cur, "device_type");
     
    172167    phandle handle)
    173168{
    174         ofw_tree_node_t *cur;
    175        
    176         for (cur = root; cur; cur = cur->peer) {
     169        for (ofw_tree_node_t *cur = root; cur; cur = cur->peer) {
    177170                if (cur->node_handle == handle)
    178171                        return cur;
    179172               
    180173                if (cur->child) {
    181                         ofw_tree_node_t *node
    182                             = ofw_tree_find_node_by_handle(cur->child, handle);
     174                        ofw_tree_node_t *node =
     175                            ofw_tree_find_node_by_handle(cur->child, handle);
    183176                        if (node)
    184177                                return node;
     
    201194    const char *dtype)
    202195{
    203         ofw_tree_node_t *cur;
    204        
    205         for (cur = node->peer; cur; cur = cur->peer) {
     196        for (ofw_tree_node_t *cur = node->peer; cur; cur = cur->peer) {
    206197                ofw_tree_property_t *prop =
    207198                    ofw_tree_getprop(cur, "device_type");
     
    229220    const char *name)
    230221{
    231         ofw_tree_node_t *cur;
    232        
    233         for (cur = node->peer; cur; cur = cur->peer) {
    234                 ofw_tree_property_t *prop
    235                     = ofw_tree_getprop(cur, "name");
     222        for (ofw_tree_node_t *cur = node->peer; cur; cur = cur->peer) {
     223                ofw_tree_property_t *prop =
     224                    ofw_tree_getprop(cur, "name");
    236225               
    237226                if ((!prop) || (!prop->value))
     
    259248       
    260249        ofw_tree_node_t *node = ofw_root;
    261         size_t i;
    262250        size_t j;
    263251       
    264         for (i = 1; (i < str_size(path)) && (node); i = j + 1) {
     252        for (size_t i = 1; (i < str_size(path)) && (node); i = j + 1) {
    265253                for (j = i; (j < str_size(path)) && (path[j] != '/'); j++);
    266254               
     
    294282    const char *dtype, ofw_tree_walker_t walker, void *arg)
    295283{
    296         ofw_tree_node_t *cur;
    297        
    298         for (cur = node; cur; cur = cur->peer) {
     284        for (ofw_tree_node_t *cur = node; cur; cur = cur->peer) {
    299285                ofw_tree_property_t *prop =
    300286                    ofw_tree_getprop(cur, "device_type");
     
    334320}
    335321
    336 /** Print OpenFirmware device subtree rooted in a node.
     322/** Get OpenFirmware node properties.
     323 *
     324 * @param item    Sysinfo item (unused).
     325 * @param size    Size of the returned data.
     326 * @param dry_run Do not get the data, just calculate the size.
     327 * @param data    OpenFirmware node.
     328 *
     329 * @return Data containing a serialized dump of all node
     330 *         properties. If the return value is not NULL, it
     331 *         should be freed in the context of the sysinfo request.
     332 *
     333 */
     334static void *ofw_sysinfo_properties(struct sysinfo_item *item, size_t *size,
     335    bool dry_run, void *data)
     336{
     337        ofw_tree_node_t *node = (ofw_tree_node_t *) data;
     338       
     339        /* Compute serialized data size */
     340        *size = 0;
     341        for (size_t i = 0; i < node->properties; i++)
     342                *size += str_size(node->property[i].name) + 1 +
     343                    sizeof(node->property[i].size) + node->property[i].size;
     344       
     345        if (dry_run)
     346                return NULL;
     347       
     348        void *dump = malloc(*size, FRAME_ATOMIC);
     349        if (dump == NULL) {
     350                *size = 0;
     351                return NULL;
     352        }
     353       
     354        /* Serialize the data */
     355        size_t pos = 0;
     356        for (size_t i = 0; i < node->properties; i++) {
     357                /* Property name */
     358                str_cpy(dump + pos, *size - pos, node->property[i].name);
     359                pos += str_size(node->property[i].name) + 1;
     360               
     361                /* Value size */
     362                memcpy(dump + pos, &node->property[i].size,
     363                    sizeof(node->property[i].size));
     364                pos += sizeof(node->property[i].size);
     365               
     366                /* Value */
     367                memcpy(dump + pos, node->property[i].value,
     368                    node->property[i].size);
     369                pos += node->property[i].size;
     370        }
     371       
     372        return ((void *) dump);
     373}
     374
     375/** Map OpenFirmware device subtree rooted in a node into sysinfo.
    337376 *
    338377 * Child nodes are processed recursively and peer nodes are processed
     
    343382 *
    344383 */
    345 static void ofw_tree_node_print(ofw_tree_node_t *node, const char *path)
     384static void ofw_tree_node_sysinfo(ofw_tree_node_t *node, const char *path)
    346385{
    347386        char *cur_path = (char *) malloc(PATH_MAX_LEN, 0);
    348         ofw_tree_node_t *cur;
    349        
    350         for (cur = node; cur; cur = cur->peer) {
    351                 if ((cur->parent) && (path)) {
    352                         snprintf(cur_path, PATH_MAX_LEN, "%s/%s", path, cur->da_name);
    353                         printf("%s\n", cur_path);
    354                 } else {
    355                         snprintf(cur_path, PATH_MAX_LEN, "%s", cur->da_name);
    356                         printf("/\n");
    357                 }
     387       
     388        for (ofw_tree_node_t *cur = node; cur; cur = cur->peer) {
     389                if ((cur->parent) && (path))
     390                        snprintf(cur_path, PATH_MAX_LEN, "%s.%s", path, cur->da_name);
     391                else
     392                        snprintf(cur_path, PATH_MAX_LEN, "firmware.%s", cur->da_name);
     393               
     394                sysinfo_set_item_gen_data(cur_path, NULL, ofw_sysinfo_properties,
     395                    (void *) cur);
    358396               
    359397                if (cur->child)
    360                         ofw_tree_node_print(cur->child, cur_path);
     398                        ofw_tree_node_sysinfo(cur->child, cur_path);
    361399        }
    362400       
     
    364402}
    365403
    366 /** Print the structure of the OpenFirmware device tree. */
    367 void ofw_tree_print(void)
    368 {
    369         ofw_tree_node_print(ofw_root, NULL);
     404/** Map the OpenFirmware device tree into sysinfo. */
     405void ofw_sysinfo_map(void)
     406{
     407        ofw_tree_node_sysinfo(ofw_root, NULL);
    370408}
    371409
Note: See TracChangeset for help on using the changeset viewer.