[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <bc5473f8-1c40-4e50-bf8b-43233b3d53a5@amd.com>
Date: Tue, 29 Oct 2024 14:18:32 +0100
From: Christian König <christian.koenig@....com>
To: Michał Winiarski <michal.winiarski@...el.com>,
linux-pci@...r.kernel.org, intel-xe@...ts.freedesktop.org,
dri-devel@...ts.freedesktop.org, linux-kernel@...r.kernel.org,
Bjorn Helgaas <bhelgaas@...gle.com>, Krzysztof Wilczyński
<kw@...ux.com>, Ilpo Järvinen
<ilpo.jarvinen@...ux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@...el.com>,
Michal Wajdeczko <michal.wajdeczko@...el.com>,
Lucas De Marchi <lucas.demarchi@...el.com>,
Thomas Hellström <thomas.hellstrom@...ux.intel.com>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Maxime Ripard <mripard@...nel.org>, Thomas Zimmermann <tzimmermann@...e.de>,
David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>,
Matt Roper <matthew.d.roper@...el.com>
Subject: Re: [PATCH v4 2/7] PCI: Add a helper to identify IOV resources
Am 25.10.24 um 23:50 schrieb Michał Winiarski:
> There are multiple places where special handling is required for IOV
> resources.
>
> Extract it to pci_resource_is_iov() helper and drop a few ifdefs.
>
> Signed-off-by: Michał Winiarski <michal.winiarski@...el.com>
> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
Reviewed-by: Christian König <christian.koenig@....com>
> ---
> drivers/pci/pci.h | 19 +++++++++++++++----
> drivers/pci/setup-bus.c | 7 +++----
> drivers/pci/setup-res.c | 4 +---
> 3 files changed, 19 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index 14d00ce45bfa9..48d345607e57e 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -580,6 +580,10 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno);
> resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
> void pci_restore_iov_state(struct pci_dev *dev);
> int pci_iov_bus_range(struct pci_bus *bus);
> +static inline bool pci_resource_is_iov(int resno)
> +{
> + return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END;
> +}
> extern const struct attribute_group sriov_pf_dev_attr_group;
> extern const struct attribute_group sriov_vf_dev_attr_group;
> #else
> @@ -589,12 +593,21 @@ static inline int pci_iov_init(struct pci_dev *dev)
> }
> static inline void pci_iov_release(struct pci_dev *dev) { }
> static inline void pci_iov_remove(struct pci_dev *dev) { }
> +static inline void pci_iov_update_resource(struct pci_dev *dev, int resno) { }
> +static inline resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev,
> + int resno)
> +{
> + return 0;
> +}
> static inline void pci_restore_iov_state(struct pci_dev *dev) { }
> static inline int pci_iov_bus_range(struct pci_bus *bus)
> {
> return 0;
> }
> -
> +static inline bool pci_resource_is_iov(int resno)
> +{
> + return false;
> +}
> #endif /* CONFIG_PCI_IOV */
>
> #ifdef CONFIG_PCIE_PTM
> @@ -616,12 +629,10 @@ unsigned long pci_cardbus_resource_alignment(struct resource *);
> static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
> struct resource *res)
> {
> -#ifdef CONFIG_PCI_IOV
> int resno = res - dev->resource;
>
> - if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END)
> + if (pci_resource_is_iov(resno))
> return pci_sriov_resource_alignment(dev, resno);
> -#endif
> if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS)
> return pci_cardbus_resource_alignment(res);
> return resource_alignment(res);
> diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
> index 23082bc0ca37a..ba293df10c050 100644
> --- a/drivers/pci/setup-bus.c
> +++ b/drivers/pci/setup-bus.c
> @@ -1093,17 +1093,16 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
> (r->flags & mask) != type3))
> continue;
> r_size = resource_size(r);
> -#ifdef CONFIG_PCI_IOV
> +
> /* Put SRIOV requested res to the optional list */
> - if (realloc_head && i >= PCI_IOV_RESOURCES &&
> - i <= PCI_IOV_RESOURCE_END) {
> + if (realloc_head && pci_resource_is_iov(i)) {
> add_align = max(pci_resource_alignment(dev, r), add_align);
> r->end = r->start - 1;
> add_to_list(realloc_head, dev, r, r_size, 0 /* Don't care */);
> children_add_size += r_size;
> continue;
> }
> -#endif
> +
> /*
> * aligns[0] is for 1MB (since bridge memory
> * windows are always at least 1MB aligned), so
> diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
> index c6d933ddfd464..e2cf79253ebda 100644
> --- a/drivers/pci/setup-res.c
> +++ b/drivers/pci/setup-res.c
> @@ -127,10 +127,8 @@ void pci_update_resource(struct pci_dev *dev, int resno)
> {
> if (resno <= PCI_ROM_RESOURCE)
> pci_std_update_resource(dev, resno);
> -#ifdef CONFIG_PCI_IOV
> - else if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END)
> + else if (pci_resource_is_iov(resno))
> pci_iov_update_resource(dev, resno);
> -#endif
> }
>
> int pci_claim_resource(struct pci_dev *dev, int resource)
Powered by blists - more mailing lists