From patchwork Tue Nov 26 11:22:02 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: 845560 Delivered-To: patch@linaro.org Received: by 2002:a5d:6989:0:b0:382:43a8:7b94 with SMTP id g9csp154933wru; Tue, 26 Nov 2024 03:24:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUEdtFB+1LwVE+GqCcteVO78advR2dR/39Tnaodfi2eyReGO8D1lxAQlb+PmpkYbD9oJEK0HQ==@linaro.org X-Google-Smtp-Source: AGHT+IEWLQyWfKYVSW9GA8z5FbrxqoKCuDnggVHSWaCkNx0I2JkHjHl1POdAnBdlVoXSpGi+eMTK X-Received: by 2002:a05:622a:5805:b0:463:eef:ba30 with SMTP id d75a77b69052e-466a3bb2fd0mr51340961cf.20.1732620251174; Tue, 26 Nov 2024 03:24:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1732620251; cv=none; d=google.com; s=arc-20240605; b=UOys54PZf2FHlYq/PMh6CNwqPcR0RwyqbOK7A2GzwTSjqkS/1TvnTr1SDzJHKlUfgA e6c1gbDyi8LVf6ICzdq43T+66UOKcSKTKw9r3/NC4PfZE+epd4s863FwHZtbHEyfSj2O Q3sCIa0dGyIAHUTWiNxXQqBipp1upQCPtBsIcw9JILHMT0EnyIfq0qNXl0qNK1jINjjr eGcsD1XnBFAQx9PtLNLLJWufHgnXKXVr6o6+T72HUxoklkvF8LhWq3asKRcLtPhySKXM yDgroH0WdYIf/1N/9aMAe5fujCZBewiNYFF9sOlB9RnLE7B7Frmfsng1gsguCMIUPXbl 69rQ== 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=ym7MlPUFYz2GU5YCplhDtE7b6ovE3xgVe6aZRCcPdv4=; fh=siS/4HMv/4Bjpv+J3MqwgZ5TPB6jtxhL8giIGJt6+cQ=; b=hNIDcWryUdk+VewgdMC4SRnUm+MoDYv2V0R17GYD/bqczsteU9K+qlMclqJJog5pB8 BsTy+OVBkM+TKFrDma51JOaohOY8S/4+oW+s+XThNONn47cBEac+eftAGZ44I7mdyl9w tL8DbmrXluPkavOj+NQVbgNFo2R7Oiqd1u48BNcqjhsQ4790DgsXet2KQje8s+tkSoXd a0uvm2ApjCrXFW7H+cMm5qeHEoH8FNW6hAw6v9ET8b5K2dy2yrlyCGv01f1OCy3Ki2nS 2USiCoVmRvPia+bpBzNuM6s54dB+I3rV3Ow/17935yhd1Y3U3g0Y+1pTSSeoCQTjMdAA tT8g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O269jXpe; 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 d75a77b69052e-46693b31379si13760461cf.6.2024.11.26.03.24.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Nov 2024 03:24:11 -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=O269jXpe; 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 1tFteX-0003ok-W1; Tue, 26 Nov 2024 06:22:46 -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 1tFteS-0003mu-L0 for qemu-devel@nongnu.org; Tue, 26 Nov 2024 06:22:43 -0500 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tFteM-0002dm-Tg for qemu-devel@nongnu.org; Tue, 26 Nov 2024 06:22:37 -0500 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-434a8b94fb5so1170305e9.0 for ; Tue, 26 Nov 2024 03:22:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732620152; x=1733224952; 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=ym7MlPUFYz2GU5YCplhDtE7b6ovE3xgVe6aZRCcPdv4=; b=O269jXpeoMK9d1++iTv+YTvOFcSfjM9awFg3fi93MDx5LY5PIBYYL2fxJTNi/PeMWK x2kewtuNbVV/z1r6AvUz2mE8nnoIq27syZTxNoddQktPcmloj1pmUQjuFdR78DlCsOyN qjD3N0wCN4BXh/mWKHZYo19e3OsqHUC35LlXpXIteTjvVTBo06DaQHd1M2V3k3GJMbZo JsEeAtCeKrVL1ZmCAsz8mgrJqS+aHGbAgIzsytwNqskzatFWdf9oX6KUy5eSLVAYza0y S1xyhxT51OyYJTmSyUpSn/9iUDwkN5CYQT8mWDUn+4Rgf/edkkQqEIzdgoH4nq77KKN7 FFqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732620152; x=1733224952; 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=ym7MlPUFYz2GU5YCplhDtE7b6ovE3xgVe6aZRCcPdv4=; b=rKGiiqfEM2WqwRnq5WjlBvtohAPAWM8dUgR2lEtG3WITwOSow7w0Bj6yDYSKA+lbI+ xP4EjUDEFnY1eZZY2tNrYMCsCKl0u87MQQBoKfSEI1E8JOQAzwJxBQKE4ZeDYG1w+1Cl j0r+pF+q/zn4PpY2tfnUSqznDjqHPk2n38GD+lNuKl7efSYzgUP//z/ZeMmXpXHlOKvj c0rejp9FM1zt/3ib8BCd9gYXJaDXfLDXknwiKpTDYSWymX9LqsbFR72bsdG/igUDeTxf GBYfOo3qWryr1BWSQa8Y/msn4DmpQeYTQu/Sh8uG6CAWCq5vjWkWx2H1zZwngwU2b4a+ 8J/w== X-Gm-Message-State: AOJu0YzwLYZoh5n3X2KrlX5g8DVd7TkE58j9l9fAZLQmS7qiZ7lDUfvV njpQzeq3djOwFV2nokLUfqPwx0SlhFbKsiYuphTSLajoChy8Bon/ivE5Z6KJh6W5Lbn2A/r/PRf s X-Gm-Gg: ASbGncvi2ZczQ4XJIWT6jjGCEmoaezyEXiUeOQvedoON+6SjPvwsooTdcLW1X97/R8h zZ/Bl4LVQOMEW+GSrjiRHLfOLFaZl4M/tR0NKbd9F4eT14nldejEwyJIIts/W1tZx6cnKk9c5RO 3oqLqha1OTTv4K6ATRPrl6LgntkYmvt1vDQR4SyVNRv+h0x4A/dw71MsgS06kWCVDe1daNp7CUR xrYvBjM0wetYvjZhw0v6pb2YecuHAXhJLj8jAwZqtLcyUjA6o690L5CBeRWiqgfc/mgyNAt X-Received: by 2002:a7b:c85a:0:b0:431:15f1:421d with SMTP id 5b1f17b1804b1-434a4eb786dmr23408865e9.16.1732620152605; Tue, 26 Nov 2024 03:22:32 -0800 (PST) Received: from localhost.localdomain ([176.176.143.205]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3825fb3134bsm12970699f8f.58.2024.11.26.03.22.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 26 Nov 2024 03:22:32 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, qemu-s390x@nongnu.org, Thomas Huth , "Michael S. Tsirkin" , qemu-riscv@nongnu.org, Marcel Apfelbaum , Peter Maydell , qemu-arm@nongnu.org, Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH-for-10.0 v2 03/13] hw/pci: Factor machine_refuses_bar_at_addr_0() helper out Date: Tue, 26 Nov 2024 12:22:02 +0100 Message-ID: <20241126112212.64524-4-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241126112212.64524-1-philmd@linaro.org> References: <20241126112212.64524-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=philmd@linaro.org; helo=mail-wm1-x333.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=unavailable 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 Since we are going to re-use access to the MachineClass::pci_allow_0_address field, factor the current code as a new machine_refuses_bar_at_addr_0() helper. In pci_bar_address() invert 'allow_0_address' logic as 'bar_at_addr_0_refused'. Signed-off-by: Philippe Mathieu-Daudé --- hw/pci/pci.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 1416ae202c3..e05f8a828bb 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -520,6 +520,13 @@ bool pci_bus_bypass_iommu(PCIBus *bus) return host_bridge->bypass_iommu; } +static bool machine_refuses_bar_at_addr_0(void) +{ + MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine()); + + return !mc->pci_allow_0_address; +} + static void pci_root_bus_internal_init(PCIBus *bus, DeviceState *parent, MemoryRegion *mem, MemoryRegion *io, uint8_t devfn_min) @@ -1472,8 +1479,7 @@ pcibus_t pci_bar_address(PCIDevice *d, { pcibus_t new_addr, last_addr; uint16_t cmd = pci_get_word(d->config + PCI_COMMAND); - MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine()); - bool allow_0_address = mc->pci_allow_0_address; + bool bar_at_addr_0_refused = machine_refuses_bar_at_addr_0(); if (type & PCI_BASE_ADDRESS_SPACE_IO) { if (!(cmd & PCI_COMMAND_IO)) { @@ -1485,7 +1491,7 @@ pcibus_t pci_bar_address(PCIDevice *d, * TODO: make priorities correct and remove this work around. */ if (last_addr <= new_addr || last_addr >= UINT32_MAX || - (!allow_0_address && new_addr == 0)) { + (bar_at_addr_0_refused && new_addr == 0)) { return PCI_BAR_UNMAPPED; } return new_addr; @@ -1506,7 +1512,7 @@ pcibus_t pci_bar_address(PCIDevice *d, mappings, we handle specific values as invalid mappings. */ if (last_addr <= new_addr || last_addr == PCI_BAR_UNMAPPED || - (!allow_0_address && new_addr == 0)) { + (bar_at_addr_0_refused && new_addr == 0)) { return PCI_BAR_UNMAPPED; }