]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
test: dm: pci: Add cases for finding PCI capability APIs
authorBin Meng <bmeng.cn@gmail.com>
Fri, 3 Aug 2018 08:14:53 +0000 (01:14 -0700)
committerSimon Glass <sjg@chromium.org>
Wed, 8 Aug 2018 11:49:31 +0000 (12:49 +0100)
Add several PCI capability and extended capability ID registers
in the swap_case driver, so that we can add test case for
dm_pci_find_capability() and dm_pci_find_ext_capability().

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
arch/sandbox/include/asm/test.h
drivers/misc/swap_case.c
test/dm/pci.c

index 57aeca840236f194d03c2116e46d51d307ddc6f1..c8ae52b248db9454e1f102f697cd7ca2ac76acef 100644 (file)
 #define SANDBOX_PCI_CLASS_CODE         PCI_CLASS_CODE_COMM
 #define SANDBOX_PCI_CLASS_SUB_CODE     PCI_CLASS_SUB_CODE_COMM_SERIAL
 
+#define PCI_CAP_ID_PM_OFFSET           0x50
+#define PCI_CAP_ID_EXP_OFFSET          0x60
+#define PCI_CAP_ID_MSIX_OFFSET         0x70
+
+#define PCI_EXT_CAP_ID_ERR_OFFSET      0x100
+#define PCI_EXT_CAP_ID_VC_OFFSET       0x200
+#define PCI_EXT_CAP_ID_DSN_OFFSET      0x300
+
 /* Useful for PCI_VDEVICE() macro */
 #define PCI_VENDOR_ID_SANDBOX          SANDBOX_PCI_VENDOR_ID
 #define SWAP_CASE_DRV_DATA             0x55aa
index 790bb0c4bdcb69536af31e20ea7408eebf05f561..bffb809f14d9fdc87f6464e3a948dbd898cc2621 100644 (file)
@@ -118,6 +118,27 @@ static int sandbox_swap_case_read_config(struct udevice *emul, uint offset,
                *valuep = result;
                break;
        }
+       case PCI_CAPABILITY_LIST:
+               *valuep = PCI_CAP_ID_PM_OFFSET;
+               break;
+       case PCI_CAP_ID_PM_OFFSET:
+               *valuep = (PCI_CAP_ID_EXP_OFFSET << 8) | PCI_CAP_ID_PM;
+               break;
+       case PCI_CAP_ID_EXP_OFFSET:
+               *valuep = (PCI_CAP_ID_MSIX_OFFSET << 8) | PCI_CAP_ID_EXP;
+               break;
+       case PCI_CAP_ID_MSIX_OFFSET:
+               *valuep = PCI_CAP_ID_MSIX;
+               break;
+       case PCI_EXT_CAP_ID_ERR_OFFSET:
+               *valuep = (PCI_EXT_CAP_ID_VC_OFFSET << 20) | PCI_EXT_CAP_ID_ERR;
+               break;
+       case PCI_EXT_CAP_ID_VC_OFFSET:
+               *valuep = (PCI_EXT_CAP_ID_DSN_OFFSET << 20) | PCI_EXT_CAP_ID_VC;
+               break;
+       case PCI_EXT_CAP_ID_DSN_OFFSET:
+               *valuep = PCI_EXT_CAP_ID_DSN;
+               break;
        }
 
        return 0;
index e03f6ba671b832f2c57c05ad3daa4379efe9e093..869970072d5cec31bc645dbf205d157a6302b4d5 100644 (file)
@@ -188,3 +188,35 @@ static int dm_test_pci_mixed(struct unit_test_state *uts)
        return 0;
 }
 DM_TEST(dm_test_pci_mixed, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test looking up PCI capability and extended capability */
+static int dm_test_pci_cap(struct unit_test_state *uts)
+{
+       struct udevice *bus, *swap;
+       int cap;
+
+       ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 0, &bus));
+       ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap));
+
+       /* look up PCI_CAP_ID_EXP */
+       cap = dm_pci_find_capability(swap, PCI_CAP_ID_EXP);
+       ut_asserteq(PCI_CAP_ID_EXP_OFFSET, cap);
+
+       /* look up PCI_CAP_ID_PCIX */
+       cap = dm_pci_find_capability(swap, PCI_CAP_ID_PCIX);
+       ut_asserteq(0, cap);
+
+       ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 1, &bus));
+       ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &swap));
+
+       /* look up PCI_EXT_CAP_ID_DSN */
+       cap = dm_pci_find_ext_capability(swap, PCI_EXT_CAP_ID_DSN);
+       ut_asserteq(PCI_EXT_CAP_ID_DSN_OFFSET, cap);
+
+       /* look up PCI_EXT_CAP_ID_SRIOV */
+       cap = dm_pci_find_ext_capability(swap, PCI_EXT_CAP_ID_SRIOV);
+       ut_asserteq(0, cap);
+
+       return 0;
+}
+DM_TEST(dm_test_pci_cap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);