Received: by 2002:a17:505:32ab:b0:1be9:327d:8ee3 with SMTP id js11csp92308njb; Tue, 4 Feb 2025 01:23:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX/Oy0tB0Xx1/WPBVM9/uL1PurxlQkla972VYFNNCw9LTuq4AQm9HuV6TYghdDz6a3R3uruh6mgZ6y9FA==@linaro.org X-Google-Smtp-Source: AGHT+IGC2HNCFT8PKSB4uI9W+h/3JDWkE/BMhpObIHHLLLq/ypcb4+aBafOcWrXPJq3NVQvTNZYd X-Received: by 2002:a05:620a:bd4:b0:7b7:e5b:3b24 with SMTP id af79cd13be357-7bffcda8723mr3599397285a.50.1738660979809; Tue, 04 Feb 2025 01:22:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1738660979; cv=none; d=google.com; s=arc-20240605; b=SuW0StgQpv8fuy59YYJoeOQrmG/0LJXfClxmMZ+pYH3d4sf0uQkc5OJ9Uya/cSmE5S Fw/YzcR1sa2jAlSONdQgdABOy03LLYffFJ68Iu3ZJwNo3++ekZg4n/soZTtILMEJ/d5z EsqQcSIQ8cWjAL69cZ5R/coxSZdAwk1RG32vurxD9JXSminWMCRIBuAXL8tvpiEozIBJ 9Jx7B7+yYGQS2o32wKaQQ3sTEkKzbvkL+3yBX/kFaKqAu9zrCwhdJREGAX3tXw5jHLJE GW6L5m0NTKUQVUs/LX8mvTN6eF2ZzuO0Og2oHV9QaOfFQfrxkqFxXFiZMBbC0rS5wyyo v1Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=r8qJcnNvkV2vDa+pvhn/pUMBPEEUiO9U4AbL5C/A4EI=; fh=Pm1UHi1hscNaSwZ+FPOYRM1ALuVOP4U9xt+8ykB2GNU=; b=OgxYe5Q9FzwyJgMlr9GkfNkp8qO3X3G5Q53UC3tUFLjvlvyDc54fkqyH1ijhEQQFDF pigRmdrdcq+p9ismZc1zWCbRPGEUROfyUiDHXM6svs8ms1VQeos3bclVxcamRv/fN8lK fgpkpNh7ZKh8yUOGdh5cjhKMXEQVbOZAArf5O9DaonScmrez1yjcbid3Fhbwqo37JZhj EDr51VcFD7BJq2Ef6+VqYSSW3/KB2MfmybkqNaJGAfgZ3BmUa3K9/75anCYxQ4EeFDCr P+1U3KAe8VcWFubJ4iXVoM+6xzQHbk16c3SdHX1scfDP8xoyFcWUsdto+1NOX2hmvcJa m/4Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="M/v57iB4"; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7c02dbddb35si227512385a.326.2025.02.04.01.22.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Feb 2025 01:22:59 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="M/v57iB4"; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tfF7Y-0004iF-RO; Tue, 04 Feb 2025 04:21:28 -0500 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 1tfF7X-0004hI-SQ; Tue, 04 Feb 2025 04:21:27 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tfF7V-00052V-UP; Tue, 04 Feb 2025 04:21:27 -0500 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-436281c8a38so37592785e9.3; Tue, 04 Feb 2025 01:21:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738660883; x=1739265683; 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; bh=r8qJcnNvkV2vDa+pvhn/pUMBPEEUiO9U4AbL5C/A4EI=; b=M/v57iB4Kjy7a8+3loZLfcT00Fq8ANfbbvNuDKCybpKTRYdgudvNppThI88fJSybDE jZZfN0APomYCews0TCB5OF/7eaP7VIrGuGXETU8qAfSzJKtXZq6VI7GLwDeUSi1JtJu7 it2Hr6SPU6UkbMIj2SY6K7bn0OQc3ByTtxErvQQp9Ch/5NohFOZ9PXk4rZYZEr+qxaKW Xg6SOqwbJcQRnSF9EwaKifWceZgBlG5jKvhgsjl4B35inLJ7jTyMxFvb1LPq3Y1alI+h ZckqR94S/sVpBcmU8XCjpjHzEFhGNI7g2hpbjPdnKw3xVxuwA1zAknTVZnPcnOjd0VlZ Utgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738660883; x=1739265683; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r8qJcnNvkV2vDa+pvhn/pUMBPEEUiO9U4AbL5C/A4EI=; b=qRQIDMlWPTjD98BvryGS52t7yXOwZQr0oZl34TfMb1F7z8LdLlik8aN1qepquVCHIv R6vLdgR6AnlA9b6E465V+5AJ2hqWTWcxKaT6j+JusSzRZhz5Rf2m3RaTWP6idmWY+h8d sT4TpY9wuOSSbOSS+oqItCAt2UH04eTJFjAhGhOv/2DtSoDxgRdToVZy3pYxa52fPBqk 0YHcYImI2is/K09m807C3r07fItFx/zoblPj1F5m6XK8jqxaPkcuvV//i7Z5OouFn45w KVicke4WP8G2vNTB6VEURaLmICK7BqfFNO1N09+7WcDl2kT/oha7osmQBCAZtGn+S4/2 A8AQ== X-Forwarded-Encrypted: i=1; AJvYcCV7xDphUFhkCYFlznmclSN/ycjp1tf3PL7LO8DSx9GV7dpjsb5BdEZ+ODolKc7ycS54wIsHCBXZdQ==@nongnu.org X-Gm-Message-State: AOJu0YxU6PDa1bh+ZwUZQubL1fj1fPs1/ogNHqyFGWzvxNHuM+xxnQdA vXN6qZRJHDcKDWEGxVg96s5s7toXe8Tlpv06lEDgaxRdOIcF0Ivmx2InJg== X-Gm-Gg: ASbGnctc8j8HHMgSKra8FCugFYbrAgI54nLq2wX35McPsDO1secsspp3g7bEGLPyofL vhEccAxRqGePQuYQlwhZdl2ri3Gk5M4MVw3k+IJ6akPYb1lKqs7OWVvMVkwc0uSVgpQq0iYgO4J vQ/Vb32mr8lHFRbw9jRJjn3WNwtW4o88voP+zEJje54qp4tOVdpmoGwS9gK2bcDoZl3lp7Q7ULp VeOMh8k8ItKXT2lUsyKHNAdWHZ3xyzVQSqR0iqFrwcpFGQHc4uJMSjLFBZX5wMJHoe7hKZZS1t+ XkhrsVBYLSKtumj/YaEw48sjMpHWyLt14nSDjeczHm1jdlyQMbjKef8dWjVLGXAWI6OQZcinmF2 h3YEvJgwXmw== X-Received: by 2002:a05:600c:4c24:b0:434:f609:1afa with SMTP id 5b1f17b1804b1-438e01fdfe1mr191296755e9.4.1738660883217; Tue, 04 Feb 2025 01:21:23 -0800 (PST) Received: from Georg-PC.fritz.box (p200300faaf0043006a2cae69f03f1c85.dip0.t-ipconnect.de. [2003:fa:af00:4300:6a2c:ae69:f03f:1c85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438e23d42c7sm187233595e9.3.2025.02.04.01.21.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2025 01:21:21 -0800 (PST) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Bernhard Beschow , qemu-arm@nongnu.org, Peter Maydell , Andrey Smirnov , Paolo Bonzini Subject: [PATCH v2 02/18] hw/pci-host/designware: Prevent device attachment on internal PCIe root bus Date: Tue, 4 Feb 2025 10:20:56 +0100 Message-ID: <20250204092112.26957-3-shentey@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204092112.26957-1-shentey@gmail.com> References: <20250204092112.26957-1-shentey@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=shentey@gmail.com; helo=mail-wm1-x335.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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: jwVglNZoTBpu On the real device, the PCIe root bus is only connected to a PCIe bridge and does not allow for direct attachment of devices. Doing so in QEMU results in no PCI devices being detected by Linux. Instead, PCI devices should plug into the secondary PCIe bus spawned by the internal PCIe bridge. Unfortunately, QEMU defaults to plugging devices into the PCIe root bus. To work around this, every PCI device created on the command line needs an extra `bus=dw-pcie` option which is error prone. Fix that by marking the PCIe root bus as full which makes QEMU decend into the child PCIe bus. Signed-off-by: Bernhard Beschow --- include/hw/pci-host/designware.h | 7 +++++++ hw/pci-host/designware.c | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/hw/pci-host/designware.h b/include/hw/pci-host/designware.h index bf8b278978..a35a3bd06c 100644 --- a/include/hw/pci-host/designware.h +++ b/include/hw/pci-host/designware.h @@ -25,12 +25,19 @@ #include "hw/pci/pci_bridge.h" #include "qom/object.h" +#define TYPE_DESIGNWARE_PCIE_ROOT_BUS "designware-pcie-root-BUS" +OBJECT_DECLARE_SIMPLE_TYPE(DesignwarePCIERootBus, DESIGNWARE_PCIE_ROOT_BUS) + #define TYPE_DESIGNWARE_PCIE_HOST "designware-pcie-host" OBJECT_DECLARE_SIMPLE_TYPE(DesignwarePCIEHost, DESIGNWARE_PCIE_HOST) #define TYPE_DESIGNWARE_PCIE_ROOT "designware-pcie-root" OBJECT_DECLARE_SIMPLE_TYPE(DesignwarePCIERoot, DESIGNWARE_PCIE_ROOT) +struct DesignwarePCIERootBus { + PCIBus parent; +}; + typedef struct DesignwarePCIEViewport { DesignwarePCIERoot *root; diff --git a/hw/pci-host/designware.c b/hw/pci-host/designware.c index 3e8c36e6a7..c07740bfaa 100644 --- a/hw/pci-host/designware.c +++ b/hw/pci-host/designware.c @@ -55,6 +55,17 @@ #define DESIGNWARE_PCIE_ATU_DEVFN(x) (((x) >> 16) & 0xff) #define DESIGNWARE_PCIE_ATU_UPPER_TARGET 0x91C +static void designware_pcie_root_bus_class_init(ObjectClass *klass, void *data) +{ + BusClass *k = BUS_CLASS(klass); + + /* + * Designware has only a single root complex. Enforce the limit on the + * parent bus + */ + k->max_dev = 1; +} + static DesignwarePCIEHost * designware_pcie_root_to_host(DesignwarePCIERoot *root) { @@ -699,7 +710,7 @@ static void designware_pcie_host_realize(DeviceState *dev, Error **errp) &s->pci.memory, &s->pci.io, 0, 4, - TYPE_PCIE_BUS); + TYPE_DESIGNWARE_PCIE_ROOT_BUS); pci->bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE; memory_region_init(&s->pci.address_space_root, @@ -754,6 +765,11 @@ static void designware_pcie_host_init(Object *obj) static const TypeInfo designware_pcie_types[] = { { + .name = TYPE_DESIGNWARE_PCIE_ROOT_BUS, + .parent = TYPE_PCIE_BUS, + .instance_size = sizeof(DesignwarePCIERootBus), + .class_init = designware_pcie_root_bus_class_init, + }, { .name = TYPE_DESIGNWARE_PCIE_HOST, .parent = TYPE_PCI_HOST_BRIDGE, .instance_size = sizeof(DesignwarePCIEHost), -- 2.48.1