[Midnightbsd-cvs] src [9917] trunk/sys/pci: sync with freebsd 10-stable

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Fri May 25 08:55:41 EDT 2018


Revision: 9917
          http://svnweb.midnightbsd.org/src/?rev=9917
Author:   laffer1
Date:     2018-05-25 08:55:40 -0400 (Fri, 25 May 2018)
Log Message:
-----------
sync with freebsd 10-stable

Modified Paths:
--------------
    trunk/sys/pci/intpm.c
    trunk/sys/pci/ncr.c

Modified: trunk/sys/pci/intpm.c
===================================================================
--- trunk/sys/pci/intpm.c	2018-05-25 12:54:08 UTC (rev 9916)
+++ trunk/sys/pci/intpm.c	2018-05-25 12:55:40 UTC (rev 9917)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1998, 1999 Takanori Watanabe
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/pci/intpm.c 310076 2016-12-14 16:35:17Z avg $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -43,6 +44,7 @@
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>
 #include <pci/intpmreg.h>
+#include <dev/amdsbwd/amd_chipset.h>
 
 #include "opt_intpm.h"
 
@@ -52,8 +54,10 @@
 	struct resource		*irq_res;
 	void			*irq_hand;
 	device_t		smbus;
+	int			io_rid;
 	int			isbusy;
 	int			cfg_irq9;
+	int			sb8xx;
 	int			poll;
 	struct mtx		lock;
 };
@@ -101,13 +105,13 @@
 	case 0x43721002:
 		device_set_desc(dev, "ATI IXP400 SMBus Controller");
 		break;
-	case 0x43851002:
-		/* SB800 and newer can not be configured in a compatible way. */
-		if (pci_get_revid(dev) >= 0x40)
-			return (ENXIO);
-		device_set_desc(dev, "AMD SB600/700/710/750 SMBus Controller");
-		/* XXX Maybe force polling right here? */
+	case AMDSB_SMBUS_DEVID:
+		device_set_desc(dev, "AMD SB600/7xx/8xx/9xx SMBus Controller");
 		break;
+	case AMDFCH_SMBUS_DEVID:	/* AMD FCH */
+	case AMDCZ_SMBUS_DEVID:		/* AMD Carizzo FCH */
+		device_set_desc(dev, "AMD FCH SMBus Controller");
+		break;
 	default:
 		return (ENXIO);
 	}
@@ -115,7 +119,101 @@
 	return (BUS_PROBE_DEFAULT);
 }
 
+static uint8_t
+amd_pmio_read(struct resource *res, uint8_t reg)
+{
+	bus_write_1(res, 0, reg);	/* Index */
+	return (bus_read_1(res, 1));	/* Data */
+}
+
 static int
