Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1206442lqe; Mon, 8 Apr 2024 01:46:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXnOfwKT+t1B2rtT5RzScmDWJdKo9kk+iwEAJ/L0OZBIO9pl8afYmeKJ6HfYcomrQcFXucG+4PU+FA5BPj3jMGfZhxIR34jONRJn4fn+Q== X-Google-Smtp-Source: AGHT+IEx4VdiaWq+kNhLudpOQvhSdwJF1ZuAzQsQmsSIv3VkzJbFxi18S54hYabJIEbJveArLdMN X-Received: by 2002:a50:d796:0:b0:56e:2ebc:5c4 with SMTP id w22-20020a50d796000000b0056e2ebc05c4mr6000891edi.20.1712565991502; Mon, 08 Apr 2024 01:46:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712565991; cv=pass; d=google.com; s=arc-20160816; b=D0d7AzOqGxF6iXRj6sjfp8gv5JU+Df3EHeNVJSkaUefhxEpdjyEwbDTsprE+F+Kh7u YUPKUEGxuaqLElAc3ZozgH2Vg+mPRupF2ZiBwf9GV9lBDQol9D4rWwtrXhexv3uAPca3 JflckoRoivw7L3FAyp7t8e0TN2BtFEhNxcyit5vOpyu8x0qG3Kiwop/qOfPUksHogMIv V9vdF/Dt+4aShqBPAaOXWQHk4uOtgT+gLeSayz2nY8z0fv7n7gWzwvOxqyozNTVL2nWb FjBz1f9OKZMHEac2Sdahl97ZPYghhGEY5twbA5LsSYI6swOzrCq81NC6NZ9uZdWPqPfL ux+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=HBYxescmGlqJZbkhxXkrYbSUutHFKaQyU2GxTiA6gSQ=; fh=zUUwy8aA01LrJm17zeq2y70iiByRmMjfnhVnYLGvEeg=; b=PXpZBOr4V0yRg3dYXU9/MOwf9tC8lTacbxjQvXXkaMtlhas3oidlhzvFgZ3JnEXTeF 8rLCoYftowKWP+j/F9snqrA6ohVt8Tau6zi1aaf4NeSRTVqB+yZYQsnbFsG1kpheu+jG dcvy0c15EVEg2DZHoXDuSwZGSKODnmES02wbJSG4UhUX8bSWhNdhOrSAZzpt3qGTGWaa YgCdkJFtTq/6dje856tfqWp0qnxnjK2cvfpWpalhrY7D9AdHcYlzAGpi2MJlpBCPmOvR dm+wFFx8B7fequHAiTd6jNE/qHCu8gfPDhQ0T6Xu3eHdYE+oXowtXQQ4rLm+o7AaK72J CyWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZwocmTi5; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-135066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135066-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id fd3-20020a056402388300b0056e2a14f4adsi3388285edb.626.2024.04.08.01.46.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 01:46:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZwocmTi5; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-135066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135066-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 15AAE1F22C1E for ; Mon, 8 Apr 2024 08:46:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE7F23A1BE; Mon, 8 Apr 2024 08:44:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZwocmTi5" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29F234595A for ; Mon, 8 Apr 2024 08:44:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712565884; cv=none; b=qkbpeajcMqsF6VaHSQ0CmMLtaAEu8MCvaFb5Y+Zqtlrytu7a5HF3+g90MYJugaVcmGgiNUD1sIq0Xo3VD9sK0Ddgtr3DwXjSkWYVAnilWvLqNM1/xt4lQyoQhq7EDzTodK9HIs1ISnrwldJ/PRqa0Wd+7/IFjCbP9gl/MEZSlJg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712565884; c=relaxed/simple; bh=ph/4KcAsTi43ubN861sbaEt6JoUBoxu5rEFqsUZSaCk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ANya5WXOOdlWSSGCsObsmZGspQzEve/7zbhZEbs1HcMU6KNouuBZHUX1tb+m+GFEcPgn6d2A5zB1jHkpVr4uG2hm6ONd1/wfUUAz0/w8zUYanicmpClSVTLzdsSxYEJ4gy1qG8sMvESBx0furaj8rXZniyxXi5zLT7H7620FFdc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZwocmTi5; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712565881; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HBYxescmGlqJZbkhxXkrYbSUutHFKaQyU2GxTiA6gSQ=; b=ZwocmTi59N1GRS+VdlBAinkZ0cAKVKFapAVvO1EHpTgxFkUeMqYJTodeTNpOcimPgvggvw CFe5ep56MsaZCu4L98Hi8/I0nnfFFI5VPVv+FMPi2kX3qh3JVoAbc84oCbVt84I1RgFrM2 dkwmnSe/cZFqptM5/XKgfnclwY2LaUE= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-325-A6ZpCqy2NGemZCqrOsEyUQ-1; Mon, 08 Apr 2024 04:44:39 -0400 X-MC-Unique: A6ZpCqy2NGemZCqrOsEyUQ-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-78d699bb0b9so5134885a.0 for ; Mon, 08 Apr 2024 01:44:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712565879; x=1713170679; 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=HBYxescmGlqJZbkhxXkrYbSUutHFKaQyU2GxTiA6gSQ=; b=NbFkKRaQIfXWFEM8gGT8OEWnpeClisZs4Id2ZVeAqIZdYlqqIXI3/Dvh5w6MZt2ij9 XAORoYU7LMpIv0iopQ6ZyOUykAtzs6qEW0DoDbnOl0IpwLhgxmpD9dfAPPTJZtTEfvO+ AAMe83Jjb98Po1nmeyVblkfhGvpAoJM7OoxoA9dVKe5Nv6AG/7wNC/dTjZYNaiL2W8Hj R7y97joQ6EF1y0C+91XOQfQxJlY8PkbXyyfOP8/cMjZBxiVGz3SEuCPxBq2fNmhyEuw9 KP0H+EO8xsrb3+WOz0uF+2BaNZOPuw12fpTDFjD69HZebIcbDl2xtgjY15eKhP6jvrmz tY0Q== X-Forwarded-Encrypted: i=1; AJvYcCVSOhzhK4kKNtTAVwcS5dedBiKYDgZgCo8CeR7evZ6hVOQTWjnf3btstc0jxKAiLzU0skEN3e4LRQ2sCuCBPeQlqtE3IRGQsQboea8g X-Gm-Message-State: AOJu0YzEhnnH1RJC+SuEdAfTN7wI8XhH/nFcAH3sLy1UKkmT01dmJc6v wqSpXwEmENAN4exXXzBKh3JK+WJiYipSlZ0feAKnoseur4kfxK7ZWBe27nxVNdqGP0wtMVKfKeY C3fun15vWEwgk/1mBABQIGTtoYLalYuBjGTcfH+YcHZcsWIw3CC/7XUuyJ0TsKQ== X-Received: by 2002:a05:620a:4014:b0:78b:c3a2:26ce with SMTP id h20-20020a05620a401400b0078bc3a226cemr9387797qko.7.1712565879330; Mon, 08 Apr 2024 01:44:39 -0700 (PDT) X-Received: by 2002:a05:620a:4014:b0:78b:c3a2:26ce with SMTP id h20-20020a05620a401400b0078bc3a226cemr9387787qko.7.1712565879044; Mon, 08 Apr 2024 01:44:39 -0700 (PDT) Received: from pstanner-thinkpadt14sgen1.muc.redhat.com (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id oo15-20020a05620a530f00b0078d54e39f6csm2036989qkn.23.2024.04.08.01.44.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 01:44:38 -0700 (PDT) From: Philipp Stanner To: Hans de Goede , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Bjorn Helgaas , Sam Ravnborg , dakr@redhat.com Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Philipp Stanner Subject: [PATCH v6 05/10] PCI: Move dev-enabled status bit to struct pci_dev Date: Mon, 8 Apr 2024 10:44:17 +0200 Message-ID: <20240408084423.6697-6-pstanner@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240408084423.6697-1-pstanner@redhat.com> References: <20240408084423.6697-1-pstanner@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The bit describing whether the PCI device is currently enabled is stored in struct pci_devres. Besides this struct being subject of a cleanup process, struct pci_device is in general the right place to store this information, since it is not devres-specific. Move the 'enabled' boolean bit to struct pci_dev. Signed-off-by: Philipp Stanner --- drivers/pci/devres.c | 11 ++++------- drivers/pci/pci.c | 17 ++++++++++------- drivers/pci/pci.h | 1 - include/linux/pci.h | 1 + 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index d9cd7f97c38c..623e27aea2b1 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -403,7 +403,7 @@ static void pcim_release(struct device *gendev, void *res) if (this->restore_intx) pci_intx(dev, this->orig_intx); - if (this->enabled && !this->pinned) + if (!this->pinned) pci_disable_device(dev); } @@ -446,14 +446,11 @@ int pcim_enable_device(struct pci_dev *pdev) dr = get_pci_dr(pdev); if (unlikely(!dr)) return -ENOMEM; - if (dr->enabled) - return 0; rc = pci_enable_device(pdev); - if (!rc) { + if (!rc) pdev->is_managed = 1; - dr->enabled = 1; - } + return rc; } EXPORT_SYMBOL(pcim_enable_device); @@ -471,7 +468,7 @@ void pcim_pin_device(struct pci_dev *pdev) struct pci_devres *dr; dr = find_pci_dr(pdev); - WARN_ON(!dr || !dr->enabled); + WARN_ON(!dr || !pdev->enabled); if (dr) dr->pinned = 1; } diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index c0c1ee17a06b..9f1419bac9b9 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2011,6 +2011,9 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) u16 cmd; u8 pin; + if (dev->enabled) + return 0; + err = pci_set_power_state(dev, PCI_D0); if (err < 0 && err != -EIO) return err; @@ -2025,7 +2028,7 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) pci_fixup_device(pci_fixup_enable, dev); if (dev->msi_enabled || dev->msix_enabled) - return 0; + goto success_out; pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); if (pin) { @@ -2035,6 +2038,8 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) cmd & ~PCI_COMMAND_INTX_DISABLE); } +success_out: + dev->enabled = true; return 0; } @@ -2193,6 +2198,9 @@ static void do_pci_disable_device(struct pci_dev *dev) { u16 pci_command; + if (!dev->enabled) + return; + pci_read_config_word(dev, PCI_COMMAND, &pci_command); if (pci_command & PCI_COMMAND_MASTER) { pci_command &= ~PCI_COMMAND_MASTER; @@ -2200,6 +2208,7 @@ static void do_pci_disable_device(struct pci_dev *dev) } pcibios_disable_device(dev); + dev->enabled = false; } /** @@ -2227,12 +2236,6 @@ void pci_disable_enabled_device(struct pci_dev *dev) */ void pci_disable_device(struct pci_dev *dev) { - struct pci_devres *dr; - - dr = find_pci_dr(dev); - if (dr) - dr->enabled = 0; - dev_WARN_ONCE(&dev->dev, atomic_read(&dev->enable_cnt) <= 0, "disabling already-disabled device"); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 040ed2825554..2b6c0df133bf 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -823,7 +823,6 @@ static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev) * then remove them from here. */ struct pci_devres { - unsigned int enabled:1; unsigned int pinned:1; unsigned int orig_intx:1; unsigned int restore_intx:1; diff --git a/include/linux/pci.h b/include/linux/pci.h index 0f203338f820..95cdd1bc73c4 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -367,6 +367,7 @@ struct pci_dev { this is D0-D3, D0 being fully functional, and D3 being off. */ u8 pm_cap; /* PM capability offset */ + unsigned int enabled:1; /* Whether this dev is enabled */ unsigned int imm_ready:1; /* Supports Immediate Readiness */ unsigned int pme_support:5; /* Bitmask of states from which PME# can be generated */ -- 2.44.0