ia64/xen-unstable

changeset 18242:9113b3bacfac

xend: fix finding pci capability

Xend doesn't start up on my laptop which has a PCI-CardBus bridge.
PCI-CardBus bridge device doesn't have a capability chain.
Also sanity checking of a capability chain.

Signed-off-by: Kouya Shimura <kouya@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Aug 04 11:10:27 2008 +0100 (2008-08-04)
parents 6c1eb35869fd
children 206db026800c
files tools/python/xen/util/pci.py
line diff
     1.1 --- a/tools/python/xen/util/pci.py	Mon Aug 04 11:07:17 2008 +0100
     1.2 +++ b/tools/python/xen/util/pci.py	Mon Aug 04 11:10:27 2008 +0100
     1.3 @@ -44,6 +44,12 @@ PCI_STATUS = 0x6
     1.4  PCI_CLASS_DEVICE = 0x0a
     1.5  PCI_CLASS_BRIDGE_PCI = 0x0604
     1.6  
     1.7 +PCI_HEADER_TYPE = 0x0e
     1.8 +PCI_HEADER_TYPE_MASK = 0x7f
     1.9 +PCI_HEADER_TYPE_NORMAL  = 0
    1.10 +PCI_HEADER_TYPE_BRIDGE  = 1
    1.11 +PCI_HEADER_TYPE_CARDBUS = 2
    1.12 +
    1.13  PCI_CAPABILITY_LIST = 0x34
    1.14  PCI_CB_BRIDGE_CONTROL = 0x3e
    1.15  PCI_BRIDGE_CTL_BUS_RESET= 0x40
    1.16 @@ -710,12 +716,24 @@ class PciDevice:
    1.17                 self.name+SYSFS_PCI_DEV_CONFIG_PATH
    1.18          try:
    1.19              conf_file = open(path, 'rb')
    1.20 +            conf_file.seek(PCI_HEADER_TYPE)
    1.21 +            header_type = ord(conf_file.read(1)) & PCI_HEADER_TYPE_MASK
    1.22 +            if header_type == PCI_HEADER_TYPE_CARDBUS:
    1.23 +                return
    1.24              conf_file.seek(PCI_STATUS_OFFSET)
    1.25              status = ord(conf_file.read(1))
    1.26              if status&PCI_STATUS_CAP_MASK:
    1.27                  conf_file.seek(PCI_CAP_OFFSET)
    1.28                  capa_pointer = ord(conf_file.read(1))
    1.29 +                capa_count = 0
    1.30                  while capa_pointer:
    1.31 +                    if capa_pointer < 0x40:
    1.32 +                        raise PciDeviceParseError(
    1.33 +                            ('Broken capability chain: %s' % self.name))
    1.34 +                    capa_count += 1
    1.35 +                    if capa_count > 96:
    1.36 +                        raise PciDeviceParseError(
    1.37 +                            ('Looped capability chain: %s' % self.name))
    1.38                      conf_file.seek(capa_pointer)
    1.39                      capa_id = ord(conf_file.read(1))
    1.40                      capa_pointer = ord(conf_file.read(1))