From patchwork Wed Mar 29 20:25:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: D Scott Phillips X-Patchwork-Id: 13193194 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 DCB72C74A5B for ; Wed, 29 Mar 2023 20:26:42 +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: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:In-Reply-To:References: List-Owner; bh=CxlNyYTm40EJbL7XvkTeuFjiW7H2fr3H4BTxzSa/0ao=; b=ve7d4Me2kTE7Lh 5AaGPTgic+nV6pu3Q+zutgE7/Kf42BAex6pgHNX+z6uu3Tv8yZktGSzvo1nddkhX4+IG0ivcIjPDB G/aaLBHttN/CmERHB9DFYykPBcDJc5CDqpuwuyKrPh0tKLQXGO9RtPTfsCpsG/iL4Z40hvVPqimWM aNUum8VM0Rvb+11GesVkuTJAAB+5zl3Vmj6IZW9IB2fB3yqjiNpBMLyfp5SN1OTFuXMJF7pdAQmn1 bAxxz9wwl/6m45Ov8qAZGbdCNnV1tqotH+ZgDrLZZXzcQLQh2eFG+ALx4U+7gyDVi2KZ6UYMhC/2z guO5VmTlx9Pr9A8m6CVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phcMg-001lic-1B; Wed, 29 Mar 2023 20:25:50 +0000 Received: from mail-dm6nam11on2072c.outbound.protection.outlook.com ([2a01:111:f400:7eaa::72c] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1phcMc-001lgT-0X for linux-arm-kernel@lists.infradead.org; Wed, 29 Mar 2023 20:25:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bNZkWkFzMkp2igE8qt0k1HUJYcryLxKtnB1+vacFcbevEuzDqtXLELY7qO1O3hwxntUu5jPjq7AwWOmFTbLsKZJUR2LuKkPso1lxvdUphODSJbnjEs/gtDMoFw3rSPQR2HJlJ3Z1RVqxcs71FnXTqBYQjJHEjBhvhz5AyglvtFCcsW+vc9LbSnCrOo6aGKUcXfvdPMmvAAFhCzAzmyb6IlipYxm2fVGion/+6zFgZMM+7pjhT123PkDSdsbl328AxdCJuj1GAIiJUgHd/XVdwVPZ5A1XzHfRc9e50yE0Vk/SOvkrNp11YX9iZoSpATxibwTDfNl306JKa8WcRaxeBQ== 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=rtHFCOUt8UQ9mUK00YAxaWWwIgm8N7ZSqFmiIA9b26U=; b=L6f19XIXoqC8HoRG36W7rwknas5DE0g+CLSA1Dg7DFM8+WSPUc0o7Np9VzkyPXw7nsFoQ+3PNp7oKxfq48aqtBKlMT+LreuGr2sH7O5qHUvQW+jy4TvOcJuCqFkhEG62u92z9smjy8xzkb3Y7Vom1AAW/y9gZusP09yjLk4wQKwpOGxOr975FlIpkIMMTGuK2Paj2zeBaUYIO6QGpVuuTzXso0TJ2Fg6/yaA37FpvgfknBjAw4I4MDF9+6MlhnZ/XarhO+fZ82svvXaIOcyZIo6P+uiuwj0ADnaN2k9HW8BUue4brMXHlc+x50gmOk+WmVucx/qBrxxMH+ZhGNEgow== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rtHFCOUt8UQ9mUK00YAxaWWwIgm8N7ZSqFmiIA9b26U=; b=eOpqwCfMTBSUV7ZTCtX/1nYRK5HCqmwj7Ar+x8fzdNVb04ADSUsMkY/J6kQyyiuCz9WtYN0UfzecsBH/P+N3YuiPNeUm0KmeScxnrNDqtg5/HOK0Jr+k8S/G0dyXo6OEA41CsSSOcJUh3WYCV4+T9cP/JdwOr/hZxrHtSJfFTrw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) by BL0PR01MB4260.prod.exchangelabs.com (2603:10b6:208:49::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.18; Wed, 29 Mar 2023 20:25:33 +0000 Received: from MWHPR0101MB2893.prod.exchangelabs.com ([fe80::6f92:8006:1d6d:4cec]) by MWHPR0101MB2893.prod.exchangelabs.com ([fe80::6f92:8006:1d6d:4cec%6]) with mapi id 15.20.6254.018; Wed, 29 Mar 2023 20:25:33 +0000 From: D Scott Phillips To: linux-arm-kernel@lists.infradead.org, James Morse Cc: Catalin Marinas , Will Deacon Subject: [PATCH v2 1/2] arm64: sdei: Use alternative patching to select the conduit in sdei exit Date: Wed, 29 Mar 2023 13:25:18 -0700 Message-Id: <20230329202519.6110-1-scott@os.amperecomputing.com> X-Mailer: git-send-email 2.39.2 X-ClientProxiedBy: CH2PR14CA0015.namprd14.prod.outlook.com (2603:10b6:610:60::25) To MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR0101MB2893:EE_|BL0PR01MB4260:EE_ X-MS-Office365-Filtering-Correlation-Id: a069b446-b900-4ebf-3d73-08db3093beb4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SZFx+ZU1hfkFKcqHCBESivcVzHujwEjNSxDhLOHqISJ6V+KFlL23YR9dSGKJaTW0+PRaF2TdD2XEjkeHP4MZsB+Po8qlkQJbucBzBSQ7PfaasyoJAzhcce8FkdvXZEuUgRvCaHJMDHur/kdhSyl8Ai6Hfm1fbGS1ac/72dfrIlxIuCo07/Oht8jVyGNpSYqyb9JoliqmrzKBIKtAZjg1zWacX8JJQWCsjcQ1EBGTUvU32KY976G2okAoEPNprrjaMJNPB1OORtWEKsCXEZcPrpRImeUKfn0b8JGrx662KcT58KsddZUnikqkd0Z2GXp2XdkpGWjY1+i30CSiYCZCZAujzAq1fKVzIN4m2OpKhjsdUc6nHA7XMYbRbu44CiGHAwRr3ORQdrdUpwmr5e593+SskhtQQ0XMqp4l+epgPpayz7bbMSYqw5bXFUZMA+jRjIxa5SPFLHwG2h3ucwoXRlijW6zAFjeQZB3vUZ1GJLc1mIDG6i8R2+swrlKCBTzNlWwewihtD25e+dExbO8YvXj3m4Ig8ozZPoIo06cky6o2enYjoN/s2QXdxxmXkDJdG6YLXZ0AW4Vc6Hckp8EA/udLNuM/HYtrvzAczHhHp3/xFdHweHHJ+xUEJIp5g2VC X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR0101MB2893.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(136003)(396003)(39850400004)(376002)(366004)(346002)(451199021)(478600001)(316002)(38100700002)(38350700002)(54906003)(86362001)(83380400001)(2616005)(2906002)(6486002)(52116002)(5660300002)(8676002)(66556008)(66946007)(66476007)(6916009)(4326008)(6506007)(8936002)(6512007)(6666004)(41300700001)(186003)(1076003)(26005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WhqWoJDTWRMd5au2Q6svpbcgAuxT4Pp0vaONYOfBLPtB0AeSntHCPr4z4M/YLVThGaW961i2gqBJtbRFaf0MCyIaM46J7jAxW5V/JzYiLk+WScxw9W6DlFE2cATJS64+AcMqBMn5WE8zVqSRF95RR6j23nmGkS59iO6O2CYkf9dD+yoDkhujfKL0y/1fGm8sQsjusj+txf3lEmCfR2UMM4+UQNLfreYZRcIfPPkyv25ZGm/NpUNv/2MY/LFzYQ+fSYapaltWeprZbrgKzTFUCugOGec79mCwbD5SH+p8rMKUNqvjADJRkoxiWOCiCtI0a1slc6WulDccEJr5HQG0nB9HcizUdwwCQtcqEIMRMVx68GpO2wB+Fn5S+ZkXhHXgseY7PZTigd8BfsXfBacd9GcTIlTfVSO20D2J8u8e2b+WthxEpBhqhbQ7k/0zZTuQYvw60/JlXxRPTxNV1I+iGSHpaTYAPtF5Mvf5LK/OOaVCBeDfyfN40psqf/Oa2RusootTed3s6pUmAOLbjFzI+4aawoI5pAoIc+5Q5daMHuoHd7qcQLTpJz1k1l+zkvXgXWzcht9Y0ItkbUJC02heDMKY/S7sxcF6rIKo0zOjBCXKvyLisaZRLztoyK8iYMD1BZqJcohUgnzcXTtrYAcH6fu9OGDMznYO7k19M9GmU0btv9CM2iUO5dcqkuU7YhTRuaOPGzZi9TYlawJmaMbHyDzFsJrT92ceKjzTj4OAtDchtiRRaD7AJHZeCCSbS2HsGn7V4v2vzTHTNuQZBm2cnkGGM1ijEYJyNxDO+dS/K4Eue7frHSyFb8xSYE8bLtUY3tD6Eh8jJVhgqW5Rb5L2m2DPq8xLhQggUDRhfHYw+xUiJXJ/nEVRaLRzQzVmb6oiURYj27ELde5Medx1/c37ZaF2KYTgpWYy2CQbSU6rZDP9RfP1vgiN0dONPXjqkb0TdUhER79N6KiBH5AkL4uL8KmCKUAA4ZOfwDsnBWfl75s3I/S+c3vRzgOT5Oao4Fabb3H6HrjPso4EoCUHth+qIdRNFPH6NCJ7wdWlgL+FqTLDM5vvNGDMtv32EK3W/O701XNWrJ6O3wZYGYN6u9j60Uy7D2Oyy9TCuh2p96VMOLCFP9ZidUeRIKWyED8YKUO5IeoM25XNOHflUyYfLx7azPeBahdWD7YHifXD8Ht3L1QbtWC9zaDarav2ToYkjYLY2q+6AESrhKSRy6ExlBDLVNJ1br/6cM8P3ZtsTdRvJakmL12XkV6zlOZeRLYDyD7uhQ1K94nO2Vqlh16SdQoizDq4knVNIND9pywyOlertlO/IoDoKm3UsKjiH9ORCucfTMnguKXjUm2WHqnHaH0tRWnHu4IRsS9ufIlbixH3+rjGKEDuXjq5+ueYck9K+EN2xCQnCYhPXOrGyby4n+BRzWG05G4VyFo0Wu2q+5Hct/kiYUJ2C6htnsV1fKu/OVBuEg/gIbMWd1m7W/dSnCStxOv7piaURmrJR8piDrdl6eaMAsGSCPv2ECWxx/m5j+PRW53W4MdGdayioZJNXv/I5baMinH7ktfIpP32coZeemuIWoG5yCsQBu28tdJYZ130gJ0FXjtey1jrFqD7jM0W5g== X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: a069b446-b900-4ebf-3d73-08db3093beb4 X-MS-Exchange-CrossTenant-AuthSource: MWHPR0101MB2893.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2023 20:25:32.9073 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Rq4p7q0pnYpf/1BuAD/hQzh6146/hAEH4rdqBaIweJUiuvWu5rVM87yGD4IpHuptKN6Q8BfBB7pbF5C1oR/F+PCCivcbFfjHAZ4Hd9NfESCywwqovvdSfCb7vMCheySi X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR01MB4260 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230329_132546_473522_EC8B4C2A X-CRM114-Status: GOOD ( 21.46 ) 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 Patch in the conduit instruction for SDEI instead of branching between the possible conduits. The sdei driver's conduit initialization is moved earlier in the initialization flow, into setup_arch(), so that it is ready in time for alternative patching. Suggested-by: James Morse Signed-off-by: D Scott Phillips --- Hi James, Here's a change to patch in the conduit instruction on the sdei handler exit path. It wound up a little involved because the separate conduit `method` in arm,sdei-1.0 nodes. arch/arm64/include/asm/sdei.h | 13 +++---- arch/arm64/kernel/entry.S | 26 ++++++------- arch/arm64/kernel/sdei.c | 30 ++++++++++++--- arch/arm64/kernel/setup.c | 3 ++ drivers/firmware/arm_sdei.c | 71 +++++++++++++++++++---------------- include/linux/arm_sdei.h | 6 ++- 6 files changed, 88 insertions(+), 61 deletions(-) diff --git a/arch/arm64/include/asm/sdei.h b/arch/arm64/include/asm/sdei.h index 4292d9bafb9d..badb39510515 100644 --- a/arch/arm64/include/asm/sdei.h +++ b/arch/arm64/include/asm/sdei.h @@ -3,10 +3,6 @@ #ifndef __ASM_SDEI_H #define __ASM_SDEI_H -/* Values for sdei_exit_mode */ -#define SDEI_EXIT_HVC 0 -#define SDEI_EXIT_SMC 1 - #define SDEI_STACK_SIZE IRQ_STACK_SIZE #ifndef __ASSEMBLY__ @@ -17,8 +13,6 @@ #include -extern unsigned long sdei_exit_mode; - /* Software Delegated Exception entry point from firmware*/ asmlinkage void __sdei_asm_handler(unsigned long event_num, unsigned long arg, unsigned long pc, unsigned long pstate); @@ -40,8 +34,11 @@ asmlinkage unsigned long __sdei_handler(struct pt_regs *regs, unsigned long do_sdei_event(struct pt_regs *regs, struct sdei_registered_event *arg); -unsigned long sdei_arch_get_entry_point(int conduit); -#define sdei_arch_get_entry_point(x) sdei_arch_get_entry_point(x) +unsigned long sdei_arch_get_entry_point(void); +#define sdei_arch_get_entry_point sdei_arch_get_entry_point + +void __init sdei_patch_conduit(struct alt_instr *alt, __le32 *origptr, + __le32 *updptr, int nr_inst); #endif /* __ASSEMBLY__ */ #endif /* __ASM_SDEI_H */ diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 11cb99c4d298..80b6f67a67d4 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -909,13 +909,10 @@ NOKPROBE(call_on_irq_stack) #include #include -.macro sdei_handler_exit exit_mode - /* On success, this call never returns... */ - cmp \exit_mode, #SDEI_EXIT_SMC - b.ne 99f - smc #0 - b . -99: hvc #0 +.macro sdei_handler_exit +alternative_cb ARM64_ALWAYS_SYSTEM, sdei_patch_conduit + nop // Patched to SMC/HVC #0 +alternative_cb_end b . .endm @@ -950,7 +947,6 @@ NOKPROBE(__sdei_asm_entry_trampoline) * Make the exit call and restore the original ttbr1_el1 * * x0 & x1: setup for the exit API call - * x2: exit_mode * x4: struct sdei_registered_event argument from registration time. */ SYM_CODE_START(__sdei_asm_exit_trampoline) @@ -959,7 +955,7 @@ SYM_CODE_START(__sdei_asm_exit_trampoline) tramp_unmap_kernel tmp=x4 -1: sdei_handler_exit exit_mode=x2 +1: sdei_handler_exit SYM_CODE_END(__sdei_asm_exit_trampoline) NOKPROBE(__sdei_asm_exit_trampoline) .popsection // .entry.tramp.text @@ -1065,14 +1061,16 @@ SYM_CODE_START(__sdei_asm_handler) mov_q x3, SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME csel x0, x2, x3, ls - ldr_l x2, sdei_exit_mode - -alternative_if_not ARM64_UNMAP_KERNEL_AT_EL0 - sdei_handler_exit exit_mode=x2 +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +alternative_if ARM64_UNMAP_KERNEL_AT_EL0 + b 1f alternative_else_nop_endif +#endif + + sdei_handler_exit #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 - tramp_alias dst=x5, sym=__sdei_asm_exit_trampoline, tmp=x3 +1: tramp_alias dst=x5, sym=__sdei_asm_exit_trampoline, tmp=x3 br x5 #endif SYM_CODE_END(__sdei_asm_handler) diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c index 830be01af32d..be7f6ea49956 100644 --- a/arch/arm64/kernel/sdei.c +++ b/arch/arm64/kernel/sdei.c @@ -20,8 +20,6 @@ #include #include -unsigned long sdei_exit_mode; - /* * VMAP'd stacks checking for stack overflow on exception using sp as a scratch * register, meaning SDEI has to switch to its own stack. We need two stacks as @@ -162,7 +160,7 @@ static int init_sdei_scs(void) return err; } -unsigned long sdei_arch_get_entry_point(int conduit) +unsigned long sdei_arch_get_entry_point(void) { /* * SDEI works between adjacent exception levels. If we booted at EL1 we @@ -181,8 +179,6 @@ unsigned long sdei_arch_get_entry_point(int conduit) if (init_sdei_scs()) goto out_err_free_stacks; - sdei_exit_mode = (conduit == SMCCC_CONDUIT_HVC) ? SDEI_EXIT_HVC : SDEI_EXIT_SMC; - #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 if (arm64_kernel_unmapped_at_el0()) { unsigned long offset; @@ -262,3 +258,27 @@ unsigned long __kprobes do_sdei_event(struct pt_regs *regs, return vbar + 0x480; } + +/* + * Patch in the sdei conduit instruction. + */ +void __init sdei_patch_conduit(struct alt_instr *alt, __le32 *origptr, + __le32 *updptr, int nr_inst) +{ + u32 insn; + + BUG_ON(nr_inst != 1); /* NOP -> HVC/SMC */ + + switch (sdei_get_conduit()) { + case SMCCC_CONDUIT_HVC: + insn = aarch64_insn_get_hvc_value(); + break; + case SMCCC_CONDUIT_SMC: + insn = aarch64_insn_get_smc_value(); + break; + default: + return; + } + + *updptr = cpu_to_le32(insn); +} diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 12cfe9d0d3fa..87168c5d0c34 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -360,6 +361,8 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) else psci_acpi_init(); + sdei_conduit_init(); + init_bootcpu_ops(); smp_init_cpus(); smp_build_mpidr_hash(); diff --git a/drivers/firmware/arm_sdei.c b/drivers/firmware/arm_sdei.c index 1e1a51510e83..0dbb88bcc9a2 100644 --- a/drivers/firmware/arm_sdei.c +++ b/drivers/firmware/arm_sdei.c @@ -919,37 +919,12 @@ int sdei_unregister_ghes(struct ghes *ghes) return err; } -static int sdei_get_conduit(struct platform_device *pdev) +enum arm_smccc_conduit sdei_get_conduit(void) { - const char *method; - struct device_node *np = pdev->dev.of_node; - - sdei_firmware_call = NULL; - if (np) { - if (of_property_read_string(np, "method", &method)) { - pr_warn("missing \"method\" property\n"); - return SMCCC_CONDUIT_NONE; - } - - if (!strcmp("hvc", method)) { - sdei_firmware_call = &sdei_smccc_hvc; - return SMCCC_CONDUIT_HVC; - } else if (!strcmp("smc", method)) { - sdei_firmware_call = &sdei_smccc_smc; - return SMCCC_CONDUIT_SMC; - } - - pr_warn("invalid \"method\" property: %s\n", method); - } else if (!acpi_disabled) { - if (acpi_psci_use_hvc()) { - sdei_firmware_call = &sdei_smccc_hvc; - return SMCCC_CONDUIT_HVC; - } else { - sdei_firmware_call = &sdei_smccc_smc; - return SMCCC_CONDUIT_SMC; - } - } - + if (sdei_firmware_call == sdei_smccc_hvc) + return SMCCC_CONDUIT_HVC; + if (sdei_firmware_call == sdei_smccc_smc) + return SMCCC_CONDUIT_SMC; return SMCCC_CONDUIT_NONE; } @@ -957,9 +932,7 @@ static int sdei_probe(struct platform_device *pdev) { int err; u64 ver = 0; - int conduit; - conduit = sdei_get_conduit(pdev); if (!sdei_firmware_call) return 0; @@ -984,7 +957,7 @@ static int sdei_probe(struct platform_device *pdev) if (err) return err; - sdei_entry_point = sdei_arch_get_entry_point(conduit); + sdei_entry_point = sdei_arch_get_entry_point(); if (!sdei_entry_point) { /* Not supported due to hardware or boot configuration */ sdei_mark_interface_broken(); @@ -1059,6 +1032,38 @@ static bool __init sdei_present_acpi(void) return true; } +void __init sdei_conduit_init(void) +{ + const char *method; + struct device_node *np; + + if (acpi_disabled) { + np = of_find_matching_node_and_match(NULL, sdei_of_match, NULL); + if (!np || !of_device_is_available(np)) + return; + + if (of_property_read_string(np, "method", &method)) { + pr_warn("missing \"method\" property\n"); + return; + } + + if (!strcmp("hvc", method)) + sdei_firmware_call = &sdei_smccc_hvc; + else if (!strcmp("smc", method)) + sdei_firmware_call = &sdei_smccc_smc; + else + pr_warn("invalid \"method\" property: %s\n", method); + } else { + if (!sdei_present_acpi()) + return; + + if (acpi_psci_use_hvc()) + sdei_firmware_call = &sdei_smccc_hvc; + else + sdei_firmware_call = &sdei_smccc_smc; + } +} + void __init sdei_init(void) { struct platform_device *pdev; diff --git a/include/linux/arm_sdei.h b/include/linux/arm_sdei.h index 14dc461b0e82..de9aafd87c48 100644 --- a/include/linux/arm_sdei.h +++ b/include/linux/arm_sdei.h @@ -13,7 +13,7 @@ /* Arch code should override this to set the entry point from firmware... */ #ifndef sdei_arch_get_entry_point -#define sdei_arch_get_entry_point(conduit) (0) +#define sdei_arch_get_entry_point() (0) #endif /* @@ -22,6 +22,8 @@ */ typedef int (sdei_event_callback)(u32 event, struct pt_regs *regs, void *arg); +enum arm_smccc_conduit sdei_get_conduit(void); + /* * Register your callback to claim an event. The event must be described * by firmware. @@ -47,10 +49,12 @@ int sdei_unregister_ghes(struct ghes *ghes); int sdei_mask_local_cpu(void); int sdei_unmask_local_cpu(void); void __init sdei_init(void); +void __init sdei_conduit_init(void); #else static inline int sdei_mask_local_cpu(void) { return 0; } static inline int sdei_unmask_local_cpu(void) { return 0; } static inline void sdei_init(void) { } +static inline void sdei_conduit_init(void) { } #endif /* CONFIG_ARM_SDE_INTERFACE */