Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F137058654
D12217.id32657.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
15 KB
Referenced Files
None
Subscribers
None
D12217.id32657.diff
View Options
Index: share/man/man4/Makefile
===================================================================
--- share/man/man4/Makefile
+++ share/man/man4/Makefile
@@ -46,6 +46,7 @@
amdpm.4 \
${_amdsbwd.4} \
${_amdsmb.4} \
+ ${_amdsmn.4} \
${_amdtemp.4} \
${_bxe.4} \
amr.4 \
@@ -768,6 +769,7 @@
_aibs.4= aibs.4
_amdsbwd.4= amdsbwd.4
_amdsmb.4= amdsmb.4
+_amdsmn.4= amdsmn.4
_amdtemp.4= amdtemp.4
_asmc.4= asmc.4
_bxe.4= bxe.4
Index: share/man/man4/amdsmn.4
===================================================================
--- /dev/null
+++ share/man/man4/amdsmn.4
@@ -0,0 +1,64 @@
+.\"-
+.\" Copyright (c) 2017 Conrad Meyer <cem@FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd September 1, 2017
+.Dt AMDSMN 4
+.Os
+.Sh NAME
+.Nm amdsmn
+.Nd device driver for
+.Tn AMD
+processor System Management Network
+.Sh SYNOPSIS
+To compile this driver into the kernel, place the following line in your
+kernel configuration file:
+.Bd -ragged -offset indent
+.Cd "device amdsmn"
+.Ed
+.Pp
+Alternatively, to load the driver as a module at boot time, place the
+following line in
+.Xr loader.conf 5 :
+.Bd -literal -offset indent
+amdsmn_load="YES"
+.Ed
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for resources on the System Management Network bus
+in
+.Tn AMD
+Family 17h processors.
+.Sh SEE ALSO
+.Xr loader 8
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Fx 12.0 .
+.Sh AUTHORS
+.An Conrad Meyer Aq Mt cem@FreeBSD.org
Index: share/man/man4/amdtemp.4
===================================================================
--- share/man/man4/amdtemp.4
+++ share/man/man4/amdtemp.4
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd March 27, 2015
+.Dd September 2, 2017
.Dt AMDTEMP 4
.Os
.Sh NAME
@@ -53,7 +53,7 @@
driver provides support for the on-die digital thermal sensor present
in
.Tn AMD
-Family 0Fh, 10h, 11h, 12h, 14h, 15h, and 16h processors.
+Family 0Fh, 10h, 11h, 12h, 14h, 15h, 16h, and 17h processors.
.Pp
For Family 0Fh processors, the
.Nm
@@ -64,8 +64,8 @@
in the corresponding CPU device's sysctl tree, displaying the maximum
temperature of the two sensors located in each CPU core.
.Pp
-For Family 10h, 11h, 12h, 14h, 15h, and 16h processors, the driver reports each
-package's temperature through a sysctl node, named
+For Family 10h, 11h, 12h, 14h, 15h, 16h, and 17h processors, the driver reports
+each package's temperature through a sysctl node, named
.Va dev.amdtemp.%d.core0.sensor0 .
The driver also creates
.Va dev.cpu.%d.temperature
Index: sys/amd64/conf/NOTES
===================================================================
--- sys/amd64/conf/NOTES
+++ sys/amd64/conf/NOTES
@@ -583,6 +583,11 @@
#
options ENABLE_ALART # Control alarm on Intel intpm driver
+#
+# AMD System Management Network (SMN)
+#
+device amdsmn
+
#
# Number of initial kernel page table pages used for early bootstrap.
# This number should include enough pages to map the kernel and any
Index: sys/boot/forth/loader.conf
===================================================================
--- sys/boot/forth/loader.conf
+++ sys/boot/forth/loader.conf
@@ -525,6 +525,7 @@
vkbd_load="NO" # Virtual AT keyboard interface
vpd_load="NO" # Vital Product Data kernel interface
vpo_load="NO" # Parallel to SCSI interface driver
+amdsmn_load="NO" # AMD Family 17h System Management Network
amdtemp_load="NO" # AMD K8/K10/K11 temperature monitor
tpm_load="NO" # Trusted Platform Module
wbwd_load="NO" # Winbond watchdog
Index: sys/conf/files.amd64
===================================================================
--- sys/conf/files.amd64
+++ sys/conf/files.amd64
@@ -198,6 +198,7 @@
dev/agp/agp_i810.c optional agp
dev/agp/agp_via.c optional agp
dev/amdsbwd/amdsbwd.c optional amdsbwd
+dev/amdsmn/amdsmn.c optional amdsmn | amdtemp
dev/amdtemp/amdtemp.c optional amdtemp
dev/arcmsr/arcmsr.c optional arcmsr pci
dev/asmc/asmc.c optional asmc isa
Index: sys/conf/files.i386
===================================================================
--- sys/conf/files.i386
+++ sys/conf/files.i386
@@ -152,6 +152,7 @@
dev/agp/agp_via.c optional agp
dev/aic/aic_isa.c optional aic isa
dev/amdsbwd/amdsbwd.c optional amdsbwd
+dev/amdsmn/amdsmn.c optional amdsmn | amdtemp
dev/amdtemp/amdtemp.c optional amdtemp
dev/arcmsr/arcmsr.c optional arcmsr pci
dev/asmc/asmc.c optional asmc isa
Index: sys/dev/amdsmn/amdsmn.h
===================================================================
--- /dev/null
+++ sys/dev/amdsmn/amdsmn.h
@@ -0,0 +1,32 @@
+/*-
+ * Copyright (c) 2017 Conrad Meyer <cem@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD $
+ */
+
+#pragma once
+
+int amdsmn_read(device_t dev, uint32_t addr, uint32_t *value);
+int amdsmn_write(device_t dev, uint32_t addr, uint32_t value);
Index: sys/dev/amdsmn/amdsmn.c
===================================================================
--- /dev/null
+++ sys/dev/amdsmn/amdsmn.c
@@ -0,0 +1,186 @@
+/*-
+ * Copyright (c) 2017 Conrad Meyer <cem@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Driver for the AMD Family 17h CPU System Management Network.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/lock.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+#include <sys/sysctl.h>
+#include <sys/systm.h>
+
+#include <machine/cpufunc.h>
+#include <machine/md_var.h>
+#include <machine/specialreg.h>
+
+#include <dev/pci/pcivar.h>
+#include <x86/pci_cfgreg.h>
+
+#include <dev/amdsmn/amdsmn.h>
+
+#define SMN_ADDR_REG 0x60
+#define SMN_DATA_REG 0x64
+
+struct amdsmn_softc {
+ struct mtx smn_lock;
+};
+
+static struct pciid {
+ uint32_t device_id;
+} amdsmn_ids[] = {
+ { 0x14501022 },
+};
+
+/*
+ * Device methods.
+ */
+static void amdsmn_identify(driver_t *driver, device_t parent);
+static int amdsmn_probe(device_t dev);
+static int amdsmn_attach(device_t dev);
+static int amdsmn_detach(device_t dev);
+
+static device_method_t amdsmn_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_identify, amdsmn_identify),
+ DEVMETHOD(device_probe, amdsmn_probe),
+ DEVMETHOD(device_attach, amdsmn_attach),
+ DEVMETHOD(device_detach, amdsmn_detach),
+ DEVMETHOD_END
+};
+
+static driver_t amdsmn_driver = {
+ "amdsmn",
+ amdsmn_methods,
+ sizeof(struct amdsmn_softc),
+};
+
+static devclass_t amdsmn_devclass;
+DRIVER_MODULE(amdsmn, hostb, amdsmn_driver, amdsmn_devclass, NULL, NULL);
+MODULE_VERSION(amdsmn, 1);
+
+static void
+amdsmn_identify(driver_t *driver, device_t parent)
+{
+ device_t child;
+ uint32_t devid;
+ size_t i;
+
+ /* Make sure we're not being doubly invoked. */
+ if (device_find_child(parent, "amdsmn", -1) != NULL)
+ return;
+
+ devid = pci_get_devid(parent);
+ for (i = 0; i < nitems(amdsmn_ids); i++)
+ if (amdsmn_ids[i].device_id == devid)
+ break;
+
+ if (i >= nitems(amdsmn_ids))
+ return;
+
+ child = device_add_child(parent, "amdsmn", -1);
+ if (child == NULL)
+ device_printf(parent, "add amdsmn child failed\n");
+}
+
+static int
+amdsmn_probe(device_t dev)
+{
+ uint32_t family;
+
+ if (resource_disabled("amdsmn", 0))
+ return (ENXIO);
+
+ family = CPUID_TO_FAMILY(cpu_id);
+
+ switch (family) {
+ case 0x17:
+ break;
+ default:
+ return (ENXIO);
+ }
+ device_set_desc(dev, "AMD Family 17h System Management Network");
+
+ return (BUS_PROBE_GENERIC);
+}
+
+static int
+amdsmn_attach(device_t dev)
+{
+ struct amdsmn_softc *sc = device_get_softc(dev);
+
+ mtx_init(&sc->smn_lock, "SMN mtx", "SMN", MTX_DEF);
+ return (0);
+}
+
+int
+amdsmn_detach(device_t dev)
+{
+ struct amdsmn_softc *sc = device_get_softc(dev);
+
+ mtx_destroy(&sc->smn_lock);
+ return (0);
+}
+
+int
+amdsmn_read(device_t dev, uint32_t addr, uint32_t *value)
+{
+ struct amdsmn_softc *sc = device_get_softc(dev);
+ device_t parent;
+
+ parent = device_get_parent(dev);
+
+ mtx_lock(&sc->smn_lock);
+ pci_write_config(parent, SMN_ADDR_REG, addr, 4);
+ *value = pci_read_config(parent, SMN_DATA_REG, 4);
+ mtx_unlock(&sc->smn_lock);
+
+ return (0);
+}
+
+int
+amdsmn_write(device_t dev, uint32_t addr, uint32_t value)
+{
+ struct amdsmn_softc *sc = device_get_softc(dev);
+ device_t parent;
+
+ parent = device_get_parent(dev);
+
+ mtx_lock(&sc->smn_lock);
+ pci_write_config(parent, SMN_ADDR_REG, addr, 4);
+ pci_write_config(parent, SMN_DATA_REG, value, 4);
+ mtx_unlock(&sc->smn_lock);
+
+ return (0);
+}
Index: sys/dev/amdtemp/amdtemp.c
===================================================================
--- sys/dev/amdtemp/amdtemp.c
+++ sys/dev/amdtemp/amdtemp.c
@@ -49,6 +49,8 @@
#include <dev/pci/pcivar.h>
#include <x86/pci_cfgreg.h>
+#include <dev/amdsmn/amdsmn.h>
+
typedef enum {
CORE0_SENSOR0,
CORE0_SENSOR1,
@@ -59,7 +61,6 @@
} amdsensor_t;
struct amdtemp_softc {
- device_t sc_dev;
int sc_ncores;
int sc_ntemps;
int sc_flags;
@@ -70,6 +71,7 @@
int32_t (*sc_gettemp)(device_t, amdsensor_t);
struct sysctl_oid *sc_sysctl_cpu[MAXCPU];
struct intr_config_hook sc_ich;
+ device_t sc_smn;
};
#define VENDORID_AMD 0x1022
@@ -82,6 +84,7 @@
#define DEVICEID_AMD_MISC16 0x1533
#define DEVICEID_AMD_MISC16_M30H 0x1583
#define DEVICEID_AMD_MISC17 0x141d
+#define DEVICEID_AMD_HOSTB17H 0x1450
static struct amdtemp_product {
uint16_t amdtemp_vendorid;
@@ -96,6 +99,7 @@
{ VENDORID_AMD, DEVICEID_AMD_MISC16 },
{ VENDORID_AMD, DEVICEID_AMD_MISC16_M30H },
{ VENDORID_AMD, DEVICEID_AMD_MISC17 },
+ { VENDORID_AMD, DEVICEID_AMD_HOSTB17H },
{ 0, 0 }
};
@@ -104,6 +108,11 @@
*/
#define AMDTEMP_REPTMP_CTRL 0xa4
+/*
+ * Reported Temperature, Family 17h
+ */
+#define AMDTEMP_17H_CUR_TMP 0x59800
+
/*
* Thermaltrip Status Register (Family 0Fh only)
*/
@@ -133,6 +142,7 @@
static int amdtemp_match(device_t dev);
static int32_t amdtemp_gettemp0f(device_t dev, amdsensor_t sensor);
static int32_t amdtemp_gettemp(device_t dev, amdsensor_t sensor);
+static int32_t amdtemp_gettemp17h(device_t dev, amdsensor_t sensor);
static int amdtemp_sysctl(SYSCTL_HANDLER_ARGS);
static device_method_t amdtemp_methods[] = {
@@ -153,6 +163,8 @@
static devclass_t amdtemp_devclass;
DRIVER_MODULE(amdtemp, hostb, amdtemp_driver, amdtemp_devclass, NULL, NULL);
+MODULE_VERSION(amdtemp, 1);
+MODULE_DEPEND(amdtemp, amdsmn, 1, 1, 1);
static int
amdtemp_match(device_t dev)
@@ -211,6 +223,7 @@
case 0x14:
case 0x15:
case 0x16:
+ case 0x17:
break;
default:
return (ENXIO);
@@ -240,7 +253,7 @@
cpuid = cpu_id;
family = CPUID_TO_FAMILY(cpuid);
model = CPUID_TO_MODEL(cpuid);
- if (family != 0x0f || model >= 0x40) {
+ if ((family != 0x0f || model >= 0x40) && family != 0x17) {
cpuid = pci_read_config(dev, AMDTEMP_CPUID, 4);
family = CPUID_TO_FAMILY(cpuid);
model = CPUID_TO_MODEL(cpuid);
@@ -342,6 +355,16 @@
sc->sc_gettemp = amdtemp_gettemp;
break;
+ case 0x17:
+ sc->sc_ntemps = 1;
+ sc->sc_gettemp = amdtemp_gettemp17h;
+ sc->sc_smn = device_find_child(
+ device_get_parent(dev), "amdsmn", -1);
+ if (sc->sc_smn == NULL) {
+ device_printf(dev, "No SMN device found\n");
+ return (ENXIO);
+ }
+ break;
}
/* Find number of cores per package. */
@@ -557,3 +580,19 @@
return (temp);
}
+
+static int32_t
+amdtemp_gettemp17h(device_t dev, amdsensor_t sensor)
+{
+ struct amdtemp_softc *sc = device_get_softc(dev);
+ uint32_t temp;
+ int error;
+
+ error = amdsmn_read(sc->sc_smn, AMDTEMP_17H_CUR_TMP, &temp);
+ KASSERT(error == 0, ("amdsmn_read"));
+
+ temp = ((temp >> 21) & 0x7ff) * 5 / 4;
+ temp += AMDTEMP_ZERO_C_TO_K + sc->sc_offset * 10;
+
+ return (temp);
+}
Index: sys/modules/Makefile
===================================================================
--- sys/modules/Makefile
+++ sys/modules/Makefile
@@ -35,6 +35,7 @@
alq \
${_amd_ecc_inject} \
${_amdsbwd} \
+ ${_amdsmn} \
${_amdtemp} \
amr \
${_an} \
@@ -626,6 +627,7 @@
.endif
_amd_ecc_inject=amd_ecc_inject
_amdsbwd= amdsbwd
+_amdsmn= amdsmn
_amdtemp= amdtemp
_arcmsr= arcmsr
_asmc= asmc
Index: sys/modules/amdsmn/Makefile
===================================================================
--- /dev/null
+++ sys/modules/amdsmn/Makefile
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+.PATH: ${SRCTOP}/sys/dev/amdsmn
+
+KMOD= amdsmn
+SRCS= amdsmn.c bus_if.h device_if.h pci_if.h
+
+.include <bsd.kmod.mk>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 22, 1:49 AM (7 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25865847
Default Alt Text
D12217.id32657.diff (15 KB)
Attached To
Mode
D12217: Add temperature sensor support for AMD Zen processors; two separate commits included this review.
Attached
Detach File
Event Timeline
Log In to Comment