From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 33676C531FC for ; Sat, 25 Jul 2026 01:00:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wnQki-0000Wk-SS; Fri, 24 Jul 2026 21:00: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 1wnQTC-0006uX-85 for qemu-arm@nongnu.org; Fri, 24 Jul 2026 20:42:26 -0400 Received: from mail-ua1-x935.google.com ([2607:f8b0:4864:20::935]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wnQT9-0000lp-Ri for qemu-arm@nongnu.org; Fri, 24 Jul 2026 20:42:25 -0400 Received: by mail-ua1-x935.google.com with SMTP id a1e0cc1a2514c-9692373e0b1so254905241.3 for ; Fri, 24 Jul 2026 17:42:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784940143; x=1785544943; 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=4+kYWqcfqUlxkLr4U0JT8RRf1UDUi8bzrR2cXy3DeC0=; b=LdfCzFrr4G7+8Pw/FGJAe2Z7THynleCSLyDAPWZJWTf7pX1sJRihaKaogKpROWMxN5 lBxBqFGY+XQhT/wosaw2FlQp8cXOBboQbVNat87li1rODEh5PYC0DvyBGYh6jYzq2EBm SMa5UPSFfxT31FbweqbZDC/1/siIqa5uOa6HnAufdgPI8tptfPiJoGYvriJVMwG1st8i fjkxbU1sExm40XEf1slGfNTCW264sSgnXPejDB6kNUDg3baC7Qj4GW8E7BYX9APFgyfV ubVTp8mGG8tVmGLFgGg89sCWkOxak8qg8O0MclpUnZJFMbFYTmNT2LJIKRbblpORLI/J a4Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784940143; x=1785544943; 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=4+kYWqcfqUlxkLr4U0JT8RRf1UDUi8bzrR2cXy3DeC0=; b=QS95JLE659r+vgK6Snt2MXb46UjlLMBsPvV7Jda0i3R1zAG/L83OJOdj/88+fR3dHG 9MrZDoqwgmBYtKEnMo/PpI6Q/bazBfL5866q2jShG3Us26ts3zCgT5vjdn39VNAqv09T NyO/065SmA+W9HZMwM7pTiGcRAnghPkB0Us9ZcnmOfYFyO4A7xCV91O3gox5dZ4x1nck qWPAihJdE7Py91gfmIevca+VMUSCx2i5yzBz40ylly/9ZNzqFvAtfWfGdbYeaZYXFNGN Nv29zSLVjjQO0cD6KGXu5YDWbnuvlY94PyZ88BO1hp6cesK8yq23o7CUq7kBrQ36Q29W V5OQ== X-Gm-Message-State: AOJu0Yxwv1ZiSFlQAN0+oFh/K0uinjJ0sciGpPVjlVRH8CUQnHLKQQO/ SXaNBAl9SfX6Vi1iKlDEgzVZcCl5orYLLFahynEPLQdO9/cISE1b2OZ4 X-Gm-Gg: AR+sD13XU4q1QCmY0HMyjiE8Cs6WhxA+7rOXeFZw0SXKHtyF92jPloy9G/b/JS/Vpza l0XXVRKSYLpTyb1nzrnVYI7Z0MrmpSzbiln6PzVrUFHlgEg19qTtTJIXWbyA3AZa3ELQv/DKIjQ 5eUmTol85HQF1WNBkodx9UedTL0qlStYaxy3zeUuDVcSp6PZQ9yZqwhKGdiLUHNg+PJMhotWhqG p5wK5y8VCE0si3nk/eq0OBtCrcFtz8LqUviFk2UDTcO9VllDaRtaOYgtelmoeBvapg1Zr64N7WA JWsyCyWkxZsn6sCLpf3bFXruvS70WI4uzEoQao7376TbwtncsY5Hz9Hs8tvW3aDBin+bdl463rt lG7XdX/uBx6xINtQft/ztQ9B8NkoNU8AErCZYUNSeRUS1vKAoZuP6QXvQiHlIqI5pRqmj51PWsn /tdWcsvHHvIxWjb9hhffp4JCtToZ5uZnMh X-Received: by 2002:a05:6102:1593:b0:73e:5068:824d with SMTP id ada2fe7eead31-7503feb1c74mr625304137.14.1784940142619; Fri, 24 Jul 2026 17:42:22 -0700 (PDT) Received: from localhost.localdomain ([146.71.8.128]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-97774f12690sm930591241.12.2026.07.24.17.42.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 24 Jul 2026 17:42:21 -0700 (PDT) From: Marcelo Manzo To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Jason Wang , Sergey Kambalin , Marcelo Manzo Subject: [PATCH 01/19] hw/arm/bcm2838_pcie: add BCM2838 PCIe Root Complex Date: Fri, 24 Jul 2026 20:42:00 -0400 Message-ID: <20260725004219.66222-2-marcelomanzo@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20260725004219.66222-1-marcelomanzo@gmail.com> References: <20260725004219.66222-1-marcelomanzo@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::935; envelope-from=marcelomanzo@gmail.com; helo=mail-ua1-x935.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 24 Jul 2026 21:00:27 -0400 X-BeenThere: qemu-arm@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-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org Sender: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org Add the PCI-facing "root" part (D0:F0) of the BCM2838 (Raspberry Pi 4B / BCM2711) PCIe Root Complex: a PCIe root port with the vendor's device/vendor IDs and capability offsets, not usable on its own without the host-facing part added in the next patch. Adapted from patch 13/41 of Sergey Kambalin's "Raspberry Pi 4B machine" series (patchwork series 829638, posted to qemu-devel in 2024 but never merged) against current QEMU master; the surrounding PCIe/GENET networking support for raspi4b was left unmerged upstream (base scaffolding aside), so this and the following patches complete and debug that series to get real networking working under raspi4b. Signed-off-by: Marcelo Manzo --- hw/arm/bcm2838_pcie.c | 82 +++++++++++++++++++++++++++++++++++ hw/arm/meson.build | 4 +- include/hw/arm/bcm2838_pcie.h | 53 ++++++++++++++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 hw/arm/bcm2838_pcie.c create mode 100644 include/hw/arm/bcm2838_pcie.h diff --git a/hw/arm/bcm2838_pcie.c b/hw/arm/bcm2838_pcie.c new file mode 100644 index 00000000..96a45c18 --- /dev/null +++ b/hw/arm/bcm2838_pcie.c @@ -0,0 +1,82 @@ +/* + * BCM2838 PCIe Root Complex emulation + * + * Copyright (C) 2022 Ovchinnikov Vitalii + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "hw/core/irq.h" +#include "hw/pci-host/gpex.h" +#include "hw/core/qdev-properties.h" +#include "migration/vmstate.h" +#include "qemu/module.h" +#include "hw/arm/bcm2838_pcie.h" +#include "trace.h" + +/* + * RC root part (D0:F0) + */ + +static void bcm2838_pcie_root_port_reset_hold(Object *obj, ResetType type) +{ + PCIERootPortClass *rpc = PCIE_ROOT_PORT_GET_CLASS(obj); + PCIDevice *dev = PCI_DEVICE(obj); + BCM2838PcieRootState *s = BCM2838_PCIE_ROOT(dev); + + if (rpc->parent_phases.hold) { + rpc->parent_phases.hold(obj, type); + } + + memset(s->regs, 0xFF, sizeof(s->regs)); +} + +static void bcm2838_pcie_root_init(Object *obj) +{ + PCIBridge *br = PCI_BRIDGE(obj); + br->bus_name = "pcie.1"; +} + +static void bcm2838_pcie_root_class_init(ObjectClass *class, const void *data) +{ + DeviceClass *dc = DEVICE_CLASS(class); + PCIDeviceClass *k = PCI_DEVICE_CLASS(class); + ResettableClass *rc = RESETTABLE_CLASS(class); + PCIERootPortClass *rpc = PCIE_ROOT_PORT_CLASS(class); + + dc->desc = "BCM2711 PCIe Bridge"; + /* + * PCI-facing part of the host bridge, not usable without the host-facing + * part, which can't be device_add'ed. + */ + + resettable_class_set_parent_phases(rc, NULL, + bcm2838_pcie_root_port_reset_hold, + NULL, &rpc->parent_phases); + + dc->user_creatable = false; + k->vendor_id = BCM2838_PCIE_VENDOR_ID; + k->device_id = BCM2838_PCIE_DEVICE_ID; + k->revision = BCM2838_PCIE_REVISION; + + rpc->exp_offset = BCM2838_PCIE_EXP_CAP_OFFSET; + rpc->aer_offset = BCM2838_PCIE_AER_CAP_OFFSET; +} + +static const TypeInfo bcm2838_pcie_root_info = { + .name = TYPE_BCM2838_PCIE_ROOT, + .parent = TYPE_PCIE_ROOT_PORT, + .instance_size = sizeof(BCM2838PcieRootState), + .instance_init = bcm2838_pcie_root_init, + .class_init = bcm2838_pcie_root_class_init, +}; + +static void bcm2838_pcie_register(void) +{ + type_register_static(&bcm2838_pcie_root_info); +} + +type_init(bcm2838_pcie_register) diff --git a/hw/arm/meson.build b/hw/arm/meson.build index 4233a800..b02aa346 100644 --- a/hw/arm/meson.build +++ b/hw/arm/meson.build @@ -104,7 +104,9 @@ arm_common_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4_boards.c')) arm_common_ss.add(when: 'CONFIG_MAX78000FTHR', if_true: files('max78000fthr.c')) arm_common_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c')) arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_peripherals.c')) -arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2838_peripherals.c')) +arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files( + 'bcm2838_peripherals.c', + 'bcm2838_pcie.c')) arm_common_ss.add(when: 'CONFIG_STRONGARM', if_true: files('strongarm.c')) arm_common_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c')) arm_common_ss.add(when: 'CONFIG_VERSATILE', if_true: files('versatilepb.c')) diff --git a/include/hw/arm/bcm2838_pcie.h b/include/hw/arm/bcm2838_pcie.h new file mode 100644 index 00000000..fe7a6cff --- /dev/null +++ b/include/hw/arm/bcm2838_pcie.h @@ -0,0 +1,53 @@ +/* + * BCM2838 PCIe Root Complex emulation + * + * Copyright (C) 2022 Ovchinnikov Vitalii + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef BCM2838_PCIE_H +#define BCM2838_PCIE_H + +#include "exec/hwaddr.h" +#include "hw/core/sysbus.h" +#include "hw/pci/pci.h" +#include "hw/pci/pcie_host.h" +#include "hw/pci/pcie_port.h" +#include "qom/object.h" + +#define TYPE_BCM2838_PCIE_ROOT "bcm2838-pcie-root" +OBJECT_DECLARE_TYPE(BCM2838PcieRootState, BCM2838PcieRootClass, + BCM2838_PCIE_ROOT) + +#define BCM2838_PCIE_VENDOR_ID 0x14E4 +#define BCM2838_PCIE_DEVICE_ID 0x2711 +#define BCM2838_PCIE_REVISION 20 + +#define BCM2838_PCIE_REGS_SIZE 0x9310 +#define BCM2838_PCIE_NUM_IRQS 4 + +#define BCM2838_PCIE_EXP_CAP_OFFSET 0xAC +#define BCM2838_PCIE_AER_CAP_OFFSET 0x100 + +#define BCM2838_PCIE_EXT_CFG_DATA 0x8000 +#define BCM2838_PCIE_EXT_CFG_INDEX 0x9000 + +struct BCM2838PcieRootState { + /*< private >*/ + PCIESlot parent_obj; + + /*< public >*/ + uint8_t regs[BCM2838_PCIE_REGS_SIZE - PCIE_CONFIG_SPACE_SIZE]; +}; + +struct BCM2838PcieRootClass { + /*< private >*/ + PCIERootPortClass parent_obj; + + /*< public >*/ + void (*parent_realize)(PCIDevice *dev, Error **errp); +}; + + +#endif /* BCM2838_PCIE_H */ -- 2.47.1