adjust legacy IDE resource setting (v2)

The change to force legacy mode IDE channels' resources to fixed non-zero
values confuses (at least some versions of) X, because the values reported
by the kernel and those readable from PCI config space aren't consistent
anymore. Therefore, this patch arranges for the respective BARs to also
get updated if possible.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
Acked-by: Alan Cox <alan@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>

authored by Jan Beulich and committed by Bartlomiej Zolnierkiewicz ed8ccee0 9e5755bc

+32 -13
+32 -13
drivers/pci/probe.c
··· 682 dev->irq = irq; 683 } 684 685 - #define LEGACY_IO_RESOURCE (IORESOURCE_IO | IORESOURCE_PCI_FIXED) 686 687 /** 688 * pci_setup_device - fill in class and map information of a device ··· 762 u8 progif; 763 pci_read_config_byte(dev, PCI_CLASS_PROG, &progif); 764 if ((progif & 1) == 0) { 765 - dev->resource[0].start = 0x1F0; 766 - dev->resource[0].end = 0x1F7; 767 - dev->resource[0].flags = LEGACY_IO_RESOURCE; 768 - dev->resource[1].start = 0x3F6; 769 - dev->resource[1].end = 0x3F6; 770 - dev->resource[1].flags = LEGACY_IO_RESOURCE; 771 } 772 if ((progif & 4) == 0) { 773 - dev->resource[2].start = 0x170; 774 - dev->resource[2].end = 0x177; 775 - dev->resource[2].flags = LEGACY_IO_RESOURCE; 776 - dev->resource[3].start = 0x376; 777 - dev->resource[3].end = 0x376; 778 - dev->resource[3].flags = LEGACY_IO_RESOURCE; 779 } 780 } 781 break;
··· 682 dev->irq = irq; 683 } 684 685 + static void change_legacy_io_resource(struct pci_dev * dev, unsigned index, 686 + unsigned start, unsigned end) 687 + { 688 + unsigned base = start & PCI_BASE_ADDRESS_IO_MASK; 689 + unsigned len = (end | ~PCI_BASE_ADDRESS_IO_MASK) - base + 1; 690 + 691 + /* 692 + * Some X versions get confused when the BARs reported through 693 + * /sys or /proc differ from those seen in config space, thus 694 + * try to update the config space values, too. 695 + */ 696 + if (!(pci_resource_flags(dev, index) & IORESOURCE_IO)) 697 + printk(KERN_WARNING "%s: cannot adjust BAR%u (not I/O)\n", 698 + pci_name(dev), index); 699 + else if (pci_resource_len(dev, index) != len) 700 + printk(KERN_WARNING "%s: cannot adjust BAR%u (size %04X)\n", 701 + pci_name(dev), index, (unsigned)pci_resource_len(dev, index)); 702 + else { 703 + printk(KERN_INFO "%s: trying to change BAR%u from %04X to %04X\n", 704 + pci_name(dev), index, 705 + (unsigned)pci_resource_start(dev, index), base); 706 + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + index * 4, base); 707 + } 708 + pci_resource_start(dev, index) = start; 709 + pci_resource_end(dev, index) = end; 710 + pci_resource_flags(dev, index) = 711 + IORESOURCE_IO | IORESOURCE_PCI_FIXED | PCI_BASE_ADDRESS_SPACE_IO; 712 + } 713 714 /** 715 * pci_setup_device - fill in class and map information of a device ··· 735 u8 progif; 736 pci_read_config_byte(dev, PCI_CLASS_PROG, &progif); 737 if ((progif & 1) == 0) { 738 + change_legacy_io_resource(dev, 0, 0x1F0, 0x1F7); 739 + change_legacy_io_resource(dev, 1, 0x3F6, 0x3F6); 740 } 741 if ((progif & 4) == 0) { 742 + change_legacy_io_resource(dev, 2, 0x170, 0x177); 743 + change_legacy_io_resource(dev, 3, 0x376, 0x376); 744 } 745 } 746 break;