Open source GPL/LGPL release

This commit is contained in:
svcmobrel-release
2025-12-19 15:25:44 -08:00
commit 9fc87a7ec7
2261 changed files with 576825 additions and 0 deletions

View File

@@ -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-ecc.o
MODULE = ecc
include ../Makefile.units

View File

@@ -0,0 +1,35 @@
################################### 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-ecc
include $(NV_COMPONENT_DIR)/../Makefile.units.common.interface.tmk
# Local Variables:
# indent-tabs-mode: t
# tab-width: 8
# End:
# vi: set tabstop=8 noexpandtab:

View File

@@ -0,0 +1,35 @@
################################### 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-ecc
include $(NV_COMPONENT_DIR)/../Makefile.units.common.tmk
# Local Variables:
# indent-tabs-mode: t
# tab-width: 8
# End:
# vi: set tabstop=8 noexpandtab:

View File

@@ -0,0 +1,253 @@
/*
* Copyright (c) 2019-2021, 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 <unit/unit.h>
#include <unit/io.h>
#include <nvgpu/gk20a.h>
#include <nvgpu/ecc.h>
#include <nvgpu/ltc.h>
#include <nvgpu/posix/posix-fault-injection.h>
#include <common/gr/gr_priv.h>
#include "nvgpu-ecc.h"
static void mock_ecc_free(struct gk20a *g) {
}
int test_ecc_init_support(struct unit_module *m, struct gk20a *g,
void *args)
{
/*
* Case #1:
* - First time ecc intialization.
* - "nvgpu_ecc_init_support" should perform init and return 0.
*/
g->ecc.initialized = false;
if (nvgpu_ecc_init_support(g) != 0) {
return UNIT_FAIL;
}
/*
* Case #2:
* - Second time ecc intialization.
* - "nvgpu_ecc_init_support" should skip init but return 0.
*/
g->ecc.initialized = true;
if (nvgpu_ecc_init_support(g) != 0) {
return UNIT_FAIL;
}
return UNIT_SUCCESS;
}
int test_ecc_finalize_support(struct unit_module *m, struct gk20a *g,
void *args)
{
/*
* Case #1:
* - First time ecc intialization.
* - "nvgpu_ecc_finalize_support" should perform init and return 0.
*/
g->ecc.initialized = false;
if (nvgpu_ecc_finalize_support(g) != 0) {
return UNIT_FAIL;
}
/*
* Case #2:
* - Second time ecc intialization.
* - "nvgpu_ecc_finalize_support" should skip init but return 0.
*/
g->ecc.initialized = true;
if (nvgpu_ecc_finalize_support(g) != 0) {
return UNIT_FAIL;
}
return UNIT_SUCCESS;
}
int test_ecc_counter_init(struct unit_module *m, struct gk20a *g,
void *args)
{
int ret = UNIT_SUCCESS;
struct nvgpu_ecc_stat *stat = NULL;
char *name;
struct nvgpu_posix_fault_inj *kmem_fi =
nvgpu_kmem_get_fault_injection();
/*
* Test setup:
* - Allocate memory for ecc counter name.
* - Initialize ecc support.
*/
name = nvgpu_kzalloc(g, NVGPU_ECC_STAT_NAME_MAX_SIZE + 1);
if (name == NULL) {
return UNIT_FAIL;
}
if (nvgpu_ecc_init_support(g) != 0) {
ret = UNIT_FAIL;
goto cleanup;
}
/*
* Case #1:
* - Initialize "name" with valid length string.
* - "nvgpu_ecc_counter_init" should return 0.
*/
strcpy(name, "test_counter");
if (nvgpu_ecc_counter_init(g, &stat, name) != 0) {
ret = UNIT_FAIL;
goto cleanup;
}
nvgpu_ecc_counter_deinit(g, &stat);
/*
* Case #2:
* - Inject SW fault to cause "nvgpu_kzalloc" failure.
* - "nvgpu_ecc_counter_init" should return -ENOMEM.
*/
nvgpu_posix_enable_fault_injection(kmem_fi, true, 0);
if (nvgpu_ecc_counter_init(g, &stat, name) != -ENOMEM) {
ret = UNIT_FAIL;
goto cleanup;
}
nvgpu_posix_enable_fault_injection(kmem_fi, false, 0);
/*
* Case #3:
* - Intialize "name" with string of length greater than
* NVGPU_ECC_STAT_NAME_MAX_SIZE.
* - "nvgpu_ecc_counter_init" should return 0, with a truncated
* counter name.
*/
memset(name, NVGPU_ECC_STAT_NAME_MAX_SIZE, 'a');
if (nvgpu_ecc_counter_init(g, &stat, name) != 0) {
ret = UNIT_FAIL;
goto cleanup;
}
nvgpu_ecc_counter_deinit(g, &stat);
if (!nvgpu_list_empty(&g->ecc.stats_list)) {
ret = UNIT_FAIL;
goto cleanup;
}
cleanup:
if (stat != NULL) {
nvgpu_ecc_counter_deinit(g, &stat);
}
nvgpu_kfree(g, name);
return ret;
}
int test_ecc_free(struct unit_module *m, struct gk20a *g,
void *args)
{
int ret = UNIT_SUCCESS;
if (nvgpu_ecc_init_support(g) != 0) {
return UNIT_FAIL;
}
/*
* Setup:
* - allocate memory for gr and clear it to zero.
* - set gr->config to NULL to return immediately from
* nvgpu_gr_ecc_free.
* - Allocate memory for ltc and clear it to zero, this should set
* the ltc_Count and slice_per_ltc to 0.
*/
g->gr = nvgpu_kzalloc(g, sizeof(*g->gr));
if (g->gr == NULL) {
return UNIT_FAIL;
}
g->ltc = nvgpu_kzalloc(g, sizeof(*g->ltc));
if (g->ltc == NULL) {
nvgpu_kfree(g, g->gr);
return UNIT_FAIL;
}
/*
* Case #1:
* - fb, fpba and pmu ecc HALs have ecc free handles set to NULL.
* - "nvgpu_ecc_free" should skip freeing ecc counters for fb, fpba,
* pmu and return without faulting.
*/
g->ops.fb.ecc.free = NULL;
g->ops.pmu.ecc_free = NULL;
g->ecc.ltc.ecc_sec_count = nvgpu_kzalloc(g,
sizeof(*g->ecc.ltc.ecc_sec_count));
g->ecc.ltc.ecc_ded_count = nvgpu_kzalloc(g,
sizeof(*g->ecc.ltc.ecc_ded_count));
if (g->ecc.ltc.ecc_sec_count == NULL
|| g->ecc.ltc.ecc_ded_count == NULL) {
ret = UNIT_FAIL;
goto cleanup;
}
nvgpu_ecc_free(g);
/*
* Case #2:
* - fb and pmu ecc HALs have ecc free handles are set.
* - "nvgpu_ecc_free" should return without faulting.
*/
g->ops.fb.ecc.free = mock_ecc_free;
g->ops.pmu.ecc_free = mock_ecc_free;
g->ecc.ltc.ecc_sec_count = nvgpu_kzalloc(g,
sizeof(*g->ecc.ltc.ecc_sec_count));
g->ecc.ltc.ecc_ded_count = nvgpu_kzalloc(g,
sizeof(*g->ecc.ltc.ecc_ded_count));
if (g->ecc.ltc.ecc_sec_count == NULL
|| g->ecc.ltc.ecc_ded_count == NULL) {
ret = UNIT_FAIL;
goto cleanup;
}
nvgpu_ecc_free(g);
g->ecc.ltc.ecc_sec_count = NULL;
g->ecc.ltc.ecc_ded_count = NULL;
cleanup:
if (g->ecc.ltc.ecc_sec_count != NULL) {
nvgpu_kfree(g, g->ecc.ltc.ecc_sec_count);
}
if (g->ecc.ltc.ecc_ded_count != NULL) {
nvgpu_kfree(g, g->ecc.ltc.ecc_ded_count);
}
nvgpu_kfree(g, g->gr);
nvgpu_kfree(g, g->ltc);
return ret;
}
struct unit_module_test ecc_tests[] = {
UNIT_TEST(ecc_init_support, test_ecc_init_support, NULL, 0),
UNIT_TEST(ecc_finalize_support, test_ecc_finalize_support, NULL, 0),
UNIT_TEST(ecc_counter_init, test_ecc_counter_init, NULL, 0),
UNIT_TEST(ecc_free, test_ecc_free, NULL, 0),
};
UNIT_MODULE(ecc, ecc_tests, UNIT_PRIO_NVGPU_TEST);

