From patchwork Tue Nov 13 16:08:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne CARRIERE X-Patchwork-Id: 1740751 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id D05B6DF264 for ; Wed, 14 Nov 2012 11:42:58 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TYbJq-0000YT-4k; Wed, 14 Nov 2012 11:39:47 +0000 Received: from eu1sys200aog118.obsmtp.com ([207.126.144.145]) by merlin.infradead.org with smtps (Exim 4.76 #1 (Red Hat Linux)) id 1TYJ2K-0005zM-VQ for linux-arm-kernel@lists.infradead.org; Tue, 13 Nov 2012 16:08:30 +0000 Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob118.postini.com ([207.126.147.11]) with SMTP ID DSNKUKJwdeDMuNrVZP+ySy6pbr2e/rwe3cA1@postini.com; Tue, 13 Nov 2012 16:08:28 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 6CC2D1BB; Tue, 13 Nov 2012 16:08:20 +0000 (GMT) Received: from Webmail-eu.st.com (safex1hubcas4.st.com [10.75.90.69]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0471D4CE5; Tue, 13 Nov 2012 16:08:20 +0000 (GMT) Received: from SAFEX1MAIL3.st.com ([10.75.90.7]) by Safex1hubcas4.st.com ([10.75.90.69]) with mapi; Tue, 13 Nov 2012 17:08:20 +0100 From: Etienne CARRIERE To: "linux-arm-kernel@lists.infradead.org" , Will Deacon , Russell King , Marc Zyngier , Catalin Marinas Date: Tue, 13 Nov 2012 17:08:16 +0100 Subject: [PATCH 2/2] mach-ux500: L2CC shared mutex with ARM TZ Thread-Topic: [PATCH 2/2] mach-ux500: L2CC shared mutex with ARM TZ Thread-Index: Ac3BtkhYuu+u0/HoTIWKOOqxMHm4Jw== Message-ID: <0154077FE026E54BB093CA7EB3FD1AE32B57AF1B5A@SAFEX1MAIL3.st.com> Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: fr-FR, en-US MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121113_110829_566571_0185BD0B X-CRM114-Status: GOOD ( 22.05 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [207.126.144.145 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 HTML_MESSAGE BODY: HTML included in message X-Mailman-Approved-At: Wed, 14 Nov 2012 06:26:44 -0500 Cc: Etienne CARRIERE , "Linus Walleij \(linus.walleij@linaro.org\)" , Rabin VINCENT , Srinidhi KASAGAR X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Etienne Carriere L2 cache mutex is allocated in DDR from TZ/TEE. Linux retrieves its physical address using from TEE API. It maps it to the kernel address space. Mutex needs to be cacheable, as configured in TZ MMU mapping Once configured from TEE, enable its use by l2cc driver. This patch assumes no L2 cache maintenance is request to TEE inside the time frame from linux early boot to this "late_initcall of "romcode-sm" probing. The SW architecture insures that. This patch is an example of how ux500 plans to load the TZ shared mutex into outer cache driver. This patch cannot hit kernel main track. It targets internal kernel Trees with enabled TEE driver (API to TZ world). Signed-off-by: carriere etienne --- arch/arm/mach-ux500/romcode-shared_mutex.c | 111 +++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) -- 1.7.11.3 diff --git a/arch/arm/mach-ux500/romcode-shared_mutex.c b/arch/arm/mach-ux500/romcode-shared_mutex.c new file mode 100644 index 0000000..a09df72 --- /dev/null +++ b/arch/arm/mach-ux500/romcode-shared_mutex.c @@ -0,0 +1,111 @@ +/* + * Copyright (C) ST-Ericsson SA 2012 + * License terms: GNU General Public License (GPL), version 2 + * Author: Etienne Carriere for ST-Ericsson. + * + * ROM code Mutex Configuration for A9 exclusive load and store operation + * for l2 cache maintenance. + */ + +#include +#include +#include +#include +#include + +#include +#include + +#define BASS_ROMCODE_SHARED_MUTEX 0 + +#define UUID_TEE_TA_START_LOW 0xBC765EDE +#define UUID_TEE_TA_START_MID 0x6724 +#define UUID_TEE_TA_START_HIGH 0x11DF +#define UUID_TEE_TA_START_CLOCKSEQ \ + {0x8E, 0x12, 0xEC, 0xDB, 0xDF, 0xD7, 0x20, 0x85} + +static int __devinit shared_mutex_config_probe(struct platform_device *pdev) +{ + struct tee_operation op; + struct tee_session sess; + struct tee_context ctx; + uint32_t mutex_type = BASS_ROMCODE_SHARED_MUTEX; + unsigned int paddr; + void __iomem *vaddr; + int err, ori; + + /* Selects trustzone application needed for the job. */ + struct tee_uuid static_uuid = { + UUID_TEE_TA_START_LOW, + UUID_TEE_TA_START_MID, + UUID_TEE_TA_START_HIGH, + UUID_TEE_TA_START_CLOCKSEQ, + }; + + err = teec_initialize_context(NULL, &ctx); + if (err) { + pr_err("%s: context init failed, 0x%X\n", __func__, err); + err = -EINVAL; + goto out; + } + + err = teec_open_session(&ctx, &sess, &static_uuid, + TEEC_LOGIN_PUBLIC, NULL, NULL, &ori); + if (err) { + pr_err("%s: session failed, 0x%X/0x%X\n", __func__, err, ori); + err = -EINVAL; + goto out1; + } + + memset(&op, 0, sizeof(op)); + op.param[0].tmpref.buffer = (void *)&paddr; + op.param[0].tmpref.size = sizeof(uint32_t *); + op.param[1].tmpref.buffer = (void *)&mutex_type; + op.param[1].tmpref.size = sizeof(uint32_t); + op.types = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, + TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, TEEC_NONE); + + err = teec_invoke_command(&sess, TEE_STA_CONF_SHARED_MUTEX, &op, &ori); + if (err) { + pr_err("%s: init failed, 0x%X/0x%X", __func__, err, ori); + err = -EINVAL; + goto out2; + } + + vaddr = ioremap_cached((unsigned long)paddr, SZ_1K); + if (vaddr == NULL) { + pr_err("%s: mutex map failed, 0x%X\n", __func__, paddr); + err = -EIO; + goto out2; + } + + if (!outer_tz_mutex((unsigned long)vaddr)) { + pr_err("%s: load mutex 0x%08X failed\n", __func__, (uint)vaddr); + err = -EIO; + } +out2: + (void)teec_close_session(&sess); +out1: + (void)teec_finalize_context(&ctx); +out: + return err; +} + +static struct platform_driver romcode_sm_driver = { + .driver = { + .name = "romcode-sm", + .owner = THIS_MODULE, + }, + .probe = shared_mutex_config_probe, +}; + +static int __init shared_mutex_config_init(void) +{ + return platform_driver_register(&romcode_sm_driver); +} + +/* Wait for TEE driver to be initialized. */ +late_initcall(shared_mutex_config_init); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("TZ shared mutex config");