From: Ard Biesheuvel <ardb+git@google.com>
To: linux-pci@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, "Ard Biesheuvel" <ardb@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>
Subject: [PATCH v3 1/2] PCI: Add __pci_bus_alloc_resource() to allocate with explicit flags
Date: Wed, 30 Sep 2026 12:30:31 +0200 [thread overview]
Message-ID: <20260930103036.248989-5-ardb+git@google.com> (raw)
In-Reply-To: <20260930103036.248989-4-ardb+git@google.com>
From: Ard Biesheuvel <ardb@kernel.org>
pci_bus_alloc_resource() decides which bus resources a resource may be
allocated from based on the flags of that resource: the type bits
selected by @type_mask must match, a non-prefetchable resource is never
allocated from a prefetchable bus resource, and only a 64-bit resource
may be placed above 4 GB.
In preparation for placing some non-prefetchable BARs in prefetchable
bridge windows, factor out __pci_bus_alloc_resource(), which takes the
flags to match against the bus resources as a separate argument, and
implement pci_bus_alloc_resource() on top of it by passing the flags of
the resource itself.
No functional change intended.
Assisted-by: LLM
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/pci/bus.c | 70 ++++++++++++++------
drivers/pci/pci.h | 6 ++
2 files changed, 54 insertions(+), 22 deletions(-)
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 655ed53436d3..65a54d6e049e 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -188,9 +188,9 @@ static void pci_clip_resource_to_region(struct pci_bus *bus,
}
static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
- resource_size_t size, resource_size_t align,
- resource_size_t min, unsigned long type_mask,
- resource_alignf alignf,
+ unsigned long flags, resource_size_t size,
+ resource_size_t align, resource_size_t min,
+ unsigned long type_mask, resource_alignf alignf,
void *alignf_data,
struct pci_bus_region *region)
{
@@ -210,13 +210,13 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
continue;
/* type_mask must match */
- if ((res->flags ^ r->flags) & type_mask)
+ if ((flags ^ r->flags) & type_mask)
continue;
/* We cannot allocate a non-prefetching resource
from a pre-fetching area */
if ((r->flags & IORESOURCE_PREFETCH) &&
- !(res->flags & IORESOURCE_PREFETCH))
+ !(flags & IORESOURCE_PREFETCH))
continue;
avail = *r;
@@ -247,9 +247,10 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
}
/**
- * pci_bus_alloc_resource - allocate a resource from a parent bus
+ * __pci_bus_alloc_resource - allocate a resource from a parent bus
* @bus: PCI bus
* @res: resource to allocate
+ * @flags: resource flags to match against the bus resources
* @size: size of resource to allocate
* @align: alignment of resource to allocate
* @min: minimum /proc/iomem address to allocate
@@ -257,36 +258,61 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
* @alignf: resource alignment function
* @alignf_data: data argument for resource alignment function
*
- * Given the PCI bus a device resides on, the size, minimum address,
- * alignment and type, try to find an acceptable resource allocation
- * for a specific device resource.
+ * Like pci_bus_alloc_resource(), but match the bus resources against @flags
+ * rather than @res->flags. This permits allocating a non-prefetchable
+ * resource from a prefetchable bus resource by passing @flags with
+ * IORESOURCE_PREFETCH set, which the caller must have established to be safe.
*/
-int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
- resource_size_t size, resource_size_t align,
- resource_size_t min, unsigned long type_mask,
- resource_alignf alignf,
- void *alignf_data)
+int __pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
+ unsigned long flags, resource_size_t size,
+ resource_size_t align, resource_size_t min,
+ unsigned long type_mask, resource_alignf alignf,
+ void *alignf_data)
{
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
int rc;
- if (res->flags & IORESOURCE_MEM_64) {
- rc = pci_bus_alloc_from_region(bus, res, size, align, min,
- type_mask, alignf, alignf_data,
- &pci_high);
+ if (flags & IORESOURCE_MEM_64) {
+ rc = pci_bus_alloc_from_region(bus, res, flags, size, align,
+ min, type_mask, alignf,
+ alignf_data, &pci_high);
if (rc == 0)
return 0;
- return pci_bus_alloc_from_region(bus, res, size, align, min,
- type_mask, alignf, alignf_data,
- &pci_64_bit);
+ return pci_bus_alloc_from_region(bus, res, flags, size, align,
+ min, type_mask, alignf,
+ alignf_data, &pci_64_bit);
}
#endif
- return pci_bus_alloc_from_region(bus, res, size, align, min,
+ return pci_bus_alloc_from_region(bus, res, flags, size, align, min,
type_mask, alignf, alignf_data,
&pci_32_bit);
}
+
+/**
+ * pci_bus_alloc_resource - allocate a resource from a parent bus
+ * @bus: PCI bus
+ * @res: resource to allocate
+ * @size: size of resource to allocate
+ * @align: alignment of resource to allocate
+ * @min: minimum /proc/iomem address to allocate
+ * @type_mask: IORESOURCE_* type flags
+ * @alignf: resource alignment function
+ * @alignf_data: data argument for resource alignment function
+ *
+ * Given the PCI bus a device resides on, the size, minimum address,
+ * alignment and type, try to find an acceptable resource allocation
+ * for a specific device resource.
+ */
+int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
+ resource_size_t size, resource_size_t align,
+ resource_size_t min, unsigned long type_mask,
+ resource_alignf alignf, void *alignf_data)
+{
+ return __pci_bus_alloc_resource(bus, res, res->flags, size, align, min,
+ type_mask, alignf, alignf_data);
+}
EXPORT_SYMBOL(pci_bus_alloc_resource);
/*
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index ba3c3fddddc2..8297cfb5dcd5 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -567,6 +567,12 @@ static inline int pci_resource_num(const struct pci_dev *dev,
return resno;
}
+int __pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
+ unsigned long flags, resource_size_t size,
+ resource_size_t align, resource_size_t min,
+ unsigned long type_mask, resource_alignf alignf,
+ void *alignf_data);
+
void pbus_validate_busn(struct pci_bus *bus);
struct resource *pbus_select_window(struct pci_bus *bus,
const struct resource *res);
--
2.56.0.rc1.315.gc6ed9934b7-goog
next prev parent reply other threads:[~2026-09-30 10:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 10:30 [PATCH v3 0/2] PCI: Allow non-prefetchable BARs in prefetchable windows Ard Biesheuvel
2026-09-30 10:30 ` Ard Biesheuvel [this message]
2026-09-30 10:35 ` [PATCH v3 1/2] PCI: Add __pci_bus_alloc_resource() to allocate with explicit flags sashiko-bot
2026-09-30 10:30 ` [PATCH v3 2/2] PCI: Allow 64-bit non-prefetchable BARs in prefetchable windows Ard Biesheuvel
2026-09-30 10:37 ` sashiko-bot
2026-09-30 18:50 ` Ilpo Järvinen
2026-10-02 10:13 ` Ard Biesheuvel
2026-10-02 11:36 ` Ilpo Järvinen
2026-10-02 14:06 ` Ilpo Järvinen
2026-10-08 17:52 ` Ilpo Järvinen
2026-10-13 7:45 ` Ard Biesheuvel
2026-09-30 18:31 ` [PATCH v3 0/2] PCI: Allow " Ilpo Järvinen
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=20260930103036.248989-5-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=bhelgaas@google.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.