Changeset b7068da in mainline for uspace/drv/bus/isa/isa.c


Ignore:
Timestamp:
2012-02-09T20:35:12Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
591762c6
Parents:
7cede12c (diff), 3d4750f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

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

    r7cede12c rb7068da  
    22 * Copyright (c) 2010 Lenka Trochtova
    33 * Copyright (c) 2011 Jiri Svoboda
     4 * Copyright (c) 2011 Jan Vesely
    45 * All rights reserved.
    56 *
     
    5152#include <dirent.h>
    5253#include <fcntl.h>
     54#include <ipc/irc.h>
     55#include <ipc/services.h>
     56#include <sysinfo.h>
     57#include <ns.h>
    5358#include <sys/stat.h>
     59#include <ipc/irc.h>
     60#include <ipc/services.h>
     61#include <sysinfo.h>
     62#include <ns.h>
    5463
    5564#include <ddf/driver.h>
     
    6170#include <device/hw_res.h>
    6271
     72#include "i8237.h"
     73
    6374#define NAME "isa"
    6475#define CHILD_FUN_CONF_PATH "/drv/isa/isa.dev"
     
    7081#define ISA_FUN(fun) ((isa_fun_t *) ((fun)->driver_data))
    7182
    72 #define ISA_MAX_HW_RES 4
     83#define ISA_MAX_HW_RES 5
    7384
    7485typedef struct {
     
    96107static bool isa_enable_fun_interrupt(ddf_fun_t *fnode)
    97108{
    98         /* TODO */
    99 
    100         return false;
     109        /* This is an old ugly way, copied from pci driver */
     110        assert(fnode);
     111        isa_fun_t *isa_fun = fnode->driver_data;
     112
     113        sysarg_t apic;
     114        sysarg_t i8259;
     115
     116        async_sess_t *irc_sess = NULL;
     117
     118        if (((sysinfo_get_value("apic", &apic) == EOK) && (apic))
     119            || ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259))) {
     120                irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
     121                    SERVICE_IRC, 0, 0);
     122        }
     123
     124        if (!irc_sess)
     125                return false;
     126
     127        assert(isa_fun);
     128        const hw_resource_list_t *res = &isa_fun->hw_resources;
     129        assert(res);
     130        for (size_t i = 0; i < res->count; ++i) {
     131                if (res->resources[i].type == INTERRUPT) {
     132                        const int irq = res->resources[i].res.interrupt.irq;
     133
     134                        async_exch_t *exch = async_exchange_begin(irc_sess);
     135                        const int rc =
     136                            async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq);
     137                        async_exchange_end(exch);
     138
     139                        if (rc != EOK) {
     140                                async_hangup(irc_sess);
     141                                return false;
     142                        }
     143                }
     144        }
     145
     146        async_hangup(irc_sess);
     147        return true;
     148}
     149
     150static int isa_dma_channel_fun_setup(ddf_fun_t *fnode,
     151    unsigned int channel, uint32_t pa, uint16_t size, uint8_t mode)
     152{
     153        assert(fnode);
     154        isa_fun_t *isa_fun = fnode->driver_data;
     155        const hw_resource_list_t *res = &isa_fun->hw_resources;
     156        assert(res);
     157       
     158        const unsigned int ch = channel;
     159        for (size_t i = 0; i < res->count; ++i) {
     160                if (((res->resources[i].type == DMA_CHANNEL_16) &&
     161                    (res->resources[i].res.dma_channel.dma16 == ch)) ||
     162                    ((res->resources[i].type == DMA_CHANNEL_8) &&
     163                    (res->resources[i].res.dma_channel.dma8 == ch))) {
     164                        return dma_setup_channel(channel, pa, size, mode);
     165                }
     166        }
     167       
     168        return EINVAL;
    101169}
    102170
    103171static hw_res_ops_t isa_fun_hw_res_ops = {
    104         &isa_get_fun_resources,
    105         &isa_enable_fun_interrupt
     172        .get_resource_list = isa_get_fun_resources,
     173        .enable_interrupt = isa_enable_fun_interrupt,
     174        .dma_channel_setup = isa_dma_channel_fun_setup,
    106175};
    107176
     
    274343}
    275344
     345static void isa_fun_set_dma(isa_fun_t *fun, int dma)
     346{
     347        size_t count = fun->hw_resources.count;
     348        hw_resource_t *resources = fun->hw_resources.resources;
     349       
     350        if (count < ISA_MAX_HW_RES) {
     351                if ((dma > 0) && (dma < 4)) {
     352                        resources[count].type = DMA_CHANNEL_8;
     353                        resources[count].res.dma_channel.dma8 = dma;
     354                       
     355                        fun->hw_resources.count++;
     356                        ddf_msg(LVL_NOTE, "Added dma 0x%x to function %s", dma,
     357                            fun->fnode->name);
     358                       
     359                        return;
     360                }
     361
     362                if ((dma > 4) && (dma < 8)) {
     363                        resources[count].type = DMA_CHANNEL_16;
     364                        resources[count].res.dma_channel.dma16 = dma;
     365                       
     366                        fun->hw_resources.count++;
     367                        ddf_msg(LVL_NOTE, "Added dma 0x%x to function %s", dma,
     368                            fun->fnode->name);
     369                       
     370                        return;
     371                }
     372               
     373                ddf_msg(LVL_WARN, "Skipped dma 0x%x for function %s", dma,
     374                    fun->fnode->name);
     375        }
     376}
     377
    276378static void isa_fun_set_io_range(isa_fun_t *fun, size_t addr, size_t len)
    277379{
     
    299401
    300402        val = skip_spaces(val);
    301         irq = (int)strtol(val, &end, 0x10);
     403        irq = (int) strtol(val, &end, 10);
    302404
    303405        if (val != end)
    304406                isa_fun_set_irq(fun, irq);
     407}
     408
     409static void fun_parse_dma(isa_fun_t *fun, char *val)
     410{
     411        unsigned int dma = 0;
     412        char *end = NULL;
     413       
     414        val = skip_spaces(val);
     415        dma = (unsigned int) strtol(val, &end, 10);
     416       
     417        if (val != end)
     418                isa_fun_set_dma(fun, dma);
    305419}
    306420
     
    396510        if (!prop_parse(fun, line, "io_range", &fun_parse_io_range) &&
    397511            !prop_parse(fun, line, "irq", &fun_parse_irq) &&
     512            !prop_parse(fun, line, "dma", &fun_parse_dma) &&
    398513            !prop_parse(fun, line, "match", &fun_parse_match_id)) {
    399514
     
    406521{
    407522        fun->hw_resources.resources =
    408             (hw_resource_t *)malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES);
     523            (hw_resource_t *) malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES);
    409524}
    410525
     
    590705
    591706
    592 static void isa_init() 
     707static void isa_init()
    593708{
    594709        ddf_log_init(NAME, LVL_ERROR);
Note: See TracChangeset for help on using the changeset viewer.