From f7091710a8c417878afb3ad80f07ad93b909eedd Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 28 May 2012 17:25:08 +0100 Subject: [PATCH] streamline-agp-find --- drivers/char/agp/intel-gtt.c | 56 ++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c index 912846f..32ae84c 100644 --- a/drivers/char/agp/intel-gtt.c +++ b/drivers/char/agp/intel-gtt.c @@ -1513,37 +1513,53 @@ static const struct intel_gtt_driver_description { { 0, NULL, NULL } }; -static int find_gmch(u16 device) +static int match_intel_vga(struct device *dev, void *data) { - struct pci_dev *gmch_device; + struct pci_dev *pdev = to_pci_dev(dev); + return (pdev->vendor == PCI_VENDOR_ID_INTEL && + pdev->class >> 16 == PCI_BASE_CLASS_DISPLAY && + PCI_FUNC(pdev->devfn) == 0); +} - gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL); - if (gmch_device && PCI_FUNC(gmch_device->devfn) != 0) { - gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, - device, gmch_device); - } +static struct pci_dev *find_gmch(void) +{ + struct device *dev; - if (!gmch_device) - return 0; + dev = bus_find_device(&pci_bus_type, NULL, NULL, match_intel_vga); + if (dev == NULL) + return NULL; - intel_private.pcidev = gmch_device; - return 1; + return to_pci_dev(dev); } -int intel_gmch_probe(struct pci_dev *pdev, - struct agp_bridge_data *bridge) +static const struct intel_gtt_driver * +find_driver(struct pci_dev *pdev) { - int i, mask; - intel_private.driver = NULL; + int i; for (i = 0; intel_gtt_chipsets[i].name != NULL; i++) { - if (find_gmch(intel_gtt_chipsets[i].gmch_chip_id)) { - intel_private.driver = - intel_gtt_chipsets[i].gtt_driver; - break; + if (pdev->device == intel_gtt_chipsets[i].gmch_chip_id) { + dev_info(&pdev->dev, + "Intel %s Chipset\n", + intel_gtt_chipsets[i].name); + + return intel_gtt_chipsets[i].gtt_driver; } } + return NULL; +} + +int intel_gmch_probe(struct pci_dev *pdev, + struct agp_bridge_data *bridge) +{ + int mask; + + intel_private.pcidev = find_gmch(); + if (!intel_private.pcidev) + return 0; + + intel_private.driver = find_driver(intel_private.pcidev); if (!intel_private.driver) return 0; @@ -1553,8 +1569,6 @@ int intel_gmch_probe(struct pci_dev *pdev, intel_private.bridge_dev = pci_dev_get(pdev); - dev_info(&pdev->dev, "Intel %s Chipset\n", intel_gtt_chipsets[i].name); - mask = intel_private.driver->dma_mask_size; if (pci_set_dma_mask(intel_private.pcidev, DMA_BIT_MASK(mask))) dev_err(&intel_private.pcidev->dev, -- 1.7.10