Ignore:
File:
1 edited

Legend:

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

    rd9cf684a r0c0f823b  
    22 * Copyright (c) 2010 Lenka Trochtova
    33 * Copyright (c) 2011 Jiri Svoboda
    4  * Copyright (c) 2011 Jan Vesely
    54 * All rights reserved.
    65 *
     
    5352#include <fcntl.h>
    5453#include <sys/stat.h>
    55 #include <ipc/irc.h>
    56 #include <ipc/services.h>
    57 #include <sysinfo.h>
    58 #include <ns.h>
    5954
    6055#include <ddf/driver.h>
     
    6661#include <device/hw_res.h>
    6762
    68 #include "i8237.h"
    69 
    7063#define NAME "isa"
    7164#define CHILD_FUN_CONF_PATH "/drv/isa/isa.dev"
     
    7770#define ISA_FUN(fun) ((isa_fun_t *) ((fun)->driver_data))
    7871
    79 #define ISA_MAX_HW_RES 5
     72#define ISA_MAX_HW_RES 4
    8073
    8174typedef struct {
     
    10396static bool isa_enable_fun_interrupt(ddf_fun_t *fnode)
    10497{
    105         /* This is an old ugly way, copied from pci driver */
    106         assert(fnode);
    107         isa_fun_t *isa_fun = fnode->driver_data;
    108 
    109         sysarg_t apic;
    110         sysarg_t i8259;
    111        
    112         async_sess_t *irc_sess = NULL;
    113        
    114         if (((sysinfo_get_value("apic", &apic) == EOK) && (apic))
    115             || ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259))) {
    116                 irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
    117                     SERVICE_IRC, 0, 0);
    118         }
    119        
    120         if (!irc_sess)
    121                 return false;
    122        
    123         assert(isa_fun);
    124         const hw_resource_list_t *res = &isa_fun->hw_resources;
    125         assert(res);
    126         for (size_t i = 0; i < res->count; ++i) {
    127                 if (res->resources[i].type == INTERRUPT) {
    128                         const int irq = res->resources[i].res.interrupt.irq;
    129                        
    130                         async_exch_t *exch = async_exchange_begin(irc_sess);
    131                         const int rc =
    132                             async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq);
    133                         async_exchange_end(exch);
    134                        
    135                         if (rc != EOK) {
    136                                 async_hangup(irc_sess);
    137                                 return false;
    138                         }
    139                 }
    140         }
    141        
    142         async_hangup(irc_sess);
    143         return true;
    144 }
    145 
    146 static int isa_dma_channel_fun_setup(ddf_fun_t *fnode,
    147     unsigned int channel, uint32_t pa, uint16_t size, uint8_t mode)
    148 {
    149         assert(fnode);
    150         isa_fun_t *isa_fun = fnode->driver_data;
    151         const hw_resource_list_t *res = &isa_fun->hw_resources;
    152         assert(res);
    153        
    154         const unsigned int ch = channel;
    155         for (size_t i = 0; i < res->count; ++i) {
    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))) {
    160                         return dma_setup_channel(channel, pa, size, mode);
    161                 }
    162         }
    163        
    164         return EINVAL;
     98        /* TODO */
     99
     100        return false;
    165101}
    166102
    167103static hw_res_ops_t isa_fun_hw_res_ops = {
    168         .get_resource_list = isa_get_fun_resources,
    169         .enable_interrupt = isa_enable_fun_interrupt,
    170         .dma_channel_setup = isa_dma_channel_fun_setup,
     104        &isa_get_fun_resources,
     105        &isa_enable_fun_interrupt
    171106};
    172107
     
    339274}
    340275
    341 static void isa_fun_set_dma(isa_fun_t *fun, int dma)
    342 {
    343         size_t count = fun->hw_resources.count;
    344         hw_resource_t *resources = fun->hw_resources.resources;
    345        
    346         if (count < ISA_MAX_HW_RES) {
    347                 if ((dma > 0) && (dma < 4)) {
    348                         resources[count].type = DMA_CHANNEL_8;
    349                         resources[count].res.dma_channel.dma8 = dma;
    350                        
    351                         fun->hw_resources.count++;
    352                         ddf_msg(LVL_NOTE, "Added dma 0x%x to function %s", dma,
    353                             fun->fnode->name);
    354                        
    355                         return;
    356                 }
    357 
    358                 if ((dma > 4) && (dma < 8)) {
    359                         resources[count].type = DMA_CHANNEL_16;
    360                         resources[count].res.dma_channel.dma16 = dma;
    361                        
    362                         fun->hw_resources.count++;
    363                         ddf_msg(LVL_NOTE, "Added dma 0x%x to function %s", dma,
    364                             fun->fnode->name);
    365                        
    366                         return;
    367                 }
    368                
    369                 ddf_msg(LVL_WARN, "Skipped dma 0x%x for function %s", dma,
    370                     fun->fnode->name);
    371         }
    372 }
    373 
    374276static void isa_fun_set_io_range(isa_fun_t *fun, size_t addr, size_t len)
    375277{
     
    401303        if (val != end)
    402304                isa_fun_set_irq(fun, irq);
    403 }
    404 
    405 static void fun_parse_dma(isa_fun_t *fun, char *val)
    406 {
    407         unsigned int dma = 0;
    408         char *end = NULL;
    409        
    410         val = skip_spaces(val);
    411         dma = (unsigned int) strtol(val, &end, 10);
    412        
    413         if (val != end)
    414                 isa_fun_set_dma(fun, dma);
    415305}
    416306
     
    506396        if (!prop_parse(fun, line, "io_range", &fun_parse_io_range) &&
    507397            !prop_parse(fun, line, "irq", &fun_parse_irq) &&
    508             !prop_parse(fun, line, "dma", &fun_parse_dma) &&
    509398            !prop_parse(fun, line, "match", &fun_parse_match_id)) {
    510399
     
    517406{
    518407        fun->hw_resources.resources =
    519             (hw_resource_t *) malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES);
     408            (hw_resource_t *)malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES);
    520409}
    521410
     
    701590
    702591
    703 static void isa_init()
     592static void isa_init() 
    704593{
    705594        ddf_log_init(NAME, LVL_ERROR);
Note: See TracChangeset for help on using the changeset viewer.