Module Name:    src
Committed By:   riastradh
Date:           Thu Sep 22 14:41:26 UTC 2022

Modified Files:
        src/sys/arch/x86/pci: ichlpcib.c tco.c tco.h

Log Message:
tco(4): Change has_rcba bit into version number.

Will be useful for newer Intel platform controller hubs.

No functional change intended.  Module ABI is unchanged, although older
modules will do something nonseneical when confronted with versions
above 1 -- that will require a revbump (but with any luck, it will make
life easier for versions above 2 easier once we do that).


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/x86/pci/ichlpcib.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x86/pci/tco.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/x86/pci/tco.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/ichlpcib.c
diff -u src/sys/arch/x86/pci/ichlpcib.c:1.54 src/sys/arch/x86/pci/ichlpcib.c:1.55
--- src/sys/arch/x86/pci/ichlpcib.c:1.54	Sat Aug  7 16:19:07 2021
+++ src/sys/arch/x86/pci/ichlpcib.c	Thu Sep 22 14:41:26 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ichlpcib.c,v 1.54 2021/08/07 16:19:07 thorpej Exp $	*/
+/*	$NetBSD: ichlpcib.c,v 1.55 2022/09/22 14:41:26 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ichlpcib.c,v 1.54 2021/08/07 16:19:07 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ichlpcib.c,v 1.55 2022/09/22 14:41:26 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -635,12 +635,15 @@ tcotimer_configure(device_t self)
 	struct lpcib_softc *sc = device_private(self);
 	struct lpcib_tco_attach_args arg;
 
+	if (sc->sc_has_rcba)
+		arg.ta_version = TCO_VERSION_RCBA;
+	else
+		arg.ta_version = TCO_VERSION_PCIB;
 	arg.ta_iot = sc->sc_iot;
 	arg.ta_ioh = sc->sc_ioh;
 	arg.ta_rcbat = sc->sc_rcbat;
 	arg.ta_rcbah = sc->sc_rcbah;
-	arg.ta_has_rcba = sc->sc_has_rcba;
-	arg.ta_pcib = &(sc->sc_pcib);
+	arg.ta_pcib = &sc->sc_pcib;
 
 	sc->sc_tco = config_found(self, &arg, NULL,
 	    CFARGS(.iattr = "tcoichbus"));

Index: src/sys/arch/x86/pci/tco.c
diff -u src/sys/arch/x86/pci/tco.c:1.3 src/sys/arch/x86/pci/tco.c:1.4
--- src/sys/arch/x86/pci/tco.c:1.3	Wed Sep 21 10:36:14 2022
+++ src/sys/arch/x86/pci/tco.c	Thu Sep 22 14:41:26 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tco.c,v 1.3 2022/09/21 10:36:14 riastradh Exp $	*/
+/*	$NetBSD: tco.c,v 1.4 2022/09/22 14:41:26 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tco.c,v 1.3 2022/09/21 10:36:14 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tco.c,v 1.4 2022/09/22 14:41:26 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -63,7 +63,7 @@ struct tco_softc {
 	int			sc_armed;
 	unsigned int		sc_min_t;
 	unsigned int		sc_max_t;
-	int			sc_has_rcba;
+	int			sc_version;
 };
 
 static int tco_match(device_t, cfdata_t, void *);
@@ -90,10 +90,18 @@ tco_match(device_t parent, cfdata_t matc
 {
 	struct lpcib_tco_attach_args *ta = aux;
 
-	if (ta->ta_iot != 0)
-		return 1;
+	if (ta->ta_iot == 0)
+		return 0;
 
-	return 0;
+	switch (ta->ta_version) {
+	case TCO_VERSION_RCBA:
+	case TCO_VERSION_PCIB:
+		break;
+	default:
+		return 0;
+	}
+
+	return 1;
 }
 
 static void
@@ -104,13 +112,12 @@ tco_attach(device_t parent, device_t sel
 	uint32_t ioreg;
 
 	/* Retrieve bus info shared with parent/siblings */
-
+	sc->sc_version = ta->ta_version;
 	sc->sc_iot = ta->ta_iot;
 	sc->sc_ioh = ta->ta_ioh;
 	sc->sc_rcbat = ta->ta_rcbat;
 	sc->sc_rcbah = ta->ta_rcbah;
 	sc->sc_pcib = ta->ta_pcib;
-	sc->sc_has_rcba = ta->ta_has_rcba;
 
 	aprint_normal(": TCO (watchdog) timer configured.\n");
 	aprint_naive("\n");
