From owner-svn-src-head@freebsd.org Sun Jan 7 03:31:56 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D85D3E6213C; Sun, 7 Jan 2018 03:31:56 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B3FC3722D7; Sun, 7 Jan 2018 03:31:56 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0B0CC1BCD4; Sun, 7 Jan 2018 03:31:56 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w073VtWL019149; Sun, 7 Jan 2018 03:31:55 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w073Vttb019148; Sun, 7 Jan 2018 03:31:55 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201801070331.w073Vttb019148@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sun, 7 Jan 2018 03:31:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r327669 - head/sys/arm/allwinner X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/sys/arm/allwinner X-SVN-Commit-Revision: 327669 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jan 2018 03:31:57 -0000 Author: kevans Date: Sun Jan 7 03:31:55 2018 New Revision: 327669 URL: https://svnweb.freebsd.org/changeset/base/327669 Log: 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. Modified: head/sys/arm/allwinner/aw_sid.c Modified: head/sys/arm/allwinner/aw_sid.c ============================================================================== --- head/sys/arm/allwinner/aw_sid.c Sun Jan 7 02:59:27 2018 (r327668) +++ head/sys/arm/allwinner/aw_sid.c Sun Jan 7 03:31:55 2018 (r327669) @@ -39,6 +39,8 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include #include #include #include @@ -48,6 +50,16 @@ __FBSDID("$FreeBSD$"); #include +/* 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,8 +121,37 @@ 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) { if (!ofw_bus_status_okay(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)),