From nobody Sat Sep 26 23:03:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1787693056; cv=none; d=zohomail.com; s=zohoarc; b=Hmz+UWJCYa5iQDj4rVJGhb5TpKgKYPi5dWB12AJ+bSV74Q7HxIMmm2KABuZVbcJo2y0BjmeMtpmss7N7s3ah7o/ncd+xgf67r6MMQSxFt7SdnS1O/SFl+N2xptBbJb+tYysSGXiWBYBhl4VBzej68mfBONIMqxNZv6JgeBlixI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787693056; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2xwFh4IjNi5ZPP2cvlmytxr2GRgCFO2TpO0YhBlo5+c=; b=n09zxXXqzamRFFyQox76jSN3fwszgyOdaFpM3B1PzOnqjdUqoYlzPR7mzBJMZ9fCKTw3fcfqY7jPbinUMp+Mb4F1hEZ3apzrK87BHKVsozybncVccCdeizM2k5zLclrgtJ2lDtwfZZf8Ay/PMubIQhpC6/JUHCZc9ZNDYSvy9ZQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17876930560051002.4809695297649; Tue, 25 Aug 2026 14:24:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyycc-0003TI-CH; Tue, 25 Aug 2026 17:23:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyycZ-0003Ri-Eh for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:23:51 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyycX-0002Fr-JT for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:23:51 -0400 Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67PLAQF63101136 for ; Tue, 25 Aug 2026 21:23:47 GMT Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g9bkua1vn-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 25 Aug 2026 21:23:47 +0000 (GMT) Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-8f08560ea44so3650606d6.1 for ; Tue, 25 Aug 2026 14:23:47 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([189.38.141.232]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90cc65299f0sm8646386d6.41.2026.08.25.14.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 14:23:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=2xwFh4IjNi5 ZPP2cvlmytxr2GRgCFO2TpO0YhBlo5+c=; b=c1VwDv0FknXPwOBMOTnlgfTv1Q7 8KBUx76l2T6MLiMfrphBbe+hYzMwMIMOLMiaP8oi9vay7rFWUnKrJBMrqB/5qrcw 84zIs8pdA1vwPNTOkA1sPjtBfuXj9skTeOxWJ/pE3M+e9X/dcDu7Cuk/HRDIqhfy ngYYllVHAo3pyOd4o0ddFXq8RxViiqSlyemWpwK2+uqWvY1n1XRnnBU/nT4sKLFj xaNAx3vo6/FUorbNSeVXUVHwCHkCZ6XuvonvbhtieGOBTsV34PT0tKHcCrIomurS WqgEXLR2egw7zPq6UyvJWo88xzI3zQqYsGRv7jmAuC5JviytVQ8VpoekQBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787693027; x=1788297827; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=2xwFh4IjNi5ZPP2cvlmytxr2GRgCFO2TpO0YhBlo5+c=; b=TlBbJi0kij8GseCIqBr0p7ytQezfaLXM64WkW+MQizRyP1gpxC1R3dkZLIUx/oJWzc 9ZBwXrgfJzyCp6TMF8QQJLHT22SrMtu+VeVGX7uWwPq7DLXC2g7FJ+8sXqr8w5k1SJGD 9OchGdMlU8oeXUL2I6Gwk/gJu21wLKhsnHSOCBqXoc/yRNIhThxoPhH1qJPsbIzD09zi 7phpTGSZg+zFYVVNP5uiPb5+F8N93Gskp+5NMZZyq0PUzk3v413x6GnILCFHoQiu/oag ZoofolTrhfblVdPFTDvEQa7mP6BGKzaTm4dqAPK6zcHiO3Fl2Cxvq5/zNdxAFcmU4mOF D06Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787693027; x=1788297827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=2xwFh4IjNi5ZPP2cvlmytxr2GRgCFO2TpO0YhBlo5+c=; b=rim3qzBNRy/FeO6Hkr233cD8V3AhkglEUJIOXuLdoPKVJgxTSKdmBPIojjGEmmYcQZ d/Mp2wrhN0ZriTbazdsfVjy0LJRfsk/nQoy6Z6twCaDaEmftXzmsWb70ire9Xoo9edwF etYqFQxJ3pFsV4tYU4p/Zwb2WEwpjLMHId3M+QQZN5EYVemuGjQIpOwR0qhuP2bDBPC4 xPxbX4EVkIhsNOgWUbjJ+G9n0VKsqCSrlZ1EYtYO3IjCmJwN7eGPvCz/GxjsUGqnmcbo Sya6hDSwfNDy1afoIi3dGBHroi95B2ThzYem4/C4xQrKou1Z6Hy7D8kTjQdSLSZRBhMV IuPg== X-Gm-Message-State: AFuF++lbVpuxt09ByvtIz1Yn+4EEgqSv8H09fU9DIO/jmEoPcBdswga0 1eb5M1/JIgEELofmPVMHbHGYTw2gVn9iaXUIK5uqchnfFXbpB4zIXrAHHF+Pb0pCPs/t6TpZt7w cutiVKAUtsfe0f6Yp9PGSd7lYN1V5H6nyiO8NNDJUstYgRb96V2+HqrPKkUdtqSoKQA== X-Gm-Gg: AR+sD10m/urhNAOjRT9mF70J+Q8PzWRW4oqwu1NJZ+GxwZd79ikBngFbTh/om6UAEKT nyTqTkcEGKVmN7MSH8Tzj6c0VM069B8x/Xaj3nhCy72nSbBzeZEFBzno+PqmNW/tMk8kAYKtzqj BORoAUUMkwcKLjbXt6/ydI0+sJjYsxAgwitcS5PKgnp7CxI7RadLkalyTFoZprw5qmpV8R5/Add XgT3MVuIo86WbdCFAxQgCpBtXzU47csmpg4AwzrRp850LfR9r1oDQPzBUWlBYUZYTrCj3eZl3Zi ZLMbYk3mOwKVAA44nLchM/wvW07mbKNVzb9EFm6oNMa6cj8LrGxchXIucjuBfdbAeagXinwpQuH yheVLFaSfMYePaCXkIRw2NRDGpOIlIar33vEm/w== X-Received: by 2002:a05:6214:5691:b0:90a:6c34:f8aa with SMTP id 6a1803df08f44-90cc7929cb2mr21382446d6.27.1787693026713; Tue, 25 Aug 2026 14:23:46 -0700 (PDT) X-Received: by 2002:a05:6214:5691:b0:90a:6c34:f8aa with SMTP id 6a1803df08f44-90cc7929cb2mr21381946d6.27.1787693026275; Tue, 25 Aug 2026 14:23:46 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com, Daniel Henrique Barboza , Palmer Dabbelt Subject: [PATCH 01/13] hw/riscv/fdt-common, virt.c: add create_fdt_flash() Date: Tue, 25 Aug 2026 18:23:13 -0300 Message-ID: <20260825212326.1907-2-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> References: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: bliCGwi4NZVGdkJ0nEJd13gYUnBw4EVu X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX20IbcV23MZVj Py++GGfHk1IOPO4EAQz9J4mcPS/ynBra5fNDCZ0L/G2LEGSqVlrnwMgZI5/gnN02/29AeBhbaF/ /l6Gm53j25ismcjIIbtwFA1FTgNUESg= X-Authority-Analysis: v=2.4 cv=TZGmcxQh c=1 sm=1 tr=0 ts=6a8e07e3 cx=c_pps a=7E5Bxpl4vBhpaufnMqZlrw==:117 a=MCIxunHWmQOg/5OnbzXZaw==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yOCtJkima9RkubShWh1s:22 a=EUspDBNiAAAA:8 a=agbqTSZeYTzrP7BmR6QA:9 a=pJ04lnu7RYOZP9TFuWaZ:22 X-Proofpoint-GUID: bliCGwi4NZVGdkJ0nEJd13gYUnBw4EVu X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX4K4gSaW8Y7eN RZrvPiPQ7mP6GXTLOTtgWe1VGDCTimBJem54Vs6+OxovxnDzAjn3JAL6KXzU0lDrSZ9vLsjEb22 QqQGAKhL6mzRt2bdyJy4TsysUSUspiinE8rZQ9idFdMhMwXt+9L9ZFUhiMdXdliTHhV9KdwMWZn 6jLxFKteOa1NGRPxgCGY23ayYDUOb3m/GolV+/1dVEuf4rElP4x7nFLBxU0dDHZHAqfXbv9sTzC 7tcQD0t17NoQR/3Z/PvgRAjiedveAwEf1+eB8lfhO14wEJ3jO08siNalCeTlnazdXCNqRB1g/QY 8XCwaRKXh5mVVcn+miItCVLnJaonbRdx9rWY6OtDm4Zmq56JTzMi/bHn8mT9Cj+RRjRhAxykxsn j0KmHCaVzmO827dTAV26/CQchEg7Pb1mPo52EO7vNPkCCw6dWUYz1uLjS6k34scCVUNU8x8LJDJ 42jf5dtyUvppUnPmUzg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_06,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 spamscore=0 bulkscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250182 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1787693059503158500 Content-Type: text/plain; charset="utf-8" Add a common helper to create a cfi-flash compatible flash subnode. This change only affects the existing 'virt' board for now but it will be used by the future 'riscv-server-ref' board in the future. No FDT changes intended. Signed-off-by: Daniel Henrique Barboza --- hw/riscv/fdt-common.c | 12 ++++++++++++ hw/riscv/virt.c | 18 ++---------------- include/hw/riscv/fdt-common.h | 1 + 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/hw/riscv/fdt-common.c b/hw/riscv/fdt-common.c index aa143a618b..e74423a225 100644 --- a/hw/riscv/fdt-common.c +++ b/hw/riscv/fdt-common.c @@ -282,3 +282,15 @@ void riscv_pmu_generate_fdt_node(void *fdt, uint32_t c= mask, char *pmu_name) qemu_fdt_setprop(fdt, pmu_name, "riscv,event-to-mhpmcounters", fdt_event_ctr_map, sizeof(fdt_event_ctr_map)); } + +void create_fdt_flash(void *fdt, hwaddr flashbase, hwaddr flashsize) +{ + g_autofree char *name =3D g_strdup_printf("/flash@%" PRIx64, flashbase= ); + + qemu_fdt_add_subnode(fdt, name); + qemu_fdt_setprop_string(fdt, name, "compatible", "cfi-flash"); + qemu_fdt_setprop_sized_cells(fdt, name, "reg", + 2, flashbase, 2, flashsize, + 2, flashbase + flashsize, 2, flashsize); + qemu_fdt_setprop_cell(fdt, name, "bank-width", 4); +} diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index d58656f70d..33a121abd9 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -865,21 +865,6 @@ static void create_fdt_rtc(RISCVVirtState *s, } } =20 -static void create_fdt_flash(RISCVVirtState *s) -{ - MachineState *ms =3D MACHINE(s); - hwaddr flashsize =3D s->memmap[VIRT_FLASH].size / 2; - hwaddr flashbase =3D s->memmap[VIRT_FLASH].base; - g_autofree char *name =3D g_strdup_printf("/flash@%" PRIx64, flashbase= ); - - qemu_fdt_add_subnode(ms->fdt, name); - qemu_fdt_setprop_string(ms->fdt, name, "compatible", "cfi-flash"); - qemu_fdt_setprop_sized_cells(ms->fdt, name, "reg", - 2, flashbase, 2, flashsize, - 2, flashbase + flashsize, 2, flashsize); - qemu_fdt_setprop_cell(ms->fdt, name, "bank-width", 4); -} - static void create_fdt_fw_cfg(RISCVVirtState *s) { MachineState *ms =3D MACHINE(s); @@ -1040,7 +1025,8 @@ static void create_fdt(RISCVVirtState *s) =20 qemu_fdt_add_subnode(ms->fdt, "/aliases"); =20 - create_fdt_flash(s); + create_fdt_flash(ms->fdt, s->memmap[VIRT_FLASH].base, + s->memmap[VIRT_FLASH].size / 2); create_fdt_fw_cfg(s); create_fdt_pmu(s); } diff --git a/include/hw/riscv/fdt-common.h b/include/hw/riscv/fdt-common.h index 1729a6abc6..6e438e0278 100644 --- a/include/hw/riscv/fdt-common.h +++ b/include/hw/riscv/fdt-common.h @@ -36,4 +36,5 @@ void create_fdt_plic(void *fdt, hwaddr addr, uint64_t siz= e, uint32_t cells_size, uint32_t ndev_sources, bool numa_enabled, int socket); void riscv_pmu_generate_fdt_node(void *fdt, uint32_t cmask, char *pmu_name= ); +void create_fdt_flash(void *fdt, hwaddr flashbase, hwaddr flashsize); #endif --=20 2.43.0 From nobody Sat Sep 26 23:03:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1787693100; cv=none; d=zohomail.com; s=zohoarc; b=TrhkQPysrz18MxDqBGJdaAnDT/wBgPYX/gW1T5HMekEpAzQTQJgtLIFicSIs4YhQ6uil4C7nQKkk47eqmuVk+IR5gFIFA8go7QAsK9RdmBsVfpvlBcjlZnFdf26/xx3djHKgmNcULl0veiLWgJi/URodZBAH94qSic3u1PZzOB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787693100; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AkchrvUe/LAmpQrPITt1acnChXhuDja4ZA5vZ5r9Sjg=; b=ZJbf1RiiwuAOFCqR9DmOfGaTPLyaUPpiyLciYM53DyDSJ7JOQt5DdmS3pPtJZ1rM9JOgjVb98pTX4FP1ZuagsH4zl1GHDtLD+BebKvdGwCGMVaurSrGhZU9k7OsHZaPRe5nR3MV6zTpoWbe0c5V43oA8Av21T4dSVGFtcxv8RPE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787693100859600.3255182606624; Tue, 25 Aug 2026 14:25:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyyce-0003UC-5N; Tue, 25 Aug 2026 17:23:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyycb-0003St-69 for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:23:53 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyycZ-0002GB-9u for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:23:52 -0400 Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67PLAUVQ3101202 for ; Tue, 25 Aug 2026 21:23:50 GMT Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g9bkua1vr-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 25 Aug 2026 21:23:49 +0000 (GMT) Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-90a60102d6eso3252306d6.3 for ; Tue, 25 Aug 2026 14:23:49 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([189.38.141.232]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90cc65299f0sm8646386d6.41.2026.08.25.14.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 14:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=AkchrvUe/LA mpQrPITt1acnChXhuDja4ZA5vZ5r9Sjg=; b=cYKaGBKFSwM8hGXaD6rRcE9N7b2 gjVz4di3rvX64kgG/0uJP2ZobKVW0DdG9vsX2GenmpjCzD6qpwkRqPdcND45HSON SibZMMCe0/zqed5wZuYIzSB3GogsNJhxttV4u4sYv4yPmteo38jFP6LSKobDfw6V ENWz1RXwm8vwN5oXItM4w4eE67R57XCVdeFVHGwhunrpo2NVjwyt7lur1BvRu++g DduH1KxzEee/TGXtFlQaV+heH2af3AzmkxCGqJlV6g0cp6op+X7a4nnWh2QANM8s 6q4o2CxPE60IWsHbWN0pxIcomzvX323i4rvUPSWaGmLS4Ow+ra2qaYIIUEQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787693029; x=1788297829; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=AkchrvUe/LAmpQrPITt1acnChXhuDja4ZA5vZ5r9Sjg=; b=C7jsV6hgmabY9v7Ml+/cXIMvqEA3IFu6BppGhubps/vwmayeFjRgmeaprJ70r0HS8E DuomT1A49WqZa3A/kkqLXVWKmYFymBRpn7U5NLmAn07N9KrVqLvu5I+t37/2Ep4GGoHI 8MIf60pRxNj1GzOK9zt6AgdBalTgUXBswW4vACabDKFdJH4XscV2dil0mqe8mueVovKS ZMntiUd1828ZjpCxKucMIeKeWUQRaFU8qFwBmJ7E5GmlcxFfOHrWQQhoN+bOKy5/EIQm g7a3fzmHtCcSr/GdAQRSvhUe61SSWwGNkH7J8Fi444lv77N9dS15/4r723CO5UY0dHs4 uuNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787693029; x=1788297829; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=AkchrvUe/LAmpQrPITt1acnChXhuDja4ZA5vZ5r9Sjg=; b=qLAqHORHl8HZvoaSFsBxA0vaZCkrwn2vLab7D3slKMiQZvuQTbv8DRf16avlkPxsmu VEqnQzCXn/YZYuAxt+wQaTCnBsPocCy/Zj8NNTBMN4nVku7LUcbkZfPfemP8XQdxPDbb zEc73itnhswFZokI3f0JeK/uxG0HBJ2rXPowj+Xj0AiK7Kh7MSLuBDElWr1TQwa4EdLH moUQR1/IRv0cxhGlbiiwh/W8uyrgcLu9QMyeRBgfjhyj/96C+F33mNZddzOYijQ9TXFh TXw6ydkMI2FkQGAXPw/HeODeQY7kLby+z7A6yqu/CAyORu6GWxs+hCBexycOqF9cUTlS TR3Q== X-Gm-Message-State: AFuF++mPALjPLllNz9ART7kH3bhTTkCuSiKylbwYst+akd15Xur3Q1HK 1T6p5uozyEmEu4c6G0sxyJBcqrq1H0PqDv4O1KpDYcUhcsaEqm2txXSwHa8DpkN8T5/vfzXZtc2 9QxWVbCSe4+txVLZJcE7t6siVgjfufmajIDAv2njgxRmw3oPp3ODMf8+Af/gCR79qHw== X-Gm-Gg: AR+sD120UfSJrOmZbdd/TXTX/UqFcWLPIbTir/svVwaAE7f7WIgMq2duSTwqg+A2bfN JfDq50/f5jyIRPW9ZGRSpy5fa4dNw60u2lsGU6LhxkG3iHUnrnUPxOpTZJSJxPqMihWAWSRFsI9 fqf3tCif+laBJuEc25KnNKxO2gzTAg+QP69nnNC5BQVhABNyXSBsPh5uWqrlXhT6yWMODrb/ypF ip9/n1UStHW2kl6Z08XOsISOUasK025DTf2d3lg7BmfrnswAk7ceBE6qveGYYLQOrnUsoyhg5O7 bgCiVYGVMb0uBB+Zgw2IGURbPISDtoqh/yBPswvRBk93XJdVXFEBnIV9ag+++Ci+7b/V/g+Ru1X np5tWzMyjkirLeyaePG9W3oAa5cVMUyhXoTlHcQ== X-Received: by 2002:a05:6214:568d:b0:90c:b640:7c04 with SMTP id 6a1803df08f44-90cc79fe02emr19975496d6.27.1787693028991; Tue, 25 Aug 2026 14:23:48 -0700 (PDT) X-Received: by 2002:a05:6214:568d:b0:90c:b640:7c04 with SMTP id 6a1803df08f44-90cc79fe02emr19975006d6.27.1787693028568; Tue, 25 Aug 2026 14:23:48 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com, Daniel Henrique Barboza , Palmer Dabbelt Subject: [PATCH 02/13] hw/riscv/fdt-common, virt.c: add create_fdt_syscon() Date: Tue, 25 Aug 2026 18:23:14 -0300 Message-ID: <20260825212326.1907-3-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> References: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: b1h-AcDshqtECZkmNLcOl-l-iuBoCrcV X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX3trcaO8aGp+s 34g9Y5St9rxSXq7pEsCO2eN0DKiHBu3laz3uFl5+bzdbbkxWWunGzQfJ1LGjxFTJbYIJKi2ndvV EmggbhdoFaV24yVW150ZHVDnOVvuRcc= X-Authority-Analysis: v=2.4 cv=TZGmcxQh c=1 sm=1 tr=0 ts=6a8e07e6 cx=c_pps a=wEM5vcRIz55oU/E2lInRtA==:117 a=MCIxunHWmQOg/5OnbzXZaw==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yOCtJkima9RkubShWh1s:22 a=EUspDBNiAAAA:8 a=azO7UiENNDAzAd32FwoA:9 a=OIgjcC2v60KrkQgK7BGD:22 X-Proofpoint-GUID: b1h-AcDshqtECZkmNLcOl-l-iuBoCrcV X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX/8Zvxz7qP5lW XQqWvUgAvvnkkYsZfj/uG/jbr/FLpxqRiomiPt4e8j4iylMUhsjtMusgz6GwHz7HuxYwZ9g7K7b bHHCTPMOOrOeO8pc0t+9nfJekxisH3qELHbHZy0X3j01pYpXJ92nzmiToQnufk1hULx7+wm8YB5 uhRS/4mfLarUN0YAkLWLuaQdiMRtOTQRhIoerNfQBKprkpTHh5peR+2gds5UaC3ui96VbAxwXkW 83nfn13K4EC7lDJxPDRpuYOeAklxH5oYESfIxNH5+wG2W1B4JyBKGZu68+q59ohpBMdWuN46hgk 2FhKz5i7XG02x+BKSnwnXnMth4wAN6UaLWRPDu6KMNv6yP+BjxrrgbdI3K7dpMb0NmhRZhUeC+y 6ev8cOinZFHqQQM1IFe6FTEvJcN86GZsar8T8mXyzxh7AdpI/NVWIca0I6ZF5KzzvMNqxQX5l2q iinD4K1zDp6LkkwIQMg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_06,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 spamscore=0 bulkscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250182 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1787693101607158500 Content-Type: text/plain; charset="utf-8" The soon to be added riscv-server-ref board will declare a syscon FDT similar to what the 'virt' board already does. It won't have a 'sifive,test0' and 'sifive,test1' compat string though, hence we'll add a flag to enable/disable these additional properties. The FDT is slightly changed: the subnode is now named 'soc/syscon' instead of 'soc/test' to be compatible with the latest device-tree docs. Signed-off-by: Daniel Henrique Barboza --- hw/riscv/fdt-common.c | 53 +++++++++++++++++++++++++++++++++++ hw/riscv/virt.c | 45 ++--------------------------- include/hw/riscv/fdt-common.h | 4 +++ 3 files changed, 60 insertions(+), 42 deletions(-) diff --git a/hw/riscv/fdt-common.c b/hw/riscv/fdt-common.c index e74423a225..a2168c09ec 100644 --- a/hw/riscv/fdt-common.c +++ b/hw/riscv/fdt-common.c @@ -294,3 +294,56 @@ void create_fdt_flash(void *fdt, hwaddr flashbase, hwa= ddr flashsize) 2, flashbase + flashsize, 2, flashsize); qemu_fdt_setprop_cell(fdt, name, "bank-width", 4); } + +/* + * @sifive_test_compat is used to create a FDT that declares + * compat with "sifive,test1" and "sifive,test0". This happens + * to be the case for the 'virt' machine that also creates a + * 'sifive_test' syscon device. + */ +void create_fdt_syscon(void *fdt, uint32_t *phandle, + hwaddr addr, hwaddr size, + uint32_t reboot, uint32_t poweroff, + bool sifive_test_compat) +{ + uint32_t syscon_phandle =3D (*phandle)++; + char *name; + + name =3D g_strdup_printf("/soc/syscon@%"HWADDR_PRIx, addr); + qemu_fdt_add_subnode(fdt, name); + + if (sifive_test_compat) { + static const char * const compat[3] =3D { + "sifive,test1", "sifive,test0", "syscon" + }; + + qemu_fdt_setprop_string_array(fdt, name, "compatible", + (char **)&compat, ARRAY_SIZE(compat)= ); + } else { + qemu_fdt_setprop_string(fdt, name, "compatible", "syscon"); + } + + qemu_fdt_setprop_sized_cells(fdt, name, "reg", + 2, addr, + 2, size); + + qemu_fdt_setprop_cell(fdt, name, "phandle", syscon_phandle); + + g_free(name); + + name =3D g_strdup_printf("/reboot"); + qemu_fdt_add_subnode(fdt, name); + qemu_fdt_setprop_string(fdt, name, "compatible", "syscon-reboot"); + qemu_fdt_setprop_cell(fdt, name, "regmap", syscon_phandle); + qemu_fdt_setprop_cell(fdt, name, "offset", 0x0); + qemu_fdt_setprop_cell(fdt, name, "value", reboot); + g_free(name); + + name =3D g_strdup_printf("/poweroff"); + qemu_fdt_add_subnode(fdt, name); + qemu_fdt_setprop_string(fdt, name, "compatible", "syscon-poweroff"); + qemu_fdt_setprop_cell(fdt, name, "regmap", syscon_phandle); + qemu_fdt_setprop_cell(fdt, name, "offset", 0x0); + qemu_fdt_setprop_cell(fdt, name, "value", poweroff); + g_free(name); +} diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 33a121abd9..acbbe458fa 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -766,47 +766,6 @@ static void create_fdt_pcie(RISCVVirtState *s, create_pcie_irq_map(s, ms->fdt, name, irq_pcie_phandle); } =20 -static void create_fdt_reset(RISCVVirtState *s, uint32_t *phandle) -{ - char *name; - uint32_t test_phandle; - MachineState *ms =3D MACHINE(s); - - test_phandle =3D (*phandle)++; - name =3D g_strdup_printf("/soc/test@%"HWADDR_PRIx, - s->memmap[VIRT_TEST].base); - qemu_fdt_add_subnode(ms->fdt, name); - { - static const char * const compat[3] =3D { - "sifive,test1", "sifive,test0", "syscon" - }; - qemu_fdt_setprop_string_array(ms->fdt, name, "compatible", - (char **)&compat, ARRAY_SIZE(compat)= ); - } - qemu_fdt_setprop_sized_cells(ms->fdt, name, "reg", - 2, s->memmap[VIRT_TEST].base, - 2, s->memmap[VIRT_TEST].size); - qemu_fdt_setprop_cell(ms->fdt, name, "phandle", test_phandle); - test_phandle =3D qemu_fdt_get_phandle(ms->fdt, name); - g_free(name); - - name =3D g_strdup_printf("/reboot"); - qemu_fdt_add_subnode(ms->fdt, name); - qemu_fdt_setprop_string(ms->fdt, name, "compatible", "syscon-reboot"); - qemu_fdt_setprop_cell(ms->fdt, name, "regmap", test_phandle); - qemu_fdt_setprop_cell(ms->fdt, name, "offset", 0x0); - qemu_fdt_setprop_cell(ms->fdt, name, "value", FINISHER_RESET); - g_free(name); - - name =3D g_strdup_printf("/poweroff"); - qemu_fdt_add_subnode(ms->fdt, name); - qemu_fdt_setprop_string(ms->fdt, name, "compatible", "syscon-poweroff"= ); - qemu_fdt_setprop_cell(ms->fdt, name, "regmap", test_phandle); - qemu_fdt_setprop_cell(ms->fdt, name, "offset", 0x0); - qemu_fdt_setprop_cell(ms->fdt, name, "value", FINISHER_PASS); - g_free(name); -} - static void create_fdt_uart(RISCVVirtState *s, uint32_t irq_mmio_phandle, int memId, int irqN= o) { @@ -992,7 +951,9 @@ static void finalize_fdt(RISCVVirtState *s) create_fdt_pcie(s, irq_pcie_phandle, msi_pcie_phandle, iommu_sys_phandle); =20 - create_fdt_reset(s, &phandle); + create_fdt_syscon(MACHINE(s)->fdt, &phandle, + s->memmap[VIRT_TEST].base, s->memmap[VIRT_TEST].size, + FINISHER_RESET, FINISHER_PASS, true); =20 create_fdt_uarts(s, irq_mmio_phandle); =20 diff --git a/include/hw/riscv/fdt-common.h b/include/hw/riscv/fdt-common.h index 6e438e0278..31203df517 100644 --- a/include/hw/riscv/fdt-common.h +++ b/include/hw/riscv/fdt-common.h @@ -37,4 +37,8 @@ void create_fdt_plic(void *fdt, hwaddr addr, uint64_t siz= e, bool numa_enabled, int socket); void riscv_pmu_generate_fdt_node(void *fdt, uint32_t cmask, char *pmu_name= ); void create_fdt_flash(void *fdt, hwaddr flashbase, hwaddr flashsize); +void create_fdt_syscon(void *fdt, uint32_t *phandle, + hwaddr addr, hwaddr size, + uint32_t reboot, uint32_t poweroff, + bool sifive_test_compat); #endif --=20 2.43.0 From nobody Sat Sep 26 23:03:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1787693128; cv=none; d=zohomail.com; s=zohoarc; b=dxJGKCszqY4pB1CT4tzy404r+dDKpSqqDuAfVwrHTwjJgchnpGR2w1xHX7thQ/t8yJ3XLMgnh9MaPkgAXAtAU3GQSfDdOr2b25/fVwrg+v8X5Feuj3nH2IWNl5avbL5XI8RtQ9K3pg8H5yzxnNUd1YzUQYHFexSN66+4uhfaT04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787693128; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=O9DGexoTufl6srH88MZz/5wXHHGKrgy2EfMWxzyd2nY=; b=PD3D2TBeTqUw8Wb/tTrUwHQ9qEUeMBSCdal0oRA+8Gx+27g8Iq7N9r3l9dendDKOuNv/IpzGOeUPKtnr0QBwcMV8BEJxhm6CBXfjXf5XQUIFlSyw4UbymxyXQMOh3ox0SxsX0ssTTWmuYA1YB6blZHF8gBJqnnnvBCKuDaH/25E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787693128084985.4542917854546; Tue, 25 Aug 2026 14:25:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyycf-0003VH-IZ; Tue, 25 Aug 2026 17:23:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyycd-0003Tf-DL for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:23:55 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyycb-0002Gj-K7 for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:23:55 -0400 Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67PL9hl82498720 for ; Tue, 25 Aug 2026 21:23:52 GMT Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g9fjn0tef-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 25 Aug 2026 21:23:52 +0000 (GMT) Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-90c8d271ac9so5852096d6.3 for ; Tue, 25 Aug 2026 14:23:52 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([189.38.141.232]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90cc65299f0sm8646386d6.41.2026.08.25.14.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 14:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=O9DGexoTufl 6srH88MZz/5wXHHGKrgy2EfMWxzyd2nY=; b=m/nvxvLfG2fx+h6X54haKdLdmrr pO7jvbKEqJtdzYq7xUr93OFjnwLQgKlMjqUBKSBobO0b8geIaQ0N8JReCtRRfBMZ aKiRFnfXq9yKmYUHLaZQnfys1LVXZcdL7tmP1y1aCk3LrQ4K+vl3R6x+aVyD+BQR bQgxCbjNPtpNd7CDuTlV95S/q3XbWcOwWCS/FVlgL+/89j5CsEAwZ8zeNiPjgyjK 1mho6DFgZdNWca8prPM/JHRH6E+myyf4T6Czd6mwo/dZG0ln3BvWE9O3f6s1iVLX qY7BDTo9dHE/a2SpmlRYmLhVviRGgG4ec05D01jwPwkEALZD4ndTliptLsw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787693031; x=1788297831; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=O9DGexoTufl6srH88MZz/5wXHHGKrgy2EfMWxzyd2nY=; b=UsTfGZ8U32cQSkTkfupnCKPFT8aaW1TeGBA2FmBLNEQXT5pQ2NfvJ1VvCarZ/maLlZ 5g7LN0zd6NGYBN2uhHAToHxS/hFZcPtwprYO/dm6f9UjGZohWHPG8e6shZvC/SatNoxl dKDoF9ZCs+bheCgWjNsfCjwT9ImMy/BmS4GouH3k9mVw+IamFKHQN/q234XL4Ql6Zt0+ VCuJy+psYXZoybups2ru5eFEDOH+DUryd3wJ9Zh2JjODaK9XVwjU6AsKTNJN7SVq95OG ArkjHKBS9LGCNiG2fVIuuBdL7t+V8Q/ezG3wa3g4m6m2Zpp6xApCJrg1pbGhhgUby3lx Ce8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787693031; x=1788297831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=O9DGexoTufl6srH88MZz/5wXHHGKrgy2EfMWxzyd2nY=; b=nJ39I5OUBy8PpVmMyF/2uV3DoFB8sY6FHMt7NiK9vB5OhUayi+qcX6IBuusuxsTEDR NRMrGpL2FQcdk+GAI5reIVwRv9n++P/SPF7glxD0wSLIP1dVF/zIWqLsffsIKSL1PDnE MpnSSd4rRdZ1m/3KOIOqbjRW74/PN0P0cIysfTMWcmblfJYQFXiRLdRDm50s9EBPRrpE itWkjd14wSXiFr0Gyb6K2sYjlYHDwzidzcyux4E6f1/BHzh4qfXXoEdH1+qauF3Jjbol lt7Azf1umpXyKXUakwRKJf4HPgejRF/lr85lbBNj/rnCI05BDeQXHzzSJyXDk3cjhr4a r8kQ== X-Gm-Message-State: AFuF++njZQiyMUeRvRN+O6TTOFAHyHORqbUKVls4chV+q52K+ljEbJEB 9jiltFT0CJx6DpVYWOagKtAyQaUNzmr+iBbjvukqTQhX0eNx6Aw2imUPrKhITSyCeDUdSxz+K+L Pg2L/10NOQBohCeEEgdO3dSoPALl44/0nQJ35Fite6K5a5tAhwNDaT4VrnmYssKuGoQ== X-Gm-Gg: AR+sD12LSM8+wE4896d72klSqMO/0U84pMg1tUqElkzHtT42/7lsX3UEPiD/lo3zadF 6QHL2kT/B3NOynQm3Nf7gzXmxKlZ0JNG+06aObUrqXvoSRtPT3W7oBGvGoLR1I+ncAzfWqHoQYt PMxW3KfmsnSPkFQWuAdipA4RksCd8bQ95PGl5VE+gpqA6eim49139le8C1mH1xFo427pO4mArKr uahy7AVd318bJropQ56Gi/P18Z4u2m3ZI00h1EvZV8hflTo+3NWkmInL15QRzhCLkIgq8QWTyTk iD8is6cp8+VmIcqQhMms2n7voRyVATK1W+mESH+I3bCrCGfFZP9gQcBwix+jQHy+qeiMtBeiuyN q/J6TQZ+XvxsQtxSiYiwi3gnz5YObWI9pSxDHPQ== X-Received: by 2002:a05:6214:4605:b0:8ee:d9e7:be2d with SMTP id 6a1803df08f44-90cc79308d8mr18698076d6.7.1787693031255; Tue, 25 Aug 2026 14:23:51 -0700 (PDT) X-Received: by 2002:a05:6214:4605:b0:8ee:d9e7:be2d with SMTP id 6a1803df08f44-90cc79308d8mr18697606d6.7.1787693030841; Tue, 25 Aug 2026 14:23:50 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com, Daniel Henrique Barboza , Palmer Dabbelt Subject: [PATCH 03/13] hw/riscv/fdt-common, virt.c: add create_fdt_riscv_iommu_sys() Date: Tue, 25 Aug 2026 18:23:15 -0300 Message-ID: <20260825212326.1907-4-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> References: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: l87-TPpvTjx_ggZwYB1WlZulhb5eUBYm X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfXzH2PqvKICY9E x2vA6uKyeIv7OQ1kM6+8yEy6HaGBeIVmGj0SC80M9XAAih16+1t1pCWvKBVy/jb2dzxptPqAkZS Itvx9BL+ChAj8Jj+Y2+HtnxyyOBfLDc= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX6jcynybjbMjt 8orC+HpZydyqi4OCp4Tu7oM17sUUN4XEbdjUCMVTAXEbq7+6Ag+bufbvj1efuoSqxnH4YvkO+yK 8PHUG63/tc45T63siDcUdWJmOMwC5RyY4GldbEiGsX1ozA4QXRgH37sULkRYJTw9801Nmt3mbe4 M97+YdLnjs0zwhA8+umMBeS5i/gBUITYXQd7HAUddEK11jgrq7gcNS/iH89N083dYqH+dYBeCx5 BgxDgf9aDlX/rGl+hKUKvqRxqYN6Pkou2sx5lACWUKdSDENelAhaYAz04Qj7LnXfb8FL+LmIOeh vCnhkUdbedkVMjBcCvBxUq5B0Jd9N3hmGytMyZeedlVS1/ZSRZp4QnQGuXYPGidX7WFl4jZqyE8 cG5Xvt2NQdINf2wUJcDjmFBYMhNp7fc7+8WJsue1QcgkcOQXvWCQQ22UmSuGbn6KvPw5TYDMgZw yG6Z/6irAjG26Sx9uLg== X-Authority-Analysis: v=2.4 cv=ccziaHDM c=1 sm=1 tr=0 ts=6a8e07e8 cx=c_pps a=UgVkIMxJMSkC9lv97toC5g==:117 a=MCIxunHWmQOg/5OnbzXZaw==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=EUspDBNiAAAA:8 a=-lP9cGLPB0zaG0B-UEoA:9 a=1HOtulTD9v-eNWfpl4qZ:22 X-Proofpoint-ORIG-GUID: l87-TPpvTjx_ggZwYB1WlZulhb5eUBYm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_06,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 clxscore=1015 malwarescore=0 bulkscore=0 adultscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250182 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1787693129808158500 Content-Type: text/plain; charset="utf-8" Both the 'virt' board and the future 'riscv-server-ref' boards uses an iommu-sys device that is declared in the DT. Create a helper to encapsulate the logic and avoid copy/pasting stuff between boards. No FDT changes intended. Signed-off-by: Daniel Henrique Barboza --- hw/riscv/fdt-common.c | 40 +++++++++++++++++++++++++++++ hw/riscv/virt.c | 47 ++++------------------------------- include/hw/riscv/fdt-common.h | 5 ++++ 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/hw/riscv/fdt-common.c b/hw/riscv/fdt-common.c index a2168c09ec..ddc56821d3 100644 --- a/hw/riscv/fdt-common.c +++ b/hw/riscv/fdt-common.c @@ -13,6 +13,8 @@ #include "hw/core/boards.h" #include "hw/riscv/fdt-common.h" #include "target/riscv/cpu_bits.h" +#include "hw/riscv/riscv-iommu-bits.h" +#include "hw/riscv/iommu.h" =20 void *create_board_device_tree(const char *model, const char *compatible, int *fdt_size) @@ -347,3 +349,41 @@ void create_fdt_syscon(void *fdt, uint32_t *phandle, qemu_fdt_setprop_cell(fdt, name, "value", poweroff); g_free(name); } + +void create_fdt_riscv_iommu_sys(void *fdt, hwaddr addr, hwaddr size, + uint32_t irq_chip, + uint32_t msi_phandle, + uint32_t *iommu_sys_phandle, + uint32_t iommu_sys_irq) +{ + const char comp[] =3D "riscv,iommu"; + uint32_t iommu_phandle; + g_autofree char *iommu_node =3D NULL; + uint32_t iommu_irq_map[RISCV_IOMMU_INTR_COUNT] =3D { + iommu_sys_irq + RISCV_IOMMU_INTR_CQ, + iommu_sys_irq + RISCV_IOMMU_INTR_FQ, + iommu_sys_irq + RISCV_IOMMU_INTR_PM, + iommu_sys_irq + RISCV_IOMMU_INTR_PQ, + }; + + iommu_node =3D g_strdup_printf("/soc/iommu@%"HWADDR_PRIx, addr); + iommu_phandle =3D qemu_fdt_alloc_phandle(fdt); + qemu_fdt_add_subnode(fdt, iommu_node); + + qemu_fdt_setprop(fdt, iommu_node, "compatible", comp, sizeof(comp)); + qemu_fdt_setprop_cell(fdt, iommu_node, "#iommu-cells", 1); + qemu_fdt_setprop_cell(fdt, iommu_node, "phandle", iommu_phandle); + + qemu_fdt_setprop_sized_cells(fdt, iommu_node, "reg", 2, addr, 2, size); + qemu_fdt_setprop_cell(fdt, iommu_node, "interrupt-parent", irq_chip); + + qemu_fdt_setprop_cells(fdt, iommu_node, "interrupts", + iommu_irq_map[0], FDT_IRQ_TYPE_EDGE_LOW, + iommu_irq_map[1], FDT_IRQ_TYPE_EDGE_LOW, + iommu_irq_map[2], FDT_IRQ_TYPE_EDGE_LOW, + iommu_irq_map[3], FDT_IRQ_TYPE_EDGE_LOW); + + qemu_fdt_setprop_cell(fdt, iommu_node, "msi-parent", msi_phandle); + + *iommu_sys_phandle =3D iommu_phandle; +} diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index acbbe458fa..9417aa7a06 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -867,46 +867,6 @@ static void create_fdt_virtio_iommu(RISCVVirtState *s,= uint16_t bdf) bdf + 1, iommu_phandle, bdf + 1, 0xffff - bdf); } =20 -static void create_fdt_iommu_sys(RISCVVirtState *s, uint32_t irq_chip, - uint32_t msi_phandle, - uint32_t *iommu_sys_phandle) -{ - const char comp[] =3D "riscv,iommu"; - void *fdt =3D MACHINE(s)->fdt; - uint32_t iommu_phandle; - g_autofree char *iommu_node =3D NULL; - hwaddr addr =3D s->memmap[VIRT_IOMMU_SYS].base; - hwaddr size =3D s->memmap[VIRT_IOMMU_SYS].size; - uint32_t iommu_irq_map[RISCV_IOMMU_INTR_COUNT] =3D { - IOMMU_SYS_IRQ + RISCV_IOMMU_INTR_CQ, - IOMMU_SYS_IRQ + RISCV_IOMMU_INTR_FQ, - IOMMU_SYS_IRQ + RISCV_IOMMU_INTR_PM, - IOMMU_SYS_IRQ + RISCV_IOMMU_INTR_PQ, - }; - - iommu_node =3D g_strdup_printf("/soc/iommu@%x", - (unsigned int) s->memmap[VIRT_IOMMU_SYS].ba= se); - iommu_phandle =3D qemu_fdt_alloc_phandle(fdt); - qemu_fdt_add_subnode(fdt, iommu_node); - - qemu_fdt_setprop(fdt, iommu_node, "compatible", comp, sizeof(comp)); - qemu_fdt_setprop_cell(fdt, iommu_node, "#iommu-cells", 1); - qemu_fdt_setprop_cell(fdt, iommu_node, "phandle", iommu_phandle); - - qemu_fdt_setprop_sized_cells(fdt, iommu_node, "reg", 2, addr, 2, size); - qemu_fdt_setprop_cell(fdt, iommu_node, "interrupt-parent", irq_chip); - - qemu_fdt_setprop_cells(fdt, iommu_node, "interrupts", - iommu_irq_map[0], FDT_IRQ_TYPE_EDGE_LOW, - iommu_irq_map[1], FDT_IRQ_TYPE_EDGE_LOW, - iommu_irq_map[2], FDT_IRQ_TYPE_EDGE_LOW, - iommu_irq_map[3], FDT_IRQ_TYPE_EDGE_LOW); - - qemu_fdt_setprop_cell(fdt, iommu_node, "msi-parent", msi_phandle); - - *iommu_sys_phandle =3D iommu_phandle; -} - static void create_fdt_iommu(RISCVVirtState *s, uint16_t bdf) { const char comp[] =3D "riscv,pci-iommu"; @@ -945,8 +905,11 @@ static void finalize_fdt(RISCVVirtState *s) create_fdt_virtio(s, irq_virtio_phandle); =20 if (virt_is_iommu_sys_enabled(s)) { - create_fdt_iommu_sys(s, irq_mmio_phandle, msi_pcie_phandle, - &iommu_sys_phandle); + create_fdt_riscv_iommu_sys(MACHINE(s)->fdt, + s->memmap[VIRT_IOMMU_SYS].base, + s->memmap[VIRT_IOMMU_SYS].size, + irq_mmio_phandle, msi_pcie_phandle, + &iommu_sys_phandle, IOMMU_SYS_IRQ); } create_fdt_pcie(s, irq_pcie_phandle, msi_pcie_phandle, iommu_sys_phandle); diff --git a/include/hw/riscv/fdt-common.h b/include/hw/riscv/fdt-common.h index 31203df517..37a1544706 100644 --- a/include/hw/riscv/fdt-common.h +++ b/include/hw/riscv/fdt-common.h @@ -41,4 +41,9 @@ void create_fdt_syscon(void *fdt, uint32_t *phandle, hwaddr addr, hwaddr size, uint32_t reboot, uint32_t poweroff, bool sifive_test_compat); +void create_fdt_riscv_iommu_sys(void *fdt, hwaddr addr, hwaddr size, + uint32_t irq_chip, + uint32_t msi_phandle, + uint32_t *iommu_sys_phandle, + uint32_t iommu_sys_irq); #endif --=20 2.43.0 From nobody Sat Sep 26 23:03:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1787693133; cv=none; d=zohomail.com; s=zohoarc; b=fDxWgOMt2oHp5T3E6/Yo7AIcGocDv+eAZ0+G+gU66lvD2OhY5kB+4JbSPgYOz4aStvrwrjuNDdkjRrPHzxQtdhoBLU60FbJ3Fry16ZupAtFncABEvbrBemZih3z7W2vp0fSvhk4+fHBoInNrK8pZELmBupELH9TYWCGlGoRhzbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787693133; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=g9NYXEbKr18TjHgXcHHA/K5gxI00/QYaZJRDaH3D9ew=; b=FrsmCX3dwT9bLP1/nfuBqep/2Z/ZstE6mx1msmP42zvwM0EIS2nTBSLsCRcnOg9uNLhsUS4UiGOM4BrXVXmBQkyh/TK5hjqeKeV1j/Jin9kUzKyeSEIQsRc0XfH7Qs4NJQ2VTulY5hvYk2ffn/pyAfjNCnRvzR/lvpMV+p8wX94= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787693133689631.3071186403932; Tue, 25 Aug 2026 14:25:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyyci-0003WQ-5v; Tue, 25 Aug 2026 17:24:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyycg-0003Vq-P8 for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:23:58 -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 1wyyce-0002HO-It for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:23:58 -0400 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67PLAJ5q2899382 for ; Tue, 25 Aug 2026 21:23:54 GMT Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g9fceruc2-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 25 Aug 2026 21:23:54 +0000 (GMT) Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-51c0408254aso16939001cf.0 for ; Tue, 25 Aug 2026 14:23:54 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([189.38.141.232]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90cc65299f0sm8646386d6.41.2026.08.25.14.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 14:23:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=g9NYXEbKr18 TjHgXcHHA/K5gxI00/QYaZJRDaH3D9ew=; b=PvwdADS7D7bjdLDRu3KdB5Ap/Jy XNDazIsFJKjijjOgZv7zgh9QuHSpcXeFrMjkKZOGuFzlTLFZDNgj2IXyUFH1gi9o SR66YWGODZgqaXhaMzdTBPT5JidPTUZ8dWELgoPX2q/RT0b7ysnZBxJ7aNfz2/tI X06sf8lXyFsRXRg0Xt9iOi6Ls8g5N3/qXHRCsB+HSr72Ap0iYxAyGdqvo3zSbTsL LOzKJtw9f1lP4T0ruYeGKPNLKoHkPbFhdUw6R9GDxAxAqvDZAVwgJg2e82ThvK5y BgfGZ3l0DKbdbGF4OTuKxPGsdUejJ4faZu5O2o/GxzQPdXAK7s7oATWisyQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787693034; x=1788297834; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=g9NYXEbKr18TjHgXcHHA/K5gxI00/QYaZJRDaH3D9ew=; b=Jt1QvF20ldbjdCoO6R7JdTtUD6WRl0JYBWoHz2EhwdND+y5e+FD94hsZJ1+OX0/EJK 0mxjACJgA80yWWSOAJmtKwHpfGotgbqMfSoHF+1nIL5+H/j/tdmvbRhPLW6T8ULIPWNj qlsXxxjQjCYgKlWrTwMopu9mmHFZtIl0ZwbwGVH7OIlhNxbcCa7G+iHSZxAbV42t3b+l LVtuNXgrKXaMrhFW0qAG2V5KBZLTLZJ+m0FKHqOCsAMmjRrEAJVNB1FV531IswSsVJW5 U/1itv5swbUxgbRXmdWWIRu8Wo2BcAM8wuOn06QpodWY3pQgfvmfn1/9aD/q/Tkd6wDk T0Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787693034; x=1788297834; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=g9NYXEbKr18TjHgXcHHA/K5gxI00/QYaZJRDaH3D9ew=; b=qF4hVgWdn7LQV59xsW90HVVnZgJVLKQ/lx/wNCnpy6NFoSFa1UhG8yauH92SObLI8U MthrgwC46GSW/nouj/4WF4SrAXNcBUl1ExF05wz2qesnmkGDV8prSxeqtn14fFu0fB1Z b6g6niNK/LTTfszqg8XmrWmxRm4DKhoYuec4yoDq/xl95Xh6QxgOzhStoOLgahQjlcKg 0rsRWKRAB0AImK3s4F/xa549I1YjsOckqCuygKyLAOvE6XcVGoWUORYPZcjbNzeDtNoU vmwr31Wi9aGq5sjscnhAOIEZ5xU4QPuJWhY6ywGnU/TZNDavSFy4NAEky/MPu0O1o7j9 vDsw== X-Gm-Message-State: AFuF++miEXTtorNfhWeMkPqYHkqjgLYI4ex1xfNJ69opPA1lO9PcNU4t GT4IXOxSN3EDk1Hm5QyxSTfKM5cRNzsqrxTbHBIN9iv0lfPwhUjjFUpL1Sf2F7i6ILZ+50peARA iAqK2YOjWCUlrCeCW2EhmyxXmzp/0+HlOZji+7nwcTTZC69fd4lWrJGCBev2hOSpnyQ== X-Gm-Gg: AR+sD12TkVC+3nXTWatNckvIcczEA63fmWkm41jdc8Dwlth55fOmGuIubc0Sv3h0gQF IF/aCptnyz5We10rdKEJ33FeDRVpkCZN1Icb+GP4bHSKwB5rtbp38jO5jn+l/gGX84vv1mtT04R tSBlKP0XvoIW6hH6COxFoUqNK2QVT7NETvRIz6Owm/3/D6+IZeBjzU+WNmWzYFVlVieWHxNmvvh jPEc+BseqZqrX9OhsoEQMwnWZMtKy1IT2Pu5GrKeTK972CoG1ZL/9lZ/mL4QqMLoN89GEy738Zk 1sqULmerNjzVyooehACFPoX6WOHnYZjUm2XZpb0u7alsU220fDFPPL0WI0eBrGVJ3Euknm1e69I KTyoDdlj227fQ5oVOTA9BRsL741Um8dgKmnSg1A== X-Received: by 2002:ac8:59d1:0:b0:52e:125b:9444 with SMTP id d75a77b69052e-52e2ed0710dmr104202661cf.17.1787693033753; Tue, 25 Aug 2026 14:23:53 -0700 (PDT) X-Received: by 2002:ac8:59d1:0:b0:52e:125b:9444 with SMTP id d75a77b69052e-52e2ed0710dmr104202121cf.17.1787693033231; Tue, 25 Aug 2026 14:23:53 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com, Daniel Henrique Barboza , Palmer Dabbelt Subject: [PATCH 04/13] hw/riscv/fdt_common, virt.c: add create_fdt_pcie() Date: Tue, 25 Aug 2026 18:23:16 -0300 Message-ID: <20260825212326.1907-5-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> References: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=a8AAM0SF c=1 sm=1 tr=0 ts=6a8e07ea cx=c_pps a=WeENfcodrlLV9YRTxbY/uA==:117 a=MCIxunHWmQOg/5OnbzXZaw==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=EUspDBNiAAAA:8 a=nzCZRCZgkTuinHKBC8cA:9 a=kacYvNCVWA4VmyqE58fU:22 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX/aQl5OvJfSP3 UwLN8GZOyhJiwX6lEPWEDQaPUzDHhhUsqluxRtMP4O4BifoSV/ax/W3l9dHD+bGzAJZqm/t1k0b GWYXwT7yliZlG9neYK9lV7foZvqb6aw= X-Proofpoint-ORIG-GUID: Anf7U5XeTtoso1NaRJEG9IifB_KlREjC X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX9/QSj6N4/S/g x40WFbkPMQRDMtaDlPME2MyUJkr3iHxwQgCtRnwPW0wBCFeh2VZofAwRUv593pSNgF/orWDuosG n6JJl++HUHkJiK0oFY9PDQSpaAyJL6YIHxcl6pDJ8oTcAUku6URClZvn9gCxg4hG7kBkqgnswtV AsZ7o+azEM+aTFXy+cjgxI10Yuw+CYQp8tyadiK3X4ezrFtMfiRxPSVKE6juE32yaTOeA1B13eW ncFXV/i6jq66I6XYFgMryoeQZcI5c11iN+LGF1LFNphokaQeMc9iahB30V/1yIRXpLXR/rroI2q 2l6UCcs28l1XfdwiEGXgRoBoDdkuaB1UosqIKLpVCAXezkTM+GvkTN5omnAW0QKuJ7m8yaz2ntj vCrCtsWbPmafaLu04r2G0t5gy0iv54Us9NWD5bummdbw64SvXlvLCxgPbnXsARK51BblGaOCuC9 fLxb2flD4hxClWB1YIg== X-Proofpoint-GUID: Anf7U5XeTtoso1NaRJEG9IifB_KlREjC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_06,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 spamscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 impostorscore=0 clxscore=1015 suspectscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250182 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1787693135712158500 Content-Type: text/plain; charset="utf-8" The pcie FDT is quite tedious but can be parametrized into a helper. This is going to benefit only the 'virt' board for now but it will be used by the 'riscv-server-ref' board in the near future too. Some other changes made: - FDT related macros are moved to fdt-common.h. Only a couple are being used by the helper ATM but more will be added in the next patches; - an RISCVAIAType enum is created. There are several FDTs that depends on the active AIA type being used, and we want a way to represent the different AIA modes that doesn't re-use the 'virt' specific VIRT_AIA_* macros. The enum vals are equivalent by design - we want "s->aia_type" to be used by 'virt' when calling the fdt helpers, and other boards will use "AIA_*" macros in their code. No FDT changes made. Signed-off-by: Daniel Henrique Barboza --- hw/riscv/fdt-common.c | 108 ++++++++++++++++++++++++++++++++++ hw/riscv/virt.c | 108 ++-------------------------------- include/hw/riscv/fdt-common.h | 26 ++++++++ include/hw/riscv/virt.h | 15 ----- 4 files changed, 140 insertions(+), 117 deletions(-) diff --git a/hw/riscv/fdt-common.c b/hw/riscv/fdt-common.c index ddc56821d3..67a0a3d8f2 100644 --- a/hw/riscv/fdt-common.c +++ b/hw/riscv/fdt-common.c @@ -15,6 +15,8 @@ #include "target/riscv/cpu_bits.h" #include "hw/riscv/riscv-iommu-bits.h" #include "hw/riscv/iommu.h" +#include "hw/pci/pci.h" +#include "hw/pci/pcie_host.h" =20 void *create_board_device_tree(const char *model, const char *compatible, int *fdt_size) @@ -387,3 +389,109 @@ void create_fdt_riscv_iommu_sys(void *fdt, hwaddr add= r, hwaddr size, =20 *iommu_sys_phandle =3D iommu_phandle; } + +static void create_pcie_irq_map(void *fdt, char *nodename, + uint32_t irqchip_phandle, + RISCVAIAType aia_type, uint32_t pcie_irq) +{ + int pin, dev; + uint32_t irq_map_stride =3D 0; + uint32_t full_irq_map[PCI_NUM_PINS * PCI_NUM_PINS * + FDT_MAX_INT_MAP_WIDTH] =3D {}; + uint32_t *irq_map =3D full_irq_map; + + /* + * This code creates a standard swizzle of interrupts such that + * each device's first interrupt is based on it's PCI_SLOT number. + * (See pci_swizzle_map_irq_fn()) + * + * We only need one entry per interrupt in the table (not one per + * possible slot) seeing the interrupt-map-mask will allow the table + * to wrap to any number of devices. + */ + for (dev =3D 0; dev < PCI_NUM_PINS; dev++) { + int devfn =3D dev * 0x8; + + for (pin =3D 0; pin < PCI_NUM_PINS; pin++) { + int irq_nr =3D pcie_irq + ((pin + PCI_SLOT(devfn)) % PCI_NUM_P= INS); + int i =3D 0; + + /* Fill PCI address cells */ + irq_map[i] =3D cpu_to_be32(devfn << 8); + i +=3D FDT_PCI_ADDR_CELLS; + + /* Fill PCI Interrupt cells */ + irq_map[i] =3D cpu_to_be32(pin + 1); + i +=3D FDT_PCI_INT_CELLS; + + /* Fill interrupt controller phandle and cells */ + irq_map[i++] =3D cpu_to_be32(irqchip_phandle); + irq_map[i++] =3D cpu_to_be32(irq_nr); + + if (aia_type !=3D AIA_TYPE_NONE) { + irq_map[i++] =3D cpu_to_be32(0x4); + } + + if (!irq_map_stride) { + irq_map_stride =3D i; + } + irq_map +=3D irq_map_stride; + } + } + + qemu_fdt_setprop(fdt, nodename, "interrupt-map", full_irq_map, + PCI_NUM_PINS * PCI_NUM_PINS * + irq_map_stride * sizeof(uint32_t)); + + qemu_fdt_setprop_cells(fdt, nodename, "interrupt-map-mask", + 0x1800, 0, 0, 0x7); +} + +/* + * NOTE: this function uses a "/soc/pci@..." FDT subnode that + * should be created beforehand. + */ +void create_fdt_pcie(void *fdt, int aia_type, bool has_iommu_sys, + const MemMapEntry *pcie_ecam, const MemMapEntry *pcie= _pio, + const MemMapEntry *pcie_mmio, const MemMapEntry *high= _pcie, + uint32_t irq_pcie_phandle, uint32_t msi_pcie_phandle, + uint32_t iommu_sys_phandle, uint32_t pcie_irq) +{ + g_autofree char *name =3D NULL; + + name =3D g_strdup_printf("/soc/pci@%"HWADDR_PRIx, pcie_ecam->base); + qemu_fdt_setprop_cell(fdt, name, "#address-cells", FDT_PCI_ADDR_CELLS); + qemu_fdt_setprop_cell(fdt, name, "#interrupt-cells", FDT_PCI_INT_CELLS= ); + qemu_fdt_setprop_cell(fdt, name, "#size-cells", 0x2); + qemu_fdt_setprop_string(fdt, name, "compatible", "pci-host-ecam-generi= c"); + qemu_fdt_setprop_string(fdt, name, "device_type", "pci"); + qemu_fdt_setprop_cell(fdt, name, "linux,pci-domain", 0); + + qemu_fdt_setprop_cells(fdt, name, "bus-range", 0, + pcie_ecam->size / PCIE_MMCFG_SIZE_MIN - 1); + qemu_fdt_setprop(fdt, name, "dma-coherent", NULL, 0); + + if (aia_type =3D=3D AIA_TYPE_APLIC_IMSIC) { + qemu_fdt_setprop_cell(fdt, name, "msi-parent", msi_pcie_phandle); + } + + qemu_fdt_setprop_sized_cells(fdt, name, "reg", 2, + pcie_ecam->base, 2, pcie_ecam->size); + + qemu_fdt_setprop_sized_cells(fdt, name, "ranges", + 1, FDT_PCI_RANGE_IOPORT, 2, 0, + 2, pcie_pio->base, 2, pcie_pio->size, + 1, FDT_PCI_RANGE_MMIO, + 2, pcie_mmio->base, + 2, pcie_mmio->base, 2, pcie_mmio->size, + 1, FDT_PCI_RANGE_MMIO_64BIT, + 2, high_pcie->base, + 2, high_pcie->base, 2, high_pcie->size); + + if (has_iommu_sys) { + qemu_fdt_setprop_cells(fdt, name, "iommu-map", + 0, iommu_sys_phandle, 0, 0x10000); + } + + create_pcie_irq_map(fdt, name, irq_pcie_phandle, aia_type, pcie_irq); +} diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 9417aa7a06..fc381a07f3 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -180,61 +180,6 @@ static void virt_flash_map(RISCVVirtState *s, sysmem); } =20 -static void create_pcie_irq_map(RISCVVirtState *s, void *fdt, char *nodena= me, - uint32_t irqchip_phandle) -{ - int pin, dev; - uint32_t irq_map_stride =3D 0; - uint32_t full_irq_map[PCI_NUM_PINS * PCI_NUM_PINS * - FDT_MAX_INT_MAP_WIDTH] =3D {}; - uint32_t *irq_map =3D full_irq_map; - - /* - * This code creates a standard swizzle of interrupts such that - * each device's first interrupt is based on it's PCI_SLOT number. - * (See pci_swizzle_map_irq_fn()) - * - * We only need one entry per interrupt in the table (not one per - * possible slot) seeing the interrupt-map-mask will allow the table - * to wrap to any number of devices. - */ - for (dev =3D 0; dev < PCI_NUM_PINS; dev++) { - int devfn =3D dev * 0x8; - - for (pin =3D 0; pin < PCI_NUM_PINS; pin++) { - int irq_nr =3D PCIE_IRQ + ((pin + PCI_SLOT(devfn)) % PCI_NUM_P= INS); - int i =3D 0; - - /* Fill PCI address cells */ - irq_map[i] =3D cpu_to_be32(devfn << 8); - i +=3D FDT_PCI_ADDR_CELLS; - - /* Fill PCI Interrupt cells */ - irq_map[i] =3D cpu_to_be32(pin + 1); - i +=3D FDT_PCI_INT_CELLS; - - /* Fill interrupt controller phandle and cells */ - irq_map[i++] =3D cpu_to_be32(irqchip_phandle); - irq_map[i++] =3D cpu_to_be32(irq_nr); - if (s->aia_type !=3D VIRT_AIA_TYPE_NONE) { - irq_map[i++] =3D cpu_to_be32(0x4); - } - - if (!irq_map_stride) { - irq_map_stride =3D i; - } - irq_map +=3D irq_map_stride; - } - } - - qemu_fdt_setprop(fdt, nodename, "interrupt-map", full_irq_map, - PCI_NUM_PINS * PCI_NUM_PINS * - irq_map_stride * sizeof(uint32_t)); - - qemu_fdt_setprop_cells(fdt, nodename, "interrupt-map-mask", - 0x1800, 0, 0, 0x7); -} - static void create_fdt_socket_aclint(RISCVVirtState *s, int socket, uint32_t *intc_phandles) @@ -721,51 +666,6 @@ static void create_fdt_virtio(RISCVVirtState *s, uint3= 2_t irq_virtio_phandle) } } =20 -static void create_fdt_pcie(RISCVVirtState *s, - uint32_t irq_pcie_phandle, - uint32_t msi_pcie_phandle, - uint32_t iommu_sys_phandle) -{ - g_autofree char *name =3D NULL; - MachineState *ms =3D MACHINE(s); - - name =3D g_strdup_printf("/soc/pci@%"HWADDR_PRIx, - s->memmap[VIRT_PCIE_ECAM].base); - qemu_fdt_setprop_cell(ms->fdt, name, "#address-cells", - FDT_PCI_ADDR_CELLS); - qemu_fdt_setprop_cell(ms->fdt, name, "#interrupt-cells", - FDT_PCI_INT_CELLS); - qemu_fdt_setprop_cell(ms->fdt, name, "#size-cells", 0x2); - qemu_fdt_setprop_string(ms->fdt, name, "compatible", - "pci-host-ecam-generic"); - qemu_fdt_setprop_string(ms->fdt, name, "device_type", "pci"); - qemu_fdt_setprop_cell(ms->fdt, name, "linux,pci-domain", 0); - qemu_fdt_setprop_cells(ms->fdt, name, "bus-range", 0, - s->memmap[VIRT_PCIE_ECAM].size / PCIE_MMCFG_SIZE_MIN - 1); - qemu_fdt_setprop(ms->fdt, name, "dma-coherent", NULL, 0); - if (s->aia_type =3D=3D VIRT_AIA_TYPE_APLIC_IMSIC) { - qemu_fdt_setprop_cell(ms->fdt, name, "msi-parent", msi_pcie_phandl= e); - } - qemu_fdt_setprop_sized_cells(ms->fdt, name, "reg", 2, - s->memmap[VIRT_PCIE_ECAM].base, 2, s->memmap[VIRT_PCIE_ECAM].size); - qemu_fdt_setprop_sized_cells(ms->fdt, name, "ranges", - 1, FDT_PCI_RANGE_IOPORT, 2, 0, - 2, s->memmap[VIRT_PCIE_PIO].base, 2, s->memmap[VIRT_PCIE_PIO].size, - 1, FDT_PCI_RANGE_MMIO, - 2, s->memmap[VIRT_PCIE_MMIO].base, - 2, s->memmap[VIRT_PCIE_MMIO].base, 2, s->memmap[VIRT_PCIE_MMIO].si= ze, - 1, FDT_PCI_RANGE_MMIO_64BIT, - 2, virt_high_pcie_memmap.base, - 2, virt_high_pcie_memmap.base, 2, virt_high_pcie_memmap.size); - - if (virt_is_iommu_sys_enabled(s)) { - qemu_fdt_setprop_cells(ms->fdt, name, "iommu-map", - 0, iommu_sys_phandle, 0, 0x10000); - } - - create_pcie_irq_map(s, ms->fdt, name, irq_pcie_phandle); -} - static void create_fdt_uart(RISCVVirtState *s, uint32_t irq_mmio_phandle, int memId, int irqN= o) { @@ -911,8 +811,12 @@ static void finalize_fdt(RISCVVirtState *s) irq_mmio_phandle, msi_pcie_phandle, &iommu_sys_phandle, IOMMU_SYS_IRQ); } - create_fdt_pcie(s, irq_pcie_phandle, msi_pcie_phandle, - iommu_sys_phandle); + + create_fdt_pcie(MACHINE(s)->fdt, s->aia_type, virt_is_iommu_sys_enable= d(s), + &s->memmap[VIRT_PCIE_ECAM], &s->memmap[VIRT_PCIE_PIO], + &s->memmap[VIRT_PCIE_MMIO], &virt_high_pcie_memmap, + irq_pcie_phandle, msi_pcie_phandle, iommu_sys_phandle, + PCIE_IRQ); =20 create_fdt_syscon(MACHINE(s)->fdt, &phandle, s->memmap[VIRT_TEST].base, s->memmap[VIRT_TEST].size, diff --git a/include/hw/riscv/fdt-common.h b/include/hw/riscv/fdt-common.h index 37a1544706..bee8b85597 100644 --- a/include/hw/riscv/fdt-common.h +++ b/include/hw/riscv/fdt-common.h @@ -11,6 +11,27 @@ =20 #include "target/riscv/cpu.h" =20 +#define FDT_PCI_ADDR_CELLS 3 +#define FDT_PCI_INT_CELLS 1 +#define FDT_PLIC_ADDR_CELLS 0 +#define FDT_PLIC_INT_CELLS 1 +#define FDT_APLIC_INT_CELLS 2 +#define FDT_APLIC_ADDR_CELLS 0 +#define FDT_IMSIC_INT_CELLS 0 +#define FDT_MAX_INT_CELLS 2 +#define FDT_MAX_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ + 1 + FDT_MAX_INT_CELLS) +#define FDT_PLIC_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ + 1 + FDT_PLIC_INT_CELLS) +#define FDT_APLIC_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ + 1 + FDT_APLIC_INT_CELLS) + +typedef enum RISCVAIAType { + AIA_TYPE_NONE =3D 0, + AIA_TYPE_APLIC, + AIA_TYPE_APLIC_IMSIC, +} RISCVAIAType; + void *create_board_device_tree(const char *model, const char *compatible, int *fdt_size); void create_fdt_socket_memory(void *fdt, hwaddr addr, uint64_t size, @@ -46,4 +67,9 @@ void create_fdt_riscv_iommu_sys(void *fdt, hwaddr addr, h= waddr size, uint32_t msi_phandle, uint32_t *iommu_sys_phandle, uint32_t iommu_sys_irq); +void create_fdt_pcie(void *fdt, int aia_type, bool has_iommu_sys, + const MemMapEntry *pcie_ecam, const MemMapEntry *pcie= _pio, + const MemMapEntry *pcie_mmio, const MemMapEntry *high= _pcie, + uint32_t irq_pcie_phandle, uint32_t msi_pcie_phandle, + uint32_t iommu_sys_phandle, uint32_t pcie_irq); #endif diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h index 7c862b0da2..e516898f9a 100644 --- a/include/hw/riscv/virt.h +++ b/include/hw/riscv/virt.h @@ -121,21 +121,6 @@ enum { #define VIRT_PLIC_SIZE(__num_context) \ (VIRT_PLIC_CONTEXT_BASE + (__num_context) * VIRT_PLIC_CONTEXT_STRIDE) =20 -#define FDT_PCI_ADDR_CELLS 3 -#define FDT_PCI_INT_CELLS 1 -#define FDT_PLIC_ADDR_CELLS 0 -#define FDT_PLIC_INT_CELLS 1 -#define FDT_APLIC_INT_CELLS 2 -#define FDT_APLIC_ADDR_CELLS 0 -#define FDT_IMSIC_INT_CELLS 0 -#define FDT_MAX_INT_CELLS 2 -#define FDT_MAX_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ - 1 + FDT_MAX_INT_CELLS) -#define FDT_PLIC_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ - 1 + FDT_PLIC_INT_CELLS) -#define FDT_APLIC_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ - 1 + FDT_APLIC_INT_CELLS) - bool virt_is_acpi_enabled(RISCVVirtState *s); bool virt_is_iommu_sys_enabled(RISCVVirtState *s); void virt_acpi_setup(RISCVVirtState *vms); --=20 2.43.0 From nobody Sat Sep 26 23:03:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1787693146; cv=none; d=zohomail.com; s=zohoarc; b=CiYTdsqc/5nHPqrzLgsBJedffY/+TQ4veiKkJcKwGiuuFCYZvW0dd6DlrA21fedKI/nJxah0e2tlwV/2Wry8ntGpvsie2HYfOLh9pvhH77fi5lKuFhDp1pp6PZJaWEhs0S8AA3QfZb/Vpg++JuBVmdY8OY9maKJDUpwpgm6CgoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787693146; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9HLPfSMUYJCKZ2A/C3+MYzp9wV3VCXZuI833t5CdRfM=; b=bJNG880WaVd2JzL0r/qCS9g2aRYzAn1svdr/IlzdpBFvdlIGCagrt23s2T5UKEIOQ5qa6ui6VmsNZnR0cFH04jSDEKHN0fJDb/oHClJ6Zf7xAN8AO027DK9pS65fjBdY/vgRmoMDK00ay++O8qt6zpqroHzYWX3H/xDayYDzVvQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787693146671391.9913113000879; Tue, 25 Aug 2026 14:25:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyycj-0003Xy-QS; Tue, 25 Aug 2026 17:24:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyyci-0003WW-7f for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:00 -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 1wyycg-0002Hb-5Z for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:23:59 -0400 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67PLALfa1925638 for ; Tue, 25 Aug 2026 21:23:57 GMT Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g9f9urubu-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 25 Aug 2026 21:23:57 +0000 (GMT) Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-52d33c89a29so3909871cf.1 for ; Tue, 25 Aug 2026 14:23:57 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([189.38.141.232]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90cc65299f0sm8646386d6.41.2026.08.25.14.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 14:23:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=9HLPfSMUYJC KZ2A/C3+MYzp9wV3VCXZuI833t5CdRfM=; b=mBCBRcGLUDE1jSH3/Oxr7ecOSWV J/PrDdQFxt6/Ep0359iHLRr+oARYtcSPQqaH/bpH8SG1vj62SdmiDBdPUJdQduLk MK32f5ScA1YdZgKmsXgSF6CJP0viDT1r7yIFFUoScAGxLlZrHcQHY657iBFZgOyC EJG8dqVVSN019ZYKDFoNNsC6fSPCsYIW2CvisvQ+ELvpZo7YnVdl2itH9g+aWyHR I1KQ0LtVlB/wCtNrUVkKip9ZsYOrOuSqRzD4FdXg32ZR1KIKA0JQWWLMQXTdnQnC MIkhBJUChnxLJYgD9/HLsaRePbUUXEfVfeL/YYAZtNcFwqnOduHbtKp7Xow== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787693036; x=1788297836; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=9HLPfSMUYJCKZ2A/C3+MYzp9wV3VCXZuI833t5CdRfM=; b=T1DmS/Mr/nuok79j0r7l9yu/ZyD1ddUQJfXXcHsuMZJhcY7/rsWpJzWOHcxjac2kOv DytKgXlgb5ANEG+Xy8sMa6oRpTEyVEM0rO8AINR02gL4ecuwC98C0zP7yK6y1HmToDUt NTjCaVhtts3zbfF7WkbhoVLz8lCecdsJ51c4/gZweYwL7uBKAKfNaQvVslPeRGNQALgE I2W4hoh4hwOBmtJktx1NssZyU9PCM55ATEI+XzD68KbsQn97JrmOQt07GzQvobeG/V1X sod2bBoVt2gZy6BZS+1JGRUEGcOBQI0l/ht3lccwK2dHMaXUumlJSsHVtUMUN+lP+BFm +W/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787693036; x=1788297836; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=9HLPfSMUYJCKZ2A/C3+MYzp9wV3VCXZuI833t5CdRfM=; b=aOsWOT5ERl9UspOMStnLmvNz/8aQSxpeR1qS/r9mtvONAfdBp5FmG+oHyvMPRiug0p mxa6UK85aNh2J2VEEiLKYjhE7Vf5HMhDFdKHJw9GE9gbPtzKPuaiJSN+UXCu75tI812n gtCHlmzFO0z0fFbvYkJMvm9U58st0g/1C9Yw4gsRrisjF58RZMi9+0KUcrCUtBribfPj N7MPkXy3sdHOPXjvCPN9DtBlCcYLr/Dd3YgA43VfQGrsnmeSkBiHr8xkI6+12CtO6bJH AQr5UMVV7AaVtOtjm0So7LdEorUS8Q9VSfJjplg9uEPfyYPC3P+Hz1j20LrchPNFQ+nY va5Q== X-Gm-Message-State: AFuF++kmEMt4IUQvwGQNrGB8VCBB/FcpEAgATKDMrVwfyn+A2tqMeKuC QtdsL7YAcWKMSv/JPWZpGyyk3Y2DU9NQGPixDU7w2In4GuXgkiTpN+dRx+MRZv8iIgJn1V6LObN BCa5JiGNajYUrcElU7ysi89ZE62GKA7AC5RTe/39DQW9kKm4SemgRvLlpet/0XHaKlw== X-Gm-Gg: AR+sD12/XJmiWJa03xHnDfXxGsnLLweH/JwgWYc6oRYg8iOvcyjcKjg+FyrR5Gz8+1e IjcbpnTzdbgE4QxA2eu39KZoxyzMDjQieyYr3Rs6AbHi8pNcECEnn/b6w5OEE/Tq7slNgt+u+EC hX0ZFcIP7LHlvIdCls1rb23JLo4d/cDz3XhsRdqWCYR3KmX8rWZFwMpmwts8dqRATZQMumxfRqd rIXBqVZOBTF7rATrYOen4s/RSDhzzvueKQJFc/kuvQ9P2xYVbkI0olbMFRdSS6IcX5kEQP/OiJk lsLQxjUUpnTsN7PZjNpyidZfj6NLhvf4rNPmLT/bb6/VNvya9K1AOE2m3Es2J6bRSPGBjmkd0qg VpngZ1+Ucg+YZtc60hjIy7eRLYCAV6ky70LPK3g== X-Received: by 2002:a05:6214:5681:b0:8f3:cf36:15ca with SMTP id 6a1803df08f44-90cc7986151mr19868916d6.9.1787693036199; Tue, 25 Aug 2026 14:23:56 -0700 (PDT) X-Received: by 2002:a05:6214:5681:b0:8f3:cf36:15ca with SMTP id 6a1803df08f44-90cc7986151mr19868246d6.9.1787693035564; Tue, 25 Aug 2026 14:23:55 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com, Daniel Henrique Barboza , Palmer Dabbelt Subject: [PATCH 05/13] hw/riscv/fdt_common, virt.c: add create_fdt_imsic() Date: Tue, 25 Aug 2026 18:23:17 -0300 Message-ID: <20260825212326.1907-6-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> References: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: M4ICch-s2CVpXKwgapJq9B_xEuricnIM X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX/6NULu2QfKlq 756zwkNafswI029UfkMFXNlleuyxZoAjadL4eLyjEfZQcYau7zDAKT+YnDLQF7AIPRKKLtDJyHs mm43FWzKOuBWwMeEFTq1VnhiVbsQoRGpvfCVzHprF4ZLTxZlZhluNnZaXoY6MSsnouKAWEPbPv4 np4bJxlZAXEBjBRnM8LlMl7ftXHgi23vbSawVrOmoT/lh5Ic5P245v1VIYYokFQPXjNVexACR5C MiUzK506RgjLkWmAINWFk8KwSnODufY62Xjfbh0O92OzR6PW6VWwvm2fd5q3e+DJ80gVEPp4cXl KeoY+IlK9d8+2ZrLC2eHy8yRPZ10O6HRSM7dTFudhLUXpP4Auosj7lTxKMsR0D5EOkAiRzrx1rq aNbpsztiYvjR5NnDxbrZIESufyuIxs+HFOA9L3q58/rUTzWzYKroE6k15hUC1LSH0uhbttuzNro nP8o6aZmnDlE80pdPYA== X-Authority-Analysis: v=2.4 cv=acNRWxot c=1 sm=1 tr=0 ts=6a8e07ed cx=c_pps a=JbAStetqSzwMeJznSMzCyw==:117 a=MCIxunHWmQOg/5OnbzXZaw==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_glEPmIy2e8OvE2BGh3C:22 a=EUspDBNiAAAA:8 a=leFpFR9-_kbXek5-2D0A:9 a=uxP6HrT_eTzRwkO_Te1X:22 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfXwlCbB3YAej81 sO5Fn5hwv6BXDHlJhCigMs5PNUGdo5I42zkpalIx0Y3ZV9FrPqv++TkfXKwwstluGBwRCmLxdXd /L5oDzx+/rkkPiZ0gL0fbYO0M2m+bes= X-Proofpoint-ORIG-GUID: M4ICch-s2CVpXKwgapJq9B_xEuricnIM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_06,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 clxscore=1015 phishscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 spamscore=0 adultscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250182 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1787693147717158500 Content-Type: text/plain; charset="utf-8" The FDT related to interrupt controllers should definitely be put into helpers, even if only 'virt' benefits from it, due to the amount of code that is relieved from the board alone. We'll start with 'imsic'. For this endeavor we're going to use a helper struct that will carry all the extra FDT arguments in a human format. The alternative would be to add 8 more function arguments, on top of 4 phandle arguments that we're passing around in all these controllers, and that's not only a poor reading experience but it's quite error prone too. We do not want to crowd the fdt-helper with non-FDT logic, hence we're handling the !kvm_enabled() cond in virt.c using the imsic_m_base argument. This is a pattern that we'll fall back on in the next patches too. No FDT changes made. Signed-off-by: Daniel Henrique Barboza --- hw/riscv/fdt-common.c | 94 ++++++++++++++++++++++++++++++ hw/riscv/virt.c | 104 ++++------------------------------ include/hw/riscv/fdt-common.h | 22 +++++++ 3 files changed, 128 insertions(+), 92 deletions(-) diff --git a/hw/riscv/fdt-common.c b/hw/riscv/fdt-common.c index 67a0a3d8f2..6fa2543a2a 100644 --- a/hw/riscv/fdt-common.c +++ b/hw/riscv/fdt-common.c @@ -15,8 +15,10 @@ #include "target/riscv/cpu_bits.h" #include "hw/riscv/riscv-iommu-bits.h" #include "hw/riscv/iommu.h" +#include "hw/intc/riscv_imsic.h" #include "hw/pci/pci.h" #include "hw/pci/pcie_host.h" +#include "hw/riscv/aia.h" =20 void *create_board_device_tree(const char *model, const char *compatible, int *fdt_size) @@ -495,3 +497,95 @@ void create_fdt_pcie(void *fdt, int aia_type, bool has= _iommu_sys, =20 create_pcie_irq_map(fdt, name, irq_pcie_phandle, aia_type, pcie_irq); } + +static void create_fdt_one_imsic(void *fdt, IMSICFdtProps *props, + hwaddr base_addr, + uint32_t *intc_phandles, uint32_t msi_pha= ndle, + bool m_mode, uint32_t imsic_guest_bits) +{ + RISCVHartArrayState *soc =3D (RISCVHartArrayState *)props->soc; + g_autofree char *imsic_name =3D NULL; + uint32_t imsic_max_hart_per_socket, imsic_addr, imsic_size; + g_autofree uint32_t *imsic_cells =3D NULL; + g_autofree uint32_t *imsic_regs =3D NULL; + static const char * const imsic_compat[2] =3D { + "qemu,imsics", "riscv,imsics" + }; + int cpu, socket; + + imsic_cells =3D g_new0(uint32_t, props->smp_cpus * 2); + imsic_regs =3D g_new0(uint32_t, props->socket_count * 4); + + for (cpu =3D 0; cpu < props->smp_cpus; cpu++) { + imsic_cells[cpu * 2 + 0] =3D cpu_to_be32(intc_phandles[cpu]); + imsic_cells[cpu * 2 + 1] =3D cpu_to_be32(m_mode ? IRQ_M_EXT : IRQ_= S_EXT); + } + + imsic_max_hart_per_socket =3D 0; + for (socket =3D 0; socket < props->socket_count; socket++) { + imsic_addr =3D base_addr + socket * props->imsic_group_max_size; + imsic_size =3D IMSIC_HART_SIZE(imsic_guest_bits) * + soc[socket].num_harts; + imsic_regs[socket * 4 + 0] =3D 0; + imsic_regs[socket * 4 + 1] =3D cpu_to_be32(imsic_addr); + imsic_regs[socket * 4 + 2] =3D 0; + imsic_regs[socket * 4 + 3] =3D cpu_to_be32(imsic_size); + if (imsic_max_hart_per_socket < soc[socket].num_harts) { + imsic_max_hart_per_socket =3D soc[socket].num_harts; + } + } + + imsic_name =3D g_strdup_printf("/soc/interrupt-controller@%"HWADDR_PRI= x, + base_addr); + qemu_fdt_add_subnode(fdt, imsic_name); + + qemu_fdt_setprop_string_array(fdt, imsic_name, "compatible", + (char **)&imsic_compat, + ARRAY_SIZE(imsic_compat)); + + qemu_fdt_setprop_cell(fdt, imsic_name, "#interrupt-cells", + FDT_IMSIC_INT_CELLS); + qemu_fdt_setprop(fdt, imsic_name, "interrupt-controller", NULL, 0); + qemu_fdt_setprop(fdt, imsic_name, "msi-controller", NULL, 0); + qemu_fdt_setprop(fdt, imsic_name, "interrupts-extended", + imsic_cells, props->smp_cpus * sizeof(uint32_t) * 2); + qemu_fdt_setprop(fdt, imsic_name, "reg", imsic_regs, + props->socket_count * sizeof(uint32_t) * 4); + qemu_fdt_setprop_cell(fdt, imsic_name, "riscv,num-ids", + props->irqchip_num_msis); + + if (imsic_guest_bits) { + qemu_fdt_setprop_cell(fdt, imsic_name, "riscv,guest-index-bits", + imsic_guest_bits); + } + + if (props->socket_count > 1) { + qemu_fdt_setprop_cell(fdt, imsic_name, "riscv,hart-index-bits", + imsic_num_bits(imsic_max_hart_per_socket)); + qemu_fdt_setprop_cell(fdt, imsic_name, "riscv,group-index-bits", + imsic_num_bits(props->socket_count)); + qemu_fdt_setprop_cell(fdt, imsic_name, "riscv,group-index-shift", + IMSIC_MMIO_GROUP_MIN_SHIFT); + } + qemu_fdt_setprop_cell(fdt, imsic_name, "phandle", msi_phandle); +} + +void create_fdt_imsic(void *fdt, IMSICFdtProps *props, + uint32_t *phandle, uint32_t *intc_phandles, + uint32_t *msi_m_phandle, uint32_t *msi_s_phandle) +{ + *msi_m_phandle =3D (*phandle)++; + *msi_s_phandle =3D (*phandle)++; + + if (props->imsic_m_base) { + /* M-level IMSIC node */ + create_fdt_one_imsic(fdt, props, props->imsic_m_base, + intc_phandles, *msi_m_phandle, true, 0); + } + + /* S-level IMSIC node */ + create_fdt_one_imsic(fdt, props, props->imsic_s_base, + intc_phandles, *msi_s_phandle, false, + imsic_num_bits(props->aia_guests + 1)); + +} diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index fc381a07f3..0ab91728d9 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -320,97 +320,6 @@ static void create_fdt_socket_plic(RISCVVirtState *s, } } =20 -static void create_fdt_one_imsic(RISCVVirtState *s, hwaddr base_addr, - uint32_t *intc_phandles, uint32_t msi_pha= ndle, - bool m_mode, uint32_t imsic_guest_bits) -{ - int cpu, socket; - g_autofree char *imsic_name =3D NULL; - MachineState *ms =3D MACHINE(s); - int socket_count =3D riscv_socket_count(ms); - uint32_t imsic_max_hart_per_socket, imsic_addr, imsic_size; - g_autofree uint32_t *imsic_cells =3D NULL; - g_autofree uint32_t *imsic_regs =3D NULL; - static const char * const imsic_compat[2] =3D { - "qemu,imsics", "riscv,imsics" - }; - - imsic_cells =3D g_new0(uint32_t, ms->smp.cpus * 2); - imsic_regs =3D g_new0(uint32_t, socket_count * 4); - - for (cpu =3D 0; cpu < ms->smp.cpus; cpu++) { - imsic_cells[cpu * 2 + 0] =3D cpu_to_be32(intc_phandles[cpu]); - imsic_cells[cpu * 2 + 1] =3D cpu_to_be32(m_mode ? IRQ_M_EXT : IRQ_= S_EXT); - } - - imsic_max_hart_per_socket =3D 0; - for (socket =3D 0; socket < socket_count; socket++) { - imsic_addr =3D base_addr + socket * VIRT_IMSIC_GROUP_MAX_SIZE; - imsic_size =3D IMSIC_HART_SIZE(imsic_guest_bits) * - s->soc[socket].num_harts; - imsic_regs[socket * 4 + 0] =3D 0; - imsic_regs[socket * 4 + 1] =3D cpu_to_be32(imsic_addr); - imsic_regs[socket * 4 + 2] =3D 0; - imsic_regs[socket * 4 + 3] =3D cpu_to_be32(imsic_size); - if (imsic_max_hart_per_socket < s->soc[socket].num_harts) { - imsic_max_hart_per_socket =3D s->soc[socket].num_harts; - } - } - - imsic_name =3D g_strdup_printf("/soc/interrupt-controller@%lx", - (unsigned long)base_addr); - qemu_fdt_add_subnode(ms->fdt, imsic_name); - qemu_fdt_setprop_string_array(ms->fdt, imsic_name, "compatible", - (char **)&imsic_compat, - ARRAY_SIZE(imsic_compat)); - - qemu_fdt_setprop_cell(ms->fdt, imsic_name, "#interrupt-cells", - FDT_IMSIC_INT_CELLS); - qemu_fdt_setprop(ms->fdt, imsic_name, "interrupt-controller", NULL, 0); - qemu_fdt_setprop(ms->fdt, imsic_name, "msi-controller", NULL, 0); - qemu_fdt_setprop(ms->fdt, imsic_name, "interrupts-extended", - imsic_cells, ms->smp.cpus * sizeof(uint32_t) * 2); - qemu_fdt_setprop(ms->fdt, imsic_name, "reg", imsic_regs, - socket_count * sizeof(uint32_t) * 4); - qemu_fdt_setprop_cell(ms->fdt, imsic_name, "riscv,num-ids", - VIRT_IRQCHIP_NUM_MSIS); - - if (imsic_guest_bits) { - qemu_fdt_setprop_cell(ms->fdt, imsic_name, "riscv,guest-index-bits= ", - imsic_guest_bits); - } - - if (socket_count > 1) { - qemu_fdt_setprop_cell(ms->fdt, imsic_name, "riscv,hart-index-bits", - imsic_num_bits(imsic_max_hart_per_socket)); - qemu_fdt_setprop_cell(ms->fdt, imsic_name, "riscv,group-index-bits= ", - imsic_num_bits(socket_count)); - qemu_fdt_setprop_cell(ms->fdt, imsic_name, "riscv,group-index-shif= t", - IMSIC_MMIO_GROUP_MIN_SHIFT); - } - qemu_fdt_setprop_cell(ms->fdt, imsic_name, "phandle", msi_phandle); -} - -static void create_fdt_imsic(RISCVVirtState *s, - uint32_t *phandle, uint32_t *intc_phandles, - uint32_t *msi_m_phandle, uint32_t *msi_s_phan= dle) -{ - *msi_m_phandle =3D (*phandle)++; - *msi_s_phandle =3D (*phandle)++; - - if (!kvm_enabled()) { - /* M-level IMSIC node */ - create_fdt_one_imsic(s, s->memmap[VIRT_IMSIC_M].base, intc_phandle= s, - *msi_m_phandle, true, 0); - } - - /* S-level IMSIC node */ - create_fdt_one_imsic(s, s->memmap[VIRT_IMSIC_S].base, intc_phandles, - *msi_s_phandle, false, - imsic_num_bits(s->aia_guests + 1)); - -} - /* Caller must free string after use */ static char *fdt_get_aplic_nodename(unsigned long aplic_addr) { @@ -583,8 +492,19 @@ static void create_fdt_sockets(RISCVVirtState *s, } =20 if (s->aia_type =3D=3D VIRT_AIA_TYPE_APLIC_IMSIC) { - create_fdt_imsic(s, phandle, intc_phandles, + IMSICFdtProps props =3D { + .soc =3D &s->soc, .socket_count =3D riscv_socket_count(ms), + .smp_cpus =3D ms->smp.cpus, + .imsic_m_base =3D !kvm_enabled() ? s->memmap[VIRT_IMSIC_M].bas= e : 0, + .imsic_s_base =3D s->memmap[VIRT_IMSIC_S].base, + .imsic_group_max_size =3D VIRT_IMSIC_GROUP_MAX_SIZE, + .irqchip_num_msis =3D VIRT_IRQCHIP_NUM_MSIS, + .aia_guests =3D s->aia_guests + }; + + create_fdt_imsic(ms->fdt, &props, phandle, intc_phandles, &msi_m_phandle, &msi_s_phandle); + *msi_pcie_phandle =3D msi_s_phandle; } =20 diff --git a/include/hw/riscv/fdt-common.h b/include/hw/riscv/fdt-common.h index bee8b85597..ab77bbda12 100644 --- a/include/hw/riscv/fdt-common.h +++ b/include/hw/riscv/fdt-common.h @@ -10,6 +10,8 @@ #define RISCV_VIRT_FDT_H =20 #include "target/riscv/cpu.h" +#include "hw/core/boards.h" +#include "hw/riscv/riscv_hart.h" =20 #define FDT_PCI_ADDR_CELLS 3 #define FDT_PCI_INT_CELLS 1 @@ -32,6 +34,23 @@ typedef enum RISCVAIAType { AIA_TYPE_APLIC_IMSIC, } RISCVAIAType; =20 +typedef struct IMSICFdtProps { + /* + * Machines will statically allocate RISCVHartArrayState[] pointer, + * e.g. "RISCVHartArrayState soc[VIRT_SOCKETS_MAX]". We'll have + * to use a void* pointer to handle a soc with variable sizes. + */ + void *soc; + hwaddr imsic_m_base; + hwaddr imsic_s_base; + int socket_count; + int smp_cpus; + int imsic_group_max_size; + int irqchip_num_msis; + int aia_guests; +} IMSICFdtProps; + + void *create_board_device_tree(const char *model, const char *compatible, int *fdt_size); void create_fdt_socket_memory(void *fdt, hwaddr addr, uint64_t size, @@ -72,4 +91,7 @@ void create_fdt_pcie(void *fdt, int aia_type, bool has_io= mmu_sys, const MemMapEntry *pcie_mmio, const MemMapEntry *high= _pcie, uint32_t irq_pcie_phandle, uint32_t msi_pcie_phandle, uint32_t iommu_sys_phandle, uint32_t pcie_irq); +void create_fdt_imsic(void *fdt, IMSICFdtProps *fdt_props, + uint32_t *phandle, uint32_t *intc_phandles, + uint32_t *msi_m_phandle, uint32_t *msi_s_phandle); #endif --=20 2.43.0 From nobody Sat Sep 26 23:03:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1787693139; cv=none; d=zohomail.com; s=zohoarc; b=NVvsaC2m9fqoQ3ps1atvSWstbCizDPVDvBA/B1gp/o4o9jnaJtELxbUqoKhu9yc/BB/71TneKo4PH49NeVus6McyGi5AskucZ+0lHZYTexnSGbKFXR71GUdHgRhw/0xRNwemY/51QhyM8/AjucK9SbEeCKnpAXKLUImnRnzdP1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787693139; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Vm5RAtIsvygP46EuGukx0Ed9N2TIajYAWhtbSzKTpiw=; b=Lu2SaiVyT15XH4ReM8vW3bTdh1zCxiQrHrSaB7pMkpKgQ8awZ8yoXpdHgJJkEI6affeOQzAth7FDFVhCi84QP8JmibpYTIWygMvJ+oQLN1z2ueqQM/mylQv4cseTXaJzCSIKnLf0lYon0a7Mmve4KtZtB4ThYbukNlXvCBFoSdM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787693139036228.89173117671226; Tue, 25 Aug 2026 14:25:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyycm-0003cT-BN; Tue, 25 Aug 2026 17:24:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyycl-0003Zm-GU for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:03 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyycj-0002I7-5x for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:03 -0400 Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67PL9rX43099227 for ; Tue, 25 Aug 2026 21:24:00 GMT Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g9bkua1wb-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 25 Aug 2026 21:23:59 +0000 (GMT) Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-90cc2b97f8fso5344366d6.0 for ; Tue, 25 Aug 2026 14:23:59 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([189.38.141.232]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90cc65299f0sm8646386d6.41.2026.08.25.14.23.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 14:23:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=Vm5RAtIsvyg P46EuGukx0Ed9N2TIajYAWhtbSzKTpiw=; b=F7i8SmnyiuT6ReoLQ3TPPdVmIty OesZZA6sOp1fy9RbHa8rpwJ55Qfoiye42XJlVXyN9Z7JabIvEOlpY7yo5AM3Izm6 zTnmtx83RCaP7yfl34p1XQN1goO06zNrSuSzWBmyexii+xAogLnPZEm+cHfUApvA pZtmGRINwYltzh1f+mzNGToQcIocM/46m+1kmgQU2qgNSMZz96SdLFSukmNjF3Od MiD9/oO+lHS1WuY3FfvRn9S5Gj0FwofvFSuSLYFBl66NMXqfia4U1a9pOX5nP/pk xJgCfly6wRx+wbEZ9dMmfk6t6k7WhElGfzjcMW4VXKQeQgyGAJQaMw8PMWA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787693039; x=1788297839; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Vm5RAtIsvygP46EuGukx0Ed9N2TIajYAWhtbSzKTpiw=; b=cWK8w/7iv8Vc3AswAQwANl+C40aUqU3cB6LEa1/JlBHk/TlP1G/J8WPkc+F1s15O5A w582Rebe9j8w0HylzpwK1QhSirMTYWLOWOGanneZlocQLutygLxCae1uXkvFqhM4X6+M 0T6G1dP/ZDEfd6a0Bf16gPmgQ/YP46eJZEq1U3/Qv24kfLxKCyRflqmcAEa6VDaBextH p4Sz4aDOXUyg5gISrNYOP0jjaExOrE2E20yGGU0Jl+kmLdBm4yY9iR7rBP3xSyA3Vh7H rYGDB80+pYbZ16QDYyDoD3wrO8hyoGKKExlKROCG29O9OvlVyLaomwf8iFt9grwt/O9s AJ8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787693039; x=1788297839; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Vm5RAtIsvygP46EuGukx0Ed9N2TIajYAWhtbSzKTpiw=; b=DpBGAMUMhc7zgxgtYdkKIY3PhSRbxWQl5oAv/newt092pbz/o09YrrrYn9Z5cD04a6 A4/cydsjBd3OcMHGHqphBIOnUXa3AmBfvTT/c30zWbtXYF6yvd5FcDM2VGjpciPIZthk A/zLgNBDle72ieV1aU8ZCk3iNqbypFT67ytRlyFnCveave2iV6uFR6W1dZeKIcXjxTi8 H4/nwRkRcOpmxYo6qh0L247Cd4kom2VGtWiYiBuqzBu422T630HGoCW0kky3AQtWP+xc b3raIZhXqu4DEFU9rm51SR/IQGKD24tQ9nugL0uDMBnRD9Iati6Ik7koKIo8OZxe4XkL g+FA== X-Gm-Message-State: AFuF++kE5CixcB1DPklyIoUqPIAqsLmVfEg+O6Cq3l3uQT4vsD3bcKsp gDA4lbjXIAl9vN9uL4r3q0AQC/vvgxMdGlkIycWc5Bfc9cXW57MLtGXimKiIsemgKMzGP76/n/S xFjxkpmdMy0f6Yk5d6A8sVp1qn2c1n2vl2kPXSnDtk2dUJ0xxeJcXwkkYTFWOgO0VGw== X-Gm-Gg: AR+sD10NgjiI123QjF4Qf+9L/jWujq3MwvPpYXxeoPw8T75ruaJwqZz/8jt3RhvjOv5 mb47RHgKmFJsbh1UC3U/ZpbBcfdQzAdGtmZI7wzUCEvRi05Y86c8xaECbtGO5OOlzimDHZHB2YS na9338Qqm61WI8fPJ4rQhyZvrISHSn7lL1PQm34oazyp3pJ0kEBwqT57RSiLMRQJmjIalvfcQoN 71/mRupPsk6yCmQTwyx922ilud0WeSTdDpRH57/cFy2vQPntxQ83y5E/CLkGOmzGf4tQvmWRIfz P6cAt98dQZSHcu6UKSTCdcspIPYQPHa9lWNda0hTh8YmTTbtdF+lM3L2ftQwCBsa9NzbUTRr93w T52/vbCSpVutO9IJvUcQf9Z/AOiJNaogEdVl6Cw== X-Received: by 2002:a05:6214:dcb:b0:90a:927f:8a9b with SMTP id 6a1803df08f44-90cc790a7e0mr19113796d6.7.1787693038667; Tue, 25 Aug 2026 14:23:58 -0700 (PDT) X-Received: by 2002:a05:6214:dcb:b0:90a:927f:8a9b with SMTP id 6a1803df08f44-90cc790a7e0mr19113176d6.7.1787693038128; Tue, 25 Aug 2026 14:23:58 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com, Daniel Henrique Barboza , Palmer Dabbelt Subject: [PATCH 06/13] hw/riscv/fdt_common, virt.c: add create_fdt_socket_aplic() Date: Tue, 25 Aug 2026 18:23:18 -0300 Message-ID: <20260825212326.1907-7-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> References: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: YBY9gX5bCVIUoIoiN84N4S_NOouhVDi9 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX8gn7sdR3hJe/ 2Dr0X91Nbv6TP1Qqv/JP7KUU1pQ8fqi524hRxt7YP0YFZIy3E1XELr24kLJ1ZV3p/sLguvlIyPh ocdp30EoXbAa+9pBjb+U+9RWeipR4mQ= X-Authority-Analysis: v=2.4 cv=TZGmcxQh c=1 sm=1 tr=0 ts=6a8e07ef cx=c_pps a=UgVkIMxJMSkC9lv97toC5g==:117 a=MCIxunHWmQOg/5OnbzXZaw==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yOCtJkima9RkubShWh1s:22 a=EUspDBNiAAAA:8 a=IageEFNgCMQ87KM8QjoA:9 a=1HOtulTD9v-eNWfpl4qZ:22 X-Proofpoint-GUID: YBY9gX5bCVIUoIoiN84N4S_NOouhVDi9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX6Jemg5XcH8z7 CoxTc9ZH37lF/pcyvlkYSVXv1m9VxWrGn1PPxeJiqaFYdJ02Uy6gXrkjGGBghgT0yMEljt2tL3Y JxXUYD36Uw2XqSeKs+7Y5wklZmce4OFv8ATyg+BbdyRp0TuvYC8fMjfQtqgDY0i7TgM+BZEqkIJ uyVCN6MpppUcYu+5mv5cVFzovkelumBI1Yo2CLWSsaMFI3y8hnuxUZTFIXnE/xI8SV2fNm3iuCg TOa5d5OlIsIv5Ox5cZGZjdlBxVg3XZ5VPoAvcBbvL53pY6ePNkmz4zhMhuY3IWXDHD6jsSVZ9Id i/78g5mK/yUQg6pYYiXvMO/eWtDdKo4kGl1ZXRnPNxhiMDLapQ7dAVAEYTyvpku5ynqFnHL/dlO QX/sO6bwWY6Ok1bg1FtX1ER4tcna0qlnObfcRGkuF7A+elyUtvjmgNX2wgFFKTSPlwTGOB17evm fKkh2LeF6xS/TsvQy6A== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_06,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 spamscore=0 bulkscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250182 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1787693139759158500 Content-Type: text/plain; charset="utf-8" Similar to what we did with 'imsic' in the previous patch, including creating a helper struct to encapsulate the extra arguments required to create the FDT. TODO: I believe the tt-atlantis board can use this same helper too. We just need to verify how to map the phandles used by it and what the helper is using (which was inherited by the 'virt' board). No FDT changes intended. Signed-off-by: Daniel Henrique Barboza --- hw/riscv/fdt-common.c | 106 +++++++++++++++++++++++++++ hw/riscv/virt.c | 132 +++++----------------------------- include/hw/riscv/fdt-common.h | 18 +++++ 3 files changed, 143 insertions(+), 113 deletions(-) diff --git a/hw/riscv/fdt-common.c b/hw/riscv/fdt-common.c index 6fa2543a2a..77168f5c4f 100644 --- a/hw/riscv/fdt-common.c +++ b/hw/riscv/fdt-common.c @@ -11,6 +11,7 @@ #include "qemu/error-report.h" #include "system/device_tree.h" #include "hw/core/boards.h" +#include "hw/core/sysbus-fdt.h" #include "hw/riscv/fdt-common.h" #include "target/riscv/cpu_bits.h" #include "hw/riscv/riscv-iommu-bits.h" @@ -589,3 +590,108 @@ void create_fdt_imsic(void *fdt, IMSICFdtProps *props, imsic_num_bits(props->aia_guests + 1)); =20 } + +/* Caller must free string after use */ +static char *fdt_get_aplic_nodename(hwaddr aplic_addr) +{ + return g_strdup_printf("/soc/interrupt-controller@%"HWADDR_PRIx, + aplic_addr); +} + +static void create_fdt_one_aplic(void *fdt, APLICFdtProps *props, + hwaddr aplic_addr, uint32_t aplic_size, + uint32_t msi_phandle, + uint32_t *intc_phandles, + uint32_t aplic_phandle, + uint32_t aplic_child_phandle, + bool m_mode) +{ + g_autofree char *aplic_name =3D fdt_get_aplic_nodename(aplic_addr); + g_autofree uint32_t *aplic_cells =3D g_new0(uint32_t, props->num_harts= * 2); + static const char * const aplic_compat[2] =3D { + "qemu,aplic", "riscv,aplic" + }; + int cpu; + + for (cpu =3D 0; cpu < props->num_harts; cpu++) { + aplic_cells[cpu * 2 + 0] =3D cpu_to_be32(intc_phandles[cpu]); + aplic_cells[cpu * 2 + 1] =3D cpu_to_be32(m_mode ? IRQ_M_EXT : IRQ_= S_EXT); + } + + qemu_fdt_add_subnode(fdt, aplic_name); + qemu_fdt_setprop_string_array(fdt, aplic_name, "compatible", + (char **)&aplic_compat, + ARRAY_SIZE(aplic_compat)); + qemu_fdt_setprop_cell(fdt, aplic_name, "#address-cells", + FDT_APLIC_ADDR_CELLS); + qemu_fdt_setprop_cell(fdt, aplic_name, + "#interrupt-cells", FDT_APLIC_INT_CELLS); + qemu_fdt_setprop(fdt, aplic_name, "interrupt-controller", NULL, 0); + + if (props->aia_type =3D=3D AIA_TYPE_APLIC) { + qemu_fdt_setprop(fdt, aplic_name, "interrupts-extended", + aplic_cells, props->num_harts * sizeof(uint32_t) = * 2); + } else { + qemu_fdt_setprop_cell(fdt, aplic_name, "msi-parent", msi_phandle); + } + + qemu_fdt_setprop_sized_cells(fdt, aplic_name, "reg", + 2, aplic_addr, 2, aplic_size); + qemu_fdt_setprop_cell(fdt, aplic_name, "riscv,num-sources", + props->irqchip_num_sources); + + if (aplic_child_phandle) { + qemu_fdt_setprop_cell(fdt, aplic_name, "riscv,children", + aplic_child_phandle); + qemu_fdt_setprop_cells(fdt, aplic_name, "riscv,delegation", + aplic_child_phandle, 0x1, + props->irqchip_num_sources); + } + + if (props->numa_enabled) { + qemu_fdt_setprop_cell(fdt, aplic_name, "numa-node-id", props->sock= et); + } + + qemu_fdt_setprop_cell(fdt, aplic_name, "phandle", aplic_phandle); +} + +void create_fdt_socket_aplic(void *fdt, APLICFdtProps *props, + uint32_t msi_m_phandle, + uint32_t msi_s_phandle, + uint32_t *phandle, + uint32_t *intc_phandles, + uint32_t *aplic_phandles) +{ + uint32_t aplic_m_phandle, aplic_s_phandle; + hwaddr aplic_addr; + + aplic_m_phandle =3D (*phandle)++; + aplic_s_phandle =3D (*phandle)++; + + if (props->aplic_m) { + /* M-level APLIC node */ + aplic_addr =3D props->aplic_m->base + + (props->aplic_m->size * props->socket); + create_fdt_one_aplic(fdt, props, aplic_addr, props->aplic_m->size, + msi_m_phandle, intc_phandles, + aplic_m_phandle, aplic_s_phandle, + true); + } + + /* S-level APLIC node */ + aplic_addr =3D props->aplic_s->base + (props->aplic_s->size * props->s= ocket); + create_fdt_one_aplic(fdt, props, aplic_addr, props->aplic_s->size, + msi_s_phandle, intc_phandles, + aplic_s_phandle, 0, + false); + + if (!props->socket && props->platform_bus_irq) { + g_autofree char *aplic_name =3D fdt_get_aplic_nodename(aplic_addr); + platform_bus_add_all_fdt_nodes(fdt, aplic_name, + props->platform_bus->base, + props->platform_bus->size, + props->platform_bus_irq); + } + + aplic_phandles[props->socket] =3D aplic_s_phandle; +} diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 0ab91728d9..dd8f5d9d75 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -320,113 +320,6 @@ static void create_fdt_socket_plic(RISCVVirtState *s, } } =20 -/* Caller must free string after use */ -static char *fdt_get_aplic_nodename(unsigned long aplic_addr) -{ - return g_strdup_printf("/soc/interrupt-controller@%lx", aplic_addr); -} - -static void create_fdt_one_aplic(RISCVVirtState *s, int socket, - unsigned long aplic_addr, uint32_t aplic_= size, - uint32_t msi_phandle, - uint32_t *intc_phandles, - uint32_t aplic_phandle, - uint32_t aplic_child_phandle, - bool m_mode, int num_harts) -{ - int cpu; - g_autofree char *aplic_name =3D fdt_get_aplic_nodename(aplic_addr); - g_autofree uint32_t *aplic_cells =3D g_new0(uint32_t, num_harts * 2); - MachineState *ms =3D MACHINE(s); - static const char * const aplic_compat[2] =3D { - "qemu,aplic", "riscv,aplic" - }; - - for (cpu =3D 0; cpu < num_harts; cpu++) { - aplic_cells[cpu * 2 + 0] =3D cpu_to_be32(intc_phandles[cpu]); - aplic_cells[cpu * 2 + 1] =3D cpu_to_be32(m_mode ? IRQ_M_EXT : IRQ_= S_EXT); - } - - qemu_fdt_add_subnode(ms->fdt, aplic_name); - qemu_fdt_setprop_string_array(ms->fdt, aplic_name, "compatible", - (char **)&aplic_compat, - ARRAY_SIZE(aplic_compat)); - qemu_fdt_setprop_cell(ms->fdt, aplic_name, "#address-cells", - FDT_APLIC_ADDR_CELLS); - qemu_fdt_setprop_cell(ms->fdt, aplic_name, - "#interrupt-cells", FDT_APLIC_INT_CELLS); - qemu_fdt_setprop(ms->fdt, aplic_name, "interrupt-controller", NULL, 0); - - if (s->aia_type =3D=3D VIRT_AIA_TYPE_APLIC) { - qemu_fdt_setprop(ms->fdt, aplic_name, "interrupts-extended", - aplic_cells, num_harts * sizeof(uint32_t) * 2); - } else { - qemu_fdt_setprop_cell(ms->fdt, aplic_name, "msi-parent", msi_phand= le); - } - - qemu_fdt_setprop_sized_cells(ms->fdt, aplic_name, "reg", - 2, aplic_addr, 2, aplic_size); - qemu_fdt_setprop_cell(ms->fdt, aplic_name, "riscv,num-sources", - VIRT_IRQCHIP_NUM_SOURCES); - - if (aplic_child_phandle) { - qemu_fdt_setprop_cell(ms->fdt, aplic_name, "riscv,children", - aplic_child_phandle); - qemu_fdt_setprop_cells(ms->fdt, aplic_name, "riscv,delegation", - aplic_child_phandle, 0x1, - VIRT_IRQCHIP_NUM_SOURCES); - } - - riscv_socket_fdt_write_id(ms, aplic_name, socket); - qemu_fdt_setprop_cell(ms->fdt, aplic_name, "phandle", aplic_phandle); -} - -static void create_fdt_socket_aplic(RISCVVirtState *s, - int socket, - uint32_t msi_m_phandle, - uint32_t msi_s_phandle, - uint32_t *phandle, - uint32_t *intc_phandles, - uint32_t *aplic_phandles, - int num_harts) -{ - unsigned long aplic_addr; - MachineState *ms =3D MACHINE(s); - uint32_t aplic_m_phandle, aplic_s_phandle; - - aplic_m_phandle =3D (*phandle)++; - aplic_s_phandle =3D (*phandle)++; - - if (!kvm_enabled()) { - /* M-level APLIC node */ - aplic_addr =3D s->memmap[VIRT_APLIC_M].base + - (s->memmap[VIRT_APLIC_M].size * socket); - create_fdt_one_aplic(s, socket, aplic_addr, - s->memmap[VIRT_APLIC_M].size, - msi_m_phandle, intc_phandles, - aplic_m_phandle, aplic_s_phandle, - true, num_harts); - } - - /* S-level APLIC node */ - aplic_addr =3D s->memmap[VIRT_APLIC_S].base + - (s->memmap[VIRT_APLIC_S].size * socket); - create_fdt_one_aplic(s, socket, aplic_addr, s->memmap[VIRT_APLIC_S].si= ze, - msi_s_phandle, intc_phandles, - aplic_s_phandle, 0, - false, num_harts); - - if (!socket) { - g_autofree char *aplic_name =3D fdt_get_aplic_nodename(aplic_addr); - platform_bus_add_all_fdt_nodes(ms->fdt, aplic_name, - s->memmap[VIRT_PLATFORM_BUS].base, - s->memmap[VIRT_PLATFORM_BUS].size, - VIRT_PLATFORM_BUS_IRQ); - } - - aplic_phandles[socket] =3D aplic_s_phandle; -} - static void create_fdt_pmu(RISCVVirtState *s) { g_autofree char *pmu_name =3D g_strdup_printf("/pmu"); @@ -453,6 +346,7 @@ static void create_fdt_sockets(RISCVVirtState *s, int socket_count =3D riscv_socket_count(ms); bool numa_enabled =3D riscv_numa_enabled(ms); bool is_32_bit =3D riscv_is_32bit(&s->soc[0]); + APLICFdtProps aplic_props; =20 fdt_create_cpu_socket_subnode(ms->fdt, kvm_enabled() ? kvm_riscv_get_timebase_frequency(&s->soc->harts[0]= ) : @@ -508,15 +402,26 @@ static void create_fdt_sockets(RISCVVirtState *s, *msi_pcie_phandle =3D msi_s_phandle; } =20 + if (s->aia_type !=3D VIRT_AIA_TYPE_NONE) { + aplic_props.aplic_m =3D !kvm_enabled() ? &s->memmap[VIRT_APLIC_M] = : NULL; + aplic_props.aplic_s =3D &s->memmap[VIRT_APLIC_S]; + aplic_props.platform_bus =3D &s->memmap[VIRT_PLATFORM_BUS]; + aplic_props.platform_bus_irq =3D VIRT_PLATFORM_BUS_IRQ; + aplic_props.socket =3D 0; + aplic_props.num_harts =3D ms->smp.cpus; + aplic_props.numa_enabled =3D numa_enabled; + aplic_props.irqchip_num_sources =3D VIRT_IRQCHIP_NUM_SOURCES; + aplic_props.aia_type =3D s->aia_type; + } + /* * With KVM AIA aplic-imsic, using an irqchip without split * mode, we'll use only one APLIC instance. */ if (!virt_use_emulated_aplic(s->aia_type)) { - create_fdt_socket_aplic(s, 0, + create_fdt_socket_aplic(ms->fdt, &aplic_props, msi_m_phandle, msi_s_phandle, phandle, - &intc_phandles[0], xplic_phandles, - ms->smp.cpus); + &intc_phandles[0], xplic_phandles); =20 *irq_mmio_phandle =3D xplic_phandles[0]; *irq_virtio_phandle =3D xplic_phandles[0]; @@ -531,11 +436,12 @@ static void create_fdt_sockets(RISCVVirtState *s, &intc_phandles[phandle_pos], xplic_phandles); } else { - create_fdt_socket_aplic(s, socket, + aplic_props.socket =3D socket; + aplic_props.num_harts =3D s->soc[socket].num_harts; + create_fdt_socket_aplic(ms->fdt, &aplic_props, msi_m_phandle, msi_s_phandle, phan= dle, &intc_phandles[phandle_pos], - xplic_phandles, - s->soc[socket].num_harts); + xplic_phandles); } } =20 diff --git a/include/hw/riscv/fdt-common.h b/include/hw/riscv/fdt-common.h index ab77bbda12..7a7e3ad7af 100644 --- a/include/hw/riscv/fdt-common.h +++ b/include/hw/riscv/fdt-common.h @@ -12,6 +12,7 @@ #include "target/riscv/cpu.h" #include "hw/core/boards.h" #include "hw/riscv/riscv_hart.h" +#include "exec/hwaddr.h" =20 #define FDT_PCI_ADDR_CELLS 3 #define FDT_PCI_INT_CELLS 1 @@ -50,6 +51,17 @@ typedef struct IMSICFdtProps { int aia_guests; } IMSICFdtProps; =20 +typedef struct APLICFdtProps { + const MemMapEntry *aplic_m; + const MemMapEntry *aplic_s; + const MemMapEntry *platform_bus; + int platform_bus_irq; + int socket; + int num_harts; + bool numa_enabled; + int irqchip_num_sources; + int aia_type; +} APLICFdtProps; =20 void *create_board_device_tree(const char *model, const char *compatible, int *fdt_size); @@ -94,4 +106,10 @@ void create_fdt_pcie(void *fdt, int aia_type, bool has_= iommu_sys, void create_fdt_imsic(void *fdt, IMSICFdtProps *fdt_props, uint32_t *phandle, uint32_t *intc_phandles, uint32_t *msi_m_phandle, uint32_t *msi_s_phandle); +void create_fdt_socket_aplic(void *fdt, APLICFdtProps *props, + uint32_t msi_m_phandle, + uint32_t msi_s_phandle, + uint32_t *phandle, + uint32_t *intc_phandles, + uint32_t *aplic_phandles); #endif --=20 2.43.0 From nobody Sat Sep 26 23:03:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1787693158; cv=none; d=zohomail.com; s=zohoarc; b=Dwmdz8rzThbipoaTKEm0Se7KTnhYwHv8b3kh4is8b/CWu2vLdTF/k7q88vDUGMNevUTOtOaSqexm39v0YcuaJeItHEVCxV5yBPCOMyRB8q5U0wObvalgKvVIMqMS9Y98PrV2Zm8Z2XPOzFod6rrnZIsijhZ3DJMrDOQ/yrTeWzc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787693158; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LoDaM/9hyCVyH/OGkL8dS2L29acFOpKSFw1j7Ys5DgA=; b=E4MgxgwUGm7TVx6FIgDf+hplRw9NetdzUJ7trJNje1oG7pOLA4nmY8LqYj91AWm5CBawLx2ZiLcfyxjX2Wgiz4qJwDAym1npMm9YTthmlV09mZ0XlNOm4cyUdqW6A2+PCLDnGgy3lY1YBWL6OviLMBgNgIN6X5TDLLp5dT62XZA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787693158932572.8831968811307; Tue, 25 Aug 2026 14:25:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyycp-0003ee-PT; Tue, 25 Aug 2026 17:24:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyycn-0003eG-DE for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:05 -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 1wyycl-0002IM-2j for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:05 -0400 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67PLAcDT2992628 for ; Tue, 25 Aug 2026 21:24:02 GMT Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g9cgpspbb-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 25 Aug 2026 21:24:02 +0000 (GMT) Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-5283df62d68so3625391cf.0 for ; Tue, 25 Aug 2026 14:24:02 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([189.38.141.232]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90cc65299f0sm8646386d6.41.2026.08.25.14.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 14:24:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=LoDaM/9hyCV yH/OGkL8dS2L29acFOpKSFw1j7Ys5DgA=; b=NBgRk7UxhcS9LTkhqtv3rGDRdlE ZzhQXBSJJhYu4Z22JszZNkaBJlPke9uDUyamL/8xYIOTgOaf+KmzITq5uIF8n43p +TlALCbAVnoe6+FQ1zzg5tg7fo14RidLHdUKxS9Zthk+2iE9jmoBMuad+SZhCpYA JaJIRkpRQi30/DSFLEUHUdfSyfSJ7vLERoG2CRhcMdAX9zPceDJH5Ib1pGV59LGc J9UuAyt0NUGab8PzHW/wCktK4zgEm4ZbgeVIV8dcf8TBIUzkhCRcPs70tpWgNgry 7LtQ6EK9Ch6nBqEG0nsGPVeVEJF/VxxvBYziSgA9FkTS/bqxGbA0DXmQqDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787693041; x=1788297841; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=LoDaM/9hyCVyH/OGkL8dS2L29acFOpKSFw1j7Ys5DgA=; b=aY3HOgrgnaqe+STJwLR0SDzehB+5IlNuhqYDTl16n6YvhZoYSkxfgPTzBi98asy3TQ Zx+ngKO8JKDZodgzPnixUq6P71AmvxdH4zI2mdRZ0LgjkLkSDXnN00sXz4kvFI4Ib3T5 5Ts8+XF1o8RuzU58AfjEnciiRpybXEC1hxdVcaXVXORUkg5Bon8ovBSUGQ59aSlKgmix LQt0roiQV5VzbQgdfR7IiOuX1NO0+xQodWVhWDHenCr9ou4+j6uKfswFl03arDZZBOeu i+YRYWkG1PjuEfv4aj9HtKydbxUK9o/4SIbMUArWHIbzrYl+ZKHvDWNYQFBJxeJXMugG LVHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787693041; x=1788297841; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=LoDaM/9hyCVyH/OGkL8dS2L29acFOpKSFw1j7Ys5DgA=; b=Wcv+v8HDEe7F6xkzg9PEOTzXzulMzhz/0FNV+NFdZfj0PS6xknwyEscTAUzP6C7uLU kCUdnQvV1JDRGC8R6Tvaw4fmx/zEoGkMVqfjEFXFAMFWyDHT6ltQ1cX79tAi4XOJ6r/h PFma9EvocKhZyzYPd3FJO4P5kNtPAsWaD1u1lbphWZ7rfPrNqKsWX/42ua8TmXE8k+NO THYXztlOEGLqncp3IwqOsC3YpQTbnTwVQxqY654SNqEhGG2vRWFWQYv7a0os2TsC0N6a vYPfwrrnqdIi3At66Nz7MKCE2arGMeaw/pUYdfzyW/xe/jl/26gWUWWO0Zd2dnEdFpp5 gXHg== X-Gm-Message-State: AFuF++krCxPDhvrVJOeM7Y1Yls5RLVSRoGNgIxIdUuS9rTuG1Di2uxFv EANGGVVCUkelO2qPUs4GPAm7nIdWwz52Ieh9fvNMhs2rhoMkoa8R2DmC8/waf7VFmg4eQguresz q2JOlUgYmd0GmHEWCQ9uc+19iuO4Xc1V/gEc5YGD0ml6y7aN519V01esaodD8L33Cfw== X-Gm-Gg: AR+sD10cc53PSY773eMeyQFnH/yPM6tZBfdU0TlsC2GBmGSM2AnDTgP2SEfZ5m7Dp8e 1Bq0ylo9Rm1PkI2UDJfN0NZ1Hcj8BXXdeaD4fIgHqCyCpzPoqH7bLbvimbw7lChQutzm9/gcPIh 2g06qn+0ehL7S6dU8lIUgf1xAx/E2FUY5O2/ow1/hDV/CM2WoB7CbUCFfxou7bpMxp5DycsE8t4 lCaTMhQ4z2gGnvH+YFEDacnJyv8ugedKq5sGgZfe6K5DXWJHjBsjRD9vWzLQOqh+RjkvCBc8m7M 2P0W1rhjjaW6ymmTYLpWVPoeluNteI2Rze0DLLQNvQKVuEMC2cRkqfLJrKRhUv28GNAkc/8saXJ KujNh5t0PXATI9UT5Ib796uTA1iQwGRoJrGTbtQ== X-Received: by 2002:a05:622a:451:b0:52e:1039:c465 with SMTP id d75a77b69052e-52e4223411emr21516181cf.7.1787693041329; Tue, 25 Aug 2026 14:24:01 -0700 (PDT) X-Received: by 2002:a05:622a:451:b0:52e:1039:c465 with SMTP id d75a77b69052e-52e4223411emr21515721cf.7.1787693040816; Tue, 25 Aug 2026 14:24:00 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com, Daniel Henrique Barboza , Palmer Dabbelt Subject: [PATCH 07/13] hw/riscv/fdt-common, virt.c: add create_fdt_socket_aclint() Date: Tue, 25 Aug 2026 18:23:19 -0300 Message-ID: <20260825212326.1907-8-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> References: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: DW0X60nbZpDXyaUTMw394Hv_4UXEDsJQ X-Proofpoint-ORIG-GUID: DW0X60nbZpDXyaUTMw394Hv_4UXEDsJQ X-Authority-Analysis: v=2.4 cv=I+NVgtgg c=1 sm=1 tr=0 ts=6a8e07f2 cx=c_pps a=EVbN6Ke/fEF3bsl7X48z0g==:117 a=MCIxunHWmQOg/5OnbzXZaw==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=EUspDBNiAAAA:8 a=7Bblaz4JstUzMt5rO2kA:9 a=a_PwQJl-kcHnX1M80qC6:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX/41v20+OIVZ3 nSy5sI1aDI8+z+J2hO5sy8Bt69gVlsdj8L2XMLbvopY5MJ6l4pGHEg6CsSK4p10iTBXeEz4VJkG uRErryADdLAObG+AtynoC3hArb9Wv9qocA+kN/wIYE0QqpJXGdZ57ajDT5A7mQpx1NWYDaJ+Svl 648fFdK3kZVGxp7VAKToSPzkXwx0W8Ft+1JWfHXUSYpsdEHY1Lh5lZlC/jmvUerU5kUdoyzfIM5 VEzfksJg5rT88V99NY7vh1vIUQho1qdH6sujm6xF19x9ekvMjr6f4v/F8hT27bqcfz3HQ593rvC XTsDLhch5Z8bjkMztbwc8sngsP7UutFktIvw1WucvNksNegWffPVyGklgkwioYdj1/3JAY3FvrQ xl/ZOpBE+WXSJtZLViSwfy1E8kXa6jD1t2HWzgp0fISiTIV2ii/VUGuzgXTr6/8j+K1mWCdE/2c fZuKwDKx20TGNocTcoA== X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX8YvOQ43ycPV9 boEvf0FebeCALdFKZH1o9G1QKDe9jKkWhQhGAmKYvnLLto/yhtYq6RTzy5lXDFZNlt4wR4SYkrX 1Gp82EOOEtweBho590TSw+5M2gow3Ps= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_06,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 bulkscore=0 suspectscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 adultscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250182 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1787693159841158500 Content-Type: text/plain; charset="utf-8" Yet another FDT that we want to move to a helper to avoid copy/pasting code to other boards that will use a mtimer. In particular the future 'riscv-server-ref' board. No FDT changes made. Signed-off-by: Daniel Henrique Barboza --- hw/riscv/fdt-common.c | 96 +++++++++++++++++++++++++++++++++ hw/riscv/virt.c | 99 ++++------------------------------- include/hw/riscv/fdt-common.h | 11 ++++ 3 files changed, 118 insertions(+), 88 deletions(-) diff --git a/hw/riscv/fdt-common.c b/hw/riscv/fdt-common.c index 77168f5c4f..f31cc9d3cc 100644 --- a/hw/riscv/fdt-common.c +++ b/hw/riscv/fdt-common.c @@ -16,6 +16,7 @@ #include "target/riscv/cpu_bits.h" #include "hw/riscv/riscv-iommu-bits.h" #include "hw/riscv/iommu.h" +#include "hw/intc/riscv_aclint.h" #include "hw/intc/riscv_imsic.h" #include "hw/pci/pci.h" #include "hw/pci/pcie_host.h" @@ -695,3 +696,98 @@ void create_fdt_socket_aplic(void *fdt, APLICFdtProps = *props, =20 aplic_phandles[props->socket] =3D aplic_s_phandle; } + +void create_fdt_socket_aclint(void *fdt, ACLINTFdtProps *props, + uint32_t *intc_phandles) +{ + uint32_t aclint_cells_size =3D props->num_harts * sizeof(uint32_t) * 2; + g_autofree uint32_t *aclint_mswi_cells =3D NULL; + g_autofree uint32_t *aclint_sswi_cells =3D NULL; + g_autofree uint32_t *aclint_mtimer_cells =3D NULL; + hwaddr addr, size; + char *name; + int cpu; + + aclint_mswi_cells =3D g_new0(uint32_t, props->num_harts * 2); + aclint_mtimer_cells =3D g_new0(uint32_t, props->num_harts * 2); + aclint_sswi_cells =3D g_new0(uint32_t, props->num_harts * 2); + + for (cpu =3D 0; cpu < props->num_harts; cpu++) { + aclint_mswi_cells[cpu * 2 + 0] =3D cpu_to_be32(intc_phandles[cpu]); + aclint_mswi_cells[cpu * 2 + 1] =3D cpu_to_be32(IRQ_M_SOFT); + aclint_mtimer_cells[cpu * 2 + 0] =3D cpu_to_be32(intc_phandles[cpu= ]); + aclint_mtimer_cells[cpu * 2 + 1] =3D cpu_to_be32(IRQ_M_TIMER); + aclint_sswi_cells[cpu * 2 + 0] =3D cpu_to_be32(intc_phandles[cpu]); + aclint_sswi_cells[cpu * 2 + 1] =3D cpu_to_be32(IRQ_S_SOFT); + } + + if (props->aia_type !=3D AIA_TYPE_APLIC_IMSIC) { + addr =3D props->clint->base + (props->clint->size * props->socket); + name =3D g_strdup_printf("/soc/mswi@%"HWADDR_PRIx, addr); + + qemu_fdt_add_subnode(fdt, name); + qemu_fdt_setprop_string(fdt, name, "compatible", "riscv,aclint-msw= i"); + qemu_fdt_setprop_sized_cells(fdt, name, "reg", + 2, addr, 2, RISCV_ACLINT_SWI_SIZE); + qemu_fdt_setprop(fdt, name, "interrupts-extended", + aclint_mswi_cells, aclint_cells_size); + qemu_fdt_setprop(fdt, name, "interrupt-controller", NULL, 0); + qemu_fdt_setprop_cell(fdt, name, "#interrupt-cells", 0); + + if (props->numa_enabled) { + qemu_fdt_setprop_cell(fdt, name, "numa-node-id", props->socket= ); + } + + g_free(name); + } + + if (props->aia_type =3D=3D AIA_TYPE_APLIC_IMSIC) { + addr =3D props->clint->base + + (RISCV_ACLINT_DEFAULT_MTIMER_SIZE * props->socket); + size =3D RISCV_ACLINT_DEFAULT_MTIMER_SIZE; + } else { + addr =3D props->clint->base + RISCV_ACLINT_SWI_SIZE + + (props->clint->size * props->socket); + size =3D props->clint->size - RISCV_ACLINT_SWI_SIZE; + } + + name =3D g_strdup_printf("/soc/mtimer@%"HWADDR_PRIx, addr); + qemu_fdt_add_subnode(fdt, name); + qemu_fdt_setprop_string(fdt, name, "compatible", + "riscv,aclint-mtimer"); + qemu_fdt_setprop_sized_cells(fdt, name, "reg", + 2, addr, + 2, size - RISCV_ACLINT_DEFAULT_MTIME, + 2, addr + RISCV_ACLINT_DEFAULT_MTIMECMP, + 2, RISCV_ACLINT_DEFAULT_MTIME); + qemu_fdt_setprop(fdt, name, "interrupts-extended", + aclint_mtimer_cells, aclint_cells_size); + + if (props->numa_enabled) { + qemu_fdt_setprop_cell(fdt, name, "numa-node-id", props->socket); + } + + g_free(name); + + if (props->aia_type !=3D AIA_TYPE_APLIC_IMSIC) { + addr =3D props->aclint_sswi->base + + (props->aclint_sswi->size * props->socket); + + name =3D g_strdup_printf("/soc/sswi@%"HWADDR_PRIx, addr); + qemu_fdt_add_subnode(fdt, name); + qemu_fdt_setprop_string(fdt, name, "compatible", + "riscv,aclint-sswi"); + qemu_fdt_setprop_sized_cells(fdt, name, "reg", + 2, addr, 2, props->aclint_sswi->size); + qemu_fdt_setprop(fdt, name, "interrupts-extended", + aclint_sswi_cells, aclint_cells_size); + qemu_fdt_setprop(fdt, name, "interrupt-controller", NULL, 0); + qemu_fdt_setprop_cell(fdt, name, "#interrupt-cells", 0); + + if (props->numa_enabled) { + qemu_fdt_setprop_cell(fdt, name, "numa-node-id", props->socket= ); + } + + g_free(name); + } +} diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index dd8f5d9d75..ef2670f20e 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -180,93 +180,6 @@ static void virt_flash_map(RISCVVirtState *s, sysmem); } =20 -static void create_fdt_socket_aclint(RISCVVirtState *s, - int socket, - uint32_t *intc_phandles) -{ - int cpu; - char *name; - unsigned long addr, size; - uint32_t aclint_cells_size; - g_autofree uint32_t *aclint_mswi_cells =3D NULL; - g_autofree uint32_t *aclint_sswi_cells =3D NULL; - g_autofree uint32_t *aclint_mtimer_cells =3D NULL; - MachineState *ms =3D MACHINE(s); - - aclint_mswi_cells =3D g_new0(uint32_t, s->soc[socket].num_harts * 2); - aclint_mtimer_cells =3D g_new0(uint32_t, s->soc[socket].num_harts * 2); - aclint_sswi_cells =3D g_new0(uint32_t, s->soc[socket].num_harts * 2); - - for (cpu =3D 0; cpu < s->soc[socket].num_harts; cpu++) { - aclint_mswi_cells[cpu * 2 + 0] =3D cpu_to_be32(intc_phandles[cpu]); - aclint_mswi_cells[cpu * 2 + 1] =3D cpu_to_be32(IRQ_M_SOFT); - aclint_mtimer_cells[cpu * 2 + 0] =3D cpu_to_be32(intc_phandles[cpu= ]); - aclint_mtimer_cells[cpu * 2 + 1] =3D cpu_to_be32(IRQ_M_TIMER); - aclint_sswi_cells[cpu * 2 + 0] =3D cpu_to_be32(intc_phandles[cpu]); - aclint_sswi_cells[cpu * 2 + 1] =3D cpu_to_be32(IRQ_S_SOFT); - } - aclint_cells_size =3D s->soc[socket].num_harts * sizeof(uint32_t) * 2; - - if (s->aia_type !=3D VIRT_AIA_TYPE_APLIC_IMSIC) { - addr =3D s->memmap[VIRT_CLINT].base + - (s->memmap[VIRT_CLINT].size * socket); - name =3D g_strdup_printf("/soc/mswi@%lx", addr); - - qemu_fdt_add_subnode(ms->fdt, name); - qemu_fdt_setprop_string(ms->fdt, name, "compatible", - "riscv,aclint-mswi"); - qemu_fdt_setprop_sized_cells(ms->fdt, name, "reg", - 2, addr, 2, RISCV_ACLINT_SWI_SIZE); - qemu_fdt_setprop(ms->fdt, name, "interrupts-extended", - aclint_mswi_cells, aclint_cells_size); - qemu_fdt_setprop(ms->fdt, name, "interrupt-controller", NULL, 0); - qemu_fdt_setprop_cell(ms->fdt, name, "#interrupt-cells", 0); - riscv_socket_fdt_write_id(ms, name, socket); - g_free(name); - } - - if (s->aia_type =3D=3D VIRT_AIA_TYPE_APLIC_IMSIC) { - addr =3D s->memmap[VIRT_CLINT].base + - (RISCV_ACLINT_DEFAULT_MTIMER_SIZE * socket); - size =3D RISCV_ACLINT_DEFAULT_MTIMER_SIZE; - } else { - addr =3D s->memmap[VIRT_CLINT].base + RISCV_ACLINT_SWI_SIZE + - (s->memmap[VIRT_CLINT].size * socket); - size =3D s->memmap[VIRT_CLINT].size - RISCV_ACLINT_SWI_SIZE; - } - name =3D g_strdup_printf("/soc/mtimer@%lx", addr); - qemu_fdt_add_subnode(ms->fdt, name); - qemu_fdt_setprop_string(ms->fdt, name, "compatible", - "riscv,aclint-mtimer"); - qemu_fdt_setprop_sized_cells(ms->fdt, name, "reg", - 2, addr + RISCV_ACLINT_DEFAULT_MTIME, - 2, size - RISCV_ACLINT_DEFAULT_MTIME, - 2, addr + RISCV_ACLINT_DEFAULT_MTIMECMP, - 2, RISCV_ACLINT_DEFAULT_MTIME); - qemu_fdt_setprop(ms->fdt, name, "interrupts-extended", - aclint_mtimer_cells, aclint_cells_size); - riscv_socket_fdt_write_id(ms, name, socket); - g_free(name); - - if (s->aia_type !=3D VIRT_AIA_TYPE_APLIC_IMSIC) { - addr =3D s->memmap[VIRT_ACLINT_SSWI].base + - (s->memmap[VIRT_ACLINT_SSWI].size * socket); - - name =3D g_strdup_printf("/soc/sswi@%lx", addr); - qemu_fdt_add_subnode(ms->fdt, name); - qemu_fdt_setprop_string(ms->fdt, name, "compatible", - "riscv,aclint-sswi"); - qemu_fdt_setprop_sized_cells(ms->fdt, name, "reg", - 2, addr, 2, s->memmap[VIRT_ACLINT_SSWI].size); - qemu_fdt_setprop(ms->fdt, name, "interrupts-extended", - aclint_sswi_cells, aclint_cells_size); - qemu_fdt_setprop(ms->fdt, name, "interrupt-controller", NULL, 0); - qemu_fdt_setprop_cell(ms->fdt, name, "#interrupt-cells", 0); - riscv_socket_fdt_write_id(ms, name, socket); - g_free(name); - } -} - static void create_fdt_socket_plic(RISCVVirtState *s, int socket, uint32_t *phandle, uint32_t *intc_phand= les, @@ -347,6 +260,7 @@ static void create_fdt_sockets(RISCVVirtState *s, bool numa_enabled =3D riscv_numa_enabled(ms); bool is_32_bit =3D riscv_is_32bit(&s->soc[0]); APLICFdtProps aplic_props; + ACLINTFdtProps aclint_props; =20 fdt_create_cpu_socket_subnode(ms->fdt, kvm_enabled() ? kvm_riscv_get_timebase_frequency(&s->soc->harts[0]= ) : @@ -354,6 +268,13 @@ static void create_fdt_sockets(RISCVVirtState *s, =20 intc_phandles =3D g_new0(uint32_t, ms->smp.cpus); =20 + if (virt_aclint_allowed() && s->have_aclint) { + aclint_props.clint =3D &s->memmap[VIRT_CLINT]; + aclint_props.aclint_sswi =3D &s->memmap[VIRT_ACLINT_SSWI]; + aclint_props.aia_type =3D s->aia_type; + aclint_props.numa_enabled =3D numa_enabled; + } + phandle_pos =3D ms->smp.cpus; for (socket =3D (socket_count - 1); socket >=3D 0; socket--) { hwaddr memaddr =3D s->memmap[VIRT_DRAM].base + @@ -372,7 +293,9 @@ static void create_fdt_sockets(RISCVVirtState *s, socket, riscv_numa_enabled(ms)); =20 if (virt_aclint_allowed() && s->have_aclint) { - create_fdt_socket_aclint(s, socket, + aclint_props.socket =3D socket; + aclint_props.num_harts =3D s->soc[socket].num_harts; + create_fdt_socket_aclint(ms->fdt, &aclint_props, &intc_phandles[phandle_pos]); } else if (tcg_enabled()) { hwaddr clintaddr =3D s->memmap[VIRT_CLINT].base + diff --git a/include/hw/riscv/fdt-common.h b/include/hw/riscv/fdt-common.h index 7a7e3ad7af..fbcf9aaffb 100644 --- a/include/hw/riscv/fdt-common.h +++ b/include/hw/riscv/fdt-common.h @@ -63,6 +63,15 @@ typedef struct APLICFdtProps { int aia_type; } APLICFdtProps; =20 +typedef struct ACLINTFdtProps { + const MemMapEntry *clint; + const MemMapEntry *aclint_sswi; + int socket; + int num_harts; + int aia_type; + bool numa_enabled; +} ACLINTFdtProps; + void *create_board_device_tree(const char *model, const char *compatible, int *fdt_size); void create_fdt_socket_memory(void *fdt, hwaddr addr, uint64_t size, @@ -112,4 +121,6 @@ void create_fdt_socket_aplic(void *fdt, APLICFdtProps *= props, uint32_t *phandle, uint32_t *intc_phandles, uint32_t *aplic_phandles); +void create_fdt_socket_aclint(void *fdt, ACLINTFdtProps *props, + uint32_t *intc_phandles); #endif --=20 2.43.0 From nobody Sat Sep 26 23:03:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1787693141; cv=none; d=zohomail.com; s=zohoarc; b=iJxYG6yVCqed+uqCMV5j/RlDfvggo/1L8/vIH4Khz6Bix653dCpD9tH6DyocbfnEfyvh18BuIpOPV6CKnk3lzqfZzoH7rkqeVTAuAvp9gojRVjnxVK98vLkDoBXB/VPDImHsQsNCZ1nlVuqjHCas7aXdMAYvo97vE+cf8WzC/Kk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787693141; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=b4Miz9TXKzyRvuNMMeQe6KMM7OsPQgD3XGcw9fM+m+M=; b=ng/+vN3lSkYP7niB+45BYgiTM5j2GHk38PvFeJ6jABMEJCi/ayM02lUVu22EhxqPPfIbkLK4wOoq+4C2gJ/Ia5Z8mWR0Thmfv5W0w9kxYcEJ4jCK5D9THIfmpb2Rh+k99IuO1YheUpf8PXpbbuI1ZXcqch9Xy5HRHIaU+VqUzvg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787693141365741.5591171168348; Tue, 25 Aug 2026 14:25:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyycr-0003em-6L; Tue, 25 Aug 2026 17:24:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyycp-0003ed-MW for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:07 -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 1wyycn-0002J6-Tv for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:07 -0400 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67PLA3tG3117135 for ; Tue, 25 Aug 2026 21:24:05 GMT Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g9g4mrk8q-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 25 Aug 2026 21:24:04 +0000 (GMT) Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-51c0e702df8so3934891cf.2 for ; Tue, 25 Aug 2026 14:24:04 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([189.38.141.232]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90cc65299f0sm8646386d6.41.2026.08.25.14.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 14:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=b4Miz9TXKzy RvuNMMeQe6KMM7OsPQgD3XGcw9fM+m+M=; b=KArojKMmT1yEPS8dBjoOi/q92Ln ExrYjXiROMHGdNlqicP/Dc0wEuw6TyhV16EsxhuN6GXN2bcy59rC6hS9qU3bT12b XMPH9LbkVhyj6sTsfgw3MW07xYPGbk+2XKQ54G6nNFLsil9eTGvKHiRI8laKckO+ rx+O7MB07hsEVOoDxtFzhbQ1U1Nx7++86UykIhEfdpcn8QdQ4X/rU63VH20D/3GN /Rp3uXVvVrxteNuhgW+9NOr9v2LvYPqXzCkxKF20FdX5f6FbXJ/o95cX5t3kru4r U5JHdGZsjG3/srELMfH35pj8MD9UzQDH1YxIOaSPENho9mZ73wrygG2G7VQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787693044; x=1788297844; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=b4Miz9TXKzyRvuNMMeQe6KMM7OsPQgD3XGcw9fM+m+M=; b=irzakzhYndyPHCHfNpocj3qypHwVbxqwr9H2vyaJQW1WTDGx2TfJVXfu5Pcb06FpOD hcTZy2fACW5LK0dfvhhtvquyLMG4eaHY/SIuvhhyob+/9QBAo8pxppOiRIDbcvW240LT gnlsjxlzL8mS/rwt3IPVeijKMivbZtKQtnuLJyPnYSbTTvh0R9ZQaunATXZ9luji3zFj gwWq2IaX1RmX55WakzbYPvunvLEnAza3VXH+I5umCAi62gXJHl9tiVECrfSQJXro+b6A B16dVEvjI3v7U+fr+jeCFABA4HQQ/RTtMKSR8CvgMU1+h0L3g22gazG4taR6WDztPmAB AFaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787693044; x=1788297844; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=b4Miz9TXKzyRvuNMMeQe6KMM7OsPQgD3XGcw9fM+m+M=; b=X9HbWmQVhFC4cikQBndznN11h3Fi7/6JcEbbpje66zDKnWdbHItErI3djjACQSM3i0 E0PCPF66cOPJikc4ipB/yE0yZBIAdK8ICoY9s3p/Kncy5xFLc+eodS2HEn4pDqHrEJAv 9AcwJx21nbuio7v4R3QHySlNiIlSx6mkeac7Aim6H6ARgFmv/cUD5KrwstfKLqOLc5Lg nw5Ak3eaP1V85U6UogXs5TwapM8jsU7rcIgCkC18ZPEBxQZ0G9LNxHfSbPpuN0O8bBFu BoVzR7agdgbhkySqf9Piwyn+leiSacIycWW+n1d0i38shD7ZbjiB2mJ1ok7m6vBv1T4t 9IAg== X-Gm-Message-State: AFuF++mpTsk23M4laXxrprkKaCkDXCnCewIqIbOcPizgQiu1WvwxHnJh hVfEBYzooOJTNp5T1VkgKaYMNAJEWGepJDUoXSfm9FQdKioFahDlCBheQFOEzngiuxYqSk8GsvV o26z4tAVzRTFvkGM77vB9EBgaLzMkiJrIBZq2r3Uey3b38I71P+rJzoQNDGB/5s3X0Q== X-Gm-Gg: AR+sD115H3EEybE0GPV1hr66wFon+wqN+wvTjHwNv0cNjObX3AY163cJVxwAH3g5Smn 2he3++bz+bNmh+yB5KDEFnEkQYav3HsDF2lZi5jXEVarJBHpbYpCkqdbwI3VnefKJ6BH9yS+CuU YYgfkwkRf3Md8uniRbdusIc8FpW3njeRV4oZsH7qGOZTgcetOTcoiTV22/9QNqMsuentwb7EwPZ VanTGCpsLjFEeqbK9SlghIXnXlbFyCVSAluCbrUgcBi54O4fSodTO8sO/GdJkvrVqPvWWeFwwj8 fVxbCb+SScc5DHIdjw8lS6WeNbBm+1PeTv/Rjn+8Quqd99i6vGhYhjBI30RyF3uOF5B/CqUPAsm 9AEzoYHeqd3cZqmfr/GbaL7a7eWslqTXqoHIMVA== X-Received: by 2002:a05:622a:4186:b0:51c:ae7:fa1d with SMTP id d75a77b69052e-52e42234b68mr23143261cf.5.1787693044323; Tue, 25 Aug 2026 14:24:04 -0700 (PDT) X-Received: by 2002:a05:622a:4186:b0:51c:ae7:fa1d with SMTP id d75a77b69052e-52e42234b68mr23142801cf.5.1787693043905; Tue, 25 Aug 2026 14:24:03 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com, Daniel Henrique Barboza , Palmer Dabbelt , Joel Stanley , Nicholas Piggin , Anirudh Srinivasan , Michael Ellerman , Portia Stephens Subject: [PATCH 08/13] hw/riscv/fdt-common, virt.c, tt_atlantis.c: add create_fdt_uart() Date: Tue, 25 Aug 2026 18:23:20 -0300 Message-ID: <20260825212326.1907-9-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> References: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX032HNHpELLXc pKVUkSWGtnFdORmhq2/U0WT/cikhLSBq5BKiYxtnxfx0y/q0iW+ksJ0qRcpmrv/6vh8KcWNQou6 Atz9g/eJwP+6+lGaz+Ee9gCCDgzRM5I= X-Proofpoint-ORIG-GUID: SWo403NeUpyHfmUdcRWcL2dFaFZp3TV6 X-Authority-Analysis: v=2.4 cv=eYgNubEH c=1 sm=1 tr=0 ts=6a8e07f5 cx=c_pps a=JbAStetqSzwMeJznSMzCyw==:117 a=MCIxunHWmQOg/5OnbzXZaw==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=EUspDBNiAAAA:8 a=ZXiSWbBV69HJ4aRO-VQA:9 a=uxP6HrT_eTzRwkO_Te1X:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX2JQstgExvP4G cRjb6sumvxkOCg9p6Q30njrbWkGrvJkVkphlMHwapQY9BbutIixWX76kR5MgtwgRf3ZMx4i9lwn /LuPdwv2yQix2xYhYJ4BDjXZoBDRK9QH+9ZYO2QlbaVKyVaMYIOcUwYkkvTWVhtgz7JrtAdCwpC mPg7PG9Gzd2DkH+oGjU4e3SzfFgdh7f9PhCUOQ9dPDWrLAuMAC34i31rC6SS/SV70UJH1nIu6D6 Xu0fyKxkUVeCe+30cVXKvgSzOQqaK+vF5ES6psoOdQfIGeXPE7EyjWf9bcK3h+yGVbVUw1ZEoUB f2rBR5XVf23sYbSU1Js38t/oSpj5062yhxwmbyHu3M4xb/ABI8+nZU4CjD/gDAAvbrfjcBvPeVI C45xekaYtyTcclcu+otrn0ZeYKsC5IvdoVL7TGTq5ANIyDRTygqXfBZKPXYi8i4G/VtaE5K5e7r NHE736+BxHH04CB1pWg== X-Proofpoint-GUID: SWo403NeUpyHfmUdcRWcL2dFaFZp3TV6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_06,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 impostorscore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 phishscore=0 spamscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250182 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1787693143691158500 Content-Type: text/plain; charset="utf-8" Add a common uart FDT helper to be used by 'virt' and 'tt-atlantis'. To accomodate both boards the helper is doing the following: - an 'additional_reg_props' flag is used to control whether we want 'reg-shift' and 'reg-io-width' elements added. OpenSBI won't boot with the tt-atlantis board without them, but 'virt' can't deal with them being added unconditionally either. - an 'is_serial0' flag is added to control whether we need to set additional properties related to the first serial. This is required because the 'virt' board adds two uarts in the FDT. No FDT changes intended. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Anirudh Srinivasan --- hw/riscv/fdt-common.c | 39 +++++++++++++++++++++++++++++++ hw/riscv/tt_atlantis.c | 21 +---------------- hw/riscv/virt.c | 44 +++++++---------------------------- include/hw/riscv/fdt-common.h | 4 ++++ 4 files changed, 52 insertions(+), 56 deletions(-) diff --git a/hw/riscv/fdt-common.c b/hw/riscv/fdt-common.c index f31cc9d3cc..b3f3af3762 100644 --- a/hw/riscv/fdt-common.c +++ b/hw/riscv/fdt-common.c @@ -791,3 +791,42 @@ void create_fdt_socket_aclint(void *fdt, ACLINTFdtProp= s *props, g_free(name); } } + +void create_fdt_uart(void *fdt, const MemMapEntry *uart_mem, + int uart_irq, int aia_type, + bool additional_reg_props, bool is_serial0, + uint32_t irq_mmio_phandle) +{ + g_autofree char *name =3D NULL; + + name =3D g_strdup_printf("/soc/serial@%"HWADDR_PRIx, uart_mem->base); + qemu_fdt_add_subnode(fdt, name); + qemu_fdt_setprop_string(fdt, name, "compatible", "ns16550a"); + qemu_fdt_setprop_sized_cells(fdt, name, "reg", + 2, uart_mem->base, + 2, uart_mem->size); + + /* + * The tt-atlantis board requires these extra props in the + * DT, but adding them unconditionally will break OpenSBI + * for 'virt'. + */ + if (additional_reg_props) { + qemu_fdt_setprop_cell(fdt, name, "reg-shift", 2); + qemu_fdt_setprop_cell(fdt, name, "reg-io-width", 4); + } + + qemu_fdt_setprop_cell(fdt, name, "clock-frequency", 3686400); + qemu_fdt_setprop_cell(fdt, name, "interrupt-parent", irq_mmio_phandle); + + if (aia_type =3D=3D AIA_TYPE_NONE) { + qemu_fdt_setprop_cell(fdt, name, "interrupts", uart_irq); + } else { + qemu_fdt_setprop_cells(fdt, name, "interrupts", uart_irq, 0x4); + } + + if (is_serial0) { + qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", name); + qemu_fdt_setprop_string(fdt, "/aliases", "serial0", name); + } +} diff --git a/hw/riscv/tt_atlantis.c b/hw/riscv/tt_atlantis.c index d808bcc11c..eb22b67b71 100644 --- a/hw/riscv/tt_atlantis.c +++ b/hw/riscv/tt_atlantis.c @@ -259,25 +259,6 @@ static void create_fdt_cpu(TTAtlantisState *s, const M= emMapEntry *memmap, IRQ_S_EXT, s->soc.num_harts); } =20 -static void create_fdt_uart(void *fdt, const MemMapEntry *mem, int irq, - int irqchip_phandle) -{ - g_autofree char *name =3D g_strdup_printf("/soc/serial@%"HWADDR_PRIX, - mem->base); - - qemu_fdt_add_subnode(fdt, name); - qemu_fdt_setprop_string(fdt, name, "compatible", "ns16550a"); - qemu_fdt_setprop_sized_cells(fdt, name, "reg", 2, mem->base, 2, mem->s= ize); - qemu_fdt_setprop_cell(fdt, name, "reg-shift", 2); - qemu_fdt_setprop_cell(fdt, name, "reg-io-width", 4); - qemu_fdt_setprop_cell(fdt, name, "clock-frequency", 3686400); - qemu_fdt_setprop_cell(fdt, name, "interrupt-parent", irqchip_phandle); - qemu_fdt_setprop_cells(fdt, name, "interrupts", irq, 0x4); - - qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", name); - qemu_fdt_setprop_string(fdt, "/aliases", "serial0", name); -} - static void create_fdt_rng(void *fdt) { uint8_t rng_seed[32]; @@ -345,7 +326,7 @@ static void finalize_fdt(TTAtlantisState *s) */ =20 create_fdt_uart(fdt, &s->memmap[TT_ATL_UART1], TT_ATL_UART1_IRQ, - aplic_s_phandle); + AIA_TYPE_APLIC_IMSIC, true, true, aplic_s_phandle); =20 create_fdt_clk(fdt, "periph-clk", 100000000, periph_clk_phandle); =20 diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index ef2670f20e..e4bf9c26ef 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -415,41 +415,6 @@ static void create_fdt_virtio(RISCVVirtState *s, uint3= 2_t irq_virtio_phandle) } } =20 -static void create_fdt_uart(RISCVVirtState *s, - uint32_t irq_mmio_phandle, int memId, int irqN= o) -{ - g_autofree char *name =3D NULL; - MachineState *ms =3D MACHINE(s); - - name =3D g_strdup_printf("/soc/serial@%"HWADDR_PRIx, - s->memmap[memId].base); - qemu_fdt_add_subnode(ms->fdt, name); - qemu_fdt_setprop_string(ms->fdt, name, "compatible", "ns16550a"); - qemu_fdt_setprop_sized_cells(ms->fdt, name, "reg", - 2, s->memmap[memId].base, - 2, s->memmap[memId].size); - qemu_fdt_setprop_cell(ms->fdt, name, "clock-frequency", 3686400); - qemu_fdt_setprop_cell(ms->fdt, name, "interrupt-parent", irq_mmio_phan= dle); - if (s->aia_type =3D=3D VIRT_AIA_TYPE_NONE) { - qemu_fdt_setprop_cell(ms->fdt, name, "interrupts", irqNo); - } else { - qemu_fdt_setprop_cells(ms->fdt, name, "interrupts", irqNo, 0x4); - } - - if (VIRT_UART0 =3D=3D memId) { - qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", name); - qemu_fdt_setprop_string(ms->fdt, "/aliases", "serial0", name); - } -} - -static void create_fdt_uarts(RISCVVirtState *s, uint32_t irq_mmio_phandle) -{ - if (s->uart1_present) { - create_fdt_uart(s, irq_mmio_phandle, VIRT_UART1, UART1_IRQ); - } - create_fdt_uart(s, irq_mmio_phandle, VIRT_UART0, UART0_IRQ); -} - static void create_fdt_rtc(RISCVVirtState *s, uint32_t irq_mmio_phandle) { @@ -571,7 +536,14 @@ static void finalize_fdt(RISCVVirtState *s) s->memmap[VIRT_TEST].base, s->memmap[VIRT_TEST].size, FINISHER_RESET, FINISHER_PASS, true); =20 - create_fdt_uarts(s, irq_mmio_phandle); + create_fdt_uart(MACHINE(s)->fdt, &s->memmap[VIRT_UART0], UART0_IRQ, + s->aia_type, false, true, irq_mmio_phandle); + + if (s->uart1_present) { + create_fdt_uart(MACHINE(s)->fdt, &s->memmap[VIRT_UART1], + UART1_IRQ, s->aia_type, false, false, + irq_mmio_phandle); + } =20 create_fdt_rtc(s, irq_mmio_phandle); } diff --git a/include/hw/riscv/fdt-common.h b/include/hw/riscv/fdt-common.h index fbcf9aaffb..cef1073449 100644 --- a/include/hw/riscv/fdt-common.h +++ b/include/hw/riscv/fdt-common.h @@ -123,4 +123,8 @@ void create_fdt_socket_aplic(void *fdt, APLICFdtProps *= props, uint32_t *aplic_phandles); void create_fdt_socket_aclint(void *fdt, ACLINTFdtProps *props, uint32_t *intc_phandles); +void create_fdt_uart(void *fdt, const MemMapEntry *uart_mem, + int uart_irq, int aia_type, + bool additional_reg_props, bool is_serial0, + uint32_t irq_mmio_phandle); #endif --=20 2.43.0 From nobody Sat Sep 26 23:03:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1787693166; cv=none; d=zohomail.com; s=zohoarc; b=l8YK6GLKV3x4MHy5lXPiDORSF+QdvvvRILpbSJ9znPunvPjxFLJ5Umur4nAFEkfudO4sxKvl1LE5+xs+5YTQ6tRtuPE9fAnJEH81iRUyPgSkIyGX/EzOls88HxSKwlywP2LHdihPcOhkIQJL1QiF4NBX6YjuELja9gQPWukQ0XE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787693166; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mtAqNjFTalhhyet5/Af7MHgi6AQrHr8o4cFzerJDZDw=; b=R6KcUXJC3/pelcNYdeobvp8McZr9snl0KvZWLTtanxTsNUqBJ/0olNl3b92mERlc2ysSUeRYvKnnbvYoLKeiy22U0MxQAhufNYZnUGWHucIi/AL3VxLlGnZ5diM6yyDdHM0M1WoqbTSbc2mQqBbk9CVMvKx7/Z8/FHSxSh+uPMI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787693166013731.4173626831039; Tue, 25 Aug 2026 14:26:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyycu-0003gM-A6; Tue, 25 Aug 2026 17:24:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyycr-0003fA-TY for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:09 -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 1wyycq-0002KQ-81 for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:09 -0400 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67PLA3iT3117139 for ; Tue, 25 Aug 2026 21:24:07 GMT Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g9g4mrk8t-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 25 Aug 2026 21:24:07 +0000 (GMT) Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-92e52306621so19168085a.1 for ; Tue, 25 Aug 2026 14:24:07 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([189.38.141.232]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90cc65299f0sm8646386d6.41.2026.08.25.14.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 14:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=mtAqNjFTalh hyet5/Af7MHgi6AQrHr8o4cFzerJDZDw=; b=P83RMIawkx1Ak0OmfVug3Aa49/8 s9aNPoZOwaWJeaqL12WN6TMt/Jls7h1QiGWoarVZPQZ8DnYyscQd6RyO5iJ59ysO GIcawJcWlucVlKzxnz2qhynQ6GV8pKLsHNW+PoAPbbZIQGa/VHorLhiiN0zjmLK4 +/1SrtVjoxifNuVTzxO1rmonP4Yma8zIOkPREuNPBy9ToNi76qKqHwPxAlyIyKm+ 58wiBmnK7LS5UB2sb6h9mu3SKVElCpIsP/S1eDDz30NuPxywun1v9fRiLGZ6v2T9 WkhqkYrpY3vr66W/6LdrEqM2VcWN5usjcLTSs/I55CND5YfA2v9291jyuUw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787693047; x=1788297847; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=mtAqNjFTalhhyet5/Af7MHgi6AQrHr8o4cFzerJDZDw=; b=kLDT2icHy5PPYi9+CQEs99lwSD8VgwmGqIZ+bLHq1SunnjYFuuiv9loiLJC5KXcFRh BvzDWx+MYtE8VVOZcnqLzy85IT768Q5q+g9q4p69R0yrEjGTtWcF76c8QgdQpGd8hRex elPsdOK7PEIkXo6LWrYUOjMJDT2YeNFHwxTylMFs5rVxiueQVBzwcWqNFb0RDyCJWX5R mQd8zV4dryBwAdpkoe/2qpCo4niOIup6GR33yJ3EsEJLp4GEGXtFMJeHw/r7iSAbjE5q q9TbJ7lqTsrLSD4QflZNzmX+tPV58QitAZ+n0+kvbdjchHubU5eJvVE576sjOuqcMtiy clpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787693047; x=1788297847; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=mtAqNjFTalhhyet5/Af7MHgi6AQrHr8o4cFzerJDZDw=; b=o8vQkHPL+8W6WYYrHDcC7HZ18C6jttjcXTu6/InRF/GAxTsjVfSp/aXHBdwEQsSYVb q9gve8wpCWh8QyO9JYA3svrFv7lOHhjGgAlsacpf1BK6u1jPlh2MbhjPEF/3YbPSjuD4 X2HtvLIyCAXkOZc+3sqQ/H7e9a6vfqhO/t8JGtRQ5oJkPnrlyguDQ1Yvs92DMvaNsWyr QJbJyFB71QAfXiIcjw1vxJTAUGqNTu1b7aPZ7iWMPbXw/NANtEnvKliYjrKowzzivlUv qVylHc/zo14lJK11S7olkTGcM2++KR3C/AR/IZHwTBSEviDveeH/AtcgIHy/H1UUgoZN XCfQ== X-Gm-Message-State: AFuF++k8gbR7GmHpsRnQe7WYKu/aQN62ztLXv54mfENRfbfEGd1nWBrW e+rfo+vVOgnrBAW9iiOYGo32HDDzFGUF2ssRFgRtWhKWM2irYLQafkIzNT3V0TQJ/FFKmnquTiK VgzrWiGzgagUK03WhY1tI4zfUbwVmm3TOcucRsWmM79Q0wa6nOHJRgGKKHicN7ZHAOg== X-Gm-Gg: AR+sD11CF8Xe0ikmYuhZoTY7IVuZ2jEWGa3fCS1N9PstXRjz2PRQ6pLTbRqCepkL3eD uuEMn0qHIHul7Ek63O1fBVDO3XSkb58eL73nd79JH/w6oqObyr+B+2k3fuFA4vQljChYTlPfaQ1 DN1kljPcqjcWUuEbA0SBTw8jxandh5E9tJzmPj2/Ada+RusxMlrec5F61Mrvb2qpWw8fLSF2vbw Mv6T4yLEGk03MU/d4cv0sgM9sypr0lhcxG4fyk2iVXEjc9U03wNFFJyFgyPlc1y/Bao1tDhDncX ZIOJ0c1emwEbSLNSLSszk1V84EaYlPZXxlKKT3wgz5WwRzJOJFtsD/FI0T6Tb9GMudRb3z76Hbb N/ZD6B4/mIs8ILHCdv5M9OTLyFsLnu4sWNDAI0Q== X-Received: by 2002:a05:6214:1c88:b0:907:5150:a2dd with SMTP id 6a1803df08f44-90cc7970129mr17104046d6.14.1787693046619; Tue, 25 Aug 2026 14:24:06 -0700 (PDT) X-Received: by 2002:a05:6214:1c88:b0:907:5150:a2dd with SMTP id 6a1803df08f44-90cc7970129mr17103406d6.14.1787693046146; Tue, 25 Aug 2026 14:24:06 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com, Daniel Henrique Barboza , Palmer Dabbelt Subject: [PATCH 09/13] hw/riscv/fdt-common, virt.c: add create_fdt_rtc() Date: Tue, 25 Aug 2026 18:23:21 -0300 Message-ID: <20260825212326.1907-10-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> References: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX0JXf5P+YGZYB rbj5ix3JpZyg1ehgc0XfPpS+AV7tg2cEHdc5MkpbfFW4qVCPE2N1ICw67sKXsJ/XTMX9RU+B2pR 8QZW/naXwvcSx18O9Spsx0gL1poHMFI= X-Proofpoint-ORIG-GUID: PIBF-U_M63OcoUNXPSvvfCAj3uWXKPfC X-Authority-Analysis: v=2.4 cv=eYgNubEH c=1 sm=1 tr=0 ts=6a8e07f7 cx=c_pps a=qKBjSQ1v91RyAK45QCPf5w==:117 a=MCIxunHWmQOg/5OnbzXZaw==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=EUspDBNiAAAA:8 a=RnOvKumpmH0hROQiWQcA:9 a=NFOGd7dJGGMPyQGDc5-O:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX8cxhnGRcb0H6 ttyUE385kxFwZghQS3dRO1JmcR1cj04QeWd2DI457rH39WgCBOCYPe869kVQgKYbMWED36WIDFG BiNYTiU1A91GuFy1SQ9q2Kn1XjUl7kQB6JvjHE/4wqGWjEgj/QaY0uKs5NRgN7UxfyP1p2D4FbW GyM0uo2yu5hAjQFRcj2mRJ+aTGQvcya2GZR0lSWICGdHwr5ZxidyjBs2xMYP0PU6oub0JtzW7MJ +iQYR0cMcdN69hlbFqaDUu7EqpzCumd06y13zjVbqi5f987mlxal0Ou4qI87OUNg+nSafNosUh/ Z+xfHpGB4NUeWxVQzAUd9833TkbQN3VvZDa8v72Y87eF77qhi1Rg8OXquXtma+6yXuAywskyGrc S35ahNyA4KWomxopSDDO+nkT8nsHIsLzleB7Fz+fO410K9aJD6lLO4dLwXLXzo5gTSIDkA7oqdM mG8QkTKLPXcMZtevGSg== X-Proofpoint-GUID: PIBF-U_M63OcoUNXPSvvfCAj3uWXKPfC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_06,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 impostorscore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 phishscore=0 spamscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250182 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1787693167794158500 Content-Type: text/plain; charset="utf-8" The soon to be added 'riscv-server-ref' board will add a rtc FDT subnode that is similar to what the 'virt' board users. Put it into a helper to avoid copy/pasting code. No FDT changes intended. Signed-off-by: Daniel Henrique Barboza --- hw/riscv/fdt-common.c | 23 +++++++++++++++++++++++ hw/riscv/virt.c | 26 ++------------------------ include/hw/riscv/fdt-common.h | 3 +++ 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/hw/riscv/fdt-common.c b/hw/riscv/fdt-common.c index b3f3af3762..4e12b5741e 100644 --- a/hw/riscv/fdt-common.c +++ b/hw/riscv/fdt-common.c @@ -830,3 +830,26 @@ void create_fdt_uart(void *fdt, const MemMapEntry *uar= t_mem, qemu_fdt_setprop_string(fdt, "/aliases", "serial0", name); } } + +void create_fdt_rtc(void *fdt, const MemMapEntry *rtc_mem, + int rtc_irq, int aia_type, + uint32_t irq_mmio_phandle) +{ + g_autofree char *name =3D NULL; + + name =3D g_strdup_printf("/soc/rtc@%"HWADDR_PRIx, + rtc_mem->base); + qemu_fdt_add_subnode(fdt, name); + qemu_fdt_setprop_string(fdt, name, "compatible", + "google,goldfish-rtc"); + qemu_fdt_setprop_sized_cells(fdt, name, "reg", + 2, rtc_mem->base, + 2, rtc_mem->size); + qemu_fdt_setprop_cell(fdt, name, "interrupt-parent", + irq_mmio_phandle); + if (aia_type =3D=3D AIA_TYPE_NONE) { + qemu_fdt_setprop_cell(fdt, name, "interrupts", rtc_irq); + } else { + qemu_fdt_setprop_cells(fdt, name, "interrupts", rtc_irq, 0x4); + } +} diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index e4bf9c26ef..f3c176dddc 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -415,29 +415,6 @@ static void create_fdt_virtio(RISCVVirtState *s, uint3= 2_t irq_virtio_phandle) } } =20 -static void create_fdt_rtc(RISCVVirtState *s, - uint32_t irq_mmio_phandle) -{ - g_autofree char *name =3D NULL; - MachineState *ms =3D MACHINE(s); - - name =3D g_strdup_printf("/soc/rtc@%"HWADDR_PRIx, - s->memmap[VIRT_RTC].base); - qemu_fdt_add_subnode(ms->fdt, name); - qemu_fdt_setprop_string(ms->fdt, name, "compatible", - "google,goldfish-rtc"); - qemu_fdt_setprop_sized_cells(ms->fdt, name, "reg", - 2, s->memmap[VIRT_RTC].base, - 2, s->memmap[VIRT_RTC].size); - qemu_fdt_setprop_cell(ms->fdt, name, "interrupt-parent", - irq_mmio_phandle); - if (s->aia_type =3D=3D VIRT_AIA_TYPE_NONE) { - qemu_fdt_setprop_cell(ms->fdt, name, "interrupts", RTC_IRQ); - } else { - qemu_fdt_setprop_cells(ms->fdt, name, "interrupts", RTC_IRQ, 0x4); - } -} - static void create_fdt_fw_cfg(RISCVVirtState *s) { MachineState *ms =3D MACHINE(s); @@ -545,7 +522,8 @@ static void finalize_fdt(RISCVVirtState *s) irq_mmio_phandle); } =20 - create_fdt_rtc(s, irq_mmio_phandle); + create_fdt_rtc(MACHINE(s)->fdt, &s->memmap[VIRT_RTC], RTC_IRQ, + s->aia_type, irq_mmio_phandle); } =20 static void create_fdt(RISCVVirtState *s) diff --git a/include/hw/riscv/fdt-common.h b/include/hw/riscv/fdt-common.h index cef1073449..fc518ac939 100644 --- a/include/hw/riscv/fdt-common.h +++ b/include/hw/riscv/fdt-common.h @@ -127,4 +127,7 @@ void create_fdt_uart(void *fdt, const MemMapEntry *uart= _mem, int uart_irq, int aia_type, bool additional_reg_props, bool is_serial0, uint32_t irq_mmio_phandle); +void create_fdt_rtc(void *fdt, const MemMapEntry *rtc_mem, + int rtc_irq, int aia_type, + uint32_t irq_mmio_phandle); #endif --=20 2.43.0 From nobody Sat Sep 26 23:03:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1787693110; cv=none; d=zohomail.com; s=zohoarc; b=CiPRenUCGyYabi5UXMgr1ey/eUrhWVyQ9lfD4px+n0cIc3tP9fedgS0ahM8TaBJsuGAyzyN/puBKlFPS18mlxcxWHzAgdDtWHakUlKi4g0DMMm+O7M7jqXn+g766yVPU23y663Jrc4YakS7/GJ1eSRsublfsovjmeRWmG5+SdAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787693110; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HeOItTZvILgyY+ctPuYqKhbG6qTTQsbkyGXvY2Arifc=; b=ZxRANrgQUl70zrIUXHFLR3MwmoQ5SFD5iwvZWZ8vZZajQgVh6w2cSzReKvyAJ3r6Y1kXanj4lUpMgLsIg/x7VlpXt5LKofaMtju2/wK/17dsZ9k3TKZdsm0LbPkobkFrYPrcw/fKEphNRdijo4wDOf7UhUed1Luyy9eJn6sL5hg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787693110247673.8996433577506; Tue, 25 Aug 2026 14:25:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyycw-0003h1-6b; Tue, 25 Aug 2026 17:24:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyycu-0003gQ-RA for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:12 -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 1wyycs-0002L5-VC for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:12 -0400 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67PL9qoD3116883 for ; Tue, 25 Aug 2026 21:24:10 GMT Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g9g4mrk8w-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 25 Aug 2026 21:24:09 +0000 (GMT) Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-52d7b3b6aa2so137291cf.1 for ; Tue, 25 Aug 2026 14:24:09 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([189.38.141.232]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90cc65299f0sm8646386d6.41.2026.08.25.14.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 14:24:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=HeOItTZvILg yY+ctPuYqKhbG6qTTQsbkyGXvY2Arifc=; b=njkXKCsvaZaoFNj4clVtVcQX0A5 CftkxRe0Q1O8W8bH01EM6HYO+CBpvBmBhHf7hf5rUMSbiW/JbjneSs+6CKkFsVzY wd4E21ythMSMIC8yMVOtHf4hisisaNUFT+060oRudqthzLlJET6WOWa/ucm+FX55 OXGbRnY5sWfr6kRAIjhTXVPZbpIlQksRzkBBI4oiWLB/yXezOcDH6VlrG4FX1UUU O3pXYiARupcplF0klZYSTxLGjob1wbTEtufS73Geiz1Yz6FqUu4bu6hnJvTCKsgb hHKRS4YkGETMxgZNYi+e2FD+7GxlyChSIIS33gUffmmndmMPNEo9pJ2Yg3A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787693049; x=1788297849; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=HeOItTZvILgyY+ctPuYqKhbG6qTTQsbkyGXvY2Arifc=; b=e2uzUawYuhGY6lzkr40w2rppSlrXzRTX1SJpdU+MtJ5YjOReVHFjdn47rxWGIQzXvY YKIxKN9XJo2l9svSkdiVG21flsyZhKv8oKHTUk55UC4BoBqVpxFuH3RTDVvVlqnR4gGy V1twk4qsiRQXUNIF5MyJuN444rQ+1/0naVzTKdi4izZEFwaY73+RvDyVoppr2zdo3akA 52bS1jvF8G8kZKl6L2PwlTnLEPa0wWkWUdiJ3nKt+ObgqFFUqoQ6QIpIIblVAH6aNP0X XfBJ3XbR5Xd/EQeuJN/5QUaN1hSsMPR+hwWkCcHhfhi1lbGP7hb7nvlLQHze++WdVdPe 7INA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787693049; x=1788297849; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=HeOItTZvILgyY+ctPuYqKhbG6qTTQsbkyGXvY2Arifc=; b=YBNwIrKZTYc4wsq/hD3rb2ko2paeJjsBvMi20yEt1Hz+EAWIpETwUfTfyA8h6HTZoJ +3ckfnTkIJS7dkLv4qNag2LZmYedDreM6Lp8dNc+9Jt6ceDF8GS8EyIq++7zBf1eBkGD GZRpvrGX4ygIvV6TW7tBmTCB4tMVf6pvutibyHSNj/UIPiuytL6OGeIVEevajQGwuTwU 90pckMxPPAOqBTja9WojqdJBT14B4ftD6cmSMAk+RutzH3gIXyKx+4ktWj8ttXjJHJI0 1UkWAgId4Pit8CcrKUiwvoPMaIZ3VO/hcVwe61EjBaRtAypHVSoasQynGTwCfkAPqPrT 8NRQ== X-Gm-Message-State: AFuF++l+kKrlrNhQbhbSaZs4BMGsw6LuWrRLYRk40MH+WQUD7t4bUvUt OhDuVGkLsSbxfpx+CG970NPX0GEVxo15urQiMJTvr9Ysq0utpl+3y4fPTvQgpBI/5mKUP57CQdW /TT2Wvyoc8d3d00aebNALcluLsze50K86b+QQSykxkierEaZOMSvv0J91IrnXUAKK9w== X-Gm-Gg: AR+sD13PR2D9DNvLasKGoURuE8SgVNsTGLhfvB2OmyswR876QJWdtogw19ZCsZx7Lsg QGUWEwDCYYGFBGQCvvBfoSQSaGZf+44fgNm8BeU06fR7cAz2DbFiZiOpko4/6AusLmFzt/+LIW2 EMfmxQcl24hWDdwRB5TracA949PafuiJT9nCO0MK7Rj8KjhZ/wkJvOz46CtOajSzeOQNy4WcImE xBs4xucZ8u7PGqDscvWYFEMf1I8Du7Ed13Atx3bVKI1iyjqddxEYfJcWzm63TSm/k0xG5Hklaiq hC2hOoCJMLs5nF6rxOEdyNy7Q82sshUdVPzCw5V0tuaD8ZKvQxzYpULSj4eoLz84W+I4BddttXp H05THyVeYE1zhuULT887EozYQC/z5z60rvbS4cQ== X-Received: by 2002:a05:622a:82:b0:51e:e5a2:ac82 with SMTP id d75a77b69052e-52e4230bf05mr19956721cf.23.1787693049222; Tue, 25 Aug 2026 14:24:09 -0700 (PDT) X-Received: by 2002:a05:622a:82:b0:51e:e5a2:ac82 with SMTP id d75a77b69052e-52e4230bf05mr19956041cf.23.1787693048590; Tue, 25 Aug 2026 14:24:08 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com, Daniel Henrique Barboza , Palmer Dabbelt Subject: [PATCH 10/13] hw/riscv/device-common, virt.c: add create_platform_bus() Date: Tue, 25 Aug 2026 18:23:22 -0300 Message-ID: <20260825212326.1907-11-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> References: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX8CAIxgYFaKUn Y5j25hSiCgZvGuJjKvdMkLEApKeg9fnWPT9CiEtw9fi8cjOeN/jxVm0Uxw3YoeqgGunf9fTFgJs MJkuxbk32H/rRPU5euEWa2450dg3Abo= X-Proofpoint-ORIG-GUID: kPGadjO3jhDKuLFh0PVOr26A0MAZbtjU X-Authority-Analysis: v=2.4 cv=eYgNubEH c=1 sm=1 tr=0 ts=6a8e07f9 cx=c_pps a=EVbN6Ke/fEF3bsl7X48z0g==:117 a=MCIxunHWmQOg/5OnbzXZaw==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=EUspDBNiAAAA:8 a=8qX1o8pqpDL_2YrQefAA:9 a=a_PwQJl-kcHnX1M80qC6:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX+4fETMVULlb4 9O4ci+VY8JJTnObronLgDSJjl+nlZ0uAEEERP9nNQWJJoPHs5Y9Q5t15SswoSdZdlpeuKFlGTOQ n0aFt63oP7U3Dl/4Ci7PoR5T+2+02IfechRzVBhWGl5v8qGYaaY1hVItQlBzmNKGjYIrGgGvs3G QUpfIWJxOfR2/8rAm+wExkDdOXZLh9MI2Swd38TvAUmhCjuky60u6LysQj2mXseD4Rv1ZL1oj+Q tYjI9+zWC0oUTh2npKFA8v9rmNPYgwdxxZHvJu9saEpwnv5u2cmshao1TJWFxantQfhST6n2gcK R288vcWAo9Rt0fOoxM+q9E5I5fRmsNVfxgM8Kq+kDprwEuhuRRWBF3qwla3unnUKVzVwEpClrRN e9LUKeEyKNcxJfFRl9eYC//l1/4jBYHKY9Xk48NUShZptcyoZLdnHHGW1DvLweOhMPGqVwAH0Zo BzWYo410gV46+qU8Hxw== X-Proofpoint-GUID: kPGadjO3jhDKuLFh0PVOr26A0MAZbtjU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_06,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 impostorscore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 phishscore=0 spamscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250182 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1787693111677158500 Content-Type: text/plain; charset="utf-8" There will be code repetition instances added by the 'riscv-server-ref' board w.r.t device creation and initialization. Instead of waiting for that code to land we're adding helpers beforehand. The idea is to make the new board code shorter and more palatable for reviewers. A new 'device-common' file is created for such helpers. We'll start with the platform bus, a nice piece of software that only the 'virt' board uses so far, and the 'riscv-server-ref' will use to support TPM devices. Signed-off-by: Daniel Henrique Barboza --- hw/riscv/device-common.c | 48 ++++++++++++++++++++++++++++++++ hw/riscv/meson.build | 1 + hw/riscv/virt.c | 31 ++++----------------- include/hw/riscv/device-common.h | 19 +++++++++++++ 4 files changed, 73 insertions(+), 26 deletions(-) create mode 100644 hw/riscv/device-common.c create mode 100644 include/hw/riscv/device-common.h diff --git a/hw/riscv/device-common.c b/hw/riscv/device-common.c new file mode 100644 index 0000000000..74627b996d --- /dev/null +++ b/hw/riscv/device-common.c @@ -0,0 +1,48 @@ +/* + * RISC-V board helpers for FDT generation. + * + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" + +#include "hw/riscv/device-common.h" + +#include "hw/core/platform-bus.h" +#include "hw/core/qdev.h" +#include "hw/core/qdev-properties.h" +#include "hw/core/sysbus.h" +#include "qapi/error.h" +#include "system/address-spaces.h" +#include "system/memory.h" + + +DeviceState *create_platform_bus(DeviceState *irqchip, + const MemMapEntry *platform_bus_mem, + int platform_bus_base_irq, + int platform_bus_num_irqs) +{ + MemoryRegion *sysmem =3D get_system_memory(); + DeviceState *dev; + SysBusDevice *sysbus; + + dev =3D qdev_new(TYPE_PLATFORM_BUS_DEVICE); + dev->id =3D g_strdup(TYPE_PLATFORM_BUS_DEVICE); + qdev_prop_set_uint32(dev, "num_irqs", platform_bus_num_irqs); + qdev_prop_set_uint32(dev, "mmio_size", platform_bus_mem->size); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + + sysbus =3D SYS_BUS_DEVICE(dev); + for (int i =3D 0; i < platform_bus_num_irqs; i++) { + int irq =3D platform_bus_base_irq + i; + sysbus_connect_irq(sysbus, i, qdev_get_gpio_in(irqchip, irq)); + } + + memory_region_add_subregion(sysmem, + platform_bus_mem->base, + sysbus_mmio_get_region(sysbus, 0)); + + return dev; +} diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build index 0d82ceacc4..7aa3c1578d 100644 --- a/hw/riscv/meson.build +++ b/hw/riscv/meson.build @@ -1,6 +1,7 @@ riscv_ss =3D ss.source_set() riscv_ss.add(files('aia.c')) riscv_ss.add(files('boot.c')) +riscv_ss.add(files('device-common.c')) riscv_ss.add(files('fdt-common.c')) riscv_ss.add(when: 'CONFIG_RISCV_NUMA', if_true: files('numa.c')) riscv_ss.add(files('riscv_hart.c')) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index f3c176dddc..7ecc3aeb6e 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -35,6 +35,7 @@ #include "hw/riscv/riscv-iommu-bits.h" #include "hw/riscv/virt.h" #include "hw/riscv/boot.h" +#include "hw/riscv/device-common.h" #include "hw/riscv/fdt-common.h" #include "hw/riscv/machines-qom.h" #include "hw/riscv/numa.h" @@ -661,31 +662,6 @@ static DeviceState *virt_create_plic(const MemMapEntry= *memmap, int socket, memmap[VIRT_PLIC].size); } =20 -static void create_platform_bus(RISCVVirtState *s, DeviceState *irqchip) -{ - DeviceState *dev; - SysBusDevice *sysbus; - int i; - MemoryRegion *sysmem =3D get_system_memory(); - - dev =3D qdev_new(TYPE_PLATFORM_BUS_DEVICE); - dev->id =3D g_strdup(TYPE_PLATFORM_BUS_DEVICE); - qdev_prop_set_uint32(dev, "num_irqs", VIRT_PLATFORM_BUS_NUM_IRQS); - qdev_prop_set_uint32(dev, "mmio_size", s->memmap[VIRT_PLATFORM_BUS].si= ze); - sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); - s->platform_bus_dev =3D dev; - - sysbus =3D SYS_BUS_DEVICE(dev); - for (i =3D 0; i < VIRT_PLATFORM_BUS_NUM_IRQS; i++) { - int irq =3D VIRT_PLATFORM_BUS_IRQ + i; - sysbus_connect_irq(sysbus, i, qdev_get_gpio_in(irqchip, irq)); - } - - memory_region_add_subregion(sysmem, - s->memmap[VIRT_PLATFORM_BUS].base, - sysbus_mmio_get_region(sysbus, 0)); -} - static void virt_build_smbios(RISCVVirtState *s) { MachineClass *mc =3D MACHINE_GET_CLASS(s); @@ -1006,7 +982,10 @@ static void virt_machine_init(MachineState *machine) =20 gpex_pcie_init(system_memory, pcie_irqchip, s); =20 - create_platform_bus(s, mmio_irqchip); + s->platform_bus_dev =3D create_platform_bus(mmio_irqchip, + &s->memmap[VIRT_PLATFORM_BUS= ], + VIRT_PLATFORM_BUS_IRQ, + VIRT_PLATFORM_BUS_NUM_IRQS); =20 serial_mm_init(system_memory, s->memmap[VIRT_UART0].base, 0, qdev_get_gpio_in(mmio_irqchip, UART0_IRQ), 399193, diff --git a/include/hw/riscv/device-common.h b/include/hw/riscv/device-com= mon.h new file mode 100644 index 0000000000..f91c39511f --- /dev/null +++ b/include/hw/riscv/device-common.h @@ -0,0 +1,19 @@ +/* + * RISC-V board helpers for FDT generation. + * + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef RISCV_DEVICE_COMMON_H +#define RISCV_DEVICE_COMMON_H + +#include "exec/hwaddr.h" +#include "hw/core/qdev.h" + +DeviceState *create_platform_bus(DeviceState *irqchip, + const MemMapEntry *platform_bus_mem, + int platform_bus_base_irq, + int platform_bus_num_irqs); +#endif --=20 2.43.0 From nobody Sat Sep 26 23:03:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1787693092; cv=none; d=zohomail.com; s=zohoarc; b=J7OPbQkEtU24Fe+m+JrcvYUvR7M24zhiAjvFMRceFghCovuv8ooAcNCbb10ix6z2NaFOJ4zHW83pcDgsLhD/EZRj81mRZQITPyKbCSeQRyoiuxVdfxxN35isPq/ZXvcBvULZTso7vqNVOTGa+FN0F5NVJFu/Edx6T+TQgiDUvDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787693092; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sKbGwJXyn+McuKxpE6iklpsr3F53nmaiHi3Fl9IxJqo=; b=WhQ4kHPJxMpfS2mEoA7lfLoNu2wI8qCkDSrQEutEubRezJbezvnDolBOkVC6Or3lpf4Hpw+E/O5ai4RH/GI9xpKPqM7BqJRc9k0DMYys5Q2DqY2dBC+ItDQbnnpkNBCygwYtn7BUOYJ6LBxXnlBupSOl5RK+QHQUVYBWxORRO0E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178769309231235.58665467503249; Tue, 25 Aug 2026 14:24:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyyd9-0003qH-Sy; Tue, 25 Aug 2026 17:24:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyyd7-0003oP-IP for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:25 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyyd5-0002MU-MJ for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:25 -0400 Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67PL9rWP3099221 for ; Tue, 25 Aug 2026 21:24:12 GMT Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g9bkua1x2-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 25 Aug 2026 21:24:12 +0000 (GMT) Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-904ee4473a8so3027826d6.2 for ; Tue, 25 Aug 2026 14:24:12 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([189.38.141.232]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90cc65299f0sm8646386d6.41.2026.08.25.14.24.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 14:24:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=sKbGwJXyn+M cuKxpE6iklpsr3F53nmaiHi3Fl9IxJqo=; b=TmnCd15WPZOsPEFBf7DEUPX4+3l haerKTnzY9oDQ8IZqu84gzkFmn8/MOjeSEVdnLPLyvclSxzbsXyann0N9ZZdyYsf p54ZEOKB9qNek2wkKMuzKMXV1xVWp0BVe8RTFiwBzTF84Br+BvGuRniQphAupbev WHTJ7mLykzr3v7fmE+UK9k2SxvsFLabDlVqNTUP/yoSUD24cNhGS+Maw5Pth9qVq RPrfwwvNorXmCGSngJrIRSDuQiGnpvXz85XUJk49jzSq1qjAN+SOii6EyvCuFzRO hYj2bL+jLcoDExlbxyT83Mggd20FafwLQkU/mDDGnWcTEBh1MlUxMFNSc6g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787693051; x=1788297851; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=sKbGwJXyn+McuKxpE6iklpsr3F53nmaiHi3Fl9IxJqo=; b=OWUU/tJREx8IodSFRamTdgaQT88/COubu56pwQBCJ18VhxdSp/OvBk8YMbiIhQfe+I t9YsDoIMVGGpj+UgNPYlUGjFB3Bjyxmu8LQoG+Ulbu+GVWIXMxkqdp5xBfjqsebTX31g VGJ+XRwG1md2OjEfD3IEve+C6hTK//Cbol2aP89bcKhKaERjFS8Dr+U+sc3xauqa7qzu Q2N/b6ZuSl5l22+IFBAd4EAhvPHVLfUg2urytV79uaMpkowA61DAsjBl3mfzJGXXILbx IXGsXwFRc7OJAheRc2iQD8SBchEu4NMlRdLmwjeYHEuYt7qzIbdg94TnQ2CBrFB/RTrJ +aJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787693051; x=1788297851; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=sKbGwJXyn+McuKxpE6iklpsr3F53nmaiHi3Fl9IxJqo=; b=B7eyOw5bt9KIbozKXoiUT264qNRcHXL4ZNDSAwcz+50kvI8phvGErAr6DPzZpw7dn5 hks8pTS7iJk7qjiMr5w8DKliay9qtVGILGhJq2tsfbzmwQMuQCgfMWgYARw9D6QvsZtG K3jnEUZUWcgAhB+58YaJ4i+dksjIveUHn+BEQA6yYdqHDDaHPn9Vy+0asGX6U6hLpyT/ l5GV19h7BVEjKkUdAUoJCzmmSP1xmHCrJHU1W1lYKkcRHnYYS3Im07SwDNGn6e87+10c XtnCULIFj1vghJijF9AgWF3uwp2D9oxSoG2qc8tg869aN2vP/KTC2gDnmocAcBlY5bv1 nPwg== X-Gm-Message-State: AFuF++nKK+B9NOQbd9AkXhmGZ4HDbEaZntugm3i5WdJJnmgwpYv/UUfe BJFFGEBg9yXqAa+nXhljyOK3JdksrRncq6xDllyB2rl3rh4GNfTUBwTEQ5bg0GSkqXpjqDqtEba vq0X6EQzjXJlZdg6eibWMrX+TJclSRMK5rzPbEcC5gpzNuHWduV+tkgut/d38aqfNDg== X-Gm-Gg: AR+sD13sl1v5GFnzSXUhpO5fL0s7wVdnELSBfqJEwM3JFcvGwV8A07V0jgbpFXU/JIn eASv5fJXIWtXadfVg6IFrAMtLXj8y0EJLlIGALOub195w6phm0aJesMtDu/odT9g2VHpo7qUMKw mdC3VB29wa/e0xoiRhKB6peZoCWaGXJRDc6TIOEuIAGqyhhiyHxCHT+8vRzFitZbChDgPf7aNsI zoSMSQJQ/gN/JtAe77Z2ptI6LTbGbEmA3DHd6cVg5MqYdO8eD5nNm2AiK2XjMENtrki4spCx5l2 jEB8ecK9N8kRT8c97/S0dlazPPFpA14GJ0a105guBY6Bh2uEiS7TcCzan/mry7G6JjBzN5iPGU1 QH8ecYjRnFxG+rSoyDtB+bGc8dV4/iDhz4HaddQ== X-Received: by 2002:a05:6214:1c88:b0:90c:c4fe:8d9c with SMTP id 6a1803df08f44-90cc7979099mr16769826d6.27.1787693051275; Tue, 25 Aug 2026 14:24:11 -0700 (PDT) X-Received: by 2002:a05:6214:1c88:b0:90c:c4fe:8d9c with SMTP id 6a1803df08f44-90cc7979099mr16769406d6.27.1787693050860; Tue, 25 Aug 2026 14:24:10 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com, Daniel Henrique Barboza , Palmer Dabbelt Subject: [PATCH 11/13] hw/riscv/device-common, virt.c: add flash helpers Date: Tue, 25 Aug 2026 18:23:23 -0300 Message-ID: <20260825212326.1907-12-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> References: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: NU0ZPdFVAfuv8O6UXua9bxOFGUzuI4sn X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX5jKwIIe55VeV nfCwm6rapfTyyKIWzV15p9Mlk2HkC2oFTaezOB5H7XaQOucOkTWqrVFMyvm7OF5OaMCV6vviiDc ECgraBhfzV+mtwCmtjLWdiZF17DVhPU= X-Authority-Analysis: v=2.4 cv=TZGmcxQh c=1 sm=1 tr=0 ts=6a8e07fc cx=c_pps a=7E5Bxpl4vBhpaufnMqZlrw==:117 a=MCIxunHWmQOg/5OnbzXZaw==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yOCtJkima9RkubShWh1s:22 a=EUspDBNiAAAA:8 a=Ak_EWCeJEXv7LabEeCgA:9 a=pJ04lnu7RYOZP9TFuWaZ:22 X-Proofpoint-GUID: NU0ZPdFVAfuv8O6UXua9bxOFGUzuI4sn X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX4kyrvaOZgcy9 zGWzjxSEyLFUZ643i2LxCHN3cvM0GW0v0YPpSOFBumWpFIi0vVeGAIH7c8K6bWV0Pl++SPd0vzb qtp9AnUpWCsEQPvJqQ+jrcRTUzUXfljhE9+hOyyj+ra6zW755n7VHuqBQJqVG9JeOgS9NEeOE04 Q/wPniWFnWdn9RjG5PS+TEtebrVQKT8YTPwsN+Uz5/obrvO8yFYR/WEfjmRnhwD6Sqbs0NjbMpf g34L3nHnyttcXLOFT8GtyKWGDQ2/55RJQyqsBje/C7r72onxTnDFBcl5li56zAqKGqQrnhHFcuj iaGKPtc6NARSJ3C1uI5AOEAh70qp8pJ4aWQjmfRkTXsS+Z9WqbxqctYlULwqseZpZc+A6yM37vv 15xMwOg5jEWvm6yXUqHPJYWFbh/YZbm6kl/OCCRWFGP84Iuv2Um58dzcMtgWwUYDXgPoEcgbuuC vllkBlzrma/fVC09eyg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_06,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 spamscore=0 bulkscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250182 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1787693094055158500 Content-Type: text/plain; charset="utf-8" Move the flash device creating and flash map initialization to device-common.c. Signed-off-by: Daniel Henrique Barboza --- hw/riscv/device-common.c | 44 ++++++++++++++++++++++++ hw/riscv/virt.c | 57 +++++--------------------------- include/hw/riscv/device-common.h | 6 ++++ 3 files changed, 58 insertions(+), 49 deletions(-) diff --git a/hw/riscv/device-common.c b/hw/riscv/device-common.c index 74627b996d..03e85a7c86 100644 --- a/hw/riscv/device-common.c +++ b/hw/riscv/device-common.c @@ -10,11 +10,13 @@ =20 #include "hw/riscv/device-common.h" =20 +#include "hw/block/flash.h" #include "hw/core/platform-bus.h" #include "hw/core/qdev.h" #include "hw/core/qdev-properties.h" #include "hw/core/sysbus.h" #include "qapi/error.h" +#include "qom/object.h" #include "system/address-spaces.h" #include "system/memory.h" =20 @@ -46,3 +48,45 @@ DeviceState *create_platform_bus(DeviceState *irqchip, =20 return dev; } + +PFlashCFI01 *riscv_flash_create(Object *parent, const char *name, + const char *alias_prop_name, + int flash_sector_size) +{ + /* + * Create a single flash device. We use the same parameters as + * the flash devices on the ARM virt board. + */ + DeviceState *dev =3D qdev_new(TYPE_PFLASH_CFI01); + + qdev_prop_set_uint64(dev, "sector-length", flash_sector_size); + qdev_prop_set_uint8(dev, "width", 4); + qdev_prop_set_uint8(dev, "device-width", 2); + qdev_prop_set_bit(dev, "big-endian", false); + qdev_prop_set_uint16(dev, "id0", 0x89); + qdev_prop_set_uint16(dev, "id1", 0x18); + qdev_prop_set_uint16(dev, "id2", 0x00); + qdev_prop_set_uint16(dev, "id3", 0x00); + qdev_prop_set_string(dev, "name", name); + + object_property_add_child(parent, name, OBJECT(dev)); + object_property_add_alias(parent, alias_prop_name, + OBJECT(dev), "drive"); + + return PFLASH_CFI01(dev); +} + +void riscv_init_flash_map(PFlashCFI01 *flash, hwaddr base, hwaddr size, + MemoryRegion *sysmem, int flash_sector_size) +{ + DeviceState *dev =3D DEVICE(flash); + + assert(QEMU_IS_ALIGNED(size, flash_sector_size)); + assert(size / flash_sector_size <=3D UINT32_MAX); + + qdev_prop_set_uint32(dev, "num-blocks", size / flash_sector_size); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + + memory_region_add_subregion(sysmem, base, + sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0)= ); +} diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 7ecc3aeb6e..6ffafae46d 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -120,53 +120,12 @@ static MemMapEntry virt_high_pcie_memmap; =20 #define VIRT_FLASH_SECTOR_SIZE (256 * KiB) =20 -static PFlashCFI01 *virt_flash_create1(RISCVVirtState *s, - const char *name, - const char *alias_prop_name) -{ - /* - * Create a single flash device. We use the same parameters as - * the flash devices on the ARM virt board. - */ - DeviceState *dev =3D qdev_new(TYPE_PFLASH_CFI01); - - qdev_prop_set_uint64(dev, "sector-length", VIRT_FLASH_SECTOR_SIZE); - qdev_prop_set_uint8(dev, "width", 4); - qdev_prop_set_uint8(dev, "device-width", 2); - qdev_prop_set_bit(dev, "big-endian", false); - qdev_prop_set_uint16(dev, "id0", 0x89); - qdev_prop_set_uint16(dev, "id1", 0x18); - qdev_prop_set_uint16(dev, "id2", 0x00); - qdev_prop_set_uint16(dev, "id3", 0x00); - qdev_prop_set_string(dev, "name", name); - - object_property_add_child(OBJECT(s), name, OBJECT(dev)); - object_property_add_alias(OBJECT(s), alias_prop_name, - OBJECT(dev), "drive"); - - return PFLASH_CFI01(dev); -} - static void virt_flash_create(RISCVVirtState *s) { - s->flash[0] =3D virt_flash_create1(s, "virt.flash0", "pflash0"); - s->flash[1] =3D virt_flash_create1(s, "virt.flash1", "pflash1"); -} - -static void virt_flash_map1(PFlashCFI01 *flash, - hwaddr base, hwaddr size, - MemoryRegion *sysmem) -{ - DeviceState *dev =3D DEVICE(flash); - - assert(QEMU_IS_ALIGNED(size, VIRT_FLASH_SECTOR_SIZE)); - assert(size / VIRT_FLASH_SECTOR_SIZE <=3D UINT32_MAX); - qdev_prop_set_uint32(dev, "num-blocks", size / VIRT_FLASH_SECTOR_SIZE); - sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); - - memory_region_add_subregion(sysmem, base, - sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), - 0)); + s->flash[0] =3D riscv_flash_create(OBJECT(s), "virt.flash0", "pflash0", + VIRT_FLASH_SECTOR_SIZE); + s->flash[1] =3D riscv_flash_create(OBJECT(s), "virt.flash1", "pflash1", + VIRT_FLASH_SECTOR_SIZE); } =20 static void virt_flash_map(RISCVVirtState *s, @@ -175,10 +134,10 @@ static void virt_flash_map(RISCVVirtState *s, hwaddr flashsize =3D s->memmap[VIRT_FLASH].size / 2; hwaddr flashbase =3D s->memmap[VIRT_FLASH].base; =20 - virt_flash_map1(s->flash[0], flashbase, flashsize, - sysmem); - virt_flash_map1(s->flash[1], flashbase + flashsize, flashsize, - sysmem); + riscv_init_flash_map(s->flash[0], flashbase, flashsize, + sysmem, VIRT_FLASH_SECTOR_SIZE); + riscv_init_flash_map(s->flash[1], flashbase + flashsize, flashsize, + sysmem, VIRT_FLASH_SECTOR_SIZE); } =20 static void create_fdt_socket_plic(RISCVVirtState *s, diff --git a/include/hw/riscv/device-common.h b/include/hw/riscv/device-com= mon.h index f91c39511f..1cdb8ab5cc 100644 --- a/include/hw/riscv/device-common.h +++ b/include/hw/riscv/device-common.h @@ -10,10 +10,16 @@ #define RISCV_DEVICE_COMMON_H =20 #include "exec/hwaddr.h" +#include "hw/block/flash.h" #include "hw/core/qdev.h" =20 DeviceState *create_platform_bus(DeviceState *irqchip, const MemMapEntry *platform_bus_mem, int platform_bus_base_irq, int platform_bus_num_irqs); +PFlashCFI01 *riscv_flash_create(Object *parent, const char *name, + const char *alias_prop_name, + int flash_sector_size); +void riscv_init_flash_map(PFlashCFI01 *flash, hwaddr base, hwaddr size, + MemoryRegion *sysmem, int flash_sector_size); #endif --=20 2.43.0 From nobody Sat Sep 26 23:03:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1787693114; cv=none; d=zohomail.com; s=zohoarc; b=bVYvYJLbH71jiJx0NU/KNHYzyZX9nVXUuugCnNjd8uVylom4phFceYW4fWJYRWsTyBue/LpLG1IXrtnYSrL+re45G7Ir4pF88NOC8BRAZvpJJcmJPcPS/JrlEIelNG7dLTWdOGnWumsqHR8vh9/T0lh6yfqUPnf2LldGeIW5aLc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787693114; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zik9fMnwPW+cjZ1etBvvnJ0/y9M6axxZ9bmNknOgDGA=; b=l2FHGhRKYcN8wU00i/vQvfQkHL8f15ryooDts/07vzsn5GipwP5GKGHM0/PXgP0xUbnIuwfr7uKZhKAXgik8FP7VMs5hb+x0GmpWa4pHroSj/55uON5JerOeNIfaeWymB4R4VX0agZAOhvXcg0WQxKblCG1RanuHHWCzUvBA1Ds= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787693114137284.3434531729563; Tue, 25 Aug 2026 14:25:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyydH-0003z1-33; Tue, 25 Aug 2026 17:24:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyydF-0003tf-G0 for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:33 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyydD-0002NV-Fs for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:33 -0400 Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67PLA17i2499408 for ; Tue, 25 Aug 2026 21:24:20 GMT Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g9fjn0tfp-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 25 Aug 2026 21:24:20 +0000 (GMT) Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-52769fc3f2eso4359071cf.0 for ; Tue, 25 Aug 2026 14:24:19 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([189.38.141.232]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90cc65299f0sm8646386d6.41.2026.08.25.14.24.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 14:24:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=zik9fMnwPW+ cjZ1etBvvnJ0/y9M6axxZ9bmNknOgDGA=; b=PWdSrIAuJDQgM96F3IXQIJ4TQL8 Z8FFBN5Zf/Ro4o80k3n04VzE0mrzkv7i5XaOaA2qcnMTrrhxJ81XojTK7e3tVViI N7hX10bh6/im46AUsOoo8jQFy6amTW716HpgTfNoTxC8mZ122PA1vlmPMmEVhz1w Dc/GMwuxe8lYL27JDcIIHc60uUAy4fTsG4HfuuTvOu+SYnV7X9io7MbHpBEkK/xQ GsS9dKjkMztVWyycYeVLaPj/zB7MosXaCsWUpA3x3cYMeMbaijJb6NO9vX8tcxqZ GNOAvbRjFdwrLXxjEAaIJ3VBjaBoRfiz6NmCXgE5bRiNjgMl+LY4BjdK3aw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787693059; x=1788297859; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zik9fMnwPW+cjZ1etBvvnJ0/y9M6axxZ9bmNknOgDGA=; b=IQV1SkNi5tE5lq1Hv4at+2z+rWgM0mlxaTj6NmOgQCeGY3Z2UQ4OWbdavkEcFF5DCK Tc4UirLqTxm25GbRCYS2G61WwdnikY6ofxtIw3GKQRCacFkq2bb1FVsdoGxO1+vtvR// 590nOs74iPdOvTJ6DEkkJXZDXoDoAzu6QvZFZfUI+tL/Cz/GA4a591gv7K9NvXXpsRLm JvcN6k5Vc03gDr3+HmgD4rWHffmz33isRSnWPNKnPg7xY+++o8RaYBQf0eWxAVtk/WZ/ M2FmeUCRXaL9lePR4eqcf3xm7KEQITIeHCzcl1/oWmAMdiRFNHwze/yJ29zTjNz09bBr ZoXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787693059; x=1788297859; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=zik9fMnwPW+cjZ1etBvvnJ0/y9M6axxZ9bmNknOgDGA=; b=iyLsVHP2y4fIjuiincOtHrEUzOyVBe0b23LudxBJUKE9jwJHzbVtlZIF7nFtC+k7TA e1V9ivtL6FLuqnyGmbnDJNpj44oWjiNfA67b7adO2ugwfrVShmcWp+K2sAKjVBqZUVH2 giDhuxWTwalTd5jfPq87EHpMOBK/2zFf0ZQ0qGvlljpiFNIHlL4L7tgH2BMGk+6HgFjq CdQlDe+IWOEyXW/6/dfVp1s+qC/8FOqHwKlmuQQhOobaW1cY2hMZUjVhabv8Oy2OQW/I UG5rkMAy+AORsEfdlG1/aeArI878zh7lnDTQL6AjhsERXExCkcNnaAbzj4ANU/C74isB UFVw== X-Gm-Message-State: AFuF++lsyeUHZkNTPfkqnpp5HSSoSqb2tLRC6CCJ2zMKScL/yeauvkcs 3lQDz42dx+Vzky/sNP96rCeoMqQii0gXT4Ay0CzahIFz65wymhcv1ZobGZvv8QUnz7FALBlEsDh Nbs/CPJjEJbUlO50VEtoURS42u391pBUrmbSUjhLCnewyJ4CdGvsUEKlvtx405RSZjg== X-Gm-Gg: AR+sD10/jvywgfIQgeyWGEcW8+Tfyb6CeLBUvroKhTs5jgzbJUJgwE/JLeiU8GKZ7/o xP8Kw3uPrVkPPhqAb7UoiWKsmudXR0oD5XKWQ/Q4Hcr1cW6F0NFMLxQ/ChcfBN4ALPDRRnzrupG vsHZFwAhNwrez4fNj6yYtNkruBpjCc0mKGESfIyTZDB1x+whFaPrLFBvevQoTi08pHMswPnOVp6 yBus5Sn8H/FkuEdraD6IPbyH72KC417nr0Z7spWdFytXA7WjllNz/o4nsM5h/Zq41I61NMNqhqw s/rAy7kg5WjJZ+kUhV7BXSgkPnkvprGd2PLvQqYzEignaHgxaMgcheax8/3e6cTPt+++3IR0Lv7 mix8mg41OOHmoFlnnTbgicGvL9Ufw/j2sHPiiBw== X-Received: by 2002:a05:622a:1903:b0:528:3882:3869 with SMTP id d75a77b69052e-52e4228dd23mr22908971cf.13.1787693054122; Tue, 25 Aug 2026 14:24:14 -0700 (PDT) X-Received: by 2002:a05:622a:1903:b0:528:3882:3869 with SMTP id d75a77b69052e-52e4228dd23mr22907721cf.13.1787693053142; Tue, 25 Aug 2026 14:24:13 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com, Daniel Henrique Barboza , Palmer Dabbelt Subject: [PATCH 12/13] hw/riscv/device-common, virt.c: add gpex_pcie_init() Date: Tue, 25 Aug 2026 18:23:24 -0300 Message-ID: <20260825212326.1907-13-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> References: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: lXuaUSO6g6voLRwU-fNO-cbpFDkCdU2k X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfXyZGTir35W+xM A7Y6JIcFdqWuLbE9JEEpZFz3q1nDQAMM96edvqGdxgeZL98Ensy3cgBZqUuLq91j3fHKjMme+Oa BHSm2467E0mT8K1AGW8t7c+nIRIpilg= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX/WNYc/RhfkF1 Z7xZe4GyrDTJVj6cctMxw7Kaie/WZepH/tiw/dD/s17ul3Ah1UqLXsSm1Rwo8VuxUBMMbAaSlcy 4GJq2rPVGocFSFqB5GVgy5kHZzFMnWrJwuCocEj0yLk4JvTT+vf6AazlcUNwLAWxrMYM44g4Kp2 igfzKMBvk5ccKi/f77o9VZpC9gVQ0Xz3yPVa3qzBRnXzp3SaJ5rJ5NGegBLDKXAK/6GUV/aJgMo 08O4tA77fMxIDzl/FsyHsZtcPX/FfxPSIvWhf3VEXUaDuRfnW4TbFS9VQfI/e09S43QYIudg7YV IgbW1iE45FRd5wMDsy0v/RFqMaW5JYdl891DWfNEDe8rtdzrflM0RwO7NFKDtCaVMCm+teMOvGL yH0Rof4/JnVa9T9PTUFi9HGZwSX32bYYTySRdwtUuqo1lkJhy3e861VpBFQNcSYPNXa0dZjveM6 T6Knibjp6/8NLITeApw== X-Authority-Analysis: v=2.4 cv=ccziaHDM c=1 sm=1 tr=0 ts=6a8e0804 cx=c_pps a=JbAStetqSzwMeJznSMzCyw==:117 a=MCIxunHWmQOg/5OnbzXZaw==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=EUspDBNiAAAA:8 a=i57S3HUJNi793Ni1t6cA:9 a=uxP6HrT_eTzRwkO_Te1X:22 X-Proofpoint-ORIG-GUID: lXuaUSO6g6voLRwU-fNO-cbpFDkCdU2k X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_06,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 clxscore=1015 malwarescore=0 bulkscore=0 adultscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250182 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1787693115933158500 Content-Type: text/plain; charset="utf-8" The GPEX_HOST initialization in 'virt' can be moved to device-common.c and be re-used later for other boards, namely the future 'riscv-server-ref' emulation. Signed-off-by: Daniel Henrique Barboza --- hw/riscv/device-common.c | 76 +++++++++++++++++++++++++++++++ hw/riscv/virt.c | 77 ++------------------------------ include/hw/riscv/device-common.h | 7 +++ 3 files changed, 87 insertions(+), 73 deletions(-) diff --git a/hw/riscv/device-common.c b/hw/riscv/device-common.c index 03e85a7c86..49f6fb8dd2 100644 --- a/hw/riscv/device-common.c +++ b/hw/riscv/device-common.c @@ -15,6 +15,8 @@ #include "hw/core/qdev.h" #include "hw/core/qdev-properties.h" #include "hw/core/sysbus.h" +#include "hw/pci/pci.h" +#include "hw/pci-host/gpex.h" #include "qapi/error.h" #include "qom/object.h" #include "system/address-spaces.h" @@ -90,3 +92,77 @@ void riscv_init_flash_map(PFlashCFI01 *flash, hwaddr bas= e, hwaddr size, memory_region_add_subregion(sysmem, base, sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0)= ); } + +DeviceState *gpex_pcie_init(MemoryRegion *sys_mem, + DeviceState *irqchip, + const MemMapEntry *pcie_ecam_mem, + const MemMapEntry *pcie_mmio_mem, + const MemMapEntry *high_pcie_mmio_mem, + const MemMapEntry *pcie_pio_mem, + int pcie_irq) +{ + DeviceState *dev; + MemoryRegion *ecam_alias, *ecam_reg; + MemoryRegion *mmio_alias, *high_mmio_alias, *mmio_reg; + hwaddr ecam_base =3D pcie_ecam_mem->base; + hwaddr ecam_size =3D pcie_ecam_mem->size; + hwaddr mmio_base =3D pcie_mmio_mem->base; + hwaddr mmio_size =3D pcie_mmio_mem->size; + hwaddr high_mmio_base =3D high_pcie_mmio_mem->base; + hwaddr high_mmio_size =3D high_pcie_mmio_mem->size; + hwaddr pio_base =3D pcie_pio_mem->base; + hwaddr pio_size =3D pcie_pio_mem->size; + + dev =3D qdev_new(TYPE_GPEX_HOST); + + /* Set GPEX object properties for the virt machine */ + object_property_set_uint(OBJECT(dev), PCI_HOST_ECAM_BASE, + ecam_base, NULL); + object_property_set_int(OBJECT(dev), PCI_HOST_ECAM_SIZE, + ecam_size, NULL); + object_property_set_uint(OBJECT(dev), PCI_HOST_BELOW_4G_MMIO_BASE, + mmio_base, NULL); + object_property_set_int(OBJECT(dev), PCI_HOST_BELOW_4G_MMIO_SIZE, + mmio_size, NULL); + object_property_set_uint(OBJECT(dev), PCI_HOST_ABOVE_4G_MMIO_BASE, + high_mmio_base, NULL); + object_property_set_int(OBJECT(dev), PCI_HOST_ABOVE_4G_MMIO_SIZE, + high_mmio_size, NULL); + object_property_set_uint(OBJECT(dev), PCI_HOST_PIO_BASE, + pio_base, NULL); + object_property_set_int(OBJECT(dev), PCI_HOST_PIO_SIZE, + pio_size, NULL); + + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + + ecam_alias =3D g_new0(MemoryRegion, 1); + ecam_reg =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); + memory_region_init_alias(ecam_alias, OBJECT(dev), "pcie-ecam", + ecam_reg, 0, ecam_size); + memory_region_add_subregion(get_system_memory(), ecam_base, ecam_alias= ); + + mmio_alias =3D g_new0(MemoryRegion, 1); + mmio_reg =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1); + memory_region_init_alias(mmio_alias, OBJECT(dev), "pcie-mmio", + mmio_reg, mmio_base, mmio_size); + memory_region_add_subregion(get_system_memory(), mmio_base, mmio_alias= ); + + /* Map high MMIO space */ + high_mmio_alias =3D g_new0(MemoryRegion, 1); + memory_region_init_alias(high_mmio_alias, OBJECT(dev), "pcie-mmio-high= ", + mmio_reg, high_mmio_base, high_mmio_size); + memory_region_add_subregion(get_system_memory(), high_mmio_base, + high_mmio_alias); + + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, pio_base); + + for (int i =3D 0; i < PCI_NUM_PINS; i++) { + qemu_irq irq =3D qdev_get_gpio_in(irqchip, pcie_irq + i); + + sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq); + gpex_set_irq_num(GPEX_HOST(dev), i, pcie_irq + i); + } + + GPEX_HOST(dev)->gpex_cfg.bus =3D PCI_HOST_BRIDGE(dev)->bus; + return dev; +} diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 6ffafae46d..af9de36726 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -518,78 +518,6 @@ static void create_fdt(RISCVVirtState *s) create_fdt_pmu(s); } =20 -static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem, - DeviceState *irqchip, - RISCVVirtState *s) -{ - DeviceState *dev; - MemoryRegion *ecam_alias, *ecam_reg; - MemoryRegion *mmio_alias, *high_mmio_alias, *mmio_reg; - hwaddr ecam_base =3D s->memmap[VIRT_PCIE_ECAM].base; - hwaddr ecam_size =3D s->memmap[VIRT_PCIE_ECAM].size; - hwaddr mmio_base =3D s->memmap[VIRT_PCIE_MMIO].base; - hwaddr mmio_size =3D s->memmap[VIRT_PCIE_MMIO].size; - hwaddr high_mmio_base =3D virt_high_pcie_memmap.base; - hwaddr high_mmio_size =3D virt_high_pcie_memmap.size; - hwaddr pio_base =3D s->memmap[VIRT_PCIE_PIO].base; - hwaddr pio_size =3D s->memmap[VIRT_PCIE_PIO].size; - qemu_irq irq; - int i; - - dev =3D qdev_new(TYPE_GPEX_HOST); - - /* Set GPEX object properties for the virt machine */ - object_property_set_uint(OBJECT(dev), PCI_HOST_ECAM_BASE, - ecam_base, NULL); - object_property_set_int(OBJECT(dev), PCI_HOST_ECAM_SIZE, - ecam_size, NULL); - object_property_set_uint(OBJECT(dev), PCI_HOST_BELOW_4G_MMIO_BASE, - mmio_base, NULL); - object_property_set_int(OBJECT(dev), PCI_HOST_BELOW_4G_MMIO_SIZE, - mmio_size, NULL); - object_property_set_uint(OBJECT(dev), PCI_HOST_ABOVE_4G_MMIO_BASE, - high_mmio_base, NULL); - object_property_set_int(OBJECT(dev), PCI_HOST_ABOVE_4G_MMIO_SIZE, - high_mmio_size, NULL); - object_property_set_uint(OBJECT(dev), PCI_HOST_PIO_BASE, - pio_base, NULL); - object_property_set_int(OBJECT(dev), PCI_HOST_PIO_SIZE, - pio_size, NULL); - - sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); - - ecam_alias =3D g_new0(MemoryRegion, 1); - ecam_reg =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); - memory_region_init_alias(ecam_alias, OBJECT(dev), "pcie-ecam", - ecam_reg, 0, ecam_size); - memory_region_add_subregion(get_system_memory(), ecam_base, ecam_alias= ); - - mmio_alias =3D g_new0(MemoryRegion, 1); - mmio_reg =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1); - memory_region_init_alias(mmio_alias, OBJECT(dev), "pcie-mmio", - mmio_reg, mmio_base, mmio_size); - memory_region_add_subregion(get_system_memory(), mmio_base, mmio_alias= ); - - /* Map high MMIO space */ - high_mmio_alias =3D g_new0(MemoryRegion, 1); - memory_region_init_alias(high_mmio_alias, OBJECT(dev), "pcie-mmio-high= ", - mmio_reg, high_mmio_base, high_mmio_size); - memory_region_add_subregion(get_system_memory(), high_mmio_base, - high_mmio_alias); - - sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, pio_base); - - for (i =3D 0; i < PCI_NUM_PINS; i++) { - irq =3D qdev_get_gpio_in(irqchip, PCIE_IRQ + i); - - sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq); - gpex_set_irq_num(GPEX_HOST(dev), i, PCIE_IRQ + i); - } - - GPEX_HOST(dev)->gpex_cfg.bus =3D PCI_HOST_BRIDGE(dev)->bus; - return dev; -} - static FWCfgState *create_fw_cfg(const MachineState *ms, hwaddr base) { FWCfgState *fw_cfg; @@ -939,7 +867,10 @@ static void virt_machine_init(MachineState *machine) qdev_get_gpio_in(virtio_irqchip, VIRTIO_IRQ + i)); } =20 - gpex_pcie_init(system_memory, pcie_irqchip, s); + gpex_pcie_init(system_memory, pcie_irqchip, + &s->memmap[VIRT_PCIE_ECAM], &s->memmap[VIRT_PCIE_MMIO], + &virt_high_pcie_memmap, &s->memmap[VIRT_PCIE_PIO], + PCIE_IRQ); =20 s->platform_bus_dev =3D create_platform_bus(mmio_irqchip, &s->memmap[VIRT_PLATFORM_BUS= ], diff --git a/include/hw/riscv/device-common.h b/include/hw/riscv/device-com= mon.h index 1cdb8ab5cc..77760e082c 100644 --- a/include/hw/riscv/device-common.h +++ b/include/hw/riscv/device-common.h @@ -22,4 +22,11 @@ PFlashCFI01 *riscv_flash_create(Object *parent, const ch= ar *name, int flash_sector_size); void riscv_init_flash_map(PFlashCFI01 *flash, hwaddr base, hwaddr size, MemoryRegion *sysmem, int flash_sector_size); +DeviceState *gpex_pcie_init(MemoryRegion *sys_mem, + DeviceState *irqchip, + const MemMapEntry *pcie_ecam_mem, + const MemMapEntry *pcie_mmio_mem, + const MemMapEntry *high_pcie_mmio_mem, + const MemMapEntry *pcie_pio_mem, + int pcie_irq); #endif --=20 2.43.0 From nobody Sat Sep 26 23:03:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1787693136; cv=none; d=zohomail.com; s=zohoarc; b=XaMTlGuLhFNr1QYlt2DWvOt8CKIrJ9/JZF5IzlRvz5xZLES8yzlc+4FtiEf08hSQJIijYYy0zaURrkWJpDYBqk+VL4EXcuHy37FNQ06OXxirts05usnB8cJgu5xtlneb0kF9CFuMLxTC6pf7bh07gFrTUAdSc24kz6v1WK61wHg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787693136; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wnP82xrulJPH4SceLT/7zH5771Vh+GqItvqzst16sMY=; b=TKMiFUujKvszbc5OzX86hfzvc9aOe+ZYd3NLxYYmU9UWzFFpAuhWP4AmT/tNwsymO8CjwdZN9w670tXPgcsRyVe8S0TfguInWph6TwneJkFQaYtuPWJXVr1Ad4fVWi4a+zLozpY6hrzJy2RZK+RhNvLM+iXFY0WTgvgrzGx2qDc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787693136028780.7544813557145; Tue, 25 Aug 2026 14:25:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyydD-0003rS-Co; Tue, 25 Aug 2026 17:24:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyydC-0003qe-5j for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:30 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyydA-0002NB-C6 for qemu-devel@nongnu.org; Tue, 25 Aug 2026 17:24:29 -0400 Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67PL9hlk2498710 for ; Tue, 25 Aug 2026 21:24:17 GMT Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g9fjn0tfm-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 25 Aug 2026 21:24:16 +0000 (GMT) Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-904c1d588bbso3530776d6.0 for ; Tue, 25 Aug 2026 14:24:16 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([189.38.141.232]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90cc65299f0sm8646386d6.41.2026.08.25.14.24.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 14:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=wnP82xrulJP H4SceLT/7zH5771Vh+GqItvqzst16sMY=; b=mLhbNWe0iaycBC/T81KbYxudJ8m yijxpR3m9SIjmk8qoCCxJdDzd27Kbq8Z5UZhOh8gr7UpXCs69Hz61jpWZwVpVOld WYYYAyToxcUcln9jIaXDb1gSiZOcMQjcruH8fcS4Pc3NH6BsmGCsNgat1j6KV0XM RCBfpPSzbkwfaDsPxVBunK9yNA9XqaYPe75OWfIaSps8YMzOY93awGIMQZn/c8FR rmy35ywatuOSsbLcen6asJOcmXizl1NAYJi33tPQdlHky6xplTDJRcj07785TPXl ksTe1SNUGbwCa7Hu/mv1FOWhrnpvyVYY4+qmdjl4gG0r9rmbn7g2LTPbUhQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787693056; x=1788297856; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=wnP82xrulJPH4SceLT/7zH5771Vh+GqItvqzst16sMY=; b=QPwh5tjN7eja7LYF73wdt4od27dXMQYtZtQZP+00FxtGUYevWLtmt1xYMGCIwgauGp 8hPmF7X69Gu2kwnnPTLAu4HYVg0kYDzqJ0/Zmv5MakOOh0mTHUazHXhUzRrzrdh03YGF aaWyzCBV7X3ZQsxoE4nbuJ8yuqrHuDGmrhoHendDSKRpj9nAWviDuEr7C3Lpj4+T5Ffu z8qurn6fL+8Sgob6jEuf2/kuk+fgSil+zCqG82n8xFD3LE0ej5LomY3StojygYpouiz2 cijieiep3MLA3rm3CKJbcN30pJCzMVM6pKPQfKfJc/rKrw55k8XzygeA3Yc2M8SOhcHj meMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787693056; x=1788297856; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=wnP82xrulJPH4SceLT/7zH5771Vh+GqItvqzst16sMY=; b=F21pQilFXoDWZhNc8MyYgvEzbHP1f1pEgWA6rEWusIg2W3PHzSTIw6ML1nVQyYOfw8 9Npb8e1de73X5KJiwqryqX4Fqvg0gaAC1JgVfIW51CMubZAqbQgxtc4NwYJNPEVeMdxO lEgV0LehYraj1QPVYvoiXWc1dOe+SRaQ/5ZgMyvFKpx78UHo450OMzbgD2N75urfJasK TeoeXbyYhY4OgiX+IHUqq5e6Uup81nbzJJ1KTPxGH4Wa2AOhTaIS9tm8wFMU4nSw9kbu yVVt2muIyuUyShS6XOHjwe6kPPcp+lcnaAOBjxPygS20xVmgoiLdPmnaCeYYLgkO9sxj VIxg== X-Gm-Message-State: AFuF++lic1gNwY3yoYt/osmDhKRCcgnrNr6tC6mU8ogls/RisIvPB/vc DMLxjaLUlA3GKKZdgtp/7JmS0j1lcXEZzvpyuqOfJVwgdrGR65Z6IBnQPJH34g5y62KAqV8fTC4 WIbC8QlBo5PCYHvCP0eiDjGsOLGIXtGVNeKp/gcjXld37ZhEONt3D4jV7D0Smv2MDlw== X-Gm-Gg: AR+sD132kin1k7pfIA+m3EaoCF7KYe4EABcdXYcLkUn1wpGodeU5Hpjefesh6DttZTa qRusdBE3Tgr7voa4ZkesZUlr9RJ2LxJs6ffcJAMYnebETfNYsrEq1pQgyLdUtwha5bG5GxBIz8u wOQJYdRuGXAo4dI982xDFrQrtoeN09URXuBLvueMeUXNbO7gHRiOfBShPcCxcEXYTXgyjk+4S2G 9PB8vopEgS9/zD2b6p0Q+8b+QCgHDx7Y6AeDQJvb4jB0LQoyppTsT9JdrEeM70es6VmgHL77ut+ gOzbztsU6WTzh8kDeyx6yUFow6ZbP5aYXfW8p9V1qGI1/A5kyCJheRgsvpkXUmcpPdRbG4Mfsmc TouVfDiAVfnr9gKFaWfWVe4H4CICWIoTtKxeIVw== X-Received: by 2002:a05:6214:4890:b0:907:be64:6b76 with SMTP id 6a1803df08f44-90cc6aafa7cmr27569966d6.12.1787693055851; Tue, 25 Aug 2026 14:24:15 -0700 (PDT) X-Received: by 2002:a05:6214:4890:b0:907:be64:6b76 with SMTP id 6a1803df08f44-90cc6aafa7cmr27569406d6.12.1787693055400; Tue, 25 Aug 2026 14:24:15 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com, Daniel Henrique Barboza , Palmer Dabbelt Subject: [PATCH 13/13] hw/riscv/riscv-iommu-sys.c, virt.c: add create_riscv_iommu_sys() Date: Tue, 25 Aug 2026 18:23:25 -0300 Message-ID: <20260825212326.1907-14-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> References: <20260825212326.1907-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: t7_bZQbhSQKBTB3zOnw0T8bYcjWbBdEQ X-Proofpoint-Spam-Info: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX+yDDE93+jnMz RYAnH8flplZSQsacjrs/AYrrwwtiUmV71EXI7qUgRZD0GDeo6zGgPV2rEosEVE6hjzFFd78VzCo AKkPWD8wdtFi4c/zYV/3NehLUztpEP0= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI1MDE4MiBTYWx0ZWRfX9JhI27HzNjwB Bv5r6FlY+PtGKoBIaxD8YL88nLKtda3RViFs1gMy0IMa2s4tAms+o1ptFlkhEKZOYK6P3AoPbWl xVqAJGcYewiT4sg5BHhS9Yoej0NWKyU5MldosMleyUhZJ5OZm2udTiEYKk7MBas3PQsMMrSZESc dqwxc+p2Wdhtt3EapdjUzfr3htywubBxtjtqd9MI+9gKP7olSTKCe3zoYEukevHfOOzjZKUownX 7DTSyEiZBu9Z7kXHGrvyMOy20v5K2iHy6C28M9Hft+AvNtCMx7spDdYEZSBsoYW25uRnRS8h4PJ 66+G8kDKXv4M/tH/1JpvXeBguGu1SwzMQuztdCUe+tPwEhmdgVKinHTKOmx3xDCcE9n+cLM+kLb if00xWpG6b8b8PtB6wOZ4v7CkSheUNn2Q06dlD7SzVZzcc5idRJCQksaPFuEwumxf8ndZpUkrX6 YKBv52/TJKZbBBKodBg== X-Authority-Analysis: v=2.4 cv=ccziaHDM c=1 sm=1 tr=0 ts=6a8e0800 cx=c_pps a=7E5Bxpl4vBhpaufnMqZlrw==:117 a=MCIxunHWmQOg/5OnbzXZaw==:17 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=EUspDBNiAAAA:8 a=7ypw5r5HuOgaF4lO-pgA:9 a=pJ04lnu7RYOZP9TFuWaZ:22 X-Proofpoint-ORIG-GUID: t7_bZQbhSQKBTB3zOnw0T8bYcjWbBdEQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-25_06,2026-08-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 clxscore=1015 malwarescore=0 bulkscore=0 adultscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608250182 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1787693137671158500 Content-Type: text/plain; charset="utf-8" Move the creation of riscv-iommu-sys to its own file instead of open coding it in the 'virt' board. Other boards in the future might want to use this device and we want to avoid code duplication. Signed-off-by: Daniel Henrique Barboza --- hw/riscv/riscv-iommu-sys.c | 25 +++++++++++++++++++++++++ hw/riscv/riscv-iommu.h | 3 +++ hw/riscv/virt.c | 23 +++-------------------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/hw/riscv/riscv-iommu-sys.c b/hw/riscv/riscv-iommu-sys.c index 3314adeed2..258c171efd 100644 --- a/hw/riscv/riscv-iommu-sys.c +++ b/hw/riscv/riscv-iommu-sys.c @@ -217,6 +217,31 @@ static void riscv_iommu_sys_init(Object *obj) riscv_iommu_set_cap_igs(iommu, RISCV_IOMMU_CAP_IGS_BOTH); } =20 +DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip, + hwaddr addr, int base_irq, + bool is_32_bit) +{ + DeviceState *iommu_sys =3D qdev_new(TYPE_RISCV_IOMMU_SYS); + + object_property_set_uint(OBJECT(iommu_sys), "addr", addr, &error_fatal= ); + object_property_set_uint(OBJECT(iommu_sys), "base-irq", + base_irq, &error_fatal); + object_property_set_link(OBJECT(iommu_sys), "irqchip", + OBJECT(mmio_irqchip), + &error_fatal); + /* + * For riscv64 use a physical address size of 56 bits (44 bit PPN), + * and for riscv32 use 34 bits (22 bit PPN). + */ + object_property_set_uint(OBJECT(iommu_sys), "pas-bits", + is_32_bit ? 34 : 56, + &error_fatal); + + sysbus_realize_and_unref(SYS_BUS_DEVICE(iommu_sys), &error_fatal); + + return iommu_sys; +} + static const Property riscv_iommu_sys_properties[] =3D { DEFINE_PROP_UINT64("addr", RISCVIOMMUStateSys, addr, 0), DEFINE_PROP_UINT32("base-irq", RISCVIOMMUStateSys, base_irq, 0), diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h index da70e8bfa8..7c470ba084 100644 --- a/hw/riscv/riscv-iommu.h +++ b/hw/riscv/riscv-iommu.h @@ -104,6 +104,9 @@ void riscv_iommu_set_cap_igs(RISCVIOMMUState *s, riscv_= iommu_igs_mode mode); void riscv_iommu_reset(RISCVIOMMUState *s); void riscv_iommu_notify(RISCVIOMMUState *s, int vec_type); void riscv_iommu_fault(RISCVIOMMUState *s, struct riscv_iommu_fq_record *e= v); +DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip, + hwaddr addr, int base_irq, + bool is_32_bit); =20 typedef struct RISCVIOMMUContext RISCVIOMMUContext; /* Device translation context state. */ diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index af9de36726..9b63e4af60 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -32,6 +32,7 @@ #include "hw/core/sysbus-fdt.h" #include "hw/riscv/riscv_hart.h" #include "hw/riscv/iommu.h" +#include "hw/riscv/riscv-iommu.h" #include "hw/riscv/riscv-iommu-bits.h" #include "hw/riscv/virt.h" #include "hw/riscv/boot.h" @@ -910,26 +911,8 @@ static void virt_machine_init(MachineState *machine) } =20 if (virt_is_iommu_sys_enabled(s)) { - DeviceState *iommu_sys =3D qdev_new(TYPE_RISCV_IOMMU_SYS); - - object_property_set_uint(OBJECT(iommu_sys), "addr", - s->memmap[VIRT_IOMMU_SYS].base, - &error_fatal); - object_property_set_uint(OBJECT(iommu_sys), "base-irq", - IOMMU_SYS_IRQ, - &error_fatal); - object_property_set_link(OBJECT(iommu_sys), "irqchip", - OBJECT(mmio_irqchip), - &error_fatal); - /* - * For riscv64 use a physical address size of 56 bits (44 bit PPN), - * and for riscv32 use 34 bits (22 bit PPN). - */ - object_property_set_uint(OBJECT(iommu_sys), "pas-bits", - riscv_is_32bit(&s->soc[0]) ? 34 : 56, - &error_fatal); - - sysbus_realize_and_unref(SYS_BUS_DEVICE(iommu_sys), &error_fatal); + riscv_create_iommu_sys(mmio_irqchip, s->memmap[VIRT_IOMMU_SYS].bas= e, + IOMMU_SYS_IRQ, riscv_is_32bit(&s->soc[0])); } =20 s->machine_done.notify =3D virt_machine_done; --=20 2.43.0