Ignore:
File:
1 edited

Legend:

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

    r0bbd13e r85c4cc45  
    5252#include <dirent.h>
    5353#include <fcntl.h>
    54 #include <ipc/irc.h>
    55 #include <ipc/services.h>
    56 #include <sysinfo.h>
    57 #include <ns.h>
    5854#include <sys/stat.h>
    5955#include <ipc/irc.h>
     
    6662#include <ops/hw_res.h>
    6763
     64#include <devman.h>
     65#include <ipc/devman.h>
    6866#include <device/hw_res.h>
    6967
    70 #include "i8237.h"
     68#include "dma_controller.h"
    7169
    7270#define NAME "isa"
     
    9189        fibril_mutex_t mutex;
    9290        ddf_fun_t *fnode;
     91        hw_resource_t resources[ISA_MAX_HW_RES];
    9392        hw_resource_list_t hw_resources;
    9493        link_t bus_link;
     
    147146
    148147static int isa_dma_channel_fun_setup(ddf_fun_t *fnode,
    149     unsigned int channel, uint32_t pa, uint16_t size, uint8_t mode)
     148    unsigned channel, uint32_t pa, uint16_t size, uint8_t mode)
    150149{
    151150        assert(fnode);
     
    153152        const hw_resource_list_t *res = &isa_fun->hw_resources;
    154153        assert(res);
    155        
    156         const unsigned int ch = channel;
     154        const int ch = channel;
    157155        for (size_t i = 0; i < res->count; ++i) {
    158                 if (((res->resources[i].type == DMA_CHANNEL_16) &&
    159                     (res->resources[i].res.dma_channel.dma16 == ch)) ||
    160                     ((res->resources[i].type == DMA_CHANNEL_8) &&
    161                     (res->resources[i].res.dma_channel.dma8 == ch))) {
     156                if ((res->resources[i].type == DMA_CHANNEL_16 &&
     157                    res->resources[i].res.dma_channel.dma16 == ch) ||
     158                    (res->resources[i].type == DMA_CHANNEL_8 &&
     159                    res->resources[i].res.dma_channel.dma8 == ch)) {
    162160                        return dma_setup_channel(channel, pa, size, mode);
    163161                }
    164162        }
    165        
    166163        return EINVAL;
    167164}
     
    175172static ddf_dev_ops_t isa_fun_ops;
    176173
    177 static int isa_dev_add(ddf_dev_t *dev);
     174static int isa_add_device(ddf_dev_t *dev);
    178175static int isa_dev_remove(ddf_dev_t *dev);
    179176static int isa_fun_online(ddf_fun_t *fun);
     
    182179/** The isa device driver's standard operations */
    183180static driver_ops_t isa_ops = {
    184         .dev_add = &isa_dev_add,
     181        .add_device = &isa_add_device,
    185182        .dev_remove = &isa_dev_remove,
    186183        .fun_online = &isa_fun_online,
     
    201198
    202199        isa_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(isa_fun_t));
    203         if (fun == NULL) {
    204                 ddf_fun_destroy(fnode);
     200        if (fun == NULL)
    205201                return NULL;
    206         }
    207202
    208203        fibril_mutex_initialize(&fun->mutex);
     204        fun->hw_resources.resources = fun->resources;
     205
    209206        fun->fnode = fnode;
    210207        return fun;
     
    347344        size_t count = fun->hw_resources.count;
    348345        hw_resource_t *resources = fun->hw_resources.resources;
    349        
     346
    350347        if (count < ISA_MAX_HW_RES) {
    351                 if ((dma > 0) && (dma < 4)) {
     348                if (dma > 0 && dma < 4) {
    352349                        resources[count].type = DMA_CHANNEL_8;
    353350                        resources[count].res.dma_channel.dma8 = dma;
    354                        
     351
    355352                        fun->hw_resources.count++;
    356353                        ddf_msg(LVL_NOTE, "Added dma 0x%x to function %s", dma,
    357354                            fun->fnode->name);
    358                        
    359355                        return;
    360356                }
    361357
    362                 if ((dma > 4) && (dma < 8)) {
     358                if (dma > 4 && dma < 8) {
    363359                        resources[count].type = DMA_CHANNEL_16;
    364360                        resources[count].res.dma_channel.dma16 = dma;
    365                        
     361
    366362                        fun->hw_resources.count++;
    367363                        ddf_msg(LVL_NOTE, "Added dma 0x%x to function %s", dma,
    368364                            fun->fnode->name);
    369                        
    370365                        return;
    371366                }
    372                
     367
    373368                ddf_msg(LVL_WARN, "Skipped dma 0x%x for function %s", dma,
    374369                    fun->fnode->name);
     
    401396
    402397        val = skip_spaces(val);
    403         irq = (int) strtol(val, &end, 10);
     398        irq = (int)strtol(val, &end, 0x10);
    404399
    405400        if (val != end)
     
    409404static void fun_parse_dma(isa_fun_t *fun, char *val)
    410405{
    411         unsigned int dma = 0;
     406        int dma = 0;
    412407        char *end = NULL;
    413        
     408
    414409        val = skip_spaces(val);
    415         dma = (unsigned int) strtol(val, &end, 10);
    416        
     410        dma = (int)strtol(val, &end, 10);
     411
    417412        if (val != end)
    418413                isa_fun_set_dma(fun, dma);
     
    518513}
    519514
    520 static void fun_hw_res_alloc(isa_fun_t *fun)
    521 {
    522         fun->hw_resources.resources =
    523             (hw_resource_t *) malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES);
    524 }
    525 
    526 static void fun_hw_res_free(isa_fun_t *fun)
    527 {
    528         free(fun->hw_resources.resources);
    529         fun->hw_resources.resources = NULL;
    530 }
    531 
    532515static char *isa_fun_read_info(char *fun_conf, isa_bus_t *isa)
    533516{
     
    558541                return NULL;
    559542        }
    560 
    561         /* Allocate buffer for the list of hardware resources of the device. */
    562         fun_hw_res_alloc(fun);
    563543
    564544        /* Get properties of the device (match ids, irq and io range). */
     
    609589}
    610590
    611 static int isa_dev_add(ddf_dev_t *dev)
     591static int isa_add_device(ddf_dev_t *dev)
    612592{
    613593        isa_bus_t *isa;
    614594
    615         ddf_msg(LVL_DEBUG, "isa_dev_add, device handle = %d",
     595        ddf_msg(LVL_DEBUG, "isa_add_device, device handle = %d",
    616596            (int) dev->handle);
    617597
     
    677657                list_remove(&fun->bus_link);
    678658
    679                 fun_hw_res_free(fun);
    680659                ddf_fun_destroy(fun->fnode);
    681660        }
Note: See TracChangeset for help on using the changeset viewer.