Skip to content

Commit 0d292a1

Browse files
floatiousbjorn-helgaas
authored andcommitted
misc: pci_endpoint_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. If CAP_UNALIGNED_ACCESS is set, that means that the EP side supports reading/writing to an address without any alignment requirements. Thus, if CAP_UNALIGNED_ACCESS is set, make sure that the host side does not add any extra padding to the buffers that we allocate (which was only done in order to get the buffers to satisfy certain alignment requirements by the endpoint controller). 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 8a02612 commit 0d292a1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

drivers/misc/pci_endpoint_test.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
#define PCI_ENDPOINT_TEST_FLAGS 0x2c
7070
#define FLAG_USE_DMA BIT(0)
7171

72+
#define PCI_ENDPOINT_TEST_CAPS 0x30
73+
#define CAP_UNALIGNED_ACCESS BIT(0)
74+
7275
#define PCI_DEVICE_ID_TI_AM654 0xb00c
7376
#define PCI_DEVICE_ID_TI_J7200 0xb00f
7477
#define PCI_DEVICE_ID_TI_AM64 0xb010
@@ -805,6 +808,20 @@ static const struct file_operations pci_endpoint_test_fops = {
805808
.unlocked_ioctl = pci_endpoint_test_ioctl,
806809
};
807810

811+
static void pci_endpoint_test_get_capabilities(struct pci_endpoint_test *test)
812+
{
813+
struct pci_dev *pdev = test->pdev;
814+
struct device *dev = &pdev->dev;
815+
u32 caps;
816+
817+
caps = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CAPS);
818+
dev_dbg(dev, "PCI_ENDPOINT_TEST_CAPS: %#x\n", caps);
819+
820+
/* CAP_UNALIGNED_ACCESS is set if the EP can do unaligned access */
821+
if (caps & CAP_UNALIGNED_ACCESS)
822+
test->alignment = 0;
823+
}
824+
808825
static int pci_endpoint_test_probe(struct pci_dev *pdev,
809826
const struct pci_device_id *ent)
810827
{
@@ -906,6 +923,8 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
906923
goto err_kfree_test_name;
907924
}
908925

926+
pci_endpoint_test_get_capabilities(test);
927+
909928
misc_device = &test->miscdev;
910929
misc_device->minor = MISC_DYNAMIC_MINOR;
911930
misc_device->name = kstrdup(name, GFP_KERNEL);

0 commit comments

Comments
 (0)