Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp575371rdb; Mon, 15 Jan 2024 06:48:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFp5iSOtHP11jljPfS5AeBF5Z9Gq3ZBXYJTAEWJaldQ7owSHqvqhmS2OZ2/IwnoSmvBbis3 X-Received: by 2002:a05:6e02:152b:b0:360:8a7e:9c83 with SMTP id i11-20020a056e02152b00b003608a7e9c83mr5907562ilu.16.1705330134848; Mon, 15 Jan 2024 06:48:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705330134; cv=none; d=google.com; s=arc-20160816; b=b4p5G8JEN9/sr/DhBmNksLhCWlCMlg/NAAab1sppeqI2nqupofU0DPv/A+lATavLHM GuVCFuSshGsWnulckHYBp4VHFxrjg1c56TlVTAlaWbhPodc0iJCoDaEnoNy9GYJy5lGP 8ccO/ISz/NRnm4k7tq483klaAZB69qO5djfBL9o2qRDIWoFUBG8HlxpmPs7RqYugaKBp vWlmOrAJBmq1o1t8NXmlTKuh1mPPszoWWio4mQl2hjMy+AaOLGuRIbeqbkAGAbkY2SeN 1sCj0MZK4usxxFDIH3mD/UrStiZEhfb4sIXnQgixfGU3I1vFxpj5b7j/fe0GcbKev9TI p1Hg== ARC-Message-Signature: i=1; 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=RO0mZDJz5TK909+4LedW3qKsNhM3MJg2yInHziL/J8s=; fh=AY1J9PDScN0xrIvhrMJy8TMRSbPeq4owI1m0lsalYQU=; b=uIV2vCFjF3TSPmaxbJFQfDAUYdJOvFGzop53txMuENqN207jE4FxkoG4Nw/xf0i38T iQcXCJ+IDJ4fjMQHxX60NNRK2X+RFNNNoFfF8iiQYzO5rNeDJIgmphHXctatjZBOMd6M WRDTDvrhzjcjm+HYMVecv34Rh888tTmdkRWxlPYMmv9u2xHDf96FuHGTwnGTjbUMAuX8 NmuSIJfJqr8mzaY6YUzfyK/6Wg2sg2IBXoJ8eHxA9qgokpz42hfBsuJyrYjZiOkcUBCa 93AUxGn3GL2cVVYXvt+tdr6RIk9sELkcp4d9zpu//QzSM9ZhMAHYRz6UfSwLuo59v0/H HIKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=C0HHSfn0; spf=pass (google.com: domain of linux-kernel+bounces-26129-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26129-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 207-20020a6300d8000000b005c1b316d768si8984575pga.664.2024.01.15.06.48.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 06:48:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26129-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=C0HHSfn0; spf=pass (google.com: domain of linux-kernel+bounces-26129-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26129-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id E5EDFB20AC3 for ; Mon, 15 Jan 2024 14:48:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 84276179AB; Mon, 15 Jan 2024 14:47:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="C0HHSfn0" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 0F860179A5 for ; Mon, 15 Jan 2024 14:47:25 +0000 (UTC) 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=1705330045; 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=RO0mZDJz5TK909+4LedW3qKsNhM3MJg2yInHziL/J8s=; b=C0HHSfn0qZzHu/IAqsZ53H2L3xXeNpzULGhL2STwLlECph0/nohD/e/tN1QnCM5gnl+tYC QWURZVZEpS5SR9UICD2C07LJjikEbecsEFxvuId1OmdoPMI97ofhXR8ROJQ0gu7uOUWyFe 9jJJL/ZYEWuzgBIKanbmNlPDHedB6Iw= Received: from mail-ua1-f72.google.com (mail-ua1-f72.google.com [209.85.222.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680-9-iHSTusNGitpIQMXQploQ-1; Mon, 15 Jan 2024 09:47:24 -0500 X-MC-Unique: 9-iHSTusNGitpIQMXQploQ-1 Received: by mail-ua1-f72.google.com with SMTP id a1e0cc1a2514c-7cdaffe6b9aso377467241.0 for ; Mon, 15 Jan 2024 06:47:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705330043; x=1705934843; 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=RO0mZDJz5TK909+4LedW3qKsNhM3MJg2yInHziL/J8s=; b=X9AFvPh0x1COb4Pwp8et/I+2yS6HV+lTnTtJcjtNQ7UEXvPNWEhCYl+uEAYEOI9KqT mZhNeFhcLRPy4hKckqvAh3yc8MCNtr5DgyiPMozTCMVcbgv/mJhnNlYqAxLlCyxKNgdq xJM2kQfRglhgg0qw5Lb/NBCuaoGtSJWze5clbjuto6gFVIVlaxKFfIpWSxWrSrmXLR72 c4DA4zPGAyfDZ2+WuxoFptyhHTvfoyNZPAuPyQCqZSuKtEKsIVlsZuNo6kgNE5SajnGg +3vQW0sBcJzUYZTTKBEcinCCWs6HgovkfCk5aZ4yBpvOSNoIpK27bP2uIexqjlMY9w47 TVzw== X-Gm-Message-State: AOJu0Yw5kXEoiqYxxhebZ/elA2tQYmMYqhH8BNtCfJUBhsqbePylfz1k 4qBTvPYlco5tpk0QaaL7pD+RIF1GtDPKj+5YrakSnvl3e5C/Nvv9dSoUjoqHdiqcrjOBu/r2b3Z R8y0CbiL2Y3LHMeBE+RvLOGnJwYVGPy0a X-Received: by 2002:a05:6122:200a:b0:4b6:e3fa:7599 with SMTP id l10-20020a056122200a00b004b6e3fa7599mr4678997vkd.0.1705330043473; Mon, 15 Jan 2024 06:47:23 -0800 (PST) X-Received: by 2002:a05:6122:200a:b0:4b6:e3fa:7599 with SMTP id l10-20020a056122200a00b004b6e3fa7599mr4678977vkd.0.1705330043173; Mon, 15 Jan 2024 06:47:23 -0800 (PST) Received: from pstanner-thinkpadt14sgen1.muc.redhat.com (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id ne13-20020a056214424d00b006815cf9a644sm1020720qvb.55.2024.01.15.06.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 06:47:22 -0800 (PST) From: Philipp Stanner To: Jonathan Corbet , Hans de Goede , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Bjorn Helgaas , Philipp Stanner , Sam Ravnborg , dakr@redhat.com Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-pci@vger.kernel.org Subject: [PATCH 05/10] pci: move enabled status bit to pci_dev struct Date: Mon, 15 Jan 2024 15:46:16 +0100 Message-ID: <20240115144655.32046-7-pstanner@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115144655.32046-2-pstanner@redhat.com> References: <20240115144655.32046-2-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 the devres-struct. Besides this struct being subject of a cleanup process, the device-struct 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 1e5cf950775d..bf957f0bc5ac 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -411,7 +411,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); } @@ -456,14 +456,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); @@ -481,7 +478,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 66639dd754c7..0fb9e7bb0e43 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1953,6 +1953,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; @@ -1967,7 +1970,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) { @@ -1977,6 +1980,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; } @@ -2146,6 +2151,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; @@ -2153,6 +2161,7 @@ static void do_pci_disable_device(struct pci_dev *dev) } pcibios_disable_device(dev); + dev->enabled = false; } /** @@ -2180,12 +2189,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 7c2181677760..dbb76a3fb0e4 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -809,7 +809,6 @@ static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev) * when a device is enabled using managed PCI device enable interface. */ 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 641ee30f7d2d..a356bdcc14cc 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.43.0