From owner-svn-src-head@freebsd.org Wed Mar 29 23:13:05 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DE9F8D2416C; Wed, 29 Mar 2017 23:13:05 +0000 (UTC) (envelope-from gavin@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B6BC4A58; Wed, 29 Mar 2017 23:13:05 +0000 (UTC) (envelope-from gavin@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2TND4Qr031353; Wed, 29 Mar 2017 23:13:04 GMT (envelope-from gavin@FreeBSD.org) Received: (from gavin@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2TND4Qc031352; Wed, 29 Mar 2017 23:13:04 GMT (envelope-from gavin@FreeBSD.org) Message-Id: <201703292313.v2TND4Qc031352@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: gavin set sender to gavin@FreeBSD.org using -f From: Gavin Atkinson Date: Wed, 29 Mar 2017 23:13:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r316184 - head/sys/dev/ichsmb X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Mar 2017 23:13:06 -0000 Author: gavin Date: Wed Mar 29 23:13:04 2017 New Revision: 316184 URL: https://svnweb.freebsd.org/changeset/base/316184 Log: ichsmb: switch device_probe() from a large case statement to a lookup table. The case statement was getting unmanageably large, and I'm about to add several more devices to it. MFC after: 2 weeks Modified: head/sys/dev/ichsmb/ichsmb_pci.c Modified: head/sys/dev/ichsmb/ichsmb_pci.c ============================================================================== --- head/sys/dev/ichsmb/ichsmb_pci.c Wed Mar 29 23:00:07 2017 (r316183) +++ head/sys/dev/ichsmb/ichsmb_pci.c Wed Mar 29 23:13:04 2017 (r316184) @@ -67,33 +67,71 @@ __FBSDID("$FreeBSD$"); #include /* PCI unique identifiers */ -#define ID_82801AA 0x24138086 -#define ID_82801AB 0x24238086 -#define ID_82801BA 0x24438086 -#define ID_82801CA 0x24838086 -#define ID_82801DC 0x24C38086 -#define ID_82801EB 0x24D38086 -#define ID_82801FB 0x266A8086 -#define ID_82801GB 0x27da8086 -#define ID_82801H 0x283e8086 -#define ID_82801I 0x29308086 -#define ID_82801JI 0x3a308086 -#define ID_PCH 0x3b308086 -#define ID_6300ESB 0x25a48086 -#define ID_631xESB 0x269b8086 -#define ID_DH89XXCC 0x23308086 -#define ID_PATSBURG 0x1d228086 -#define ID_CPT 0x1c228086 -#define ID_PPT 0x1e228086 -#define ID_AVOTON 0x1f3c8086 -#define ID_COLETOCRK 0x23B08086 -#define ID_LPT 0x8c228086 -#define ID_LPTLP 0x9c228086 -#define ID_WCPT 0x8ca28086 -#define ID_WCPTLP 0x9ca28086 -#define ID_WELLSBURG 0x8d228086 -#define ID_SRPT 0xa1238086 -#define ID_SRPTLP 0x9d238086 +#define PCI_VENDOR_INTEL 0x8086 +#define ID_82801AA 0x2413 +#define ID_82801AB 0x2423 +#define ID_82801BA 0x2443 +#define ID_82801CA 0x2483 +#define ID_82801DC 0x24C3 +#define ID_82801EB 0x24D3 +#define ID_82801FB 0x266A +#define ID_82801GB 0x27da +#define ID_82801H 0x283e +#define ID_82801I 0x2930 +#define ID_82801JI 0x3a30 +#define ID_PCH 0x3b30 +#define ID_6300ESB 0x25a4 +#define ID_631xESB 0x269b +#define ID_DH89XXCC 0x2330 +#define ID_PATSBURG 0x1d22 +#define ID_CPT 0x1c22 +#define ID_PPT 0x1e22 +#define ID_AVOTON 0x1f3c +#define ID_COLETOCRK 0x23B0 +#define ID_LPT 0x8c22 +#define ID_LPTLP 0x9c22 +#define ID_WCPT 0x8ca2 +#define ID_WCPTLP 0x9ca2 +#define ID_WELLSBURG 0x8d22 +#define ID_SRPT 0xa123 +#define ID_SRPTLP 0x9d23 + +static const struct ichsmb_device { + uint16_t id; + const char *name; +} ichsmb_devices[] = { + { ID_82801AA, "Intel 82801AA (ICH) SMBus controller" }, + { ID_82801AB, "Intel 82801AB (ICH0) SMBus controller" }, + { ID_82801BA, "Intel 82801BA (ICH2) SMBus controller" }, + { ID_82801CA, "Intel 82801CA (ICH3) SMBus controller" }, + { ID_82801DC, "Intel 82801DC (ICH4) SMBus controller" }, + { ID_82801EB, "Intel 82801EB (ICH5) SMBus controller" }, + { ID_82801FB, "Intel 82801FB (ICH6) SMBus controller" }, + { ID_82801GB, "Intel 82801GB (ICH7) SMBus controller" }, + { ID_82801H, "Intel 82801H (ICH8) SMBus controller" }, + { ID_82801I, "Intel 82801I (ICH9) SMBus controller" }, + { ID_82801GB, "Intel 82801GB (ICH7) SMBus controller" }, + { ID_82801H, "Intel 82801H (ICH8) SMBus controller" }, + { ID_82801I, "Intel 82801I (ICH9) SMBus controller" }, + { ID_82801JI, "Intel 82801JI (ICH10) SMBus controller" }, + { ID_PCH, "Intel PCH SMBus controller" }, + { ID_6300ESB, "Intel 6300ESB (ICH) SMBus controller" }, + { ID_631xESB, "Intel 631xESB/6321ESB (ESB2) SMBus controller" }, + { ID_DH89XXCC, "Intel DH89xxCC SMBus controller" }, + { ID_PATSBURG, "Intel Patsburg SMBus controller" }, + { ID_CPT, "Intel Cougar Point SMBus controller" }, + { ID_PPT, "Intel Panther Point SMBus controller" }, + { ID_AVOTON, "Intel Avoton SMBus controller" }, + { ID_LPT, "Intel Lynx Point SMBus controller" }, + { ID_LPTLP, "Intel Lynx Point-LP SMBus controller" }, + { ID_WCPT, "Intel Wildcat Point SMBus controller" }, + { ID_WCPTLP, "Intel Wildcat Point-LP SMBus controller" }, + { ID_COLETOCRK, "Intel Coleto Creek SMBus controller" }, + { ID_WELLSBURG, "Intel Wellsburg SMBus controller" }, + { ID_SRPT, "Intel Sunrise Point-H SMBus controller" }, + { ID_SRPTLP, "Intel Sunrise Point-LP SMBus controller" }, + { 0, NULL }, +}; /* Internal functions */ static int ichsmb_pci_probe(device_t dev); @@ -139,95 +177,19 @@ DRIVER_MODULE(ichsmb, pci, ichsmb_pci_dr static int ichsmb_pci_probe(device_t dev) { - /* Check PCI identifier */ - switch (pci_get_devid(dev)) { - case ID_82801AA: - device_set_desc(dev, "Intel 82801AA (ICH) SMBus controller"); - break; - case ID_82801AB: - device_set_desc(dev, "Intel 82801AB (ICH0) SMBus controller"); - break; - case ID_82801BA: - device_set_desc(dev, "Intel 82801BA (ICH2) SMBus controller"); - break; - case ID_82801CA: - device_set_desc(dev, "Intel 82801CA (ICH3) SMBus controller"); - break; - case ID_82801DC: - device_set_desc(dev, "Intel 82801DC (ICH4) SMBus controller"); - break; - case ID_82801EB: - device_set_desc(dev, "Intel 82801EB (ICH5) SMBus controller"); - break; - case ID_82801FB: - device_set_desc(dev, "Intel 82801FB (ICH6) SMBus controller"); - break; - case ID_82801GB: - device_set_desc(dev, "Intel 82801GB (ICH7) SMBus controller"); - break; - case ID_82801H: - device_set_desc(dev, "Intel 82801H (ICH8) SMBus controller"); - break; - case ID_82801I: - device_set_desc(dev, "Intel 82801I (ICH9) SMBus controller"); - break; - case ID_82801JI: - device_set_desc(dev, "Intel 82801JI (ICH10) SMBus controller"); - break; - case ID_PCH: - device_set_desc(dev, "Intel PCH SMBus controller"); - break; - case ID_6300ESB: - device_set_desc(dev, "Intel 6300ESB (ICH) SMBus controller"); - break; - case ID_631xESB: - device_set_desc(dev, "Intel 631xESB/6321ESB (ESB2) SMBus controller"); - break; - case ID_DH89XXCC: - device_set_desc(dev, "Intel DH89xxCC SMBus controller"); - break; - case ID_PATSBURG: - device_set_desc(dev, "Intel Patsburg SMBus controller"); - break; - case ID_CPT: - device_set_desc(dev, "Intel Cougar Point SMBus controller"); - break; - case ID_PPT: - device_set_desc(dev, "Intel Panther Point SMBus controller"); - break; - case ID_AVOTON: - device_set_desc(dev, "Intel Avoton SMBus controller"); - break; - case ID_LPT: - device_set_desc(dev, "Intel Lynx Point SMBus controller"); - break; - case ID_LPTLP: - device_set_desc(dev, "Intel Lynx Point-LP SMBus controller"); - break; - case ID_WCPT: - device_set_desc(dev, "Intel Wildcat Point SMBus controller"); - break; - case ID_WCPTLP: - device_set_desc(dev, "Intel Wildcat Point-LP SMBus controller"); - break; - case ID_COLETOCRK: - device_set_desc(dev, "Intel Coleto Creek SMBus controller"); - break; - case ID_WELLSBURG: - device_set_desc(dev, "Intel Wellsburg SMBus controller"); - break; - case ID_SRPT: - device_set_desc(dev, "Intel Sunrise Point-H SMBus controller"); - break; - case ID_SRPTLP: - device_set_desc(dev, "Intel Sunrise Point-LP SMBus controller"); - break; - default: + const struct ichsmb_device *device; + + if (pci_get_vendor(dev) != PCI_VENDOR_INTEL) return (ENXIO); + + for (device = ichsmb_devices; device->name != NULL; device++) { + if (pci_get_device(dev) == device->id) { + device_set_desc(dev, device->name); + return (ichsmb_probe(dev)); + } } - /* Done */ - return (ichsmb_probe(dev)); + return (ENXIO); } static int