From patchwork Mon Jun 3 05:59:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: CLEMENT MATHIEU--DRIF X-Patchwork-Id: 13683248 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 lists.gnu.org (lists.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 9C61CC25B76 for ; Mon, 3 Jun 2024 06:01:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0jl-0006nk-WD; Mon, 03 Jun 2024 02:00:06 -0400 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 1sE0je-0006gx-R2 for qemu-devel@nongnu.org; Mon, 03 Jun 2024 01:59:58 -0400 Received: from smarthost2.eviden.com ([80.78.11.83]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0jc-000731-Ov for qemu-devel@nongnu.org; Mon, 03 Jun 2024 01:59:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eviden.com; i=@eviden.com; q=dns/txt; s=mail; t=1717394397; x=1748930397; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=hK7styFD7PCpSuTqw2+IHY/14iimk7sPF6ZR7mmO87Q=; b=dOIZIS5kTGzNLRllhHlXdvajTliOng8eDYPZvpmhUAumRNhJZfwnXkW1 BK0uhcpQIBmaGXlIgCl0NqiT147JPhPpbkKmcuMzvFB+908Q5fynScmeC agUyS8Et8/njHSKAOFDxi8O1FFTrcdty9WaTrC2zyEwjBzA9Gh8Q0hXi5 dzFV+pApBDut3G4K5hANtnZSt41PY74gsgr2HxVmHVX6qZdd3N+oSohSY 9rqzmNtKbIZ7WRVZsuKVsMtoGYHepEkjJ8vqGMn6jK2h6f5NlH6F5VRcS w6Gx+AMd5GCxueJkxbNxGgUSJGBnFUbW/s9XDeVkZbHvj73KWEV4a54BP g==; X-IronPort-AV: E=Sophos;i="6.08,210,1712613600"; d="scan'208";a="13763248" X-MGA-submission: MDHZAAo1OJOV+Fyug36ems18i4MkrNmeAB7tbqgwyCWfnLzNqzmMk1kQbgOMby6oYv/NunlRqpr5LAw18pC+lanF+biuFYha7ho4mQUh1L9jdRQcVfvUb0/JxFBogU854jiv7tn6Te0n4hPedCIZI3K9q8ZIb2wZMC+w5NfQq2x7TA== Received: from mail-he1eur01lp2051.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) ([104.47.0.51]) by smarthost2.eviden.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2024 07:59:53 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hf8DfcDxL9a3rhILDOvWp9Mj5ABtwXZo+apzN+9zUem/xsXAMa9YKgvwhI5CyWNrLwwWqfLR/1WgtIHF98c6fhWCwY+GZwnsMUue+GiWa9itfyVubpG6FkBngWjzlrXOtz52lwGDztr7zU9bf9Ig9SMatC75L0+/yZ/moNZ4wXNcgBhqRGkzNDHdyc9Ot3pU8Myn6lyfMep1qojDLMpVBOJB1JDXnlnl7vL9VIbhdcMDqB0anmrC3BTYWFWOehEaVSJir030GQZjmmPdhbt6PKzb740XL4CkkEP4BOOkD+fO1Gmypy8gY+ow0AKYVluaxTOToUgfoM9De0k36jtA8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hK7styFD7PCpSuTqw2+IHY/14iimk7sPF6ZR7mmO87Q=; b=dPNjoMUR7C93kgROOsPpfFz2oOf4i5ePQ21PjATpcHrfEfxUTdoZ54enYe56H4LBoOH4VuBe6q8W9l1UrbgS31HO7THPBDQafbTTMPbyo2c4bXDU4bvUiARMaO2zKXUNVsv8a7WgfBzseBronB7bXeseKS6uLdlkBKZx6x+7O4EP8LmS++9cmtfHH9yV7OWSaKwgbpUFNXNwzOoqnMgzHWy5bBXMKqIswXt17vm5PDjE/0txaJVdPJGhIJde8VwZioinJ4UZXbdj4WLFA1qki7eiHOr9PscuKcjr/1oVRYbzzUKfD1BrynWs5IB7RZKxddzifRbgOhDk2duBLAD6Ag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=eviden.com; dmarc=pass action=none header.from=eviden.com; dkim=pass header.d=eviden.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Eviden.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hK7styFD7PCpSuTqw2+IHY/14iimk7sPF6ZR7mmO87Q=; b=TGFxeGK/TNshkWUxHgW0ClDD7vIW3WmEWU236nFJabuwwn8HHU01gesKehq6YblpHNKdj6hKWDql/WuBRcW/x3uJXuD4TfTZUa8vMWDaaL+XuRGloUjSInF7f6inZ8H5v+v3gYVGFj2bj96N/YfjGeUytVIwGfiZypYrXI5ALKQrdunpIGHstpOfjBxH+ZB/gEqjjFd5zCz9fhmIfW8Y/XFzXfMpfZKWMSvDb2hSodCFpV+f5ScsNvUqoICy7em7e3stl8cM5AVOQEyX/J43RoaxdEY0Lh8jpLOSxaQwE+Hq6MTgDRzHKuf5Y9PUCfiBxyBxtvS4AJWVE6CFzzB+2w== Received: from AM8PR07MB7602.eurprd07.prod.outlook.com (2603:10a6:20b:24b::7) by VI1PR07MB6238.eurprd07.prod.outlook.com (2603:10a6:800:136::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Mon, 3 Jun 2024 05:59:46 +0000 Received: from AM8PR07MB7602.eurprd07.prod.outlook.com ([fe80::fbd7:ca71:b636:6f9d]) by AM8PR07MB7602.eurprd07.prod.outlook.com ([fe80::fbd7:ca71:b636:6f9d%5]) with mapi id 15.20.7633.021; Mon, 3 Jun 2024 05:59:46 +0000 From: CLEMENT MATHIEU--DRIF To: "qemu-devel@nongnu.org" CC: "jasowang@redhat.com" , "zhenzhong.duan@intel.com" , "kevin.tian@intel.com" , "yi.l.liu@intel.com" , "joao.m.martins@oracle.com" , "peterx@redhat.com" , "mst@redhat.com" , CLEMENT MATHIEU--DRIF Subject: [PATCH ats_vtd v5 09/22] pci: cache the bus mastering status in the device Thread-Topic: [PATCH ats_vtd v5 09/22] pci: cache the bus mastering status in the device Thread-Index: AQHatXs8uu4aQUIynkS7hn2PtCehRw== Date: Mon, 3 Jun 2024 05:59:46 +0000 Message-ID: <20240603055917.18735-10-clement.mathieu--drif@eviden.com> References: <20240603055917.18735-1-clement.mathieu--drif@eviden.com> In-Reply-To: <20240603055917.18735-1-clement.mathieu--drif@eviden.com> Accept-Language: en-GB, fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=eviden.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: AM8PR07MB7602:EE_|VI1PR07MB6238:EE_ x-ms-office365-filtering-correlation-id: 753f9ba4-419f-404d-c104-08dc83925f3d x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230031|376005|366007|1800799015|38070700009; x-microsoft-antispam-message-info: =?utf-8?q?kWrOMsiZGtZzt7hFbvGFvy3GRFO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wr1KYBHYUMY5S?= =?utf-8?q?QEjs3/T7PznglHhzglT0XGdRf+Pi1T4Dq0uWqtrUMOR3rUa6zxEH5UB6Pr8fXjMVj?= =?utf-8?q?e0VlCPQ76Yqk/AuXHJPSWv422wST4tR6p52w/TMok5ZgAiwSB3OYvm6avD5DMiL7g?= =?utf-8?q?G+0BZ1hYoQ0OutG/lRQRpjb2lOLzhtNfeKYSycHG2FCY4f5Q6tvDLz6jIjeNOUVbm?= =?utf-8?q?C3uFXNznrBJyYERNkdBDz5B9ZR9uznRtuV6IakhY/o8/rEEj0myCtpmXlmG16g/dp?= =?utf-8?q?AY7Szx6koGrh9WhjA6OEcGhupDw427REYsr63KiZ6+R1C6LnR7tssc6Km64YG31Hg?= =?utf-8?q?4gzJ7kQJFVp3+VZrAYErR6TlX6BMFn+Wu/i2VPGeDWKXDFCuwYQHiYrv1EnEyw4wq?= =?utf-8?q?1HpUIDO6UmY9mR6zq1/nQn/YxHqvNNMxVCw=3D=3D?= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM8PR07MB7602.eurprd07.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(376005)(366007)(1800799015)(38070700009); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?3l8GbVNFPCay3oM67b+RYCywUbIZ?= =?utf-8?q?T33ptzu3gxNUGapF0QDCpP+YbaTOHAr5Bo8X1K9GapSxy7+WPqVrRiemB7F7h0219?= =?utf-8?q?8e+cVUONEie7ysnSY33qgvRaAQ4hlnrP1iP37xVdiktgeXuXtgU6p00WT04G2AkJ4?= =?utf-8?q?zsk8Ojc/nitlf3P3k4D5jWp2AfMHsych/f24yyiEtMyj7HUpr7beg0dylm1UNIMC6?= =?utf-8?q?yofyXdHfuMsu4CU0BL12/iiDZS4c3/KJmrIcMcwvyLSFyLgfQ+9Gj5vI3tZS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ntz8gir5v/5457OZzV1Chw9BG0klHoi?= =?utf-8?q?a497Yk+QFM1LE4xrXIihA0KdL5TDbfQa4dGnAg4Xeurh8NlYxNgV7i0Z42DjdNcoi?= =?utf-8?q?ixtnHu8Ux61OQR2lC5VmbbMINvsDnEcrbhOm9N3mENA0nDIrENeJOH0OXbO7R7dDZ?= =?utf-8?q?NFrH3EVjpqmttWwbh0ahEHYtU+pTC/o9FH8zWeJrMe2P472XZs1DnkROImaAcHz4v?= =?utf-8?q?osSB2KI1fPRu4Cu6VmAtmoxMCqwzAPpIu5O07M54zD+Y3C8sFM6hOpyoy+4NAnSka?= =?utf-8?q?Z8uS2qI0HTpTC1WDng2gd8xyj2XtX8bB31FvinTO/i+951cF9DeCAUJ/IhYqDCAlU?= =?utf-8?q?CJQ/Y/gCBaZHmDFB23CiejA1yHm/49CH5L9gmPbPOKkLRb7kJhpkPXRdZS/REId+I?= =?utf-8?q?kgPCebwRLPtchvkMfDcy6loByZgobzvJzXDOGODgzUgJarng+cfk2Y8=3D?= Content-ID: <0330FBE49A40324C94D980484758CC6F@eurprd07.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: eviden.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: AM8PR07MB7602.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 753f9ba4-419f-404d-c104-08dc83925f3d X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Jun 2024 05:59:46.5829 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 7d1c7785-2d8a-437d-b842-1ed5d8fbe00a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 2itEcEgfnG1v3AXPuYUhWBqBPtGIjUCpg4LB4WRs4iiMqBaGzPFpUXBZzD52DQSJExhxLNJEfhpaJmwYa4KaiXo9oaMqP8z0wrC2nw4M87f13fp3n0qBSVLhIg2+DKJK X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB6238 Received-SPF: pass client-ip=80.78.11.83; envelope-from=clement.mathieu--drif@eviden.com; helo=smarthost2.eviden.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Clément Mathieu--Drif Signed-off-by: Clément Mathieu--Drif --- hw/pci/pci.c | 24 ++++++++++++++---------- include/hw/pci/pci_device.h | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index c8a8aab306..51feede3cf 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -116,6 +116,12 @@ static GSequence *pci_acpi_index_list(void) return used_acpi_index_list; } +static void pci_set_master(PCIDevice *d, bool enable) +{ + memory_region_set_enabled(&d->bus_master_enable_region, enable); + d->is_master = enable; /* cache the status */ +} + static void pci_init_bus_master(PCIDevice *pci_dev) { AddressSpace *dma_as = pci_device_iommu_address_space(pci_dev); @@ -123,7 +129,7 @@ static void pci_init_bus_master(PCIDevice *pci_dev) memory_region_init_alias(&pci_dev->bus_master_enable_region, OBJECT(pci_dev), "bus master", dma_as->root, 0, memory_region_size(dma_as->root)); - memory_region_set_enabled(&pci_dev->bus_master_enable_region, false); + pci_set_master(pci_dev, false); memory_region_add_subregion(&pci_dev->bus_master_container_region, 0, &pci_dev->bus_master_enable_region); } @@ -657,9 +663,8 @@ static int get_pci_config_device(QEMUFile *f, void *pv, size_t size, pci_bridge_update_mappings(PCI_BRIDGE(s)); } - memory_region_set_enabled(&s->bus_master_enable_region, - pci_get_word(s->config + PCI_COMMAND) - & PCI_COMMAND_MASTER); + pci_set_master(s, + pci_get_word(s->config + PCI_COMMAND) & PCI_COMMAND_MASTER); g_free(config); return 0; @@ -1611,9 +1616,9 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val_in, int if (ranges_overlap(addr, l, PCI_COMMAND, 2)) { pci_update_irq_disabled(d, was_irq_disabled); - memory_region_set_enabled(&d->bus_master_enable_region, - (pci_get_word(d->config + PCI_COMMAND) - & PCI_COMMAND_MASTER) && d->has_power); + pci_set_master(d, + (pci_get_word(d->config + PCI_COMMAND) & + PCI_COMMAND_MASTER) && d->has_power); } msi_write_config(d, addr, val_in, l); @@ -2888,9 +2893,8 @@ void pci_set_power(PCIDevice *d, bool state) d->has_power = state; pci_update_mappings(d); - memory_region_set_enabled(&d->bus_master_enable_region, - (pci_get_word(d->config + PCI_COMMAND) - & PCI_COMMAND_MASTER) && d->has_power); + pci_set_master(d, (pci_get_word(d->config + PCI_COMMAND) + & PCI_COMMAND_MASTER) && d->has_power); if (!d->has_power) { pci_device_reset(d); } diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index d3dd0f64b2..7fa501569a 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -87,6 +87,7 @@ struct PCIDevice { char name[64]; PCIIORegion io_regions[PCI_NUM_REGIONS]; AddressSpace bus_master_as; + bool is_master; MemoryRegion bus_master_container_region; MemoryRegion bus_master_enable_region;