1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-11 09:50:12 +00:00

amdtemp: Remove CTLFLAG_NEEDGIANT from sysctls.

It seems to be needed only to serialize very old K8 registers access.
Introduce separate lock for that and remove Giant dependency.

MFC after:	2 weeks
This commit is contained in:
Alexander Motin 2021-12-25 21:03:54 -05:00
parent 9a6201ac2f
commit 6c101ed7a3

View File

@ -41,7 +41,9 @@ __FBSDID("$FreeBSD$");
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
@ -86,6 +88,7 @@ struct amdtemp_softc {
struct sysctl_oid *sc_sysctl_cpu[MAXCPU];
struct intr_config_hook sc_ich;
device_t sc_smn;
struct mtx sc_lock;
};
/*
@ -479,6 +482,7 @@ amdtemp_attach(device_t dev)
if (sc->sc_ncores > MAXCPU)
return (ENXIO);
mtx_init(&sc->sc_lock, "amdtemp", NULL, MTX_DEF);
if (erratum319)
device_printf(dev,
"Erratum 319: temperature measurement may be inaccurate\n");
@ -506,7 +510,7 @@ amdtemp_attach(device_t dev)
SYSCTL_ADD_PROC(sysctlctx,
SYSCTL_CHILDREN(sysctlnode),
OID_AUTO, "sensor0",
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_NEEDGIANT,
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
dev, CORE0_SENSOR0, amdtemp_sysctl, "IK",
"Core 0 / Sensor 0 temperature");
@ -518,7 +522,7 @@ amdtemp_attach(device_t dev)
SYSCTL_ADD_PROC(sysctlctx,
SYSCTL_CHILDREN(sysctlnode),
OID_AUTO, "sensor1",
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_NEEDGIANT,
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
dev, CORE0_SENSOR1, amdtemp_sysctl, "IK",
"Core 0 / Sensor 1 temperature");
@ -531,14 +535,14 @@ amdtemp_attach(device_t dev)
SYSCTL_ADD_PROC(sysctlctx,
SYSCTL_CHILDREN(sysctlnode),
OID_AUTO, "sensor0",
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_NEEDGIANT,
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
dev, CORE1_SENSOR0, amdtemp_sysctl, "IK",
"Core 1 / Sensor 0 temperature");
SYSCTL_ADD_PROC(sysctlctx,
SYSCTL_CHILDREN(sysctlnode),
OID_AUTO, "sensor1",
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_NEEDGIANT,
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
dev, CORE1_SENSOR1, amdtemp_sysctl, "IK",
"Core 1 / Sensor 1 temperature");
}
@ -591,7 +595,7 @@ amdtemp_intrhook(void *arg)
sc->sc_sysctl_cpu[i] = SYSCTL_ADD_PROC(sysctlctx,
SYSCTL_CHILDREN(device_get_sysctl_tree(cpu)),
OID_AUTO, "temperature",
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_NEEDGIANT,
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
dev, sensor, amdtemp_sysctl, "IK",
"Current temparature");
}
@ -612,6 +616,7 @@ amdtemp_detach(device_t dev)
/* NewBus removes the dev.amdtemp.N tree by itself. */
mtx_destroy(&sc->sc_lock);
return (0);
}
@ -652,6 +657,8 @@ amdtemp_gettemp0f(device_t dev, amdsensor_t sensor)
struct amdtemp_softc *sc = device_get_softc(dev);
uint32_t mask, offset, temp;
mtx_lock(&sc->sc_lock);
/* Set Sensor/Core selector. */
temp = pci_read_config(dev, AMDTEMP_THERMTP_STAT, 1);
temp &= ~(AMDTEMP_TTSR_SELCORE | AMDTEMP_TTSR_SELSENSOR);
@ -683,6 +690,7 @@ amdtemp_gettemp0f(device_t dev, amdsensor_t sensor)
temp = ((temp >> 14) & mask) * 5 / 2;
temp += AMDTEMP_ZERO_C_TO_K + (sc->sc_offset - offset) * 10;
mtx_unlock(&sc->sc_lock);
return (temp);
}