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 10C00CCF2C4 for ; Sun, 18 Oct 2026 13:37:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xIR3d-0002Gj-1R; Sun, 18 Oct 2026 09:36:13 -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 1xIR3a-0002EP-Rf for qemu-arm@nongnu.org; Sun, 18 Oct 2026 09:36:10 -0400 Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xIR3X-0002FY-Fx for qemu-arm@nongnu.org; Sun, 18 Oct 2026 09:36:10 -0400 Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-93e4c00d71aso126501485a.3 for ; Sun, 18 Oct 2026 06:36:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792330566; x=1792935366; 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=f/8GOdTEqapJOexxTIPpjYi49fOr9v1/dqfidXGlON4=; b=CITkTqvsRawaqF9o+CVNBmc4GXnXQt4ZYuluKK/YJw40e/vawiiDwYZHcdl0ZpbZIB 2d7vkaB6K5NZeTK65CFjtIYYps8WziWCPzI7oSVusJF/wa2uNaP95CVuauYoqge04N/o Wo8FlmSflVhwX0YetqDcnPjef1tHo3ZPdQnmMKQII2hI3qKaDvVbjy20Ya8HnOiIFRKL Y5v0Nz/DXfTzaAsGyvAinXuLlMR8VI236hJ2VLwFQs/5ts2YZiJbCIukvwD41Z5E3UeC 8TH9FJJO3K86BNgPlTC2ky1D1Rhbk0XbjSK77CnZ+7U3eUOub787aurb6kha+yxElsaS xUYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792330566; x=1792935366; 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=f/8GOdTEqapJOexxTIPpjYi49fOr9v1/dqfidXGlON4=; b=xWUerNBopFbhQSnwBQ6quleCB7isopCzBt0er4H5CAHyH6uB9BV1nrRaAAJYnl60rE 5sM0QTOk5/YeTEbz4hZUzlacYLiE3LoY7ykwiDm1UnvlCZOpyB7QbKH5FKEUCwDFDZmU 9aAJIFGa/8HVul4K22cPPajkdkmBeAuwbEv8qLzmDrhZrRqpnTthZoiTBbA2lLWfqkP8 Od+RFAiRQf0Hawg6/65n6V4UscnVvg00O42xOsH81tBqjliQyvPROncfd9EyEiFJaGx3 nEd5MqIpTjODxBUptCiypcdAIdPeiJhuqme2WfPSEwaMQcdlUTFXnGUZdtYmZuRQ9hm/ lqdQ== X-Forwarded-Encrypted: i=1; AKwUvByKG46Yh5BQfzFsAOMn4jAip4nITcQ+rjmRuXtZKTllmPpm3A1fed4s7zGRQ/WOkFfC2JQrnzjL9w==@nongnu.org X-Gm-Message-State: AFq9FYKsAHLxVCJnU5QbJRO5OlLu+JiXOyEFSdTBqPUELw+kZp/0yRhI 57vL3kLdYW6M7a6Tb9WHlZkU6+dPlNCtk9dok91GLhLKiPVXhGn1UWc2D31IsJ9e X-Gm-Gg: AYBFou1Lsoa1nE0aHpuLCJ6RY/9GgawiWWLD8HmVnBy9UxlWkuf40TZ6oBZvSa8iHCN ku/4YTL/rcvHqrwYkI3tZuBCIKP53eWB1PO12tmmgjuftqg+YVSfgeCKfhARFU9nf8iGs5bp5q6 m6zqa6ZAdtEWLII0fbPvQM2f11neAnahqPTVpXpKGHupzvrWqzXQ9b/ECNw9PSNbVoGU+mKdKpB rucKv3cy2SDNZiIVDiPnpQcmeUNqzuL0+5eBWIocc/QfXAs0UHWpRh3xFxDKH5BIgH4S3MFU5+M 30c9N//30eNvo+rj7s+nr5TpVA6cNGhs3EoV7A9onFzLy0opUX5FWzshxNfiZ5+E13rzNcPCUEd deYASs9afQOqLzUQoDvknoGccWEbMSHPb9I8QsnjPTuuJ51VQ81qd5QahaAWWLpHkatbTz+NVka soR4ueBAY7zjmWd09x9/T7aax6XKcdx3AI1LCPInIncQE+qW3cJ44g27/GFqmh1S9oZv/EIBe24 ioaxi5SWrHzDKAV4eBKZDm1SLxqcmtIX8yrW/IJDmmMUmsPUIUsI/ji7cxBFvS6bLVFpCs= X-Received: by 2002:a05:620a:2a16:b0:93e:920c:c00e with SMTP id af79cd13be357-93f29ceecb2mr870626485a.21.1792330566452; Sun, 18 Oct 2026 06:36:06 -0700 (PDT) Received: from localhost.localdomain ([2606:6d00:159:2900:ecfc:9d0d:b95b:11bf]) by smtp.gmail.com with ESMTPSA id af79cd13be357-93f2a854bb7sm459056485a.23.2026.10.18.06.36.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 18 Oct 2026 06:36:06 -0700 (PDT) From: Marcelo Manzo To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Cc: peter.maydell@linaro.org, philmd@oss.qualcomm.com, Marcelo Manzo Subject: [PATCH v4 01/17] hw/arm/bcm2838_pcie: add BCM2838 PCIe Root Complex Date: Sun, 18 Oct 2026 09:35:47 -0400 Message-ID: <20261018133603.64323-2-marcelomanzo@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261018133603.64323-1-marcelomanzo@gmail.com> References: <20261018133603.64323-1-marcelomanzo@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::72e; envelope-from=marcelomanzo@gmail.com; helo=mail-qk1-x72e.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-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 | 103 ++++++++++++++++++++++++++++++++++ hw/arm/meson.build | 4 +- include/hw/arm/bcm2838_pcie.h | 54 ++++++++++++++++++ 3 files changed, 160 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..1ebb05657b --- /dev/null +++ b/hw/arm/bcm2838_pcie.c @@ -0,0 +1,103 @@ +/* + * 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/pci/pcie.h" +#include "hw/pci/pcie_aer.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 const VMStateDescription vmstate_bcm2838_pcie_root = { + .name = "bcm2838-pcie-root", + .priority = MIG_PRI_PCI_BUS, + .version_id = 1, + .minimum_version_id = 1, + .post_load = pcie_cap_slot_post_load, + .fields = (const VMStateField[]) { + VMSTATE_PCI_DEVICE(parent_obj.parent_obj.parent_obj.parent_obj, + BCM2838PcieRootState), + VMSTATE_STRUCT(parent_obj.parent_obj.parent_obj.parent_obj.exp.aer_log, + BCM2838PcieRootState, 0, vmstate_pcie_aer_log, + PCIEAERLog), + VMSTATE_UINT8_ARRAY(regs, BCM2838PcieRootState, + BCM2838_PCIE_REGS_SIZE - PCIE_CONFIG_SPACE_SIZE), + VMSTATE_END_OF_LIST() + } +}; + +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"; + dc->vmsd = &vmstate_bcm2838_pcie_root; + + resettable_class_set_parent_phases(rc, NULL, + bcm2838_pcie_root_port_reset_hold, + NULL, &rpc->parent_phases); + + /* + * PCI-facing part of the host bridge, not usable without the host-facing + * part, which can't be device_add'ed. + */ + 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..cb95c65331 --- /dev/null +++ b/include/hw/arm/bcm2838_pcie.h @@ -0,0 +1,54 @@ +/* + * 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 >*/ + /* Controller registers above the 4KB config space; little-endian bytes */ + 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