Skip to content

Commit 8a02612

Browse files
floatiousbjorn-helgaas
authored andcommitted
PCI: endpoint: pci-epf-test: Add support for capabilities
The test BAR is on the EP side is allocated using pci_epf_alloc_space(), which allocates the backing memory using dma_alloc_coherent(), which will return zeroed memory regardless of __GFP_ZERO was set or not. This means that running a new version of pci-endpoint-test.c (host side) with an old version of pci-epf-test.c (EP side) will not see any capabilities being set (as intended), so this is backwards compatible. Additionally, the EP side always allocates at least 128 bytes for the test BAR (excluding the MSI-X table), this means that adding another register at offset 0x30 is still within the 128 available bytes. For now, we only add the CAP_UNALIGNED_ACCESS capability. Set CAP_UNALIGNED_ACCESS if the EPC driver can handle any address (because it implements the .align_addr callback). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Niklas Cassel <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Reviewed-by: Frank Li <[email protected]>
1 parent 235c2b1 commit 8a02612

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

drivers/pci/endpoint/functions/pci-epf-test.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
#define TIMER_RESOLUTION 1
4646

47+
#define CAP_UNALIGNED_ACCESS BIT(0)
48+
4749
static struct workqueue_struct *kpcitest_workqueue;
4850

4951
struct pci_epf_test {
@@ -74,6 +76,7 @@ struct pci_epf_test_reg {
7476
u32 irq_type;
7577
u32 irq_number;
7678
u32 flags;
79+
u32 caps;
7780
} __packed;
7881

7982
static struct pci_epf_header test_header = {
@@ -739,6 +742,20 @@ static void pci_epf_test_clear_bar(struct pci_epf *epf)
739742
}
740743
}
741744

745+
static void pci_epf_test_set_capabilities(struct pci_epf *epf)
746+
{
747+
struct pci_epf_test *epf_test = epf_get_drvdata(epf);
748+
enum pci_barno test_reg_bar = epf_test->test_reg_bar;
749+
struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar];
750+
struct pci_epc *epc = epf->epc;
751+
u32 caps = 0;
752+
753+
if (epc->ops->align_addr)
754+
caps |= CAP_UNALIGNED_ACCESS;
755+
756+
reg->caps = cpu_to_le32(caps);
757+
}
758+
742759
static int pci_epf_test_epc_init(struct pci_epf *epf)
743760
{
744761
struct pci_epf_test *epf_test = epf_get_drvdata(epf);
@@ -763,6 +780,8 @@ static int pci_epf_test_epc_init(struct pci_epf *epf)
763780
}
764781
}
765782

783+
pci_epf_test_set_capabilities(epf);
784+
766785
ret = pci_epf_test_set_bar(epf);
767786
if (ret)
768787
return ret;

0 commit comments

Comments
 (0)