Changeset 8b1e15ac in mainline for uspace/drv/isa/isa.c


Ignore:
Timestamp:
2011-02-11T22:26:36Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
68414f4a
Parents:
1b367b4
Message:

Finish splitting device node: devman client in C library, drv library. Update device drivers accordingly.

File:
1 edited

Legend:

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

    r1b367b4 r8b1e15ac  
    5858
    5959#define NAME "isa"
    60 #define CHILD_DEV_CONF_PATH "/drv/isa/isa.dev"
     60#define CHILD_FUN_CONF_PATH "/drv/isa/isa.dev"
    6161
    6262#define ISA_MAX_HW_RES 4
    6363
    64 typedef struct isa_child_data {
     64typedef struct isa_fun_data {
    6565        hw_resource_list_t hw_resources;
    66 } isa_child_data_t;
    67 
    68 static hw_resource_list_t *isa_get_child_resources(device_t *dev)
    69 {
    70         isa_child_data_t *dev_data;
    71 
    72         dev_data = (isa_child_data_t *)dev->driver_data;
    73         if (dev_data == NULL)
     66} isa_fun_data_t;
     67
     68static hw_resource_list_t *isa_get_fun_resources(function_t *fun)
     69{
     70        isa_fun_data_t *fun_data;
     71
     72        fun_data = (isa_fun_data_t *)fun->driver_data;
     73        if (fun_data == NULL)
    7474                return NULL;
    7575
    76         return &dev_data->hw_resources;
    77 }
    78 
    79 static bool isa_enable_child_interrupt(device_t *dev)
     76        return &fun_data->hw_resources;
     77}
     78
     79static bool isa_enable_fun_interrupt(function_t *fun)
    8080{
    8181        // TODO
     
    8484}
    8585
    86 static hw_res_ops_t isa_child_hw_res_ops = {
    87         &isa_get_child_resources,
    88         &isa_enable_child_interrupt
     86static hw_res_ops_t isa_fun_hw_res_ops = {
     87        &isa_get_fun_resources,
     88        &isa_enable_fun_interrupt
    8989};
    9090
    91 static device_ops_t isa_child_dev_ops;
     91static device_ops_t isa_fun_dev_ops;
    9292
    9393static int isa_add_device(device_t *dev);
     
    105105
    106106
    107 static isa_child_data_t *create_isa_child_data()
    108 {
    109         isa_child_data_t *data;
    110 
    111         data = (isa_child_data_t *) malloc(sizeof(isa_child_data_t));
     107static isa_fun_data_t *create_isa_fun_data()
     108{
     109        isa_fun_data_t *data;
     110
     111        data = (isa_fun_data_t *) malloc(sizeof(isa_fun_data_t));
    112112        if (data != NULL)
    113                 memset(data, 0, sizeof(isa_child_data_t));
     113                memset(data, 0, sizeof(isa_fun_data_t));
    114114
    115115        return data;
    116116}
    117117
    118 static device_t *create_isa_child_dev()
    119 {
    120         device_t *dev = create_device();
    121         if (dev == NULL)
     118static function_t *create_isa_fun()
     119{
     120        function_t *fun = create_function();
     121        if (fun == NULL)
    122122                return NULL;
    123123
    124         isa_child_data_t *data = create_isa_child_data();
     124        isa_fun_data_t *data = create_isa_fun_data();
    125125        if (data == NULL) {
    126                 delete_device(dev);
     126                delete_function(fun);
    127127                return NULL;
    128128        }
    129129
    130         dev->driver_data = data;
    131         return dev;
    132 }
    133 
    134 static char *read_dev_conf(const char *conf_path)
     130        fun->driver_data = data;
     131        return fun;
     132}
     133
     134static char *read_fun_conf(const char *conf_path)
    135135{
    136136        bool suc = false;
     
    151151        lseek(fd, 0, SEEK_SET);
    152152        if (len == 0) {
    153                 printf(NAME ": read_dev_conf error: configuration file '%s' "
     153                printf(NAME ": read_fun_conf error: configuration file '%s' "
    154154                    "is empty.\n", conf_path);
    155155                goto cleanup;
     
    158158        buf = malloc(len + 1);
    159159        if (buf == NULL) {
    160                 printf(NAME ": read_dev_conf error: memory allocation failed.\n");
     160                printf(NAME ": read_fun_conf error: memory allocation failed.\n");
    161161                goto cleanup;
    162162        }
    163163
    164164        if (0 >= read(fd, buf, len)) {
    165                 printf(NAME ": read_dev_conf error: unable to read file '%s'.\n",
     165                printf(NAME ": read_fun_conf error: unable to read file '%s'.\n",
    166166                    conf_path);
    167167                goto cleanup;
     
    249249}
    250250
    251 static void isa_child_set_irq(device_t *dev, int irq)
    252 {
    253         isa_child_data_t *data = (isa_child_data_t *)dev->driver_data;
     251static void isa_fun_set_irq(function_t *fun, int irq)
     252{
     253        isa_fun_data_t *data = (isa_fun_data_t *)fun->driver_data;
    254254
    255255        size_t count = data->hw_resources.count;
     
    262262                data->hw_resources.count++;
    263263
    264                 printf(NAME ": added irq 0x%x to device %s\n", irq, dev->name);
    265         }
    266 }
    267 
    268 static void isa_child_set_io_range(device_t *dev, size_t addr, size_t len)
    269 {
    270         isa_child_data_t *data = (isa_child_data_t *)dev->driver_data;
     264                printf(NAME ": added irq 0x%x to function %s\n", irq, fun->name);
     265        }
     266}
     267
     268static void isa_fun_set_io_range(function_t *fun, size_t addr, size_t len)
     269{
     270        isa_fun_data_t *data = (isa_fun_data_t *)fun->driver_data;
    271271
    272272        size_t count = data->hw_resources.count;
     
    282282
    283283                printf(NAME ": added io range (addr=0x%x, size=0x%x) to "
    284                     "device %s\n", (unsigned int) addr, (unsigned int) len,
    285                     dev->name);
    286         }
    287 }
    288 
    289 static void get_dev_irq(device_t *dev, char *val)
     284                    "function %s\n", (unsigned int) addr, (unsigned int) len,
     285                    fun->name);
     286        }
     287}
     288
     289static void get_dev_irq(function_t *fun, char *val)
    290290{
    291291        int irq = 0;
    292292        char *end = NULL;
    293293
    294         val = skip_spaces(val); 
     294        val = skip_spaces(val);
    295295        irq = (int)strtol(val, &end, 0x10);
    296296
    297297        if (val != end)
    298                 isa_child_set_irq(dev, irq);
    299 }
    300 
    301 static void get_dev_io_range(device_t *dev, char *val)
     298                isa_fun_set_irq(fun, irq);
     299}
     300
     301static void get_dev_io_range(function_t *fun, char *val)
    302302{
    303303        size_t addr, len;
    304304        char *end = NULL;
    305305
    306         val = skip_spaces(val); 
     306        val = skip_spaces(val);
    307307        addr = strtol(val, &end, 0x10);
    308308
     
    310310                return;
    311311
    312         val = skip_spaces(end); 
     312        val = skip_spaces(end);
    313313        len = strtol(val, &end, 0x10);
    314314
     
    316316                return;
    317317
    318         isa_child_set_io_range(dev, addr, len);
     318        isa_fun_set_io_range(fun, addr, len);
    319319}
    320320
     
    331331}
    332332
    333 static void get_dev_match_id(device_t *dev, char *val)
     333static void get_fun_match_id(function_t *fun, char *val)
    334334{
    335335        char *id = NULL;
     
    342342        if (val == end) {
    343343                printf(NAME " : error - could not read match score for "
    344                     "device %s.\n", dev->name);
     344                    "function %s.\n", fun->name);
    345345                return;
    346346        }
     
    348348        match_id_t *match_id = create_match_id();
    349349        if (match_id == NULL) {
    350                 printf(NAME " : failed to allocate match id for device %s.\n",
    351                     dev->name);
     350                printf(NAME " : failed to allocate match id for function %s.\n",
     351                    fun->name);
    352352                return;
    353353        }
     
    357357        if (id == NULL) {
    358358                printf(NAME " : error - could not read match id for "
    359                     "device %s.\n", dev->name);
     359                    "function %s.\n", fun->name);
    360360                delete_match_id(match_id);
    361361                return;
     
    365365        match_id->score = score;
    366366
    367         printf(NAME ": adding match id '%s' with score %d to device %s\n", id,
    368             score, dev->name);
    369         add_match_id(&dev->match_ids, match_id);
    370 }
    371 
    372 static bool read_dev_prop(device_t *dev, char *line, const char *prop,
    373     void (*read_fn)(device_t *, char *))
     367        printf(NAME ": adding match id '%s' with score %d to function %s\n", id,
     368            score, fun->name);
     369        add_match_id(&fun->match_ids, match_id);
     370}
     371
     372static bool read_fun_prop(function_t *fun, char *line, const char *prop,
     373    void (*read_fn)(function_t *, char *))
    374374{
    375375        size_t proplen = str_size(prop);
     
    378378                line += proplen;
    379379                line = skip_spaces(line);
    380                 (*read_fn)(dev, line);
     380                (*read_fn)(fun, line);
    381381
    382382                return true;
     
    386386}
    387387
    388 static void get_dev_prop(device_t *dev, char *line)
     388static void get_fun_prop(function_t *fun, char *line)
    389389{
    390390        /* Skip leading spaces. */
    391391        line = skip_spaces(line);
    392392
    393         if (!read_dev_prop(dev, line, "io_range", &get_dev_io_range) &&
    394             !read_dev_prop(dev, line, "irq", &get_dev_irq) &&
    395             !read_dev_prop(dev, line, "match", &get_dev_match_id))
     393        if (!read_fun_prop(fun, line, "io_range", &get_dev_io_range) &&
     394            !read_fun_prop(fun, line, "irq", &get_dev_irq) &&
     395            !read_fun_prop(fun, line, "match", &get_fun_match_id))
    396396        {
    397397            printf(NAME " error undefined device property at line '%s'\n",
     
    400400}
    401401
    402 static void child_alloc_hw_res(device_t *dev)
    403 {
    404         isa_child_data_t *data = (isa_child_data_t *)dev->driver_data;
     402static void child_alloc_hw_res(function_t *fun)
     403{
     404        isa_fun_data_t *data = (isa_fun_data_t *)fun->driver_data;
    405405        data->hw_resources.resources =
    406406            (hw_resource_t *)malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES);
    407407}
    408408
    409 static char *read_isa_dev_info(char *dev_conf, device_t *parent)
     409static char *read_isa_fun_info(char *fun_conf, device_t *dev)
    410410{
    411411        char *line;
    412         char *dev_name = NULL;
     412        char *fun_name = NULL;
    413413
    414414        /* Skip empty lines. */
    415415        while (true) {
    416                 line = str_get_line(dev_conf, &dev_conf);
     416                line = str_get_line(fun_conf, &fun_conf);
    417417
    418418                if (line == NULL) {
     
    426426
    427427        /* Get device name. */
    428         dev_name = get_device_name(line);
    429         if (dev_name == NULL)
     428        fun_name = get_device_name(line);
     429        if (fun_name == NULL)
    430430                return NULL;
    431431
    432         device_t *dev = create_isa_child_dev();
    433         if (dev == NULL) {
    434                 free(dev_name);
     432        function_t *fun = create_isa_fun();
     433        if (fun == NULL) {
     434                free(fun_name);
    435435                return NULL;
    436436        }
    437437
    438         dev->name = dev_name;
     438        fun->name = fun_name;
     439        fun->ftype = fun_inner;
    439440
    440441        /* Allocate buffer for the list of hardware resources of the device. */
    441         child_alloc_hw_res(dev);
     442        child_alloc_hw_res(fun);
    442443
    443444        /* Get properties of the device (match ids, irq and io range). */
    444445        while (true) {
    445                 line = str_get_line(dev_conf, &dev_conf);
     446                line = str_get_line(fun_conf, &fun_conf);
    446447
    447448                if (line_empty(line)) {
     
    454455                 * and store it in the device structure.
    455456                 */
    456                 get_dev_prop(dev, line);
    457 
    458                 //printf(NAME ": next line ='%s'\n", dev_conf);
     457                get_fun_prop(fun, line);
     458
     459                //printf(NAME ": next line ='%s'\n", fun_conf);
    459460                //printf(NAME ": current line ='%s'\n", line);
    460461        }
    461462
    462463        /* Set device operations to the device. */
    463         dev->ops = &isa_child_dev_ops;
    464 
    465         printf(NAME ": child_device_register(dev, parent); device is %s.\n",
    466             dev->name);
    467         child_device_register(dev, parent);
    468 
    469         return dev_conf;
    470 }
    471 
    472 static void parse_dev_conf(char *conf, device_t *parent)
     464        fun->ops = &isa_fun_dev_ops;
     465
     466        printf(NAME ": register_function(fun, dev); function is %s.\n",
     467            fun->name);
     468        register_function(fun, dev);
     469
     470        return fun_conf;
     471}
     472
     473static void parse_fun_conf(char *conf, device_t *dev)
    473474{
    474475        while (conf != NULL && *conf != '\0') {
    475                 conf = read_isa_dev_info(conf, parent);
    476         }
    477 }
    478 
    479 static void add_legacy_children(device_t *parent)
    480 {
    481         char *dev_conf;
    482 
    483         dev_conf = read_dev_conf(CHILD_DEV_CONF_PATH);
    484         if (dev_conf != NULL) {
    485                 parse_dev_conf(dev_conf, parent);
    486                 free(dev_conf);
     476                conf = read_isa_fun_info(conf, dev);
     477        }
     478}
     479
     480static void add_legacy_children(device_t *dev)
     481{
     482        char *fun_conf;
     483
     484        fun_conf = read_fun_conf(CHILD_FUN_CONF_PATH);
     485        if (fun_conf != NULL) {
     486                parse_fun_conf(fun_conf, dev);
     487                free(fun_conf);
    487488        }
    488489}
     
    492493        printf(NAME ": isa_add_device, device handle = %d\n",
    493494            (int) dev->handle);
     495
     496        /* Make the bus device more visible. Does not do anything. */
     497        printf(NAME ": adding a 'ctl' function\n");
     498
     499        function_t *ctl = create_function();
     500        ctl->ftype = fun_exposed;
     501        ctl->name = "ctl";
     502        register_function(ctl, dev);
    494503
    495504        /* Add child devices. */
     
    502511static void isa_init()
    503512{
    504         isa_child_dev_ops.interfaces[HW_RES_DEV_IFACE] = &isa_child_hw_res_ops;
     513        isa_fun_dev_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops;
    505514}
    506515
Note: See TracChangeset for help on using the changeset viewer.