Changeset 66babbd in mainline


Ignore:
Timestamp:
2010-03-25T09:55:09Z (14 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a087f2e
Parents:
d347b53
Message:

child device registration - match ids

Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/devman.c

    rd347b53 r66babbd  
    3939#include <malloc.h>
    4040#include <bool.h>
     41#include <adt/list.h>
    4142
    4243static int devman_phone_driver = -1;
     
    106107}
    107108
     109static int devman_send_match_id(int phone, match_id_t *match_id) \
     110{
     111        ipc_call_t answer;
     112        async_send_1(phone, DEVMAN_ADD_MATCH_ID, match_id->score, &answer);
     113        int retval = async_data_write_start(phone, match_id->id, str_size(match_id->id));
     114        return retval; 
     115}
     116
     117
     118static int devman_send_match_ids(int phone, match_id_list_t *match_ids)
     119{
     120        link_t *link = match_ids->ids.next;
     121        match_id_t *match_id = NULL;
     122        int ret = EOK;
     123       
     124        while (link != &match_ids->ids) {
     125                match_id = list_get_instance(link, match_id_t, link);
     126                if (EOK != (ret = devman_send_match_id(phone, match_id)))
     127                {
     128                        printf("Driver failed to send match id, error number = %d\n", ret);
     129                        return ret;                     
     130                }
     131                link = link->next;
     132        }
     133        return ret;     
     134}
     135
    108136int devman_child_device_register(
    109137        const char *name, match_id_list_t *match_ids, device_handle_t parent_handle, device_handle_t *handle)
     
    116144        async_serialize_start();
    117145       
     146        int match_count = list_count(&match_ids->ids); 
    118147        ipc_call_t answer;
    119         aid_t req = async_send_1(phone, DEVMAN_ADD_CHILD_DEVICE, parent_handle, &answer);
     148        aid_t req = async_send_2(phone, DEVMAN_ADD_CHILD_DEVICE, parent_handle, match_count, &answer);
    120149
    121150        ipcarg_t retval = async_data_write_start(phone, name, str_size(name));
     
    126155        }
    127156       
    128         // TODO match ids
     157        devman_send_match_ids(phone, match_ids);
    129158       
    130159        async_wait_for(req, &retval);
     
    141170        if (handle != NULL)
    142171                *handle = (int) IPC_GET_ARG1(answer);   
     172               
     173        return retval;
    143174}
    144175
  • uspace/lib/libc/include/ipc/devman.h

    rd347b53 r66babbd  
    5151        /** Id of device model.
    5252         */
    53         const char *id;
     53        char *id;
    5454        /** Relevancy of device-to-driver match.
    5555         * The higher is the product of scores specified for the device by the bus driver and by the leaf driver,
     
    121121typedef enum {
    122122        DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
    123         DEVMAN_ADD_CHILD_DEVICE
     123        DEVMAN_ADD_CHILD_DEVICE,
     124        DEVMAN_ADD_MATCH_ID
    124125
    125126} driver_to_devman_t;
  • uspace/lib/libdrv/generic/driver.c

    rd347b53 r66babbd  
    4747#include <string.h>
    4848#include <ctype.h>
     49#include <errno.h>
    4950
    5051#include <devman.h>
     
    153154        assert(NULL != child->name);
    154155       
    155         if (devman_child_device_register(child->name, &child->match_ids, parent->handle, &child->handle)) {
    156                 // TODO initialize child device
     156        if (EOK == devman_child_device_register(child->name, &child->match_ids, parent->handle, &child->handle)) {
    157157                return true;
    158158        }
  • uspace/srv/devman/main.c

    rd347b53 r66babbd  
    120120}
    121121
     122static int devman_receive_match_id(match_id_list_t *match_ids) {
     123       
     124        match_id_t *match_id = create_match_id();
     125        ipc_callid_t callid;
     126        ipc_call_t call;
     127        int rc = 0;
     128       
     129        callid = async_get_call(&call);
     130        if (DEVMAN_ADD_MATCH_ID != IPC_GET_METHOD(call)) {
     131                printf(NAME ": ERROR: devman_receive_match_id - invalid protocol.\n");
     132                ipc_answer_0(callid, EINVAL);
     133                delete_match_id(match_id);
     134                return EINVAL;
     135        }
     136       
     137        if (NULL == match_id) {
     138                printf(NAME ": ERROR: devman_receive_match_id - failed to allocate match id.\n");
     139                ipc_answer_0(callid, ENOMEM);
     140                return ENOMEM;
     141        }
     142       
     143        match_id->score = IPC_GET_ARG1(call);
     144       
     145        rc = async_string_receive(&match_id->id, DEVMAN_NAME_MAXLEN, NULL);     
     146        if (EOK != rc) {
     147                delete_match_id(match_id);
     148                return rc;
     149        }
     150       
     151        list_append(&match_id->link, &match_ids->ids);
     152        return rc;
     153}
     154
     155static int devman_receive_match_ids(ipcarg_t match_count, match_id_list_t *match_ids)
     156{
     157        int ret = EOK;
     158        int i;
     159        for (i = 0; i < match_count; i++) {
     160                if (EOK != (ret = devman_receive_match_id(match_ids))) {
     161                        return ret;
     162                }
     163        }
     164        return ret;
     165}
     166
    122167static void devman_add_child(ipc_callid_t callid, ipc_call_t *call, driver_t *driver)
    123168{
    124169        printf(NAME ": devman_add_child\n");
    125 
     170       
    126171        device_handle_t parent_handle = IPC_GET_ARG1(*call);
     172        ipcarg_t match_count = IPC_GET_ARG2(*call);
     173       
    127174        node_t *parent =  find_dev_node(&device_tree, parent_handle);
    128175       
     
    130177                ipc_answer_0(callid, ENOENT);
    131178                return;
    132         }
     179        }       
    133180       
    134181        char *dev_name = NULL;
    135182        int rc = async_string_receive(&dev_name, DEVMAN_NAME_MAXLEN, NULL);     
    136         if (rc != EOK) {
     183        if (EOK != rc) {
    137184                ipc_answer_0(callid, rc);
    138185                return;
     
    147194        }       
    148195       
    149         // TODO match ids
     196        devman_receive_match_ids(match_count, &node->match_ids);
    150197       
    151198        // return device handle to parent's driver
  • uspace/srv/drivers/root/root.c

    rd347b53 r66babbd  
    5555static bool root_init();
    5656
     57/** The root device driver's standard operations.
     58 */
    5759static driver_ops_t root_ops = {
    5860        .add_device = &root_add_device
    5961};
    6062
     63/** The root device driver structure.
     64 */
    6165static driver_t root_driver = {
    6266        .name = NAME,
     
    6468};
    6569
     70/** Create the device which represents the root of HW device tree.
     71 * @param parent parent of the newly created device.
     72 */
    6673static bool add_platform_child(device_t *parent) {
    6774        printf(NAME ": adding new child for platform device.\n");
     
    107114}
    108115
     116/** Get the root device.
     117 * @param dev the device which is root of the whole device tree (both of HW and pseudo devices).
     118 */
    109119static bool root_add_device(device_t *dev)
    110120{
Note: See TracChangeset for help on using the changeset viewer.