On Fri, Jan 31, 2025 at 07:29:51PM +0100, Niklas Cassel wrote: > Add a helper function to convert a size to the representation used by the > Resizable BAR Capability Register. > > Signed-off-by: Niklas Cassel <cassel@xxxxxxxxxx> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@xxxxxxxxxx> One nit below. > --- > drivers/pci/endpoint/pci-epc-core.c | 27 +++++++++++++++++++++++++++ > include/linux/pci-epc.h | 1 + > 2 files changed, 28 insertions(+) > > diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c > index 10dfc716328e..5d6aef956b13 100644 > --- a/drivers/pci/endpoint/pci-epc-core.c > +++ b/drivers/pci/endpoint/pci-epc-core.c > @@ -638,6 +638,33 @@ int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no, > } > EXPORT_SYMBOL_GPL(pci_epc_set_bar); > > +/** > + * pci_epc_bar_size_to_rebar_cap() - convert a size to the representation used > + * by the Resizable BAR Capability Register > + * @size: the size to convert > + * @cap: where to store the result > + * > + * Returns 0 on success and a negative error code in case of error. > + */ > +int pci_epc_bar_size_to_rebar_cap(size_t size, u32 *cap) > +{ > + /* > + * According to PCIe base spec, min size for a resizable BAR is 1 MB, > + * thus disallow a requested BAR size smaller than 1 MB. > + * Disallow a requested BAR size larger than 128 TB. > + */ > + if (size < SZ_1M || (u64)size > (SZ_128G * 1024)) You could've used (SZ_1T * 128). But no need to respin just for this. - Mani -- மணிவண்ணன் சதாசிவம்