From 741723e81a3ebb287a8ae78c58896450f0637f0e Mon Sep 17 00:00:00 2001 From: Thomas Fleury Date: Thu, 30 May 2019 14:44:50 -0700 Subject: [PATCH] gpu: nvgpu: unit: add test module for channel Add unit test module for channel. Move re-usable code at units/fifo level. This included init and remove fifo support. Added missing exports for libnvgpu-drv Jira NVGPU-3480 Change-Id: Ibe4b423c3fb032b4add242d6c6dd705e43617b6e Signed-off-by: Thomas Fleury Reviewed-on: https://git-master.nvidia.com/r/2126662 Reviewed-by: Nicolas Benech GVS: Gerrit_Virtual_Submit Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions --- Makefile.umbrella.tmk | 1 + drivers/gpu/nvgpu/libnvgpu-drv.export | 7 ++ drivers/gpu/nvgpu/libnvgpu-drv_safe.export | 7 ++ userspace/Makefile.sources | 1 + userspace/required_tests.json | 10 ++ userspace/units/fifo/channel/Makefile | 26 +++++ .../units/fifo/channel/Makefile.interface.tmk | 35 ++++++ userspace/units/fifo/channel/Makefile.tmk | 38 ++++++ userspace/units/fifo/channel/nvgpu-channel.c | 31 +++++ userspace/units/fifo/nvgpu-fifo.c | 109 ++++++++++++++++++ userspace/units/fifo/nvgpu-fifo.h | 43 +++++++ 11 files changed, 308 insertions(+) create mode 100644 userspace/units/fifo/channel/Makefile create mode 100644 userspace/units/fifo/channel/Makefile.interface.tmk create mode 100644 userspace/units/fifo/channel/Makefile.tmk create mode 100644 userspace/units/fifo/channel/nvgpu-channel.c create mode 100644 userspace/units/fifo/nvgpu-fifo.c create mode 100644 userspace/units/fifo/nvgpu-fifo.h diff --git a/Makefile.umbrella.tmk b/Makefile.umbrella.tmk index ed403b66c..bd66a5744 100644 --- a/Makefile.umbrella.tmk +++ b/Makefile.umbrella.tmk @@ -53,6 +53,7 @@ NV_REPOSITORY_COMPONENTS += userspace/units/mm/gmmu/pd_cache NV_REPOSITORY_COMPONENTS += userspace/units/mm/gmmu/page_table NV_REPOSITORY_COMPONENTS += userspace/units/mm/page_table_faults NV_REPOSITORY_COMPONENTS += userspace/units/mm/vm +NV_REPOSITORY_COMPONENTS += userspace/units/fifo/channel NV_REPOSITORY_COMPONENTS += userspace/units/fifo/runlist NV_REPOSITORY_COMPONENTS += userspace/units/fuse NV_REPOSITORY_COMPONENTS += userspace/units/list diff --git a/drivers/gpu/nvgpu/libnvgpu-drv.export b/drivers/gpu/nvgpu/libnvgpu-drv.export index 519c32b4b..26c7a097b 100644 --- a/drivers/gpu/nvgpu/libnvgpu-drv.export +++ b/drivers/gpu/nvgpu/libnvgpu-drv.export @@ -36,6 +36,7 @@ gv11b_fb_init_hw gv11b_fb_is_fault_buf_enabled gv11b_fb_intr_is_mmu_fault_pending gv11b_gpu_phys_addr +gv11b_init_hal gv11b_mm_is_bar1_supported gv11b_mm_init_inst_block gv11b_mm_l2_flush @@ -65,6 +66,7 @@ nvgpu_dma_alloc nvgpu_dma_alloc_get_fault_injection nvgpu_dma_alloc_vid_at nvgpu_dma_free +nvgpu_fifo_init_support nvgpu_free nvgpu_free_enabled_flags nvgpu_free_fixed @@ -134,7 +136,9 @@ nvgpu_posix_io_get_error_code nvgpu_posix_io_init_reg_space nvgpu_posix_io_readl_reg_space nvgpu_posix_io_record_access +nvgpu_posix_io_register_reg_space nvgpu_posix_io_start_recorder +nvgpu_posix_io_unregister_reg_space nvgpu_posix_io_writel_reg_space nvgpu_posix_is_fault_injection_triggered nvgpu_posix_probe @@ -173,6 +177,8 @@ nvgpu_spinlock_acquire nvgpu_spinlock_init nvgpu_spinlock_release nvgpu_usermode_writel +nvgpu_userd_init_slabs +nvgpu_vfree_impl nvgpu_vm_area_alloc nvgpu_vm_area_free nvgpu_vm_find_mapped_buf @@ -180,6 +186,7 @@ nvgpu_vm_init nvgpu_vm_map nvgpu_vm_put nvgpu_vm_unmap +nvgpu_vzalloc_impl nvgpu_writel nvgpu_writel_check set_bit diff --git a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export index c63762843..b5b56e5aa 100644 --- a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export +++ b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export @@ -36,6 +36,7 @@ gv11b_fb_init_hw gv11b_fb_is_fault_buf_enabled gv11b_fb_intr_is_mmu_fault_pending gv11b_gpu_phys_addr +gv11b_init_hal gv11b_mm_is_bar1_supported gv11b_mm_init_inst_block gv11b_mm_l2_flush @@ -65,6 +66,7 @@ nvgpu_dma_alloc nvgpu_dma_alloc_get_fault_injection nvgpu_dma_alloc_vid_at nvgpu_dma_free +nvgpu_fifo_init_support nvgpu_free nvgpu_free_enabled_flags nvgpu_free_fixed @@ -134,7 +136,9 @@ nvgpu_posix_io_get_error_code nvgpu_posix_io_init_reg_space nvgpu_posix_io_readl_reg_space nvgpu_posix_io_record_access +nvgpu_posix_io_register_reg_space nvgpu_posix_io_start_recorder +nvgpu_posix_io_unregister_reg_space nvgpu_posix_io_writel_reg_space nvgpu_posix_is_fault_injection_triggered nvgpu_posix_probe @@ -172,7 +176,9 @@ nvgpu_sgt_ipa_to_pa nvgpu_spinlock_acquire nvgpu_spinlock_init nvgpu_spinlock_release +nvgpu_userd_init_slabs nvgpu_usermode_writel +nvgpu_vfree_impl nvgpu_vm_area_alloc nvgpu_vm_area_free nvgpu_vm_find_mapped_buf @@ -180,6 +186,7 @@ nvgpu_vm_init nvgpu_vm_map nvgpu_vm_put nvgpu_vm_unmap +nvgpu_vzalloc_impl nvgpu_writel nvgpu_writel_check set_bit diff --git a/userspace/Makefile.sources b/userspace/Makefile.sources index b3d925c64..f6ed58948 100644 --- a/userspace/Makefile.sources +++ b/userspace/Makefile.sources @@ -62,6 +62,7 @@ UNITS := \ $(UNIT_SRC)/mm/page_table_faults \ $(UNIT_SRC)/mm/nvgpu_mem \ $(UNIT_SRC)/mm/vm \ + $(UNIT_SRC)/fifo/channel \ $(UNIT_SRC)/fifo/runlist \ $(UNIT_SRC)/fifo/tsg \ $(UNIT_SRC)/list \ diff --git a/userspace/required_tests.json b/userspace/required_tests.json index d49e47e2f..113ec733c 100644 --- a/userspace/required_tests.json +++ b/userspace/required_tests.json @@ -564,6 +564,16 @@ "test_level": 0, "unit": "nvgpu_allocator" }, + { + "test": "init_support", + "test_level": 0, + "unit": "nvgpu_channel" + }, + { + "test": "remove_support", + "test_level": 0, + "unit": "nvgpu_channel" + }, { "test": "mem_create_from_phys", "test_level": 0, diff --git a/userspace/units/fifo/channel/Makefile b/userspace/units/fifo/channel/Makefile new file mode 100644 index 000000000..e2e23bbc4 --- /dev/null +++ b/userspace/units/fifo/channel/Makefile @@ -0,0 +1,26 @@ +# 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. + +.SUFFIXES: + +OBJS = nvgpu-channel.o ../nvgpu-fifo.o ../nvgpu-fifo-gv11b.o +MODULE = nvgpu-channel + +include ../../Makefile.units diff --git a/userspace/units/fifo/channel/Makefile.interface.tmk b/userspace/units/fifo/channel/Makefile.interface.tmk new file mode 100644 index 000000000..608700ca5 --- /dev/null +++ b/userspace/units/fifo/channel/Makefile.interface.tmk @@ -0,0 +1,35 @@ +################################### tell Emacs this is a -*- makefile-gmake -*- +# +# Copyright (c) 2018-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. +# +# tmake for SW Mobile component makefile +# +############################################################################### + +NVGPU_UNIT_NAME=nvgpu-channel + +include $(NV_COMPONENT_DIR)/../../Makefile.units.common.interface.tmk + +# Local Variables: +# indent-tabs-mode: t +# tab-width: 8 +# End: +# vi: set tabstop=8 noexpandtab: diff --git a/userspace/units/fifo/channel/Makefile.tmk b/userspace/units/fifo/channel/Makefile.tmk new file mode 100644 index 000000000..01450e754 --- /dev/null +++ b/userspace/units/fifo/channel/Makefile.tmk @@ -0,0 +1,38 @@ +################################### tell Emacs this is a -*- makefile-gmake -*- +# +# 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. +# +# tmake for SW Mobile component makefile +# +############################################################################### + +NVGPU_UNIT_NAME = nvgpu-channel +NVGPU_UNIT_SRCS = nvgpu-channel.c \ + ../nvgpu-fifo.c \ + ../nvgpu-fifo-gv11b.c + +include $(NV_COMPONENT_DIR)/../../Makefile.units.common.tmk + +# Local Variables: +# indent-tabs-mode: t +# tab-width: 8 +# End: +# vi: set tabstop=8 noexpandtab: diff --git a/userspace/units/fifo/channel/nvgpu-channel.c b/userspace/units/fifo/channel/nvgpu-channel.c new file mode 100644 index 000000000..8c08c02e5 --- /dev/null +++ b/userspace/units/fifo/channel/nvgpu-channel.c @@ -0,0 +1,31 @@ +/* + * 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. + */ +#include + +#include "../nvgpu-fifo.h" + +struct unit_module_test nvgpu_channel_tests[] = { + UNIT_TEST(init_support, test_fifo_init_support, NULL, 0), + UNIT_TEST(remove_support, test_fifo_remove_support, NULL, 0), +}; + +UNIT_MODULE(nvgpu_channel, nvgpu_channel_tests, UNIT_PRIO_NVGPU_TEST); diff --git a/userspace/units/fifo/nvgpu-fifo.c b/userspace/units/fifo/nvgpu-fifo.c new file mode 100644 index 000000000..cc6b088e4 --- /dev/null +++ b/userspace/units/fifo/nvgpu-fifo.c @@ -0,0 +1,109 @@ +/* + * 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. + */ +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "hal/init/hal_gv11b.h" + +#include "nvgpu-fifo.h" +#include "nvgpu-fifo-gv11b.h" + +static u32 stub_gv11b_gr_init_get_no_of_sm(struct gk20a *g) +{ + return 8; +} + +#ifdef NVGPU_USERD +static int stub_userd_setup_sw(struct gk20a *g) +{ + struct nvgpu_fifo *f = &g->fifo; + int err; + + f->userd_entry_size = g->ops.userd.entry_size(g); + + err = nvgpu_userd_init_slabs(g); + if (err != 0) { + nvgpu_err(g, "failed to init userd support"); + return err; + } + + return 0; +} +#endif + +int test_fifo_init_support(struct unit_module *m, struct gk20a *g, void *args) +{ + int err; + + err = test_fifo_setup_gv11b_reg_space(m, g); + if (err != 0) { + goto fail; + } + + gv11b_init_hal(g); + g->ops.fifo.init_fifo_setup_hw = NULL; + g->ops.gr.init.get_no_of_sm = stub_gv11b_gr_init_get_no_of_sm; + g->ops.tsg.init_eng_method_buffers = NULL; + +#ifdef NVGPU_USERD + /* + * Regular USERD init requires bar1.vm to be initialized + * Use a stub in unit tests, since it will be disabled in + * safety build anyway. + */ + g->ops.userd.setup_sw = stub_userd_setup_sw; +#endif + + err = nvgpu_fifo_init_support(g); + if (err != 0) { + test_fifo_cleanup_gv11b_reg_space(m, g); + goto fail; + } + + /* Do not allocate from vidmem */ + nvgpu_set_enabled(g, NVGPU_MM_UNIFIED_MEMORY, true); + + return UNIT_SUCCESS; + +fail: + return UNIT_FAIL; +} + +int test_fifo_remove_support(struct unit_module *m, + struct gk20a *g, void *args) +{ + if (g->fifo.remove_support) { + g->fifo.remove_support(&g->fifo); + } + + return UNIT_SUCCESS; +} + diff --git a/userspace/units/fifo/nvgpu-fifo.h b/userspace/units/fifo/nvgpu-fifo.h new file mode 100644 index 000000000..57aa66b3a --- /dev/null +++ b/userspace/units/fifo/nvgpu-fifo.h @@ -0,0 +1,43 @@ +/* + * 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_NVGPU_FIFO_H +#define UNIT_NVGPU_FIFO_H + +#include + +#ifdef UNIT_FIFO_DEBUG +#define unit_verbose unit_info +#else +#define unit_verbose(unit, msg, ...) \ + do { \ + if (0) \ + { unit_info(unit, msg, ##__VA_ARGS__); \ + } \ + } while (0) +#endif + +int test_fifo_init_support(struct unit_module *m, + struct gk20a *g, void *args); +int test_fifo_remove_support(struct unit_module *m, + struct gk20a *g, void *args); + +#endif /* UNIT_NVGPU_FIFO_H */