diff --git a/Makefile.umbrella.tmk b/Makefile.umbrella.tmk index 1aec37304..d3e475d8a 100644 --- a/Makefile.umbrella.tmk +++ b/Makefile.umbrella.tmk @@ -1,6 +1,6 @@ ################################### tell Emacs this is a -*- makefile-gmake -*- # -# Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. +# Copyright (c) 2018-2019 NVIDIA CORPORATION. All rights reserved. # # NVIDIA CORPORATION and its licensors retain all intellectual property # and proprietary rights in and to this software, related documentation @@ -35,6 +35,7 @@ NV_REPOSITORY_COMPONENTS += userspace/units/mm/page_table_faults NV_REPOSITORY_COMPONENTS += userspace/units/fifo/runlist NV_REPOSITORY_COMPONENTS += userspace/units/fuse NV_REPOSITORY_COMPONENTS += userspace/units/list +NV_REPOSITORY_COMPONENTS += userspace/units/enabled endif # Local Variables: diff --git a/userspace/Makefile.sources b/userspace/Makefile.sources index 13a664453..7639e197a 100644 --- a/userspace/Makefile.sources +++ b/userspace/Makefile.sources @@ -1,6 +1,6 @@ # -*- mode: makefile -*- # -# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. +# 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"), @@ -57,9 +57,10 @@ UNITS := \ $(UNIT_SRC)/mm/allocators/nvgpu_allocator \ $(UNIT_SRC)/mm/gmmu/pd_cache \ $(UNIT_SRC)/mm/gmmu/page_table \ - $(UNIT_SRC)/mm/page_table_faults \ + $(UNIT_SRC)/mm/page_table_faults \ $(UNIT_SRC)/fifo/runlist \ - $(UNIT_SRC)/list + $(UNIT_SRC)/list \ + $(UNIT_SRC)/enabled # A test unit. Not really needed any more... -# $(UNIT_SRC)/test +# $(UNIT_SRC)/test \ No newline at end of file diff --git a/userspace/required_tests.json b/userspace/required_tests.json index 33a20e406..892f85e4e 100644 --- a/userspace/required_tests.json +++ b/userspace/required_tests.json @@ -1,4 +1,20 @@ [ + { + "test": "enabled_flags_false_check", + "unit": "enabled" + }, + { + "test": "free", + "unit": "enabled" + }, + { + "test": "init", + "unit": "enabled" + }, + { + "test": "set_enabled", + "unit": "enabled" + }, { "test": "cache_default", "unit": "fault_injection" diff --git a/userspace/units/enabled/Makefile b/userspace/units/enabled/Makefile new file mode 100644 index 000000000..785de604d --- /dev/null +++ b/userspace/units/enabled/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-enabled.o +MODULE = nvgpu-enabled + +include ../Makefile.units diff --git a/userspace/units/enabled/Makefile.interface.tmk b/userspace/units/enabled/Makefile.interface.tmk new file mode 100644 index 000000000..eaacb41a8 --- /dev/null +++ b/userspace/units/enabled/Makefile.interface.tmk @@ -0,0 +1,23 @@ +################################### tell Emacs this is a -*- makefile-gmake -*- +# +# Copyright (c) 2019, NVIDIA CORPORATION. All Rights Reserved. +# +# NVIDIA CORPORATION and its licensors retain all intellectual property +# and proprietary rights in and to this software, related documentation +# and any modifications thereto. Any use, reproduction, disclosure or +# distribution of this software and related documentation without an express +# license agreement from NVIDIA CORPORATION is strictly prohibited. +# +# tmake for SW Mobile component makefile +# +############################################################################### + +NVGPU_UNIT_NAME=nvgpu-enabled + +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/enabled/Makefile.tmk b/userspace/units/enabled/Makefile.tmk new file mode 100644 index 000000000..29ade7105 --- /dev/null +++ b/userspace/units/enabled/Makefile.tmk @@ -0,0 +1,23 @@ +################################### tell Emacs this is a -*- makefile-gmake -*- +# +# Copyright (c) 2019 NVIDIA CORPORATION. All Rights Reserved. +# +# NVIDIA CORPORATION and its licensors retain all intellectual property +# and proprietary rights in and to this software, related documentation +# and any modifications thereto. Any use, reproduction, disclosure or +# distribution of this software and related documentation without an express +# license agreement from NVIDIA CORPORATION is strictly prohibited. +# +# tmake for SW Mobile component makefile +# +############################################################################### + +NVGPU_UNIT_NAME=nvgpu-enabled + +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/enabled/nvgpu-enabled.c b/userspace/units/enabled/nvgpu-enabled.c new file mode 100644 index 000000000..b87522688 --- /dev/null +++ b/userspace/units/enabled/nvgpu-enabled.c @@ -0,0 +1,163 @@ +/* + * 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 + +static unsigned long *original_enabled_flags; + +/* + * Test nvgpu_init_enabled_flags(): + * + * 1. With memory failure, check that init fails with -ENOMEM + * 2. Init works in regular scenario + * + * This test should be first to execute. Newly, inited enabled_flags will be + * used by rest of the tests in this module. + * + * Note: Since, enabled_flags are allocated during gk20a init, we store + * original allocated memory address in test_init_free_parameters structure. + * This pointer should be restored before exiting this module. + */ +static int test_nvgpu_init_enabled_flags(struct unit_module *m, + struct gk20a *g, void *args) +{ + int err; + struct nvgpu_posix_fault_inj *kmem_fi = + nvgpu_kmem_get_fault_injection(); + original_enabled_flags = g->enabled_flags; + + /* + * Test 1 - Enable SW fault injection and check that init function + * fails with -ENOMEM. + */ + + nvgpu_posix_enable_fault_injection(kmem_fi, true, 0); + err = nvgpu_init_enabled_flags(g); + if (err != -ENOMEM) { + g->enabled_flags = original_enabled_flags; + unit_return_fail(m, + "enabled_flags init didn't fail as expected\n"); + } + nvgpu_posix_enable_fault_injection(kmem_fi, false, 0); + + /* + * Test 2 - Check that enabled_flags are inited successfully + * Use these flags (allocated memory) for next tests in module. + */ + + err = nvgpu_init_enabled_flags(g); + if (err != 0) { + g->enabled_flags = original_enabled_flags; + unit_return_fail(m, "enabled_flags init failed\n"); + } + return UNIT_SUCCESS; +} + +/* + * Test nvgpu_is_enabled(): + * + * As enabled_flags inited(using kzalloc) by previous test, all flags should + * be disabled (set to 0). +*/ +static int test_nvgpu_enabled_flags_false_check(struct unit_module *m, + struct gk20a *g, void *args) +{ + u32 i; + u32 n = NVGPU_MAX_ENABLED_BITS; + + for (i = 1U; i < n; i++) { /* First flag is index 1 */ + if (nvgpu_is_enabled(g, i)) { + g->enabled_flags = original_enabled_flags; + unit_return_fail(m, + "enabled_flag %u inited to non-zero value\n", i); + } + } + + return UNIT_SUCCESS; +} + +/* + * Test nvgpu_set_enabled(): + * + * 1. Set given flag, check that flag is enabled + * 2. Reset given flag, check that flag is disabled + * + * Flag status is checked using nvgpu_is_enabled() function. This function is + * verified in previous test. + */ +static int test_nvgpu_set_enabled(struct unit_module *m, + struct gk20a *g, void *args) +{ + u32 i; + u32 n = NVGPU_MAX_ENABLED_BITS; + + for (i = 1U; i < n; i++) { /* First flag is index 1 */ + nvgpu_set_enabled(g, i, true); + if (!nvgpu_is_enabled(g, i)) { + g->enabled_flags = original_enabled_flags; + unit_return_fail(m, + "enabled_flag %u could not be enabled\n", i); + } + + nvgpu_set_enabled(g, i, false); + if (nvgpu_is_enabled(g, i)) { + g->enabled_flags = original_enabled_flags; + unit_return_fail(m, + "enabled_flag %u could not be disabled\n", i); + } + } + + return UNIT_SUCCESS; +} + +/* + * Test nvgpu_free_enabled_flags(): Free memory allocated in init test. + * + * Note: Not many alternatives to verify that memory is actually freed as + * pages are cached and accessible until replaced. + */ +static int test_nvgpu_free_enabled_flags(struct unit_module *m, + struct gk20a *g, void *args) +{ + nvgpu_free_enabled_flags(g); + g->enabled_flags = original_enabled_flags; + return UNIT_SUCCESS; +} + +struct unit_module_test enabled_tests[] = { + /* + * Init test should run first in order to use newly allocated memory. + */ + UNIT_TEST(init, test_nvgpu_init_enabled_flags, NULL), + + UNIT_TEST(enabled_flags_false_check, test_nvgpu_enabled_flags_false_check, NULL), + UNIT_TEST(set_enabled, test_nvgpu_set_enabled, NULL), + + UNIT_TEST(free, test_nvgpu_free_enabled_flags, NULL), +}; + +UNIT_MODULE(enabled, enabled_tests, UNIT_PRIO_NVGPU_TEST); \ No newline at end of file