mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Testing for extended PCI config space
@ 2004-02-18 19:01 Matthew Wilcox
  0 siblings, 0 replies; only message in thread
From: Matthew Wilcox @ 2004-02-18 19:01 UTC (permalink / raw)
  To: linux-pci; +Cc: linux-kernel


It's kind of tricky to figure out whether we can access the extended
config space or not.  Given that nobody checks the return value from
pci_read_config_*(), I don't know whether we'll be able to persuade them
to check pdev->cfg_size or not, but we can at least try to get it right.

/**
 * pci_cfg_space_size - get the configuration space size of the PCI device.
 *
 * Regular PCI devices have 256 bytes, but PCI-X 2 and PCI Express devices
 * have 4096 bytes.  Even if the device is capable, that doesn't mean we can
 * access it.  Maybe we don't have a way to generate extended config space
 * accesses, or the device is behind a reverse Express bridge.  So we try
 * reading the dword at 0x100 which must either be 0 or a valid extended
 * capability header.
 */
static int pci_cfg_space_size(struct pci_dev *dev)
{
        int pos;
        u32 status;

        pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
        if (!pos) {
                pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
                if (!pos)
                        goto fail;

                pci_read_config_dword(dev, pos + PCI_X_STATUS, &status);
                if (!(status & (PCI_X_STATUS_266MHZ | PCI_X_STATUS_533MHZ)))
                        goto fail;
        }

        if (pci_read_config_dword(dev, 256, &status) != PCIBIOS_SUCCESSFUL)
                goto fail;
        if (status == 0xffffffff)
                goto fail;

        return PCI_CFG_SPACE_EXP_SIZE;

 fail:
        return PCI_CFG_SPACE_SIZE;
}


-- 
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-02-18 19:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-18 19:01 Testing for extended PCI config space Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®