Changeset 5856b627 in mainline for uspace/drv/bus/isa/isa.c
- Timestamp:
- 2013-08-20T12:36:48Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 26e2de3
- Parents:
- 0ee999d (diff), 4da8fdb (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
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/isa/isa.c
r0ee999d r5856b627 85 85 fibril_mutex_t mutex; 86 86 ddf_fun_t *fnode; 87 hw_resource_t resources[ISA_MAX_HW_RES]; 87 88 hw_resource_list_t hw_resources; 88 89 link_t bus_link; … … 103 104 static hw_resource_list_t *isa_get_fun_resources(ddf_fun_t *fnode) 104 105 { 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)106 isa_fun_t *isa = isa_fun(fnode); 107 assert(isa); 108 109 return &isa->hw_resources; 110 } 111 112 static bool isa_fun_enable_interrupt(ddf_fun_t *fnode) 112 113 { 113 114 /* This is an old ugly way, copied from pci driver */ 114 115 assert(fnode); 115 isa_fun_t *fun = isa_fun(fnode); 116 isa_fun_t *isa = isa_fun(fnode); 117 assert(isa); 116 118 117 119 sysarg_t apic; … … 129 131 return false; 130 132 131 const hw_resource_list_t *res = & fun->hw_resources;133 const hw_resource_list_t *res = &isa->hw_resources; 132 134 assert(res); 133 135 for (size_t i = 0; i < res->count; ++i) { … … 151 153 } 152 154 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)155 static int isa_fun_setup_dma(ddf_fun_t *fnode, 156 unsigned int channel, uint32_t pa, uint32_t size, uint8_t mode) 155 157 { 156 158 assert(fnode); 157 isa_fun_t *fun = isa_fun(fnode); 158 const hw_resource_list_t *res = &fun->hw_resources; 159 isa_fun_t *isa = isa_fun(fnode); 160 assert(isa); 161 const hw_resource_list_t *res = &isa->hw_resources; 159 162 assert(res); 160 161 const unsigned int ch = channel; 163 162 164 for (size_t i = 0; i < res->count; ++i) { 165 /* Check for assigned channel */ 163 166 if (((res->resources[i].type == DMA_CHANNEL_16) && 164 (res->resources[i].res.dma_channel.dma16 == ch )) ||167 (res->resources[i].res.dma_channel.dma16 == channel)) || 165 168 ((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 169 (res->resources[i].res.dma_channel.dma8 == channel))) { 170 return dma_channel_setup(channel, pa, size, mode); 171 } 172 } 173 174 return EINVAL; 175 } 176 177 static int isa_fun_remain_dma(ddf_fun_t *fnode, 178 unsigned channel, size_t *size) 179 { 180 assert(size); 181 assert(fnode); 182 isa_fun_t *isa = isa_fun(fnode); 183 assert(isa); 184 const hw_resource_list_t *res = &isa->hw_resources; 185 assert(res); 186 187 for (size_t i = 0; i < res->count; ++i) { 188 /* Check for assigned channel */ 189 if (((res->resources[i].type == DMA_CHANNEL_16) && 190 (res->resources[i].res.dma_channel.dma16 == channel)) || 191 ((res->resources[i].type == DMA_CHANNEL_8) && 192 (res->resources[i].res.dma_channel.dma8 == channel))) { 193 return dma_channel_remain(channel, size); 194 } 195 } 196 171 197 return EINVAL; 172 198 } … … 174 200 static hw_res_ops_t isa_fun_hw_res_ops = { 175 201 .get_resource_list = isa_get_fun_resources, 176 .enable_interrupt = isa_enable_fun_interrupt, 177 .dma_channel_setup = isa_dma_channel_fun_setup, 202 .enable_interrupt = isa_fun_enable_interrupt, 203 .dma_channel_setup = isa_fun_setup_dma, 204 .dma_channel_remain = isa_fun_remain_dma, 178 205 }; 179 206 180 static ddf_dev_ops_t isa_fun_ops; 207 static ddf_dev_ops_t isa_fun_ops= { 208 .interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops, 209 }; 181 210 182 211 static int isa_dev_add(ddf_dev_t *dev); … … 212 241 213 242 fibril_mutex_initialize(&fun->mutex); 243 fun->hw_resources.resources = fun->resources; 244 214 245 fun->fnode = fnode; 215 246 return fun; … … 270 301 { 271 302 char *line = str; 303 *next = NULL; 272 304 273 305 if (str == NULL) { 274 *next = NULL;275 306 return NULL; 276 307 } … … 282 313 if (*str != '\0') { 283 314 *next = str + 1; 284 } else {285 *next = NULL;286 315 } 287 316 … … 310 339 /* Get the name part of the rest of the line. */ 311 340 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) 341 return line; 342 } 343 344 static inline const char *skip_spaces(const char *line) 326 345 { 327 346 /* Skip leading spaces. */ … … 332 351 } 333 352 334 static void isa_fun_ set_irq(isa_fun_t *fun, int irq)353 static void isa_fun_add_irq(isa_fun_t *fun, int irq) 335 354 { 336 355 size_t count = fun->hw_resources.count; … … 348 367 } 349 368 350 static void isa_fun_ set_dma(isa_fun_t *fun, int dma)369 static void isa_fun_add_dma(isa_fun_t *fun, int dma) 351 370 { 352 371 size_t count = fun->hw_resources.count; … … 381 400 } 382 401 383 static void isa_fun_ set_io_range(isa_fun_t *fun, size_t addr, size_t len)402 static void isa_fun_add_io_range(isa_fun_t *fun, size_t addr, size_t len) 384 403 { 385 404 size_t count = fun->hw_resources.count; … … 400 419 } 401 420 402 static void fun_parse_irq(isa_fun_t *fun, c har *val)421 static void fun_parse_irq(isa_fun_t *fun, const char *val) 403 422 { 404 423 int irq = 0; … … 409 428 410 429 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; 430 isa_fun_add_irq(fun, irq); 431 } 432 433 static void fun_parse_dma(isa_fun_t *fun, const char *val) 434 { 417 435 char *end = NULL; 418 436 419 437 val = skip_spaces(val); 420 dma = (unsigned int)strtol(val, &end, 10);438 const int dma = strtol(val, &end, 10); 421 439 422 440 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)441 isa_fun_add_dma(fun, dma); 442 } 443 444 static void fun_parse_io_range(isa_fun_t *fun, const char *val) 427 445 { 428 446 size_t addr, len; … … 441 459 return; 442 460 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;461 isa_fun_add_io_range(fun, addr, len); 462 } 463 464 static void get_match_id(char **id, const char *val) 465 { 466 const char *end = val; 449 467 450 468 while (!isspace(*end)) … … 456 474 } 457 475 458 static void fun_parse_match_id(isa_fun_t *fun, c har *val)476 static void fun_parse_match_id(isa_fun_t *fun, const char *val) 459 477 { 460 478 char *id = NULL; 461 int score = 0;462 479 char *end = NULL; 463 int rc;464 480 465 481 val = skip_spaces(val); 466 482 467 score = (int)strtol(val, &end, 10);483 int score = (int)strtol(val, &end, 10); 468 484 if (val == end) { 469 485 ddf_msg(LVL_ERROR, "Cannot read match score for function " … … 483 499 "function %s", id, score, ddf_fun_get_name(fun->fnode)); 484 500 485 rc = ddf_fun_add_match_id(fun->fnode, id, score);501 int rc = ddf_fun_add_match_id(fun->fnode, id, score); 486 502 if (rc != EOK) { 487 503 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", … … 492 508 } 493 509 494 static bool prop_parse(isa_fun_t *fun, c har *line, const char *prop,495 void (*read_fn)(isa_fun_t *, c har *))510 static bool prop_parse(isa_fun_t *fun, const char *line, const char *prop, 511 void (*read_fn)(isa_fun_t *, const char *)) 496 512 { 497 513 size_t proplen = str_size(prop); … … 508 524 } 509 525 510 static void fun_prop_parse(isa_fun_t *fun, c har *line)526 static void fun_prop_parse(isa_fun_t *fun, const char *line) 511 527 { 512 528 /* Skip leading spaces. */ … … 523 539 } 524 540 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 541 static char *isa_fun_read_info(char *fun_conf, isa_bus_t *isa) 538 542 { 539 543 char *line; 540 char *fun_name = NULL;541 544 542 545 /* Skip empty lines. */ 543 while (true){546 do { 544 547 line = str_get_line(fun_conf, &fun_conf); 545 548 … … 549 552 } 550 553 551 if (!line_empty(line)) 552 break; 553 } 554 } while (line_empty(line)); 554 555 555 556 /* Get device name. */ 556 fun_name = get_device_name(line);557 const char *fun_name = get_device_name(line); 557 558 if (fun_name == NULL) 558 559 return NULL; 559 560 560 561 isa_fun_t *fun = isa_fun_create(isa, fun_name); 561 free(fun_name);562 562 if (fun == NULL) { 563 563 return NULL; 564 564 } 565 566 /* Allocate buffer for the list of hardware resources of the device. */567 fun_hw_res_alloc(fun);568 565 569 566 /* Get properties of the device (match ids, irq and io range). */ … … 596 593 } 597 594 598 static void fun_conf_parse(char *conf, isa_bus_t *isa) 599 { 595 static void isa_functions_add(isa_bus_t *isa) 596 { 597 char *conf = fun_conf_read(CHILD_FUN_CONF_PATH); 600 598 while (conf != NULL && *conf != '\0') { 601 599 conf = isa_fun_read_info(conf, isa); 602 600 } 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 } 601 free(conf); 614 602 } 615 603 616 604 static int isa_dev_add(ddf_dev_t *dev) 617 605 { 618 isa_bus_t *isa;619 620 606 ddf_msg(LVL_DEBUG, "isa_dev_add, device handle = %d", 621 607 (int) ddf_dev_get_handle(dev)); 622 608 623 isa = ddf_dev_data_alloc(dev, sizeof(isa_bus_t));609 isa_bus_t *isa = ddf_dev_data_alloc(dev, sizeof(isa_bus_t)); 624 610 if (isa == NULL) 625 611 return ENOMEM; … … 658 644 { 659 645 isa_bus_t *isa = isa_bus(dev); 660 int rc;661 646 662 647 fibril_mutex_lock(&isa->mutex); … … 666 651 isa_fun_t, bus_link); 667 652 668 rc = ddf_fun_offline(fun->fnode);653 int rc = ddf_fun_offline(fun->fnode); 669 654 if (rc != EOK) { 670 655 fibril_mutex_unlock(&isa->mutex); … … 682 667 list_remove(&fun->bus_link); 683 668 684 fun_hw_res_free(fun);685 669 ddf_fun_destroy(fun->fnode); 686 670 } … … 709 693 } 710 694 711 712 static void isa_init() 713 { 695 int main(int argc, char *argv[]) 696 { 697 printf(NAME ": HelenOS ISA bus driver\n"); 714 698 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 699 return ddf_driver_main(&isa_driver); 723 700 }
Note:
See TracChangeset
for help on using the changeset viewer.