From patchwork Thu Nov 21 10:01:52 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: 844672 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:8b:b0:382:43a8:7b94 with SMTP id m11csp2175691wrx; Thu, 21 Nov 2024 02:02:08 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU3VzVfthDxNcd83kXC248Ep3/LZSmp8ce1zH4QiK0nT7+7W7joW6G5G6MJwdAyzbWnv834Kg==@linaro.org X-Google-Smtp-Source: AGHT+IGc92HFh3S8T5uuvQHg96KDJb8o7dr+jjlz5kXIIoZdzu41HPWCezLitLDqbS0l2EbBJNB8 X-Received: by 2002:a05:6102:b10:b0:4ad:4dd5:2b31 with SMTP id ada2fe7eead31-4adaf411f8amr7273384137.3.1732183328478; Thu, 21 Nov 2024 02:02:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1732183328; cv=none; d=google.com; s=arc-20240605; b=AixVTSFeLDJg24PV3xLxh85oN5VD9e/LJZLxoAxTNbR19O6xWUhbeclYIoyXtXvWrW BOBQ4Chw1kzP3Iip/+cd7R+134+TzzsGXim0NqNvFthYp+I/GI/avFcbc3UuVGsjBB+r 2IK4qGHLqw2TTRU4C0yXBd8/azh7hbLr0j+4WLeit91IZ6mF0TlPSkFChhgH/ZTBU25w KzijhUfKXqqFODJi28T60h/gM3dfXegKEtC65cHVWEEl4G3xtSh9f9hvC0EseA44ETn4 Q+YJbpxg+bzydtGot3JkOwGyedp28rXtTgZglWjV7XZAQutvyIhn8qVvCwciKSGR+SmZ 4cTA== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=pGj58m+Vwzu7KfW3YTaiVXOTXVXViIn2zLD/4MTPWG4=; fh=00hne69IVoSTs8u+VtqwijWAgJWj3bC1xdJVAKWf3KE=; b=QNcaq8TnAd6fICdVK/YAkas2jxrZgkRpsPwQmvndyDsLLN78aCWD6IhQalaQrF2p7A dFABR8JLqLl+2HLZPpeyFXAMRIgcb7QSzKM2yeMvFSPe4M40AdwUoL4lmUYj25z4bIQd QeZzTXEZB7na5Igc6n5J8zst70h7npipI1LajkNDLx4KmCgs433H5cmLpx4vddEMFE3u hKXAXHYYt3uRCIVr+16XxWbxV3vv+oGgpWgyubiOq73RQYg0Qw7gD3/O+lBU7Mk7pdvc OVKUULlzK9a6sxRD1G2+uTgHDbuDiFjCymcMAtE+mDg9ClR2GpZ2WqIs4bme02l53nTW IS9Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HTS9zP5x; 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 ada2fe7eead31-4adbe45162csi675536137.309.2024.11.21.02.02.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Nov 2024 02:02:08 -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=HTS9zP5x; 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 1tE40i-0004Ae-9i; Thu, 21 Nov 2024 05:02:04 -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 1tE40d-00040a-PC for qemu-devel@nongnu.org; Thu, 21 Nov 2024 05:02:01 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tE40c-000692-2F for qemu-devel@nongnu.org; Thu, 21 Nov 2024 05:01:59 -0500 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-3822ba3cdbcso492136f8f.0 for ; Thu, 21 Nov 2024 02:01:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732183315; x=1732788115; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=pGj58m+Vwzu7KfW3YTaiVXOTXVXViIn2zLD/4MTPWG4=; b=HTS9zP5x8DoTlC3Bd1/fpfPBOMzno3FDn5pFSjAkhBywRt6YVzXfJ6x3jPF5+POgrm hyRcpfmfa5nQvamcYJxlPDvgcgI+V8Pnj2gR4wrUVaNTjR+yC50sbV24bXiPvsSuqrDO 2gVza+WfYhTjKs+aIC8DaYVqY94oPKReRhBZhhxMAOtj2GJyKZkpv9/Qm+O3WJjRR2kc 1FbG56H5Z8UKjj+kW2j1u+Auzb4PodOZIMEgrWywjGQ+7V60La02kcU287oa1QbVja0k cTYozFVTVARpPrBfvcH2NxHemZgmWz+rlBhAWQ2lkbPWOzkg4I7zV3M9DgOSBZVcZKg4 QH4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732183315; x=1732788115; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pGj58m+Vwzu7KfW3YTaiVXOTXVXViIn2zLD/4MTPWG4=; b=pFvp94UbBpj50EZDYItq8XBDjHUpoaeLsKwAnrpnXIkOSUBZtUipZpOKAwXXuMnWcU niLBHeA6ZYhEWP/6KKA5D0qA5rwdl/q1AtePLv9DkvsWLxhcKdezFZJHjzQxtDZK7yNM XAuGRzmnxN+cNUUSUZIMpmeIV0xqHhWmWy6PwAELCAjtxUeHB5MZMsPu9F58obKv40P9 WxAH21iQgZ483DnRuDjMv5UK6oXTZWFC5TxGbuNMfiaxFLPbFoG/n+891jm9d73xgyEI TqJBDWy91bLh4mQYB9gr/5xSGdZeHZyvYILENUWFZ9xS/EdY7LixXa9yg+KIdXEGek3d AhZA== X-Gm-Message-State: AOJu0YwL+ivWM/myIMUkBbR7aSdtfpnw30lODY0FJZcVXdVg6x644Fe3 PUYrYzqjWXwO73DkWPaxqWN+KNlp0sMySmPt3gF41vatHGkHxh3bF4gTMCiaTDWSAQyBNlRXnT3 T X-Received: by 2002:a05:6000:1543:b0:381:cffc:d40b with SMTP id ffacd0b85a97d-38254b15a5dmr4993596f8f.39.1732183315532; Thu, 21 Nov 2024 02:01:55 -0800 (PST) Received: from localhost.localdomain ([176.187.204.90]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3825494ca3fsm4486989f8f.111.2024.11.21.02.01.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 21 Nov 2024 02:01:55 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , John Snow , Bernhard Beschow , qemu-block@nongnu.org, Beniamino Galvani , Strahinja Jankovic , =?utf-8?q?Philippe_Mat?= =?utf-8?q?hieu-Daud=C3=A9?= , Peter Xu Subject: [PATCH] hw/ide/ahci: Check for PCI device once in ahci_init() Date: Thu, 21 Nov 2024 11:01:52 +0100 Message-ID: <20241121100152.65476-1-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=philmd@linaro.org; helo=mail-wr1-x434.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 object_dynamic_cast() is expensive; IRQ helpers are certainly a bad place to call it. Since the device type won't change at runtime, resolve it once when the AHCI context is initialized in ahci_init(). Reported-by: Peter Xu Signed-off-by: Philippe Mathieu-Daudé --- include/hw/ide/ahci.h | 2 +- hw/ide/ahci.c | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/include/hw/ide/ahci.h b/include/hw/ide/ahci.h index ba31e75ff9..f6d977610d 100644 --- a/include/hw/ide/ahci.h +++ b/include/hw/ide/ahci.h @@ -37,7 +37,7 @@ typedef struct AHCIControlRegs { } AHCIControlRegs; typedef struct AHCIState { - DeviceState *container; + PCIDevice *pci_dev; AHCIDevice *dev; AHCIControlRegs control_regs; diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 0eb24304ee..f2eb3b527b 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -181,14 +181,10 @@ static uint32_t ahci_port_read(AHCIState *s, int port, int offset) static void ahci_irq_raise(AHCIState *s) { - DeviceState *dev_state = s->container; - PCIDevice *pci_dev = (PCIDevice *) object_dynamic_cast(OBJECT(dev_state), - TYPE_PCI_DEVICE); - trace_ahci_irq_raise(s); - if (pci_dev && msi_enabled(pci_dev)) { - msi_notify(pci_dev, 0); + if (s->pci_dev && msi_enabled(s->pci_dev)) { + msi_notify(s->pci_dev, 0); } else { qemu_irq_raise(s->irq); } @@ -196,13 +192,9 @@ static void ahci_irq_raise(AHCIState *s) static void ahci_irq_lower(AHCIState *s) { - DeviceState *dev_state = s->container; - PCIDevice *pci_dev = (PCIDevice *) object_dynamic_cast(OBJECT(dev_state), - TYPE_PCI_DEVICE); - trace_ahci_irq_lower(s); - if (!pci_dev || !msi_enabled(pci_dev)) { + if (!s->pci_dev || !msi_enabled(s->pci_dev)) { qemu_irq_lower(s->irq); } } @@ -1608,7 +1600,8 @@ static const IDEDMAOps ahci_dma_ops = { void ahci_init(AHCIState *s, DeviceState *qdev) { - s->container = qdev; + s->pci_dev = (PCIDevice *)object_dynamic_cast(OBJECT(qdev), TYPE_PCI_DEVICE); + /* XXX BAR size should be 1k, but that breaks, so bump it to 4k for now */ memory_region_init_io(&s->mem, OBJECT(qdev), &ahci_mem_ops, s, "ahci", AHCI_MEM_BAR_SIZE);