From patchwork Thu Aug 11 21:40:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 596709 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9B46C3F6B0 for ; Thu, 11 Aug 2022 21:47:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233297AbiHKVrF (ORCPT ); Thu, 11 Aug 2022 17:47:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234651AbiHKVrE (ORCPT ); Thu, 11 Aug 2022 17:47:04 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BC9A9F19D; Thu, 11 Aug 2022 14:47:03 -0700 (PDT) Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27BKqvWm029339; Thu, 11 Aug 2022 21:46:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=NdBMegGfQRT3NVnpSimV4eMtuPXioAvn9GAQ6vw5iwE=; b=brhFAAFY9Iz85xVA5cwZFU8u34ZH7JljhDoD5Zy43pIPlCFjvs0HHEKEe72qjjvPsZ03 /CWSjvzOFsmyZ5Lkzw+nM6BgSddl4DXGka9F0dnpqa0cbxKy2WGMM5j5EFc5eBzWpK6R dWTdHrZFnoFvFs7uAQ/iSBRS3k+QifdX5u1qaqU/W2ynB2X3A04K3M8NPQyOcJXzPTXH 1BeJSUJs3SmTu0Ca3r+tbyaiHOYprP3BsIfQE1yx6gzitPV2ShEAHMp3BlZs4gaDpdt/ zpvaqxSc3CiytVIsSLoDOrh2TRB9L7R86HW8PZJeh47TLHuglYDUSNMS87ApH3KQNE0C vA== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3hvh25vhct-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Aug 2022 21:46:56 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 27BLfuaI011392 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Aug 2022 21:41:56 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Thu, 11 Aug 2022 14:41:54 -0700 From: Elliot Berman To: Bjorn Andersson , Mark Rutland , Lorenzo Pieralisi , "Sudeep Holla" CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , , "Marc Zyngier" , Rob Herring , "Krzysztof Kozlowski" , Jonathan Corbet , Will Deacon , Catalin Marinas , , , Subject: [PATCH v3 01/12] arm64: smccc: Include alternative-macros.h Date: Thu, 11 Aug 2022 14:40:56 -0700 Message-ID: <20220811214107.1074343-2-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220811214107.1074343-1-quic_eberman@quicinc.com> References: <20220811214107.1074343-1-quic_eberman@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: JRPNxkqRVBm2POyhiGf6NOtUYlXTFCI1 X-Proofpoint-ORIG-GUID: JRPNxkqRVBm2POyhiGf6NOtUYlXTFCI1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-11_13,2022-08-11_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 suspectscore=0 mlxscore=0 mlxlogscore=766 impostorscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208110065 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Fix build error when CONFIG_ARM64_SVE is selected and asm/alternative-macros.h wasn't implicitly included by another header. Fixes: cfa7ff959a78 ("arm64: smccc: Support SMCCC v1.3 SVE register saving hint") Signed-off-by: Elliot Berman --- include/linux/arm-smccc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index 220c8c60e021..6a627cdbbdec 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -383,6 +383,7 @@ asmlinkage void __arm_smccc_hvc(unsigned long a0, unsigned long a1, /* nVHE hypervisor doesn't have a current thread so needs separate checks */ #if defined(CONFIG_ARM64_SVE) && !defined(__KVM_NVHE_HYPERVISOR__) +#include #define SMCCC_SVE_CHECK ALTERNATIVE("nop \n", "bl __arm_smccc_sve_check \n", \ ARM64_SVE) From patchwork Thu Aug 11 21:40:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 596708 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21A3BC3F6B0 for ; Thu, 11 Aug 2022 21:47:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235499AbiHKVrK (ORCPT ); Thu, 11 Aug 2022 17:47:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234651AbiHKVrI (ORCPT ); Thu, 11 Aug 2022 17:47:08 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE84C9F195; Thu, 11 Aug 2022 14:47:06 -0700 (PDT) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27BL6q3F015580; Thu, 11 Aug 2022 21:46:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=P1MZK1bgp2f6Ap1wWe9NnGFnK9eBy0m0V3Y4M6yY8iQ=; b=DNEN2Nbc+BK9LZqzjAoXEuy0j0AZ6dhshEVEfMyga0xSOOMIV48QEHyH1GpCYoSELOG4 QSVCshezrhER1Gxyyc84KZbXyvVknN8F/TIvutRdLMrIwkoXW0haOirSa0lyf0kQXzjU Q8zHe30LJI/R9XlzED6HrnbSTfszoWJl9QSMYsiwkT86BoQ77BlpiDqgUE1r4/eEXEIy lAe4eL9d2Ua4sSoKxH9ZXnYIdzW98RYee004eFOCMYMGaF3+AEa0dBfXhSrkFt9YOMRG tyL/ITBu04H49v/ToXfbB6EP1R/zvjIcm/Zm+9LZGF5+iewXJB+ZUMDsRLWZaxkWDKG0 Sg== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3huwqg7px0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Aug 2022 21:46:57 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 27BLfusx017994 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Aug 2022 21:41:56 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Thu, 11 Aug 2022 14:41:55 -0700 From: Elliot Berman To: Bjorn Andersson , , Jonathan Corbet CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , , "Mark Rutland" , Lorenzo Pieralisi , Sudeep Holla , "Marc Zyngier" , Rob Herring , "Krzysztof Kozlowski" , Will Deacon , Catalin Marinas , , Subject: [PATCH v3 02/12] docs: gunyah: Introduce Gunyah Hypervisor Date: Thu, 11 Aug 2022 14:40:57 -0700 Message-ID: <20220811214107.1074343-3-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220811214107.1074343-1-quic_eberman@quicinc.com> References: <20220811214107.1074343-1-quic_eberman@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: kr5S5-CNIo-5dY5orITU_TAtRWkWfWfn X-Proofpoint-GUID: kr5S5-CNIo-5dY5orITU_TAtRWkWfWfn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-11_13,2022-08-11_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1015 phishscore=0 priorityscore=1501 mlxscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208110065 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Gunyah is an open-source Type-1 hypervisor developed by Qualcomm. It does not depend on any lower-privileged OS/kernel code for its core functionality. This increases its security and can support a smaller trusted computing based when compared to Type-2 hypervisors. Add documentation describing the Gunyah hypervisor and the main components of the Gunyah hypervisor which are of interest to Linux virtualization development. Signed-off-by: Elliot Berman --- Documentation/virt/gunyah/index.rst | 102 ++++++++++++++++++++ Documentation/virt/gunyah/message-queue.rst | 52 ++++++++++ Documentation/virt/index.rst | 1 + MAINTAINERS | 7 ++ 4 files changed, 162 insertions(+) create mode 100644 Documentation/virt/gunyah/index.rst create mode 100644 Documentation/virt/gunyah/message-queue.rst diff --git a/Documentation/virt/gunyah/index.rst b/Documentation/virt/gunyah/index.rst new file mode 100644 index 000000000000..780ff958a83b --- /dev/null +++ b/Documentation/virt/gunyah/index.rst @@ -0,0 +1,102 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================= +Gunyah Hypervisor +================= + +.. toctree:: + :maxdepth: 1 + + message-queue + +Gunyah is a Type-1 hypervisor which is independent of any OS kernel, and runs in +a higher CPU privilege level. It does not depend on any lower-privileged operating system +for its core functionality. This increases its security and can support a much smaller +trusted computing base than a Type-2 hypervisor. + +Gunyah is an open source hypervisor. The source repo is available at +https://github.com/quic/gunyah-hypervisor. + +Gunyah provides these following features. + +- Scheduling: + A scheduler for virtual CPUs (vCPUs) on physical CPUs and enables time-sharing + of the CPUs. Gunyah supports two models of scheduling: + 1. "Behind the back" scheduling in which Gunyah hypervisor schedules vCPUS on its own + 2. "Proxy" scheduling in which a delegated VM can donate part of one of its vCPU slice + to another VM's vCPU via a hypercall. +- Memory Management: + APIs handling memory, abstracted as objects, limiting direct use of physical + addresses. Memory ownership and usage tracking of all memory under its control. + Memory partitioning between VMs is a fundamental security feature. +- Interrupt Virtualization: + Uses CPU hardware interrupt virtualization capabilities. Interrupts are handled + in the hypervisor and routed to the assigned VM. +- Inter-VM Communication: + There are several different mechanisms provided for communicating between VMs. +- Virtual platform: + Architectural devices such as interrupt controllers and CPU timers are directly provided + by the hypervisor as well as core virtual platform devices and system APIs such as ARM PSCI. +- Device Virtualization: + Para-virtualization of devices is supported using inter-VM communication. + +Architectures supported +======================= +AArch64 with a GIC + +Resources and Capabilities +========================== + +Some services or resources provided by the Gunyah hypervisor are described to a virtual machine by +capability IDs. For instance, inter-VM communication is performed with doorbells and message queues. +Gunyah allows access to manipulate that doorbell via the capability ID. These devices are described +in Linux as a struct gunyah_device. + +High level management of these resources is performed by the resource manager VM. RM informs a +guest VM about resources it can access through either the device tree or via guest-initiated RPC. + +For each virtual machine, Gunyah maintains a table of resources which can be accessed by that VM. +An entry in this table is called a "capability" and VMs can only access resources via this +capability table. Hence, virtual Gunyah devices are referenced by a "capability IDs" and not a +"resource IDs". A VM can have multiple capability IDs mapping to the same resource. If 2 VMs have +access to the same resource, they may not be using the same capability ID to access that resource +since the tables are independent per VM. + +Resource Manager +================ + +The resource manager (RM) is a privileged application VM supporting the Gunyah Hypervisor. +It provides policy enforcement aspects of the virtualization system. The resource manager can +be treated as an extension of the Hypervisor but is separated to its own partition to ensure +that the hypervisor layer itself remains small and secure and to maintain a separation of policy +and mechanism in the platform. On arm64, RM runs at NS-EL1 similar to other virtual machines. + +Communication with the resource manager from each guest VM happens with message-queue.rst. Details +about the specific messages can be found in drivers/virt/gunyah/rsc_mgr.c + +:: + + +-------+ +--------+ +--------+ + | RM | | VM_A | | VM_B | + +-.-.-.-+ +---.----+ +---.----+ + | | | | + +-.-.-----------.------------.----+ + | | \==========/ | | + | \========================/ | + | Gunyah | + +---------------------------------+ + +The source for the resource manager is available at https://github.com/quic/gunyah-resource-manager. + +The resource manager provides the following features: + +- VM lifecycle management: allocating a VM, starting VMs, destruction of VMs +- VM access control policy, including memory sharing and lending +- Interrupt routing configuration +- Forwarding of system-level events (e.g. VM shutdown) to owner VM + +When booting a virtual machine which uses a devicetree, resource manager overlays a +/hypervisor node. This node can let Linux know it is running as a Gunyah guest VM, +how to communicate with resource manager, and basic description and capabilities of +this VM. See Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml for a description +of this node. diff --git a/Documentation/virt/gunyah/message-queue.rst b/Documentation/virt/gunyah/message-queue.rst new file mode 100644 index 000000000000..e130f124ed52 --- /dev/null +++ b/Documentation/virt/gunyah/message-queue.rst @@ -0,0 +1,52 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Message Queues +============== +Message queue is a simple low-capacity IPC channel between two VMs. It is +intended for sending small control and configuration messages. Each message +queue object is unidirectional, so a full-duplex IPC channel requires a pair of +objects. + +Messages can be up to 1024 bytes in length. Longer messages require a further +protocol on top of the message queue messages themselves. For instance, communication +with the resource manager adds a header field for sending longer messages via multiple +message fragments. + +The diagram below shows how message queue works. A typical configuration involves +2 message queues. Message queue 1 allows VM_A to send messages to VM_B. Message +queue 2 allows VM_B to send messages to VM_A. + +1. VM_A sends a message of up to 1024 bytes in length. It raises a hypercall + with the message to inform the hypervisor to add the message to + message queue 1's queue. +2. Gunyah raises the corresponding interrupt for VM_B when any of these happens: + a. gh_msgq_send has PUSH flag. Queue is immediately flushed. This is the typical case. + b. Explicility with gh_msgq_push command from VM_A. + c. Message queue has reached a threshold depth. +3. VM_B calls gh_msgq_recv and Gunyah copies message to requested buffer. + +For VM_B to send a message to VM_A, the process is identical, except that hypercalls +reference message queue 2's capability ID. + +:: + + +---------------+ +-----------------+ +---------------+ + | VM_A | |Gunyah hypervisor| | VM_B | + | | | | | | + | | | | | | + | | Tx | | | | + | |-------->| | Rx vIRQ | | + |gh_msgq_send() | Tx vIRQ |Message queue 1 |-------->|gh_msgq_recv() | + | |<------- | | | | + | | | | | | + | Message Queue | | | | Message Queue | + | driver | | | | driver | + | | | | | | + | | | | | | + | | | | Tx | | + | | Rx vIRQ | |<--------| | + |gh_msgq_recv() |<--------|Message queue 2 | Tx vIRQ |gh_msgq_send() | + | | | |-------->| | + | | | | | | + | | | | | | + +---------------+ +-----------------+ +---------------+ diff --git a/Documentation/virt/index.rst b/Documentation/virt/index.rst index 492f0920b988..dd4e8ef284eb 100644 --- a/Documentation/virt/index.rst +++ b/Documentation/virt/index.rst @@ -14,6 +14,7 @@ Linux Virtualization Support ne_overview acrn/index coco/sev-guest + gunyah/index .. only:: html and subproject diff --git a/MAINTAINERS b/MAINTAINERS index 64379c699903..24d1660bbafa 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8734,6 +8734,13 @@ L: linux-efi@vger.kernel.org S: Maintained F: block/partitions/efi.* +GUNYAH HYPERVISOR DRIVER +M: Elliot Berman +M: Murali Nalajala +L: linux-arm-msm@vger.kernel.org +S: Supported +F: Documentation/virt/gunyah/ + HABANALABS PCI DRIVER M: Oded Gabbay S: Supported From patchwork Thu Aug 11 21:41:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 596705 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2121CC25B07 for ; Thu, 11 Aug 2022 22:06:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235762AbiHKWGI (ORCPT ); Thu, 11 Aug 2022 18:06:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236369AbiHKWGG (ORCPT ); Thu, 11 Aug 2022 18:06:06 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8DF4248CA; Thu, 11 Aug 2022 15:06:03 -0700 (PDT) Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27BM1q8L012558; Thu, 11 Aug 2022 22:05:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=CBqQhmy5q8Ih5/yMHtszBKU42svrecCMR3Zi5a9CEqs=; b=YdXUFqM6hKJeaDKeZlh0xEaJHPW9tK1QvnTM9nVstx/56Y+CI0JxEAgqlXT/sRguOcl3 464Inu/PcajygM1jFwfC4Uc6gIFqc7PA9CvneG4jFTohwa0R0XPYP5cstSUOFpZvvj98 28To6VgFLTinWxDf1NWoxG3yFQvIAUCgpNqRaFllIGmTkvfq7lGTJNyku7gQB5LmTp/U eFltoydmCyLQ0Kgf2pa5o8Hhz9JAm4BMmR1mcPhUg9z6thR7k6kCUuYTgCxcTt1v2QgG EAxNLCvjw/0OAeJ00O6ckydX4bzMXxpkLXRdGJTGCA7h0M22l3iIko5qf5+n6ETd8vQl uw== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3hvh25vjdf-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Aug 2022 22:05:54 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 27BLfwVb011414 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Aug 2022 21:41:58 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Thu, 11 Aug 2022 14:41:57 -0700 From: Elliot Berman To: Bjorn Andersson , Lorenzo Pieralisi , Sudeep Holla , "Marc Zyngier" CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , , "Mark Rutland" , Rob Herring , "Krzysztof Kozlowski" , Jonathan Corbet , Will Deacon , Catalin Marinas , , , Subject: [PATCH v3 05/12] virt: gunyah: Add hypercalls to identify Gunyah Date: Thu, 11 Aug 2022 14:41:00 -0700 Message-ID: <20220811214107.1074343-6-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220811214107.1074343-1-quic_eberman@quicinc.com> References: <20220811214107.1074343-1-quic_eberman@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: px05yBckFTcPvlodJQ7zfZj9dzqxXa6v X-Proofpoint-ORIG-GUID: px05yBckFTcPvlodJQ7zfZj9dzqxXa6v X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-11_13,2022-08-11_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 impostorscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208110066 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add hypercalls to identify when Linux is running a virtual machine under Gunyah. There are two calls to help identify Gunyah: 1. gh_hypercall_get_uid() returns a UID when running under a Gunyah hypervisor. 2. gh_hypercall_hyp_identify() returns build information and a set of feature flags that are supported by Gunyah. Signed-off-by: Elliot Berman --- MAINTAINERS | 2 + arch/arm64/Kbuild | 1 + arch/arm64/gunyah/Makefile | 2 + arch/arm64/gunyah/hypercall.c | 71 +++++++++++++++++++++++++++++++++++ drivers/virt/Kconfig | 2 + drivers/virt/gunyah/Kconfig | 13 +++++++ include/asm-generic/gunyah.h | 36 ++++++++++++++++++ 7 files changed, 127 insertions(+) create mode 100644 arch/arm64/gunyah/Makefile create mode 100644 arch/arm64/gunyah/hypercall.c create mode 100644 drivers/virt/gunyah/Kconfig diff --git a/MAINTAINERS b/MAINTAINERS index 14030c8ffe8a..f5d5ebb62701 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8741,6 +8741,8 @@ L: linux-arm-msm@vger.kernel.org S: Supported F: Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml F: Documentation/virt/gunyah/ +F: arch/arm64/gunyah/ +F: drivers/virt/gunyah/ F: include/asm-generic/gunyah.h HABANALABS PCI DRIVER diff --git a/arch/arm64/Kbuild b/arch/arm64/Kbuild index 5bfbf7d79c99..fbcde0d5cec8 100644 --- a/arch/arm64/Kbuild +++ b/arch/arm64/Kbuild @@ -4,6 +4,7 @@ obj-$(CONFIG_KVM) += kvm/ obj-$(CONFIG_XEN) += xen/ obj-$(subst m,y,$(CONFIG_HYPERV)) += hyperv/ obj-$(CONFIG_CRYPTO) += crypto/ +obj-$(CONFIG_GUNYAH) += gunyah/ # for cleaning subdir- += boot diff --git a/arch/arm64/gunyah/Makefile b/arch/arm64/gunyah/Makefile new file mode 100644 index 000000000000..f71a9533c266 --- /dev/null +++ b/arch/arm64/gunyah/Makefile @@ -0,0 +1,2 @@ +obj-$(CONFIG_GUNYAH) += gunyah_hypercall.o +gunyah_hypercall-y += hypercall.o diff --git a/arch/arm64/gunyah/hypercall.c b/arch/arm64/gunyah/hypercall.c new file mode 100644 index 000000000000..5b08c9d80de0 --- /dev/null +++ b/arch/arm64/gunyah/hypercall.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include +#include +#include + +#define GH_CALL_TYPE_PLATFORM_CALL 0 +#define GH_CALL_TYPE_HYPERCALL 2 +#define GH_CALL_TYPE_SERVICE 3 +#define GH_CALL_TYPE_SHIFT 14 +#define GH_CALL_FUNCTION_NUM_MASK 0x3fff + +#define GH_SERVICE(fn) ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_VENDOR_HYP, \ + (GH_CALL_TYPE_SERVICE << GH_CALL_TYPE_SHIFT) \ + | ((fn) & GH_CALL_FUNCTION_NUM_MASK)) + +#define GH_HYPERCALL_CALL_UID GH_SERVICE(0x3f01) + +#define GH_HYPERCALL(fn) ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_VENDOR_HYP, \ + (GH_CALL_TYPE_HYPERCALL << GH_CALL_TYPE_SHIFT) \ + | ((fn) & GH_CALL_FUNCTION_NUM_MASK)) + +#define GH_HYPERCALL_HYP_IDENTIFY GH_HYPERCALL(0x0000) + +/** + * gh_hypercall_get_uid() - Returns a UID when running under a Gunyah hypervisor. + * @uid: An array of 4 u32's (u32 uid[4];) + * + * The UID will be either QC_HYP_UID or GUNYAH_UID defined in include/asm-generic/gunyah.h. + * QC_HYP_UID is returned on platforms using Qualcomm's version of Gunyah. + * GUNYAH_UID is returned on platforms using open source version of Gunyah. + * If the uid is not one of the above two UIDs, then it is assumed that the hypervisor or firmware + * is not Gunyah. + */ +void gh_hypercall_get_uid(u32 *uid) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_hvc(GH_HYPERCALL_CALL_UID, &res); + + uid[0] = res.a0; + uid[1] = res.a1; + uid[2] = res.a2; + uid[3] = res.a3; +} +EXPORT_SYMBOL_GPL(gh_hypercall_get_uid); + +/** + * gh_hypercall_hyp_identify() - Returns build information and feature flags supported by Gunyah. + * @hyp_identify: filled by the hypercall with the API info and feature flags. + */ +void gh_hypercall_hyp_identify(struct gh_hypercall_hyp_identify_resp *hyp_identity) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_hvc(GH_HYPERCALL_HYP_IDENTIFY, &res); + + hyp_identity->api_info = res.a0; + hyp_identity->flags[0] = res.a1; + hyp_identity->flags[1] = res.a2; + hyp_identity->flags[2] = res.a3; +} +EXPORT_SYMBOL_GPL(gh_hypercall_hyp_identify); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Gunyah Hypervisor Hypercalls"); diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig index 87ef258cec64..1c346f798ace 100644 --- a/drivers/virt/Kconfig +++ b/drivers/virt/Kconfig @@ -48,6 +48,8 @@ source "drivers/virt/nitro_enclaves/Kconfig" source "drivers/virt/acrn/Kconfig" +source "drivers/virt/gunyah/Kconfig" + source "drivers/virt/coco/efi_secret/Kconfig" source "drivers/virt/coco/sev-guest/Kconfig" diff --git a/drivers/virt/gunyah/Kconfig b/drivers/virt/gunyah/Kconfig new file mode 100644 index 000000000000..c1a621aaefc6 --- /dev/null +++ b/drivers/virt/gunyah/Kconfig @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config GUNYAH + tristate "Gunyah Virtualization drivers" + depends on ARM64 + select AUXILIARY_BUS + help + The Gunyah drivers are the helper interfaces that runs in a guest VM + such as basic inter-VM IPC and signaling mechanism,s and higher level + services such as memory/device sharing, IRQ sharing, and so on. + + Say Y/M here to enable the drivers needed to interact in a Gunyah + virtual environment. diff --git a/include/asm-generic/gunyah.h b/include/asm-generic/gunyah.h index 64a02dd3b5ad..86eb59e203ef 100644 --- a/include/asm-generic/gunyah.h +++ b/include/asm-generic/gunyah.h @@ -71,4 +71,40 @@ static inline int gh_remap_error(int gh_error) } } +#define QC_HYP_UID0 0x19bd54bd +#define QC_HYP_UID1 0x0b37571b +#define QC_HYP_UID2 0x946f609b +#define QC_HYP_UID3 0x54539de6 + +#define GUNYAH_UID0 0x673d5f14 +#define GUNYAH_UID1 0x9265ce36 +#define GUNYAH_UID2 0xa4535fdb +#define GUNYAH_UID3 0xc1d58fcd + +#define gh_uid_matches(prefix, uid) \ + ((uid)[0] == prefix ## _UID0 && (uid)[1] == prefix ## _UID1 && \ + (uid)[2] == prefix ## _UID2 && (uid)[3] == prefix ## _UID3) + +#define GH_API_INFO_API_VERSION(x) (((x) >> 0) & 0x3fff) +#define GH_API_INFO_BIG_ENDIAN(x) (((x) >> 14) & 1) +#define GH_API_INFO_IS_64BIT(x) (((x) >> 15) & 1) +#define GH_API_INFO_VARIANT(x) (((x) >> 56) & 0xff) + +#define GH_IDENTIFY_PARTITION_CSPACE(flags) (((flags)[0] >> 0) & 1) +#define GH_IDENTIFY_DOORBELL(flags) (((flags)[0] >> 1) & 1) +#define GH_IDENTIFY_MSGQUEUE(flags) (((flags)[0] >> 2) & 1) +#define GH_IDENTIFY_VIC(flags) (((flags)[0] >> 3) & 1) +#define GH_IDENTIFY_VPM(flags) (((flags)[0] >> 4) & 1) +#define GH_IDENTIFY_VCPU(flags) (((flags)[0] >> 5) & 1) +#define GH_IDENTIFY_MEMEXTENT(flags) (((flags)[0] >> 6) & 1) +#define GH_IDENTIFY_TRACE_CTRL(flags) (((flags)[0] >> 7) & 1) + +struct gh_hypercall_hyp_identify_resp { + u64 api_info; + u64 flags[3]; +}; + +void gh_hypercall_get_uid(u32 *uid); +void gh_hypercall_hyp_identify(struct gh_hypercall_hyp_identify_resp *hyp_identity); + #endif From patchwork Thu Aug 11 21:41:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 596706 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B994C3F6B0 for ; Thu, 11 Aug 2022 21:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236162AbiHKV4I (ORCPT ); Thu, 11 Aug 2022 17:56:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236086AbiHKV4E (ORCPT ); Thu, 11 Aug 2022 17:56:04 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D34B67CBF; Thu, 11 Aug 2022 14:56:03 -0700 (PDT) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27BLkYSm017425; Thu, 11 Aug 2022 21:55:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=o32zkpwWp2BJgilgcohYN9jdVJI5EyHrbrja1y46rII=; b=L89/jB7iMggjOdpPzsFuSbsnir/rN7KauAfCr/r+BkmW5pXvfG3dbVw9kiUiVqlgT+H7 hjx8s8ubWKc7UquxaT3Y5l4GJ+r2vs9B4qamg3aOTjXXEZTJ5CIj7GklIZKa3tnCmZ7D 8Dy4lOn7dK5C0abWAeqpXlgLt+Q3RDYtgCb0ZN8nA7ivo3QS+dDhARsCFU+woaIDwgvk V72p2knWMQVMwEejJln/JNM1f3KZonLfcue4wfH+NXTfPwqtsoz7R5H7ytKRmoHzKine orLQbbxzW+Tkk6lXD6U+o4Uf0DwKeKPQ+y1a1HRHm1NQ8y4VuKGqfIwpuR1mtpn2JL/+ AA== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3hv95ywwyv-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Aug 2022 21:55:55 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 27BLfxwD018010 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Aug 2022 21:41:59 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Thu, 11 Aug 2022 14:41:57 -0700 From: Elliot Berman To: Bjorn Andersson CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , , "Mark Rutland" , Lorenzo Pieralisi , Sudeep Holla , "Marc Zyngier" , Rob Herring , "Krzysztof Kozlowski" , Jonathan Corbet , Will Deacon , Catalin Marinas , , , Subject: [PATCH v3 06/12] virt: gunyah: Add sysfs nodes Date: Thu, 11 Aug 2022 14:41:01 -0700 Message-ID: <20220811214107.1074343-7-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220811214107.1074343-1-quic_eberman@quicinc.com> References: <20220811214107.1074343-1-quic_eberman@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: ICSVZdz8PXV-Pzra8Pl6HqA7xOWDyZcn X-Proofpoint-GUID: ICSVZdz8PXV-Pzra8Pl6HqA7xOWDyZcn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-11_13,2022-08-11_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 adultscore=0 bulkscore=0 impostorscore=0 suspectscore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208110066 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add /sys/hypervisor support when detecting that Linux is running in a Gunyah environment. Export the version of Gunyah which is reported via the hyp_identify hypercall. Signed-off-by: Elliot Berman --- .../ABI/testing/sysfs-hypervisor-gunyah | 23 +++++ MAINTAINERS | 1 + drivers/virt/Makefile | 1 + drivers/virt/gunyah/Makefile | 2 + drivers/virt/gunyah/sysfs.c | 87 +++++++++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-hypervisor-gunyah create mode 100644 drivers/virt/gunyah/Makefile create mode 100644 drivers/virt/gunyah/sysfs.c diff --git a/Documentation/ABI/testing/sysfs-hypervisor-gunyah b/Documentation/ABI/testing/sysfs-hypervisor-gunyah new file mode 100644 index 000000000000..219465783a9e --- /dev/null +++ b/Documentation/ABI/testing/sysfs-hypervisor-gunyah @@ -0,0 +1,23 @@ +What: /sys/hypervisor/type +Date: August 2022 +KernelVersion: 6.0 +Contact: linux-arm-msm@vger.kernel.org +Description: If running under Gunyah: + Type of hypervisor: + "gunyah": Gunyah hypervisor + +What: /sys/hypervisor/gunyah/api +Date: August 2022 +KernelVersion: 6.0 +Contact: linux-arm-msm@vger.kernel.org +Description: If running under Gunyah: + The Gunyah API version. + +What: /sys/hypervisor/gunyah/variant +Date: August 2022 +KernelVersion: 6.0 +Contact: linux-arm-msm@vger.kernel.org +Description: If running under Gunyah: + The Gunyah variant (build) version. + The open source build of Gunyah will report "81". + The Qualcomm build of Gunyah will report "72". diff --git a/MAINTAINERS b/MAINTAINERS index f5d5ebb62701..c774bbcdb348 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8739,6 +8739,7 @@ M: Elliot Berman M: Murali Nalajala L: linux-arm-msm@vger.kernel.org S: Supported +F: Documentation/ABI/testing/sysfs-hypervisor-gunyah F: Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml F: Documentation/virt/gunyah/ F: arch/arm64/gunyah/ diff --git a/drivers/virt/Makefile b/drivers/virt/Makefile index 093674e05c40..5cd759f60122 100644 --- a/drivers/virt/Makefile +++ b/drivers/virt/Makefile @@ -9,5 +9,6 @@ obj-y += vboxguest/ obj-$(CONFIG_NITRO_ENCLAVES) += nitro_enclaves/ obj-$(CONFIG_ACRN_HSM) += acrn/ +obj-$(CONFIG_GUNYAH) += gunyah/ obj-$(CONFIG_EFI_SECRET) += coco/efi_secret/ obj-$(CONFIG_SEV_GUEST) += coco/sev-guest/ diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile new file mode 100644 index 000000000000..e15f16c17142 --- /dev/null +++ b/drivers/virt/gunyah/Makefile @@ -0,0 +1,2 @@ +gunyah-y += sysfs.o +obj-$(CONFIG_GUNYAH) += gunyah.o diff --git a/drivers/virt/gunyah/sysfs.c b/drivers/virt/gunyah/sysfs.c new file mode 100644 index 000000000000..9de700fdbfcb --- /dev/null +++ b/drivers/virt/gunyah/sysfs.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#define pr_fmt(fmt) "gunyah: " fmt + +#include +#include +#include +#include +#include + +static struct gh_hypercall_hyp_identify_resp gunyah_api; + +static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer) +{ + return sysfs_emit(buffer, "gunyah\n"); +} +static struct kobj_attribute type_attr = __ATTR_RO(type); + +static ssize_t api_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer) +{ + return sysfs_emit(buffer, "%d\n", (int)GH_API_INFO_API_VERSION(gunyah_api.api_info)); +} +static struct kobj_attribute api_attr = __ATTR_RO(api); + +static ssize_t variant_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer) +{ + return sysfs_emit(buffer, "%d\n", (int)GH_API_INFO_VARIANT(gunyah_api.api_info)); +} +static struct kobj_attribute variant_attr = __ATTR_RO(variant); + +static struct attribute *gunyah_attrs[] = { + &api_attr.attr, + &variant_attr.attr, + NULL +}; + +static const struct attribute_group gunyah_group = { + .name = "gunyah", + .attrs = gunyah_attrs, +}; + +static int __init gunyah_init(void) +{ + int ret; + u32 uid[4]; + + gh_hypercall_get_uid(uid); + + if (!(gh_uid_matches(GUNYAH, uid) || gh_uid_matches(QC_HYP, uid))) + return 0; + + gh_hypercall_hyp_identify(&gunyah_api); + + if (GH_API_INFO_API_VERSION(gunyah_api.api_info) != 1) { + pr_warn("Unrecognized gunyah version: %llu. Currently supported: 1\n", + GH_API_INFO_API_VERSION(gunyah_api.api_info)); + return 0; + } + + pr_notice("Running under Gunyah hypervisor %llx/v%lld\n", + GH_API_INFO_VARIANT(gunyah_api.api_info), + GH_API_INFO_API_VERSION(gunyah_api.api_info)); + + ret = sysfs_create_file(hypervisor_kobj, &type_attr.attr); + if (ret) + return ret; + + ret = sysfs_create_group(hypervisor_kobj, &gunyah_group); + if (ret) + sysfs_remove_file(hypervisor_kobj, &type_attr.attr); + + return ret; +} +module_init(gunyah_init); + +static void __exit gunyah_exit(void) +{ + sysfs_remove_group(hypervisor_kobj, &gunyah_group); + sysfs_remove_file(hypervisor_kobj, &type_attr.attr); +} +module_exit(gunyah_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Gunyah Hypervisor Driver"); From patchwork Thu Aug 11 21:41:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 596710 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 707CEC25B06 for ; Thu, 11 Aug 2022 21:42:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234493AbiHKVmT (ORCPT ); Thu, 11 Aug 2022 17:42:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234075AbiHKVmR (ORCPT ); Thu, 11 Aug 2022 17:42:17 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E869B9F0F0; Thu, 11 Aug 2022 14:42:15 -0700 (PDT) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27BLFZ1h013925; Thu, 11 Aug 2022 21:42:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=NC33KSDXeB0LL2tYGcYNxEW9CS++jQkTREdYC0ffEL0=; b=fSgdBBzUBzsn5L6/FpA8T10erwEGg/Ayh6QlYcn1RnQvIIVoyt06BDugVt02D5aEShNK TNMdVJnI8o+7qLbaH8T6vcaWTKqj9PWXoPqVLYHbfiesZnlDJWJbpYjDVPNxWKSpJylV q4UGr3sM6auh//vSiWz7vhKCYRMut32XmjgYvaPPcM7XzsP/IyuzEQWoMJ1TUJ4sfU6C RCiodTAsbKyuDJp1CbB56RJ6CntI7AaD5WuyNxnHmUEVhg+rPAWyVG2bYyCmUJrzWnUO Ke0O3bOGc/dAiAMRhdYzJNVV7a22IbwGanMsU6mGrldwPYwrvnvAQRol4nWKY/I+pBvI lA== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3hw89x06bd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Aug 2022 21:42:00 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 27BLfxFJ022590 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Aug 2022 21:41:59 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Thu, 11 Aug 2022 14:41:58 -0700 From: Elliot Berman To: Bjorn Andersson CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , , "Mark Rutland" , Lorenzo Pieralisi , Sudeep Holla , "Marc Zyngier" , Rob Herring , "Krzysztof Kozlowski" , Jonathan Corbet , Will Deacon , Catalin Marinas , , , Subject: [PATCH v3 07/12] gunyah: msgq: Add Gunyah message queues Date: Thu, 11 Aug 2022 14:41:02 -0700 Message-ID: <20220811214107.1074343-8-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220811214107.1074343-1-quic_eberman@quicinc.com> References: <20220811214107.1074343-1-quic_eberman@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: dvf0Z2EvkNI-qO9eH5r2peMTnSVRPqBl X-Proofpoint-ORIG-GUID: dvf0Z2EvkNI-qO9eH5r2peMTnSVRPqBl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-11_13,2022-08-11_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 phishscore=0 clxscore=1015 spamscore=0 suspectscore=0 impostorscore=0 priorityscore=1501 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208110065 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Gunyah message queues are unidirectional pipelines to communicate between 2 virtual machines, but are typically paired to allow bidirectional communication. The intended use case is for small control messages between 2 VMs, as they support a maximum of 1024 bytes. Signed-off-by: Elliot Berman --- MAINTAINERS | 1 + arch/arm64/gunyah/hypercall.c | 33 ++++++ drivers/virt/gunyah/Makefile | 2 +- drivers/virt/gunyah/msgq.c | 192 ++++++++++++++++++++++++++++++++++ include/asm-generic/gunyah.h | 5 + include/linux/gunyah.h | 71 +++++++++++++ 6 files changed, 303 insertions(+), 1 deletion(-) create mode 100644 drivers/virt/gunyah/msgq.c create mode 100644 include/linux/gunyah.h diff --git a/MAINTAINERS b/MAINTAINERS index c774bbcdb348..444891e02546 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8745,6 +8745,7 @@ F: Documentation/virt/gunyah/ F: arch/arm64/gunyah/ F: drivers/virt/gunyah/ F: include/asm-generic/gunyah.h +F: include/linux/gunyah.h HABANALABS PCI DRIVER M: Oded Gabbay diff --git a/arch/arm64/gunyah/hypercall.c b/arch/arm64/gunyah/hypercall.c index 5b08c9d80de0..042cca31879e 100644 --- a/arch/arm64/gunyah/hypercall.c +++ b/arch/arm64/gunyah/hypercall.c @@ -26,6 +26,8 @@ | ((fn) & GH_CALL_FUNCTION_NUM_MASK)) #define GH_HYPERCALL_HYP_IDENTIFY GH_HYPERCALL(0x0000) +#define GH_HYPERCALL_MSGQ_SEND GH_HYPERCALL(0x001B) +#define GH_HYPERCALL_MSGQ_RECV GH_HYPERCALL(0x001C) /** * gh_hypercall_get_uid() - Returns a UID when running under a Gunyah hypervisor. @@ -67,5 +69,36 @@ void gh_hypercall_hyp_identify(struct gh_hypercall_hyp_identify_resp *hyp_identi } EXPORT_SYMBOL_GPL(gh_hypercall_hyp_identify); +int gh_hypercall_msgq_send(u64 capid, size_t size, uintptr_t buff, int tx_flags, bool *ready) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_hvc(GH_HYPERCALL_MSGQ_SEND, capid, size, buff, tx_flags, 0, &res); + + if (res.a0) + return res.a0; + + *ready = res.a1; + + return res.a0; +} +EXPORT_SYMBOL_GPL(gh_hypercall_msgq_send); + +int gh_hypercall_msgq_recv(u64 capid, uintptr_t buff, size_t size, size_t *recv_size, bool *ready) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_hvc(GH_HYPERCALL_MSGQ_RECV, capid, buff, size, 0, &res); + + if (res.a0) + return res.a0; + + *recv_size = res.a1; + *ready = res.a2; + + return res.a0; +} +EXPORT_SYMBOL_GPL(gh_hypercall_msgq_recv); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Gunyah Hypervisor Hypercalls"); diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile index e15f16c17142..3c7efd2220c1 100644 --- a/drivers/virt/gunyah/Makefile +++ b/drivers/virt/gunyah/Makefile @@ -1,2 +1,2 @@ -gunyah-y += sysfs.o +gunyah-y += sysfs.o msgq.o obj-$(CONFIG_GUNYAH) += gunyah.o diff --git a/drivers/virt/gunyah/msgq.c b/drivers/virt/gunyah/msgq.c new file mode 100644 index 000000000000..05c3d90ac1ed --- /dev/null +++ b/drivers/virt/gunyah/msgq.c @@ -0,0 +1,192 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include + +static irqreturn_t gh_msgq_irq_handler(int irq, void *data) +{ + struct gunyah_msgq *msgq = data; + void (*on_ready)(struct gunyah_msgq *msgq); + + spin_lock(&msgq->lock); + msgq->ready = true; + on_ready = msgq->on_ready; + spin_unlock(&msgq->lock); + + if (on_ready) + on_ready(msgq); + + wake_up_interruptible_all(&msgq->wq); + + return IRQ_HANDLED; +} + +static int __gh_msgq_send(struct gunyah_msgq *msgq, void *buff, size_t size, u64 tx_flags) +{ + unsigned long flags, gh_err; + ssize_t ret; + bool ready; + + spin_lock_irqsave(&msgq->lock, flags); + gh_err = gh_hypercall_msgq_send(msgq->ghdev.capid, size, (uintptr_t)buff, tx_flags, &ready); + switch (gh_err) { + case GH_ERROR_OK: + ret = 0; + msgq->ready = ready; + break; + case GH_ERROR_MSGQUEUE_FULL: + ret = -EAGAIN; + msgq->ready = false; + break; + default: + ret = gh_remap_error(gh_err); + break; + } + spin_unlock_irqrestore(&msgq->lock, flags); + + return ret; +} + +/** + * gh_msgq_send() - Send a message to the client running on a different VM + * @client: The client descriptor that was obtained via gh_msgq_register() + * @buff: Pointer to the buffer where the received data must be placed + * @buff_size: The size of the buffer space available + * @flags: Optional flags to pass to receive the data. For the list of flags, + * see linux/gunyah/gh_msgq.h + * + * Returns: The number of bytes copied to buff. <0 if there was an error. + * + * Note: this function may sleep and should not be called from interrupt context + */ +ssize_t gh_msgq_send(struct gunyah_msgq *msgq, void *buff, size_t size, const unsigned long flags) +{ + ssize_t ret; + u64 tx_flags = 0; + + if (unlikely(msgq->ghdev.type != GUNYAH_DEVICE_TYPE_MSGQ_TX)) + return -EINVAL; + + if (flags & GH_MSGQ_TX_PUSH) + tx_flags |= GH_HYPERCALL_MSGQ_TX_FLAGS_PUSH; + + do { + ret = __gh_msgq_send(msgq, buff, size, tx_flags); + + if (ret == -EAGAIN) { + if (flags & GH_MSGQ_NONBLOCK) + goto out; + if (wait_event_interruptible(msgq->wq, msgq->ready)) + ret = -ERESTARTSYS; + } + } while (ret == -EAGAIN); + +out: + return ret; +} +EXPORT_SYMBOL_GPL(gh_msgq_send); + +static ssize_t __gh_msgq_recv(struct gunyah_msgq *msgq, void *buff, size_t size) +{ + unsigned long flags, gh_err; + size_t recv_size; + ssize_t ret; + bool ready; + + spin_lock_irqsave(&msgq->lock, flags); + + gh_err = gh_hypercall_msgq_recv(msgq->ghdev.capid, (uintptr_t)buff, size, + &recv_size, &ready); + switch (gh_err) { + case GH_ERROR_OK: + ret = recv_size; + msgq->ready = ready; + break; + case GH_ERROR_MSGQUEUE_EMPTY: + ret = -EAGAIN; + msgq->ready = false; + break; + default: + ret = gh_remap_error(gh_err); + break; + } + spin_unlock_irqrestore(&msgq->lock, flags); + + return ret; +} + +/** + * gh_msgq_recv() - Receive a message from the client running on a different VM + * @client: The client descriptor that was obtained via gh_msgq_register() + * @buff: Pointer to the buffer where the received data must be placed + * @buff_size: The size of the buffer space available + * @flags: Optional flags to pass to receive the data. For the list of flags, + * see linux/gunyah/gh_msgq.h + * + * Returns: The number of bytes copied to buff. <0 if there was an error. + * + * Note: this function may sleep and should not be called from interrupt context + */ +ssize_t gh_msgq_recv(struct gunyah_msgq *msgq, void *buff, size_t size, const unsigned long flags) +{ + ssize_t ret; + + if (unlikely(msgq->ghdev.type != GUNYAH_DEVICE_TYPE_MSGQ_RX)) + return -EINVAL; + + do { + ret = __gh_msgq_recv(msgq, buff, size); + + if (ret == -EAGAIN) { + if (flags & GH_MSGQ_NONBLOCK) + goto out; + if (wait_event_interruptible(msgq->wq, msgq->ready)) + ret = -ERESTARTSYS; + } + } while (ret == -EAGAIN); + +out: + return ret; +} +EXPORT_SYMBOL_GPL(gh_msgq_recv); + +struct gunyah_msgq *__gunyah_msgq_alloc(enum gunyah_device_type type, u64 capid, int irq) +{ + struct gunyah_msgq *msgq; + int ret; + + msgq = kzalloc(sizeof(*msgq), GFP_KERNEL); + if (!msgq) + return NULL; + + msgq->ghdev.type = type; + msgq->ghdev.capid = capid; + msgq->ghdev.irq = irq; + + msgq->ready = true; /* Assume we can use the message queue right away */ + init_waitqueue_head(&msgq->wq); + spin_lock_init(&msgq->lock); + + ret = request_irq(msgq->ghdev.irq, gh_msgq_irq_handler, 0, "gh_msgq", msgq); + if (WARN(ret, "Failed to request message queue irq %d: %d\n", irq, ret)) { + kfree(msgq); + return NULL; + } + + return msgq; +} +EXPORT_SYMBOL_GPL(__gunyah_msgq_alloc); + +void gunyah_msgq_free(struct gunyah_msgq *msgq) +{ + free_irq(msgq->ghdev.irq, msgq); + kfree(msgq); +} +EXPORT_SYMBOL_GPL(gunyah_msgq_free); diff --git a/include/asm-generic/gunyah.h b/include/asm-generic/gunyah.h index 86eb59e203ef..43915faea704 100644 --- a/include/asm-generic/gunyah.h +++ b/include/asm-generic/gunyah.h @@ -107,4 +107,9 @@ struct gh_hypercall_hyp_identify_resp { void gh_hypercall_get_uid(u32 *uid); void gh_hypercall_hyp_identify(struct gh_hypercall_hyp_identify_resp *hyp_identity); +#define GH_HYPERCALL_MSGQ_TX_FLAGS_PUSH BIT(0) + +int gh_hypercall_msgq_send(u64 capid, size_t size, uintptr_t buff, int tx_flags, bool *ready); +int gh_hypercall_msgq_recv(u64 capid, uintptr_t buff, size_t size, size_t *recv_size, bool *ready); + #endif diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h new file mode 100644 index 000000000000..57e83b0d78cf --- /dev/null +++ b/include/linux/gunyah.h @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef _GUNYAH_H +#define _GUNYAH_H + +#include + +/* Follows resource manager's resource types for VM_GET_HYP_RESOURCES */ +enum gunyah_device_type { + GUNYAH_DEVICE_TYPE_BELL_TX = 0, + GUNYAH_DEVICE_TYPE_BELL_RX = 1, + GUNYAH_DEVICE_TYPE_MSGQ_TX = 2, + GUNYAH_DEVICE_TYPE_MSGQ_RX = 3, + GUNYAH_DEVICE_TYPE_VCPU = 4, +}; + +struct gunyah_device { + enum gunyah_device_type type; + u64 capid; + int irq; +}; + +/** + * Gunyah Message Queues + */ + +struct gunyah_msgq { + struct gunyah_device ghdev; + + /* Set by the message queue client */ + void (*on_ready)(struct gunyah_msgq *msgq); + void *data; + + /* msgq private */ + bool ready; + wait_queue_head_t wq; + spinlock_t lock; +}; + +#define GH_MSGQ_MAX_MSG_SIZE 1024 + +/* Possible flags to pass for Tx or Rx */ +#define GH_MSGQ_TX_PUSH BIT(0) +#define GH_MSGQ_NONBLOCK BIT(32) + +static inline struct gunyah_msgq * __must_check to_gunyah_msgq(struct gunyah_device *ghdev) +{ + if (ghdev->type != GUNYAH_DEVICE_TYPE_BELL_TX && ghdev->type != GUNYAH_DEVICE_TYPE_BELL_RX) + return NULL; + return container_of(ghdev, struct gunyah_msgq, ghdev); +} + +ssize_t gh_msgq_send(struct gunyah_msgq *msgq, void *buff, size_t size, const unsigned long flags); +ssize_t gh_msgq_recv(struct gunyah_msgq *msgq, void *buff, size_t size, const unsigned long flags); +struct gunyah_msgq *__gunyah_msgq_alloc(enum gunyah_device_type type, u64 capid, int irq); +void gunyah_msgq_free(struct gunyah_msgq *msgq); + +static inline struct gunyah_msgq *gunyah_msgq_tx_alloc(u64 capid, int irq) +{ + return __gunyah_msgq_alloc(GUNYAH_DEVICE_TYPE_BELL_TX, capid, irq); +} + +static inline struct gunyah_msgq *gunyah_msgq_rx_alloc(u64 capid, int irq) +{ + return __gunyah_msgq_alloc(GUNYAH_DEVICE_TYPE_BELL_RX, capid, irq); +} + +#endif From patchwork Thu Aug 11 21:41:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 596707 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E850DC19F2A for ; Thu, 11 Aug 2022 21:47:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235639AbiHKVrN (ORCPT ); Thu, 11 Aug 2022 17:47:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235544AbiHKVrK (ORCPT ); Thu, 11 Aug 2022 17:47:10 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C945A9F195; Thu, 11 Aug 2022 14:47:09 -0700 (PDT) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27BLS6uQ018610; Thu, 11 Aug 2022 21:47:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=9SG6mHL+qXasSyzhyP5QHde46SeS4oqPOWl95Qbo4XQ=; b=UwgRTiD+AN97AbE8oJOqIVjOIYQ0f6WmAdhRjUZm1xaWYjyqo1fbhwRK/SWC7o1IJZho O61fwvnUtGs9j8RHogIF9Nr5hdw9f/Y2/DpVjWbk5mARrw/QTOVId+TSDQs646y8jkLN oKjopySZGv3AXtn7GtCqX27zdJkVvpH7IfiFyxp6knVWJ9wo+WUcadO7S3YzZ7TPAIF3 kRQ81VGPOQq0bvJGyf4v3d7zllwaDXffBLjRl9TSjhydIU2LorHqBGfjTLVNsdXVFwEG mOUqz5wABDCVLK1X6VkHDLf4RPl3YZjSHmbBbVkYP8GD6X4l3s2HxRKtubxuAeglBFv4 MQ== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3hw89x06rd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Aug 2022 21:47:02 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 27BLg2g0018084 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Aug 2022 21:42:02 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Thu, 11 Aug 2022 14:42:00 -0700 From: Elliot Berman To: Bjorn Andersson CC: Elliot Berman , Murali Nalajala , Trilok Soni , "Srivatsa Vaddagiri" , Carl van Schaik , Andy Gross , Dmitry Baryshkov , , "Mark Rutland" , Lorenzo Pieralisi , Sudeep Holla , "Marc Zyngier" , Rob Herring , "Krzysztof Kozlowski" , Jonathan Corbet , Will Deacon , Catalin Marinas , , , Subject: [PATCH v3 11/12] gunyah: rsc_mgr: Add auxiliary devices for console Date: Thu, 11 Aug 2022 14:41:06 -0700 Message-ID: <20220811214107.1074343-12-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220811214107.1074343-1-quic_eberman@quicinc.com> References: <20220811214107.1074343-1-quic_eberman@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: eVNwVEscxmphkOUGMwEPxREAQiw9Iq1U X-Proofpoint-ORIG-GUID: eVNwVEscxmphkOUGMwEPxREAQiw9Iq1U X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-11_13,2022-08-11_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 mlxlogscore=809 lowpriorityscore=0 phishscore=0 clxscore=1015 spamscore=0 suspectscore=0 impostorscore=0 priorityscore=1501 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208110065 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Gunyah resource manager exposes a concrete functionalities which complicate a single resource manager driver. Use auxiliary bus to help split high level functions for the resource manager and keep the primary resource manager driver focused on the RPC with RM itself. Delegate Resource Manager's console functionality to the auxiliary bus. Signed-off-by: Elliot Berman --- drivers/virt/gunyah/rsc_mgr.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/virt/gunyah/rsc_mgr.c b/drivers/virt/gunyah/rsc_mgr.c index 635bd7a52653..7a899deaae8f 100644 --- a/drivers/virt/gunyah/rsc_mgr.c +++ b/drivers/virt/gunyah/rsc_mgr.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -95,6 +96,8 @@ struct gh_rsc_mgr { struct mutex send_lock; struct work_struct recv_work; + + struct auxiliary_device console_adev; }; static struct gh_rsc_mgr *__rsc_mgr; @@ -572,8 +575,21 @@ static int gh_rm_drv_probe(struct platform_device *pdev) __rsc_mgr = rsc_mgr; + rsc_mgr->console_adev.dev.parent = &pdev->dev; + rsc_mgr->console_adev.name = "console"; + ret = auxiliary_device_init(&rsc_mgr->console_adev); + if (ret) + goto err_msgq; + ret = auxiliary_device_add(&rsc_mgr->console_adev); + if (ret) + goto err_console_adev_uninit; + return 0; +err_console_adev_uninit: + auxiliary_device_uninit(&rsc_mgr->console_adev); +err_msgq: + gunyah_msgq_free(rsc_mgr->msgq_rx); err_msgq_tx: gunyah_msgq_free(rsc_mgr->msgq_tx); return ret; @@ -583,6 +599,9 @@ static int gh_rm_drv_remove(struct platform_device *pdev) { struct gh_rsc_mgr *rsc_mgr = platform_get_drvdata(pdev); + auxiliary_device_delete(&rsc_mgr->console_adev); + auxiliary_device_uninit(&rsc_mgr->console_adev); + __rsc_mgr = NULL; gunyah_msgq_free(rsc_mgr->msgq_tx);