aw_sid: Add method for reading keys via prctl registers

Technically supported on the later SoCs, this will only really be used to
add support for the H3 sid. The H3 has a silicon bug that manifests itself
by returning garbled rootkeys unless first read via the prctl registers.
This commit is contained in:
Kyle Evans 2018-01-07 03:31:55 +00:00
parent 5dce212d67
commit 86c6868161
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=327669

View File

@ -39,6 +39,8 @@ __FBSDID("$FreeBSD$");
#include <sys/bus.h>
#include <sys/rman.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/module.h>
#include <sys/sysctl.h>
#include <machine/bus.h>
@ -48,6 +50,16 @@ __FBSDID("$FreeBSD$");
#include <arm/allwinner/aw_sid.h>
/* efuse registers */
#define SID_PRCTL 0x40
#define SID_PRCTL_OFFSET_MASK 0xff
#define SID_PRCTL_OFFSET(n) (((n) & SID_PRCTL_OFFSET_MASK) << 16)
#define SID_PRCTL_LOCK (0xac << 8)
#define SID_PRCTL_READ (0x01 << 1)
#define SID_PRCTL_WRITE (0x01 << 0)
#define SID_PRKEY 0x50
#define SID_RDKEY 0x60
#define SID_SRAM 0x200
#define SID_THERMAL_CALIB0 (SID_SRAM + 0x34)
#define SID_THERMAL_CALIB1 (SID_SRAM + 0x38)
@ -56,6 +68,7 @@ __FBSDID("$FreeBSD$");
struct aw_sid_conf {
bus_size_t rootkey_offset;
bool has_prctl;
bool has_thermal;
};
@ -69,11 +82,13 @@ static const struct aw_sid_conf a20_conf = {
static const struct aw_sid_conf a64_conf = {
.rootkey_offset = SID_SRAM,
.has_prctl = true,
.has_thermal = true,
};
static const struct aw_sid_conf a83t_conf = {
.rootkey_offset = SID_SRAM,
.has_prctl = true,
.has_thermal = true,
};
@ -88,6 +103,7 @@ static struct ofw_compat_data compat_data[] = {
struct aw_sid_softc {
struct resource *res;
struct aw_sid_conf *sid_conf;
struct mtx prctl_mtx;
};
static struct aw_sid_softc *aw_sid_sc;
@ -105,6 +121,35 @@ enum sid_keys {
#define WR4(sc, reg, val) bus_write_4((sc)->res, (reg), (val))
static int aw_sid_sysctl(SYSCTL_HANDLER_ARGS);
static int aw_sid_prctl_read(device_t dev, bus_size_t offset, uint32_t *val);
/*
* offset here is offset into efuse space, rather than offset into sid register
* space. This form of read is only an option for newer SoC: A83t, H3, A64
*/
static int
aw_sid_prctl_read(device_t dev, bus_size_t offset, uint32_t *val)
{
struct aw_sid_softc *sc;
uint32_t readval;
sc = device_get_softc(dev);
if (!sc->sid_conf->has_prctl)
return (1);
mtx_lock(&sc->prctl_mtx);
readval = SID_PRCTL_OFFSET(offset) | SID_PRCTL_LOCK | SID_PRCTL_READ;
WR4(sc, SID_PRCTL, readval);
/* Read bit will be cleared once read has concluded */
while (RD4(sc, SID_PRCTL) & SID_PRCTL_READ)
continue;
readval = RD4(sc, SID_RDKEY);
mtx_unlock(&sc->prctl_mtx);
*val = readval;
return (0);
}
static int
aw_sid_probe(device_t dev)
@ -131,8 +176,9 @@ aw_sid_attach(device_t dev)
return (ENXIO);
}
aw_sid_sc = sc;
mtx_init(&sc->prctl_mtx, device_get_nameunit(dev), NULL, MTX_DEF);
sc->sid_conf = (struct aw_sid_conf *)ofw_bus_search_compatible(dev, compat_data)->ocd_data;
aw_sid_sc = sc;
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),