From: ALOK TIWARI <alok.a.tiwari@oracle.com>
To: "Frank Li" <Frank.Li@nxp.com>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Kishon Vijay Abraham I" <kishon@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Jon Mason" <jdmason@kudzu.us>,
"Dave Jiang" <dave.jiang@intel.com>,
"Allen Hubbe" <allenbh@gmail.com>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
ntb@lists.linux.dev
Subject: Re: [PATCH 1/2] PCI: endpoint: Enhance pci_epf_alloc_space() and rename to pci_epf_set_inbound_space()
Date: Fri, 29 Aug 2025 22:51:56 +0530 [thread overview]
Message-ID: <1624f0d5-4ee9-496d-b51e-0ad3ac1c00b9@oracle.com> (raw)
In-Reply-To: <20250815-vntb_msi_doorbell-v1-1-32df6c4bf96c@nxp.com>
On 8/16/2025 3:50 AM, Frank Li wrote:
> +int pci_epf_set_inbound_space(struct pci_epf *epf, size_t size,
> + enum pci_barno bar,
> + const struct pci_epc_features *epc_features,
> + enum pci_epc_interface_type type,
> + bool from_memory,
> + dma_addr_t inbound_addr)
> {
> u64 bar_fixed_size = epc_features->bar[bar].fixed_size;
> size_t aligned_size, align = epc_features->align;
> @@ -270,7 +276,32 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
> dma_addr_t phys_addr;
> struct pci_epc *epc;
> struct device *dev;
> - void *space;
> + void *space = NULL;
> + dma_addr_t up;
> +
> + up = inbound_addr + size - 1;
> +
> + /*
> + * Bits: 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
> + * Inbound_addr: U U U U U U 0 X X X X X X X X X
> + * Up: U U U U U U 1 X X X X X X X X X
> + *
> + * U means address bits have not change in Range [Inbound_Addr, Up]
> + * X means bit 0 or 1.
> + *
> + * Inbound_addr^Up 0 0 0 0 0 0 1 X X X X X X X X X
> + * Find first bit 1 pos from MSB, 2 ^ pos windows will cover
> + * [Inbound_Addr, Up] range.
> + */
> + if (!from_memory) {
> + int pos;
> +
> + for (pos = sizeof(dma_addr_t) - 1; pos > 0; pos--)
> + if ((up ^ inbound_addr) & BIT_ULL(pos))
> + break;
> +
sizeof(dma_addr_t) returns bytes, not bits.
so 7..1 time loop in enough here ?
> + size = 1 << pos;
> + }
>
> if (size < 128)
> size = 128;
> @@ -283,7 +314,7 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
> if (size > bar_fixed_size) {
> dev_err(&epf->dev,
> "requested BAR size is larger than fixed size\n");
> - return NULL;
> + return -EINVAL;
> }
> size = bar_fixed_size;
> } else {
> @@ -308,13 +339,25 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
> }
>
> dev = epc->dev.parent;
> - space = dma_alloc_coherent(dev, aligned_size, &phys_addr, GFP_KERNEL);
> - if (!space) {
> - dev_err(dev, "failed to allocate mem space\n");
> - return NULL;
> +
> + if (from_memory) {
> + space = dma_alloc_coherent(dev, aligned_size,
> + &phys_addr, GFP_KERNEL);
> + if (!space) {
> + dev_err(dev, "failed to allocate mem space\n");
> + return -ENOMEM;
> + }
> + }
> +
> + epf_bar[bar].phys_addr = from_memory ?
> + phys_addr : ALIGN_DOWN(inbound_addr, aligned_size);
> +
> + if (!from_memory && (epf_bar[bar].phys_addr + size < up)) {
> + dev_err(&epf->dev,
> + "Given bar can't fit required inbound memory region\n");
consider bar -> BAR
> + return -EINVAL;
> }
>
Thanks,
Alok
next prev parent reply other threads:[~2025-08-29 17:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-15 22:20 [PATCH 0/2] pci: endpoint: vntb: add MSI doorbell support Frank Li
2025-08-15 22:20 ` [PATCH 1/2] PCI: endpoint: Enhance pci_epf_alloc_space() and rename to pci_epf_set_inbound_space() Frank Li
2025-08-29 17:21 ` ALOK TIWARI [this message]
2025-08-30 14:46 ` Manivannan Sadhasivam
2025-08-15 22:20 ` [PATCH 2/2] PCI: endpoint: pci-epf-vntb: Add MSI doorbell support Frank Li
2025-08-30 15:44 ` Manivannan Sadhasivam
2025-08-29 16:35 ` [PATCH 0/2] pci: endpoint: vntb: add " Frank Li
2025-08-29 16:41 ` Manivannan Sadhasivam
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=1624f0d5-4ee9-496d-b51e-0ad3ac1c00b9@oracle.com \
--to=alok.a.tiwari@oracle.com \
--cc=Frank.Li@nxp.com \
--cc=allenbh@gmail.com \
--cc=bhelgaas@google.com \
--cc=dave.jiang@intel.com \
--cc=jdmason@kudzu.us \
--cc=kishon@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mani@kernel.org \
--cc=ntb@lists.linux.dev \
/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;
as well as URLs for NNTP newsgroup(s).