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 302A7C2D0A6 for ; Thu, 15 Oct 2026 18:11:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHPvP-0001Kv-HU; Thu, 15 Oct 2026 14:11: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 1xHPvN-0001Gi-DL for qemu-devel@nongnu.org; Thu, 15 Oct 2026 14:11:29 -0400 Received: from mail-qt1-x82e.google.com ([2607:f8b0:4864:20::82e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xHPvK-0001Ru-NV for qemu-devel@nongnu.org; Thu, 15 Oct 2026 14:11:29 -0400 Received: by mail-qt1-x82e.google.com with SMTP id d75a77b69052e-5350cc60b51so77506651cf.1 for ; Thu, 15 Oct 2026 11:11:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792087885; x=1792692685; 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=s2UvpvDX9ejIgABxm9OON8dWOXW2neu5g/bj+TjWyx4=; b=ITHjrSG80cOc67Imippj7pxr3F/JmKpSOcGHZ28k/ncQS5cbfQyzOicixmhnRX/lXf sSgUuD/vlsDTAcu1v87AbVQwTjyGi02nbm3SZ4MdbDCHPz72DOJXcQKg2UBjZGPQV1aC rOTblXDprSqCFs8lCZWlhXdK9Yb/nV4Q9jjcGx/VqkpiBprT2mnOfZGhKrRTCuLVA/Bv ozTcdIa/vxSIXXNd8rfG/whVIOlkcPz2ha//bFJePm+CvpPO/q93GEo0FgwcxrIxv2mj PO7MMmn2lbKA3nSw2BsMHmjGxy6NRfVR+EtoMSLevegKlNaoIrRDdZDyNqUXqK2h8SKE Fv+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792087885; x=1792692685; 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=s2UvpvDX9ejIgABxm9OON8dWOXW2neu5g/bj+TjWyx4=; b=JwSgO3YkXrYdlkp9pWLWkQa9ZmVCYVcreCNgbg1xBpYIC8GIxb7U95sCth3aSOXjV2 EJ3nq21z1z4z4g+pqSoEawgk6og9RtaK3ko8rXPFhc2RaagrtTx8JlIJ+65l+m510mVB VE1nJMvcCZNA/477mF9D+CPE2vXxsmS+W+wdLA9N8Q1IiZT3nQI55T4K4uAY0u+q0GHf jrycJHL6CAvunPt0iGspWLHiJpwlCaVc8K2KwHoUvc3w6u8HnZKLExczG9XjCq8ceWBa 1LvQJnfncnWoSJDwVlJg4eawKBM4DyusiAXX/h5yLDDRqfCPw1LFfTSjb/RufjpBl4Nw 5hfA== X-Gm-Message-State: AFq9FYLmzzo7ctJiStIvRX8Sa96S4f7STTCWZkeadMZQAeczzl3Whmcw UoPlchjv9fPDifOEm3pYutppxLB+/8KEkIXYMhvTdHcKVKjzVSx6oQJU1gq0gV0R X-Gm-Gg: AYBFou1UQeXQZ3VgfUpw9ttR8+gB6kYZBjYBAsml1E5LoNXXWBX4chOhpgRmjE+HQiP aF4bRHC87lucact+lQ3PLzyyMffOGK3xAsvt9/08t5wIGRzaUvRTAB+hJ+nYDAeqO8DfBRCN2xa midRnb1E50jwyw1wkisPTYaqK3+dHhfjpb1H3kButXSwv03cmvIGRcY379OlE8Pgr9h9KZSVjBU HGCGQ8moQuvJNYSUUwdk7b8vCiAEhjyOwTGqsdO2EkeKCB3rKVJJ5dbFN6AB4+vF9BZgFcloCo7 oaeUZopwXfxBoYMKuxnQisbXttG3PX32cVyXfTp1RFoVKK6Ir2KqdQogZhv32638b6ohs+a5gUN RGMhw9cOFJECg+J6x/rieYtH+7hCefcH0ttx0xNABz27eb+7kuBFxyFzYDTSZhj4EfAwmsPvfGV 5WTL37hu43axtn//2vVadziAACVZSfk3e3KsDpEzskGhZG52cfu+hDD2O3rTk7fhxhSwEfCT4hP 4Frs2woASL0xBUv3vuMExqs4x1MaauGz8nD02NYh3/6hnyYlyLSCqp+f16MyvS43hEmqXw= X-Received: by 2002:a05:622a:4086:b0:535:231d:653e with SMTP id d75a77b69052e-5359fb8efc9mr293050681cf.45.1792087885529; Thu, 15 Oct 2026 11:11:25 -0700 (PDT) Received: from localhost.localdomain ([2606:6d00:159:2900:919:5388:4e10:5949]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-536127efe4asm32130611cf.19.2026.10.15.11.11.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 15 Oct 2026 11:11:25 -0700 (PDT) From: Marcelo Manzo To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Cc: Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Marcelo Manzo Subject: [PATCH v3 01/16] hw/arm/bcm2838_pcie: add BCM2838 PCIe Root Complex Date: Thu, 15 Oct 2026 14:11:06 -0400 Message-ID: <20261015181122.60608-2-marcelomanzo@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261015181122.60608-1-marcelomanzo@gmail.com> References: <20261015181122.60608-1-marcelomanzo@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::82e; envelope-from=marcelomanzo@gmail.com; helo=mail-qt1-x82e.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-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=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 0000000000..96a45c1863 --- /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 bcc068de04..f3c1b0e00f 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 0000000000..fe7a6cff19 --- /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.55.0