Changeset 5dc9622 in mainline


Ignore:
Timestamp:
2010-04-18T19:44:17Z (14 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5fe1c32
Parents:
c1a8ae52
Message:

finished pseudo enumeration of ISA legacy devices (the ISA bus driver enumerates legacy devices specified in a configuration file)

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/amd64/Makefile.inc

    rc1a8ae52 r5dc9622  
    4242        isa
    4343
     44RD_DRV_CONF = \
     45        isa/isa.dev
     46
    4447MODULES := $(notdir $(COMPONENTS))
    4548
     
    7578                cp $(USPACEDIR)/srv/drivers/$$driver/$$driver $(USPACEDIR)/dist/srv/drivers/$$driver/ ; \
    7679        done
     80        for drv_conf in $(RD_DRV_CONF); do \
     81                cp $(USPACEDIR)/srv/drivers/$$drv_conf $(USPACEDIR)/dist/srv/drivers/$$drv_conf ; \
     82        done
    7783        for file in $(RD_APPS) ; do \
    7884                cp $$file $(USPACEDIR)/dist/app/ ; \
     
    9399                rm -f $(USPACEDIR)/dist/srv/`basename $$file` ; \
    94100        done
     101        for drv_conf in $(RD_DRV_CONF) ; do \
     102                rm -r $(USPACEDIR)/dist/srv/drivers/$$drv_conf ; \
     103        done
    95104        for driver in $(RD_DRVS) ; do \
    96105                rm -r $(USPACEDIR)/dist/srv/drivers/$$driver ; \
  • uspace/lib/libc/include/device/hw_res.h

    rc1a8ae52 r5dc9622  
    3939#include <bool.h>
    4040
     41// HW resource provider interface
     42
     43typedef enum {
     44        GET_RESOURCE_LIST = 0,
     45        ENABLE_INTERRUPT       
     46} hw_res_funcs_t;
     47
     48/** HW resource types. */
     49typedef enum {
     50        INTERRUPT,
     51        IO_RANGE,
     52        MEM_RANGE
     53} hw_res_type_t;
     54
     55typedef enum {
     56        LITTLE_ENDIAN = 0,
     57        BIG_ENDIAN
     58} endianness_t;
     59
     60
    4161/** HW resource (e.g. interrupt, memory register, i/o register etc.). */
    4262typedef struct hw_resource {
     
    7494
    7595
     96
    7697bool get_hw_resources(int dev_phone, hw_resource_list_t *hw_resources);
    7798
  • uspace/lib/libc/include/ipc/dev_iface.h

    rc1a8ae52 r5dc9622  
    4747
    4848
    49 
    50 // HW resource provider interface
    51 
    52 typedef enum {
    53         GET_RESOURCE_LIST = 0,
    54         ENABLE_INTERRUPT       
    55 } hw_res_funcs_t;
    56 
    57 /** HW resource types. */
    58 typedef enum {
    59         INTERRUPT,
    60         IO_RANGE,
    61         MEM_RANGE
    62 } hw_res_type_t;
    63 
    64 typedef enum {
    65         LITTLE_ENDIAN = 0,
    66         BIG_ENDIAN
    67 } endianness_t;
    68 
    6949#endif
  • uspace/srv/drivers/isa/isa.c

    rc1a8ae52 r5dc9622  
    5151
    5252#include <driver.h>
     53#include <resource.h>
     54
    5355#include <devman.h>
    5456#include <ipc/devman.h>
     57#include <device/hw_res.h>
    5558
    5659#define NAME "isa"
    5760#define CHILD_DEV_CONF_PATH "/srv/drivers/isa/isa.dev"
     61
     62#define ISA_MAX_HW_RES 4
     63
     64typedef struct isa_child_data {
     65        hw_resource_list_t hw_resources;       
     66} isa_child_data_t;
     67
     68static hw_resource_list_t * isa_get_child_resources(device_t *dev)
     69{
     70        isa_child_data_t *dev_data = (isa_child_data_t *)dev->driver_data;
     71        if (NULL == dev_data) {
     72                return NULL;
     73        }
     74        return &dev_data->hw_resources;
     75}
     76
     77static bool isa_enable_child_interrupt(device_t *dev)
     78{
     79        // TODO
     80       
     81        return false;
     82}
     83
     84static resource_iface_t isa_child_res_iface = {
     85        &isa_get_child_resources,
     86        &isa_enable_child_interrupt     
     87};
     88
     89static device_class_t isa_child_class;
    5890
    5991static bool isa_add_device(device_t *dev);
     
    71103        .driver_ops = &isa_ops
    72104};
    73 
    74 typedef struct isa_child_data {
    75         hw_resource_list_t hw_resources;       
    76 } isa_child_data_t;
    77105
    78106
     
    154182}
    155183
    156 static char * str_get_line(char *str) {
    157         return strtok(str, "\n");
     184static char * str_get_line(char *str, char **next) {
     185        char *line = str;
     186        while (0 != *str && '\n' != *str) {
     187                str++;
     188        }
     189       
     190        if (0 != *str) {
     191                *next = str + 1;
     192        } else {
     193                *next = NULL;
     194        }
     195       
     196        *str = 0;       
     197       
     198        return line;
    158199}
    159200
     
    180221       
    181222        // alloc output buffer
    182         size_t len = str_size(line);
    183         char *name = malloc(len + 1);
     223        size_t size = str_size(line) + 1;
     224        char *name = malloc(size);
    184225       
    185226        if (NULL != name) {
    186227                // copy the result to the output buffer
    187                 str_cpy(name, len, line);
     228                str_cpy(name, size, line);
    188229        }
    189230
     
    201242
    202243
    203 void isa_child_set_irq(device_t *dev, int irq)
    204 {
    205         // TODO
     244static void isa_child_set_irq(device_t *dev, int irq)
     245{
     246        isa_child_data_t *data = (isa_child_data_t *)dev->driver_data;
     247       
     248        size_t count = data->hw_resources.count;
     249        hw_resource_t *resources = data->hw_resources.resources;
     250       
     251        if (count < ISA_MAX_HW_RES) {
     252                resources[count].type = INTERRUPT;
     253                resources[count].res.interrupt.irq = irq;
     254               
     255                data->hw_resources.count++;
     256        }       
     257}
     258
     259static void isa_child_set_io_range(device_t *dev, size_t addr, size_t len)
     260{
     261        isa_child_data_t *data = (isa_child_data_t *)dev->driver_data;
     262       
     263        size_t count = data->hw_resources.count;
     264        hw_resource_t *resources = data->hw_resources.resources;
     265       
     266        if (count < ISA_MAX_HW_RES) {
     267                resources[count].type = IO_RANGE;
     268                resources[count].res.io_range.address = addr;
     269                resources[count].res.io_range.size = len;
     270                resources[count].res.io_range.endianness = LITTLE_ENDIAN;               
     271                data->hw_resources.count++;
     272        }       
    206273}
    207274
     
    212279       
    213280        val = skip_spaces(val);
    214         irq = strtol(val, &end, 0x10);
     281        irq = (int)strtol(val, &end, 0x10);
    215282       
    216283        if (val != end) {
     
    221288static void get_dev_io_range(device_t *dev, char *val)
    222289{
    223         // TODO
    224 }
    225 
    226 static void get_dev_macth_id(device_t *dev, char *val)
    227 {
    228         // TODO
     290        size_t addr, len;
     291        char *end = NULL;
     292       
     293        val = skip_spaces(val);
     294        addr = strtol(val, &end, 0x10);
     295       
     296        if (val == end) {
     297                return;
     298        }
     299       
     300        val = skip_spaces(end);
     301        len = strtol(val, &end, 0x10);
     302       
     303        if (val == end) {
     304                return;
     305        }
     306       
     307        isa_child_set_io_range(dev, addr, len);
     308}
     309
     310static void get_match_id(char **id, char *val)
     311{
     312        char *end = val;
     313       
     314        while (isspace(*end)) {
     315                end++;
     316        }       
     317        *end = 0;
     318       
     319        size_t size = str_size(val) + 1;
     320        *id = (char *)malloc(size);
     321        str_cpy(*id, size, val);       
     322}
     323
     324static void get_dev_match_id(device_t *dev, char *val)
     325{       
     326        char *id = NULL;
     327        int score = 0;
     328        char *end = NULL;
     329       
     330        val = skip_spaces(val);
     331       
     332        score = (int)strtol(val, &end, 0x10);
     333        if (val == end) {
     334                return;
     335        }
     336       
     337        match_id_t *match_id = create_match_id();
     338        if (NULL == match_id) {
     339                return;
     340        }
     341       
     342        val = skip_spaces(end);
     343        get_match_id(&id, val);
     344        if (NULL == id) {
     345                delete_match_id(match_id);
     346                return;
     347        }
     348       
     349        match_id->id = id;
     350        match_id->score = score;
     351       
     352        add_match_id(&dev->match_ids, match_id);
    229353}
    230354
     
    242366                get_dev_irq(dev, val);         
    243367        } else if (NULL != (val = strtok(line, "match"))) {
    244                 get_dev_macth_id(dev, val);
     368                get_dev_match_id(dev, val);
    245369        }       
    246370}
    247371
     372static void child_alloc_hw_res(device_t *dev)
     373{
     374        isa_child_data_t *data = (isa_child_data_t *)dev->driver_data;
     375        data->hw_resources.resources =
     376                (hw_resource_t *)malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES);
     377       
     378}
     379
    248380static char * read_isa_dev_info(char *dev_conf, device_t *parent)
    249381{
    250382        char *line;
    251         bool cont = true;
    252383        char *dev_name = NULL;
    253384       
    254385        // skip empty lines
    255         while (cont) {
    256                 line = dev_conf;               
    257                 dev_conf = str_get_line(line);
    258                
    259                 if (NULL == dev_conf) {
     386        while (true) { 
     387                line = str_get_line(dev_conf, &dev_conf);
     388               
     389                if (NULL == line) {
    260390                        // no more lines
    261391                        return NULL;
     
    264394                if (!line_empty(line)) {
    265395                        break;
    266                 }
    267                
    268                 if (NULL == dev_conf) {
    269                         return NULL;
    270396                }
    271397        }
     
    284410        dev->name = dev_name;
    285411       
     412        // allocate buffer for the list of hardware resources of the device
     413        child_alloc_hw_res(dev);
     414       
    286415        // get properties of the device (match ids, irq and io range)
    287         cont = true;
    288         while (cont) {
    289                 line = dev_conf;               
    290                 dev_conf = str_get_line(line);
    291                 cont = line_empty(line);
     416        while (true) {         
     417                line = str_get_line(dev_conf, &dev_conf);
     418               
     419                if (line_empty(line)) {
     420                        // no more device properties
     421                        break;
     422                }
     423               
    292424                // get the device's property from the configuration line and store it in the device structure
    293                 if (cont) {
    294                         get_dev_prop(dev, line);
    295                 }               
    296         }
    297        
    298         // TODO class & interfaces !!!
     425                get_dev_prop(dev, line);
     426        }
     427       
     428        // set a class (including the corresponding set of interfaces) to the device
     429        dev->class = &isa_child_class;
     430       
    299431        child_device_register(dev, parent);
    300432       
     
    328460}
    329461
     462static void isa_init()
     463{
     464        isa_child_class.id = 0; // TODO
     465        isa_child_class.interfaces[HW_RES_DEV_IFACE] = &isa_child_res_iface;
     466}
     467
    330468int main(int argc, char *argv[])
    331469{
    332470        printf(NAME ": HelenOS ISA bus driver\n");     
     471        isa_init();
    333472        return driver_main(&isa_driver);
    334473}
Note: See TracChangeset for help on using the changeset viewer.