source: mainline/uspace/drv/bus/isa/isa.c@ 295f658

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 295f658 was d9cf684a, checked in by Martin Decky <martin@…>, 14 years ago

cherrypick and adopt Intel 8237A DMA controller support from bzr://krabicka.net/orome/helenos/audio/

  • Property mode set to 100644
File size: 15.4 KB
RevLine 
[892e4e1]1/*
2 * Copyright (c) 2010 Lenka Trochtova
[68414f4a]3 * Copyright (c) 2011 Jiri Svoboda
[d9cf684a]4 * Copyright (c) 2011 Jan Vesely
[892e4e1]5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
32 * @defgroup isa ISA bus driver.
33 * @brief HelenOS ISA bus driver.
34 * @{
35 */
36
37/** @file
38 */
39
[f278930]40#include <adt/list.h>
[892e4e1]41#include <assert.h>
42#include <stdio.h>
43#include <errno.h>
44#include <bool.h>
45#include <fibril_synch.h>
46#include <stdlib.h>
[c47e1a8]47#include <str.h>
[cd0684d]48#include <str_error.h>
[892e4e1]49#include <ctype.h>
50#include <macros.h>
[c1a8ae52]51#include <malloc.h>
52#include <dirent.h>
53#include <fcntl.h>
54#include <sys/stat.h>
[d9cf684a]55#include <ipc/irc.h>
56#include <ipc/services.h>
57#include <sysinfo.h>
58#include <ns.h>
[892e4e1]59
[af6b5157]60#include <ddf/driver.h>
[fc51296]61#include <ddf/log.h>
[41b56084]62#include <ops/hw_res.h>
[5dc9622]63
[892e4e1]64#include <devman.h>
65#include <ipc/devman.h>
[5dc9622]66#include <device/hw_res.h>
[892e4e1]67
[d9cf684a]68#include "i8237.h"
69
[892e4e1]70#define NAME "isa"
[8b1e15ac]71#define CHILD_FUN_CONF_PATH "/drv/isa/isa.dev"
[892e4e1]72
[f278930]73/** Obtain soft-state from device node */
74#define ISA_BUS(dev) ((isa_bus_t *) ((dev)->driver_data))
75
76/** Obtain soft-state from function node */
77#define ISA_FUN(fun) ((isa_fun_t *) ((fun)->driver_data))
[68414f4a]78
[d9cf684a]79#define ISA_MAX_HW_RES 5
[5dc9622]80
[f278930]81typedef struct {
82 fibril_mutex_t mutex;
83 ddf_dev_t *dev;
84 ddf_fun_t *fctl;
85 list_t functions;
86} isa_bus_t;
87
[68414f4a]88typedef struct isa_fun {
[f278930]89 fibril_mutex_t mutex;
[83a2f43]90 ddf_fun_t *fnode;
[032e0bb]91 hw_resource_list_t hw_resources;
[f278930]92 link_t bus_link;
[68414f4a]93} isa_fun_t;
[5dc9622]94
[83a2f43]95static hw_resource_list_t *isa_get_fun_resources(ddf_fun_t *fnode)
[5dc9622]96{
[68414f4a]97 isa_fun_t *fun = ISA_FUN(fnode);
98 assert(fun != NULL);
[032e0bb]99
[68414f4a]100 return &fun->hw_resources;
[5dc9622]101}
102
[83a2f43]103static bool isa_enable_fun_interrupt(ddf_fun_t *fnode)
[5dc9622]104{
[d9cf684a]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}
[032e0bb]145
[d9cf684a]146static 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;
[5dc9622]165}
166
[8b1e15ac]167static hw_res_ops_t isa_fun_hw_res_ops = {
[d9cf684a]168 .get_resource_list = isa_get_fun_resources,
169 .enable_interrupt = isa_enable_fun_interrupt,
170 .dma_channel_setup = isa_dma_channel_fun_setup,
[5dc9622]171};
172
[83a2f43]173static ddf_dev_ops_t isa_fun_ops;
[5dc9622]174
[0c0f823b]175static int isa_dev_add(ddf_dev_t *dev);
[f278930]176static int isa_dev_remove(ddf_dev_t *dev);
[5b68e0c]177static int isa_fun_online(ddf_fun_t *fun);
178static int isa_fun_offline(ddf_fun_t *fun);
[892e4e1]179
[032e0bb]180/** The isa device driver's standard operations */
[892e4e1]181static driver_ops_t isa_ops = {
[0c0f823b]182 .dev_add = &isa_dev_add,
[f278930]183 .dev_remove = &isa_dev_remove,
[5b68e0c]184 .fun_online = &isa_fun_online,
185 .fun_offline = &isa_fun_offline
[892e4e1]186};
187
[032e0bb]188/** The isa device driver structure. */
[892e4e1]189static driver_t isa_driver = {
190 .name = NAME,
191 .driver_ops = &isa_ops
192};
193
[f278930]194static isa_fun_t *isa_fun_create(isa_bus_t *isa, const char *name)
[c1a8ae52]195{
[f278930]196 ddf_fun_t *fnode = ddf_fun_create(isa->dev, fun_inner, name);
197 if (fnode == NULL)
[c1a8ae52]198 return NULL;
[032e0bb]199
[f278930]200 isa_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(isa_fun_t));
201 if (fun == NULL)
[c1a8ae52]202 return NULL;
[032e0bb]203
[f278930]204 fibril_mutex_initialize(&fun->mutex);
[68414f4a]205 fun->fnode = fnode;
[8b1e15ac]206 return fun;
[c1a8ae52]207}
208
[68414f4a]209static char *fun_conf_read(const char *conf_path)
[032e0bb]210{
211 bool suc = false;
[c1a8ae52]212 char *buf = NULL;
213 bool opened = false;
[032e0bb]214 int fd;
[c47e1a8]215 size_t len = 0;
[032e0bb]216
[c1a8ae52]217 fd = open(conf_path, O_RDONLY);
218 if (fd < 0) {
[ebcb05a]219 ddf_msg(LVL_ERROR, "Unable to open %s", conf_path);
[c1a8ae52]220 goto cleanup;
[032e0bb]221 }
222
223 opened = true;
224
[c1a8ae52]225 len = lseek(fd, 0, SEEK_END);
[fc51296]226 lseek(fd, 0, SEEK_SET);
[c1a8ae52]227 if (len == 0) {
[ebcb05a]228 ddf_msg(LVL_ERROR, "Configuration file '%s' is empty.",
[fc51296]229 conf_path);
[032e0bb]230 goto cleanup;
[c1a8ae52]231 }
[032e0bb]232
[c1a8ae52]233 buf = malloc(len + 1);
234 if (buf == NULL) {
[ebcb05a]235 ddf_msg(LVL_ERROR, "Memory allocation failed.");
[c1a8ae52]236 goto cleanup;
[032e0bb]237 }
238
[c1a8ae52]239 if (0 >= read(fd, buf, len)) {
[ebcb05a]240 ddf_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
[c1a8ae52]241 goto cleanup;
242 }
[032e0bb]243
[c1a8ae52]244 buf[len] = 0;
[032e0bb]245
[c1a8ae52]246 suc = true;
[032e0bb]247
[c1a8ae52]248cleanup:
[032e0bb]249 if (!suc && buf != NULL) {
250 free(buf);
[c1a8ae52]251 buf = NULL;
252 }
[032e0bb]253
254 if (opened)
255 close(fd);
256
257 return buf;
[c1a8ae52]258}
259
[032e0bb]260static char *str_get_line(char *str, char **next)
261{
[5dc9622]262 char *line = str;
[032e0bb]263
264 if (str == NULL) {
[f928a8a]265 *next = NULL;
266 return NULL;
267 }
[032e0bb]268
269 while (*str != '\0' && *str != '\n') {
[5dc9622]270 str++;
[032e0bb]271 }
272
273 if (*str != '\0') {
[5dc9622]274 *next = str + 1;
275 } else {
276 *next = NULL;
[032e0bb]277 }
278
279 *str = '\0';
[5dc9622]280 return line;
[c1a8ae52]281}
282
283static bool line_empty(const char *line)
284{
[032e0bb]285 while (line != NULL && *line != 0) {
286 if (!isspace(*line))
[c1a8ae52]287 return false;
[032e0bb]288 line++;
289 }
290
291 return true;
[c1a8ae52]292}
293
[032e0bb]294static char *get_device_name(char *line)
295{
296 /* Skip leading spaces. */
297 while (*line != '\0' && isspace(*line)) {
[c1a8ae52]298 line++;
299 }
[032e0bb]300
301 /* Get the name part of the rest of the line. */
302 strtok(line, ":");
303
304 /* Allocate output buffer. */
[5dc9622]305 size_t size = str_size(line) + 1;
306 char *name = malloc(size);
[032e0bb]307
308 if (name != NULL) {
309 /* Copy the result to the output buffer. */
[5dc9622]310 str_cpy(name, size, line);
[c1a8ae52]311 }
312
313 return name;
314}
315
[032e0bb]316static inline char *skip_spaces(char *line)
[c1a8ae52]317{
[032e0bb]318 /* Skip leading spaces. */
319 while (*line != '\0' && isspace(*line))
[c1a8ae52]320 line++;
321
[032e0bb]322 return line;
323}
[c1a8ae52]324
[68414f4a]325static void isa_fun_set_irq(isa_fun_t *fun, int irq)
[c1a8ae52]326{
[68414f4a]327 size_t count = fun->hw_resources.count;
328 hw_resource_t *resources = fun->hw_resources.resources;
[032e0bb]329
[5dc9622]330 if (count < ISA_MAX_HW_RES) {
331 resources[count].type = INTERRUPT;
332 resources[count].res.interrupt.irq = irq;
[032e0bb]333
[68414f4a]334 fun->hw_resources.count++;
[032e0bb]335
[ebcb05a]336 ddf_msg(LVL_NOTE, "Added irq 0x%x to function %s", irq,
[68414f4a]337 fun->fnode->name);
[032e0bb]338 }
[5dc9622]339}
340
[d9cf684a]341static 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
[68414f4a]374static void isa_fun_set_io_range(isa_fun_t *fun, size_t addr, size_t len)
[5dc9622]375{
[68414f4a]376 size_t count = fun->hw_resources.count;
377 hw_resource_t *resources = fun->hw_resources.resources;
[032e0bb]378
[5dc9622]379 if (count < ISA_MAX_HW_RES) {
380 resources[count].type = IO_RANGE;
381 resources[count].res.io_range.address = addr;
382 resources[count].res.io_range.size = len;
[032e0bb]383 resources[count].res.io_range.endianness = LITTLE_ENDIAN;
384
[68414f4a]385 fun->hw_resources.count++;
[032e0bb]386
[fc51296]387 ddf_msg(LVL_NOTE, "Added io range (addr=0x%x, size=0x%x) to "
[ebcb05a]388 "function %s", (unsigned int) addr, (unsigned int) len,
[68414f4a]389 fun->fnode->name);
[032e0bb]390 }
[c1a8ae52]391}
392
[68414f4a]393static void fun_parse_irq(isa_fun_t *fun, char *val)
[c1a8ae52]394{
395 int irq = 0;
396 char *end = NULL;
[032e0bb]397
[8b1e15ac]398 val = skip_spaces(val);
[5dc9622]399 irq = (int)strtol(val, &end, 0x10);
[032e0bb]400
401 if (val != end)
[8b1e15ac]402 isa_fun_set_irq(fun, irq);
[c1a8ae52]403}
404
[d9cf684a]405static 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);
415}
416
[68414f4a]417static void fun_parse_io_range(isa_fun_t *fun, char *val)
[c1a8ae52]418{
[5dc9622]419 size_t addr, len;
420 char *end = NULL;
[032e0bb]421
[8b1e15ac]422 val = skip_spaces(val);
[5dc9622]423 addr = strtol(val, &end, 0x10);
[032e0bb]424
425 if (val == end)
[5dc9622]426 return;
[032e0bb]427
[8b1e15ac]428 val = skip_spaces(end);
[5dc9622]429 len = strtol(val, &end, 0x10);
[032e0bb]430
431 if (val == end)
[5dc9622]432 return;
[032e0bb]433
[8b1e15ac]434 isa_fun_set_io_range(fun, addr, len);
[c1a8ae52]435}
436
[5dc9622]437static void get_match_id(char **id, char *val)
[c1a8ae52]438{
[5dc9622]439 char *end = val;
[032e0bb]440
441 while (!isspace(*end))
[5dc9622]442 end++;
[032e0bb]443
[f928a8a]444 size_t size = end - val + 1;
[5dc9622]445 *id = (char *)malloc(size);
[032e0bb]446 str_cpy(*id, size, val);
[5dc9622]447}
448
[68414f4a]449static void fun_parse_match_id(isa_fun_t *fun, char *val)
[032e0bb]450{
[5dc9622]451 char *id = NULL;
452 int score = 0;
453 char *end = NULL;
[cd0684d]454 int rc;
[032e0bb]455
[68414f4a]456 val = skip_spaces(val);
[032e0bb]457
[5fe1c32]458 score = (int)strtol(val, &end, 10);
[5dc9622]459 if (val == end) {
[fc51296]460 ddf_msg(LVL_ERROR, "Cannot read match score for function "
[ebcb05a]461 "%s.", fun->fnode->name);
[5dc9622]462 return;
463 }
[032e0bb]464
[bab6388]465 val = skip_spaces(end);
[5dc9622]466 get_match_id(&id, val);
[032e0bb]467 if (id == NULL) {
[ebcb05a]468 ddf_msg(LVL_ERROR, "Cannot read match ID for function %s.",
[fc51296]469 fun->fnode->name);
[5dc9622]470 return;
471 }
[032e0bb]472
[fc51296]473 ddf_msg(LVL_DEBUG, "Adding match id '%s' with score %d to "
[ebcb05a]474 "function %s", id, score, fun->fnode->name);
[cd0684d]475
476 rc = ddf_fun_add_match_id(fun->fnode, id, score);
[fc51296]477 if (rc != EOK) {
[ebcb05a]478 ddf_msg(LVL_ERROR, "Failed adding match ID: %s",
[fc51296]479 str_error(rc));
480 }
[ef9460b]481
482 free(id);
[c1a8ae52]483}
484
[68414f4a]485static bool prop_parse(isa_fun_t *fun, char *line, const char *prop,
486 void (*read_fn)(isa_fun_t *, char *))
[5fe1c32]487{
488 size_t proplen = str_size(prop);
[032e0bb]489
490 if (str_lcmp(line, prop, proplen) == 0) {
[5fe1c32]491 line += proplen;
492 line = skip_spaces(line);
[8b1e15ac]493 (*read_fn)(fun, line);
[032e0bb]494
[5fe1c32]495 return true;
496 }
[032e0bb]497
498 return false;
[5fe1c32]499}
500
[68414f4a]501static void fun_prop_parse(isa_fun_t *fun, char *line)
[c1a8ae52]502{
[032e0bb]503 /* Skip leading spaces. */
[c1a8ae52]504 line = skip_spaces(line);
[032e0bb]505
[68414f4a]506 if (!prop_parse(fun, line, "io_range", &fun_parse_io_range) &&
507 !prop_parse(fun, line, "irq", &fun_parse_irq) &&
[d9cf684a]508 !prop_parse(fun, line, "dma", &fun_parse_dma) &&
[fc51296]509 !prop_parse(fun, line, "match", &fun_parse_match_id)) {
510
[ebcb05a]511 ddf_msg(LVL_ERROR, "Undefined device property at line '%s'",
[fc51296]512 line);
[032e0bb]513 }
[c1a8ae52]514}
515
[68414f4a]516static void fun_hw_res_alloc(isa_fun_t *fun)
[5dc9622]517{
[818fffe]518 fun->hw_resources.resources =
[d9cf684a]519 (hw_resource_t *) malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES);
[5dc9622]520}
521
[f278930]522static void fun_hw_res_free(isa_fun_t *fun)
523{
524 free(fun->hw_resources.resources);
525 fun->hw_resources.resources = NULL;
526}
527
528static char *isa_fun_read_info(char *fun_conf, isa_bus_t *isa)
[c1a8ae52]529{
530 char *line;
[8b1e15ac]531 char *fun_name = NULL;
[032e0bb]532
533 /* Skip empty lines. */
534 while (true) {
[8b1e15ac]535 line = str_get_line(fun_conf, &fun_conf);
[032e0bb]536
537 if (line == NULL) {
538 /* no more lines */
[c1a8ae52]539 return NULL;
540 }
[032e0bb]541
542 if (!line_empty(line))
[c1a8ae52]543 break;
544 }
[032e0bb]545
546 /* Get device name. */
[8b1e15ac]547 fun_name = get_device_name(line);
548 if (fun_name == NULL)
[c1a8ae52]549 return NULL;
[032e0bb]550
[f278930]551 isa_fun_t *fun = isa_fun_create(isa, fun_name);
[8b1e15ac]552 if (fun == NULL) {
553 free(fun_name);
[c1a8ae52]554 return NULL;
555 }
[032e0bb]556
557 /* Allocate buffer for the list of hardware resources of the device. */
[68414f4a]558 fun_hw_res_alloc(fun);
[032e0bb]559
560 /* Get properties of the device (match ids, irq and io range). */
561 while (true) {
[8b1e15ac]562 line = str_get_line(fun_conf, &fun_conf);
[032e0bb]563
[5dc9622]564 if (line_empty(line)) {
[032e0bb]565 /* no more device properties */
[5dc9622]566 break;
567 }
[032e0bb]568
569 /*
570 * Get the device's property from the configuration line
571 * and store it in the device structure.
572 */
[68414f4a]573 fun_prop_parse(fun, line);
[c1a8ae52]574 }
[032e0bb]575
576 /* Set device operations to the device. */
[97a62fe]577 fun->fnode->ops = &isa_fun_ops;
578
[ebcb05a]579 ddf_msg(LVL_DEBUG, "Binding function %s.", fun->fnode->name);
[032e0bb]580
[97a62fe]581 /* XXX Handle error */
582 (void) ddf_fun_bind(fun->fnode);
[032e0bb]583
[f278930]584 list_append(&fun->bus_link, &isa->functions);
585
[8b1e15ac]586 return fun_conf;
[c1a8ae52]587}
588
[f278930]589static void fun_conf_parse(char *conf, isa_bus_t *isa)
[c1a8ae52]590{
[032e0bb]591 while (conf != NULL && *conf != '\0') {
[f278930]592 conf = isa_fun_read_info(conf, isa);
[032e0bb]593 }
[c1a8ae52]594}
595
[f278930]596static void isa_functions_add(isa_bus_t *isa)
[c1a8ae52]597{
[8b1e15ac]598 char *fun_conf;
[032e0bb]599
[68414f4a]600 fun_conf = fun_conf_read(CHILD_FUN_CONF_PATH);
[8b1e15ac]601 if (fun_conf != NULL) {
[f278930]602 fun_conf_parse(fun_conf, isa);
[8b1e15ac]603 free(fun_conf);
[c1a8ae52]604 }
605}
[892e4e1]606
[0c0f823b]607static int isa_dev_add(ddf_dev_t *dev)
[892e4e1]608{
[f278930]609 isa_bus_t *isa;
610
[0c0f823b]611 ddf_msg(LVL_DEBUG, "isa_dev_add, device handle = %d",
[ab3a851]612 (int) dev->handle);
[032e0bb]613
[f278930]614 isa = ddf_dev_data_alloc(dev, sizeof(isa_bus_t));
615 if (isa == NULL)
616 return ENOMEM;
617
618 fibril_mutex_initialize(&isa->mutex);
619 isa->dev = dev;
620 list_initialize(&isa->functions);
621
[8b1e15ac]622 /* Make the bus device more visible. Does not do anything. */
[ebcb05a]623 ddf_msg(LVL_DEBUG, "Adding a 'ctl' function");
[8b1e15ac]624
[f278930]625 fibril_mutex_lock(&isa->mutex);
626
627 isa->fctl = ddf_fun_create(dev, fun_exposed, "ctl");
628 if (isa->fctl == NULL) {
[ebcb05a]629 ddf_msg(LVL_ERROR, "Failed creating control function.");
[97a62fe]630 return EXDEV;
631 }
632
[f278930]633 if (ddf_fun_bind(isa->fctl) != EOK) {
634 ddf_fun_destroy(isa->fctl);
[ebcb05a]635 ddf_msg(LVL_ERROR, "Failed binding control function.");
[97a62fe]636 return EXDEV;
637 }
[8b1e15ac]638
[68414f4a]639 /* Add functions as specified in the configuration file. */
[f278930]640 isa_functions_add(isa);
[ebcb05a]641 ddf_msg(LVL_NOTE, "Finished enumerating legacy functions");
[032e0bb]642
[f278930]643 fibril_mutex_unlock(&isa->mutex);
644
645 return EOK;
646}
647
648static int isa_dev_remove(ddf_dev_t *dev)
649{
650 isa_bus_t *isa = ISA_BUS(dev);
651 int rc;
652
653 fibril_mutex_lock(&isa->mutex);
654
655 while (!list_empty(&isa->functions)) {
656 isa_fun_t *fun = list_get_instance(list_first(&isa->functions),
657 isa_fun_t, bus_link);
658
659 rc = ddf_fun_offline(fun->fnode);
660 if (rc != EOK) {
661 fibril_mutex_unlock(&isa->mutex);
662 ddf_msg(LVL_ERROR, "Failed offlining %s", fun->fnode->name);
663 return rc;
664 }
665
666 rc = ddf_fun_unbind(fun->fnode);
667 if (rc != EOK) {
668 fibril_mutex_unlock(&isa->mutex);
669 ddf_msg(LVL_ERROR, "Failed unbinding %s", fun->fnode->name);
670 return rc;
671 }
672
673 list_remove(&fun->bus_link);
674
675 fun_hw_res_free(fun);
676 ddf_fun_destroy(fun->fnode);
677 }
678
679 if (ddf_fun_unbind(isa->fctl) != EOK) {
680 fibril_mutex_unlock(&isa->mutex);
681 ddf_msg(LVL_ERROR, "Failed unbinding control function.");
682 return EXDEV;
683 }
684
685 fibril_mutex_unlock(&isa->mutex);
686
[df747b9c]687 return EOK;
[892e4e1]688}
689
[5b68e0c]690static int isa_fun_online(ddf_fun_t *fun)
691{
692 ddf_msg(LVL_DEBUG, "isa_fun_online()");
693 return ddf_fun_online(fun);
694}
695
696static int isa_fun_offline(ddf_fun_t *fun)
697{
698 ddf_msg(LVL_DEBUG, "isa_fun_offline()");
699 return ddf_fun_offline(fun);
700}
701
702
[d9cf684a]703static void isa_init()
[5dc9622]704{
[fc51296]705 ddf_log_init(NAME, LVL_ERROR);
[68414f4a]706 isa_fun_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops;
[5dc9622]707}
708
[892e4e1]709int main(int argc, char *argv[])
710{
[032e0bb]711 printf(NAME ": HelenOS ISA bus driver\n");
[5dc9622]712 isa_init();
[83a2f43]713 return ddf_driver_main(&isa_driver);
[892e4e1]714}
715
716/**
717 * @}
718 */
Note: See TracBrowser for help on using the repository browser.