Changeset bda60d9 in mainline for uspace/lib/libc/include/ipc/devman.h


Ignore:
Timestamp:
2010-03-19T14:40:14Z (14 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 {
Note: See TracChangeset for help on using the changeset viewer.