Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/root/root.c

    reff1f033 r7e752b2  
    11/*
    22 * Copyright (c) 2010 Lenka Trochtova
    3  * Copyright (c) 2010 Vojtech Horky
    43 * All rights reserved.
    54 *
     
    4746#include <macros.h>
    4847#include <inttypes.h>
    49 #include <sysinfo.h>
    5048
    5149#include <driver.h>
     
    5452
    5553#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
    6454
    6555static int root_add_device(device_t *dev);
     
    7666};
    7767
    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  */
    83 static 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 
    9568/** Create the device which represents the root of HW device tree.
    9669 *
     
    10073static int add_platform_child(device_t *parent)
    10174{
    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;
     75        printf(NAME ": adding new child for platform device.\n");
     76       
     77        int res = EOK;
     78        device_t *platform = NULL;
     79        match_id_t *match_id = NULL;
     80       
     81        /* Create new device. */
     82        platform = create_device();
     83        if (NULL == platform) {
     84                res = ENOMEM;
     85                goto failure;
     86        }       
     87       
     88        platform->name = "hw";
     89        printf(NAME ": the new device's name is %s.\n", platform->name);
     90       
     91        /* Initialize match id list. */
     92        match_id = create_match_id();
     93        if (NULL == match_id) {
     94                res = ENOMEM;
     95                goto failure;
    11396        }
    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;
     97       
     98        /* TODO - replace this with some better solution (sysinfo ?) */
     99        match_id->id = STRING(UARCH);
     100        match_id->score = 100;
     101        add_match_id(&platform->match_ids, match_id);
     102       
     103        /* Register child device. */
     104        res = child_device_register(platform, parent);
     105        if (EOK != res)
     106                goto failure;
     107       
     108        return res;
     109       
     110failure:
     111        if (NULL != match_id)
     112                match_id->id = NULL;
     113       
     114        if (NULL != platform) {
     115                platform->name = NULL;
     116                delete_device(platform);
    120117        }
    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 
    133         printf(NAME ": adding new child for platform device.\n");
    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 
     118       
    140119        return res;
    141120}
     
    151130            dev->handle);
    152131       
    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 
    160132        /* Register root device's children. */
    161133        int res = add_platform_child(dev);
Note: See TracChangeset for help on using the changeset viewer.