From 70aa2dc65b45b85cc65224729c6ea1919f69e550 Mon Sep 17 00:00:00 2001 From: Thomas Fleury Date: Tue, 12 Nov 2019 18:10:24 -0500 Subject: [PATCH] gpu: nvgpu: unit: add tests for gm20b channel HAL Added unit tests for the following HALs: - gm20b_channel_bind Jira NVGPU-3789 Change-Id: If25e20e99b17e3c0e3d8280326535dd6fa1e61a4 Signed-off-by: Thomas Fleury Reviewed-on: https://git-master.nvidia.com/r/2238575 Reviewed-by: mobile promotions Tested-by: mobile promotions --- .../gpu/nvgpu/hal/fifo/channel_gm20b_fusa.c | 6 +- userspace/Makefile.sources | 1 + userspace/SWUTS.sources | 1 + userspace/units/fifo/channel/gm20b/Makefile | 32 ++++++ .../fifo/channel/gm20b/Makefile.interface.tmk | 35 ++++++ .../units/fifo/channel/gm20b/Makefile.tmk | 40 +++++++ .../fifo/channel/gm20b/nvgpu-channel-gm20b.c | 101 ++++++++++++++++++ .../fifo/channel/gm20b/nvgpu-channel-gm20b.h | 62 +++++++++++ 8 files changed, 275 insertions(+), 3 deletions(-) create mode 100644 userspace/units/fifo/channel/gm20b/Makefile create mode 100644 userspace/units/fifo/channel/gm20b/Makefile.interface.tmk create mode 100644 userspace/units/fifo/channel/gm20b/Makefile.tmk create mode 100644 userspace/units/fifo/channel/gm20b/nvgpu-channel-gm20b.c create mode 100644 userspace/units/fifo/channel/gm20b/nvgpu-channel-gm20b.h diff --git a/drivers/gpu/nvgpu/hal/fifo/channel_gm20b_fusa.c b/drivers/gpu/nvgpu/hal/fifo/channel_gm20b_fusa.c index ebe0576eb..e6cc80019 100644 --- a/drivers/gpu/nvgpu/hal/fifo/channel_gm20b_fusa.c +++ b/drivers/gpu/nvgpu/hal/fifo/channel_gm20b_fusa.c @@ -42,7 +42,7 @@ void gm20b_channel_bind(struct nvgpu_channel *c) nvgpu_log_info(g, "bind channel %d inst ptr 0x%08x", c->chid, inst_ptr); - gk20a_writel(g, ccsr_channel_inst_r(c->chid), + nvgpu_writel(g, ccsr_channel_inst_r(c->chid), ccsr_channel_inst_ptr_f(inst_ptr) | nvgpu_aperture_mask(g, &c->inst_block, ccsr_channel_inst_target_sys_mem_ncoh_f(), @@ -50,8 +50,8 @@ void gm20b_channel_bind(struct nvgpu_channel *c) ccsr_channel_inst_target_vid_mem_f()) | ccsr_channel_inst_bind_true_f()); - gk20a_writel(g, ccsr_channel_r(c->chid), - (gk20a_readl(g, ccsr_channel_r(c->chid)) & + nvgpu_writel(g, ccsr_channel_r(c->chid), + (nvgpu_readl(g, ccsr_channel_r(c->chid)) & ~ccsr_channel_enable_set_f(~U32(0U))) | ccsr_channel_enable_set_true_f()); nvgpu_smp_wmb(); diff --git a/userspace/Makefile.sources b/userspace/Makefile.sources index 907b6d713..2af38bf85 100644 --- a/userspace/Makefile.sources +++ b/userspace/Makefile.sources @@ -75,6 +75,7 @@ UNITS := \ $(UNIT_SRC)/fifo \ $(UNIT_SRC)/fifo/channel \ $(UNIT_SRC)/fifo/channel/gk20a \ + $(UNIT_SRC)/fifo/channel/gm20b \ $(UNIT_SRC)/fifo/runlist \ $(UNIT_SRC)/fifo/tsg \ $(UNIT_SRC)/fifo/tsg/gv11b \ diff --git a/userspace/SWUTS.sources b/userspace/SWUTS.sources index a04bb818a..3a8a9742b 100644 --- a/userspace/SWUTS.sources +++ b/userspace/SWUTS.sources @@ -9,6 +9,7 @@ INPUT += ../../../userspace/units/netlist/nvgpu-netlist.h INPUT += ../../../userspace/units/fifo/nvgpu-fifo.h INPUT += ../../../userspace/units/fifo/channel/nvgpu-channel.h INPUT += ../../../userspace/units/fifo/channel/nvgpu-channel-gk20a.h +INPUT += ../../../userspace/units/fifo/channel/nvgpu-channel-gm20b.h INPUT += ../../../userspace/units/fifo/runlist/nvgpu-runlist.h INPUT += ../../../userspace/units/fifo/tsg/nvgpu-tsg.h INPUT += ../../../userspace/units/fifo/tsg/gv11b/nvgpu-tsg-gv11b.h diff --git a/userspace/units/fifo/channel/gm20b/Makefile b/userspace/units/fifo/channel/gm20b/Makefile new file mode 100644 index 000000000..63b893d53 --- /dev/null +++ b/userspace/units/fifo/channel/gm20b/Makefile @@ -0,0 +1,32 @@ +# 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-gm20b.o +MODULE = nvgpu-channel-gm20b + +LIB_PATHS += -lnvgpu-fifo +include ../../../Makefile.units + +lib$(MODULE).so: fifo + +fifo: + $(MAKE) -C ../.. diff --git a/userspace/units/fifo/channel/gm20b/Makefile.interface.tmk b/userspace/units/fifo/channel/gm20b/Makefile.interface.tmk new file mode 100644 index 000000000..e4e0ac6c0 --- /dev/null +++ b/userspace/units/fifo/channel/gm20b/Makefile.interface.tmk @@ -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-channel-gm20b + +include $(NV_SOURCE)/kernel/nvgpu/userspace/units/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/gm20b/Makefile.tmk b/userspace/units/fifo/channel/gm20b/Makefile.tmk new file mode 100644 index 000000000..1434bf255 --- /dev/null +++ b/userspace/units/fifo/channel/gm20b/Makefile.tmk @@ -0,0 +1,40 @@ +################################### 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-gm20b +NVGPU_UNIT_SRCS = nvgpu-channel-gm20b.c + +NVGPU_UNIT_INTERFACE_DIRS := \ + $(NV_SOURCE)/kernel/nvgpu/userspace/units/fifo \ + $(NV_SOURCE)/kernel/nvgpu/drivers/gpu/nvgpu + +include $(NV_SOURCE)/kernel/nvgpu/userspace/units/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/gm20b/nvgpu-channel-gm20b.c b/userspace/units/fifo/channel/gm20b/nvgpu-channel-gm20b.c new file mode 100644 index 000000000..86f511003 --- /dev/null +++ b/userspace/units/fifo/channel/gm20b/nvgpu-channel-gm20b.c @@ -0,0 +1,101 @@ +/* + * 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 +#include +#include +#include + +#include "hal/fifo/channel_gm20b.h" +#include + +#include "../../nvgpu-fifo.h" +#include "nvgpu-channel-gm20b.h" + +#ifdef CHANNEL_GM20B_UNIT_DEBUG +#undef unit_verbose +#define unit_verbose unit_info +#else +#define unit_verbose(unit, msg, ...) \ + do { \ + if (0) { \ + unit_info(unit, msg, ##__VA_ARGS__); \ + } \ + } while (0) +#endif + +#define assert(cond) unit_assert(cond, goto done) + +int test_gm20b_channel_bind(struct unit_module *m, + struct gk20a *g, void *args) +{ + bool privileged = false; + u32 runlist_id = NVGPU_INVALID_RUNLIST_ID; + struct nvgpu_channel *ch; + int ret = UNIT_FAIL; + + assert(g->ops.channel.bind == gm20b_channel_bind); + + ch = nvgpu_channel_open_new(g, runlist_id, + privileged, getpid(), getpid()); + assert(ch); + assert(nvgpu_atomic_read(&ch->bound) == 0); + + nvgpu_writel(g, ccsr_channel_inst_r(ch->chid), 0); + nvgpu_writel(g, ccsr_channel_r(ch->chid), 0); + + gm20b_channel_bind(ch); + + assert(nvgpu_readl(g, ccsr_channel_inst_r(ch->chid)) != 0); + assert(nvgpu_readl(g, ccsr_channel_r(ch->chid)) != 0); + assert(nvgpu_atomic_read(&ch->bound) == 1); + + nvgpu_atomic_set(&ch->bound, 0); + + ret = UNIT_SUCCESS; +done: + if (ch) { + nvgpu_channel_close(ch); + } + + return ret; +} + + +struct unit_module_test nvgpu_channel_gm20b_tests[] = { + UNIT_TEST(init_support, test_fifo_init_support, NULL, 0), + UNIT_TEST(bind, test_gm20b_channel_bind, NULL, 0), + UNIT_TEST(remove_support, test_fifo_remove_support, NULL, 0), +}; + +UNIT_MODULE(nvgpu_channel_gm20b, nvgpu_channel_gm20b_tests, UNIT_PRIO_NVGPU_TEST); diff --git a/userspace/units/fifo/channel/gm20b/nvgpu-channel-gm20b.h b/userspace/units/fifo/channel/gm20b/nvgpu-channel-gm20b.h new file mode 100644 index 000000000..5f3ddbfcb --- /dev/null +++ b/userspace/units/fifo/channel/gm20b/nvgpu-channel-gm20b.h @@ -0,0 +1,62 @@ +/* + * 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_CHANNEL_GM20B_H +#define UNIT_NVGPU_CHANNEL_GM20B_H + +#include + +struct unit_module; +struct gk20a; + +/** @addtogroup SWUTS-fifo-channel-gm20b + * @{ + * + * Software Unit Test Specification for fifo/channel/gm20b + */ + +/** + * Test specification for: test_gm20b_channel_bind + * + * Description: Branch coverage for gm20b_channel_bind + * + * Test Type: Feature based + * + * Input: test_fifo_init_support() run for this GPU + * + * Steps: + * - Create channel. + * - Write 0 to ccsr_channel_inst_r and ccsr_channel_r. + * - Call g->ops.channel.bind. + * - Check that ccsr_channel_inst_r and ccsr_channel_r have + * been programmed. + * - Check that ch->bound is set. + * + * Output: Returns PASS if all branches gave expected results. FAIL otherwise. + */ +int test_gm20b_channel_bind(struct unit_module *m, + struct gk20a *g, void *args); + +/** + * @} + */ + +#endif /* UNIT_NVGPU_CHANNEL_GM20B_H */