On Thu, Jan 22, 2026 at 10:23:03AM +0100, Niklas Cassel wrote:
> On Thu, Jan 22, 2026 at 05:49:08PM +0900, Koichiro Den wrote:
> > Extend dw_pcie_ep_set_bar() to support inbound mappings for BAR
> > subranges using Address Match Mode IB iATU when pci_epf_bar.num_submap
> > is non-zero.
> >
> > Rename the existing BAR-match helper into dw_pcie_ep_ib_atu_bar() and
> > introduce dw_pcie_ep_ib_atu_addr() for Address Match Mode. When
> > num_submap is non-zero, read the assigned BAR base address and program
> > one inbound iATU window per subrange. Validate the submap array before
> > programming:
> > - each subrange is aligned to pci->region_align
> > - subranges cover the whole BAR (no gaps and no overlaps)
> > - subranges are sorted in ascending order by offset
> >
> > Track Address Match Mode mappings and tear them down on clear_bar() and
> > on set_bar() error paths to avoid leaving half-programmed state or
> > untranslated BAR holes.
> >
> > Advertise this capability by extending the common feature bit
> > initializer macro (DWC_EPC_COMMON_FEATURES).
> >
> > This enables multiple inbound windows within a single BAR, which is
> > useful on platforms where usable BARs are scarce but EPFs need multiple
> > inbound regions.
> >
> > Reviewed-by: Frank Li <[email protected]>
> > Signed-off-by: Koichiro Den <[email protected]>
> > ---
>
>
> > @@ -331,6 +503,13 @@ static int dw_pcie_ep_set_bar(struct pci_epc *epc, u8
> > func_no, u8 vfunc_no,
> > ep->epf_bar[bar]->flags != flags)
> > return -EINVAL;
> >
> > + /*
> > + * When dynamically changing a BAR, tear down any existing
> > + * mappings before re-programming.
> > + */
> > + if (ep->epf_bar[bar]->num_submap || epf_bar->num_submap)
> > + dw_pcie_ep_clear_ib_maps(ep, bar);
> > +
> > /*
> > * When dynamically changing a BAR, skip writing the BAR reg, as
> > * that would clear the BAR's PCI address assigned by the host.
> > @@ -369,8 +548,12 @@ static int dw_pcie_ep_set_bar(struct pci_epc *epc, u8
> > func_no, u8 vfunc_no,
> > else
> > type = PCIE_ATU_TYPE_IO;
> >
> > - ret = dw_pcie_ep_inbound_atu(ep, func_no, type, epf_bar->phys_addr, bar,
> > - size);
> > + if (epf_bar->num_submap)
> > + ret = dw_pcie_ep_ib_atu_addr(ep, func_no, type, epf_bar);
> > + else
> > + ret = dw_pcie_ep_ib_atu_bar(ep, func_no, type,
> > + epf_bar->phys_addr, bar, size);
>
> If someone calls set_bar() with a submap, without having called set_bar()
> first
> without a submap, we will still call dw_pcie_ep_ib_atu_addr() here.
>
> To make sure that dw_pcie_ep_ib_atu_addr() cannot be called without already
> having a BAR configured, to we perhaps want something like:
Thanks for the review.
Isn't the existing guard in dw_pcie_ep_ib_atu_addr sufficient?
[...]
base = dw_pcie_ep_read_bar_assigned(ep, func_no, bar, epf_bar->flags);
if (!base) {
dev_err(dev,
"BAR%u not assigned, cannot set up sub-range
mappings\n",
bar);
return -EINVAL;
}
Koichiro
>
> diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c
> b/drivers/pci/controller/dwc/pcie-designware-ep.c
> index 0567552b784c..fe26b7f7b212 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-ep.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c
> @@ -487,6 +487,9 @@ static int dw_pcie_ep_set_bar(struct pci_epc *epc, u8
> func_no, u8 vfunc_no,
> if ((flags & PCI_BASE_ADDRESS_MEM_TYPE_64) && (bar & 1))
> return -EINVAL;
>
> + if (!ep->epf_bar[bar] && epf_bar->num_submap)
> + return -EINVAL;
> +
> /*
> * Certain EPF drivers dynamically change the physical address of a
> BAR
> * (i.e. they call set_bar() twice, without ever calling clear_bar(),
> as
>
>
> or
>
>
> diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c
> b/drivers/pci/controller/dwc/pcie-designware-ep.c
> index 0567552b784c..8aeaa6fe53f9 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-ep.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c
> @@ -475,6 +475,7 @@ static int dw_pcie_ep_set_bar(struct pci_epc *epc, u8
> func_no, u8 vfunc_no,
> struct dw_pcie_ep *ep = epc_get_drvdata(epc);
> struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
> enum pci_barno bar = epf_bar->barno;
> + bool use_addr_match_mode = false;
> size_t size = epf_bar->size;
> enum pci_epc_bar_type bar_type;
> int flags = epf_bar->flags;
> @@ -510,6 +511,9 @@ static int dw_pcie_ep_set_bar(struct pci_epc *epc, u8
> func_no, u8 vfunc_no,
> if (ep->epf_bar[bar]->num_submap || epf_bar->num_submap)
> dw_pcie_ep_clear_ib_maps(ep, bar);
>
> + if (epf_bar->num_submap)
> + use_addr_match_mode = true;
> +
> /*
> * When dynamically changing a BAR, skip writing the BAR reg,
> as
> * that would clear the BAR's PCI address assigned by the
> host.
> @@ -548,7 +552,7 @@ static int dw_pcie_ep_set_bar(struct pci_epc *epc, u8
> func_no, u8 vfunc_no,
> else
> type = PCIE_ATU_TYPE_IO;
>
> - if (epf_bar->num_submap)
> + if (use_addr_match_mode)
> ret = dw_pcie_ep_ib_atu_addr(ep, func_no, type, epf_bar);
> else
> ret = dw_pcie_ep_ib_atu_bar(ep, func_no, type,