Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp14479231ybl; Mon, 30 Dec 2019 10:51:49 -0800 (PST) X-Google-Smtp-Source: APXvYqzfrvkA2g92Cg+nskPFoA46T6avJ7tz/XDme4j9plaHB1lW1UTY3PxRf5ezxMIPq6fBZ1KM X-Received: by 2002:a9d:6251:: with SMTP id i17mr3020143otk.14.1577731909497; Mon, 30 Dec 2019 10:51:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577731909; cv=none; d=google.com; s=arc-20160816; b=tJ2cT3C0iFtUhNtFKZJwV5+F/99ufOw1Nxpe2hNyo6339o8gUPW6j29C39oDQRno9f KTVLlx45erfvEITNRKt+WT+fVKOkf0l2hwwxfJBCPBSjpcJyE946SCbS89tqhSq33ECU BtNb4AQ+arno0ALoA4yvM2y+wayQ70jlOe0V4B4I5+X0WrK5sSCwXjd0qyDGMlEUzlbO F7Qhlw3PtJGP6E/TsOggmSkhI6FwPiDzK4hHlhzynKla0I4gvxWzEnw5unXacSu+9lfX W3wM6kSJ/7vfPT/Z+luZ5hlxij0UEAo4KrEcgvOxEDRZkKf0qwqigFgB4SLG+fXM5eVD FLrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oq06FeNTSrVdnZTZ0YySVTawPG99vf9FqZbFKv4Mw80=; b=ksEj8GvZs0oJlESSGWKt2p5HF4WXoEaoGbpHgRUY3Q6B5aSO1zeMLt2KC6t5hbkoBw ECC4Go7LihXo+KXTNWD6JdtazIdF4vc57qtlaoIK3UwQ0pexXnLMXojuLhonFpo6+B0+ RVORMfC8OqrYu0xki0QYCu41zrZVmQiX43MnyXRIpgYSP5mY4QLqyD1WZTjx0+wx+tW2 mGVhl4IcSW21NBzMZMH3/BS8PWAG7om+EAoB83VByga9d6pH5ii+np+bBsTnhMlG578E pYYVv4e22CQmlDbRxWlnWVc2SMYdO/d1bUdZ5qSZigiRjbZtLG6jgaSCSDImNoJ2+D4U HPuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=h9SkhOD6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8si21177516oih.141.2019.12.30.10.51.37; Mon, 30 Dec 2019 10:51:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=h9SkhOD6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727680AbfL3Sup (ORCPT + 99 others); Mon, 30 Dec 2019 13:50:45 -0500 Received: from lelv0142.ext.ti.com ([198.47.23.249]:44330 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727278AbfL3Suo (ORCPT ); Mon, 30 Dec 2019 13:50:44 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id xBUIogDP033123; Mon, 30 Dec 2019 12:50:42 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1577731842; bh=oq06FeNTSrVdnZTZ0YySVTawPG99vf9FqZbFKv4Mw80=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=h9SkhOD6XwQ1f5O6Vv2JTYW0vIhhWhTiu944vPTogW44wholL1bvRjc1PuURidvbi O2EzkUmm/vVzgvqEtjwVMlqZQr+QBwL8vJnWPksqr6a/RgtlpUD/e1n1eickymo8k7 RX7K9ea+AeqQDq3HoOzENyb05MRjf7r1bzpsUmBI= Received: from DFLE109.ent.ti.com (dfle109.ent.ti.com [10.64.6.30]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id xBUIogml048226 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 30 Dec 2019 12:50:42 -0600 Received: from DFLE110.ent.ti.com (10.64.6.31) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Mon, 30 Dec 2019 12:50:42 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE110.ent.ti.com (10.64.6.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Mon, 30 Dec 2019 12:50:42 -0600 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id xBUIofMv044153; Mon, 30 Dec 2019 12:50:41 -0600 Received: from localhost ([10.250.65.50]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id xBUIofu06990; Mon, 30 Dec 2019 12:50:41 -0600 (CST) From: "Andrew F. Davis" To: Tony Lindgren CC: , , "Andrew F . Davis" Subject: [PATCH v3 3/4] ARM: OMAP2+: Use ARM SMC Calling Convention when OP-TEE is available Date: Mon, 30 Dec 2019 13:50:03 -0500 Message-ID: <20191230185004.32279-4-afd@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230185004.32279-1-afd@ti.com> References: <20191230185004.32279-1-afd@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On High-Security(HS) OMAP2+ class devices a couple actions must be performed from the ARM TrustZone during boot. These traditionally can be performed by calling into the secure ROM code resident in this secure world using legacy SMC calls. Optionally OP-TEE can replace this secure world functionality by replacing the ROM after boot. ARM recommends a standard calling convention is used for this interaction (SMC Calling Convention). We check for the presence of OP-TEE and use this type of call to perform the needed actions, falling back to the legacy OMAP ROM call if OP-TEE is not available. Signed-off-by: Andrew F. Davis --- arch/arm/mach-omap2/common.h | 2 +- arch/arm/mach-omap2/omap-secure.c | 27 +++++++++++++++++++++++++++ arch/arm/mach-omap2/omap-secure.h | 2 ++ arch/arm/mach-omap2/omap-smc.S | 6 +++--- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/arch/arm/mach-omap2/common.h b/arch/arm/mach-omap2/common.h index 223b37c48389..3b1fd8e7d705 100644 --- a/arch/arm/mach-omap2/common.h +++ b/arch/arm/mach-omap2/common.h @@ -255,7 +255,7 @@ extern void gic_dist_disable(void); extern void gic_dist_enable(void); extern bool gic_dist_disabled(void); extern void gic_timer_retrigger(void); -extern void omap_smc1(u32 fn, u32 arg); +extern void _omap_smc1(u32 fn, u32 arg); extern void omap4_sar_ram_init(void); extern void __iomem *omap4_get_sar_ram_base(void); extern void omap4_mpuss_early_init(void); diff --git a/arch/arm/mach-omap2/omap-secure.c b/arch/arm/mach-omap2/omap-secure.c index 39d8070aede6..3a09d860c7a9 100644 --- a/arch/arm/mach-omap2/omap-secure.c +++ b/arch/arm/mach-omap2/omap-secure.c @@ -8,6 +8,7 @@ * Copyright (C) 2013 Pali Rohár */ +#include #include #include #include @@ -17,12 +18,17 @@ #include #include +#include "common.h" #include "omap-secure.h" static phys_addr_t omap_secure_memblock_base; bool optee_available; +#define OMAP_SIP_SMC_STD_CALL_VAL(func_num) \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_SIP, (func_num)) + static void __init omap_optee_init_check(void) { struct device_node *np; @@ -66,6 +72,27 @@ u32 omap_secure_dispatcher(u32 idx, u32 flag, u32 nargs, u32 arg1, u32 arg2, return ret; } +void omap_smccc_smc(u32 fn, u32 arg) +{ + struct arm_smccc_res res; + + arm_smccc_smc(OMAP_SIP_SMC_STD_CALL_VAL(fn), arg, + 0, 0, 0, 0, 0, 0, &res); + WARN(res.a0, "Secure function call 0x%08x failed\n", fn); +} + +void omap_smc1(u32 fn, u32 arg) +{ + /* + * If this platform has OP-TEE installed we use ARM SMC calls + * otherwise fall back to the OMAP ROM style calls. + */ + if (optee_available) + omap_smccc_smc(fn, arg); + else + _omap_smc1(fn, arg); +} + /* Allocate the memory to save secure ram */ int __init omap_secure_ram_reserve_memblock(void) { diff --git a/arch/arm/mach-omap2/omap-secure.h b/arch/arm/mach-omap2/omap-secure.h index 78a1c4f04bbe..736e594365f4 100644 --- a/arch/arm/mach-omap2/omap-secure.h +++ b/arch/arm/mach-omap2/omap-secure.h @@ -62,6 +62,8 @@ extern u32 omap_secure_dispatcher(u32 idx, u32 flag, u32 nargs, u32 arg1, u32 arg2, u32 arg3, u32 arg4); +extern void omap_smccc_smc(u32 fn, u32 arg); +extern void omap_smc1(u32 fn, u32 arg); extern u32 omap_smc2(u32 id, u32 falg, u32 pargs); extern u32 omap_smc3(u32 id, u32 process, u32 flag, u32 pargs); extern phys_addr_t omap_secure_ram_mempool_base(void); diff --git a/arch/arm/mach-omap2/omap-smc.S b/arch/arm/mach-omap2/omap-smc.S index fd2bcd91f4a1..d4832845a4e8 100644 --- a/arch/arm/mach-omap2/omap-smc.S +++ b/arch/arm/mach-omap2/omap-smc.S @@ -18,18 +18,18 @@ * the monitor API number. It uses few CPU registers * internally and hence they need be backed up including * link register "lr". - * Function signature : void omap_smc1(u32 fn, u32 arg) + * Function signature : void _omap_smc1(u32 fn, u32 arg) */ .arch armv7-a .arch_extension sec -ENTRY(omap_smc1) +ENTRY(_omap_smc1) stmfd sp!, {r2-r12, lr} mov r12, r0 mov r0, r1 dsb smc #0 ldmfd sp!, {r2-r12, pc} -ENDPROC(omap_smc1) +ENDPROC(_omap_smc1) /** * u32 omap_smc2(u32 id, u32 falg, u32 pargs) -- 2.17.1