From patchwork Wed Oct 11 16:52:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srivatsa Vaddagiri X-Patchwork-Id: 13417613 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BACF4CDB467 for ; Wed, 11 Oct 2023 16:54:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqcSk-0000IU-Ou; Wed, 11 Oct 2023 12:53:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSh-0000HE-87; Wed, 11 Oct 2023 12:53:31 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqcSf-0001At-He; Wed, 11 Oct 2023 12:53:30 -0400 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BFrLb1011628; Wed, 11 Oct 2023 16:53:28 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=OYCj5FL3OV5QlxZRwhcgh3ou9oCfEtGrdS4IoYFnXsQ=; b=B16G3WT69vCdcuOdnZ+55pX8mB1KUEFubHSYZEJifQ0ACnQvEtVYF+Hz0lqfTsbr7C12 dE8K2JNW1MeVZIRShiypq37jKtns14wtPd8uSmDBg+lxgKd11H1w3qHmwhjc+38n8Cz4 hnD33+Fakydhpyzb0j8Kd9AjXFnRCJuKyFJNJdVbBwQbkjLqjmiBNvlJ/PGFW/wvI5w0 jd9u1kFRJv/JhcXGaiLH2v8osSTUP89M5DjUiTVpt8Nvk1/Rnr2gW2WCei0BNeNrhxEx +wGPVycmrO704mZr9EHoaqn2bTPJpN7jgS5gY15eVYajowWSyhHYlOBWXO7nkUTBP2DU Hw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tnnvw9hhy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:27 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39BGrRj6031404 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 16:53:27 GMT Received: from blr-ubuntu-31.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Wed, 11 Oct 2023 09:53:22 -0700 From: Srivatsa Vaddagiri To: , , , CC: , , , , , , Subject: [RFC/PATCH v0 09/12] gunyah: Customize device-tree Date: Wed, 11 Oct 2023 16:52:31 +0000 Message-ID: <20231011165234.1323725-10-quic_svaddagi@quicinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> References: <20231011165234.1323725-1-quic_svaddagi@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: _F8R9LE1Fet3-AZiB_Sn7-fXrO-ZHsmh X-Proofpoint-GUID: _F8R9LE1Fet3-AZiB_Sn7-fXrO-ZHsmh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_12,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 phishscore=0 clxscore=1015 spamscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110148 Received-SPF: pass client-ip=205.220.180.131; envelope-from=quic_svaddagi@quicinc.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Customize device-tree with Gunyah specific properties. Some of these properties include specification of doorbells that need to be created and associated with various interrupts. Signed-off-by: Srivatsa Vaddagiri --- hw/arm/virt.c | 11 ++++++ include/sysemu/gunyah.h | 7 ++++ target/arm/gunyah.c | 79 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 4293e01383..15fdf7be05 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2024,6 +2024,14 @@ static void virt_cpu_post_init(VirtMachineState *vms, MemoryRegion *sysmem) } } +static void virt_modify_dtb(const struct arm_boot_info *binfo, void *fdt) +{ + const VirtMachineState *vms = container_of(binfo, VirtMachineState, + bootinfo); + + gunyah_arm_fdt_customize(fdt, vms->memmap[VIRT_MEM].base, vms->gic_phandle); +} + static void machvirt_init(MachineState *machine) { VirtMachineState *vms = VIRT_MACHINE(machine); @@ -2335,6 +2343,9 @@ static void machvirt_init(MachineState *machine) vms->bootinfo.skip_dtb_autoload = true; vms->bootinfo.firmware_loaded = firmware_loaded; vms->bootinfo.psci_conduit = vms->psci_conduit; + if (gunyah_enabled()) { + vms->bootinfo.modify_dtb = virt_modify_dtb; + } arm_load_kernel(ARM_CPU(first_cpu), machine, &vms->bootinfo); vms->machine_done.notify = virt_machine_done; diff --git a/include/sysemu/gunyah.h b/include/sysemu/gunyah.h index 101e190619..f077837437 100644 --- a/include/sysemu/gunyah.h +++ b/include/sysemu/gunyah.h @@ -35,6 +35,8 @@ DECLARE_INSTANCE_CHECKER(GUNYAHState, GUNYAH_STATE, TYPE_GUNYAH_ACCEL) int gunyah_arm_set_dtb(__u64 dtb_start, __u64 dtb_size); +void gunyah_arm_fdt_customize(void *fdt, uint64_t mem_base, + uint32_t gic_phandle); #else /* CONFIG_GUNYAH_IS_POSSIBLE */ @@ -45,6 +47,11 @@ static inline int gunyah_arm_set_dtb(__u64 dtb_start, __u64 dtb_size) return -1; } +static inline void gunyah_arm_fdt_customize(void *fdt, uint64_t mem_base, + uint32_t gic_phandle) +{ +} + #endif /* CONFIG_GUNYAH_IS_POSSIBLE */ #endif /* QEMU_GUNYAH_H */ diff --git a/target/arm/gunyah.c b/target/arm/gunyah.c index 73c1c2a88a..1521f2d414 100644 --- a/target/arm/gunyah.c +++ b/target/arm/gunyah.c @@ -11,6 +11,9 @@ #include "sysemu/gunyah.h" #include "sysemu/gunyah_int.h" #include "linux-headers/linux/gunyah.h" +#include "exec/memory.h" +#include "sysemu/device_tree.h" +#include "hw/arm/fdt.h" /* * Specify location of device-tree in guest address space. @@ -43,3 +46,79 @@ int gunyah_arm_set_dtb(__u64 dtb_start, __u64 dtb_size) return 0; } + +void gunyah_arm_fdt_customize(void *fdt, uint64_t mem_base, + uint32_t gic_phandle) +{ + char *nodename; + int i; + GUNYAHState *state = get_gunyah_state(); + + qemu_fdt_add_subnode(fdt, "/gunyah-vm-config"); + qemu_fdt_setprop_string(fdt, "/gunyah-vm-config", + "image-name", "qemu-vm"); + qemu_fdt_setprop_string(fdt, "/gunyah-vm-config", "os-type", "linux"); + + nodename = g_strdup_printf("/gunyah-vm-config/memory"); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "#address-cells", 2); + qemu_fdt_setprop_cell(fdt, nodename, "#size-cells", 2); + qemu_fdt_setprop_u64(fdt, nodename, "base-address", mem_base); + + g_free(nodename); + + nodename = g_strdup_printf("/gunyah-vm-config/interrupts"); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "config", gic_phandle); + g_free(nodename); + + nodename = g_strdup_printf("/gunyah-vm-config/vcpus"); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "affinity", "proxy"); + g_free(nodename); + + nodename = g_strdup_printf("/gunyah-vm-config/vdevices"); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "generate", "/hypervisor"); + g_free(nodename); + + for (i = 0; i < state->nr_slots; ++i) { + if (!state->slots[i].start || state->slots[i].lend || + state->slots[i].start == mem_base) { + continue; + } + + nodename = g_strdup_printf("/gunyah-vm-config/vdevices/shm-%x", i); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "vdevice-type", "shm"); + qemu_fdt_setprop_string(fdt, nodename, "push-compatible", "dma"); + qemu_fdt_setprop(fdt, nodename, "peer-default", NULL, 0); + qemu_fdt_setprop_u64(fdt, nodename, "dma_base", 0); + g_free(nodename); + + nodename = g_strdup_printf("/gunyah-vm-config/vdevices/shm-%x/memory", + i); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cell(fdt, nodename, "label", i); + qemu_fdt_setprop_cell(fdt, nodename, "#address-cells", 2); + qemu_fdt_setprop_u64(fdt, nodename, "base", state->slots[i].start); + g_free(nodename); + } + + for (i = 0; i < state->nr_irqs; ++i) { + nodename = g_strdup_printf("/gunyah-vm-config/vdevices/bell-%x", i); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "vdevice-type", "doorbell"); + char *p = g_strdup_printf("/hypervisor/bell-%x", i); + qemu_fdt_setprop_string(fdt, nodename, "generate", p); + g_free(p); + qemu_fdt_setprop_cell(fdt, nodename, "label", i); + qemu_fdt_setprop(fdt, nodename, "peer-default", NULL, 0); + qemu_fdt_setprop(fdt, nodename, "source-can-clear", NULL, 0); + + qemu_fdt_setprop_cells(fdt, nodename, "interrupts", + GIC_FDT_IRQ_TYPE_SPI, i, GIC_FDT_IRQ_FLAGS_LEVEL_HI); + + g_free(nodename); + } +}