diff --git a/userspace/SWUTS.h b/userspace/SWUTS.h index 5ceb38933..32960d2ff 100644 --- a/userspace/SWUTS.h +++ b/userspace/SWUTS.h @@ -54,6 +54,7 @@ * - @ref SWUTS-mm-allocators-bitmap-allocator * - @ref SWUTS-mm-allocators-buddy-allocator * - @ref SWUTS-mm-as + * - @ref SWUTS-mm-dma * - @ref SWUTS-mm-nvgpu-mem * - @ref SWUTS-mm-nvgpu-sgt * - @ref SWUTS-mm-mm diff --git a/userspace/SWUTS.sources b/userspace/SWUTS.sources index 0b036faf5..29e3c2283 100644 --- a/userspace/SWUTS.sources +++ b/userspace/SWUTS.sources @@ -27,6 +27,7 @@ INPUT += ../../../userspace/units/ltc/nvgpu-ltc.h INPUT += ../../../userspace/units/mm/allocators/bitmap_allocator/bitmap_allocator.h INPUT += ../../../userspace/units/mm/allocators/buddy_allocator/buddy_allocator.h INPUT += ../../../userspace/units/mm/as/as.h +INPUT += ../../../userspace/units/mm/dma/dma.h INPUT += ../../../userspace/units/mm/nvgpu_mem/nvgpu_mem.h INPUT += ../../../userspace/units/mm/nvgpu_sgt/nvgpu_sgt.h INPUT += ../../../userspace/units/mm/mm/mm.h diff --git a/userspace/units/mm/dma/dma.c b/userspace/units/mm/dma/dma.c index 676c80893..b62f722b6 100644 --- a/userspace/units/mm/dma/dma.c +++ b/userspace/units/mm/dma/dma.c @@ -20,6 +20,7 @@ * DEALINGS IN THE SOFTWARE. */ +#include "dma.h" #include #include @@ -202,12 +203,7 @@ static int init_mm(struct unit_module *m, struct gk20a *g) return UNIT_SUCCESS; } -/* - * Test: test_mm_dma_init - * This test must be run once and be the first one as it initializes the MM - * subsystem. - */ -static int test_mm_dma_init(struct unit_module *m, struct gk20a *g, void *args) +int test_mm_dma_init(struct unit_module *m, struct gk20a *g, void *args) { u64 debug_level = (u64)args; @@ -273,8 +269,7 @@ static struct nvgpu_mem *create_test_mem(void) * Test to target nvgpu_dma_alloc_flags_* functions, testing several possible * flags and SYSMEM/VIDMEM. */ -static int test_mm_dma_alloc_flags(struct unit_module *m, struct gk20a *g, - void *args) +int test_mm_dma_alloc_flags(struct unit_module *m, struct gk20a *g, void *args) { int err; struct nvgpu_os_posix *p = nvgpu_os_posix_from_gk20a(g); @@ -342,12 +337,8 @@ end: return result; } -/* - * Test to target nvgpu_dma_alloc_* functions, testing automatic or forced - * allocations in SYSMEM or VIDMEM. - */ -static int test_mm_dma_alloc(struct unit_module *m, struct gk20a *g, - void *args) + +int test_mm_dma_alloc(struct unit_module *m, struct gk20a *g, void *args) { int err; struct nvgpu_os_posix *p = nvgpu_os_posix_from_gk20a(g); @@ -430,8 +421,7 @@ end: * Test to target nvgpu_dma_alloc_map_* functions, testing allocations and GMMU * mappings in SYSMEM or VIDMEM. */ -static int test_mm_dma_alloc_map(struct unit_module *m, struct gk20a *g, - void *args) +int test_mm_dma_alloc_map(struct unit_module *m, struct gk20a *g, void *args) { int err; struct nvgpu_os_posix *p = nvgpu_os_posix_from_gk20a(g); @@ -513,10 +503,7 @@ end: return result; } -/* - * Test error handling branches in nvgpu_dma_alloc_map - */ -static int test_mm_dma_alloc_map_fault_injection(struct unit_module *m, +int test_mm_dma_alloc_map_fault_injection(struct unit_module *m, struct gk20a *g, void *args) { int err; diff --git a/userspace/units/mm/dma/dma.h b/userspace/units/mm/dma/dma.h new file mode 100644 index 000000000..1438dad9b --- /dev/null +++ b/userspace/units/mm/dma/dma.h @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef UNIT_DMA_H +#define UNIT_DMA_H + +struct gk20a; +struct unit_module; + +/** @addtogroup SWUTS-mm-dma + * @{ + * + * Software Unit Test Specification for mm.dma + */ + +/** + * Test specification for: test_mm_dma_init + * + * Description: This test must be run once and be the first one as it + * initializes the MM subsystem. + * + * Test Type: Feature based, Init + * + * Targets: nvgpu_vm_init + * + * Input: None + * + * Steps: + * - Initialize the enabled flag NVGPU_MM_UNIFIED_MEMORY. + * - Allocate a test buffer to be used as VIDMEM. + * - Register test IO callbacks for PRAMIN. + * - Set the ops.bus.set_bar0_window HAL. + * - Set the ops.pramin.data032_r HAL. + * - Register the BUS_BAR0 test IO space. + * - Set all needed MM-related HALs. + * - Ensure that MM HAL indicates that BAR1 is not supported. + * - Create a test VM with big pages enabled. + * + * Output: Returns PASS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_mm_dma_init(struct unit_module *m, struct gk20a *g, void *__args); + +/** + * Test specification for: test_mm_dma_alloc + * + * Description: Test to target nvgpu_dma_alloc_* functions, testing automatic or + * forced allocations in SYSMEM or VIDMEM. + * + * Test Type: Feature based + * + * Targets: nvgpu_dma_alloc_flags_sys, nvgpu_dma_free, nvgpu_dma_alloc_flags_vid + * + * Input: test_mm_dma_init + * + * Steps: + * - Create a test nvgpu_mem instance (4 KB size with a static physical address) + * - Set memory interface as non IOMMU-able, iGPU and SYSMEM. + * - Create a DMA allocation on the nvgpu_mem instance and ensure it succeeds. + * - Ensure the allocated DMA has a SYSMEM aperture. + * - Free the allocation. + * - Perform the same DMA allocation but explicitly request it to be performed + * in SYSMEM. Ensure it succeeded and has a SYSMEM aperture. + * - Free the allocation. + * + * Output: Returns PASS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_mm_dma_alloc(struct unit_module *m, struct gk20a *g, void *args); + +/** + * Test specification for: test_mm_dma_alloc_flags + * + * Description: Test to target nvgpu_dma_alloc_flags_* functions, testing + * several possible flags and SYSMEM/VIDMEM. + * + * Test Type: Feature based + * + * Targets: nvgpu_dma_alloc_flags_sys, nvgpu_dma_free, nvgpu_dma_alloc_flags_vid + * + * Input: test_mm_dma_init + * + * Steps: + * - Create a test nvgpu_mem instance (4 KB size with a static physical address) + * - Set memory interface as non IOMMU-able, iGPU and SYSMEM. + * - Create a DMA allocation on the nvgpu_mem instance with a READ_ONLY flag and + * ensure it succeeds. + * - Ensure the allocated DMA has a SYSMEM aperture. + * - Free the allocation. + * - Perform the same DMA allocation with the NVGPU_DMA_PHYSICALLY_ADDRESSED + * flag. Ensure it succeeded and has a SYSMEM aperture. + * - Free the allocation. + * + * Output: Returns PASS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_mm_dma_alloc_flags(struct unit_module *m, struct gk20a *g, void *args); + +/** + * Test specification for: test_mm_dma_alloc_map + * + * Description: Test to target nvgpu_dma_alloc_map_* functions, testing + * allocations and GMMU mappings in SYSMEM or VIDMEM. + * + * Test Type: Feature based + * + * Targets: nvgpu_dma_alloc_map, nvgpu_dma_unmap_free, nvgpu_dma_alloc_map_sys, + * nvgpu_dma_alloc_map_vid + * + * Input: test_mm_dma_init + * + * Steps: + * - Create a test nvgpu_mem instance (4 KB size with a static physical address) + * - Set memory interface as non IOMMU-able, iGPU and SYSMEM. + * - Create a DMA allocation on the nvgpu_mem instance and map it, then ensure + * it succeeds. + * - Ensure the allocated DMA has a SYSMEM aperture. + * - Free and unmap the allocation. + * - Perform the same DMA allocation/map but explicitly request it to be + * performed in SYSMEM. Ensure it succeeded and has a SYSMEM aperture. + * - Free and unmap the allocation. + * + * Output: Returns PASS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_mm_dma_alloc_map(struct unit_module *m, struct gk20a *g, void *args); + +/** + * Test specification for: test_mm_dma_alloc_map_fault_injection + * + * Description: Test error handling branches in nvgpu_dma_alloc_map + * + * Test Type: Feature based + * + * Targets: nvgpu_dma_alloc_map, nvgpu_dma_unmap_free + * + * Input: test_mm_dma_init + * + * Steps: + * - Create a test nvgpu_mem instance (4 KB size with a static physical address) + * - Set memory interface as non IOMMU-able, iGPU and SYSMEM. + * - Setup DMA fault injection to trigger at the next allocation. + * - Try to perform an allocation and map and ensure it failed as expected. + * - Reset fault injection to trigger at the 5th call in order to target the + * nvgpu_gmmu_map inside of the nvgpu_dma_alloc_flags_sys function. + * - Try to perform an allocation and map and ensure it failed as expected. + * - Disable fault injection. + * + * Output: Returns PASS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_mm_dma_alloc_map_fault_injection(struct unit_module *m, + struct gk20a *g, void *args); +/** }@ */ +#endif /* UNIT_DMA_H */