From owner-svn-src-all@freebsd.org Fri Dec 14 09:28:21 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 520451327C00; Fri, 14 Dec 2018 09:28:21 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E867D950A1; Fri, 14 Dec 2018 09:28:20 +0000 (UTC) (envelope-from avg@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DC4942D4B8; Fri, 14 Dec 2018 09:28:20 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wBE9SKkm030417; Fri, 14 Dec 2018 09:28:20 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wBE9SKeQ030414; Fri, 14 Dec 2018 09:28:20 GMT (envelope-from avg@FreeBSD.org) Message-Id: <201812140928.wBE9SKeQ030414@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Fri, 14 Dec 2018 09:28:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r342072 - head/sys/dev/ichwd X-SVN-Group: head X-SVN-Commit-Author: avg X-SVN-Commit-Paths: head/sys/dev/ichwd X-SVN-Commit-Revision: 342072 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: E867D950A1 X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-1.55 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.85)[-0.853,0]; NEURAL_HAM_SHORT(-0.70)[-0.700,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Dec 2018 09:28:21 -0000 Author: avg Date: Fri Dec 14 09:28:20 2018 New Revision: 342072 URL: https://svnweb.freebsd.org/changeset/base/342072 Log: ichwd: add support for clearing No Reboot bit in TCOv4 This is based on a patch developed by Tetsuya Uemura . Many thanks! Submitted by: Tetsuya Uemura (earlier version) Tested by: Tetsuya Uemura MFC after: 2 weeks Modified: head/sys/dev/ichwd/ichwd.c head/sys/dev/ichwd/ichwd.h Modified: head/sys/dev/ichwd/ichwd.c ============================================================================== --- head/sys/dev/ichwd/ichwd.c Fri Dec 14 09:24:14 2018 (r342071) +++ head/sys/dev/ichwd/ichwd.c Fri Dec 14 09:28:20 2018 (r342072) @@ -76,6 +76,10 @@ __FBSDID("$FreeBSD$"); #include +#include +#include +#include + 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); } Modified: head/sys/dev/ichwd/ichwd.h ============================================================================== --- head/sys/dev/ichwd/ichwd.h Fri Dec 14 09:24:14 2018 (r342071) +++ head/sys/dev/ichwd/ichwd.h Fri Dec 14 09:28:20 2018 (r342072) @@ -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; }; @@ -299,6 +302,18 @@ struct ichwd_softc { #define ICH_TCOCTL 0x54 /* TCO Control */ #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 */