diff options
author | Tom Rini <trini@konsulko.com> | 2023-01-27 14:48:22 -0500 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-01-27 14:48:22 -0500 |
commit | f147aa80f52989c7455022ca1ab959e8545feccc (patch) | |
tree | 5e513d166bf3859bf649601099110312406c4c34 /test/dm/iommu.c | |
parent | aa7c61f62923a1c9e9ec7f588ad37016d8c7323c (diff) | |
parent | e330c8b83e8784d23614f80ca3f12b11ceb515d8 (diff) |
Merge branch '2023-01-27-apple-soc-updates'
First, to quote the author:
This series adds support for the PCIe controller found on Apple M1 and
M2 machines and enables support for PCIe XHCI controllers. This makes
the type-A USB ports on the M1 Mac mini work. Since the use of Apples
DART IOMMU is mandatory (these PCIe DARTs don't support bypass mode),
this adds DMA mapping operations to the IOMMU uclass and implements
them for the Apple DART. It modifies the XHCI driver code to go map
DMA buffers through the IOMMU if there is one. Since the M1 Mac mini
now has two types of XHCI controllers with different number of ports
(2 for the DWC3 controllers, 8 for the Fresco Logic PCIe controller)
this uncovered an issue in with the way the hub descriptor is
implemented in the XHCI driver.
Second, Mark also fixes some Apple-specific instances of
CONFIG_IS_ENABLED that should be IS_ENABLED.
Diffstat (limited to 'test/dm/iommu.c')
-rw-r--r-- | test/dm/iommu.c | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/test/dm/iommu.c b/test/dm/iommu.c index 94174a7482b..62d38f1214a 100644 --- a/test/dm/iommu.c +++ b/test/dm/iommu.c @@ -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,75 @@ 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); + +static int dm_test_iommu_pci(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_find_device(UCLASS_IOMMU, 0, &dev)); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); + + /* Probing P2SB probes the IOMMU through the "iommu-map" property */ + ut_assertok(uclass_probe_all(UCLASS_P2SB)); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); + + return 0; +} +DM_TEST(dm_test_iommu_pci, UT_TESTF_SCAN_FDT); + +static int dm_test_iommu_pci_noiommu(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_find_device(UCLASS_IOMMU, 0, &dev)); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); + + /* Probing PMC should not probe the IOMMU */ + ut_assertok(uclass_probe_all(UCLASS_ACPI_PMC)); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); + + return 0; +} +DM_TEST(dm_test_iommu_pci_noiommu, UT_TESTF_SCAN_FDT); |