diff --git a/Makefile.umbrella.tmk b/Makefile.umbrella.tmk index 20443dd01..ef1f3b2a9 100644 --- a/Makefile.umbrella.tmk +++ b/Makefile.umbrella.tmk @@ -97,6 +97,7 @@ NV_REPOSITORY_COMPONENTS += userspace/units/gr/setup NV_REPOSITORY_COMPONENTS += userspace/units/gr/intr NV_REPOSITORY_COMPONENTS += userspace/units/acr NV_REPOSITORY_COMPONENTS += userspace/units/cg +NV_REPOSITORY_COMPONENTS += userspace/units/sync endif # Local Variables: diff --git a/arch/nvgpu-posix.yaml b/arch/nvgpu-posix.yaml index 5cc767078..89580d5d9 100644 --- a/arch/nvgpu-posix.yaml +++ b/arch/nvgpu-posix.yaml @@ -53,7 +53,8 @@ headers: include/nvgpu/posix/soc_fuse.h, include/nvgpu/posix/vm.h, include/nvgpu/posix/posix_vidmem.h, - include/nvgpu/posix/queue.h ] + include/nvgpu/posix/queue.h, + include/nvgpu/posix/posix-nvhost.h ] sort: safe: yes diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/posix-nvhost.h b/drivers/gpu/nvgpu/include/nvgpu/posix/posix-nvhost.h new file mode 100644 index 000000000..c92fe5d6e --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/posix-nvhost.h @@ -0,0 +1,57 @@ +/* + * 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 NVGPU_POSIX_NVHOST_H +#define NVGPU_POSIX_NVHOST_H + +#include + +struct gk20a; +struct nvgpu_nvhost_dev { + u32 host1x_sp_base; + u32 host1x_sp_size; + u32 nb_hw_pts; +}; + +void nvgpu_free_nvhost_dev(struct gk20a *g); + +int nvgpu_get_nvhost_dev(struct gk20a *g); + +int nvgpu_nvhost_syncpt_unit_interface_get_aperture( + struct nvgpu_nvhost_dev *nvgpu_syncpt_dev, + u64 *base, size_t *size); + +u32 nvgpu_nvhost_syncpt_unit_interface_get_byte_offset(u32 syncpt_id); + +void nvgpu_nvhost_syncpt_set_min_eq_max_ext( + struct nvgpu_nvhost_dev *nvhost_dev, u32 id); +void nvgpu_nvhost_syncpt_put_ref_ext( + struct nvgpu_nvhost_dev *nvhost_dev, u32 id); + +u32 nvgpu_nvhost_get_syncpt_client_managed( + struct nvgpu_nvhost_dev *nvhost_dev, + const char *syncpt_name); + +void nvgpu_nvhost_syncpt_set_safe_state( + struct nvgpu_nvhost_dev *nvhost_dev, u32 id); + +#endif \ No newline at end of file diff --git a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export index 0e9d09874..c557dac3a 100644 --- a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export +++ b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export @@ -498,4 +498,5 @@ nvgpu_test_bit nvgpu_test_and_clear_bit nvgpu_test_and_set_bit vm_aspace_id - +nvgpu_get_nvhost_dev +nvgpu_free_nvhost_dev diff --git a/drivers/gpu/nvgpu/os/posix/posix-nvhost.c b/drivers/gpu/nvgpu/os/posix/posix-nvhost.c index 6133cf807..f06ec5f09 100644 --- a/drivers/gpu/nvgpu/os/posix/posix-nvhost.c +++ b/drivers/gpu/nvgpu/os/posix/posix-nvhost.c @@ -22,27 +22,72 @@ #include #include -#include +#include + +static inline u32 nvgpu_nvhost_syncpt_nb_hw_pts( + struct nvgpu_nvhost_dev *nvgpu_syncpt_dev) +{ + return nvgpu_syncpt_dev->nb_hw_pts; +} + +void nvgpu_free_nvhost_dev(struct gk20a *g) { + + if (g->nvhost_dev != NULL) { + nvgpu_kfree(g, g->nvhost_dev); + g->nvhost_dev = NULL; + } +} int nvgpu_get_nvhost_dev(struct gk20a *g) { - BUG(); + int ret = 0; + + g->nvhost_dev = nvgpu_kzalloc(g, sizeof(struct nvgpu_nvhost_dev)); + if (g->nvhost_dev == NULL) { + return -ENOMEM; + } + + g->nvhost_dev->host1x_sp_base = 0x60000000; + g->nvhost_dev->host1x_sp_size = 0x400000; + g->nvhost_dev->nb_hw_pts = 704U; + ret = nvgpu_nvhost_syncpt_unit_interface_get_aperture( + g->nvhost_dev, &g->syncpt_unit_base, + &g->syncpt_unit_size); + if (ret != 0) { + nvgpu_err(g, "Failed to get syncpt interface"); + goto fail_nvgpu_get_nvhost_dev; + } + g->syncpt_size = + nvgpu_nvhost_syncpt_unit_interface_get_byte_offset(1); + return 0; + +fail_nvgpu_get_nvhost_dev: + nvgpu_free_nvhost_dev(g); + + return ret; } -void nvgpu_free_nvhost_dev(struct gk20a *g) +int nvgpu_nvhost_syncpt_unit_interface_get_aperture( + struct nvgpu_nvhost_dev *nvgpu_syncpt_dev, + u64 *base, size_t *size) { - BUG(); + if (nvgpu_syncpt_dev == NULL || base == NULL || size == NULL) { + return -ENOSYS; + } + + *base = (u64)nvgpu_syncpt_dev->host1x_sp_base; + *size = nvgpu_syncpt_dev->host1x_sp_size; + + return 0; + } -bool nvgpu_nvhost_syncpt_is_valid_pt_ext( - struct nvgpu_nvhost_dev *nvhost_dev, u32 id) +u32 nvgpu_nvhost_syncpt_unit_interface_get_byte_offset(u32 syncpt_id) { - BUG(); - return false; + return nvgpu_safe_mult_u32(syncpt_id, 0x1000U); } - void nvgpu_nvhost_syncpt_set_min_eq_max_ext( struct nvgpu_nvhost_dev *nvhost_dev, u32 id) { @@ -59,14 +104,6 @@ u32 nvgpu_nvhost_get_syncpt_client_managed( struct nvgpu_nvhost_dev *nvhost_dev, const char *syncpt_name) { - BUG(); - return 0U; -} - -u32 nvgpu_nvhost_syncpt_read_maxval( - struct nvgpu_nvhost_dev *nvhost_dev, u32 id) -{ - BUG(); return 0U; } @@ -75,58 +112,3 @@ void nvgpu_nvhost_syncpt_set_safe_state( { BUG(); } - -#ifdef CONFIG_SYNC -u32 nvgpu_nvhost_sync_pt_id(struct sync_pt *pt) -{ - BUG(); - return 0U; -} - -u32 nvgpu_nvhost_sync_pt_thresh(struct sync_pt *pt) -{ - BUG(); - return 0U; -} - -struct sync_fence *nvgpu_nvhost_sync_fdget(int fd) -{ - BUG(); - return NULL; -} - -int nvgpu_nvhost_sync_num_pts(struct sync_fence *fence) -{ - BUG(); - return 0; -} - -struct sync_fence *nvgpu_nvhost_sync_create_fence( - struct nvgpu_nvhost_dev *nvhost_dev, - u32 id, u32 thresh, const char *name) -{ - BUG(); - return NULL; -} -#endif /* CONFIG_SYNC */ - -#ifdef CONFIG_TEGRA_T19X_GRHOST -int nvgpu_nvhost_syncpt_unit_interface_get_aperture( - struct nvgpu_nvhost_dev *nvhost_dev, - u64 *base, size_t *size) -{ - BUG(); - return 0; -} - -u32 nvgpu_nvhost_syncpt_unit_interface_get_byte_offset(u32 syncpt_id) -{ - BUG(); - return 0U; -} - -int nvgpu_nvhost_syncpt_init(struct gk20a *g) -{ - return -ENOSYS; -} -#endif diff --git a/userspace/Makefile.sources b/userspace/Makefile.sources index 9fa878c9a..eff14ed07 100644 --- a/userspace/Makefile.sources +++ b/userspace/Makefile.sources @@ -105,4 +105,5 @@ UNITS := \ $(UNIT_SRC)/gr/intr \ $(UNIT_SRC)/gr/setup \ $(UNIT_SRC)/acr \ - $(UNIT_SRC)/cg + $(UNIT_SRC)/cg \ + $(UNIT_SRC)/sync \ No newline at end of file diff --git a/userspace/units/fifo/libnvgpu-fifo.export b/userspace/units/fifo/libnvgpu-fifo.export index 3f610c68c..ae4074567 100644 --- a/userspace/units/fifo/libnvgpu-fifo.export +++ b/userspace/units/fifo/libnvgpu-fifo.export @@ -25,4 +25,4 @@ test_fifo_remove_support test_fifo_subtest_pruned test_fifo_flags_str test_fifo_setup_gv11b_reg_space - +test_fifo_cleanup_gv11b_reg_space diff --git a/userspace/units/sync/Makefile b/userspace/units/sync/Makefile new file mode 100644 index 000000000..00d01b2d4 --- /dev/null +++ b/userspace/units/sync/Makefile @@ -0,0 +1,33 @@ +# 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-sync.o +MODULE = nvgpu-sync + +LIB_PATHS += -lnvgpu-fifo + +include ../Makefile.units + +lib$(MODULE).so: nvgpu-fifo + +nvgpu-fifo: + $(MAKE) -C ../fifo diff --git a/userspace/units/sync/Makefile.interface.tmk b/userspace/units/sync/Makefile.interface.tmk new file mode 100644 index 000000000..c6f628412 --- /dev/null +++ b/userspace/units/sync/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-sync + +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/sync/Makefile.tmk b/userspace/units/sync/Makefile.tmk new file mode 100644 index 000000000..8740fd2df --- /dev/null +++ b/userspace/units/sync/Makefile.tmk @@ -0,0 +1,41 @@ +################################## 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-sync +NVGPU_UNIT_SRCS=nvgpu-sync.c + +NVGPU_UNIT_INTERFACE_DIRS := \ + $(NV_COMPONENT_DIR)/../fifo \ + $(NV_SOURCE)/kernel/nvgpu/drivers/gpu/nvgpu + +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/sync/nvgpu-sync.c b/userspace/units/sync/nvgpu-sync.c new file mode 100644 index 000000000..3e467ec16 --- /dev/null +++ b/userspace/units/sync/nvgpu-sync.c @@ -0,0 +1,117 @@ +/* + * 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 "../fifo/nvgpu-fifo-gv11b.h" +#include "nvgpu-sync.h" + +#define NV_PMC_BOOT_0_ARCHITECTURE_GV110 (0x00000015 << \ + NVGPU_GPU_ARCHITECTURE_SHIFT) +#define NV_PMC_BOOT_0_IMPLEMENTATION_B 0xB + +static struct nvgpu_channel *ch; + +int test_sync_init(struct unit_module *m, struct gk20a *g, void *args) +{ + int ret = 0; + + test_fifo_setup_gv11b_reg_space(m, g); + + nvgpu_set_enabled(g, NVGPU_HAS_SYNCPOINTS, true); + + /* + * HAL init parameters for gv11b + */ + g->params.gpu_arch = NV_PMC_BOOT_0_ARCHITECTURE_GV110; + g->params.gpu_impl = NV_PMC_BOOT_0_IMPLEMENTATION_B; + + /* + * HAL init required for getting + * the sync ops initialized. + */ + ret = nvgpu_init_hal(g); + if (ret != 0) { + return -ENODEV; + } + + ret = nvgpu_get_nvhost_dev(g); + if (ret != 0) { + unit_return_fail(m, "nvgpu_sync_early_init failed\n"); + } + + ch = nvgpu_kzalloc(g, sizeof(struct nvgpu_channel)); + if (ch == NULL) { + unit_return_fail(m, "sync channel creation failure"); + } + + ch->g = g; + + return UNIT_SUCCESS; +} + +int test_sync_create_sync(struct unit_module *m, struct gk20a *g, void *args) +{ + struct nvgpu_channel_sync *sync = NULL; + + sync = nvgpu_channel_sync_create(ch, true); + + if (sync != NULL) { + unit_return_fail(m, "expected failure in creating sync points"); + } + + return UNIT_SUCCESS; +} + +int test_sync_deinit(struct unit_module *m, struct gk20a *g, void *args) +{ + if (ch != NULL) { + nvgpu_kfree(g, ch); + } + + if (g->nvhost_dev == NULL) { + unit_return_fail(m ,"no valid nvhost device exists\n"); + } + + nvgpu_free_nvhost_dev(g); + + test_fifo_cleanup_gv11b_reg_space(m, g); + + return UNIT_SUCCESS; +} + +struct unit_module_test nvgpu_sync_tests[] = { + UNIT_TEST(sync_init, test_sync_init, NULL, 0), + UNIT_TEST(sync_deinit, test_sync_create_sync, NULL, 0), + UNIT_TEST(sync_deinit, test_sync_deinit, NULL, 0), +}; + +UNIT_MODULE(nvgpu-sync, nvgpu_sync_tests, UNIT_PRIO_NVGPU_TEST); \ No newline at end of file diff --git a/userspace/units/sync/nvgpu-sync.h b/userspace/units/sync/nvgpu-sync.h new file mode 100644 index 000000000..e1c09ef49 --- /dev/null +++ b/userspace/units/sync/nvgpu-sync.h @@ -0,0 +1,34 @@ +/* + * 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_SYNC_H +#define UNIT_NVGPU_SYNC_H + +#include + +struct gk20a; +struct unit_module; + +int test_sync_init(struct unit_module *m, struct gk20a *g, void *args); +int test_sync_deinit(struct unit_module *m, struct gk20a *g, void *args); +int test_sync_create_sync(struct unit_module *m, struct gk20a *g, void *args); + +#endif /* UNIT_NVGPU_SYNC_H */