From patchwork Fri Jan 27 11:40:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13118611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 00A69C54EAA for ; Fri, 27 Jan 2023 12:23:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=i8wLQA6QZztKwAj7OOLy5xN815qVP8zY36sHMDa+jO4=; b=3Zm9pZ60kG7N1Q wLpMzc1kZs2oXj4FrdNzvnTvOaLHEX4lQtsyvRcxfvapOjGA8Sbntzsdfr7yuFE5fHVdM2gcCGVQA CgHNL1GPJmdP0Va+sAPOqFNTtj1BAmYWx5MnWhgx1IqjFlHTINaKYa8OUpfB6j8+3yMts2WeHkNLa Y9f6akFgonuDLGbvdQMlTBzmx6bIbM73VrHjuqt631fUV7u6n+Zm8Bu4aH/5MQA9oysn5CscTyvRO rMZbX3mBa0pMkE+yEoE/Wnp/NHc6BUQqN2YWtYQ7lHzWi6tLDuTIYtyJ1fjPpPhzfKsufYfI3b4r/ NcZ/GlbdZp45R7rzrNzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLNjz-00EW8E-RJ; Fri, 27 Jan 2023 12:22:00 +0000 Received: from mail-am0eur02on2074.outbound.protection.outlook.com ([40.107.247.74] helo=EUR02-AM0-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLN7j-00EDzZ-OS for linux-arm-kernel@lists.infradead.org; Fri, 27 Jan 2023 11:42:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m3PXBb4SSqTJtAHYbgMwbsFsilPhoJvLJat1+V5pGRk=; b=teCllaDYprHB57RNGMDs+MbVsedMgn2+Yw86C637bEdiObkB8PsfAWv+Y+XxPOLH4msvA/gJwPUq702toOWO1xcIZHPnX9Ep2ySWBmFkoYHHikDbtkO0/YgX+9ofJQmHikee+DPXXkc5JdrxMfzk4bxDsYUMbuR6KPzBJaU1dms= Received: from AM6PR08CA0043.eurprd08.prod.outlook.com (2603:10a6:20b:c0::31) by AS8PR08MB6456.eurprd08.prod.outlook.com (2603:10a6:20b:336::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.23; Fri, 27 Jan 2023 11:42:13 +0000 Received: from AM7EUR03FT053.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:c0:cafe::88) by AM6PR08CA0043.outlook.office365.com (2603:10a6:20b:c0::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.23 via Frontend Transport; Fri, 27 Jan 2023 11:42:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT053.mail.protection.outlook.com (100.127.140.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.22 via Frontend Transport; Fri, 27 Jan 2023 11:42:13 +0000 Received: ("Tessian outbound 0d7b2ab0f13d:v132"); Fri, 27 Jan 2023 11:42:13 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: f10d6ff2762418f7 X-CR-MTA-TID: 64aa7808 Received: from 4942fa1c6f02.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 92B6480C-80AA-44BC-AC6F-3CA257DF5AB0.1; Fri, 27 Jan 2023 11:42:05 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 4942fa1c6f02.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 27 Jan 2023 11:42:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SwOjveYkIk9iEBPUHRkXVu+3flM8sABzyumrJwn/UEhm2fy4ZgCY73hZMdbaGXA3vukJc112WnmJE/xb6iauiOgAdfDlE0J02SVSEc8jhJZtm+trwsBVIL6FWSXAojCnxaBbqoom2ZyeBc3TI3Ww1rd2ipknyBVRt2QifTNDKGAf1f1RU0A1y7jB87swNw1aiSpwKbYbciGXOKLErKahBGUkgVnt/kVmegW0zY3hJ+hwLfpJdbbHNnXQIXaeCIhi/vPEqS0vLoL/JafN920WoG6Qwl+XVWaDWiBmRWHUpNU3NxGAf9KfgNycr0w+9gQKvAND32W5g4rbsoPiE8rSfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=m3PXBb4SSqTJtAHYbgMwbsFsilPhoJvLJat1+V5pGRk=; b=WoTXprq/EWjq4tC+imzQgrFrp01cxfjYqESgLllb8yeOE3Tr1Tc1Qc2k/l/dUtvWeBS9A/x/ZreI88uGJKQ3z2Upml/voSOmjgGQdLByUFQ8WGjewqUOq5h8YvW7cKU6x216JqE1USezmvnUjsyV07red16I60MAZi+nyJ2ZjHdoJUvAu1hCAmZ//M0ts9lFuXsOIlfSmLpiwZxtqDQ94HeiJCdAjQLYfppxZQIuWH0pudLwU5zg//nTKBXC8l3j4xkBRnen1HjtOvVX8JCJWbzTKsG5SOKOYvqh6zcCu9u1DsN6zmWOtuvPlplb5MmOL3hMMYvBjNsuG2WkXsoqrw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=linux.dev smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m3PXBb4SSqTJtAHYbgMwbsFsilPhoJvLJat1+V5pGRk=; b=teCllaDYprHB57RNGMDs+MbVsedMgn2+Yw86C637bEdiObkB8PsfAWv+Y+XxPOLH4msvA/gJwPUq702toOWO1xcIZHPnX9Ep2ySWBmFkoYHHikDbtkO0/YgX+9ofJQmHikee+DPXXkc5JdrxMfzk4bxDsYUMbuR6KPzBJaU1dms= Received: from AM5PR04CA0010.eurprd04.prod.outlook.com (2603:10a6:206:1::23) by VE1PR08MB5583.eurprd08.prod.outlook.com (2603:10a6:800:1ac::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Fri, 27 Jan 2023 11:42:03 +0000 Received: from AM7EUR03FT005.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:1:cafe::45) by AM5PR04CA0010.outlook.office365.com (2603:10a6:206:1::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.23 via Frontend Transport; Fri, 27 Jan 2023 11:42:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by AM7EUR03FT005.mail.protection.outlook.com (100.127.140.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6043.25 via Frontend Transport; Fri, 27 Jan 2023 11:42:02 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Fri, 27 Jan 2023 11:42:01 +0000 Received: from e124191.cambridge.arm.com (10.1.197.45) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Fri, 27 Jan 2023 11:41:55 +0000 From: Joey Gouly To: Andrew Jones , , CC: , Alexandru Elisei , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Suzuki K Poulose , "Thomas Huth" , Will Deacon , Zenghui Yu , , , , Subject: [RFC kvm-unit-tests 08/27] arm: realm: Realm initialisation Date: Fri, 27 Jan 2023 11:40:49 +0000 Message-ID: <20230127114108.10025-9-joey.gouly@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230127114108.10025-1-joey.gouly@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127114108.10025-1-joey.gouly@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AM7EUR03FT005:EE_|VE1PR08MB5583:EE_|AM7EUR03FT053:EE_|AS8PR08MB6456:EE_ X-MS-Office365-Filtering-Correlation-Id: d7160db4-6661-492e-3250-08db005b8876 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: l1n7+XZjSyqfW/XOP8i0HXiuC0odLH+5j+ZTSyT9gGkaRekbTisuAFI2rf+E9S3uoxHXu39O2eDwNo/s9tyKbU3QlifTtTLRkOOUmGdDFG/SU/I/4sbm97AbqXWavs1s8WqOWEvo8FNEEM0FeYk7f5QjYjgjprHnS+WPIIhwfRaFx08Sxw16xGBSk3fowbrAF559a6tqdnsLVHkpXY9ylLFzm/XUc/7l5Xe1+gw8HFwK3t0hXpFnPokRwRKYZ6zaOkYH+Ip/BulhaizmSR6qDVJ+l4RVT08QsjR2DRS62T1eQ3KokqmYtQZ5hYOlDnXQIQ0/p02Zh4L5yrR+t0UtyUGvjHgWiGKyeKgOR+E95dmlxWLGeHIJvBIkIdGEVhGoGVW3L2koi/Cgb3FNgFLU8nGRVV6gFU5SE6n7M7zGxyytYYDEUvAdMzas/yezCLpXRaXoFLtj5HAl/ag1qKGr2oBg8zFSZuS470yPT320w1dyFZ71T9uGErO4dn2xHlkvZh6GzL1jTnPgSpriQ4wNRPrflbuFj/nWbJ8PFVWpZtF3suCj70j7OIcKKUlQhhNslcXd+07oBNQh7LvdbzAX+2f8wqWiG/ZODejxg9hz4UPHIVj1RaW6mafvBe206lnAAR8RPPmfv47gnCvtMn2XIzUgVcabcaV3v5jDPRXbVVw3rUcvXkxSLeR2iN6DcFUpUsdpI82wUYCCj+298bv5OyQ0wyWbmeNmCe93ySfTXkR7fVOMQ0ahsG1b2lO2eRWG X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(346002)(376002)(136003)(396003)(39860400002)(451199018)(36840700001)(46966006)(40470700004)(81166007)(8676002)(36756003)(86362001)(82740400003)(40480700001)(44832011)(2906002)(426003)(4326008)(1076003)(6666004)(7416002)(40460700003)(83380400001)(186003)(41300700001)(26005)(8936002)(5660300002)(478600001)(336012)(70586007)(54906003)(316002)(82310400005)(70206006)(356005)(47076005)(36860700001)(2616005)(110136005)(7696005)(36900700001)(2101003);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5583 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT053.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 246d5100-1af4-47aa-93e9-08db005b8239 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: h/KGx8mmr707bpfnrfnyoGmvCI3D3GEU9Pj8mrOkbfKdvHY9i/VQsMOurESzVWG53OSFjPZRWhxwakQzsZbMQBa8FnKpclJmyrBHyJ8JE87+O6fW+TidBy/zvaAPR6UQVCf7T0FaRWq7XAaobqXRD7iQajIIA2/RqDw5Pn3eLEhlzQW+nNe+LJcNKo21VX1oybM+vGZpHEHbv4Ng/tB5BMW7WifC1bRpjcJB74TOsPnw8xChhfO35ai+KXyVmJ59+z28uSG0JPjf9zlWSCArWJkmN5BU11aanZCd+DnpOjFbP2ymkOGnCL2kIj7pqbQ8vsDOU2mSJN/Hl2bcR5XQpJPi2+PNocQ4VHj+SHzjnI2HPtUWbLvjvI1uhcNwsyeiNIg0vgRBHAuDUx852aGxlNbin9LxnnWIBzgK/jH5Nifn0WqZmSCk6z6AzNDfThDv/oRx9VfTyaQu96Uv6T2HcY/V04rjJ3a4i1pK0NpcnfA5PbL41GBCBeQsYjnd0J2bcU+owrb6q+Y/fwxgrw4WHadrWMqNLLZLa3CyeePga3q4jBDnUlbg800ud5o3nRE+0kcScWKOhSezcFJw21O0XxC0V4/oagtkeTN2q4FUQmz7IlSwQnOlZYHk7R1LMI+nM7hTyl8dNaPPkvA1fA/BEZTVPtvKo4VHrCboBxl+5ZAes9fsn5oe/9zVI+kffJDGCiOjyJAG3Cw+QNcvFQmowQ6hnsIoqXz2Hg+7a006fPw= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230025)(4636009)(136003)(376002)(39860400002)(396003)(346002)(451199018)(46966006)(40470700004)(36840700001)(41300700001)(8936002)(5660300002)(336012)(36860700001)(426003)(47076005)(40460700003)(83380400001)(40480700001)(82740400003)(316002)(110136005)(36756003)(86362001)(54906003)(82310400005)(7696005)(70586007)(70206006)(8676002)(186003)(4326008)(26005)(2616005)(1076003)(478600001)(81166007)(6666004)(107886003)(2906002)(44832011)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2023 11:42:13.3591 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d7160db4-6661-492e-3250-08db005b8876 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM7EUR03FT053.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6456 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230127_034228_018284_F0730646 X-CRM114-Status: GOOD ( 16.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org During the boot, run a check for the presence of RMM. If we are Realm, detect the Realm configuration using RSI and initialise the key parameters. Also expose a helper to indicate if this is running inside a Realm Co-developed-by: Suzuki K Poulose Signed-off-by: Suzuki K Poulose Signed-off-by: Joey Gouly --- arm/Makefile.arm64 | 1 + lib/arm/asm/rsi.h | 16 ++++++++++ lib/arm/setup.c | 3 ++ lib/arm64/asm/processor.h | 8 +++++ lib/arm64/asm/rsi.h | 36 +++++++++++++++++++++ lib/arm64/rsi.c | 67 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 131 insertions(+) create mode 100644 lib/arm/asm/rsi.h create mode 100644 lib/arm64/asm/rsi.h create mode 100644 lib/arm64/rsi.c diff --git a/arm/Makefile.arm64 b/arm/Makefile.arm64 index 42e18e77..ab557f84 100644 --- a/arm/Makefile.arm64 +++ b/arm/Makefile.arm64 @@ -24,6 +24,7 @@ cstart.o = $(TEST_DIR)/cstart64.o cflatobjs += lib/arm64/processor.o cflatobjs += lib/arm64/spinlock.o cflatobjs += lib/arm64/gic-v3-its.o lib/arm64/gic-v3-its-cmd.o +cflatobjs += lib/arm64/rsi.o OBJDIRS += lib/arm64 diff --git a/lib/arm/asm/rsi.h b/lib/arm/asm/rsi.h new file mode 100644 index 00000000..d1f72c25 --- /dev/null +++ b/lib/arm/asm/rsi.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2022 Arm Limited. + * All rights reserved. + */ +#ifndef __ASMARM_RSI_H_ +#define __ASMARM_RSI_H_ + +#include + +static inline bool is_realm(void) +{ + return false; +} + +#endif /* __ASMARM_RSI_H_ */ diff --git a/lib/arm/setup.c b/lib/arm/setup.c index 65d98e97..36d4d826 100644 --- a/lib/arm/setup.c +++ b/lib/arm/setup.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -244,6 +245,8 @@ void setup(const void *fdt, phys_addr_t freemem_start) u32 fdt_size; int ret; + arm_rsi_init(); + assert(sizeof(long) == 8 || freemem_start < (3ul << 30)); freemem = (void *)(unsigned long)freemem_start; diff --git a/lib/arm64/asm/processor.h b/lib/arm64/asm/processor.h index 1c73ba32..320ebaef 100644 --- a/lib/arm64/asm/processor.h +++ b/lib/arm64/asm/processor.h @@ -114,6 +114,14 @@ static inline unsigned long get_id_aa64mmfr0_el1(void) #define ID_AA64MMFR0_TGRAN64_SUPPORTED 0x0 #define ID_AA64MMFR0_TGRAN16_SUPPORTED 0x1 +static inline unsigned long get_id_aa64pfr0_el1(void) +{ + return read_sysreg(id_aa64pfr0_el1); +} + +#define ID_AA64PFR0_EL1_EL3 (0xf << 12) +#define ID_AA64PFR0_EL1_EL3_NI (0x0 << 12) + static inline bool system_supports_granule(size_t granule) { u32 shift; diff --git a/lib/arm64/asm/rsi.h b/lib/arm64/asm/rsi.h new file mode 100644 index 00000000..8b9b91b2 --- /dev/null +++ b/lib/arm64/asm/rsi.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2022 Arm Limited. + * All rights reserved. + */ +#ifndef __ASMARM64_RSI_H_ +#define __ASMARM64_RSI_H_ + +#include + +#include +#include +#include + +#define RSI_GRANULE_SIZE SZ_4K + +extern bool rsi_present; + +void arm_rsi_init(void); + +int rsi_invoke(unsigned int function_id, unsigned long arg0, + unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, + unsigned long arg5, unsigned long arg6, + unsigned long arg7, unsigned long arg8, + unsigned long arg9, unsigned long arg10, + struct smccc_result *result); + +int rsi_get_version(void); + +static inline bool is_realm(void) +{ + return rsi_present; +} + +#endif /* __ASMARM64_RSI_H_ */ diff --git a/lib/arm64/rsi.c b/lib/arm64/rsi.c new file mode 100644 index 00000000..23a4e963 --- /dev/null +++ b/lib/arm64/rsi.c @@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2022 Arm Limited. + * All rights reserved. + */ +#include + +#include +#include +#include + +bool rsi_present; + +int rsi_invoke(unsigned int function_id, unsigned long arg0, + unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, + unsigned long arg5, unsigned long arg6, + unsigned long arg7, unsigned long arg8, + unsigned long arg9, unsigned long arg10, + struct smccc_result *result) +{ + return arm_smccc_smc(function_id, arg0, arg1, arg2, arg3, arg4, arg5, + arg6, arg7, arg8, arg9, arg10, result); +} + +struct rsi_realm_config __attribute__((aligned(RSI_GRANULE_SIZE))) config; + +static unsigned long rsi_get_realm_config(struct rsi_realm_config *cfg) +{ + struct smccc_result res; + + rsi_invoke(SMC_RSI_REALM_CONFIG, __virt_to_phys((unsigned long)cfg), + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &res); + + return res.r0; +} + +int rsi_get_version(void) +{ + struct smccc_result res = {}; + int ret; + + if ((get_id_aa64pfr0_el1() & ID_AA64PFR0_EL1_EL3) == ID_AA64PFR0_EL1_EL3_NI) + return -1; + + ret = rsi_invoke(SMC_RSI_ABI_VERSION, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + &res); + if (ret) + return ret; + + return res.r0; +} + +void arm_rsi_init(void) +{ + if (rsi_get_version() != RSI_ABI_VERSION) + return; + + if (rsi_get_realm_config(&config)) + return; + + rsi_present = true; + + phys_mask_shift = (config.ipa_width - 1); + /* Set the upper bit of the IPA as the NS_SHARED pte attribute */ + prot_ns_shared = (1UL << phys_mask_shift); +}