[892e4e1] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Lenka Trochtova
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /**
|
---|
| 30 | * @defgroup isa ISA bus driver.
|
---|
| 31 | * @brief HelenOS ISA bus driver.
|
---|
| 32 | * @{
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | /** @file
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #include <assert.h>
|
---|
| 39 | #include <stdio.h>
|
---|
| 40 | #include <errno.h>
|
---|
| 41 | #include <bool.h>
|
---|
| 42 | #include <fibril_synch.h>
|
---|
| 43 | #include <stdlib.h>
|
---|
[c47e1a8] | 44 | #include <str.h>
|
---|
[892e4e1] | 45 | #include <ctype.h>
|
---|
| 46 | #include <macros.h>
|
---|
[c1a8ae52] | 47 | #include <malloc.h>
|
---|
| 48 | #include <dirent.h>
|
---|
| 49 | #include <fcntl.h>
|
---|
| 50 | #include <sys/stat.h>
|
---|
[892e4e1] | 51 |
|
---|
| 52 | #include <driver.h>
|
---|
[5dc9622] | 53 | #include <resource.h>
|
---|
| 54 |
|
---|
[892e4e1] | 55 | #include <devman.h>
|
---|
| 56 | #include <ipc/devman.h>
|
---|
[5dc9622] | 57 | #include <device/hw_res.h>
|
---|
[892e4e1] | 58 |
|
---|
| 59 | #define NAME "isa"
|
---|
[a79d88d] | 60 | #define CHILD_DEV_CONF_PATH "/drv/isa/isa.dev"
|
---|
[892e4e1] | 61 |
|
---|
[5dc9622] | 62 | #define ISA_MAX_HW_RES 4
|
---|
| 63 |
|
---|
| 64 | typedef struct isa_child_data {
|
---|
[032e0bb] | 65 | hw_resource_list_t hw_resources;
|
---|
[5dc9622] | 66 | } isa_child_data_t;
|
---|
| 67 |
|
---|
[032e0bb] | 68 | static hw_resource_list_t *isa_get_child_resources(device_t *dev)
|
---|
[5dc9622] | 69 | {
|
---|
[032e0bb] | 70 | isa_child_data_t *dev_data;
|
---|
| 71 |
|
---|
| 72 | dev_data = (isa_child_data_t *)dev->driver_data;
|
---|
| 73 | if (dev_data == NULL)
|
---|
[5dc9622] | 74 | return NULL;
|
---|
[032e0bb] | 75 |
|
---|
[5dc9622] | 76 | return &dev_data->hw_resources;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[032e0bb] | 79 | static bool isa_enable_child_interrupt(device_t *dev)
|
---|
[5dc9622] | 80 | {
|
---|
| 81 | // TODO
|
---|
[032e0bb] | 82 |
|
---|
[5dc9622] | 83 | return false;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | static resource_iface_t isa_child_res_iface = {
|
---|
| 87 | &isa_get_child_resources,
|
---|
[032e0bb] | 88 | &isa_enable_child_interrupt
|
---|
[5dc9622] | 89 | };
|
---|
| 90 |
|
---|
[5159ae9] | 91 | static device_ops_t isa_child_dev_ops;
|
---|
[5dc9622] | 92 |
|
---|
[df747b9c] | 93 | static int isa_add_device(device_t *dev);
|
---|
[892e4e1] | 94 |
|
---|
[032e0bb] | 95 | /** The isa device driver's standard operations */
|
---|
[892e4e1] | 96 | static driver_ops_t isa_ops = {
|
---|
| 97 | .add_device = &isa_add_device
|
---|
| 98 | };
|
---|
| 99 |
|
---|
[032e0bb] | 100 | /** The isa device driver structure. */
|
---|
[892e4e1] | 101 | static driver_t isa_driver = {
|
---|
| 102 | .name = NAME,
|
---|
| 103 | .driver_ops = &isa_ops
|
---|
| 104 | };
|
---|
| 105 |
|
---|
[c1a8ae52] | 106 |
|
---|
[032e0bb] | 107 | static isa_child_data_t *create_isa_child_data()
|
---|
[c1a8ae52] | 108 | {
|
---|
[032e0bb] | 109 | isa_child_data_t *data;
|
---|
| 110 |
|
---|
| 111 | data = (isa_child_data_t *) malloc(sizeof(isa_child_data_t));
|
---|
| 112 | if (data != NULL)
|
---|
| 113 | memset(data, 0, sizeof(isa_child_data_t));
|
---|
| 114 |
|
---|
| 115 | return data;
|
---|
[c1a8ae52] | 116 | }
|
---|
| 117 |
|
---|
[032e0bb] | 118 | static device_t *create_isa_child_dev()
|
---|
[c1a8ae52] | 119 | {
|
---|
| 120 | device_t *dev = create_device();
|
---|
[032e0bb] | 121 | if (dev == NULL)
|
---|
[c1a8ae52] | 122 | return NULL;
|
---|
[032e0bb] | 123 |
|
---|
[c1a8ae52] | 124 | isa_child_data_t *data = create_isa_child_data();
|
---|
[032e0bb] | 125 | if (data == NULL) {
|
---|
[c1a8ae52] | 126 | delete_device(dev);
|
---|
| 127 | return NULL;
|
---|
| 128 | }
|
---|
[032e0bb] | 129 |
|
---|
[c1a8ae52] | 130 | dev->driver_data = data;
|
---|
| 131 | return dev;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[032e0bb] | 134 | static char *read_dev_conf(const char *conf_path)
|
---|
| 135 | {
|
---|
| 136 | bool suc = false;
|
---|
[c1a8ae52] | 137 | char *buf = NULL;
|
---|
| 138 | bool opened = false;
|
---|
[032e0bb] | 139 | int fd;
|
---|
[c47e1a8] | 140 | size_t len = 0;
|
---|
[032e0bb] | 141 |
|
---|
[c1a8ae52] | 142 | fd = open(conf_path, O_RDONLY);
|
---|
| 143 | if (fd < 0) {
|
---|
| 144 | printf(NAME ": unable to open %s\n", conf_path);
|
---|
| 145 | goto cleanup;
|
---|
[032e0bb] | 146 | }
|
---|
| 147 |
|
---|
| 148 | opened = true;
|
---|
| 149 |
|
---|
[c1a8ae52] | 150 | len = lseek(fd, 0, SEEK_END);
|
---|
| 151 | lseek(fd, 0, SEEK_SET);
|
---|
| 152 | if (len == 0) {
|
---|
[032e0bb] | 153 | printf(NAME ": read_dev_conf error: configuration file '%s' "
|
---|
| 154 | "is empty.\n", conf_path);
|
---|
| 155 | goto cleanup;
|
---|
[c1a8ae52] | 156 | }
|
---|
[032e0bb] | 157 |
|
---|
[c1a8ae52] | 158 | buf = malloc(len + 1);
|
---|
| 159 | if (buf == NULL) {
|
---|
| 160 | printf(NAME ": read_dev_conf error: memory allocation failed.\n");
|
---|
| 161 | goto cleanup;
|
---|
[032e0bb] | 162 | }
|
---|
| 163 |
|
---|
[c1a8ae52] | 164 | if (0 >= read(fd, buf, len)) {
|
---|
[032e0bb] | 165 | printf(NAME ": read_dev_conf error: unable to read file '%s'.\n",
|
---|
| 166 | conf_path);
|
---|
[c1a8ae52] | 167 | goto cleanup;
|
---|
| 168 | }
|
---|
[032e0bb] | 169 |
|
---|
[c1a8ae52] | 170 | buf[len] = 0;
|
---|
[032e0bb] | 171 |
|
---|
[c1a8ae52] | 172 | suc = true;
|
---|
[032e0bb] | 173 |
|
---|
[c1a8ae52] | 174 | cleanup:
|
---|
[032e0bb] | 175 | if (!suc && buf != NULL) {
|
---|
| 176 | free(buf);
|
---|
[c1a8ae52] | 177 | buf = NULL;
|
---|
| 178 | }
|
---|
[032e0bb] | 179 |
|
---|
| 180 | if (opened)
|
---|
| 181 | close(fd);
|
---|
| 182 |
|
---|
| 183 | return buf;
|
---|
[c1a8ae52] | 184 | }
|
---|
| 185 |
|
---|
[032e0bb] | 186 | static char *str_get_line(char *str, char **next)
|
---|
| 187 | {
|
---|
[5dc9622] | 188 | char *line = str;
|
---|
[032e0bb] | 189 |
|
---|
| 190 | if (str == NULL) {
|
---|
[f928a8a] | 191 | *next = NULL;
|
---|
| 192 | return NULL;
|
---|
| 193 | }
|
---|
[032e0bb] | 194 |
|
---|
| 195 | while (*str != '\0' && *str != '\n') {
|
---|
[5dc9622] | 196 | str++;
|
---|
[032e0bb] | 197 | }
|
---|
| 198 |
|
---|
| 199 | if (*str != '\0') {
|
---|
[5dc9622] | 200 | *next = str + 1;
|
---|
| 201 | } else {
|
---|
| 202 | *next = NULL;
|
---|
[032e0bb] | 203 | }
|
---|
| 204 |
|
---|
| 205 | *str = '\0';
|
---|
[5dc9622] | 206 | return line;
|
---|
[c1a8ae52] | 207 | }
|
---|
| 208 |
|
---|
| 209 | static bool line_empty(const char *line)
|
---|
| 210 | {
|
---|
[032e0bb] | 211 | while (line != NULL && *line != 0) {
|
---|
| 212 | if (!isspace(*line))
|
---|
[c1a8ae52] | 213 | return false;
|
---|
[032e0bb] | 214 | line++;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | return true;
|
---|
[c1a8ae52] | 218 | }
|
---|
| 219 |
|
---|
[032e0bb] | 220 | static char *get_device_name(char *line)
|
---|
| 221 | {
|
---|
| 222 | /* Skip leading spaces. */
|
---|
| 223 | while (*line != '\0' && isspace(*line)) {
|
---|
[c1a8ae52] | 224 | line++;
|
---|
| 225 | }
|
---|
[032e0bb] | 226 |
|
---|
| 227 | /* Get the name part of the rest of the line. */
|
---|
| 228 | strtok(line, ":");
|
---|
| 229 |
|
---|
| 230 | /* Allocate output buffer. */
|
---|
[5dc9622] | 231 | size_t size = str_size(line) + 1;
|
---|
| 232 | char *name = malloc(size);
|
---|
[032e0bb] | 233 |
|
---|
| 234 | if (name != NULL) {
|
---|
| 235 | /* Copy the result to the output buffer. */
|
---|
[5dc9622] | 236 | str_cpy(name, size, line);
|
---|
[c1a8ae52] | 237 | }
|
---|
| 238 |
|
---|
| 239 | return name;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
[032e0bb] | 242 | static inline char *skip_spaces(char *line)
|
---|
[c1a8ae52] | 243 | {
|
---|
[032e0bb] | 244 | /* Skip leading spaces. */
|
---|
| 245 | while (*line != '\0' && isspace(*line))
|
---|
[c1a8ae52] | 246 | line++;
|
---|
| 247 |
|
---|
[032e0bb] | 248 | return line;
|
---|
| 249 | }
|
---|
[c1a8ae52] | 250 |
|
---|
[5dc9622] | 251 | static void isa_child_set_irq(device_t *dev, int irq)
|
---|
[c1a8ae52] | 252 | {
|
---|
[5dc9622] | 253 | isa_child_data_t *data = (isa_child_data_t *)dev->driver_data;
|
---|
[032e0bb] | 254 |
|
---|
[5dc9622] | 255 | size_t count = data->hw_resources.count;
|
---|
| 256 | hw_resource_t *resources = data->hw_resources.resources;
|
---|
[032e0bb] | 257 |
|
---|
[5dc9622] | 258 | if (count < ISA_MAX_HW_RES) {
|
---|
| 259 | resources[count].type = INTERRUPT;
|
---|
| 260 | resources[count].res.interrupt.irq = irq;
|
---|
[032e0bb] | 261 |
|
---|
[5dc9622] | 262 | data->hw_resources.count++;
|
---|
[032e0bb] | 263 |
|
---|
[f928a8a] | 264 | printf(NAME ": added irq 0x%x to device %s\n", irq, dev->name);
|
---|
[032e0bb] | 265 | }
|
---|
[5dc9622] | 266 | }
|
---|
| 267 |
|
---|
| 268 | static void isa_child_set_io_range(device_t *dev, size_t addr, size_t len)
|
---|
| 269 | {
|
---|
| 270 | isa_child_data_t *data = (isa_child_data_t *)dev->driver_data;
|
---|
[032e0bb] | 271 |
|
---|
[5dc9622] | 272 | size_t count = data->hw_resources.count;
|
---|
| 273 | hw_resource_t *resources = data->hw_resources.resources;
|
---|
[032e0bb] | 274 |
|
---|
[5dc9622] | 275 | if (count < ISA_MAX_HW_RES) {
|
---|
| 276 | resources[count].type = IO_RANGE;
|
---|
| 277 | resources[count].res.io_range.address = addr;
|
---|
| 278 | resources[count].res.io_range.size = len;
|
---|
[032e0bb] | 279 | resources[count].res.io_range.endianness = LITTLE_ENDIAN;
|
---|
| 280 |
|
---|
[5dc9622] | 281 | data->hw_resources.count++;
|
---|
[032e0bb] | 282 |
|
---|
| 283 | printf(NAME ": added io range (addr=0x%x, size=0x%x) to "
|
---|
| 284 | "device %s\n", addr, len, dev->name);
|
---|
| 285 | }
|
---|
[c1a8ae52] | 286 | }
|
---|
| 287 |
|
---|
| 288 | static void get_dev_irq(device_t *dev, char *val)
|
---|
| 289 | {
|
---|
| 290 | int irq = 0;
|
---|
| 291 | char *end = NULL;
|
---|
[032e0bb] | 292 |
|
---|
[c1a8ae52] | 293 | val = skip_spaces(val);
|
---|
[5dc9622] | 294 | irq = (int)strtol(val, &end, 0x10);
|
---|
[032e0bb] | 295 |
|
---|
| 296 | if (val != end)
|
---|
| 297 | isa_child_set_irq(dev, irq);
|
---|
[c1a8ae52] | 298 | }
|
---|
| 299 |
|
---|
| 300 | static void get_dev_io_range(device_t *dev, char *val)
|
---|
| 301 | {
|
---|
[5dc9622] | 302 | size_t addr, len;
|
---|
| 303 | char *end = NULL;
|
---|
[032e0bb] | 304 |
|
---|
[5dc9622] | 305 | val = skip_spaces(val);
|
---|
| 306 | addr = strtol(val, &end, 0x10);
|
---|
[032e0bb] | 307 |
|
---|
| 308 | if (val == end)
|
---|
[5dc9622] | 309 | return;
|
---|
[032e0bb] | 310 |
|
---|
[5dc9622] | 311 | val = skip_spaces(end);
|
---|
| 312 | len = strtol(val, &end, 0x10);
|
---|
[032e0bb] | 313 |
|
---|
| 314 | if (val == end)
|
---|
[5dc9622] | 315 | return;
|
---|
[032e0bb] | 316 |
|
---|
[5dc9622] | 317 | isa_child_set_io_range(dev, addr, len);
|
---|
[c1a8ae52] | 318 | }
|
---|
| 319 |
|
---|
[5dc9622] | 320 | static void get_match_id(char **id, char *val)
|
---|
[c1a8ae52] | 321 | {
|
---|
[5dc9622] | 322 | char *end = val;
|
---|
[032e0bb] | 323 |
|
---|
| 324 | while (!isspace(*end))
|
---|
[5dc9622] | 325 | end++;
|
---|
[032e0bb] | 326 |
|
---|
[f928a8a] | 327 | size_t size = end - val + 1;
|
---|
[5dc9622] | 328 | *id = (char *)malloc(size);
|
---|
[032e0bb] | 329 | str_cpy(*id, size, val);
|
---|
[5dc9622] | 330 | }
|
---|
| 331 |
|
---|
| 332 | static void get_dev_match_id(device_t *dev, char *val)
|
---|
[032e0bb] | 333 | {
|
---|
[5dc9622] | 334 | char *id = NULL;
|
---|
| 335 | int score = 0;
|
---|
| 336 | char *end = NULL;
|
---|
[032e0bb] | 337 |
|
---|
[5dc9622] | 338 | val = skip_spaces(val);
|
---|
[032e0bb] | 339 |
|
---|
[5fe1c32] | 340 | score = (int)strtol(val, &end, 10);
|
---|
[5dc9622] | 341 | if (val == end) {
|
---|
[032e0bb] | 342 | printf(NAME " : error - could not read match score for "
|
---|
| 343 | "device %s.\n", dev->name);
|
---|
[5dc9622] | 344 | return;
|
---|
| 345 | }
|
---|
[032e0bb] | 346 |
|
---|
[5dc9622] | 347 | match_id_t *match_id = create_match_id();
|
---|
[032e0bb] | 348 | if (match_id == NULL) {
|
---|
| 349 | printf(NAME " : failed to allocate match id for device %s.\n",
|
---|
| 350 | dev->name);
|
---|
[5dc9622] | 351 | return;
|
---|
| 352 | }
|
---|
[032e0bb] | 353 |
|
---|
[5dc9622] | 354 | val = skip_spaces(end);
|
---|
| 355 | get_match_id(&id, val);
|
---|
[032e0bb] | 356 | if (id == NULL) {
|
---|
| 357 | printf(NAME " : error - could not read match id for "
|
---|
| 358 | "device %s.\n", dev->name);
|
---|
[5dc9622] | 359 | delete_match_id(match_id);
|
---|
| 360 | return;
|
---|
| 361 | }
|
---|
[032e0bb] | 362 |
|
---|
[5dc9622] | 363 | match_id->id = id;
|
---|
| 364 | match_id->score = score;
|
---|
[032e0bb] | 365 |
|
---|
| 366 | printf(NAME ": adding match id '%s' with score %d to device %s\n", id,
|
---|
| 367 | score, dev->name);
|
---|
[5dc9622] | 368 | add_match_id(&dev->match_ids, match_id);
|
---|
[c1a8ae52] | 369 | }
|
---|
| 370 |
|
---|
[032e0bb] | 371 | static bool read_dev_prop(device_t *dev, char *line, const char *prop,
|
---|
| 372 | void (*read_fn)(device_t *, char *))
|
---|
[5fe1c32] | 373 | {
|
---|
| 374 | size_t proplen = str_size(prop);
|
---|
[032e0bb] | 375 |
|
---|
| 376 | if (str_lcmp(line, prop, proplen) == 0) {
|
---|
[5fe1c32] | 377 | line += proplen;
|
---|
| 378 | line = skip_spaces(line);
|
---|
| 379 | (*read_fn)(dev, line);
|
---|
[032e0bb] | 380 |
|
---|
[5fe1c32] | 381 | return true;
|
---|
| 382 | }
|
---|
[032e0bb] | 383 |
|
---|
| 384 | return false;
|
---|
[5fe1c32] | 385 | }
|
---|
| 386 |
|
---|
[c1a8ae52] | 387 | static void get_dev_prop(device_t *dev, char *line)
|
---|
| 388 | {
|
---|
[032e0bb] | 389 | /* Skip leading spaces. */
|
---|
[c1a8ae52] | 390 | line = skip_spaces(line);
|
---|
[032e0bb] | 391 |
|
---|
[5fe1c32] | 392 | if (!read_dev_prop(dev, line, "io_range", &get_dev_io_range) &&
|
---|
[032e0bb] | 393 | !read_dev_prop(dev, line, "irq", &get_dev_irq) &&
|
---|
| 394 | !read_dev_prop(dev, line, "match", &get_dev_match_id))
|
---|
| 395 | {
|
---|
| 396 | printf(NAME " error undefined device property at line '%s'\n",
|
---|
| 397 | line);
|
---|
| 398 | }
|
---|
[c1a8ae52] | 399 | }
|
---|
| 400 |
|
---|
[032e0bb] | 401 | static void child_alloc_hw_res(device_t *dev)
|
---|
[5dc9622] | 402 | {
|
---|
| 403 | isa_child_data_t *data = (isa_child_data_t *)dev->driver_data;
|
---|
| 404 | data->hw_resources.resources =
|
---|
[032e0bb] | 405 | (hw_resource_t *)malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES);
|
---|
[5dc9622] | 406 | }
|
---|
| 407 |
|
---|
[032e0bb] | 408 | static char *read_isa_dev_info(char *dev_conf, device_t *parent)
|
---|
[c1a8ae52] | 409 | {
|
---|
| 410 | char *line;
|
---|
| 411 | char *dev_name = NULL;
|
---|
[032e0bb] | 412 |
|
---|
| 413 | /* Skip empty lines. */
|
---|
| 414 | while (true) {
|
---|
[5dc9622] | 415 | line = str_get_line(dev_conf, &dev_conf);
|
---|
[032e0bb] | 416 |
|
---|
| 417 | if (line == NULL) {
|
---|
| 418 | /* no more lines */
|
---|
[c1a8ae52] | 419 | return NULL;
|
---|
| 420 | }
|
---|
[032e0bb] | 421 |
|
---|
| 422 | if (!line_empty(line))
|
---|
[c1a8ae52] | 423 | break;
|
---|
| 424 | }
|
---|
[032e0bb] | 425 |
|
---|
| 426 | /* Get device name. */
|
---|
[c1a8ae52] | 427 | dev_name = get_device_name(line);
|
---|
[032e0bb] | 428 | if (dev_name == NULL)
|
---|
[c1a8ae52] | 429 | return NULL;
|
---|
[032e0bb] | 430 |
|
---|
[c1a8ae52] | 431 | device_t *dev = create_isa_child_dev();
|
---|
[032e0bb] | 432 | if (dev == NULL) {
|
---|
[c1a8ae52] | 433 | free(dev_name);
|
---|
| 434 | return NULL;
|
---|
| 435 | }
|
---|
[032e0bb] | 436 |
|
---|
[c1a8ae52] | 437 | dev->name = dev_name;
|
---|
[032e0bb] | 438 |
|
---|
| 439 | /* Allocate buffer for the list of hardware resources of the device. */
|
---|
[5dc9622] | 440 | child_alloc_hw_res(dev);
|
---|
[032e0bb] | 441 |
|
---|
| 442 | /* Get properties of the device (match ids, irq and io range). */
|
---|
| 443 | while (true) {
|
---|
| 444 | line = str_get_line(dev_conf, &dev_conf);
|
---|
| 445 |
|
---|
[5dc9622] | 446 | if (line_empty(line)) {
|
---|
[032e0bb] | 447 | /* no more device properties */
|
---|
[5dc9622] | 448 | break;
|
---|
| 449 | }
|
---|
[032e0bb] | 450 |
|
---|
| 451 | /*
|
---|
| 452 | * Get the device's property from the configuration line
|
---|
| 453 | * and store it in the device structure.
|
---|
| 454 | */
|
---|
[5dc9622] | 455 | get_dev_prop(dev, line);
|
---|
[032e0bb] | 456 |
|
---|
[f928a8a] | 457 | //printf(NAME ": next line ='%s'\n", dev_conf);
|
---|
[032e0bb] | 458 | //printf(NAME ": current line ='%s'\n", line);
|
---|
[c1a8ae52] | 459 | }
|
---|
[032e0bb] | 460 |
|
---|
| 461 | /* Set device operations to the device. */
|
---|
[5159ae9] | 462 | dev->ops = &isa_child_dev_ops;
|
---|
[032e0bb] | 463 |
|
---|
| 464 | printf(NAME ": child_device_register(dev, parent); device is %s.\n",
|
---|
| 465 | dev->name);
|
---|
| 466 | child_device_register(dev, parent);
|
---|
| 467 |
|
---|
| 468 | return dev_conf;
|
---|
[c1a8ae52] | 469 | }
|
---|
| 470 |
|
---|
[c47e1a8] | 471 | static void parse_dev_conf(char *conf, device_t *parent)
|
---|
[c1a8ae52] | 472 | {
|
---|
[032e0bb] | 473 | while (conf != NULL && *conf != '\0') {
|
---|
[c1a8ae52] | 474 | conf = read_isa_dev_info(conf, parent);
|
---|
[032e0bb] | 475 | }
|
---|
[c1a8ae52] | 476 | }
|
---|
| 477 |
|
---|
| 478 | static void add_legacy_children(device_t *parent)
|
---|
| 479 | {
|
---|
[032e0bb] | 480 | char *dev_conf;
|
---|
| 481 |
|
---|
| 482 | dev_conf = read_dev_conf(CHILD_DEV_CONF_PATH);
|
---|
| 483 | if (dev_conf != NULL) {
|
---|
| 484 | parse_dev_conf(dev_conf, parent);
|
---|
[c1a8ae52] | 485 | free(dev_conf);
|
---|
| 486 | }
|
---|
| 487 | }
|
---|
[892e4e1] | 488 |
|
---|
[032e0bb] | 489 | static int isa_add_device(device_t *dev)
|
---|
[892e4e1] | 490 | {
|
---|
| 491 | printf(NAME ": isa_add_device, device handle = %d\n", dev->handle);
|
---|
[032e0bb] | 492 |
|
---|
| 493 | /* Add child devices. */
|
---|
[c1a8ae52] | 494 | add_legacy_children(dev);
|
---|
[7e752b2] | 495 | printf(NAME ": finished the enumeration of legacy devices\n");
|
---|
[032e0bb] | 496 |
|
---|
[df747b9c] | 497 | return EOK;
|
---|
[892e4e1] | 498 | }
|
---|
| 499 |
|
---|
[5dc9622] | 500 | static void isa_init()
|
---|
| 501 | {
|
---|
[5159ae9] | 502 | isa_child_dev_ops.interfaces[HW_RES_DEV_IFACE] = &isa_child_res_iface;
|
---|
[5dc9622] | 503 | }
|
---|
| 504 |
|
---|
[892e4e1] | 505 | int main(int argc, char *argv[])
|
---|
| 506 | {
|
---|
[032e0bb] | 507 | printf(NAME ": HelenOS ISA bus driver\n");
|
---|
[5dc9622] | 508 | isa_init();
|
---|
[892e4e1] | 509 | return driver_main(&isa_driver);
|
---|
| 510 | }
|
---|
| 511 |
|
---|
| 512 | /**
|
---|
| 513 | * @}
|
---|
| 514 | */
|
---|
| 515 | |
---|