Re: [PATCH v4 2/7] PCI: endpoint: Add pci_epc_bar_size_to_rebar_cap()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

> +/**
> + * 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))
> +		return -EINVAL;
> +
> +	*cap = ilog2(size) - ilog2(SZ_1M);
> +
> +	/* Sizes in REBAR_CAP start at BIT(4). */
> +	*cap = BIT(*cap + 4);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(pci_epc_bar_size_to_rebar_cap);

This doesn't seem specific to EPC.  It looks basically similar to
pci_rebar_bytes_to_size().  Can we consolidate anything there?

Since we're basing this on the spec, we should include a complete
citation, e.g., PCIe r6.0, sec xxx.

Bjorn




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux