source: mainline/uspace/drv/bus/isa/isa.c@ 3d4ad475

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3d4ad475 was 3d4ad475, checked in by Jan Vesely <jano.vesely@…>, 13 years ago

isa: Do not allocate and copy name string.

ddf_fun_create does that for us.

  • Property mode set to 100644
File size: 14.9 KB
RevLine 
[892e4e1]1/*
2 * Copyright (c) 2010 Lenka Trochtova
[68414f4a]3 * Copyright (c) 2011 Jiri Svoboda
[ec388d7]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>
[5960b48]54#include <ipc/irc.h>
55#include <ipc/services.h>
56#include <sysinfo.h>
57#include <ns.h>
[c1a8ae52]58#include <sys/stat.h>
[1a11a16]59#include <ipc/irc.h>
60#include <ipc/services.h>
61#include <sysinfo.h>
62#include <ns.h>
[892e4e1]63
[af6b5157]64#include <ddf/driver.h>
[fc51296]65#include <ddf/log.h>
[41b56084]66#include <ops/hw_res.h>
[5dc9622]67
68#include <device/hw_res.h>
[892e4e1]69
[d9cf684a]70#include "i8237.h"
[ec388d7]71
[892e4e1]72#define NAME "isa"
[8b1e15ac]73#define CHILD_FUN_CONF_PATH "/drv/isa/isa.dev"
[892e4e1]74
[f278930]75/** Obtain soft-state from device node */
76#define ISA_BUS(dev) ((isa_bus_t *) ((dev)->driver_data))
77
78/** Obtain soft-state from function node */
79#define ISA_FUN(fun) ((isa_fun_t *) ((fun)->driver_data))
[68414f4a]80
[55a8e0cb]81#define ISA_MAX_HW_RES 5
[5dc9622]82
[f278930]83typedef struct {
84 fibril_mutex_t mutex;
85 ddf_dev_t *dev;
86 ddf_fun_t *fctl;
87 list_t functions;
88} isa_bus_t;
89
[68414f4a]90typedef struct isa_fun {
[f278930]91 fibril_mutex_t mutex;
[83a2f43]92 ddf_fun_t *fnode;
[85c4cc45]93 hw_resource_t resources[ISA_MAX_HW_RES];
[032e0bb]94 hw_resource_list_t hw_resources;
[f278930]95 link_t bus_link;
[68414f4a]96} isa_fun_t;
[5dc9622]97
[83a2f43]98static hw_resource_list_t *isa_get_fun_resources(ddf_fun_t *fnode)
[5dc9622]99{
[68414f4a]100 isa_fun_t *fun = ISA_FUN(fnode);
101 assert(fun != NULL);
[032e0bb]102
[68414f4a]103 return &fun->hw_resources;
[5dc9622]104}
105
[83a2f43]106static bool isa_enable_fun_interrupt(ddf_fun_t *fnode)
[5dc9622]107{
[1a11a16]108 /* This is an old ugly way, copied from pci driver */
109 assert(fnode);
110 isa_fun_t *isa_fun = fnode->driver_data;
[032e0bb]111
[1a11a16]112 sysarg_t apic;
113 sysarg_t i8259;
114
115 async_sess_t *irc_sess = NULL;
116
117 if (((sysinfo_get_value("apic", &apic) == EOK) && (apic))
118 || ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259))) {
119 irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
120 SERVICE_IRC, 0, 0);
121 }
122
123 if (!irc_sess)
124 return false;
125
126 assert(isa_fun);
[ec388d7]127 const hw_resource_list_t *res = &isa_fun->hw_resources;
[1a11a16]128 assert(res);
[ec388d7]129 for (size_t i = 0; i < res->count; ++i) {
[1a11a16]130 if (res->resources[i].type == INTERRUPT) {
131 const int irq = res->resources[i].res.interrupt.irq;
132
133 async_exch_t *exch = async_exchange_begin(irc_sess);
134 const int rc =
135 async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq);
136 async_exchange_end(exch);
137
138 if (rc != EOK) {
139 async_hangup(irc_sess);
140 return false;
141 }
142 }
143 }
144
145 async_hangup(irc_sess);
146 return true;
[5dc9622]147}
148
[ec388d7]149static int isa_dma_channel_fun_setup(ddf_fun_t *fnode,
[d9cf684a]150 unsigned int channel, uint32_t pa, uint16_t size, uint8_t mode)
[ec388d7]151{
152 assert(fnode);
153 isa_fun_t *isa_fun = fnode->driver_data;
154 const hw_resource_list_t *res = &isa_fun->hw_resources;
155 assert(res);
[d9cf684a]156
157 const unsigned int ch = channel;
[ec388d7]158 for (size_t i = 0; i < res->count; ++i) {
[d9cf684a]159 if (((res->resources[i].type == DMA_CHANNEL_16) &&
160 (res->resources[i].res.dma_channel.dma16 == ch)) ||
161 ((res->resources[i].type == DMA_CHANNEL_8) &&
162 (res->resources[i].res.dma_channel.dma8 == ch))) {
[ec388d7]163 return dma_setup_channel(channel, pa, size, mode);
164 }
165 }
[d9cf684a]166
[ec388d7]167 return EINVAL;
168}
169
[8b1e15ac]170static hw_res_ops_t isa_fun_hw_res_ops = {
[ec388d7]171 .get_resource_list = isa_get_fun_resources,
172 .enable_interrupt = isa_enable_fun_interrupt,
173 .dma_channel_setup = isa_dma_channel_fun_setup,
[5dc9622]174};
175
[83a2f43]176static ddf_dev_ops_t isa_fun_ops;
[5dc9622]177
[0c0f823b]178static int isa_dev_add(ddf_dev_t *dev);
[f278930]179static int isa_dev_remove(ddf_dev_t *dev);
[5b68e0c]180static int isa_fun_online(ddf_fun_t *fun);
181static int isa_fun_offline(ddf_fun_t *fun);
[892e4e1]182
[032e0bb]183/** The isa device driver's standard operations */
[892e4e1]184static driver_ops_t isa_ops = {
[0c0f823b]185 .dev_add = &isa_dev_add,
[f278930]186 .dev_remove = &isa_dev_remove,
[5b68e0c]187 .fun_online = &isa_fun_online,
188 .fun_offline = &isa_fun_offline
[892e4e1]189};
190
[032e0bb]191/** The isa device driver structure. */
[892e4e1]192static driver_t isa_driver = {
193 .name = NAME,
194 .driver_ops = &isa_ops
195};
196
[f278930]197static isa_fun_t *isa_fun_create(isa_bus_t *isa, const char *name)
[c1a8ae52]198{
[f278930]199 ddf_fun_t *fnode = ddf_fun_create(isa->dev, fun_inner, name);
200 if (fnode == NULL)
[c1a8ae52]201 return NULL;
[032e0bb]202
[f278930]203 isa_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(isa_fun_t));
[0bbd13e]204 if (fun == NULL) {
205 ddf_fun_destroy(fnode);
[c1a8ae52]206 return NULL;
[0bbd13e]207 }
[032e0bb]208
[f278930]209 fibril_mutex_initialize(&fun->mutex);
[85c4cc45]210 fun->hw_resources.resources = fun->resources;
211
[68414f4a]212 fun->fnode = fnode;
[8b1e15ac]213 return fun;
[c1a8ae52]214}
215
[68414f4a]216static char *fun_conf_read(const char *conf_path)
[032e0bb]217{
218 bool suc = false;
[c1a8ae52]219 char *buf = NULL;
220 bool opened = false;
[032e0bb]221 int fd;
[c47e1a8]222 size_t len = 0;
[032e0bb]223
[c1a8ae52]224 fd = open(conf_path, O_RDONLY);
225 if (fd < 0) {
[ebcb05a]226 ddf_msg(LVL_ERROR, "Unable to open %s", conf_path);
[c1a8ae52]227 goto cleanup;
[032e0bb]228 }
229
230 opened = true;
231
[c1a8ae52]232 len = lseek(fd, 0, SEEK_END);
[fc51296]233 lseek(fd, 0, SEEK_SET);
[c1a8ae52]234 if (len == 0) {
[ebcb05a]235 ddf_msg(LVL_ERROR, "Configuration file '%s' is empty.",
[fc51296]236 conf_path);
[032e0bb]237 goto cleanup;
[c1a8ae52]238 }
[032e0bb]239
[c1a8ae52]240 buf = malloc(len + 1);
241 if (buf == NULL) {
[ebcb05a]242 ddf_msg(LVL_ERROR, "Memory allocation failed.");
[c1a8ae52]243 goto cleanup;
[032e0bb]244 }
245
[c1a8ae52]246 if (0 >= read(fd, buf, len)) {
[ebcb05a]247 ddf_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
[c1a8ae52]248 goto cleanup;
249 }
[032e0bb]250
[c1a8ae52]251 buf[len] = 0;
[032e0bb]252
[c1a8ae52]253 suc = true;
[032e0bb]254
[c1a8ae52]255cleanup:
[032e0bb]256 if (!suc && buf != NULL) {
257 free(buf);
[c1a8ae52]258 buf = NULL;
259 }
[032e0bb]260
261 if (opened)
262 close(fd);
263
264 return buf;
[c1a8ae52]265}
266
[032e0bb]267static char *str_get_line(char *str, char **next)
268{
[5dc9622]269 char *line = str;
[032e0bb]270
271 if (str == NULL) {
[f928a8a]272 *next = NULL;
273 return NULL;
274 }
[032e0bb]275
276 while (*str != '\0' && *str != '\n') {
[5dc9622]277 str++;
[032e0bb]278 }
279
280 if (*str != '\0') {
[5dc9622]281 *next = str + 1;
282 } else {
283 *next = NULL;
[032e0bb]284 }
285
286 *str = '\0';
[5dc9622]287 return line;
[c1a8ae52]288}
289
290static bool line_empty(const char *line)
291{
[032e0bb]292 while (line != NULL && *line != 0) {
293 if (!isspace(*line))
[c1a8ae52]294 return false;
[032e0bb]295 line++;
296 }
297
298 return true;
[c1a8ae52]299}
300
[032e0bb]301static char *get_device_name(char *line)
302{
303 /* Skip leading spaces. */
304 while (*line != '\0' && isspace(*line)) {
[c1a8ae52]305 line++;
306 }
[032e0bb]307
308 /* Get the name part of the rest of the line. */
309 strtok(line, ":");
[3d4ad475]310 return line;
[c1a8ae52]311}
312
[032e0bb]313static inline char *skip_spaces(char *line)
[c1a8ae52]314{
[032e0bb]315 /* Skip leading spaces. */
316 while (*line != '\0' && isspace(*line))
[c1a8ae52]317 line++;
318
[032e0bb]319 return line;
320}
[c1a8ae52]321
[82e4005]322static void isa_fun_add_irq(isa_fun_t *fun, int irq)
[c1a8ae52]323{
[68414f4a]324 size_t count = fun->hw_resources.count;
325 hw_resource_t *resources = fun->hw_resources.resources;
[032e0bb]326
[5dc9622]327 if (count < ISA_MAX_HW_RES) {
328 resources[count].type = INTERRUPT;
329 resources[count].res.interrupt.irq = irq;
[032e0bb]330
[68414f4a]331 fun->hw_resources.count++;
[032e0bb]332
[ebcb05a]333 ddf_msg(LVL_NOTE, "Added irq 0x%x to function %s", irq,
[68414f4a]334 fun->fnode->name);
[032e0bb]335 }
[5dc9622]336}
337
[82e4005]338static void isa_fun_add_dma(isa_fun_t *fun, int dma)
[55a8e0cb]339{
340 size_t count = fun->hw_resources.count;
341 hw_resource_t *resources = fun->hw_resources.resources;
[d9cf684a]342
[55a8e0cb]343 if (count < ISA_MAX_HW_RES) {
[d9cf684a]344 if ((dma > 0) && (dma < 4)) {
[55a8e0cb]345 resources[count].type = DMA_CHANNEL_8;
346 resources[count].res.dma_channel.dma8 = dma;
[d9cf684a]347
[55a8e0cb]348 fun->hw_resources.count++;
349 ddf_msg(LVL_NOTE, "Added dma 0x%x to function %s", dma,
350 fun->fnode->name);
[d9cf684a]351
[55a8e0cb]352 return;
353 }
354
[d9cf684a]355 if ((dma > 4) && (dma < 8)) {
[55a8e0cb]356 resources[count].type = DMA_CHANNEL_16;
357 resources[count].res.dma_channel.dma16 = dma;
[d9cf684a]358
[55a8e0cb]359 fun->hw_resources.count++;
360 ddf_msg(LVL_NOTE, "Added dma 0x%x to function %s", dma,
361 fun->fnode->name);
[d9cf684a]362
[55a8e0cb]363 return;
364 }
[d9cf684a]365
[55a8e0cb]366 ddf_msg(LVL_WARN, "Skipped dma 0x%x for function %s", dma,
367 fun->fnode->name);
368 }
369}
370
[82e4005]371static void isa_fun_add_io_range(isa_fun_t *fun, size_t addr, size_t len)
[5dc9622]372{
[68414f4a]373 size_t count = fun->hw_resources.count;
374 hw_resource_t *resources = fun->hw_resources.resources;
[032e0bb]375
[5dc9622]376 if (count < ISA_MAX_HW_RES) {
377 resources[count].type = IO_RANGE;
378 resources[count].res.io_range.address = addr;
379 resources[count].res.io_range.size = len;
[032e0bb]380 resources[count].res.io_range.endianness = LITTLE_ENDIAN;
381
[68414f4a]382 fun->hw_resources.count++;
[032e0bb]383
[fc51296]384 ddf_msg(LVL_NOTE, "Added io range (addr=0x%x, size=0x%x) to "
[ebcb05a]385 "function %s", (unsigned int) addr, (unsigned int) len,
[68414f4a]386 fun->fnode->name);
[032e0bb]387 }
[c1a8ae52]388}
389
[68414f4a]390static void fun_parse_irq(isa_fun_t *fun, char *val)
[c1a8ae52]391{
392 int irq = 0;
393 char *end = NULL;
[032e0bb]394
[8b1e15ac]395 val = skip_spaces(val);
[5cc9eba]396 irq = (int) strtol(val, &end, 10);
[032e0bb]397
398 if (val != end)
[82e4005]399 isa_fun_add_irq(fun, irq);
[c1a8ae52]400}
401
[55a8e0cb]402static void fun_parse_dma(isa_fun_t *fun, char *val)
403{
[d9cf684a]404 unsigned int dma = 0;
[55a8e0cb]405 char *end = NULL;
[d9cf684a]406
[55a8e0cb]407 val = skip_spaces(val);
[d9cf684a]408 dma = (unsigned int) strtol(val, &end, 10);
409
[55a8e0cb]410 if (val != end)
[82e4005]411 isa_fun_add_dma(fun, dma);
[55a8e0cb]412}
413
[68414f4a]414static void fun_parse_io_range(isa_fun_t *fun, char *val)
[c1a8ae52]415{
[5dc9622]416 size_t addr, len;
417 char *end = NULL;
[032e0bb]418
[8b1e15ac]419 val = skip_spaces(val);
[5dc9622]420 addr = strtol(val, &end, 0x10);
[032e0bb]421
422 if (val == end)
[5dc9622]423 return;
[032e0bb]424
[8b1e15ac]425 val = skip_spaces(end);
[5dc9622]426 len = strtol(val, &end, 0x10);
[032e0bb]427
428 if (val == end)
[5dc9622]429 return;
[032e0bb]430
[82e4005]431 isa_fun_add_io_range(fun, addr, len);
[c1a8ae52]432}
433
[5dc9622]434static void get_match_id(char **id, char *val)
[c1a8ae52]435{
[5dc9622]436 char *end = val;
[032e0bb]437
438 while (!isspace(*end))
[5dc9622]439 end++;
[032e0bb]440
[f928a8a]441 size_t size = end - val + 1;
[5dc9622]442 *id = (char *)malloc(size);
[032e0bb]443 str_cpy(*id, size, val);
[5dc9622]444}
445
[68414f4a]446static void fun_parse_match_id(isa_fun_t *fun, char *val)
[032e0bb]447{
[5dc9622]448 char *id = NULL;
449 int score = 0;
450 char *end = NULL;
[cd0684d]451 int rc;
[032e0bb]452
[68414f4a]453 val = skip_spaces(val);
[032e0bb]454
[5fe1c32]455 score = (int)strtol(val, &end, 10);
[5dc9622]456 if (val == end) {
[fc51296]457 ddf_msg(LVL_ERROR, "Cannot read match score for function "
[ebcb05a]458 "%s.", fun->fnode->name);
[5dc9622]459 return;
460 }
[032e0bb]461
[bab6388]462 val = skip_spaces(end);
[5dc9622]463 get_match_id(&id, val);
[032e0bb]464 if (id == NULL) {
[ebcb05a]465 ddf_msg(LVL_ERROR, "Cannot read match ID for function %s.",
[fc51296]466 fun->fnode->name);
[5dc9622]467 return;
468 }
[032e0bb]469
[fc51296]470 ddf_msg(LVL_DEBUG, "Adding match id '%s' with score %d to "
[ebcb05a]471 "function %s", id, score, fun->fnode->name);
[cd0684d]472
473 rc = ddf_fun_add_match_id(fun->fnode, id, score);
[fc51296]474 if (rc != EOK) {
[ebcb05a]475 ddf_msg(LVL_ERROR, "Failed adding match ID: %s",
[fc51296]476 str_error(rc));
477 }
[ef9460b]478
479 free(id);
[c1a8ae52]480}
481
[68414f4a]482static bool prop_parse(isa_fun_t *fun, char *line, const char *prop,
483 void (*read_fn)(isa_fun_t *, char *))
[5fe1c32]484{
485 size_t proplen = str_size(prop);
[032e0bb]486
487 if (str_lcmp(line, prop, proplen) == 0) {
[5fe1c32]488 line += proplen;
489 line = skip_spaces(line);
[8b1e15ac]490 (*read_fn)(fun, line);
[032e0bb]491
[5fe1c32]492 return true;
493 }
[032e0bb]494
495 return false;
[5fe1c32]496}
497
[68414f4a]498static void fun_prop_parse(isa_fun_t *fun, char *line)
[c1a8ae52]499{
[032e0bb]500 /* Skip leading spaces. */
[c1a8ae52]501 line = skip_spaces(line);
[032e0bb]502
[68414f4a]503 if (!prop_parse(fun, line, "io_range", &fun_parse_io_range) &&
504 !prop_parse(fun, line, "irq", &fun_parse_irq) &&
[55a8e0cb]505 !prop_parse(fun, line, "dma", &fun_parse_dma) &&
[fc51296]506 !prop_parse(fun, line, "match", &fun_parse_match_id)) {
507
[ebcb05a]508 ddf_msg(LVL_ERROR, "Undefined device property at line '%s'",
[fc51296]509 line);
[032e0bb]510 }
[c1a8ae52]511}
512
[f278930]513static char *isa_fun_read_info(char *fun_conf, isa_bus_t *isa)
[c1a8ae52]514{
515 char *line;
[032e0bb]516
517 /* Skip empty lines. */
[1de97fe6]518 do {
[8b1e15ac]519 line = str_get_line(fun_conf, &fun_conf);
[032e0bb]520
521 if (line == NULL) {
522 /* no more lines */
[c1a8ae52]523 return NULL;
524 }
[032e0bb]525
[1de97fe6]526 } while (line_empty(line));
[032e0bb]527
528 /* Get device name. */
[3d4ad475]529 const char *fun_name = get_device_name(line);
[8b1e15ac]530 if (fun_name == NULL)
[c1a8ae52]531 return NULL;
[032e0bb]532
[f278930]533 isa_fun_t *fun = isa_fun_create(isa, fun_name);
[8b1e15ac]534 if (fun == NULL) {
[c1a8ae52]535 return NULL;
536 }
[032e0bb]537
538 /* Get properties of the device (match ids, irq and io range). */
539 while (true) {
[8b1e15ac]540 line = str_get_line(fun_conf, &fun_conf);
[032e0bb]541
[5dc9622]542 if (line_empty(line)) {
[032e0bb]543 /* no more device properties */
[5dc9622]544 break;
545 }
[032e0bb]546
547 /*
548 * Get the device's property from the configuration line
549 * and store it in the device structure.
550 */
[68414f4a]551 fun_prop_parse(fun, line);
[c1a8ae52]552 }
[032e0bb]553
554 /* Set device operations to the device. */
[97a62fe]555 fun->fnode->ops = &isa_fun_ops;
556
[ebcb05a]557 ddf_msg(LVL_DEBUG, "Binding function %s.", fun->fnode->name);
[032e0bb]558
[97a62fe]559 /* XXX Handle error */
560 (void) ddf_fun_bind(fun->fnode);
[032e0bb]561
[f278930]562 list_append(&fun->bus_link, &isa->functions);
563
[8b1e15ac]564 return fun_conf;
[c1a8ae52]565}
566
[f278930]567static void fun_conf_parse(char *conf, isa_bus_t *isa)
[c1a8ae52]568{
[032e0bb]569 while (conf != NULL && *conf != '\0') {
[f278930]570 conf = isa_fun_read_info(conf, isa);
[032e0bb]571 }
[c1a8ae52]572}
573
[f278930]574static void isa_functions_add(isa_bus_t *isa)
[c1a8ae52]575{
[8b1e15ac]576 char *fun_conf;
[032e0bb]577
[68414f4a]578 fun_conf = fun_conf_read(CHILD_FUN_CONF_PATH);
[8b1e15ac]579 if (fun_conf != NULL) {
[f278930]580 fun_conf_parse(fun_conf, isa);
[8b1e15ac]581 free(fun_conf);
[c1a8ae52]582 }
583}
[892e4e1]584
[0c0f823b]585static int isa_dev_add(ddf_dev_t *dev)
[892e4e1]586{
[f278930]587 isa_bus_t *isa;
588
[0c0f823b]589 ddf_msg(LVL_DEBUG, "isa_dev_add, device handle = %d",
[ab3a851]590 (int) dev->handle);
[032e0bb]591
[f278930]592 isa = ddf_dev_data_alloc(dev, sizeof(isa_bus_t));
593 if (isa == NULL)
594 return ENOMEM;
595
596 fibril_mutex_initialize(&isa->mutex);
597 isa->dev = dev;
598 list_initialize(&isa->functions);
599
[8b1e15ac]600 /* Make the bus device more visible. Does not do anything. */
[ebcb05a]601 ddf_msg(LVL_DEBUG, "Adding a 'ctl' function");
[8b1e15ac]602
[f278930]603 fibril_mutex_lock(&isa->mutex);
604
605 isa->fctl = ddf_fun_create(dev, fun_exposed, "ctl");
606 if (isa->fctl == NULL) {
[ebcb05a]607 ddf_msg(LVL_ERROR, "Failed creating control function.");
[97a62fe]608 return EXDEV;
609 }
610
[f278930]611 if (ddf_fun_bind(isa->fctl) != EOK) {
612 ddf_fun_destroy(isa->fctl);
[ebcb05a]613 ddf_msg(LVL_ERROR, "Failed binding control function.");
[97a62fe]614 return EXDEV;
615 }
[8b1e15ac]616
[68414f4a]617 /* Add functions as specified in the configuration file. */
[f278930]618 isa_functions_add(isa);
[ebcb05a]619 ddf_msg(LVL_NOTE, "Finished enumerating legacy functions");
[032e0bb]620
[f278930]621 fibril_mutex_unlock(&isa->mutex);
622
623 return EOK;
624}
625
626static int isa_dev_remove(ddf_dev_t *dev)
627{
628 isa_bus_t *isa = ISA_BUS(dev);
629 int rc;
630
631 fibril_mutex_lock(&isa->mutex);
632
633 while (!list_empty(&isa->functions)) {
634 isa_fun_t *fun = list_get_instance(list_first(&isa->functions),
635 isa_fun_t, bus_link);
636
637 rc = ddf_fun_offline(fun->fnode);
638 if (rc != EOK) {
639 fibril_mutex_unlock(&isa->mutex);
640 ddf_msg(LVL_ERROR, "Failed offlining %s", fun->fnode->name);
641 return rc;
642 }
643
644 rc = ddf_fun_unbind(fun->fnode);
645 if (rc != EOK) {
646 fibril_mutex_unlock(&isa->mutex);
647 ddf_msg(LVL_ERROR, "Failed unbinding %s", fun->fnode->name);
648 return rc;
649 }
650
651 list_remove(&fun->bus_link);
652
653 ddf_fun_destroy(fun->fnode);
654 }
655
656 if (ddf_fun_unbind(isa->fctl) != EOK) {
657 fibril_mutex_unlock(&isa->mutex);
658 ddf_msg(LVL_ERROR, "Failed unbinding control function.");
659 return EXDEV;
660 }
661
662 fibril_mutex_unlock(&isa->mutex);
663
[df747b9c]664 return EOK;
[892e4e1]665}
666
[5b68e0c]667static int isa_fun_online(ddf_fun_t *fun)
668{
669 ddf_msg(LVL_DEBUG, "isa_fun_online()");
670 return ddf_fun_online(fun);
671}
672
673static int isa_fun_offline(ddf_fun_t *fun)
674{
675 ddf_msg(LVL_DEBUG, "isa_fun_offline()");
676 return ddf_fun_offline(fun);
677}
678
679
[1a11a16]680static void isa_init()
[5dc9622]681{
[fc51296]682 ddf_log_init(NAME, LVL_ERROR);
[68414f4a]683 isa_fun_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops;
[5dc9622]684}
685
[892e4e1]686int main(int argc, char *argv[])
687{
[032e0bb]688 printf(NAME ": HelenOS ISA bus driver\n");
[5dc9622]689 isa_init();
[83a2f43]690 return ddf_driver_main(&isa_driver);
[892e4e1]691}
692
693/**
694 * @}
695 */
Note: See TracBrowser for help on using the repository browser.