Linux PCI subsystem development
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Philipp Stanner <pstanner@redhat.com>
Cc: Hans de Goede <hdegoede@redhat.com>,
	 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	 Maxime Ripard <mripard@kernel.org>,
	 Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>,
	 Daniel Vetter <daniel@ffwll.ch>,
	Bjorn Helgaas <bhelgaas@google.com>,
	 Sam Ravnborg <sam@ravnborg.org>,
	dakr@redhat.com,  dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org,  linux-pci@vger.kernel.org
Subject: Re: [PATCH v7 10/13] PCI: Give pci(m)_intx its own devres callback
Date: Thu, 13 Jun 2024 20:23:26 +0300 (EEST)	[thread overview]
Message-ID: <6cd568a9-1332-5a47-bdb2-ea079a8462af@linux.intel.com> (raw)
In-Reply-To: <20240605081605.18769-12-pstanner@redhat.com>

On Wed, 5 Jun 2024, Philipp Stanner wrote:

> 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.
> 
> Signed-off-by: Philipp Stanner <pstanner@redhat.com>
> ---
>  drivers/pci/devres.c | 76 ++++++++++++++++++++++++++++++++++++--------
>  drivers/pci/pci.c    | 23 ++++++++------
>  drivers/pci/pci.h    |  7 ++--
>  3 files changed, 80 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
> index 0bafb67e1886..9a997de280df 100644
> --- a/drivers/pci/devres.c
> +++ b/drivers/pci/devres.c
> @@ -40,6 +40,11 @@ struct pcim_iomap_devres {
>  	void __iomem *table[PCI_STD_NUM_BARS];
>  };
>  
> +/* Used to restore the old intx state on driver detach. */

INTx

> +struct pcim_intx_devres {
> +	int orig_intx;
> +};
> +
>  enum pcim_addr_devres_type {
>  	/* Default initializer. */
>  	PCIM_ADDR_DEVRES_TYPE_INVALID,
> @@ -392,32 +397,75 @@ int pcim_set_mwi(struct pci_dev *pdev)
>  }
>  EXPORT_SYMBOL(pcim_set_mwi);
>  
> +
>  static inline bool mask_contains_bar(int mask, int bar)

Stray change.

-- 
 i.

>  {
>  	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 (!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 (!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 04accdfab7ce..de58e77f0ee0 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -4444,11 +4444,23 @@ void pci_disable_parity(struct pci_dev *dev)
>   * 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!
> + *
> + * Use pcim_intx() if you need a managed version.
>   */
>  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)
> @@ -4456,17 +4468,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 dbf6772aaaaf..3aa57cd8b3e5 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -823,11 +823,14 @@ static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev)
>   * 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);
> 

  reply	other threads:[~2024-06-13 17:23 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-05  8:15 [PATCH v7 00/13] Make PCI's devres API more consistent Philipp Stanner
2024-06-05  8:15 ` [PATCH v7 01/13] PCI: Add and use devres helper for bit masks Philipp Stanner
2024-06-13 16:57   ` Ilpo Järvinen
2024-06-05  8:15 ` [PATCH v7 02/13] PCI: Add devres helpers for iomap table Philipp Stanner
2024-06-05  8:15 ` [PATCH v7 03/13] PCI: Reimplement plural devres functions Philipp Stanner
2024-06-13 16:54   ` Ilpo Järvinen
2024-06-13 18:45     ` Bjorn Helgaas
2024-06-05  8:15 ` [PATCH v7 04/13] PCI: Deprecate two surplus " Philipp Stanner
2024-06-05  8:15 ` [PATCH v7 05/13] PCI: Make devres region requests consistent Philipp Stanner
2024-06-05  8:15 ` [PATCH v7 06/13] PCI: Warn users about complicated devres nature Philipp Stanner
2024-06-05  8:15 ` [PATCH v7 07/13] PCI: Move dev-enabled status bit to struct pci_dev Philipp Stanner
2024-06-05 21:11   ` Bjorn Helgaas
2024-06-06  7:59     ` Philipp Stanner
2024-06-05  8:16 ` [PATCH v7 08/13] PCI: Move pinned " Philipp Stanner
2024-06-05  8:16 ` [PATCH v7 09/13] PCI: Give pcim_set_mwi() its own devres callback Philipp Stanner
2024-06-13 17:19   ` Ilpo Järvinen
2024-06-14  8:15     ` Philipp Stanner
2024-06-05  8:16 ` [PATCH v7 10/13] PCI: Give pci(m)_intx " Philipp Stanner
2024-06-13 17:23   ` Ilpo Järvinen [this message]
2024-06-13 18:47     ` Bjorn Helgaas
2024-06-05  8:16 ` [PATCH v7 11/13] PCI: Remove legacy pcim_release() Philipp Stanner
2024-06-05  8:16 ` [PATCH v7 12/13] PCI: Add pcim_iomap_range() Philipp Stanner
2024-06-05  8:16 ` [PATCH v7 13/13] drm/vboxvideo: fix mapping leaks Philipp Stanner
2024-06-07 19:40 ` [PATCH v7 00/13] Make PCI's devres API more consistent Bjorn Helgaas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6cd568a9-1332-5a47-bdb2-ea079a8462af@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=airlied@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=dakr@redhat.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=pstanner@redhat.com \
    --cc=sam@ravnborg.org \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox