Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/driver.c

    r7e752b2 r0ca16307  
    4848#include <ctype.h>
    4949#include <errno.h>
    50 #include <inttypes.h>
    5150
    5251#include <ipc/driver.h>
     
    165164       
    166165        devman_handle_t dev_handle =  IPC_GET_ARG1(*icall);
     166        devman_handle_t parent_dev_handle = IPC_GET_ARG2(*icall);
     167   
    167168        device_t *dev = create_device();
    168169        dev->handle = dev_handle;
     
    172173       
    173174        add_to_devices_list(dev);
     175        dev->parent = driver_get_device(&devices, parent_dev_handle);
     176       
    174177        res = driver->driver_ops->add_device(dev);
    175178        if (0 == res) {
    176                 printf("%s: new device with handle=%" PRIun " was added.\n",
     179                printf("%s: new device with handle = %x was added.\n",
    177180                    driver->name, dev_handle);
    178181        } else {
    179                 printf("%s: failed to add a new device with handle = %" PRIun ".\n",
     182                printf("%s: failed to add a new device with handle = %d.\n",
    180183                    driver->name, dev_handle);
    181184                remove_from_devices_list(dev);
     
    204207                        break;
    205208                default:
    206                         ipc_answer_0(callid, ENOENT);
     209                        if (!(callid & IPC_CALLID_NOTIFICATION))
     210                                ipc_answer_0(callid, ENOENT);
    207211                }
    208212        }
     
    226230        if (dev == NULL) {
    227231                printf("%s: driver_connection_gen error - no device with handle"
    228                     " %" PRIun " was found.\n", driver->name, handle);
     232                    " %x was found.\n", driver->name, handle);
    229233                ipc_answer_0(iid, ENOENT);
    230234                return;
     
    290294                                printf("%s: driver_connection_gen error - ",
    291295                                    driver->name);
    292                                 printf("device with handle %" PRIun " has no interface "
     296                                printf("device with handle %d has no interface "
    293297                                    "with id %d.\n", handle, iface_idx);
    294298                                ipc_answer_0(callid, ENOTSUP);
     
    377381}
    378382
     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
    379437int driver_main(driver_t *drv)
    380438{
Note: See TracChangeset for help on using the changeset viewer.