diff --git a/userspace/SWUTS.h b/userspace/SWUTS.h index 279b5e159..36b85b415 100644 --- a/userspace/SWUTS.h +++ b/userspace/SWUTS.h @@ -104,6 +104,7 @@ * - @ref SWUTS-gr * - @ref SWUTS-gr-setup * - @ref SWUTS-gr-intr + * - @ref SWUTS-gr-init-hal-gv11b * - @ref SWUTS-gr-falcon * - @ref SWUTS-gr-fs-state * - @ref SWUTS-gr-global-ctx diff --git a/userspace/SWUTS.sources b/userspace/SWUTS.sources index d9d9b2398..3e516e74a 100644 --- a/userspace/SWUTS.sources +++ b/userspace/SWUTS.sources @@ -75,6 +75,7 @@ INPUT += ../../../userspace/units/class/nvgpu-class.h INPUT += ../../../userspace/units/gr/nvgpu-gr.h INPUT += ../../../userspace/units/gr/setup/nvgpu-gr-setup.h INPUT += ../../../userspace/units/gr/intr/nvgpu-gr-intr.h +INPUT += ../../../userspace/units/gr/intr/nvgpu-gr-init-hal-gv11b.h INPUT += ../../../userspace/units/gr/intr/nvgpu-gr-falcon.h INPUT += ../../../userspace/units/gr/intr/nvgpu-gr-fs-state.h INPUT += ../../../userspace/units/gr/intr/nvgpu-gr-global-ctx.h diff --git a/userspace/required_tests.json b/userspace/required_tests.json index 7f3d4fa7e..b72a49769 100644 --- a/userspace/required_tests.json +++ b/userspace/required_tests.json @@ -2489,6 +2489,18 @@ "unit": "nvgpu_gr_init", "test_level": 0 }, + { + "test": "test_gr_init_hal_error_injection", + "case": "gr_init_hal_error_injection", + "unit": "nvgpu_gr_init", + "test_level": 0 + }, + { + "test": "test_gr_init_hal_wait_empty", + "case": "gr_init_hal_wait_empty", + "unit": "nvgpu_gr_init", + "test_level": 0 + }, { "test": "test_gr_remove_setup", "case": "gr_remove_setup", diff --git a/userspace/units/gr/init/Makefile b/userspace/units/gr/init/Makefile index 060c352ea..b395d7e76 100644 --- a/userspace/units/gr/init/Makefile +++ b/userspace/units/gr/init/Makefile @@ -20,7 +20,9 @@ .SUFFIXES: -OBJS = nvgpu-gr-init.o +OBJS = nvgpu-gr-init.o \ + nvgpu-gr-init-hal-gv11b.o + MODULE = nvgpu-gr-init LIB_PATHS += -lnvgpu-gr diff --git a/userspace/units/gr/init/Makefile.tmk b/userspace/units/gr/init/Makefile.tmk index 21366ed6d..257cb0b87 100644 --- a/userspace/units/gr/init/Makefile.tmk +++ b/userspace/units/gr/init/Makefile.tmk @@ -25,7 +25,8 @@ ############################################################################### NVGPU_UNIT_NAME = nvgpu-gr-init -NVGPU_UNIT_SRCS = nvgpu-gr-init.c +NVGPU_UNIT_SRCS = nvgpu-gr-init.c \ + nvgpu-gr-init-hal-gv11b.c NVGPU_UNIT_INTERFACE_DIRS := \ $(NV_COMPONENT_DIR)/.. \ diff --git a/userspace/units/gr/init/nvgpu-gr-init-hal-gv11b.c b/userspace/units/gr/init/nvgpu-gr-init-hal-gv11b.c new file mode 100644 index 000000000..d16fe1022 --- /dev/null +++ b/userspace/units/gr/init/nvgpu-gr-init-hal-gv11b.c @@ -0,0 +1,194 @@ +/* + * 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 "common/gr/gr_priv.h" + +#include "../nvgpu-gr.h" +#include "nvgpu-gr-init-hal-gv11b.h" + +#include + +#define DUMMY_SIZE 0xF0U + +static int dummy_l2_flush(struct gk20a *g, bool invalidate) +{ + return 0; +} + +int test_gr_init_hal_wait_empty(struct unit_module *m, + struct gk20a *g, void *args) +{ + int err; + int i; + struct nvgpu_posix_fault_inj *timer_fi = + nvgpu_timers_get_fault_injection(); + + /* Fail timeout initialization */ + nvgpu_posix_enable_fault_injection(timer_fi, true, 0); + err = g->ops.gr.init.wait_empty(g); + if (err == 0) { + return UNIT_FAIL; + } + + nvgpu_posix_enable_fault_injection(timer_fi, false, 0); + + /* gr_status is non-zero, gr_activity are zero, expect failure */ + nvgpu_writel(g, gr_status_r(), BIT32(7)); + nvgpu_writel(g, gr_activity_0_r(), 0); + nvgpu_writel(g, gr_activity_1_r(), 0); + nvgpu_writel(g, gr_activity_2_r(), 0); + nvgpu_writel(g, gr_activity_4_r(), 0); + + err = g->ops.gr.init.wait_empty(g); + if (err == 0) { + return UNIT_FAIL; + } + + /* gr_status is non-zero, gr_activity are non-zero, expect failure */ + nvgpu_writel(g, gr_status_r(), BIT32(7)); + nvgpu_writel(g, gr_activity_0_r(), 0x4); + nvgpu_writel(g, gr_activity_1_r(), 0x4); + nvgpu_writel(g, gr_activity_2_r(), 0x4); + nvgpu_writel(g, gr_activity_4_r(), 0x4); + + err = g->ops.gr.init.wait_empty(g); + if (err == 0) { + return UNIT_FAIL; + } + + /* gr_status is zero, gr_activity are non-zero, expect failure */ + nvgpu_writel(g, gr_status_r(), 0); + for (i = 1; i < 16; i++) { + if (i & 0x1) { + nvgpu_writel(g, gr_activity_0_r(), 0x2); + } else { + nvgpu_writel(g, gr_activity_0_r(), 0x104); + } + if (i & 0x2) { + nvgpu_writel(g, gr_activity_1_r(), 0x2); + } else { + nvgpu_writel(g, gr_activity_1_r(), 0x104); + } + if (i & 0x4) { + nvgpu_writel(g, gr_activity_2_r(), 0x2); + } else { + nvgpu_writel(g, gr_activity_2_r(), 0x0); + } + if (i & 0x8) { + nvgpu_writel(g, gr_activity_4_r(), 0x2); + } else { + nvgpu_writel(g, gr_activity_4_r(), 0x104); + } + + err = g->ops.gr.init.wait_empty(g); + if (err == 0) { + return UNIT_FAIL; + } + } + + /* Both gr_status and gr_activity registers are zero, expect success */ + nvgpu_writel(g, gr_status_r(), 0); + nvgpu_writel(g, gr_activity_0_r(), 0); + nvgpu_writel(g, gr_activity_1_r(), 0); + nvgpu_writel(g, gr_activity_2_r(), 0); + nvgpu_writel(g, gr_activity_4_r(), 0); + + err = g->ops.gr.init.wait_empty(g); + if (err != 0) { + return UNIT_FAIL; + } + + return UNIT_SUCCESS; +} + +int test_gr_init_hal_error_injection(struct unit_module *m, + struct gk20a *g, void *args) +{ + int err; + struct vm_gk20a *vm; + struct nvgpu_gr_ctx_desc *desc; + struct nvgpu_gr_ctx *gr_ctx = NULL; + u32 size; + + g->ops.mm.cache.l2_flush = dummy_l2_flush; + + vm = nvgpu_vm_init(g, SZ_4K, SZ_4K << 10, (1ULL << 32), + (1ULL << 32) + (1ULL << 37), false, false, false, + "dummy"); + if (!vm) { + unit_return_fail(m, "failed to allocate VM"); + } + + /* Setup gr_ctx and patch_ctx */ + desc = nvgpu_gr_ctx_desc_alloc(g); + if (!desc) { + unit_return_fail(m, "failed to allocate memory"); + } + + gr_ctx = nvgpu_alloc_gr_ctx_struct(g); + if (!gr_ctx) { + unit_return_fail(m, "failed to allocate memory"); + } + + nvgpu_gr_ctx_set_size(desc, NVGPU_GR_CTX_CTX, DUMMY_SIZE); + err = nvgpu_gr_ctx_alloc(g, gr_ctx, desc, vm); + if (err != 0) { + unit_return_fail(m, "failed to allocate context"); + } + + nvgpu_gr_ctx_set_size(desc, NVGPU_GR_CTX_PATCH_CTX, DUMMY_SIZE); + err = nvgpu_gr_ctx_alloc_patch_ctx(g, gr_ctx, desc, vm); + if (err != 0) { + unit_return_fail(m, "failed to allocate patch context"); + } + + /* global_ctx = false and arbitrary size */ + g->ops.gr.init.commit_global_pagepool(g, gr_ctx, 0x12345678, + DUMMY_SIZE, false, false); + + /* Verify correct size is set */ + size = nvgpu_readl(g, gr_scc_pagepool_r()); + if ((size & 0x3FF) != DUMMY_SIZE) { + unit_return_fail(m, "expected size not set"); + } + + /* cleanup */ + nvgpu_gr_ctx_free_patch_ctx(g, vm, gr_ctx); + nvgpu_free_gr_ctx_struct(g, gr_ctx); + nvgpu_gr_ctx_desc_free(g, desc); + nvgpu_vm_put(vm); + + return UNIT_SUCCESS; +} diff --git a/userspace/units/gr/init/nvgpu-gr-init-hal-gv11b.h b/userspace/units/gr/init/nvgpu-gr-init-hal-gv11b.h new file mode 100644 index 000000000..3a2307081 --- /dev/null +++ b/userspace/units/gr/init/nvgpu-gr-init-hal-gv11b.h @@ -0,0 +1,92 @@ +/* + * 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_GR_INIT_HAL_GV11B_H +#define UNIT_NVGPU_GR_INIT_HAL_GV11B_H + +#include + +struct gk20a; +struct unit_module; + +/** @addtogroup SWUTS-gr-init-hal-gv11b + * @{ + * + * Software Unit Test Specification for common.gr.init HAL + */ + +/** + * Test specification for: test_gr_init_hal_wait_empty. + * + * Description: Verify error handling in g->ops.gr.init.wait_empty. + * + * Test Type: Feature, Error guessing. + * + * Targets: g->ops.gr.init.wait_empty. + * + * Input: gr_init_setup, gr_init_prepare, gr_init_support must have + * been executed successfully. + * + * Steps: + * - Inject timeout error and call g->ops.gr.init.wait_empty. + * Should fail since timeout initialization fails. + * - Set various pass/fail values of gr_status and gr_activity registers + * and verify the pass/fail output of g->ops.gr.init.wait_empty as + * appropriate. + * + * Output: Returns PASS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_gr_init_hal_wait_empty(struct unit_module *m, + struct gk20a *g, void *args); + +/** + * Test specification for: test_gr_init_hal_error_injection. + * + * Description: Code coverage test for g->ops.gr.init.commit_global_pagepool. + * + * Test Type: Feature, Error guessing. + * + * Targets: g->ops.gr.init.commit_global_pagepool. + * + * Input: gr_init_setup, gr_init_prepare, gr_init_support must have + * been executed successfully. + * + * Steps: + * - Setup VM for testing. + * - Setup gr_ctx and patch_ctx for testing. + * - Call g->ops.gr.init.commit_global_pagepool with global_ctx flag set + * to false and with arbitrary size. + * - Read back size from register and ensure correct size is set. + * - Cleanup temporary resources. + * + * Output: Returns PASS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_gr_init_hal_error_injection(struct unit_module *m, + struct gk20a *g, void *args); + +#endif /* UNIT_NVGPU_GR_INIT_HAL_GV11B_H */ + +/** + * @} + */ + diff --git a/userspace/units/gr/init/nvgpu-gr-init.c b/userspace/units/gr/init/nvgpu-gr-init.c index e84d435c7..aebea35e6 100644 --- a/userspace/units/gr/init/nvgpu-gr-init.c +++ b/userspace/units/gr/init/nvgpu-gr-init.c @@ -40,6 +40,7 @@ #include "common/gr/gr_priv.h" #include "../nvgpu-gr.h" +#include "nvgpu-gr-init-hal-gv11b.h" #define GR_TEST_FUSES_OVERRIDE_DISABLE_TRUE 0x1U #define GR_TEST_FUSES_OVERRIDE_DISABLE_FALSE 0x0U @@ -182,6 +183,8 @@ struct unit_module_test nvgpu_gr_init_tests[] = { UNIT_TEST(gr_init_setup, test_gr_init_setup, NULL, 0), UNIT_TEST(gr_init_prepare, test_gr_init_prepare, NULL, 0), UNIT_TEST(gr_init_support, test_gr_init_support, NULL, 0), + UNIT_TEST(gr_init_hal_error_injection, test_gr_init_hal_error_injection, NULL, 0), + UNIT_TEST(gr_init_hal_wait_empty, test_gr_init_hal_wait_empty, NULL, 0), UNIT_TEST(gr_suspend, test_gr_suspend, NULL, 0), UNIT_TEST(gr_ecc_features, test_gr_init_ecc_features, NULL, 0), UNIT_TEST(gr_remove_support, test_gr_remove_support, NULL, 0),