From nobody Fri Nov 7 09:10:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537197168003987.6124039585936; Mon, 17 Sep 2018 08:12:48 -0700 (PDT) Received: from localhost ([::1]:36050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1vCd-0007Lc-3c for importer@patchew.org; Mon, 17 Sep 2018 11:12:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53197) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1uyj-0004cs-G9 for qemu-devel@nongnu.org; Mon, 17 Sep 2018 10:58:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g1uyh-0007Iu-Vd for qemu-devel@nongnu.org; Mon, 17 Sep 2018 10:58:21 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:45872) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g1uyh-00078o-HZ for qemu-devel@nongnu.org; Mon, 17 Sep 2018 10:58:19 -0400 Received: by mail-pf1-x431.google.com with SMTP id i26-v6so7670891pfo.12 for ; Mon, 17 Sep 2018 07:58:11 -0700 (PDT) Received: from biggerfish-TM1701.lan (45.78.72.26.16clouds.com. [45.78.72.26]) by smtp.gmail.com with ESMTPSA id 87-v6sm21276632pfn.103.2018.09.17.07.58.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Sep 2018 07:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Dqc8MVy0UMF5DqNsHbkogPaS5TUxGL1d13QBzAi5JEE=; b=djoO0/b/J5MItxaFH3qYp/z9iOzMePl6RB2M+4wGZ5lf8e4SAPZK/pSe9YcfT/ThHD JgfbdU2nWadCfb76vcjKocK4I3/mfYhhW+tNlnw2jmqbhObfsmU92VRUOVriqxfhpDfb wgR9kGm9Y1/MOnWwZIKUwxgue55eCVXSfCRqzC6KLOWVvBxGH+vyubyXzy1qP7FoYUX4 u0F+hhYUr4gdmXkajW4o8zjIdNn/VoSTDBc2xQLfpRWWR6wuTwGYg7OkesyS0DNUbyZp Tu3yQy/MtEH+HnUij2m/8UxlpCSt6oENM8McRE5xEJmhdFXVeOgvEcNRZ6kFPVT6DuKO KdbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Dqc8MVy0UMF5DqNsHbkogPaS5TUxGL1d13QBzAi5JEE=; b=qEQvHBgrXMtWOq2UKL6XNyCI+9dfSPTCAGuZr+hxgXn36Dbfv+snWjX+QHWYxcH12w juFhN9trSJwQxz14BK8kQLmHCGkcpFhxzyt9txVNYe8QUPQ9FTY/NCtwUj2tEK+w3fxm 94Pm2ZfFSaBS9WqBkXvGfCLisIWrj3FLBsRIYG7K0WgoBjmE3aAgWWOlKbYwFDG6WRme JYo4FRQxYkhGGt+Wx5CTjH8Q6pq29+v1iOG+JwgIDupx4MbTg0oWGJ5acOFw4d65tSiT sGNfMGokTueRuRGKax31bFMhClFA/NotROVf0Uhtl6AfJqV2P8R/3IOw9IJ2jgYNAOJw L6Lg== X-Gm-Message-State: APzg51D4tPesUG5+r+BpihiW5EsDTirLeJpr066gdcehQawzitsaIk7G AURq79hJnJolrFwJ2EwrA2B5l5aLpS0= X-Google-Smtp-Source: ANB0VdbLscDRFD1Sl+yRyQenrYzWJDrtGp4vzSFw9J0QBXHIVgCJlC4GVL8GPqgeWEH1C/sjmy1bBQ== X-Received: by 2002:a63:9f19:: with SMTP id g25-v6mr24449597pge.39.1537196290583; Mon, 17 Sep 2018 07:58:10 -0700 (PDT) From: Zihan Yang To: qemu-devel@nongnu.org Date: Mon, 17 Sep 2018 22:57:36 +0800 Message-Id: <1537196258-12581-6-git-send-email-whois.zihan.yang@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1537196258-12581-1-git-send-email-whois.zihan.yang@gmail.com> References: <1537196258-12581-1-git-send-email-whois.zihan.yang@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::431 Subject: [Qemu-devel] [RFC v5 5/6] pci_expander_bridge: add config_write callback for pxb-pcie X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zihan Yang , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This allows SeaBIOS to configure MCFG base during initialization. The mcfg size is calculated using based on desired bus number Signed-off-by: Zihan Yang --- hw/pci-bridge/pci_expander_bridge.c | 37 +++++++++++++++++++++++++= ++++ include/hw/pci-bridge/pci_expander_bridge.h | 7 ++++++ 2 files changed, 44 insertions(+) diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expand= er_bridge.c index 1e1999d..09413df 100644 --- a/hw/pci-bridge/pci_expander_bridge.c +++ b/hw/pci-bridge/pci_expander_bridge.c @@ -20,6 +20,7 @@ #include "hw/pci-bridge/pci_expander_bridge.h" #include "qemu/range.h" #include "qemu/error-report.h" +#include "qemu/units.h" #include "sysemu/numa.h" #include "qapi/visitor.h" =20 @@ -395,6 +396,41 @@ static void pxb_dev_exitfn(PCIDevice *pci_dev) pxb_dev_list =3D g_list_remove(pxb_dev_list, pxb); } =20 +static void pxb_pcie_update_pciexbar(PXBDev *pxb) +{ + PCIDevice *pci_dev =3D PCI_DEVICE(pxb); + PCIBus *pxb_bus =3D pci_get_bus(pci_dev); + BusState *bus =3D BUS(QLIST_FIRST(&pxb_bus->child)); + PCIExpressHost *pehb =3D PCIE_HOST_BRIDGE(bus->parent); + + uint64_t addr; + uint32_t length; + int enable; + + addr =3D pci_get_quad(pci_dev->config + PXB_PCIE_HOST_BRIDGE_MCFG_BAR); + enable =3D addr & PXB_PCIE_HOST_BRIDGE_ENABLE; + addr &=3D PXB_PCIE_HOST_BRIDGE_PCIEXBAR_ADMSK; + length =3D (pxb->max_bus - pxb->bus_nr + 1) * MiB; + + pcie_host_mmcfg_update(pehb, enable, addr, length); +} + +static void pxb_pcie_config_write(PCIDevice *d, uint32_t address, + uint32_t val, int len) +{ + PXBDev *pxb =3D PXB_PCIE_DEV(d); + + pci_default_write_config(d, address, val, len); + + /* Since desired bus number is provided by pxb-pcie, + we just need seabios to decide the mcfg_base for us. + mcfg_size can be calculated easily */ + if (ranges_overlap(address, len, PXB_PCIE_HOST_BRIDGE_MCFG_BAR, + PXB_PCIE_HOST_BRIDGE_MCFG_BAR_SIZE)) { + pxb_pcie_update_pciexbar(pxb); + } +} + static Property pxb_dev_properties[] =3D { /* Note: 0 is not a legal PXB bus number. */ DEFINE_PROP_UINT8(PROP_PXB_BUS_NR, PXBDev, bus_nr, 0), @@ -459,6 +495,7 @@ static void pxb_pcie_dev_class_init(ObjectClass *klass,= void *data) k->vendor_id =3D PCI_VENDOR_ID_REDHAT; k->device_id =3D PCI_DEVICE_ID_REDHAT_PXB_PCIE; k->class_id =3D PCI_CLASS_BRIDGE_HOST; + k->config_write =3D pxb_pcie_config_write; =20 dc->desc =3D "PCI Express Expander Bridge"; dc->props =3D pxb_pcie_dev_properties; diff --git a/include/hw/pci-bridge/pci_expander_bridge.h b/include/hw/pci-b= ridge/pci_expander_bridge.h index e017c62..5be0a8e 100644 --- a/include/hw/pci-bridge/pci_expander_bridge.h +++ b/include/hw/pci-bridge/pci_expander_bridge.h @@ -2,6 +2,7 @@ #define HW_PCI_EXPANDER_H =20 #include "hw/pci/pcie_host.h" +#include "hw/pci-host/q35.h" =20 #define TYPE_PXB_PCIE_HOST "pxb-pcie-host" #define PXB_PCIE_HOST_DEVICE(obj) \ @@ -13,4 +14,10 @@ typedef struct PXBPCIEHost { /*< public >*/ } PXBPCIEHost; =20 +#define PXB_PCIE_HOST_BRIDGE_MCFG_BAR 0x50 /* 64bit regis= ter */ +#define PXB_PCIE_HOST_BRIDGE_MCFG_BAR_SIZE 8 +#define PXB_PCIE_HOST_BRIDGE_ENABLE MCH_HOST_BRIDGE_PCIEXB= AREN +/* The mcfg_base of pxb-pcie is not 256MB-aligned, but MB-aligned */ +#define PXB_PCIE_HOST_BRIDGE_PCIEXBAR_ADMSK Q35_MASK(64, 35, 20) + #endif --=20 2.7.4