1 // SPDX-License-Identifier: GPL-2.0+
8 #include <dm/uclass-internal.h>
11 #include <test/test.h>
15 static int dm_test_iommu(struct unit_test_state *uts)
21 ut_assertok(uclass_find_device(UCLASS_IOMMU, 0, &dev));
22 ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
24 /* Probing USB probes the IOMMU through the "iommus" property */
25 ut_assertok(uclass_probe_all(UCLASS_USB));
26 ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
31 ut_assertok(uclass_find_device(UCLASS_USB, 0, &dev));
32 dva = dev_iommu_dma_map(dev, addr, 256);
33 ut_assert(dva >= 0x89abc000 && dva < 0x89ac00000);
35 dev_iommu_dma_unmap(dev, dva, 256);
41 DM_TEST(dm_test_iommu, UTF_SCAN_FDT);
43 static int dm_test_iommu_noiommu(struct unit_test_state *uts)
49 ut_assertok(uclass_find_device(UCLASS_IOMMU, 0, &dev));
50 ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
52 /* Probing ethernet should not probe the IOMMU */
53 ut_assertok(uclass_probe_all(UCLASS_ETH));
54 ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
59 ut_assertok(uclass_find_device(UCLASS_ETH, 0, &dev));
60 dva = dev_iommu_dma_map(dev, addr, 256);
61 ut_assert(dva == virt_to_phys(addr));
63 dev_iommu_dma_unmap(dev, dva, 256);
69 DM_TEST(dm_test_iommu_noiommu, UTF_SCAN_FDT);
71 static int dm_test_iommu_pci(struct unit_test_state *uts)
75 ut_assertok(uclass_find_device(UCLASS_IOMMU, 0, &dev));
76 ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
78 /* Probing P2SB probes the IOMMU through the "iommu-map" property */
79 ut_assertok(uclass_probe_all(UCLASS_P2SB));
80 ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
84 DM_TEST(dm_test_iommu_pci, UTF_SCAN_FDT);
86 static int dm_test_iommu_pci_noiommu(struct unit_test_state *uts)
90 ut_assertok(uclass_find_device(UCLASS_IOMMU, 0, &dev));
91 ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
93 /* Probing PMC should not probe the IOMMU */
94 ut_assertok(uclass_probe_all(UCLASS_ACPI_PMC));
95 ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
99 DM_TEST(dm_test_iommu_pci_noiommu, UTF_SCAN_FDT);