From patchwork Thu Jun 13 11:50:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 1947352 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=CLo2ThCF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=139.178.88.99; helo=sv.mirrors.kernel.org; envelope-from=linux-pci+bounces-8718-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [139.178.88.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0LRP6Wgzz20KL for ; Thu, 13 Jun 2024 21:54:09 +1000 (AEST) 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id ABDA1282F68 for ; Thu, 13 Jun 2024 11:54:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 849D91459F3; Thu, 13 Jun 2024 11:50:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CLo2ThCF" X-Original-To: linux-pci@vger.kernel.org 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 01DF51448C6 for ; Thu, 13 Jun 2024 11:50:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279451; cv=none; b=mFth5C2qyy4J0rsMJVHTa/LrkYYOHlL5LwhvUhPGXHwIGgXYsgUhxwlIXTTvvmE6jiwgTK0/pBnPxrPIcdQ2gcNq0xVZ+vVwLaBwbFhslyqCFciPgXSNx+ymIUbd97lBYGLadWw8ItLt8lrk+P37fR9Bcq5zfMDtTPRj1sTGgV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279451; c=relaxed/simple; bh=uxWR+cyvQnS6F+Ku7i7pYs3ZA+OagBoxvbut16jkiT8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iVkvckM0PJ/6CuW3OEeIAfe+Tv6PosOfkEAUKOblgyO6ytf/gkfqVP/iXLwcSIW50QB5PDj5aUh7F1qaMFqTOQ05gpPlNLjikWin0NSb3AgLGLCCBBLMUMRubVWBpxDbrXbI9V/vExd2b4iNXkU+DHO12Swnt5FO1SLq0H2QxA4= 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=CLo2ThCF; arc=none smtp.client-ip=170.10.133.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=1718279448; 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=Oyizp71aDVZTVSj1hEgGPWD4Zgvxaje3MhAhMHAAQDo=; b=CLo2ThCFKPSJDssi4eH+TlfhKKari8ckyIxBPwD/ThJY8NLwSZPneR7k7eDb1ilzBrNzST zGr6yWu4x40ZK1aAgelIyyi29NvB0yHdC+vamx88EioxDbbD/3sYeKpfsmEbtDNjT89FLe UkxThevCmA2b8YRDJ0lIKHzlo4kIUNY= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-kip71_kBPkOkJXbyLM6BTg-1; Thu, 13 Jun 2024 07:50:47 -0400 X-MC-Unique: kip71_kBPkOkJXbyLM6BTg-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2ebe9456e2dso435521fa.2 for ; Thu, 13 Jun 2024 04:50:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279446; x=1718884246; 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=Oyizp71aDVZTVSj1hEgGPWD4Zgvxaje3MhAhMHAAQDo=; b=q0mW7rB9pgHwEYEsXnCTPbxESAeZtvGXTeYJxBME8Qf1E0wjyX55EJvt3NIaeKkyYu 9aF98zPiEv/+/q+MaGLIC/Z1SmyVn9TMT5qakz20Tuza2V4rvbIbWJZh2IqP5CAH6eyN k5A7f+zg7IKe4BG+9wnAEBBR6UjL2ZSJgNQ3hYWX7xIL4s4s7tp/hUUalgh78oX+4er6 jCK1SoR9F2xNcSU7RYlHZCj8WMm2apZzKY8S83e/hM74ibLpJ8GjQC32yRf5VWL5fhZm KKrAfdcPv2iEqxKnoUH8zWpaQhj1ejvI8ll0dUCB0E6gI0nCHdgsp3Ox6riNW4jD5Dip MYOg== X-Forwarded-Encrypted: i=1; AJvYcCXFDKjRgRWD4/0ofka/mOQPIRyXJwVYe1LOz/h2mtHxhzYPyTopGMtPFJmQ9Yds5KIpC8g9QUoQcsHn3Moolgvr/hZCX6ofsOgK X-Gm-Message-State: AOJu0Yy7cHXEQQ0PM0qAb6jhzfx9x85WJYuU1PbNlEawD+GrYMkD3cFl LetatbQb/diUVMv24cp0oMsG17oPwG4CiGjrzObz3OPAVfWwaejHZErK3MxEWM5k3ga8lrWXAen KGSKRoRsIsWr0V6rWexXv+s+sGXfsnMgJ+ABNiD1cd9DfhRCpaZRT8XUB5g== X-Received: by 2002:ac2:4db6:0:b0:52b:b349:c224 with SMTP id 2adb3069b0e04-52ca59e8a34mr41632e87.0.1718279446136; Thu, 13 Jun 2024 04:50:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLhEgk5PVdiMFlFsN3ltE7pAoZnfjyVgZ6hFXz98dULDmP/AUIKfgL84nHKqB6KbULbimrYw== X-Received: by 2002:ac2:4db6:0:b0:52b:b349:c224 with SMTP id 2adb3069b0e04-52ca59e8a34mr41612e87.0.1718279445706; Thu, 13 Jun 2024 04:50:45 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 04:50:45 -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 01/13] PCI: Add and use devres helper for bit masks Date: Thu, 13 Jun 2024 13:50:14 +0200 Message-ID: <20240613115032.29098-2-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> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The current derves implementation uses manual shift operations to check whether a bit in a mask is set. The code can be made more readable by writing a small helper function for that. Implement mask_contains_bar() and use it where applicable. Link: https://lore.kernel.org/r/20240605081605.18769-3-pstanner@redhat.com Signed-off-by: Philipp Stanner Signed-off-by: Bjorn Helgaas --- drivers/pci/devres.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index 2c562b9eaf80..f13edd4a3873 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -161,6 +161,10 @@ int pcim_set_mwi(struct pci_dev *dev) } EXPORT_SYMBOL(pcim_set_mwi); +static inline bool mask_contains_bar(int mask, int bar) +{ + return mask & BIT(bar); +} static void pcim_release(struct device *gendev, void *res) { @@ -169,7 +173,7 @@ static void pcim_release(struct device *gendev, void *res) int i; for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) - if (this->region_mask & (1 << i)) + if (mask_contains_bar(this->region_mask, i)) pci_release_region(dev, i); if (this->mwi) @@ -363,7 +367,7 @@ int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name) for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { unsigned long len; - if (!(mask & (1 << i))) + if (!mask_contains_bar(mask, i)) continue; rc = -EINVAL; @@ -386,7 +390,7 @@ int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name) pci_release_region(pdev, i); err_inval: while (--i >= 0) { - if (!(mask & (1 << i))) + if (!mask_contains_bar(mask, i)) continue; pcim_iounmap(pdev, iomap[i]); pci_release_region(pdev, i); @@ -438,7 +442,7 @@ void pcim_iounmap_regions(struct pci_dev *pdev, int mask) return; for (i = 0; i < PCIM_IOMAP_MAX; i++) { - if (!(mask & (1 << i))) + if (!mask_contains_bar(mask, i)) continue; pcim_iounmap(pdev, iomap[i]); From patchwork Thu Jun 13 11:50:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 1947353 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZdNVIF+P; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-pci+bounces-8719-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0LRW4Tzkz20KL for ; Thu, 13 Jun 2024 21:54:15 +1000 (AEST) 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 D9EA91F24F96 for ; Thu, 13 Jun 2024 11:54:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1321A1474B5; Thu, 13 Jun 2024 11:50:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZdNVIF+P" X-Original-To: linux-pci@vger.kernel.org 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 659EF1459E6 for ; Thu, 13 Jun 2024 11:50:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279452; cv=none; b=EwZL59wA8UZBQL82hLcE6S3OeUm0P3dH3ppU/qMh73Px2q+YHTP5a3HRs7puWDHBp0wfEeZW8j9ld9nK7MbY3lIAwlupOYmLGhkWDR/4Ky7lRGFL4umO9SB83TnolZ+aT4RDPW9z/EU+AtNFiMKS8KHdqh7K5hSYHZ37hEa67ug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279452; c=relaxed/simple; bh=TgkR4Nl7UsfcnDus5PAQ/eglmpUMQS/oRcoljkpQuXI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sCQzTVxMUl90jPhAQT3gImeD6PNza2LvfnUrjbNm+px6vEgnViHojQgVXxIt5Oi3LF1kmYM3fNLES37quL4eihuEMz1ZgWsahO7MIoLYEolGqmpm+wTs8vyJPbz4y5qjf1YklZIWZg1Wt5DFB1sAy6TcbzhVXYkNCo4rvEnaY1A= 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=ZdNVIF+P; arc=none smtp.client-ip=170.10.133.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=1718279449; 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=qTRnfk+xncNuJMn54sP5qzAQh4gcZ4Sy3yYao6iQeYc=; b=ZdNVIF+PjrWZ/q07uXOujXwgtW0eY7cw6hVfZIdnysC0EaqqYSIEoJedkVg7+fqW94ST4d 5QmBPkrUcdVCIH6xRHgckUUJlQfjpJxSLNlUi7UWI6Z+x1gtJv+ACUh4UW5PqcCI98Uh2t 0IbIBe5jMhO8FWogNOMkOPUWBMCz/2g= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-4YoePO5JPauJ1_Ag6hDhpQ-1; Thu, 13 Jun 2024 07:50:48 -0400 X-MC-Unique: 4YoePO5JPauJ1_Ag6hDhpQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4217aad795aso1583135e9.3 for ; Thu, 13 Jun 2024 04:50:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279447; x=1718884247; 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=qTRnfk+xncNuJMn54sP5qzAQh4gcZ4Sy3yYao6iQeYc=; b=JNFcVV08ZcUjUUBsHU2y3zhvZvZMj1Sp77luyfbAkYpXVLar1KyrVnZa82mLxGN494 0IRc38JelGl/2MwZ6aeMbETnUCY3aWIZcHa3QrO0mhyqGwXVUJ9ZE4fpzdWTIINi+TDO CZ9DE6NLe+tJ6SMv7KVS3pF0B0jkISGPKxWwe/VywHtTLa7kioak0pXXgdwW21VvGnnI +8kO2+wkoRx1fBt+EuYuZDi9TzMxT4j40RtV01Utwom2ypaMp0R8hx4i3I3HCalfG93A B+8vHgcDXiUUtbO9VE4FSlTM0KqXsBYKNuNMoDDxU7oD/qE2U/HOOIfauTLpyG3v/4vs Xefg== X-Forwarded-Encrypted: i=1; AJvYcCUiFAtiYJzmuFg7QAoef329cPHEmCQ229KGWcIEQ22fjSHf/QWGLkt7E3NIDDkD5MNH43qOJRiYKtU7qnWlN09NPUxyfpqJND0i X-Gm-Message-State: AOJu0YxGrbbtbtWXXKdBAIDS0vHSfJiCGgN3arpTSMXkVzgo62EtquH1 lS6ODEr+f6WermaPWv7UOTlIvjwzLsApxS1hn6L7D/wCJQrYtBVK3beAPk8589A0tcpWX0HkYPG xIENejvG/yBzQMfbpGs1jrh7PVR+RcWK8/U3oVWBjzItgcTS2Rvf7QScAIw== X-Received: by 2002:a05:600c:350b:b0:421:74d4:f32c with SMTP id 5b1f17b1804b1-423041e1d4cmr1371035e9.1.1718279447048; Thu, 13 Jun 2024 04:50:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHv8ZBvdV4IZRRiIgJbZsBfiAJdHKRwnxvdFK5xMqJJnZPKz428Y6zIL/fRH5SPX2HOkbTO0A== X-Received: by 2002:a05:600c:350b:b0:421:74d4:f32c with SMTP id 5b1f17b1804b1-423041e1d4cmr1370945e9.1.1718279446627; Thu, 13 Jun 2024 04:50:46 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 04:50:46 -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 02/13] PCI: Add devres helpers for iomap table Date: Thu, 13 Jun 2024 13:50:15 +0200 Message-ID: <20240613115032.29098-3-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> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The pcim_iomap_devres.table administrated by pcim_iomap_table() has its entries set and unset at several places throughout devres.c using manual iterations which are effectively code duplications. Add pcim_add_mapping_to_legacy_table() and pcim_remove_mapping_from_legacy_table() helper functions and use them where possible. Link: https://lore.kernel.org/r/20240605081605.18769-4-pstanner@redhat.com Signed-off-by: Philipp Stanner [bhelgaas: s/short bar/int bar/ for consistency] Signed-off-by: Bjorn Helgaas --- drivers/pci/devres.c | 77 +++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 19 deletions(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index f13edd4a3873..845d6fab0ce7 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -297,6 +297,52 @@ void __iomem * const *pcim_iomap_table(struct pci_dev *pdev) } EXPORT_SYMBOL(pcim_iomap_table); +/* + * Fill the legacy mapping-table, so that drivers using the old API can + * still get a BAR's mapping address through pcim_iomap_table(). + */ +static int pcim_add_mapping_to_legacy_table(struct pci_dev *pdev, + void __iomem *mapping, int bar) +{ + void __iomem **legacy_iomap_table; + + if (bar >= PCI_STD_NUM_BARS) + return -EINVAL; + + legacy_iomap_table = (void __iomem **)pcim_iomap_table(pdev); + if (!legacy_iomap_table) + return -ENOMEM; + + /* The legacy mechanism doesn't allow for duplicate mappings. */ + WARN_ON(legacy_iomap_table[bar]); + + legacy_iomap_table[bar] = mapping; + + return 0; +} + +/* + * Remove a mapping. The table only contains whole-BAR mappings, so this will + * never interfere with ranged mappings. + */ +static void pcim_remove_mapping_from_legacy_table(struct pci_dev *pdev, + void __iomem *addr) +{ + int bar; + void __iomem **legacy_iomap_table; + + legacy_iomap_table = (void __iomem **)pcim_iomap_table(pdev); + if (!legacy_iomap_table) + return; + + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { + if (legacy_iomap_table[bar] == addr) { + legacy_iomap_table[bar] = NULL; + return; + } + } +} + /** * pcim_iomap - Managed pcim_iomap() * @pdev: PCI device to iomap for @@ -308,16 +354,20 @@ EXPORT_SYMBOL(pcim_iomap_table); */ void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen) { - void __iomem **tbl; + void __iomem *mapping; - BUG_ON(bar >= PCIM_IOMAP_MAX); - - tbl = (void __iomem **)pcim_iomap_table(pdev); - if (!tbl || tbl[bar]) /* duplicate mappings not allowed */ + mapping = pci_iomap(pdev, bar, maxlen); + if (!mapping) return NULL; - tbl[bar] = pci_iomap(pdev, bar, maxlen); - return tbl[bar]; + if (pcim_add_mapping_to_legacy_table(pdev, mapping, bar) != 0) + goto err_table; + + return mapping; + +err_table: + pci_iounmap(pdev, mapping); + return NULL; } EXPORT_SYMBOL(pcim_iomap); @@ -330,20 +380,9 @@ EXPORT_SYMBOL(pcim_iomap); */ void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr) { - void __iomem **tbl; - int i; - pci_iounmap(pdev, addr); - tbl = (void __iomem **)pcim_iomap_table(pdev); - BUG_ON(!tbl); - - for (i = 0; i < PCIM_IOMAP_MAX; i++) - if (tbl[i] == addr) { - tbl[i] = NULL; - return; - } - WARN_ON(1); + pcim_remove_mapping_from_legacy_table(pdev, addr); } EXPORT_SYMBOL(pcim_iounmap); From patchwork Thu Jun 13 11:50:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 1947354 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=N47oFeH1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-pci+bounces-8720-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0LS01rrRz20KL for ; Thu, 13 Jun 2024 21:54:40 +1000 (AEST) 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 4F0211F256D1 for ; Thu, 13 Jun 2024 11:54:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6F9B1482F3; Thu, 13 Jun 2024 11:50:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="N47oFeH1" X-Original-To: linux-pci@vger.kernel.org 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 0F5411474B6 for ; Thu, 13 Jun 2024 11:50:51 +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=1718279454; cv=none; b=rbfyJOaNGdAyLlzjmu9XhxD5ELsy+AIesgWQRmZBzkFuSZVKZQ6WsroJE2d6xy1Md46UWyRY6J5/Jz25yPFBq1q9WZzKwlem8Q4RGMmA245XLrCFoamqY62Hxs3t0QF6RV4P4qRQ8fpbOwdLKjvZ98DxoxBJokAjElyJpIu9bZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279454; c=relaxed/simple; bh=uWUzFsdvpSHc64lHKkPsUVgfWCCMYvJqUAk/DiCtcSs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ntcAjnAFDEpMs9yRvXBkcokC4C8vnvFnfvtDtEI6ZFftXWYJEuGTGRdaPMcZCqZ2WppI7T0vFqVMQrsgjUD/hJV65o6iLhtjuN5vq6UMX1oGN8yNZvUUW7QQ0LJ42I2hDYdG1A1xCwzmBwJI1aFENzEUZXb0qXFiu2k1yAWE5NI= 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=N47oFeH1; 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=1718279451; 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=owM7d9MOt/jRqhqh2hkOR6CRgSB25b9Tr8ToAYjipS8=; b=N47oFeH1BChznm1zV8b8bLKZoJGnx5MxftjyDSCf5bsNPjRm5GcN6L2fg97oNXZWa4aR4W zvyu3X4dXhlvFUdU13jS40FCjUM0ApB4S/ItM5DzXlBQP3nD3+c4HeudKXlS46vm+Ei2yO XgOqYaLc5kxwNVoaNI8SnFqb2wSiOKQ= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-I4tkmnKEMR-nVGKcEjzOzw-1; Thu, 13 Jun 2024 07:50:49 -0400 X-MC-Unique: I4tkmnKEMR-nVGKcEjzOzw-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-36073543200so107616f8f.3 for ; Thu, 13 Jun 2024 04:50:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279448; x=1718884248; 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=owM7d9MOt/jRqhqh2hkOR6CRgSB25b9Tr8ToAYjipS8=; b=WylfyTIZintg17hIWChGC3srgsSq4VM1sJ4Pc1CPBaSdr8RJO5/G7rXeCOKqbvzugo ELLU2AR/u0uGXDaq69Kjg54hSJW+Emrn+Yq0flHllzrxc9GI2jsZtNYGBfcJZsDQQ/qb 4RFo1qxEp7LfnM+Jbgifkdf3EjFHZuz5eejCnOcUtbKxE/OA/7IGhPqSEoVPcvPn/kPz Bl2UcN//NMwhyCRDpr0rtc+UQAAmr/MKvMPU1etBpdZAO5udUjHXqTxyf7X70eJLx/Ap yumF5GVK9rzn3AE1iBOjAi6yoWHXYKNGGnbYEz7bRY3H1OXunsqLF+QvIVtxSq03Wi/H zDZw== X-Forwarded-Encrypted: i=1; AJvYcCUfy1JPWo0/WaV5xdQSCS/gOM8SfrskEXTgsbrKy/F5kzPZWg+bnxbBMTDosYaQjrMoTR6R1Pia6ZQqDVui+/jiP6lB4H6JtcMz X-Gm-Message-State: AOJu0YwYqanq+fr6IMXR1kJZ1m2JQDKmh3Q94lpggrDEyBwY0SfeNvyh wDqoFOiqVDfXxB42tZVKblspv6AqjQRvJ/zKQ/y3BtaWJcF+fGGAGtYy1HorJ1EJmZ0mwZepI6O uruxRfOxgoxlcSX6k665awTCVmbO8EbHWxE66LjADVHVmBTYITjLU0xppag== X-Received: by 2002:a05:6000:1565:b0:35f:306f:1580 with SMTP id ffacd0b85a97d-360799b1549mr219956f8f.0.1718279448137; Thu, 13 Jun 2024 04:50:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9cmmBRW9Stdsi/0+iK7+da7RrjIrMU5kxwu1c5epv9+cZ27afQqEVK8UIzXm69jHmn71+7Q== X-Received: by 2002:a05:6000:1565:b0:35f:306f:1580 with SMTP id ffacd0b85a97d-360799b1549mr219936f8f.0.1718279447676; Thu, 13 Jun 2024 04:50:47 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 04:50:47 -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 03/13] PCI: Add partial-BAR devres support Date: Thu, 13 Jun 2024 13:50:16 +0200 Message-ID: <20240613115032.29098-4-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> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With the current PCI devres API implementing a managed version of pci_iomap_range() is impossible. Furthermore, the PCI devres API currently is inconsistent and complicated. This is in large part due to the fact that there are hybrid functions which are only sometimes managed via devres, and functions IO-mapping and requesting several BARs at once and returning mappings through a separately administrated table. This table's indexing mechanism does not support partial-BAR mappings. Another notable problem is that there are no separate managed counterparts for region-request functions such as pci_request_region(), as they exist for other PCI functions (e.g., pci_iomap() <-> pcim_iomap()). Instead, functions based on __pci_request_region() change their internal behavior and suddenly become managed functions when pcim_enable_device() instead of pci_enable_device() is used. This API is hard to understand and potentially bug-provoking. Hence, it should be made more consistent. This patch adds the necessary infrastructure for partial-BAR mappings managed with devres. That infrastructure also serves as a ground layer for significantly simplifying the PCI devres API in subsequent patches which can then cleanly separate managed and unmanaged API. When having the long term goal of providing always managed functions prefixed with "pcim_" and never managed functions prefixed with "pci_" and, thus, separating managed and unmanaged APIs cleanly, new PCI devres infrastructure cannot use __pci_request_region() and its wrappers since those would then again interact with PCI devres and, consequently, prevent the managed nature from being removed from the pci_* functions in the first place. Thus, it's necessary to provide an alternative to __pci_request_region(). This patch addresses the following problems of the PCI devres API: a) There is no PCI devres infrastructure on which a managed counter part to pci_iomap_range() could be based on. b) The vast majority of the users of plural functions such as pcim_iomap_regions() only ever sets a single bit in the bit mask, consequently making them singular functions anyways. c) region-request functions being sometimes managed and sometimes not is bug-provoking. pcim_* functions should always be managed, pci_* functions never. Add a new PCI device resource, pcim_addr_devres, that serves to encapsulate all device resource types related to region requests and IO-mappings since those are very frequently created together. Add a set of alternatives cleanly separated from the hybrid mechanism in __pci_request_region() and its respective wrappers: - __pcim_request_region_range() - __pcim_release_region_range() - __pcim_request_region() - __pcim_release_region() Add the following PCI-internal devres functions based on the above: - pcim_iomap_region() - pcim_iounmap_region() - _pcim_request_region() - pcim_request_region() - pcim_release_region() - pcim_request_all_regions() - pcim_release_all_regions() Add new needed helper pcim_remove_bar_from_legacy_table(). Rework the following public interfaces using the new infrastructure listed above: - pcim_iomap_release() - pcim_iomap() - pcim_iounmap() - pcim_iomap_regions() - pcim_iomap_regions_request_all() - pcim_iounmap_regions() Update API documentation. Link: https://lore.kernel.org/r/20240605081605.18769-5-pstanner@redhat.com Signed-off-by: Philipp Stanner Signed-off-by: Bjorn Helgaas --- drivers/pci/devres.c | 608 ++++++++++++++++++++++++++++++++++++++----- drivers/pci/pci.c | 22 ++ drivers/pci/pci.h | 5 + 3 files changed, 568 insertions(+), 67 deletions(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index 845d6fab0ce7..cf2c11b54ca6 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -4,14 +4,243 @@ #include "pci.h" /* - * PCI iomap devres + * On the state of PCI's devres implementation: + * + * The older devres API for PCI has two significant problems: + * + * 1. It is very strongly tied to the statically allocated mapping table in + * struct pcim_iomap_devres below. This is mostly solved in the sense of the + * pcim_ functions in this file providing things like ranged mapping by + * bypassing this table, wheras the functions that were present in the old + * API still enter the mapping addresses into the table for users of the old + * API. + * + * 2. The region-request-functions in pci.c do become managed IF the device has + * been enabled with pcim_enable_device() instead of pci_enable_device(). + * This resulted in the API becoming inconsistent: Some functions have an + * obviously managed counter-part (e.g., pci_iomap() <-> pcim_iomap()), + * whereas some don't and are never managed, while others don't and are + * _sometimes_ managed (e.g. pci_request_region()). + * + * Consequently, in the new API, region requests performed by the pcim_ + * functions are automatically cleaned up through the devres callback + * pcim_addr_resource_release(), while requests performed by + * pcim_enable_device() + pci_*region*() are automatically cleaned up + * through the for-loop in pcim_release(). + * + * TODO 1: + * Remove the legacy table entirely once all calls to pcim_iomap_table() in + * the kernel have been removed. + * + * TODO 2: + * Port everyone calling pcim_enable_device() + pci_*region*() to using the + * pcim_ functions. Then, remove all devres functionality from pci_*region*() + * functions and remove the associated cleanups described above in point #2. */ -#define PCIM_IOMAP_MAX PCI_STD_NUM_BARS +/* + * Legacy struct storing addresses to whole mapped BARs. + */ struct pcim_iomap_devres { - void __iomem *table[PCIM_IOMAP_MAX]; + void __iomem *table[PCI_STD_NUM_BARS]; +}; + +enum pcim_addr_devres_type { + /* Default initializer. */ + PCIM_ADDR_DEVRES_TYPE_INVALID, + + /* A requested region spanning an entire BAR. */ + PCIM_ADDR_DEVRES_TYPE_REGION, + + /* + * A requested region spanning an entire BAR, and a mapping for + * the entire BAR. + */ + PCIM_ADDR_DEVRES_TYPE_REGION_MAPPING, + + /* + * A mapping within a BAR, either spanning the whole BAR or just a + * range. Without a requested region. + */ + PCIM_ADDR_DEVRES_TYPE_MAPPING, }; +/* + * This struct envelops IO or MEM addresses, i.e., mappings and region + * requests, because those are very frequently requested and released + * together. + */ +struct pcim_addr_devres { + enum pcim_addr_devres_type type; + void __iomem *baseaddr; + unsigned long offset; + unsigned long len; + short bar; +}; + +static inline void pcim_addr_devres_clear(struct pcim_addr_devres *res) +{ + memset(res, 0, sizeof(*res)); + res->bar = -1; +} + +/* + * The following functions, __pcim_*_region*, exist as counterparts to the + * versions from pci.c - which, unfortunately, can be in "hybrid mode", i.e., + * sometimes managed, sometimes not. + * + * To separate the APIs cleanly, we define our own, simplified versions here. + */ + +/** + * __pcim_request_region_range - Request a ranged region + * @pdev: PCI device the region belongs to + * @bar: BAR the range is within + * @offset: offset from the BAR's start address + * @maxlen: length in bytes, beginning at @offset + * @name: name associated with the request + * @req_flags: flags for the request, e.g., for kernel-exclusive requests + * + * Returns: 0 on success, a negative error code on failure. + * + * Request a range within a device's PCI BAR. Sanity check the input. + */ +static int __pcim_request_region_range(struct pci_dev *pdev, int bar, + unsigned long offset, unsigned long maxlen, + const char *name, int req_flags) +{ + resource_size_t start = pci_resource_start(pdev, bar); + resource_size_t len = pci_resource_len(pdev, bar); + unsigned long dev_flags = pci_resource_flags(pdev, bar); + + if (start == 0 || len == 0) /* Unused BAR. */ + return 0; + if (len <= offset) + return -EINVAL; + + start += offset; + len -= offset; + + if (len > maxlen && maxlen != 0) + len = maxlen; + + if (dev_flags & IORESOURCE_IO) { + if (!request_region(start, len, name)) + return -EBUSY; + } else if (dev_flags & IORESOURCE_MEM) { + if (!__request_mem_region(start, len, name, req_flags)) + return -EBUSY; + } else { + /* That's not a device we can request anything on. */ + return -ENODEV; + } + + return 0; +} + +static void __pcim_release_region_range(struct pci_dev *pdev, int bar, + unsigned long offset, unsigned long maxlen) +{ + resource_size_t start = pci_resource_start(pdev, bar); + resource_size_t len = pci_resource_len(pdev, bar); + unsigned long flags = pci_resource_flags(pdev, bar); + + if (len <= offset || start == 0) + return; + + if (len == 0 || maxlen == 0) /* This an unused BAR. Do nothing. */ + return; + + start += offset; + len -= offset; + + if (len > maxlen) + len = maxlen; + + if (flags & IORESOURCE_IO) + release_region(start, len); + else if (flags & IORESOURCE_MEM) + release_mem_region(start, len); +} + +static int __pcim_request_region(struct pci_dev *pdev, int bar, + const char *name, int flags) +{ + unsigned long offset = 0; + unsigned long len = pci_resource_len(pdev, bar); + + return __pcim_request_region_range(pdev, bar, offset, len, name, flags); +} + +static void __pcim_release_region(struct pci_dev *pdev, int bar) +{ + unsigned long offset = 0; + unsigned long len = pci_resource_len(pdev, bar); + + __pcim_release_region_range(pdev, bar, offset, len); +} + +static void pcim_addr_resource_release(struct device *dev, void *resource_raw) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pcim_addr_devres *res = resource_raw; + + switch (res->type) { + case PCIM_ADDR_DEVRES_TYPE_REGION: + __pcim_release_region(pdev, res->bar); + break; + case PCIM_ADDR_DEVRES_TYPE_REGION_MAPPING: + pci_iounmap(pdev, res->baseaddr); + __pcim_release_region(pdev, res->bar); + break; + case PCIM_ADDR_DEVRES_TYPE_MAPPING: + pci_iounmap(pdev, res->baseaddr); + break; + default: + break; + } +} + +static struct pcim_addr_devres *pcim_addr_devres_alloc(struct pci_dev *pdev) +{ + struct pcim_addr_devres *res; + + res = devres_alloc_node(pcim_addr_resource_release, sizeof(*res), + GFP_KERNEL, dev_to_node(&pdev->dev)); + if (res) + pcim_addr_devres_clear(res); + return res; +} + +/* Just for consistency and readability. */ +static inline void pcim_addr_devres_free(struct pcim_addr_devres *res) +{ + devres_free(res); +} + +/* + * Used by devres to identify a pcim_addr_devres. + */ +static int pcim_addr_resources_match(struct device *dev, void *a_raw, void *b_raw) +{ + struct pcim_addr_devres *a, *b; + + a = a_raw; + b = b_raw; + + if (a->type != b->type) + return 0; + + switch (a->type) { + case PCIM_ADDR_DEVRES_TYPE_REGION: + case PCIM_ADDR_DEVRES_TYPE_REGION_MAPPING: + return a->bar == b->bar; + case PCIM_ADDR_DEVRES_TYPE_MAPPING: + return a->baseaddr == b->baseaddr; + default: + return 0; + } +} static void devm_pci_unmap_iospace(struct device *dev, void *ptr) { @@ -92,8 +321,8 @@ EXPORT_SYMBOL(devm_pci_remap_cfgspace); * * All operations are managed and will be undone on driver detach. * - * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code - * on failure. Usage example:: + * Returns a pointer to the remapped memory or an IOMEM_ERR_PTR() encoded error + * code on failure. Usage example:: * * res = platform_get_resource(pdev, IORESOURCE_MEM, 0); * base = devm_pci_remap_cfg_resource(&pdev->dev, res); @@ -172,6 +401,17 @@ static void pcim_release(struct device *gendev, void *res) struct pci_devres *this = res; int i; + /* + * This is legacy code. + * + * All regions requested by a pcim_ function do get released through + * pcim_addr_resource_release(). Thanks to the hybrid nature of the pci_ + * region-request functions, this for-loop has to release the regions + * if they have been requested by such a function. + * + * TODO: Remove this once all users of pcim_enable_device() PLUS + * pci-region-request-functions have been ported to pcim_ functions. + */ for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) if (mask_contains_bar(this->region_mask, i)) pci_release_region(dev, i); @@ -258,19 +498,21 @@ EXPORT_SYMBOL(pcim_pin_device); static void pcim_iomap_release(struct device *gendev, void *res) { - struct pci_dev *dev = to_pci_dev(gendev); - struct pcim_iomap_devres *this = res; - int i; - - for (i = 0; i < PCIM_IOMAP_MAX; i++) - if (this->table[i]) - pci_iounmap(dev, this->table[i]); + /* + * Do nothing. This is legacy code. + * + * Cleanup of the mappings is now done directly through the callbacks + * registered when creating them. + */ } /** * pcim_iomap_table - access iomap allocation table * @pdev: PCI device to access iomap table for * + * Returns: + * Const pointer to array of __iomem pointers on success, NULL on failure. + * * Access iomap allocation table for @dev. If iomap table doesn't * exist and @pdev is managed, it will be allocated. All iomaps * recorded in the iomap table are automatically unmapped on driver @@ -343,30 +585,67 @@ static void pcim_remove_mapping_from_legacy_table(struct pci_dev *pdev, } } +/* + * The same as pcim_remove_mapping_from_legacy_table(), but identifies the + * mapping by its BAR index. + */ +static void pcim_remove_bar_from_legacy_table(struct pci_dev *pdev, short bar) +{ + void __iomem **legacy_iomap_table; + + if (bar >= PCI_STD_NUM_BARS) + return; + + legacy_iomap_table = (void __iomem **)pcim_iomap_table(pdev); + if (!legacy_iomap_table) + return; + + legacy_iomap_table[bar] = NULL; +} + /** * pcim_iomap - Managed pcim_iomap() * @pdev: PCI device to iomap for * @bar: BAR to iomap * @maxlen: Maximum length of iomap * - * Managed pci_iomap(). Map is automatically unmapped on driver - * detach. + * Returns: __iomem pointer on success, NULL on failure. + * + * Managed pci_iomap(). Map is automatically unmapped on driver detach. If + * desired, unmap manually only with pcim_iounmap(). + * + * This SHOULD only be used once per BAR. + * + * NOTE: + * Contrary to the other pcim_* functions, this function does not return an + * IOMEM_ERR_PTR() on failure, but a simple NULL. This is done for backwards + * compatibility. */ void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen) { void __iomem *mapping; + struct pcim_addr_devres *res; + + res = pcim_addr_devres_alloc(pdev); + if (!res) + return NULL; + res->type = PCIM_ADDR_DEVRES_TYPE_MAPPING; mapping = pci_iomap(pdev, bar, maxlen); if (!mapping) - return NULL; + goto err_iomap; + res->baseaddr = mapping; if (pcim_add_mapping_to_legacy_table(pdev, mapping, bar) != 0) goto err_table; + devres_add(&pdev->dev, res); return mapping; err_table: pci_iounmap(pdev, mapping); +err_iomap: + pcim_addr_devres_free(res); return NULL; } EXPORT_SYMBOL(pcim_iomap); @@ -376,91 +655,291 @@ EXPORT_SYMBOL(pcim_iomap); * @pdev: PCI device to iounmap for * @addr: Address to unmap * - * Managed pci_iounmap(). @addr must have been mapped using pcim_iomap(). + * Managed pci_iounmap(). @addr must have been mapped using a pcim_* mapping + * function. */ void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr) { - pci_iounmap(pdev, addr); + struct pcim_addr_devres res_searched; + + pcim_addr_devres_clear(&res_searched); + res_searched.type = PCIM_ADDR_DEVRES_TYPE_MAPPING; + res_searched.baseaddr = addr; + + if (devres_release(&pdev->dev, pcim_addr_resource_release, + pcim_addr_resources_match, &res_searched) != 0) { + /* Doesn't exist. User passed nonsense. */ + return; + } pcim_remove_mapping_from_legacy_table(pdev, addr); } EXPORT_SYMBOL(pcim_iounmap); +/** + * pcim_iomap_region - Request and iomap a PCI BAR + * @pdev: PCI device to map IO resources for + * @bar: Index of a BAR to map + * @name: Name associated with the request + * + * Returns: __iomem pointer on success, an IOMEM_ERR_PTR on failure. + * + * Mapping and region will get automatically released on driver detach. If + * desired, release manually only with pcim_iounmap_region(). + */ +static void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar, + const char *name) +{ + int ret; + struct pcim_addr_devres *res; + + res = pcim_addr_devres_alloc(pdev); + if (!res) + return IOMEM_ERR_PTR(-ENOMEM); + + res->type = PCIM_ADDR_DEVRES_TYPE_REGION_MAPPING; + res->bar = bar; + + ret = __pcim_request_region(pdev, bar, name, 0); + if (ret != 0) + goto err_region; + + res->baseaddr = pci_iomap(pdev, bar, 0); + if (!res->baseaddr) { + ret = -EINVAL; + goto err_iomap; + } + + devres_add(&pdev->dev, res); + return res->baseaddr; + +err_iomap: + __pcim_release_region(pdev, bar); +err_region: + pcim_addr_devres_free(res); + + return IOMEM_ERR_PTR(ret); +} + +/** + * pcim_iounmap_region - Unmap and release a PCI BAR + * @pdev: PCI device to operate on + * @bar: Index of BAR to unmap and release + * + * Unmap a BAR and release its region manually. Only pass BARs that were + * previously mapped by pcim_iomap_region(). + */ +static void pcim_iounmap_region(struct pci_dev *pdev, int bar) +{ + struct pcim_addr_devres res_searched; + + pcim_addr_devres_clear(&res_searched); + res_searched.type = PCIM_ADDR_DEVRES_TYPE_REGION_MAPPING; + res_searched.bar = bar; + + devres_release(&pdev->dev, pcim_addr_resource_release, + pcim_addr_resources_match, &res_searched); +} + /** * pcim_iomap_regions - Request and iomap PCI BARs * @pdev: PCI device to map IO resources for * @mask: Mask of BARs to request and iomap - * @name: Name used when requesting regions + * @name: Name associated with the requests + * + * Returns: 0 on success, negative error code on failure. * * Request and iomap regions specified by @mask. */ int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name) { - void __iomem * const *iomap; - int i, rc; + int ret; + short bar; + void __iomem *mapping; - iomap = pcim_iomap_table(pdev); - if (!iomap) - return -ENOMEM; + for (bar = 0; bar < DEVICE_COUNT_RESOURCE; bar++) { + if (!mask_contains_bar(mask, bar)) + continue; - for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { - unsigned long len; + mapping = pcim_iomap_region(pdev, bar, name); + if (IS_ERR(mapping)) { + ret = PTR_ERR(mapping); + goto err; + } + ret = pcim_add_mapping_to_legacy_table(pdev, mapping, bar); + if (ret != 0) + goto err; + } - if (!mask_contains_bar(mask, i)) - continue; + return 0; - rc = -EINVAL; - len = pci_resource_len(pdev, i); - if (!len) - goto err_inval; +err: + while (--bar >= 0) { + pcim_iounmap_region(pdev, bar); + pcim_remove_bar_from_legacy_table(pdev, bar); + } - rc = pci_request_region(pdev, i, name); - if (rc) - goto err_inval; + return ret; +} +EXPORT_SYMBOL(pcim_iomap_regions); - rc = -ENOMEM; - if (!pcim_iomap(pdev, i, 0)) - goto err_region; +static int _pcim_request_region(struct pci_dev *pdev, int bar, const char *name, + int request_flags) +{ + int ret; + struct pcim_addr_devres *res; + + res = pcim_addr_devres_alloc(pdev); + if (!res) + return -ENOMEM; + res->type = PCIM_ADDR_DEVRES_TYPE_REGION; + res->bar = bar; + + ret = __pcim_request_region(pdev, bar, name, request_flags); + if (ret != 0) { + pcim_addr_devres_free(res); + return ret; } + devres_add(&pdev->dev, res); return 0; +} - err_region: - pci_release_region(pdev, i); - err_inval: - while (--i >= 0) { - if (!mask_contains_bar(mask, i)) - continue; - pcim_iounmap(pdev, iomap[i]); - pci_release_region(pdev, i); +/** + * pcim_request_region - Request a PCI BAR + * @pdev: PCI device to requestion region for + * @bar: Index of BAR to request + * @name: Name associated with the request + * + * Returns: 0 on success, a negative error code on failure. + * + * Request region specified by @bar. + * + * The region will automatically be released on driver detach. If desired, + * release manually only with pcim_release_region(). + */ +static int pcim_request_region(struct pci_dev *pdev, int bar, const char *name) +{ + return _pcim_request_region(pdev, bar, name, 0); +} + +/** + * pcim_release_region - Release a PCI BAR + * @pdev: PCI device to operate on + * @bar: Index of BAR to release + * + * Release a region manually that was previously requested by + * pcim_request_region(). + */ +static void pcim_release_region(struct pci_dev *pdev, int bar) +{ + struct pcim_addr_devres res_searched; + + pcim_addr_devres_clear(&res_searched); + res_searched.type = PCIM_ADDR_DEVRES_TYPE_REGION; + res_searched.bar = bar; + + devres_release(&pdev->dev, pcim_addr_resource_release, + pcim_addr_resources_match, &res_searched); +} + + +/** + * pcim_release_all_regions - Release all regions of a PCI-device + * @pdev: the PCI device + * + * Release all regions previously requested through pcim_request_region() + * or pcim_request_all_regions(). + * + * Can be called from any context, i.e., not necessarily as a counterpart to + * pcim_request_all_regions(). + */ +static void pcim_release_all_regions(struct pci_dev *pdev) +{ + short bar; + + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) + pcim_release_region(pdev, bar); +} + +/** + * pcim_request_all_regions - Request all regions + * @pdev: PCI device to map IO resources for + * @name: name associated with the request + * + * Returns: 0 on success, negative error code on failure. + * + * Requested regions will automatically be released at driver detach. If + * desired, release individual regions with pcim_release_region() or all of + * them at once with pcim_release_all_regions(). + */ +static int pcim_request_all_regions(struct pci_dev *pdev, const char *name) +{ + int ret; + short bar; + + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { + ret = pcim_request_region(pdev, bar, name); + if (ret != 0) + goto err; } - return rc; + return 0; + +err: + pcim_release_all_regions(pdev); + + return ret; } -EXPORT_SYMBOL(pcim_iomap_regions); /** * pcim_iomap_regions_request_all - Request all BARs and iomap specified ones * @pdev: PCI device to map IO resources for * @mask: Mask of BARs to iomap - * @name: Name used when requesting regions + * @name: Name associated with the requests + * + * Returns: 0 on success, negative error code on failure. * * Request all PCI BARs and iomap regions specified by @mask. + * + * To release these resources manually, call pcim_release_region() for the + * regions and pcim_iounmap() for the mappings. */ int pcim_iomap_regions_request_all(struct pci_dev *pdev, int mask, const char *name) { - int request_mask = ((1 << 6) - 1) & ~mask; - int rc; + short bar; + int ret; + void __iomem **legacy_iomap_table; - rc = pci_request_selected_regions(pdev, request_mask, name); - if (rc) - return rc; + ret = pcim_request_all_regions(pdev, name); + if (ret != 0) + return ret; - rc = pcim_iomap_regions(pdev, mask, name); - if (rc) - pci_release_selected_regions(pdev, request_mask); - return rc; + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { + if (!mask_contains_bar(mask, bar)) + continue; + if (!pcim_iomap(pdev, bar, 0)) + goto err; + } + + return 0; + +err: + /* + * If bar is larger than 0, then pcim_iomap() above has most likely + * failed because of -EINVAL. If it is equal 0, most likely the table + * couldn't be created, indicating -ENOMEM. + */ + ret = bar > 0 ? -EINVAL : -ENOMEM; + legacy_iomap_table = (void __iomem **)pcim_iomap_table(pdev); + + while (--bar >= 0) + pcim_iounmap(pdev, legacy_iomap_table[bar]); + + pcim_release_all_regions(pdev); + + return ret; } EXPORT_SYMBOL(pcim_iomap_regions_request_all); @@ -473,19 +952,14 @@ EXPORT_SYMBOL(pcim_iomap_regions_request_all); */ void pcim_iounmap_regions(struct pci_dev *pdev, int mask) { - void __iomem * const *iomap; - int i; + short bar; - iomap = pcim_iomap_table(pdev); - if (!iomap) - return; - - for (i = 0; i < PCIM_IOMAP_MAX; i++) { - if (!mask_contains_bar(mask, i)) + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { + if (!mask_contains_bar(mask, bar)) continue; - pcim_iounmap(pdev, iomap[i]); - pci_release_region(pdev, i); + pcim_iounmap_region(pdev, bar); + pcim_remove_bar_from_legacy_table(pdev, bar); } } EXPORT_SYMBOL(pcim_iounmap_regions); diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 59e0949fb079..d94445f5f882 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3883,6 +3883,17 @@ void pci_release_region(struct pci_dev *pdev, int bar) release_mem_region(pci_resource_start(pdev, bar), pci_resource_len(pdev, bar)); + /* + * This devres utility makes this function sometimes managed + * (when pcim_enable_device() has been called before). + * + * This is bad because it conflicts with the pcim_ functions being + * exclusively responsible for managed PCI. Its "sometimes yes, + * sometimes no" nature can cause bugs. + * + * TODO: Remove this once all users that use pcim_enable_device() PLUS + * a region request function have been ported to using pcim_ functions. + */ dr = find_pci_dr(pdev); if (dr) dr->region_mask &= ~(1 << bar); @@ -3927,6 +3938,17 @@ static int __pci_request_region(struct pci_dev *pdev, int bar, goto err_out; } + /* + * This devres utility makes this function sometimes managed + * (when pcim_enable_device() has been called before). + * + * This is bad because it conflicts with the pcim_ functions being + * exclusively responsible for managed pci. Its "sometimes yes, + * sometimes no" nature can cause bugs. + * + * TODO: Remove this once all users that use pcim_enable_device() PLUS + * a region request function have been ported to using pcim_ functions. + */ dr = find_pci_dr(pdev); if (dr) dr->region_mask |= 1 << bar; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index fd44565c4756..c09487f5550c 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -826,6 +826,11 @@ struct pci_devres { unsigned int orig_intx:1; unsigned int restore_intx:1; unsigned int mwi:1; + + /* + * TODO: remove the region_mask once everyone calling + * pcim_enable_device() + pci_*region*() is ported to pcim_ functions. + */ u32 region_mask; }; From patchwork Thu Jun 13 11:50:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 1947355 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RLbS/hEg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-pci+bounces-8721-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0LS1727Kz20KL for ; Thu, 13 Jun 2024 21:54:41 +1000 (AEST) 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E9F181C21343 for ; Thu, 13 Jun 2024 11:54:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E4F18148301; Thu, 13 Jun 2024 11:50:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RLbS/hEg" X-Original-To: linux-pci@vger.kernel.org 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 4A540143C5F for ; Thu, 13 Jun 2024 11:50:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279454; cv=none; b=TszhUG0pjE6w4TOgQmyBOOP1MkDdlloSY9W6XQaY25kpeMIlNgUDvf7itqmO6+PHgiFQIvvNJLFldekNOlkePMMG25HE0YAow9Qy+1RTw+Ut/TqYL3WfUwrwKb/3Zyc0ANcH6WD7VEBM0r3oELoteLHk0vhq6dv/BcGeOlx3uaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279454; c=relaxed/simple; bh=CKmb7V8YQKy60Y3zYZ5nF36qcetaUUfvS68MhKTVZyk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MLBaiQTh7SZn9AYEMJ59w7fk63uFXtP85IwsalDr+CDVDmoBqAeHwsbDzVX3sFRC08gTNbU5GCDmPz3migYkTz//0mYL20FWNc7TYTYY6ZOlH2Yv96gp8DIUqwyk7iiUJx37q71edfTWSTiZ9xfIMs9ErsWChwIDRHaKFMmweKQ= 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=RLbS/hEg; arc=none smtp.client-ip=170.10.133.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=1718279452; 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=CL+kLbe+Y26ksl0hcQ0e5foEJJ8TqrY6DSq54p9TklM=; b=RLbS/hEg17EQO8jILC2nuz/YivgLWKFduWRYcAYqKLuM3ZJrL4T2d2abz2lchYlpkEK5bc WA/6ns7mIUj8xsl9Cg2Juaii+2fsO8YtJ7JZ4BHhWKsjuxDNqNbrMEgoMCaEiF4Zu2iqt5 E2cLQQb/nxjHcxMv2a+AABtFJsIJq6k= 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-696-iycpxrN9Pja6UFceaAfZmg-1; Thu, 13 Jun 2024 07:50:50 -0400 X-MC-Unique: iycpxrN9Pja6UFceaAfZmg-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4210e98f8d7so1509715e9.3 for ; Thu, 13 Jun 2024 04:50:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279449; x=1718884249; 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=CL+kLbe+Y26ksl0hcQ0e5foEJJ8TqrY6DSq54p9TklM=; b=NjUlDsOYanGmffEZhaC9NIVedxIfk38d9+Mb5XBtUCEDb5uU4CubAH4wvNRyGWdQSS 754aVEOoOYVWbi7nnk2FMiz0b22JA0s+33esx92Rxogqk+0xdV+TP0rgQ+13P1RG3S0h MzpLnXHaMwOI0i84mP4XameDZLQereKQDPCHkXfulBRYCn/KE0qzaDjJGs9xU3QTVzEj k+fOFzZjZDKSfOouhAXGjqQbiETqPSoYljEb10Eb1XWUz9dYtiZO/U/4redoJ7g7cOFW MLpWQBml91DOhbXdw/nj+OLkPOFo7JZDYqROV1kNCL6QofKl/iofUqjmOMvJfmlD5P9h ikDg== X-Forwarded-Encrypted: i=1; AJvYcCXZZS5woEMyxNfsjOiNOewxYegw8M8yXYJQk3p/isANSlDOruPPdlVfn8KZqgpj1zJQDUQ42Yb4Ncd/TQmnUOySaHr8egi7dt29 X-Gm-Message-State: AOJu0YwHasyN3Oqe6Obnju/aLPXREuayjwB4DQYIbQyuQRrLhu+sjAkL r7VgwekNQ1bCHr3foKetfT0XV/ArZeeeiUVrnH0awfyDQCqQd/1pLlN+QQt55VXr5M2tgSRetE3 l834/I6M1Rz9RDctl6+AJHkwXbONrF2fSPz+faQFWsicVfOx2Hfr6IjBILQ== X-Received: by 2002:a5d:5f93:0:b0:35f:306f:1587 with SMTP id ffacd0b85a97d-36079a50f05mr208537f8f.5.1718279448841; Thu, 13 Jun 2024 04:50:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEPTiocjmZpdSuZITHvA9vbQ/P9nyYz57aqk+QbvsZnFOIEMIsJGsexzqpTKeFCx6yJ+Ucbw== X-Received: by 2002:a5d:5f93:0:b0:35f:306f:1587 with SMTP id ffacd0b85a97d-36079a50f05mr208519f8f.5.1718279448583; Thu, 13 Jun 2024 04:50:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 04:50:48 -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 04/13] PCI: Deprecate two surplus devres functions Date: Thu, 13 Jun 2024 13:50:17 +0200 Message-ID: <20240613115032.29098-5-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> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 pcim_iomap_table() should not be used anymore because it contributed to the PCI devres API being designed contrary to devres's design goals. pcim_iomap_regions_request_all() is a surplus, complicated function that can easily be replaced by using a pcim_* request function in combination with a pcim_* mapping function. Mark pcim_iomap_table() and pcim_iomap_regions_request_all() as deprecated in the function documentation. Link: https://lore.kernel.org/r/20240605081605.18769-6-pstanner@redhat.com Signed-off-by: Philipp Stanner Signed-off-by: Bjorn Helgaas --- drivers/pci/devres.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index cf2c11b54ca6..5ecffc7424ed 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -507,7 +507,7 @@ static void pcim_iomap_release(struct device *gendev, void *res) } /** - * pcim_iomap_table - access iomap allocation table + * pcim_iomap_table - access iomap allocation table (DEPRECATED) * @pdev: PCI device to access iomap table for * * Returns: @@ -521,6 +521,11 @@ static void pcim_iomap_release(struct device *gendev, void *res) * This function might sleep when the table is first allocated but can * be safely called without context and guaranteed to succeed once * allocated. + * + * This function is DEPRECATED. Do not use it in new code. Instead, obtain a + * mapping's address directly from one of the pcim_* mapping functions. For + * example: + * void __iomem *mappy = pcim_iomap(pdev, bar, length); */ void __iomem * const *pcim_iomap_table(struct pci_dev *pdev) { @@ -894,6 +899,7 @@ static int pcim_request_all_regions(struct pci_dev *pdev, const char *name) /** * pcim_iomap_regions_request_all - Request all BARs and iomap specified ones + * (DEPRECATED) * @pdev: PCI device to map IO resources for * @mask: Mask of BARs to iomap * @name: Name associated with the requests @@ -904,6 +910,10 @@ static int pcim_request_all_regions(struct pci_dev *pdev, const char *name) * * To release these resources manually, call pcim_release_region() for the * regions and pcim_iounmap() for the mappings. + * + * This function is DEPRECATED. Don't use it in new code. Instead, use one + * of the pcim_* region request functions in combination with a pcim_* + * mapping function. */ int pcim_iomap_regions_request_all(struct pci_dev *pdev, int mask, const char *name) From patchwork Thu Jun 13 11:50:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 1947356 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GZpx68r7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-pci+bounces-8722-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0LSG6WwQz20KL for ; Thu, 13 Jun 2024 21:54:54 +1000 (AEST) 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A99E4282AC3 for ; Thu, 13 Jun 2024 11:54:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EEF521487C0; Thu, 13 Jun 2024 11:50:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GZpx68r7" X-Original-To: linux-pci@vger.kernel.org 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 069CC147C8B for ; Thu, 13 Jun 2024 11:50:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279455; cv=none; b=ZXVC1aSa/sdQNqaNs+h7QaXqh9No2WU5dqCwdgNhfat13BehpDy/LE66stVLjLDVgQ3CRuuRl7Q1nb7+Jy8p7nqCIqs2cZuzHJfONoPMSg9z1R9c2Gi58N6MalhWZM5WmVxAiDruXhfJijudV2lCwkl2jcv/aBA8fzK+y4f6qjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279455; c=relaxed/simple; bh=Rc0vk4XaTa4NVY067IZa1x33Rqvecp2YYmlgZGJ+vNs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HrF1ngkgFMXOfnwgVeXg4/vogTcKjEunPr7Of5/KVSEqH57JppoUqIPeVhFxKU1q0+gmSG+yjhaRMsMr6pj3TTuulXBnQVByGNn9wQcdsLReLW1abHCaseJk9RMCoFtlQ0m82GydxPPt+p3Ql7LIbk1cKVDGqEdvebOKRq3PyVs= 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=GZpx68r7; arc=none smtp.client-ip=170.10.133.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=1718279453; 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=ViBYsK7r7YHaCmYfaljCmdF+x2qktzp5uILOcoPl4ng=; b=GZpx68r7RHlMbmH6kRric3fBdZHm3zP4mrJaFwvqM2yi4ZY6VahE/S2ZsdtFQzEHpDSgMW 446D95MudpA93Ee2+qYZi83FMdnD6cIgSuQt+1MwdSXkGxz04yEMthUHji1/pMyfupr6C5 knv28vdqPWK12TIMgu+Lk7uMv+MxXPA= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-692-gua4oK3-NWGhRQyqHK5BWQ-1; Thu, 13 Jun 2024 07:50:51 -0400 X-MC-Unique: gua4oK3-NWGhRQyqHK5BWQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42180d2a0d6so1525955e9.1 for ; Thu, 13 Jun 2024 04:50:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279450; x=1718884250; 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=ViBYsK7r7YHaCmYfaljCmdF+x2qktzp5uILOcoPl4ng=; b=w8tWijH/Bi10vTXb7L1yHhCYI+RO8heickikQ3nLxVcHm9LaIr3fxAPoIzcGI6VBfQ wKc8tAl9i1yZMFHl0hkHJRFX0GeDUz2CpUuOdnOrYmTg6U++EEdhNl671t+tjDlNpKfg YEg9gKrA2PZQbC5TmyUoKxOCuBFnPK+HOM+wt6H0AjeQ/gWnGD9QTmB71/uXUhKg5BHw O+GJoXoHcJA2KkLee6/RTWqM98IO0ocUuAyg77VlRaTWhdbs6ORwhPMsDGMArujR5c3h MgAsaKIU1E9x2AwlDl0KKcynWHZn9fWSqc+S1tme6Z6qTcyLZaI9I+T0/0/wr4QnRhg2 3bTw== X-Forwarded-Encrypted: i=1; AJvYcCV+o/oO1sJKKm4IXeZwxowQuCbyxJdP8GkaTs0ZYHIZXM67+QtXxsfFO/ipay0xD7w2X5bh/VYt/6/rMia19wFvdAv/ey2EFeg5 X-Gm-Message-State: AOJu0Yx2GEd/aO+nyNsq09zIG+trwPwbI98eheHaWZSjPBQpj+oGgKjj 4Zi9ZA6FRQ6PLdeWojBmEEqOe4AIQQOjwp01FVD0bB3F7YALsQVAy5hMEan5le7PxcqSP2QPKlC 9Wjnw1r9t9SPGHxh1+Vslw7kKvYEOuOzJ7vT76UUIzLJ8l8Yyrngc9/DuOA== X-Received: by 2002:a05:6000:4023:b0:35f:2fd3:85d5 with SMTP id ffacd0b85a97d-36079a472f1mr168573f8f.3.1718279450573; Thu, 13 Jun 2024 04:50:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBBfx4nYnLD/abQa3JiWhpHQ7DZlbaL9/HZMDFVCmtO64CnJnRENAa7IHgBrFFdGtk0NJd5w== X-Received: by 2002:a05:6000:4023:b0:35f:2fd3:85d5 with SMTP id ffacd0b85a97d-36079a472f1mr168552f8f.3.1718279450264; Thu, 13 Jun 2024 04:50:50 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 04:50:49 -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 05/13] PCI: Make devres region requests consistent Date: Thu, 13 Jun 2024 13:50:18 +0200 Message-ID: <20240613115032.29098-6-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> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that pure managed region request functions are available, the implementation of the hybrid-functions which are only sometimes managed can be made more consistent and readable by wrapping those always-managed functions. Implement pcim_request_region_exclusive() as a PCI-internal helper. Have the PCI request / release functions call their pcim_ counterparts. Remove the now surplus region_mask from struct pci_devres. Link: https://lore.kernel.org/r/20240605081605.18769-7-pstanner@redhat.com Signed-off-by: Philipp Stanner Signed-off-by: Bjorn Helgaas --- drivers/pci/devres.c | 53 ++++++++++++++++++++++---------------------- drivers/pci/pci.c | 47 +++++++++++++-------------------------- drivers/pci/pci.h | 10 ++++----- 3 files changed, 45 insertions(+), 65 deletions(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index 5ecffc7424ed..d90bed785c3f 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -24,18 +24,15 @@ * * Consequently, in the new API, region requests performed by the pcim_ * functions are automatically cleaned up through the devres callback - * pcim_addr_resource_release(), while requests performed by - * pcim_enable_device() + pci_*region*() are automatically cleaned up - * through the for-loop in pcim_release(). + * pcim_addr_resource_release(). + * Users utilizing pcim_enable_device() + pci_*region*() are redirected in + * pci.c to the managed functions here in this file. This isn't exactly + * perfect, but the only alternative way would be to port ALL drivers using + * said combination to pcim_ functions. * - * TODO 1: + * TODO: * Remove the legacy table entirely once all calls to pcim_iomap_table() in * the kernel have been removed. - * - * TODO 2: - * Port everyone calling pcim_enable_device() + pci_*region*() to using the - * pcim_ functions. Then, remove all devres functionality from pci_*region*() - * functions and remove the associated cleanups described above in point #2. */ /* @@ -399,22 +396,6 @@ static void pcim_release(struct device *gendev, void *res) { struct pci_dev *dev = to_pci_dev(gendev); struct pci_devres *this = res; - int i; - - /* - * This is legacy code. - * - * All regions requested by a pcim_ function do get released through - * pcim_addr_resource_release(). Thanks to the hybrid nature of the pci_ - * region-request functions, this for-loop has to release the regions - * if they have been requested by such a function. - * - * TODO: Remove this once all users of pcim_enable_device() PLUS - * pci-region-request-functions have been ported to pcim_ functions. - */ - for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) - if (mask_contains_bar(this->region_mask, i)) - pci_release_region(dev, i); if (this->mwi) pci_clear_mwi(dev); @@ -823,11 +804,29 @@ static int _pcim_request_region(struct pci_dev *pdev, int bar, const char *name, * The region will automatically be released on driver detach. If desired, * release manually only with pcim_release_region(). */ -static int pcim_request_region(struct pci_dev *pdev, int bar, const char *name) +int pcim_request_region(struct pci_dev *pdev, int bar, const char *name) { return _pcim_request_region(pdev, bar, name, 0); } +/** + * pcim_request_region_exclusive - Request a PCI BAR exclusively + * @pdev: PCI device to requestion region for + * @bar: Index of BAR to request + * @name: Name associated with the request + * + * Returns: 0 on success, a negative error code on failure. + * + * Request region specified by @bar exclusively. + * + * The region will automatically be released on driver detach. If desired, + * release manually only with pcim_release_region(). + */ +int pcim_request_region_exclusive(struct pci_dev *pdev, int bar, const char *name) +{ + return _pcim_request_region(pdev, bar, name, IORESOURCE_EXCLUSIVE); +} + /** * pcim_release_region - Release a PCI BAR * @pdev: PCI device to operate on @@ -836,7 +835,7 @@ static int pcim_request_region(struct pci_dev *pdev, int bar, const char *name) * Release a region manually that was previously requested by * pcim_request_region(). */ -static void pcim_release_region(struct pci_dev *pdev, int bar) +void pcim_release_region(struct pci_dev *pdev, int bar) { struct pcim_addr_devres res_searched; diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index d94445f5f882..7013699db242 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3872,7 +3872,15 @@ EXPORT_SYMBOL(pci_enable_atomic_ops_to_root); */ void pci_release_region(struct pci_dev *pdev, int bar) { - struct pci_devres *dr; + /* + * This is done for backwards compatibility, because the old PCI devres + * API had a mode in which the function became managed if it had been + * enabled with pcim_enable_device() instead of pci_enable_device(). + */ + if (pci_is_managed(pdev)) { + pcim_release_region(pdev, bar); + return; + } if (pci_resource_len(pdev, bar) == 0) return; @@ -3882,21 +3890,6 @@ void pci_release_region(struct pci_dev *pdev, int bar) else if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) release_mem_region(pci_resource_start(pdev, bar), pci_resource_len(pdev, bar)); - - /* - * This devres utility makes this function sometimes managed - * (when pcim_enable_device() has been called before). - * - * This is bad because it conflicts with the pcim_ functions being - * exclusively responsible for managed PCI. Its "sometimes yes, - * sometimes no" nature can cause bugs. - * - * TODO: Remove this once all users that use pcim_enable_device() PLUS - * a region request function have been ported to using pcim_ functions. - */ - dr = find_pci_dr(pdev); - if (dr) - dr->region_mask &= ~(1 << bar); } EXPORT_SYMBOL(pci_release_region); @@ -3922,7 +3915,12 @@ EXPORT_SYMBOL(pci_release_region); static int __pci_request_region(struct pci_dev *pdev, int bar, const char *res_name, int exclusive) { - struct pci_devres *dr; + if (pci_is_managed(pdev)) { + if (exclusive == IORESOURCE_EXCLUSIVE) + return pcim_request_region_exclusive(pdev, bar, res_name); + + return pcim_request_region(pdev, bar, res_name); + } if (pci_resource_len(pdev, bar) == 0) return 0; @@ -3938,21 +3936,6 @@ static int __pci_request_region(struct pci_dev *pdev, int bar, goto err_out; } - /* - * This devres utility makes this function sometimes managed - * (when pcim_enable_device() has been called before). - * - * This is bad because it conflicts with the pcim_ functions being - * exclusively responsible for managed pci. Its "sometimes yes, - * sometimes no" nature can cause bugs. - * - * TODO: Remove this once all users that use pcim_enable_device() PLUS - * a region request function have been ported to using pcim_ functions. - */ - dr = find_pci_dr(pdev); - if (dr) - dr->region_mask |= 1 << bar; - return 0; err_out: diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index c09487f5550c..2403c5a0ff7a 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -826,16 +826,14 @@ struct pci_devres { unsigned int orig_intx:1; unsigned int restore_intx:1; unsigned int mwi:1; - - /* - * TODO: remove the region_mask once everyone calling - * pcim_enable_device() + pci_*region*() is ported to pcim_ functions. - */ - u32 region_mask; }; struct pci_devres *find_pci_dr(struct pci_dev *pdev); +int pcim_request_region(struct pci_dev *pdev, int bar, const char *name); +int pcim_request_region_exclusive(struct pci_dev *pdev, int bar, const char *name); +void pcim_release_region(struct pci_dev *pdev, int bar); + /* * Config Address for PCI Configuration Mechanism #1 * From patchwork Thu Jun 13 11:50:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 1947357 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=e++wb/Ay; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-pci+bounces-8723-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0LSb1gsnz1ydW for ; Thu, 13 Jun 2024 21:55:11 +1000 (AEST) 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 B1FE01F25DBE for ; Thu, 13 Jun 2024 11:55:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2308B1487ED; Thu, 13 Jun 2024 11:50:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e++wb/Ay" X-Original-To: linux-pci@vger.kernel.org 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 472241482F1 for ; Thu, 13 Jun 2024 11:50:54 +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=1718279457; cv=none; b=l3Ibz5YN+uC7kmT7hwhhcdupUqW9tsy1+QbCHxErc+8rr4G736Gg+M+xDxEiGoslHWQmpPtgzrMPSnXA4TNp096buFVbj1nTWN+rOteSzTPss0tkh2jBT5YnglDpEJXtzytdqOx+3vBBqbqP0q9QVJi/wHkLYGdG2BfQSduxVnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279457; c=relaxed/simple; bh=5PE3+Mg+QJfwk/81MP4neUpiVdZJoI7gS0UJ6lgiki8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=absZQUx5XfHEu9OWY76RP/cKBhEpvf1ZBCaxCIH2mHSI2fCUZUYEwxSJay1Se5xzr0nmDVVxkdssRyEK6rFE1AgZlFw1nX1DZklH7cUbqQZmeFXjOGDDc7cz62Fc1K66Pzg7q3/CZ569eSrv5WoW3lZx/0TN/B/0XWZA1GAWCak= 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=e++wb/Ay; 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=1718279454; 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=QeDlmSjlnwr2O/aP5XCLyUukk4Ihvpzfb1AuxNmdg5k=; b=e++wb/Ayii81mKY/qGs4HIDWx44Wepvu9Jk7wZOD1DuQr37InJezBG+xwLywiDlG7ty3L3 DMs+WqUCygZrnqERpchM2SWazcqUO21ZnpFndtncYlUdr0tmqw+YHG0jsycdkkI20bjezY AY26I5RpQ23FQJqBPSrg07J7n0w+E5A= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-53-DM6Oq8b7OO2WPmA-Kf3hPg-1; Thu, 13 Jun 2024 07:50:52 -0400 X-MC-Unique: DM6Oq8b7OO2WPmA-Kf3hPg-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4217e21bcd4so1585975e9.2 for ; Thu, 13 Jun 2024 04:50:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279451; x=1718884251; 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=QeDlmSjlnwr2O/aP5XCLyUukk4Ihvpzfb1AuxNmdg5k=; b=SXOBGMRMi1IKejI4GI0tsEzGMozA6xO7UJk4ddymnNZqD7p41Nb7HbLk1XtHmXOGtb 6kp68RQt2voQHW/SAFyhqlV9QAYxZ3eMv387DtTciWDw8SMyF16joPu/DtGRhrRyHnFb fI15D6KRMyhVOcZix6i797DpBXKOUdhbdcFipDAC98fyBKd5fkr1vi2yCvjOUvk/nLfc 34B60eWWF3BwmH07/ki8s+ga1E9p4BPcj5ZXuxw2gT9oQjVqrNjeRFzwsLV8yT8Yslzy 30xmOxwnzZDChPK/gHANfgQlXyceJiC2XYqzKQv94Dd3vJeCpWdC9qtkAStLJDsia9CN 19+w== X-Forwarded-Encrypted: i=1; AJvYcCVhKAM+IgQIJ03d9qbqUPOjdBQYo4vFSNHeFX3KKEFD+hKCAQ9jlhq+wD7UwfUgLfDlz7hz4JBpDbPmcm9zJlZnrMr1Tu/Gc4zU X-Gm-Message-State: AOJu0YyM/eFXc3eGYH7Yt6onvDN8dkXdU+pNdRPqbKqFDhBTA+MA9VbD jnfhgPa1sC5bUit0B4BWlL6CUH9sMbh0CvbwORUwtAPCG8ae0wls3TvwBmL2e3OgbIeCY53Z3n1 1lDeafWsrsYYf7RHIjulkXDiI0XxScwhBuPCRPZlhtvUwV8lvqNSrCoDvmQ== X-Received: by 2002:a05:6000:1845:b0:35f:1f7e:892e with SMTP id ffacd0b85a97d-36079a5fdddmr172023f8f.7.1718279451483; Thu, 13 Jun 2024 04:50:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpv9lSaVfD9w56GIK9nZEr6kUGUg9N6/YznSMrwsXxnz492p2v4uVfvUh2ehH31as5XiaCgw== X-Received: by 2002:a05:6000:1845:b0:35f:1f7e:892e with SMTP id ffacd0b85a97d-36079a5fdddmr172006f8f.7.1718279451134; Thu, 13 Jun 2024 04:50:51 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 04:50:50 -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 06/13] PCI: Warn users about complicated devres nature Date: Thu, 13 Jun 2024 13:50:19 +0200 Message-ID: <20240613115032.29098-7-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> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The PCI region-request functions become managed functions when pcim_enable_device() has been called previously instead of pci_enable_device(). This has already caused a bug (in 8558de401b5f) by confusing users, who came to believe that all PCI functions, such as pci_iomap_range(), suddenly are managed that way, which is not the case. Add comments to the relevant functions' docstrings that warn users about this behavior. Link: https://lore.kernel.org/r/20240605081605.18769-8-pstanner@redhat.com Signed-off-by: Philipp Stanner Signed-off-by: Bjorn Helgaas --- drivers/pci/iomap.c | 16 ++++++++++++++++ drivers/pci/pci.c | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/drivers/pci/iomap.c b/drivers/pci/iomap.c index c9725428e387..a715a4803c95 100644 --- a/drivers/pci/iomap.c +++ b/drivers/pci/iomap.c @@ -23,6 +23,10 @@ * * @maxlen specifies the maximum length to map. If you want to get access to * the complete BAR from offset to the end, pass %0 here. + * + * NOTE: + * This function is never managed, even if you initialized with + * pcim_enable_device(). * */ void __iomem *pci_iomap_range(struct pci_dev *dev, int bar, @@ -63,6 +67,10 @@ EXPORT_SYMBOL(pci_iomap_range); * * @maxlen specifies the maximum length to map. If you want to get access to * the complete BAR from offset to the end, pass %0 here. + * + * NOTE: + * This function is never managed, even if you initialized with + * pcim_enable_device(). * */ void __iomem *pci_iomap_wc_range(struct pci_dev *dev, int bar, @@ -106,6 +114,10 @@ EXPORT_SYMBOL_GPL(pci_iomap_wc_range); * * @maxlen specifies the maximum length to map. If you want to get access to * the complete BAR without checking for its length first, pass %0 here. + * + * NOTE: + * This function is never managed, even if you initialized with + * pcim_enable_device(). If you need automatic cleanup, use pcim_iomap(). * */ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen) { @@ -127,6 +139,10 @@ EXPORT_SYMBOL(pci_iomap); * * @maxlen specifies the maximum length to map. If you want to get access to * the complete BAR without checking for its length first, pass %0 here. + * + * NOTE: + * This function is never managed, even if you initialized with + * pcim_enable_device(). * */ void __iomem *pci_iomap_wc(struct pci_dev *dev, int bar, unsigned long maxlen) { diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 7013699db242..5e4f377411ec 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3900,6 +3900,8 @@ EXPORT_SYMBOL(pci_release_region); * @res_name: Name to be associated with resource. * @exclusive: whether the region access is exclusive or not * + * Returns: 0 on success, negative error code on failure. + * * Mark the PCI region associated with PCI device @pdev BAR @bar as * being reserved by owner @res_name. Do not access any * address inside the PCI regions unless this call returns @@ -3950,6 +3952,8 @@ static int __pci_request_region(struct pci_dev *pdev, int bar, * @bar: BAR to be reserved * @res_name: Name to be associated with resource * + * Returns: 0 on success, negative error code on failure. + * * Mark the PCI region associated with PCI device @pdev BAR @bar as * being reserved by owner @res_name. Do not access any * address inside the PCI regions unless this call returns @@ -3957,6 +3961,11 @@ static int __pci_request_region(struct pci_dev *pdev, int bar, * * Returns 0 on success, or %EBUSY on error. A warning * message is also printed on failure. + * + * NOTE: + * This is a "hybrid" function: It's normally unmanaged, but becomes managed + * when pcim_enable_device() has been called in advance. This hybrid feature is + * DEPRECATED! If you want managed cleanup, use the pcim_* functions instead. */ int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name) { @@ -4007,6 +4016,13 @@ static int __pci_request_selected_regions(struct pci_dev *pdev, int bars, * @pdev: PCI device whose resources are to be reserved * @bars: Bitmask of BARs to be requested * @res_name: Name to be associated with resource + * + * Returns: 0 on success, negative error code on failure. + * + * NOTE: + * This is a "hybrid" function: It's normally unmanaged, but becomes managed + * when pcim_enable_device() has been called in advance. This hybrid feature is + * DEPRECATED! If you want managed cleanup, use the pcim_* functions instead. */ int pci_request_selected_regions(struct pci_dev *pdev, int bars, const char *res_name) @@ -4015,6 +4031,19 @@ int pci_request_selected_regions(struct pci_dev *pdev, int bars, } EXPORT_SYMBOL(pci_request_selected_regions); +/** + * pci_request_selected_regions_exclusive - Request regions exclusively + * @pdev: PCI device to request regions from + * @bars: bit mask of BARs to request + * @res_name: name to be associated with the requests + * + * Returns: 0 on success, negative error code on failure. + * + * NOTE: + * This is a "hybrid" function: It's normally unmanaged, but becomes managed + * when pcim_enable_device() has been called in advance. This hybrid feature is + * DEPRECATED! If you want managed cleanup, use the pcim_* functions instead. + */ int pci_request_selected_regions_exclusive(struct pci_dev *pdev, int bars, const char *res_name) { @@ -4032,7 +4061,6 @@ EXPORT_SYMBOL(pci_request_selected_regions_exclusive); * successful call to pci_request_regions(). Call this function only * after all use of the PCI regions has ceased. */ - void pci_release_regions(struct pci_dev *pdev) { pci_release_selected_regions(pdev, (1 << PCI_STD_NUM_BARS) - 1); @@ -4064,6 +4092,8 @@ EXPORT_SYMBOL(pci_request_regions); * @pdev: PCI device whose resources are to be reserved * @res_name: Name to be associated with resource. * + * Returns: 0 on success, negative error code on failure. + * * Mark all PCI regions associated with PCI device @pdev as being reserved * by owner @res_name. Do not access any address inside the PCI regions * unless this call returns successfully. @@ -4073,6 +4103,11 @@ EXPORT_SYMBOL(pci_request_regions); * * Returns 0 on success, or %EBUSY on error. A warning message is also * printed on failure. + * + * NOTE: + * This is a "hybrid" function: It's normally unmanaged, but becomes managed + * when pcim_enable_device() has been called in advance. This hybrid feature is + * DEPRECATED! If you want managed cleanup, use the pcim_* functions instead. */ int pci_request_regions_exclusive(struct pci_dev *pdev, const char *res_name) { @@ -4404,6 +4439,11 @@ void pci_disable_parity(struct pci_dev *dev) * @enable: boolean: whether to enable or disable PCI INTx * * Enables/disables PCI INTx for device @pdev + * + * NOTE: + * This is a "hybrid" function: It's normally unmanaged, but becomes managed + * when pcim_enable_device() has been called in advance. This hybrid feature is + * DEPRECATED! */ void pci_intx(struct pci_dev *pdev, int enable) { From patchwork Thu Jun 13 11:50:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 1947358 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ONkuou/t; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-pci+bounces-8724-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0LSn2HJKz1ydW for ; Thu, 13 Jun 2024 21:55:21 +1000 (AEST) 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 9E9121F25FD7 for ; Thu, 13 Jun 2024 11:55:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 543D014883F; Thu, 13 Jun 2024 11:50:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ONkuou/t" X-Original-To: linux-pci@vger.kernel.org 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 6775F1487DA for ; Thu, 13 Jun 2024 11:50:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279458; cv=none; b=iim1XLLH9+mYI2LVJuiWExpBRiYd5A9FCOppRbQMwXZFeIzgrF8BqxqiSw7uARdDrHZBlX8JHIEYFDwVodyIiICO3SPlUvPWDo56+1n79ScYF+G+TV3F0a6kxTD/Q04SF3GwTpThcZUa7ip4iGPddHgNle58J+Y5kiwHxHAmFbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279458; c=relaxed/simple; bh=xCJskR4ZILXQ5wDrghh4Sq+j29QXGosY9+0FgltF0/I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=di6j+U9SchSKWrWgvPM13TSbWtJ1kN/nJCx+zf/aQ/hNo6KGcfOBQUnumC1HFK+HvybjGt34R2zn5vIJGKKWs3FjaGWMGcaA+QhcbntTjG7ZSUGD02a08ncWwGGN5+a+W3RfqqcUxLIUX1aZlUsxuC8wm2QjhrjGLBhwvxmPdKo= 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=ONkuou/t; arc=none smtp.client-ip=170.10.133.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=1718279455; 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=qMEejGKihJo2G832kSH48RcHSFeE2XrrHWpYzOQBaEo=; b=ONkuou/tKfMRfE3Y/QnJKm4lGCi2cZQPQ6CR6B8qrIHmWlDf6dkZy/8/YGVroVTM3SXGci dFHoNd2HBkFREFwznSprQjI6MC4oBGT1fBE8BscpPV1Jz/hfRUGxl2sdih+3Lg0nomAeyg SfakEpQhEiy0kHSgOCD2m7Oh/M8czbc= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-100-xOXLsQoaPJ26jUEsS2dcwA-1; Thu, 13 Jun 2024 07:50:54 -0400 X-MC-Unique: xOXLsQoaPJ26jUEsS2dcwA-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2ebd962eb88so397811fa.3 for ; Thu, 13 Jun 2024 04:50:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279453; x=1718884253; 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=qMEejGKihJo2G832kSH48RcHSFeE2XrrHWpYzOQBaEo=; b=IJQTJLaz/JrDH3EJZUcvkZRiP0NdF7B1s5e1MQ2noqDyW0iTfRz4IzTrt9Wn1tsVBE cf32u+/76qGupQYfaHwSPMFO5jK6fRGoFSJfCscvzZ1RH1V8vv9eigPIVBIjLD4zHvCW XbkLIp6C16a/h2RJHoAJKWpcvKI5v9L/Mdt5pYhdvE0o7+jQHkSBRw0Fs9TpGDzy7zZ9 D8VuXEnpXwMuhwXXBE1iMq5jFGbPXlR5Cb7L/9w9AZGyZNvpI/PKtvMXY4aWKMTIeZS/ m+woebxePk89EIt3QjVKQZzKRsM2Fg3FCxE2op5ZxNLrkIotRIAo/9KuS+fg7uT9hKWr nyuQ== X-Forwarded-Encrypted: i=1; AJvYcCUDHDvsoPcpCNm8SHTYXogAzWYZaP2PsP0FqRGa4yQOJM1VepQxsIOT2GebrGSBD0w5UhKemPcw8XeHA/G30ReSz4Y/QftoloYC X-Gm-Message-State: AOJu0YwFP5upI+7nkCAMUGXVVLW+1AaEdHRFEp58TQMDtnaIVH4e0k5t jQvBOhPOT9nhT+FbHaZOv5VWRAzD8lPdOXXnTxJE7Cb9EnSddH7tShL7g9+pxSLqcN3ut5KU+Pn 7zPzqdIfpht4qu4wkYBqkgXOu5iq50P3gdp8guzuWklve0fUE4x+pFiBz6A== X-Received: by 2002:a05:6512:1598:b0:52c:8784:5b2c with SMTP id 2adb3069b0e04-52ca5d03c67mr13446e87.3.1718279452684; Thu, 13 Jun 2024 04:50:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEqupRIXquizQF60Ogvk1gSUj/lELnfPgWk0B7d0l5dOVUd+wsdDCM/WABqJ9TrRzGJhmkEQ== X-Received: by 2002:a05:6512:1598:b0:52c:8784:5b2c with SMTP id 2adb3069b0e04-52ca5d03c67mr13426e87.3.1718279452377; Thu, 13 Jun 2024 04:50:52 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 04:50:51 -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 07/13] PCI: Remove enabled status bit from pci_devres Date: Thu, 13 Jun 2024 13:50:20 +0200 Message-ID: <20240613115032.29098-8-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> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The PCI devres implementation has a separate boolean to track whether a device is enabled. That, however, can easily be tracked in an agnostic manner through the function pci_is_enabled(). Using it allows for simplifying the PCI devres implementation. Replace the separate 'enabled' status bit from struct pci_devres with calls to pci_is_enabled() at the appropriate places. Signed-off-by: Philipp Stanner --- drivers/pci/devres.c | 11 ++++------- drivers/pci/pci.c | 6 ------ drivers/pci/pci.h | 1 - 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index d90bed785c3f..643e3a94a1d6 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 (pci_is_enabled(dev) && !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 || !pci_is_enabled(pdev)); if (dr) dr->pinned = 1; } diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 5e4f377411ec..db2cc48f3d63 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2218,12 +2218,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 2403c5a0ff7a..d7f00b43b098 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -821,7 +821,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; From patchwork Thu Jun 13 11:50:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 1947360 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=h8Cfdo2Q; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-pci+bounces-8726-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0LT505yxz1ydW for ; Thu, 13 Jun 2024 21:55:37 +1000 (AEST) 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3ACED1C22892 for ; Thu, 13 Jun 2024 11:55:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C662148FEB; Thu, 13 Jun 2024 11:51:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="h8Cfdo2Q" X-Original-To: linux-pci@vger.kernel.org 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 087B2148837 for ; Thu, 13 Jun 2024 11:50:57 +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=1718279459; cv=none; b=MS2Pf7W3YneH45jJ19omMLp+dJ6mWgpL9rlcQ0+hFqkhrxwoPU8RoogUN4YZStoht2Cn03LLm+HgTgWl0+h7ztP8ViNdyD8UT743RfqTTgRKGq2UMKQj71WYO5ueTlOL3V0r/BbePmtL4MOMzhUdbGLY8OlKDsSCy8OKvjpPrd0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279459; c=relaxed/simple; bh=pCQsKw5JTEucg35lXycT49o+c0HiqjktK3rXy0MLKzM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pge9Etxb+tuXwyoJoXQa4t11/GGhcGsD+mPhOJ5Hvh92m5n9fV9Xg6yHHfuOe43IlAKnoUwoN0ZPmgKJtiHl5JZKjrsWLgR/fhDzNNQKznm/atyr9qSxC+GAhm79kcX9SVJl/AV30TgP6LYhGhUETRnVt4RuaVtYw3/ruDog9HI= 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=h8Cfdo2Q; 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=1718279457; 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=cVfgCjKnb7mN7tw6g3EsRXSFrlAe3Q6EtTbj0A26jHk=; b=h8Cfdo2QREHXS+XW3Qn/4dbxXQ8yNMudE6eowX96DkN2B14bjGwJ+/vXef1Vp3ITsingyn RjM2GzEZTWi0M9e7oMMPAfRGHZ7Qrr4j4EscEtPbuv+YAOGih7/9IUWfXdH1M+Dc/YepWR 7+IWxZ2ntlaTOOArLXEqNOUmjUNtkao= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-H6sqTD9COZGHohC0C-YE9A-1; Thu, 13 Jun 2024 07:50:55 -0400 X-MC-Unique: H6sqTD9COZGHohC0C-YE9A-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2eaeaefbcc6so1418861fa.3 for ; Thu, 13 Jun 2024 04:50:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279454; x=1718884254; 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=cVfgCjKnb7mN7tw6g3EsRXSFrlAe3Q6EtTbj0A26jHk=; b=nCrmXz96nLBxbiGkXcjHfiraMSbFrlnUY3PV7/+L14s0sAcnBRf7hA/1S7+f3V3XdG mAdwYxJRpvMAa83jSUXPfnkfEuLnfatXdJ6KpqmcckTZsC2S9AXvJ/BSxga+RFOAoJkL xov+a/H1VdaL6Yr2jUatyanrubaNFCtz9/UpdFkfCEwAWBiBXONLdRoo/aWkaCyQB3ph RtHqQN5a+xrrpEg/Ega4yzIMi3GnqANnvI3TAlXNYa1tUVxqm10MmycM7Rf5RlaMuskq SxyiKdmnNcyMpBYV0r/gEcBQBwt/FMM/+CuJD/d7W/pu4TEddwF3qif709mFNUf+LHjg zukw== X-Forwarded-Encrypted: i=1; AJvYcCUiMCrNACnvr+nXSInFxFBAzF+jktHx6TjtL2feqRUCHrEh6gkeuEwgrDXI1/DPHgrCNFUVAqhbeXP/r8Gei6JwGNcAfcnRSm1P X-Gm-Message-State: AOJu0Yx6xO+W1Hem65t0zFAm/jbdXDiouX+zl8mR2hY5OuGmV3Wa1y3+ Jdp7S1f9hPqHllC2Yp/q+vEn4JZMXEh0z9TkThBmCtXVf5bEEjvpsG5vWGxQMcNTvI+9wsxqMf/ VtkM7nhgnaNGz4QkFVjEdbhJHNQD5g8+HrtD42yLPfEBWx/yZPu/WLs92gw== X-Received: by 2002:a05:6512:ac3:b0:52c:9e80:387a with SMTP id 2adb3069b0e04-52ca59e9d11mr72165e87.0.1718279453801; Thu, 13 Jun 2024 04:50:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3dSZsb8l1qGTBxCy/CxpKhrwqSIxs3fGuB9Mz5Llia8E6mlHaM5OG7LJkgO+LSWP5CNnfZA== X-Received: by 2002:a05:6512:ac3:b0:52c:9e80:387a with SMTP id 2adb3069b0e04-52ca59e9d11mr72136e87.0.1718279453401; Thu, 13 Jun 2024 04:50:53 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 04:50:53 -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 08/13] PCI: Move pinned status bit to struct pci_dev Date: Thu, 13 Jun 2024 13:50:21 +0200 Message-ID: <20240613115032.29098-9-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> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The bit describing whether the PCI device is currently pinned is stored in struct pci_devres. To clean up and simplify the PCI devres API, it's better if this information is stored in struct pci_dev. This will later permit simplifying pcim_enable_device(). Move the 'pinned' boolean bit to struct pci_dev. Restructure bits in struct pci_dev so the pm / pme fields are next to each other. Signed-off-by: Philipp Stanner --- drivers/pci/devres.c | 14 ++++---------- drivers/pci/pci.h | 1 - include/linux/pci.h | 3 ++- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index 643e3a94a1d6..84caa0034813 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 (pci_is_enabled(dev) && !this->pinned) + if (pci_is_enabled(dev) && !dev->pinned) pci_disable_device(dev); } @@ -459,18 +459,12 @@ EXPORT_SYMBOL(pcim_enable_device); * pcim_pin_device - Pin managed PCI device * @pdev: PCI device to pin * - * Pin managed PCI device @pdev. Pinned device won't be disabled on - * driver detach. @pdev must have been enabled with - * pcim_enable_device(). + * Pin managed PCI device @pdev. Pinned device won't be disabled on driver + * detach. @pdev must have been enabled with pcim_enable_device(). */ void pcim_pin_device(struct pci_dev *pdev) { - struct pci_devres *dr; - - dr = find_pci_dr(pdev); - WARN_ON(!dr || !pci_is_enabled(pdev)); - if (dr) - dr->pinned = 1; + pdev->pinned = true; } EXPORT_SYMBOL(pcim_pin_device); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index d7f00b43b098..6e02ba1b5947 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -821,7 +821,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 pinned:1; unsigned int orig_intx:1; unsigned int restore_intx:1; unsigned int mwi:1; diff --git a/include/linux/pci.h b/include/linux/pci.h index fb004fd4e889..0c19f0717899 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -367,10 +367,11 @@ struct pci_dev { this is D0-D3, D0 being fully functional, and D3 being off. */ u8 pm_cap; /* PM capability offset */ - unsigned int imm_ready:1; /* Supports Immediate Readiness */ unsigned int pme_support:5; /* Bitmask of states from which PME# can be generated */ unsigned int pme_poll:1; /* Poll device's PME status bit */ + unsigned int pinned:1; /* Whether this dev is pinned */ + unsigned int imm_ready:1; /* Supports Immediate Readiness */ unsigned int d1_support:1; /* Low power state D1 is supported */ unsigned int d2_support:1; /* Low power state D2 is supported */ unsigned int no_d1d2:1; /* D1 and D2 are forbidden */ From patchwork Thu Jun 13 11:50:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 1947359 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aI1JMrCV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-pci+bounces-8725-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0LT21LYBz1ydW for ; Thu, 13 Jun 2024 21:55:34 +1000 (AEST) 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5BD921C227C0 for ; Thu, 13 Jun 2024 11:55:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5FC71459EA; Thu, 13 Jun 2024 11:50:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aI1JMrCV" X-Original-To: linux-pci@vger.kernel.org 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 0E30A1459E5 for ; Thu, 13 Jun 2024 11:50:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279459; cv=none; b=i4/oPar5QCfelytGcX4543uh9jSuOJxyiSO6mTi7kUMNN/DQBfY/h8AZuvzSK4GiQq736lHikFPdThgp+OF1c8tqb+wkcrTrDmMnTmeSyxkF8tyQjTBoPVk7Wx/C+NfrUtLow8Y7K4Z/wucUAxOoTR7BcHqC77cwgk5havyx3a4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279459; c=relaxed/simple; bh=MwGxicOTdTG5eVnpyN9pPmSLSF5RFtnjndQbPoUTe1Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=me3ESZgrPgdzsxv/VrwbVw65RcSQpaS0tlQ0xybF/6tFPV9rDllCl5Uk7CqzMoKSxZKok7ZneM0NYiYPrdFXS1VBB9OjbIA2uXxnv58XhmJi1whVWia8AVgwTj/BqoECaznxCqofri6cYa/ft5cEhA+6P/77MCUJF5l9Hu6S8Hg= 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=aI1JMrCV; arc=none smtp.client-ip=170.10.133.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=1718279457; 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=Kh8+O2F7jgAFtGp/MUXcCP7XcWz8NnTH6l7tP4PdYbo=; b=aI1JMrCV0MYatILd9FSeNlnIr4oKuFgiaUndJUbTgz00JzPhN2nvfayJFWHlZp1EMGn2MW gFpqu5xy6l7p+erscQmlD5UV7QgcRrW1os/9G2VqNfZ0oItSh5kmBzCgqUchsN7eVL0CvT i1Jg/p3WESg4B6I8jdjWxfkecx5EQyY= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-jrBxgQNvP6C7IzhjDfZozg-1; Thu, 13 Jun 2024 07:50:55 -0400 X-MC-Unique: jrBxgQNvP6C7IzhjDfZozg-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-354dfd4971dso106186f8f.0 for ; Thu, 13 Jun 2024 04:50:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279454; x=1718884254; 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=Kh8+O2F7jgAFtGp/MUXcCP7XcWz8NnTH6l7tP4PdYbo=; b=PShWxhT1EoP60xC5JZuw4LvcGK8owR8092owmHDzqbd3CIyljgZQEGwWIuM5xwIlfH UBlVz4O2Jha9GXw0QKuuIvbrlqpFASeaP02c/F7rAukFtjpHOmkdZvzsLVJR7CF3Zg9A IF4ThIQ+4cD4b6bmkMFMCE9/XSbUugiChZLdL2F4QypW/53v2TFTbRC63DsCNwJmb8pt TUG4o108EBqj0YmVWbTOZRsXblSp9uU6E7UhGUbcU2i+JNkRUzXasRXoTHsdXkGdRMWq yfDb4xoMwINjbQ2A6hDRTzzta6cZOYbCjJSn7+cSczCQtI1KqSwM5tIN0tzoFiQ6vfEm PPDQ== X-Forwarded-Encrypted: i=1; AJvYcCUGmadJhlR+jpYLOjVq143pZYWtA5OvedHEEsHG6eEgKQbWC+iUQbxmg2VYYcHRLhZXfojEQzAnsUU=@vger.kernel.org X-Gm-Message-State: AOJu0YzpmmT/NUkW8bZ+MHnJg1V8pI9vw7lbYTL4pW2+Ie3ohxjTb1FF zX5zbdHY5FyfTIJT47PCXZaYQ0GiUgWqLzv9hUphe3tFJE5CsQUgiCIF7DOz3Ocpp7rsjsULw+r 6P0k4TcwInWJxcWySwPnSv2kem7aEuHcXJEQsbtVKR8S0DolUYowsubnRaw== X-Received: by 2002:a5d:5f93:0:b0:360:6f5c:f5b3 with SMTP id ffacd0b85a97d-36079a6be34mr198403f8f.7.1718279454626; Thu, 13 Jun 2024 04:50:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWMTtngZAgGMBECTjwydMRwQNlXRtCSyH8PxV40YfOhooXvc8s+2rU6f0CqUMNMS0veU1KZA== X-Received: by 2002:a5d:5f93:0:b0:360:6f5c:f5b3 with SMTP id ffacd0b85a97d-36079a6be34mr198391f8f.7.1718279454381; Thu, 13 Jun 2024 04:50:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 04:50:54 -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 09/13] PCI: Give pcim_set_mwi() its own devres callback Date: Thu, 13 Jun 2024 13:50:22 +0200 Message-ID: <20240613115032.29098-10-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> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Managing pci_set_mwi() with devres can easily be done with its own callback, without the necessity to store any state about it in a device-related struct. Remove the MWI state from struct pci_devres. Give pcim_set_mwi() a separate devres-callback. Signed-off-by: Philipp Stanner --- drivers/pci/devres.c | 29 ++++++++++++++++++----------- drivers/pci/pci.h | 1 - 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index 84caa0034813..e8de93e95eb6 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -366,24 +366,34 @@ void __iomem *devm_pci_remap_cfg_resource(struct device *dev, } EXPORT_SYMBOL(devm_pci_remap_cfg_resource); +static void __pcim_clear_mwi(void *pdev_raw) +{ + struct pci_dev *pdev = pdev_raw; + + pci_clear_mwi(pdev); +} + /** * pcim_set_mwi - a device-managed pci_set_mwi() - * @dev: the PCI device for which MWI is enabled + * @pdev: the PCI device for which MWI is enabled * * Managed pci_set_mwi(). * * RETURNS: An appropriate -ERRNO error value on error, or zero for success. */ -int pcim_set_mwi(struct pci_dev *dev) +int pcim_set_mwi(struct pci_dev *pdev) { - struct pci_devres *dr; + int ret; - dr = find_pci_dr(dev); - if (!dr) - return -ENOMEM; + ret = devm_add_action(&pdev->dev, __pcim_clear_mwi, pdev); + if (ret != 0) + return ret; + + ret = pci_set_mwi(pdev); + if (ret != 0) + devm_remove_action(&pdev->dev, __pcim_clear_mwi, pdev); - dr->mwi = 1; - return pci_set_mwi(dev); + return ret; } EXPORT_SYMBOL(pcim_set_mwi); @@ -397,9 +407,6 @@ static void pcim_release(struct device *gendev, void *res) struct pci_dev *dev = to_pci_dev(gendev); struct pci_devres *this = res; - if (this->mwi) - pci_clear_mwi(dev); - if (this->restore_intx) pci_intx(dev, this->orig_intx); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 6e02ba1b5947..c355bb6a698d 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) struct pci_devres { unsigned int orig_intx:1; unsigned int restore_intx:1; - unsigned int mwi:1; }; struct pci_devres *find_pci_dr(struct pci_dev *pdev); From patchwork Thu Jun 13 11:50:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 1947362 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bWlAy/pe; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-pci+bounces-8728-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0LV20gRLz1ydW for ; Thu, 13 Jun 2024 21:56:26 +1000 (AEST) 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 7B53D1F268C4 for ; Thu, 13 Jun 2024 11:56:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02387145A14; Thu, 13 Jun 2024 11:51:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bWlAy/pe" X-Original-To: linux-pci@vger.kernel.org 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 195B7149011 for ; Thu, 13 Jun 2024 11:51:00 +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=1718279462; cv=none; b=Y6g0+xozB58VeitySD28VnoseO715OmHUH/d6V1HoK7KCgJdGK2ff9MSPFEWdamlnokPP46yBJoQMzd4Th6klEsJpRRQJrGaWG4v0cHFru8spkVojDrXJ/bW6g+uTypLvnNUatVCtbHE0hkSR2FUUNSmPKBQsF0TbrpkorYAYp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279462; c=relaxed/simple; bh=mgYu+PdBk2Uxe11LPVB6MI3T1q9XfYavbWG7yJM+v24=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AeJ/KyjjjHVmW1u+g6joE6hnr9rDvSiR7AsTXPOQ4YxDkY9ToqJi7m0XHHglpJiN//zAZ24myKcjCtVn8wtqFC421FY7Bz97PDqxDSPdo0n2BXrXUSIGkR9BcEqxFEt/qMhx64N6H1GoVkbZV7rwk0awiBuN1T3ozRkdA0kKrtI= 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=bWlAy/pe; 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=1718279460; 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=UXtJP09mnY/VoBFabkO3D30y5UZGrDuagfM4gYTmfUM=; b=bWlAy/peIAtgXU0jJ6x2w36K00YFLpILrChPW47Mx7uOGGTQoPs0Mkdrl0R4CTEauTQmhu sNMgfHOlsDIMK4Je26yc9ja6zClvvRBVOMcKH/mlAL8rjbnfRw9/FSF3RTbRE99TUrVSQ6 QH851d/rfGoYtw6gv77QP0WBe5ZKnn0= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-539-Byc60YzEP8q7kuk2auIaOQ-1; Thu, 13 Jun 2024 07:50:56 -0400 X-MC-Unique: Byc60YzEP8q7kuk2auIaOQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42183fdb22bso1602495e9.1 for ; Thu, 13 Jun 2024 04:50:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279456; x=1718884256; 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=UXtJP09mnY/VoBFabkO3D30y5UZGrDuagfM4gYTmfUM=; b=C38djLX0ijrna8i0NfMUQcih+M0sY3eP1PsssciegHdnsNwD28XXAxc/44b8I+sM5T XLd/9iwvsy1A3r3mOH17P0HlgPHvwzOK4pqu63jTm4EPQ2+2HvsJPT99qVedZYFxDbFk O3BSTyfqMdAFIpk3OoW9a6RZtui+Z06KpeZiu4QlTj5VwqCC0A2izbO+fTxftZRPgUpU uqb2L/pTXflbIanIEKhbZRET+/o1mlSmpXq8/E1EFJ27kfjlcet2nc35IIQ6d5YpWDP7 NlPkFA2X2RNJ9A7xQVKf29YwtYt99CYp81R0GZWQJca5H/0MAZFGg9nG3fTGNfZOYBPS GIzA== X-Forwarded-Encrypted: i=1; AJvYcCWFFH55hKmFVl9DPV8hmvvYTzrp1BpsNmF7hlvWjiEO1TX/PnpDdDQ2wkQKgXjJhvtEHqI9Xn5VkzYMwQc47WDoc3Y9IhQ/8t0U X-Gm-Message-State: AOJu0Yw/t3MKt7IKu2w6tRP5MlxMONgPqb+RR05DbGqFIq/1YcBIT+9I gGUpFjLhS8J5LtmQpD61uepd3xv6uD8uTeV8Pd7sah6+2T/foO2pdwDwA4J/UW1mNMrqCQh3OJP 0u0qlNPY8ft0R1UKd+BYOBQx2EWi0u0WRmi68SU90Nyq8hRd4yYsXD03PEw== X-Received: by 2002:a05:6000:1aca:b0:35f:305d:d2c8 with SMTP id ffacd0b85a97d-36079a4c065mr196888f8f.3.1718279455710; Thu, 13 Jun 2024 04:50:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFg6sk3xnm8Dx/Hnr1TCgUs2mRnf7/ulhG/8nI0xWi/V2RpnZJUye6zcNtI5u+FrxW/ybB/fw== X-Received: by 2002:a05:6000:1aca:b0:35f:305d:d2c8 with SMTP id ffacd0b85a97d-36079a4c065mr196879f8f.3.1718279455407; Thu, 13 Jun 2024 04:50:55 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 04:50:55 -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 10/13] PCI: Give pci_intx() its own devres callback Date: Thu, 13 Jun 2024 13:50:23 +0200 Message-ID: <20240613115032.29098-11-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> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 pci_intx() is one of the functions that have "hybrid mode" (i.e., sometimes managed, sometimes not). Providing a separate pcim_intx() function with its own device resource and cleanup callback allows for removing further large parts of the legacy PCI devres implementation. As in the region-request-functions, pci_intx() has to call into its managed counterpart for backwards compatibility. As pci_intx() is an outdated function, pcim_intx() shall not be made visible to drivers via a public API. Implement pcim_intx() with its own device resource. Make pci_intx() call pcim_intx() in the managed case. Remove the now surplus function find_pci_dr(). Signed-off-by: Philipp Stanner Reported-by: Ashish Kalra Signed-off-by: Philipp Stanner Tested-by: Ashish Kalra --- drivers/pci/devres.c | 76 ++++++++++++++++++++++++++++++++++++-------- drivers/pci/pci.c | 21 ++++++------ drivers/pci/pci.h | 13 ++++---- 3 files changed, 80 insertions(+), 30 deletions(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index e8de93e95eb6..7b72c952a9e5 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -42,6 +42,11 @@ struct pcim_iomap_devres { void __iomem *table[PCI_STD_NUM_BARS]; }; +/* Used to restore the old intx state on driver detach. */ +struct pcim_intx_devres { + int orig_intx; +}; + enum pcim_addr_devres_type { /* Default initializer. */ PCIM_ADDR_DEVRES_TYPE_INVALID, @@ -397,32 +402,75 @@ int pcim_set_mwi(struct pci_dev *pdev) } EXPORT_SYMBOL(pcim_set_mwi); + static inline bool mask_contains_bar(int mask, int bar) { return mask & BIT(bar); } -static void pcim_release(struct device *gendev, void *res) +static void pcim_intx_restore(struct device *dev, void *data) { - struct pci_dev *dev = to_pci_dev(gendev); - struct pci_devres *this = res; + struct pci_dev *pdev = to_pci_dev(dev); + struct pcim_intx_devres *res = data; - if (this->restore_intx) - pci_intx(dev, this->orig_intx); + pci_intx(pdev, res->orig_intx); +} - if (pci_is_enabled(dev) && !dev->pinned) - pci_disable_device(dev); +static struct pcim_intx_devres *get_or_create_intx_devres(struct device *dev) +{ + struct pcim_intx_devres *res; + + res = devres_find(dev, pcim_intx_restore, NULL, NULL); + if (res) + return res; + + res = devres_alloc(pcim_intx_restore, sizeof(*res), GFP_KERNEL); + if (res) + devres_add(dev, res); + + return res; } -/* - * TODO: After the last four callers in pci.c are ported, find_pci_dr() - * needs to be made static again. +/** + * pcim_intx - managed pci_intx() + * @pdev: the PCI device to operate on + * @enable: boolean: whether to enable or disable PCI INTx + * + * Returns: 0 on success, -ENOMEM on error. + * + * Enables/disables PCI INTx for device @pdev. + * Restores the original state on driver detach. */ -struct pci_devres *find_pci_dr(struct pci_dev *pdev) +int pcim_intx(struct pci_dev *pdev, int enable) { - if (pci_is_managed(pdev)) - return devres_find(&pdev->dev, pcim_release, NULL, NULL); - return NULL; + u16 pci_command, new; + struct pcim_intx_devres *res; + + res = get_or_create_intx_devres(&pdev->dev); + if (!res) + return -ENOMEM; + + res->orig_intx = !enable; + + pci_read_config_word(pdev, PCI_COMMAND, &pci_command); + + if (enable) + new = pci_command & ~PCI_COMMAND_INTX_DISABLE; + else + new = pci_command | PCI_COMMAND_INTX_DISABLE; + + if (new != pci_command) + pci_write_config_word(pdev, PCI_COMMAND, new); + + return 0; +} + +static void pcim_release(struct device *gendev, void *res) +{ + 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) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index db2cc48f3d63..1b4832a60047 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4443,6 +4443,16 @@ void pci_intx(struct pci_dev *pdev, int enable) { u16 pci_command, new; + /* + * This is done for backwards compatibility, because the old PCI devres + * API had a mode in which this function became managed if the dev had + * been enabled with pcim_enable_device() instead of pci_enable_device(). + */ + if (pci_is_managed(pdev)) { + WARN_ON_ONCE(pcim_intx(pdev, enable) != 0); + return; + } + pci_read_config_word(pdev, PCI_COMMAND, &pci_command); if (enable) @@ -4450,17 +4460,8 @@ void pci_intx(struct pci_dev *pdev, int enable) else new = pci_command | PCI_COMMAND_INTX_DISABLE; - if (new != pci_command) { - struct pci_devres *dr; - + if (new != pci_command) pci_write_config_word(pdev, PCI_COMMAND, new); - - dr = find_pci_dr(pdev); - if (dr && !dr->restore_intx) { - dr->restore_intx = 1; - dr->orig_intx = !enable; - } - } } EXPORT_SYMBOL_GPL(pci_intx); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index c355bb6a698d..9e87528f1157 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -816,16 +816,17 @@ static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev) * 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 and find_pci_dr() only need to be here because - * they're used in pci.c. Port or move these functions to devres.c and - * then remove them from here. + * 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 { - unsigned int orig_intx:1; - unsigned int restore_intx:1; + /* + * TODO: + * This struct is now surplus. Remove it by refactoring pci/devres.c + */ }; -struct pci_devres *find_pci_dr(struct pci_dev *pdev); +int pcim_intx(struct pci_dev *dev, int enable); int pcim_request_region(struct pci_dev *pdev, int bar, const char *name); int pcim_request_region_exclusive(struct pci_dev *pdev, int bar, const char *name); 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: 1947361 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HVF7FhFw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-pci+bounces-8727-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0LTf2djGz1ydW for ; Thu, 13 Jun 2024 21:56:06 +1000 (AEST) 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 520901C20BBD for ; Thu, 13 Jun 2024 11:56:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EDE74145A11; Thu, 13 Jun 2024 11:51:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HVF7FhFw" X-Original-To: linux-pci@vger.kernel.org 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 21AA2148FF5 for ; Thu, 13 Jun 2024 11:51:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279461; cv=none; b=ETEDBYwuVFMkWKfHzQ7nJqX3g6mi0Ms3xiYbPQ8S5kF8GQ5maWfg9BQXQpAQZnHTpLq5YkLUq5V60j04jM+d86t9/MNZmT4fEoiH6p6dUkcTr4CruV4FS8eaiLeuEIkHUBZ9ohwp6LirFNE/tJNAdZc7BDUTo3htt/1oG/pj2JI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279461; c=relaxed/simple; bh=r0grzUmBcSDYCaYgn9ysXFCKA4yu6vMMhBtQa+BDezY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YAj+Wy8J/u6flc6jCdB/TlImb0XVHB2GLl3jqDko4eEm6Qms5I0m6udOFu9CQBIgygemaW9XtI+gUgI8hddrMdMYeP9UYjXZeF0i9KgyWl42hk9jhIfwLSgXnnlbupbf8BeylUP+KPlJ2hWlX2kyShpgfSefK2vOByGKoHik1ng= 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=HVF7FhFw; arc=none smtp.client-ip=170.10.133.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=1718279459; 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=DkCOJZ/wPtUvxbKR6iZK0j94vWla8EApzDXg+GJsTLg=; b=HVF7FhFw9OXidnm3QlIMvIgeUOdvT53c33TnYvYyfyEaN7MsNGp+q1rAPIkl9gJPDgPkV9 Agne8n0HMabXQDpiS4UHSpir8Pf3OpQS8mQVlW18032GBL9D8sk6WgJg4q7rxLbiRvoZmh kS+yay74tJnOMg2XEjqczx2Mz8neTCY= 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-378-LPdNPLFJPc2NSGAytRGkdA-1; Thu, 13 Jun 2024 07:50:58 -0400 X-MC-Unique: LPdNPLFJPc2NSGAytRGkdA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4210e98f8d7so1509995e9.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=AA8fzDL6Mf5ZfPV/T+CiiEGJRLfZbXoVSWPsw5Go4aqiLm/iEuL2Eivj+hgw/ZDdCB YmYnUsAFaH1xEEcBPciJ8zDTU8k9PviY2tkpb10jqroBcCSK2DsmDEsNxrOfplUhRe0o zGVYyTLqGGeZzhwI0mjgGR6Yc1FMWMejHpPwNc8Ax//V8G0WnXWCz/z4oKbrIJHsW4E/ f+cRJB6ugmhi/v7jFmoNg01p30xLQRIiLF1c6ekVKwrvSyqkEyd5CMBDBFF+kTGwwQJc asAlwREc2Qqxd6iV8R/vMJFqs+I16WwuEMjzLr1U1tUbirtdqqfAUq/7j9x8LQjWZ9dR R0Og== X-Forwarded-Encrypted: i=1; AJvYcCXzbVPnVZSFVIe581LnLuo5VQ5rwFWUxlIAiOrFG6yu88cfwVGvtu0Th5NZ1IZyftsOdttgzJWAGXI5gr5JetYv4bz/JDmNMWMn X-Gm-Message-State: AOJu0YxMTFrpw/pd9ZV7ZPJbZPYzv/ui74+4vh29x6OTfw44YILO/HHm 3qHZIAtfOFSYRP+36mUYOGkr66jswikLUHheo1BH/MfQMesrsn54cRRnMpSkVWjsMBJLlDA0rGf KNUivbVhl49TgDJO3AIUWBG4d0VlJ84qGNa6uSeuD/0VhGK03Xct5oscHvw== X-Received: by 2002:a05:6000:1845:b0:35f:e38:6758 with SMTP id ffacd0b85a97d-36079a587a3mr156388f8f.7.1718279456835; 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> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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); From patchwork Thu Jun 13 11:50:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 1947364 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZihnRTZP; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-pci+bounces-8730-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0LVk3MmMz1ydW for ; Thu, 13 Jun 2024 21:57:02 +1000 (AEST) 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 12253282B70 for ; Thu, 13 Jun 2024 11:57:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96F9E14A09A; Thu, 13 Jun 2024 11:51:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZihnRTZP" X-Original-To: linux-pci@vger.kernel.org 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 B7922149DE2 for ; Thu, 13 Jun 2024 11:51:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279465; cv=none; b=UaN743e61hBEhwGSAs2MOhTEshHekqdIO+6lf/ssA4Q4R4iRQGv4bKvWyVHwUI3GXc/H53t0V8a8VTwbU8EfoQVi3HWIL04Bt1sJwQk7ngKdFENA/2s9l14XLWZS+05EDU8pH/euxrXcbt+zD3zjSVFSkbXGdLAMngX2gxV7AVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279465; c=relaxed/simple; bh=XM+HU7hb6QVEb253YkrStrtEiG/dnPO/pYNia1HjcLU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KDIxEz6rtLJ3Ft4ufFUGFbpJqeMBAd3kvNj37r5HsT7K/Gfuh9/n+BhnOo3c9RnyW7vlnhcs2N5mQL0r1bn2sH0s3JRiAckaE9R+NbkcxRWurud6RnmSNRSICXyb5ofFTI5GD3heXtdRwvt2JIoUqGHyf/2Bl/CK3kDE4gJBcOY= 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=ZihnRTZP; arc=none smtp.client-ip=170.10.133.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=1718279462; 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=000KYz6ID2QoUMG52/WJvZNJGOa8UH1A+/S3718oumg=; b=ZihnRTZPY65ze0b+emRIlOq2jlzp3VyKFonjy89gCooNZFyQ3cCHuXGopj8xNS33P8hAwW A+/h2LoBWRa9oCF2ksRiiVmylpL6FBgq0J7NJu8EOmo+5ywJgUH654o4dxshDVFonj7h9k CuyrKwmHG1hfDCFqb252aFeCOj8CGvY= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-xIKUkm9iN7-c_F5oHzwrVA-1; Thu, 13 Jun 2024 07:51:01 -0400 X-MC-Unique: xIKUkm9iN7-c_F5oHzwrVA-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2ebe771d008so1447601fa.1 for ; Thu, 13 Jun 2024 04:51:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279460; x=1718884260; 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=000KYz6ID2QoUMG52/WJvZNJGOa8UH1A+/S3718oumg=; b=ZhKcDig2JhYcdHCgLRQZ4b27YQTUoYANNwhkq4hgylJkDzJhqhGdsA+oOJZqfxyyhy 0I/r2h2ndBGF2hOtMMBjWLK/io/bNo9R68LOR0GaJhe5E1LXf0EpAhkRgth+4veFr1O5 bl6SUIzNm95z/fTVc7UaRWaW9uVRPxbMd1Y4d3fa49iBFfVPgl+DHQmb9QD+JSyLQA1s a4GrDzw1VX3kS8CIJkQG7mqY6n6cDLbXO+W0c7ZNmrrUkE+Wnj1Y9TAO2jw1BFyMJpae k6xxEBc5EjIYMC97cSdpbfoOy65cFpsKqjdzKygV8aQdQAjr6oygOMGy3lFfvL7mQKOF wPog== X-Forwarded-Encrypted: i=1; AJvYcCVN5p4fbxnMrCQkPiNl8xGobTwUrFOmA0ju5QiNYe+KxYyiMtSsSSqtc/POiKLZm41QolQqcIeTsY9h3bJVOIlmZSW+quY7McE+ X-Gm-Message-State: AOJu0Yyy3YhjKKIsKmwTOPR5eZhCDIHPGr6C79LDCNeh6kSXjOpVEjKF VH3wgTIPSJZqHHXnvo6Gjk2cDAvB6pVyYY0StoNrRDlm8Or6G6TfFss+y8IfqoCOMguU4YWtOrw 14WC6OCjJCn7S94/RqGSuDR9OhwrruSyKrpbbEMSdEo2ZoilpehZfg5CR4Q== X-Received: by 2002:a05:6512:ac3:b0:52c:9e80:387a with SMTP id 2adb3069b0e04-52ca59e9d11mr72416e87.0.1718279459265; Thu, 13 Jun 2024 04:50:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnhuJuSAKliDxcFbokg6egscMNv+7jsPTJ86B+AWP/UZU7fL3bpTZJKANl4Bt8/kMHQDmyzw== X-Received: by 2002:a05:6512:ac3:b0:52c:9e80:387a with SMTP id 2adb3069b0e04-52ca59e9d11mr72313e87.0.1718279457545; Thu, 13 Jun 2024 04:50:57 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 04:50:57 -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 12/13] PCI: Add pcim_iomap_range() Date: Thu, 13 Jun 2024 13:50:25 +0200 Message-ID: <20240613115032.29098-13-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> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The only managed mapping function currently is pcim_iomap() which doesn't allow for mapping an area starting at a certain offset, which many drivers want. Add pcim_iomap_range() as an exported function. Signed-off-by: Philipp Stanner --- drivers/pci/devres.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 2 ++ 2 files changed, 46 insertions(+) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index 37ac8fd37291..2f0379a4e58f 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -1015,3 +1015,47 @@ void pcim_iounmap_regions(struct pci_dev *pdev, int mask) } } EXPORT_SYMBOL(pcim_iounmap_regions); + +/** + * pcim_iomap_range - Create a ranged __iomap mapping within a PCI BAR + * @pdev: PCI device to map IO resources for + * @bar: Index of the BAR + * @offset: Offset from the begin of the BAR + * @len: Length in bytes for the mapping + * + * Returns: __iomem pointer on success, an IOMEM_ERR_PTR on failure. + * + * Creates a new IO-Mapping within the specified @bar, ranging from @offset to + * @offset + @len. + * + * The mapping will automatically get unmapped on driver detach. If desired, + * release manually only with pcim_iounmap(). + */ +void __iomem *pcim_iomap_range(struct pci_dev *pdev, int bar, + unsigned long offset, unsigned long len) +{ + void __iomem *mapping; + struct pcim_addr_devres *res; + + res = pcim_addr_devres_alloc(pdev); + if (!res) + return IOMEM_ERR_PTR(-ENOMEM); + + mapping = pci_iomap_range(pdev, bar, offset, len); + if (!mapping) { + pcim_addr_devres_free(res); + return IOMEM_ERR_PTR(-EINVAL); + } + + res->type = PCIM_ADDR_DEVRES_TYPE_MAPPING; + res->baseaddr = mapping; + + /* + * Ranged mappings don't get added to the legacy-table, since the table + * only ever keeps track of whole BARs. + */ + + devres_add(&pdev->dev, res); + return mapping; +} +EXPORT_SYMBOL(pcim_iomap_range); diff --git a/include/linux/pci.h b/include/linux/pci.h index 0c19f0717899..98893a89bb5b 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2303,6 +2303,8 @@ int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name); int pcim_iomap_regions_request_all(struct pci_dev *pdev, int mask, const char *name); void pcim_iounmap_regions(struct pci_dev *pdev, int mask); +void __iomem *pcim_iomap_range(struct pci_dev *pdev, int bar, + unsigned long offset, unsigned long len); extern int pci_pci_problems; #define PCIPCI_FAIL 1 /* No PCI PCI DMA */ From patchwork Thu Jun 13 11:50:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 1947363 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=L3muyuzt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-pci+bounces-8729-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0LVV3CS7z1ydW for ; Thu, 13 Jun 2024 21:56:50 +1000 (AEST) 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 DAF621F26D20 for ; Thu, 13 Jun 2024 11:56:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 99ECB149E0A; Thu, 13 Jun 2024 11:51:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="L3muyuzt" X-Original-To: linux-pci@vger.kernel.org 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 E4256149C4C for ; Thu, 13 Jun 2024 11:51:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279464; cv=none; b=Evl91H5pu/sGc7e8MPjImf826WVCNILJflc9oCzXnyB0vfsnXFObup3W0npUEYQoLJvAiADyvGF7mN3PGi1hZbvE2pQq1Y5kPT1UBqb27GXfy4YLnLk4WVlTEJeD2GofEjcdDYvE4HxY5M7AprpclR3FCJoE/J7e2yjMByM++hk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718279464; c=relaxed/simple; bh=iGO9d2tDV8jgMXAb9ljo4BmxYhAXls7ncq8pchC9GTM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n8vmr/dnBK3qiBveU1jV/fUqDdUczZlFjNgfOIQgMBmeUUrByw/z8GSXFG+v7+9udrgEYwjM5cZjt5NOQ8tJn5cEr1bJmnxjfB9K8OQSD4ydmVUP8nNlzvy246ocUQ9OD6WA48Jo/EwFTDaXa1+Aydl0JFGg5hKA9lpPG87QYeU= 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=L3muyuzt; arc=none smtp.client-ip=170.10.133.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=1718279462; 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=9WQJKGGQ63IpYpwAqks0j3zwgngy8EFW/hBQkkDLpOw=; b=L3muyuztZ6LOEQvWQlHONgETqgjo3k/aAc7Hkw51QCOKMQRB6xTYwJBeYOPUK6MEZ6KPTu WfpkBc7PLblzJFlRiIro7q6s5FL9MZzzvKWQNOJfLWy40Yb0zOltrxBgC6a7h7YoEpAeiX l7alLtbMrwvA79dPWIvtuQ2ECHo/ozQ= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-456-zf97ePQ4O_K6OOp-MG8BGQ-1; Thu, 13 Jun 2024 07:51:00 -0400 X-MC-Unique: zf97ePQ4O_K6OOp-MG8BGQ-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-35f184b67ceso79928f8f.2 for ; Thu, 13 Jun 2024 04:51:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279459; x=1718884259; 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=9WQJKGGQ63IpYpwAqks0j3zwgngy8EFW/hBQkkDLpOw=; b=oewnUPWyQNOdHaCaXTBWtBvzUoBKjtsJq0Zlg4UI8JjKd2vLKnFMxfgKqfqEQH5CKH DoUeA4iaTBwyRqexUoMZwgCL7+flK8dn11cfmtWwPdVG2ryyojsluKP2QfePP5YuJH1A dnOdffiMZY2sFFgnb/0yvlJ8m5YijIF6VGZXvF1p2cQSj5xjZFdqgIaG1EekktM1mNcm WJmyQOISrEwHi7VLzUQPYojUq8Ig54mkEvsYNVIWQSJc5XlZMT7/ZQIDuSL0d1NHvfcQ 3zooN9XAk7/NvmyY24ERdIed6hCuFOm+s37KSMHjQw4GDYGuJfwy1TjVpQT799Jimqv2 RXhg== X-Forwarded-Encrypted: i=1; AJvYcCXf1RZPhPHI1Od9mYng8W87MBDeRj0iujYGg41KrmU2f3uFVQPVUtfm4TQYKWeB2epKJcbWywqA4YQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yzro1yRs7ta/wx/p4QccyLIrR+Z0DP5wPqIoPBS19TFZA+EWsPW P5LpqVRbj97CP3xh2h0EI3D2T9Br83nopyjoH01a7IZhVmwnUjmrAFwZPwjq5SPxDNjBzR6jAoH X1WWGm3zwkHrsxACZAS5AHXjS6K3H83gWDysqpyPDorNVWrKYM7U9oDU9/Q== X-Received: by 2002:a5d:6da4:0:b0:35f:2584:7714 with SMTP id ffacd0b85a97d-36079a55d96mr164403f8f.5.1718279459402; Thu, 13 Jun 2024 04:50:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElWKl4RSn/FE/WxBDl2/l3vU5Ab6FM43jl4nz2rwpq5A2nGMHBM+4ko0mCUeuR7gvoXMoyQA== X-Received: by 2002:a5d:6da4:0:b0:35f:2584:7714 with SMTP id ffacd0b85a97d-36079a55d96mr164394f8f.5.1718279459138; Thu, 13 Jun 2024 04:50:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 04:50:58 -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 13/13] drm/vboxvideo: fix mapping leaks Date: Thu, 13 Jun 2024 13:50:26 +0200 Message-ID: <20240613115032.29098-14-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> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When the PCI devres API was introduced to this driver, it was wrongly assumed that initializing the device with pcim_enable_device() instead of pci_enable_device() will make all PCI functions managed. This is wrong and was caused by the quite confusing PCI devres API in which some, but not all, functions become managed that way. The function pci_iomap_range() is never managed. Replace pci_iomap_range() with the actually managed function pcim_iomap_range(). Fixes: 8558de401b5f ("drm/vboxvideo: use managed pci functions") Signed-off-by: Philipp Stanner Reviewed-by: Hans de Goede --- drivers/gpu/drm/vboxvideo/vbox_main.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/vboxvideo/vbox_main.c b/drivers/gpu/drm/vboxvideo/vbox_main.c index 42c2d8a99509..d4ade9325401 100644 --- a/drivers/gpu/drm/vboxvideo/vbox_main.c +++ b/drivers/gpu/drm/vboxvideo/vbox_main.c @@ -42,12 +42,11 @@ static int vbox_accel_init(struct vbox_private *vbox) /* Take a command buffer for each screen from the end of usable VRAM. */ vbox->available_vram_size -= vbox->num_crtcs * VBVA_MIN_BUFFER_SIZE; - vbox->vbva_buffers = pci_iomap_range(pdev, 0, - vbox->available_vram_size, - vbox->num_crtcs * - VBVA_MIN_BUFFER_SIZE); - if (!vbox->vbva_buffers) - return -ENOMEM; + vbox->vbva_buffers = pcim_iomap_range( + pdev, 0, vbox->available_vram_size, + vbox->num_crtcs * VBVA_MIN_BUFFER_SIZE); + if (IS_ERR(vbox->vbva_buffers)) + return PTR_ERR(vbox->vbva_buffers); for (i = 0; i < vbox->num_crtcs; ++i) { vbva_setup_buffer_context(&vbox->vbva_info[i], @@ -116,11 +115,10 @@ int vbox_hw_init(struct vbox_private *vbox) DRM_INFO("VRAM %08x\n", vbox->full_vram_size); /* Map guest-heap at end of vram */ - vbox->guest_heap = - pci_iomap_range(pdev, 0, GUEST_HEAP_OFFSET(vbox), - GUEST_HEAP_SIZE); - if (!vbox->guest_heap) - return -ENOMEM; + vbox->guest_heap = pcim_iomap_range(pdev, 0, + GUEST_HEAP_OFFSET(vbox), GUEST_HEAP_SIZE); + if (IS_ERR(vbox->guest_heap)) + return PTR_ERR(vbox->guest_heap); /* Create guest-heap mem-pool use 2^4 = 16 byte chunks */ vbox->guest_pool = devm_gen_pool_create(vbox->ddev.dev, 4, -1,