Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp650810rdb; Thu, 22 Feb 2024 15:26:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX9366MMjGjbheh9566hjgJdHzwX4SWihNptuhru+kIVcQG9ddWlR+0WENWcF+dpLExyZUYaJtaAxISEVbaybut/+GBJbdyI9d7Hekhzw== X-Google-Smtp-Source: AGHT+IHDHvjmRGLzSjXuorpnS85brJRUupn0G6P2is2CiphvAnmUCqe8xMokjuQvg2QpUfOgfjyM X-Received: by 2002:a05:6808:1405:b0:3c0:3db2:4d62 with SMTP id w5-20020a056808140500b003c03db24d62mr454010oiv.9.1708644387254; Thu, 22 Feb 2024 15:26:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708644387; cv=pass; d=google.com; s=arc-20160816; b=RM0DVhh0OMjylSoOYERuABHRD+GTR6/MCtZPu+LrOzZ/Pz1r0F8zoj5sG/eoZAWNeE 6SQ6fuO/XvcH4zSoTYDM5ptL3EmN8wSfF+EgnpVl0YgA0wLVWMVsY3hQzz8qPxB6WBRA 4TnjERaaEHhOPyR24YG0mi86VGUUBVKKejwZM47hPnn05HtOET/saThzTeVwCDEE4lVy RHaHc5wOlRAA4AYI+Z+KCyHHPAMN72acFoitQk7N/PSS3DiEzejjOnTlSqhY0FdtSkpu BNbfzR9NKwHl17gSsc2xQzPg6D/mMfM1ytXpia2WJZiC9Xd8SVbImX5lD06Cv5+vZYxF px2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=RFrpvK2ncCEA3pXuIWUNixiWOQ+1QGG1zWVmRqVDqG8=; fh=j53ffieBeHmuArQHAkiXDczYOIriM+Jf92hqYE3BW8U=; b=p7GE2y0iBFReJyN4nKcb8PZsnsXAN1WMUui5HxA+Mk80l/e5PGzCmrvQBKZaZDdr5g UWQx9h4wP7RKRghGyrNzsM1taZpITOdP08b3+MTh3LfTURzkLjGaGVTJGqD2c07gcgY3 VsBTcfUYgLL4cp0aSLXYaP1vWyFPjdUWJyI8cAy6owUzU3WXj6ESp5LMxDY89lzq/16A ZIlzNr5BItHX6yyssHkfhJ2NHJ+eAKPxlJJIhHFRocsuMyXbPKXu6pjIoM3/6GcMpg34 HMXpXVPpLH8GSZiK8KqlkndTVzUyFitpL37oEDGFPau1C745G9TD+IxDIVKa7571sfd+ S+Nw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=m667LTrq; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-77524-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77524-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id kr17-20020a056a004b5100b006e4c89faa05si2437906pfb.137.2024.02.22.15.26.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 15:26:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77524-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=m667LTrq; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-77524-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77524-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 52B74B2465F for ; Thu, 22 Feb 2024 23:25:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1E1F158D90; Thu, 22 Feb 2024 23:17:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="m667LTrq" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFFD61586E7; Thu, 22 Feb 2024 23:17:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708643848; cv=none; b=Wpm6AXcrcMc3kekpQnddtejNj+ckb4rOflH1xL8f+kx1vx2tyq5UgPCYeRCdxzG1bHZVyte0NpQgvYuBYioS336zxtTc/2p1xfbCEPNNzG3lXL1qctcUYlhhhv9cfnhdWerWHQ5F80bR+vU+uTk0DFpeVpYkHzPfyL+bfjILrQQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708643848; c=relaxed/simple; bh=51dtO8360xWrEtggfpbjq1Rqrgqxn5XxoawweGjUKx8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=H3uth7c2cghCjALorm9kRcArR3wfSxeambmEuXY4rietlxNL7vbi/BCET60eUqIe4jIlPWZHndd7ZZlzmJ7ceRQmsVAxX1t4ARwlgUbfk5Xn55OWtAHXUSdNUuUz8Gu1Zgn4K+Hiy5Zererd8UPXxcL1GCvRkHS16NYAIo/nxgs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=m667LTrq; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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-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 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 --- 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; }; /******************************************************************************/ -- 2.34.1