Changeset 3a0a4d8 in mainline for uspace/drv/bus/isa/isa.c
- Timestamp:
- 2013-09-12T07:54:05Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 95027b5
- Parents:
- 47f5a77 (diff), 64f3d3b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
uspace/drv/bus/isa/isa.c (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/isa/isa.c
r47f5a77 r3a0a4d8 67 67 68 68 #include <device/hw_res.h> 69 #include <device/pio_window.h> 69 70 70 71 #include "i8237.h" … … 79 80 ddf_dev_t *dev; 80 81 ddf_fun_t *fctl; 82 pio_window_t pio_win; 81 83 list_t functions; 82 84 } isa_bus_t; … … 85 87 fibril_mutex_t mutex; 86 88 ddf_fun_t *fnode; 89 hw_resource_t resources[ISA_MAX_HW_RES]; 87 90 hw_resource_list_t hw_resources; 88 91 link_t bus_link; … … 103 106 static hw_resource_list_t *isa_get_fun_resources(ddf_fun_t *fnode) 104 107 { 105 isa_fun_t * fun= isa_fun(fnode);106 assert( fun != NULL);107 108 return & fun->hw_resources;109 } 110 111 static bool isa_ enable_fun_interrupt(ddf_fun_t *fnode)108 isa_fun_t *isa = isa_fun(fnode); 109 assert(isa); 110 111 return &isa->hw_resources; 112 } 113 114 static bool isa_fun_enable_interrupt(ddf_fun_t *fnode) 112 115 { 113 116 /* This is an old ugly way, copied from pci driver */ 114 117 assert(fnode); 115 isa_fun_t *fun = isa_fun(fnode); 118 isa_fun_t *isa = isa_fun(fnode); 119 assert(isa); 116 120 117 121 sysarg_t apic; … … 129 133 return false; 130 134 131 const hw_resource_list_t *res = & fun->hw_resources;135 const hw_resource_list_t *res = &isa->hw_resources; 132 136 assert(res); 133 137 for (size_t i = 0; i < res->count; ++i) { … … 151 155 } 152 156 153 static int isa_ dma_channel_fun_setup(ddf_fun_t *fnode,154 unsigned int channel, uint32_t pa, uint 16_t size, uint8_t mode)157 static int isa_fun_setup_dma(ddf_fun_t *fnode, 158 unsigned int channel, uint32_t pa, uint32_t size, uint8_t mode) 155 159 { 156 160 assert(fnode); 157 isa_fun_t *fun = isa_fun(fnode); 158 const hw_resource_list_t *res = &fun->hw_resources; 161 isa_fun_t *isa = isa_fun(fnode); 162 assert(isa); 163 const hw_resource_list_t *res = &isa->hw_resources; 159 164 assert(res); 160 161 const unsigned int ch = channel; 165 162 166 for (size_t i = 0; i < res->count; ++i) { 167 /* Check for assigned channel */ 163 168 if (((res->resources[i].type == DMA_CHANNEL_16) && 164 (res->resources[i].res.dma_channel.dma16 == ch )) ||169 (res->resources[i].res.dma_channel.dma16 == channel)) || 165 170 ((res->resources[i].type == DMA_CHANNEL_8) && 166 (res->resources[i].res.dma_channel.dma8 == ch))) { 167 return dma_setup_channel(channel, pa, size, mode); 168 } 169 } 170 171 (res->resources[i].res.dma_channel.dma8 == channel))) { 172 return dma_channel_setup(channel, pa, size, mode); 173 } 174 } 175 176 return EINVAL; 177 } 178 179 static int isa_fun_remain_dma(ddf_fun_t *fnode, 180 unsigned channel, size_t *size) 181 { 182 assert(size); 183 assert(fnode); 184 isa_fun_t *isa = isa_fun(fnode); 185 assert(isa); 186 const hw_resource_list_t *res = &isa->hw_resources; 187 assert(res); 188 189 for (size_t i = 0; i < res->count; ++i) { 190 /* Check for assigned channel */ 191 if (((res->resources[i].type == DMA_CHANNEL_16) && 192 (res->resources[i].res.dma_channel.dma16 == channel)) || 193 ((res->resources[i].type == DMA_CHANNEL_8) && 194 (res->resources[i].res.dma_channel.dma8 == channel))) { 195 return dma_channel_remain(channel, size); 196 } 197 } 198 171 199 return EINVAL; 172 200 } … … 174 202 static hw_res_ops_t isa_fun_hw_res_ops = { 175 203 .get_resource_list = isa_get_fun_resources, 176 .enable_interrupt = isa_enable_fun_interrupt, 177 .dma_channel_setup = isa_dma_channel_fun_setup, 204 .enable_interrupt = isa_fun_enable_interrupt, 205 .dma_channel_setup = isa_fun_setup_dma, 206 .dma_channel_remain = isa_fun_remain_dma, 178 207 }; 179 208 180 static ddf_dev_ops_t isa_fun_ops; 209 static ddf_dev_ops_t isa_fun_ops= { 210 .interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops, 211 }; 181 212 182 213 static int isa_dev_add(ddf_dev_t *dev); … … 212 243 213 244 fibril_mutex_initialize(&fun->mutex); 245 fun->hw_resources.resources = fun->resources; 246 214 247 fun->fnode = fnode; 215 248 return fun; … … 270 303 { 271 304 char *line = str; 305 *next = NULL; 272 306 273 307 if (str == NULL) { 274 *next = NULL;275 308 return NULL; 276 309 } … … 282 315 if (*str != '\0') { 283 316 *next = str + 1; 284 } else {285 *next = NULL;286 317 } 287 318 … … 310 341 /* Get the name part of the rest of the line. */ 311 342 strtok(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) 343 return line; 344 } 345 346 static inline const char *skip_spaces(const char *line) 326 347 { 327 348 /* Skip leading spaces. */ … … 332 353 } 333 354 334 static void isa_fun_ set_irq(isa_fun_t *fun, int irq)355 static void isa_fun_add_irq(isa_fun_t *fun, int irq) 335 356 { 336 357 size_t count = fun->hw_resources.count; … … 348 369 } 349 370 350 static void isa_fun_ set_dma(isa_fun_t *fun, int dma)371 static void isa_fun_add_dma(isa_fun_t *fun, int dma) 351 372 { 352 373 size_t count = fun->hw_resources.count; … … 381 402 } 382 403 383 static void isa_fun_ set_io_range(isa_fun_t *fun, size_t addr, size_t len)404 static void isa_fun_add_io_range(isa_fun_t *fun, size_t addr, size_t len) 384 405 { 385 406 size_t count = fun->hw_resources.count; 386 407 hw_resource_t *resources = fun->hw_resources.resources; 408 409 isa_bus_t *isa = isa_bus(ddf_fun_get_dev(fun->fnode)); 387 410 388 411 if (count < ISA_MAX_HW_RES) { 389 412 resources[count].type = IO_RANGE; 390 413 resources[count].res.io_range.address = addr; 414 resources[count].res.io_range.address += isa->pio_win.io.base; 391 415 resources[count].res.io_range.size = len; 392 416 resources[count].res.io_range.endianness = LITTLE_ENDIAN; … … 400 424 } 401 425 402 static void fun_parse_irq(isa_fun_t *fun, c har *val)426 static void fun_parse_irq(isa_fun_t *fun, const char *val) 403 427 { 404 428 int irq = 0; … … 409 433 410 434 if (val != end) 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; 435 isa_fun_add_irq(fun, irq); 436 } 437 438 static void fun_parse_dma(isa_fun_t *fun, const char *val) 439 { 417 440 char *end = NULL; 418 441 419 442 val = skip_spaces(val); 420 dma = (unsigned int)strtol(val, &end, 10);443 const int dma = strtol(val, &end, 10); 421 444 422 445 if (val != end) 423 isa_fun_ set_dma(fun, dma);424 } 425 426 static void fun_parse_io_range(isa_fun_t *fun, c har *val)446 isa_fun_add_dma(fun, dma); 447 } 448 449 static void fun_parse_io_range(isa_fun_t *fun, const char *val) 427 450 { 428 451 size_t addr, len; … … 441 464 return; 442 465 443 isa_fun_ set_io_range(fun, addr, len);444 } 445 446 static void get_match_id(char **id, c har *val)447 { 448 c har *end = val;466 isa_fun_add_io_range(fun, addr, len); 467 } 468 469 static void get_match_id(char **id, const char *val) 470 { 471 const char *end = val; 449 472 450 473 while (!isspace(*end)) … … 456 479 } 457 480 458 static void fun_parse_match_id(isa_fun_t *fun, c har *val)481 static void fun_parse_match_id(isa_fun_t *fun, const char *val) 459 482 { 460 483 char *id = NULL; 461 int score = 0;462 484 char *end = NULL; 463 int rc;464 485 465 486 val = skip_spaces(val); 466 487 467 score = (int)strtol(val, &end, 10);488 int score = (int)strtol(val, &end, 10); 468 489 if (val == end) { 469 490 ddf_msg(LVL_ERROR, "Cannot read match score for function " … … 483 504 "function %s", id, score, ddf_fun_get_name(fun->fnode)); 484 505 485 rc = ddf_fun_add_match_id(fun->fnode, id, score);506 int rc = ddf_fun_add_match_id(fun->fnode, id, score); 486 507 if (rc != EOK) { 487 508 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", … … 492 513 } 493 514 494 static bool prop_parse(isa_fun_t *fun, c har *line, const char *prop,495 void (*read_fn)(isa_fun_t *, c har *))515 static bool prop_parse(isa_fun_t *fun, const char *line, const char *prop, 516 void (*read_fn)(isa_fun_t *, const char *)) 496 517 { 497 518 size_t proplen = str_size(prop); … … 508 529 } 509 530 510 static void fun_prop_parse(isa_fun_t *fun, c har *line)531 static void fun_prop_parse(isa_fun_t *fun, const char *line) 511 532 { 512 533 /* Skip leading spaces. */ … … 523 544 } 524 545 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 537 546 static char *isa_fun_read_info(char *fun_conf, isa_bus_t *isa) 538 547 { 539 548 char *line; 540 char *fun_name = NULL;541 549 542 550 /* Skip empty lines. */ 543 while (true){551 do { 544 552 line = str_get_line(fun_conf, &fun_conf); 545 553 … … 549 557 } 550 558 551 if (!line_empty(line)) 552 break; 553 } 559 } while (line_empty(line)); 554 560 555 561 /* Get device name. */ 556 fun_name = get_device_name(line);562 const char *fun_name = get_device_name(line); 557 563 if (fun_name == NULL) 558 564 return NULL; 559 565 560 566 isa_fun_t *fun = isa_fun_create(isa, fun_name); 561 free(fun_name);562 567 if (fun == NULL) { 563 568 return NULL; 564 569 } 565 566 /* Allocate buffer for the list of hardware resources of the device. */567 fun_hw_res_alloc(fun);568 570 569 571 /* Get properties of the device (match ids, irq and io range). */ … … 596 598 } 597 599 598 static void fun_conf_parse(char *conf, isa_bus_t *isa) 599 { 600 static void isa_functions_add(isa_bus_t *isa) 601 { 602 char *conf = fun_conf_read(CHILD_FUN_CONF_PATH); 600 603 while (conf != NULL && *conf != '\0') { 601 604 conf = isa_fun_read_info(conf, isa); 602 605 } 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 } 606 free(conf); 614 607 } 615 608 616 609 static int isa_dev_add(ddf_dev_t *dev) 617 610 { 618 isa_bus_t *isa; 611 async_sess_t *sess; 612 int rc; 619 613 620 614 ddf_msg(LVL_DEBUG, "isa_dev_add, device handle = %d", 621 615 (int) ddf_dev_get_handle(dev)); 622 616 623 isa = ddf_dev_data_alloc(dev, sizeof(isa_bus_t));617 isa_bus_t *isa = ddf_dev_data_alloc(dev, sizeof(isa_bus_t)); 624 618 if (isa == NULL) 625 619 return ENOMEM; … … 628 622 isa->dev = dev; 629 623 list_initialize(&isa->functions); 624 625 sess = ddf_dev_parent_sess_create(dev, EXCHANGE_SERIALIZE); 626 if (sess == NULL) { 627 ddf_msg(LVL_ERROR, "isa_dev_add failed to connect to the " 628 "parent driver."); 629 return ENOENT; 630 } 631 632 rc = pio_window_get(sess, &isa->pio_win); 633 if (rc != EOK) { 634 ddf_msg(LVL_ERROR, "isa_dev_add failed to get PIO window " 635 "for the device."); 636 return rc; 637 } 630 638 631 639 /* Make the bus device more visible. Does not do anything. */ … … 658 666 { 659 667 isa_bus_t *isa = isa_bus(dev); 660 int rc;661 668 662 669 fibril_mutex_lock(&isa->mutex); … … 666 673 isa_fun_t, bus_link); 667 674 668 rc = ddf_fun_offline(fun->fnode);675 int rc = ddf_fun_offline(fun->fnode); 669 676 if (rc != EOK) { 670 677 fibril_mutex_unlock(&isa->mutex); … … 682 689 list_remove(&fun->bus_link); 683 690 684 fun_hw_res_free(fun);685 691 ddf_fun_destroy(fun->fnode); 686 692 } … … 709 715 } 710 716 711 712 static void isa_init() 713 { 717 int main(int argc, char *argv[]) 718 { 719 printf(NAME ": HelenOS ISA bus driver\n"); 714 720 ddf_log_init(NAME); 715 isa_fun_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops;716 }717 718 int main(int argc, char *argv[])719 {720 printf(NAME ": HelenOS ISA bus driver\n");721 isa_init();722 721 return ddf_driver_main(&isa_driver); 723 722 }
Note:
See TracChangeset
for help on using the changeset viewer.
