Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 Jul 2017 15:19:07 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r321720 - head/sys/dev/ichwd
Message-ID:  <201707301519.v6UFJ7AT004183@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Sun Jul 30 15:19:07 2017
New Revision: 321720
URL: https://svnweb.freebsd.org/changeset/base/321720

Log:
  Attach ichwd(4) only to ISA bus of the LPC bridge.
  
  Resource allocation for parent device does not look good by itself, but
  attempt to allocate them for unrelated device just does not end up good.
  On Asus X99-E WS/USB3.1 system reporting ISA bridge via both PCI and ACPI
  this reported to cause kernel panic on shutdown due to messed resources:
  https://bugs.freenas.org/issues/25237.
  
  MFC after:	1 week

Modified:
  head/sys/dev/ichwd/ichwd.c

Modified: head/sys/dev/ichwd/ichwd.c
==============================================================================
--- head/sys/dev/ichwd/ichwd.c	Sun Jul 30 11:50:16 2017	(r321719)
+++ head/sys/dev/ichwd/ichwd.c	Sun Jul 30 15:19:07 2017	(r321720)
@@ -533,23 +533,26 @@ ichwd_event(void *arg, unsigned int cmd, int *error)
 }
 
 static device_t
-ichwd_find_ich_lpc_bridge(struct ichwd_device **id_p)
+ichwd_find_ich_lpc_bridge(device_t isa, struct ichwd_device **id_p)
 {
 	struct ichwd_device *id;
-	device_t ich = NULL;
+	device_t isab;
+	uint16_t devid;
 
-	/* look for an ICH LPC interface bridge */
-	for (id = ichwd_devices; id->desc != NULL; ++id)
-		if ((ich = pci_find_device(VENDORID_INTEL, id->device)) != NULL)
-			break;
-
-	if (ich == NULL)
+	/* Check whether parent ISA bridge looks familiar. */
+	isab = device_get_parent(isa);
+	if (pci_get_vendor(isab) != VENDORID_INTEL)
 		return (NULL);
+	devid = pci_get_device(isab);
+	for (id = ichwd_devices; id->desc != NULL; ++id) {
+		if (devid == id->device) {
+			if (id_p != NULL)
+				*id_p = id;
+			return (isab);
+		}
+	}
 
-	if (id_p)
-		*id_p = id;
-
-	return (ich);
+	return (NULL);
 }
 
 /*
@@ -565,7 +568,7 @@ ichwd_identify(driver_t *driver, device_t parent)
 	uint32_t base_address;
 	int rc;
 
-	ich = ichwd_find_ich_lpc_bridge(&id_p);
+	ich = ichwd_find_ich_lpc_bridge(parent, &id_p);
 	if (ich == NULL)
 		return;
 
@@ -618,7 +621,7 @@ ichwd_probe(device_t dev)
 	if (isa_get_logicalid(dev) != 0)
 		return (ENXIO);
 
-	if (ichwd_find_ich_lpc_bridge(&id_p) == NULL)
+	if (ichwd_find_ich_lpc_bridge(device_get_parent(dev), &id_p) == NULL)
 		return (ENXIO);
 
 	device_set_desc_copy(dev, id_p->desc);
@@ -636,7 +639,7 @@ ichwd_attach(device_t dev)
 	sc = device_get_softc(dev);
 	sc->device = dev;
 
-	ich = ichwd_find_ich_lpc_bridge(&id_p);
+	ich = ichwd_find_ich_lpc_bridge(device_get_parent(dev), &id_p);
 	if (ich == NULL) {
 		device_printf(sc->device, "Can not find ICH device.\n");
 		goto fail;
@@ -726,7 +729,6 @@ static int
 ichwd_detach(device_t dev)
 {
 	struct ichwd_softc *sc;
-	device_t ich = NULL;
 
 	sc = device_get_softc(dev);
 
@@ -751,9 +753,8 @@ ichwd_detach(device_t dev)
 	bus_release_resource(dev, SYS_RES_IOPORT, sc->smi_rid, sc->smi_res);
 
 	/* deallocate memory resource */
-	ich = ichwd_find_ich_lpc_bridge(NULL);
-	if (sc->gcs_res && ich)
-		bus_release_resource(ich, SYS_RES_MEMORY, sc->gcs_rid,
+	if (sc->gcs_res)
+		bus_release_resource(sc->ich, SYS_RES_MEMORY, sc->gcs_rid,
 		    sc->gcs_res);
 
 	return (0);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201707301519.v6UFJ7AT004183>