aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndriy Gapon <avg@FreeBSD.org>2018-12-14 09:28:20 +0000
committerAndriy Gapon <avg@FreeBSD.org>2018-12-14 09:28:20 +0000
commit8b65c16f6e14df7bcf8c188d6de33b892a3ffea8 (patch)
treeb029bddbdb770bcc3c6478bec70d9d196cfde0fa
parentbc044625ede1a4b6362c0ecb0933b4a3136825f1 (diff)
downloadsrc-8b65c16f6e14df7bcf8c188d6de33b892a3ffea8.tar.gz
src-8b65c16f6e14df7bcf8c188d6de33b892a3ffea8.zip
ichwd: add support for clearing No Reboot bit in TCOv4
This is based on a patch developed by Tetsuya Uemura <t_uemura@macome.co.jp>. Many thanks! Submitted by: Tetsuya Uemura <t_uemura@macome.co.jp> (earlier version) Tested by: Tetsuya Uemura <t_uemura@macome.co.jp> MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=342072
-rw-r--r--sys/dev/ichwd/ichwd.c65
-rw-r--r--sys/dev/ichwd/ichwd.h15
2 files changed, 76 insertions, 4 deletions
diff --git a/sys/dev/ichwd/ichwd.c b/sys/dev/ichwd/ichwd.c
index 79bc50a48206..c33572e0873d 100644
--- a/sys/dev/ichwd/ichwd.c
+++ b/sys/dev/ichwd/ichwd.c
@@ -76,6 +76,10 @@ __FBSDID("$FreeBSD$");
#include <dev/ichwd/ichwd.h>
+#include <x86/pci_cfgreg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pci_private.h>
+
static struct ichwd_device ichwd_devices[] = {
{ DEVICEID_82801AA, "Intel 82801AA watchdog timer", 1, 1 },
{ DEVICEID_82801AB, "Intel 82801AB watchdog timer", 1, 1 },
@@ -309,6 +313,8 @@ static devclass_t ichwd_devclass;
/* NB: TCO version 3 devices use the gcs_res resource for the PMC register. */
#define ichwd_read_pmc_4(sc, off) \
bus_read_4((sc)->gcs_res, (off))
+#define ichwd_read_gc_4(sc, off) \
+ bus_read_4((sc)->gc_res, (off))
#define ichwd_write_tco_1(sc, off, val) \
bus_write_1((sc)->tco_res, (off), (val))
@@ -323,6 +329,8 @@ static devclass_t ichwd_devclass;
/* NB: TCO version 3 devices use the gcs_res resource for the PMC register. */
#define ichwd_write_pmc_4(sc, off, val) \
bus_write_4((sc)->gcs_res, (off), (val))
+#define ichwd_write_gc_4(sc, off, val) \
+ bus_write_4((sc)->gc_res, (off), (val))
#define ichwd_verbose_printf(dev, ...) \
do { \
@@ -495,9 +503,12 @@ ichwd_clear_noreboot(struct ichwd_softc *sc)
rc = EIO;
break;
case 4:
- /*
- * TODO. This needs access to a hidden PCI device at 31:1.
- */
+ status = ichwd_read_gc_4(sc, 0);
+ status &= ~SMB_GC_NO_REBOOT;
+ ichwd_write_gc_4(sc, 0, status);
+ status = ichwd_read_gc_4(sc, 0);
+ if (status & SMB_GC_NO_REBOOT)
+ rc = EIO;
break;
default:
ichwd_verbose_printf(sc->device,
@@ -611,6 +622,7 @@ ichwd_identify(driver_t *driver, device_t parent)
struct ichwd_device *id_p;
device_t ich, smb;
device_t dev;
+ uint64_t base_address64;
uint32_t base_address;
uint32_t ctl;
int rc;
@@ -671,6 +683,33 @@ ichwd_identify(driver_t *driver, device_t parent)
"Can not set TCO v%d I/O resource (err = %d)\n",
id_p->tco_version, rc);
}
+
+ /*
+ * Unhide Primary to Sideband Bridge (P2SB) PCI device, so that
+ * we can discover the base address of Private Configuration
+ * Space via the bridge's BAR.
+ * Then hide back the bridge.
+ */
+ pci_cfgregwrite(0, 31, 1, 0xe1, 0, 1);
+ base_address64 = pci_cfgregread(0, 31, 1, SBREG_BAR + 4, 4);
+ base_address64 <<= 32;
+ base_address64 |= pci_cfgregread(0, 31, 1, SBREG_BAR, 4);
+ base_address64 &= ~0xfull;
+ pci_cfgregwrite(0, 31, 1, 0xe1, 1, 1);
+
+ /*
+ * No Reboot bit is in General Control register, offset 0xc,
+ * within the SMBus target port, ID 0xc6.
+ */
+ base_address64 += PCR_REG_OFF(SMB_PORT_ID, SMB_GC_REG);
+ rc = bus_set_resource(dev, SYS_RES_MEMORY, 1, base_address64,
+ SMB_GC_SIZE);
+ if (rc != 0) {
+ ichwd_verbose_printf(dev,
+ "Can not set TCO v%d PCR I/O resource (err = %d)\n",
+ id_p->tco_version, rc);
+ }
+
break;
default:
ichwd_verbose_printf(dev,
@@ -723,6 +762,18 @@ ichwd_smb_attach(device_t dev)
return (ENXIO);
}
+ /*
+ * Allocate General Control I/O register in PCH
+ * Private Configuration Space (PCR).
+ */
+ sc->gc_rid = 1;
+ sc->gc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->gc_rid,
+ RF_ACTIVE | RF_SHAREABLE);
+ if (sc->gc_res == NULL) {
+ device_printf(dev, "unable to reserve hidden P2SB registers\n");
+ return (ENXIO);
+ }
+
/* Get ACPI base address. */
isab = device_get_parent(device_get_parent(dev));
pmdev = pci_find_dbsf(pci_get_domain(isab), pci_get_bus(isab), 31, 2);
@@ -737,7 +788,7 @@ ichwd_smb_attach(device_t dev)
}
/* Allocate SMI control I/O register space. */
- sc->smi_rid = 1;
+ sc->smi_rid = 2;
sc->smi_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->smi_rid,
acpi_base + SMI_BASE, acpi_base + SMI_BASE + SMI_LEN - 1, SMI_LEN,
RF_ACTIVE | RF_SHAREABLE);
@@ -854,6 +905,9 @@ ichwd_attach(device_t dev)
if (sc->gcs_res != NULL)
bus_release_resource(sc->ich, SYS_RES_MEMORY,
sc->gcs_rid, sc->gcs_res);
+ if (sc->gc_res != NULL)
+ bus_release_resource(dev, SYS_RES_MEMORY,
+ sc->gc_rid, sc->gc_res);
return (ENXIO);
}
@@ -889,6 +943,9 @@ ichwd_detach(device_t dev)
if (sc->gcs_res)
bus_release_resource(sc->ich, SYS_RES_MEMORY, sc->gcs_rid,
sc->gcs_res);
+ if (sc->gc_res)
+ bus_release_resource(dev, SYS_RES_MEMORY, sc->gc_rid,
+ sc->gc_res);
return (0);
}
diff --git a/sys/dev/ichwd/ichwd.h b/sys/dev/ichwd/ichwd.h
index 32682c4a6c32..b79da247494e 100644
--- a/sys/dev/ichwd/ichwd.h
+++ b/sys/dev/ichwd/ichwd.h
@@ -59,6 +59,9 @@ struct ichwd_softc {
int gcs_rid;
struct resource *gcs_res;
+ int gc_rid;
+ struct resource *gc_res;
+
eventhandler_tag ev_tag;
};
@@ -300,6 +303,18 @@ struct ichwd_softc {
#define ICH_TCOCTL_TCO_BASE_EN 0x0100 /* TCO Base decoding enabled */
#define ICH_TCOCTL_TCO_BASE_LOCK 0x0001 /* TCOBASE is locked */
+/*
+ * Configuration registers in Sunrise Point and Lewisburg PCH Sideband Interface
+ * and Private Configuration Space.
+ */
+#define SBREG_BAR 0x10
+#define SMB_GC_REG 0xc
+#define SMB_GC_SIZE 4
+#define SMB_GC_NO_REBOOT 0x2
+#define SMB_PORT_ID 0xc6
+#define PCR_PORTID_SHIFT 16
+#define PCR_REG_OFF(pid, reg) (((pid) << PCR_PORTID_SHIFT) | (reg))
+
/* register names and locations (relative to PMBASE) */
#define SMI_BASE 0x30 /* base address for SMI registers */
#define SMI_LEN 0x08