summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorIan Romanick <idr@umwelt.(none)>2006-07-06 12:48:51 -0700
committerIan Romanick <idr@umwelt.(none)>2006-07-06 12:48:51 -0700
commit8d07ee070ecf0d403d9d27c80764d343b80af6f0 (patch)
treecf85ff7b3a3180b8395c5488d99905abd9962766 /hw
parent704e645207d88a2d0a372cf69f6abd778ed4c30b (diff)
Refactor linuxGetIOSize and linuxGetSizes. Eliminate the unnecessary
optimization in the search loop.
Diffstat (limited to 'hw')
-rw-r--r--hw/xfree86/os-support/bus/linuxPci.c59
1 files changed, 23 insertions, 36 deletions
diff --git a/hw/xfree86/os-support/bus/linuxPci.c b/hw/xfree86/os-support/bus/linuxPci.c
index 0714c9cea..7f6376a3a 100644
--- a/hw/xfree86/os-support/bus/linuxPci.c
+++ b/hw/xfree86/os-support/bus/linuxPci.c
@@ -421,7 +421,7 @@ xf86GetPciHostConfigFromTag(PCITAG Tag)
*
* Please keep this table in ascending vendor/device order.
*/
-static struct pciSizes {
+static const struct pciSizes {
unsigned short vendor, device;
unsigned long io_size, mem_size;
} pciControllerSizes[] = {
@@ -444,9 +444,12 @@ static struct pciSizes {
};
#define NUM_SIZES (sizeof(pciControllerSizes) / sizeof(pciControllerSizes[0]))
-static unsigned long
-linuxGetIOSize(PCITAG Tag)
+static const struct pciSizes *
+linuxGetSizesStruct(PCITAG Tag)
{
+ static const struct pciSizes default_size = {
+ 0, 0, 1U << 16, (unsigned long)(1ULL << 32)
+ };
pciConfigPtr pPCI;
int i;
@@ -454,47 +457,31 @@ linuxGetIOSize(PCITAG Tag)
if ((pPCI = xf86GetPciHostConfigFromTag(Tag))) {
/* Look up vendor/device */
for (i = 0; i < NUM_SIZES; i++) {
- if (pPCI->pci_vendor > pciControllerSizes[i].vendor)
- continue;
- if (pPCI->pci_vendor < pciControllerSizes[i].vendor)
- break;
- if (pPCI->pci_device > pciControllerSizes[i].device)
- continue;
- if (pPCI->pci_device < pciControllerSizes[i].device)
- break;
- return pciControllerSizes[i].io_size;
+ if ((pPCI->pci_vendor == pciControllerSizes[i].vendor)
+ && (pPCI->pci_device == pciControllerSizes[i].device)) {
+ return & pciControllerSizes[i];
+ }
}
}
- return 1U << 16; /* Default to 64K */
+ /* Default to 64KB I/O and 4GB memory. */
+ return & default_size;
}
-static void
-linuxGetSizes(PCITAG Tag, unsigned long *io_size, unsigned long *mem_size)
+static __inline__ unsigned long
+linuxGetIOSize(PCITAG Tag)
{
- pciConfigPtr pPCI;
- int i;
+ const struct pciSizes * const sizes = linuxGetSizesStruct(Tag);
+ return sizes->io_size;
+}
- *io_size = (1U << 16); /* Default to 64K */
- *mem_size = (unsigned long)(1ULL << 32); /* Default to 4G */
+static __inline__ void
+linuxGetSizes(PCITAG Tag, unsigned long *io_size, unsigned long *mem_size)
+{
+ const struct pciSizes * const sizes = linuxGetSizesStruct(Tag);
- /* Find host bridge */
- if ((pPCI = xf86GetPciHostConfigFromTag(Tag))) {
- /* Look up vendor/device */
- for (i = 0; i < NUM_SIZES; i++) {
- if (pPCI->pci_vendor > pciControllerSizes[i].vendor)
- continue;
- if (pPCI->pci_vendor < pciControllerSizes[i].vendor)
- break;
- if (pPCI->pci_device > pciControllerSizes[i].device)
- continue;
- if (pPCI->pci_device < pciControllerSizes[i].device)
- break;
- *io_size = pciControllerSizes[i].io_size;
- *mem_size = pciControllerSizes[i].mem_size;
- break;
- }
- }
+ *io_size = sizes->io_size;
+ *mem_size = sizes->mem_size;
}
_X_EXPORT int