diff options
Diffstat (limited to 'arch/sparc64/kernel/pci.c')
| -rw-r--r-- | arch/sparc64/kernel/pci.c | 127 |
1 files changed, 5 insertions, 122 deletions
diff --git a/arch/sparc64/kernel/pci.c b/arch/sparc64/kernel/pci.c index ec8bf4012c0c..2ff7c32ab0ce 100644 --- a/arch/sparc64/kernel/pci.c +++ b/arch/sparc64/kernel/pci.c | |||
| @@ -359,134 +359,17 @@ void pcibios_fixup_bus(struct pci_bus *pbus) | |||
| 359 | pbus->resource[1] = &pbm->mem_space; | 359 | pbus->resource[1] = &pbm->mem_space; |
| 360 | } | 360 | } |
| 361 | 361 | ||
| 362 | int pci_claim_resource(struct pci_dev *pdev, int resource) | 362 | struct resource *pcibios_select_root(struct pci_dev *pdev, struct resource *r) |
| 363 | { | 363 | { |
| 364 | struct pci_pbm_info *pbm = pdev->bus->sysdata; | 364 | struct pci_pbm_info *pbm = pdev->bus->sysdata; |
| 365 | struct resource *res = &pdev->resource[resource]; | 365 | struct resource *root = NULL; |
| 366 | struct resource *root; | ||
| 367 | |||
| 368 | if (!pbm) | ||
| 369 | return -EINVAL; | ||
| 370 | 366 | ||
| 371 | if (res->flags & IORESOURCE_IO) | 367 | if (r->flags & IORESOURCE_IO) |
| 372 | root = &pbm->io_space; | 368 | root = &pbm->io_space; |
| 373 | else | 369 | if (r->flags & IORESOURCE_MEM) |
| 374 | root = &pbm->mem_space; | 370 | root = &pbm->mem_space; |
| 375 | 371 | ||
| 376 | pbm->parent->resource_adjust(pdev, res, root); | 372 | return root; |
| 377 | |||
| 378 | return request_resource(root, res); | ||
| 379 | } | ||
| 380 | |||
| 381 | /* | ||
| 382 | * Given the PCI bus a device resides on, try to | ||
| 383 | * find an acceptable resource allocation for a | ||
| 384 | * specific device resource.. | ||
| 385 | */ | ||
| 386 | static int pci_assign_bus_resource(const struct pci_bus *bus, | ||
| 387 | struct pci_dev *dev, | ||
| 388 | struct resource *res, | ||
| 389 | unsigned long size, | ||
| 390 | unsigned long min, | ||
| 391 | int resno) | ||
| 392 | { | ||
| 393 | unsigned int type_mask; | ||
| 394 | int i; | ||
| 395 | |||
| 396 | type_mask = IORESOURCE_IO | IORESOURCE_MEM; | ||
| 397 | for (i = 0 ; i < 4; i++) { | ||
| 398 | struct resource *r = bus->resource[i]; | ||
| 399 | if (!r) | ||
| 400 | continue; | ||
| 401 | |||
| 402 | /* type_mask must match */ | ||
| 403 | if ((res->flags ^ r->flags) & type_mask) | ||
| 404 | continue; | ||
| 405 | |||
| 406 | /* Ok, try it out.. */ | ||
| 407 | if (allocate_resource(r, res, size, min, -1, size, NULL, NULL) < 0) | ||
| 408 | continue; | ||
| 409 | |||
| 410 | /* PCI config space updated by caller. */ | ||
| 411 | return 0; | ||
| 412 | } | ||
| 413 | return -EBUSY; | ||
| 414 | } | ||
| 415 | |||
| 416 | int pci_assign_resource(struct pci_dev *pdev, int resource) | ||
| 417 | { | ||
| 418 | struct pcidev_cookie *pcp = pdev->sysdata; | ||
| 419 | struct pci_pbm_info *pbm = pcp->pbm; | ||
| 420 | struct resource *res = &pdev->resource[resource]; | ||
| 421 | unsigned long min, size; | ||
| 422 | int err; | ||
| 423 | |||
| 424 | if (res->flags & IORESOURCE_IO) | ||
| 425 | min = pbm->io_space.start + 0x400UL; | ||
| 426 | else | ||
| 427 | min = pbm->mem_space.start; | ||
| 428 | |||
| 429 | size = res->end - res->start + 1; | ||
| 430 | |||
| 431 | err = pci_assign_bus_resource(pdev->bus, pdev, res, size, min, resource); | ||
| 432 | |||
| 433 | if (err < 0) { | ||
| 434 | printk("PCI: Failed to allocate resource %d for %s\n", | ||
| 435 | resource, pci_name(pdev)); | ||
| 436 | } else { | ||
| 437 | /* Update PCI config space. */ | ||
| 438 | pbm->parent->base_address_update(pdev, resource); | ||
| 439 | } | ||
| 440 | |||
| 441 | return err; | ||
| 442 | } | ||
| 443 | |||
| 444 | /* Sort resources by alignment */ | ||
| 445 | void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head) | ||
| 446 | { | ||
| 447 | int i; | ||
| 448 | |||
| 449 | for (i = 0; i < PCI_NUM_RESOURCES; i++) { | ||
| 450 | struct resource *r; | ||
| 451 | struct resource_list *list, *tmp; | ||
| 452 | unsigned long r_align; | ||
| 453 | |||
| 454 | r = &dev->resource[i]; | ||
| 455 | r_align = r->end - r->start; | ||
| 456 | |||
| 457 | if (!(r->flags) || r->parent) | ||
| 458 | continue; | ||
| 459 | if (!r_align) { | ||
| 460 | printk(KERN_WARNING "PCI: Ignore bogus resource %d " | ||
| 461 | "[%lx:%lx] of %s\n", | ||
| 462 | i, r->start, r->end, pci_name(dev)); | ||
| 463 | continue; | ||
| 464 | } | ||
| 465 | r_align = (i < PCI_BRIDGE_RESOURCES) ? r_align + 1 : r->start; | ||
| 466 | for (list = head; ; list = list->next) { | ||
| 467 | unsigned long align = 0; | ||
| 468 | struct resource_list *ln = list->next; | ||
| 469 | int idx; | ||
| 470 | |||
| 471 | if (ln) { | ||
| 472 | idx = ln->res - &ln->dev->resource[0]; | ||
| 473 | align = (idx < PCI_BRIDGE_RESOURCES) ? | ||
| 474 | ln->res->end - ln->res->start + 1 : | ||
| 475 | ln->res->start; | ||
| 476 | } | ||
| 477 | if (r_align > align) { | ||
| 478 | tmp = kmalloc(sizeof(*tmp), GFP_KERNEL); | ||
| 479 | if (!tmp) | ||
| 480 | panic("pdev_sort_resources(): " | ||
| 481 | "kmalloc() failed!\n"); | ||
| 482 | tmp->next = ln; | ||
| 483 | tmp->res = r; | ||
| 484 | tmp->dev = dev; | ||
| 485 | list->next = tmp; | ||
| 486 | break; | ||
| 487 | } | ||
| 488 | } | ||
| 489 | } | ||
| 490 | } | 373 | } |
| 491 | 374 | ||
| 492 | void pcibios_update_irq(struct pci_dev *pdev, int irq) | 375 | void pcibios_update_irq(struct pci_dev *pdev, int irq) |
