ide: make ide_pci_check_iomem() actually work
PATCH 1/1 ide: make ide_pci_check_iomem() actually work
This function didn't actually check if a given BAR is in I/O space because of using the bogus PCI_BASE_ADDRESS_IO_MASK (which equals ~3) to test the resource flags instead of IORESOURCE_IO -- fix this, make ide_hwif_configure() check the results failing if necessary, and move the printk() call to the failure path.
---
The patch is against today's Linus' tree...
drivers/ide/setup-pci.c | 23 ++++++++++++----------- 1 files changed, 12 insertions(+), 11 deletions(-)
drivers/ide/setup-pci.c +12 -11
@@ -312,11 +312,12 @@ static int ide_pci_configure(struct pci_* @d: IDE port info * @bar: BAR number * -* Checks if a BAR is configured and points to MMIO space. If so -* print an error and return an error code. Otherwise return 0 +* Checks if a BAR is configured and points to MMIO space. If so, +* return an error code. Otherwise return 0 */ -static int ide_pci_check_iomem (struct pci_dev *dev,const struct ide_port_info *d,int bar) +static int ide_pci_check_iomem (struct pci_dev *dev,const struct ide_port_info *d, +int bar) {ulong flags =pci_resource_flags (dev, bar);
@@ -324,14 +325,11 @@ static int ide_pci_check_iomem(struct pcif (!flags ||pci_resource_len (dev, bar) ==0 )return 0 ; -/* I/O space */ -if (flags &PCI_BASE_ADDRESS_IO_MASK ) +/* I/O space */ +if (flags &IORESOURCE_IO )return 0 ;/* Bad */ -printk (KERN_ERR "%s: IO baseregs (BIOS) are reported " -"as MEM, report to " -"<[email protected]>.\n" , d->name);return -EINVAL ; }
@@ -360,9 +358,12 @@ static ide_hwif_t *ide_hwif_configure(ststruct hw_regs_s hw;if ((d->host_flags &IDE_HFLAG_ISA_PORTS ) ==0 ) { -/* Possibly we should fail if these checks report true */ -ide_pci_check_iomem (dev, d,2 *port); -ide_pci_check_iomem (dev, d,2 *port+1 ); +if (ide_pci_check_iomem (dev, d,2 * port) || +ide_pci_check_iomem (dev, d,2 * port +1 )) { +printk (KERN_ERR "%s: I/O baseregs (BIOS) are reported " +"as MEM for port %d!\n" , d->name, port); +return NULL ; + } ctl =pci_resource_start (dev,2 *port+1 ); base =pci_resource_start (dev,2 *port);
Hi,
Quoted 4 lines · Sergei Shtylyov
This function didn't actually check if a given BAR is in I/O space because of using the bogus
PCI_BASE_ADDRESS_IO_MASK(which equals ~3) to test the resource flags instead ofIORESOURCE_IO-- fix this, makeide_hwif_configure()check the results failing if necessary, and move theprintk()call to the failure path.
This change is OK in itself but I worry that ide_pci_check_iomem() may now return "false" errors (bogus PCI_BASE_ADDRESS_IO_MASK check resulted in MEM resources always surviving ide_pci_check_iomem() calls before the fix) for some host drivers (siimage, scc_pata...) resulting in failed initialization.
How's about removing this dead/broken function instead for now?
[ IIRC for managed PCI devices these checks are done by generic code so
once IDE got converted to use it we will get them as an added bonus... ]
Thanks,
Bart
Quoted 61 lines
Signed-off-by Sergei Shtylyov <[email protected]>---
The patch is against today's Linus' tree...drivers/ide/setup-pci.c | 23 ++++++++++++----------- 1 files changed, 12 insertions(+), 11 deletions(-)Index:
linux-2.6/drivers/ide/setup-pci.c
===================================================================drivers/ide/setup-pci.c +12
-11@@ -312,11 +312,12 @@ static int ide_pci_configure(struct pci_* @d: IDE port info * @bar: BAR number * -* Checks if a BAR is configured and points to MMIO space. If so -* print an error and return an error code. Otherwise return 0 +* Checks if a BAR is configured and points to MMIO space. If so, +* return an error code. Otherwise return 0 */ -static int ide_pci_check_iomem (struct pci_dev *dev,const struct ide_port_info *d,int bar) +static int ide_pci_check_iomem (struct pci_dev *dev,const struct ide_port_info *d, +int bar) {ulong flags =pci_resource_flags (dev, bar);@@ -324,14 +325,11 @@ static int ide_pci_check_iomem(struct pcif (!flags ||pci_resource_len (dev, bar) ==0 )return 0 ; -/* I/O space */ -if (flags &PCI_BASE_ADDRESS_IO_MASK ) +/* I/O space */ +if (flags &IORESOURCE_IO )return 0 ;/* Bad */ -printk (KERN_ERR "%s: IO baseregs (BIOS) are reported " -"as MEM, report to " -"<[email protected]>.\n" , d->name);return -EINVAL ; }@@ -360,9 +358,12 @@ static ide_hwif_t *ide_hwif_configure(ststruct hw_regs_s hw;if ((d->host_flags &IDE_HFLAG_ISA_PORTS ) ==0 ) { -/* Possibly we should fail if these checks report true */ -ide_pci_check_iomem (dev, d,2 *port); -ide_pci_check_iomem (dev, d,2 *port+1 ); +if (ide_pci_check_iomem (dev, d,2 * port) || +ide_pci_check_iomem (dev, d,2 * port +1 )) { +printk (KERN_ERR "%s: I/O baseregs (BIOS) are reported " +"as MEM for port %d!\n" , d->name, port); +return NULL ; + } ctl =pci_resource_start (dev,2 *port+1 ); base =pci_resource_start (dev,2 *port);
Hello.
Quoted 9 lines · Bartlomiej Zolnierkiewicz
Quoted 4 lines
This function didn't actually check if a given BAR is in I/O space because of using the bogus
PCI_BASE_ADDRESS_IO_MASK(which equals ~3) to test the resource flags instead ofIORESOURCE_IO-- fix this, makeide_hwif_configure()check the results failing if necessary, and move theprintk()call to the failure path.This change is OK in itself but I worry that
ide_pci_check_iomem()may now return "false" errors (bogusPCI_BASE_ADDRESS_IO_MASKcheck resulted in MEM resources always survivingide_pci_check_iomem()calls before the fix) for some host drivers (siimage,scc_pata...) resulting in failed initialization.
The SiI chips do have normal I/O resources at BAR0..BAR3. As for scc_pata,
the control should not even get there because BAR0..BAR3 are *not* IDE command/control block bases on this chip (BAR0/1 are control/DMA bases if you look into setup_mmio_scc()) but they are treated as such by the code immediately following ide_pci_check_iomem() calls in ide_hwif_configure(), i.e. we might have an error here. The same can be said about the PowerMAC driver which has all its MMIO registers at BAR0.
Quoted 1 line
How's about removing this dead/broken function instead for now?
If we indeed have a MMIO problem here, it's not in this function but in
its callers.
Quoted 62 lines
Thanks,
BartQuoted 59 lines
Signed-off-by Sergei Shtylyov <[email protected]>---
The patch is against today's Linus' tree...
drivers/ide/setup-pci.c| 23 ++++++++++++-----------1 files changed, 12 insertions(+), 11 deletions(-)Index:
linux-2.6/drivers/ide/setup-pci.c
===================================================================drivers/ide/setup-pci.c +12
-11@@ -312,11 +312,12 @@ static int ide_pci_configure(struct pci_* @d: IDE port info * @bar: BAR number * -* Checks if a BAR is configured and points to MMIO space. If so -* print an error and return an error code. Otherwise return 0 +* Checks if a BAR is configured and points to MMIO space. If so, +* return an error code. Otherwise return 0 */ -static int ide_pci_check_iomem (struct pci_dev *dev,const struct ide_port_info *d,int bar) +static int ide_pci_check_iomem (struct pci_dev *dev,const struct ide_port_info *d, +int bar) {ulong flags =pci_resource_flags (dev, bar);@@ -324,14 +325,11 @@ static int ide_pci_check_iomem(struct pcif (!flags ||pci_resource_len (dev, bar) ==0 )return 0 ; -/* I/O space */ -if (flags &PCI_BASE_ADDRESS_IO_MASK ) +/* I/O space */ +if (flags &IORESOURCE_IO )return 0 ;/* Bad */ -printk (KERN_ERR "%s: IO baseregs (BIOS) are reported " -"as MEM, report to " -"<[email protected]>.\n" , d->name);return -EINVAL ; }@@ -360,9 +358,12 @@ static ide_hwif_t *ide_hwif_configure(ststruct hw_regs_s hw;if ((d->host_flags &IDE_HFLAG_ISA_PORTS ) ==0 ) { -/* Possibly we should fail if these checks report true */ -ide_pci_check_iomem (dev, d,2 *port); -ide_pci_check_iomem (dev, d,2 *port+1 ); +if (ide_pci_check_iomem (dev, d,2 * port) || +ide_pci_check_iomem (dev, d,2 * port +1 )) { +printk (KERN_ERR "%s: I/O baseregs (BIOS) are reported " +"as MEM for port %d!\n" , d->name, port); +return NULL ; + }
Quoted 2 lines
drivers/ide/setup-pci.c static ide_hwif_t *ide_hwif_configure(st · line 369
Quoted 2 lines
drivers/ide/setup-pci.c +0
-0ctl =pci_resource_start (dev,2 *port+1 ); base =pci_resource_start (dev,2 *port);
Above's the code that I was talking about...
WBR, Sergei
Quoted 10 lines · I just
Quoted 9 lines
Quoted 4 lines
This function didn't actually check if a given BAR is in I/O space because of using the bogus
PCI_BASE_ADDRESS_IO_MASK(which equals ~3) to test the resource flags instead ofIORESOURCE_IO-- fix this, makeide_hwif_configure()check the results failing if necessary, and move theprintk()call to the failure path.This change is OK in itself but I worry that
ide_pci_check_iomem()may now return "false" errors (bogusPCI_BASE_ADDRESS_IO_MASKcheck resulted in MEM resources always survivingide_pci_check_iomem()calls before the fix) for some host drivers (siimage,scc_pata...) resulting in failed initialization.
Quoted 7 lines
The SiI chips do have normal I/O resources at BAR0..BAR3. As for
scc_pata, the control should not even get there because BAR0..BAR3 are *not* IDE command/control block bases on this chip (BAR0/1 are control/DMA bases if you look intosetup_mmio_scc()) but they are treated as such by the code immediately followingide_pci_check_iomem()calls inide_hwif_configure(), i.e. we might have an error here. The same can be said about the PowerMAC driver which has all its MMIO registers at BAR0.Quoted 1 line
How's about removing this dead/broken function instead for now?
If we indeed have a MMIO problem here, it's not in this function but
in its callers.
Looks like we actually have this problem with scc_pata -- it callside_setup_pci_device() which should lead to calling ide_hwif_configure(). But this is broken since this call chain expects a normal PCI IDE controller with BAR0..BAR3 either non-existant or being primary/secondary port bases in I/O space.
Quoted 4 lines
Quoted 4 lines
Thanks,
BartQuoted 1 line
Signed-off-by Sergei Shtylyov <[email protected]>
WBR, Sergei
[ added Akira & Kou to cc: ]
Quoted 31 lines · Sergei Shtylyov
Quoted 28 lines · I just
Quoted 9 lines
Quoted 8 lines
This function didn't actually check if a given BAR is in I/O space because of
using the bogusPCI_BASE_ADDRESS_IO_MASK(which equals ~3) to test the resource
flags instead ofIORESOURCE_IO-- fix this, makeide_hwif_configure()check the
results failing if necessary, and move theprintk()call to the failure path.Quoted 8 lines
This change is OK in itself but I worry that
ide_pci_check_iomem()may now
return "false" errors (bogusPCI_BASE_ADDRESS_IO_MASKcheck resulted in MEM
resources always survivingide_pci_check_iomem()calls before the fix) for
some host drivers (siimage,scc_pata...) resulting in failed initialization.The SiI chips do have normal I/O resources at BAR0..BAR3. As for
scc_pata, the control should not even get there because BAR0..BAR3 are *not* IDE command/control block bases on this chip (BAR0/1 are control/DMA bases if you look intosetup_mmio_scc()) but they are treated as such by the code immediately followingide_pci_check_iomem()calls inide_hwif_configure(), i.e. we might have an error here. The same can be said about the PowerMAC driver which has all its MMIO registers at BAR0.Quoted 1 line
How's about removing this dead/broken function instead for now?
Quoted 7 lines
Quoted 2 lines
If we indeed have a MMIO problem here, it's not in this function but
in its callers.Looks like we actually have this problem with
scc_pata-- it callside_setup_pci_device()which should lead to callingide_hwif_configure(). But this is broken since this call chain expects a normal PCI IDE controller with BAR0..BAR3 either non-existant or being primary/secondary port bases in I/O space.
Yep, scc_pata needs fixing before your patch can be applied.
Looks like it just needs to do all the needed setup itself in init_setup_scc() instead of calling ide_setup_pci_device() [ similarly to how cs5520 host driver handles this in cs5520.c::cs5520_init_one() ].
PS it would be also nice to call pci_enable_device() before setup_mmio_scc()
(which accesses PCI BARs, calls pci_set_master() etc.) while we are at it (driver seems to work fine without it ATM but it may break in future).
Thanks,
Bart
Quoted 38 lines · Bartlomiej Zolnierkiewicz
[ added Akira & Kou to cc: ]
Quoted 34 lines · Sergei Shtylyov
Quoted 31 lines · I just
Quoted 9 lines
Quoted 8 lines
This function didn't actually check if a given BAR is in I/O space because of
using the bogusPCI_BASE_ADDRESS_IO_MASK(which equals ~3) to test the resource
flags instead ofIORESOURCE_IO-- fix this, makeide_hwif_configure()check the
results failing if necessary, and move theprintk()call to the failure path.Quoted 8 lines
This change is OK in itself but I worry that
ide_pci_check_iomem()may now
return "false" errors (bogusPCI_BASE_ADDRESS_IO_MASKcheck resulted in MEM
resources always survivingide_pci_check_iomem()calls before the fix) for
some host drivers (siimage,scc_pata...) resulting in failed initialization.The SiI chips do have normal I/O resources at BAR0..BAR3. As for
scc_pata, the control should not even get there because BAR0..BAR3 are *not* IDE command/control block bases on this chip (BAR0/1 are control/DMA bases if you look intosetup_mmio_scc()) but they are treated as such by the code immediately followingide_pci_check_iomem()calls inide_hwif_configure(), i.e. we might have an error here. The same can be said about the PowerMAC driver which has all its MMIO registers at BAR0.Quoted 1 line
How's about removing this dead/broken function instead for now?
If we indeed have a MMIO problem here, it's not in this function but
in its callers.
Quoted 6 lines
Quoted 4 lines
Looks like we actually have this problem with
scc_pata-- it callside_setup_pci_device()which should lead to callingide_hwif_configure(). But this is broken since this call chain expects a normal PCI IDE controller with BAR0..BAR3 either non-existant or being primary/secondary port bases in I/O space.Yep,
scc_pataneeds fixing before your patch can be applied.
[...]
Sergei, I applied your patch just after scc_pata's one.
Thanks,
Bart