+sb8xx_attach(device_t dev)
+{
+	static const int	AMDSB_SMBIO_WIDTH = 0x14;
+	struct intsmb_softc	*sc;
+	struct resource		*res;
+	uint32_t		devid;
+	uint8_t			revid;
+	uint16_t		addr;
+	int			rid;
+	int			rc;
+	bool			enabled;
+
+	sc = device_get_softc(dev);
+	rid = 0;
+	rc = bus_set_resource(dev, SYS_RES_IOPORT, rid, AMDSB_PMIO_INDEX,
+	    AMDSB_PMIO_WIDTH);
+	if (rc != 0) {
+		device_printf(dev, "bus_set_resource for PM IO failed\n");
+		return (ENXIO);
+	}
+	res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
+	    RF_ACTIVE);
+	if (res == NULL) {
+		device_printf(dev, "bus_alloc_resource for PM IO failed\n");
+		return (ENXIO);
+	}
+
+	devid = pci_get_devid(dev);
+	revid = pci_get_revid(dev);
+	if (devid == AMDSB_SMBUS_DEVID ||
+	    (devid == AMDFCH_SMBUS_DEVID && revid < AMDFCH41_SMBUS_REVID) ||
+	    (devid == AMDCZ_SMBUS_DEVID  && revid < AMDCZ49_SMBUS_REVID)) {
+		addr = amd_pmio_read(res, AMDSB8_PM_SMBUS_EN + 1);
+		addr <<= 8;
+		addr |= amd_pmio_read(res, AMDSB8_PM_SMBUS_EN);
+		enabled = (addr & AMDSB8_SMBUS_EN) != 0;
+		addr &= AMDSB8_SMBUS_ADDR_MASK;
+	} else {
+		addr = amd_pmio_read(res, AMDFCH41_PM_DECODE_EN0);
+		enabled = (addr & AMDFCH41_SMBUS_EN) != 0;
+		addr = amd_pmio_read(res, AMDFCH41_PM_DECODE_EN1);
+		addr <<= 8;
+	}
+
+	bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
+	bus_delete_resource(dev, SYS_RES_IOPORT, rid);
+
+	if (!enabled) {
+		device_printf(dev, "SB8xx/SB9xx/FCH SMBus not enabled\n");
+		return (ENXIO);
+	}
+
+	sc->io_rid = 0;
+	rc = bus_set_resource(dev, SYS_RES_IOPORT, sc->io_rid, addr,
+	    AMDSB_SMBIO_WIDTH);
+	if (rc != 0) {
+		device_printf(dev, "bus_set_resource for SMBus IO failed\n");
+		return (ENXIO);
+	}
+	if (res == NULL) {
+		device_printf(dev, "bus_alloc_resource for SMBus IO failed\n");
+		return (ENXIO);
+	}
+	sc->io_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &sc->io_rid,
+	    RF_ACTIVE);
+	sc->poll = 1;
+	return (0);
+}
+
+static void
+intsmb_release_resources(device_t dev)
+{
+	struct intsmb_softc *sc = device_get_softc(dev);
+
+	if (sc->smbus)
+		device_delete_child(dev, sc->smbus);
+	if (sc->irq_hand)
+		bus_teardown_intr(dev, sc->irq_res, sc->irq_hand);
+	if (sc->irq_res)
+		bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
+	if (sc->io_res)
+		bus_release_resource(dev, SYS_RES_IOPORT, sc->io_rid,
+		    sc->io_res);
+	mtx_destroy(&sc->lock);
+}
+
+static int
 intsmb_attach(device_t dev)
 {
 	struct intsmb_softc *sc = device_get_softc(dev);
@@ -128,18 +226,34 @@
 	mtx_init(&sc->lock, device_get_nameunit(dev), "intsmb", MTX_DEF);
 
 	sc->cfg_irq9 = 0;
+	switch (pci_get_devid(dev)) {
 #ifndef NO_CHANGE_PCICONF
-	switch (pci_get_devid(dev)) {
 	case 0x71138086:	/* Intel 82371AB */
 	case 0x719b8086:	/* Intel 82443MX */
 		/* Changing configuration is allowed. */
 		sc->cfg_irq9 = 1;
 		break;
+#endif
+	case AMDSB_SMBUS_DEVID:
+		if (pci_get_revid(dev) >= AMDSB8_SMBUS_REVID)
+			sc->sb8xx = 1;
+		break;
+	case AMDFCH_SMBUS_DEVID:
+	case AMDCZ_SMBUS_DEVID:
+		sc->sb8xx = 1;
+		break;
 	}
-#endif
 
-	rid = PCI_BASE_ADDR_SMB;
-	sc->io_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
+	if (sc->sb8xx) {
+		error = sb8xx_attach(dev);
+		if (error != 0)
+			goto fail;
+		else
+			goto no_intr;
+	}
+
+	sc->io_rid = PCI_BASE_ADDR_SMB;
+	sc->io_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &sc->io_rid,
 	    RF_ACTIVE);
 	if (sc->io_res == NULL) {
 		device_printf(dev, "Could not allocate I/O space\n");
@@ -212,12 +326,15 @@
 	sc->isbusy = 0;
 	sc->smbus = device_add_child(dev, "smbus", -1);
 	if (sc->smbus == NULL) {
+		device_printf(dev, "failed to add smbus child\n");
 		error = ENXIO;
 		goto fail;
 	}
 	error = device_probe_and_attach(sc->smbus);
-	if (error)
+	if (error) {
+		device_printf(dev, "failed to probe+attach smbus child\n");
 		goto fail;
+	}
 
 #ifdef ENABLE_ALART
 	/* Enable Arart */
@@ -226,7 +343,7 @@
 	return (0);
 
 fail:
-	intsmb_detach(dev);
+	intsmb_release_resources(dev);
 	return (error);
 }
 
@@ -233,23 +350,15 @@
 static int
 intsmb_detach(device_t dev)
 {
-	struct intsmb_softc *sc = device_get_softc(dev);
 	int error;
 
 	error = bus_generic_detach(dev);
-	if (error)
+	if (error) {
+		device_printf(dev, "bus detach failed\n");
 		return (error);
+	}
 
-	if (sc->smbus)
-		device_delete_child(dev, sc->smbus);
-	if (sc->irq_hand)
-		bus_teardown_intr(dev, sc->irq_res, sc->irq_hand);
-	if (sc->irq_res)
-		bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
-	if (sc->io_res)
-		bus_release_resource(dev, SYS_RES_IOPORT, PCI_BASE_ADDR_SMB,
-		    sc->io_res);
-	mtx_destroy(&sc->lock);
+	intsmb_release_resources(dev);
 	return (0);
 }
 
@@ -677,39 +786,11 @@
 	return (error);
 }
 
