From patchwork Thu Feb 22 23:16:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13568233 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE8D9C54798 for ; Thu, 22 Feb 2024 23:17:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 142386B008A; Thu, 22 Feb 2024 18:16:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CAF66B008C; Thu, 22 Feb 2024 18:16:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A19DD6B008A; Thu, 22 Feb 2024 18:16:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5AEB46B008A for ; Thu, 22 Feb 2024 18:16:45 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A94D0140F56 for ; Thu, 22 Feb 2024 23:16:44 +0000 (UTC) X-FDA: 81821001528.02.3A47623 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf06.hostedemail.com (Postfix) with ESMTP id 8C7FF18001B for ; Thu, 22 Feb 2024 23:16:42 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=m667LTrq; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf06.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708643802; a=rsa-sha256; cv=none; b=VsONHJnb1TG+4Lbvj/SCOwIZjF/p1uLV9Kap/8gfwycgd7skTwehUniBdtffAqlC2jN/Ao uKt8Yf3yeZUZMjwkIde/VfpZkuUnWhQOZ8TPoTPIjXk1uMJmQ6AxTmJHpdWXU5eo/4WoB4 HayhLRKTx7SM0oRsBIk/ROiJfPtaUD8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=m667LTrq; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf06.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708643802; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RFrpvK2ncCEA3pXuIWUNixiWOQ+1QGG1zWVmRqVDqG8=; b=JEVSmsYF0yqhK22/geuXpKu6s/KT98DUNN4e2wbolBClq4nSXqNwL3TcJkkc0jGFS6mqvT RF+LRQg3RAAjUSHxzRPoamRCMEmat6ekwHHublmMeiymWeUW3qs4a12HybdShC54vrxu/x Rlm9JFZz6hb43tHL6dBH0C6D1KBraco= Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41MMT6YA003866; Thu, 22 Feb 2024 23:16:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=RFrpvK2ncCEA3pXuIWUNixiWOQ+1QGG1zWVmRqVDqG8 =; b=m667LTrq+pQJLoeLwUiFbZ0WPVvbpUz5ZSQJDDs4ROMQCrDYiIXVFCZyxki cVaDNfVvESh1i9Zspzzi616cDjC7uJFMM7/ODi708TpmEPNFUn8BMPZ091pfYeQZ 29gIVYlJ9JGklhmafgN7G+x0SdMWWfbsI2TpBkenD32XIlta06RMgNn3cdFyNQUO ZOFoRx5O8ShU/ftSzzSwyU203n9y3oYGMIqJNuhH31ZY8L2A7ikNicrRTMoPMnIl aILlKE8i0Y2dZtlz2ruBErITN9jX7A+jNAeYuLNFWfBMGVwaElRqjZUVpmr3BCeV T8IYqbA7A2AULng+NtaJ7/T7yyw== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wdvwwbj6w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:34 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41MNGXdK015985 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 23:16:33 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.1118.40; Thu, 22 Feb 2024 15:16:32 -0800 From: Elliot Berman Date: Thu, 22 Feb 2024 15:16:34 -0800 Subject: [PATCH v17 11/35] virt: gunyah: Translate gh_rm_hyp_resource into gunyah_resource MIME-Version: 1.0 Message-ID: <20240222-gunyah-v17-11-1e9da6763d38@quicinc.com> References: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> In-Reply-To: <20240222-gunyah-v17-0-1e9da6763d38@quicinc.com> To: Alex Elder , Srinivas Kandagatla , Murali Nalajal , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Philip Derrin , Prakruthi Deepak Heragu , Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Catalin Marinas , Will Deacon , Konrad Dybcio , Bjorn Andersson , Dmitry Baryshkov , "Fuad Tabba" , Sean Christopherson , "Andrew Morton" CC: , , , , , , Elliot Berman X-Mailer: b4 0.12.4 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) 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: qeUnMGLImSCMNFcN-vw0JZKmgk1Qogf9 X-Proofpoint-GUID: qeUnMGLImSCMNFcN-vw0JZKmgk1Qogf9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 spamscore=0 impostorscore=0 mlxlogscore=952 clxscore=1015 phishscore=0 adultscore=0 suspectscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402220179 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8C7FF18001B X-Stat-Signature: yb5f4oqw4mnt3pzzmfpasa94od66wt6k X-HE-Tag: 1708643802-622100 X-HE-Meta: U2FsdGVkX1/4sygpI+yylCcNZkpxV86aonsTcmnGbpv4e7K05xWMqRDGO1HLOlnoKGiwm/uojYHGEjyud4AdGbdGE/g+nTtPXwYVMmPKJijg3z0CMqxhniJYmYqt6qTp5/WUCUwhuXCEmB5AEL2vSfxQl8OpXTTUkhuu61Hc2gImJ2t7tpYs/qjpUBZqdatZN9seeAFsGT36RWVFBtLmLc2sp4nxRNyj1ph/ZU+v0tfSh5RdG4XN//CgFUYeRvK5sIBmLXHoENxH+UwYc4ddYHs1LCHBjJ1ZlcUdkAG5/nyWLrg1CEqGmeJLuLkYz+Zqo9mWarE0vwDxxRmU13bC3b4Wqo0JWA+MRLH21madoQiMtlqYigho87ZlmKZqE43PLTEXQYHk/1oaNYiX7HaxZvPTOQEPSRHkDu/t1I06CkF9Uwo6NpwPJyRE1qJXxC/qqwZCdwgu+tTNdJFYJeuD4BxGf45cl/vF+oqoTW+cecGCJqB5XYAYUAYplI6NLqf2rW43w/HkT+nnqEzA38eW/TeG5weLg43pL0RWgPo8fakqTJlSth0o1jCNivn3QlRtA3uB0hn0mnLcSben1vuVv22FkveWSvdCz9A72rP22Cv90OEtmHla/wgHYChnPrsIjKgY/3wfAi3qz9v5eWn7ZWUD3iZ4S7gjjENQBHrTRPcMQkVK5TYkiN7UE14LxAa6fBZPziwTDEt0xajmfu9Af+dLmsp6KQMyazwGqW0y/ICP3KOb7m9YtEmJ8Jvr9ltuqhC1fEWWtrg/rScnmXRSQPppW2jtX+rijH43nDiAONcyTjeB7TO5ZgWSgxbZJyhxDC93ftVwIyQx0LgOQT8sJSI70poV2QPiXmStQ3J5g3hQJmDattITcRMcxxaOn5PVhF2rwRfwvAAuqpStnUAb/lO+ymZBDxS5xLMlPbTuNocDqnVlKcReIanIE5Ro+Tuef3jtYZAQn3qjt9hv9Yr 5rE0BAKT Tapf+epNTG39nzc26ykbSeUEcmPHQKUFn3cG3 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When booting a Gunyah virtual machine, the host VM may gain capabilities to interact with resources for the guest virtual machine. Examples of such resources are vCPUs or message queues. To use those resources, we need to translate the RM response into a gunyah_resource structure which are useful to Linux drivers. Presently, Linux drivers need only to know the type of resource, the capability ID, and an interrupt. On ARM64 systems, the interrupt reported by Gunyah is the GIC interrupt ID number and always a SPI or extended SPI. Signed-off-by: Elliot Berman Reviewed-by: Srivatsa Vaddagiri --- arch/arm64/include/asm/gunyah.h | 36 ++++++++++++++++++++++ drivers/virt/gunyah/rsc_mgr.c | 67 +++++++++++++++++++++++++++++++++++++++++ drivers/virt/gunyah/rsc_mgr.h | 5 +++ include/linux/gunyah.h | 2 ++ 4 files changed, 110 insertions(+) diff --git a/arch/arm64/include/asm/gunyah.h b/arch/arm64/include/asm/gunyah.h new file mode 100644 index 0000000000000..0cd3debe22b64 --- /dev/null +++ b/arch/arm64/include/asm/gunyah.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ +#ifndef _ASM_GUNYAH_H +#define _ASM_GUNYAH_H + +#include +#include + +static inline int arch_gunyah_fill_irq_fwspec_params(u32 virq, + struct irq_fwspec *fwspec) +{ + /* Assume that Gunyah gave us an SPI or ESPI; defensively check it */ + if (WARN(virq < 32, "Unexpected virq: %d\n", virq)) { + return -EINVAL; + } else if (virq <= 1019) { + fwspec->param_count = 3; + fwspec->param[0] = 0; /* GIC_SPI */ + fwspec->param[1] = virq - 32; /* virq 32 -> SPI 0 */ + fwspec->param[2] = IRQ_TYPE_EDGE_RISING; + } else if (WARN(virq < 4096, "Unexpected virq: %d\n", virq)) { + return -EINVAL; + } else if (virq < 5120) { + fwspec->param_count = 3; + fwspec->param[0] = 2; /* GIC_ESPI */ + fwspec->param[1] = virq - 4096; /* virq 4096 -> ESPI 0 */ + fwspec->param[2] = IRQ_TYPE_EDGE_RISING; + } else { + WARN(1, "Unexpected virq: %d\n", virq); + return -EINVAL; + } + return 0; +} + +#endif diff --git a/drivers/virt/gunyah/rsc_mgr.c b/drivers/virt/gunyah/rsc_mgr.c index fb0efe68f0e22..c320c9ceaf8ac 100644 --- a/drivers/virt/gunyah/rsc_mgr.c +++ b/drivers/virt/gunyah/rsc_mgr.c @@ -9,9 +9,12 @@ #include #include #include +#include #include #include +#include + #include "rsc_mgr.h" #include "vm_mgr.h" @@ -121,6 +124,7 @@ struct gunyah_rm_message { * @send_ready: completed when we know Tx message queue can take more messages * @nh: notifier chain for clients interested in RM notification messages * @miscdev: /dev/gunyah + * @parent_fwnode: Parent IRQ fwnode to translate Gunyah hwirqs to Linux irqs */ struct gunyah_rm { struct device *dev; @@ -138,6 +142,7 @@ struct gunyah_rm { struct blocking_notifier_head nh; struct miscdevice miscdev; + struct fwnode_handle *parent_fwnode; }; /** @@ -178,6 +183,53 @@ static inline int gunyah_rm_error_remap(enum gunyah_rm_error rm_error) } } +struct gunyah_resource * +gunyah_rm_alloc_resource(struct gunyah_rm *rm, + struct gunyah_rm_hyp_resource *hyp_resource) +{ + struct gunyah_resource *ghrsc; + int ret; + + ghrsc = kzalloc(sizeof(*ghrsc), GFP_KERNEL); + if (!ghrsc) + return NULL; + + ghrsc->type = hyp_resource->type; + ghrsc->capid = le64_to_cpu(hyp_resource->cap_id); + ghrsc->irq = IRQ_NOTCONNECTED; + ghrsc->rm_label = le32_to_cpu(hyp_resource->resource_label); + if (hyp_resource->virq) { + struct irq_fwspec fwspec; + + + fwspec.fwnode = rm->parent_fwnode; + ret = arch_gunyah_fill_irq_fwspec_params(le32_to_cpu(hyp_resource->virq), &fwspec); + if (ret) { + dev_err(rm->dev, + "Failed to translate interrupt for resource %d label: %d: %d\n", + ghrsc->type, ghrsc->rm_label, ret); + } + + ret = irq_create_fwspec_mapping(&fwspec); + if (ret < 0) { + dev_err(rm->dev, + "Failed to allocate interrupt for resource %d label: %d: %d\n", + ghrsc->type, ghrsc->rm_label, ret); + kfree(ghrsc); + return NULL; + } + ghrsc->irq = ret; + } + + return ghrsc; +} + +void gunyah_rm_free_resource(struct gunyah_resource *ghrsc) +{ + irq_dispose_mapping(ghrsc->irq); + kfree(ghrsc); +} + static int gunyah_rm_init_message_payload(struct gunyah_rm_message *message, const void *msg, size_t hdr_size, size_t msg_size) @@ -707,6 +759,7 @@ static int gunyah_rm_probe_rx_msgq(struct gunyah_rm *rm, static int gunyah_rm_probe(struct platform_device *pdev) { + struct device_node *parent_irq_node; struct gunyah_rm *rm; int ret; @@ -734,6 +787,20 @@ static int gunyah_rm_probe(struct platform_device *pdev) if (ret) return ret; + parent_irq_node = of_irq_find_parent(pdev->dev.of_node); + if (!parent_irq_node) { + dev_err(&pdev->dev, + "Failed to find interrupt parent of resource manager\n"); + return -ENODEV; + } + + rm->parent_fwnode = of_node_to_fwnode(parent_irq_node); + if (!rm->parent_fwnode) { + dev_err(&pdev->dev, + "Failed to find interrupt parent domain of resource manager\n"); + return -ENODEV; + } + rm->miscdev.parent = &pdev->dev; rm->miscdev.name = "gunyah"; rm->miscdev.minor = MISC_DYNAMIC_MINOR; diff --git a/drivers/virt/gunyah/rsc_mgr.h b/drivers/virt/gunyah/rsc_mgr.h index 205b9ea735e53..52711de77bb79 100644 --- a/drivers/virt/gunyah/rsc_mgr.h +++ b/drivers/virt/gunyah/rsc_mgr.h @@ -99,6 +99,11 @@ struct gunyah_rm_hyp_resources { int gunyah_rm_get_hyp_resources(struct gunyah_rm *rm, u16 vmid, struct gunyah_rm_hyp_resources **resources); +struct gunyah_resource * +gunyah_rm_alloc_resource(struct gunyah_rm *rm, + struct gunyah_rm_hyp_resource *hyp_resource); +void gunyah_rm_free_resource(struct gunyah_resource *ghrsc); + int gunyah_rm_call(struct gunyah_rm *rsc_mgr, u32 message_id, const void *req_buf, size_t req_buf_size, void **resp_buf, size_t *resp_buf_size); diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index acd70f9824253..45033bdb5e151 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -29,6 +29,8 @@ struct gunyah_resource { enum gunyah_resource_type type; u64 capid; unsigned int irq; + + u32 rm_label; }; /******************************************************************************/