Subject: Re: [PATCH v6 1/5] PCI: endpoint: Add BAR subrange mapping support

From: Niklas Cassel <[email-masked]>
Date: Tue, 13 Jan 2026 11:13:59 +0100

On Tue, Jan 13, 2026 at 11:37:11AM +0900, Koichiro Den wrote:
> Extend the PCI endpoint core to support mapping subranges within a BAR.
> Introduce a new 'submap' field and a 'use_submap' flag in struct
> pci_epf_bar so an endpoint function driver can request inbound mappings
> that fully cover the BAR.
> 
> Add a subrange_mapping feature bit to struct pci_epc_features so EPC
> drivers can explicitly advertise support. Make pci_epc_set_bar() reject
> use_submap requests (-EINVAL) when the EPC does not advertise
> subrange_mapping, to avoid silently accepting a configuration that the
> controller cannot implement.
> 
> The submap array describes the complete BAR layout (no overlaps and no
> gaps are allowed to avoid exposing untranslated address ranges). This
> provides the generic infrastructure needed to map multiple logical
> regions into a single BAR at different offsets, without assuming a
> controller-specific inbound address translation mechanism. Also, the
> array must be sorted in ascending order by offset.
> 
> Signed-off-by: Koichiro Den <[email-masked]>
> ---

I think this patch should be after the:
"PCI: endpoint: Add dynamic_inbound_mapping EPC feature"
patch...

>  drivers/pci/endpoint/pci-epc-core.c |  3 +++
>  include/linux/pci-epc.h             |  3 +++
>  include/linux/pci-epf.h             | 31 +++++++++++++++++++++++++++++
>  3 files changed, 37 insertions(+)
> 
> diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
> index ca7f19cc973a..8d809a2c3ce9 100644
> --- a/drivers/pci/endpoint/pci-epc-core.c
> +++ b/drivers/pci/endpoint/pci-epc-core.c
> @@ -596,6 +596,9 @@ int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
>  	if (!epc_features)
>  		return -EINVAL;
>  
> +	if (epf_bar->use_submap && !epc_features->subrange_mapping)
> +		return -EINVAL;

...then you can change this condition to:

	if (epf_bar->use_submap &&
	    !(epc_features->dynamic_inbound_mapping &&
	      epc_features->subrange_mapping))
		return -EINVAL;

> +
>  	if (epc_features->bar[bar].type == BAR_RESIZABLE &&
>  	    (epf_bar->size < SZ_1M || (u64)epf_bar->size > (SZ_128G * 1024)))
>  		return -EINVAL;
> diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
> index 4286bfdbfdfa..898a29e7d6f7 100644
> --- a/include/linux/pci-epc.h
> +++ b/include/linux/pci-epc.h
> @@ -223,6 +223,8 @@ struct pci_epc_bar_desc {
>  /**
>   * struct pci_epc_features - features supported by a EPC device per function
>   * @linkup_notifier: indicate if the EPC device can notify EPF driver on link up
> + * @subrange_mapping: indicate if the EPC device can map inbound subranges for a
> + *                    BAR

This text should probably also mention that this feature depends on the
dynamic_inbound_mapping feature.

With those comments fixed, looks good to me:
Reviewed-by: Niklas Cassel <[email-masked]>