Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-8]: src Pull up following revision(s) (requested by msaitoh in ti...



details:   https://anonhg.NetBSD.org/src/rev/cc6def8f536d
branches:  netbsd-8
changeset: 371828:cc6def8f536d
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Oct 11 18:22:44 2022 +0000

description:
Pull up following revision(s) (requested by msaitoh in ticket #1773):

        share/man/man4/man4.x86/amdsmn.4                1.4,1.5
        share/man/man4/man4.x86/amdzentemp.4            1.7
        sys/arch/x86/pci/amdsmn.c                       1.7-1.9,1.13,1.14
        sys/arch/x86/pci/amdzentemp.c                   1.8-1.10,1.12-1.15

adjust for possible 49K offset

presence of this offset is indicated by a set 19th bit which is shifted away
this brings the temperature to "normal" levels on my ryzen 2700
(I assumed the same 49K offset as the k10temp project)

correct for known temperature bias values.

Update to support Family 15h Model 60 temperature sensors.

Changes based on FreeBSD amdtemp driver changes by Conrad Meyer.

XXX: Some code duplication between this driver and amdtemp as
     parts of the 15h refresh code share more in common with
     older CPUs while accessing the device more like 17h.

Don't mix sign and unsigned operands. Just use size_t for the loop.

Apply previous change ("Don't mix sign and unsigned operands. Just use
size_t for the loop.") to another loop variable.

amdzentemp(4): Add Zen 3 support.

amdzentemp(4): Add support for per CCD temperature sensor from FreeBSD.

Fix build failure on i386.

Rename for AMD F15/6X device. No functional change.
amdsmn(4),amdzentemp(4): Add support for 17h/6xh and 19h/6xh.

Note that these drivers are present on some newer AMD Family 15h
processors.

amdsmn.4: Now support AMD Family 19h processors.

diffstat:

 share/man/man4/man4.x86/amdsmn.4     |    7 +-
 share/man/man4/man4.x86/amdzentemp.4 |    6 +-
 sys/arch/x86/pci/amdsmn.c            |   73 ++++++-
 sys/arch/x86/pci/amdzentemp.c        |  301 +++++++++++++++++++++++++++++++---
 4 files changed, 334 insertions(+), 53 deletions(-)

diffs (truncated from 607 to 300 lines):

diff -r 5eafeb1d489c -r cc6def8f536d share/man/man4/man4.x86/amdsmn.4
--- a/share/man/man4/man4.x86/amdsmn.4  Tue Oct 11 18:07:11 2022 +0000
+++ b/share/man/man4/man4.x86/amdsmn.4  Tue Oct 11 18:22:44 2022 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: amdsmn.4,v 1.3.2.2 2018/02/05 13:06:55 martin Exp $
+.\"    $NetBSD: amdsmn.4,v 1.3.2.3 2022/10/11 18:22:44 martin Exp $
 .\"
 .\" Copyright (c) 2018 Ian Clark <mrrooster%gmail.com@localhost>
 .\" All rights reserved.
@@ -54,7 +54,7 @@
 .\"
 .\" $FreeBSD: head/share/man/man4/amdsmn.4 323184 2017-09-05 15:13:41Z cem $
 .\"
-.Dd January 22, 2018
+.Dd October 2, 2022
 .Dt AMDSMN 4 x86
 .Os
 .Sh NAME
@@ -66,7 +66,8 @@
 The
 .Nm
 driver provides support for resources on the System Management Network bus
-in AMD Family 17h processors.
+in AMD Family 19h processors, 17h processors and some later
+AMD Family 15h processors.
 .Sh SEE ALSO
 .Xr amdzentemp 4
 .Sh HISTORY
diff -r 5eafeb1d489c -r cc6def8f536d share/man/man4/man4.x86/amdzentemp.4
--- a/share/man/man4/man4.x86/amdzentemp.4      Tue Oct 11 18:07:11 2022 +0000
+++ b/share/man/man4/man4.x86/amdzentemp.4      Tue Oct 11 18:22:44 2022 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: amdzentemp.4,v 1.6.2.2 2018/02/05 13:06:55 martin Exp $
+.\" $NetBSD: amdzentemp.4,v 1.6.2.3 2022/10/11 18:22:44 martin Exp $
 .\"-
 .\" Copyright (c) 2008 Christoph Egger
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD: src/share/man/man4/coretemp.4,v 1.4 2007/10/15 20:00:19 netchild Exp $
 .\"
-.Dd January 28, 2018
+.Dd April 20, 2020
 .Dt AMDZENTEMP 4 x86
 .Os
 .Sh NAME
@@ -38,7 +38,7 @@
 The
 .Nm
 driver provides support for the on-die digital thermal sensor present
-on AMD Ryzen CPUs
+on AMD Ryzen CPUs and some later AMD Opteron CPUs.
 .Pp
 These sensors provide 0.125\(deC accuracy.
 There is one sensor for each CPU socket.
diff -r 5eafeb1d489c -r cc6def8f536d sys/arch/x86/pci/amdsmn.c
--- a/sys/arch/x86/pci/amdsmn.c Tue Oct 11 18:07:11 2022 +0000
+++ b/sys/arch/x86/pci/amdsmn.c Tue Oct 11 18:22:44 2022 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: amdsmn.c,v 1.3.2.4 2019/08/06 16:05:11 martin Exp $    */
+/*     $NetBSD: amdsmn.c,v 1.3.2.5 2022/10/11 18:22:44 martin Exp $    */
 
 /*-
- * Copyright (c) 2017 Conrad Meyer <cem%FreeBSD.org@localhost>
+ * Copyright (c) 2017, 2019 Conrad Meyer <cem%FreeBSD.org@localhost>
  * All rights reserved.
  *
  * NetBSD port by Ian Clark <mrrooster%gmail.com@localhost>
@@ -29,10 +29,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amdsmn.c,v 1.3.2.4 2019/08/06 16:05:11 martin Exp $ ");
+__KERNEL_RCSID(0, "$NetBSD: amdsmn.c,v 1.3.2.5 2022/10/11 18:22:44 martin Exp $ ");
 
 /*
- * Driver for the AMD Family 17h CPU System Management Network.
+ * Driver for the AMD Family 15h (model 60+) and 17h CPU
+ * System Management Network.
  */
 
 #include <sys/param.h>
@@ -52,11 +53,15 @@
 #include "amdsmn.h"
 #include "ioconf.h"
 
-#define        SMN_ADDR_REG    0x60
-#define        SMN_DATA_REG    0x64
+#define        F15H_SMN_ADDR_REG       0xb8
+#define        F15H_SMN_DATA_REG       0xbc
+#define        F17H_SMN_ADDR_REG       0x60
+#define        F17H_SMN_DATA_REG       0x64
 
 struct amdsmn_softc {
        kmutex_t smn_lock;
+       uint8_t smn_addr_reg;
+       uint8_t smn_data_reg;
        struct pci_attach_args pa;
        pci_chipset_tag_t pc;
        pcitag_t pcitag;
@@ -64,10 +69,39 @@
 
 static const struct pciid {
        uint16_t        amdsmn_deviceid;
+       uint8_t         amdsmn_addr_reg;
+       uint8_t         amdsmn_data_reg;
 } amdsmn_ids[] = {
-       { PCI_PRODUCT_AMD_F17_RC },
-       { PCI_PRODUCT_AMD_F17_1X_RC },
-       { PCI_PRODUCT_AMD_F17_7X_RC },
+       {
+               .amdsmn_deviceid = PCI_PRODUCT_AMD_F15_6X_RC,
+               .amdsmn_addr_reg = F15H_SMN_ADDR_REG,
+               .amdsmn_data_reg = F15H_SMN_DATA_REG,
+       },
+       {
+               .amdsmn_deviceid = PCI_PRODUCT_AMD_F17_RC,
+               .amdsmn_addr_reg = F17H_SMN_ADDR_REG,
+               .amdsmn_data_reg = F17H_SMN_DATA_REG,
+       },
+       {
+               .amdsmn_deviceid = PCI_PRODUCT_AMD_F17_1X_RC,
+               .amdsmn_addr_reg = F17H_SMN_ADDR_REG,
+               .amdsmn_data_reg = F17H_SMN_DATA_REG,
+       },
+       {
+               .amdsmn_deviceid = PCI_PRODUCT_AMD_F17_6X_RC,
+               .amdsmn_addr_reg = F17H_SMN_ADDR_REG,
+               .amdsmn_data_reg = F17H_SMN_DATA_REG,
+       },
+       {
+               .amdsmn_deviceid = PCI_PRODUCT_AMD_F17_7X_RC,
+               .amdsmn_addr_reg = F17H_SMN_ADDR_REG,
+               .amdsmn_data_reg = F17H_SMN_DATA_REG,
+       },
+       {
+               .amdsmn_deviceid = PCI_PRODUCT_AMD_F19_6X_RC,
+               .amdsmn_addr_reg = F17H_SMN_ADDR_REG,
+               .amdsmn_data_reg = F17H_SMN_DATA_REG,
+       },
 };
 
 static int amdsmn_match(device_t, cfdata_t, void *);
@@ -83,7 +117,7 @@
 amdsmn_match(device_t parent, cfdata_t match, void *aux)
 {
        struct pci_attach_args *pa = aux;
-       unsigned int i;
+       size_t i;
 
        if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_AMD)
                return 0;
@@ -110,12 +144,21 @@
        struct amdsmn_softc *sc = device_private(self);
        struct pci_attach_args *pa = aux;
        int flags = 0;
+       size_t i;
 
        mutex_init(&sc->smn_lock, MUTEX_DEFAULT, IPL_NONE);
        sc->pa = *pa;
        sc->pc = pa->pa_pc;
        sc->pcitag = pa->pa_tag;
-       aprint_normal(": AMD Family 17h System Management Network\n");
+
+       for (i = 0; i < __arraycount(amdsmn_ids); i++)
+               if (PCI_PRODUCT(pa->pa_id) == amdsmn_ids[i].amdsmn_deviceid) {
+                       sc->smn_addr_reg = amdsmn_ids[i].amdsmn_addr_reg;
+                       sc->smn_data_reg = amdsmn_ids[i].amdsmn_data_reg;
+               }
+
+       // aprint_normal(": AMD Family 17h System Management Network\n");
+       aprint_normal(": AMD System Management Network\n");
        amdsmn_rescan(self, "amdsmnbus", &flags);
 }
 
@@ -146,8 +189,8 @@
        struct amdsmn_softc *sc = device_private(dev);
 
        mutex_enter(&sc->smn_lock);
-       pci_conf_write(sc->pc, sc->pcitag, SMN_ADDR_REG, addr);
-       *value = pci_conf_read(sc->pc, sc->pcitag, SMN_DATA_REG);
+       pci_conf_write(sc->pc, sc->pcitag, sc->smn_addr_reg, addr);
+       *value = pci_conf_read(sc->pc, sc->pcitag, sc->smn_data_reg);
        mutex_exit(&sc->smn_lock);
 
        return 0;
@@ -159,8 +202,8 @@
        struct amdsmn_softc *sc = device_private(dev);
 
        mutex_enter(&sc->smn_lock);
-       pci_conf_write(sc->pc, sc->pcitag, SMN_ADDR_REG, addr);
-       pci_conf_write(sc->pc, sc->pcitag, SMN_DATA_REG, value);
+       pci_conf_write(sc->pc, sc->pcitag, sc->smn_addr_reg, addr);
+       pci_conf_write(sc->pc, sc->pcitag, sc->smn_data_reg, value);
        mutex_exit(&sc->smn_lock);
 
        return 0;
diff -r 5eafeb1d489c -r cc6def8f536d sys/arch/x86/pci/amdzentemp.c
--- a/sys/arch/x86/pci/amdzentemp.c     Tue Oct 11 18:07:11 2022 +0000
+++ b/sys/arch/x86/pci/amdzentemp.c     Tue Oct 11 18:22:44 2022 +0000
@@ -1,8 +1,11 @@
-/*      $NetBSD: amdzentemp.c,v 1.7.2.2 2018/02/05 13:06:55 martin Exp $ */
+/*      $NetBSD: amdzentemp.c,v 1.7.2.3 2022/10/11 18:22:44 martin Exp $ */
 /*      $OpenBSD: kate.c,v 1.2 2008/03/27 04:52:03 cnst Exp $   */
 
 /*
- * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Copyright (c) 2019 Conrad Meyer <cem%FreeBSD.org@localhost>
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -50,7 +53,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amdzentemp.c,v 1.7.2.2 2018/02/05 13:06:55 martin Exp $ ");
+__KERNEL_RCSID(0, "$NetBSD: amdzentemp.c,v 1.7.2.3 2022/10/11 18:22:44 martin Exp $ ");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -70,17 +73,64 @@
 
 #include "amdsmn.h"
 
-/* Address to query for temp on family 17h */
-#define AMD_17H_CUR_TMP    0x59800
+#define        AMD_CURTMP_RANGE_ADJUST 49000000        /* in microKelvins (ie, 49C) */
+#define        AMD_CURTMP_RANGE_CHECK  __BIT(19)
+#define        F10_TEMP_CURTMP         __BITS(31,21)   /* XXX same as amdtemp.c */
+#define        F10_TEMP_CURTMP_MASK    0x7ff
+#define        F15M60_CURTMP_TJSEL     __BITS(17,16)
+
+/*
+ * Reported Temperature, Family 15h, M60+
+ *
+ * Same register bit definitions as other Family 15h CPUs, but access is
+ * indirect via SMN, like Family 17h.
+ */
+#define        AMD_15H_M60H_REPTMP_CTRL        0xd8200ca4
+
+/*
+ * Reported Temperature, Family 17h
+ *
+ * According to AMD OSRR for 17H, section 4.2.1, bits 31-21 of this register
+ * provide the current temp.  bit 19, when clear, means the temp is reported in
+ * a range 0.."225C" (probable typo for 255C), and when set changes the range
+ * to -49..206C.
+ */
+#define        AMD_17H_CUR_TMP                 0x59800
+
+/*
+ * The following register set was discovered experimentally by Ondrej Čerman
+ * and collaborators, but is not (yet) documented in a PPR/OSRR (other than
+ * the M70H PPR SMN memory map showing [0x59800, +0x314] as allocated to
+ * SMU::THM).  It seems plausible and the Linux sensor folks have adopted it.
+ */
+#define        AMD_17H_CCD_TMP_BASE            0x59954
+#define        AMD_17H_CCD_TMP_VALID           __BIT(11)
 
 struct amdzentemp_softc {
-        pci_chipset_tag_t sc_pc;
-        pcitag_t sc_pcitag;
+       device_t sc_dev;
        struct sysmon_envsys *sc_sme;
        device_t sc_smn;
        envsys_data_t *sc_sensor;
        size_t sc_sensor_len;
-        size_t sc_numsensors;
+       size_t sc_numsensors;
+       int32_t sc_offset;
+       uint32_t sc_ccd_tmp_base;
+};
+
+enum {
+       NOSENSOR = 0,
+       CORE0_SENSOR0,
+       CCD_BASE,
+       CCD0 = CCD_BASE,
+       CCD1,
+       CCD2,
+       CCD3,
+       CCD4,
+       CCD5,
+       CCD6,
+       CCD7,
+       CCD_MAX,
+       NUM_CCDS = CCD_MAX - CCD_BASE
 };
 
 
@@ -88,9 +138,12 @@
 static void amdzentemp_attach(device_t, device_t, void *);
 static int  amdzentemp_detach(device_t, int);
 
-static void amdzentemp_family17_init(struct amdzentemp_softc *);
-static void amdzentemp_family17_setup_sensors(struct amdzentemp_softc *, int);
+static void amdzentemp_init(struct amdzentemp_softc *, int, int);


Home | Main Index | Thread Index | Old Index