Changeset 0ca16307 in mainline


Ignore:
Timestamp:
2010-11-29T23:52:22Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6f9e7fea
Parents:
0d6915f
Message:

Add wrapper for adding child device with single match id

The mentioned wrapper neatly wraps calls for creating new device, new match
id and registering such device at devman.

This call is now used in root driver.

Location:
uspace
Files:
3 edited

Legend:

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

    r0d6915f r0ca16307  
    11/*
    22 * Copyright (c) 2010 Lenka Trochtova
     3 * Copyright (c) 2010 Vojtech Horky
    34 * All rights reserved.
    45 *
     
    5253#define NAME "root"
    5354
     55#define PLATFORM_DEVICE_NAME "hw"
     56#define PLATFORM_DEVICE_MATCH_ID STRING(UARCH)
     57#define PLATFORM_DEVICE_MATCH_SCORE 100
     58
    5459static int root_add_device(device_t *dev);
    5560
     
    7378{
    7479        printf(NAME ": adding new child for platform device.\n");
     80        printf(NAME ":   device node is `%s' (%d %s)\n", PLATFORM_DEVICE_NAME,
     81            PLATFORM_DEVICE_MATCH_SCORE, PLATFORM_DEVICE_MATCH_ID);
    7582       
    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        
     83        int res = child_device_register_wrapper(parent, PLATFORM_DEVICE_NAME,
     84            PLATFORM_DEVICE_MATCH_ID, PLATFORM_DEVICE_MATCH_SCORE);
     85
    11886        return res;
    11987}
  • uspace/lib/drv/generic/driver.c

    r0d6915f r0ca16307  
    381381}
    382382
     383/** Wrapper for child_device_register for devices with single match id.
     384 *
     385 * @param parent Parent device.
     386 * @param child_name Child device name.
     387 * @param child_match_id Child device match id.
     388 * @param child_match_score Child device match score.
     389 * @return Error code.
     390 */
     391int child_device_register_wrapper(device_t *parent, const char *child_name,
     392    const char *child_match_id, int child_match_score)
     393{
     394        device_t *child = NULL;
     395        match_id_t *match_id = NULL;
     396        int rc;
     397
     398        child = create_device();
     399        if (child == NULL) {
     400                rc = ENOMEM;
     401                goto failure;
     402        }
     403
     404        child->name = child_name;
     405
     406        match_id = create_match_id();
     407        if (match_id == NULL) {
     408                rc = ENOMEM;
     409                goto failure;
     410        }
     411
     412        match_id->id = child_match_id;
     413        match_id->score = child_match_score;
     414        add_match_id(&child->match_ids, match_id);
     415
     416        rc = child_device_register(child, parent);
     417        if (EOK != rc)
     418                goto failure;
     419
     420        goto leave;
     421
     422failure:
     423        if (match_id != NULL) {
     424                match_id->id = NULL;
     425                delete_match_id(match_id);
     426        }
     427
     428        if (child != NULL) {
     429                child->name = NULL;
     430                delete_device(child);
     431        }
     432
     433leave:
     434        return rc;
     435}
     436
    383437int driver_main(driver_t *drv)
    384438{
  • uspace/lib/drv/include/driver.h

    r0d6915f r0ca16307  
    199199
    200200int child_device_register(device_t *, device_t *);
     201int child_device_register_wrapper(device_t *, const char *, const char *, int);
    201202
    202203
Note: See TracChangeset for help on using the changeset viewer.