From patchwork Thu Jun 13 11:50:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13696695 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 F289EC27C75 for ; Thu, 13 Jun 2024 11:51:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8859A10EA4F; Thu, 13 Jun 2024 11:51:31 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="Xb5yws+c"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 540C010EA4D for ; Thu, 13 Jun 2024 11:51:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718279461; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DkCOJZ/wPtUvxbKR6iZK0j94vWla8EApzDXg+GJsTLg=; b=Xb5yws+cTUM5fjpCwVoZOZZ33zL8B1IKjq0lP/KmulDQ45E1PiEBWHzw5YU95uj0odiQHV Rf6I+cGUbAKscljTOF0PmvFHX1WOSn8DXRFjqUoO5BqqaHfOITNL4O9fiAMP6X7grc0Bdz qxurwbG1nbR9/l+1ANPTtNGgkFHYqkQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-262-AUGMcqcnNwG3Oq6_INkeKw-1; Thu, 13 Jun 2024 07:50:58 -0400 X-MC-Unique: AUGMcqcnNwG3Oq6_INkeKw-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4210e98f8d7so1510005e9.3 for ; Thu, 13 Jun 2024 04:50:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279457; x=1718884257; 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=DkCOJZ/wPtUvxbKR6iZK0j94vWla8EApzDXg+GJsTLg=; b=X/c3gVN7bE9SQoctdpgsm6x+hHp+8uoquQ0Pw/bm2vt6BoPysYRmoEzvSUgltpG7vG yMsgIdpKn4zIi6wIQ3niTJZqtoz87MUK/OY/x2jq48cwcXiyFXO8opeU+OUCfqTJzlq9 24hNtzQKqrMdX+YWFMPPelQuIiwb5OW6nCSydyNtjr7M93VXOXwiL+bJG0w6ejvY8L3p L0eayZBBsfbIkOe4/Wh3PUefUKeg5IaV+cExZgpmPgejnOJWYS8KD8U8dFuDWSnY+OHR FJz1RqIC9vAaaNnmCNvJ+bKnkx8gE17TNxAX9+W9tuyPieLXzN8oZeBzD6uFnwe3djmw sz6A== X-Gm-Message-State: AOJu0Yyqabt1PyZ10EW6C9IiE2FRULbNM9Lr/qoOc9dfAQMKrDVRrHQk WKeI8/iISWD+8B2YkKG/EszS1ODDTOlJHsN8xV24y1h1O5CbHiqTE6gVg/bgJ1hC3C957l5ZCEL ovBIAUHT12fnadTlqzyHbRt3yKCZDptSkRV+BoDrhHquytZl9GOprkS+z/6zx6ASS8g== X-Received: by 2002:a05:6000:1845:b0:35f:e38:6758 with SMTP id ffacd0b85a97d-36079a587a3mr156397f8f.7.1718279456841; Thu, 13 Jun 2024 04:50:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2TEvywhfauVMW37zv3JfoMBzZNIERzrEKPTEghMv7QdmvZthOHWTnGztKiTfV2ZqUSTTNVg== X-Received: by 2002:a05:6000:1845:b0:35f:e38:6758 with SMTP id ffacd0b85a97d-36079a587a3mr156374f8f.7.1718279456563; Thu, 13 Jun 2024 04:50:56 -0700 (PDT) Received: from pstanner-thinkpadt14sgen1.remote.csb (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3607509c883sm1510620f8f.29.2024.06.13.04.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 04:50:56 -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 v9 11/13] PCI: Remove legacy pcim_release() Date: Thu, 13 Jun 2024 13:50:24 +0200 Message-ID: <20240613115032.29098-12-pstanner@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240613115032.29098-1-pstanner@redhat.com> References: <20240613115032.29098-1-pstanner@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Thanks to preceding cleanup steps, pcim_release() is now not needed anymore and can be replaced by pcim_disable_device(), which is the exact counterpart to pcim_enable_device(). This permits removing further parts of the old PCI devres implementation. Replace pcim_release() with pcim_disable_device(). Remove the now surplus function get_pci_dr(). Remove the struct pci_devres from pci.h. Signed-off-by: Philipp Stanner --- drivers/pci/devres.c | 53 +++++++++++++++++++++----------------------- drivers/pci/pci.h | 16 ------------- 2 files changed, 25 insertions(+), 44 deletions(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index 7b72c952a9e5..37ac8fd37291 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -465,48 +465,45 @@ int pcim_intx(struct pci_dev *pdev, int enable) return 0; } -static void pcim_release(struct device *gendev, void *res) +static void pcim_disable_device(void *pdev_raw) { - struct pci_dev *dev = to_pci_dev(gendev); - - if (pci_is_enabled(dev) && !dev->pinned) - pci_disable_device(dev); -} - -static struct pci_devres *get_pci_dr(struct pci_dev *pdev) -{ - struct pci_devres *dr, *new_dr; - - dr = devres_find(&pdev->dev, pcim_release, NULL, NULL); - if (dr) - return dr; + struct pci_dev *pdev = pdev_raw; - new_dr = devres_alloc(pcim_release, sizeof(*new_dr), GFP_KERNEL); - if (!new_dr) - return NULL; - return devres_get(&pdev->dev, new_dr, NULL, NULL); + if (!pdev->pinned) + pci_disable_device(pdev); } /** * pcim_enable_device - Managed pci_enable_device() * @pdev: PCI device to be initialized * - * Managed pci_enable_device(). + * Returns: 0 on success, negative error code on failure. + * + * Managed pci_enable_device(). Device will automatically be disabled on + * driver detach. */ int pcim_enable_device(struct pci_dev *pdev) { - struct pci_devres *dr; - int rc; + int ret; - dr = get_pci_dr(pdev); - if (unlikely(!dr)) - return -ENOMEM; + ret = devm_add_action(&pdev->dev, pcim_disable_device, pdev); + if (ret != 0) + return ret; - rc = pci_enable_device(pdev); - if (!rc) - pdev->is_managed = 1; + /* + * We prefer removing the action in case of an error over + * devm_add_action_or_reset() because the later could theoretically be + * disturbed by users having pinned the device too soon. + */ + ret = pci_enable_device(pdev); + if (ret != 0) { + devm_remove_action(&pdev->dev, pcim_disable_device, pdev); + return ret; + } - return rc; + pdev->is_managed = true; + + return ret; } EXPORT_SYMBOL(pcim_enable_device); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 9e87528f1157..e51e6fa79fcc 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -810,22 +810,6 @@ static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev) } #endif -/* - * Managed PCI resources. This manages device on/off, INTx/MSI/MSI-X - * on/off and BAR regions. pci_dev itself records MSI/MSI-X status, so - * there's no need to track it separately. pci_devres is initialized - * when a device is enabled using managed PCI device enable interface. - * - * TODO: Struct pci_devres only needs to be here because they're used in pci.c. - * Port or move these functions to devres.c and then remove them from here. - */ -struct pci_devres { - /* - * TODO: - * This struct is now surplus. Remove it by refactoring pci/devres.c - */ -}; - int pcim_intx(struct pci_dev *dev, int enable); int pcim_request_region(struct pci_dev *pdev, int bar, const char *name);