@@ -154,12 +161,15 @@ tco_attach(device_t parent, device_t sel
 	 * ICH5 or older are limited to 4ticks min and 39ticks max.
 	 *                              2secs          23secs
 	 */
-	if (sc->sc_has_rcba) {
+	switch (sc->sc_version) {
+	case TCO_VERSION_RCBA:
 		sc->sc_max_t = LPCIB_TCOTIMER2_MAX_TICK;
 		sc->sc_min_t = LPCIB_TCOTIMER2_MIN_TICK;
-	} else {
+		break;
+	case TCO_VERSION_PCIB:
 		sc->sc_max_t = LPCIB_TCOTIMER_MAX_TICK;
 		sc->sc_min_t = LPCIB_TCOTIMER_MIN_TICK;
+		break;
 	}
 	sc->sc_smw.smw_period = lpcib_tcotimer_tick_to_second(sc->sc_max_t);
 
@@ -230,20 +240,23 @@ tcotimer_setmode(struct sysmon_wdog *smw
 		tcotimer_stop(sc);
 
 		/* set the timeout, */
-		if (sc->sc_has_rcba) {
+		switch (sc->sc_version) {
+		case TCO_VERSION_RCBA:
 			/* ICH6 or newer */
 			ich6period = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
 			    LPCIB_TCO_TMR2);
 			ich6period &= 0xfc00;
 			bus_space_write_2(sc->sc_iot, sc->sc_ioh,
 			    LPCIB_TCO_TMR2, ich6period | period);
-		} else {
+			break;
+		case TCO_VERSION_PCIB:
 			/* ICH5 or older */
 			ich5period = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
 			    LPCIB_TCO_TMR);
 			ich5period &= 0xc0;
 			bus_space_write_1(sc->sc_iot, sc->sc_ioh,
 			    LPCIB_TCO_TMR, ich5period | period);
+			break;
 		}
 
 		/* and start/reload the timer. */
@@ -260,10 +273,14 @@ tcotimer_tickle(struct sysmon_wdog *smw)
 	struct tco_softc *sc = smw->smw_cookie;
 
 	/* any value is allowed */
-	if (sc->sc_has_rcba)
+	switch (sc->sc_version) {
+	case TCO_VERSION_RCBA:
 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO_RLD, 1);
-	else
+		break;
+	case TCO_VERSION_PCIB:
 		bus_space_write_1(sc->sc_iot, sc->sc_ioh, LPCIB_TCO_RLD, 1);
+		break;
+	}
 
 	return 0;
 }
@@ -308,7 +325,8 @@ tcotimer_disable_noreboot(device_t self)
 {
 	struct tco_softc *sc = device_private(self);
 
-	if (sc->sc_has_rcba) {
+	switch (sc->sc_version) {
+	case TCO_VERSION_RCBA: {
 		uint32_t status;
 
 		status = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
@@ -320,7 +338,9 @@ tcotimer_disable_noreboot(device_t self)
 		    LPCIB_GCS_OFFSET);
 		if (status & LPCIB_GCS_NO_REBOOT)
 			goto error;
-	} else {
+		break;
+	}
+	case TCO_VERSION_PCIB: {
 		pcireg_t pcireg;
 
 		pcireg = pci_conf_read(sc->sc_pcib->sc_pc, sc->sc_pcib->sc_tag,
@@ -333,6 +353,8 @@ tcotimer_disable_noreboot(device_t self)
 			if (pcireg & LPCIB_PCI_GEN_STA_NO_REBOOT)
 				goto error;
 		}
+		break;
+	}
 	}
 
 	return 0;

Index: src/sys/arch/x86/pci/tco.h
diff -u src/sys/arch/x86/pci/tco.h:1.1 src/sys/arch/x86/pci/tco.h:1.2
--- src/sys/arch/x86/pci/tco.h:1.1	Sun May  3 02:50:59 2015
+++ src/sys/arch/x86/pci/tco.h	Thu Sep 22 14:41:26 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tco.h,v 1.1 2015/05/03 02:50:59 pgoyette Exp $	*/
+/*	$NetBSD: tco.h,v 1.2 2022/09/22 14:41:26 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -36,8 +36,11 @@
 #ifndef _X86_PCI_TCO_H_
 #define _X86_PCI_TCO_H_
 
-struct lpcib_tco_attach_args {  
-	int			ta_has_rcba;
+struct lpcib_tco_attach_args {
+	enum {
+		TCO_VERSION_PCIB = 0,
+		TCO_VERSION_RCBA = 1,
+	}			ta_version;
 	bus_space_tag_t		ta_iot;
 	bus_space_handle_t	ta_ioh;
 	bus_space_tag_t		ta_rcbat;

Reply via email to