From nobody Sat Nov 15 11:35:46 2025 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; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1752659983; cv=pass; d=zohomail.com; s=zohoarc; b=WDFpFNK3hHjI6tFvmpa+HOwmT3/e1I3EI90RbxOfP4DxbP/0DCID3T2rHb0NeM9GW2VJ1APKT7Oi1mzSAdHGmHfJrPtiaUYl1TMtUwf8OQTLot7iX/+g0cVIl5F4eFL9fuSUdfAa5d9dJ8G1CluhkICE8gVIH1pGIfeUkJbuPC4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752659983; h=Content-Type: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=fXb4XEZ7ymCrklIeQzxnqvN4HHrUMSi65cm/gYKpgz8=; b=L4OcWEUZ3aa0eb/SuG6n/ItBwae5BKAFHXbM/+72I3XBxZuSH0sQ/SMgQTt53M3fZGUBd1pjAcelLMcaLLVYmaHB/dsg+OT+HOBwo+CgIaJMFFpNXOW8pD4aL92qTxK3KmXfCDpBbhBpikd3P9niMijpgUBaA4MiqZGqHq6GtF8= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752659983418319.12370555093025; Wed, 16 Jul 2025 02:59:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubysp-0003pm-1P; Wed, 16 Jul 2025 05:57:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubyrT-0001JE-4F; Wed, 16 Jul 2025 05:55:41 -0400 Received: from mail-bn1nam02on20603.outbound.protection.outlook.com ([2a01:111:f403:2407::603] helo=NAM02-BN1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubyrO-0006aC-B5; Wed, 16 Jul 2025 05:55:38 -0400 Received: from BYAPR05CA0038.namprd05.prod.outlook.com (2603:10b6:a03:74::15) by LV3PR12MB9168.namprd12.prod.outlook.com (2603:10b6:408:19a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.29; Wed, 16 Jul 2025 09:55:27 +0000 Received: from SJ5PEPF00000207.namprd05.prod.outlook.com (2603:10b6:a03:74:cafe::49) by BYAPR05CA0038.outlook.office365.com (2603:10b6:a03:74::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8943.17 via Frontend Transport; Wed, 16 Jul 2025 09:55:27 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SJ5PEPF00000207.mail.protection.outlook.com (10.167.244.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8943.21 via Frontend Transport; Wed, 16 Jul 2025 09:55:26 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 16 Jul 2025 04:55:11 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 16 Jul 2025 04:55:11 -0500 Received: from XFR-LUMICHEL-L2.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 16 Jul 2025 04:55:09 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bpmWj7PsHLA8fuwRk0dZUythlRlK4Gbn7RsMPhZ1dAkB6+JoVxJQ6a+sWo3M72nMX0wYxuUX4RlHZzbtf3h2q3qsL2EH9Y5849rwncGP49udcVOKAY3aaILJajQgOkqfHXnO2+gIv+g+SwTnXk+P52PAOd34nstPsW7UP6gB9Xro2Ig97101aO8LuNwCCIiayuL4snOIX684Knl4QkBxgzE/OqpHRoC3LS5S7dd+WBibdnbrnZrZYCG0u5f1A4sukR4tcmIZdMhKPGi3aCyDK7MM113vBmNhgvxPBdcj/RWh9kHLa5zGGos5FbJnh8deIq1M0bHLVpm0gmFqTl0X2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fXb4XEZ7ymCrklIeQzxnqvN4HHrUMSi65cm/gYKpgz8=; b=pNgpNpSGNgN+9P1aE3zFWurXnYNJCIBH66txzCbczWQ8tqlfv3ke2rdbpsDiK5N+bqQVSp5fA4rfxMD8NgoK7la06CJNJFIUYu2mqqV30AVhVjeoyFud2t675SvDnZh9kvg2oBEiaUeqZBfp4l9y/SEv+Tw+VWUR3lVc8tPPBnTAwYMEE25WjKK/FgYg/2gxOr8WIpIGV5BzAqPWBTNgsmZWKMWJLqmZ1LlGH8bdwLsjbnBryidaWjldapz2dxiq62wRn+r86WTs1IOSR3LrpRNglU5SuDZKQ+OOG4mtF07KStLWpyU1uHcRZcNNL5sYOVfl/XRo+DMazY8wAxnbZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nongnu.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fXb4XEZ7ymCrklIeQzxnqvN4HHrUMSi65cm/gYKpgz8=; b=dcMVCQsIM1I19gqgCA1iiaMPSTBRZNe7hoEaD7rxt9NBLGaLIzeCKJAi+BCyun7k97Dy1tSn0F0/QOGi8U2EObpsHM4QuuXvS4VvdwJmEN7t5ofkpRpk8UG1o7tly1qhp1zyNGJfYUjaZAf3BbDDDgbUw+n8ZxeZ6fYxys2TWAw= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; 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=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Luc Michel To: , CC: Luc Michel , Peter Maydell , Francisco Iglesias , "Edgar E . Iglesias" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alistair Francis , "Frederic Konrad" , Sai Pavan Boddu Subject: [PATCH 07/48] hw/arm/xlnx-versal: gem: refactor creation Date: Wed, 16 Jul 2025 11:53:49 +0200 Message-ID: <20250716095432.81923-8-luc.michel@amd.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250716095432.81923-1-luc.michel@amd.com> References: <20250716095432.81923-1-luc.michel@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF00000207:EE_|LV3PR12MB9168:EE_ X-MS-Office365-Filtering-Correlation-Id: 365404e3-32d0-495d-5912-08ddc44ee40f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?TUBDy/o36TVHpGTNEof5+Wgy453VS4CGhEw0HKldjLGUfwN34nviVXQRdgBG?= =?us-ascii?Q?aKI/ht4lGhL3RSAfFQnVsJBiAjguS3i5INIBZfgCGRWyFgVfLNtzApbyQ1aZ?= =?us-ascii?Q?myDoQaXfqoPmSx8EUvE7kje7eqhnUaI0bEHIwWnTQt6SNzbbA7W7gT7Mx+IO?= =?us-ascii?Q?0SLmQ8s+BZxe8jMnlX8t1zrAUIbvRwHZ9Yxd/aLXCNfkY09T0okaRAGTVjZb?= =?us-ascii?Q?BfsH3wzW31hCS78BeW/ky8Jq9ZyexiGnv6UBNTGAsHAnhISIipTlJvk3efe5?= =?us-ascii?Q?LqtSX4FdLZiGxwsvUnmbLRSARWRYT1fdHSWMp4rP1OlqDrHhFmX5m8IQOxLi?= =?us-ascii?Q?/x9w+qgF4PqYhIC9tcp6X6QXOJMRaE4fhq6WB2XsaFosxdFg7iHttwht3tqR?= =?us-ascii?Q?FQndNQXx0uAwIPtv/1x8B6iKuaBKeDfjclh9yym/Nz46lionId/ypkeVQDX+?= =?us-ascii?Q?S4iXGTVIz35X2nI97sstGIu9CxQUCdQuom1Woof0INWoNEugIH8jdmVHl8yA?= =?us-ascii?Q?cvT533oDtnPpqe0kNM0AwR89iRwOOIpZJx9wzzbPzdztAN6agVFDdBvVPCMu?= =?us-ascii?Q?z3/hnZNkZzeqep4+7KlEmk7Bu0SUwSjKC8INP6LSgDRt57Iek2J11LsGUf0G?= =?us-ascii?Q?nqn7uc7kPcLj2aKnyRIgg3REK/6kx+rE8/g2TN69lCngWf8HhAgwtJsrwbN5?= =?us-ascii?Q?Xsj07efBccd4Lmnu56x5yo57KviyTHK7mK2TZFleuH+fa7MkH54FrjJWcWKO?= =?us-ascii?Q?wIHzUarUKq0PCMAZJBemwXmjkAXWphOc4SNu0odEAMLUq+Wgf9VnvHq1Khuf?= =?us-ascii?Q?LCXlyUk4nkrvhxcMHK059R++eNs5TxthrSxtNjwdEHIDbfoNA1oaBqGS4sUt?= =?us-ascii?Q?o4ZKvZuFSGWt6nBKNgGp5D79xCoosZVFiIZeW3/PRcNAUJZQUeRU1ZtuleKI?= =?us-ascii?Q?FVDLBNUgFh42M8GpXjOCzbPLy1zhkHymzCxGSbjVdaxPmOmXC7W4wn+YeFI6?= =?us-ascii?Q?qJO8wZYQhWfVboa28vAmd9pRlZ9MEr8q8OS/J37OyEuuv6fSxKrhe2OcfS9v?= =?us-ascii?Q?nLna8WcOgCNDXncPqnuBLGm76ByhLpz1cQfqQzLPuzLBwKwk492d8Cnwc05P?= =?us-ascii?Q?T08v84/162hZDy1/VgOTqVFBh4QqWlFLxPIA01NEmBX5E0J61VTYVjBhVR/A?= =?us-ascii?Q?XVXuHu+pvWsaVn5cG2F2sw51dRik8qc8lcHBUeH+ZeaArSrF37yaHvdvMQlL?= =?us-ascii?Q?vhfGMOB1hzReICXiE1xcw2kprtZAIOFkKTKtH8F5AaCEZ5jztTNoXSRcTLOz?= =?us-ascii?Q?oWxG2XxLO+4Ef629pWGZw0QShz0eVrkf0ehwZ5LWRKKXSxhsBAfyW0umu8T3?= =?us-ascii?Q?dvfj9ZzuLdCiJl4Xn4HR41lqpKIZI62YltsCG7f0D9MpF1ttcuB/jZHYjcOL?= =?us-ascii?Q?PqOnkLPVuikWU4RfgkdJIXOyTq4aUira1JgH+HX7ZkZjLJa8h2rFt7VyJmfr?= =?us-ascii?Q?UsukVVkduHorFDCmwPbNu1jdDt4+3fyw40TZ?= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB03.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(376014)(36860700013)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2025 09:55:26.7830 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 365404e3-32d0-495d-5912-08ddc44ee40f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ5PEPF00000207.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9168 Received-SPF: permerror client-ip=2a01:111:f403:2407::603; envelope-from=Luc.Michel@amd.com; helo=NAM02-BN1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1752659985310116600 Content-Type: text/plain; charset="utf-8" Refactor the GEM ethernet controllers creation using the VersalMap structure. Note that the connection to the CRL is removed for now and will be re-added by next commits. Signed-off-by: Luc Michel Reviewed-by: Francisco Iglesias --- include/hw/arm/xlnx-versal.h | 3 - hw/arm/xlnx-versal-virt.c | 54 ------------- hw/arm/xlnx-versal.c | 151 +++++++++++++++++++++++++---------- 3 files changed, 108 insertions(+), 100 deletions(-) diff --git a/include/hw/arm/xlnx-versal.h b/include/hw/arm/xlnx-versal.h index 4a7a2d85aac..1fcc2b623da 100644 --- a/include/hw/arm/xlnx-versal.h +++ b/include/hw/arm/xlnx-versal.h @@ -16,11 +16,10 @@ #include "hw/sysbus.h" #include "hw/cpu/cluster.h" #include "hw/or-irq.h" #include "hw/intc/arm_gicv3.h" #include "hw/dma/xlnx-zdma.h" -#include "hw/net/cadence_gem.h" #include "hw/rtc/xlnx-zynqmp-rtc.h" #include "qom/object.h" #include "hw/usb/xlnx-usb-subsystem.h" #include "hw/misc/xlnx-versal-xramc.h" #include "hw/nvram/xlnx-bbram.h" @@ -76,12 +75,10 @@ struct Versal { =20 struct { MemoryRegion mr_ocm; =20 struct { - CadenceGEMState gem[XLNX_VERSAL_NR_GEMS]; - OrIRQState gem_irq_orgate[XLNX_VERSAL_NR_GEMS]; XlnxZDMA adma[XLNX_VERSAL_NR_ADMAS]; VersalUsb2 usb; } iou; =20 /* Real-time Processing Unit. */ diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c index 99ce84d5a46..09f87dc76dd 100644 --- a/hw/arm/xlnx-versal-virt.c +++ b/hw/arm/xlnx-versal-virt.c @@ -36,11 +36,10 @@ struct VersalVirt { =20 void *fdt; int fdt_size; struct { uint32_t gic; - uint32_t ethernet_phy[2]; uint32_t clk_125Mhz; uint32_t clk_25Mhz; uint32_t usb; uint32_t dwc; } phandle; @@ -55,23 +54,19 @@ struct VersalVirt { }; =20 static void fdt_create(VersalVirt *s) { MachineClass *mc =3D MACHINE_GET_CLASS(s); - int i; =20 s->fdt =3D create_device_tree(&s->fdt_size); if (!s->fdt) { error_report("create_device_tree() failed"); exit(1); } =20 /* Allocate all phandles. */ s->phandle.gic =3D qemu_fdt_alloc_phandle(s->fdt); - for (i =3D 0; i < ARRAY_SIZE(s->phandle.ethernet_phy); i++) { - s->phandle.ethernet_phy[i] =3D qemu_fdt_alloc_phandle(s->fdt); - } s->phandle.clk_25Mhz =3D qemu_fdt_alloc_phandle(s->fdt); s->phandle.clk_125Mhz =3D qemu_fdt_alloc_phandle(s->fdt); =20 s->phandle.usb =3D qemu_fdt_alloc_phandle(s->fdt); s->phandle.dwc =3D qemu_fdt_alloc_phandle(s->fdt); @@ -207,58 +202,10 @@ static void fdt_add_usb_xhci_nodes(VersalVirt *s) qemu_fdt_setprop_cell(s->fdt, name, "phandle", s->phandle.dwc); qemu_fdt_setprop_string(s->fdt, name, "maximum-speed", "high-speed"); g_free(name); } =20 -static void fdt_add_fixed_link_nodes(VersalVirt *s, char *gemname, - uint32_t phandle) -{ - char *name =3D g_strdup_printf("%s/fixed-link", gemname); - - qemu_fdt_add_subnode(s->fdt, name); - qemu_fdt_setprop_cell(s->fdt, name, "phandle", phandle); - qemu_fdt_setprop(s->fdt, name, "full-duplex", NULL, 0); - qemu_fdt_setprop_cell(s->fdt, name, "speed", 1000); - g_free(name); -} - -static void fdt_add_gem_nodes(VersalVirt *s) -{ - uint64_t addrs[] =3D { MM_GEM1, MM_GEM0 }; - unsigned int irqs[] =3D { VERSAL_GEM1_IRQ_0, VERSAL_GEM0_IRQ_0 }; - const char clocknames[] =3D "pclk\0hclk\0tx_clk\0rx_clk"; - const char compat_gem[] =3D "cdns,zynqmp-gem\0cdns,gem"; - int i; - - for (i =3D 0; i < ARRAY_SIZE(addrs); i++) { - char *name =3D g_strdup_printf("/ethernet@%" PRIx64, addrs[i]); - qemu_fdt_add_subnode(s->fdt, name); - - fdt_add_fixed_link_nodes(s, name, s->phandle.ethernet_phy[i]); - qemu_fdt_setprop_string(s->fdt, name, "phy-mode", "rgmii-id"); - qemu_fdt_setprop_cell(s->fdt, name, "phy-handle", - s->phandle.ethernet_phy[i]); - qemu_fdt_setprop_cells(s->fdt, name, "clocks", - s->phandle.clk_25Mhz, s->phandle.clk_25Mhz, - s->phandle.clk_125Mhz, s->phandle.clk_125Mh= z); - qemu_fdt_setprop(s->fdt, name, "clock-names", - clocknames, sizeof(clocknames)); - qemu_fdt_setprop_cells(s->fdt, name, "interrupts", - GIC_FDT_IRQ_TYPE_SPI, irqs[i], - GIC_FDT_IRQ_FLAGS_LEVEL_HI, - GIC_FDT_IRQ_TYPE_SPI, irqs[i], - GIC_FDT_IRQ_FLAGS_LEVEL_HI); - qemu_fdt_setprop_sized_cells(s->fdt, name, "reg", - 2, addrs[i], 2, 0x1000); - qemu_fdt_setprop(s->fdt, name, "compatible", - compat_gem, sizeof(compat_gem)); - qemu_fdt_setprop_cell(s->fdt, name, "#address-cells", 1); - qemu_fdt_setprop_cell(s->fdt, name, "#size-cells", 0); - g_free(name); - } -} - static void fdt_add_zdma_nodes(VersalVirt *s) { const char clocknames[] =3D "clk_main\0clk_apb"; const char compat[] =3D "xlnx,zynqmp-dma-1.0"; int i; @@ -607,11 +554,10 @@ static void versal_virt_init(MachineState *machine) &error_abort); } =20 fdt_create(s); versal_set_fdt(&s->soc, s->fdt); - fdt_add_gem_nodes(s); fdt_add_gic_nodes(s); fdt_add_timer_nodes(s); fdt_add_zdma_nodes(s); fdt_add_usb_xhci_nodes(s); fdt_add_rtc_node(s); diff --git a/hw/arm/xlnx-versal.c b/hw/arm/xlnx-versal.c index b963a05935b..062f9a91a6c 100644 --- a/hw/arm/xlnx-versal.c +++ b/hw/arm/xlnx-versal.c @@ -27,10 +27,11 @@ #include "system/device_tree.h" #include "hw/arm/fdt.h" #include "hw/char/pl011.h" #include "hw/net/xlnx-versal-canfd.h" #include "hw/sd/sdhci.h" +#include "hw/net/cadence_gem.h" =20 #define XLNX_VERSAL_ACPU_TYPE ARM_CPU_TYPE_NAME("cortex-a72") #define XLNX_VERSAL_RCPU_TYPE ARM_CPU_TYPE_NAME("cortex-r5f") #define GEM_REVISION 0x40070106 =20 @@ -49,10 +50,18 @@ typedef struct VersalMap { VersalSimplePeriphMap canfd[4]; size_t num_canfd; =20 VersalSimplePeriphMap sdhci[2]; size_t num_sdhci; + + struct VersalGemMap { + VersalSimplePeriphMap map; + size_t num_prio_queue; + const char *phy_mode; + const uint32_t speed; + } gem[3]; + size_t num_gem; } VersalMap; =20 static const VersalMap VERSAL_MAP =3D { .uart[0] =3D { 0xff000000, 18 }, .uart[1] =3D { 0xff010000, 19 }, @@ -63,10 +72,14 @@ static const VersalMap VERSAL_MAP =3D { .num_canfd =3D 2, =20 .sdhci[0] =3D { 0xf1040000, 126 }, .sdhci[1] =3D { 0xf1050000, 128 }, .num_sdhci =3D 2, + + .gem[0] =3D { { 0xff0c0000, 56 }, 2, "rgmii-id", 1000 }, + .gem[1] =3D { { 0xff0d0000, 58 }, 2, "rgmii-id", 1000 }, + .num_gem =3D 2, }; =20 static const VersalMap *VERSION_TO_MAP[] =3D { [VERSAL_VER_VERSAL] =3D &VERSAL_MAP, }; @@ -109,10 +122,22 @@ static void versal_sysbus_connect_irq(Versal *s, SysB= usDevice *sbd, } =20 sysbus_connect_irq(sbd, sbd_idx, irq); } =20 +static void versal_qdev_connect_gpio_out(Versal *s, DeviceState *dev, + int dev_idx, int irq_idx) +{ + qemu_irq irq =3D versal_get_irq(s, irq_idx); + + if (irq =3D=3D NULL) { + return; + } + + qdev_connect_gpio_out(dev, dev_idx, irq); +} + static inline char *versal_fdt_add_subnode(Versal *s, const char *path, uint64_t at, const char *compat, size_t compat_sz) { char *p; @@ -138,10 +163,25 @@ static inline char *versal_fdt_add_simple_subnode(Ver= sal *s, const char *path, =20 qemu_fdt_setprop_sized_cells(s->cfg.fdt, p, "reg", 2, addr, 2, len); return p; } =20 +static inline DeviceState *create_or_gate(Versal *s, Object *parent, + const char *name, uint16_t num_l= ines, + int irq_idx) +{ + DeviceState *or; + + or =3D qdev_new(TYPE_OR_IRQ); + qdev_prop_set_uint16(or, "num-lines", num_lines); + object_property_add_child(parent, name, OBJECT(or)); + qdev_realize_and_unref(or, NULL, &error_abort); + versal_qdev_connect_gpio_out(s, or, 0, irq_idx); + + return or; +} + static void versal_create_apu_cpus(Versal *s) { int i; =20 object_initialize_child(OBJECT(s), "apu-cluster", &s->fpd.apu.cluster, @@ -375,50 +415,80 @@ static void versal_create_usbs(Versal *s, qemu_irq *p= ic) =20 mr =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1); memory_region_add_subregion(&s->mr_ps, MM_USB2_CTRL_REGS, mr); } =20 -static void versal_create_gems(Versal *s, qemu_irq *pic) +static void versal_create_gem(Versal *s, + const struct VersalGemMap *map) { + DeviceState *dev; + MemoryRegion *mr; + DeviceState *or; int i; + g_autofree char *node; + g_autofree char *phy_node; + int phy_phandle; + const char compatible[] =3D "cdns,zynqmp-gem\0cdns,gem"; + const char clocknames[] =3D "pclk\0hclk\0tx_clk\0rx_clk"; + g_autofree uint32_t *irq_prop; =20 - for (i =3D 0; i < ARRAY_SIZE(s->lpd.iou.gem); i++) { - static const int irqs[] =3D { VERSAL_GEM0_IRQ_0, VERSAL_GEM1_IRQ_0= }; - static const uint64_t addrs[] =3D { MM_GEM0, MM_GEM1 }; - char *name =3D g_strdup_printf("gem%d", i); - DeviceState *dev; - MemoryRegion *mr; - OrIRQState *or_irq; - - object_initialize_child(OBJECT(s), name, &s->lpd.iou.gem[i], - TYPE_CADENCE_GEM); - or_irq =3D &s->lpd.iou.gem_irq_orgate[i]; - object_initialize_child(OBJECT(s), "gem-irq-orgate[*]", - or_irq, TYPE_OR_IRQ); - dev =3D DEVICE(&s->lpd.iou.gem[i]); - qemu_configure_nic_device(dev, true, NULL); - object_property_set_int(OBJECT(dev), "phy-addr", 23, &error_abort); - object_property_set_int(OBJECT(dev), "num-priority-queues", 2, - &error_abort); - object_property_set_int(OBJECT(or_irq), - "num-lines", 2, &error_fatal); - qdev_realize(DEVICE(or_irq), NULL, &error_fatal); - qdev_connect_gpio_out(DEVICE(or_irq), 0, pic[irqs[i]]); - - object_property_set_link(OBJECT(dev), "dma", OBJECT(&s->mr_ps), - &error_abort); - sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal); - - mr =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); - memory_region_add_subregion(&s->mr_ps, addrs[i], mr); - - sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, qdev_get_gpio_in(DEVICE= (or_irq), 0)); - sysbus_connect_irq(SYS_BUS_DEVICE(dev), 1, qdev_get_gpio_in(DEVICE= (or_irq), 1)); - g_free(name); + dev =3D qdev_new(TYPE_CADENCE_GEM); + object_property_add_child(OBJECT(s), "gem[*]", OBJECT(dev)); + + qemu_configure_nic_device(dev, true, NULL); + object_property_set_int(OBJECT(dev), "phy-addr", 23, &error_abort); + object_property_set_int(OBJECT(dev), "num-priority-queues", + map->num_prio_queue, &error_abort); + + object_property_set_link(OBJECT(dev), "dma", OBJECT(&s->mr_ps), + &error_abort); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + + mr =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); + memory_region_add_subregion(&s->mr_ps, map->map.addr, mr); + + /* + * The GEM controller exposes one IRQ line per priority queue. In Vers= al + * family devices, those are OR'ed together. + */ + or =3D create_or_gate(s, OBJECT(dev), "irq-orgate", + map->num_prio_queue, map->map.irq); + + for (i =3D 0; i < map->num_prio_queue; i++) { + sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, qdev_get_gpio_in(or, i)= ); + } + + node =3D versal_fdt_add_simple_subnode(s, "/ethernet", map->map.addr, = 0x1000, + compatible, sizeof(compatible)); + phy_node =3D g_strdup_printf("%s/fixed-link", node); + phy_phandle =3D qemu_fdt_alloc_phandle(s->cfg.fdt); + + /* Fixed link PHY node */ + qemu_fdt_add_subnode(s->cfg.fdt, phy_node); + qemu_fdt_setprop_cell(s->cfg.fdt, phy_node, "phandle", phy_phandle); + qemu_fdt_setprop(s->cfg.fdt, phy_node, "full-duplex", NULL, 0); + qemu_fdt_setprop_cell(s->cfg.fdt, phy_node, "speed", map->speed); + + qemu_fdt_setprop_string(s->cfg.fdt, node, "phy-mode", map->phy_mode); + qemu_fdt_setprop_cell(s->cfg.fdt, node, "phy-handle", phy_phandle); + qemu_fdt_setprop_cells(s->cfg.fdt, node, "clocks", + s->phandle.clk_25mhz, s->phandle.clk_25mhz, + s->phandle.clk_125mhz, s->phandle.clk_125mhz); + qemu_fdt_setprop(s->cfg.fdt, node, "clock-names", + clocknames, sizeof(clocknames)); + + irq_prop =3D g_new(uint32_t, map->num_prio_queue * 3); + for (i =3D 0; i < map->num_prio_queue; i++) { + irq_prop[3 * i] =3D cpu_to_be32(GIC_FDT_IRQ_TYPE_SPI); + irq_prop[3 * i + 1] =3D cpu_to_be32(map->map.irq); + irq_prop[3 * i + 2] =3D cpu_to_be32(GIC_FDT_IRQ_FLAGS_LEVEL_HI); } + qemu_fdt_setprop(s->cfg.fdt, node, "interrupts", irq_prop, + sizeof(uint32_t) * map->num_prio_queue * 3); } =20 + static void versal_create_admas(Versal *s, qemu_irq *pic) { int i; =20 for (i =3D 0; i < ARRAY_SIZE(s->lpd.iou.adma); i++) { @@ -900,18 +970,10 @@ static void versal_create_crl(Versal *s, qemu_irq *pi= c) object_property_set_link(OBJECT(&s->lpd.crl), name, OBJECT(&s->lpd.rpu.cpu[i]), &error_abort); } =20 - for (i =3D 0; i < ARRAY_SIZE(s->lpd.iou.gem); i++) { - g_autofree gchar *name =3D g_strdup_printf("gem[%d]", i); - - object_property_set_link(OBJECT(&s->lpd.crl), - name, OBJECT(&s->lpd.iou.gem[i]), - &error_abort); - } - for (i =3D 0; i < ARRAY_SIZE(s->lpd.iou.adma); i++) { g_autofree gchar *name =3D g_strdup_printf("adma[%d]", i); =20 object_property_set_link(OBJECT(&s->lpd.crl), name, OBJECT(&s->lpd.iou.adma[i]), @@ -1095,12 +1157,15 @@ static void versal_realize(DeviceState *dev, Error = **errp) =20 for (i =3D 0; i < map->num_sdhci; i++) { versal_create_sdhci(s, &map->sdhci[i]); } =20 + for (i =3D 0; i < map->num_gem; i++) { + versal_create_gem(s, &map->gem[i]); + } + versal_create_usbs(s, pic); - versal_create_gems(s, pic); versal_create_admas(s, pic); versal_create_pmc_apb_irq_orgate(s, pic); versal_create_rtc(s, pic); versal_create_trng(s, pic); versal_create_xrams(s, pic); --=20 2.50.0