From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id BAB887803DF for ; Fri, 31 May 2024 07:14:28 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=kkOf+oZgRzHBtEX6hhBMQvlNPFKHtAGj9m79yuQLE2Q=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:User-Agent:To:From:Subject:Organization:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20240206; t=1717139668; v=1; b=ZE0lI+8ea4k91y2Hp2F54i6No7FGpE//vGhDmoyHJWYkJxC3a6x0fxd/KhyBXkRuuaMJez5Z MMXBMUkuw6ldAvKX0HViYKAhLKvCVHu+FeLsrCMUWBYCCgmnBw4rzXmhrAfm7DsPYMmsu6H8fPh nSe8In3iZhpPbKTGOidt3SPwkxclgzQ1IsoY8ADn8wdSgZPH6V05miclNrFP2YFdz6Co0yi8piK 32nH8QJnYsP/FCS47e5Lm06I/nh9u281OCBgvbNMlm/9DmfQhU2+Sw2jaczBG1ef4+fXyLUvCej Wo1g88KpaMWcM6ej3QZmR/nls+2nN3gbBb4f4O610VcwA== X-Received: by 127.0.0.2 with SMTP id 89zzYY7687511xBcMlL3sUNp; Fri, 31 May 2024 00:14:27 -0700 X-Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) by mx.groups.io with SMTP id smtpd.web10.5944.1717139666346240511 for ; Fri, 31 May 2024 00:14:26 -0700 X-Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a626777f74eso169737466b.3 for ; Fri, 31 May 2024 00:14:26 -0700 (PDT) X-Gm-Message-State: ZzThPkD8Jd41Y99dJARORlM7x7686176AA= X-Google-Smtp-Source: AGHT+IFEQ6GujCa67D4fuNKPFiiWZ6LHnLWuoL3h8e7tVluW2vDZKXzOgI56mO6sgVtXrvmaCMpb3A== X-Received: by 2002:a17:907:7811:b0:a66:7b79:3573 with SMTP id a640c23a62f3a-a682022f8a8mr77011166b.25.1717139664341; Fri, 31 May 2024 00:14:24 -0700 (PDT) X-Received: from [192.168.200.106] (83.11.37.15.ipv4.supernova.orange.pl. [83.11.37.15]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67eb344431sm55111166b.195.2024.05.31.00.14.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 31 May 2024 00:14:23 -0700 (PDT) Message-ID: <28f07a88-f664-43f4-871d-b5d0b82c7727@linaro.org> Date: Fri, 31 May 2024 09:14:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: devel@edk2.groups.io From: "Marcin Juszkiewicz" Subject: [edk2-devel] ArmCallSmc() and SMCCC specification Organization: Linaro Cc: Leif Lindholm , Ard Biesheuvel , Sami Mujawar Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Fri, 31 May 2024 00:14:26 -0700 Resent-From: marcin.juszkiewicz@linaro.org Reply-To: devel@edk2.groups.io,marcin.juszkiewicz@linaro.org List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Language: pl-PL, en-GB, en-HK Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=ZE0lI+8e; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=linaro.org (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io EDK2/ArmPkg/Library/ArmSmcLib has code to do SMC calls. There are ArmCallSmc[0-3]() functions for up to 3 arguments/results and ArmCallSmc() function which can use 7 arguments and get 4 results back. This implementation looks like version B (Nov 2016) of SMCCC specification [1] with one more register used. 1. https://developer.arm.com/documentation/den0028/b/ In 2020 we got version C of spec (and then D, E, F) which allows to use more registers: > Allow R4—R7 (SMC32/HVC32) to be used as result registers. > Allow X8—X17 to be used as parameter registers in SMC64/HVC64. > Allow X4—X17 to be used as result registers in SMC64/HVC64. And I started to wonder how to update EDK2 to newer version of SMCCC spec as one of in-progress QemuSbsa SMC calls may return more than 4 values. ARM_SMC_ARGS in ArmSmcLib.h can be expanded to handle up to Arg17 in an easy way and guarded by "#if defined(__aarch64__)" to not change it on Arm32. Then ArmCallSmc() in {AArch64,Arm}/ArmSmc.S needs changes. But here it gets tricky. On Arm we preserve r4-r8 and restore them after call like spec says. Which we do not do on AArch64 as version B of spec did not required that (and this changed in version C). If we start handling more than 4 results then we need to know how many results are expected and restore rest of r4-r7/x4-x17 registers: > When an SMC32/HVC32 call is made from AArch32: > • A Function Identifier is passed in register R0. > • Arguments are passed in registers R1-R7. > • Results are returned in R0-R7. > • The registers R4-R7 must be preserved unless they contain results, > as specified in the function definition. > • Registers R8-R14 are saved by the function that is called, and must > be preserved over the SMC or HVC call. > > When an SMC64/HVC64 call is made from AArch64: > • A Function Identifier is passed in register W0. > • Arguments are passed in registers X1-X17. > • Results are returned in X0-X17. > • Registers X4-X17 must be preserved unless they contain results, as > specified in the function definition. > • Registers X18-X30 and stack pointers SP_EL0 and SP_ELx are saved by > the function that is called, and must be preserved over the SMC or > HVC call. From what I saw in both edk2/ and edk2-platforms/ most of code uses ArmCallSmc() function with ARM_SMC_ARGS structure populared with arguments. ArmCallSmc[0-3]() are used by Smbios, Psci and QemuSbsa code only. Now the question is: how to handle change? We could add ArmCallSmc[4-17] but that name only tells how many arguments we pass to SMC call, not how many results we expect. Or should we add NumberOfResults argument to ArmCallSmc() to know which registers we should preserve and which are results? And how complicated this assembly function will become? -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#119408): https://edk2.groups.io/g/devel/message/119408 Mute This Topic: https://groups.io/mt/106403741/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-