Changeset eff1f033 in mainline for uspace/drv/root/root.c


Ignore:
Timestamp:
2010-12-21T22:23:03Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5f0123b
Parents:
78ffb70
Message:

Match platform driver based on platform name instead of architecture name. Obtain platform name from kernel via sysinfo.

File:
1 edited

Legend:

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

    r78ffb70 reff1f033  
    4747#include <macros.h>
    4848#include <inttypes.h>
     49#include <sysinfo.h>
    4950
    5051#include <driver.h>
     
    5556
    5657#define PLATFORM_DEVICE_NAME "hw"
    57 #define PLATFORM_DEVICE_MATCH_ID STRING(UARCH)
     58#define PLATFORM_DEVICE_MATCH_ID_FMT "platform/%s"
    5859#define PLATFORM_DEVICE_MATCH_SCORE 100
    5960
     
    99100static int add_platform_child(device_t *parent)
    100101{
     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
    101133        printf(NAME ": adding new child for platform device.\n");
    102134        printf(NAME ":   device node is `%s' (%d %s)\n", PLATFORM_DEVICE_NAME,
    103             PLATFORM_DEVICE_MATCH_SCORE, PLATFORM_DEVICE_MATCH_ID);
    104        
    105         int res = child_device_register_wrapper(parent, PLATFORM_DEVICE_NAME,
    106             PLATFORM_DEVICE_MATCH_ID, PLATFORM_DEVICE_MATCH_SCORE);
     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);
    107139
    108140        return res;
Note: See TracChangeset for help on using the changeset viewer.