Changeset 973ef9fc in mainline for uspace/drv/root/root.c


Ignore:
Timestamp:
2010-12-25T21:20:28Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
631ee0c
Parents:
1bfd3d3 (diff), 09178b7f (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
  • uspace/drv/root/root.c

    r1bfd3d3 r973ef9fc  
    11/*
    22 * Copyright (c) 2010 Lenka Trochtova
     3 * Copyright (c) 2010 Vojtech Horky
    34 * All rights reserved.
    45 *
     
    4546#include <ctype.h>
    4647#include <macros.h>
     48#include <inttypes.h>
     49#include <sysinfo.h>
    4750
    4851#include <driver.h>
     
    5154
    5255#define NAME "root"
     56
     57#define PLATFORM_DEVICE_NAME "hw"
     58#define PLATFORM_DEVICE_MATCH_ID_FMT "platform/%s"
     59#define PLATFORM_DEVICE_MATCH_SCORE 100
     60
     61#define VIRTUAL_DEVICE_NAME "virt"
     62#define VIRTUAL_DEVICE_MATCH_ID "rootvirt"
     63#define VIRTUAL_DEVICE_MATCH_SCORE 100
    5364
    5465static int root_add_device(device_t *dev);
     
    6576};
    6677
     78/** Create the device which represents the root of virtual device tree.
     79 *
     80 * @param parent Parent of the newly created device.
     81 * @return Error code.
     82 */
     83static int add_virtual_root_child(device_t *parent)
     84{
     85        printf(NAME ": adding new child for virtual devices.\n");
     86        printf(NAME ":   device node is `%s' (%d %s)\n", VIRTUAL_DEVICE_NAME,
     87            VIRTUAL_DEVICE_MATCH_SCORE, VIRTUAL_DEVICE_MATCH_ID);
     88
     89        int res = child_device_register_wrapper(parent, VIRTUAL_DEVICE_NAME,
     90            VIRTUAL_DEVICE_MATCH_ID, VIRTUAL_DEVICE_MATCH_SCORE);
     91
     92        return res;
     93}
     94
    6795/** Create the device which represents the root of HW device tree.
    6896 *
     
    72100static int add_platform_child(device_t *parent)
    73101{
     102        char *match_id;
     103        char *platform;
     104        size_t platform_size;
     105        int res;
     106
     107        /* Get platform name from sysinfo. */
     108
     109        platform = sysinfo_get_data("platform", &platform_size);
     110        if (platform == NULL) {
     111                printf(NAME ": Failed to obtain platform name.\n");
     112                return ENOENT;
     113        }
     114
     115        /* Null-terminate string. */
     116        platform = realloc(platform, platform_size + 1);
     117        if (platform == NULL) {
     118                printf(NAME ": Memory allocation failed.\n");
     119                return ENOMEM;
     120        }
     121
     122        platform[platform_size] = '\0';
     123
     124        /* Construct match ID. */
     125
     126        if (asprintf(&match_id, PLATFORM_DEVICE_MATCH_ID_FMT, platform) == -1) {
     127                printf(NAME ": Memory allocation failed.\n");
     128                return ENOMEM;
     129        }
     130
     131        /* Add child. */
     132
    74133        printf(NAME ": adding new child for platform device.\n");
    75        
    76         int res = EOK;
    77         device_t *platform = NULL;
    78         match_id_t *match_id = NULL;
    79        
    80         /* Create new device. */
    81         platform = create_device();
    82         if (NULL == platform) {
    83                 res = ENOMEM;
    84                 goto failure;
    85         }       
    86        
    87         platform->name = "hw";
    88         printf(NAME ": the new device's name is %s.\n", platform->name);
    89        
    90         /* Initialize match id list. */
    91         match_id = create_match_id();
    92         if (NULL == match_id) {
    93                 res = ENOMEM;
    94                 goto failure;
    95         }
    96        
    97         /* TODO - replace this with some better solution (sysinfo ?) */
    98         match_id->id = STRING(UARCH);
    99         match_id->score = 100;
    100         add_match_id(&platform->match_ids, match_id);
    101        
    102         /* Register child device. */
    103         res = child_device_register(platform, parent);
    104         if (EOK != res)
    105                 goto failure;
    106        
    107         return res;
    108        
    109 failure:
    110         if (NULL != match_id)
    111                 match_id->id = NULL;
    112        
    113         if (NULL != platform) {
    114                 platform->name = NULL;
    115                 delete_device(platform);
    116         }
    117        
     134        printf(NAME ":   device node is `%s' (%d %s)\n", PLATFORM_DEVICE_NAME,
     135            PLATFORM_DEVICE_MATCH_SCORE, match_id);
     136
     137        res = child_device_register_wrapper(parent, PLATFORM_DEVICE_NAME,
     138            match_id, PLATFORM_DEVICE_MATCH_SCORE);
     139
    118140        return res;
    119141}
     
    126148static int root_add_device(device_t *dev)
    127149{
    128         printf(NAME ": root_add_device, device handle = %d\n", dev->handle);
     150        printf(NAME ": root_add_device, device handle=%" PRIun "\n",
     151            dev->handle);
    129152       
     153        /*
     154         * Register virtual devices root.
     155         * We ignore error occurrence because virtual devices shall not be
     156         * vital for the system.
     157         */
     158        add_virtual_root_child(dev);
     159
    130160        /* Register root device's children. */
    131161        int res = add_platform_child(dev);
Note: See TracChangeset for help on using the changeset viewer.