From nobody Fri Jan 24 21:43:03 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Yfrs35ZKWz5lSN0; Fri, 24 Jan 2025 21:43:03 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Yfrs32S5Nz3lQy; Fri, 24 Jan 2025 21:43:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737754983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=epzHe+UpRnfMHZDtwg6V6BuXMqcUJaUk5dAJ2n/GnYI=; b=F/litTajukGXxt1Pl3zXdIYGBED31dA7mg6rRsE/wfBDZNhZ1RJ1LaYEHa+k3G8Q+ipqXb kN9SBOb/98dmHCyOT2Qi/XblRDXc7Blv4qhpwbu8TlzpUlyeyXxToMcMzfLRZ9dYA/Np9T FpuiyDn6mIhk2lvMfPctEJa/kbkfhphfRGhaeHlbMh5PsRKms+J4bCjuIxhcd9jNIYyxfK ijWCdTh0HveEXHWNhh6HlBJi0O3I0/oCjQr1PPFLjw9+c431rZtVsaRFEh6mIeG/PZw97x GpGIgS0ysapRJYJBdTC4pk6Z/PoX3gSC56+25+O30nUAEgkr8MebWtk8T5DQbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737754983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=epzHe+UpRnfMHZDtwg6V6BuXMqcUJaUk5dAJ2n/GnYI=; b=DBdam54MKd7rfJ1jm6cK/UfNe00+hntTf1o/Cctn20GS1zXMgUKYvoBAIVw4PXgKajXkV0 rLjfoIiXjme6vFos59lNdtmoJZ0E2zeMeWXU6Drtr5cDK+26WBA0UZTfrnkX4uDNNoKir/ 6v6G7tWYto3RObny6yZ1lRW+xYIJbfVytb9nlPeKQVkxhslRMnLH4ezuGrKegqY1Pcmsl5 zgsDRRy1+AredyuH2Vn+RVVbbtY+PGGzypr2ZbpdJXMZFRiaAhJvD3els2kkpRw09V+JNI h0YqoZScmzTEPJiihny0GFPugbdjQc+B1dbXKhn3zuvE1ouugacRyMEY46iDYA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737754983; a=rsa-sha256; cv=none; b=YJt3ZYYSj8iktkxGROkYtf8RXuGJFLrf+OXgpMNSiJCZxUs1o7ttibCt/qBAopYNxPbVn7 KcLcX0GDb6FwbBwl7+n59cXWFHvDRiaGgXtyUEIL/jyyDQwF0lYbELktpMxcmviukfeWAo LbrTB697KxC6ubjlW3X8LuX9GCvhsHXKlOeMke2HjewpL4QoHCH1bYGmDbEq49//4WtATP jGfwHeacfHtEpmxGDYNhmISzWLUqe1qQ6pN93KRAoywOl2IDGuWJEqCswmSh6H8fecTkB1 9QU6hY8XNPXPRalwudNXijbX2jROxH5laemSNvpG/QHY/jQgsGo2SRh1pj9SGg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Yfrs321Q7zjw0; Fri, 24 Jan 2025 21:43:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50OLh3Hq012743; Fri, 24 Jan 2025 21:43:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50OLh3Kv012740; Fri, 24 Jan 2025 21:43:03 GMT (envelope-from git) Date: Fri, 24 Jan 2025 21:43:03 GMT Message-Id: <202501242143.50OLh3Kv012740@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: b2a49e88d1c6 - main - intpm: use MMIO for AMD EFCH CPUs List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b2a49e88d1c65ee41279b593fe0d50ce4ec31f75 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=b2a49e88d1c65ee41279b593fe0d50ce4ec31f75 commit b2a49e88d1c65ee41279b593fe0d50ce4ec31f75 Author: Brian Poole AuthorDate: 2024-10-07 13:09:35 +0000 Commit: Warner Losh CommitDate: 2025-01-24 21:42:40 +0000 intpm: use MMIO for AMD EFCH CPUs Recent AMD CPUs (SMBus PCI revision ID >= 0x51) can disable port-mapped IO and only support memory-mapped IO. In practice this was observed on a Zen 3 CPU where PMIO reads all returned 0xff. Update the driver to use MMIO for these processors while continuing to use PMIO by default. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1437 --- sys/dev/amdsbwd/amd_chipset.h | 2 ++ sys/dev/intpm/intpm.c | 44 ++++++++++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/sys/dev/amdsbwd/amd_chipset.h b/sys/dev/amdsbwd/amd_chipset.h index 1bc637a30845..44db7b3168d0 100644 --- a/sys/dev/amdsbwd/amd_chipset.h +++ b/sys/dev/amdsbwd/amd_chipset.h @@ -123,6 +123,7 @@ */ #define AMDFCH41_WDT_FIXED_ADDR 0xfeb00000u #define AMDFCH41_MMIO_ADDR 0xfed80000u +#define AMDFCH41_MMIO_PM_OFF 0x0300 #define AMDFCH41_MMIO_SMBUS_OFF 0x0a00 #define AMDFCH41_MMIO_WDT_OFF 0x0b00 @@ -143,5 +144,6 @@ #define AMDFCH41_SMBUS_REVID 0x41 #define AMDCZ_SMBUS_DEVID 0x790b1022 #define AMDCZ49_SMBUS_REVID 0x49 +#define AMDCZ51_SMBUS_REVID 0x51 #define HYGONCZ_SMBUS_DEVID 0x790b1d94 diff --git a/sys/dev/intpm/intpm.c b/sys/dev/intpm/intpm.c index 3aa76ff48263..2f12e0dcf49b 100644 --- a/sys/dev/intpm/intpm.c +++ b/sys/dev/intpm/intpm.c @@ -55,6 +55,7 @@ struct intsmb_softc { int cfg_irq9; int sb8xx; int poll; + int type; struct mtx lock; }; @@ -135,28 +136,44 @@ sb8xx_attach(device_t dev) struct resource *res; uint32_t devid; uint8_t revid; - uint16_t addr; + uint32_t addr; int rid; int rc; bool enabled; sc = device_get_softc(dev); + devid = pci_get_devid(dev); + revid = pci_get_revid(dev); + + /* + * Comment from Linux i2c-piix4.c: + * + * cd6h/cd7h port I/O accesses can be disabled on AMD processors + * w/ SMBus PCI revision ID 0x51 or greater. MMIO is supported on + * the same processors and is the recommended access method. + */ + if (devid == AMDCZ_SMBUS_DEVID && revid >= AMDCZ51_SMBUS_REVID) { + sc->type = SYS_RES_MEMORY; + addr = AMDFCH41_MMIO_ADDR + AMDFCH41_MMIO_PM_OFF; + } else { + sc->type = SYS_RES_IOPORT; + addr = AMDSB_PMIO_INDEX; + } + rid = 0; - rc = bus_set_resource(dev, SYS_RES_IOPORT, rid, AMDSB_PMIO_INDEX, + rc = bus_set_resource(dev, sc->type, rid, addr, 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, + res = bus_alloc_resource_any(dev, sc->type, &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)) { @@ -165,6 +182,10 @@ sb8xx_attach(device_t dev) addr |= amd_pmio_read(res, AMDSB8_PM_SMBUS_EN); enabled = (addr & AMDSB8_SMBUS_EN) != 0; addr &= AMDSB8_SMBUS_ADDR_MASK; + } else if (devid == AMDCZ_SMBUS_DEVID && revid >= AMDCZ51_SMBUS_REVID) { + addr = bus_read_1(res, AMDFCH41_PM_DECODE_EN0); + enabled = (addr & AMDFCH41_SMBUS_EN) != 0; + addr = AMDFCH41_MMIO_ADDR + AMDFCH41_MMIO_SMBUS_OFF; } else { addr = amd_pmio_read(res, AMDFCH41_PM_DECODE_EN0); enabled = (addr & AMDFCH41_SMBUS_EN) != 0; @@ -172,8 +193,8 @@ sb8xx_attach(device_t dev) addr <<= 8; } - bus_release_resource(dev, SYS_RES_IOPORT, rid, res); - bus_delete_resource(dev, SYS_RES_IOPORT, rid); + bus_release_resource(dev, sc->type, rid, res); + bus_delete_resource(dev, sc->type, rid); if (!enabled) { device_printf(dev, "SB8xx/SB9xx/FCH SMBus not enabled\n"); @@ -181,13 +202,13 @@ sb8xx_attach(device_t dev) } sc->io_rid = 0; - rc = bus_set_resource(dev, SYS_RES_IOPORT, sc->io_rid, addr, + rc = bus_set_resource(dev, sc->type, sc->io_rid, addr, AMDSB_SMBIO_WIDTH); if (rc != 0) { device_printf(dev, "bus_set_resource for SMBus IO failed\n"); return (ENXIO); } - sc->io_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &sc->io_rid, + sc->io_res = bus_alloc_resource_any(dev, sc->type, &sc->io_rid, RF_ACTIVE); if (sc->io_res == NULL) { device_printf(dev, "Could not allocate I/O space\n"); @@ -208,7 +229,7 @@ intsmb_release_resources(device_t dev) 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, + bus_release_resource(dev, sc->type, sc->io_rid, sc->io_res); mtx_destroy(&sc->lock); } @@ -226,6 +247,7 @@ intsmb_attach(device_t dev) mtx_init(&sc->lock, device_get_nameunit(dev), "intsmb", MTX_DEF); sc->cfg_irq9 = 0; + sc->type = SYS_RES_IOPORT; switch (pci_get_devid(dev)) { #ifndef NO_CHANGE_PCICONF case 0x71138086: /* Intel 82371AB */ @@ -254,7 +276,7 @@ intsmb_attach(device_t dev) } sc->io_rid = PCI_BASE_ADDR_SMB; - sc->io_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &sc->io_rid, + sc->io_res = bus_alloc_resource_any(dev, sc->type, &sc->io_rid, RF_ACTIVE); if (sc->io_res == NULL) { device_printf(dev, "Could not allocate I/O space\n");