Changeset 00aece0 in mainline for uspace/drv/bus/pci/pciintel/pci.c
- Timestamp:
- 2012-02-18T16:47:38Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4449c6c
- Parents:
- bd5f3b7 (diff), f943dd3 (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/pci/pciintel/pci.c
rbd5f3b7 r00aece0 78 78 #define PCI_BUS_FROM_FUN(fun) ((fun)->busptr) 79 79 80 /** Max is 47, align to something nice. */ 81 #define ID_MAX_STR_LEN 50 82 80 83 static hw_resource_list_t *pciintel_get_resources(ddf_fun_t *fnode) 81 84 { … … 89 92 static bool pciintel_enable_interrupt(ddf_fun_t *fnode) 90 93 { 91 /* This is an old ugly way , copied from ne2000 driver*/94 /* This is an old ugly way */ 92 95 assert(fnode); 93 96 pci_fun_t *dev_data = (pci_fun_t *) fnode->driver_data; … … 184 187 185 188 static hw_res_ops_t pciintel_hw_res_ops = { 186 &pciintel_get_resources,187 &pciintel_enable_interrupt189 .get_resource_list = &pciintel_get_resources, 190 .enable_interrupt = &pciintel_enable_interrupt, 188 191 }; 189 192 … … 202 205 }; 203 206 204 static int pci_add_device(ddf_dev_t *); 207 static int pci_dev_add(ddf_dev_t *); 208 static int pci_fun_online(ddf_fun_t *); 209 static int pci_fun_offline(ddf_fun_t *); 205 210 206 211 /** PCI bus driver standard operations */ 207 212 static driver_ops_t pci_ops = { 208 .add_device = &pci_add_device 213 .dev_add = &pci_dev_add, 214 .fun_online = &pci_fun_online, 215 .fun_offline = &pci_fun_offline, 209 216 }; 210 217 … … 215 222 }; 216 223 217 static pci_bus_t *pci_bus_new(void)218 {219 pci_bus_t *bus;220 221 bus = (pci_bus_t *) calloc(1, sizeof(pci_bus_t));222 if (bus == NULL)223 return NULL;224 225 fibril_mutex_initialize(&bus->conf_mutex);226 return bus;227 }228 229 static void pci_bus_delete(pci_bus_t *bus)230 {231 assert(bus != NULL);232 free(bus);233 }234 235 224 static void pci_conf_read(pci_fun_t *fun, int reg, uint8_t *buf, size_t len) 236 225 { … … 239 228 fibril_mutex_lock(&bus->conf_mutex); 240 229 241 uint32_t conf_addr; 242 conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg); 230 const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg); 243 231 void *addr = bus->conf_data_port + (reg & 3); 244 232 … … 325 313 void pci_fun_create_match_ids(pci_fun_t *fun) 326 314 { 327 char *match_id_str;328 315 int rc; 329 330 asprintf(&match_id_str, "pci/ven=%04x&dev=%04x", 316 char match_id_str[ID_MAX_STR_LEN]; 317 318 /* Vendor ID & Device ID, length(incl \0) 22 */ 319 rc = snprintf(match_id_str, ID_MAX_STR_LEN, "pci/ven=%04x&dev=%04x", 331 320 fun->vendor_id, fun->device_id); 332 333 if (match_id_str == NULL) { 334 ddf_msg(LVL_ERROR, "Out of memory creating match ID."); 335 return; 321 if (rc < 0) { 322 ddf_msg(LVL_ERROR, "Failed creating match ID str: %s", 323 str_error(rc)); 336 324 } 337 325 338 326 rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 90); 339 327 if (rc != EOK) { 340 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", 328 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc)); 329 } 330 331 /* Class, subclass, prog IF, revision, length(incl \0) 47 */ 332 rc = snprintf(match_id_str, ID_MAX_STR_LEN, 333 "pci/class=%02x&subclass=%02x&progif=%02x&revision=%02x", 334 fun->class_code, fun->subclass_code, fun->prog_if, fun->revision); 335 if (rc < 0) { 336 ddf_msg(LVL_ERROR, "Failed creating match ID str: %s", 341 337 str_error(rc)); 342 338 } 343 344 free(match_id_str); 345 346 /* TODO add more ids (with subsys ids, using class id etc.) */ 339 340 rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 70); 341 if (rc != EOK) { 342 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc)); 343 } 344 345 /* Class, subclass, prog IF, length(incl \0) 35 */ 346 rc = snprintf(match_id_str, ID_MAX_STR_LEN, 347 "pci/class=%02x&subclass=%02x&progif=%02x", 348 fun->class_code, fun->subclass_code, fun->prog_if); 349 if (rc < 0) { 350 ddf_msg(LVL_ERROR, "Failed creating match ID str: %s", 351 str_error(rc)); 352 } 353 354 rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 60); 355 if (rc != EOK) { 356 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc)); 357 } 358 359 /* Class, subclass, length(incl \0) 25 */ 360 rc = snprintf(match_id_str, ID_MAX_STR_LEN, 361 "pci/class=%02x&subclass=%02x", 362 fun->class_code, fun->subclass_code); 363 if (rc < 0) { 364 ddf_msg(LVL_ERROR, "Failed creating match ID str: %s", 365 str_error(rc)); 366 } 367 368 rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 50); 369 if (rc != EOK) { 370 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc)); 371 } 372 373 /* Class, length(incl \0) 13 */ 374 rc = snprintf(match_id_str, ID_MAX_STR_LEN, "pci/class=%02x", 375 fun->class_code); 376 if (rc < 0) { 377 ddf_msg(LVL_ERROR, "Failed creating match ID str: %s", 378 str_error(rc)); 379 } 380 381 rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 40); 382 if (rc != EOK) { 383 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc)); 384 } 385 386 /* TODO add subsys ids, but those exist only in header type 0 */ 347 387 } 348 388 … … 495 535 for (fnum = 0; multi && fnum < 8; fnum++) { 496 536 pci_fun_init(fun, bus_num, dnum, fnum); 497 fun->vendor_id = pci_conf_read_16(fun,498 PCI_VENDOR_ID);499 fun->device_id = pci_conf_read_16(fun,500 PCI_DEVICE_ID);501 537 if (fun->vendor_id == 0xffff) { 502 538 /* … … 525 561 526 562 fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name); 563 free(fun_name); 527 564 if (fnode == NULL) { 528 565 ddf_msg(LVL_ERROR, "Failed creating function."); … … 530 567 } 531 568 532 free(fun_name);533 569 fun->fnode = fnode; 534 570 … … 574 610 } 575 611 576 static int pci_ add_device(ddf_dev_t *dnode)612 static int pci_dev_add(ddf_dev_t *dnode) 577 613 { 578 614 pci_bus_t *bus = NULL; … … 581 617 int rc; 582 618 583 ddf_msg(LVL_DEBUG, "pci_ add_device");619 ddf_msg(LVL_DEBUG, "pci_dev_add"); 584 620 dnode->parent_sess = NULL; 585 621 586 bus = pci_bus_new();622 bus = ddf_dev_data_alloc(dnode, sizeof(pci_bus_t)); 587 623 if (bus == NULL) { 588 ddf_msg(LVL_ERROR, "pci_ add_deviceallocation failed.");624 ddf_msg(LVL_ERROR, "pci_dev_add allocation failed."); 589 625 rc = ENOMEM; 590 626 goto fail; 591 627 } 628 fibril_mutex_initialize(&bus->conf_mutex); 629 592 630 bus->dnode = dnode; 593 631 dnode->driver_data = bus; … … 596 634 dnode->handle, IPC_FLAG_BLOCKING); 597 635 if (!dnode->parent_sess) { 598 ddf_msg(LVL_ERROR, "pci_ add_devicefailed to connect to the "636 ddf_msg(LVL_ERROR, "pci_dev_add failed to connect to the " 599 637 "parent driver."); 600 638 rc = ENOENT; … … 606 644 rc = hw_res_get_resource_list(dnode->parent_sess, &hw_resources); 607 645 if (rc != EOK) { 608 ddf_msg(LVL_ERROR, "pci_ add_devicefailed to get hw resources "646 ddf_msg(LVL_ERROR, "pci_dev_add failed to get hw resources " 609 647 "for the device."); 610 648 goto fail; … … 655 693 656 694 fail: 657 if (bus != NULL)658 pci_bus_delete(bus);659 660 695 if (dnode->parent_sess) 661 696 async_hangup(dnode->parent_sess); … … 668 703 669 704 return rc; 705 } 706 707 static int pci_fun_online(ddf_fun_t *fun) 708 { 709 ddf_msg(LVL_DEBUG, "pci_fun_online()"); 710 return ddf_fun_online(fun); 711 } 712 713 static int pci_fun_offline(ddf_fun_t *fun) 714 { 715 ddf_msg(LVL_DEBUG, "pci_fun_offline()"); 716 return ddf_fun_offline(fun); 670 717 } 671 718 … … 694 741 fun->dev = dev; 695 742 fun->fn = fn; 743 fun->vendor_id = pci_conf_read_16(fun, PCI_VENDOR_ID); 744 fun->device_id = pci_conf_read_16(fun, PCI_DEVICE_ID); 745 fun->class_code = pci_conf_read_8(fun, PCI_BASE_CLASS); 746 fun->subclass_code = pci_conf_read_8(fun, PCI_SUB_CLASS); 747 fun->prog_if = pci_conf_read_8(fun, PCI_PROG_IF); 748 fun->revision = pci_conf_read_8(fun, PCI_REVISION_ID); 696 749 } 697 750 … … 714 767 bool pci_alloc_resource_list(pci_fun_t *fun) 715 768 { 716 fun->hw_resources.resources = 717 (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t)); 718 return fun->hw_resources.resources != NULL; 769 fun->hw_resources.resources = fun->resources; 770 return true; 719 771 } 720 772 721 773 void pci_clean_resource_list(pci_fun_t *fun) 722 774 { 723 if (fun->hw_resources.resources != NULL) { 724 free(fun->hw_resources.resources); 725 fun->hw_resources.resources = NULL; 726 } 775 fun->hw_resources.resources = NULL; 727 776 } 728 777
Note:
See TracChangeset
for help on using the changeset viewer.