Changes in uspace/drv/bus/isa/isa.c [9e470c0:3e6a98c5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/isa/isa.c
r9e470c0 r3e6a98c5 65 65 #include <ddf/log.h> 66 66 #include <ops/hw_res.h> 67 #include <ops/pio_window.h>68 67 69 68 #include <device/hw_res.h> 70 #include <device/pio_window.h>71 69 72 70 #include "i8237.h" … … 81 79 ddf_dev_t *dev; 82 80 ddf_fun_t *fctl; 83 pio_window_t pio_win;84 81 list_t functions; 85 82 } isa_bus_t; … … 88 85 fibril_mutex_t mutex; 89 86 ddf_fun_t *fnode; 90 hw_resource_t resources[ISA_MAX_HW_RES];91 87 hw_resource_list_t hw_resources; 92 88 link_t bus_link; … … 105 101 } 106 102 107 static hw_resource_list_t *isa_ fun_get_resources(ddf_fun_t *fnode)103 static hw_resource_list_t *isa_get_fun_resources(ddf_fun_t *fnode) 108 104 { 109 105 isa_fun_t *fun = isa_fun(fnode); 110 assert(fun );106 assert(fun != NULL); 111 107 112 108 return &fun->hw_resources; 113 109 } 114 110 115 static bool isa_ fun_enable_interrupt(ddf_fun_t *fnode)111 static bool isa_enable_fun_interrupt(ddf_fun_t *fnode) 116 112 { 117 113 /* This is an old ugly way, copied from pci driver */ 118 114 assert(fnode); 119 115 isa_fun_t *fun = isa_fun(fnode); 120 assert(fun);121 116 122 117 sysarg_t apic; … … 156 151 } 157 152 158 static int isa_ fun_setup_dma(ddf_fun_t *fnode,159 unsigned int channel, uint32_t pa, uint 32_t size, uint8_t mode)153 static int isa_dma_channel_fun_setup(ddf_fun_t *fnode, 154 unsigned int channel, uint32_t pa, uint16_t size, uint8_t mode) 160 155 { 161 156 assert(fnode); 162 157 isa_fun_t *fun = isa_fun(fnode); 163 assert(fun);164 158 const hw_resource_list_t *res = &fun->hw_resources; 165 159 assert(res); 166 160 161 const unsigned int ch = channel; 167 162 for (size_t i = 0; i < res->count; ++i) { 168 /* Check for assigned channel */169 163 if (((res->resources[i].type == DMA_CHANNEL_16) && 170 (res->resources[i].res.dma_channel.dma16 == ch annel)) ||164 (res->resources[i].res.dma_channel.dma16 == ch)) || 171 165 ((res->resources[i].type == DMA_CHANNEL_8) && 172 (res->resources[i].res.dma_channel.dma8 == ch annel))) {173 return dma_ channel_setup(channel, pa, size, mode);166 (res->resources[i].res.dma_channel.dma8 == ch))) { 167 return dma_setup_channel(channel, pa, size, mode); 174 168 } 175 169 } 176 170 177 171 return EINVAL; 178 172 } 179 173 180 static int isa_fun_remain_dma(ddf_fun_t *fnode,181 unsigned channel, size_t *size)182 {183 assert(size);184 assert(fnode);185 isa_fun_t *fun = isa_fun(fnode);186 assert(fun);187 const hw_resource_list_t *res = &fun->hw_resources;188 assert(res);189 190 for (size_t i = 0; i < res->count; ++i) {191 /* Check for assigned channel */192 if (((res->resources[i].type == DMA_CHANNEL_16) &&193 (res->resources[i].res.dma_channel.dma16 == channel)) ||194 ((res->resources[i].type == DMA_CHANNEL_8) &&195 (res->resources[i].res.dma_channel.dma8 == channel))) {196 return dma_channel_remain(channel, size);197 }198 }199 200 return EINVAL;201 }202 203 174 static hw_res_ops_t isa_fun_hw_res_ops = { 204 .get_resource_list = isa_fun_get_resources, 205 .enable_interrupt = isa_fun_enable_interrupt, 206 .dma_channel_setup = isa_fun_setup_dma, 207 .dma_channel_remain = isa_fun_remain_dma, 175 .get_resource_list = isa_get_fun_resources, 176 .enable_interrupt = isa_enable_fun_interrupt, 177 .dma_channel_setup = isa_dma_channel_fun_setup, 208 178 }; 209 179 210 static pio_window_t *isa_fun_get_pio_window(ddf_fun_t *fnode) 211 { 212 ddf_dev_t *dev = ddf_fun_get_dev(fnode); 213 isa_bus_t *isa = isa_bus(dev); 214 assert(isa); 215 216 return &isa->pio_win; 217 } 218 219 static pio_window_ops_t isa_fun_pio_window_ops = { 220 .get_pio_window = isa_fun_get_pio_window 221 }; 222 223 static ddf_dev_ops_t isa_fun_ops= { 224 .interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops, 225 .interfaces[PIO_WINDOW_DEV_IFACE] = &isa_fun_pio_window_ops, 226 }; 180 static ddf_dev_ops_t isa_fun_ops; 227 181 228 182 static int isa_dev_add(ddf_dev_t *dev); … … 258 212 259 213 fibril_mutex_initialize(&fun->mutex); 260 fun->hw_resources.resources = fun->resources;261 262 214 fun->fnode = fnode; 263 215 return fun; … … 318 270 { 319 271 char *line = str; 320 *next = NULL;321 272 322 273 if (str == NULL) { 274 *next = NULL; 323 275 return NULL; 324 276 } … … 330 282 if (*str != '\0') { 331 283 *next = str + 1; 284 } else { 285 *next = NULL; 332 286 } 333 287 … … 356 310 /* Get the name part of the rest of the line. */ 357 311 strtok(line, ":"); 358 return line; 359 } 360 361 static inline const char *skip_spaces(const char *line) 312 313 /* Allocate output buffer. */ 314 size_t size = str_size(line) + 1; 315 char *name = malloc(size); 316 317 if (name != NULL) { 318 /* Copy the result to the output buffer. */ 319 str_cpy(name, size, line); 320 } 321 322 return name; 323 } 324 325 static inline char *skip_spaces(char *line) 362 326 { 363 327 /* Skip leading spaces. */ … … 368 332 } 369 333 370 static void isa_fun_ add_irq(isa_fun_t *fun, int irq)334 static void isa_fun_set_irq(isa_fun_t *fun, int irq) 371 335 { 372 336 size_t count = fun->hw_resources.count; … … 384 348 } 385 349 386 static void isa_fun_ add_dma(isa_fun_t *fun, int dma)350 static void isa_fun_set_dma(isa_fun_t *fun, int dma) 387 351 { 388 352 size_t count = fun->hw_resources.count; … … 417 381 } 418 382 419 static void isa_fun_ add_io_range(isa_fun_t *fun, size_t addr, size_t len)383 static void isa_fun_set_io_range(isa_fun_t *fun, size_t addr, size_t len) 420 384 { 421 385 size_t count = fun->hw_resources.count; 422 386 hw_resource_t *resources = fun->hw_resources.resources; 423 424 isa_bus_t *isa = isa_bus(ddf_fun_get_dev(fun->fnode));425 387 426 388 if (count < ISA_MAX_HW_RES) { 427 389 resources[count].type = IO_RANGE; 428 390 resources[count].res.io_range.address = addr; 429 resources[count].res.io_range.address += isa->pio_win.io.base;430 391 resources[count].res.io_range.size = len; 431 resources[count].res.io_range.relative = false;432 392 resources[count].res.io_range.endianness = LITTLE_ENDIAN; 433 393 … … 440 400 } 441 401 442 static void fun_parse_irq(isa_fun_t *fun, c onst char *val)402 static void fun_parse_irq(isa_fun_t *fun, char *val) 443 403 { 444 404 int irq = 0; … … 449 409 450 410 if (val != end) 451 isa_fun_add_irq(fun, irq); 452 } 453 454 static void fun_parse_dma(isa_fun_t *fun, const char *val) 455 { 411 isa_fun_set_irq(fun, irq); 412 } 413 414 static void fun_parse_dma(isa_fun_t *fun, char *val) 415 { 416 unsigned int dma = 0; 456 417 char *end = NULL; 457 418 458 419 val = skip_spaces(val); 459 const int dma =strtol(val, &end, 10);420 dma = (unsigned int) strtol(val, &end, 10); 460 421 461 422 if (val != end) 462 isa_fun_ add_dma(fun, dma);463 } 464 465 static void fun_parse_io_range(isa_fun_t *fun, c onst char *val)423 isa_fun_set_dma(fun, dma); 424 } 425 426 static void fun_parse_io_range(isa_fun_t *fun, char *val) 466 427 { 467 428 size_t addr, len; … … 480 441 return; 481 442 482 isa_fun_ add_io_range(fun, addr, len);483 } 484 485 static void get_match_id(char **id, c onst char *val)486 { 487 c onst char *end = val;443 isa_fun_set_io_range(fun, addr, len); 444 } 445 446 static void get_match_id(char **id, char *val) 447 { 448 char *end = val; 488 449 489 450 while (!isspace(*end)) … … 495 456 } 496 457 497 static void fun_parse_match_id(isa_fun_t *fun, c onst char *val)458 static void fun_parse_match_id(isa_fun_t *fun, char *val) 498 459 { 499 460 char *id = NULL; 461 int score = 0; 500 462 char *end = NULL; 463 int rc; 501 464 502 465 val = skip_spaces(val); 503 466 504 intscore = (int)strtol(val, &end, 10);467 score = (int)strtol(val, &end, 10); 505 468 if (val == end) { 506 469 ddf_msg(LVL_ERROR, "Cannot read match score for function " … … 520 483 "function %s", id, score, ddf_fun_get_name(fun->fnode)); 521 484 522 intrc = ddf_fun_add_match_id(fun->fnode, id, score);485 rc = ddf_fun_add_match_id(fun->fnode, id, score); 523 486 if (rc != EOK) { 524 487 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", … … 529 492 } 530 493 531 static bool prop_parse(isa_fun_t *fun, c onst char *line, const char *prop,532 void (*read_fn)(isa_fun_t *, c onst char *))494 static bool prop_parse(isa_fun_t *fun, char *line, const char *prop, 495 void (*read_fn)(isa_fun_t *, char *)) 533 496 { 534 497 size_t proplen = str_size(prop); … … 545 508 } 546 509 547 static void fun_prop_parse(isa_fun_t *fun, c onst char *line)510 static void fun_prop_parse(isa_fun_t *fun, char *line) 548 511 { 549 512 /* Skip leading spaces. */ … … 560 523 } 561 524 525 static void fun_hw_res_alloc(isa_fun_t *fun) 526 { 527 fun->hw_resources.resources = 528 (hw_resource_t *) malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES); 529 } 530 531 static void fun_hw_res_free(isa_fun_t *fun) 532 { 533 free(fun->hw_resources.resources); 534 fun->hw_resources.resources = NULL; 535 } 536 562 537 static char *isa_fun_read_info(char *fun_conf, isa_bus_t *isa) 563 538 { 564 539 char *line; 540 char *fun_name = NULL; 565 541 566 542 /* Skip empty lines. */ 567 do{543 while (true) { 568 544 line = str_get_line(fun_conf, &fun_conf); 569 545 … … 573 549 } 574 550 575 } while (line_empty(line)); 551 if (!line_empty(line)) 552 break; 553 } 576 554 577 555 /* Get device name. */ 578 const char *fun_name = get_device_name(line);556 fun_name = get_device_name(line); 579 557 if (fun_name == NULL) 580 558 return NULL; 581 559 582 560 isa_fun_t *fun = isa_fun_create(isa, fun_name); 561 free(fun_name); 583 562 if (fun == NULL) { 584 563 return NULL; 585 564 } 565 566 /* Allocate buffer for the list of hardware resources of the device. */ 567 fun_hw_res_alloc(fun); 586 568 587 569 /* Get properties of the device (match ids, irq and io range). */ … … 614 596 } 615 597 616 static void isa_functions_add(isa_bus_t *isa) 617 { 618 char *conf = fun_conf_read(CHILD_FUN_CONF_PATH); 598 static void fun_conf_parse(char *conf, isa_bus_t *isa) 599 { 619 600 while (conf != NULL && *conf != '\0') { 620 601 conf = isa_fun_read_info(conf, isa); 621 602 } 622 free(conf); 603 } 604 605 static void isa_functions_add(isa_bus_t *isa) 606 { 607 char *fun_conf; 608 609 fun_conf = fun_conf_read(CHILD_FUN_CONF_PATH); 610 if (fun_conf != NULL) { 611 fun_conf_parse(fun_conf, isa); 612 free(fun_conf); 613 } 623 614 } 624 615 625 616 static int isa_dev_add(ddf_dev_t *dev) 626 617 { 627 async_sess_t *sess; 628 int rc; 618 isa_bus_t *isa; 629 619 630 620 ddf_msg(LVL_DEBUG, "isa_dev_add, device handle = %d", 631 621 (int) ddf_dev_get_handle(dev)); 632 622 633 isa _bus_t *isa= ddf_dev_data_alloc(dev, sizeof(isa_bus_t));623 isa = ddf_dev_data_alloc(dev, sizeof(isa_bus_t)); 634 624 if (isa == NULL) 635 625 return ENOMEM; … … 638 628 isa->dev = dev; 639 629 list_initialize(&isa->functions); 640 641 sess = ddf_dev_parent_sess_create(dev, EXCHANGE_SERIALIZE);642 if (sess == NULL) {643 ddf_msg(LVL_ERROR, "isa_dev_add failed to connect to the "644 "parent driver.");645 return ENOENT;646 }647 648 rc = pio_window_get(sess, &isa->pio_win);649 if (rc != EOK) {650 ddf_msg(LVL_ERROR, "isa_dev_add failed to get PIO window "651 "for the device.");652 return rc;653 }654 630 655 631 /* Make the bus device more visible. Does not do anything. */ … … 682 658 { 683 659 isa_bus_t *isa = isa_bus(dev); 660 int rc; 684 661 685 662 fibril_mutex_lock(&isa->mutex); … … 689 666 isa_fun_t, bus_link); 690 667 691 intrc = ddf_fun_offline(fun->fnode);668 rc = ddf_fun_offline(fun->fnode); 692 669 if (rc != EOK) { 693 670 fibril_mutex_unlock(&isa->mutex); … … 705 682 list_remove(&fun->bus_link); 706 683 684 fun_hw_res_free(fun); 707 685 ddf_fun_destroy(fun->fnode); 708 686 } … … 731 709 } 732 710 711 712 static void isa_init() 713 { 714 ddf_log_init(NAME); 715 isa_fun_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops; 716 } 717 733 718 int main(int argc, char *argv[]) 734 719 { 735 720 printf(NAME ": HelenOS ISA bus driver\n"); 736 ddf_log_init(NAME);721 isa_init(); 737 722 return ddf_driver_main(&isa_driver); 738 723 }
Note:
See TracChangeset
for help on using the changeset viewer.