From patchwork Tue Jan 23 21:10:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 125599 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp2007685ljf; Tue, 23 Jan 2018 13:11:50 -0800 (PST) X-Google-Smtp-Source: AH8x226Pj101Rmp1k8xMZAh8VDHX5tDaHFZg84nrXgw6CkqHZVVuAJ1OyoaLerZ4Gdzj7YNM9tHK X-Received: by 10.80.204.140 with SMTP id q12mr21001676edi.176.1516741910042; Tue, 23 Jan 2018 13:11:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516741910; cv=none; d=google.com; s=arc-20160816; b=BURR3sTgCTbqqU/vUwucR65jcYTSx0t0GBA1wMzfAuQTLm0qoZBDLRQEsZx2U3VoXU aKdd+cM6uXqMQXxUsH8mgZvw6fC7iKgLvs+fMPiBu5E07tmFoKn2GX5MfAAVmmAFO1KV ZPS6BRl0A0BC1t5ctIwLwuz10RgOeeNQJbogaNaSTIJFOD4djMOomMPUoSc3NUp8LySb S/dlFyuUQSiV1e8br8ir1S+XXt2b8N9bKdMCuBariVAjLd8mvJgA15vZLuTgLI7lbZBK mLq8lwzL+NZHPwTLtR/1LjUSEuNJMob2NTkffnWKtM4SzOZBIgji6XNZWgvMTwSfZ5Zi Ku7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=gBbDxyofD/l3Xi5XB2gtxjt+v1fSyjqdhWQCj+Og7F0=; b=LXGGyIVElzFQvxtlbUCVDvFlDHzpnSA3W9JzhEt1WXbvtisBhyDwO/TC8eZI42qEWC A6+y95jwtyCzZWCRkAVbgTiGqpLVZj7ZxHRBodBtkDiwzRbrd7GzIV/QgfGaBvvQ48Qz 8ZehjfjxZyWrbFEURVMN3t5cSDlhpzlp78YSoP/9tedwAvuVTqV8TBFtRhhDNnxWKiJF C0VvU5YzRmeyFYU4oBsEL7jY1fZAWbAEICH8jDr5R9k+hCPm/16PXr/795DjDNDnP15u qo/R7wH6vCwfeoiCPb/YAYq+R7mVRVM3v2/fQSEB6rVIsRO7235ihP0gRsJ8TZitE06Q +YNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=V83JMSCH; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id i1si687165edc.272.2018.01.23.13.11.49; Tue, 23 Jan 2018 13:11:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=V83JMSCH; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 92F6BC21C93; Tue, 23 Jan 2018 21:11:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D57A5C22153; Tue, 23 Jan 2018 21:11:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E5447C21DD7; Tue, 23 Jan 2018 21:10:57 +0000 (UTC) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by lists.denx.de (Postfix) with ESMTPS id 63038C21C93 for ; Tue, 23 Jan 2018 21:10:57 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id 143so4455240wma.5 for ; Tue, 23 Jan 2018 13:10:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RIE0jz9gICESbGu7eqat6IQ7Wv6u8cEXq2dTHRqU6ug=; b=V83JMSCHWdWHXOalPrizoqCKhq8q80zQHu+ZilEtm2UxB8A3t51yE9djmz0+uVBSBQ bzbNqKfFqtRKgj7yXA4jpVZEQkRCmKiW5RoUSzMviHkEcCZ63kzRo8/y40O/58kS7Xgm MZNVYGD9GfG88vqo9xHDsbv5rlRsTrr2Amj7o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RIE0jz9gICESbGu7eqat6IQ7Wv6u8cEXq2dTHRqU6ug=; b=oUg7e+AD6wsX9l5LkhnRl4SMp4GKAkt/I7RGQunDGw6bQszpFPKwpE47v7mPQkOUT/ ocmQyzqBlVmS03QTyu9iRESD7QLZpGnfVh4Lt2ubKJC2Y4sOelLtFndq0e3ZlQJONPtG HMOTlekVfeNfcX1vAMXxn5Nk7BhVwM6THFtxHghY30VnQ6EyTtf/XBOqkqUyIuu6eex7 IZNuW5TBvSbhP1YY+VdyDh5E2yOxO4m8VrUQtoE0x0DBAATSCuk5POvqCkep/mMDL4ug zr1iisMi3IsX/uWOidvEOTl2SaI58m1u7kIp8yRpk4I06nNAQheBFJsCmz1MOkQ4xbwl ZA5A== X-Gm-Message-State: AKwxyteWzcHehyPNA6X4oLjjdweHdvbrYty/UygY+5SP1wQlqsj02LYg pxO/jB7ZjNTtcJ8dBoNLDHESnzHsp/k= X-Received: by 10.80.142.25 with SMTP id 25mr5226391edw.127.1516741856868; Tue, 23 Jan 2018 13:10:56 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id x25sm13860657eda.8.2018.01.23.13.10.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Jan 2018 13:10:56 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, trini@konsulko.com Date: Tue, 23 Jan 2018 21:10:52 +0000 Message-Id: <1516741853-12458-2-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516741853-12458-1-git-send-email-bryan.odonoghue@linaro.org> References: <1516741853-12458-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Aneesh Bansal , fabio.estevam@nxp.com, Ruchika Gupta Subject: [U-Boot] [PATCH 1/2] drivers/crypto/fsl: assign job-rings to non-TrustZone X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" After enabling TrustZone various parts of the CAAM silicon become inaccessible to non TrustZone contexts. The job-ring registers are designed to allow non TrustZone contexts like Linux to still submit jobs to CAAM even after TrustZone has been enabled. The default job-ring permissions after the BootROM look like this for job-ring zero. ms=0x00008001 ls=0x00008001 The MS field is JRaMIDR_MS (job ring MID most significant). Referring to "Security Reference Manual for i.MX 7Dual and 7Solo Applications Processors, Rev. 0, 03/2017" section 8.10.4 we see that JROWN_NS controls whether or not a job-ring is accessible from non TrustZone. Bit 15 (TrustZone) is the logical inverse of bit 3 hence the above value of 0x8001 shows that JROWN_NS=0 and TrustZone=1. Clearly then as soon as TrustZone becomes active the job-ring registers are no longer accessible from Linux, which is not what we want. This patch explicitly sets all job-ring registers to JROWN_NS=1 (non TrustZone) by default. If a piece of TrustZone firmware requires ownership of job-ring registers it can unset the JROWN_NS bit itself. This patch in conjunction with a modification of the Linux kernel to skip HWRNG initialisation makes CAAM usable to Linux with TrustZone enabled. Signed-off-by: Bryan O'Donoghue Cc: Fabio Estevam Cc: Peng Fan Cc: Alex Porosanu Cc: Ruchika Gupta Cc: Aneesh Bansal Link: https://github.com/OP-TEE/optee_os/issues/1408 Link: https://tinyurl.com/yam5gv9a --- drivers/crypto/fsl/jr.c | 9 +++++++++ drivers/crypto/fsl/jr.h | 1 + 2 files changed, 10 insertions(+) diff --git a/drivers/crypto/fsl/jr.c b/drivers/crypto/fsl/jr.c index 986eabf..cbf570d 100644 --- a/drivers/crypto/fsl/jr.c +++ b/drivers/crypto/fsl/jr.c @@ -566,6 +566,8 @@ int sec_init_idx(uint8_t sec_idx) { ccsr_sec_t *sec = (void *)SEC_ADDR(sec_idx); uint32_t mcr = sec_in32(&sec->mcfgr); + uint32_t jrown_ns; + int i; int ret = 0; #ifdef CONFIG_FSL_CORENET @@ -621,6 +623,13 @@ int sec_init_idx(uint8_t sec_idx) #endif #endif + /* Set ownership of job rings to non-TrustZone mode by default */ + for (i = 0; i < ARRAY_SIZE(sec->jrliodnr); i++) { + jrown_ns = sec_in32(&sec->jrliodnr[i].ms); + jrown_ns |= JROWN_NS; + sec_out32(&sec->jrliodnr[i].ms, jrown_ns); + } + ret = jr_init(sec_idx); if (ret < 0) { printf("SEC initialization failed\n"); diff --git a/drivers/crypto/fsl/jr.h b/drivers/crypto/fsl/jr.h index d897e57..72f7501 100644 --- a/drivers/crypto/fsl/jr.h +++ b/drivers/crypto/fsl/jr.h @@ -34,6 +34,7 @@ #define JRNSLIODN_MASK 0x0fff0000 #define JRSLIODN_SHIFT 0 #define JRSLIODN_MASK 0x00000fff +#define JROWN_NS 0x00000008 #define JQ_DEQ_ERR -1 #define JQ_DEQ_TO_ERR -2