Changes in uspace/drv/bus/isa/isa.c [e882e3a:f278930] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/isa/isa.c
re882e3a rf278930 2 2 * Copyright (c) 2010 Lenka Trochtova 3 3 * Copyright (c) 2011 Jiri Svoboda 4 * Copyright (c) 2011 Jan Vesely5 4 * All rights reserved. 6 5 * … … 52 51 #include <dirent.h> 53 52 #include <fcntl.h> 54 #include <ipc/irc.h>55 #include <ipc/services.h>56 #include <sysinfo.h>57 #include <ns.h>58 53 #include <sys/stat.h> 59 #include <ipc/irc.h>60 #include <ipc/services.h>61 #include <sysinfo.h>62 #include <ns.h>63 54 64 55 #include <ddf/driver.h> … … 66 57 #include <ops/hw_res.h> 67 58 59 #include <devman.h> 60 #include <ipc/devman.h> 68 61 #include <device/hw_res.h> 69 70 #include "i8237.h"71 62 72 63 #define NAME "isa" … … 79 70 #define ISA_FUN(fun) ((isa_fun_t *) ((fun)->driver_data)) 80 71 81 #define ISA_MAX_HW_RES 572 #define ISA_MAX_HW_RES 4 82 73 83 74 typedef struct { … … 105 96 static bool isa_enable_fun_interrupt(ddf_fun_t *fnode) 106 97 { 107 /* This is an old ugly way, copied from pci driver */ 108 assert(fnode); 109 isa_fun_t *isa_fun = fnode->driver_data; 110 111 sysarg_t apic; 112 sysarg_t i8259; 113 114 async_sess_t *irc_sess = NULL; 115 116 if (((sysinfo_get_value("apic", &apic) == EOK) && (apic)) 117 || ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259))) { 118 irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE, 119 SERVICE_IRC, 0, 0); 120 } 121 122 if (!irc_sess) 123 return false; 124 125 assert(isa_fun); 126 const hw_resource_list_t *res = &isa_fun->hw_resources; 127 assert(res); 128 for (size_t i = 0; i < res->count; ++i) { 129 if (res->resources[i].type == INTERRUPT) { 130 const int irq = res->resources[i].res.interrupt.irq; 131 132 async_exch_t *exch = async_exchange_begin(irc_sess); 133 const int rc = 134 async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq); 135 async_exchange_end(exch); 136 137 if (rc != EOK) { 138 async_hangup(irc_sess); 139 return false; 140 } 141 } 142 } 143 144 async_hangup(irc_sess); 145 return true; 146 } 147 148 static int isa_dma_channel_fun_setup(ddf_fun_t *fnode, 149 unsigned int channel, uint32_t pa, uint16_t size, uint8_t mode) 150 { 151 assert(fnode); 152 isa_fun_t *isa_fun = fnode->driver_data; 153 const hw_resource_list_t *res = &isa_fun->hw_resources; 154 assert(res); 155 156 const unsigned int ch = channel; 157 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))) { 162 return dma_setup_channel(channel, pa, size, mode); 163 } 164 } 165 166 return EINVAL; 98 /* TODO */ 99 100 return false; 167 101 } 168 102 169 103 static hw_res_ops_t isa_fun_hw_res_ops = { 170 .get_resource_list = isa_get_fun_resources, 171 .enable_interrupt = isa_enable_fun_interrupt, 172 .dma_channel_setup = isa_dma_channel_fun_setup, 104 &isa_get_fun_resources, 105 &isa_enable_fun_interrupt 173 106 }; 174 107 175 108 static ddf_dev_ops_t isa_fun_ops; 176 109 177 static int isa_ dev_add(ddf_dev_t *dev);110 static int isa_add_device(ddf_dev_t *dev); 178 111 static int isa_dev_remove(ddf_dev_t *dev); 179 112 static int isa_fun_online(ddf_fun_t *fun); … … 182 115 /** The isa device driver's standard operations */ 183 116 static driver_ops_t isa_ops = { 184 . dev_add = &isa_dev_add,117 .add_device = &isa_add_device, 185 118 .dev_remove = &isa_dev_remove, 186 119 .fun_online = &isa_fun_online, … … 341 274 } 342 275 343 static void isa_fun_set_dma(isa_fun_t *fun, int dma)344 {345 size_t count = fun->hw_resources.count;346 hw_resource_t *resources = fun->hw_resources.resources;347 348 if (count < ISA_MAX_HW_RES) {349 if ((dma > 0) && (dma < 4)) {350 resources[count].type = DMA_CHANNEL_8;351 resources[count].res.dma_channel.dma8 = dma;352 353 fun->hw_resources.count++;354 ddf_msg(LVL_NOTE, "Added dma 0x%x to function %s", dma,355 fun->fnode->name);356 357 return;358 }359 360 if ((dma > 4) && (dma < 8)) {361 resources[count].type = DMA_CHANNEL_16;362 resources[count].res.dma_channel.dma16 = dma;363 364 fun->hw_resources.count++;365 ddf_msg(LVL_NOTE, "Added dma 0x%x to function %s", dma,366 fun->fnode->name);367 368 return;369 }370 371 ddf_msg(LVL_WARN, "Skipped dma 0x%x for function %s", dma,372 fun->fnode->name);373 }374 }375 376 276 static void isa_fun_set_io_range(isa_fun_t *fun, size_t addr, size_t len) 377 277 { … … 399 299 400 300 val = skip_spaces(val); 401 irq = (int) strtol(val, &end,10);301 irq = (int)strtol(val, &end, 0x10); 402 302 403 303 if (val != end) 404 304 isa_fun_set_irq(fun, irq); 405 }406 407 static void fun_parse_dma(isa_fun_t *fun, char *val)408 {409 unsigned int dma = 0;410 char *end = NULL;411 412 val = skip_spaces(val);413 dma = (unsigned int) strtol(val, &end, 10);414 415 if (val != end)416 isa_fun_set_dma(fun, dma);417 305 } 418 306 … … 508 396 if (!prop_parse(fun, line, "io_range", &fun_parse_io_range) && 509 397 !prop_parse(fun, line, "irq", &fun_parse_irq) && 510 !prop_parse(fun, line, "dma", &fun_parse_dma) &&511 398 !prop_parse(fun, line, "match", &fun_parse_match_id)) { 512 399 … … 518 405 static void fun_hw_res_alloc(isa_fun_t *fun) 519 406 { 520 fun->hw_resources.resources = 521 (hw_resource_t *) 407 fun->hw_resources.resources = 408 (hw_resource_t *)malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES); 522 409 } 523 410 … … 607 494 } 608 495 609 static int isa_ dev_add(ddf_dev_t *dev)496 static int isa_add_device(ddf_dev_t *dev) 610 497 { 611 498 isa_bus_t *isa; 612 499 613 ddf_msg(LVL_DEBUG, "isa_ dev_add, device handle = %d",500 ddf_msg(LVL_DEBUG, "isa_add_device, device handle = %d", 614 501 (int) dev->handle); 615 502 … … 703 590 704 591 705 static void isa_init() 592 static void isa_init() 706 593 { 707 594 ddf_log_init(NAME, LVL_ERROR);
Note:
See TracChangeset
for help on using the changeset viewer.