View File

@@ -0,0 +1,161 @@
/*
* Copyright (c) 2019-2021, 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_ECC_H
#define UNIT_NVGPU_ECC_H
struct gk20a;
struct unit_module;
/** @addtogroup SWUTS-ecc
* @{
*
* Software Unit Test Specification for nvgpu.common.ecc
*/
/**
* Test specification for: test_ecc_init_support
*
* Description: Verify the "nvgpu_ecc_init_support" API.
*
* Test Type: Feature Based
*
* Targets: nvgpu_ecc_init_support, gops_ecc.ecc_init_support
*
* Input: None
*
* Steps:
* - Test case #1
* - Fresh initalization, ecc.initialized = false.
* - "nvgpu_ecc_init_support" should succeed and return 0.
* - Test case #2
* - Re-initialization, ecc.initailiziation = true.
* - "nvgpu_ecc_init_support" will succeed but skip init and return 0.
*
* Output:
* - UNIT_FAIL if "nvgpu_ecc_init_support" fails with non-zero return value.
* - UNIT_SUCCESS otherwise
*/
int test_ecc_init_support(struct unit_module *m,
struct gk20a *g, void *args);
/**
* Test specification for: test_ecc_finalize_support
*
* Description: Verify the "nvgpu_ecc_finalize_support" API.
*
* Test Type: Feature Based
*
* Targets: nvgpu_ecc_finalize_support, gops_ecc.ecc_finalize_support
*
* Input: None
*
* Steps:
* - Test case #1
* - Fresh initalization, ecc.initialized = false.
* - "nvgpu_ecc_finalize_support" should succeed and return 0.
* - Test case #2
* - Re-initialization, ecc.initailiziation = true.
* - "nvgpu_ecc_finalize_support" will succeed but skip init and return 0.
*
* Output:
* - UNIT_FAIL if "nvgpu_ecc_finalize_support" fails with non-zero return value.
* - UNIT_SUCCESS otherwise
*/
int test_ecc_finalize_support(struct unit_module *m,
struct gk20a *g, void *args);
/**
* Test specification for: test_ecc_counter_init
*
* Description: Verify "nvgpu_ecc_counter_init" API.
*
* Test Type: Feature Based
*
* Targets: nvgpu_ecc_counter_init, nvgpu_ecc_stat_add
*
* Input: nvgpu_ecc_init_support
*
* Steps:
* - Invokes "nvgpu_ecc_init_support".
* - Allocate memory for counter name string.
* - Test case #1
* - Invokes "nvgpu_ecc_counter_init" with valid counter name("test_counter")
* - "nvgpu_ecc_counter_init" should succeed and return 0.
* - Test case #2
* - Inject memory allocation fault
* - "nvgpu_ecc_counter_init" should return -ENOMEM
* - Test Case #3
* - Set counter name to string with invalid length equal to
* NVGPU_ECC_STAT_NAME_MAX_SIZE.
* - "nvgpu_ecc_counter_init" will truncate the counter name and return 0.
* - Test case #4
* - Verify that the g->ecc.stats_list is empty.
*
* Output:
* - UNIT_FAIL under the following conditions:
* - Counter name memory allocation failed.
* - "nvgpu_ecc_init_support" failed.
* - "nvgpu_ecc_counter_init" failed.
* - UNIT_SUCCESS otherwise
*/
int test_ecc_counter_init(struct unit_module *m,
struct gk20a *g, void *args);
/**
* Test specification for: test_ecc_free
*
* Description: Verify "nvgpu_ecc_free" API.
*
* Test Type: Feature Based
*
* Targets: nvgpu_ecc_free
*
* Input: nvgpu_ecc_init_support
*
* Steps:
* - Do the following setup
* - "nvgpu_ecc_init_support".
* - assign respective HALs and allocate memory for g->ltc and g->gr.
* - Test case #1
* - Invokes "nvgpu_ecc_free" with unassigned fb_ecc_free, fbpa_ecc_free
* and pmu.ecc_free HALs.
* - "nvgpu_ecc_free" should succeed without faulting.
* - Test case #2
* - Invokes "nvgpu_ecc_free" with uassigned fb_ecc_free, fbpa_ecc_free
* and pmu.ecc_free HALs.
* - "nvgpu_ecc_free" should succeed without faulting.
*
* Output:
* - UNIT_FAIL under the following conditions:
* - "nvgpu_ecc_init_support" failed.
* - Memory allocation failed for either g->gr or g->ltc.
* - Memory allocation failed for either ltc.ecc_sec/ded_count.
*
* - UNIT_SUCCESS otherwise
*/
int test_ecc_free(struct unit_module *m,
struct gk20a *g, void *args);
#endif /* UNIT_NVGPU_ECC_H */