From patchwork Sun Dec 13 13:11:34 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 67024 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nBDDfU8Y011005 for ; Sun, 13 Dec 2009 13:41:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753348AbZLMNla (ORCPT ); Sun, 13 Dec 2009 08:41:30 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753353AbZLMNl3 (ORCPT ); Sun, 13 Dec 2009 08:41:29 -0500 Received: from smtp-noauth7.primus.ca ([216.254.180.38]:51245 "HELO mail-08.primus.ca" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with SMTP id S1753348AbZLMNl3 (ORCPT ); Sun, 13 Dec 2009 08:41:29 -0500 Received: from dsl-173-206-141-177.tor.primus.ca ([173.206.141.177] helo=harry.int.wil.cx) by mail-08.primus.ca with esmtp (Exim 4.69) (envelope-from ) id 1NJoKz-0003sJ-2j; Sun, 13 Dec 2009 08:18:14 -0500 Received: by harry.int.wil.cx (Postfix, from userid 1000) id A0E9E56ABF; Sun, 13 Dec 2009 08:11:41 -0500 (EST) From: Matthew Wilcox To: linux-pci@vger.kernel.org, jbarnes@virtuousgeek.org Cc: Matthew Wilcox , Matthew Wilcox Subject: [PATCH 4/5] Add support for AGP in cur/max bus speed Date: Sun, 13 Dec 2009 08:11:34 -0500 Message-Id: <1260709895-9510-4-git-send-email-matthew@wil.cx> X-Mailer: git-send-email 1.6.5 In-Reply-To: <1260709895-9510-3-git-send-email-matthew@wil.cx> References: <1260709895-9510-1-git-send-email-matthew@wil.cx> <1260709895-9510-2-git-send-email-matthew@wil.cx> <1260709895-9510-3-git-send-email-matthew@wil.cx> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index e31c49c..64479e2 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -437,11 +437,56 @@ void pcie_update_link_speed(struct pci_bus *bus, u16 linksta) } EXPORT_SYMBOL_GPL(pcie_update_link_speed); +static unsigned char agp_speeds[] = { + AGP_UNKNOWN, + AGP_1X, + AGP_2X, + AGP_4X, + AGP_8X +}; + +static enum pci_bus_speed agp_speed(int agp3, int agpstat) +{ + int index = 0; + + if (agpstat & 4) + index = 3; + else if (agpstat & 2) + index = 2; + else if (agpstat & 1) + index = 1; + else + goto out; + + if (agp3) { + index += 2; + if (index == 5) + index = 0; + } + + out: + return agp_speeds[index]; +} + + static void pci_set_bus_speed(struct pci_bus *bus) { struct pci_dev *bridge = bus->self; int pos; + pos = pci_find_capability(bridge, PCI_CAP_ID_AGP); + if (!pos) + pos = pci_find_capability(bridge, PCI_CAP_ID_AGP3); + if (pos) { + u32 agpstat, agpcmd; + + pci_read_config_dword(bridge, pos + PCI_AGP_STATUS, &agpstat); + bus->max_bus_speed = agp_speed(agpstat & 8, agpstat & 7); + + pci_read_config_dword(bridge, pos + PCI_AGP_COMMAND, &agpcmd); + bus->cur_bus_speed = agp_speed(agpstat & 8, agpcmd & 7); + } + pos = pci_find_capability(bridge, PCI_CAP_ID_PCIX); if (pos) { u16 status; diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c index 6f6b8d2..c7260d4 100644 --- a/drivers/pci/slot.c +++ b/drivers/pci/slot.c @@ -61,11 +61,11 @@ static char *pci_bus_speed_strings[] = { "66 MHz PCI-X 266", /* 0x09 */ "100 MHz PCI-X 266", /* 0x0a */ "133 MHz PCI-X 266", /* 0x0b */ - NULL, /* 0x0c */ - NULL, /* 0x0d */ - NULL, /* 0x0e */ - NULL, /* 0x0f */ - NULL, /* 0x10 */ + "Unknown AGP", /* 0x0c */ + "1x AGP", /* 0x0d */ + "2x AGP", /* 0x0e */ + "4x AGP", /* 0x0f */ + "8x AGP", /* 0x10 */ "66 MHz PCI-X 533", /* 0x11 */ "100 MHz PCI-X 533", /* 0x12 */ "133 MHz PCI-X 533", /* 0x13 */ diff --git a/include/linux/pci.h b/include/linux/pci.h index 3f03c4c..55fa471 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -200,6 +200,11 @@ enum pci_bus_speed { PCI_SPEED_66MHz_PCIX_266 = 0x09, PCI_SPEED_100MHz_PCIX_266 = 0x0a, PCI_SPEED_133MHz_PCIX_266 = 0x0b, + AGP_UNKNOWN = 0x0c, + AGP_1X = 0x0d, + AGP_2X = 0x0e, + AGP_4X = 0x0f, + AGP_8X = 0x10, PCI_SPEED_66MHz_PCIX_533 = 0x11, PCI_SPEED_100MHz_PCIX_533 = 0x12, PCI_SPEED_133MHz_PCIX_533 = 0x13,