aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/setup-bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/setup-bus.c')
-rw-r--r--drivers/pci/setup-bus.c66
1 files changed, 42 insertions, 24 deletions
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 66cb8f4cc5f4..21212155eaba 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -404,6 +404,43 @@ static struct resource *find_free_bus_resource(struct pci_bus *bus, unsigned lon
404 return NULL; 404 return NULL;
405} 405}
406 406
407static resource_size_t calculate_iosize(resource_size_t size,
408 resource_size_t min_size,
409 resource_size_t size1,
410 resource_size_t old_size,
411 resource_size_t align)
412{
413 if (size < min_size)
414 size = min_size;
415 if (old_size == 1 )
416 old_size = 0;
417 /* To be fixed in 2.5: we should have sort of HAVE_ISA
418 flag in the struct pci_bus. */
419#if defined(CONFIG_ISA) || defined(CONFIG_EISA)
420 size = (size & 0xff) + ((size & ~0xffUL) << 2);
421#endif
422 size = ALIGN(size + size1, align);
423 if (size < old_size)
424 size = old_size;
425 return size;
426}
427
428static resource_size_t calculate_memsize(resource_size_t size,
429 resource_size_t min_size,
430 resource_size_t size1,
431 resource_size_t old_size,
432 resource_size_t align)
433{
434 if (size < min_size)
435 size = min_size;
436 if (old_size == 1 )
437 old_size = 0;
438 if (size < old_size)
439 size = old_size;
440 size = ALIGN(size + size1, align);
441 return size;
442}
443
407/* Sizing the IO windows of the PCI-PCI bridge is trivial, 444/* Sizing the IO windows of the PCI-PCI bridge is trivial,
408 since these windows have 4K granularity and the IO ranges 445 since these windows have 4K granularity and the IO ranges
409 of non-bridge PCI devices are limited to 256 bytes. 446 of non-bridge PCI devices are limited to 256 bytes.
@@ -412,7 +449,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size)
412{ 449{
413 struct pci_dev *dev; 450 struct pci_dev *dev;
414 struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO); 451 struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO);
415 unsigned long size = 0, size1 = 0, old_size; 452 unsigned long size = 0, size1 = 0;
416 453
417 if (!b_res) 454 if (!b_res)
418 return; 455 return;
@@ -435,19 +472,8 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size)
435 size1 += r_size; 472 size1 += r_size;
436 } 473 }
437 } 474 }
438 if (size < min_size) 475 size = calculate_iosize(size, min_size, size1,
439 size = min_size; 476 resource_size(b_res), 4096);
440 old_size = resource_size(b_res);
441 if (old_size == 1)
442 old_size = 0;
443/* To be fixed in 2.5: we should have sort of HAVE_ISA
444 flag in the struct pci_bus. */
445#if defined(CONFIG_ISA) || defined(CONFIG_EISA)
446 size = (size & 0xff) + ((size & ~0xffUL) << 2);
447#endif
448 size = ALIGN(size + size1, 4096);
449 if (size < old_size)
450 size = old_size;
451 if (!size) { 477 if (!size) {
452 if (b_res->start || b_res->end) 478 if (b_res->start || b_res->end)
453 dev_info(&bus->self->dev, "disabling bridge window " 479 dev_info(&bus->self->dev, "disabling bridge window "
@@ -468,7 +494,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
468 unsigned long type, resource_size_t min_size) 494 unsigned long type, resource_size_t min_size)
469{ 495{
470 struct pci_dev *dev; 496 struct pci_dev *dev;
471 resource_size_t min_align, align, size, old_size; 497 resource_size_t min_align, align, size;
472 resource_size_t aligns[12]; /* Alignments from 1Mb to 2Gb */ 498 resource_size_t aligns[12]; /* Alignments from 1Mb to 2Gb */
473 int order, max_order; 499 int order, max_order;
474 struct resource *b_res = find_free_bus_resource(bus, type); 500 struct resource *b_res = find_free_bus_resource(bus, type);
@@ -516,14 +542,6 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
516 mem64_mask &= r->flags & IORESOURCE_MEM_64; 542 mem64_mask &= r->flags & IORESOURCE_MEM_64;
517 } 543 }
518 } 544 }
519 if (size < min_size)
520 size = min_size;
521 old_size = resource_size(b_res);
522 if (old_size == 1)
523 old_size = 0;
524 if (size < old_size)
525 size = old_size;
526
527 align = 0; 545 align = 0;
528 min_align = 0; 546 min_align = 0;
529 for (order = 0; order <= max_order; order++) { 547 for (order = 0; order <= max_order; order++) {
@@ -537,7 +555,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
537 min_align = align1 >> 1; 555 min_align = align1 >> 1;
538 align += aligns[order]; 556 align += aligns[order];
539 } 557 }
540 size = ALIGN(size, min_align); 558 size = calculate_memsize(size, min_size, 0, resource_size(b_res), align);
541 if (!size) { 559 if (!size) {
542 if (b_res->start || b_res->end) 560 if (b_res->start || b_res->end)
543 dev_info(&bus->self->dev, "disabling bridge window " 561 dev_info(&bus->self->dev, "disabling bridge window "