From patchwork Fri Dec 13 23:30:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 850294 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:2c4:b0:385:e875:8a9e with SMTP id o4csp1778989wry; Fri, 13 Dec 2024 15:32:29 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV1UubBdyaS3Ue5JLiQN5RTtr8+jvd8juw9dC3c8bOYCEaBrbHDPh9dWXRDvvIyLZx4t4YyhQ==@linaro.org X-Google-Smtp-Source: AGHT+IHJGfVTMQLRD+aszJSx+VCooJbvxKpbdkF5zZKEjXEhEpwaLPbatNYupCcXAGZPmGNOut7B X-Received: by 2002:a05:6214:27ec:b0:6d8:7db7:1f2e with SMTP id 6a1803df08f44-6dc8ca68e65mr65817886d6.14.1734132749274; Fri, 13 Dec 2024 15:32:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1734132749; cv=none; d=google.com; s=arc-20240605; b=gmpG6TVLHAuSNs/3haYb8RtDfamu3wZKuu2Jy22Os+os9iAgt53EAfn3hjR5nQDf1m 7Jkk5bWdatURk0k+WMlaRd/JWbo9KhgRpi1Yad3DuCk+3pI3IBG+LJTXXXrB8j15slew vZu9ZRo+Ru/gmfKxzZJf7HZPH2b5z/dniU6fB18goFkOMPTIF3b//1f6FvSnWhWZ/IDt Z2ZgYtgV1mP1KkpUQihmmejPyZbXOQ4riomq45LklV5WKIm0qhgidCYvQHzJG8/LV+j+ pmV33FEoE1RKe3OfnG90JVuQvGZezbaP1JOkwYJ5yag9CKB4NXTvnrMD3C2Z5Y48KGAs ONvQ== 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=bGLsAY1QOgkinuwwLWyIxYZvjMgpGCzP2nfQjOcTbV8=; fh=iBCV4w7YK1vyHYfwyxOoXBCd3sIBF9+yH+94qSO9meY=; b=VOqe/74xlQmhHv1fPGBWAWQR7mSqS6ijBO7wOxG6YgO1tznd1zn6Jg3Gi7ZS3CGlOz VqLV7V3fFICzEJOdfpID5lJPJl0cv4GyY//pG1gUjps3YxwNgtEvqIJRwhe/iQOfxCms UxwqWNu//ejtc7wcwxqpEHL/Fk+3LKal1pMfqwXJf4sfZVbCPRONFkA+5Ym8sCCWy06n GnZe1K+YzLaQhShlodLrTLontgOeReAfGuIjnyPCJTEFuZW0fffASc4UMN8u4ziYLDeJ G66GCz/Bt28LLwIKPJnmLxv5HcNqM4TuIboDi1U5OOxWFDqisQISRs3euooQDlDdF7Fr 07iw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SbzNgFM8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; 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 6a1803df08f44-6dccd34d3basi5903296d6.263.2024.12.13.15.32.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Dec 2024 15:32:29 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=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=@linaro.org header.s=google header.b=SbzNgFM8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; 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 1tMF8V-000390-GE; Fri, 13 Dec 2024 18:31:57 -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 1tMF8M-00032M-OL for qemu-devel@nongnu.org; Fri, 13 Dec 2024 18:31:47 -0500 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tMF8L-000321-4W for qemu-devel@nongnu.org; Fri, 13 Dec 2024 18:31:46 -0500 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3862a921123so1697880f8f.3 for ; Fri, 13 Dec 2024 15:31:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1734132701; x=1734737501; 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=bGLsAY1QOgkinuwwLWyIxYZvjMgpGCzP2nfQjOcTbV8=; b=SbzNgFM8kikmxtsqU5OaAqSR7+CMVbqC9a2Txn4m258AL6bWpRhXMcGPCvGCN2Ojmg XvS6IQGZhacRa6DcYLFVHvyprMUZsyN/e+8eKmcy+mlpEmxSmQmn2yjso1pAbXDZ8uW9 3T3pxfHbFNt6xT8y9urAdrkzkgSeIs4efGb3g8Iq6QigEbqg9zM1R8oYy9TbcoO8hb2W K3gH+B7FcOiL6m/pfuSehn8A25gDUrGsv94/Nskg+JSOttEA9rTz5X9oFy3Mj6jnH2X/ cwdbdYeTilDGzHWk6LaXZqZJyaXpdTEHunhdkxKlknDDuQ7Dd3HZ6UaI7CWb2dpoxPL0 zttQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734132701; x=1734737501; 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=bGLsAY1QOgkinuwwLWyIxYZvjMgpGCzP2nfQjOcTbV8=; b=OjKNa9pEMrc8L/rckpN33OFmoF808mqV1QGIIgy+CJiUbn5Vh12fofeKRaJUckMhet 9VltBMgaBFdCjztAab5Bshl1PQLxx21eV39A9PApxyj/QaBk7C0AIW3KA2VwtR6HRc+j xeiY/HzwbmX1PK1O371+804gxIv1eENtxxMNAcUpczx1M2iKVbkcN/wkf9wHCbscC8m1 xkKB3GrJJWg7GH4IHMJbwF27QnUmE6GycgOfS+Mw4YD7vpr+vh+K6Gd7AmhxXdDThoTb 9mH5bd0GVT9GcG3NwL3K4WdTcdaDRPEKqr9RDQk5HmtL09Zi3/TbLjoYr48UA5bPOT4j QLKQ== X-Gm-Message-State: AOJu0YxZuoLKfLJJ39P7T9lEITZtfw4VYBMszcF+Jf/p87VtINEYF5F6 LBBVSfb2hCq5TsooLnVHhH1YLqaqVLYEyOvFBXjMsxTDwRd2I3JqNv7PTsCCDsHjfLXSUr/F51Y 6Pno= X-Gm-Gg: ASbGncv/ftPL8VmsslcEDZf4r294b8Xc5u4M9ShXuKwhZ4rglVd5c8tBwUQkT4aLMYB unSoao7Uft7m1B3tdprobhmMFQWpEMVoXBo4SluRMLqC4yzUgwprugsHOMmHa6EmMAE3xD6nN9w u3gpZfZIesTKUgTs+pWVTG8RhTLiqy1iwsC5rRCGCrEJ6R3TDnMKLFlzIUw9oKvvG2B5fySY7Pz 9rmbSPlK56L1gPlCI0ZkhR9MsmcuwaOOxJ6R1tsDu7l4af6uVlh8pQL12Xp0FyR4ZLPute2f7U2 s5ffeQ== X-Received: by 2002:a05:6000:1fae:b0:385:ea2b:12cc with SMTP id ffacd0b85a97d-38880acd0b7mr3491819f8f.13.1734132701437; Fri, 13 Dec 2024 15:31:41 -0800 (PST) Received: from localhost.localdomain ([45.93.146.194]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c8046bf8sm821961f8f.82.2024.12.13.15.31.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 13 Dec 2024 15:31:40 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?D?= =?utf-8?q?aniel_P_=2E_Berrang=C3=A9?= Subject: [PULL 08/20] hw/pci: Have PCI_BUS implement TYPE_FW_CFG_DATA_GENERATOR_INTERFACE Date: Sat, 14 Dec 2024 00:30:43 +0100 Message-ID: <20241213233055.39574-9-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241213233055.39574-1-philmd@linaro.org> References: <20241213233055.39574-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=philmd@linaro.org; helo=mail-wr1-x42a.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, 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The FW_CFG_DATA_GENERATOR interface allows any object to produce a blob of data consumable by the fw_cfg device. Implement that for PCI bus objects. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Message-Id: <20241213133352.10915-5-philmd@linaro.org> --- hw/pci/pci.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 1416ae202c3..8844251eceb 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -46,6 +46,7 @@ #include "hw/pci/msix.h" #include "hw/hotplug.h" #include "hw/boards.h" +#include "hw/nvram/fw_cfg.h" #include "qapi/error.h" #include "qemu/cutils.h" #include "pci-internal.h" @@ -216,11 +217,41 @@ static uint16_t pcibus_numa_node(PCIBus *bus) return NUMA_NODE_UNASSIGNED; } +static GByteArray *pci_bus_fw_cfg_gen_data(Object *obj, Error **errp) +{ + PCIBus *bus = PCI_BUS(obj); + GByteArray *byte_array; + uint64_t extra_hosts = 0; + + if (!bus) { + return NULL; + } + + QLIST_FOREACH(bus, &bus->child, sibling) { + /* look for expander root buses */ + if (pci_bus_is_root(bus)) { + extra_hosts++; + } + } + + if (!extra_hosts) { + return NULL; + } + extra_hosts = cpu_to_le64(extra_hosts); + + byte_array = g_byte_array_new(); + g_byte_array_append(byte_array, + (const void *)&extra_hosts, sizeof(extra_hosts)); + + return byte_array; +} + static void pci_bus_class_init(ObjectClass *klass, void *data) { BusClass *k = BUS_CLASS(klass); PCIBusClass *pbc = PCI_BUS_CLASS(klass); ResettableClass *rc = RESETTABLE_CLASS(klass); + FWCfgDataGeneratorClass *fwgc = FW_CFG_DATA_GENERATOR_CLASS(klass); k->print_dev = pcibus_dev_print; k->get_dev_path = pcibus_get_dev_path; @@ -232,6 +263,8 @@ static void pci_bus_class_init(ObjectClass *klass, void *data) pbc->bus_num = pcibus_num; pbc->numa_node = pcibus_numa_node; + + fwgc->get_data = pci_bus_fw_cfg_gen_data; } static const TypeInfo pci_bus_info = { @@ -240,6 +273,10 @@ static const TypeInfo pci_bus_info = { .instance_size = sizeof(PCIBus), .class_size = sizeof(PCIBusClass), .class_init = pci_bus_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_FW_CFG_DATA_GENERATOR_INTERFACE }, + { } + } }; static const TypeInfo cxl_interface_info = {