From: Ard Biesheuvel <ardb+git@google.com>
To: 0001-PCI-Tolerate-non-prefetchable-64-bit-BARs-in-prefetc.patch@google.com
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 v2 1/2] PCI: Add __pci_bus_alloc_resource() to allocate with explicit flags
Date: Fri, 25 Sep 2026 18:47:54 +0200 [thread overview]
Message-ID: <20260925164801.4047844-5-ardb+git@google.com> (raw)
In-Reply-To: <20260925164801.4047844-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 sparse
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 655ed53436..65a54d6e04 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 ba3c3fdddd..8297cfb5dc 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-25 16:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 16:47 [PATCH v2 0/2] PCI: Allow non-prefetchable BARs in prefetchable windows Ard Biesheuvel
2026-09-25 16:47 ` Ard Biesheuvel [this message]
2026-09-25 16:47 ` [PATCH v2 2/2] " Ard Biesheuvel
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=20260925164801.4047844-5-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=0001-PCI-Tolerate-non-prefetchable-64-bit-BARs-in-prefetc.patch@google.com \
--cc=ardb@kernel.org \
--cc=bhelgaas@google.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®