Changeset 68414f4a in mainline for uspace/drv/rootpc/rootpc.c


Ignore:
Timestamp:
2011-02-13T20:03:45Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bab6388
Parents:
8b1e15ac
Message:

Refactor drivers

  • Rename soft-state structures to have the simplest names
  • Use soft-state structures as a starting point instead of DDF device or function nodes
  • Convert to standard naming scheme
File:
1 edited

Legend:

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

    r8b1e15ac r68414f4a  
    5555#define NAME "rootpc"
    5656
    57 typedef struct rootpc_fun_data {
     57/** Obtain function soft-state from DDF function node */
     58#define ROOTPC_FUN(fnode) ((rootpc_fun_t *) (fnode)->driver_data)
     59
     60typedef struct rootpc_fun {
    5861        hw_resource_list_t hw_resources;
    59 } rootpc_fun_data_t;
     62} rootpc_fun_t;
    6063
    6164static int rootpc_add_device(device_t *dev);
     
    8285};
    8386
    84 static rootpc_fun_data_t pci_data = {
     87static rootpc_fun_t pci_data = {
    8588        .hw_resources = {
    8689                1,
     
    8992};
    9093
    91 static hw_resource_list_t *rootpc_get_fun_resources(function_t *fun)
    92 {
    93         rootpc_fun_data_t *data;
    94        
    95         data = (rootpc_fun_data_t *) fun->driver_data;
    96         if (NULL == data)
    97                 return NULL;
    98        
    99         return &data->hw_resources;
    100 }
    101 
    102 static bool rootpc_enable_fun_interrupt(function_t *fun)
     94static hw_resource_list_t *rootpc_get_resources(function_t *fnode)
     95{
     96        rootpc_fun_t *fun = ROOTPC_FUN(fnode);
     97       
     98        assert(fun != NULL);
     99        return &fun->hw_resources;
     100}
     101
     102static bool rootpc_enable_interrupt(function_t *fun)
    103103{
    104104        /* TODO */
     
    108108
    109109static hw_res_ops_t fun_hw_res_ops = {
    110         &rootpc_get_fun_resources,
    111         &rootpc_enable_fun_interrupt
     110        &rootpc_get_resources,
     111        &rootpc_enable_interrupt
    112112};
    113113
     
    116116
    117117static bool
    118 rootpc_add_fun(device_t *parent, const char *name, const char *str_match_id,
    119     rootpc_fun_data_t *drv_data)
     118rootpc_add_fun(device_t *dev, const char *name, const char *str_match_id,
     119    rootpc_fun_t *fun)
    120120{
    121121        printf(NAME ": adding new function '%s'.\n", name);
    122122       
    123         function_t *fun = NULL;
     123        function_t *fnode = NULL;
    124124        match_id_t *match_id = NULL;
    125125       
    126126        /* Create new device. */
    127         fun = create_function();
    128         if (fun == NULL)
     127        fnode = create_function();
     128        if (fnode == NULL)
    129129                goto failure;
    130130       
    131         fun->name = name;
    132         fun->driver_data = drv_data;
    133         fun->ftype = fun_inner;
     131        fnode->name = name;
     132        fnode->driver_data = fun;
     133        fnode->ftype = fun_inner;
    134134       
    135135        /* Initialize match id list */
    136136        match_id = create_match_id();
    137         if (NULL == match_id)
     137        if (match_id == NULL)
    138138                goto failure;
    139139       
    140140        match_id->id = str_match_id;
    141141        match_id->score = 100;
    142         add_match_id(&fun->match_ids, match_id);
     142        add_match_id(&fnode->match_ids, match_id);
    143143       
    144144        /* Set provided operations to the device. */
    145         fun->ops = &rootpc_fun_ops;
     145        fnode->ops = &rootpc_fun_ops;
    146146       
    147147        /* Register function. */
    148         if (EOK != register_function(fun, parent))
     148        if (register_function(fnode, dev) != EOK)
    149149                goto failure;
    150         printf(NAME ": registered function handle = %u\n", fun->handle);
     150        printf(NAME ": registered function handle = %u\n", fnode->handle);
    151151       
    152152        return true;
    153153       
    154154failure:
    155         if (NULL != match_id)
     155        if (match_id != NULL)
    156156                match_id->id = NULL;
    157157       
    158         if (NULL != fun) {
    159                 fun->name = NULL;
    160                 delete_function(fun);
     158        if (fnode != NULL) {
     159                fnode->name = NULL;
     160                delete_function(fnode);
    161161        }
    162162       
Note: See TracChangeset for help on using the changeset viewer.