-/*
- * Data sheet claims that it implements all function, but also claims
- * that it implements 7 function and not mention PCALL. So I don't know
- * whether it will work.
- */
 static int
 intsmb_pcall(device_t dev, u_char slave, char cmd, short sdata, short *rdata)
 {
-#ifdef PROCCALL_TEST
-	struct intsmb_softc *sc = device_get_softc(dev);
-	int error;
 
-	INTSMB_LOCK(sc);
-	error = intsmb_free(sc);
-	if (error) {
-		INTSMB_UNLOCK(sc);
-		return (error);
-	}
-	bus_write_1(sc->io_res, PIIX4_SMBHSTADD, slave & ~LSB);
-	bus_write_1(sc->io_res, PIIX4_SMBHSTCMD, cmd);
-	bus_write_1(sc->io_res, PIIX4_SMBHSTDAT0, sdata & 0xff);
-	bus_write_1(sc->io_res, PIIX4_SMBHSTDAT1, (sdata & 0xff) >> 8);
-	intsmb_start(sc, PIIX4_SMBHSTCNT_PROT_WDATA, 0);
-	error = intsmb_stop(sc);
-	if (error == 0) {
-		*rdata = bus_read_1(sc->io_res, PIIX4_SMBHSTDAT0);
-		*rdata |= bus_read_1(sc->io_res, PIIX4_SMBHSTDAT1) << 8;
-	}
-	INTSMB_UNLOCK(sc);
-	return (error);
-#else
 	return (SMB_ENOTSUPP);
-#endif
 }
 
 static int
@@ -749,9 +830,6 @@
 	int error, i;
 	u_char data, nread;
 
-	if (*count > SMBBLOCKTRANS_MAX || *count == 0)
-		return (SMB_EINVAL);
-
 	INTSMB_LOCK(sc);
 	error = intsmb_free(sc);
 	if (error) {
@@ -764,18 +842,14 @@
 
 	bus_write_1(sc->io_res, PIIX4_SMBHSTADD, slave | LSB);
 	bus_write_1(sc->io_res, PIIX4_SMBHSTCMD, cmd);
-	bus_write_1(sc->io_res, PIIX4_SMBHSTDAT0, *count);
 	intsmb_start(sc, PIIX4_SMBHSTCNT_PROT_BLOCK, 0);
 	error = intsmb_stop(sc);
 	if (error == 0) {
 		nread = bus_read_1(sc->io_res, PIIX4_SMBHSTDAT0);
 		if (nread != 0 && nread <= SMBBLOCKTRANS_MAX) {
-			for (i = 0; i < nread; i++) {
+			*count = nread;
+			for (i = 0; i < nread; i++)
 				data = bus_read_1(sc->io_res, PIIX4_SMBBLKDAT);
-				if (i < *count)
-					buf[i] = data;
-			}
-			*count = nread;
 		} else
 			error = SMB_EBUSERR;
 	}
@@ -813,7 +887,8 @@
 	sizeof(struct intsmb_softc),
 };
 
-DRIVER_MODULE(intsmb, pci, intsmb_driver, intsmb_devclass, 0, 0);
+DRIVER_MODULE_ORDERED(intsmb, pci, intsmb_driver, intsmb_devclass, 0, 0,
+    SI_ORDER_ANY);
 DRIVER_MODULE(smbus, intsmb, smbus_driver, smbus_devclass, 0, 0);
 MODULE_DEPEND(intsmb, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER);
 MODULE_VERSION(intsmb, 1);

Modified: trunk/sys/pci/ncr.c
===================================================================
--- trunk/sys/pci/ncr.c	2018-05-25 12:54:08 UTC (rev 9916)
+++ trunk/sys/pci/ncr.c	2018-05-25 12:55:40 UTC (rev 9917)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /**************************************************************************
 **
 **
@@ -40,7 +41,7 @@
 */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/pci/ncr.c 254263 2013-08-12 23:30:01Z scottl $");
 
 
 #define NCR_DATE "pl30 98/1/1"
@@ -4857,7 +4858,7 @@
 	*/
 	fak = (kpc - 1) / div_10M[div] + 1;
 
-#if 0	/* You can #if 1 if you think this optimization is usefull */
+#if 0	/* You can #if 1 if you think this optimization is useful */
 
 	per = (fak * div_10M[div]) / clk;
 
@@ -5544,7 +5545,6 @@
 	**	Freeze system to be able to read the messages.
 	*/
 	printf ("ncr: fatal error: system halted - press reset to reboot ...");
-	(void) splhigh();
 	for (;;);
 #endif
 
@@ -6397,12 +6397,8 @@
 	(ncb_p np, u_long target, u_long lun)
 {
 	lcb_p lp;
-	int s;
 	nccb_p cp = NULL;
 
-	/* Keep our timeout handler out */
-	s = splsoftclock();
-	
 	/*
 	**	Lun structure available ?
 	*/
@@ -6430,12 +6426,10 @@
 	if (cp != NULL) {
 		if (cp->magic) {
 			printf("%s: Bogus free cp found\n", ncr_name(np));
-			splx(s);
 			return (NULL);
 		}
 		cp->magic = 1;
 	}
-	splx(s);
 	return (cp);
 }
 



More information about the Midnightbsd-cvs mailing list