Changeset bda60d9 in mainline for uspace/lib


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

adding child device - parts of code

Location:
uspace/lib
Files:
5 edited

Legend:

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

    r7707954 rbda60d9  
    106106}
    107107
    108 int devman_child_device_register(const char *name, long parent_handle, long *handle)
     108int devman_child_device_register(
     109        const char *name, match_id_list_t *match_ids, device_handle_t parent_handle, device_handle_t *handle)
    109110{       
    110111        int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING);
     
    124125                return retval;
    125126        }
     127       
     128        // TODO match ids
    126129       
    127130        async_wait_for(req, &retval);
  • uspace/lib/libc/include/devman.h

    r7707954 rbda60d9  
    4646
    4747int devman_driver_register(const char *, async_client_conn_t);
    48 int devman_child_device_register(const char *name, long parent_handle, long *handle);
     48int devman_child_device_register(const char *, match_id_list_t *, device_handle_t, device_handle_t *);
    4949
    5050
  • uspace/lib/libc/include/ipc/devman.h

    r7707954 rbda60d9  
    3434#define LIBC_IPC_DEVMAN_H_
    3535
     36#include <adt/list.h>
    3637#include <ipc/ipc.h>
     38#include <stdlib.h>
     39#include <string.h>
    3740
    3841#define DEVMAN_NAME_MAXLEN 256
     42
     43typedef ipcarg_t device_handle_t;
     44
     45/** Ids of device models used for device-to-driver matching.
     46 */
     47typedef struct match_id {
     48        /** Pointers to next and previous ids.
     49         */
     50        link_t link;
     51        /** Id of device model.
     52         */
     53        const char *id;
     54        /** Relevancy of device-to-driver match.
     55         * The higher is the product of scores specified for the device by the bus driver and by the leaf driver,
     56         * the more suitable is the leaf driver for handling the device.
     57         */
     58        unsigned int score;
     59} match_id_t;
     60
     61/** List of ids for matching devices to drivers sorted
     62 * according to match scores in descending order.
     63 */
     64typedef struct match_id_list {
     65        link_t ids;
     66} match_id_list_t;
     67
     68
     69static inline match_id_t * create_match_id()
     70{
     71        match_id_t *id = malloc(sizeof(match_id_t));
     72        memset(id, 0, sizeof(match_id_t));
     73        return id;
     74}
     75
     76static inline void delete_match_id(match_id_t *id)
     77{
     78        if (id) {
     79                if (NULL != id->id) {
     80                        free(id->id);
     81                }
     82                free(id);
     83        }
     84}
     85
     86static inline void add_match_id(match_id_list_t *ids, match_id_t *id)
     87{
     88        match_id_t *mid = NULL;
     89        link_t *link = ids->ids.next;   
     90       
     91        while (link != &ids->ids) {
     92                mid = list_get_instance(link, match_id_t,link);
     93                if (mid->score < id->score) {
     94                        break;
     95                }       
     96                link = link->next;
     97        }
     98       
     99        list_insert_before(&id->link, link);   
     100}
     101
     102static inline void clean_match_ids(match_id_list_t *ids)
     103{
     104        link_t *link = NULL;
     105        match_id_t *id;
     106       
     107        while(!list_empty(&ids->ids)) {
     108                link = ids->ids.next;
     109                list_remove(link);             
     110                id = list_get_instance(link, match_id_t, link);
     111                delete_match_id(id);           
     112        }       
     113}
    39114
    40115typedef enum {
  • uspace/lib/libdrv/generic/driver.c

    r7707954 rbda60d9  
    7272        // result of the operation - device was added, device is not present etc.
    7373        ipcarg_t ret = 0;       
    74         ipcarg_t dev_handle =  IPC_GET_ARG1(*icall);
     74        device_handle_t dev_handle =  IPC_GET_ARG1(*icall);
    7575       
    7676        printf("%s: adding device with handle = %x \n", driver->name, dev_handle);
     
    109109                                ipc_answer_0(callid, ENOENT);
    110110                }
    111         }
    112        
     111        }       
    113112}
    114113
     
    150149}
    151150
    152 bool child_device_register(device_t *child, const char *child_name, device_t *parent)
     151bool child_device_register(device_t *child, device_t *parent)
    153152{
    154         if (devman_child_device_register(child_name, parent->handle, &child->handle)) {
     153        printf("%s: child_device_register\n", driver->name);
     154       
     155        assert(NULL != child->name);
     156       
     157        if (devman_child_device_register(child->name, &child->match_ids, parent->handle, &child->handle)) {
    155158                // TODO initialize child device
    156159                return true;
  • uspace/lib/libdrv/include/driver.h

    r7707954 rbda60d9  
    3737
    3838#include <adt/list.h>
     39#include <ipc/devman.h>
    3940
    4041typedef struct device {
    41         long handle;
     42        device_handle_t handle;
    4243        ipcarg_t parent_phone; 
     44        const char *name;
     45        match_id_list_t match_ids;
    4346       
    4447        // TODO add more items - parent bus type etc.
     
    6467        if (NULL != dev) {
    6568                memset(dev, 0, sizeof(device_t));
    66         }
    67        
     69        }       
     70        list_initialize(&dev->match_ids.ids);
    6871        return dev;
    6972}
    7073
    71 bool child_device_register(device_t *child, const char *child_name, device_t *parent);
     74static inline delete_device(device_t *dev) {
     75        clean_match_ids(&dev->match_ids);
     76        if (NULL != dev->name) {
     77                free(dev->name);
     78        }
     79        free(dev);
     80}
    7281
     82bool child_device_register(device_t *child, device_t *parent);
    7383
    7484
Note: See TracChangeset for help on using the changeset viewer.