2008-04-12 14:04:08 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2009-03-13 16:28:25 +00:00
|
|
|
* Copyright (c) 2008, 2009 Rui Paulo <rpaulo@FreeBSD.org>
|
|
|
|
* Copyright (c) 2009 Norikatsu Shigemura <nork@FreeBSD.org>
|
2012-02-24 00:02:46 +00:00
|
|
|
* Copyright (c) 2009-2012 Jung-uk Kim <jkim@FreeBSD.org>
|
2008-04-12 14:04:08 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2012-02-24 00:02:46 +00:00
|
|
|
* Driver for the AMD CPU on-die thermal sensors.
|
2009-09-11 21:47:44 +00:00
|
|
|
* Initially based on the k8temp Linux driver.
|
2008-04-12 14:04:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kernel.h>
|
2009-09-11 21:47:44 +00:00
|
|
|
#include <sys/module.h>
|
2008-04-12 14:04:08 +00:00
|
|
|
#include <sys/sysctl.h>
|
2009-09-11 21:47:44 +00:00
|
|
|
#include <sys/systm.h>
|
2008-04-12 14:04:08 +00:00
|
|
|
|
2009-09-14 23:08:19 +00:00
|
|
|
#include <machine/cpufunc.h>
|
2008-04-12 14:04:08 +00:00
|
|
|
#include <machine/md_var.h>
|
2009-09-11 21:47:44 +00:00
|
|
|
#include <machine/specialreg.h>
|
2008-04-12 14:04:08 +00:00
|
|
|
|
|
|
|
#include <dev/pci/pcivar.h>
|
2012-02-24 00:02:46 +00:00
|
|
|
#include <x86/pci_cfgreg.h>
|
2008-04-12 14:04:08 +00:00
|
|
|
|
2017-09-05 15:19:14 +00:00
|
|
|
#include <dev/amdsmn/amdsmn.h>
|
|
|
|
|
2009-03-13 16:28:25 +00:00
|
|
|
typedef enum {
|
2012-02-24 00:02:46 +00:00
|
|
|
CORE0_SENSOR0,
|
|
|
|
CORE0_SENSOR1,
|
|
|
|
CORE1_SENSOR0,
|
|
|
|
CORE1_SENSOR1,
|
2009-03-13 16:28:25 +00:00
|
|
|
CORE0,
|
|
|
|
CORE1
|
|
|
|
} amdsensor_t;
|
|
|
|
|
|
|
|
struct amdtemp_softc {
|
2009-09-11 21:47:44 +00:00
|
|
|
int sc_ncores;
|
2008-04-12 14:04:08 +00:00
|
|
|
int sc_ntemps;
|
2009-09-14 23:08:19 +00:00
|
|
|
int sc_flags;
|
2012-02-24 00:02:46 +00:00
|
|
|
#define AMDTEMP_FLAG_CS_SWAP 0x01 /* ThermSenseCoreSel is inverted. */
|
|
|
|
#define AMDTEMP_FLAG_CT_10BIT 0x02 /* CurTmp is 10-bit wide. */
|
|
|
|
#define AMDTEMP_FLAG_ALT_OFFSET 0x04 /* CurTmp starts at -28C. */
|
|
|
|
int32_t sc_offset;
|
2009-09-11 21:47:44 +00:00
|
|
|
int32_t (*sc_gettemp)(device_t, amdsensor_t);
|
|
|
|
struct sysctl_oid *sc_sysctl_cpu[MAXCPU];
|
2008-07-05 23:19:37 +00:00
|
|
|
struct intr_config_hook sc_ich;
|
2017-09-05 15:19:14 +00:00
|
|
|
device_t sc_smn;
|
2008-04-12 14:04:08 +00:00
|
|
|
};
|
|
|
|
|
2009-09-11 21:47:44 +00:00
|
|
|
#define VENDORID_AMD 0x1022
|
|
|
|
#define DEVICEID_AMD_MISC0F 0x1103
|
|
|
|
#define DEVICEID_AMD_MISC10 0x1203
|
|
|
|
#define DEVICEID_AMD_MISC11 0x1303
|
2013-08-26 17:38:36 +00:00
|
|
|
#define DEVICEID_AMD_MISC12 0x1403
|
2012-02-24 00:02:46 +00:00
|
|
|
#define DEVICEID_AMD_MISC14 0x1703
|
|
|
|
#define DEVICEID_AMD_MISC15 0x1603
|
2014-03-14 12:15:28 +00:00
|
|
|
#define DEVICEID_AMD_MISC16 0x1533
|
2016-04-19 15:07:04 +00:00
|
|
|
#define DEVICEID_AMD_MISC16_M30H 0x1583
|
2014-10-13 13:13:42 +00:00
|
|
|
#define DEVICEID_AMD_MISC17 0x141d
|
2018-11-14 03:42:39 +00:00
|
|
|
#define DEVICEID_AMD_HOSTB17H_ROOT 0x1450
|
|
|
|
#define DEVICEID_AMD_HOSTB17H_DF_F3 0x1463
|
|
|
|
#define DEVICEID_AMD_HOSTB17H_M10H_ROOT 0x15d0
|
|
|
|
#define DEVICEID_AMD_HOSTB17H_M10H_DF_F3 0x15eb
|
2009-03-13 16:28:25 +00:00
|
|
|
|
|
|
|
static struct amdtemp_product {
|
|
|
|
uint16_t amdtemp_vendorid;
|
|
|
|
uint16_t amdtemp_deviceid;
|
|
|
|
} amdtemp_products[] = {
|
|
|
|
{ VENDORID_AMD, DEVICEID_AMD_MISC0F },
|
|
|
|
{ VENDORID_AMD, DEVICEID_AMD_MISC10 },
|
|
|
|
{ VENDORID_AMD, DEVICEID_AMD_MISC11 },
|
2013-08-26 17:38:36 +00:00
|
|
|
{ VENDORID_AMD, DEVICEID_AMD_MISC12 },
|
2012-02-24 00:02:46 +00:00
|
|
|
{ VENDORID_AMD, DEVICEID_AMD_MISC14 },
|
|
|
|
{ VENDORID_AMD, DEVICEID_AMD_MISC15 },
|
2014-03-14 12:15:28 +00:00
|
|
|
{ VENDORID_AMD, DEVICEID_AMD_MISC16 },
|
2016-04-19 15:07:04 +00:00
|
|
|
{ VENDORID_AMD, DEVICEID_AMD_MISC16_M30H },
|
2014-10-13 13:13:42 +00:00
|
|
|
{ VENDORID_AMD, DEVICEID_AMD_MISC17 },
|
2018-11-14 03:42:39 +00:00
|
|
|
{ VENDORID_AMD, DEVICEID_AMD_HOSTB17H_ROOT },
|
|
|
|
{ VENDORID_AMD, DEVICEID_AMD_HOSTB17H_M10H_ROOT },
|
2008-04-12 14:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2012-02-24 00:02:46 +00:00
|
|
|
* Reported Temperature Control Register
|
2008-04-12 14:04:08 +00:00
|
|
|
*/
|
2009-09-11 21:47:44 +00:00
|
|
|
#define AMDTEMP_REPTMP_CTRL 0xa4
|
2008-04-12 14:04:08 +00:00
|
|
|
|
2017-09-05 15:19:14 +00:00
|
|
|
/*
|
|
|
|
* Reported Temperature, Family 17h
|
2018-11-14 04:50:29 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2017-09-05 15:19:14 +00:00
|
|
|
*/
|
2018-11-14 04:50:29 +00:00
|
|
|
#define AMDTEMP_17H_CUR_TMP 0x59800
|
|
|
|
#define AMDTEMP_17H_CUR_TMP_RANGE_SEL (1 << 19)
|
|
|
|
#define AMDTEMP_17H_CUR_TMP_RANGE_OFF 490
|
2017-09-05 15:19:14 +00:00
|
|
|
|
2009-03-13 16:28:25 +00:00
|
|
|
/*
|
2012-02-24 00:02:46 +00:00
|
|
|
* Thermaltrip Status Register (Family 0Fh only)
|
2009-03-13 16:28:25 +00:00
|
|
|
*/
|
2009-09-11 21:47:44 +00:00
|
|
|
#define AMDTEMP_THERMTP_STAT 0xe4
|
2012-02-24 00:02:46 +00:00
|
|
|
#define AMDTEMP_TTSR_SELCORE 0x04
|
|
|
|
#define AMDTEMP_TTSR_SELSENSOR 0x40
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DRAM Configuration High Register
|
|
|
|
*/
|
|
|
|
#define AMDTEMP_DRAM_CONF_HIGH 0x94 /* Function 2 */
|
|
|
|
#define AMDTEMP_DRAM_MODE_DDR3 0x0100
|
2009-03-13 16:28:25 +00:00
|
|
|
|
2009-09-11 21:47:44 +00:00
|
|
|
/*
|
|
|
|
* CPU Family/Model Register
|
|
|
|
*/
|
|
|
|
#define AMDTEMP_CPUID 0xfc
|
2008-04-12 14:04:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Device methods.
|
|
|
|
*/
|
2009-03-13 16:28:25 +00:00
|
|
|
static void amdtemp_identify(driver_t *driver, device_t parent);
|
|
|
|
static int amdtemp_probe(device_t dev);
|
|
|
|
static int amdtemp_attach(device_t dev);
|
|
|
|
static void amdtemp_intrhook(void *arg);
|
|
|
|
static int amdtemp_detach(device_t dev);
|
|
|
|
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);
|
2017-09-05 15:19:14 +00:00
|
|
|
static int32_t amdtemp_gettemp17h(device_t dev, amdsensor_t sensor);
|
2009-03-13 16:28:25 +00:00
|
|
|
static int amdtemp_sysctl(SYSCTL_HANDLER_ARGS);
|
|
|
|
|
|
|
|
static device_method_t amdtemp_methods[] = {
|
2008-04-12 14:04:08 +00:00
|
|
|
/* Device interface */
|
2009-03-13 16:28:25 +00:00
|
|
|
DEVMETHOD(device_identify, amdtemp_identify),
|
|
|
|
DEVMETHOD(device_probe, amdtemp_probe),
|
|
|
|
DEVMETHOD(device_attach, amdtemp_attach),
|
|
|
|
DEVMETHOD(device_detach, amdtemp_detach),
|
2008-04-12 14:04:08 +00:00
|
|
|
|
2013-01-30 18:01:20 +00:00
|
|
|
DEVMETHOD_END
|
2008-04-12 14:04:08 +00:00
|
|
|
};
|
|
|
|
|
2009-03-13 16:28:25 +00:00
|
|
|
static driver_t amdtemp_driver = {
|
|
|
|
"amdtemp",
|
|
|
|
amdtemp_methods,
|
|
|
|
sizeof(struct amdtemp_softc),
|
2008-04-12 14:04:08 +00:00
|
|
|
};
|
|
|
|
|
2009-03-13 16:28:25 +00:00
|
|
|
static devclass_t amdtemp_devclass;
|
|
|
|
DRIVER_MODULE(amdtemp, hostb, amdtemp_driver, amdtemp_devclass, NULL, NULL);
|
2017-09-05 15:19:14 +00:00
|
|
|
MODULE_VERSION(amdtemp, 1);
|
|
|
|
MODULE_DEPEND(amdtemp, amdsmn, 1, 1, 1);
|
2017-09-14 15:34:45 +00:00
|
|
|
MODULE_PNP_INFO("U16:vendor;U16:device", pci, amdtemp, amdtemp_products,
|
Reapply, with minor tweaks, r338025, from the original commit:
Remove unused and easy to misuse PNP macro parameter
Inspired by r338025, just remove the element size parameter to the
MODULE_PNP_INFO macro entirely. The 'table' parameter is now required to
have correct pointer (or array) type. Since all invocations of the macro
already had this property and the emitted PNP data continues to include the
element size, there is no functional change.
Mostly done with the coccinelle 'spatch' tool:
$ cat modpnpsize0.cocci
@normaltables@
identifier b,c;
expression a,d,e;
declarer MODULE_PNP_INFO;
@@
MODULE_PNP_INFO(a,b,c,d,
-sizeof(d[0]),
e);
@singletons@
identifier b,c,d;
expression a;
declarer MODULE_PNP_INFO;
@@
MODULE_PNP_INFO(a,b,c,&d,
-sizeof(d),
1);
$ rg -l MODULE_PNP_INFO -- sys | \
xargs spatch --in-place --sp-file modpnpsize0.cocci
(Note that coccinelle invokes diff(1) via a PATH search and expects diff to
tolerate the -B flag, which BSD diff does not. So I had to link gdiff into
PATH as diff to use spatch.)
Tinderbox'd (-DMAKE_JUST_KERNELS).
Approved by: re (glen)
2018-09-26 17:12:14 +00:00
|
|
|
nitems(amdtemp_products));
|
2008-04-12 14:04:08 +00:00
|
|
|
|
|
|
|
static int
|
2009-03-13 16:28:25 +00:00
|
|
|
amdtemp_match(device_t dev)
|
2008-04-12 14:04:08 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint16_t vendor, devid;
|
2009-09-11 21:47:44 +00:00
|
|
|
|
|
|
|
vendor = pci_get_vendor(dev);
|
2008-04-12 14:04:08 +00:00
|
|
|
devid = pci_get_device(dev);
|
|
|
|
|
2017-09-14 15:34:45 +00:00
|
|
|
for (i = 0; i < nitems(amdtemp_products); i++) {
|
2009-03-13 16:28:25 +00:00
|
|
|
if (vendor == amdtemp_products[i].amdtemp_vendorid &&
|
|
|
|
devid == amdtemp_products[i].amdtemp_deviceid)
|
2008-04-12 14:04:08 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-03-13 16:28:25 +00:00
|
|
|
amdtemp_identify(driver_t *driver, device_t parent)
|
2008-04-12 14:04:08 +00:00
|
|
|
{
|
|
|
|
device_t child;
|
|
|
|
|
|
|
|
/* Make sure we're not being doubly invoked. */
|
2009-03-13 16:28:25 +00:00
|
|
|
if (device_find_child(parent, "amdtemp", -1) != NULL)
|
2008-04-12 14:04:08 +00:00
|
|
|
return;
|
2009-09-11 21:47:44 +00:00
|
|
|
|
2009-03-13 16:28:25 +00:00
|
|
|
if (amdtemp_match(parent)) {
|
|
|
|
child = device_add_child(parent, "amdtemp", -1);
|
2008-04-12 14:04:08 +00:00
|
|
|
if (child == NULL)
|
2009-03-13 16:28:25 +00:00
|
|
|
device_printf(parent, "add amdtemp child failed\n");
|
2008-04-12 14:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-03-13 16:28:25 +00:00
|
|
|
amdtemp_probe(device_t dev)
|
2008-04-12 14:04:08 +00:00
|
|
|
{
|
2009-09-14 23:08:19 +00:00
|
|
|
uint32_t family, model;
|
2009-09-11 21:47:44 +00:00
|
|
|
|
2012-10-22 13:06:09 +00:00
|
|
|
if (resource_disabled("amdtemp", 0))
|
|
|
|
return (ENXIO);
|
2017-09-05 20:35:25 +00:00
|
|
|
if (!amdtemp_match(device_get_parent(dev)))
|
|
|
|
return (ENXIO);
|
2012-10-22 13:06:09 +00:00
|
|
|
|
2009-09-14 23:08:19 +00:00
|
|
|
family = CPUID_TO_FAMILY(cpu_id);
|
|
|
|
model = CPUID_TO_MODEL(cpu_id);
|
2009-09-11 21:47:44 +00:00
|
|
|
|
|
|
|
switch (family) {
|
|
|
|
case 0x0f:
|
2009-09-14 23:08:19 +00:00
|
|
|
if ((model == 0x04 && (cpu_id & CPUID_STEPPING) == 0) ||
|
|
|
|
(model == 0x05 && (cpu_id & CPUID_STEPPING) <= 1))
|
2009-09-11 21:47:44 +00:00
|
|
|
return (ENXIO);
|
|
|
|
break;
|
|
|
|
case 0x10:
|
|
|
|
case 0x11:
|
2012-02-24 00:02:46 +00:00
|
|
|
case 0x12:
|
|
|
|
case 0x14:
|
|
|
|
case 0x15:
|
2014-03-14 12:15:28 +00:00
|
|
|
case 0x16:
|
2017-09-05 15:19:14 +00:00
|
|
|
case 0x17:
|
2009-09-11 21:47:44 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-04-12 14:04:08 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
2009-09-11 21:47:44 +00:00
|
|
|
device_set_desc(dev, "AMD CPU On-Die Thermal Sensors");
|
|
|
|
|
2008-04-12 14:04:08 +00:00
|
|
|
return (BUS_PROBE_GENERIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-03-13 16:28:25 +00:00
|
|
|
amdtemp_attach(device_t dev)
|
2008-04-12 14:04:08 +00:00
|
|
|
{
|
2012-02-24 00:02:46 +00:00
|
|
|
char tn[32];
|
|
|
|
u_int regs[4];
|
2009-03-13 16:28:25 +00:00
|
|
|
struct amdtemp_softc *sc = device_get_softc(dev);
|
2008-04-12 14:04:08 +00:00
|
|
|
struct sysctl_ctx_list *sysctlctx;
|
|
|
|
struct sysctl_oid *sysctlnode;
|
2009-09-11 21:47:44 +00:00
|
|
|
uint32_t cpuid, family, model;
|
2012-02-24 00:02:46 +00:00
|
|
|
u_int bid;
|
|
|
|
int erratum319, unit;
|
2009-09-11 21:47:44 +00:00
|
|
|
|
2012-02-24 00:02:46 +00:00
|
|
|
erratum319 = 0;
|
2009-09-14 23:08:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CPUID Register is available from Revision F.
|
|
|
|
*/
|
2012-02-24 00:02:46 +00:00
|
|
|
cpuid = cpu_id;
|
|
|
|
family = CPUID_TO_FAMILY(cpuid);
|
|
|
|
model = CPUID_TO_MODEL(cpuid);
|
2017-09-05 15:19:14 +00:00
|
|
|
if ((family != 0x0f || model >= 0x40) && family != 0x17) {
|
2009-09-14 23:08:19 +00:00
|
|
|
cpuid = pci_read_config(dev, AMDTEMP_CPUID, 4);
|
|
|
|
family = CPUID_TO_FAMILY(cpuid);
|
|
|
|
model = CPUID_TO_MODEL(cpuid);
|
|
|
|
}
|
2009-09-11 21:47:44 +00:00
|
|
|
|
|
|
|
switch (family) {
|
|
|
|
case 0x0f:
|
|
|
|
/*
|
2009-09-14 23:08:19 +00:00
|
|
|
* Thermaltrip Status Register
|
|
|
|
*
|
|
|
|
* - ThermSenseCoreSel
|
|
|
|
*
|
|
|
|
* Revision F & G: 0 - Core1, 1 - Core0
|
|
|
|
* Other: 0 - Core0, 1 - Core1
|
|
|
|
*
|
|
|
|
* - CurTmp
|
2009-09-11 21:47:44 +00:00
|
|
|
*
|
|
|
|
* Revision G: bits 23-14
|
2009-09-14 23:08:19 +00:00
|
|
|
* Other: bits 23-16
|
2009-09-11 21:47:44 +00:00
|
|
|
*
|
2009-09-14 23:08:19 +00:00
|
|
|
* XXX According to the BKDG, CurTmp, ThermSenseSel and
|
|
|
|
* ThermSenseCoreSel bits were introduced in Revision F
|
|
|
|
* but CurTmp seems working fine as early as Revision C.
|
|
|
|
* However, it is not clear whether ThermSenseSel and/or
|
|
|
|
* ThermSenseCoreSel work in undocumented cases as well.
|
|
|
|
* In fact, the Linux driver suggests it may not work but
|
|
|
|
* we just assume it does until we find otherwise.
|
2012-02-24 00:02:46 +00:00
|
|
|
*
|
|
|
|
* XXX According to Linux, CurTmp starts at -28C on
|
|
|
|
* Socket AM2 Revision G processors, which is not
|
|
|
|
* documented anywhere.
|
2009-09-11 21:47:44 +00:00
|
|
|
*/
|
2012-02-24 00:02:46 +00:00
|
|
|
if (model >= 0x40)
|
2009-09-14 23:08:19 +00:00
|
|
|
sc->sc_flags |= AMDTEMP_FLAG_CS_SWAP;
|
2012-02-24 00:02:46 +00:00
|
|
|
if (model >= 0x60 && model != 0xc1) {
|
|
|
|
do_cpuid(0x80000001, regs);
|
|
|
|
bid = (regs[1] >> 9) & 0x1f;
|
|
|
|
switch (model) {
|
|
|
|
case 0x68: /* Socket S1g1 */
|
|
|
|
case 0x6c:
|
|
|
|
case 0x7c:
|
|
|
|
break;
|
|
|
|
case 0x6b: /* Socket AM2 and ASB1 (2 cores) */
|
|
|
|
if (bid != 0x0b && bid != 0x0c)
|
|
|
|
sc->sc_flags |=
|
|
|
|
AMDTEMP_FLAG_ALT_OFFSET;
|
|
|
|
break;
|
|
|
|
case 0x6f: /* Socket AM2 and ASB1 (1 core) */
|
|
|
|
case 0x7f:
|
|
|
|
if (bid != 0x07 && bid != 0x09 &&
|
|
|
|
bid != 0x0c)
|
|
|
|
sc->sc_flags |=
|
|
|
|
AMDTEMP_FLAG_ALT_OFFSET;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sc->sc_flags |= AMDTEMP_FLAG_ALT_OFFSET;
|
|
|
|
}
|
|
|
|
sc->sc_flags |= AMDTEMP_FLAG_CT_10BIT;
|
2009-09-14 23:08:19 +00:00
|
|
|
}
|
2009-09-11 21:47:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* There are two sensors per core.
|
|
|
|
*/
|
|
|
|
sc->sc_ntemps = 2;
|
2008-04-12 14:04:08 +00:00
|
|
|
|
2009-03-13 16:28:25 +00:00
|
|
|
sc->sc_gettemp = amdtemp_gettemp0f;
|
2009-09-11 21:47:44 +00:00
|
|
|
break;
|
|
|
|
case 0x10:
|
2012-02-24 00:02:46 +00:00
|
|
|
/*
|
|
|
|
* Erratum 319 Inaccurate Temperature Measurement
|
|
|
|
*
|
|
|
|
* http://support.amd.com/us/Processor_TechDocs/41322.pdf
|
|
|
|
*/
|
|
|
|
do_cpuid(0x80000001, regs);
|
|
|
|
switch ((regs[1] >> 28) & 0xf) {
|
|
|
|
case 0: /* Socket F */
|
|
|
|
erratum319 = 1;
|
|
|
|
break;
|
|
|
|
case 1: /* Socket AM2+ or AM3 */
|
|
|
|
if ((pci_cfgregread(pci_get_bus(dev),
|
|
|
|
pci_get_slot(dev), 2, AMDTEMP_DRAM_CONF_HIGH, 2) &
|
|
|
|
AMDTEMP_DRAM_MODE_DDR3) != 0 || model > 0x04 ||
|
|
|
|
(model == 0x04 && (cpuid & CPUID_STEPPING) >= 3))
|
|
|
|
break;
|
|
|
|
/* XXX 00100F42h (RB-C2) exists in both formats. */
|
|
|
|
erratum319 = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
2009-09-11 21:47:44 +00:00
|
|
|
case 0x11:
|
2012-02-24 00:02:46 +00:00
|
|
|
case 0x12:
|
|
|
|
case 0x14:
|
|
|
|
case 0x15:
|
2014-03-14 12:15:28 +00:00
|
|
|
case 0x16:
|
2009-09-11 21:47:44 +00:00
|
|
|
/*
|
|
|
|
* There is only one sensor per package.
|
|
|
|
*/
|
|
|
|
sc->sc_ntemps = 1;
|
|
|
|
|
2009-03-13 16:28:25 +00:00
|
|
|
sc->sc_gettemp = amdtemp_gettemp;
|
2009-09-11 21:47:44 +00:00
|
|
|
break;
|
2017-09-05 15:19:14 +00:00
|
|
|
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) {
|
|
|
|
if (bootverbose)
|
|
|
|
device_printf(dev, "No SMN device found\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
break;
|
2009-03-13 16:28:25 +00:00
|
|
|
}
|
|
|
|
|
2009-09-11 21:47:44 +00:00
|
|
|
/* Find number of cores per package. */
|
|
|
|
sc->sc_ncores = (amd_feature2 & AMDID2_CMP) != 0 ?
|
|
|
|
(cpu_procinfo2 & AMDID_CMP_CORES) + 1 : 1;
|
|
|
|
if (sc->sc_ncores > MAXCPU)
|
|
|
|
return (ENXIO);
|
|
|
|
|
2012-02-24 00:02:46 +00:00
|
|
|
if (erratum319)
|
|
|
|
device_printf(dev,
|
|
|
|
"Erratum 319: temperature measurement may be inaccurate\n");
|
2009-09-11 21:47:44 +00:00
|
|
|
if (bootverbose)
|
|
|
|
device_printf(dev, "Found %d cores and %d sensors.\n",
|
|
|
|
sc->sc_ncores,
|
|
|
|
sc->sc_ntemps > 1 ? sc->sc_ntemps * sc->sc_ncores : 1);
|
|
|
|
|
2008-04-12 14:04:08 +00:00
|
|
|
/*
|
2009-03-13 16:28:25 +00:00
|
|
|
* dev.amdtemp.N tree.
|
2008-04-12 14:04:08 +00:00
|
|
|
*/
|
2012-02-24 00:02:46 +00:00
|
|
|
unit = device_get_unit(dev);
|
|
|
|
snprintf(tn, sizeof(tn), "dev.amdtemp.%d.sensor_offset", unit);
|
|
|
|
TUNABLE_INT_FETCH(tn, &sc->sc_offset);
|
|
|
|
|
2008-04-12 14:04:08 +00:00
|
|
|
sysctlctx = device_get_sysctl_ctx(dev);
|
2012-02-24 00:02:46 +00:00
|
|
|
SYSCTL_ADD_INT(sysctlctx,
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
|
|
|
|
"sensor_offset", CTLFLAG_RW, &sc->sc_offset, 0,
|
|
|
|
"Temperature sensor offset");
|
2008-04-12 14:04:08 +00:00
|
|
|
sysctlnode = SYSCTL_ADD_NODE(sysctlctx,
|
2009-09-11 21:47:44 +00:00
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
|
2012-02-24 00:02:46 +00:00
|
|
|
"core0", CTLFLAG_RD, 0, "Core 0");
|
2009-09-11 21:47:44 +00:00
|
|
|
|
2008-04-12 14:04:08 +00:00
|
|
|
SYSCTL_ADD_PROC(sysctlctx,
|
|
|
|
SYSCTL_CHILDREN(sysctlnode),
|
2012-02-24 00:02:46 +00:00
|
|
|
OID_AUTO, "sensor0", CTLTYPE_INT | CTLFLAG_RD,
|
|
|
|
dev, CORE0_SENSOR0, amdtemp_sysctl, "IK",
|
|
|
|
"Core 0 / Sensor 0 temperature");
|
2009-09-11 21:47:44 +00:00
|
|
|
|
|
|
|
if (sc->sc_ntemps > 1) {
|
|
|
|
SYSCTL_ADD_PROC(sysctlctx,
|
|
|
|
SYSCTL_CHILDREN(sysctlnode),
|
2012-02-24 00:02:46 +00:00
|
|
|
OID_AUTO, "sensor1", CTLTYPE_INT | CTLFLAG_RD,
|
|
|
|
dev, CORE0_SENSOR1, amdtemp_sysctl, "IK",
|
|
|
|
"Core 0 / Sensor 1 temperature");
|
|
|
|
|
|
|
|
if (sc->sc_ncores > 1) {
|
|
|
|
sysctlnode = SYSCTL_ADD_NODE(sysctlctx,
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
|
|
|
|
OID_AUTO, "core1", CTLFLAG_RD, 0, "Core 1");
|
|
|
|
|
|
|
|
SYSCTL_ADD_PROC(sysctlctx,
|
|
|
|
SYSCTL_CHILDREN(sysctlnode),
|
|
|
|
OID_AUTO, "sensor0", CTLTYPE_INT | CTLFLAG_RD,
|
|
|
|
dev, CORE1_SENSOR0, amdtemp_sysctl, "IK",
|
|
|
|
"Core 1 / Sensor 0 temperature");
|
2009-09-11 21:47:44 +00:00
|
|
|
|
|
|
|
SYSCTL_ADD_PROC(sysctlctx,
|
|
|
|
SYSCTL_CHILDREN(sysctlnode),
|
2012-02-24 00:02:46 +00:00
|
|
|
OID_AUTO, "sensor1", CTLTYPE_INT | CTLFLAG_RD,
|
|
|
|
dev, CORE1_SENSOR1, amdtemp_sysctl, "IK",
|
|
|
|
"Core 1 / Sensor 1 temperature");
|
|
|
|
}
|
2009-09-11 21:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to create dev.cpu sysctl entries and setup intrhook function.
|
|
|
|
* This is needed because the cpu driver may be loaded late on boot,
|
|
|
|
* after us.
|
|
|
|
*/
|
|
|
|
amdtemp_intrhook(dev);
|
|
|
|
sc->sc_ich.ich_func = amdtemp_intrhook;
|
|
|
|
sc->sc_ich.ich_arg = dev;
|
|
|
|
if (config_intrhook_establish(&sc->sc_ich) != 0) {
|
|
|
|
device_printf(dev, "config_intrhook_establish failed!\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
2008-04-12 14:04:08 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-07-05 23:19:37 +00:00
|
|
|
void
|
2009-03-13 16:28:25 +00:00
|
|
|
amdtemp_intrhook(void *arg)
|
2008-07-05 23:19:37 +00:00
|
|
|
{
|
2009-03-13 16:28:25 +00:00
|
|
|
struct amdtemp_softc *sc;
|
2008-07-05 23:19:37 +00:00
|
|
|
struct sysctl_ctx_list *sysctlctx;
|
2009-09-11 21:47:44 +00:00
|
|
|
device_t dev = (device_t)arg;
|
|
|
|
device_t acpi, cpu, nexus;
|
|
|
|
amdsensor_t sensor;
|
|
|
|
int i;
|
2008-07-05 23:19:37 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2009-09-11 21:47:44 +00:00
|
|
|
|
2008-07-05 23:19:37 +00:00
|
|
|
/*
|
|
|
|
* dev.cpu.N.temperature.
|
|
|
|
*/
|
|
|
|
nexus = device_find_child(root_bus, "nexus", 0);
|
|
|
|
acpi = device_find_child(nexus, "acpi", 0);
|
|
|
|
|
2009-09-11 21:47:44 +00:00
|
|
|
for (i = 0; i < sc->sc_ncores; i++) {
|
|
|
|
if (sc->sc_sysctl_cpu[i] != NULL)
|
|
|
|
continue;
|
2008-07-05 23:19:37 +00:00
|
|
|
cpu = device_find_child(acpi, "cpu",
|
2009-09-11 21:47:44 +00:00
|
|
|
device_get_unit(dev) * sc->sc_ncores + i);
|
|
|
|
if (cpu != NULL) {
|
2008-07-05 23:19:37 +00:00
|
|
|
sysctlctx = device_get_sysctl_ctx(cpu);
|
|
|
|
|
2009-09-11 21:47:44 +00:00
|
|
|
sensor = sc->sc_ntemps > 1 ?
|
2012-02-24 00:02:46 +00:00
|
|
|
(i == 0 ? CORE0 : CORE1) : CORE0_SENSOR0;
|
2008-07-05 23:19:37 +00:00
|
|
|
sc->sc_sysctl_cpu[i] = SYSCTL_ADD_PROC(sysctlctx,
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(cpu)),
|
|
|
|
OID_AUTO, "temperature", CTLTYPE_INT | CTLFLAG_RD,
|
2009-09-11 21:47:44 +00:00
|
|
|
dev, sensor, amdtemp_sysctl, "IK",
|
|
|
|
"Current temparature");
|
2008-07-05 23:19:37 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-11 21:47:44 +00:00
|
|
|
if (sc->sc_ich.ich_arg != NULL)
|
|
|
|
config_intrhook_disestablish(&sc->sc_ich);
|
2008-07-05 23:19:37 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 14:04:08 +00:00
|
|
|
int
|
2009-03-13 16:28:25 +00:00
|
|
|
amdtemp_detach(device_t dev)
|
2008-04-12 14:04:08 +00:00
|
|
|
{
|
2009-03-13 16:28:25 +00:00
|
|
|
struct amdtemp_softc *sc = device_get_softc(dev);
|
2009-09-11 21:47:44 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sc->sc_ncores; i++)
|
|
|
|
if (sc->sc_sysctl_cpu[i] != NULL)
|
2008-04-12 14:04:08 +00:00
|
|
|
sysctl_remove_oid(sc->sc_sysctl_cpu[i], 1, 0);
|
|
|
|
|
2009-03-13 16:28:25 +00:00
|
|
|
/* NewBus removes the dev.amdtemp.N tree by itself. */
|
2009-09-11 21:47:44 +00:00
|
|
|
|
2008-04-12 14:04:08 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-03-13 16:28:25 +00:00
|
|
|
amdtemp_sysctl(SYSCTL_HANDLER_ARGS)
|
2008-04-12 14:04:08 +00:00
|
|
|
{
|
2009-09-11 21:47:44 +00:00
|
|
|
device_t dev = (device_t)arg1;
|
2009-03-13 16:28:25 +00:00
|
|
|
struct amdtemp_softc *sc = device_get_softc(dev);
|
2009-09-11 21:47:44 +00:00
|
|
|
amdsensor_t sensor = (amdsensor_t)arg2;
|
|
|
|
int32_t auxtemp[2], temp;
|
2008-04-12 14:04:08 +00:00
|
|
|
int error;
|
|
|
|
|
2009-09-11 21:47:44 +00:00
|
|
|
switch (sensor) {
|
2008-04-12 14:04:08 +00:00
|
|
|
case CORE0:
|
2012-02-24 00:02:46 +00:00
|
|
|
auxtemp[0] = sc->sc_gettemp(dev, CORE0_SENSOR0);
|
|
|
|
auxtemp[1] = sc->sc_gettemp(dev, CORE0_SENSOR1);
|
2008-05-14 09:57:21 +00:00
|
|
|
temp = imax(auxtemp[0], auxtemp[1]);
|
2008-04-12 14:04:08 +00:00
|
|
|
break;
|
|
|
|
case CORE1:
|
2012-02-24 00:02:46 +00:00
|
|
|
auxtemp[0] = sc->sc_gettemp(dev, CORE1_SENSOR0);
|
|
|
|
auxtemp[1] = sc->sc_gettemp(dev, CORE1_SENSOR1);
|
2008-05-14 09:57:21 +00:00
|
|
|
temp = imax(auxtemp[0], auxtemp[1]);
|
2008-04-12 14:04:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-09-11 21:47:44 +00:00
|
|
|
temp = sc->sc_gettemp(dev, sensor);
|
2008-04-12 14:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
error = sysctl_handle_int(oidp, &temp, 0, req);
|
2009-09-11 21:47:44 +00:00
|
|
|
|
2008-04-12 14:04:08 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2016-05-22 13:58:32 +00:00
|
|
|
#define AMDTEMP_ZERO_C_TO_K 2731
|
2009-09-11 21:47:44 +00:00
|
|
|
|
2008-04-12 14:04:08 +00:00
|
|
|
static int32_t
|
2009-03-13 16:28:25 +00:00
|
|
|
amdtemp_gettemp0f(device_t dev, amdsensor_t sensor)
|
2008-04-12 14:04:08 +00:00
|
|
|
{
|
2009-09-11 21:47:44 +00:00
|
|
|
struct amdtemp_softc *sc = device_get_softc(dev);
|
2012-02-24 00:02:46 +00:00
|
|
|
uint32_t mask, offset, temp;
|
2009-09-11 21:47:44 +00:00
|
|
|
|
|
|
|
/* Set Sensor/Core selector. */
|
2012-02-24 00:02:46 +00:00
|
|
|
temp = pci_read_config(dev, AMDTEMP_THERMTP_STAT, 1);
|
|
|
|
temp &= ~(AMDTEMP_TTSR_SELCORE | AMDTEMP_TTSR_SELSENSOR);
|
2008-04-12 14:04:08 +00:00
|
|
|
switch (sensor) {
|
2012-02-24 00:02:46 +00:00
|
|
|
case CORE0_SENSOR1:
|
|
|
|
temp |= AMDTEMP_TTSR_SELSENSOR;
|
2009-09-11 22:05:59 +00:00
|
|
|
/* FALLTHROUGH */
|
2012-02-24 00:02:46 +00:00
|
|
|
case CORE0_SENSOR0:
|
2009-09-11 21:47:44 +00:00
|
|
|
case CORE0:
|
2009-09-14 23:08:19 +00:00
|
|
|
if ((sc->sc_flags & AMDTEMP_FLAG_CS_SWAP) != 0)
|
2012-02-24 00:02:46 +00:00
|
|
|
temp |= AMDTEMP_TTSR_SELCORE;
|
2008-04-12 14:04:08 +00:00
|
|
|
break;
|
2012-02-24 00:02:46 +00:00
|
|
|
case CORE1_SENSOR1:
|
|
|
|
temp |= AMDTEMP_TTSR_SELSENSOR;
|
2009-09-11 22:05:59 +00:00
|
|
|
/* FALLTHROUGH */
|
2012-02-24 00:02:46 +00:00
|
|
|
case CORE1_SENSOR0:
|
2009-09-11 21:47:44 +00:00
|
|
|
case CORE1:
|
2009-09-14 23:08:19 +00:00
|
|
|
if ((sc->sc_flags & AMDTEMP_FLAG_CS_SWAP) == 0)
|
2012-02-24 00:02:46 +00:00
|
|
|
temp |= AMDTEMP_TTSR_SELCORE;
|
2008-04-12 14:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-02-24 00:02:46 +00:00
|
|
|
pci_write_config(dev, AMDTEMP_THERMTP_STAT, temp, 1);
|
2009-09-11 21:47:44 +00:00
|
|
|
|
2009-09-14 23:08:19 +00:00
|
|
|
mask = (sc->sc_flags & AMDTEMP_FLAG_CT_10BIT) != 0 ? 0x3ff : 0x3fc;
|
2012-02-24 00:02:46 +00:00
|
|
|
offset = (sc->sc_flags & AMDTEMP_FLAG_ALT_OFFSET) != 0 ? 28 : 49;
|
|
|
|
temp = pci_read_config(dev, AMDTEMP_THERMTP_STAT, 4);
|
|
|
|
temp = ((temp >> 14) & mask) * 5 / 2;
|
|
|
|
temp += AMDTEMP_ZERO_C_TO_K + (sc->sc_offset - offset) * 10;
|
2009-09-11 21:47:44 +00:00
|
|
|
|
2009-03-12 18:59:39 +00:00
|
|
|
return (temp);
|
|
|
|
}
|
2009-03-13 16:28:25 +00:00
|
|
|
|
|
|
|
static int32_t
|
|
|
|
amdtemp_gettemp(device_t dev, amdsensor_t sensor)
|
|
|
|
{
|
2012-02-24 00:02:46 +00:00
|
|
|
struct amdtemp_softc *sc = device_get_softc(dev);
|
2009-03-13 16:28:25 +00:00
|
|
|
uint32_t temp;
|
|
|
|
|
2009-09-11 21:47:44 +00:00
|
|
|
temp = pci_read_config(dev, AMDTEMP_REPTMP_CTRL, 4);
|
2012-02-24 00:02:46 +00:00
|
|
|
temp = ((temp >> 21) & 0x7ff) * 5 / 4;
|
|
|
|
temp += AMDTEMP_ZERO_C_TO_K + sc->sc_offset * 10;
|
2009-03-13 16:28:25 +00:00
|
|
|
|
|
|
|
return (temp);
|
|
|
|
}
|
2017-09-05 15:19:14 +00:00
|
|
|
|
|
|
|
static int32_t
|
|
|
|
amdtemp_gettemp17h(device_t dev, amdsensor_t sensor)
|
|
|
|
{
|
|
|
|
struct amdtemp_softc *sc = device_get_softc(dev);
|
2018-11-14 04:50:29 +00:00
|
|
|
uint32_t temp, val;
|
2017-09-05 15:19:14 +00:00
|
|
|
int error;
|
|
|
|
|
2018-11-14 04:50:29 +00:00
|
|
|
error = amdsmn_read(sc->sc_smn, AMDTEMP_17H_CUR_TMP, &val);
|
2017-09-05 15:19:14 +00:00
|
|
|
KASSERT(error == 0, ("amdsmn_read"));
|
|
|
|
|
2018-11-14 04:50:29 +00:00
|
|
|
temp = ((val >> 21) & 0x7ff) * 5 / 4;
|
|
|
|
if ((val & AMDTEMP_17H_CUR_TMP_RANGE_SEL) != 0)
|
|
|
|
temp -= AMDTEMP_17H_CUR_TMP_RANGE_OFF;
|
2017-09-05 15:19:14 +00:00
|
|
|
temp += AMDTEMP_ZERO_C_TO_K + sc->sc_offset * 10;
|
|
|
|
|
|
|
|
return (temp);
|
|
|
|
}
|