test: Add test for IOMMU uclass map/unmap ops
Test that the map and unmap operations work for devices that have DMA translated by an IOMMU and devices that don't have DMA translated by an IOMMU. Signed-off-by: Mark Kettenis <kettenis@openbsd.org> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -8,12 +8,16 @@
|
||||
#include <dm/test.h>
|
||||
#include <dm/uclass-internal.h>
|
||||
#include <iommu.h>
|
||||
#include <malloc.h>
|
||||
#include <test/test.h>
|
||||
#include <test/ut.h>
|
||||
#include <asm/io.h>
|
||||
|
||||
static int dm_test_iommu(struct unit_test_state *uts)
|
||||
{
|
||||
struct udevice *dev;
|
||||
dma_addr_t dva;
|
||||
void *addr;
|
||||
|
||||
ut_assertok(uclass_find_device(UCLASS_IOMMU, 0, &dev));
|
||||
ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
|
||||
@@ -22,7 +26,45 @@ static int dm_test_iommu(struct unit_test_state *uts)
|
||||
ut_assertok(uclass_probe_all(UCLASS_USB));
|
||||
ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
|
||||
|
||||
addr = malloc(256);
|
||||
ut_assert(addr);
|
||||
|
||||
ut_assertok(uclass_find_device(UCLASS_USB, 0, &dev));
|
||||
dva = dev_iommu_dma_map(dev, addr, 256);
|
||||
ut_assert(dva >= 0x89abc000 && dva < 0x89ac00000);
|
||||
|
||||
dev_iommu_dma_unmap(dev, dva, 256);
|
||||
|
||||
free(addr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DM_TEST(dm_test_iommu, UT_TESTF_SCAN_FDT);
|
||||
|
||||
static int dm_test_iommu_noiommu(struct unit_test_state *uts)
|
||||
{
|
||||
struct udevice *dev;
|
||||
dma_addr_t dva;
|
||||
void *addr;
|
||||
|
||||
ut_assertok(uclass_find_device(UCLASS_IOMMU, 0, &dev));
|
||||
ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
|
||||
|
||||
/* Probing ethernet should not probe the IOMMU */
|
||||
ut_assertok(uclass_probe_all(UCLASS_ETH));
|
||||
ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
|
||||
|
||||
addr = malloc(256);
|
||||
ut_assert(addr);
|
||||
|
||||
ut_assertok(uclass_find_device(UCLASS_ETH, 0, &dev));
|
||||
dva = dev_iommu_dma_map(dev, addr, 256);
|
||||
ut_assert(dva == virt_to_phys(addr));
|
||||
|
||||
dev_iommu_dma_unmap(dev, dva, 256);
|
||||
|
||||
free(addr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
DM_TEST(dm_test_iommu_noiommu, UT_TESTF_SCAN_FDT);
|
||||
|
||||
Reference in New Issue
Block a user