From a42b57181bdb99af4a21a290407f23d7cb6e97f3 Mon Sep 17 00:00:00 2001 From: Zhen Chen Date: Tue, 10 Aug 2021 15:44:31 +0800 Subject: [PATCH] MALI: rockchip: upgrade bifrost DDK to g7p1-01bet0, from g6p0-01eac0 Including modifications under drivers/base/ from the new DDK. Resolve lots of conflicts. Fix compilation errors when CONFIG_DEBUG_FS is disabled. Change-Id: I69f9ac87d927441d0b92b8dac8b704922aeb6a0a Signed-off-by: Zhen Chen --- Documentation/ABI/testing/sysfs-device-mali | 17 +- .../devicetree/bindings/arm/mali-bifrost.txt | 4 +- .../bindings/arm/memory_group_manager.txt | 4 +- .../bindings/arm/priority_control_manager.txt | 4 +- .../arm/protected_memory_allocator.txt | 4 +- .../devicetree/bindings/power/mali-opp.txt | 2 +- Documentation/dma-buf-test-exporter.txt | 42 + drivers/base/Kconfig | 3 +- drivers/base/arm/Kbuild | 34 + drivers/base/arm/Kconfig | 64 ++ drivers/base/arm/Makefile | 98 ++ drivers/base/arm/Mconfig | 64 ++ .../arm/dma_buf_lock/src/Kbuild} | 13 +- .../src}/Makefile | 10 +- .../base/arm/dma_buf_lock/src/dma_buf_lock.c | 898 ++++++++++++++++++ .../base/arm/dma_buf_lock/src/dma_buf_lock.h | 46 + drivers/base/arm/dma_buf_test_exporter/Kbuild | 23 + .../base/arm/dma_buf_test_exporter/build.bp | 36 + .../dma-buf-test-exporter.c | 824 ++++++++++++++++ drivers/base/arm/memory_group_manager/Kbuild | 6 +- .../base/arm/memory_group_manager/build.bp | 12 +- .../memory_group_manager.c | 8 +- .../arm/protected_memory_allocator/Kbuild | 6 +- .../arm/protected_memory_allocator/Makefile | 37 - .../arm/protected_memory_allocator/build.bp | 10 +- .../protected_memory_allocator.c | 2 +- drivers/gpu/arm/bifrost/Kbuild | 386 ++++---- drivers/gpu/arm/bifrost/Kconfig | 375 ++++---- drivers/gpu/arm/bifrost/Makefile | 209 +++- drivers/gpu/arm/bifrost/Mconfig | 282 +++--- drivers/gpu/arm/bifrost/arbiter/Kbuild | 8 +- .../arm/bifrost/arbiter/mali_kbase_arbif.c | 16 +- .../arm/bifrost/arbiter/mali_kbase_arbif.h | 9 +- .../bifrost/arbiter/mali_kbase_arbiter_defs.h | 2 +- .../arbiter/mali_kbase_arbiter_interface.h | 7 +- .../bifrost/arbiter/mali_kbase_arbiter_pm.c | 102 +- .../bifrost/arbiter/mali_kbase_arbiter_pm.h | 20 +- drivers/gpu/arm/bifrost/backend/gpu/Kbuild | 65 +- .../backend/gpu/mali_kbase_backend_config.h | 4 +- .../gpu/mali_kbase_cache_policy_backend.c | 4 +- .../gpu/mali_kbase_cache_policy_backend.h | 2 +- .../gpu/mali_kbase_clk_rate_trace_mgr.c | 8 +- .../gpu/mali_kbase_clk_rate_trace_mgr.h | 2 +- .../gpu/mali_kbase_debug_job_fault_backend.c | 6 +- .../bifrost/backend/gpu/mali_kbase_devfreq.c | 109 ++- .../bifrost/backend/gpu/mali_kbase_devfreq.h | 4 +- .../backend/gpu/mali_kbase_gpuprops_backend.c | 8 +- .../backend/gpu/mali_kbase_instr_backend.c | 2 +- .../backend/gpu/mali_kbase_instr_defs.h | 4 +- .../backend/gpu/mali_kbase_instr_internal.h | 4 +- .../backend/gpu/mali_kbase_irq_internal.h | 4 +- .../backend/gpu/mali_kbase_irq_linux.c | 12 +- .../bifrost/backend/gpu/mali_kbase_jm_as.c | 4 +- .../bifrost/backend/gpu/mali_kbase_jm_defs.h | 4 +- .../bifrost/backend/gpu/mali_kbase_jm_hw.c | 4 +- .../backend/gpu/mali_kbase_jm_internal.h | 6 +- .../bifrost/backend/gpu/mali_kbase_jm_rb.c | 25 +- .../bifrost/backend/gpu/mali_kbase_jm_rb.h | 4 +- .../backend/gpu/mali_kbase_js_backend.c | 2 +- .../backend/gpu/mali_kbase_js_internal.h | 4 +- .../backend/gpu/mali_kbase_l2_mmu_config.c | 4 +- .../backend/gpu/mali_kbase_l2_mmu_config.h | 4 +- .../backend/gpu/mali_kbase_pm_always_on.c | 5 +- .../backend/gpu/mali_kbase_pm_always_on.h | 4 +- .../backend/gpu/mali_kbase_pm_backend.c | 4 +- .../bifrost/backend/gpu/mali_kbase_pm_ca.c | 11 +- .../bifrost/backend/gpu/mali_kbase_pm_ca.h | 4 +- .../backend/gpu/mali_kbase_pm_ca_devfreq.h | 4 +- .../backend/gpu/mali_kbase_pm_coarse_demand.c | 5 +- .../backend/gpu/mali_kbase_pm_coarse_demand.h | 4 +- .../bifrost/backend/gpu/mali_kbase_pm_defs.h | 60 +- .../backend/gpu/mali_kbase_pm_driver.c | 72 +- .../backend/gpu/mali_kbase_pm_internal.h | 8 +- .../backend/gpu/mali_kbase_pm_l2_states.h | 2 +- .../backend/gpu/mali_kbase_pm_mcu_states.h | 2 +- .../backend/gpu/mali_kbase_pm_metrics.c | 24 +- .../backend/gpu/mali_kbase_pm_policy.c | 57 +- .../backend/gpu/mali_kbase_pm_policy.h | 4 +- .../backend/gpu/mali_kbase_pm_shader_states.h | 2 +- .../arm/bifrost/backend/gpu/mali_kbase_time.c | 6 +- drivers/gpu/arm/bifrost/build.bp | 243 +++-- .../arm/bifrost/context/Kbuild} | 16 +- .../context/backend/mali_kbase_context_csf.c | 6 +- .../context/backend/mali_kbase_context_jm.c | 8 +- .../arm/bifrost/context/mali_kbase_context.c | 6 +- .../arm/bifrost/context/mali_kbase_context.h | 4 +- .../context/mali_kbase_context_internal.h | 4 +- drivers/gpu/arm/bifrost/csf/Kbuild | 43 +- .../gpu/arm/bifrost/csf/ipa_control/Kbuild | 6 +- .../ipa_control/mali_kbase_csf_ipa_control.c | 6 +- .../ipa_control/mali_kbase_csf_ipa_control.h | 4 +- drivers/gpu/arm/bifrost/csf/mali_kbase_csf.c | 213 ++++- drivers/gpu/arm/bifrost/csf/mali_kbase_csf.h | 20 +- .../csf/mali_kbase_csf_cpu_queue_debugfs.c | 4 +- .../csf/mali_kbase_csf_cpu_queue_debugfs.h | 4 +- .../bifrost/csf/mali_kbase_csf_csg_debugfs.c | 41 +- .../bifrost/csf/mali_kbase_csf_csg_debugfs.h | 4 +- .../gpu/arm/bifrost/csf/mali_kbase_csf_defs.h | 12 +- .../arm/bifrost/csf/mali_kbase_csf_firmware.c | 75 +- .../arm/bifrost/csf/mali_kbase_csf_firmware.h | 27 +- .../bifrost/csf/mali_kbase_csf_firmware_cfg.c | 2 +- .../bifrost/csf/mali_kbase_csf_firmware_cfg.h | 2 +- .../csf/mali_kbase_csf_firmware_no_mali.c | 85 +- .../csf/mali_kbase_csf_heap_context_alloc.c | 4 +- .../csf/mali_kbase_csf_heap_context_alloc.h | 4 +- .../gpu/arm/bifrost/csf/mali_kbase_csf_kcpu.c | 20 +- .../gpu/arm/bifrost/csf/mali_kbase_csf_kcpu.h | 2 +- .../bifrost/csf/mali_kbase_csf_kcpu_debugfs.c | 8 +- .../bifrost/csf/mali_kbase_csf_kcpu_debugfs.h | 4 +- .../csf/mali_kbase_csf_protected_memory.c | 8 +- .../csf/mali_kbase_csf_protected_memory.h | 4 +- .../bifrost/csf/mali_kbase_csf_reset_gpu.c | 2 +- .../bifrost/csf/mali_kbase_csf_scheduler.c | 527 +++++++--- .../bifrost/csf/mali_kbase_csf_scheduler.h | 47 +- .../bifrost/csf/mali_kbase_csf_tiler_heap.c | 2 +- .../bifrost/csf/mali_kbase_csf_tiler_heap.h | 4 +- .../csf/mali_kbase_csf_tiler_heap_debugfs.c | 6 +- .../csf/mali_kbase_csf_tiler_heap_debugfs.h | 4 +- .../csf/mali_kbase_csf_tiler_heap_def.h | 4 +- .../arm/bifrost/csf/mali_kbase_csf_timeout.c | 6 +- .../arm/bifrost/csf/mali_kbase_csf_timeout.h | 4 +- .../bifrost/csf/mali_kbase_csf_tl_reader.c | 18 +- .../bifrost/csf/mali_kbase_csf_tl_reader.h | 4 +- .../bifrost/csf/mali_kbase_csf_trace_buffer.c | 6 +- .../bifrost/csf/mali_kbase_csf_trace_buffer.h | 4 +- drivers/gpu/arm/bifrost/debug/Kbuild | 27 + .../mali_kbase_debug_ktrace_codes_csf.h | 129 ++- .../mali_kbase_debug_ktrace_codes_jm.h | 4 +- .../backend/mali_kbase_debug_ktrace_csf.c | 4 +- .../backend/mali_kbase_debug_ktrace_csf.h | 4 +- .../mali_kbase_debug_ktrace_defs_csf.h | 9 +- .../backend/mali_kbase_debug_ktrace_defs_jm.h | 2 +- .../backend/mali_kbase_debug_ktrace_jm.c | 4 +- .../backend/mali_kbase_debug_ktrace_jm.h | 4 +- .../mali_kbase_debug_linux_ktrace_csf.h | 55 +- .../mali_kbase_debug_linux_ktrace_jm.h | 4 +- .../bifrost/debug/mali_kbase_debug_ktrace.c | 8 +- .../bifrost/debug/mali_kbase_debug_ktrace.h | 6 +- .../debug/mali_kbase_debug_ktrace_codes.h | 4 +- .../debug/mali_kbase_debug_ktrace_defs.h | 6 +- .../debug/mali_kbase_debug_ktrace_internal.h | 4 +- .../debug/mali_kbase_debug_linux_ktrace.h | 2 +- .../{tests/kutf/Makefile => device/Kbuild} | 27 +- .../device/backend/mali_kbase_device_csf.c | 357 ++++--- .../device/backend/mali_kbase_device_hw_csf.c | 23 +- .../device/backend/mali_kbase_device_hw_jm.c | 4 +- .../device/backend/mali_kbase_device_jm.c | 162 ++-- .../arm/bifrost/device/mali_kbase_device.c | 95 +- .../arm/bifrost/device/mali_kbase_device.h | 17 +- .../arm/bifrost/device/mali_kbase_device_hw.c | 12 +- .../device/mali_kbase_device_internal.h | 26 +- .../Kconfig => gpu/arm/bifrost/gpu/Kbuild} | 16 +- .../gpu/backend/mali_kbase_gpu_fault_csf.c | 4 +- .../gpu/backend/mali_kbase_gpu_fault_jm.c | 6 +- drivers/gpu/arm/bifrost/gpu/mali_kbase_gpu.c | 4 +- .../arm/bifrost/gpu/mali_kbase_gpu_fault.h | 2 +- .../arm/bifrost/gpu/mali_kbase_gpu_regmap.h | 2 +- drivers/gpu/arm/bifrost/ipa/Kbuild | 20 +- .../mali_kbase_ipa_counter_common_csf.c | 4 +- .../mali_kbase_ipa_counter_common_csf.h | 4 +- .../mali_kbase_ipa_counter_common_jm.c | 4 +- .../mali_kbase_ipa_counter_common_jm.h | 9 +- .../ipa/backend/mali_kbase_ipa_counter_csf.c | 21 +- .../ipa/backend/mali_kbase_ipa_counter_jm.c | 12 +- drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa.c | 15 +- drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa.h | 4 +- .../arm/bifrost/ipa/mali_kbase_ipa_debugfs.c | 4 +- .../arm/bifrost/ipa/mali_kbase_ipa_debugfs.h | 4 +- .../arm/bifrost/ipa/mali_kbase_ipa_simple.c | 6 +- .../arm/bifrost/ipa/mali_kbase_ipa_simple.h | 4 +- .../gpu/arm/bifrost/jm/mali_kbase_jm_defs.h | 10 +- drivers/gpu/arm/bifrost/jm/mali_kbase_jm_js.h | 2 +- .../gpu/arm/bifrost/jm/mali_kbase_js_defs.h | 6 +- .../arm/bifrost/mali_base_hwconfig_features.h | 56 +- .../arm/bifrost/mali_base_hwconfig_issues.h | 32 +- drivers/gpu/arm/bifrost/mali_kbase.h | 6 +- .../arm/bifrost/mali_kbase_as_fault_debugfs.c | 8 +- .../arm/bifrost/mali_kbase_as_fault_debugfs.h | 6 +- drivers/gpu/arm/bifrost/mali_kbase_bits.h | 4 +- .../gpu/arm/bifrost/mali_kbase_cache_policy.c | 4 +- .../gpu/arm/bifrost/mali_kbase_cache_policy.h | 2 +- drivers/gpu/arm/bifrost/mali_kbase_caps.h | 2 +- drivers/gpu/arm/bifrost/mali_kbase_ccswe.c | 4 +- drivers/gpu/arm/bifrost/mali_kbase_ccswe.h | 4 +- drivers/gpu/arm/bifrost/mali_kbase_config.c | 63 +- drivers/gpu/arm/bifrost/mali_kbase_config.h | 180 +++- .../arm/bifrost/mali_kbase_config_defaults.h | 2 +- .../gpu/arm/bifrost/mali_kbase_core_linux.c | 124 ++- .../arm/bifrost/mali_kbase_cs_experimental.h | 4 +- .../gpu/arm/bifrost/mali_kbase_ctx_sched.c | 4 +- .../gpu/arm/bifrost/mali_kbase_ctx_sched.h | 2 +- drivers/gpu/arm/bifrost/mali_kbase_debug.c | 4 +- drivers/gpu/arm/bifrost/mali_kbase_debug.h | 4 +- .../arm/bifrost/mali_kbase_debug_job_fault.c | 4 +- .../arm/bifrost/mali_kbase_debug_job_fault.h | 4 +- .../arm/bifrost/mali_kbase_debug_mem_view.c | 6 +- .../arm/bifrost/mali_kbase_debug_mem_view.h | 4 +- .../arm/bifrost/mali_kbase_debugfs_helper.c | 33 +- .../arm/bifrost/mali_kbase_debugfs_helper.h | 27 +- drivers/gpu/arm/bifrost/mali_kbase_defs.h | 52 +- .../arm/bifrost/mali_kbase_disjoint_events.c | 4 +- .../gpu/arm/bifrost/mali_kbase_dma_fence.c | 25 +- .../gpu/arm/bifrost/mali_kbase_dma_fence.h | 9 +- .../gpu/arm/bifrost/mali_kbase_dummy_job_wa.c | 10 +- .../gpu/arm/bifrost/mali_kbase_dummy_job_wa.h | 4 +- .../gpu/arm/bifrost/mali_kbase_dvfs_debugfs.c | 6 +- .../gpu/arm/bifrost/mali_kbase_dvfs_debugfs.h | 4 +- drivers/gpu/arm/bifrost/mali_kbase_event.c | 4 +- drivers/gpu/arm/bifrost/mali_kbase_fence.c | 4 +- drivers/gpu/arm/bifrost/mali_kbase_fence.h | 4 +- .../gpu/arm/bifrost/mali_kbase_fence_defs.h | 4 +- .../gpu/arm/bifrost/mali_kbase_fence_ops.c | 4 +- drivers/gpu/arm/bifrost/mali_kbase_gator.h | 4 +- .../bifrost/mali_kbase_gpu_memory_debugfs.c | 4 +- .../bifrost/mali_kbase_gpu_memory_debugfs.h | 2 +- drivers/gpu/arm/bifrost/mali_kbase_gpuprops.c | 18 +- drivers/gpu/arm/bifrost/mali_kbase_gpuprops.h | 2 +- .../arm/bifrost/mali_kbase_gpuprops_types.h | 2 +- drivers/gpu/arm/bifrost/mali_kbase_gwt.c | 4 +- drivers/gpu/arm/bifrost/mali_kbase_gwt.h | 2 +- drivers/gpu/arm/bifrost/mali_kbase_hw.c | 22 +- drivers/gpu/arm/bifrost/mali_kbase_hw.h | 2 +- .../arm/bifrost/mali_kbase_hwaccess_backend.h | 4 +- .../arm/bifrost/mali_kbase_hwaccess_defs.h | 4 +- .../bifrost/mali_kbase_hwaccess_gpuprops.h | 4 +- .../arm/bifrost/mali_kbase_hwaccess_instr.h | 6 +- .../gpu/arm/bifrost/mali_kbase_hwaccess_jm.h | 2 +- .../gpu/arm/bifrost/mali_kbase_hwaccess_pm.h | 4 +- .../arm/bifrost/mali_kbase_hwaccess_time.h | 2 +- drivers/gpu/arm/bifrost/mali_kbase_hwcnt.c | 4 +- .../bifrost/mali_kbase_hwcnt_accumulator.h | 4 +- .../arm/bifrost/mali_kbase_hwcnt_backend.h | 73 +- .../bifrost/mali_kbase_hwcnt_backend_csf.c | 13 +- .../bifrost/mali_kbase_hwcnt_backend_csf.h | 2 +- .../bifrost/mali_kbase_hwcnt_backend_csf_if.h | 66 +- .../mali_kbase_hwcnt_backend_csf_if_fw.c | 39 +- .../mali_kbase_hwcnt_backend_csf_if_fw.h | 2 +- .../arm/bifrost/mali_kbase_hwcnt_backend_jm.c | 38 +- .../arm/bifrost/mali_kbase_hwcnt_backend_jm.h | 4 +- .../arm/bifrost/mali_kbase_hwcnt_context.h | 4 +- .../gpu/arm/bifrost/mali_kbase_hwcnt_gpu.c | 152 ++- .../gpu/arm/bifrost/mali_kbase_hwcnt_gpu.h | 60 +- .../gpu/arm/bifrost/mali_kbase_hwcnt_legacy.c | 2 +- .../gpu/arm/bifrost/mali_kbase_hwcnt_legacy.h | 4 +- .../gpu/arm/bifrost/mali_kbase_hwcnt_types.c | 18 +- .../gpu/arm/bifrost/mali_kbase_hwcnt_types.h | 40 +- .../bifrost/mali_kbase_hwcnt_virtualizer.c | 4 +- .../bifrost/mali_kbase_hwcnt_virtualizer.h | 4 +- drivers/gpu/arm/bifrost/mali_kbase_jd.c | 14 +- .../gpu/arm/bifrost/mali_kbase_jd_debugfs.c | 4 +- .../gpu/arm/bifrost/mali_kbase_jd_debugfs.h | 2 +- drivers/gpu/arm/bifrost/mali_kbase_jm.c | 2 +- drivers/gpu/arm/bifrost/mali_kbase_jm.h | 4 +- drivers/gpu/arm/bifrost/mali_kbase_js.c | 16 +- drivers/gpu/arm/bifrost/mali_kbase_js.h | 2 +- .../gpu/arm/bifrost/mali_kbase_js_ctx_attr.c | 2 +- .../gpu/arm/bifrost/mali_kbase_js_ctx_attr.h | 2 +- .../gpu/arm/bifrost/mali_kbase_kinstr_jm.c | 4 +- .../gpu/arm/bifrost/mali_kbase_kinstr_jm.h | 2 +- drivers/gpu/arm/bifrost/mali_kbase_linux.h | 2 +- drivers/gpu/arm/bifrost/mali_kbase_mem.c | 29 +- drivers/gpu/arm/bifrost/mali_kbase_mem.h | 4 +- .../gpu/arm/bifrost/mali_kbase_mem_linux.c | 38 +- .../gpu/arm/bifrost/mali_kbase_mem_linux.h | 2 +- .../gpu/arm/bifrost/mali_kbase_mem_lowlevel.h | 2 +- drivers/gpu/arm/bifrost/mali_kbase_mem_pool.c | 2 +- .../arm/bifrost/mali_kbase_mem_pool_debugfs.c | 4 +- .../arm/bifrost/mali_kbase_mem_pool_debugfs.h | 4 +- .../arm/bifrost/mali_kbase_mem_pool_group.c | 4 +- .../arm/bifrost/mali_kbase_mem_pool_group.h | 4 +- .../bifrost/mali_kbase_mem_profile_debugfs.c | 4 +- .../bifrost/mali_kbase_mem_profile_debugfs.h | 2 +- .../mali_kbase_mem_profile_debugfs_buf_size.h | 2 +- .../arm/bifrost/mali_kbase_mipe_gen_header.h | 2 +- .../gpu/arm/bifrost/mali_kbase_mipe_proto.h | 2 +- .../gpu/arm/bifrost/mali_kbase_native_mgm.c | 4 +- .../gpu/arm/bifrost/mali_kbase_native_mgm.h | 2 +- .../arm/bifrost/mali_kbase_platform_fake.c | 3 +- drivers/gpu/arm/bifrost/mali_kbase_pm.c | 6 +- drivers/gpu/arm/bifrost/mali_kbase_pm.h | 2 +- .../bifrost/mali_kbase_regs_history_debugfs.c | 8 +- .../bifrost/mali_kbase_regs_history_debugfs.h | 28 +- .../gpu/arm/bifrost/mali_kbase_reset_gpu.h | 2 +- drivers/gpu/arm/bifrost/mali_kbase_smc.c | 6 +- drivers/gpu/arm/bifrost/mali_kbase_smc.h | 6 +- drivers/gpu/arm/bifrost/mali_kbase_softjobs.c | 2 +- drivers/gpu/arm/bifrost/mali_kbase_strings.c | 4 +- drivers/gpu/arm/bifrost/mali_kbase_strings.h | 4 +- drivers/gpu/arm/bifrost/mali_kbase_sync.h | 6 +- .../gpu/arm/bifrost/mali_kbase_sync_android.c | 4 +- .../gpu/arm/bifrost/mali_kbase_sync_common.c | 2 +- .../gpu/arm/bifrost/mali_kbase_sync_file.c | 4 +- .../arm/bifrost/mali_kbase_trace_gpu_mem.c | 4 +- .../arm/bifrost/mali_kbase_trace_gpu_mem.h | 8 +- drivers/gpu/arm/bifrost/mali_kbase_utility.h | 4 +- drivers/gpu/arm/bifrost/mali_kbase_vinstr.c | 64 +- drivers/gpu/arm/bifrost/mali_kbase_vinstr.h | 4 +- drivers/gpu/arm/bifrost/mali_linux_trace.h | 2 +- drivers/gpu/arm/bifrost/mali_malisw.h | 2 +- .../bifrost/mali_power_gpu_frequency_trace.c | 4 +- .../bifrost/mali_power_gpu_frequency_trace.h | 4 +- drivers/gpu/arm/bifrost/mmu/Kbuild | 30 + .../bifrost/mmu/backend/mali_kbase_mmu_csf.c | 13 +- .../bifrost/mmu/backend/mali_kbase_mmu_jm.c | 4 +- drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu.c | 41 +- drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu.h | 4 +- .../gpu/arm/bifrost/mmu/mali_kbase_mmu_hw.h | 2 +- .../bifrost/mmu/mali_kbase_mmu_hw_direct.c | 2 +- .../arm/bifrost/mmu/mali_kbase_mmu_internal.h | 4 +- .../bifrost/mmu/mali_kbase_mmu_mode_aarch64.c | 4 +- drivers/gpu/arm/bifrost/platform/Kconfig | 4 +- .../arm/bifrost/platform/devicetree/Kbuild | 11 +- .../devicetree/mali_kbase_clk_rate_trace.c | 4 +- .../devicetree/mali_kbase_config_devicetree.c | 17 +- .../devicetree/mali_kbase_config_platform.c | 43 + .../devicetree/mali_kbase_config_platform.h | 8 +- .../devicetree/mali_kbase_runtime_pm.c | 5 +- drivers/gpu/arm/bifrost/platform/rk/Kbuild | 3 +- .../gpu/arm/bifrost/platform/vexpress/Kbuild | 8 +- .../vexpress/mali_kbase_config_platform.h | 4 +- .../vexpress/mali_kbase_config_vexpress.c | 17 +- .../bifrost/platform/vexpress_1xv7_a57/Kbuild | 8 +- .../mali_kbase_config_platform.h | 4 +- .../mali_kbase_config_vexpress.c | 17 +- .../platform/vexpress_6xvirtex7_10mhz/Kbuild | 10 +- .../mali_kbase_config_platform.h | 4 +- .../mali_kbase_config_vexpress.c | 17 +- .../gpu/arm/bifrost/protected_mode_switcher.h | 2 +- drivers/gpu/arm/bifrost/tests/Kbuild | 15 +- drivers/gpu/arm/bifrost/tests/Kconfig | 44 +- drivers/gpu/arm/bifrost/tests/Mconfig | 70 +- drivers/gpu/arm/bifrost/tests/build.bp | 40 + .../bifrost/tests/include/kutf/kutf_helpers.h | 4 +- .../tests/include/kutf/kutf_helpers_user.h | 4 +- .../arm/bifrost/tests/include/kutf/kutf_mem.h | 4 +- .../tests/include/kutf/kutf_resultset.h | 4 +- .../bifrost/tests/include/kutf/kutf_suite.h | 4 +- .../bifrost/tests/include/kutf/kutf_utils.h | 4 +- drivers/gpu/arm/bifrost/tests/kutf/Kbuild | 18 +- drivers/gpu/arm/bifrost/tests/kutf/build.bp | 12 +- .../gpu/arm/bifrost/tests/kutf/kutf_helpers.c | 4 +- .../bifrost/tests/kutf/kutf_helpers_user.c | 4 +- drivers/gpu/arm/bifrost/tests/kutf/kutf_mem.c | 4 +- .../arm/bifrost/tests/kutf/kutf_resultset.c | 4 +- .../gpu/arm/bifrost/tests/kutf/kutf_suite.c | 6 +- .../gpu/arm/bifrost/tests/kutf/kutf_utils.c | 4 +- .../mali_kutf_clk_rate_trace/kernel/Kbuild | 10 +- .../mali_kutf_clk_rate_trace/kernel/Kconfig | 29 - .../mali_kutf_clk_rate_trace/kernel/Makefile | 56 -- .../mali_kutf_clk_rate_trace/kernel/build.bp | 13 +- .../kernel/mali_kutf_clk_rate_trace_test.c | 104 +- .../mali_kutf_clk_rate_trace_test.h | 8 +- .../bifrost/tests/mali_kutf_irq_test/Kbuild | 10 +- .../bifrost/tests/mali_kutf_irq_test/Kconfig | 28 - .../bifrost/tests/mali_kutf_irq_test/Makefile | 50 - .../bifrost/tests/mali_kutf_irq_test/build.bp | 9 +- .../mali_kutf_irq_test_main.c | 2 +- .../{Makefile.kbase => thirdparty/Kbuild} | 4 +- .../arm/bifrost/thirdparty/mali_kbase_mmap.c | 4 +- drivers/gpu/arm/bifrost/tl/Kbuild | 32 + .../tl/backend/mali_kbase_timeline_csf.c | 8 +- .../tl/backend/mali_kbase_timeline_jm.c | 8 +- .../gpu/arm/bifrost/tl/mali_kbase_timeline.c | 2 +- .../gpu/arm/bifrost/tl/mali_kbase_timeline.h | 2 +- .../arm/bifrost/tl/mali_kbase_timeline_io.c | 2 +- .../arm/bifrost/tl/mali_kbase_timeline_priv.h | 2 +- .../arm/bifrost/tl/mali_kbase_tl_serialize.h | 4 +- .../gpu/arm/bifrost/tl/mali_kbase_tlstream.c | 2 +- .../gpu/arm/bifrost/tl/mali_kbase_tlstream.h | 2 +- .../arm/bifrost/tl/mali_kbase_tracepoints.c | 2 +- .../arm/bifrost/tl/mali_kbase_tracepoints.h | 12 +- include/linux/dma-buf-test-exporter.h | 81 ++ include/linux/memory_group_manager.h | 4 +- include/linux/priority_control_manager.h | 2 +- include/linux/protected_memory_allocator.h | 4 +- include/linux/protected_mode_switcher.h | 4 +- .../arm/bifrost/csf/mali_gpu_csf_registers.h | 76 +- .../arm/bifrost/csf/mali_kbase_csf_ioctl.h | 47 +- .../gpu/arm/bifrost/gpu/mali_kbase_gpu_id.h | 2 + .../arm/bifrost/gpu/mali_kbase_gpu_regmap.h | 10 + 380 files changed, 7205 insertions(+), 2620 deletions(-) create mode 100644 Documentation/dma-buf-test-exporter.txt create mode 100644 drivers/base/arm/Kbuild create mode 100644 drivers/base/arm/Kconfig create mode 100644 drivers/base/arm/Makefile create mode 100644 drivers/base/arm/Mconfig rename drivers/{gpu/arm/bifrost/tests/kutf/Kconfig => base/arm/dma_buf_lock/src/Kbuild} (69%) rename drivers/base/arm/{memory_group_manager => dma_buf_lock/src}/Makefile (85%) create mode 100644 drivers/base/arm/dma_buf_lock/src/dma_buf_lock.c create mode 100644 drivers/base/arm/dma_buf_lock/src/dma_buf_lock.h create mode 100644 drivers/base/arm/dma_buf_test_exporter/Kbuild create mode 100644 drivers/base/arm/dma_buf_test_exporter/build.bp create mode 100644 drivers/base/arm/dma_buf_test_exporter/dma-buf-test-exporter.c delete mode 100644 drivers/base/arm/protected_memory_allocator/Makefile rename drivers/{base/arm/protected_memory_allocator/Kconfig => gpu/arm/bifrost/context/Kbuild} (63%) create mode 100644 drivers/gpu/arm/bifrost/debug/Kbuild rename drivers/gpu/arm/bifrost/{tests/kutf/Makefile => device/Kbuild} (58%) rename drivers/{base/arm/memory_group_manager/Kconfig => gpu/arm/bifrost/gpu/Kbuild} (66%) create mode 100644 drivers/gpu/arm/bifrost/mmu/Kbuild create mode 100644 drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_config_platform.c create mode 100644 drivers/gpu/arm/bifrost/tests/build.bp delete mode 100644 drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/Kconfig delete mode 100644 drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/Makefile delete mode 100644 drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/Kconfig delete mode 100644 drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/Makefile rename drivers/gpu/arm/bifrost/{Makefile.kbase => thirdparty/Kbuild} (82%) create mode 100644 drivers/gpu/arm/bifrost/tl/Kbuild create mode 100644 include/linux/dma-buf-test-exporter.h diff --git a/Documentation/ABI/testing/sysfs-device-mali b/Documentation/ABI/testing/sysfs-device-mali index 1cd1819d42bc..99f8ae57b7c9 100644 --- a/Documentation/ABI/testing/sysfs-device-mali +++ b/Documentation/ABI/testing/sysfs-device-mali @@ -15,10 +15,11 @@ What: /sys/class/misc/mali%u/device/core_mask Description: - This attribute is used to restrict number of shader core - available, is useful for debugging purposes. Reading - this attribute provides us mask of cores available. - Writing to it will set the current core mask. + This attribute is used to restrict the number of shader cores + available in this instance, is useful for debugging purposes. + Reading this attribute provides us mask of all cores available. + Writing to it will set the current core mask. Doesn't + allow disabling all the cores present in this instance. What: /sys/class/misc/mali%u/device/debug_command Description: @@ -43,6 +44,14 @@ Description: Its a readonly attribute and on reading gives details on the options used with the dummy workaround. +What: /sys/class/misc/mali%u/device/fw_timeout +Description: + This attribute is available only with mali platform + device-driver that supports a CSF GPU. This attribute is + used to set the duration value in milliseconds for the + waiting timeout used for a GPU status change request being + acknowledged by the FW. + What: /sys/class/misc/mali%u/device/gpuinfo Description: This attribute provides description of the present Mali GPU. diff --git a/Documentation/devicetree/bindings/arm/mali-bifrost.txt b/Documentation/devicetree/bindings/arm/mali-bifrost.txt index 93493e833c9b..a74d56945a1d 100644 --- a/Documentation/devicetree/bindings/arm/mali-bifrost.txt +++ b/Documentation/devicetree/bindings/arm/mali-bifrost.txt @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # # (C) COPYRIGHT 2013-2021 ARM Limited. All rights reserved. # @@ -97,6 +97,8 @@ for details. are used at different points so care should be taken to configure both power models in the device tree (specifically dynamic-coefficient, static-coefficient and scale) to best match the platform. +- power_policy : Sets the GPU power policy at probe time. Available options are + "coarse_demand" and "always_on". If not set, then "coarse_demand" is used. - system-coherency : Sets the coherency protocol to be used for coherent accesses made from the GPU. If not set then no coherency is used. diff --git a/Documentation/devicetree/bindings/arm/memory_group_manager.txt b/Documentation/devicetree/bindings/arm/memory_group_manager.txt index 77a94743a97b..634973f1434c 100644 --- a/Documentation/devicetree/bindings/arm/memory_group_manager.txt +++ b/Documentation/devicetree/bindings/arm/memory_group_manager.txt @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software diff --git a/Documentation/devicetree/bindings/arm/priority_control_manager.txt b/Documentation/devicetree/bindings/arm/priority_control_manager.txt index 0a34896dd8ee..c7dd14f64427 100644 --- a/Documentation/devicetree/bindings/arm/priority_control_manager.txt +++ b/Documentation/devicetree/bindings/arm/priority_control_manager.txt @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software diff --git a/Documentation/devicetree/bindings/arm/protected_memory_allocator.txt b/Documentation/devicetree/bindings/arm/protected_memory_allocator.txt index 8ca5f08c6b44..89a3cc7fad46 100644 --- a/Documentation/devicetree/bindings/arm/protected_memory_allocator.txt +++ b/Documentation/devicetree/bindings/arm/protected_memory_allocator.txt @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software diff --git a/Documentation/devicetree/bindings/power/mali-opp.txt b/Documentation/devicetree/bindings/power/mali-opp.txt index 411c99229e95..009e8eab3d40 100644 --- a/Documentation/devicetree/bindings/power/mali-opp.txt +++ b/Documentation/devicetree/bindings/power/mali-opp.txt @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # # (C) COPYRIGHT 2017, 2019-2021 ARM Limited. All rights reserved. # diff --git a/Documentation/dma-buf-test-exporter.txt b/Documentation/dma-buf-test-exporter.txt new file mode 100644 index 000000000000..b01020c06751 --- /dev/null +++ b/Documentation/dma-buf-test-exporter.txt @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note +# +# (C) COPYRIGHT 2012-2013, 2020-2021 ARM Limited. All rights reserved. +# +# This program is free software and is provided to you under the terms of the +# GNU General Public License version 2 as published by the Free Software +# Foundation, and any use by you of this program is subject to the terms +# of such GNU license. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you can access it online at +# http://www.gnu.org/licenses/gpl-2.0.html. +# +# + +===================== +dma-buf-test-exporter +===================== + +Overview +-------- + +The dma-buf-test-exporter is a simple exporter of dma_buf objects. +It has a private API to allocate and manipulate the buffers which are represented as dma_buf fds. +The private API allows: +* simple allocation of physically non-contiguous buffers +* simple allocation of physically contiguous buffers +* query kernel side API usage stats (number of attachments, number of mappings, mmaps) +* failure mode configuration (fail attach, mapping, mmap) +* kernel side memset of buffers + +The buffers support all of the dma_buf API, including mmap. + +It supports being compiled as a module both in-tree and out-of-tree. + +See include/linux/dma-buf-test-exporter.h for the ioctl interface. +See Documentation/dma-buf-sharing.txt for details on dma_buf. diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index edcaf6d35f23..3e82b64c6184 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig @@ -183,8 +183,7 @@ config SOC_BUS source "drivers/base/regmap/Kconfig" -source "drivers/base/arm/memory_group_manager/Kconfig" -source "drivers/base/arm/protected_memory_allocator/Kconfig" +source "drivers/base/arm/Kconfig" config DMA_SHARED_BUFFER bool diff --git a/drivers/base/arm/Kbuild b/drivers/base/arm/Kbuild new file mode 100644 index 000000000000..b0fbf9369381 --- /dev/null +++ b/drivers/base/arm/Kbuild @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note +# +# (C) COPYRIGHT 2021 ARM Limited. All rights reserved. +# +# This program is free software and is provided to you under the terms of the +# GNU General Public License version 2 as published by the Free Software +# Foundation, and any use by you of this program is subject to the terms +# of such GNU license. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you can access it online at +# http://www.gnu.org/licenses/gpl-2.0.html. +# +# + +# +# ccflags +# +ccflags-y += -I$(src)/../../../include + +subdir-ccflags-y += $(ccflags-y) + +# +# Kernel modules +# +obj-$(CONFIG_DMA_SHARED_BUFFER_TEST_EXPORTER) += dma_buf_test_exporter/ +obj-$(CONFIG_MALI_MEMORY_GROUP_MANAGER) += memory_group_manager/ +obj-$(CONFIG_MALI_PROTECTED_MEMORY_ALLOCATOR) += protected_memory_allocator/ + diff --git a/drivers/base/arm/Kconfig b/drivers/base/arm/Kconfig new file mode 100644 index 000000000000..75d543489707 --- /dev/null +++ b/drivers/base/arm/Kconfig @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note +# +# (C) COPYRIGHT 2021 ARM Limited. All rights reserved. +# +# This program is free software and is provided to you under the terms of the +# GNU General Public License version 2 as published by the Free Software +# Foundation, and any use by you of this program is subject to the terms +# of such GNU license. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you can access it online at +# http://www.gnu.org/licenses/gpl-2.0.html. +# +# + +menuconfig MALI_BASE_MODULES + bool "Mali Base extra modules" + default n + help + Enable this option to build support for a Arm Mali base modules. + Those modules provide extra features or debug interfaces and, + are optional for the use of the Mali GPU modules. + +config DMA_SHARED_BUFFER_TEST_EXPORTER + bool "Build dma-buf framework test exporter module" + depends on MALI_BASE_MODULES && DMA_SHARED_BUFFER + default y + help + This option will build the dma-buf framework test exporter module. + Usable to help test importers. + + Modules: + - dma-buf-test-exporter.ko + +config MALI_MEMORY_GROUP_MANAGER + bool "Build Mali Memory Group Manager module" + depends on MALI_BASE_MODULES + default y + help + This option will build the memory group manager module. + This is an example implementation for allocation and release of pages + for memory pools managed by Mali GPU device drivers. + + Modules: + - memory_group_manager.ko + +config MALI_PROTECTED_MEMORY_ALLOCATOR + bool "Build Mali Protected Memory Allocator module" + depends on MALI_BASE_MODULES && MALI_CSF_SUPPORT + default y + help + This option will build the protected memory allocator module. + This is an example implementation for allocation and release of pages + of secure memory intended to be used by the firmware + of Mali GPU device drivers. + + Modules: + - protected_memory_allocator.ko + diff --git a/drivers/base/arm/Makefile b/drivers/base/arm/Makefile new file mode 100644 index 000000000000..0bd6ab5f502f --- /dev/null +++ b/drivers/base/arm/Makefile @@ -0,0 +1,98 @@ +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note +# +# (C) COPYRIGHT 2021 ARM Limited. All rights reserved. +# +# This program is free software and is provided to you under the terms of the +# GNU General Public License version 2 as published by the Free Software +# Foundation, and any use by you of this program is subject to the terms +# of such GNU license. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you can access it online at +# http://www.gnu.org/licenses/gpl-2.0.html. +# +# + +# +# Paths +# +KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build +KDIR ?= $(KERNEL_SRC) + +ifeq ($(KDIR),) + $(error Must specify KDIR to point to the kernel to target)) +endif + +vars := +# +# Default configuration values +# +CONFIG_MALI_BASE_MODULES ?= n + +ifeq ($(CONFIG_MALI_BASE_MODULES),y) + CONFIG_MALI_CSF_SUPPORT ?= n + + ifneq ($(CONFIG_DMA_SHARED_BUFFER),n) + CONFIG_DMA_SHARED_BUFFER_TEST_EXPORTER ?= y + else + # Prevent misuse when CONFIG_DMA_SHARED_BUFFER=n + CONFIG_DMA_SHARED_BUFFER_TEST_EXPORTER = n + endif + + CONFIG_MALI_MEMORY_GROUP_MANAGER ?= y + + ifneq ($(CONFIG_MALI_CSF_SUPPORT), n) + CONFIG_MALI_PROTECTED_MEMORY_ALLOCATOR ?= y + endif + +else + # Prevent misuse when CONFIG_MALI_BASE_MODULES=n + CONFIG_DMA_SHARED_BUFFER_TEST_EXPORTER = n + CONFIG_MALI_MEMORY_GROUP_MANAGER = n + CONFIG_MALI_PROTECTED_MEMORY_ALLOCATOR = n + +endif + +CONFIGS := \ + CONFIG_MALI_BASE_MODULES \ + CONFIG_MALI_CSF_SUPPORT \ + CONFIG_DMA_SHARED_BUFFER_TEST_EXPORTER \ + CONFIG_MALI_MEMORY_GROUP_MANAGER \ + CONFIG_MALI_PROTECTED_MEMORY_ALLOCATOR + + +# +# MAKE_ARGS to pass the custom CONFIGs on out-of-tree build +# +# Generate the list of CONFIGs and values. +# $(value config) is the name of the CONFIG option. +# $(value $(value config)) is its value (y, m). +# When the CONFIG is not set to y or m, it defaults to n. +MAKE_ARGS := $(foreach config,$(CONFIGS), \ + $(if $(filter y m,$(value $(value config))), \ + $(value config)=$(value $(value config)), \ + $(value config)=n)) + +# +# EXTRA_CFLAGS to define the custom CONFIGs on out-of-tree build +# +# Generate the list of CONFIGs defines with values from CONFIGS. +# $(value config) is the name of the CONFIG option. +# When set to y or m, the CONFIG gets defined to 1. +EXTRA_CFLAGS := $(foreach config,$(CONFIGS), \ + $(if $(filter y m,$(value $(value config))), \ + -D$(value config)=1)) + +all: + $(MAKE) -C $(KDIR) M=$(CURDIR) $(MAKE_ARGS) EXTRA_CFLAGS="$(EXTRA_CFLAGS)" KBUILD_EXTRA_SYMBOLS="$(EXTRA_SYMBOLS)" modules + +modules_install: + $(MAKE) -C $(KDIR) M=$(CURDIR) $(MAKE_ARGS) modules_install + +clean: + $(MAKE) -C $(KDIR) M=$(CURDIR) $(MAKE_ARGS) clean diff --git a/drivers/base/arm/Mconfig b/drivers/base/arm/Mconfig new file mode 100644 index 000000000000..d21a72e4b9a7 --- /dev/null +++ b/drivers/base/arm/Mconfig @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note +# +# (C) COPYRIGHT 2021 ARM Limited. All rights reserved. +# +# This program is free software and is provided to you under the terms of the +# GNU General Public License version 2 as published by the Free Software +# Foundation, and any use by you of this program is subject to the terms +# of such GNU license. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you can access it online at +# http://www.gnu.org/licenses/gpl-2.0.html. +# +# + +menuconfig MALI_BASE_MODULES + bool "Mali Base extra modules" + default y if BACKEND_KERNEL + help + Enable this option to build support for a Arm Mali base modules. + Those modules provide extra features or debug interfaces and, + are optional for the use of the Mali GPU modules. + +config DMA_SHARED_BUFFER_TEST_EXPORTER + bool "Build dma-buf framework test exporter module" + depends on MALI_BASE_MODULES + default y + help + This option will build the dma-buf framework test exporter module. + Usable to help test importers. + + Modules: + - dma-buf-test-exporter.ko + +config MALI_MEMORY_GROUP_MANAGER + bool "Build Mali Memory Group Manager module" + depends on MALI_BASE_MODULES + default y + help + This option will build the memory group manager module. + This is an example implementation for allocation and release of pages + for memory pools managed by Mali GPU device drivers. + + Modules: + - memory_group_manager.ko + +config MALI_PROTECTED_MEMORY_ALLOCATOR + bool "Build Mali Protected Memory Allocator module" + depends on MALI_BASE_MODULES && GPU_HAS_CSF + default y + help + This option will build the protected memory allocator module. + This is an example implementation for allocation and release of pages + of secure memory intended to be used by the firmware + of Mali GPU device drivers. + + Modules: + - protected_memory_allocator.ko + diff --git a/drivers/gpu/arm/bifrost/tests/kutf/Kconfig b/drivers/base/arm/dma_buf_lock/src/Kbuild similarity index 69% rename from drivers/gpu/arm/bifrost/tests/kutf/Kconfig rename to drivers/base/arm/dma_buf_lock/src/Kbuild index 7ea95b600160..c7ae3324e798 100644 --- a/drivers/gpu/arm/bifrost/tests/kutf/Kconfig +++ b/drivers/base/arm/dma_buf_lock/src/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2017, 2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2012, 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -18,9 +18,6 @@ # # -config MALI_KUTF - tristate "Mali Kernel Unit Test Framework" - default m - help - Enables MALI testing framework. To compile it as a module, - choose M here - this will generate a single module called kutf. +ifeq ($(CONFIG_DMA_SHARED_BUFFER), y) +obj-m := dma_buf_lock.o +endif diff --git a/drivers/base/arm/memory_group_manager/Makefile b/drivers/base/arm/dma_buf_lock/src/Makefile similarity index 85% rename from drivers/base/arm/memory_group_manager/Makefile rename to drivers/base/arm/dma_buf_lock/src/Makefile index 4f1ef727cb23..451d2d710123 100644 --- a/drivers/base/arm/memory_group_manager/Makefile +++ b/drivers/base/arm/dma_buf_lock/src/Makefile @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2012, 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -27,8 +27,10 @@ ARCH ?= $(shell uname -m) KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build KDIR ?= $(KERNEL_SRC) -all: - $(MAKE) ARCH=$(ARCH) -C $(KDIR) M=$(CURDIR) EXTRA_CFLAGS="-I$(CURDIR)/../../../../include" modules CONFIG_MALI_MEMORY_GROUP_MANAGER=m +all: dma_buf_lock + +dma_buf_lock: + $(MAKE) ARCH=$(ARCH) -C $(KDIR) M=$(CURDIR) EXTRA_CFLAGS="-I$(CURDIR)/../../../../../include" clean: $(MAKE) ARCH=$(ARCH) -C $(KDIR) M=$(CURDIR) clean diff --git a/drivers/base/arm/dma_buf_lock/src/dma_buf_lock.c b/drivers/base/arm/dma_buf_lock/src/dma_buf_lock.c new file mode 100644 index 000000000000..f5ab1ed8f405 --- /dev/null +++ b/drivers/base/arm/dma_buf_lock/src/dma_buf_lock.c @@ -0,0 +1,898 @@ +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note +/* + * + * (C) COPYRIGHT 2012-2014, 2017-2018, 2020-2021 ARM Limited. All rights reserved. + * + * This program is free software and is provided to you under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation, and any use by you of this program is subject to the terms + * of such GNU license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you can access it online at + * http://www.gnu.org/licenses/gpl-2.0.html. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if (KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE) +#include +#else +#include +#endif +#include +#include +#include +#include +#include +#include + +#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) + +#include + +#define dma_fence_context_alloc(a) fence_context_alloc(a) +#define dma_fence_init(a, b, c, d, e) fence_init(a, b, c, d, e) +#define dma_fence_get(a) fence_get(a) +#define dma_fence_put(a) fence_put(a) +#define dma_fence_signal(a) fence_signal(a) +#define dma_fence_is_signaled(a) fence_is_signaled(a) +#define dma_fence_add_callback(a, b, c) fence_add_callback(a, b, c) +#define dma_fence_remove_callback(a, b) fence_remove_callback(a, b) + +#if (KERNEL_VERSION(4, 9, 68) > LINUX_VERSION_CODE) +#define dma_fence_get_status(a) (fence_is_signaled(a) ? (a)->status ?: 1 : 0) +#else +#define dma_fence_get_status(a) (fence_is_signaled(a) ? (a)->error ?: 1 : 0) +#endif + +#else + +#include + +#if (KERNEL_VERSION(4, 11, 0) > LINUX_VERSION_CODE) +#define dma_fence_get_status(a) (dma_fence_is_signaled(a) ? \ + (a)->status ?: 1 \ + : 0) +#endif + +#endif /* < 4.10.0 */ + +#include "dma_buf_lock.h" + +/* Maximum number of buffers that a single handle can address */ +#define DMA_BUF_LOCK_BUF_MAX 32 + +#define DMA_BUF_LOCK_DEBUG 1 + +#define DMA_BUF_LOCK_INIT_BIAS 0xFF + +static dev_t dma_buf_lock_dev; +static struct cdev dma_buf_lock_cdev; +static struct class *dma_buf_lock_class; +static char dma_buf_lock_dev_name[] = "dma_buf_lock"; + +#ifdef HAVE_UNLOCKED_IOCTL +static long dma_buf_lock_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); +#else +static int dma_buf_lock_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg); +#endif + +static struct file_operations dma_buf_lock_fops = +{ + .owner = THIS_MODULE, +#ifdef HAVE_UNLOCKED_IOCTL + .unlocked_ioctl = dma_buf_lock_ioctl, +#else + .ioctl = dma_buf_lock_ioctl, +#endif + .compat_ioctl = dma_buf_lock_ioctl, +}; + +typedef struct dma_buf_lock_resource +{ +#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) + struct fence fence; +#else + struct dma_fence fence; +#endif + int *list_of_dma_buf_fds; /* List of buffers copied from userspace */ + atomic_t locked; /* Status of lock */ + struct dma_buf **dma_bufs; + unsigned long exclusive; /* Exclusive access bitmap */ + atomic_t fence_dep_count; /* Number of dma-fence dependencies */ + struct list_head dma_fence_callbacks; /* list of all callbacks set up to wait on other fences */ + wait_queue_head_t wait; + struct kref refcount; + struct list_head link; + struct work_struct work; + int count; +} dma_buf_lock_resource; + +/** + * struct dma_buf_lock_fence_cb - Callback data struct for dma-fence + * @fence_cb: Callback function + * @fence: Pointer to the fence object on which this callback is waiting + * @res: Pointer to dma_buf_lock_resource that is waiting on this callback + * @node: List head for linking this callback to the lock resource + */ +struct dma_buf_lock_fence_cb { +#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) + struct fence_cb fence_cb; + struct fence *fence; +#else + struct dma_fence_cb fence_cb; + struct dma_fence *fence; +#endif + struct dma_buf_lock_resource *res; + struct list_head node; +}; + +static LIST_HEAD(dma_buf_lock_resource_list); +static DEFINE_MUTEX(dma_buf_lock_mutex); + +static inline int is_dma_buf_lock_file(struct file *); +static void dma_buf_lock_dounlock(struct kref *ref); + + +/*** dma_buf_lock fence part ***/ + +/* Spin lock protecting all Mali fences as fence->lock. */ +static DEFINE_SPINLOCK(dma_buf_lock_fence_lock); + +static const char * +#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) +dma_buf_lock_fence_get_driver_name(struct fence *fence) +#else +dma_buf_lock_fence_get_driver_name(struct dma_fence *fence) +#endif +{ + return "dma_buf_lock"; +} + +static const char * +#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) +dma_buf_lock_fence_get_timeline_name(struct fence *fence) +#else +dma_buf_lock_fence_get_timeline_name(struct dma_fence *fence) +#endif +{ + return "dma_buf_lock.timeline"; +} + +static bool +#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) +dma_buf_lock_fence_enable_signaling(struct fence *fence) +#else +dma_buf_lock_fence_enable_signaling(struct dma_fence *fence) +#endif +{ + return true; +} + +#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) +const struct fence_ops dma_buf_lock_fence_ops = { + .wait = fence_default_wait, +#else +const struct dma_fence_ops dma_buf_lock_fence_ops = { + .wait = dma_fence_default_wait, +#endif + .get_driver_name = dma_buf_lock_fence_get_driver_name, + .get_timeline_name = dma_buf_lock_fence_get_timeline_name, + .enable_signaling = dma_buf_lock_fence_enable_signaling, +}; + +static void +dma_buf_lock_fence_init(dma_buf_lock_resource *resource) +{ + dma_fence_init(&resource->fence, + &dma_buf_lock_fence_ops, + &dma_buf_lock_fence_lock, + 0, + 0); +} + +static void +dma_buf_lock_fence_free_callbacks(dma_buf_lock_resource *resource) +{ + struct dma_buf_lock_fence_cb *cb, *tmp; + + /* Clean up and free callbacks. */ + list_for_each_entry_safe(cb, tmp, &resource->dma_fence_callbacks, node) { + /* Cancel callbacks that hasn't been called yet and release the + * reference taken in dma_buf_lock_fence_add_callback(). + */ + dma_fence_remove_callback(cb->fence, &cb->fence_cb); + dma_fence_put(cb->fence); + list_del(&cb->node); + kfree(cb); + } +} + +static void +dma_buf_lock_fence_work(struct work_struct *pwork) +{ + dma_buf_lock_resource *resource = + container_of(pwork, dma_buf_lock_resource, work); + + WARN_ON(atomic_read(&resource->fence_dep_count)); + WARN_ON(!atomic_read(&resource->locked)); + WARN_ON(!resource->exclusive); + + mutex_lock(&dma_buf_lock_mutex); + kref_put(&resource->refcount, dma_buf_lock_dounlock); + mutex_unlock(&dma_buf_lock_mutex); +} + +static void +#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) +dma_buf_lock_fence_callback(struct fence *fence, struct fence_cb *cb) +#else +dma_buf_lock_fence_callback(struct dma_fence *fence, struct dma_fence_cb *cb) +#endif +{ + struct dma_buf_lock_fence_cb *dma_buf_lock_cb = container_of(cb, + struct dma_buf_lock_fence_cb, + fence_cb); + dma_buf_lock_resource *resource = dma_buf_lock_cb->res; + +#if DMA_BUF_LOCK_DEBUG + printk(KERN_DEBUG "dma_buf_lock_fence_callback\n"); +#endif + + /* Callback function will be invoked in atomic context. */ + + if (atomic_dec_and_test(&resource->fence_dep_count)) { + atomic_set(&resource->locked, 1); + wake_up(&resource->wait); + + if (resource->exclusive) + /* Warn if the work was already queued */ + WARN_ON(!schedule_work(&resource->work)); + } +} + +#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) +static int +dma_buf_lock_fence_add_callback(dma_buf_lock_resource *resource, + struct fence *fence, + fence_func_t callback) +#else +static int +dma_buf_lock_fence_add_callback(dma_buf_lock_resource *resource, + struct dma_fence *fence, + dma_fence_func_t callback) +#endif +{ + int err = 0; + struct dma_buf_lock_fence_cb *fence_cb; + + if (!fence) + return -EINVAL; + + fence_cb = kmalloc(sizeof(*fence_cb), GFP_KERNEL); + if (!fence_cb) + return -ENOMEM; + + fence_cb->fence = fence; + fence_cb->res = resource; + INIT_LIST_HEAD(&fence_cb->node); + + err = dma_fence_add_callback(fence, &fence_cb->fence_cb, + callback); + + if (err == -ENOENT) { + /* Fence signaled, get the completion result */ + err = dma_fence_get_status(fence); + + /* remap success completion to err code */ + if (err == 1) + err = 0; + + kfree(fence_cb); + } else if (err) { + kfree(fence_cb); + } else { + /* + * Get reference to fence that will be kept until callback gets + * cleaned up in dma_buf_lock_fence_free_callbacks(). + */ + dma_fence_get(fence); + atomic_inc(&resource->fence_dep_count); + /* Add callback to resource's list of callbacks */ + list_add(&fence_cb->node, &resource->dma_fence_callbacks); + } + + return err; +} + +#if (KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE) +static int +dma_buf_lock_add_fence_reservation_callback(dma_buf_lock_resource *resource, + struct reservation_object *resv, + bool exclusive) +#else +static int +dma_buf_lock_add_fence_reservation_callback(dma_buf_lock_resource *resource, + struct dma_resv *resv, + bool exclusive) +#endif +{ +#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) + struct fence *excl_fence = NULL; + struct fence **shared_fences = NULL; +#else + struct dma_fence *excl_fence = NULL; + struct dma_fence **shared_fences = NULL; +#endif + unsigned int shared_count = 0; + int err, i; + +#if (KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE) + err = reservation_object_get_fences_rcu( +#else + err = dma_resv_get_fences_rcu( +#endif + resv, + &excl_fence, + &shared_count, + &shared_fences); + if (err) + return err; + + if (excl_fence) { + err = dma_buf_lock_fence_add_callback(resource, + excl_fence, + dma_buf_lock_fence_callback); + + /* Release our reference, taken by reservation_object_get_fences_rcu(), + * to the fence. We have set up our callback (if that was possible), + * and it's the fence's owner is responsible for singling the fence + * before allowing it to disappear. + */ + dma_fence_put(excl_fence); + + if (err) + goto out; + } + + if (exclusive) { + for (i = 0; i < shared_count; i++) { + err = dma_buf_lock_fence_add_callback(resource, + shared_fences[i], + dma_buf_lock_fence_callback); + if (err) + goto out; + } + } + + /* Release all our references to the shared fences, taken by + * reservation_object_get_fences_rcu(). We have set up our callback (if + * that was possible), and it's the fence's owner is responsible for + * signaling the fence before allowing it to disappear. + */ +out: + for (i = 0; i < shared_count; i++) + dma_fence_put(shared_fences[i]); + kfree(shared_fences); + + return err; +} + +static void +dma_buf_lock_release_fence_reservation(dma_buf_lock_resource *resource, + struct ww_acquire_ctx *ctx) +{ + unsigned int r; + + for (r = 0; r < resource->count; r++) + ww_mutex_unlock(&resource->dma_bufs[r]->resv->lock); + ww_acquire_fini(ctx); +} + +static int +dma_buf_lock_acquire_fence_reservation(dma_buf_lock_resource *resource, + struct ww_acquire_ctx *ctx) +{ +#if (KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE) + struct reservation_object *content_resv = NULL; +#else + struct dma_resv *content_resv = NULL; +#endif + unsigned int content_resv_idx = 0; + unsigned int r; + int err = 0; + + ww_acquire_init(ctx, &reservation_ww_class); + +retry: + for (r = 0; r < resource->count; r++) { + if (resource->dma_bufs[r]->resv == content_resv) { + content_resv = NULL; + continue; + } + + err = ww_mutex_lock(&resource->dma_bufs[r]->resv->lock, ctx); + if (err) + goto error; + } + + ww_acquire_done(ctx); + return err; + +error: + content_resv_idx = r; + + /* Unlock the locked one ones */ + while (r--) + ww_mutex_unlock(&resource->dma_bufs[r]->resv->lock); + + if (content_resv) + ww_mutex_unlock(&content_resv->lock); + + /* If we deadlock try with lock_slow and retry */ + if (err == -EDEADLK) { +#if DMA_BUF_LOCK_DEBUG + printk(KERN_DEBUG "deadlock at dma_buf fd %i\n", + resource->list_of_dma_buf_fds[content_resv_idx]); +#endif + content_resv = resource->dma_bufs[content_resv_idx]->resv; + ww_mutex_lock_slow(&content_resv->lock, ctx); + goto retry; + } + + /* If we are here the function failed */ + ww_acquire_fini(ctx); + return err; +} + +static int dma_buf_lock_handle_release(struct inode *inode, struct file *file) +{ + dma_buf_lock_resource *resource; + + if (!is_dma_buf_lock_file(file)) + return -EINVAL; + + resource = file->private_data; +#if DMA_BUF_LOCK_DEBUG + printk("dma_buf_lock_handle_release\n"); +#endif + mutex_lock(&dma_buf_lock_mutex); + kref_put(&resource->refcount, dma_buf_lock_dounlock); + mutex_unlock(&dma_buf_lock_mutex); + + return 0; +} + +static unsigned int dma_buf_lock_handle_poll(struct file *file, + struct poll_table_struct *wait) +{ + dma_buf_lock_resource *resource; + unsigned int ret = 0; + + if (!is_dma_buf_lock_file(file)) + return POLLERR; + + resource = file->private_data; +#if DMA_BUF_LOCK_DEBUG + printk("dma_buf_lock_handle_poll\n"); +#endif + if (atomic_read(&resource->locked) == 1) { + /* Resources have been locked */ + ret = POLLIN | POLLRDNORM; + if (resource->exclusive) + ret |= POLLOUT | POLLWRNORM; + } + else + { + if (!poll_does_not_wait(wait)) + poll_wait(file, &resource->wait, wait); + } +#if DMA_BUF_LOCK_DEBUG + printk("dma_buf_lock_handle_poll : return %i\n", ret); +#endif + return ret; +} + +static const struct file_operations dma_buf_lock_handle_fops = { + .owner = THIS_MODULE, + .release = dma_buf_lock_handle_release, + .poll = dma_buf_lock_handle_poll, +}; + +/* + * is_dma_buf_lock_file - Check if struct file* is associated with dma_buf_lock + */ +static inline int is_dma_buf_lock_file(struct file *file) +{ + return file->f_op == &dma_buf_lock_handle_fops; +} + + + +/* + * Start requested lock. + * + * Allocates required memory, copies dma_buf_fd list from userspace, + * acquires related reservation objects, and starts the lock. + */ +static int dma_buf_lock_dolock(dma_buf_lock_k_request *request) +{ + dma_buf_lock_resource *resource; + struct ww_acquire_ctx ww_ctx; + int size; + int fd; + int i; + int ret; + + if (request->list_of_dma_buf_fds == NULL) + return -EINVAL; + if (request->count <= 0) + return -EINVAL; + if (request->count > DMA_BUF_LOCK_BUF_MAX) + return -EINVAL; + if (request->exclusive != DMA_BUF_LOCK_NONEXCLUSIVE && + request->exclusive != DMA_BUF_LOCK_EXCLUSIVE) + return -EINVAL; + + resource = kzalloc(sizeof(dma_buf_lock_resource), GFP_KERNEL); + if (resource == NULL) + return -ENOMEM; + + atomic_set(&resource->locked, 0); + kref_init(&resource->refcount); + INIT_LIST_HEAD(&resource->link); + INIT_WORK(&resource->work, dma_buf_lock_fence_work); + resource->count = request->count; + + /* Allocate space to store dma_buf_fds received from user space */ + size = request->count * sizeof(int); + resource->list_of_dma_buf_fds = kmalloc(size, GFP_KERNEL); + + if (resource->list_of_dma_buf_fds == NULL) { + kfree(resource); + return -ENOMEM; + } + + /* Allocate space to store dma_buf pointers associated with dma_buf_fds */ + size = sizeof(struct dma_buf *) * request->count; + resource->dma_bufs = kmalloc(size, GFP_KERNEL); + + if (resource->dma_bufs == NULL) { + kfree(resource->list_of_dma_buf_fds); + kfree(resource); + return -ENOMEM; + } + + /* Copy requested list of dma_buf_fds from user space */ + size = request->count * sizeof(int); + if (copy_from_user(resource->list_of_dma_buf_fds, + (void __user *)request->list_of_dma_buf_fds, + size) != 0) { + kfree(resource->list_of_dma_buf_fds); + kfree(resource->dma_bufs); + kfree(resource); + return -ENOMEM; + } +#if DMA_BUF_LOCK_DEBUG + for (i = 0; i < request->count; i++) + printk("dma_buf %i = %X\n", i, resource->list_of_dma_buf_fds[i]); +#endif + + /* Initialize the fence associated with dma_buf_lock resource */ + dma_buf_lock_fence_init(resource); + + INIT_LIST_HEAD(&resource->dma_fence_callbacks); + + atomic_set(&resource->fence_dep_count, DMA_BUF_LOCK_INIT_BIAS); + + /* Add resource to global list */ + mutex_lock(&dma_buf_lock_mutex); + + list_add(&resource->link, &dma_buf_lock_resource_list); + + mutex_unlock(&dma_buf_lock_mutex); + + for (i = 0; i < request->count; i++) + { + /* Convert fd into dma_buf structure */ + resource->dma_bufs[i] = dma_buf_get(resource->list_of_dma_buf_fds[i]); + + if (IS_ERR_VALUE(PTR_ERR(resource->dma_bufs[i]))) + { + mutex_lock(&dma_buf_lock_mutex); + kref_put(&resource->refcount, dma_buf_lock_dounlock); + mutex_unlock(&dma_buf_lock_mutex); + return -EINVAL; + } + + /*Check the reservation object associated with dma_buf */ + if (resource->dma_bufs[i]->resv == NULL) { + mutex_lock(&dma_buf_lock_mutex); + kref_put(&resource->refcount, dma_buf_lock_dounlock); + mutex_unlock(&dma_buf_lock_mutex); + return -EINVAL; + } +#if DMA_BUF_LOCK_DEBUG + printk(KERN_DEBUG "dma_buf_lock_dolock : dma_buf_fd %i dma_buf %p dma_fence reservation %p\n", + resource->list_of_dma_buf_fds[i], resource->dma_bufs[i], resource->dma_bufs[i]->resv); +#endif + } + + init_waitqueue_head(&resource->wait); + + kref_get(&resource->refcount); + + /* Create file descriptor associated with lock request */ + fd = anon_inode_getfd("dma_buf_lock", &dma_buf_lock_handle_fops, + (void *)resource, 0); + if (fd < 0) + { + mutex_lock(&dma_buf_lock_mutex); + kref_put(&resource->refcount, dma_buf_lock_dounlock); + kref_put(&resource->refcount, dma_buf_lock_dounlock); + mutex_unlock(&dma_buf_lock_mutex); + return fd; + } + + resource->exclusive = request->exclusive; + + /* Start locking process */ + ret = dma_buf_lock_acquire_fence_reservation(resource, &ww_ctx); + if (ret) { +#if DMA_BUF_LOCK_DEBUG + printk(KERN_DEBUG "dma_buf_lock_dolock : Error %d locking reservations.\n", ret); +#endif + put_unused_fd(fd); + mutex_lock(&dma_buf_lock_mutex); + kref_put(&resource->refcount, dma_buf_lock_dounlock); + kref_put(&resource->refcount, dma_buf_lock_dounlock); + mutex_unlock(&dma_buf_lock_mutex); + return ret; + } + + /* Take an extra reference for exclusive access, which will be dropped + * once the pre-existing fences attached to dma-buf resources, for which + * we have commited for exclusive access, are signaled. + * At a given time there can be only one exclusive fence attached to a + * reservation object, so the new exclusive fence replaces the original + * fence and the future sync is done against the new fence which is + * supposed to be signaled only after the original fence was signaled. + * If the new exclusive fence is signaled prematurely then the resources + * would become available for new access while they are already being + * written to by the original owner. + */ + if (resource->exclusive) + kref_get(&resource->refcount); + + for (i = 0; i < request->count; i++) { +#if (KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE) + struct reservation_object *resv = resource->dma_bufs[i]->resv; +#else + struct dma_resv *resv = resource->dma_bufs[i]->resv; +#endif + if (!test_bit(i, &resource->exclusive)) { + +#if (KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE) + ret = reservation_object_reserve_shared(resv); +#else + ret = dma_resv_reserve_shared(resv, 0); +#endif + if (ret) { +#if DMA_BUF_LOCK_DEBUG + printk(KERN_DEBUG "dma_buf_lock_dolock : Error %d reserving space for shared fence.\n", ret); +#endif + break; + } + + ret = dma_buf_lock_add_fence_reservation_callback(resource, + resv, + false); + if (ret) { +#if DMA_BUF_LOCK_DEBUG + printk(KERN_DEBUG "dma_buf_lock_dolock : Error %d adding reservation to callback.\n", ret); +#endif + break; + } + +#if (KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE) + reservation_object_add_shared_fence(resv, &resource->fence); +#else + dma_resv_add_shared_fence(resv, &resource->fence); +#endif + } else { + ret = dma_buf_lock_add_fence_reservation_callback(resource, + resv, + true); + if (ret) { +#if DMA_BUF_LOCK_DEBUG + printk(KERN_DEBUG "dma_buf_lock_dolock : Error %d adding reservation to callback.\n", ret); +#endif + break; + } + +#if (KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE) + reservation_object_add_excl_fence(resv, &resource->fence); +#else + dma_resv_add_excl_fence(resv, &resource->fence); +#endif + } + } + + dma_buf_lock_release_fence_reservation(resource, &ww_ctx); + + /* Test if the callbacks were already triggered */ + if (!atomic_sub_return(DMA_BUF_LOCK_INIT_BIAS, &resource->fence_dep_count)) { + atomic_set(&resource->locked, 1); + + /* Drop the extra reference taken for exclusive access */ + if (resource->exclusive) + dma_buf_lock_fence_work(&resource->work); + } + + if (IS_ERR_VALUE((unsigned long)ret)) + { + put_unused_fd(fd); + + mutex_lock(&dma_buf_lock_mutex); + kref_put(&resource->refcount, dma_buf_lock_dounlock); + kref_put(&resource->refcount, dma_buf_lock_dounlock); + mutex_unlock(&dma_buf_lock_mutex); + + return ret; + } + +#if DMA_BUF_LOCK_DEBUG + printk("dma_buf_lock_dolock : complete\n"); +#endif + mutex_lock(&dma_buf_lock_mutex); + kref_put(&resource->refcount, dma_buf_lock_dounlock); + mutex_unlock(&dma_buf_lock_mutex); + + return fd; +} + +static void dma_buf_lock_dounlock(struct kref *ref) +{ + int i; + dma_buf_lock_resource *resource = container_of(ref, dma_buf_lock_resource, refcount); + + atomic_set(&resource->locked, 0); + + /* Signal the resource's fence. */ + dma_fence_signal(&resource->fence); + + dma_buf_lock_fence_free_callbacks(resource); + + list_del(&resource->link); + + for (i = 0; i < resource->count; i++) + { + if (resource->dma_bufs[i]) + dma_buf_put(resource->dma_bufs[i]); + } + + kfree(resource->dma_bufs); + kfree(resource->list_of_dma_buf_fds); + dma_fence_put(&resource->fence); +} + +static int __init dma_buf_lock_init(void) +{ + int err; +#if DMA_BUF_LOCK_DEBUG + printk("dma_buf_lock_init\n"); +#endif + err = alloc_chrdev_region(&dma_buf_lock_dev, 0, 1, dma_buf_lock_dev_name); + + if (err == 0) { + cdev_init(&dma_buf_lock_cdev, &dma_buf_lock_fops); + + err = cdev_add(&dma_buf_lock_cdev, dma_buf_lock_dev, 1); + + if (err == 0) { + dma_buf_lock_class = class_create(THIS_MODULE, dma_buf_lock_dev_name); + if (IS_ERR(dma_buf_lock_class)) + err = PTR_ERR(dma_buf_lock_class); + else + { + struct device *mdev; + mdev = device_create(dma_buf_lock_class, NULL, dma_buf_lock_dev, NULL, dma_buf_lock_dev_name); + if (!IS_ERR(mdev)) + return 0; + + err = PTR_ERR(mdev); + class_destroy(dma_buf_lock_class); + } + cdev_del(&dma_buf_lock_cdev); + } + + unregister_chrdev_region(dma_buf_lock_dev, 1); + } +#if DMA_BUF_LOCK_DEBUG + printk("dma_buf_lock_init failed\n"); +#endif + return err; +} + +static void __exit dma_buf_lock_exit(void) +{ +#if DMA_BUF_LOCK_DEBUG + printk("dma_buf_lock_exit\n"); +#endif + + /* Unlock all outstanding references */ + while (1) + { + mutex_lock(&dma_buf_lock_mutex); + if (list_empty(&dma_buf_lock_resource_list)) + { + mutex_unlock(&dma_buf_lock_mutex); + break; + } + else + { + dma_buf_lock_resource *resource = list_entry(dma_buf_lock_resource_list.next, + dma_buf_lock_resource, link); + kref_put(&resource->refcount, dma_buf_lock_dounlock); + mutex_unlock(&dma_buf_lock_mutex); + } + } + + device_destroy(dma_buf_lock_class, dma_buf_lock_dev); + + class_destroy(dma_buf_lock_class); + + cdev_del(&dma_buf_lock_cdev); + + unregister_chrdev_region(dma_buf_lock_dev, 1); +} + +#ifdef HAVE_UNLOCKED_IOCTL +static long dma_buf_lock_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +#else +static int dma_buf_lock_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) +#endif +{ + dma_buf_lock_k_request request; + int size = _IOC_SIZE(cmd); + + if (_IOC_TYPE(cmd) != DMA_BUF_LOCK_IOC_MAGIC) + return -ENOTTY; + if ((_IOC_NR(cmd) < DMA_BUF_LOCK_IOC_MINNR) || (_IOC_NR(cmd) > DMA_BUF_LOCK_IOC_MAXNR)) + return -ENOTTY; + + switch (cmd) + { + case DMA_BUF_LOCK_FUNC_LOCK_ASYNC: + if (size != sizeof(dma_buf_lock_k_request)) + return -ENOTTY; + if (copy_from_user(&request, (void __user *)arg, size)) + return -EFAULT; +#if DMA_BUF_LOCK_DEBUG + printk("DMA_BUF_LOCK_FUNC_LOCK_ASYNC - %i\n", request.count); +#endif + return dma_buf_lock_dolock(&request); + } + + return -ENOTTY; +} + +module_init(dma_buf_lock_init); +module_exit(dma_buf_lock_exit); + +MODULE_LICENSE("GPL"); + diff --git a/drivers/base/arm/dma_buf_lock/src/dma_buf_lock.h b/drivers/base/arm/dma_buf_lock/src/dma_buf_lock.h new file mode 100644 index 000000000000..104af1f20503 --- /dev/null +++ b/drivers/base/arm/dma_buf_lock/src/dma_buf_lock.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * + * (C) COPYRIGHT 2012, 2020-2021 ARM Limited. All rights reserved. + * + * This program is free software and is provided to you under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation, and any use by you of this program is subject to the terms + * of such GNU license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you can access it online at + * http://www.gnu.org/licenses/gpl-2.0.html. + * + */ + +#ifndef _DMA_BUF_LOCK_H +#define _DMA_BUF_LOCK_H + +typedef enum dma_buf_lock_exclusive +{ + DMA_BUF_LOCK_NONEXCLUSIVE = 0, + DMA_BUF_LOCK_EXCLUSIVE = -1 +} dma_buf_lock_exclusive; + +typedef struct dma_buf_lock_k_request +{ + int count; + int *list_of_dma_buf_fds; + int timeout; + dma_buf_lock_exclusive exclusive; +} dma_buf_lock_k_request; + +#define DMA_BUF_LOCK_IOC_MAGIC '~' + +#define DMA_BUF_LOCK_FUNC_LOCK_ASYNC _IOW(DMA_BUF_LOCK_IOC_MAGIC, 11, dma_buf_lock_k_request) + +#define DMA_BUF_LOCK_IOC_MINNR 11 +#define DMA_BUF_LOCK_IOC_MAXNR 11 + +#endif /* _DMA_BUF_LOCK_H */ diff --git a/drivers/base/arm/dma_buf_test_exporter/Kbuild b/drivers/base/arm/dma_buf_test_exporter/Kbuild new file mode 100644 index 000000000000..0e20cb44543e --- /dev/null +++ b/drivers/base/arm/dma_buf_test_exporter/Kbuild @@ -0,0 +1,23 @@ +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note +# +# (C) COPYRIGHT 2012, 2020-2021 ARM Limited. All rights reserved. +# +# This program is free software and is provided to you under the terms of the +# GNU General Public License version 2 as published by the Free Software +# Foundation, and any use by you of this program is subject to the terms +# of such GNU license. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you can access it online at +# http://www.gnu.org/licenses/gpl-2.0.html. +# +# + +ifeq ($(CONFIG_DMA_SHARED_BUFFER_TEST_EXPORTER), y) +obj-m += dma-buf-test-exporter.o +endif diff --git a/drivers/base/arm/dma_buf_test_exporter/build.bp b/drivers/base/arm/dma_buf_test_exporter/build.bp new file mode 100644 index 000000000000..a49fb81d6665 --- /dev/null +++ b/drivers/base/arm/dma_buf_test_exporter/build.bp @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * + * (C) COPYRIGHT 2017, 2020-2021 ARM Limited. All rights reserved. + * + * This program is free software and is provided to you under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation, and any use by you of this program is subject to the terms + * of such GNU license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you can access it online at + * http://www.gnu.org/licenses/gpl-2.0.html. + * + */ + +bob_kernel_module { + name: "dma-buf-test-exporter", + defaults: [ + "kernel_defaults" + ], + srcs: [ + "Kbuild", + "dma-buf-test-exporter.c", + ], + enabled: false, + dma_shared_buffer_test_exporter: { + kbuild_options: ["CONFIG_DMA_SHARED_BUFFER_TEST_EXPORTER=y"], + enabled: true, + }, +} diff --git a/drivers/base/arm/dma_buf_test_exporter/dma-buf-test-exporter.c b/drivers/base/arm/dma_buf_test_exporter/dma-buf-test-exporter.c new file mode 100644 index 000000000000..ccf73ccbcc3f --- /dev/null +++ b/drivers/base/arm/dma_buf_test_exporter/dma-buf-test-exporter.c @@ -0,0 +1,824 @@ +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note +/* + * + * (C) COPYRIGHT 2012-2021 ARM Limited. All rights reserved. + * + * This program is free software and is provided to you under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation, and any use by you of this program is subject to the terms + * of such GNU license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you can access it online at + * http://www.gnu.org/licenses/gpl-2.0.html. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if (KERNEL_VERSION(4, 8, 0) > LINUX_VERSION_CODE) +#include +#endif +#include + +/* Maximum size allowed in a single DMA_BUF_TE_ALLOC call */ +#define DMA_BUF_TE_ALLOC_MAX_SIZE ((8ull << 30) >> PAGE_SHIFT) /* 8 GB */ + +/* Since kernel version 5.0 CONFIG_ARCH_NO_SG_CHAIN replaced CONFIG_ARCH_HAS_SG_CHAIN */ +#if KERNEL_VERSION(5, 0, 0) > LINUX_VERSION_CODE +#if (!defined(ARCH_HAS_SG_CHAIN) && !defined(CONFIG_ARCH_HAS_SG_CHAIN)) +#define NO_SG_CHAIN +#endif +#elif defined(CONFIG_ARCH_NO_SG_CHAIN) +#define NO_SG_CHAIN +#endif + +struct dma_buf_te_alloc { + /* the real alloc */ + size_t nr_pages; + struct page **pages; + + /* the debug usage tracking */ + int nr_attached_devices; + int nr_device_mappings; + int nr_cpu_mappings; + + /* failure simulation */ + int fail_attach; + int fail_map; + int fail_mmap; + + bool contiguous; + dma_addr_t contig_dma_addr; + void *contig_cpu_addr; +}; + +struct dma_buf_te_attachment { + struct sg_table *sg; + bool attachment_mapped; +}; + +static struct miscdevice te_device; + +#if (KERNEL_VERSION(4, 19, 0) > LINUX_VERSION_CODE) +static int dma_buf_te_attach(struct dma_buf *buf, struct device *dev, struct dma_buf_attachment *attachment) +#else +static int dma_buf_te_attach(struct dma_buf *buf, struct dma_buf_attachment *attachment) +#endif +{ + struct dma_buf_te_alloc *alloc; + alloc = buf->priv; + + if (alloc->fail_attach) + return -EFAULT; + + attachment->priv = kzalloc(sizeof(struct dma_buf_te_attachment), GFP_KERNEL); + if (!attachment->priv) + return -ENOMEM; + + /* dma_buf is externally locked during call */ + alloc->nr_attached_devices++; + return 0; +} + +static void dma_buf_te_detach(struct dma_buf *buf, struct dma_buf_attachment *attachment) +{ + struct dma_buf_te_alloc *alloc = buf->priv; + struct dma_buf_te_attachment *pa = attachment->priv; + + /* dma_buf is externally locked during call */ + + WARN(pa->attachment_mapped, "WARNING: dma-buf-test-exporter detected detach with open device mappings"); + + alloc->nr_attached_devices--; + + kfree(pa); +} + +static struct sg_table *dma_buf_te_map(struct dma_buf_attachment *attachment, enum dma_data_direction direction) +{ + struct sg_table *sg; + struct scatterlist *iter; + struct dma_buf_te_alloc *alloc; + struct dma_buf_te_attachment *pa = attachment->priv; + size_t i; + int ret; + + alloc = attachment->dmabuf->priv; + + if (alloc->fail_map) + return ERR_PTR(-ENOMEM); + + if (WARN(pa->attachment_mapped, + "WARNING: Attempted to map already mapped attachment.")) + return ERR_PTR(-EBUSY); + +#ifdef NO_SG_CHAIN + /* if the ARCH can't chain we can't have allocs larger than a single sg can hold */ + if (alloc->nr_pages > SG_MAX_SINGLE_ALLOC) + return ERR_PTR(-EINVAL); +#endif /* NO_SG_CHAIN */ + + sg = kmalloc(sizeof(struct sg_table), GFP_KERNEL); + if (!sg) + return ERR_PTR(-ENOMEM); + + /* from here we access the allocation object, so lock the dmabuf pointing to it */ + mutex_lock(&attachment->dmabuf->lock); + + if (alloc->contiguous) + ret = sg_alloc_table(sg, 1, GFP_KERNEL); + else + ret = sg_alloc_table(sg, alloc->nr_pages, GFP_KERNEL); + if (ret) { + mutex_unlock(&attachment->dmabuf->lock); + kfree(sg); + return ERR_PTR(ret); + } + + if (alloc->contiguous) { + sg_dma_len(sg->sgl) = alloc->nr_pages * PAGE_SIZE; + sg_set_page(sg->sgl, pfn_to_page(PFN_DOWN(alloc->contig_dma_addr)), alloc->nr_pages * PAGE_SIZE, 0); + sg_dma_address(sg->sgl) = alloc->contig_dma_addr; + } else { + for_each_sg(sg->sgl, iter, alloc->nr_pages, i) + sg_set_page(iter, alloc->pages[i], PAGE_SIZE, 0); + } + + if (!dma_map_sg(attachment->dev, sg->sgl, sg->nents, direction)) { + mutex_unlock(&attachment->dmabuf->lock); + sg_free_table(sg); + kfree(sg); + return ERR_PTR(-ENOMEM); + } + + alloc->nr_device_mappings++; + pa->attachment_mapped = true; + pa->sg = sg; + mutex_unlock(&attachment->dmabuf->lock); + return sg; +} + +static void dma_buf_te_unmap(struct dma_buf_attachment *attachment, + struct sg_table *sg, enum dma_data_direction direction) +{ + struct dma_buf_te_alloc *alloc; + struct dma_buf_te_attachment *pa = attachment->priv; + + alloc = attachment->dmabuf->priv; + + mutex_lock(&attachment->dmabuf->lock); + + WARN(!pa->attachment_mapped, "WARNING: Unmatched unmap of attachment."); + + alloc->nr_device_mappings--; + pa->attachment_mapped = false; + pa->sg = NULL; + mutex_unlock(&attachment->dmabuf->lock); + + dma_unmap_sg(attachment->dev, sg->sgl, sg->nents, direction); + sg_free_table(sg); + kfree(sg); +} + +static void dma_buf_te_release(struct dma_buf *buf) +{ + size_t i; + struct dma_buf_te_alloc *alloc; + alloc = buf->priv; + /* no need for locking */ + + if (alloc->contiguous) { +#if (KERNEL_VERSION(4, 8, 0) <= LINUX_VERSION_CODE) + dma_free_attrs(te_device.this_device, + alloc->nr_pages * PAGE_SIZE, + alloc->contig_cpu_addr, + alloc->contig_dma_addr, + DMA_ATTR_WRITE_COMBINE); +#else + DEFINE_DMA_ATTRS(attrs); + + dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); + dma_free_attrs(te_device.this_device, + alloc->nr_pages * PAGE_SIZE, + alloc->contig_cpu_addr, alloc->contig_dma_addr, &attrs); +#endif + } else { + for (i = 0; i < alloc->nr_pages; i++) + __free_page(alloc->pages[i]); + } +#if (KERNEL_VERSION(4, 12, 0) <= LINUX_VERSION_CODE) + kvfree(alloc->pages); +#else + kfree(alloc->pages); +#endif + kfree(alloc); +} + +static int dma_buf_te_sync(struct dma_buf *dmabuf, + enum dma_data_direction direction, + bool start_cpu_access) +{ + struct dma_buf_attachment *attachment; + + mutex_lock(&dmabuf->lock); + + list_for_each_entry(attachment, &dmabuf->attachments, node) { + struct dma_buf_te_attachment *pa = attachment->priv; + struct sg_table *sg = pa->sg; + if (!sg) { + dev_dbg(te_device.this_device, "no mapping for device %s\n", dev_name(attachment->dev)); + continue; + } + + if (start_cpu_access) { + dev_dbg(te_device.this_device, "sync cpu with device %s\n", dev_name(attachment->dev)); + + dma_sync_sg_for_cpu(attachment->dev, sg->sgl, sg->nents, direction); + } else { + dev_dbg(te_device.this_device, "sync device %s with cpu\n", dev_name(attachment->dev)); + + dma_sync_sg_for_device(attachment->dev, sg->sgl, sg->nents, direction); + } + } + + mutex_unlock(&dmabuf->lock); + return 0; +} + +#if (KERNEL_VERSION(4, 6, 0) <= LINUX_VERSION_CODE) +static int dma_buf_te_begin_cpu_access(struct dma_buf *dmabuf, + enum dma_data_direction direction) +#else +static int dma_buf_te_begin_cpu_access(struct dma_buf *dmabuf, size_t start, + size_t len, + enum dma_data_direction direction) +#endif +{ + return dma_buf_te_sync(dmabuf, direction, true); +} + +#if (KERNEL_VERSION(4, 6, 0) <= LINUX_VERSION_CODE) +static int dma_buf_te_end_cpu_access(struct dma_buf *dmabuf, + enum dma_data_direction direction) +{ + return dma_buf_te_sync(dmabuf, direction, false); +} +#else +static void dma_buf_te_end_cpu_access(struct dma_buf *dmabuf, size_t start, + size_t len, + enum dma_data_direction direction) +{ + dma_buf_te_sync(dmabuf, direction, false); +} +#endif + +static void dma_buf_te_mmap_open(struct vm_area_struct *vma) +{ + struct dma_buf *dma_buf; + struct dma_buf_te_alloc *alloc; + dma_buf = vma->vm_private_data; + alloc = dma_buf->priv; + + mutex_lock(&dma_buf->lock); + alloc->nr_cpu_mappings++; + mutex_unlock(&dma_buf->lock); +} + +static void dma_buf_te_mmap_close(struct vm_area_struct *vma) +{ + struct dma_buf *dma_buf; + struct dma_buf_te_alloc *alloc; + dma_buf = vma->vm_private_data; + alloc = dma_buf->priv; + + BUG_ON(alloc->nr_cpu_mappings <= 0); + mutex_lock(&dma_buf->lock); + alloc->nr_cpu_mappings--; + mutex_unlock(&dma_buf->lock); +} + +#if KERNEL_VERSION(4, 11, 0) > LINUX_VERSION_CODE +static int dma_buf_te_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) +#elif KERNEL_VERSION(5, 1, 0) > LINUX_VERSION_CODE +static int dma_buf_te_mmap_fault(struct vm_fault *vmf) +#else +static vm_fault_t dma_buf_te_mmap_fault(struct vm_fault *vmf) +#endif +{ + struct dma_buf_te_alloc *alloc; + struct dma_buf *dmabuf; + struct page *pageptr; + +#if KERNEL_VERSION(4, 11, 0) > LINUX_VERSION_CODE + dmabuf = vma->vm_private_data; +#else + dmabuf = vmf->vma->vm_private_data; +#endif + alloc = dmabuf->priv; + + if (vmf->pgoff > alloc->nr_pages) + return VM_FAULT_SIGBUS; + + pageptr = alloc->pages[vmf->pgoff]; + + BUG_ON(!pageptr); + + get_page(pageptr); + vmf->page = pageptr; + + return 0; +} + +struct vm_operations_struct dma_buf_te_vm_ops = { + .open = dma_buf_te_mmap_open, + .close = dma_buf_te_mmap_close, + .fault = dma_buf_te_mmap_fault +}; + +static int dma_buf_te_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma) +{ + struct dma_buf_te_alloc *alloc; + alloc = dmabuf->priv; + + if (alloc->fail_mmap) + return -ENOMEM; + + vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP; + vma->vm_ops = &dma_buf_te_vm_ops; + vma->vm_private_data = dmabuf; + + /* we fault in the pages on access */ + + /* call open to do the ref-counting */ + dma_buf_te_vm_ops.open(vma); + + return 0; +} + +#if KERNEL_VERSION(4, 19, 0) > LINUX_VERSION_CODE +static void *dma_buf_te_kmap_atomic(struct dma_buf *buf, unsigned long page_num) +{ + /* IGNORE */ + return NULL; +} +#endif + +static void *dma_buf_te_kmap(struct dma_buf *buf, unsigned long page_num) +{ + struct dma_buf_te_alloc *alloc; + + alloc = buf->priv; + if (page_num >= alloc->nr_pages) + return NULL; + + return kmap(alloc->pages[page_num]); +} +static void dma_buf_te_kunmap(struct dma_buf *buf, + unsigned long page_num, void *addr) +{ + struct dma_buf_te_alloc *alloc; + + alloc = buf->priv; + if (page_num >= alloc->nr_pages) + return; + + kunmap(alloc->pages[page_num]); + return; +} + +static struct dma_buf_ops dma_buf_te_ops = { + /* real handlers */ + .attach = dma_buf_te_attach, + .detach = dma_buf_te_detach, + .map_dma_buf = dma_buf_te_map, + .unmap_dma_buf = dma_buf_te_unmap, + .release = dma_buf_te_release, + .mmap = dma_buf_te_mmap, + .begin_cpu_access = dma_buf_te_begin_cpu_access, + .end_cpu_access = dma_buf_te_end_cpu_access, +#if KERNEL_VERSION(4, 12, 0) > LINUX_VERSION_CODE + .kmap = dma_buf_te_kmap, + .kunmap = dma_buf_te_kunmap, + + /* nop handlers for mandatory functions we ignore */ + .kmap_atomic = dma_buf_te_kmap_atomic +#else +#if KERNEL_VERSION(5, 6, 0) > LINUX_VERSION_CODE + .map = dma_buf_te_kmap, + .unmap = dma_buf_te_kunmap, +#endif + +#if KERNEL_VERSION(4, 19, 0) > LINUX_VERSION_CODE + /* nop handlers for mandatory functions we ignore */ + .map_atomic = dma_buf_te_kmap_atomic +#endif +#endif +}; + +static int do_dma_buf_te_ioctl_version(struct dma_buf_te_ioctl_version __user *buf) +{ + struct dma_buf_te_ioctl_version v; + + if (copy_from_user(&v, buf, sizeof(v))) + return -EFAULT; + + if (v.op != DMA_BUF_TE_ENQ) + return -EFAULT; + + v.op = DMA_BUF_TE_ACK; + v.major = DMA_BUF_TE_VER_MAJOR; + v.minor = DMA_BUF_TE_VER_MINOR; + + if (copy_to_user(buf, &v, sizeof(v))) + return -EFAULT; + else + return 0; +} + +static int do_dma_buf_te_ioctl_alloc(struct dma_buf_te_ioctl_alloc __user *buf, bool contiguous) +{ + struct dma_buf_te_ioctl_alloc alloc_req; + struct dma_buf_te_alloc *alloc; + struct dma_buf *dma_buf; + size_t i = 0; + size_t max_nr_pages = DMA_BUF_TE_ALLOC_MAX_SIZE; + int fd; + + if (copy_from_user(&alloc_req, buf, sizeof(alloc_req))) { + dev_err(te_device.this_device, "%s: couldn't get user data", __func__); + goto no_input; + } + + if (!alloc_req.size) { + dev_err(te_device.this_device, "%s: no size specified", __func__); + goto invalid_size; + } + +#ifdef NO_SG_CHAIN + /* Whilst it is possible to allocate larger buffer, we won't be able to + * map it during actual usage (mmap() still succeeds). We fail here so + * userspace code can deal with it early than having driver failure + * later on. + */ + if (max_nr_pages > SG_MAX_SINGLE_ALLOC) + max_nr_pages = SG_MAX_SINGLE_ALLOC; +#endif /* NO_SG_CHAIN */ + + if (alloc_req.size > max_nr_pages) { + dev_err(te_device.this_device, "%s: buffer size of %llu pages exceeded the mapping limit of %zu pages", + __func__, alloc_req.size, max_nr_pages); + goto invalid_size; + } + + alloc = kzalloc(sizeof(struct dma_buf_te_alloc), GFP_KERNEL); + if (alloc == NULL) { + dev_err(te_device.this_device, "%s: couldn't alloc object", __func__); + goto no_alloc_object; + } + + alloc->nr_pages = alloc_req.size; + alloc->contiguous = contiguous; + +#if (KERNEL_VERSION(4, 12, 0) <= LINUX_VERSION_CODE) + alloc->pages = kvzalloc(sizeof(struct page *) * alloc->nr_pages, GFP_KERNEL); +#else + alloc->pages = kzalloc(sizeof(struct page *) * alloc->nr_pages, GFP_KERNEL); +#endif + + if (!alloc->pages) { + dev_err(te_device.this_device, + "%s: couldn't alloc %zu page structures", + __func__, alloc->nr_pages); + goto free_alloc_object; + } + + if (contiguous) { + dma_addr_t dma_aux; + +#if (KERNEL_VERSION(4, 8, 0) <= LINUX_VERSION_CODE) + alloc->contig_cpu_addr = dma_alloc_attrs(te_device.this_device, + alloc->nr_pages * PAGE_SIZE, + &alloc->contig_dma_addr, + GFP_KERNEL | __GFP_ZERO, + DMA_ATTR_WRITE_COMBINE); +#else + DEFINE_DMA_ATTRS(attrs); + + dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); + alloc->contig_cpu_addr = dma_alloc_attrs(te_device.this_device, + alloc->nr_pages * PAGE_SIZE, + &alloc->contig_dma_addr, + GFP_KERNEL | __GFP_ZERO, &attrs); +#endif + if (!alloc->contig_cpu_addr) { + dev_err(te_device.this_device, "%s: couldn't alloc contiguous buffer %zu pages", + __func__, alloc->nr_pages); + goto free_page_struct; + } + dma_aux = alloc->contig_dma_addr; + for (i = 0; i < alloc->nr_pages; i++) { + alloc->pages[i] = pfn_to_page(PFN_DOWN(dma_aux)); + dma_aux += PAGE_SIZE; + } + } else { + for (i = 0; i < alloc->nr_pages; i++) { + alloc->pages[i] = alloc_page(GFP_KERNEL | __GFP_ZERO); + if (alloc->pages[i] == NULL) { + dev_err(te_device.this_device, "%s: couldn't alloc page", __func__); + goto no_page; + } + } + } + + /* alloc ready, let's export it */ + { + struct dma_buf_export_info export_info = { + .exp_name = "dma_buf_te", + .owner = THIS_MODULE, + .ops = &dma_buf_te_ops, + .size = alloc->nr_pages << PAGE_SHIFT, + .flags = O_CLOEXEC | O_RDWR, + .priv = alloc, + }; + + dma_buf = dma_buf_export(&export_info); + } + + if (IS_ERR_OR_NULL(dma_buf)) { + dev_err(te_device.this_device, "%s: couldn't export dma_buf", __func__); + goto no_export; + } + + /* get fd for buf */ + fd = dma_buf_fd(dma_buf, O_CLOEXEC); + + if (fd < 0) { + dev_err(te_device.this_device, "%s: couldn't get fd from dma_buf", __func__); + goto no_fd; + } + + return fd; + +no_fd: + dma_buf_put(dma_buf); +no_export: + /* i still valid */ +no_page: + if (contiguous) { +#if (KERNEL_VERSION(4, 8, 0) <= LINUX_VERSION_CODE) + dma_free_attrs(te_device.this_device, + alloc->nr_pages * PAGE_SIZE, + alloc->contig_cpu_addr, + alloc->contig_dma_addr, + DMA_ATTR_WRITE_COMBINE); +#else + DEFINE_DMA_ATTRS(attrs); + + dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); + dma_free_attrs(te_device.this_device, + alloc->nr_pages * PAGE_SIZE, + alloc->contig_cpu_addr, alloc->contig_dma_addr, &attrs); +#endif + } else { + while (i-- > 0) + __free_page(alloc->pages[i]); + } +free_page_struct: +#if (KERNEL_VERSION(4, 12, 0) <= LINUX_VERSION_CODE) + kvfree(alloc->pages); +#else + kfree(alloc->pages); +#endif +free_alloc_object: + kfree(alloc); +no_alloc_object: +invalid_size: +no_input: + return -EFAULT; +} + +static int do_dma_buf_te_ioctl_status(struct dma_buf_te_ioctl_status __user *arg) +{ + struct dma_buf_te_ioctl_status status; + struct dma_buf *dmabuf; + struct dma_buf_te_alloc *alloc; + int res = -EINVAL; + + if (copy_from_user(&status, arg, sizeof(status))) + return -EFAULT; + + dmabuf = dma_buf_get(status.fd); + if (IS_ERR_OR_NULL(dmabuf)) + return -EINVAL; + + /* verify it's one of ours */ + if (dmabuf->ops != &dma_buf_te_ops) + goto err_have_dmabuf; + + /* ours, get the current status */ + alloc = dmabuf->priv; + + /* lock while reading status to take a snapshot */ + mutex_lock(&dmabuf->lock); + status.attached_devices = alloc->nr_attached_devices; + status.device_mappings = alloc->nr_device_mappings; + status.cpu_mappings = alloc->nr_cpu_mappings; + mutex_unlock(&dmabuf->lock); + + if (copy_to_user(arg, &status, sizeof(status))) + goto err_have_dmabuf; + + /* All OK */ + res = 0; + +err_have_dmabuf: + dma_buf_put(dmabuf); + return res; +} + +static int do_dma_buf_te_ioctl_set_failing(struct dma_buf_te_ioctl_set_failing __user *arg) +{ + struct dma_buf *dmabuf; + struct dma_buf_te_ioctl_set_failing f; + struct dma_buf_te_alloc *alloc; + int res = -EINVAL; + + if (copy_from_user(&f, arg, sizeof(f))) + return -EFAULT; + + dmabuf = dma_buf_get(f.fd); + if (IS_ERR_OR_NULL(dmabuf)) + return -EINVAL; + + /* verify it's one of ours */ + if (dmabuf->ops != &dma_buf_te_ops) + goto err_have_dmabuf; + + /* ours, set the fail modes */ + alloc = dmabuf->priv; + /* lock to set the fail modes atomically */ + mutex_lock(&dmabuf->lock); + alloc->fail_attach = f.fail_attach; + alloc->fail_map = f.fail_map; + alloc->fail_mmap = f.fail_mmap; + mutex_unlock(&dmabuf->lock); + + /* success */ + res = 0; + +err_have_dmabuf: + dma_buf_put(dmabuf); + return res; +} + +static u32 dma_te_buf_fill(struct dma_buf *dma_buf, unsigned int value) +{ + struct dma_buf_attachment *attachment; + struct sg_table *sgt; + struct scatterlist *sg; + unsigned int count; + unsigned int offset = 0; + int ret = 0; + size_t i; + + attachment = dma_buf_attach(dma_buf, te_device.this_device); + if (IS_ERR_OR_NULL(attachment)) + return -EBUSY; + + sgt = dma_buf_map_attachment(attachment, DMA_BIDIRECTIONAL); + if (IS_ERR_OR_NULL(sgt)) { + ret = PTR_ERR(sgt); + goto no_import; + } + + ret = dma_buf_begin_cpu_access(dma_buf, +#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE + 0, dma_buf->size, +#endif + DMA_BIDIRECTIONAL); + if (ret) + goto no_cpu_access; + + for_each_sg(sgt->sgl, sg, sgt->nents, count) { + for (i = 0; i < sg_dma_len(sg); i = i + PAGE_SIZE) { + void *addr = NULL; +#if KERNEL_VERSION(5, 6, 0) <= LINUX_VERSION_CODE + addr = dma_buf_te_kmap(dma_buf, i >> PAGE_SHIFT); +#else + addr = dma_buf_kmap(dma_buf, i >> PAGE_SHIFT); +#endif + if (!addr) { + ret = -EPERM; + goto no_kmap; + } + memset(addr, value, PAGE_SIZE); +#if KERNEL_VERSION(5, 6, 0) <= LINUX_VERSION_CODE + dma_buf_te_kunmap(dma_buf, i >> PAGE_SHIFT, addr); +#else + dma_buf_kunmap(dma_buf, i >> PAGE_SHIFT, addr); +#endif + } + offset += sg_dma_len(sg); + } + +no_kmap: + dma_buf_end_cpu_access(dma_buf, +#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE + 0, dma_buf->size, +#endif + DMA_BIDIRECTIONAL); +no_cpu_access: + dma_buf_unmap_attachment(attachment, sgt, DMA_BIDIRECTIONAL); +no_import: + dma_buf_detach(dma_buf, attachment); + return ret; +} + +static int do_dma_buf_te_ioctl_fill(struct dma_buf_te_ioctl_fill __user *arg) +{ + + struct dma_buf *dmabuf; + struct dma_buf_te_ioctl_fill f; + int ret; + + if (copy_from_user(&f, arg, sizeof(f))) + return -EFAULT; + + dmabuf = dma_buf_get(f.fd); + if (IS_ERR_OR_NULL(dmabuf)) + return -EINVAL; + + ret = dma_te_buf_fill(dmabuf, f.value); + dma_buf_put(dmabuf); + + return ret; +} + +static long dma_buf_te_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + switch (cmd) { + case DMA_BUF_TE_VERSION: + return do_dma_buf_te_ioctl_version((struct dma_buf_te_ioctl_version __user *)arg); + case DMA_BUF_TE_ALLOC: + return do_dma_buf_te_ioctl_alloc((struct dma_buf_te_ioctl_alloc __user *)arg, false); + case DMA_BUF_TE_ALLOC_CONT: + return do_dma_buf_te_ioctl_alloc((struct dma_buf_te_ioctl_alloc __user *)arg, true); + case DMA_BUF_TE_QUERY: + return do_dma_buf_te_ioctl_status((struct dma_buf_te_ioctl_status __user *)arg); + case DMA_BUF_TE_SET_FAILING: + return do_dma_buf_te_ioctl_set_failing((struct dma_buf_te_ioctl_set_failing __user *)arg); + case DMA_BUF_TE_FILL: + return do_dma_buf_te_ioctl_fill((struct dma_buf_te_ioctl_fill __user *)arg); + default: + return -ENOTTY; + } +} + +static const struct file_operations dma_buf_te_fops = { + .owner = THIS_MODULE, + .unlocked_ioctl = dma_buf_te_ioctl, + .compat_ioctl = dma_buf_te_ioctl, +}; + +static int __init dma_buf_te_init(void) +{ + int res; + te_device.minor = MISC_DYNAMIC_MINOR; + te_device.name = "dma_buf_te"; + te_device.fops = &dma_buf_te_fops; + + res = misc_register(&te_device); + if (res) { + printk(KERN_WARNING"Misc device registration failed of 'dma_buf_te'\n"); + return res; + } + te_device.this_device->coherent_dma_mask = DMA_BIT_MASK(32); + + dev_info(te_device.this_device, "dma_buf_te ready\n"); + return 0; + +} + +static void __exit dma_buf_te_exit(void) +{ + misc_deregister(&te_device); +} + +module_init(dma_buf_te_init); +module_exit(dma_buf_te_exit); +MODULE_LICENSE("GPL"); diff --git a/drivers/base/arm/memory_group_manager/Kbuild b/drivers/base/arm/memory_group_manager/Kbuild index 1b0f8b07b399..99ce311a7aad 100644 --- a/drivers/base/arm/memory_group_manager/Kbuild +++ b/drivers/base/arm/memory_group_manager/Kbuild @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # # (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. # @@ -18,4 +18,6 @@ # # -obj-$(CONFIG_MALI_MEMORY_GROUP_MANAGER) := memory_group_manager.o +ifeq ($(CONFIG_MALI_MEMORY_GROUP_MANAGER), y) +obj-m := memory_group_manager.o +endif diff --git a/drivers/base/arm/memory_group_manager/build.bp b/drivers/base/arm/memory_group_manager/build.bp index 4eb447cc1257..23db183e4f1b 100644 --- a/drivers/base/arm/memory_group_manager/build.bp +++ b/drivers/base/arm/memory_group_manager/build.bp @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -21,10 +21,16 @@ bob_kernel_module { name: "memory_group_manager", + defaults: [ + "kernel_defaults" + ], srcs: [ "Kbuild", "memory_group_manager.c", ], - kbuild_options: ["CONFIG_MALI_MEMORY_GROUP_MANAGER=m"], - defaults: ["kernel_defaults"], + enabled: false, + mali_memory_group_manager: { + kbuild_options: ["CONFIG_MALI_MEMORY_GROUP_MANAGER=y"], + enabled: true, + }, } diff --git a/drivers/base/arm/memory_group_manager/memory_group_manager.c b/drivers/base/arm/memory_group_manager/memory_group_manager.c index 2ce3b940ed72..270257287e71 100644 --- a/drivers/base/arm/memory_group_manager/memory_group_manager.c +++ b/drivers/base/arm/memory_group_manager/memory_group_manager.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -25,7 +25,7 @@ #include #include #include -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) #include #endif #include @@ -97,12 +97,12 @@ struct mgm_group { struct mgm_groups { struct mgm_group groups[MEMORY_GROUP_MANAGER_NR_GROUPS]; struct device *dev; -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) struct dentry *mgm_debugfs_root; #endif }; -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) static int mgm_size_get(void *data, u64 *val) { diff --git a/drivers/base/arm/protected_memory_allocator/Kbuild b/drivers/base/arm/protected_memory_allocator/Kbuild index 205c5f1ee95a..25295a9a0f76 100644 --- a/drivers/base/arm/protected_memory_allocator/Kbuild +++ b/drivers/base/arm/protected_memory_allocator/Kbuild @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # # (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. # @@ -18,4 +18,6 @@ # # -obj-$(CONFIG_MALI_PROTECTED_MEMORY_ALLOCATOR) := protected_memory_allocator.o +ifeq ($(CONFIG_MALI_PROTECTED_MEMORY_ALLOCATOR), y) +obj-m := protected_memory_allocator.o +endif diff --git a/drivers/base/arm/protected_memory_allocator/Makefile b/drivers/base/arm/protected_memory_allocator/Makefile deleted file mode 100644 index 93f49b5efdf2..000000000000 --- a/drivers/base/arm/protected_memory_allocator/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. -# -# This program is free software and is provided to you under the terms of the -# GNU General Public License version 2 as published by the Free Software -# Foundation, and any use by you of this program is subject to the terms -# of such GNU license. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, you can access it online at -# http://www.gnu.org/licenses/gpl-2.0.html. -# -# - -# linux build system bootstrap for out-of-tree module - -# default to building for the host -ARCH ?= $(shell uname -m) - -# Handle Android Common Kernel source naming -KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build -KDIR ?= $(KERNEL_SRC) - -all: - $(MAKE) ARCH=$(ARCH) -C $(KDIR) M=$(CURDIR) EXTRA_CFLAGS="-I$(CURDIR)/../../../../include" modules CONFIG_MALI_PROTECTED_MEMORY_ALLOCATOR=m - -clean: - $(MAKE) ARCH=$(ARCH) -C $(KDIR) M=$(CURDIR) clean - -modules_install: - $(MAKE) ARCH=$(ARCH) -C $(KDIR) M=$(CURDIR) modules_install diff --git a/drivers/base/arm/protected_memory_allocator/build.bp b/drivers/base/arm/protected_memory_allocator/build.bp index ddb0510cacd6..4c56154061e8 100644 --- a/drivers/base/arm/protected_memory_allocator/build.bp +++ b/drivers/base/arm/protected_memory_allocator/build.bp @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -21,14 +21,16 @@ bob_kernel_module { name: "protected_memory_allocator", + defaults: [ + "kernel_defaults" + ], srcs: [ "Kbuild", "protected_memory_allocator.c", ], - kbuild_options: ["CONFIG_MALI_PROTECTED_MEMORY_ALLOCATOR=m"], - defaults: ["kernel_defaults"], enabled: false, - build_csf_only_module: { + mali_protected_memory_allocator: { + kbuild_options: ["CONFIG_MALI_PROTECTED_MEMORY_ALLOCATOR=y"], enabled: true, }, } diff --git a/drivers/base/arm/protected_memory_allocator/protected_memory_allocator.c b/drivers/base/arm/protected_memory_allocator/protected_memory_allocator.c index a34b3a44fb79..6684210762d0 100644 --- a/drivers/base/arm/protected_memory_allocator/protected_memory_allocator.c +++ b/drivers/base/arm/protected_memory_allocator/protected_memory_allocator.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/Kbuild b/drivers/gpu/arm/bifrost/Kbuild index 8b4ece17cfe5..83c331d832db 100644 --- a/drivers/gpu/arm/bifrost/Kbuild +++ b/drivers/gpu/arm/bifrost/Kbuild @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # # (C) COPYRIGHT 2012-2021 ARM Limited. All rights reserved. # @@ -18,221 +18,237 @@ # # -# Driver version string which is returned to userspace via an ioctl -MALI_RELEASE_NAME ?= '"g6p0-01eac0"' - -# Paths required for build - # make $(src) as absolute path if it is not already, by prefixing $(srctree) +# This is to prevent any build issue due to wrong path. src:=$(if $(patsubst /%,,$(src)),$(srctree)/$(src),$(src)) -KBASE_PATH = $(src) -KBASE_PLATFORM_PATH = $(KBASE_PATH)/platform_dummy -UMP_PATH = $(src)/../../../base +# +# Prevent misuse when Kernel configurations are not present by default +# in out-of-tree builds +# +ifneq ($(CONFIG_ANDROID),n) +ifeq ($(CONFIG_GPU_TRACEPOINTS),n) + $(error CONFIG_GPU_TRACEPOINTS must be set in Kernel configuration) +endif +endif + +ifeq ($(CONFIG_DMA_SHARED_BUFFER),n) + $(error CONFIG_DMA_SHARED_BUFFER must be set in Kernel configuration) +endif + +ifeq ($(CONFIG_PM_DEVFREQ),n) + $(error CONFIG_PM_DEVFREQ must be set in Kernel configuration) +endif + +ifeq ($(CONFIG_DEVFREQ_THERMAL),n) + $(error CONFIG_DEVFREQ_THERMAL must be set in Kernel configuration) +endif + +ifeq ($(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND),n) + $(error CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND must be set in Kernel configuration) +endif + +ifeq ($(CONFIG_MALI_PRFCNT_SET_SELECT_VIA_DEBUG_FS), y) + ifneq ($(CONFIG_DEBUG_FS), y) + $(error CONFIG_MALI_PRFCNT_SET_SELECT_VIA_DEBUG_FS depends on CONFIG_DEBUG_FS to be set in Kernel configuration) + endif +endif + +ifeq ($(CONFIG_MALI_BIFROST_FENCE_DEBUG), y) + ifneq ($(CONFIG_SYNC), y) + ifneq ($(CONFIG_SYNC_FILE), y) + $(error CONFIG_MALI_BIFROST_FENCE_DEBUG depends on CONFIG_SYNC || CONFIG_SYNC_FILE to be set in Kernel configuration) + endif + endif +endif + +# +# Configurations +# + +# Driver version string which is returned to userspace via an ioctl +MALI_RELEASE_NAME ?= '"g7p1-01bet0"' # Set up defaults if not defined by build system -MALI_CUSTOMER_RELEASE ?= 1 -MALI_UNIT_TEST ?= 0 +ifeq ($(CONFIG_MALI_BIFROST_DEBUG), y) + MALI_UNIT_TEST = 1 + MALI_CUSTOMER_RELEASE ?= 0 +else + MALI_UNIT_TEST ?= 0 + MALI_CUSTOMER_RELEASE ?= 1 +endif MALI_COVERAGE ?= 0 + CONFIG_MALI_PLATFORM_NAME ?= "devicetree" + +# Kconfig passes in the name with quotes for in-tree builds - remove them. +MALI_PLATFORM_DIR := $(shell echo $(CONFIG_MALI_PLATFORM_NAME)) + +ifeq ($(CONFIG_MALI_CSF_SUPPORT),y) + MALI_JIT_PRESSURE_LIMIT_BASE = 0 + MALI_USE_CSF = 1 +else + MALI_JIT_PRESSURE_LIMIT_BASE ?= 1 + MALI_USE_CSF ?= 0 +endif + +ifneq ($(CONFIG_MALI_KUTF), n) + MALI_KERNEL_TEST_API ?= 1 +else + MALI_KERNEL_TEST_API ?= 0 +endif + # Experimental features (corresponding -D definition should be appended to -# DEFINES below, e.g. for MALI_EXPERIMENTAL_FEATURE, +# ccflags-y below, e.g. for MALI_EXPERIMENTAL_FEATURE, # -DMALI_EXPERIMENTAL_FEATURE=$(MALI_EXPERIMENTAL_FEATURE) should be appended) # # Experimental features must default to disabled, e.g.: # MALI_EXPERIMENTAL_FEATURE ?= 0 MALI_INCREMENTAL_RENDERING ?= 0 -ifeq ($(CONFIG_MALI_CSF_SUPPORT),y) -MALI_JIT_PRESSURE_LIMIT_BASE = 0 -MALI_USE_CSF = 1 -else -MALI_JIT_PRESSURE_LIMIT_BASE ?= 1 -MALI_USE_CSF ?= 0 -endif +# +# ccflags +# +ccflags-y = \ + -DMALI_CUSTOMER_RELEASE=$(MALI_CUSTOMER_RELEASE) \ + -DMALI_USE_CSF=$(MALI_USE_CSF) \ + -DMALI_KERNEL_TEST_API=$(MALI_KERNEL_TEST_API) \ + -DMALI_UNIT_TEST=$(MALI_UNIT_TEST) \ + -DMALI_COVERAGE=$(MALI_COVERAGE) \ + -DMALI_RELEASE_NAME=$(MALI_RELEASE_NAME) \ + -DMALI_JIT_PRESSURE_LIMIT_BASE=$(MALI_JIT_PRESSURE_LIMIT_BASE) \ + -DMALI_INCREMENTAL_RENDERING=$(MALI_INCREMENTAL_RENDERING) \ + -DMALI_KBASE_BUILD \ + -DMALI_PLATFORM_DIR=$(MALI_PLATFORM_DIR) -ifneq ($(CONFIG_MALI_KUTF), n) -MALI_KERNEL_TEST_API ?= 1 -else -MALI_KERNEL_TEST_API ?= 0 -endif - -# Set up our defines, which will be passed to gcc -DEFINES = \ - -DMALI_CUSTOMER_RELEASE=$(MALI_CUSTOMER_RELEASE) \ - -DMALI_USE_CSF=$(MALI_USE_CSF) \ - -DMALI_KERNEL_TEST_API=$(MALI_KERNEL_TEST_API) \ - -DMALI_UNIT_TEST=$(MALI_UNIT_TEST) \ - -DMALI_COVERAGE=$(MALI_COVERAGE) \ - -DMALI_RELEASE_NAME=$(MALI_RELEASE_NAME) \ - -DMALI_JIT_PRESSURE_LIMIT_BASE=$(MALI_JIT_PRESSURE_LIMIT_BASE) \ - -DMALI_INCREMENTAL_RENDERING=$(MALI_INCREMENTAL_RENDERING) ifeq ($(KBUILD_EXTMOD),) # in-tree -DEFINES +=-DMALI_KBASE_PLATFORM_PATH=../../$(src)/platform/$(CONFIG_MALI_PLATFORM_NAME) + ccflags-y +=-DMALI_KBASE_PLATFORM_PATH=../../$(src)/platform/$(CONFIG_MALI_PLATFORM_NAME) else # out-of-tree -DEFINES +=-DMALI_KBASE_PLATFORM_PATH=$(src)/platform/$(CONFIG_MALI_PLATFORM_NAME) + ccflags-y +=-DMALI_KBASE_PLATFORM_PATH=$(src)/platform/$(CONFIG_MALI_PLATFORM_NAME) endif -DEFINES += -I$(srctree)/drivers/staging/android +ccflags-y += \ + -I$(srctree)/include/linux \ + -I$(srctree)/drivers/staging/android \ + -I$(src) \ + -I$(src)/platform/$(MALI_PLATFORM_DIR) \ + -I$(src)/../../../base \ + -I$(src)/../../../../include -DEFINES += -DMALI_KBASE_BUILD +subdir-ccflags-y += $(ccflags-y) -# Use our defines when compiling -ccflags-y += $(DEFINES) -I$(KBASE_PATH) -I$(KBASE_PLATFORM_PATH) -I$(UMP_PATH) -I$(srctree)/include/linux -subdir-ccflags-y += $(DEFINES) -I$(KBASE_PATH) -I$(KBASE_PLATFORM_PATH) -I$(UMP_PATH) -I$(srctree)/include/linux - -SRC := \ - context/mali_kbase_context.c \ - debug/mali_kbase_debug_ktrace.c \ - device/mali_kbase_device.c \ - device/mali_kbase_device_hw.c \ - mali_kbase_cache_policy.c \ - mali_kbase_ccswe.c \ - mali_kbase_mem.c \ - mali_kbase_mem_pool_group.c \ - mali_kbase_native_mgm.c \ - mali_kbase_ctx_sched.c \ - mali_kbase_jm.c \ - mali_kbase_gpuprops.c \ - mali_kbase_pm.c \ - mali_kbase_config.c \ - mali_kbase_vinstr.c \ - mali_kbase_hwcnt.c \ - mali_kbase_hwcnt_gpu.c \ - mali_kbase_hwcnt_legacy.c \ - mali_kbase_hwcnt_types.c \ - mali_kbase_hwcnt_virtualizer.c \ - mali_kbase_softjobs.c \ - mali_kbase_hw.c \ - mali_kbase_debug.c \ - mali_kbase_gpu_memory_debugfs.c \ - mali_kbase_mem_linux.c \ - mali_kbase_core_linux.c \ - mali_kbase_mem_profile_debugfs.c \ - mmu/mali_kbase_mmu.c \ - mmu/mali_kbase_mmu_hw_direct.c \ - mmu/mali_kbase_mmu_mode_aarch64.c \ - mali_kbase_disjoint_events.c \ - mali_kbase_debug_mem_view.c \ - mali_kbase_smc.c \ - mali_kbase_mem_pool.c \ - mali_kbase_mem_pool_debugfs.c \ - mali_kbase_debugfs_helper.c \ - mali_kbase_strings.c \ - mali_kbase_as_fault_debugfs.c \ - mali_kbase_regs_history_debugfs.c \ - mali_kbase_dvfs_debugfs.c \ - mali_power_gpu_frequency_trace.c \ - mali_kbase_trace_gpu_mem.c \ - thirdparty/mali_kbase_mmap.c \ - tl/mali_kbase_timeline.c \ - tl/mali_kbase_timeline_io.c \ - tl/mali_kbase_tlstream.c \ - tl/mali_kbase_tracepoints.c \ - gpu/mali_kbase_gpu.c - -ifeq ($(MALI_USE_CSF),1) - SRC += \ - mali_kbase_hwcnt_backend_csf.c \ - mali_kbase_hwcnt_backend_csf_if_fw.c \ - debug/backend/mali_kbase_debug_ktrace_csf.c \ - device/backend/mali_kbase_device_csf.c \ - device/backend/mali_kbase_device_hw_csf.c \ - gpu/backend/mali_kbase_gpu_fault_csf.c \ - tl/backend/mali_kbase_timeline_csf.c \ - mmu/backend/mali_kbase_mmu_csf.c \ - context/backend/mali_kbase_context_csf.c -else - SRC += \ - mali_kbase_hwcnt_backend_jm.c \ - mali_kbase_dummy_job_wa.c \ - mali_kbase_debug_job_fault.c \ - mali_kbase_event.c \ - mali_kbase_jd.c \ - mali_kbase_jd_debugfs.c \ - mali_kbase_js.c \ - mali_kbase_js_ctx_attr.c \ - mali_kbase_kinstr_jm.c \ - debug/backend/mali_kbase_debug_ktrace_jm.c \ - device/backend/mali_kbase_device_jm.c \ - device/backend/mali_kbase_device_hw_jm.c \ - gpu/backend/mali_kbase_gpu_fault_jm.c \ - tl/backend/mali_kbase_timeline_jm.c \ - mmu/backend/mali_kbase_mmu_jm.c \ - context/backend/mali_kbase_context_jm.c -endif - -ifeq ($(CONFIG_MALI_CINSTR_GWT),y) - SRC += mali_kbase_gwt.c -endif - - -ifeq ($(MALI_CUSTOMER_RELEASE),0) - SRC += mali_kbase_regs_dump_debugfs.c -endif - - -ccflags-y += -I$(KBASE_PATH) -I$(KBASE_PATH)/debug \ - -I$(KBASE_PATH)/debug/backend - -# Tell the Linux build system from which .o file to create the kernel module +# +# Kernel Modules +# obj-$(CONFIG_MALI_BIFROST) += bifrost_kbase.o +obj-$(CONFIG_MALI_KUTF) += tests/ -# Tell the Linux build system to enable building of our .c files -bifrost_kbase-y := $(SRC:.c=.o) +bifrost_kbase-y := \ + mali_kbase_cache_policy.o \ + mali_kbase_ccswe.o \ + mali_kbase_mem.o \ + mali_kbase_mem_pool_group.o \ + mali_kbase_native_mgm.o \ + mali_kbase_ctx_sched.o \ + mali_kbase_gpuprops.o \ + mali_kbase_pm.o \ + mali_kbase_config.o \ + mali_kbase_vinstr.o \ + mali_kbase_hwcnt.o \ + mali_kbase_hwcnt_gpu.o \ + mali_kbase_hwcnt_legacy.o \ + mali_kbase_hwcnt_types.o \ + mali_kbase_hwcnt_virtualizer.o \ + mali_kbase_softjobs.o \ + mali_kbase_hw.o \ + mali_kbase_debug.o \ + mali_kbase_gpu_memory_debugfs.o \ + mali_kbase_mem_linux.o \ + mali_kbase_core_linux.o \ + mali_kbase_mem_profile_debugfs.o \ + mali_kbase_disjoint_events.o \ + mali_kbase_debug_mem_view.o \ + mali_kbase_smc.o \ + mali_kbase_mem_pool.o \ + mali_kbase_mem_pool_debugfs.o \ + mali_kbase_debugfs_helper.o \ + mali_kbase_strings.o \ + mali_kbase_as_fault_debugfs.o \ + mali_kbase_regs_history_debugfs.o \ + mali_kbase_dvfs_debugfs.o \ + mali_power_gpu_frequency_trace.o \ + mali_kbase_trace_gpu_mem.o -# Kconfig passes in the name with quotes for in-tree builds - remove them. -platform_name := $(shell echo $(CONFIG_MALI_PLATFORM_NAME)) -MALI_PLATFORM_DIR := platform/$(platform_name) -ccflags-y += -I$(src)/$(MALI_PLATFORM_DIR) -include $(src)/$(MALI_PLATFORM_DIR)/Kbuild +bifrost_kbase-$(CONFIG_MALI_CINSTR_GWT) += mali_kbase_gwt.o -ifeq ($(CONFIG_MALI_BIFROST_DEVFREQ),y) - ifeq ($(CONFIG_DEVFREQ_THERMAL),y) - include $(src)/ipa/Kbuild - endif +bifrost_kbase-$(CONFIG_SYNC) += \ + mali_kbase_sync_android.o \ + mali_kbase_sync_common.o + +bifrost_kbase-$(CONFIG_SYNC_FILE) += \ + mali_kbase_fence_ops.o \ + mali_kbase_sync_file.o \ + mali_kbase_sync_common.o + +ifeq ($(CONFIG_MALI_CSF_SUPPORT),y) + bifrost_kbase-y += \ + mali_kbase_hwcnt_backend_csf.o \ + mali_kbase_hwcnt_backend_csf_if_fw.o +else + bifrost_kbase-y += \ + mali_kbase_jm.o \ + mali_kbase_hwcnt_backend_jm.o \ + mali_kbase_dummy_job_wa.o \ + mali_kbase_debug_job_fault.o \ + mali_kbase_event.o \ + mali_kbase_jd.o \ + mali_kbase_jd_debugfs.o \ + mali_kbase_js.o \ + mali_kbase_js_ctx_attr.o \ + mali_kbase_kinstr_jm.o + + bifrost_kbase-$(CONFIG_MALI_BIFROST_DMA_FENCE) += \ + mali_kbase_fence_ops.o \ + mali_kbase_dma_fence.o \ + mali_kbase_fence.o + + bifrost_kbase-$(CONFIG_SYNC_FILE) += \ + mali_kbase_fence_ops.o \ + mali_kbase_fence.o endif -ifeq ($(MALI_USE_CSF),1) - include $(src)/csf/Kbuild -else -# empty + +INCLUDE_SUBDIR = \ + $(src)/context/Kbuild \ + $(src)/debug/Kbuild \ + $(src)/device/Kbuild \ + $(src)/backend/gpu/Kbuild \ + $(src)/mmu/Kbuild \ + $(src)/tl/Kbuild \ + $(src)/gpu/Kbuild \ + $(src)/thirdparty/Kbuild \ + $(src)/platform/$(MALI_PLATFORM_DIR)/Kbuild + +ifeq ($(CONFIG_MALI_CSF_SUPPORT),y) + INCLUDE_SUBDIR += $(src)/csf/Kbuild endif ifeq ($(CONFIG_MALI_ARBITER_SUPPORT),y) - include $(src)/arbiter/Kbuild + INCLUDE_SUBDIR += $(src)/arbiter/Kbuild +endif + +ifeq ($(CONFIG_MALI_BIFROST_DEVFREQ),y) + ifeq ($(CONFIG_DEVFREQ_THERMAL),y) + INCLUDE_SUBDIR += $(src)/ipa/Kbuild + endif +endif + +ifeq ($(KBUILD_EXTMOD),) +# in-tree + -include $(INCLUDE_SUBDIR) else -# empty +# out-of-tree + include $(INCLUDE_SUBDIR) endif - -ifeq ($(MALI_USE_CSF),0) - bifrost_kbase-$(CONFIG_MALI_BIFROST_DMA_FENCE) += \ - mali_kbase_fence_ops.o \ - mali_kbase_dma_fence.o \ - mali_kbase_fence.o - - bifrost_kbase-$(CONFIG_SYNC_FILE) += \ - mali_kbase_fence_ops.o \ - mali_kbase_fence.o -endif - -bifrost_kbase-$(CONFIG_SYNC) += \ - mali_kbase_sync_android.o \ - mali_kbase_sync_common.o - -bifrost_kbase-$(CONFIG_SYNC_FILE) += \ - mali_kbase_fence_ops.o \ - mali_kbase_sync_file.o \ - mali_kbase_sync_common.o - -include $(src)/backend/gpu/Kbuild -bifrost_kbase-y += $(BACKEND:.c=.o) - - -ccflags-y += -I$(src)/backend/gpu -subdir-ccflags-y += -I$(src)/backend/gpu - -# For kutf and mali_kutf_irq_latency_test -obj-$(CONFIG_MALI_KUTF) += tests/ diff --git a/drivers/gpu/arm/bifrost/Kconfig b/drivers/gpu/arm/bifrost/Kconfig index fdbeafc010fb..39dca109b40d 100644 --- a/drivers/gpu/arm/bifrost/Kconfig +++ b/drivers/gpu/arm/bifrost/Kconfig @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # # (C) COPYRIGHT 2012-2021 ARM Limited. All rights reserved. # @@ -18,11 +18,12 @@ # # - menuconfig MALI_BIFROST tristate "Mali Bifrost series support" select GPU_TRACEPOINTS if ANDROID select DMA_SHARED_BUFFER + select PM_DEVFREQ + select DEVFREQ_THERMAL default n help Enable this option to build support for a ARM Mali Bifrost GPU. @@ -30,20 +31,43 @@ menuconfig MALI_BIFROST To compile this driver as a module, choose M here: this will generate a single module, called mali_kbase. +if MALI_BIFROST + +config MALI_PLATFORM_NAME + depends on MALI_BIFROST + string "Platform name" + default "devicetree" + help + Enter the name of the desired platform configuration directory to + include in the build. 'platform/$(MALI_PLATFORM_NAME)/Makefile' must + exist. + +config MALI_REAL_HW + depends on MALI_BIFROST + def_bool !MALI_BIFROST_NO_MALI + +menu "Platform specific options" +source "drivers/gpu/arm/midgard/platform/Kconfig" +endmenu + config MALI_CSF_SUPPORT - bool "Mali CSF based GPU support" + bool "Enable Mali CSF based GPU support" depends on MALI_BIFROST=m default n help Enables support for CSF based GPUs. -config MALI_BIFROST_GATOR_SUPPORT - bool "Enable Streamline tracing support" - depends on MALI_BIFROST - default n +config MALI_BIFROST_DEVFREQ + bool "Enable devfreq support for Mali" + depends on MALI_BIFROST && PM_DEVFREQ + select DEVFREQ_GOV_SIMPLE_ONDEMAND + default y help - Enables kbase tracing used by the Arm Streamline Performance Analyzer. - The tracepoints are used to derive GPU activity charts in Streamline. + Support devfreq for Mali. + + Using the devfreq framework and, by default, the simple on-demand + governor, the frequency of Mali will be dynamically selected from the + available OPPs. config MALI_BIFROST_DVFS bool "Enable legacy DVFS" @@ -52,28 +76,25 @@ config MALI_BIFROST_DVFS help Choose this option to enable legacy DVFS in the Mali Midgard DDK. +config MALI_BIFROST_GATOR_SUPPORT + bool "Enable Streamline tracing support" + depends on MALI_BIFROST + default y + help + Enables kbase tracing used by the Arm Streamline Performance Analyzer. + The tracepoints are used to derive GPU activity charts in Streamline. + config MALI_BIFROST_ENABLE_TRACE bool "Enable kbase tracing" depends on MALI_BIFROST default y if MALI_BIFROST_DEBUG default n help - Enables tracing in kbase. Trace log available through + Enables tracing in kbase. Trace log available through the "mali_trace" debugfs file, when the CONFIG_DEBUG_FS is enabled -config MALI_BIFROST_DEVFREQ - bool "devfreq support for Mali" - depends on MALI_BIFROST && PM_DEVFREQ - select DEVFREQ_GOV_SIMPLE_ONDEMAND - help - Support devfreq for Mali. - - Using the devfreq framework and, by default, the simpleondemand - governor, the frequency of Mali will be dynamically selected from the - available OPPs. - config MALI_BIFROST_DMA_FENCE - bool "DMA_BUF fence support for Mali" + bool "Enable DMA_BUF fence support for Mali" depends on MALI_BIFROST default n help @@ -82,18 +103,9 @@ config MALI_BIFROST_DMA_FENCE This option should only be enabled if the Linux Kernel has built in support for DMA_BUF fences. -config MALI_PLATFORM_NAME - depends on MALI_BIFROST - string "Platform name" - default "devicetree" - help - Enter the name of the desired platform configuration directory to - include in the build. 'platform/$(MALI_PLATFORM_NAME)/Kbuild' must - exist. - config MALI_ARBITER_SUPPORT bool "Enable arbiter support for Mali" - depends on MALI_BIFROST + depends on MALI_BIFROST && !MALI_CSF_SUPPORT default n help Enable support for the arbiter interface in the driver. @@ -102,126 +114,13 @@ config MALI_ARBITER_SUPPORT If unsure, say N. -# MALI_BIFROST_EXPERT configuration options - -menuconfig MALI_BIFROST_EXPERT - depends on MALI_BIFROST - bool "Enable Expert Settings" - default n - help - Enabling this option and modifying the default settings may produce a driver with performance or - other limitations. - -config MALI_CORESTACK - bool "Support controlling power to the GPU core stack" - depends on MALI_BIFROST && MALI_BIFROST_EXPERT - default n - help - Enabling this feature on supported GPUs will let the driver powering - on/off the GPU core stack independently without involving the Power - Domain Controller. This should only be enabled on platforms which - integration of the PDC to the Mali GPU is known to be problematic. - This feature is currently only supported on t-Six and t-HEx GPUs. - - If unsure, say N. - -config MALI_BIFROST_DEBUG - bool "Debug build" - depends on MALI_BIFROST && MALI_BIFROST_EXPERT - default n - help - Select this option for increased checking and reporting of errors. - -config MALI_BIFROST_FENCE_DEBUG - bool "Debug sync fence usage" - depends on MALI_BIFROST && MALI_BIFROST_EXPERT && (SYNC || SYNC_FILE) - default y if MALI_BIFROST_DEBUG - help - Select this option to enable additional checking and reporting on the - use of sync fences in the Mali driver. - - This will add a 3s timeout to all sync fence waits in the Mali - driver, so that when work for Mali has been waiting on a sync fence - for a long time a debug message will be printed, detailing what fence - is causing the block, and which dependent Mali atoms are blocked as a - result of this. - - The timeout can be changed at runtime through the js_soft_timeout - device attribute, where the timeout is specified in milliseconds. - -config MALI_BIFROST_NO_MALI - bool "No Mali" - depends on MALI_BIFROST && MALI_BIFROST_EXPERT - default n - help - This can be used to test the driver in a simulated environment - whereby the hardware is not physically present. If the hardware is physically - present it will not be used. This can be used to test the majority of the - driver without needing actual hardware or for software benchmarking. - All calls to the simulated hardware will complete immediately as if the hardware - completed the task. - -config MALI_REAL_HW - def_bool !MALI_BIFROST_NO_MALI - -config MALI_BIFROST_ERROR_INJECT - bool "Error injection" - depends on MALI_BIFROST && MALI_BIFROST_EXPERT && MALI_BIFROST_NO_MALI - default n - help - Enables insertion of errors to test module failure and recovery mechanisms. - -config MALI_BIFROST_SYSTEM_TRACE - bool "Enable system event tracing support" - depends on MALI_BIFROST && MALI_BIFROST_EXPERT - default y if MALI_BIFROST_DEBUG - default n - help - Choose this option to enable system trace events for each - kbase event. This is typically used for debugging but has - minimal overhead when not in use. Enable only if you know what - you are doing. - -config MALI_2MB_ALLOC - bool "Attempt to allocate 2MB pages" - depends on MALI_BIFROST && MALI_BIFROST_EXPERT - default n - help - Rather than allocating all GPU memory page-by-page, attempt to - allocate 2MB pages from the kernel. This reduces TLB pressure and - helps to prevent memory fragmentation. - - If in doubt, say N - -config MALI_PWRSOFT_765 - bool "PWRSOFT-765 ticket" - depends on MALI_BIFROST && MALI_BIFROST_EXPERT - default n - help - PWRSOFT-765 fixes devfreq cooling devices issues. The fix was merged - in kernel v4.10, however if backported into the kernel then this - option must be manually selected. - - If using kernel >= v4.10 then say N, otherwise if devfreq cooling - changes have been backported say Y to avoid compilation errors. - -config MALI_MEMORY_FULLY_BACKED - bool "Memory fully physically-backed" - depends on MALI_BIFROST && MALI_BIFROST_EXPERT - default n - help - This option enables full physical backing of all virtual - memory allocations in the kernel. Notice that this build - option only affects allocations of grow-on-GPU-page-fault - memory. - config MALI_DMA_BUF_MAP_ON_DEMAND - bool "Map imported dma-bufs on demand" + bool "Enable map imported dma-bufs on demand" depends on MALI_BIFROST default n help This option caused kbase to set up the GPU mapping of imported - dma-buf when needed to run atoms. This is the legacy behaviour. + dma-buf when needed to run atoms. This is the legacy behavior. This is intended for testing and the option will get removed in the future. @@ -240,51 +139,123 @@ config MALI_DMA_BUF_LEGACY_COMPAT flushes in other drivers. This only has an effect for clients using UK 11.18 or older. For later UK versions it is not possible. -config MALI_HW_ERRATA_1485982_NOT_AFFECTED - bool "Disable workaround for BASE_HW_ISSUE_GPU2017_1336" +menuconfig MALI_BIFROST_EXPERT + depends on MALI_BIFROST + bool "Enable Expert Settings" + default n + help + Enabling this option and modifying the default settings may produce + a driver with performance or other limitations. + +if MALI_BIFROST_EXPERT + +config MALI_2MB_ALLOC + bool "Attempt to allocate 2MB pages" depends on MALI_BIFROST && MALI_BIFROST_EXPERT default n help - This option disables the default workaround for GPU2017-1336. The - workaround keeps the L2 cache powered up except for powerdown and reset. + Rather than allocating all GPU memory page-by-page, attempt to + allocate 2MB pages from the kernel. This reduces TLB pressure and + helps to prevent memory fragmentation. - The workaround introduces a limitation that will prevent the running of - protected mode content on fully coherent platforms, as the switch to IO - coherency mode requires the L2 to be turned off. + If in doubt, say N -config MALI_HW_ERRATA_1485982_USE_CLOCK_ALTERNATIVE - bool "Use alternative workaround for BASE_HW_ISSUE_GPU2017_1336" - depends on MALI_BIFROST && MALI_BIFROST_EXPERT && !MALI_HW_ERRATA_1485982_NOT_AFFECTED +config MALI_MEMORY_FULLY_BACKED + bool "Enable memory fully physically-backed" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT default n help - This option uses an alternative workaround for GPU2017-1336. Lowering - the GPU clock to a, platform specific, known good frequeuncy before - powering down the L2 cache. The clock can be specified in the device - tree using the property, opp-mali-errata-1485982. Otherwise the - slowest clock will be selected. + This option enables full physical backing of all virtual + memory allocations in the kernel. Notice that this build + option only affects allocations of grow-on-GPU-page-fault + memory. + +config MALI_CORESTACK + bool "Enable support of GPU core stack power control" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT + default n + help + Enabling this feature on supported GPUs will let the driver powering + on/off the GPU core stack independently without involving the Power + Domain Controller. This should only be enabled on platforms which + integration of the PDC to the Mali GPU is known to be problematic. + This feature is currently only supported on t-Six and t-HEx GPUs. + + If unsure, say N. + +comment "Platform options" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT + +config MALI_BIFROST_NO_MALI + bool "Enable No Mali" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT + default n + help + This can be used to test the driver in a simulated environment + whereby the hardware is not physically present. If the hardware is physically + present it will not be used. This can be used to test the majority of the + driver without needing actual hardware or for software benchmarking. + All calls to the simulated hardware will complete immediately as if the hardware + completed the task. + +config MALI_BIFROST_ERROR_INJECT + bool "Enable No Mali error injection" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT && MALI_BIFROST_NO_MALI + default n + help + Enables insertion of errors to test module failure and recovery mechanisms. config MALI_GEM5_BUILD bool "Enable build of Mali kernel driver for GEM5" - depends on MALI_BIFROST + depends on MALI_BIFROST && MALI_BIFROST_EXPERT default n help This option is to do a Mali GEM5 build. If unsure, say N. -# Instrumentation options. +comment "Debug options" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT -config MALI_JOB_DUMP - bool "Enable system level support needed for job dumping" +config MALI_BIFROST_DEBUG + bool "Enable debug build" depends on MALI_BIFROST && MALI_BIFROST_EXPERT default n help - Choose this option to enable system level support needed for - job dumping. This is typically used for instrumentation but has + Select this option for increased checking and reporting of errors. + +config MALI_BIFROST_FENCE_DEBUG + bool "Enable debug sync fence usage" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT && (SYNC || SYNC_FILE) + default y if MALI_BIFROST_DEBUG + help + Select this option to enable additional checking and reporting on the + use of sync fences in the Mali driver. + + This will add a 3s timeout to all sync fence waits in the Mali + driver, so that when work for Mali has been waiting on a sync fence + for a long time a debug message will be printed, detailing what fence + is causing the block, and which dependent Mali atoms are blocked as a + result of this. + + The timeout can be changed at runtime through the js_soft_timeout + device attribute, where the timeout is specified in milliseconds. + +config MALI_BIFROST_SYSTEM_TRACE + bool "Enable system event tracing support" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT + default y if MALI_BIFROST_DEBUG + default n + help + Choose this option to enable system trace events for each + kbase event. This is typically used for debugging but has minimal overhead when not in use. Enable only if you know what you are doing. +comment "Instrumentation options" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT + choice - prompt "Performance counters set" + prompt "Select Performance counters set" default MALI_PRFCNT_SET_PRIMARY depends on MALI_BIFROST && MALI_BIFROST_EXPERT @@ -321,7 +292,7 @@ config MALI_PRFCNT_SET_TERTIARY endchoice config MALI_PRFCNT_SET_SELECT_VIA_DEBUG_FS - bool "Allow runtime selection of performance counters set via debugfs" + bool "Enable runtime selection of performance counters set via debugfs" depends on MALI_BIFROST && MALI_BIFROST_EXPERT && DEBUG_FS default n help @@ -343,5 +314,65 @@ config MALI_PRFCNT_SET_SELECT_VIA_DEBUG_FS If unsure, say N. -source "drivers/gpu/arm/midgard/platform/Kconfig" -# source "drivers/gpu/arm/midgard/tests/Kconfig" +config MALI_JOB_DUMP + bool "Enable system level support needed for job dumping" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT + default n + help + Choose this option to enable system level support needed for + job dumping. This is typically used for instrumentation but has + minimal overhead when not in use. Enable only if you know what + you are doing. + +comment "Workarounds" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT + +config MALI_PWRSOFT_765 + bool "Enable workaround for PWRSOFT-765" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT + default n + help + PWRSOFT-765 fixes devfreq cooling devices issues. The fix was merged + in kernel v4.10, however if backported into the kernel then this + option must be manually selected. + + If using kernel >= v4.10 then say N, otherwise if devfreq cooling + changes have been backported say Y to avoid compilation errors. + +config MALI_HW_ERRATA_1485982_NOT_AFFECTED + bool "Disable workaround for BASE_HW_ISSUE_GPU2017_1336" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT + default n + help + This option disables the default workaround for GPU2017-1336. The + workaround keeps the L2 cache powered up except for powerdown and reset. + + The workaround introduces a limitation that will prevent the running of + protected mode content on fully coherent platforms, as the switch to IO + coherency mode requires the L2 to be turned off. + +config MALI_HW_ERRATA_1485982_USE_CLOCK_ALTERNATIVE + bool "Use alternative workaround for BASE_HW_ISSUE_GPU2017_1336" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT && !MALI_HW_ERRATA_1485982_NOT_AFFECTED + default n + help + This option uses an alternative workaround for GPU2017-1336. Lowering + the GPU clock to a, platform specific, known good frequency before + powering down the L2 cache. The clock can be specified in the device + tree using the property, opp-mali-errata-1485982. Otherwise the + slowest clock will be selected. + +endif + +config MALI_ARBITRATION + bool "Enable Virtualization reference code" + depends on MALI_BIFROST + default n + help + Enables the build of several reference modules used in the reference + virtualization setup for Mali + If unsure, say N. + +source "drivers/gpu/arm/midgard/tests/Kconfig" + +endif diff --git a/drivers/gpu/arm/bifrost/Makefile b/drivers/gpu/arm/bifrost/Makefile index 89760d9f850a..ecc6f1ed2a6d 100644 --- a/drivers/gpu/arm/bifrost/Makefile +++ b/drivers/gpu/arm/bifrost/Makefile @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # # (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. # @@ -18,47 +18,198 @@ # # -# Handle Android Common Kernel source naming KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build KDIR ?= $(KERNEL_SRC) -# out-of-tree -ifeq ($(KBUILD_EXTMOD),) -export CONFIG_MALI_MIDGARD?=m - -ifneq ($(CONFIG_MALI_MIDGARD),n) -export CONFIG_MALI_CSF_SUPPORT?=n -export CONFIG_MALI_KUTF?=m -export CONFIG_MALI_REAL_HW?=y - -# Handle default y/m in Kconfig -export CONFIG_MALI_BIFROST_GATOR_SUPPORT?=y -export CONFIG_MALI_BIFROST_DEVFREQ?=n -ifneq ($(CONFIG_PM_DEVFREQ),n) -export CONFIG_MALI_BIFROST_DEVFREQ?=y +ifeq ($(KDIR),) + $(error Must specify KDIR to point to the kernel to target)) endif -DEFINES += -DCONFIG_MALI_MIDGARD=$(CONFIG_MALI_MIDGARD) \ - -DCONFIG_MALI_CSF_SUPPORT=$(CONFIG_MALI_CSF_SUPPORT) \ - -DCONFIG_MALI_KUTF=$(CONFIG_MALI_KUTF) \ - -DCONFIG_MALI_REAL_HW=$(CONFIG_MALI_REAL_HW) \ - -DCONFIG_MALI_GATOR_SUPPORT=$(CONFIG_MALI_BIFROST_GATOR_SUPPORT) \ - -DCONFIG_MALI_DEVFREQ=$(CONFIG_MALI_BIFROST_DEVFREQ) +# +# Default configuration values +# +# Dependency resolution is done through statements as Kconfig +# is not supported for out-of-tree builds. +# -export DEFINES +CONFIG_MALI_BIFROST ?= m +ifeq ($(CONFIG_MALI_BIFROST),m) + CONFIG_MALI_BIFROST_GATOR_SUPPORT ?= y + CONFIG_MALI_ARBITRATION ?= n + CONFIG_MALI_PARTITION_MANAGER ?= n -endif + ifneq ($(CONFIG_MALI_BIFROST_NO_MALI),y) + # Prevent misuse when CONFIG_MALI_BIFROST_NO_MALI=y + CONFIG_MALI_REAL_HW ?= y + endif + + ifeq ($(CONFIG_MALI_BIFROST_DVFS),y) + # Prevent misuse when CONFIG_MALI_BIFROST_DVFS=y + CONFIG_MALI_BIFROST_DEVFREQ ?= n + else + CONFIG_MALI_BIFROST_DEVFREQ ?= y + endif + + ifeq ($(CONFIG_MALI_DMA_BUF_MAP_ON_DEMAND), y) + # Prevent misuse when CONFIG_MALI_DMA_BUF_MAP_ON_DEMAND=y + CONFIG_MALI_DMA_BUF_LEGACY_COMPAT = n + endif + + ifeq ($(CONFIG_BSP_HAS_HYPERVISOR),y) + ifneq ($(CONFIG_MALI_ARBITRATION), n) + CONFIG_MALI_XEN ?= m + endif + endif + + # + # Expert/Debug/Test released configurations + # + ifeq ($(CONFIG_MALI_BIFROST_EXPERT), y) + ifeq ($(CONFIG_MALI_BIFROST_NO_MALI), y) + CONFIG_MALI_REAL_HW = n + else + # Prevent misuse when CONFIG_MALI_BIFROST_NO_MALI=n + CONFIG_MALI_REAL_HW = y + CONFIG_MALI_BIFROST_ERROR_INJECT = n + endif + + ifeq ($(CONFIG_MALI_HW_ERRATA_1485982_NOT_AFFECTED), y) + # Prevent misuse when CONFIG_MALI_HW_ERRATA_1485982_NOT_AFFECTED=y + CONFIG_MALI_HW_ERRATA_1485982_USE_CLOCK_ALTERNATIVE = n + endif + + ifeq ($(CONFIG_MALI_BIFROST_DEBUG), y) + CONFIG_MALI_BIFROST_ENABLE_TRACE ?= y + CONFIG_MALI_BIFROST_SYSTEM_TRACE ?= y + + ifeq ($(CONFIG_SYNC), y) + CONFIG_MALI_BIFROST_FENCE_DEBUG ?= y + else + ifeq ($(CONFIG_SYNC_FILE), y) + CONFIG_MALI_BIFROST_FENCE_DEBUG ?= y + else + CONFIG_MALI_BIFROST_FENCE_DEBUG = n + endif + endif + else + # Prevent misuse when CONFIG_MALI_BIFROST_DEBUG=n + CONFIG_MALI_BIFROST_ENABLE_TRACE = n + CONFIG_MALI_BIFROST_SYSTEM_TRACE = n + CONFIG_MALI_BIFROST_FENCE_DEBUG = n + endif + else + # Prevent misuse when CONFIG_MALI_BIFROST_EXPERT=n + CONFIG_MALI_CORESTACK = n + CONFIG_MALI_2MB_ALLOC = n + CONFIG_MALI_PWRSOFT_765 = n + CONFIG_MALI_MEMORY_FULLY_BACKED = n + CONFIG_MALI_JOB_DUMP = n + CONFIG_MALI_BIFROST_NO_MALI = n + CONFIG_MALI_REAL_HW = y + CONFIG_MALI_BIFROST_ERROR_INJECT = n + CONFIG_MALI_HW_ERRATA_1485982_NOT_AFFECTED = n + CONFIG_MALI_HW_ERRATA_1485982_USE_CLOCK_ALTERNATIVE = n + CONFIG_MALI_PRFCNT_SET_SELECT_VIA_DEBUG_FS = n + CONFIG_MALI_BIFROST_DEBUG = n + CONFIG_MALI_BIFROST_ENABLE_TRACE = n + CONFIG_MALI_BIFROST_SYSTEM_TRACE = n + CONFIG_MALI_BIFROST_FENCE_DEBUG = n + endif + + ifeq ($(CONFIG_MALI_BIFROST_DEBUG), y) + CONFIG_MALI_KUTF ?= y + ifeq ($(CONFIG_MALI_KUTF), y) + CONFIG_MALI_KUTF_IRQ_TEST ?= y + CONFIG_MALI_KUTF_CLK_RATE_TRACE ?= y + else + # Prevent misuse when CONFIG_MALI_KUTF=n + CONFIG_MALI_KUTF_IRQ_TEST = n + CONFIG_MALI_KUTF_CLK_RATE_TRACE = n + endif + else + # Prevent misuse when CONFIG_MALI_BIFROST_DEBUG=n + CONFIG_MALI_KUTF = n + CONFIG_MALI_KUTF_IRQ_TEST = n + CONFIG_MALI_KUTF_CLK_RATE_TRACE = n + endif +else + # Prevent misuse when CONFIG_MALI_BIFROST=n + CONFIG_MALI_ARBITRATION = n + CONFIG_MALI_KUTF = n + CONFIG_MALI_KUTF_IRQ_TEST = n + CONFIG_MALI_KUTF_CLK_RATE_TRACE = n endif -KBASE_PATH_RELATIVE = $(CURDIR) +# All Mali CONFIG should be listed here +CONFIGS := \ + CONFIG_MALI_BIFROST \ + CONFIG_MALI_CSF_SUPPORT \ + CONFIG_MALI_BIFROST_GATOR_SUPPORT \ + CONFIG_MALI_BIFROST_DMA_FENCE \ + CONFIG_MALI_ARBITER_SUPPORT \ + CONFIG_MALI_ARBITRATION \ + CONFIG_MALI_PARTITION_MANAGER \ + CONFIG_MALI_REAL_HW \ + CONFIG_MALI_GEM5_BUILD \ + CONFIG_MALI_BIFROST_DEVFREQ \ + CONFIG_MALI_BIFROST_DVFS \ + CONFIG_MALI_DMA_BUF_MAP_ON_DEMAND \ + CONFIG_MALI_DMA_BUF_LEGACY_COMPAT \ + CONFIG_MALI_BIFROST_EXPERT \ + CONFIG_MALI_CORESTACK \ + CONFIG_MALI_2MB_ALLOC \ + CONFIG_MALI_PWRSOFT_765 \ + CONFIG_MALI_MEMORY_FULLY_BACKED \ + CONFIG_MALI_JOB_DUMP \ + CONFIG_MALI_BIFROST_NO_MALI \ + CONFIG_MALI_BIFROST_ERROR_INJECT \ + CONFIG_MALI_HW_ERRATA_1485982_NOT_AFFECTED \ + CONFIG_MALI_HW_ERRATA_1485982_USE_CLOCK_ALTERNATIVE \ + CONFIG_MALI_PRFCNT_SET_PRIMARY \ + CONFIG_MALI_BIFROST_PRFCNT_SET_SECONDARY \ + CONFIG_MALI_PRFCNT_SET_TERTIARY \ + CONFIG_MALI_PRFCNT_SET_SELECT_VIA_DEBUG_FS \ + CONFIG_MALI_BIFROST_DEBUG \ + CONFIG_MALI_BIFROST_ENABLE_TRACE \ + CONFIG_MALI_BIFROST_SYSTEM_TRACE \ + CONFIG_MALI_BIFROST_FENCE_DEBUG \ + CONFIG_MALI_KUTF \ + CONFIG_MALI_KUTF_IRQ_TEST \ + CONFIG_MALI_KUTF_CLK_RATE_TRACE \ + CONFIG_MALI_XEN -# we get the symbols from modules using KBUILD_EXTRA_SYMBOLS to prevent warnings about unknown functions +# +# MAKE_ARGS to pass the custom CONFIGs on out-of-tree build +# +# Generate the list of CONFIGs and values. +# $(value config) is the name of the CONFIG option. +# $(value $(value config)) is its value (y, m). +# When the CONFIG is not set to y or m, it defaults to n. +MAKE_ARGS := $(foreach config,$(CONFIGS), \ + $(if $(filter y m,$(value $(value config))), \ + $(value config)=$(value $(value config)), \ + $(value config)=n)) + +# +# EXTRA_CFLAGS to define the custom CONFIGs on out-of-tree build +# +# Generate the list of CONFIGs defines with values from CONFIGS. +# $(value config) is the name of the CONFIG option. +# When set to y or m, the CONFIG gets defined to 1. +EXTRA_CFLAGS := $(foreach config,$(CONFIGS), \ + $(if $(filter y m,$(value $(value config))), \ + -D$(value config)=1)) + +# +# KBUILD_EXTRA_SYMBOLS to prevent warnings about unknown functions +# + all: - $(MAKE) -C $(KDIR) M=$(CURDIR) EXTRA_CFLAGS="-I$(CURDIR)/../../../../include -I$(CURDIR)/../../../../tests/include $(SCONS_CFLAGS)" $(SCONS_CONFIGS) KBUILD_EXTRA_SYMBOLS="$(EXTRA_SYMBOLS)" modules + $(MAKE) -C $(KDIR) M=$(CURDIR) $(MAKE_ARGS) EXTRA_CFLAGS="$(EXTRA_CFLAGS)" KBUILD_EXTRA_SYMBOLS="$(EXTRA_SYMBOLS)" modules modules_install: - $(MAKE) -C $(KDIR) M=$(CURDIR) modules_install + $(MAKE) -C $(KDIR) M=$(CURDIR) $(MAKE_ARGS) modules_install clean: - $(MAKE) -C $(KDIR) M=$(CURDIR) clean + $(MAKE) -C $(KDIR) M=$(CURDIR) $(MAKE_ARGS) clean diff --git a/drivers/gpu/arm/bifrost/Mconfig b/drivers/gpu/arm/bifrost/Mconfig index 7d6695d5eae7..83bd0ad0d682 100644 --- a/drivers/gpu/arm/bifrost/Mconfig +++ b/drivers/gpu/arm/bifrost/Mconfig @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # # (C) COPYRIGHT 2012-2021 ARM Limited. All rights reserved. # @@ -27,13 +27,52 @@ menuconfig MALI_BIFROST To compile this driver as a module, choose M here: this will generate a single module, called mali_kbase. -config MALI_CSF_SUPPORT - bool "Mali CSF based GPU support" +config MALI_PLATFORM_NAME depends on MALI_BIFROST - default n + string "Platform name" + default "hisilicon" if PLATFORM_HIKEY960 + default "hisilicon" if PLATFORM_HIKEY970 + default "devicetree" + help + Enter the name of the desired platform configuration directory to + include in the build. 'platform/$(MALI_PLATFORM_NAME)/Makefile' must + exist. + + When PLATFORM_CUSTOM is set, this needs to be set manually to + pick up the desired platform files. + +config MALI_REAL_HW + bool + depends on MALI_BIFROST + default y + default n if NO_MALI + +config MALI_CSF_SUPPORT + bool "Enable Mali CSF based GPU support" + depends on MALI_BIFROST + default y if GPU_HAS_CSF help Enables support for CSF based GPUs. +config MALI_BIFROST_DEVFREQ + bool "Enable devfreq support for Mali" + depends on MALI_BIFROST + default y if PLATFORM_JUNO + default y if PLATFORM_CUSTOM + help + Support devfreq for Mali. + + Using the devfreq framework and, by default, the simple on-demand + governor, the frequency of Mali will be dynamically selected from the + available OPPs. + +config MALI_BIFROST_DVFS + bool "Enable legacy DVFS" + depends on MALI_BIFROST && !MALI_BIFROST_DEVFREQ + default n + help + Choose this option to enable legacy DVFS in the Mali Midgard DDK. + config MALI_BIFROST_GATOR_SUPPORT bool "Enable Streamline tracing support" depends on MALI_BIFROST && !BACKEND_USER @@ -42,35 +81,17 @@ config MALI_BIFROST_GATOR_SUPPORT Enables kbase tracing used by the Arm Streamline Performance Analyzer. The tracepoints are used to derive GPU activity charts in Streamline. -config MALI_BIFROST_DVFS - bool "Enable legacy DVFS" - depends on MALI_BIFROST && !MALI_BIFROST_DEVFREQ - default n - help - Choose this option to enable legacy DVFS in the Mali Midgard DDK. - config MALI_BIFROST_ENABLE_TRACE bool "Enable kbase tracing" + depends on MALI_BIFROST default y if MALI_BIFROST_DEBUG default n help - Enables tracing in kbase. Trace log available through + Enables tracing in kbase. Trace log available through the "mali_trace" debugfs file, when the CONFIG_DEBUG_FS is enabled -config MALI_BIFROST_DEVFREQ - bool "devfreq support for Mali" - depends on MALI_BIFROST - default y if PLATFORM_JUNO - default y if PLATFORM_CUSTOM - help - Support devfreq for Mali. - - Using the devfreq framework and, by default, the simpleondemand - governor, the frequency of Mali will be dynamically selected from the - available OPPs. - config MALI_BIFROST_DMA_FENCE - bool "DMA_BUF fence support for Mali" + bool "Enable DMA_BUF fence support for Mali" depends on MALI_BIFROST default n help @@ -79,23 +100,9 @@ config MALI_BIFROST_DMA_FENCE This option should only be enabled if the Linux Kernel has built in support for DMA_BUF fences. -config MALI_PLATFORM_NAME - depends on MALI_BIFROST - string "Platform name" - default "hisilicon" if PLATFORM_HIKEY960 - default "hisilicon" if PLATFORM_HIKEY970 - default "devicetree" - help - Enter the name of the desired platform configuration directory to - include in the build. 'platform/$(MALI_PLATFORM_NAME)/Kbuild' must - exist. - - When PLATFORM_CUSTOM is set, this needs to be set manually to - pick up the desired platform files. - config MALI_ARBITER_SUPPORT bool "Enable arbiter support for Mali" - depends on MALI_BIFROST && !GPU_HAS_CSF + depends on MALI_BIFROST && !MALI_CSF_SUPPORT default n help Enable support for the arbiter interface in the driver. @@ -104,18 +111,68 @@ config MALI_ARBITER_SUPPORT If unsure, say N. -# MALI_BIFROST_EXPERT configuration options +config DMA_BUF_SYNC_IOCTL_SUPPORTED + bool "Enable Kernel DMA buffers support DMA_BUF_IOCTL_SYNC" + depends on MALI_BIFROST && BACKEND_KERNEL + default y + +config MALI_DMA_BUF_MAP_ON_DEMAND + bool "Enable map imported dma-bufs on demand" + depends on MALI_BIFROST + default n + default y if !DMA_BUF_SYNC_IOCTL_SUPPORTED + help + This option caused kbase to set up the GPU mapping of imported + dma-buf when needed to run atoms. This is the legacy behavior. + + This is intended for testing and the option will get removed in the + future. + +config MALI_DMA_BUF_LEGACY_COMPAT + bool "Enable legacy compatibility cache flush on dma-buf map" + depends on MALI_BIFROST && !MALI_DMA_BUF_MAP_ON_DEMAND + default n + help + This option enables compatibility with legacy dma-buf mapping + behavior, then the dma-buf is mapped on import, by adding cache + maintenance where MALI_DMA_BUF_MAP_ON_DEMAND would do the mapping, + including a cache flush. + + This option might work-around issues related to missing cache + flushes in other drivers. This only has an effect for clients using + UK 11.18 or older. For later UK versions it is not possible. menuconfig MALI_BIFROST_EXPERT depends on MALI_BIFROST bool "Enable Expert Settings" default y help - Enabling this option and modifying the default settings may produce a driver with performance or - other limitations. + Enabling this option and modifying the default settings may produce + a driver with performance or other limitations. + +config MALI_2MB_ALLOC + bool "Attempt to allocate 2MB pages" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT + default n + help + Rather than allocating all GPU memory page-by-page, attempt to + allocate 2MB pages from the kernel. This reduces TLB pressure and + helps to prevent memory fragmentation. + + If in doubt, say N + +config MALI_MEMORY_FULLY_BACKED + bool "Enable memory fully physically-backed" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT + default n + help + This option enables full physical backing of all virtual + memory allocations in the kernel. Notice that this build + option only affects allocations of grow-on-GPU-page-fault + memory. config MALI_CORESTACK - bool "Support controlling power to the GPU core stack" + bool "Enable support of GPU core stack power control" depends on MALI_BIFROST && MALI_BIFROST_EXPERT default n help @@ -127,39 +184,16 @@ config MALI_CORESTACK If unsure, say N. -config MALI_BIFROST_DEBUG - bool "Debug build" - depends on MALI_BIFROST && MALI_BIFROST_EXPERT - default y if DEBUG - default n - help - Select this option for increased checking and reporting of errors. - -config MALI_BIFROST_FENCE_DEBUG - bool "Debug sync fence usage" - depends on MALI_BIFROST && MALI_BIFROST_EXPERT - default y if MALI_BIFROST_DEBUG - help - Select this option to enable additional checking and reporting on the - use of sync fences in the Mali driver. - - This will add a 3s timeout to all sync fence waits in the Mali - driver, so that when work for Mali has been waiting on a sync fence - for a long time a debug message will be printed, detailing what fence - is causing the block, and which dependent Mali atoms are blocked as a - result of this. - - The timeout can be changed at runtime through the js_soft_timeout - device attribute, where the timeout is specified in milliseconds. - choice prompt "Error injection level" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT default MALI_ERROR_INJECT_NONE help Enables insertion of errors to test module failure and recovery mechanisms. config MALI_ERROR_INJECT_NONE bool "disabled" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT help Error injection is disabled. @@ -179,14 +213,49 @@ endchoice config MALI_ERROR_INJECT_ON string + depends on MALI_BIFROST && MALI_BIFROST_EXPERT default "0" if MALI_ERROR_INJECT_NONE default "1" if MALI_ERROR_INJECT_TRACK_LIST default "2" if MALI_ERROR_INJECT_RANDOM config MALI_BIFROST_ERROR_INJECT bool + depends on MALI_BIFROST && MALI_BIFROST_EXPERT default y if !MALI_ERROR_INJECT_NONE +config MALI_GEM5_BUILD + bool "Enable build of Mali kernel driver for GEM5" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT + default n + help + This option is to do a Mali GEM5 build. + If unsure, say N. + +config MALI_BIFROST_DEBUG + bool "Enable debug build" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT + default y if DEBUG + default n + help + Select this option for increased checking and reporting of errors. + +config MALI_BIFROST_FENCE_DEBUG + bool "Enable debug sync fence usage" + depends on MALI_BIFROST && MALI_BIFROST_EXPERT + default y if MALI_BIFROST_DEBUG + help + Select this option to enable additional checking and reporting on the + use of sync fences in the Mali driver. + + This will add a 3s timeout to all sync fence waits in the Mali + driver, so that when work for Mali has been waiting on a sync fence + for a long time a debug message will be printed, detailing what fence + is causing the block, and which dependent Mali atoms are blocked as a + result of this. + + The timeout can be changed at runtime through the js_soft_timeout + device attribute, where the timeout is specified in milliseconds. + config MALI_BIFROST_SYSTEM_TRACE bool "Enable system event tracing support" depends on MALI_BIFROST && MALI_BIFROST_EXPERT @@ -198,56 +267,35 @@ config MALI_BIFROST_SYSTEM_TRACE minimal overhead when not in use. Enable only if you know what you are doing. -config MALI_2MB_ALLOC - bool "Attempt to allocate 2MB pages" +# Instrumentation options. + +# config MALI_PRFCNT_SET_PRIMARY exists in the Kernel Kconfig but is configured using CINSTR_PRIMARY_HWC in Mconfig. +# config MALI_BIFROST_PRFCNT_SET_SECONDARY exists in the Kernel Kconfig but is configured using CINSTR_SECONDARY_HWC in Mconfig. +# config MALI_PRFCNT_SET_TERTIARY exists in the Kernel Kconfig but is configured using CINSTR_TERTIARY_HWC in Mconfig. +# config MALI_PRFCNT_SET_SELECT_VIA_DEBUG_FS exists in the Kernel Kconfig but is configured using CINSTR_HWC_SET_SELECT_VIA_DEBUG_FS in Mconfig. + +config MALI_JOB_DUMP + bool "Enable system level support needed for job dumping" depends on MALI_BIFROST && MALI_BIFROST_EXPERT default n help - Rather than allocating all GPU memory page-by-page, attempt to - allocate 2MB pages from the kernel. This reduces TLB pressure and - helps to prevent memory fragmentation. - - If in doubt, say N + Choose this option to enable system level support needed for + job dumping. This is typically used for instrumentation but has + minimal overhead when not in use. Enable only if you know what + you are doing. config MALI_PWRSOFT_765 - bool "PWRSOFT-765 ticket" + bool "Enable workaround for PWRSOFT-765" depends on MALI_BIFROST && MALI_BIFROST_EXPERT default n help - PWRSOFT-765 fixes devfreq cooling devices issues. However, they are - not merged in mainline kernel yet. So this define helps to guard those - parts of the code. + PWRSOFT-765 fixes devfreq cooling devices issues. The fix was merged + in kernel v4.10, however if backported into the kernel then this + option must be manually selected. -config MALI_MEMORY_FULLY_BACKED - bool "Memory fully physically-backed" - default n - help - This option enables full backing of all virtual memory allocations - for the kernel. This only affects grow-on-GPU-page-fault memory. + If using kernel >= v4.10 then say N, otherwise if devfreq cooling + changes have been backported say Y to avoid compilation errors. -config MALI_DMA_BUF_MAP_ON_DEMAND - bool "Map imported dma-bufs on demand" - depends on MALI_BIFROST - default n - default y if !DMA_BUF_SYNC_IOCTL_SUPPORTED - help - This option caused kbase to set up the GPU mapping of imported - dma-buf when needed to run atoms. This is the legacy behaviour. - -config MALI_DMA_BUF_LEGACY_COMPAT - bool "Enable legacy compatibility cache flush on dma-buf map" - depends on MALI_BIFROST && !MALI_DMA_BUF_MAP_ON_DEMAND - default n - help - This option enables compatibility with legacy dma-buf mapping - behavior, then the dma-buf is mapped on import, by adding cache - maintenance where MALI_DMA_BUF_MAP_ON_DEMAND would do the mapping, - including a cache flush. - -config MALI_REAL_HW - bool - default y - default n if NO_MALI config MALI_HW_ERRATA_1485982_NOT_AFFECTED bool "Disable workaround for BASE_HW_ISSUE_GPU2017_1336" @@ -273,20 +321,6 @@ config MALI_HW_ERRATA_1485982_USE_CLOCK_ALTERNATIVE tree using the property, opp-mali-errata-1485982. Otherwise the slowest clock will be selected. -config MALI_GEM5_BUILD - bool "Enable build of Mali kernel driver for GEM5" - depends on MALI_BIFROST - default n - help - This option is to do a Mali GEM5 build. - If unsure, say N. - -# Instrumentation options. - -# config MALI_JOB_DUMP exists in the Kernel Kconfig but is configured using CINSTR_JOB_DUMP in Mconfig. -# config MALI_PRFCNT_SET_PRIMARY exists in the Kernel Kconfig but is configured using CINSTR_PRIMARY_HWC in Mconfig. -# config MALI_BIFROST_PRFCNT_SET_SECONDARY exists in the Kernel Kconfig but is configured using CINSTR_SECONDARY_HWC in Mconfig. -# config MALI_PRFCNT_SET_TERTIARY exists in the Kernel Kconfig but is configured using CINSTR_TERTIARY_HWC in Mconfig. -# config MALI_PRFCNT_SET_SELECT_VIA_DEBUG_FS exists in the Kernel Kconfig but is configured using CINSTR_HWC_SET_SELECT_VIA_DEBUG_FS in Mconfig. +source "kernel/drivers/gpu/arm/midgard/arbitration/Mconfig" source "kernel/drivers/gpu/arm/midgard/tests/Mconfig" diff --git a/drivers/gpu/arm/bifrost/arbiter/Kbuild b/drivers/gpu/arm/bifrost/arbiter/Kbuild index 4c04cabce93c..2e6b111441ca 100644 --- a/drivers/gpu/arm/bifrost/arbiter/Kbuild +++ b/drivers/gpu/arm/bifrost/arbiter/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -19,5 +19,5 @@ # bifrost_kbase-y += \ - arbiter/mali_kbase_arbif.o \ - arbiter/mali_kbase_arbiter_pm.o + arbiter/mali_kbase_arbif.o \ + arbiter/mali_kbase_arbiter_pm.o diff --git a/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbif.c b/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbif.c index 7d6ab0cd95c7..64e11ce53625 100644 --- a/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbif.c +++ b/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbif.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -170,11 +170,15 @@ static void on_gpu_lost(struct device *dev) * * Initialise Kbase Arbiter interface and assign callback functions. * - * Return: 0 on success else a Linux error code + * Return: + * * 0 - the interface was initialized or was not specified + * * in the device tree. + * * -EFAULT - the interface was specified but failed to initialize. + * * -EPROBE_DEFER - module dependencies are not yet available. */ int kbase_arbif_init(struct kbase_device *kbdev) { -#ifdef CONFIG_OF +#if IS_ENABLED(CONFIG_OF) struct arbiter_if_arb_vm_ops ops; struct arbiter_if_dev *arb_if; struct device_node *arbiter_if_node; @@ -218,8 +222,8 @@ int kbase_arbif_init(struct kbase_device *kbdev) ops.arb_vm_max_config = on_max_config; ops.arb_vm_update_freq = on_update_freq; - kbdev->arb.arb_freq.arb_freq = 0; + kbdev->arb.arb_freq.freq_updated = false; mutex_init(&kbdev->arb.arb_freq.arb_freq_lock); /* register kbase arbiter_if callbacks */ @@ -229,6 +233,8 @@ int kbase_arbif_init(struct kbase_device *kbdev) if (err) { dev_err(&pdev->dev, "Failed to register with arbiter\n"); module_put(pdev->dev.driver->owner); + if (err != -EPROBE_DEFER) + err = -EFAULT; return err; } } @@ -307,6 +313,8 @@ void kbase_arbif_gpu_stopped(struct kbase_device *kbdev, u8 gpu_required) if (arb_if && arb_if->vm_ops.vm_arb_gpu_stopped) { dev_dbg(kbdev->dev, "%s\n", __func__); KBASE_TLSTREAM_TL_ARBITER_STOPPED(kbdev, kbdev); + if (gpu_required) + KBASE_TLSTREAM_TL_ARBITER_REQUESTED(kbdev, kbdev); arb_if->vm_ops.vm_arb_gpu_stopped(arb_if, gpu_required); } } diff --git a/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbif.h b/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbif.h index 710559c4fe02..701ffd42f6f7 100644 --- a/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbif.h +++ b/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbif.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -57,8 +57,11 @@ enum kbase_arbif_evt { * Initialize the arbiter interface and also determines * if Arbiter functionality is required. * - * Return: 0 if the Arbiter interface was successfully initialized or the - * Arbiter was not required. + * Return: + * * 0 - the interface was initialized or was not specified + * * in the device tree. + * * -EFAULT - the interface was specified but failed to initialize. + * * -EPROBE_DEFER - module dependencies are not yet available. */ int kbase_arbif_init(struct kbase_device *kbdev); diff --git a/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_defs.h b/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_defs.h index 586c5d4f69db..570a82afa0ce 100644 --- a/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_defs.h +++ b/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_defs.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_interface.h b/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_interface.h index 84389e828f4d..c0137f7adc9d 100644 --- a/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_interface.h +++ b/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_interface.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -132,6 +132,11 @@ struct arbiter_if_vm_arb_ops { * @dev: The device structure to supply in the callbacks. * @ops: The callbacks that the device driver supports * (none are optional). + * + * Return: + * * 0 - successful. + * * -EINVAL - invalid argument. + * * -EPROBE_DEFER - module dependencies are not yet available. */ int (*vm_arb_register_dev)(struct arbiter_if_dev *arbif_dev, struct device *dev, struct arbiter_if_arb_vm_ops *ops); diff --git a/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_pm.c b/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_pm.c index 456cc70753cd..5c75686254ed 100644 --- a/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_pm.c +++ b/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_pm.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -27,9 +27,9 @@ #include #include #include -#include +#include #include -#include +#include #include #include @@ -37,6 +37,7 @@ * after the following time (in milliseconds) has ellapsed. */ #define GPU_REQUEST_TIMEOUT 1000 +#define KHZ_TO_HZ 1000 #define MAX_L2_SLICES_MASK 0xFF @@ -528,8 +529,16 @@ int kbase_arbiter_pm_gpu_assigned(struct kbase_device *kbdev) static void kbase_arbiter_pm_vm_gpu_start(struct kbase_device *kbdev) { struct kbase_arbiter_vm_state *arb_vm_state = kbdev->pm.arb_vm_state; + bool freq_updated = false; lockdep_assert_held(&arb_vm_state->vm_state_lock); + mutex_lock(&kbdev->arb.arb_freq.arb_freq_lock); + if (kbdev->arb.arb_freq.freq_updated) { + kbdev->arb.arb_freq.freq_updated = false; + freq_updated = true; + } + mutex_unlock(&kbdev->arb.arb_freq.arb_freq_lock); + cancel_request_timer(kbdev); switch (arb_vm_state->vm_state) { case KBASE_VM_STATE_INITIALIZING: @@ -555,9 +564,16 @@ static void kbase_arbiter_pm_vm_gpu_start(struct kbase_device *kbdev) kbase_arbiter_pm_vm_set_state(kbdev, KBASE_VM_STATE_SUSPENDED); break; default: - dev_warn(kbdev->dev, - "GPU_GRANTED when not expected - state %s\n", - kbase_arbiter_pm_vm_state_str(arb_vm_state->vm_state)); + /* + * GPU_GRANTED can be received when there is a frequency update + * Only show a warning if received in an unexpected state + * without a frequency update + */ + if (!freq_updated) + dev_warn(kbdev->dev, + "GPU_GRANTED when not expected - state %s\n", + kbase_arbiter_pm_vm_state_str( + arb_vm_state->vm_state)); break; } } @@ -1005,13 +1021,25 @@ int kbase_arbiter_pm_ctx_active_handle_suspend(struct kbase_device *kbdev, * kbase_arbiter_pm_update_gpu_freq() - Updates GPU clock frequency received * from arbiter. * @arb_freq - Pointer to struchture holding GPU clock frequenecy data - * @freq - New frequency value + * @freq - New frequency value in KHz */ void kbase_arbiter_pm_update_gpu_freq(struct kbase_arbiter_freq *arb_freq, - uint32_t freq) + uint32_t freq) { + struct kbase_gpu_clk_notifier_data ndata; + mutex_lock(&arb_freq->arb_freq_lock); - arb_freq->arb_freq = freq; + if (arb_freq->arb_freq != freq) { + ndata.new_rate = freq * KHZ_TO_HZ; + ndata.old_rate = arb_freq->arb_freq * KHZ_TO_HZ; + ndata.gpu_clk_handle = arb_freq; + arb_freq->arb_freq = freq; + arb_freq->freq_updated = true; + if (arb_freq->nb) + arb_freq->nb->notifier_call(arb_freq->nb, + POST_RATE_CHANGE, &ndata); + } + mutex_unlock(&arb_freq->arb_freq_lock); } @@ -1046,14 +1074,64 @@ static unsigned long get_arb_gpu_clk_rate(struct kbase_device *kbdev, (struct kbase_arbiter_freq *) gpu_clk_handle; mutex_lock(&arb_dev_freq->arb_freq_lock); - freq = arb_dev_freq->arb_freq; + /* Convert from KHz to Hz */ + freq = arb_dev_freq->arb_freq * KHZ_TO_HZ; mutex_unlock(&arb_dev_freq->arb_freq_lock); return freq; } +/** + * arb_gpu_clk_notifier_register() - Register a clock rate change notifier. + * @kbdev - kbase_device pointer + * @gpu_clk_handle - Handle unique to the enumerated GPU clock + * @nb - notifier block containing the callback function pointer + * + * Returns 0 on success, negative error code otherwise. + * + * This function registers a callback function that is invoked whenever the + * frequency of the clock corresponding to @gpu_clk_handle changes. + */ +static int arb_gpu_clk_notifier_register(struct kbase_device *kbdev, + void *gpu_clk_handle, struct notifier_block *nb) +{ + int ret = 0; + struct kbase_arbiter_freq *arb_dev_freq = + (struct kbase_arbiter_freq *)gpu_clk_handle; + + if (!arb_dev_freq->nb) + arb_dev_freq->nb = nb; + else + ret = -EBUSY; + + return ret; +} + +/** + * gpu_clk_notifier_unregister() - Unregister clock rate change notifier + * @kbdev - kbase_device pointer + * @gpu_clk_handle - Handle unique to the enumerated GPU clock + * @nb - notifier block containing the callback function pointer + * + * This function pointer is used to unregister a callback function that + * was previously registered to get notified of a frequency change of the + * clock corresponding to @gpu_clk_handle. + */ +static void arb_gpu_clk_notifier_unregister(struct kbase_device *kbdev, + void *gpu_clk_handle, struct notifier_block *nb) +{ + struct kbase_arbiter_freq *arb_dev_freq = + (struct kbase_arbiter_freq *)gpu_clk_handle; + if (arb_dev_freq->nb == nb) { + arb_dev_freq->nb = NULL; + } else { + dev_err(kbdev->dev, "%s - notifier did not match\n", + __func__); + } +} + struct kbase_clk_rate_trace_op_conf arb_clk_rate_trace_ops = { .get_gpu_clk_rate = get_arb_gpu_clk_rate, .enumerate_gpu_clk = enumerate_arb_gpu_clk, - .gpu_clk_notifier_register = NULL, - .gpu_clk_notifier_unregister = NULL + .gpu_clk_notifier_register = arb_gpu_clk_notifier_register, + .gpu_clk_notifier_unregister = arb_gpu_clk_notifier_unregister }; diff --git a/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_pm.h b/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_pm.h index 0f74b631c76e..1f570bbe1d6e 100644 --- a/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_pm.h +++ b/drivers/gpu/arm/bifrost/arbiter/mali_kbase_arbiter_pm.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -168,15 +168,27 @@ extern struct kbase_clk_rate_trace_op_conf arb_clk_rate_trace_ops; /** * struct kbase_arbiter_freq - Holding the GPU clock frequency data retrieved * from arbiter - * @arb_freq: GPU clock frequency value - * @arb_freq_lock: Mutex protecting access to arbfreq value + * @arb_freq: GPU clock frequency value + * @arb_freq_lock: Mutex protecting access to arbfreq value + * @nb: Notifier block to receive rate change callbacks + * @freq_updated: Flag to indicate whether a frequency changed has just been + * communicated to avoid "GPU_GRANTED when not expected" warning */ struct kbase_arbiter_freq { uint32_t arb_freq; struct mutex arb_freq_lock; + struct notifier_block *nb; + bool freq_updated; }; +/** + * kbase_arbiter_pm_update_gpu_freq() - Update GPU frequency + * @arb_freq: Pointer to GPU clock frequency data + * @freq: The new frequency + * + * Updates the GPU frequency and triggers any notifications + */ void kbase_arbiter_pm_update_gpu_freq(struct kbase_arbiter_freq *arb_freq, - uint32_t freq); + uint32_t freq); #endif /*_MALI_KBASE_ARBITER_PM_H_ */ diff --git a/drivers/gpu/arm/bifrost/backend/gpu/Kbuild b/drivers/gpu/arm/bifrost/backend/gpu/Kbuild index 928766d65632..dab5449a225e 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/Kbuild +++ b/drivers/gpu/arm/bifrost/backend/gpu/Kbuild @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # # (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. # @@ -18,47 +18,32 @@ # # -BACKEND += \ - backend/gpu/mali_kbase_cache_policy_backend.c \ - backend/gpu/mali_kbase_gpuprops_backend.c \ - backend/gpu/mali_kbase_irq_linux.c \ - backend/gpu/mali_kbase_js_backend.c \ - backend/gpu/mali_kbase_pm_backend.c \ - backend/gpu/mali_kbase_pm_driver.c \ - backend/gpu/mali_kbase_pm_metrics.c \ - backend/gpu/mali_kbase_pm_ca.c \ - backend/gpu/mali_kbase_pm_always_on.c \ - backend/gpu/mali_kbase_pm_coarse_demand.c \ - backend/gpu/mali_kbase_pm_policy.c \ - backend/gpu/mali_kbase_time.c \ - backend/gpu/mali_kbase_l2_mmu_config.c \ - backend/gpu/mali_kbase_clk_rate_trace_mgr.c +bifrost_kbase-y += \ + backend/gpu/mali_kbase_cache_policy_backend.o \ + backend/gpu/mali_kbase_gpuprops_backend.o \ + backend/gpu/mali_kbase_irq_linux.o \ + backend/gpu/mali_kbase_js_backend.o \ + backend/gpu/mali_kbase_pm_backend.o \ + backend/gpu/mali_kbase_pm_driver.o \ + backend/gpu/mali_kbase_pm_metrics.o \ + backend/gpu/mali_kbase_pm_ca.o \ + backend/gpu/mali_kbase_pm_always_on.o \ + backend/gpu/mali_kbase_pm_coarse_demand.o \ + backend/gpu/mali_kbase_pm_policy.o \ + backend/gpu/mali_kbase_time.o \ + backend/gpu/mali_kbase_l2_mmu_config.o \ + backend/gpu/mali_kbase_clk_rate_trace_mgr.o -ifeq ($(MALI_USE_CSF),1) -# empty -else - BACKEND += \ - backend/gpu/mali_kbase_instr_backend.c \ - backend/gpu/mali_kbase_jm_as.c \ - backend/gpu/mali_kbase_debug_job_fault_backend.c \ - backend/gpu/mali_kbase_jm_hw.c \ - backend/gpu/mali_kbase_jm_rb.c +ifeq ($(MALI_USE_CSF),0) + bifrost_kbase-y += \ + backend/gpu/mali_kbase_instr_backend.o \ + backend/gpu/mali_kbase_jm_as.o \ + backend/gpu/mali_kbase_debug_job_fault_backend.o \ + backend/gpu/mali_kbase_jm_hw.o \ + backend/gpu/mali_kbase_jm_rb.o endif -ifeq ($(MALI_CUSTOMER_RELEASE),0) -BACKEND += \ - backend/gpu/mali_kbase_pm_always_on_demand.c -endif -ifeq ($(CONFIG_MALI_BIFROST_DEVFREQ),y) -BACKEND += \ - backend/gpu/mali_kbase_devfreq.c -endif +bifrost_kbase-$(CONFIG_MALI_BIFROST_DEVFREQ) += \ + backend/gpu/mali_kbase_devfreq.o -ifeq ($(CONFIG_MALI_BIFROST_NO_MALI),y) - # Dummy model - BACKEND += backend/gpu/mali_kbase_model_dummy.c - BACKEND += backend/gpu/mali_kbase_model_linux.c - # HW error simulation - BACKEND += backend/gpu/mali_kbase_model_error_generator.c -endif diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_backend_config.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_backend_config.h index a6bbdbbc150c..6924fdb8a608 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_backend_config.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_backend_config.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014-2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_cache_policy_backend.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_cache_policy_backend.c index fee946478667..e542ccf32659 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_cache_policy_backend.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_cache_policy_backend.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2014-2016, 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2016, 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_cache_policy_backend.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_cache_policy_backend.h index 53b9667cc669..5294c2c100a9 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_cache_policy_backend.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_cache_policy_backend.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2014-2016, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_clk_rate_trace_mgr.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_clk_rate_trace_mgr.c index 7076ab4f73ee..6ad0f58b47cb 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_clk_rate_trace_mgr.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_clk_rate_trace_mgr.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. @@ -27,7 +27,7 @@ #include #include #include -#include "mali_kbase_clk_rate_trace_mgr.h" +#include "backend/gpu/mali_kbase_clk_rate_trace_mgr.h" #ifdef CONFIG_TRACE_POWER_GPU_FREQUENCY #include @@ -299,8 +299,8 @@ void kbase_clk_rate_trace_manager_notify_all( kbdev = container_of(clk_rtm, struct kbase_device, pm.clk_rtm); - dev_dbg(kbdev->dev, "GPU clock %u rate changed to %lu", - clk_index, new_rate); + dev_dbg(kbdev->dev, "%s - GPU clock %u rate changed to %lu, pid: %d", + __func__, clk_index, new_rate, current->pid); /* Raise standard `power/gpu_frequency` ftrace event */ { diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_clk_rate_trace_mgr.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_clk_rate_trace_mgr.h index ba250bec4491..f7ec9d11ee94 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_clk_rate_trace_mgr.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_clk_rate_trace_mgr.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_debug_job_fault_backend.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_debug_job_fault_backend.c index b5ca79db5fad..e121b417f80d 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_debug_job_fault_backend.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_debug_job_fault_backend.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2012-2015, 2018-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2012-2015, 2018-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -23,7 +23,7 @@ #include #include "mali_kbase_debug_job_fault.h" -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) /*GPU_CONTROL_REG(r)*/ static int gpu_control_reg_snapshot[] = { diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_devfreq.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_devfreq.c index e64d273fa87f..bbf75bafd22f 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_devfreq.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_devfreq.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2014-2020 ARM Limited. All rights reserved. @@ -28,7 +28,7 @@ #include #include #include -#ifdef CONFIG_DEVFREQ_THERMAL +#if IS_ENABLED(CONFIG_DEVFREQ_THERMAL) #include #endif @@ -190,7 +190,7 @@ kbase_devfreq_target(struct device *dev, unsigned long *target_freq, u32 flags) dev_dbg(dev, "%lu-->%lu\n", kbdev->current_nominal_freq, nominal_freq); -#ifdef CONFIG_REGULATOR +#if IS_ENABLED(CONFIG_REGULATOR) /* Regulators and clocks work in pairs: every clock has a regulator, * and we never expect to have more regulators than clocks. * @@ -242,7 +242,7 @@ kbase_devfreq_target(struct device *dev, unsigned long *target_freq, u32 flags) } } -#ifdef CONFIG_REGULATOR +#if IS_ENABLED(CONFIG_REGULATOR) for (i = 0; i < kbdev->nr_clocks; i++) { if (kbdev->regulators[i] && kbdev->current_voltages[i] != volts[i] && @@ -381,18 +381,21 @@ static void kbase_devfreq_term_freq_table(struct kbase_device *kbdev) struct devfreq_dev_profile *dp = &kbdev->devfreq_profile; kfree(dp->freq_table); + dp->freq_table = NULL; } static void kbase_devfreq_term_core_mask_table(struct kbase_device *kbdev) { kfree(kbdev->devfreq_table); + kbdev->devfreq_table = NULL; } static void kbase_devfreq_exit(struct device *dev) { struct kbase_device *kbdev = dev_get_drvdata(dev); - kbase_devfreq_term_freq_table(kbdev); + if (kbdev) + kbase_devfreq_term_freq_table(kbdev); } static void kbasep_devfreq_read_suspend_clock(struct kbase_device *kbdev, @@ -464,7 +467,7 @@ static int kbase_devfreq_init_core_mask_table(struct kbase_device *kbdev) u64 core_mask, opp_freq, real_freqs[BASE_MAX_NR_CLOCKS_REGULATORS]; int err; -#ifdef CONFIG_REGULATOR +#if IS_ENABLED(CONFIG_REGULATOR) u32 opp_volts[BASE_MAX_NR_CLOCKS_REGULATORS]; #endif @@ -492,7 +495,7 @@ static int kbase_devfreq_init_core_mask_table(struct kbase_device *kbdev) err); continue; } -#ifdef CONFIG_REGULATOR +#if IS_ENABLED(CONFIG_REGULATOR) err = of_property_read_u32_array(node, "opp-microvolt", opp_volts, kbdev->nr_regulators); if (err < 0) { @@ -546,7 +549,7 @@ static int kbase_devfreq_init_core_mask_table(struct kbase_device *kbdev) kbdev->devfreq_table[i].real_freqs[j] = real_freqs[j]; } -#ifdef CONFIG_REGULATOR +#if IS_ENABLED(CONFIG_REGULATOR) if (kbdev->nr_regulators > 0) { int j; @@ -631,8 +634,12 @@ void kbase_devfreq_enqueue_work(struct kbase_device *kbdev, WARN_ON(work_type == DEVFREQ_WORK_NONE); spin_lock_irqsave(&kbdev->hwaccess_lock, flags); - kbdev->devfreq_queue.req_type = work_type; - queue_work(kbdev->devfreq_queue.workq, &kbdev->devfreq_queue.work); + /* Skip enqueuing a work if workqueue has already been terminated. */ + if (likely(kbdev->devfreq_queue.workq)) { + kbdev->devfreq_queue.req_type = work_type; + queue_work(kbdev->devfreq_queue.workq, + &kbdev->devfreq_queue.work); + } spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags); dev_dbg(kbdev->dev, "Enqueuing devfreq req: %s\n", kbase_devfreq_req_type_name(work_type)); @@ -654,11 +661,19 @@ static int kbase_devfreq_work_init(struct kbase_device *kbdev) static void kbase_devfreq_work_term(struct kbase_device *kbdev) { - destroy_workqueue(kbdev->devfreq_queue.workq); + unsigned long flags; + struct workqueue_struct *workq; + + spin_lock_irqsave(&kbdev->hwaccess_lock, flags); + workq = kbdev->devfreq_queue.workq; + kbdev->devfreq_queue.workq = NULL; + spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags); + + destroy_workqueue(workq); } static unsigned long kbase_devfreq_get_static_power(struct devfreq *devfreq, - unsigned long voltage) + unsigned long voltage) { struct device *dev = devfreq->dev.parent; struct kbase_device *kbdev = dev_get_drvdata(dev); @@ -718,14 +733,6 @@ int kbase_devfreq_init(struct kbase_device *kbdev) return err; } - /* Initialise devfreq suspend/resume workqueue */ - err = kbase_devfreq_work_init(kbdev); - if (err) { - kbase_devfreq_term_freq_table(kbdev); - dev_err(kbdev->dev, "Devfreq initialization failed"); - return err; - } - of_property_read_u32(np, "upthreshold", &ondemand_data.upthreshold); of_property_read_u32(np, "downdifferential", @@ -734,8 +741,21 @@ int kbase_devfreq_init(struct kbase_device *kbdev) "simple_ondemand", &ondemand_data); if (IS_ERR(kbdev->devfreq)) { err = PTR_ERR(kbdev->devfreq); - kbase_devfreq_work_term(kbdev); + kbdev->devfreq = NULL; + kbase_devfreq_term_core_mask_table(kbdev); kbase_devfreq_term_freq_table(kbdev); + dev_err(kbdev->dev, "Fail to add devfreq device(%d)\n", err); + return err; + } + + /* Initialize devfreq suspend/resume workqueue */ + err = kbase_devfreq_work_init(kbdev); + if (err) { + if (devfreq_remove_device(kbdev->devfreq)) + dev_err(kbdev->dev, "Fail to rm devfreq\n"); + kbdev->devfreq = NULL; + kbase_devfreq_term_core_mask_table(kbdev); + dev_err(kbdev->dev, "Fail to init devfreq workqueue\n"); return err; } @@ -759,12 +779,12 @@ int kbase_devfreq_init(struct kbase_device *kbdev) mali_mdevp.data = kbdev->devfreq; kbdev->mdev_info = rockchip_system_monitor_register(kbdev->dev, - &mali_mdevp); + &mali_mdevp); if (IS_ERR(kbdev->mdev_info)) { dev_dbg(kbdev->dev, "without system monitor\n"); - kbdev->mdev_info = NULL; + kbdev->mdev_info = NULL; } -#ifdef CONFIG_DEVFREQ_THERMAL +#if IS_ENABLED(CONFIG_DEVFREQ_THERMAL) if (of_find_compatible_node(kbdev->dev->of_node, NULL, "simple-power-model")) { of_property_read_u32(kbdev->dev->of_node, @@ -782,23 +802,23 @@ int kbase_devfreq_init(struct kbase_device *kbdev) if (!kbase_dcp->dyn_power_coeff) { err = -EINVAL; dev_err(kbdev->dev, "failed to get dynamic-coefficient\n"); - goto cooling_failed; + goto ipa_init_failed; } kbdev->devfreq_cooling = of_devfreq_cooling_register_power(kbdev->dev->of_node, - kbdev->devfreq, - kbase_dcp); + kbdev->devfreq, + kbase_dcp); if (IS_ERR(kbdev->devfreq_cooling)) { err = PTR_ERR(kbdev->devfreq_cooling); dev_err(kbdev->dev, "failed to register cooling device\n"); - goto cooling_failed; + goto cooling_reg_failed; } } else { err = kbase_ipa_init(kbdev); if (err) { dev_err(kbdev->dev, "IPA initialization failed\n"); - goto cooling_failed; + goto ipa_init_failed; } kbdev->devfreq_cooling = of_devfreq_cooling_register_power( @@ -808,26 +828,32 @@ int kbase_devfreq_init(struct kbase_device *kbdev) if (IS_ERR(kbdev->devfreq_cooling)) { err = PTR_ERR(kbdev->devfreq_cooling); dev_err(kbdev->dev, - "Failed to register cooling device (%d)\n", - err); - goto cooling_failed; - } + "Failed to register cooling device (%d)\n", + err); + goto cooling_reg_failed; + } + } #endif return 0; -#ifdef CONFIG_DEVFREQ_THERMAL -cooling_failed: +#if IS_ENABLED(CONFIG_DEVFREQ_THERMAL) +cooling_reg_failed: + kbase_ipa_term(kbdev); +ipa_init_failed: devfreq_unregister_opp_notifier(kbdev->dev, kbdev->devfreq); #endif /* CONFIG_DEVFREQ_THERMAL */ + opp_notifier_failed: + kbase_devfreq_work_term(kbdev); + if (devfreq_remove_device(kbdev->devfreq)) dev_err(kbdev->dev, "Failed to terminate devfreq (%d)\n", err); - else - kbdev->devfreq = NULL; - kbase_devfreq_work_term(kbdev); + kbdev->devfreq = NULL; + + kbase_devfreq_term_core_mask_table(kbdev); return err; } @@ -838,8 +864,7 @@ void kbase_devfreq_term(struct kbase_device *kbdev) dev_dbg(kbdev->dev, "Term Mali devfreq\n"); - rockchip_system_monitor_unregister(kbdev->mdev_info); -#ifdef CONFIG_DEVFREQ_THERMAL +#if IS_ENABLED(CONFIG_DEVFREQ_THERMAL) if (kbdev->devfreq_cooling) devfreq_cooling_unregister(kbdev->devfreq_cooling); @@ -850,6 +875,8 @@ void kbase_devfreq_term(struct kbase_device *kbdev) devfreq_unregister_opp_notifier(kbdev->dev, kbdev->devfreq); + kbase_devfreq_work_term(kbdev); + err = devfreq_remove_device(kbdev->devfreq); if (err) dev_err(kbdev->dev, "Failed to terminate devfreq (%d)\n", err); @@ -857,6 +884,4 @@ void kbase_devfreq_term(struct kbase_device *kbdev) kbdev->devfreq = NULL; kbase_devfreq_term_core_mask_table(kbdev); - - kbase_devfreq_work_term(kbdev); } diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_devfreq.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_devfreq.h index d1305d382990..4a1587ecdff1 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_devfreq.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_devfreq.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014, 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014, 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_gpuprops_backend.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_gpuprops_backend.c index 7542209ca247..11088db568c0 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_gpuprops_backend.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_gpuprops_backend.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. @@ -45,6 +45,12 @@ int kbase_backend_gpuprops_get(struct kbase_device *kbdev, registers.core_features = kbase_reg_read(kbdev, GPU_CONTROL_REG(CORE_FEATURES)); #else /* !MALI_USE_CSF */ + if (((registers.gpu_id & GPU_ID2_PRODUCT_MODEL) == + GPU_ID2_PRODUCT_TGRX) || + ((registers.gpu_id & GPU_ID2_PRODUCT_MODEL) == + GPU_ID2_PRODUCT_TVAX)) + registers.core_features = + kbase_reg_read(kbdev, GPU_CONTROL_REG(CORE_FEATURES)); #endif /* MALI_USE_CSF */ registers.tiler_features = kbase_reg_read(kbdev, GPU_CONTROL_REG(TILER_FEATURES)); diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_instr_backend.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_instr_backend.c index edc2f69e47f7..0c5fe9d21ee9 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_instr_backend.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_instr_backend.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_instr_defs.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_instr_defs.h index 05d5193b9b1c..e356348b657f 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_instr_defs.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_instr_defs.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2014, 2016, 2018-2021 ARM Limited. All rights reserved. @@ -26,7 +26,7 @@ #ifndef _KBASE_INSTR_DEFS_H_ #define _KBASE_INSTR_DEFS_H_ -#include "../../mali_kbase_hwcnt_gpu.h" +#include /* * Instrumentation State Machine States diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_instr_internal.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_instr_internal.h index c0472fadb687..332cc6944d94 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_instr_internal.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_instr_internal.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014, 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014, 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_irq_internal.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_irq_internal.h index bad249c9ee03..2671ce52851f 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_irq_internal.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_irq_internal.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014-2015, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2015, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_irq_linux.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_irq_linux.c index 92aa4e481660..72def5e7aabb 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_irq_linux.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_irq_linux.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2014-2016,2018-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2016, 2018-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -25,7 +25,7 @@ #include -#if !defined(CONFIG_MALI_BIFROST_NO_MALI) +#if !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) /* GPU IRQ Tags */ #define JOB_IRQ_TAG 0 @@ -232,7 +232,7 @@ int kbase_set_custom_irq_handler(struct kbase_device *kbdev, result = -EINVAL; dev_err(kbdev->dev, "Can't request interrupt %d (index %d)\n", kbdev->irqs[irq_type].irq, irq_type); -#ifdef CONFIG_SPARSE_IRQ +#if IS_ENABLED(CONFIG_SPARSE_IRQ) dev_err(kbdev->dev, "You have CONFIG_SPARSE_IRQ support enabled - is the interrupt number correct for this configuration?\n"); #endif /* CONFIG_SPARSE_IRQ */ } @@ -461,7 +461,7 @@ int kbase_install_interrupts(struct kbase_device *kbdev) if (err) { dev_err(kbdev->dev, "Can't request interrupt %d (index %d)\n", kbdev->irqs[i].irq, i); -#ifdef CONFIG_SPARSE_IRQ +#if IS_ENABLED(CONFIG_SPARSE_IRQ) dev_err(kbdev->dev, "You have CONFIG_SPARSE_IRQ support enabled - is the interrupt number correct for this configuration?\n"); #endif /* CONFIG_SPARSE_IRQ */ goto release; @@ -501,4 +501,4 @@ void kbase_synchronize_irqs(struct kbase_device *kbdev) KBASE_EXPORT_TEST_API(kbase_synchronize_irqs); -#endif /* !defined(CONFIG_MALI_BIFROST_NO_MALI) */ +#endif /* !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) */ diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_as.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_as.c index 57ff67b75cab..888aa59421a7 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_as.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_as.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2014-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_defs.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_defs.h index 97663c7d00eb..e29ace710ed7 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_defs.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_defs.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_hw.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_hw.c index 6acacf1eeed4..e7e9fb1d8b47 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_hw.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_hw.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -300,7 +300,7 @@ void kbase_job_hw_submit(struct kbase_device *kbdev, &kbdev->gpu_props.props.raw_props.js_features[js], "ctx_nr,atom_nr"); kbase_kinstr_jm_atom_hw_submit(katom); -#ifdef CONFIG_GPU_TRACEPOINTS +#if IS_ENABLED(CONFIG_GPU_TRACEPOINTS) if (!kbase_backend_nr_atoms_submitted(kbdev, js)) { /* If this is the only job on the slot, trace it as starting */ char js_string[16]; diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_internal.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_internal.h index 6761cbd9a32a..1039e851f959 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_internal.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_internal.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2011-2016, 2018-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2011-2016, 2018-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -59,7 +59,7 @@ void kbase_job_submit_nolock(struct kbase_device *kbdev, void kbase_job_done_slot(struct kbase_device *kbdev, int s, u32 completion_code, u64 job_tail, ktime_t *end_timestamp); -#ifdef CONFIG_GPU_TRACEPOINTS +#if IS_ENABLED(CONFIG_GPU_TRACEPOINTS) static inline char *kbasep_make_job_slot_string(int js, char *js_string, size_t js_size) { diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_rb.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_rb.c index 5fdf9b63d263..a3cb5477ae64 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_rb.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_rb.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. @@ -289,9 +289,11 @@ static void kbase_gpu_release_atom(struct kbase_device *kbdev, katom->gpu_rb_state = KBASE_ATOM_GPU_RB_READY; kbase_pm_metrics_update(kbdev, end_timestamp); + /* Inform platform at start/finish of atom */ + kbasep_platform_event_atom_complete(katom); + if (katom->core_req & BASE_JD_REQ_PERMON) kbase_pm_release_gpu_cycle_counter_nolock(kbdev); - /* ***FALLTHROUGH: TRANSITION TO LOWER STATE*** */ KBASE_TLSTREAM_TL_NRET_ATOM_LPU(kbdev, katom, &kbdev->gpu_props.props.raw_props.js_features @@ -301,6 +303,8 @@ static void kbase_gpu_release_atom(struct kbase_device *kbdev, &kbdev->gpu_props.props.raw_props.js_features [katom->slot_nr]); + /* ***FALLTHROUGH: TRANSITION TO LOWER STATE*** */ + case KBASE_ATOM_GPU_RB_READY: /* ***FALLTHROUGH: TRANSITION TO LOWER STATE*** */ @@ -847,7 +851,7 @@ void kbase_backend_slot_update(struct kbase_device *kbdev) break; katom[idx]->gpu_rb_state = - KBASE_ATOM_GPU_RB_WAITING_PROTECTED_MODE_PREV; + KBASE_ATOM_GPU_RB_WAITING_PROTECTED_MODE_PREV; /* ***TRANSITION TO HIGHER STATE*** */ /* fallthrough */ @@ -987,7 +991,11 @@ void kbase_backend_slot_update(struct kbase_device *kbdev) kbase_job_hw_submit(kbdev, katom[idx], js); katom[idx]->gpu_rb_state = - KBASE_ATOM_GPU_RB_SUBMITTED; + KBASE_ATOM_GPU_RB_SUBMITTED; + + /* ***TRANSITION TO HIGHER STATE*** */ + /* fallthrough */ + case KBASE_ATOM_GPU_RB_SUBMITTED: /* Inform power management at start/finish of * atom so it can update its GPU utilisation @@ -996,10 +1004,9 @@ void kbase_backend_slot_update(struct kbase_device *kbdev) kbase_pm_metrics_update(kbdev, &katom[idx]->start_timestamp); - /* ***TRANSITION TO HIGHER STATE*** */ - /* fallthrough */ - case KBASE_ATOM_GPU_RB_SUBMITTED: - /* Atom submitted to HW, nothing else to do */ + /* Inform platform at start/finish of atom */ + kbasep_platform_event_atom_submit(katom[idx]); + break; case KBASE_ATOM_GPU_RB_RETURN_TO_JS: @@ -1225,7 +1232,7 @@ void kbase_gpu_complete_hw(struct kbase_device *kbdev, int js, * - Schedule out the parent context if necessary, and schedule a new * one in. */ -#ifdef CONFIG_GPU_TRACEPOINTS +#if IS_ENABLED(CONFIG_GPU_TRACEPOINTS) { /* The atom in the HEAD */ struct kbase_jd_atom *next_katom = kbase_gpu_inspect(kbdev, js, diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_rb.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_rb.h index 14da98143f74..d3ff203762f9 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_rb.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_jm_rb.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014-2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_js_backend.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_js_backend.c index 0940bccccddd..ea4c4d0cfe73 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_js_backend.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_js_backend.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_js_internal.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_js_internal.h index e15528d069ac..52842882156f 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_js_internal.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_js_internal.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014-2015, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2015, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_l2_mmu_config.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_l2_mmu_config.c index 884cbd6326f1..713154688de1 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_l2_mmu_config.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_l2_mmu_config.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_l2_mmu_config.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_l2_mmu_config.h index 2dfeadb178c2..07014ad360d8 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_l2_mmu_config.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_l2_mmu_config.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_always_on.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_always_on.c index 66fb24d27b86..077c234d8802 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_always_on.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_always_on.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2010-2015, 2018-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2010-2015, 2018-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -58,6 +58,7 @@ const struct kbase_pm_policy kbase_pm_always_on_policy_ops = { always_on_term, /* term */ always_on_shaders_needed, /* shaders_needed */ always_on_get_core_active, /* get_core_active */ + NULL, /* handle_event */ KBASE_PM_POLICY_ID_ALWAYS_ON, /* id */ #if MALI_USE_CSF ALWAYS_ON_PM_SCHED_FLAGS, /* pm_sched_flags */ diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_always_on.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_always_on.h index e500d46dc82d..98d35dabec88 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_always_on.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_always_on.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2011-2015, 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2011-2015, 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_backend.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_backend.c index a03078b33063..38baa0d27937 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_backend.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_backend.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -37,7 +37,7 @@ #include #include #include -#include +#include static void kbase_pm_gpu_poweroff_wait_wq(struct work_struct *data); static void kbase_pm_hwcnt_disable_worker(struct work_struct *data); diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_ca.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_ca.c index 368f89dd0c61..95b9d6c9a383 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_ca.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_ca.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2013-2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2013-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -26,9 +26,6 @@ #include #include #include -#ifdef MALI_BIFROST_NO_MALI -#include -#endif #include int kbase_pm_ca_init(struct kbase_device *kbdev) @@ -123,9 +120,7 @@ u64 kbase_pm_ca_get_instr_core_mask(struct kbase_device *kbdev) { lockdep_assert_held(&kbdev->hwaccess_lock); -#ifdef CONFIG_MALI_BIFROST_NO_MALI - return (((1ull) << KBASE_DUMMY_MODEL_MAX_SHADER_CORES) - 1); -#elif MALI_USE_CSF +#if MALI_USE_CSF return kbase_pm_get_ready_cores(kbdev, KBASE_PM_CORE_SHADER); #else return kbdev->pm.backend.pm_shaders_core_mask; diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_ca.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_ca.h index c20bf6f965ee..8d169c38ff6f 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_ca.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_ca.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2011-2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2011-2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_ca_devfreq.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_ca_devfreq.h index d24bccd9e1a0..41f3c14835e7 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_ca_devfreq.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_ca_devfreq.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_coarse_demand.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_coarse_demand.c index dd8fad4f2384..f40b753850df 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_coarse_demand.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_coarse_demand.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2012-2016, 2018-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2012-2016, 2018-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -57,6 +57,7 @@ const struct kbase_pm_policy kbase_pm_coarse_demand_policy_ops = { coarse_demand_term, /* term */ coarse_demand_shaders_needed, /* shaders_needed */ coarse_demand_get_core_active, /* get_core_active */ + NULL, /* handle_event */ KBASE_PM_POLICY_ID_COARSE_DEMAND, /* id */ #if MALI_USE_CSF COARSE_ON_DEMAND_PM_SCHED_FLAGS, /* pm_sched_flags */ diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_coarse_demand.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_coarse_demand.h index f1a0e3aab24e..5e3f17ec0650 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_coarse_demand.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_coarse_demand.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2012-2015, 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2012-2015, 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_defs.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_defs.h index e7017ad14792..5018ecea8385 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_defs.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_defs.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. @@ -28,9 +28,6 @@ #include "mali_kbase_pm_always_on.h" #include "mali_kbase_pm_coarse_demand.h" -#if !MALI_CUSTOMER_RELEASE -#include "mali_kbase_pm_always_on_demand.h" -#endif /* Forward definition - see mali_kbase.h */ struct kbase_device; @@ -179,8 +176,12 @@ struct kbasep_pm_metrics_state { * @work: Work item which cancels the timer * @timer: Timer for powering off the shader cores * @configured_interval: Period of GPU poweroff timer - * @configured_ticks: User-configured number of ticks to wait after the shader - * power down request is received before turning off the cores + * @default_ticks: User-configured number of ticks to wait after the shader + * power down request is received before turning off the cores + * @configured_ticks: Power-policy configured number of ticks to wait after the + * shader power down request is received before turning off + * the cores. For simple power policies, this is equivalent + * to @default_ticks. * @remaining_ticks: Number of remaining timer ticks until shaders are powered off * @cancel_queued: True if the cancellation work item has been queued. This is * required to ensure that it is not queued twice, e.g. after @@ -194,6 +195,7 @@ struct kbasep_pm_tick_timer_state { struct hrtimer timer; ktime_t configured_interval; + unsigned int default_ticks; unsigned int configured_ticks; unsigned int remaining_ticks; @@ -204,9 +206,6 @@ struct kbasep_pm_tick_timer_state { union kbase_pm_policy_data { struct kbasep_pm_policy_always_on always_on; struct kbasep_pm_policy_coarse_demand coarse_demand; -#if !MALI_CUSTOMER_RELEASE - struct kbasep_pm_policy_always_on_demand always_on_demand; -#endif }; /** @@ -217,7 +216,8 @@ union kbase_pm_policy_data { * * @pm_current_policy: The policy that is currently actively controlling the * power state. - * @pm_policy_data: Private data for current PM policy + * @pm_policy_data: Private data for current PM policy. This is automatically + * zeroed when a policy change occurs. * @reset_done: Flag when a reset is complete * @reset_done_wait: Wait queue to wait for changes to @reset_done * @gpu_cycle_counter_requests: The reference count of active gpu cycle counter @@ -464,6 +464,33 @@ enum kbase_pm_policy_id { KBASE_PM_POLICY_ID_ALWAYS_ON }; +/** + * enum kbase_pm_policy_event - PM Policy event ID + */ +enum kbase_pm_policy_event { + /** + * @KBASE_PM_POLICY_EVENT_IDLE: Indicates that the GPU power state + * model has determined that the GPU has gone idle. + */ + KBASE_PM_POLICY_EVENT_IDLE, + /** + * @KBASE_PM_POLICY_EVENT_POWER_ON: Indicates that the GPU state model + * is preparing to power on the GPU. + */ + KBASE_PM_POLICY_EVENT_POWER_ON, + /** + * @KBASE_PM_POLICY_EVENT_TIMER_HIT: Indicates that the GPU became + * active while the Shader Tick Timer was holding the GPU in a powered + * on state. + */ + KBASE_PM_POLICY_EVENT_TIMER_HIT, + /** + * @KBASE_PM_POLICY_EVENT_TIMER_MISS: Indicates that the GPU did not + * become active before the Shader Tick Timer timeout occurred. + */ + KBASE_PM_POLICY_EVENT_TIMER_MISS, +}; + /** * struct kbase_pm_policy - Power policy structure. * @@ -476,6 +503,9 @@ enum kbase_pm_policy_id { * @shaders_needed: Function called to find out if shader cores are needed * @get_core_active: Function called to get the current overall GPU power * state + * @handle_event: Function called when a PM policy event occurs. Should be + * set to NULL if the power policy doesn't require any + * event notifications. * @id: Field indicating an ID for this policy. This is not * necessarily the same as its index in the list returned * by kbase_pm_list_policies(). @@ -536,6 +566,16 @@ struct kbase_pm_policy { */ bool (*get_core_active)(struct kbase_device *kbdev); + /** + * Function called when a power event occurs + * + * @kbdev: The kbase device structure for the device (must be a + * valid pointer) + * @event: The id of the power event that has occurred + */ + void (*handle_event)(struct kbase_device *kbdev, + enum kbase_pm_policy_event event); + enum kbase_pm_policy_id id; #if MALI_USE_CSF diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_driver.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_driver.c index 6e742fb1137e..bcada93e46a2 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_driver.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_driver.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -244,7 +244,7 @@ static u32 core_type_to_reg(enum kbase_pm_core_type core_type, return (u32)core_type + (u32)action; } -#ifdef CONFIG_ARM64 +#if IS_ENABLED(CONFIG_ARM64) static void mali_cci_flush_l2(struct kbase_device *kbdev) { const u32 mask = CLEAN_CACHES_COMPLETED | RESET_COMPLETED; @@ -1343,6 +1343,12 @@ static int kbase_pm_shaders_update_state(struct kbase_device *kbdev) kbase_pm_invoke(kbdev, KBASE_PM_CORE_SHADER, backend->shaders_avail, ACTION_PWRON); + if (backend->pm_current_policy && + backend->pm_current_policy->handle_event) + backend->pm_current_policy->handle_event( + kbdev, + KBASE_PM_POLICY_EVENT_POWER_ON); + backend->shaders_state = KBASE_SHADERS_PEND_ON_CORESTACK_ON; } break; @@ -1395,6 +1401,12 @@ static int kbase_pm_shaders_update_state(struct kbase_device *kbdev) /* Wait for being disabled */ ; } else if (!backend->shaders_desired) { + if (backend->pm_current_policy && + backend->pm_current_policy->handle_event) + backend->pm_current_policy->handle_event( + kbdev, + KBASE_PM_POLICY_EVENT_IDLE); + if (kbdev->pm.backend.protected_transition_override || #ifdef CONFIG_MALI_ARBITER_SUPPORT kbase_pm_is_suspending(kbdev) || @@ -1455,9 +1467,21 @@ static int kbase_pm_shaders_update_state(struct kbase_device *kbdev) } if (backend->shaders_desired) { + if (backend->pm_current_policy && + backend->pm_current_policy->handle_event) + backend->pm_current_policy->handle_event( + kbdev, + KBASE_PM_POLICY_EVENT_TIMER_HIT); + stt->remaining_ticks = 0; backend->shaders_state = KBASE_SHADERS_ON_CORESTACK_ON_RECHECK; } else if (stt->remaining_ticks == 0) { + if (backend->pm_current_policy && + backend->pm_current_policy->handle_event) + backend->pm_current_policy->handle_event( + kbdev, + KBASE_PM_POLICY_EVENT_TIMER_MISS); + backend->shaders_state = KBASE_SHADERS_WAIT_FINISHED_CORESTACK_ON; #ifdef CONFIG_MALI_ARBITER_SUPPORT } else if (kbase_pm_is_suspending(kbdev) || @@ -1776,7 +1800,8 @@ int kbase_pm_state_machine_init(struct kbase_device *kbdev) hrtimer_init(&stt->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); stt->timer.function = shader_tick_timer_callback; stt->configured_interval = HR_TIMER_DELAY_NSEC(DEFAULT_PM_GPU_POWEROFF_TICK_NS); - stt->configured_ticks = DEFAULT_PM_POWEROFF_TICK_SHADER; + stt->default_ticks = DEFAULT_PM_POWEROFF_TICK_SHADER; + stt->configured_ticks = stt->default_ticks; return 0; } @@ -1912,24 +1937,43 @@ static void kbase_pm_timed_out(struct kbase_device *kbdev) kbase_reset_gpu(kbdev); } -void kbase_pm_wait_for_l2_powered(struct kbase_device *kbdev) +int kbase_pm_wait_for_l2_powered(struct kbase_device *kbdev) { unsigned long flags; unsigned long timeout; - int err; + long remaining; + int err = 0; spin_lock_irqsave(&kbdev->hwaccess_lock, flags); kbase_pm_update_state(kbdev); spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags); - timeout = jiffies + msecs_to_jiffies(PM_TIMEOUT_MS); +#if MALI_USE_CSF + timeout = kbase_csf_timeout_in_jiffies(PM_TIMEOUT_MS); +#else + timeout = msecs_to_jiffies(PM_TIMEOUT_MS); +#endif /* Wait for cores */ - err = wait_event_killable(kbdev->pm.backend.gpu_in_desired_state_wait, - kbase_pm_is_in_desired_state_with_l2_powered(kbdev)); +#if KERNEL_VERSION(4, 13, 1) <= LINUX_VERSION_CODE + remaining = wait_event_killable_timeout( +#else + remaining = wait_event_timeout( +#endif + kbdev->pm.backend.gpu_in_desired_state_wait, + kbase_pm_is_in_desired_state_with_l2_powered(kbdev), timeout); - if (err < 0 && time_after(jiffies, timeout)) + if (!remaining) { kbase_pm_timed_out(kbdev); + err = -ETIMEDOUT; + } else if (remaining < 0) { + dev_info( + kbdev->dev, + "Wait for desired PM state with L2 powered got interrupted"); + err = (int)remaining; + } + + return err; } int kbase_pm_wait_for_desired_state(struct kbase_device *kbdev) @@ -2045,6 +2089,7 @@ static void update_user_reg_page_mapping(struct kbase_device *kbdev) } #endif + /* * pmu layout: * 0x0000: PMU TAG (RO) (0xCAFECAFE) @@ -2462,7 +2507,7 @@ void kbase_pm_cache_snoop_enable(struct kbase_device *kbdev) { if ((kbdev->current_gpu_coherency_mode == COHERENCY_ACE) && !kbdev->cci_snoop_enabled) { -#ifdef CONFIG_ARM64 +#if IS_ENABLED(CONFIG_ARM64) if (kbdev->snoop_enable_smc != 0) kbase_invoke_smc_fid(kbdev->snoop_enable_smc, 0, 0, 0); #endif /* CONFIG_ARM64 */ @@ -2474,7 +2519,7 @@ void kbase_pm_cache_snoop_enable(struct kbase_device *kbdev) void kbase_pm_cache_snoop_disable(struct kbase_device *kbdev) { if (kbdev->cci_snoop_enabled) { -#ifdef CONFIG_ARM64 +#if IS_ENABLED(CONFIG_ARM64) if (kbdev->snoop_disable_smc != 0) { mali_cci_flush_l2(kbdev); kbase_invoke_smc_fid(kbdev->snoop_disable_smc, 0, 0, 0); @@ -2754,9 +2799,8 @@ kbase_pm_request_gpu_cycle_counter_do_request(struct kbase_device *kbdev) /* This might happen after GPU reset. * Then counter needs to be kicked. */ - if (!IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) && - (!(kbase_reg_read(kbdev, GPU_CONTROL_REG(GPU_STATUS)) & - GPU_STATUS_CYCLE_COUNT_ACTIVE))) { + if (!(kbase_reg_read(kbdev, GPU_CONTROL_REG(GPU_STATUS)) & + GPU_STATUS_CYCLE_COUNT_ACTIVE)) { kbase_reg_write(kbdev, GPU_CONTROL_REG(GPU_COMMAND), GPU_COMMAND_CYCLE_COUNT_START); } diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_internal.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_internal.h index d27eb58ebcda..9ec5890b0d13 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_internal.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_internal.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -28,7 +28,7 @@ #include -#include "mali_kbase_pm_ca.h" +#include "backend/gpu/mali_kbase_pm_ca.h" #include "mali_kbase_pm_policy.h" @@ -263,8 +263,10 @@ int kbase_pm_wait_for_desired_state(struct kbase_device *kbdev); * because this function will take that lock itself. * * @kbdev: The kbase device structure for the device (must be a valid pointer) + * + * Return: 0 on success, error code on error */ -void kbase_pm_wait_for_l2_powered(struct kbase_device *kbdev); +int kbase_pm_wait_for_l2_powered(struct kbase_device *kbdev); /** * kbase_pm_update_dynamic_cores_onoff - Update the L2 and shader power state diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_l2_states.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_l2_states.h index d66b92841290..ef72f6083afd 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_l2_states.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_l2_states.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_mcu_states.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_mcu_states.h index eab30eb32c56..4e9992839ff7 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_mcu_states.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_mcu_states.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_metrics.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_metrics.c index 319a60bc62e8..551bf44a1775 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_metrics.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_metrics.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2011-2021 ARM Limited. All rights reserved. @@ -28,7 +28,7 @@ #include #if MALI_USE_CSF -#include "mali_kbase_clk_rate_trace_mgr.h" +#include "backend/gpu/mali_kbase_clk_rate_trace_mgr.h" #include #else #include @@ -206,7 +206,7 @@ static void kbase_pm_get_dvfs_utilisation_calc(struct kbase_device *kbdev) "Failed to query the increment of GPU_ACTIVE counter: err=%d", err); } else { - u64 diff_ns, margin_ns; + u64 diff_ns; s64 diff_ns_signed; u32 ns_time; ktime_t diff = ktime_sub( @@ -219,15 +219,7 @@ static void kbase_pm_get_dvfs_utilisation_calc(struct kbase_device *kbdev) diff_ns = (u64)diff_ns_signed; - /* Use a margin value that is approximately 1% of the time - * difference. - */ - margin_ns = diff_ns >> 6; - - /* Calculate time difference in units of 256ns */ - ns_time = (u32)(diff_ns >> KBASE_PM_TIME_SHIFT); - -#ifndef CONFIG_MALI_BIFROST_NO_MALI +#if !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) /* The GPU_ACTIVE counter shouldn't clock-up more time than has * actually elapsed - but still some margin needs to be given * when doing the comparison. There could be some drift between @@ -239,6 +231,10 @@ static void kbase_pm_get_dvfs_utilisation_calc(struct kbase_device *kbdev) * time. */ if (!kbdev->pm.backend.metrics.skip_gpu_active_sanity_check) { + /* Use a margin value that is approximately 1% of the time + * difference. + */ + u64 margin_ns = diff_ns >> 6; if (gpu_active_counter > (diff_ns + margin_ns)) { dev_info( kbdev->dev, @@ -247,9 +243,9 @@ static void kbase_pm_get_dvfs_utilisation_calc(struct kbase_device *kbdev) (unsigned long long)diff_ns); } } -#else - CSTD_UNUSED(margin_ns); #endif + /* Calculate time difference in units of 256ns */ + ns_time = (u32)(diff_ns >> KBASE_PM_TIME_SHIFT); /* Add protected_time to gpu_active_counter so that time in * protected mode is included in the apparent GPU active time, diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_policy.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_policy.c index 1f56ae867177..9b5006c87871 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_policy.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_policy.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -33,29 +33,30 @@ #include #endif +#include + static const struct kbase_pm_policy *const all_policy_list[] = { -#ifdef CONFIG_MALI_BIFROST_NO_MALI - &kbase_pm_always_on_policy_ops, &kbase_pm_coarse_demand_policy_ops, -#if !MALI_CUSTOMER_RELEASE - &kbase_pm_always_on_demand_policy_ops, -#endif -#else /* CONFIG_MALI_BIFROST_NO_MALI */ - &kbase_pm_coarse_demand_policy_ops, -#if !MALI_CUSTOMER_RELEASE - &kbase_pm_always_on_demand_policy_ops, -#endif &kbase_pm_always_on_policy_ops -#endif /* CONFIG_MALI_BIFROST_NO_MALI */ }; -#if MALI_USE_CSF void kbase_pm_policy_init(struct kbase_device *kbdev) { - unsigned long flags; const struct kbase_pm_policy *default_policy = all_policy_list[0]; + struct device_node *np = kbdev->dev->of_node; + const char *power_policy_name; + unsigned long flags; + int i; -#if defined CONFIG_MALI_BIFROST_DEBUG + if (of_property_read_string(np, "power_policy", &power_policy_name) == 0) { + for (i = 0; i < ARRAY_SIZE(all_policy_list); i++) + if (sysfs_streq(all_policy_list[i]->name, power_policy_name)) { + default_policy = all_policy_list[i]; + break; + } + } + +#if MALI_USE_CSF && defined(CONFIG_MALI_BIFROST_DEBUG) /* Use always_on policy if module param fw_debug=1 is * passed, to aid firmware debugging. */ @@ -63,31 +64,18 @@ void kbase_pm_policy_init(struct kbase_device *kbdev) default_policy = &kbase_pm_always_on_policy_ops; #endif - default_policy->init(kbdev); +#if MALI_USE_CSF spin_lock_irqsave(&kbdev->hwaccess_lock, flags); kbdev->pm.backend.pm_current_policy = default_policy; - kbdev->pm.backend.csf_pm_sched_flags = - default_policy->pm_sched_flags; + kbdev->pm.backend.csf_pm_sched_flags = default_policy->pm_sched_flags; spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags); -} -#else /* MALI_USE_CSF */ -void kbase_pm_policy_init(struct kbase_device *kbdev) -{ - kbdev->pm.backend.pm_current_policy = all_policy_list[0]; - -#if MALI_USE_CSF && defined CONFIG_MALI_BIFROST_DEBUG - /* Use always_on policy if module param fw_debug=1 is - * passed, to aid firmware debugging. - */ - if (fw_debug) - kbdev->pm.backend.pm_current_policy = - &kbase_pm_always_on_policy_ops; +#else + CSTD_UNUSED(flags); + kbdev->pm.backend.pm_current_policy = default_policy; #endif - kbdev->pm.backend.pm_current_policy->init(kbdev); } -#endif /* MALI_USE_CSF */ void kbase_pm_policy_term(struct kbase_device *kbdev) { @@ -373,6 +361,9 @@ void kbase_pm_set_policy(struct kbase_device *kbdev, if (old_policy->term) old_policy->term(kbdev); + memset(&kbdev->pm.backend.pm_policy_data, 0, + sizeof(union kbase_pm_policy_data)); + KBASE_KTRACE_ADD(kbdev, PM_CURRENT_POLICY_INIT, NULL, new_policy->id); if (new_policy->init) new_policy->init(kbdev); diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_policy.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_policy.h index a513a26ac92c..e8113659b92e 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_policy.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_policy.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2010-2015, 2018-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2010-2015, 2018-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_shader_states.h b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_shader_states.h index 2276713d9987..8622ef78d363 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_shader_states.h +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_shader_states.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_time.c b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_time.c index 7abb8e2c7b06..d10e40426099 100644 --- a/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_time.c +++ b/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_time.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2014-2016, 2018-2021 ARM Limited. All rights reserved. @@ -76,9 +76,6 @@ void kbase_backend_get_gpu_time_norequest(struct kbase_device *kbdev, */ static bool timedwait_cycle_count_active(struct kbase_device *kbdev) { -#ifdef CONFIG_MALI_BIFROST_NO_MALI - return true; -#else bool success = false; const unsigned int timeout = 100; const unsigned long remaining = jiffies + msecs_to_jiffies(timeout); @@ -91,7 +88,6 @@ static bool timedwait_cycle_count_active(struct kbase_device *kbdev) } } return success; -#endif } #endif diff --git a/drivers/gpu/arm/bifrost/build.bp b/drivers/gpu/arm/bifrost/build.bp index b1b52ffe9a1c..f88f60401596 100644 --- a/drivers/gpu/arm/bifrost/build.bp +++ b/drivers/gpu/arm/bifrost/build.bp @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2017-2021 ARM Limited. All rights reserved. @@ -25,14 +25,17 @@ * both mali_kbase and the test modules. */ bob_defaults { name: "mali_kbase_shared_config_defaults", + defaults: [ + "kernel_defaults", + ], no_mali: { - kbuild_options: ["CONFIG_MALI_BIFROST_NO_MALI=y"], + kbuild_options: [ + "CONFIG_MALI_BIFROST_NO_MALI=y", + "CONFIG_MALI_NO_MALI_DEFAULT_GPU={{.gpu}}", + ], }, - mali_real_hw: { - kbuild_options: ["CONFIG_MALI_REAL_HW=y"], - }, - mali_dma_fence: { - kbuild_options: ["CONFIG_MALI_BIFROST_DMA_FENCE=y"], + gpu_has_csf: { + kbuild_options: ["CONFIG_MALI_CSF_SUPPORT=y"], }, mali_devfreq: { kbuild_options: ["CONFIG_MALI_BIFROST_DEVFREQ=y"], @@ -40,8 +43,62 @@ bob_defaults { mali_midgard_dvfs: { kbuild_options: ["CONFIG_MALI_BIFROST_DVFS=y"], }, + mali_gator_support: { + kbuild_options: ["CONFIG_MALI_BIFROST_GATOR_SUPPORT=y"], + }, + mali_midgard_enable_trace: { + kbuild_options: ["CONFIG_MALI_BIFROST_ENABLE_TRACE=y"], + }, + mali_dma_fence: { + kbuild_options: ["CONFIG_MALI_BIFROST_DMA_FENCE=y"], + }, + mali_arbiter_support: { + kbuild_options: ["CONFIG_MALI_ARBITER_SUPPORT=y"], + }, + mali_dma_buf_map_on_demand: { + kbuild_options: ["CONFIG_MALI_DMA_BUF_MAP_ON_DEMAND=y"], + }, + mali_dma_buf_legacy_compat: { + kbuild_options: ["CONFIG_MALI_DMA_BUF_LEGACY_COMPAT=y"], + }, + mali_2mb_alloc: { + kbuild_options: ["CONFIG_MALI_2MB_ALLOC=y"], + }, + mali_memory_fully_backed: { + kbuild_options: ["CONFIG_MALI_MEMORY_FULLY_BACKED=y"], + }, + mali_corestack: { + kbuild_options: ["CONFIG_MALI_CORESTACK=y"], + }, + mali_real_hw: { + kbuild_options: ["CONFIG_MALI_REAL_HW=y"], + }, + mali_error_inject_none: { + kbuild_options: ["CONFIG_MALI_ERROR_INJECT_NONE=y"], + }, + mali_error_inject_track_list: { + kbuild_options: ["CONFIG_MALI_ERROR_INJECT_TRACK_LIST=y"], + }, + mali_error_inject_random: { + kbuild_options: ["CONFIG_MALI_ERROR_INJECT_RANDOM=y"], + }, + mali_error_inject: { + kbuild_options: ["CONFIG_MALI_BIFROST_ERROR_INJECT=y"], + }, + mali_gem5_build: { + kbuild_options: ["CONFIG_MALI_GEM5_BUILD=y"], + }, mali_debug: { - kbuild_options: ["CONFIG_MALI_BIFROST_DEBUG=y"], + kbuild_options: [ + "CONFIG_MALI_BIFROST_DEBUG=y", + "MALI_KERNEL_TEST_API={{.debug}}", + ], + }, + mali_fence_debug: { + kbuild_options: ["CONFIG_MALI_BIFROST_FENCE_DEBUG=y"], + }, + mali_system_trace: { + kbuild_options: ["CONFIG_MALI_BIFROST_SYSTEM_TRACE=y"], }, buslog: { kbuild_options: ["CONFIG_MALI_BUSLOG=y"], @@ -52,91 +109,8 @@ bob_defaults { cinstr_gwt: { kbuild_options: ["CONFIG_MALI_CINSTR_GWT=y"], }, - mali_gator_support: { - kbuild_options: ["CONFIG_MALI_BIFROST_GATOR_SUPPORT=y"], - }, - mali_midgard_enable_trace: { - kbuild_options: ["CONFIG_MALI_BIFROST_ENABLE_TRACE=y"], - }, - mali_system_trace: { - kbuild_options: ["CONFIG_MALI_BIFROST_SYSTEM_TRACE=y"], - }, - mali_pwrsoft_765: { - kbuild_options: ["CONFIG_MALI_PWRSOFT_765=y"], - }, - mali_memory_fully_backed: { - kbuild_options: ["CONFIG_MALI_MEMORY_FULLY_BACKED=y"], - }, - mali_dma_buf_map_on_demand: { - kbuild_options: ["CONFIG_MALI_DMA_BUF_MAP_ON_DEMAND=y"], - }, - mali_dma_buf_legacy_compat: { - kbuild_options: ["CONFIG_MALI_DMA_BUF_LEGACY_COMPAT=y"], - }, - mali_arbiter_support: { - kbuild_options: ["CONFIG_MALI_ARBITER_SUPPORT=y"], - }, - mali_gem5_build: { - kbuild_options: ["CONFIG_MALI_GEM5_BUILD=y"], - }, - kbuild_options: [ - "MALI_UNIT_TEST={{.unit_test_code}}", - "MALI_CUSTOMER_RELEASE={{.release}}", - "MALI_USE_CSF={{.gpu_has_csf}}", - "MALI_KERNEL_TEST_API={{.debug}}", - ], - defaults: ["kernel_defaults"], -} - -bob_kernel_module { - name: "mali_kbase", - srcs: [ - "*.c", - "*.h", - "Kbuild", - "backend/gpu/*.c", - "backend/gpu/*.h", - "backend/gpu/Kbuild", - "context/*.c", - "context/*.h", - "ipa/*.c", - "ipa/*.h", - "ipa/Kbuild", - "platform/*.h", - "platform/*/*.c", - "platform/*/*.h", - "platform/*/Kbuild", - "thirdparty/*.c", - "debug/*.c", - "debug/*.h", - "device/*.c", - "device/*.h", - "gpu/*.c", - "gpu/*.h", - "tl/*.c", - "tl/*.h", - "mmu/*.c", - "mmu/*.h", - ], - kbuild_options: [ - "CONFIG_MALI_KUTF=n", - "CONFIG_MALI_MIDGARD=m", - "CONFIG_MALI_NO_MALI_DEFAULT_GPU={{.gpu}}", - "CONFIG_MALI_PLATFORM_NAME={{.mali_platform_name}}", - ], - buslog: { - extra_symbols: [ - "bus_logger", - ], - }, - mali_corestack: { - kbuild_options: ["CONFIG_MALI_CORESTACK=y"], - }, - mali_error_inject: { - kbuild_options: ["CONFIG_MALI_BIFROST_ERROR_INJECT=y"], - }, - mali_error_inject_random: { - kbuild_options: ["CONFIG_MALI_ERROR_INJECT_RANDOM=y"], + cinstr_primary_hwc: { + kbuild_options: ["CONFIG_MALI_PRFCNT_SET_PRIMARY=y"], }, cinstr_secondary_hwc: { kbuild_options: ["CONFIG_MALI_BIFROST_PRFCNT_SET_SECONDARY=y"], @@ -147,8 +121,11 @@ bob_kernel_module { cinstr_hwc_set_select_via_debug_fs: { kbuild_options: ["CONFIG_MALI_PRFCNT_SET_SELECT_VIA_DEBUG_FS=y"], }, - mali_2mb_alloc: { - kbuild_options: ["CONFIG_MALI_2MB_ALLOC=y"], + mali_job_dump: { + kbuild_options: ["CONFIG_MALI_JOB_DUMP"], + }, + mali_pwrsoft_765: { + kbuild_options: ["CONFIG_MALI_PWRSOFT_765=y"], }, mali_hw_errata_1485982_not_affected: { kbuild_options: ["CONFIG_MALI_HW_ERRATA_1485982_NOT_AFFECTED=y"], @@ -156,6 +133,71 @@ bob_kernel_module { mali_hw_errata_1485982_use_clock_alternative: { kbuild_options: ["CONFIG_MALI_HW_ERRATA_1485982_USE_CLOCK_ALTERNATIVE=y"], }, + kbuild_options: [ + "CONFIG_MALI_PLATFORM_NAME={{.mali_platform_name}}", + "MALI_CUSTOMER_RELEASE={{.release}}", + "MALI_UNIT_TEST={{.unit_test_code}}", + "MALI_USE_CSF={{.gpu_has_csf}}", + "MALI_JIT_PRESSURE_LIMIT_BASE={{.jit_pressure_limit_base}}", + + // Start of CS experimental features definitions. + // If there is nothing below, definition should be added as follows: + // "MALI_EXPERIMENTAL_FEATURE={{.experimental_feature}}" + // experimental_feature above comes from Mconfig in + // /product/base/ + // However, in Mconfig, experimental_feature should be looked up (for + // similar explanation to this one) as ALLCAPS, i.e. + // EXPERIMENTAL_FEATURE. + // + // IMPORTANT: MALI_CS_EXPERIMENTAL should NEVER be defined below as it + // is an umbrella feature that would be open for inappropriate use + // (catch-all for experimental CS code without separating it into + // different features). + "MALI_INCREMENTAL_RENDERING={{.incremental_rendering}}", + "GPU_TIMESTAMP_CORRECTION={{.gpu_timestamp_correction}}", + ], +} + +bob_kernel_module { + name: "mali_kbase", + defaults: [ + "mali_kbase_shared_config_defaults", + ], + srcs: [ + "*.c", + "*.h", + "Kbuild", + "backend/gpu/*.c", + "backend/gpu/*.h", + "backend/gpu/Kbuild", + "context/*.c", + "context/*.h", + "context/Kbuild", + "ipa/*.c", + "ipa/*.h", + "ipa/Kbuild", + "platform/*.h", + "platform/*/*.c", + "platform/*/*.h", + "platform/*/Kbuild", + "thirdparty/*.c", + "thirdparty/Kbuild", + "debug/*.c", + "debug/*.h", + "debug/Kbuild", + "device/*.c", + "device/*.h", + "device/Kbuild", + "gpu/*.c", + "gpu/*.h", + "gpu/Kbuild", + "tl/*.c", + "tl/*.h", + "tl/Kbuild", + "mmu/*.c", + "mmu/*.h", + "mmu/Kbuild", + ], gpu_has_job_manager: { srcs: [ "context/backend/*_jm.c", @@ -172,7 +214,6 @@ bob_kernel_module { ], }, gpu_has_csf: { - kbuild_options: ["CONFIG_MALI_CSF_SUPPORT=y"], srcs: [ "context/backend/*_csf.c", "csf/*.c", @@ -199,5 +240,13 @@ bob_kernel_module { "arbiter/Kbuild", ], }, - defaults: ["mali_kbase_shared_config_defaults"], + kbuild_options: [ + "CONFIG_MALI_BIFROST=m", + "CONFIG_MALI_KUTF=n", + ], + buslog: { + extra_symbols: [ + "bus_logger", + ], + }, } diff --git a/drivers/base/arm/protected_memory_allocator/Kconfig b/drivers/gpu/arm/bifrost/context/Kbuild similarity index 63% rename from drivers/base/arm/protected_memory_allocator/Kconfig rename to drivers/gpu/arm/bifrost/context/Kbuild index 5ee5dcce625d..156b46a12870 100644 --- a/drivers/base/arm/protected_memory_allocator/Kconfig +++ b/drivers/gpu/arm/bifrost/context/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2012-2013, 2016-2017, 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -18,10 +18,10 @@ # # +bifrost_kbase-y += context/mali_kbase_context.o -config MALI_PROTECTED_MEMORY_ALLOCATOR - tristate "MALI_PROTECTED_MEMORY_ALLOCATOR" - help - This option enables an example implementation of a protected memory allocator - for allocation and release of pages of secure memory intended to be used - by the firmware of Mali GPU device drivers. +ifeq ($(CONFIG_MALI_CSF_SUPPORT),y) + bifrost_kbase-y += context/backend/mali_kbase_context_csf.o +else + bifrost_kbase-y += context/backend/mali_kbase_context_jm.o +endif diff --git a/drivers/gpu/arm/bifrost/context/backend/mali_kbase_context_csf.c b/drivers/gpu/arm/bifrost/context/backend/mali_kbase_context_csf.c index c6602476284f..1ce806f639d4 100644 --- a/drivers/gpu/arm/bifrost/context/backend/mali_kbase_context_csf.c +++ b/drivers/gpu/arm/bifrost/context/backend/mali_kbase_context_csf.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -32,7 +32,7 @@ #include #include -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) #include #include #include diff --git a/drivers/gpu/arm/bifrost/context/backend/mali_kbase_context_jm.c b/drivers/gpu/arm/bifrost/context/backend/mali_kbase_context_jm.c index d74e31fe8ca4..8ce81e78a9e6 100644 --- a/drivers/gpu/arm/bifrost/context/backend/mali_kbase_context_jm.c +++ b/drivers/gpu/arm/bifrost/context/backend/mali_kbase_context_jm.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -34,7 +34,7 @@ #include #include -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) #include #include @@ -147,7 +147,7 @@ static const struct kbase_context_init context_init[] = { "JS kctx initialization failed" }, { kbase_jd_init, kbase_jd_exit, "JD initialization failed" }, { kbase_context_submit_check, NULL, "Enabling job submission failed" }, -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) { kbase_debug_job_fault_context_init, kbase_debug_job_fault_context_term, "Job fault context initialization failed" }, @@ -155,6 +155,8 @@ static const struct kbase_context_init context_init[] = { { NULL, kbase_context_flush_jobs, NULL }, { kbase_context_add_to_dev_list, kbase_context_remove_from_dev_list, "Adding kctx to device failed" }, + { kbasep_platform_context_init, kbasep_platform_context_term, + "Platform callback for kctx initialization failed" }, }; static void kbase_context_term_partial( diff --git a/drivers/gpu/arm/bifrost/context/mali_kbase_context.c b/drivers/gpu/arm/bifrost/context/mali_kbase_context.c index fa4970be05ce..b2e7025dd334 100644 --- a/drivers/gpu/arm/bifrost/context/mali_kbase_context.c +++ b/drivers/gpu/arm/bifrost/context/mali_kbase_context.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -154,7 +154,7 @@ int kbase_context_common_init(struct kbase_context *kctx) atomic_set(&kctx->event_count, 0); #if !MALI_USE_CSF atomic_set(&kctx->event_closed, false); -#ifdef CONFIG_GPU_TRACEPOINTS +#if IS_ENABLED(CONFIG_GPU_TRACEPOINTS) atomic_set(&kctx->jctx.work_id, 0); #endif #endif diff --git a/drivers/gpu/arm/bifrost/context/mali_kbase_context.h b/drivers/gpu/arm/bifrost/context/mali_kbase_context.h index f18f64b172be..a0c51c90cd23 100644 --- a/drivers/gpu/arm/bifrost/context/mali_kbase_context.h +++ b/drivers/gpu/arm/bifrost/context/mali_kbase_context.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2011-2017, 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2011-2017, 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/context/mali_kbase_context_internal.h b/drivers/gpu/arm/bifrost/context/mali_kbase_context_internal.h index fd009b8ebc89..1cde7394c705 100644 --- a/drivers/gpu/arm/bifrost/context/mali_kbase_context_internal.h +++ b/drivers/gpu/arm/bifrost/context/mali_kbase_context_internal.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/csf/Kbuild b/drivers/gpu/arm/bifrost/csf/Kbuild index d65b75f32525..7bb5f54452b1 100644 --- a/drivers/gpu/arm/bifrost/csf/Kbuild +++ b/drivers/gpu/arm/bifrost/csf/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2018-2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -19,24 +19,29 @@ # bifrost_kbase-y += \ - csf/mali_kbase_csf_firmware_cfg.o \ - csf/mali_kbase_csf_trace_buffer.o \ - csf/mali_kbase_csf.o \ - csf/mali_kbase_csf_scheduler.o \ - csf/mali_kbase_csf_kcpu.o \ - csf/mali_kbase_csf_tiler_heap.o \ - csf/mali_kbase_csf_timeout.o \ - csf/mali_kbase_csf_tl_reader.o \ - csf/mali_kbase_csf_heap_context_alloc.o \ - csf/mali_kbase_csf_reset_gpu.o \ - csf/mali_kbase_csf_csg_debugfs.o \ - csf/mali_kbase_csf_kcpu_debugfs.o \ - csf/mali_kbase_csf_protected_memory.o \ - csf/mali_kbase_csf_tiler_heap_debugfs.o \ - csf/mali_kbase_csf_cpu_queue_debugfs.o + csf/mali_kbase_csf_firmware_cfg.o \ + csf/mali_kbase_csf_trace_buffer.o \ + csf/mali_kbase_csf.o \ + csf/mali_kbase_csf_scheduler.o \ + csf/mali_kbase_csf_kcpu.o \ + csf/mali_kbase_csf_tiler_heap.o \ + csf/mali_kbase_csf_timeout.o \ + csf/mali_kbase_csf_tl_reader.o \ + csf/mali_kbase_csf_heap_context_alloc.o \ + csf/mali_kbase_csf_reset_gpu.o \ + csf/mali_kbase_csf_csg_debugfs.o \ + csf/mali_kbase_csf_kcpu_debugfs.o \ + csf/mali_kbase_csf_protected_memory.o \ + csf/mali_kbase_csf_tiler_heap_debugfs.o \ + csf/mali_kbase_csf_cpu_queue_debugfs.o bifrost_kbase-$(CONFIG_MALI_REAL_HW) += csf/mali_kbase_csf_firmware.o -bifrost_kbase-$(CONFIG_MALI_BIFROST_NO_MALI) += csf/mali_kbase_csf_firmware_no_mali.o -include $(src)/csf/ipa_control/Kbuild +ifeq ($(KBUILD_EXTMOD),) +# in-tree + -include $(src)/csf/ipa_control/Kbuild +else +# out-of-tree + include $(src)/csf/ipa_control/Kbuild +endif diff --git a/drivers/gpu/arm/bifrost/csf/ipa_control/Kbuild b/drivers/gpu/arm/bifrost/csf/ipa_control/Kbuild index 222e0c803572..dc30281e4781 100644 --- a/drivers/gpu/arm/bifrost/csf/ipa_control/Kbuild +++ b/drivers/gpu/arm/bifrost/csf/ipa_control/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -19,4 +19,4 @@ # bifrost_kbase-y += \ - csf/ipa_control/mali_kbase_csf_ipa_control.o \ No newline at end of file + csf/ipa_control/mali_kbase_csf_ipa_control.o diff --git a/drivers/gpu/arm/bifrost/csf/ipa_control/mali_kbase_csf_ipa_control.c b/drivers/gpu/arm/bifrost/csf/ipa_control/mali_kbase_csf_ipa_control.c index 7b0845c0d78c..e23d68110b58 100644 --- a/drivers/gpu/arm/bifrost/csf/ipa_control/mali_kbase_csf_ipa_control.c +++ b/drivers/gpu/arm/bifrost/csf/ipa_control/mali_kbase_csf_ipa_control.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -20,7 +20,7 @@ */ #include -#include "mali_kbase_clk_rate_trace_mgr.h" +#include "backend/gpu/mali_kbase_clk_rate_trace_mgr.h" #include "mali_kbase_csf_ipa_control.h" /* diff --git a/drivers/gpu/arm/bifrost/csf/ipa_control/mali_kbase_csf_ipa_control.h b/drivers/gpu/arm/bifrost/csf/ipa_control/mali_kbase_csf_ipa_control.h index a828e01f9d4d..348a52f54d8f 100644 --- a/drivers/gpu/arm/bifrost/csf/ipa_control/mali_kbase_csf_ipa_control.h +++ b/drivers/gpu/arm/bifrost/csf/ipa_control/mali_kbase_csf_ipa_control.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf.c index 00f89088c7ba..b4c780b25048 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. @@ -144,14 +144,21 @@ static void gpu_munmap_user_io_pages(struct kbase_context *kctx, mutex_unlock(&kctx->kbdev->csf.reg_lock); } -static void init_user_output_page(struct kbase_queue *queue) +static void init_user_io_pages(struct kbase_queue *queue) { - u32 *addr = (u32 *)(queue->user_io_addr + PAGE_SIZE); + u32 *input_addr = (u32 *)(queue->user_io_addr); + u32 *output_addr = (u32 *)(queue->user_io_addr + PAGE_SIZE); - addr[CS_EXTRACT_LO/4] = 0; - addr[CS_EXTRACT_HI/4] = 0; + input_addr[CS_INSERT_LO/4] = 0; + input_addr[CS_INSERT_HI/4] = 0; - addr[CS_ACTIVE/4] = 0; + input_addr[CS_EXTRACT_INIT_LO/4] = 0; + input_addr[CS_EXTRACT_INIT_HI/4] = 0; + + output_addr[CS_EXTRACT_LO/4] = 0; + output_addr[CS_EXTRACT_HI/4] = 0; + + output_addr[CS_ACTIVE/4] = 0; } /* Map the input/output pages in the shared interface segment of MCU firmware @@ -350,7 +357,7 @@ int kbase_csf_alloc_command_stream_user_pages(struct kbase_context *kctx, if (ret) goto kernel_map_failed; - init_user_output_page(queue); + init_user_io_pages(queue); ret = gpu_mmap_user_io_pages(kctx->kbdev, queue->phys, reg); if (ret) @@ -455,19 +462,39 @@ static void release_queue(struct kbase_queue *queue) static void oom_event_worker(struct work_struct *data); static void fatal_event_worker(struct work_struct *data); -int kbase_csf_queue_register(struct kbase_context *kctx, - struct kbase_ioctl_cs_queue_register *reg) +/* Between reg and reg_ex, one and only one must be null */ +static int csf_queue_register_internal(struct kbase_context *kctx, + struct kbase_ioctl_cs_queue_register *reg, + struct kbase_ioctl_cs_queue_register_ex *reg_ex) { struct kbase_queue *queue; int ret = 0; struct kbase_va_region *region; - u64 queue_addr = reg->buffer_gpu_addr; - size_t queue_size = reg->buffer_size >> PAGE_SHIFT; + u64 queue_addr; + size_t queue_size; + + /* Only one pointer expected, otherwise coding error */ + if ((reg == NULL && reg_ex == NULL) || (reg && reg_ex)) { + dev_err(kctx->kbdev->dev, + "Error, one and only one param-ptr expected!"); + return -EINVAL; + } + + /* struct kbase_ioctl_cs_queue_register_ex contains a full + * struct kbase_ioctl_cs_queue_register at the start address. So + * the pointer can be safely cast to pointing to a + * kbase_ioctl_cs_queue_register object. + */ + if (reg_ex) + reg = (struct kbase_ioctl_cs_queue_register *)reg_ex; /* Validate the queue priority */ if (reg->priority > BASE_QUEUE_MAX_PRIORITY) return -EINVAL; + queue_addr = reg->buffer_gpu_addr; + queue_size = reg->buffer_size >> PAGE_SHIFT; + mutex_lock(&kctx->csf.lock); /* Check if queue is already registered */ @@ -492,6 +519,35 @@ int kbase_csf_queue_register(struct kbase_context *kctx, goto out_unlock_vm; } + /* Check address validity on cs_trace buffer etc. Don't care + * if not enabled (i.e. when size is 0). + */ + if (reg_ex && reg_ex->ex_buffer_size) { + int buf_pages = (reg_ex->ex_buffer_size + + (1 << PAGE_SHIFT) - 1) >> PAGE_SHIFT; + + region = kbase_region_tracker_find_region_enclosing_address( + kctx, reg_ex->ex_buffer_base); + if (kbase_is_region_invalid_or_free(region)) { + ret = -ENOENT; + goto out_unlock_vm; + } + + if (buf_pages > (region->nr_pages - + ((reg_ex->ex_buffer_base >> PAGE_SHIFT) - + region->start_pfn))) { + ret = -EINVAL; + goto out_unlock_vm; + } + + region = kbase_region_tracker_find_region_enclosing_address( + kctx, reg_ex->ex_offset_var_addr); + if (kbase_is_region_invalid_or_free(region)) { + ret = -ENOENT; + goto out_unlock_vm; + } + } + queue = kzalloc(sizeof(struct kbase_queue), GFP_KERNEL); if (!queue) { @@ -529,6 +585,22 @@ int kbase_csf_queue_register(struct kbase_context *kctx, region->flags |= KBASE_REG_NO_USER_FREE; + /* Initialize the cs_trace configuration parameters, When buffer_size + * is 0, trace is disabled. Here we only update the fields when + * enabled, otherwise leave them as default zeros. + */ + if (reg_ex && reg_ex->ex_buffer_size) { + u32 cfg = CS_INSTR_CONFIG_EVENT_SIZE_SET( + 0, reg_ex->ex_event_size); + cfg = CS_INSTR_CONFIG_EVENT_STATE_SET( + cfg, reg_ex->ex_event_state); + + queue->trace_cfg = cfg; + queue->trace_buffer_size = reg_ex->ex_buffer_size; + queue->trace_buffer_base = reg_ex->ex_buffer_base; + queue->trace_offset_ptr = reg_ex->ex_offset_var_addr; + } + out_unlock_vm: kbase_gpu_vm_unlock(kctx); out: @@ -537,6 +609,37 @@ out: return ret; } +int kbase_csf_queue_register(struct kbase_context *kctx, + struct kbase_ioctl_cs_queue_register *reg) +{ + return csf_queue_register_internal(kctx, reg, NULL); +} + +int kbase_csf_queue_register_ex(struct kbase_context *kctx, + struct kbase_ioctl_cs_queue_register_ex *reg) +{ + struct kbase_csf_global_iface const *const iface = + &kctx->kbdev->csf.global_iface; + u32 const glb_version = iface->version; + u32 instr = iface->instr_features; + u8 max_size = GLB_INSTR_FEATURES_EVENT_SIZE_MAX_GET(instr); + u32 min_buf_size = (1u << reg->ex_event_size) * + GLB_INSTR_FEATURES_OFFSET_UPDATE_RATE_GET(instr); + + /* If cs_trace_command not supported, the call fails */ + if (glb_version < kbase_csf_interface_version(1, 1, 0)) + return -EINVAL; + + /* Validate the cs_trace configuration parameters */ + if (reg->ex_buffer_size && + ((reg->ex_event_size > max_size) || + (reg->ex_buffer_size & (reg->ex_buffer_size - 1)) || + (reg->ex_buffer_size < min_buf_size))) + return -EINVAL; + + return csf_queue_register_internal(kctx, NULL, reg); +} + static void unbind_queue(struct kbase_context *kctx, struct kbase_queue *queue); @@ -787,6 +890,8 @@ static void unbind_stopped_queue(struct kbase_context *kctx, kbase_csf_scheduler_spin_lock(kctx->kbdev, &flags); bitmap_clear(queue->group->protm_pending_bitmap, queue->csi_index, 1); + KBASE_KTRACE_ADD_CSF_GRP_Q(kctx->kbdev, PROTM_PENDING_CLEAR, + queue->group, queue, queue->group->protm_pending_bitmap[0]); queue->group->bound_queues[queue->csi_index] = NULL; queue->group = NULL; kbase_csf_scheduler_spin_unlock(kctx->kbdev, flags); @@ -1913,6 +2018,7 @@ void kbase_csf_event_signal(struct kbase_context *kctx, bool notify_gpu) spin_lock_irqsave(&kctx->kbdev->hwaccess_lock, flags); if (kctx->kbdev->pm.backend.gpu_powered) kbase_csf_ring_doorbell(kctx->kbdev, CSF_KERNEL_DOORBELL_NR); + KBASE_KTRACE_ADD(kctx->kbdev, SYNC_UPDATE_EVENT_NOTIFY_GPU, kctx, 0u); spin_unlock_irqrestore(&kctx->kbdev->hwaccess_lock, flags); } @@ -2251,7 +2357,11 @@ static void protm_event_worker(struct work_struct *data) struct kbase_queue_group *const group = container_of(data, struct kbase_queue_group, protm_event_work); + KBASE_KTRACE_ADD_CSF_GRP(group->kctx->kbdev, PROTM_EVENT_WORKER_BEGIN, + group, 0u); kbase_csf_scheduler_group_protm_enter(group); + KBASE_KTRACE_ADD_CSF_GRP(group->kctx->kbdev, PROTM_EVENT_WORKER_END, + group, 0u); } static void report_queue_fatal_error(struct kbase_queue *const queue, @@ -2308,13 +2418,16 @@ handle_fault_event(struct kbase_queue *const queue, kbase_csf_scheduler_spin_lock_assert_held(kbdev); - dev_warn(kbdev->dev, "CSI: %d\n" - "CS_FAULT.EXCEPTION_TYPE: 0x%x (%s)\n" - "CS_FAULT.EXCEPTION_DATA: 0x%x\n" - "CS_FAULT_INFO.EXCEPTION_DATA: 0x%llx\n", - queue->csi_index, cs_fault_exception_type, - kbase_gpu_exception_name(cs_fault_exception_type), - cs_fault_exception_data, cs_fault_info_exception_data); + dev_warn(kbdev->dev, + "Ctx %d_%d Group %d CSG %d CSI: %d\n" + "CS_FAULT.EXCEPTION_TYPE: 0x%x (%s)\n" + "CS_FAULT.EXCEPTION_DATA: 0x%x\n" + "CS_FAULT_INFO.EXCEPTION_DATA: 0x%llx\n", + queue->kctx->tgid, queue->kctx->id, queue->group->handle, + queue->group->csg_nr, queue->csi_index, + cs_fault_exception_type, + kbase_gpu_exception_name(cs_fault_exception_type), + cs_fault_exception_data, cs_fault_info_exception_data); if (cs_fault_exception_type == CS_FAULT_EXCEPTION_TYPE_RESOURCE_EVICTION_TIMEOUT) @@ -2398,11 +2511,12 @@ handle_fatal_event(struct kbase_queue *const queue, kbase_csf_scheduler_spin_lock_assert_held(kbdev); dev_warn(kbdev->dev, - "CSG: %d, CSI: %d\n" + "Ctx %d_%d Group %d CSG %d CSI: %d\n" "CS_FATAL.EXCEPTION_TYPE: 0x%x (%s)\n" "CS_FATAL.EXCEPTION_DATA: 0x%x\n" "CS_FATAL_INFO.EXCEPTION_DATA: 0x%llx\n", - queue->group->handle, queue->csi_index, + queue->kctx->tgid, queue->kctx->id, queue->group->handle, + queue->group->csg_nr, queue->csi_index, cs_fatal_exception_type, kbase_gpu_exception_name(cs_fatal_exception_type), cs_fatal_exception_data, cs_fatal_info_exception_data); @@ -2505,23 +2619,28 @@ static void process_cs_interrupts(struct kbase_queue_group *const group, if ((cs_req & CS_REQ_EXCEPTION_MASK) ^ (cs_ack & CS_ACK_EXCEPTION_MASK)) { KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, CSI_FAULT_INTERRUPT, group, queue, cs_req ^ cs_ack); - handle_queue_exception_event(queue, cs_req, - cs_ack); + handle_queue_exception_event(queue, cs_req, cs_ack); } /* PROTM_PEND and TILER_OOM can be safely ignored * because they will be raised again if the group * is assigned a CSG slot in future. */ - if (group_suspending) + if (group_suspending) { + u32 const cs_req_remain = cs_req & ~CS_REQ_EXCEPTION_MASK; + u32 const cs_ack_remain = cs_ack & ~CS_ACK_EXCEPTION_MASK; + + KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, CSI_IGNORED_INTERRUPTS_GROUP_SUSPEND, + group, queue, cs_req_remain ^ cs_ack_remain); continue; + } if (((cs_req & CS_REQ_TILER_OOM_MASK) ^ (cs_ack & CS_ACK_TILER_OOM_MASK))) { get_queue(queue); - KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, CSI_TILER_OOM_INTERRUPT, group, queue, cs_req ^ cs_ack); - if (WARN_ON(!queue_work( - wq, &queue->oom_event_work))) { + KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, CSI_TILER_OOM_INTERRUPT, group, queue, + cs_req ^ cs_ack); + if (WARN_ON(!queue_work(wq, &queue->oom_event_work))) { /* The work item shall not have been * already queued, there can be only * one pending OoM event for a @@ -2533,12 +2652,17 @@ static void process_cs_interrupts(struct kbase_queue_group *const group, if ((cs_req & CS_REQ_PROTM_PEND_MASK) ^ (cs_ack & CS_ACK_PROTM_PEND_MASK)) { + KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, CSI_PROTM_PEND_INTERRUPT, group, queue, + cs_req ^ cs_ack); + dev_dbg(kbdev->dev, "Protected mode entry request for queue on csi %d bound to group-%d on slot %d", queue->csi_index, group->handle, group->csg_nr); bitmap_set(group->protm_pending_bitmap, i, 1); + KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, PROTM_PENDING_SET, group, queue, + group->protm_pending_bitmap[0]); protm_pend = true; } } @@ -2567,7 +2691,7 @@ static void process_csg_interrupts(struct kbase_device *const kbdev, int const csg_nr) { struct kbase_csf_cmd_stream_group_info *ginfo; - struct kbase_queue_group *group; + struct kbase_queue_group *group = NULL; u32 req, ack, irqreq, irqack; kbase_csf_scheduler_spin_lock_assert_held(kbdev); @@ -2575,6 +2699,8 @@ static void process_csg_interrupts(struct kbase_device *const kbdev, if (WARN_ON(csg_nr >= kbdev->csf.global_iface.group_num)) return; + KBASE_KTRACE_ADD(kbdev, CSG_INTERRUPT_PROCESS, NULL, csg_nr); + ginfo = &kbdev->csf.global_iface.groups[csg_nr]; req = kbase_csf_firmware_csg_input_read(ginfo, CSG_REQ); ack = kbase_csf_firmware_csg_output(ginfo, CSG_ACK); @@ -2583,7 +2709,7 @@ static void process_csg_interrupts(struct kbase_device *const kbdev, /* There may not be any pending CSG/CS interrupts to process */ if ((req == ack) && (irqreq == irqack)) - return; + goto out; /* Immediately set IRQ_ACK bits to be same as the IRQ_REQ bits before * examining the CS_ACK & CS_REQ bits. This would ensure that Host @@ -2604,10 +2730,10 @@ static void process_csg_interrupts(struct kbase_device *const kbdev, * slot scheduler spinlock is required. */ if (!group) - return; + goto out; if (WARN_ON(kbase_csf_scheduler_group_get_slot_locked(group) != csg_nr)) - return; + goto out; if ((req ^ ack) & CSG_REQ_SYNC_UPDATE_MASK) { kbase_csf_firmware_csg_input_mask(ginfo, @@ -2624,7 +2750,8 @@ static void process_csg_interrupts(struct kbase_device *const kbdev, CSG_REQ_IDLE_MASK); set_bit(csg_nr, scheduler->csg_slots_idle_mask); - + KBASE_KTRACE_ADD_CSF_GRP(kbdev, CSG_SLOT_IDLE_SET, group, + scheduler->csg_slots_idle_mask[0]); KBASE_KTRACE_ADD_CSF_GRP(kbdev, CSG_IDLE_INTERRUPT, group, req ^ ack); dev_dbg(kbdev->dev, "Idle notification received for Group %u on slot %d\n", group->handle, csg_nr); @@ -2640,6 +2767,8 @@ static void process_csg_interrupts(struct kbase_device *const kbdev, kbase_csf_firmware_csg_input_mask(ginfo, CSG_REQ, ack, CSG_REQ_PROGRESS_TIMER_EVENT_MASK); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, CSG_PROGRESS_TIMER_INTERRUPT, + group, req ^ ack); dev_info(kbdev->dev, "Timeout notification received for group %u of ctx %d_%d on slot %d\n", group->handle, group->kctx->tgid, group->kctx->id, csg_nr); @@ -2648,6 +2777,11 @@ static void process_csg_interrupts(struct kbase_device *const kbdev, } process_cs_interrupts(group, ginfo, irqreq, irqack); + +out: + /* group may still be NULL here */ + KBASE_KTRACE_ADD_CSF_GRP(kbdev, CSG_INTERRUPT_PROCESS_END, group, + ((u64)req ^ ack) | (((u64)irqreq ^ irqack) << 32)); } /** @@ -2741,6 +2875,7 @@ void kbase_csf_interrupt(struct kbase_device *kbdev, u32 val) lockdep_assert_held(&kbdev->hwaccess_lock); + KBASE_KTRACE_ADD(kbdev, CSF_INTERRUPT, NULL, val); kbase_reg_write(kbdev, JOB_CONTROL_REG(JOB_IRQ_CLEAR), val); if (val & JOB_IRQ_GLOBAL_IF) { @@ -2761,6 +2896,7 @@ void kbase_csf_interrupt(struct kbase_device *kbdev, u32 val) global_iface, GLB_REQ); glb_ack = kbase_csf_firmware_global_output( global_iface, GLB_ACK); + KBASE_KTRACE_ADD(kbdev, GLB_REQ_ACQ, NULL, glb_req ^ glb_ack); if ((glb_req ^ glb_ack) & GLB_REQ_PROTM_EXIT_MASK) { dev_dbg(kbdev->dev, "Protected mode exit interrupt received"); @@ -2768,8 +2904,8 @@ void kbase_csf_interrupt(struct kbase_device *kbdev, u32 val) global_iface, GLB_REQ, glb_ack, GLB_REQ_PROTM_EXIT_MASK); WARN_ON(!kbase_csf_scheduler_protected_mode_in_use(kbdev)); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_EXIT_PROTM, scheduler->active_protm_grp, 0u); scheduler->active_protm_grp = NULL; - KBASE_KTRACE_ADD(kbdev, SCHEDULER_EXIT_PROTM, NULL, 0u); kbdev->protected_mode = false; kbase_ipa_control_protm_exited(kbdev); kbase_hwcnt_backend_csf_protm_exited( @@ -2778,13 +2914,20 @@ void kbase_csf_interrupt(struct kbase_device *kbdev, u32 val) /* Handle IDLE Hysteresis notification event */ if ((glb_req ^ glb_ack) & GLB_REQ_IDLE_EVENT_MASK) { + int non_idle_offslot_grps; + bool can_suspend_on_idle; dev_dbg(kbdev->dev, "Idle-hysteresis event flagged"); kbase_csf_firmware_global_input_mask( global_iface, GLB_REQ, glb_ack, GLB_REQ_IDLE_EVENT_MASK); - if (!atomic_read(&scheduler->non_idle_offslot_grps)) { - if (kbase_pm_idle_groups_sched_suspendable(kbdev)) + non_idle_offslot_grps = atomic_read(&scheduler->non_idle_offslot_grps); + can_suspend_on_idle = kbase_pm_idle_groups_sched_suspendable(kbdev); + KBASE_KTRACE_ADD(kbdev, SCHEDULER_CAN_IDLE, NULL, + ((u64)(u32)non_idle_offslot_grps) | (((u64)can_suspend_on_idle) << 32)); + + if (!non_idle_offslot_grps) { + if (can_suspend_on_idle) queue_work(system_highpri_wq, &scheduler->gpu_idle_work); } else { @@ -2809,6 +2952,7 @@ void kbase_csf_interrupt(struct kbase_device *kbdev, u32 val) if (!remaining) { wake_up_all(&kbdev->csf.event_wait); + KBASE_KTRACE_ADD(kbdev, CSF_INTERRUPT_END, NULL, val); return; } } @@ -2823,6 +2967,7 @@ void kbase_csf_interrupt(struct kbase_device *kbdev, u32 val) kbase_csf_scheduler_spin_unlock(kbdev, flags); wake_up_all(&kbdev->csf.event_wait); + KBASE_KTRACE_ADD(kbdev, CSF_INTERRUPT_END, NULL, val); } void kbase_csf_doorbell_mapping_term(struct kbase_device *kbdev) diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf.h index effd4686a444..e3bd436dd249 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. @@ -39,7 +39,7 @@ */ #define KBASEP_USER_DB_NR_INVALID ((s8)-1) -#define FIRMWARE_PING_INTERVAL_MS (2000) /* 2 seconds */ +#define FIRMWARE_PING_INTERVAL_MS (4000) /* 4 seconds */ #define FIRMWARE_IDLE_HYSTERESIS_TIME_MS (10) /* Default 10 milliseconds */ @@ -212,6 +212,22 @@ void kbase_csf_ctx_term(struct kbase_context *kctx); int kbase_csf_queue_register(struct kbase_context *kctx, struct kbase_ioctl_cs_queue_register *reg); +/** + * kbase_csf_queue_register_ex - Register a GPU command queue with + * extended format. + * + * @kctx: Pointer to the kbase context within which the + * queue is to be registered. + * @reg: Pointer to the structure which contains details of the + * queue to be registered within the provided + * context, together with the extended parameter fields + * for supporting cs trace command. + * + * Return: 0 on success, or negative on failure. + */ +int kbase_csf_queue_register_ex(struct kbase_context *kctx, + struct kbase_ioctl_cs_queue_register_ex *reg); + /** * kbase_csf_queue_terminate - Terminate a GPU command queue. * diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_cpu_queue_debugfs.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_cpu_queue_debugfs.c index b54b2fc31939..26637bf3fa73 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_cpu_queue_debugfs.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_cpu_queue_debugfs.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. @@ -23,7 +23,7 @@ #include #include -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) bool kbase_csf_cpu_queue_read_dump_req(struct kbase_context *kctx, struct base_csf_notification *req) diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_cpu_queue_debugfs.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_cpu_queue_debugfs.h index 36336497209e..435a993955fe 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_cpu_queue_debugfs.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_cpu_queue_debugfs.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. @@ -68,7 +68,7 @@ bool kbase_csf_cpu_queue_read_dump_req(struct kbase_context *kctx, */ static inline bool kbase_csf_cpu_queue_dump_needed(struct kbase_context *kctx) { -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) return (atomic_read(&kctx->csf.cpu_queue.dump_req_status) == BASE_CSF_CPU_QUEUE_DUMP_ISSUED); #else diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_csg_debugfs.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_csg_debugfs.c index 389468307e5f..14deb989ef92 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_csg_debugfs.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_csg_debugfs.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -25,7 +25,7 @@ #include #include -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) #include "mali_kbase_csf_tl_reader.h" /** @@ -87,6 +87,32 @@ static void kbasep_csf_scheduler_dump_active_queue_cs_status_wait( blocked_reason))); } +static void kbasep_csf_scheduler_dump_active_cs_trace(struct seq_file *file, + struct kbase_csf_cmd_stream_info const *const stream) +{ + u32 val = kbase_csf_firmware_cs_input_read(stream, + CS_INSTR_BUFFER_BASE_LO); + u64 addr = ((u64)kbase_csf_firmware_cs_input_read(stream, + CS_INSTR_BUFFER_BASE_HI) << 32) | val; + val = kbase_csf_firmware_cs_input_read(stream, + CS_INSTR_BUFFER_SIZE); + + seq_printf(file, "CS_TRACE_BUF_ADDR: 0x%16llx, SIZE: %u\n", addr, val); + + /* Write offset variable address (pointer) */ + val = kbase_csf_firmware_cs_input_read(stream, + CS_INSTR_BUFFER_OFFSET_POINTER_LO); + addr = ((u64)kbase_csf_firmware_cs_input_read(stream, + CS_INSTR_BUFFER_OFFSET_POINTER_HI) << 32) | val; + seq_printf(file, "CS_TRACE_BUF_OFFSET_PTR: 0x%16llx\n", addr); + + /* EVENT_SIZE and EVENT_STATEs */ + val = kbase_csf_firmware_cs_input_read(stream, CS_INSTR_CONFIG); + seq_printf(file, "TRACE_EVENT_SIZE: 0x%x, TRACE_EVENT_STAES 0x%x\n", + CS_INSTR_CONFIG_EVENT_SIZE_GET(val), + CS_INSTR_CONFIG_EVENT_STATE_GET(val)); +} + /** * kbasep_csf_scheduler_dump_active_queue() - Print GPU command queue * debug information @@ -134,7 +160,9 @@ static void kbasep_csf_scheduler_dump_active_queue(struct seq_file *file, queue->csi_index, queue->base_addr, queue->priority, cs_insert, cs_extract, cs_active, queue->doorbell_nr); - /* Print status information for blocked group waiting for sync object */ + /* Print status information for blocked group waiting for sync object. For on-slot queues, + * if cs_trace is enabled, dump the interface's cs_trace configuration. + */ if (kbase_csf_scheduler_group_get_slot(queue->group) < 0) { if (CS_STATUS_WAIT_SYNC_WAIT_GET(queue->status_wait)) { wait_status = queue->status_wait; @@ -212,6 +240,11 @@ static void kbasep_csf_scheduler_dump_active_queue(struct seq_file *file, file, wait_status, wait_sync_value, wait_sync_live_value, wait_sync_pointer, sb_status, blocked_reason); + /* Dealing with cs_trace */ + if (kbase_csf_scheduler_queue_has_trace(queue)) + kbasep_csf_scheduler_dump_active_cs_trace(file, stream); + else + seq_puts(file, "NO CS_TRACE\n"); } seq_puts(file, "\n"); diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_csg_debugfs.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_csg_debugfs.h index c6a86b6d814b..397e657d2cb6 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_csg_debugfs.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_csg_debugfs.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_defs.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_defs.h index 05173990c6d8..53526cee1d78 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_defs.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_defs.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. @@ -314,6 +314,10 @@ struct kbase_csf_notification { * are non-zero * @blocked_reason: Value shows if the queue is blocked, and if so, * the reason why it is blocked + * @trace_buffer_base: CS trace buffer base address. + * @trace_offset_ptr: Pointer to the CS trace buffer offset variable. + * @trace_buffer_size: CS trace buffer size for the queue. + * @trace_cfg: CS trace configuration parameters. * @error: GPU command queue fatal information to pass to user space. * @fatal_event_work: Work item to handle the CS fatal event reported for this * queue. @@ -344,6 +348,10 @@ struct kbase_queue { u32 sync_value; u32 sb_status; u32 blocked_reason; + u64 trace_buffer_base; + u64 trace_offset_ptr; + u32 trace_buffer_size; + u32 trace_cfg; struct kbase_csf_notification error; struct work_struct fatal_event_work; u64 cs_fatal_info; @@ -667,7 +675,7 @@ struct kbase_csf_context { struct vm_area_struct *user_reg_vma; struct kbase_csf_scheduler_context sched; struct list_head error_list; -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) struct kbase_csf_cpu_queue_context cpu_queue; #endif }; diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware.c index 89585bfc9716..b51c0ff53278 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. @@ -993,7 +993,12 @@ static int parse_capabilities(struct kbase_device *kbdev) iface->group_stride = shared_info[GLB_GROUP_STRIDE/4]; iface->prfcnt_size = shared_info[GLB_PRFCNT_SIZE/4]; - iface->instr_features = shared_info[GLB_INSTR_FEATURES / 4]; + + if (iface->version >= kbase_csf_interface_version(1, 1, 0)) { + iface->instr_features = shared_info[GLB_INSTR_FEATURES / 4]; + } else { + iface->instr_features = 0; + } if ((GROUP_CONTROL_0 + (unsigned long)iface->group_num * iface->group_stride) > @@ -1671,29 +1676,8 @@ u32 kbase_csf_firmware_set_mcu_core_pwroff_time(struct kbase_device *kbdev, u32 } -int kbase_csf_firmware_init(struct kbase_device *kbdev) +int kbase_csf_firmware_early_init(struct kbase_device *kbdev) { - const struct firmware *firmware; - const u32 magic = FIRMWARE_HEADER_MAGIC; - u8 version_major, version_minor; - u32 version_hash; - u32 entry_end_offset; - u32 entry_offset; - int ret; - - if (WARN_ON((kbdev->as_free & MCU_AS_BITMASK) == 0)) - return -EINVAL; - kbdev->as_free &= ~MCU_AS_BITMASK; - - ret = kbase_mmu_init(kbdev, &kbdev->csf.mcu_mmu, NULL, - BASE_MEM_GROUP_DEFAULT); - - if (ret != 0) { - /* Release the address space */ - kbdev->as_free |= MCU_AS_BITMASK; - return ret; - } - init_waitqueue_head(&kbdev->csf.event_wait); kbdev->csf.interrupt_received = false; kbdev->csf.fw_timeout_ms = CSF_FIRMWARE_TIMEOUT_MS; @@ -1708,17 +1692,46 @@ int kbase_csf_firmware_init(struct kbase_device *kbdev) mutex_init(&kbdev->csf.reg_lock); + return 0; +} + +int kbase_csf_firmware_init(struct kbase_device *kbdev) +{ + const struct firmware *firmware; + const u32 magic = FIRMWARE_HEADER_MAGIC; + u8 version_major, version_minor; + u32 version_hash; + u32 entry_end_offset; + u32 entry_offset; + int ret; + + lockdep_assert_held(&kbdev->fw_load_lock); + + if (WARN_ON((kbdev->as_free & MCU_AS_BITMASK) == 0)) + return -EINVAL; + kbdev->as_free &= ~MCU_AS_BITMASK; + + ret = kbase_mmu_init(kbdev, &kbdev->csf.mcu_mmu, NULL, + BASE_MEM_GROUP_DEFAULT); + + if (ret != 0) { + /* Release the address space */ + kbdev->as_free |= MCU_AS_BITMASK; + return ret; + } + kbdev->csf.gpu_idle_hysteresis_ms = FIRMWARE_IDLE_HYSTERESIS_TIME_MS; - kbdev->csf.gpu_idle_dur_count = convert_dur_to_idle_count(kbdev, - FIRMWARE_IDLE_HYSTERESIS_TIME_MS); + kbdev->csf.gpu_idle_dur_count = convert_dur_to_idle_count( + kbdev, FIRMWARE_IDLE_HYSTERESIS_TIME_MS); kbdev->csf.mcu_core_pwroff_dur_us = DEFAULT_GLB_PWROFF_TIMEOUT_US; - kbdev->csf.mcu_core_pwroff_dur_count = - convert_dur_to_core_pwroff_count(kbdev, DEFAULT_GLB_PWROFF_TIMEOUT_US); + kbdev->csf.mcu_core_pwroff_dur_count = convert_dur_to_core_pwroff_count( + kbdev, DEFAULT_GLB_PWROFF_TIMEOUT_US); ret = kbase_mcu_shared_interface_region_tracker_init(kbdev); if (ret != 0) { - dev_err(kbdev->dev, "Failed to setup the rb tree for managing shared interface segment\n"); + dev_err(kbdev->dev, + "Failed to setup the rb tree for managing shared interface segment\n"); goto error; } @@ -2081,7 +2094,7 @@ int kbase_csf_trigger_firmware_config_update(struct kbase_device *kbdev) int err = 0; /* Ensure GPU is powered-up until we complete config update.*/ - kbase_pm_context_active(kbdev); + kbase_csf_scheduler_pm_active(kbdev); /* The 'reg_lock' is also taken and is held till the update is * complete, to ensure the config update gets serialized. @@ -2098,7 +2111,7 @@ int kbase_csf_trigger_firmware_config_update(struct kbase_device *kbdev) GLB_REQ_FIRMWARE_CONFIG_UPDATE_MASK); mutex_unlock(&kbdev->csf.reg_lock); - kbase_pm_context_idle(kbdev); + kbase_csf_scheduler_pm_idle(kbdev); return err; } diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware.h index 768d42339caf..6a78ff23bc8e 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. @@ -79,7 +79,7 @@ #define MAX_SUPPORTED_STREAMS_PER_GROUP 32 /* Waiting timeout for status change acknowledgment, in milliseconds */ -#define CSF_FIRMWARE_TIMEOUT_MS (800) /* Relaxed to 800ms from 100ms */ +#define CSF_FIRMWARE_TIMEOUT_MS (3000) /* Relaxed to 3000ms from 800ms due to Android */ struct kbase_device; @@ -266,7 +266,7 @@ u32 kbase_csf_firmware_csg_output( * @group_stride: Stride in bytes in JASID0 virtual address between * CSG capability structures. * @prfcnt_size: Performance counters size. - * @instr_features: Instrumentation features. + * @instr_features: Instrumentation features. (csf >= 1.1.0) * @groups: Address of an array of CSG capability structures. */ struct kbase_csf_global_iface { @@ -376,23 +376,31 @@ void kbase_csf_read_firmware_memory(struct kbase_device *kbdev, void kbase_csf_update_firmware_memory(struct kbase_device *kbdev, u32 gpu_addr, u32 value); +/** + * kbase_csf_firmware_early_init() - Early initializatin for the firmware. + * @kbdev: Kbase device + * + * Initialize resources related to the firmware. Must be called at kbase probe. + * + * Return: 0 if successful, negative error code on failure + */ +int kbase_csf_firmware_early_init(struct kbase_device *kbdev); + /** * kbase_csf_firmware_init() - Load the firmware for the CSF MCU + * @kbdev: Kbase device * * Request the firmware from user space and load it into memory. * * Return: 0 if successful, negative error code on failure - * - * @kbdev: Kbase device */ int kbase_csf_firmware_init(struct kbase_device *kbdev); /** * kbase_csf_firmware_term() - Unload the firmware + * @kbdev: Kbase device * * Frees the memory allocated by kbase_csf_firmware_init() - * - * @kbdev: Kbase device */ void kbase_csf_firmware_term(struct kbase_device *kbdev); @@ -443,12 +451,8 @@ void kbase_csf_enter_protected_mode(struct kbase_device *kbdev); static inline bool kbase_csf_firmware_mcu_halted(struct kbase_device *kbdev) { -#ifndef CONFIG_MALI_BIFROST_NO_MALI return (kbase_reg_read(kbdev, GPU_CONTROL_REG(MCU_STATUS)) == MCU_STATUS_HALTED); -#else - return true; -#endif } /** @@ -584,6 +588,7 @@ bool kbase_csf_firmware_core_attr_updated(struct kbase_device *kbdev); * hardware performance counter data. * @instr_features: Instrumentation features. Bits 7:4 hold the max size * of events. Bits 3:0 hold the offset update rate. + * (csf >= 1,1,0) */ u32 kbase_csf_firmware_get_glb_iface( struct kbase_device *kbdev, struct basep_cs_group_control *group_data, diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware_cfg.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware_cfg.c index 10bc4197f83a..f00acb1d106a 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware_cfg.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware_cfg.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware_cfg.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware_cfg.h index 36883abad2eb..080c154cab61 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware_cfg.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware_cfg.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware_no_mali.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware_no_mali.c index 311e3bba6f43..48864cca6b99 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware_no_mali.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware_no_mali.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. @@ -158,7 +158,7 @@ static int invent_memory_setup_entry(struct kbase_device *kbdev) /* Allocate enough memory for the struct dummy_firmware_interface. */ - interface = kmalloc(sizeof(*interface), GFP_KERNEL); + interface = kzalloc(sizeof(*interface), GFP_KERNEL); if (!interface) return -ENOMEM; @@ -237,8 +237,13 @@ static int invent_capabilities(struct kbase_device *kbdev) iface->kbdev = kbdev; iface->features = 0; iface->prfcnt_size = 64; - iface->instr_features = - 0x81; /* update rate=1, max event size = 1<<8 = 256 */ + + if (iface->version >= kbase_csf_interface_version(1, 1, 0)) { + /* update rate=1, max event size = 1<<8 = 256 */ + iface->instr_features = 0x81; + } else { + iface->instr_features = 0; + } iface->group_num = ARRAY_SIZE(interface->csg); iface->group_stride = 0; @@ -375,6 +380,37 @@ u32 kbase_csf_firmware_csg_output( return val; } +static void +csf_firmware_prfcnt_process(const struct kbase_csf_global_iface *const iface, + const u32 glb_req) +{ + struct kbase_device *kbdev = iface->kbdev; + u32 glb_ack = output_page_read(iface->output, GLB_ACK); + /* If the value of GLB_REQ.PRFCNT_SAMPLE is different from the value of + * GLB_ACK.PRFCNT_SAMPLE, the CSF will sample the performance counters. + */ + if ((glb_req ^ glb_ack) & GLB_REQ_PRFCNT_SAMPLE_MASK) { + /* NO_MALI only uses the first buffer in the ring buffer. */ + input_page_write(iface->input, GLB_PRFCNT_EXTRACT, 0); + output_page_write(iface->output, GLB_PRFCNT_INSERT, 1); + kbase_reg_write(kbdev, GPU_COMMAND, GPU_COMMAND_PRFCNT_SAMPLE); + } + + /* Propagate enable masks to model if request to enable. */ + if (glb_req & GLB_REQ_PRFCNT_ENABLE_MASK) { + u32 tiler_en, l2_en, sc_en; + + tiler_en = input_page_read(iface->input, GLB_PRFCNT_TILER_EN); + l2_en = input_page_read(iface->input, GLB_PRFCNT_MMU_L2_EN); + sc_en = input_page_read(iface->input, GLB_PRFCNT_SHADER_EN); + + /* NO_MALI platform enabled all CSHW counters by default. */ + kbase_reg_write(kbdev, PRFCNT_TILER_EN, tiler_en); + kbase_reg_write(kbdev, PRFCNT_MMU_L2_EN, l2_en); + kbase_reg_write(kbdev, PRFCNT_SHADER_EN, sc_en); + } +} + void kbase_csf_firmware_global_input( const struct kbase_csf_global_iface *const iface, const u32 offset, const u32 value) @@ -385,6 +421,7 @@ void kbase_csf_firmware_global_input( input_page_write(iface->input, offset, value); if (offset == GLB_REQ) { + csf_firmware_prfcnt_process(iface, value); /* NO_MALI: Immediately acknowledge requests */ output_page_write(iface->output, GLB_ACK, value); } @@ -854,10 +891,30 @@ u32 kbase_csf_firmware_set_mcu_core_pwroff_time(struct kbase_device *kbdev, u32 return pwroff; } +int kbase_csf_firmware_early_init(struct kbase_device *kbdev) +{ + init_waitqueue_head(&kbdev->csf.event_wait); + kbdev->csf.interrupt_received = false; + kbdev->csf.fw_timeout_ms = CSF_FIRMWARE_TIMEOUT_MS; + + INIT_LIST_HEAD(&kbdev->csf.firmware_interfaces); + INIT_LIST_HEAD(&kbdev->csf.firmware_config); + INIT_LIST_HEAD(&kbdev->csf.firmware_trace_buffers.list); + INIT_WORK(&kbdev->csf.firmware_reload_work, + kbase_csf_firmware_reload_worker); + INIT_WORK(&kbdev->csf.fw_error_work, firmware_error_worker); + + mutex_init(&kbdev->csf.reg_lock); + + return 0; +} + int kbase_csf_firmware_init(struct kbase_device *kbdev) { int ret; + lockdep_assert_held(&kbdev->fw_load_lock); + if (WARN_ON((kbdev->as_free & MCU_AS_BITMASK) == 0)) return -EINVAL; kbdev->as_free &= ~MCU_AS_BITMASK; @@ -871,26 +928,14 @@ int kbase_csf_firmware_init(struct kbase_device *kbdev) return ret; } - init_waitqueue_head(&kbdev->csf.event_wait); - kbdev->csf.interrupt_received = false; - kbdev->csf.fw_timeout_ms = CSF_FIRMWARE_TIMEOUT_MS; - - INIT_LIST_HEAD(&kbdev->csf.firmware_interfaces); - INIT_LIST_HEAD(&kbdev->csf.firmware_config); - INIT_LIST_HEAD(&kbdev->csf.firmware_trace_buffers.list); - INIT_WORK(&kbdev->csf.firmware_reload_work, - kbase_csf_firmware_reload_worker); - INIT_WORK(&kbdev->csf.fw_error_work, firmware_error_worker); - - mutex_init(&kbdev->csf.reg_lock); - kbdev->csf.gpu_idle_hysteresis_ms = FIRMWARE_IDLE_HYSTERESIS_TIME_MS; - kbdev->csf.gpu_idle_dur_count = convert_dur_to_idle_count(kbdev, - FIRMWARE_IDLE_HYSTERESIS_TIME_MS); + kbdev->csf.gpu_idle_dur_count = convert_dur_to_idle_count( + kbdev, FIRMWARE_IDLE_HYSTERESIS_TIME_MS); ret = kbase_mcu_shared_interface_region_tracker_init(kbdev); if (ret != 0) { - dev_err(kbdev->dev, "Failed to setup the rb tree for managing shared interface segment\n"); + dev_err(kbdev->dev, + "Failed to setup the rb tree for managing shared interface segment\n"); goto error; } diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_heap_context_alloc.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_heap_context_alloc.c index 6c6d181d27e1..96746c647665 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_heap_context_alloc.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_heap_context_alloc.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_heap_context_alloc.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_heap_context_alloc.h index a39ee92cad24..993db6347cb1 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_heap_context_alloc.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_heap_context_alloc.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu.c index 1203d2c40807..4e26a496305e 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. @@ -26,7 +26,7 @@ #include "mali_kbase_csf.h" #include -#ifdef CONFIG_SYNC_FILE +#if IS_ENABLED(CONFIG_SYNC_FILE) #include "mali_kbase_fence.h" #include "mali_kbase_sync.h" @@ -758,9 +758,7 @@ static int kbase_kcpu_cqs_wait_process(struct kbase_device *kbdev, KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_CQS_WAIT_END( kbdev, queue, - queue->has_error ? - evt[BASEP_EVENT_ERR_INDEX] : - 0); + evt[BASEP_EVENT_ERR_INDEX]); queue->command_started = false; } @@ -1170,7 +1168,7 @@ static int kbase_kcpu_cqs_set_operation_prepare( return 0; } -#ifdef CONFIG_SYNC_FILE +#if IS_ENABLED(CONFIG_SYNC_FILE) #if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) static void kbase_csf_fence_wait_callback(struct fence *fence, struct fence_cb *cb) @@ -1549,7 +1547,7 @@ static void kcpu_queue_process(struct kbase_kcpu_command_queue *queue, } status = 0; -#ifdef CONFIG_SYNC_FILE +#if IS_ENABLED(CONFIG_SYNC_FILE) if (ignore_waits) { kbase_kcpu_fence_wait_cancel(queue, &cmd->info.fence); @@ -1582,7 +1580,7 @@ static void kcpu_queue_process(struct kbase_kcpu_command_queue *queue, status = 0; -#ifdef CONFIG_SYNC_FILE +#if IS_ENABLED(CONFIG_SYNC_FILE) status = kbase_kcpu_fence_signal_process( queue, &cmd->info.fence); @@ -2021,7 +2019,7 @@ int kbase_csf_kcpu_queue_enqueue(struct kbase_context *kctx, kcpu_cmd->enqueue_ts = kctx->csf.kcpu_queues.num_cmds; switch (command.type) { case BASE_KCPU_COMMAND_TYPE_FENCE_WAIT: -#ifdef CONFIG_SYNC_FILE +#if IS_ENABLED(CONFIG_SYNC_FILE) ret = kbase_kcpu_fence_wait_prepare(queue, &command.info.fence, kcpu_cmd); #else @@ -2030,7 +2028,7 @@ int kbase_csf_kcpu_queue_enqueue(struct kbase_context *kctx, #endif break; case BASE_KCPU_COMMAND_TYPE_FENCE_SIGNAL: -#ifdef CONFIG_SYNC_FILE +#if IS_ENABLED(CONFIG_SYNC_FILE) ret = kbase_kcpu_fence_signal_prepare(queue, &command.info.fence, kcpu_cmd); #else @@ -2231,7 +2229,7 @@ int kbase_csf_kcpu_queue_new(struct kbase_context *kctx, queue->kctx = kctx; queue->start_offset = 0; queue->num_pending_cmds = 0; -#ifdef CONFIG_SYNC_FILE +#if IS_ENABLED(CONFIG_SYNC_FILE) queue->fence_context = dma_fence_context_alloc(1); queue->fence_seqno = 0; queue->fence_wait_processed = false; diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu.h index 86aa7dcc452e..2f6da552fdaf 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu_debugfs.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu_debugfs.c index d59e77c2b98e..0a2cde02fe1c 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu_debugfs.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu_debugfs.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -23,11 +23,11 @@ #include #include -#ifdef CONFIG_SYNC_FILE +#if IS_ENABLED(CONFIG_SYNC_FILE) #include "mali_kbase_sync.h" #endif -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) /** * kbasep_csf_kcpu_debugfs_print_queue() - Print additional info for KCPU @@ -89,7 +89,7 @@ static void kbasep_csf_kcpu_debugfs_print_queue(struct seq_file *file, struct kbase_kcpu_command *cmd = &queue->commands[queue->start_offset]; switch (cmd->type) { -#ifdef CONFIG_SYNC_FILE +#if IS_ENABLED(CONFIG_SYNC_FILE) case BASE_KCPU_COMMAND_TYPE_FENCE_WAIT: { struct kbase_sync_fence_info info; diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu_debugfs.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu_debugfs.h index 58b8e34ead92..08f2fda034a2 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu_debugfs.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_kcpu_debugfs.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_protected_memory.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_protected_memory.c index 09e72711d3cb..599748346f1f 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_protected_memory.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_protected_memory.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -22,7 +22,7 @@ #include "mali_kbase_csf_protected_memory.h" #include -#ifdef CONFIG_OF +#if IS_ENABLED(CONFIG_OF) #include #endif @@ -30,7 +30,7 @@ int kbase_csf_protected_memory_init(struct kbase_device *const kbdev) { int err = 0; -#if CONFIG_OF +#if IS_ENABLED(CONFIG_OF) struct device_node *pma_node = of_parse_phandle(kbdev->dev->of_node, "protected-memory-allocator", 0); if (!pma_node) { diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_protected_memory.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_protected_memory.h index 95f507f52d78..4c0609ee40e1 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_protected_memory.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_protected_memory.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_reset_gpu.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_reset_gpu.c index e8da0f3cccda..f6d61d7fd25d 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_reset_gpu.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_reset_gpu.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_scheduler.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_scheduler.c index f7a20d5f6678..c165c0efe57a 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_scheduler.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_scheduler.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. @@ -25,8 +25,8 @@ #include #include #include "mali_kbase_csf.h" -#include "../tl/mali_kbase_tracepoints.h" -#include "backend/gpu/mali_kbase_pm_internal.h" +#include +#include #include #include #include @@ -307,7 +307,7 @@ static u32 get_nr_active_csgs(struct kbase_device *kbdev) * * Return: the interface is actively engaged flag. */ -bool csgs_active(struct kbase_device *kbdev) +static bool csgs_active(struct kbase_device *kbdev) { u32 nr_active_csgs; @@ -388,11 +388,17 @@ static void scheduler_wait_protm_quit(struct kbase_device *kbdev) lockdep_assert_held(&scheduler->lock); + KBASE_KTRACE_ADD(kbdev, SCHEDULER_WAIT_PROTM_QUIT, NULL, + jiffies_to_msecs(wt)); + remaining = wait_event_timeout(kbdev->csf.event_wait, !kbase_csf_scheduler_protected_mode_in_use(kbdev), wt); if (!remaining) dev_warn(kbdev->dev, "Timeout, protm_quit wait skipped"); + + KBASE_KTRACE_ADD(kbdev, SCHEDULER_WAIT_PROTM_QUIT_DONE, NULL, + jiffies_to_msecs(remaining)); } /** @@ -514,7 +520,7 @@ static void scheduler_suspend(struct kbase_device *kbdev) * This function is called to change the state of queue group to non-idle * suspended state, if the group was suspended when all the queues bound to it * became empty or when some queues got blocked on a sync wait & others became - * empty. The group is also moved to the runnbale list from idle wait list in + * empty. The group is also moved to the runnable list from idle wait list in * the latter case. * So the function gets called when a queue is kicked or sync wait condition * gets satisfied. @@ -523,6 +529,7 @@ static void update_idle_suspended_group_state(struct kbase_queue_group *group) { struct kbase_csf_scheduler *scheduler = &group->kctx->kbdev->csf.scheduler; + int new_val; lockdep_assert_held(&scheduler->lock); @@ -543,7 +550,9 @@ static void update_idle_suspended_group_state(struct kbase_queue_group *group) } else return; - atomic_inc(&scheduler->non_idle_offslot_grps); + new_val = atomic_inc_return(&scheduler->non_idle_offslot_grps); + KBASE_KTRACE_ADD_CSF_GRP(group->kctx->kbdev, SCHEDULER_NONIDLE_OFFSLOT_INC, + group, new_val); } int kbase_csf_scheduler_group_get_slot_locked(struct kbase_queue_group *group) @@ -898,16 +907,8 @@ int kbase_csf_scheduler_queue_stop(struct kbase_queue *queue) static void update_hw_active(struct kbase_queue *queue, bool active) { -#ifdef CONFIG_MALI_BIFROST_NO_MALI - if (queue && queue->enabled) { - u32 *output_addr = (u32 *)(queue->user_io_addr + PAGE_SIZE); - - output_addr[CS_ACTIVE / sizeof(u32)] = active; - } -#else CSTD_UNUSED(queue); CSTD_UNUSED(active); -#endif } static void program_cs_extract_init(struct kbase_queue *queue) @@ -919,6 +920,50 @@ static void program_cs_extract_init(struct kbase_queue *queue) output_addr[CS_EXTRACT_LO / sizeof(u64)]; } +static void program_cs_trace_cfg(struct kbase_csf_cmd_stream_info *stream, + struct kbase_queue *queue) +{ + struct kbase_device *kbdev = queue->kctx->kbdev; + u32 const glb_version = kbdev->csf.global_iface.version; + + lockdep_assert_held(&kbdev->csf.scheduler.lock); + + /* If cs_trace_command not supported, nothing to program */ + if (glb_version < kbase_csf_interface_version(1, 1, 0)) + return; + + /* Program for cs_trace if enabled. In the current arrangement, it is + * possible for the context to enable the cs_trace after some queues + * has been registered in cs_trace in disabled state. This is tracked by + * the queue's trace buffer base address, which had been validated at the + * queue's register_ex call. + */ + if (kbase_csf_scheduler_queue_has_trace(queue)) { + u32 cs_cfg = CS_INSTR_CONFIG_JASID_SET( + queue->trace_cfg, queue->kctx->as_nr); + + kbase_csf_firmware_cs_input(stream, CS_INSTR_CONFIG, cs_cfg); + kbase_csf_firmware_cs_input(stream, CS_INSTR_BUFFER_SIZE, + queue->trace_buffer_size); + + kbase_csf_firmware_cs_input(stream, CS_INSTR_BUFFER_BASE_LO, + queue->trace_buffer_base & U32_MAX); + kbase_csf_firmware_cs_input(stream, CS_INSTR_BUFFER_BASE_HI, + queue->trace_buffer_base >> 32); + + kbase_csf_firmware_cs_input( + stream, CS_INSTR_BUFFER_OFFSET_POINTER_LO, + queue->trace_offset_ptr & U32_MAX); + kbase_csf_firmware_cs_input( + stream, CS_INSTR_BUFFER_OFFSET_POINTER_HI, + queue->trace_offset_ptr >> 32); + } else { + /* Place the configuration to the disabled condition */ + kbase_csf_firmware_cs_input(stream, CS_INSTR_CONFIG, 0); + kbase_csf_firmware_cs_input(stream, CS_INSTR_BUFFER_SIZE, 0); + } +} + static void program_cs(struct kbase_device *kbdev, struct kbase_queue *queue, bool ring_csg_doorbell) { @@ -976,6 +1021,9 @@ static void program_cs(struct kbase_device *kbdev, kbase_csf_firmware_cs_input(stream, CS_CONFIG, (queue->doorbell_nr << 8) | (queue->priority & 0xF)); + /* Program the queue's cs_trace configuration */ + program_cs_trace_cfg(stream, queue); + /* Enable all interrupts for now */ kbase_csf_firmware_cs_input(stream, CS_ACK_IRQ_MASK, ~((u32)0)); @@ -1016,7 +1064,10 @@ int kbase_csf_scheduler_queue_start(struct kbase_queue *queue) mutex_lock(&kbdev->csf.scheduler.lock); - KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, QUEUE_START, group, queue, group->run_state); + KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, QUEUE_START, group, queue, + group->run_state); + KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, QUEUE_SYNC_STATUS_WAIT, queue->group, + queue, queue->status_wait); if (group->run_state == KBASE_CSF_GROUP_FAULT_EVICTED) { err = -EIO; @@ -1228,19 +1279,27 @@ static bool evaluate_sync_update(struct kbase_queue *queue) bool updated = false; u32 *sync_ptr; u32 sync_wait_cond; + u32 sync_current_val; + struct kbase_device *kbdev; if (WARN_ON(!queue)) return false; - lockdep_assert_held(&queue->kctx->kbdev->csf.scheduler.lock); + kbdev = queue->kctx->kbdev; + lockdep_assert_held(&kbdev->csf.scheduler.lock); sync_ptr = kbase_phy_alloc_mapping_get(queue->kctx, queue->sync_ptr, &mapping); + KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, QUEUE_SYNC_UPDATE, queue->group, + queue, queue->sync_ptr); + KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, QUEUE_SYNC_BLOCKED_REASON, + queue->group, queue, queue->blocked_reason); + if (!sync_ptr) { dev_dbg(queue->kctx->kbdev->dev, "sync memory VA 0x%016llX already freed", queue->sync_ptr); - return false; + goto out; } sync_wait_cond = @@ -1249,21 +1308,30 @@ static bool evaluate_sync_update(struct kbase_queue *queue) WARN_ON((sync_wait_cond != CS_STATUS_WAIT_SYNC_WAIT_CONDITION_GT) && (sync_wait_cond != CS_STATUS_WAIT_SYNC_WAIT_CONDITION_LE)); + sync_current_val = READ_ONCE(*sync_ptr); + KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, QUEUE_SYNC_CURRENT_VAL, queue->group, + queue, sync_current_val); + + KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, QUEUE_SYNC_TEST_VAL, queue->group, + queue, queue->sync_value); + if (((sync_wait_cond == CS_STATUS_WAIT_SYNC_WAIT_CONDITION_GT) && - (*sync_ptr > queue->sync_value)) || + (sync_current_val > queue->sync_value)) || ((sync_wait_cond == CS_STATUS_WAIT_SYNC_WAIT_CONDITION_LE) && - (*sync_ptr <= queue->sync_value))) { + (sync_current_val <= queue->sync_value))) { /* The sync wait condition is satisfied so the group to which * queue is bound can be re-scheduled. */ updated = true; } else { - dev_dbg(queue->kctx->kbdev->dev, "sync memory not updated yet(%u)", - *sync_ptr); + dev_dbg(queue->kctx->kbdev->dev, + "sync memory not updated yet(%u)", sync_current_val); } kbase_phy_alloc_mapping_put(queue->kctx, mapping); - +out: + KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, QUEUE_SYNC_UPDATE_EVALUATED, + queue->group, queue, updated); return updated; } @@ -1290,6 +1358,9 @@ bool save_slot_cs(struct kbase_csf_cmd_stream_group_info const *const ginfo, u32 status = kbase_csf_firmware_cs_output(stream, CS_STATUS_WAIT); bool is_waiting = false; + KBASE_KTRACE_ADD_CSF_GRP_Q(stream->kbdev, QUEUE_SYNC_STATUS_WAIT, + queue->group, queue, status); + if (CS_STATUS_WAIT_SYNC_WAIT_GET(status)) { queue->status_wait = status; queue->sync_ptr = kbase_csf_firmware_cs_output(stream, @@ -1408,11 +1479,15 @@ void insert_group_to_runnable(struct kbase_csf_scheduler *const scheduler, list_add_tail(&group->link, &kctx->csf.sched.runnable_groups[group->priority]); kctx->csf.sched.num_runnable_grps++; + KBASE_KTRACE_ADD_CSF_GRP(kbdev, GROUP_INSERT_RUNNABLE, group, + kctx->csf.sched.num_runnable_grps); + /* Add the kctx if not yet in runnable kctxs */ if (kctx->csf.sched.num_runnable_grps == 1) { /* First runnable csg, adds to the runnable_kctxs */ INIT_LIST_HEAD(&kctx->csf.link); list_add_tail(&kctx->csf.link, &scheduler->runnable_kctxs); + KBASE_KTRACE_ADD(kbdev, SCHEDULER_INSERT_RUNNABLE, kctx, 0u); } scheduler->total_runnable_grps++; @@ -1438,6 +1513,9 @@ void remove_group_from_runnable(struct kbase_csf_scheduler *const scheduler, enum kbase_csf_group_state run_state) { struct kbase_context *kctx = group->kctx; + struct kbase_queue_group *new_head_grp; + struct list_head *list = + &kctx->csf.sched.runnable_groups[group->priority]; lockdep_assert_held(&scheduler->lock); @@ -1470,11 +1548,28 @@ void remove_group_from_runnable(struct kbase_csf_scheduler *const scheduler, } kctx->csf.sched.num_runnable_grps--; + KBASE_KTRACE_ADD_CSF_GRP(kctx->kbdev, GROUP_REMOVE_RUNNABLE, group, + kctx->csf.sched.num_runnable_grps); + new_head_grp = (!list_empty(list)) ? + list_first_entry(list, struct kbase_queue_group, link) : + NULL; + KBASE_KTRACE_ADD_CSF_GRP(kctx->kbdev, GROUP_HEAD_RUNNABLE, new_head_grp, + 0u); + if (kctx->csf.sched.num_runnable_grps == 0) { + struct kbase_context *new_head_kctx; + struct list_head *kctx_list = &scheduler->runnable_kctxs; /* drop the kctx */ list_del_init(&kctx->csf.link); if (scheduler->top_ctx == kctx) scheduler->top_ctx = NULL; + KBASE_KTRACE_ADD(kctx->kbdev, SCHEDULER_REMOVE_RUNNABLE, kctx, + 0u); + new_head_kctx = (!list_empty(kctx_list)) ? + list_first_entry(kctx_list, struct kbase_context, csf.link) : + NULL; + KBASE_KTRACE_ADD(kctx->kbdev, SCHEDULER_HEAD_RUNNABLE, + new_head_kctx, 0u); } WARN_ON(scheduler->total_runnable_grps == 0); @@ -1501,6 +1596,8 @@ static void insert_group_to_idle_wait(struct kbase_queue_group *const group) list_add_tail(&group->link, &kctx->csf.sched.idle_wait_groups); kctx->csf.sched.num_idle_wait_grps++; + KBASE_KTRACE_ADD_CSF_GRP(kctx->kbdev, GROUP_INSERT_IDLE_WAIT, group, + kctx->csf.sched.num_idle_wait_grps); group->run_state = KBASE_CSF_GROUP_SUSPENDED_ON_WAIT_SYNC; dev_dbg(kctx->kbdev->dev, "Group-%d suspended on sync_wait, total wait_groups: %u\n", @@ -1510,6 +1607,8 @@ static void insert_group_to_idle_wait(struct kbase_queue_group *const group) static void remove_group_from_idle_wait(struct kbase_queue_group *const group) { struct kbase_context *kctx = group->kctx; + struct list_head *list = &kctx->csf.sched.idle_wait_groups; + struct kbase_queue_group *new_head_grp; lockdep_assert_held(&kctx->kbdev->csf.scheduler.lock); @@ -1518,6 +1617,13 @@ static void remove_group_from_idle_wait(struct kbase_queue_group *const group) list_del_init(&group->link); WARN_ON(kctx->csf.sched.num_idle_wait_grps == 0); kctx->csf.sched.num_idle_wait_grps--; + KBASE_KTRACE_ADD_CSF_GRP(kctx->kbdev, GROUP_REMOVE_IDLE_WAIT, group, + kctx->csf.sched.num_idle_wait_grps); + new_head_grp = (!list_empty(list)) ? + list_first_entry(list, struct kbase_queue_group, link) : + NULL; + KBASE_KTRACE_ADD_CSF_GRP(kctx->kbdev, GROUP_HEAD_IDLE_WAIT, + new_head_grp, 0u); group->run_state = KBASE_CSF_GROUP_INACTIVE; } @@ -1540,8 +1646,12 @@ static void update_offslot_non_idle_cnt_for_faulty_grp(struct kbase_queue_group lockdep_assert_held(&scheduler->lock); - if (group->prepared_seq_num < scheduler->non_idle_scanout_grps) - atomic_dec(&scheduler->non_idle_offslot_grps); + if (group->prepared_seq_num < scheduler->non_idle_scanout_grps) { + int new_val = + atomic_dec_return(&scheduler->non_idle_offslot_grps); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_NONIDLE_OFFSLOT_DEC, + group, new_val); + } } static void update_offslot_non_idle_cnt_for_onslot_grp(struct kbase_queue_group *group) @@ -1553,8 +1663,12 @@ static void update_offslot_non_idle_cnt_for_onslot_grp(struct kbase_queue_group WARN_ON(group->csg_nr < 0); - if (group->prepared_seq_num < scheduler->non_idle_scanout_grps) - atomic_dec(&scheduler->non_idle_offslot_grps); + if (group->prepared_seq_num < scheduler->non_idle_scanout_grps) { + int new_val = + atomic_dec_return(&scheduler->non_idle_offslot_grps); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_NONIDLE_OFFSLOT_DEC, + group, new_val); + } } static void update_offslot_non_idle_cnt_on_grp_suspend( @@ -1570,16 +1684,28 @@ static void update_offslot_non_idle_cnt_on_grp_suspend( if (group->prepared_seq_num >= scheduler->non_idle_scanout_grps) { /* At scanout, it was tagged as on-slot idle */ - if (group->run_state == KBASE_CSF_GROUP_SUSPENDED) - atomic_inc(&scheduler->non_idle_offslot_grps); + if (group->run_state == KBASE_CSF_GROUP_SUSPENDED) { + int new_val = atomic_inc_return( + &scheduler->non_idle_offslot_grps); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_NONIDLE_OFFSLOT_INC, + group, new_val); + } } else { - if (group->run_state != KBASE_CSF_GROUP_SUSPENDED) - atomic_dec(&scheduler->non_idle_offslot_grps); + if (group->run_state != KBASE_CSF_GROUP_SUSPENDED) { + int new_val = atomic_dec_return( + &scheduler->non_idle_offslot_grps); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_NONIDLE_OFFSLOT_DEC, + group, new_val); + } } } else { /* async phases */ - if (group->run_state == KBASE_CSF_GROUP_SUSPENDED) - atomic_inc(&scheduler->non_idle_offslot_grps); + if (group->run_state == KBASE_CSF_GROUP_SUSPENDED) { + int new_val = atomic_inc_return( + &scheduler->non_idle_offslot_grps); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_NONIDLE_OFFSLOT_INC, + group, new_val); + } } } @@ -1641,11 +1767,6 @@ static void save_csg_slot(struct kbase_queue_group *group) bool sync_wait = false; bool idle = kbase_csf_firmware_csg_output(ginfo, CSG_STATUS_STATE) & CSG_STATUS_STATE_IDLE_MASK; - -#ifdef CONFIG_MALI_BIFROST_NO_MALI - for (i = 0; i < max_streams; i++) - update_hw_active(group->bound_queues[i], false); -#endif for (i = 0; idle && i < max_streams; i++) { struct kbase_queue *const queue = group->bound_queues[i]; @@ -1745,8 +1866,11 @@ static bool cleanup_csg_slot(struct kbase_queue_group *group) /* now marking the slot is vacant */ spin_lock_irqsave(&kbdev->csf.scheduler.interrupt_lock, flags); kbdev->csf.scheduler.csg_slots[slot].resident_group = NULL; - group->csg_nr = KBASEP_CSG_NR_INVALID; clear_bit(slot, kbdev->csf.scheduler.csg_slots_idle_mask); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, CSG_SLOT_IDLE_CLEAR, group, + kbdev->csf.scheduler.csg_slots_idle_mask[0]); + + group->csg_nr = KBASEP_CSG_NR_INVALID; set_bit(slot, kbdev->csf.scheduler.csgs_events_enable_mask); clear_bit(slot, kbdev->csf.scheduler.csg_inuse_bitmap); spin_unlock_irqrestore(&kbdev->csf.scheduler.interrupt_lock, flags); @@ -2001,8 +2125,12 @@ static void sched_evict_group(struct kbase_queue_group *group, bool fault, if (update_non_idle_offslot_grps_cnt && (group->run_state == KBASE_CSF_GROUP_SUSPENDED || - group->run_state == KBASE_CSF_GROUP_RUNNABLE)) - atomic_dec(&scheduler->non_idle_offslot_grps); + group->run_state == KBASE_CSF_GROUP_RUNNABLE)) { + int new_val = atomic_dec_return( + &scheduler->non_idle_offslot_grps); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_NONIDLE_OFFSLOT_DEC, + group, new_val); + } for (i = 0; i < MAX_SUPPORTED_STREAMS_PER_GROUP; i++) { if (group->bound_queues[i]) @@ -2047,8 +2175,9 @@ static int term_group_sync(struct kbase_queue_group *group) csg_slot_stopped_locked(kbdev, group->csg_nr), remaining); if (!remaining) { - dev_warn(kbdev->dev, "term request timed out for group %d on slot %d", - group->handle, group->csg_nr); + dev_warn(kbdev->dev, "term request timed out for group %d of context %d_%d on slot %d", + group->handle, group->kctx->tgid, + group->kctx->id, group->csg_nr); if (kbase_prepare_to_reset_gpu(kbdev, RESET_FLAGS_NONE)) kbase_reset_gpu(kbdev); err = -ETIMEDOUT; @@ -2147,9 +2276,12 @@ static int scheduler_group_schedule(struct kbase_queue_group *group) */ spin_lock_irqsave(&scheduler->interrupt_lock, flags); protm_grp = scheduler->active_protm_grp; - if (protm_grp && protm_grp != group) + if (protm_grp && protm_grp != group) { clear_bit((unsigned int)group->csg_nr, scheduler->csg_slots_idle_mask); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, CSG_SLOT_IDLE_CLEAR, group, + scheduler->csg_slots_idle_mask[0]); + } spin_unlock_irqrestore(&scheduler->interrupt_lock, flags); @@ -2166,10 +2298,14 @@ static int scheduler_group_schedule(struct kbase_queue_group *group) } } } else if (!queue_group_scheduled_locked(group)) { + int new_val; insert_group_to_runnable(&kbdev->csf.scheduler, group, KBASE_CSF_GROUP_RUNNABLE); /* A new group into the scheduler */ - atomic_inc(&kbdev->csf.scheduler.non_idle_offslot_grps); + new_val = atomic_inc_return( + &kbdev->csf.scheduler.non_idle_offslot_grps); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_NONIDLE_OFFSLOT_INC, + group, new_val); } /* Since a group has become active now, check if GPU needs to be @@ -2224,13 +2360,12 @@ static inline void count_active_address_space(struct kbase_device *kbdev, kbdev->nr_hw_address_spaces - NUM_RESERVED_AS_SLOTS; if (scheduler->ngrp_to_schedule <= total_csg_slots) { - if (kctx->csf.sched.ngrp_to_schedule == 1) { + if (kctx->csf.sched.ngrp_to_schedule == 1) scheduler->num_active_address_spaces++; - if (scheduler->num_active_address_spaces <= - max_address_space_slots) - scheduler->num_csg_slots_for_tick++; - } + if (scheduler->num_active_address_spaces <= + max_address_space_slots) + scheduler->num_csg_slots_for_tick++; } } @@ -2549,8 +2684,9 @@ static void program_suspending_csg_slots(struct kbase_device *kbdev) */ dev_warn( kbdev->dev, - "Group %pK on slot %u failed to suspend\n", - (void *)group, i); + "Group %d of context %d_%d on slot %u failed to suspend", + group->handle, group->kctx->tgid, + group->kctx->id, i); /* The group has failed suspension, stop * further examination. @@ -2878,6 +3014,8 @@ static bool scheduler_slot_protm_ack(struct kbase_device *const kbdev, struct kbase_queue *queue = group->bound_queues[i]; clear_bit(i, group->protm_pending_bitmap); + KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, PROTM_PENDING_CLEAR, group, + queue, group->protm_pending_bitmap[0]); if (!WARN_ON(!queue) && queue->enabled) { struct kbase_csf_cmd_stream_info *stream = @@ -2889,6 +3027,9 @@ static bool scheduler_slot_protm_ack(struct kbase_device *const kbdev, stream, CS_REQ) & CS_REQ_PROTM_PEND_MASK; + KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, CSI_PROTM_ACK, group, + queue, cs_protm_ack ^ cs_protm_req); + if (cs_protm_ack == cs_protm_req) { dev_dbg(kbdev->dev, "PROTM-ack already done for queue-%d group-%d slot-%d", @@ -2928,11 +3069,16 @@ static void scheduler_group_check_protm_enter(struct kbase_device *const kbdev, { struct kbase_csf_scheduler *scheduler = &kbdev->csf.scheduler; unsigned long flags; + bool protm_in_use; lockdep_assert_held(&scheduler->lock); spin_lock_irqsave(&scheduler->interrupt_lock, flags); + protm_in_use = kbase_csf_scheduler_protected_mode_in_use(kbdev); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_CHECK_PROTM_ENTER, input_grp, + protm_in_use); + /* Firmware samples the PROTM_PEND ACK bit for CSs when * Host sends PROTM_ENTER global request. So if PROTM_PEND ACK bit * is set for a CS after Host has sent the PROTM_ENTER @@ -2951,40 +3097,35 @@ static void scheduler_group_check_protm_enter(struct kbase_device *const kbdev, * be replacement, and that it is currently in a stable state (i.e. the * slot state is running). */ - if (!kbase_csf_scheduler_protected_mode_in_use(kbdev)) { - if (!WARN_ON(!input_grp)) { - const int slot = - kbase_csf_scheduler_group_get_slot_locked( - input_grp); + if (!protm_in_use && !WARN_ON(!input_grp)) { + const int slot = + kbase_csf_scheduler_group_get_slot_locked(input_grp); - /* check the input_grp is running and requesting - * protected mode - */ - if (slot >= 0 && - atomic_read( - &scheduler->csg_slots[slot].state) == - CSG_SLOT_RUNNING) { - if (kctx_as_enabled(input_grp->kctx) && - scheduler_slot_protm_ack(kbdev, - input_grp, slot)) { - /* Option of acknowledging to multiple - * CSGs from the same kctx is dropped, - * after consulting with the - * architecture team. See the comment in - * GPUCORE-21394. - */ + /* check the input_grp is running and requesting protected mode + */ + if (slot >= 0 && + atomic_read(&scheduler->csg_slots[slot].state) == + CSG_SLOT_RUNNING) { + if (kctx_as_enabled(input_grp->kctx) && + scheduler_slot_protm_ack(kbdev, input_grp, slot)) { + /* Option of acknowledging to multiple + * CSGs from the same kctx is dropped, + * after consulting with the + * architecture team. See the comment in + * GPUCORE-21394. + */ - /* Disable the idle timer */ - disable_gpu_idle_fw_timer_locked(kbdev); + /* Disable the idle timer */ + disable_gpu_idle_fw_timer_locked(kbdev); - /* Switch to protected mode */ - scheduler->active_protm_grp = input_grp; - KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_ENTER_PROTM, input_grp, 0u); + /* Switch to protected mode */ + scheduler->active_protm_grp = input_grp; + KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_ENTER_PROTM, + input_grp, 0u); - spin_unlock_irqrestore(&scheduler->interrupt_lock, flags); - kbase_csf_enter_protected_mode(kbdev); - return; - } + spin_unlock_irqrestore(&scheduler->interrupt_lock, flags); + kbase_csf_enter_protected_mode(kbdev); + return; } } } @@ -3175,7 +3316,15 @@ static void scheduler_rotate_groups(struct kbase_device *kbdev) WARN_ON(top_grp->kctx != top_ctx); if (!WARN_ON(list_empty(list))) { + struct kbase_queue_group *new_head_grp; list_move_tail(&top_grp->link, list); + new_head_grp = (!list_empty(list)) ? + list_first_entry(list, struct kbase_queue_group, link) : + NULL; + KBASE_KTRACE_ADD_CSF_GRP(kbdev, GROUP_ROTATE_RUNNABLE, + top_grp, top_ctx->csf.sched.num_runnable_grps); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, GROUP_HEAD_RUNNABLE, + new_head_grp, 0u); dev_dbg(kbdev->dev, "groups rotated for a context, num_runnable_groups: %u\n", scheduler->top_ctx->csf.sched.num_runnable_grps); @@ -3203,7 +3352,15 @@ static void scheduler_rotate_ctxs(struct kbase_device *kbdev) } if (!WARN_ON(!found)) { + struct kbase_context *new_head_kctx; list_move_tail(&pos->csf.link, list); + KBASE_KTRACE_ADD(kbdev, SCHEDULER_ROTATE_RUNNABLE, pos, + 0u); + new_head_kctx = (!list_empty(list)) ? + list_first_entry(list, struct kbase_context, csf.link) : + NULL; + KBASE_KTRACE_ADD(kbdev, SCHEDULER_HEAD_RUNNABLE, + new_head_kctx, 0u); dev_dbg(kbdev->dev, "contexts rotated\n"); } } @@ -3247,10 +3404,14 @@ static void scheduler_update_idle_slots_status(struct kbase_device *kbdev, u32 csg_req; clear_bit(i, scheduler->csg_slots_idle_mask); - + KBASE_KTRACE_ADD_CSF_GRP(kbdev, CSG_SLOT_IDLE_CLEAR, group, + scheduler->csg_slots_idle_mask[0]); if (WARN_ON(!group)) continue; + KBASE_KTRACE_ADD_CSF_GRP(kbdev, CSG_SLOT_STATUS_UPDATE, group, + i); + csg_req = kbase_csf_firmware_csg_output(ginfo, CSG_ACK); csg_req ^= CSG_REQ_STATUS_UPDATE_MASK; kbase_csf_firmware_csg_input_mask(ginfo, CSG_REQ, csg_req, @@ -3279,6 +3440,8 @@ static void scheduler_update_idle_slots_status(struct kbase_device *kbdev, bitmap_copy(failed_csg_bitmap, csg_bitmap, num_groups); csg_bitmap[0] = ~csg_bitmap[0] & db_slots; } else { + KBASE_KTRACE_ADD(kbdev, SLOTS_STATUS_UPDATE_ACK, NULL, + db_slots); csg_bitmap[0] = db_slots; } } @@ -3336,6 +3499,8 @@ static void scheduler_handle_idle_slots(struct kbase_device *kbdev) if (group_on_slot_is_idle(kbdev, i)) { group->run_state = KBASE_CSF_GROUP_IDLE; set_bit(i, scheduler->csg_slots_idle_mask); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, CSG_SLOT_IDLE_SET, + group, scheduler->csg_slots_idle_mask[0]); } else group->run_state = KBASE_CSF_GROUP_RUNNABLE; } @@ -3343,6 +3508,8 @@ static void scheduler_handle_idle_slots(struct kbase_device *kbdev) bitmap_or(scheduler->csg_slots_idle_mask, scheduler->csg_slots_idle_mask, failed_csg_bitmap, num_groups); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, CSG_SLOT_IDLE_SET, NULL, + scheduler->csg_slots_idle_mask[0]); spin_unlock_irqrestore(&scheduler->interrupt_lock, flags); } @@ -3477,20 +3644,32 @@ static void gpu_idle_worker(struct work_struct *work) struct kbase_device *kbdev = container_of( work, struct kbase_device, csf.scheduler.gpu_idle_work); struct kbase_csf_scheduler *const scheduler = &kbdev->csf.scheduler; + bool reset_active = false; + bool scheduler_is_idle_suspendable = false; + bool all_groups_suspended = false; + + KBASE_KTRACE_ADD(kbdev, IDLE_WORKER_BEGIN, NULL, 0u); + +#define __ENCODE_KTRACE_INFO(reset, idle, all_suspend) \ + (((u32)reset) | (((u32)idle) << 4) | (((u32)all_suspend) << 8)) if (kbase_reset_gpu_try_prevent(kbdev)) { dev_warn(kbdev->dev, "Quit idle for failing to prevent gpu reset.\n"); + KBASE_KTRACE_ADD(kbdev, IDLE_WORKER_END, NULL, + __ENCODE_KTRACE_INFO(true, false, false)); return; } mutex_lock(&scheduler->lock); /* Cycle completed, disable the firmware idle timer */ disable_gpu_idle_fw_timer(kbdev); - if (scheduler_idle_suspendable(kbdev) && - !kbase_reset_gpu_is_active(kbdev)) { - int ret = suspend_active_groups_on_powerdown(kbdev, false); + scheduler_is_idle_suspendable = scheduler_idle_suspendable(kbdev); + reset_active = kbase_reset_gpu_is_active(kbdev); + if (scheduler_is_idle_suspendable && !reset_active) { + all_groups_suspended = + !suspend_active_groups_on_powerdown(kbdev, false); - if (!ret) { + if (all_groups_suspended) { dev_dbg(kbdev->dev, "Scheduler becomes idle suspended now"); scheduler_suspend(kbdev); cancel_tick_timer(kbdev); @@ -3504,6 +3683,9 @@ static void gpu_idle_worker(struct work_struct *work) mutex_unlock(&scheduler->lock); kbase_reset_gpu_allow(kbdev); + KBASE_KTRACE_ADD(kbdev, IDLE_WORKER_END, NULL, + __ENCODE_KTRACE_INFO(reset_active, scheduler_is_idle_suspendable, all_groups_suspended)); +#undef __ENCODE_KTRACE_INFO } static int scheduler_prepare(struct kbase_device *kbdev) @@ -3552,6 +3734,8 @@ static int scheduler_prepare(struct kbase_device *kbdev) */ atomic_set(&scheduler->non_idle_offslot_grps, scheduler->non_idle_scanout_grps); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_NONIDLE_OFFSLOT_INC, NULL, + scheduler->non_idle_scanout_grps); /* Adds those idle but runnable groups to the scanout list */ scheduler_scan_idle_groups(kbdev); @@ -3634,9 +3818,12 @@ static void schedule_actions(struct kbase_device *kbdev) * queue jobs. */ if (protm_grp && scheduler->top_grp == protm_grp) { + int new_val; dev_dbg(kbdev->dev, "Scheduler keep protm exec: group-%d", protm_grp->handle); - atomic_dec(&scheduler->non_idle_offslot_grps); + new_val = atomic_dec_return(&scheduler->non_idle_offslot_grps); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_NONIDLE_OFFSLOT_DEC, + protm_grp, new_val); } else if (scheduler->top_grp) { if (protm_grp) dev_dbg(kbdev->dev, "Scheduler drop protm exec: group-%d", @@ -3725,6 +3912,7 @@ static void schedule_on_tock(struct work_struct *work) dev_dbg(kbdev->dev, "Waking up for event after schedule-on-tock completes."); wake_up_all(&kbdev->csf.event_wait); + KBASE_KTRACE_ADD(kbdev, SCHEDULER_TOCK_END, NULL, 0u); return; exit_no_schedule_unlock: @@ -3756,7 +3944,8 @@ static void schedule_on_tick(struct work_struct *work) scheduler_rotate(kbdev); /* Undertaking schedule action steps */ - KBASE_KTRACE_ADD(kbdev, SCHEDULER_TICK, NULL, 0u); + KBASE_KTRACE_ADD(kbdev, SCHEDULER_TICK, NULL, + scheduler->total_runnable_grps); schedule_actions(kbdev); /* Record time information */ @@ -3777,6 +3966,8 @@ static void schedule_on_tick(struct work_struct *work) dev_dbg(kbdev->dev, "Waking up for event after schedule-on-tick completes."); wake_up_all(&kbdev->csf.event_wait); + KBASE_KTRACE_ADD(kbdev, SCHEDULER_TICK_END, NULL, + scheduler->total_runnable_grps); return; exit_no_schedule_unlock: @@ -3784,7 +3975,7 @@ exit_no_schedule_unlock: kbase_reset_gpu_allow(kbdev); } -int wait_csg_slots_suspend(struct kbase_device *kbdev, +static int wait_csg_slots_suspend(struct kbase_device *kbdev, const unsigned long *slot_mask, unsigned int timeout_ms) { @@ -3907,6 +4098,82 @@ static int suspend_active_queue_groups_on_reset(struct kbase_device *kbdev) return ret; } +/** + * scheduler_handle_reset_in_protected_mode() - Update the state of normal mode + * groups when reset is done during + * protected mode execution. + * + * @group: Pointer to the device. + * + * This function is called at the time of GPU reset, before the suspension of + * queue groups, to handle the case when the reset is getting performed whilst + * GPU is in protected mode. + * On entry to protected mode all the groups, except the top group that executes + * in protected mode, are implicitly suspended by the FW. Thus this function + * simply marks the normal mode groups as suspended (and cleans up the + * corresponding CSG slots) to prevent their potential forceful eviction from + * the Scheduler. So if GPU was in protected mode and there was no fault, then + * only the protected mode group would be suspended in the regular way post exit + * from this function. And if GPU was in normal mode, then all on-slot groups + * will get suspended in the regular way. + * + * Return: true if the groups remaining on the CSG slots need to be suspended in + * the regular way by sending CSG SUSPEND reqs to FW, otherwise false. + */ +static bool scheduler_handle_reset_in_protected_mode(struct kbase_device *kbdev) +{ + struct kbase_csf_scheduler *scheduler = &kbdev->csf.scheduler; + u32 const num_groups = kbdev->csf.global_iface.group_num; + struct kbase_queue_group *protm_grp; + bool suspend_on_slot_groups; + unsigned long flags; + u32 csg_nr; + + mutex_lock(&scheduler->lock); + + spin_lock_irqsave(&scheduler->interrupt_lock, flags); + protm_grp = scheduler->active_protm_grp; + + /* If GPU wasn't in protected mode or had exited it before the GPU reset + * then all the on-slot groups can be suspended in the regular way by + * sending CSG SUSPEND requests to FW. + * If there wasn't a fault for protected mode group, then it would + * also need to be suspended in the regular way before the reset. + */ + suspend_on_slot_groups = !(protm_grp && protm_grp->faulted); + spin_unlock_irqrestore(&scheduler->interrupt_lock, flags); + + if (!protm_grp) + goto unlock; + + /* GPU is in protected mode, so all the on-slot groups barring the + * the protected mode group can be marked as suspended right away. + */ + for (csg_nr = 0; csg_nr < num_groups; csg_nr++) { + struct kbase_queue_group *const group = + kbdev->csf.scheduler.csg_slots[csg_nr].resident_group; + int new_val; + + if (!group || (group == protm_grp)) + continue; + + cleanup_csg_slot(group); + group->run_state = KBASE_CSF_GROUP_SUSPENDED; + + /* Simply treat the normal mode groups as non-idle. The tick + * scheduled after the reset will re-initialize the counter + * anyways. + */ + new_val = atomic_inc_return(&scheduler->non_idle_offslot_grps); + KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_NONIDLE_OFFSLOT_INC, + group, new_val); + } + +unlock: + mutex_unlock(&scheduler->lock); + return suspend_on_slot_groups; +} + static void scheduler_inner_reset(struct kbase_device *kbdev) { u32 const num_groups = kbdev->csf.global_iface.group_num; @@ -3926,6 +4193,9 @@ static void scheduler_inner_reset(struct kbase_device *kbdev) spin_lock_irqsave(&scheduler->interrupt_lock, flags); bitmap_fill(scheduler->csgs_events_enable_mask, MAX_SUPPORTED_CSGS); + if (scheduler->active_protm_grp) + KBASE_KTRACE_ADD_CSF_GRP(kbdev, SCHEDULER_EXIT_PROTM, + scheduler->active_protm_grp, 0u); scheduler->active_protm_grp = NULL; memset(kbdev->csf.scheduler.csg_slots, 0, num_groups * sizeof(struct kbase_csf_csg_slot)); @@ -3949,7 +4219,9 @@ void kbase_csf_scheduler_reset(struct kbase_device *kbdev) WARN_ON(!kbase_reset_gpu_is_active(kbdev)); KBASE_KTRACE_ADD(kbdev, SCHEDULER_RESET, NULL, 0u); - if (!suspend_active_queue_groups_on_reset(kbdev)) { + + if (scheduler_handle_reset_in_protected_mode(kbdev) && + !suspend_active_queue_groups_on_reset(kbdev)) { /* As all groups have been successfully evicted from the CSG * slots, clear out thee scheduler data fields and return */ @@ -4194,20 +4466,24 @@ static bool group_sync_updated(struct kbase_queue_group *group) * This function is called outside the scheduling tick/tock to determine * if the given GPU queue group can now execute in protected mode or not. * If the group pointer passed is NULL then the evaluation is done for the - * scheduler->top_grp (or the second top-group). + * highest priority group on the scheduler maintained group lists without + * tick associated rotation actions. This is referred as the 'top-group' + * in a tock action sense. * * It returns the same group pointer, that was passed as an argument, if that - * group matches the scheduler->top_grp and has pending protected region + * group matches the highest priority group and has pending protected region * requests otherwise NULL is returned. * - * If the group pointer passed is NULL then the pointer to scheduler->top_grp - * is returned if that has pending protected region requests otherwise NULL is - * returned. + * If the group pointer passed is NULL then the internal evaluated highest + * priority group is returned if that has pending protected region requests + * otherwise NULL is returned. * - * If the scheduler->top_grp is NULL, which may happen when the top-group is - * evicted during the tick, the second top-group (as a replacement of the - * top-group) is used for the match check and also for the evaluation of - * pending protected region requests if the group pointer passed is NULL. + * The evaluated highest priority group may not necessarily be the same as the + * scheduler->top_grp. This can happen if there is dynamic de-idle update + * during the tick interval for some on-slots groups that were idle during the + * scheduler normal scheduling action, where the scheduler->top_grp was set. + * The recorded scheduler->top_grp is untouched by this evualuation, so will not + * affect the scheduler context/priority list rotation arrangement. * * Return: the pointer to queue group that can currently execute in protected * mode or NULL. @@ -4224,8 +4500,7 @@ static struct kbase_queue_group *scheduler_get_protm_enter_async_group( if (scheduler->state != SCHED_INACTIVE) return NULL; - match_grp = scheduler->top_grp ? scheduler->top_grp : - get_tock_top_group(scheduler); + match_grp = get_tock_top_group(scheduler); input_grp = group ? group : match_grp; if (input_grp && (input_grp == match_grp)) { @@ -4308,6 +4583,9 @@ static bool check_sync_update_for_idle_group_protm( stream, CS_STATUS_WAIT); unsigned long flags; + KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, QUEUE_SYNC_STATUS_WAIT, + queue->group, queue, status); + if (!CS_STATUS_WAIT_SYNC_WAIT_GET(status)) continue; @@ -4323,17 +4601,32 @@ static bool check_sync_update_for_idle_group_protm( stream, CS_STATUS_WAIT_SYNC_POINTER_HI) << 32; queue->sync_value = kbase_csf_firmware_cs_output( stream, CS_STATUS_WAIT_SYNC_VALUE); + queue->blocked_reason = + CS_STATUS_BLOCKED_REASON_REASON_GET( + kbase_csf_firmware_cs_output( + stream, + CS_STATUS_BLOCKED_REASON)); if (!evaluate_sync_update(queue)) continue; /* Update csg_slots_idle_mask and group's run_state */ - spin_lock_irqsave(&scheduler->interrupt_lock, flags); - clear_bit((unsigned int)group->csg_nr, - scheduler->csg_slots_idle_mask); - spin_unlock_irqrestore(&scheduler->interrupt_lock, - flags); - group->run_state = KBASE_CSF_GROUP_RUNNABLE; + if (group->run_state != KBASE_CSF_GROUP_RUNNABLE) { + /* Only clear the group's idle flag if it has been dealt + * with by the scheduler's tick/tock action, otherwise + * leave it untouched. + */ + spin_lock_irqsave(&scheduler->interrupt_lock, + flags); + clear_bit((unsigned int)group->csg_nr, + scheduler->csg_slots_idle_mask); + KBASE_KTRACE_ADD_CSF_GRP( + kbdev, CSG_SLOT_IDLE_CLEAR, group, + scheduler->csg_slots_idle_mask[0]); + spin_unlock_irqrestore( + &scheduler->interrupt_lock, flags); + group->run_state = KBASE_CSF_GROUP_RUNNABLE; + } KBASE_KTRACE_ADD_CSF_GRP(kbdev, GROUP_SYNC_UPDATE_DONE, group, 0u); sync_update_done = true; @@ -4419,6 +4712,7 @@ static void check_group_sync_update_worker(struct work_struct *work) mutex_lock(&scheduler->lock); + KBASE_KTRACE_ADD(kbdev, GROUP_SYNC_UPDATE_WORKER_BEGIN, kctx, 0u); if (kctx->csf.sched.num_idle_wait_grps != 0) { struct kbase_queue_group *group, *temp; @@ -4438,6 +4732,7 @@ static void check_group_sync_update_worker(struct work_struct *work) if (check_sync_update_for_idle_groups_protm(kbdev)) scheduler_force_protm_exit(kbdev); + KBASE_KTRACE_ADD(kbdev, GROUP_SYNC_UPDATE_WORKER_END, kctx, 0u); mutex_unlock(&scheduler->lock); } @@ -4515,15 +4810,18 @@ int kbase_csf_scheduler_init(struct kbase_device *kbdev) return -ENOMEM; } + return 0; +} + +int kbase_csf_scheduler_early_init(struct kbase_device *kbdev) +{ + struct kbase_csf_scheduler *scheduler = &kbdev->csf.scheduler; + scheduler->timer_enabled = true; scheduler->wq = alloc_ordered_workqueue("csf_scheduler_wq", WQ_HIGHPRI); if (!scheduler->wq) { dev_err(kbdev->dev, "Failed to allocate scheduler workqueue\n"); - - kfree(scheduler->csg_slots); - scheduler->csg_slots = NULL; - return -ENOMEM; } @@ -4581,13 +4879,18 @@ void kbase_csf_scheduler_term(struct kbase_device *kbdev) cancel_tick_timer(kbdev); cancel_work_sync(&kbdev->csf.scheduler.tick_work); cancel_delayed_work_sync(&kbdev->csf.scheduler.tock_work); - destroy_workqueue(kbdev->csf.scheduler.wq); mutex_destroy(&kbdev->csf.scheduler.lock); kfree(kbdev->csf.scheduler.csg_slots); kbdev->csf.scheduler.csg_slots = NULL; } } +void kbase_csf_scheduler_early_term(struct kbase_device *kbdev) +{ + if (kbdev->csf.scheduler.wq) + destroy_workqueue(kbdev->csf.scheduler.wq); +} + /** * scheduler_enable_tick_timer_nolock - Enable the scheduler tick timer. * diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_scheduler.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_scheduler.h index 1607ff637554..428ecbee790a 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_scheduler.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_scheduler.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -168,11 +168,24 @@ int kbase_csf_scheduler_context_init(struct kbase_context *kctx); * The scheduler does the arbitration for the CSG slots * provided by the firmware between the GPU command queue groups created * by the Clients. + * This function must be called after loading firmware and parsing its capabilities. * * Return: 0 on success, or negative on failure. */ int kbase_csf_scheduler_init(struct kbase_device *kbdev); +/** + * kbase_csf_scheduler_early_init - Early initialization for the CSF scheduler + * + * @kbdev: Instance of a GPU platform device that implements a CSF interface. + * + * Initialize necessary resources such as locks, workqueue for CSF scheduler. + * This must be called at kbase probe. + * + * Return: 0 on success, or negative on failure. + */ +int kbase_csf_scheduler_early_init(struct kbase_device *kbdev); + /** * kbase_csf_scheduler_context_term() - Terminate the context-specific part * for CSF scheduler. @@ -193,6 +206,15 @@ void kbase_csf_scheduler_context_term(struct kbase_context *kctx); */ void kbase_csf_scheduler_term(struct kbase_device *kbdev); +/** + * kbase_csf_scheduler_early_term - Early termination of the CSF scheduler. + * + * @kbdev: Instance of a GPU platform device that implements a CSF interface. + * + * This should be called only when kbase probe fails or gets rmmoded. + */ +void kbase_csf_scheduler_early_term(struct kbase_device *kbdev); + /** * kbase_csf_scheduler_reset - Reset the state of all active GPU command * queue groups. @@ -422,8 +444,11 @@ kbase_csf_scheduler_advance_tick_nolock(struct kbase_device *kbdev) lockdep_assert_held(&scheduler->interrupt_lock); if (scheduler->tick_timer_active) { + KBASE_KTRACE_ADD(kbdev, SCHEDULER_ADVANCE_TICK, NULL, 0u); scheduler->tick_timer_active = false; queue_work(scheduler->wq, &scheduler->tick_work); + } else { + KBASE_KTRACE_ADD(kbdev, SCHEDULER_NOADVANCE_TICK, NULL, 0u); } } @@ -446,4 +471,24 @@ static inline void kbase_csf_scheduler_advance_tick(struct kbase_device *kbdev) spin_unlock_irqrestore(&scheduler->interrupt_lock, flags); } +/** + * kbase_csf_scheduler_queue_has_trace() - report whether the queue has been + * configured to operate with the + * cs_trace feature. + * + * @queue: Pointer to the queue. + * + * Return: True if the gpu queue is configured to operate with the cs_trace + * feature, otherwise false. + */ +static inline bool kbase_csf_scheduler_queue_has_trace(struct kbase_queue *queue) +{ + lockdep_assert_held(&queue->kctx->kbdev->csf.scheduler.lock); + /* In the current arrangement, it is possible for the context to enable + * the cs_trace after some queues have been registered with cs_trace in + * disabled state. So each queue has its own enabled/disabled condition. + */ + return (queue->trace_buffer_size && queue->trace_buffer_base); +} + #endif /* _KBASE_CSF_SCHEDULER_H_ */ diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap.c index 4b402df2f1c3..b31c82eadb96 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap.h index 683aeca38bc3..04c27f7dd40e 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap_debugfs.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap_debugfs.c index 0f69500f01ca..f46beed102e0 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap_debugfs.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap_debugfs.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -24,7 +24,7 @@ #include #include -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) /** * kbasep_csf_tiler_heap_debugfs_show() - Print tiler heap information for per context diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap_debugfs.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap_debugfs.h index 65dfaf701845..92ae91a1e620 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap_debugfs.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap_debugfs.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap_def.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap_def.h index 0bf655178fae..fb439cfe492d 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap_def.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap_def.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_timeout.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_timeout.c index 854aad581318..4d93fe56e529 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_timeout.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_timeout.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -147,7 +147,7 @@ int kbase_csf_timeout_init(struct kbase_device *const kbdev) u64 timeout = DEFAULT_PROGRESS_TIMEOUT; int err; -#ifdef CONFIG_OF +#if IS_ENABLED(CONFIG_OF) err = of_property_read_u64(kbdev->dev->of_node, "progress_timeout", &timeout); if (!err) diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_timeout.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_timeout.h index 48c71818a0ab..b406eaad2d51 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_timeout.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_timeout.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tl_reader.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tl_reader.c index de292c1d0ca2..1824c2d3849a 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tl_reader.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tl_reader.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -35,7 +35,7 @@ #include #include -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) #include "tl/mali_kbase_timeline_priv.h" #include @@ -64,7 +64,7 @@ struct kbase_csffw_tl_message { u64 cycle_counter; } __packed __aligned(4); -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) static int kbase_csf_tl_debugfs_poll_interval_read(void *data, u64 *val) { struct kbase_device *kbdev = (struct kbase_device *)data; @@ -93,11 +93,13 @@ DEFINE_DEBUGFS_ATTRIBUTE(kbase_csf_tl_poll_interval_fops, kbase_csf_tl_debugfs_poll_interval_read, kbase_csf_tl_debugfs_poll_interval_write, "%llu\n"); + void kbase_csf_tl_reader_debugfs_init(struct kbase_device *kbdev) { debugfs_create_file("csf_tl_poll_interval_in_ms", S_IRUGO | S_IWUSR, kbdev->debugfs_instr_directory, kbdev, &kbase_csf_tl_poll_interval_fops); + } #endif @@ -125,6 +127,7 @@ static void get_cpu_gpu_time( *cpu_ts = ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec; } + /** * kbase_ts_converter_init() - Initialize system timestamp converter. * @@ -168,7 +171,7 @@ static int kbase_ts_converter_init( * * Return: The CPU timestamp. */ -void kbase_ts_converter_convert( +static void kbase_ts_converter_convert( const struct kbase_ts_converter *self, u64 *gpu_ts) { @@ -474,14 +477,7 @@ int kbase_csf_tl_reader_start(struct kbase_csf_tl_reader *self, return 0; if (tl_reader_init_late(self, kbdev)) { -#if defined(CONFIG_MALI_BIFROST_NO_MALI) - dev_warn( - kbdev->dev, - "CSFFW timeline is not available for MALI_BIFROST_NO_MALI builds!"); - return 0; -#else return -EINVAL; -#endif } tl_reader_reset(self); diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tl_reader.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tl_reader.h index c691871cbdc5..1b0fcd7602a9 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tl_reader.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tl_reader.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -164,7 +164,7 @@ int kbase_csf_tl_reader_start(struct kbase_csf_tl_reader *self, */ void kbase_csf_tl_reader_stop(struct kbase_csf_tl_reader *self); -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) /** * kbase_csf_tl_reader_debugfs_init() - * Initialize debugfs for CSFFW Timelime Stream Reader. diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_trace_buffer.c b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_trace_buffer.c index afcc90b39b54..a6343c809aad 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_trace_buffer.c +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_trace_buffer.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. @@ -29,7 +29,7 @@ #include #include -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) #if (KERNEL_VERSION(4, 7, 0) > LINUX_VERSION_CODE) #define DEFINE_DEBUGFS_ATTRIBUTE DEFINE_SIMPLE_ATTRIBUTE #endif @@ -513,7 +513,7 @@ unsigned int kbase_csf_firmware_trace_buffer_read_data( } EXPORT_SYMBOL(kbase_csf_firmware_trace_buffer_read_data); -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) #define U32_BITS 32 static u64 get_trace_buffer_active_mask64(struct firmware_trace_buffer *tb) diff --git a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_trace_buffer.h b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_trace_buffer.h index e6babef9250c..b9f481dcf00d 100644 --- a/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_trace_buffer.h +++ b/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_trace_buffer.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. @@ -168,7 +168,7 @@ bool kbase_csf_firmware_trace_buffer_is_empty( unsigned int kbase_csf_firmware_trace_buffer_read_data( struct firmware_trace_buffer *trace_buffer, u8 *data, unsigned int num_bytes); -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) /** * kbase_csf_fw_trace_buffer_debugfs_init() - Add debugfs entries for setting * enable mask and dumping the binary diff --git a/drivers/gpu/arm/bifrost/debug/Kbuild b/drivers/gpu/arm/bifrost/debug/Kbuild new file mode 100644 index 000000000000..6e1f0f75c43e --- /dev/null +++ b/drivers/gpu/arm/bifrost/debug/Kbuild @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note +# +# (C) COPYRIGHT 2021 ARM Limited. All rights reserved. +# +# This program is free software and is provided to you under the terms of the +# GNU General Public License version 2 as published by the Free Software +# Foundation, and any use by you of this program is subject to the terms +# of such GNU license. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you can access it online at +# http://www.gnu.org/licenses/gpl-2.0.html. +# +# + +bifrost_kbase-y += debug/mali_kbase_debug_ktrace.o + +ifeq ($(CONFIG_MALI_CSF_SUPPORT),y) + bifrost_kbase-y += debug/backend/mali_kbase_debug_ktrace_csf.o +else + bifrost_kbase-y += debug/backend/mali_kbase_debug_ktrace_jm.o +endif diff --git a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_codes_csf.h b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_codes_csf.h index 7ed62aa02972..d05f802f0db5 100644 --- a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_codes_csf.h +++ b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_codes_csf.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -50,10 +50,52 @@ int dummy_array[] = { KBASE_KTRACE_CODE_MAKE_CODE(FIRMWARE_BOOT), KBASE_KTRACE_CODE_MAKE_CODE(FIRMWARE_REBOOT), KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_TOCK), + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_TOCK_END), + /* info_val == total number of runnable groups across all kctxs */ KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_TICK), + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_TICK_END), KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_RESET), - KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_EXIT_PROTM), + /* info_val = timeout in ms */ + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_WAIT_PROTM_QUIT), + /* info_val = remaining ms timeout, or 0 if timedout */ + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_WAIT_PROTM_QUIT_DONE), KBASE_KTRACE_CODE_MAKE_CODE(SYNC_UPDATE_EVENT), + KBASE_KTRACE_CODE_MAKE_CODE(SYNC_UPDATE_EVENT_NOTIFY_GPU), + + /* info_val = JOB_IRQ_STATUS */ + KBASE_KTRACE_CODE_MAKE_CODE(CSF_INTERRUPT), + /* info_val = JOB_IRQ_STATUS */ + KBASE_KTRACE_CODE_MAKE_CODE(CSF_INTERRUPT_END), + /* info_val = JOB_IRQ_STATUS */ + KBASE_KTRACE_CODE_MAKE_CODE(CSG_INTERRUPT_PROCESS), + /* info_val = GLB_REQ ^ GLB_ACQ */ + KBASE_KTRACE_CODE_MAKE_CODE(GLB_REQ_ACQ), + /* info_val[31:0] = num non idle offslot groups + * info_val[32] = scheduler can suspend on idle + */ + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_CAN_IDLE), + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_ADVANCE_TICK), + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_NOADVANCE_TICK), + /* kctx is added to the back of the list */ + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_INSERT_RUNNABLE), + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_REMOVE_RUNNABLE), + /* kctx is moved to the back of the list */ + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_ROTATE_RUNNABLE), + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_HEAD_RUNNABLE), + + KBASE_KTRACE_CODE_MAKE_CODE(IDLE_WORKER_BEGIN), + /* 4-bit encoding of boolean values (ease of reading as hex values) + * + * info_val[3:0] = was reset active/failed to be prevented + * info_val[7:4] = whether scheduler was both idle and suspendable + * info_val[11:8] = whether all groups were suspended + */ + KBASE_KTRACE_CODE_MAKE_CODE(IDLE_WORKER_END), + KBASE_KTRACE_CODE_MAKE_CODE(GROUP_SYNC_UPDATE_WORKER_BEGIN), + KBASE_KTRACE_CODE_MAKE_CODE(GROUP_SYNC_UPDATE_WORKER_END), + + /* info_val = bitmask of slots that gave an ACK for STATUS_UPDATE */ + KBASE_KTRACE_CODE_MAKE_CODE(SLOTS_STATUS_UPDATE_ACK), /* * Group events @@ -71,12 +113,30 @@ int dummy_array[] = { KBASE_KTRACE_CODE_MAKE_CODE(CSG_SLOT_STOPPED), /* info_val == slot cleaned */ KBASE_KTRACE_CODE_MAKE_CODE(CSG_SLOT_CLEANED), + /* info_val = slot requesting STATUS_UPDATE */ + KBASE_KTRACE_CODE_MAKE_CODE(CSG_SLOT_STATUS_UPDATE), + /* info_val = scheduler's new csg_slots_idle_mask[0] + * group->csg_nr indicates which bit was set + */ + KBASE_KTRACE_CODE_MAKE_CODE(CSG_SLOT_IDLE_SET), + /* info_val = scheduler's new csg_slots_idle_mask[0] + * group->csg_nr indicates which bit was cleared + * + * in case of no group, multiple bits may have been updated + */ + KBASE_KTRACE_CODE_MAKE_CODE(CSG_SLOT_IDLE_CLEAR), /* info_val == previous priority */ KBASE_KTRACE_CODE_MAKE_CODE(CSG_PRIO_UPDATE), /* info_val == CSG_REQ ^ CSG_ACK */ KBASE_KTRACE_CODE_MAKE_CODE(CSG_SYNC_UPDATE_INTERRUPT), /* info_val == CSG_REQ ^ CSG_ACK */ KBASE_KTRACE_CODE_MAKE_CODE(CSG_IDLE_INTERRUPT), + /* info_val == CSG_REQ ^ CSG_ACK */ + KBASE_KTRACE_CODE_MAKE_CODE(CSG_PROGRESS_TIMER_INTERRUPT), + /* info_val[31:0] == CSG_REQ ^ CSG_ACQ + * info_val[63:32] == CSG_IRQ_REQ ^ CSG_IRQ_ACK + */ + KBASE_KTRACE_CODE_MAKE_CODE(CSG_INTERRUPT_PROCESS_END), KBASE_KTRACE_CODE_MAKE_CODE(GROUP_SYNC_UPDATE_DONE), /* info_val == run state of the group */ KBASE_KTRACE_CODE_MAKE_CODE(GROUP_DESCHEDULE), @@ -86,11 +146,46 @@ int dummy_array[] = { * info_val[63:32] == number of runnable groups */ KBASE_KTRACE_CODE_MAKE_CODE(GROUP_EVICT_SCHED), + + /* info_val == new num_runnable_grps + * group is added to the back of the list for its priority level + */ + KBASE_KTRACE_CODE_MAKE_CODE(GROUP_INSERT_RUNNABLE), + /* info_val == new num_runnable_grps + */ + KBASE_KTRACE_CODE_MAKE_CODE(GROUP_REMOVE_RUNNABLE), + /* info_val == num_runnable_grps + * group is moved to the back of the list for its priority level + */ + KBASE_KTRACE_CODE_MAKE_CODE(GROUP_ROTATE_RUNNABLE), + KBASE_KTRACE_CODE_MAKE_CODE(GROUP_HEAD_RUNNABLE), + /* info_val == new num_idle_wait_grps + * group is added to the back of the list + */ + KBASE_KTRACE_CODE_MAKE_CODE(GROUP_INSERT_IDLE_WAIT), + /* info_val == new num_idle_wait_grps + * group is added to the back of the list + */ + KBASE_KTRACE_CODE_MAKE_CODE(GROUP_REMOVE_IDLE_WAIT), + KBASE_KTRACE_CODE_MAKE_CODE(GROUP_HEAD_IDLE_WAIT), + + /* info_val == is scheduler running with protected mode tasks */ + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_CHECK_PROTM_ENTER), KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_ENTER_PROTM), + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_EXIT_PROTM), /* info_val[31:0] == number of GPU address space slots in use * info_val[63:32] == number of runnable groups */ KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_TOP_GRP), + /* info_val == new count of off-slot non-idle groups + * no group indicates it was set rather than incremented + */ + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_NONIDLE_OFFSLOT_INC), + /* info_val == new count of off-slot non-idle groups */ + KBASE_KTRACE_CODE_MAKE_CODE(SCHEDULER_NONIDLE_OFFSLOT_DEC), + + KBASE_KTRACE_CODE_MAKE_CODE(PROTM_EVENT_WORKER_BEGIN), + KBASE_KTRACE_CODE_MAKE_CODE(PROTM_EVENT_WORKER_END), /* * Group + Queue events @@ -100,13 +195,41 @@ int dummy_array[] = { /* info_val == queue->enabled before stop */ KBASE_KTRACE_CODE_MAKE_CODE(CSI_STOP), KBASE_KTRACE_CODE_MAKE_CODE(CSI_STOP_REQUESTED), + /* info_val == CS_REQ ^ CS_ACK that were not processed due to the group + * being suspended + */ + KBASE_KTRACE_CODE_MAKE_CODE(CSI_IGNORED_INTERRUPTS_GROUP_SUSPEND), /* info_val == CS_REQ ^ CS_ACK */ KBASE_KTRACE_CODE_MAKE_CODE(CSI_FAULT_INTERRUPT), /* info_val == CS_REQ ^ CS_ACK */ KBASE_KTRACE_CODE_MAKE_CODE(CSI_TILER_OOM_INTERRUPT), + /* info_val == CS_REQ ^ CS_ACK */ + KBASE_KTRACE_CODE_MAKE_CODE(CSI_PROTM_PEND_INTERRUPT), + /* info_val == CS_ACK_PROTM_PEND ^ CS_REQ_PROTM_PEND */ + KBASE_KTRACE_CODE_MAKE_CODE(CSI_PROTM_ACK), /* info_val == group->run_State (for group the queue is bound to) */ KBASE_KTRACE_CODE_MAKE_CODE(QUEUE_START), KBASE_KTRACE_CODE_MAKE_CODE(QUEUE_STOP), + /* info_val == contents of CS_STATUS_WAIT_SYNC_POINTER */ + KBASE_KTRACE_CODE_MAKE_CODE(QUEUE_SYNC_UPDATE), + /* info_val == bool for result of the evaluation */ + KBASE_KTRACE_CODE_MAKE_CODE(QUEUE_SYNC_UPDATE_EVALUATED), + /* info_val == contents of CS_STATUS_WAIT */ + KBASE_KTRACE_CODE_MAKE_CODE(QUEUE_SYNC_STATUS_WAIT), + /* info_val == current sync value pointed to by queue->sync_ptr */ + KBASE_KTRACE_CODE_MAKE_CODE(QUEUE_SYNC_CURRENT_VAL), + /* info_val == current value of CS_STATUS_WAIT_SYNC_VALUE */ + KBASE_KTRACE_CODE_MAKE_CODE(QUEUE_SYNC_TEST_VAL), + /* info_val == current value of CS_STATUS_BLOCKED_REASON */ + KBASE_KTRACE_CODE_MAKE_CODE(QUEUE_SYNC_BLOCKED_REASON), + /* info_val = group's new protm_pending_bitmap[0] + * queue->csi_index indicates which bit was set + */ + KBASE_KTRACE_CODE_MAKE_CODE(PROTM_PENDING_SET), + /* info_val = group's new protm_pending_bitmap[0] + * queue->csi_index indicates which bit was cleared + */ + KBASE_KTRACE_CODE_MAKE_CODE(PROTM_PENDING_CLEAR), /* * KCPU queue events diff --git a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_codes_jm.h b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_codes_jm.h index a616f2bc492d..f419f701b523 100644 --- a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_codes_jm.h +++ b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_codes_jm.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2011-2015, 2018-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2011-2015, 2018-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_csf.c b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_csf.c index 9183520a33f0..824ca4b87b36 100644 --- a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_csf.c +++ b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_csf.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_csf.h b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_csf.h index 62cd1bca1292..e3d03730734d 100644 --- a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_csf.h +++ b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_csf.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_defs_csf.h b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_defs_csf.h index ef75afa98585..7f32cd2f23c8 100644 --- a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_defs_csf.h +++ b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_defs_csf.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. @@ -43,9 +43,14 @@ * ringbuffer RBUF (mali_trace) between csi and info_val, which is empty * for non-kcpu related traces, and usually displays the KCPU Queue ID and * an extra information value. ftrace also displays these KCPU traces. + * + * 1.3: + * Add a lot of extra new traces. Tweak some existing scheduler related traces + * to contain extra information information/happen at slightly different times. + * SCHEDULER_EXIT_PROTM now has group information */ #define KBASE_KTRACE_VERSION_MAJOR 1 -#define KBASE_KTRACE_VERSION_MINOR 2 +#define KBASE_KTRACE_VERSION_MINOR 3 /* indicates if the trace message has valid queue-group related info. */ #define KBASE_KTRACE_FLAG_CSF_GROUP (((kbase_ktrace_flag_t)1) << 0) diff --git a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_defs_jm.h b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_defs_jm.h index abd35ff46e06..c01f930ca76f 100644 --- a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_defs_jm.h +++ b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_defs_jm.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_jm.c b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_jm.c index 276290917a82..fed9c1f71c3a 100644 --- a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_jm.c +++ b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_jm.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_jm.h b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_jm.h index 233d06f2eae7..a2ce3c421574 100644 --- a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_jm.h +++ b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_jm.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_linux_ktrace_csf.h b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_linux_ktrace_csf.h index 4ed175e53f49..4b23fc940c93 100644 --- a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_linux_ktrace_csf.h +++ b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_linux_ktrace_csf.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -34,10 +34,30 @@ DEFINE_MALI_ADD_EVENT(EVICT_CTX_SLOTS); DEFINE_MALI_ADD_EVENT(FIRMWARE_BOOT); DEFINE_MALI_ADD_EVENT(FIRMWARE_REBOOT); DEFINE_MALI_ADD_EVENT(SCHEDULER_TOCK); +DEFINE_MALI_ADD_EVENT(SCHEDULER_TOCK_END); DEFINE_MALI_ADD_EVENT(SCHEDULER_TICK); +DEFINE_MALI_ADD_EVENT(SCHEDULER_TICK_END); DEFINE_MALI_ADD_EVENT(SCHEDULER_RESET); -DEFINE_MALI_ADD_EVENT(SCHEDULER_EXIT_PROTM); +DEFINE_MALI_ADD_EVENT(SCHEDULER_WAIT_PROTM_QUIT); +DEFINE_MALI_ADD_EVENT(SCHEDULER_WAIT_PROTM_QUIT_DONE); DEFINE_MALI_ADD_EVENT(SYNC_UPDATE_EVENT); +DEFINE_MALI_ADD_EVENT(SYNC_UPDATE_EVENT_NOTIFY_GPU); +DEFINE_MALI_ADD_EVENT(CSF_INTERRUPT); +DEFINE_MALI_ADD_EVENT(CSF_INTERRUPT_END); +DEFINE_MALI_ADD_EVENT(CSG_INTERRUPT_PROCESS); +DEFINE_MALI_ADD_EVENT(GLB_REQ_ACQ); +DEFINE_MALI_ADD_EVENT(SCHEDULER_CAN_IDLE); +DEFINE_MALI_ADD_EVENT(SCHEDULER_ADVANCE_TICK); +DEFINE_MALI_ADD_EVENT(SCHEDULER_NOADVANCE_TICK); +DEFINE_MALI_ADD_EVENT(SCHEDULER_INSERT_RUNNABLE); +DEFINE_MALI_ADD_EVENT(SCHEDULER_REMOVE_RUNNABLE); +DEFINE_MALI_ADD_EVENT(SCHEDULER_ROTATE_RUNNABLE); +DEFINE_MALI_ADD_EVENT(SCHEDULER_HEAD_RUNNABLE); +DEFINE_MALI_ADD_EVENT(IDLE_WORKER_BEGIN); +DEFINE_MALI_ADD_EVENT(IDLE_WORKER_END); +DEFINE_MALI_ADD_EVENT(GROUP_SYNC_UPDATE_WORKER_BEGIN); +DEFINE_MALI_ADD_EVENT(GROUP_SYNC_UPDATE_WORKER_END); +DEFINE_MALI_ADD_EVENT(SLOTS_STATUS_UPDATE_ACK); DECLARE_EVENT_CLASS(mali_csf_grp_q_template, TP_PROTO(struct kbase_device *kbdev, struct kbase_queue_group *group, @@ -112,15 +132,33 @@ DEFINE_MALI_CSF_GRP_EVENT(CSG_SLOT_STOP); DEFINE_MALI_CSF_GRP_EVENT(CSG_SLOT_STARTED); DEFINE_MALI_CSF_GRP_EVENT(CSG_SLOT_STOPPED); DEFINE_MALI_CSF_GRP_EVENT(CSG_SLOT_CLEANED); +DEFINE_MALI_CSF_GRP_EVENT(CSG_SLOT_STATUS_UPDATE); +DEFINE_MALI_CSF_GRP_EVENT(CSG_SLOT_IDLE_SET); +DEFINE_MALI_CSF_GRP_EVENT(CSG_SLOT_IDLE_CLEAR); DEFINE_MALI_CSF_GRP_EVENT(CSG_PRIO_UPDATE); DEFINE_MALI_CSF_GRP_EVENT(CSG_SYNC_UPDATE_INTERRUPT); DEFINE_MALI_CSF_GRP_EVENT(CSG_IDLE_INTERRUPT); +DEFINE_MALI_CSF_GRP_EVENT(CSG_PROGRESS_TIMER_INTERRUPT); +DEFINE_MALI_CSF_GRP_EVENT(CSG_INTERRUPT_PROCESS_END); DEFINE_MALI_CSF_GRP_EVENT(GROUP_SYNC_UPDATE_DONE); DEFINE_MALI_CSF_GRP_EVENT(GROUP_DESCHEDULE); DEFINE_MALI_CSF_GRP_EVENT(GROUP_SCHEDULE); DEFINE_MALI_CSF_GRP_EVENT(GROUP_EVICT_SCHED); +DEFINE_MALI_CSF_GRP_EVENT(GROUP_INSERT_RUNNABLE); +DEFINE_MALI_CSF_GRP_EVENT(GROUP_REMOVE_RUNNABLE); +DEFINE_MALI_CSF_GRP_EVENT(GROUP_ROTATE_RUNNABLE); +DEFINE_MALI_CSF_GRP_EVENT(GROUP_HEAD_RUNNABLE); +DEFINE_MALI_CSF_GRP_EVENT(GROUP_INSERT_IDLE_WAIT); +DEFINE_MALI_CSF_GRP_EVENT(GROUP_REMOVE_IDLE_WAIT); +DEFINE_MALI_CSF_GRP_EVENT(GROUP_HEAD_IDLE_WAIT); +DEFINE_MALI_CSF_GRP_EVENT(SCHEDULER_CHECK_PROTM_ENTER); DEFINE_MALI_CSF_GRP_EVENT(SCHEDULER_ENTER_PROTM); +DEFINE_MALI_CSF_GRP_EVENT(SCHEDULER_EXIT_PROTM); DEFINE_MALI_CSF_GRP_EVENT(SCHEDULER_TOP_GRP); +DEFINE_MALI_CSF_GRP_EVENT(SCHEDULER_NONIDLE_OFFSLOT_INC); +DEFINE_MALI_CSF_GRP_EVENT(SCHEDULER_NONIDLE_OFFSLOT_DEC); +DEFINE_MALI_CSF_GRP_EVENT(PROTM_EVENT_WORKER_BEGIN); +DEFINE_MALI_CSF_GRP_EVENT(PROTM_EVENT_WORKER_END); #undef DEFINE_MALI_CSF_GRP_EVENT @@ -136,10 +174,21 @@ DEFINE_MALI_CSF_GRP_EVENT(SCHEDULER_TOP_GRP); DEFINE_MALI_CSF_GRP_Q_EVENT(CSI_START); DEFINE_MALI_CSF_GRP_Q_EVENT(CSI_STOP); DEFINE_MALI_CSF_GRP_Q_EVENT(CSI_STOP_REQUESTED); +DEFINE_MALI_CSF_GRP_Q_EVENT(CSI_IGNORED_INTERRUPTS_GROUP_SUSPEND); DEFINE_MALI_CSF_GRP_Q_EVENT(CSI_FAULT_INTERRUPT); DEFINE_MALI_CSF_GRP_Q_EVENT(CSI_TILER_OOM_INTERRUPT); +DEFINE_MALI_CSF_GRP_Q_EVENT(CSI_PROTM_PEND_INTERRUPT); +DEFINE_MALI_CSF_GRP_Q_EVENT(CSI_PROTM_ACK); DEFINE_MALI_CSF_GRP_Q_EVENT(QUEUE_START); DEFINE_MALI_CSF_GRP_Q_EVENT(QUEUE_STOP); +DEFINE_MALI_CSF_GRP_Q_EVENT(QUEUE_SYNC_UPDATE); +DEFINE_MALI_CSF_GRP_Q_EVENT(QUEUE_SYNC_UPDATE_EVALUATED); +DEFINE_MALI_CSF_GRP_Q_EVENT(QUEUE_SYNC_STATUS_WAIT); +DEFINE_MALI_CSF_GRP_Q_EVENT(QUEUE_SYNC_CURRENT_VAL); +DEFINE_MALI_CSF_GRP_Q_EVENT(QUEUE_SYNC_TEST_VAL); +DEFINE_MALI_CSF_GRP_Q_EVENT(QUEUE_SYNC_BLOCKED_REASON); +DEFINE_MALI_CSF_GRP_Q_EVENT(PROTM_PENDING_SET); +DEFINE_MALI_CSF_GRP_Q_EVENT(PROTM_PENDING_CLEAR); #undef DEFINE_MALI_CSF_GRP_Q_EVENT diff --git a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_linux_ktrace_jm.h b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_linux_ktrace_jm.h index b368a8510ad1..2e88e696a1f5 100644 --- a/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_linux_ktrace_jm.h +++ b/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_linux_ktrace_jm.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014, 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014, 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace.c b/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace.c index 443b048d6d16..9bf86108338f 100644 --- a/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace.c +++ b/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -240,7 +240,7 @@ void kbasep_ktrace_dump(struct kbase_device *kbdev) spin_unlock_irqrestore(&kbdev->ktrace.lock, flags); } -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) struct trace_seq_state { struct kbase_ktrace_msg trace_buf[KBASE_KTRACE_SIZE]; u32 start; @@ -348,7 +348,7 @@ void kbase_ktrace_debugfs_init(struct kbase_device *kbdev) #else /* KBASE_KTRACE_TARGET_RBUF */ -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) void kbase_ktrace_debugfs_init(struct kbase_device *kbdev) { CSTD_UNUSED(kbdev); diff --git a/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace.h b/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace.h index b7545e08ab28..6cb1ea34b77f 100644 --- a/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace.h +++ b/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -65,7 +65,7 @@ void kbase_ktrace_term(struct kbase_device *kbdev); */ void kbase_ktrace_hook_wrapper(void *param); -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) /** * kbase_ktrace_debugfs_init - initialize kbase ktrace for debugfs usage, if * the selected targets support it. diff --git a/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace_codes.h b/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace_codes.h index c5ca08e0a18b..33098346ebcb 100644 --- a/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace_codes.h +++ b/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace_codes.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2011-2015, 2018-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2011-2015, 2018-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace_defs.h b/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace_defs.h index accf3cf17236..d8242ad18918 100644 --- a/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace_defs.h +++ b/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace_defs.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -114,7 +114,7 @@ union kbase_ktrace_backend; #define KBASE_KTRACE_FLAG_ALL \ (KBASE_KTRACE_FLAG_COMMON_ALL | KBASE_KTRACE_FLAG_BACKEND_ALL) -#define KBASE_KTRACE_SHIFT 8 /* 256 entries */ +#define KBASE_KTRACE_SHIFT (9) /* 512 entries */ #define KBASE_KTRACE_SIZE (1 << KBASE_KTRACE_SHIFT) #define KBASE_KTRACE_MASK ((1 << KBASE_KTRACE_SHIFT)-1) diff --git a/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace_internal.h b/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace_internal.h index 1f0fa5ecf9ea..d9bd351dcadc 100644 --- a/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace_internal.h +++ b/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_ktrace_internal.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_linux_ktrace.h b/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_linux_ktrace.h index 4a73da50029b..b56dec4b0619 100644 --- a/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_linux_ktrace.h +++ b/drivers/gpu/arm/bifrost/debug/mali_kbase_debug_linux_ktrace.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2014, 2018, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/tests/kutf/Makefile b/drivers/gpu/arm/bifrost/device/Kbuild similarity index 58% rename from drivers/gpu/arm/bifrost/tests/kutf/Makefile rename to drivers/gpu/arm/bifrost/device/Kbuild index 041f5394bf32..723ffd215696 100644 --- a/drivers/gpu/arm/bifrost/tests/kutf/Makefile +++ b/drivers/gpu/arm/bifrost/device/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2014-2017, 2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -18,17 +18,16 @@ # # -# linux build system bootstrap for out-of-tree module +bifrost_kbase-y += \ + device/mali_kbase_device.o \ + device/mali_kbase_device_hw.o -# default to building for the host -ARCH ?= $(shell uname -m) - -ifeq ($(KDIR),) -$(error Must specify KDIR to point to the kernel to target)) +ifeq ($(CONFIG_MALI_CSF_SUPPORT),y) + bifrost_kbase-y += \ + device/backend/mali_kbase_device_csf.o \ + device/backend/mali_kbase_device_hw_csf.o +else + bifrost_kbase-y += \ + device/backend/mali_kbase_device_jm.o \ + device/backend/mali_kbase_device_hw_jm.o endif - -all: - $(MAKE) ARCH=$(ARCH) -C $(KDIR) M=$(CURDIR) $(SCONS_CONFIGS) EXTRA_CFLAGS=-I$(CURDIR)/../include modules - -clean: - $(MAKE) ARCH=$(ARCH) -C $(KDIR) M=$(CURDIR) clean diff --git a/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_csf.c b/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_csf.c index 39a46276cf22..f97ee356d68e 100644 --- a/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_csf.c +++ b/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_csf.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -19,8 +19,8 @@ * */ -#include "../mali_kbase_device_internal.h" -#include "../mali_kbase_device.h" +#include +#include #include #include @@ -29,40 +29,33 @@ #include #include -#ifdef CONFIG_MALI_BIFROST_NO_MALI -#include -#endif #include #include #include #include #include +#include +#include +#include -static void kbase_device_csf_firmware_term(struct kbase_device *kbdev) +/** + * kbase_device_firmware_hwcnt_term - Terminate CSF firmware and HWC + * + * @kbdev: An instance of the GPU platform device, allocated from the probe + * method of the driver. + * + * When a kbase driver is removed, terminate CSF firmware and hardware counter + * components. + */ +static void kbase_device_firmware_hwcnt_term(struct kbase_device *kbdev) { - kbase_csf_firmware_term(kbdev); -} - -static int kbase_device_csf_firmware_init(struct kbase_device *kbdev) -{ - int err = kbase_csf_firmware_init(kbdev); - - if (!err) { - unsigned long flags; - - spin_lock_irqsave(&kbdev->hwaccess_lock, flags); - kbdev->pm.backend.mcu_state = KBASE_MCU_ON; - kbdev->csf.firmware_inited = true; - spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags); + if (kbdev->csf.firmware_inited) { + kbase_vinstr_term(kbdev->vinstr_ctx); + kbase_hwcnt_virtualizer_term(kbdev->hwcnt_gpu_virt); + kbase_hwcnt_backend_csf_metadata_term(&kbdev->hwcnt_gpu_iface); + kbase_csf_firmware_term(kbdev); } - - /* Post firmware init, idle condition is restored. Note this is - * a deferral action step from the late init stage for CSF. - */ - kbase_pm_context_idle(kbdev); - - return err; } /** @@ -128,7 +121,9 @@ static int kbase_backend_late_init(struct kbase_device *kbdev) init_waitqueue_head(&kbdev->hwaccess.backend.reset_wait); - /* kbase_pm_context_idle is called after the boot of firmware */ + kbase_pm_context_idle(kbdev); + + mutex_init(&kbdev->fw_load_lock); return 0; @@ -171,6 +166,33 @@ static void kbase_backend_late_term(struct kbase_device *kbdev) kbase_hwaccess_pm_term(kbdev); } +/** + * kbase_csf_early_init - Early initialization for firmware & scheduler. + * @kbdev: Device pointer + * + * Return: 0 on success, error code otherwise. + */ +static int kbase_csf_early_init(struct kbase_device *kbdev) +{ + int err = kbase_csf_firmware_early_init(kbdev); + + if (err) + return err; + + err = kbase_csf_scheduler_early_init(kbdev); + + return err; +} + +/** + * kbase_csf_early_init - Early termination for firmware & scheduler. + * @kbdev: Device pointer + */ +static void kbase_csf_early_term(struct kbase_device *kbdev) +{ + kbase_csf_scheduler_early_term(kbdev); +} + /** * kbase_device_hwcnt_backend_csf_if_init - Create hardware counter backend * firmware interface. @@ -214,96 +236,52 @@ static void kbase_device_hwcnt_backend_csf_term(struct kbase_device *kbdev) kbase_hwcnt_backend_csf_destroy(&kbdev->hwcnt_gpu_iface); } -/** - * kbase_device_hwcnt_backend_csf_metadata_init - Initialize hardware counter - * metadata. - * @kbdev: Device pointer - */ -static int -kbase_device_hwcnt_backend_csf_metadata_init(struct kbase_device *kbdev) -{ - /* For CSF GPUs, HWC metadata needs to query information from CSF - * firmware, so the initialization of HWC metadata only can be called - * after firmware initialized, but firmware initialization depends on - * HWC backend initialization, so we need to separate HWC backend - * metadata initialization from HWC backend initialization. - */ - return kbase_hwcnt_backend_csf_metadata_init(&kbdev->hwcnt_gpu_iface); -} - -/** - * kbase_device_hwcnt_backend_csf_metadata_term - Terminate hardware counter - * metadata. - * @kbdev: Device pointer - */ -static void -kbase_device_hwcnt_backend_csf_metadata_term(struct kbase_device *kbdev) -{ - kbase_hwcnt_backend_csf_metadata_term(&kbdev->hwcnt_gpu_iface); -} - static const struct kbase_device_init dev_init[] = { -#ifdef CONFIG_MALI_BIFROST_NO_MALI - {kbase_gpu_device_create, kbase_gpu_device_destroy, - "Dummy model initialization failed"}, -#else - {assign_irqs, NULL, - "IRQ search failed"}, - {registers_map, registers_unmap, - "Register map failed"}, -#endif - {power_control_init, power_control_term, - "Power control initialization failed"}, - {kbase_device_io_history_init, kbase_device_io_history_term, - "Register access history initialization failed"}, - {kbase_device_early_init, kbase_device_early_term, - "Early device initialization failed"}, - {kbase_device_populate_max_freq, NULL, - "Populating max frequency failed"}, - {kbase_device_misc_init, kbase_device_misc_term, - "Miscellaneous device initialization failed"}, - {kbase_device_pcm_dev_init, kbase_device_pcm_dev_term, - "Priority control manager initialization failed"}, - {kbase_ctx_sched_init, kbase_ctx_sched_term, - "Context scheduler initialization failed"}, - {kbase_mem_init, kbase_mem_term, - "Memory subsystem initialization failed"}, - {kbase_csf_protected_memory_init, kbase_csf_protected_memory_term, - "Protected memory allocator initialization failed"}, - {kbase_device_coherency_init, NULL, - "Device coherency init failed"}, - {kbase_protected_mode_init, kbase_protected_mode_term, - "Protected mode subsystem initialization failed"}, - {kbase_device_list_init, kbase_device_list_term, - "Device list setup failed"}, - {kbase_device_timeline_init, kbase_device_timeline_term, - "Timeline stream initialization failed"}, - {kbase_clk_rate_trace_manager_init, - kbase_clk_rate_trace_manager_term, - "Clock rate trace manager initialization failed"}, - {kbase_device_hwcnt_backend_csf_if_init, - kbase_device_hwcnt_backend_csf_if_term, - "GPU hwcnt backend CSF interface creation failed"}, - {kbase_device_hwcnt_backend_csf_init, - kbase_device_hwcnt_backend_csf_term, - "GPU hwcnt backend creation failed"}, - {kbase_device_hwcnt_context_init, kbase_device_hwcnt_context_term, - "GPU hwcnt context initialization failed"}, - {kbase_backend_late_init, kbase_backend_late_term, - "Late backend initialization failed"}, - {kbase_device_csf_firmware_init, kbase_device_csf_firmware_term, - "Firmware initialization failed"}, - {kbase_device_hwcnt_backend_csf_metadata_init, - kbase_device_hwcnt_backend_csf_metadata_term, - "GPU hwcnt backend metadata creation failed"}, - {kbase_device_hwcnt_virtualizer_init, - kbase_device_hwcnt_virtualizer_term, - "GPU hwcnt virtualizer initialization failed"}, - {kbase_device_vinstr_init, kbase_device_vinstr_term, - "Virtual instrumentation initialization failed"}, + { assign_irqs, NULL, "IRQ search failed" }, + { registers_map, registers_unmap, "Register map failed" }, + { power_control_init, power_control_term, + "Power control initialization failed" }, + { kbase_device_io_history_init, kbase_device_io_history_term, + "Register access history initialization failed" }, + { kbase_device_early_init, kbase_device_early_term, + "Early device initialization failed" }, + { kbase_device_populate_max_freq, NULL, + "Populating max frequency failed" }, + { kbase_device_misc_init, kbase_device_misc_term, + "Miscellaneous device initialization failed" }, + { kbase_device_pcm_dev_init, kbase_device_pcm_dev_term, + "Priority control manager initialization failed" }, + { kbase_ctx_sched_init, kbase_ctx_sched_term, + "Context scheduler initialization failed" }, + { kbase_mem_init, kbase_mem_term, + "Memory subsystem initialization failed" }, + { kbase_csf_protected_memory_init, kbase_csf_protected_memory_term, + "Protected memory allocator initialization failed" }, + { kbase_device_coherency_init, NULL, "Device coherency init failed" }, + { kbase_protected_mode_init, kbase_protected_mode_term, + "Protected mode subsystem initialization failed" }, + { kbase_device_list_init, kbase_device_list_term, + "Device list setup failed" }, + { kbase_device_timeline_init, kbase_device_timeline_term, + "Timeline stream initialization failed" }, + { kbase_clk_rate_trace_manager_init, kbase_clk_rate_trace_manager_term, + "Clock rate trace manager initialization failed" }, + { kbase_device_hwcnt_backend_csf_if_init, + kbase_device_hwcnt_backend_csf_if_term, + "GPU hwcnt backend CSF interface creation failed" }, + { kbase_device_hwcnt_backend_csf_init, + kbase_device_hwcnt_backend_csf_term, + "GPU hwcnt backend creation failed" }, + { kbase_device_hwcnt_context_init, kbase_device_hwcnt_context_term, + "GPU hwcnt context initialization failed" }, + { kbase_backend_late_init, kbase_backend_late_term, + "Late backend initialization failed" }, + { kbase_csf_early_init, kbase_csf_early_term, + "Early CSF initialization failed" }, + { NULL, kbase_device_firmware_hwcnt_term, NULL }, #ifdef MALI_KBASE_BUILD - {kbase_device_debugfs_init, kbase_device_debugfs_term, - "DebugFS initialization failed"}, + { kbase_device_debugfs_init, kbase_device_debugfs_term, + "DebugFS initialization failed" }, /* Sysfs init needs to happen before registering the device with * misc_register(), otherwise it causes a race condition between * registering the device and a uevent event being generated for @@ -316,12 +294,13 @@ static const struct kbase_device_init dev_init[] = { * paragraph that starts with "Word of warning", currently the * second-last paragraph. */ - {kbase_sysfs_init, kbase_sysfs_term, - "SysFS group creation failed"}, - {kbase_device_misc_register, kbase_device_misc_deregister, - "Misc device registration failed"}, - {kbase_gpuprops_populate_user_buffer, kbase_gpuprops_free_user_buffer, - "GPU property population failed"}, + { kbase_sysfs_init, kbase_sysfs_term, "SysFS group creation failed" }, + { kbase_device_misc_register, kbase_device_misc_deregister, + "Misc device registration failed" }, + { kbase_gpuprops_populate_user_buffer, kbase_gpuprops_free_user_buffer, + "GPU property population failed" }, + { kbase_device_late_init, kbase_device_late_term, + "Late device initialization failed" }, #endif }; @@ -352,14 +331,134 @@ int kbase_device_init(struct kbase_device *kbdev) kbase_disjoint_init(kbdev); for (i = 0; i < ARRAY_SIZE(dev_init); i++) { - err = dev_init[i].init(kbdev); - if (err) { - dev_err(kbdev->dev, "%s error = %d\n", - dev_init[i].err_mes, err); - kbase_device_term_partial(kbdev, i); - break; + if (dev_init[i].init) { + err = dev_init[i].init(kbdev); + if (err) { + dev_err(kbdev->dev, "%s error = %d\n", + dev_init[i].err_mes, err); + kbase_device_term_partial(kbdev, i); + break; + } } } return err; } + +/** + * kbase_device_hwcnt_csf_deferred_init - Initialize CSF deferred HWC components + * + * @kbdev: An instance of the GPU platform device, allocated from the probe + * method of the driver. + * + * Hardware counter components depending on firmware are initialized after CSF + * firmware is loaded. + * + * @return 0 on success. An error code on failure. + */ +static int kbase_device_hwcnt_csf_deferred_init(struct kbase_device *kbdev) +{ + int ret = 0; + + /* For CSF GPUs, HWC metadata needs to query information from CSF + * firmware, so the initialization of HWC metadata only can be called + * after firmware initialized, but firmware initialization depends on + * HWC backend initialization, so we need to separate HWC backend + * metadata initialization from HWC backend initialization. + */ + ret = kbase_hwcnt_backend_csf_metadata_init(&kbdev->hwcnt_gpu_iface); + if (ret) { + dev_err(kbdev->dev, + "GPU hwcnt backend metadata creation failed"); + return ret; + } + + ret = kbase_hwcnt_virtualizer_init( + kbdev->hwcnt_gpu_ctx, + KBASE_HWCNT_GPU_VIRTUALIZER_DUMP_THRESHOLD_NS, + &kbdev->hwcnt_gpu_virt); + if (ret) { + dev_err(kbdev->dev, + "GPU hwcnt virtualizer initialization failed"); + goto virt_fail; + } + + ret = kbase_vinstr_init(kbdev->hwcnt_gpu_virt, &kbdev->vinstr_ctx); + if (ret) { + dev_err(kbdev->dev, + "Virtual instrumentation initialization failed"); + goto vinstr_fail; + } + + return ret; + +vinstr_fail: + kbase_hwcnt_virtualizer_term(kbdev->hwcnt_gpu_virt); + +virt_fail: + kbase_hwcnt_backend_csf_metadata_term(&kbdev->hwcnt_gpu_iface); + return ret; +} + +/** + * kbase_csf_firmware_deferred_init - Load and initialize CSF firmware + * + * @kbdev: An instance of the GPU platform device, allocated from the probe + * method of the driver. + * + * Called when a device file is opened for the first time. + * To meet Android GKI vendor guideline, firmware load is deferred at + * the time when @ref kbase_open is called for the first time. + * + * @return 0 on success. An error code on failure. + */ +static int kbase_csf_firmware_deferred_init(struct kbase_device *kbdev) +{ + int err = 0; + + lockdep_assert_held(&kbdev->fw_load_lock); + + kbase_pm_context_active(kbdev); + + err = kbase_csf_firmware_init(kbdev); + if (!err) { + unsigned long flags; + + spin_lock_irqsave(&kbdev->hwaccess_lock, flags); + kbdev->pm.backend.mcu_state = KBASE_MCU_ON; + kbdev->csf.firmware_inited = true; + spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags); + } else { + dev_err(kbdev->dev, "Firmware initialization failed"); + } + + kbase_pm_context_idle(kbdev); + + return err; +} + +int kbase_device_firmware_init_once(struct kbase_device *kbdev) +{ + int ret = 0; + + mutex_lock(&kbdev->fw_load_lock); + + if (!kbdev->csf.firmware_inited) { + ret = kbase_csf_firmware_deferred_init(kbdev); + if (ret) + goto out; + + ret = kbase_device_hwcnt_csf_deferred_init(kbdev); + if (ret) { + kbase_csf_firmware_term(kbdev); + goto out; + } + + kbase_csf_debugfs_init(kbdev); + } + +out: + mutex_unlock(&kbdev->fw_load_lock); + + return ret; +} diff --git a/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_hw_csf.c b/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_hw_csf.c index 259e42a6d3ea..8427edb0dbb1 100644 --- a/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_hw_csf.c +++ b/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_hw_csf.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. @@ -53,7 +53,7 @@ static void kbase_report_gpu_fault(struct kbase_device *kbdev, u32 status, kbase_mmu_gpu_fault_interrupt(kbdev, status, as_nr, address, as_valid); } -static bool kbase_gpu_fault_interrupt(struct kbase_device *kbdev) +static void kbase_gpu_fault_interrupt(struct kbase_device *kbdev) { const u32 status = kbase_reg_read(kbdev, GPU_CONTROL_REG(GPU_FAULTSTATUS)); @@ -62,7 +62,6 @@ static bool kbase_gpu_fault_interrupt(struct kbase_device *kbdev) GPU_FAULTSTATUS_JASID_SHIFT; bool bus_fault = (status & GPU_FAULTSTATUS_EXCEPTION_TYPE_MASK) == GPU_FAULTSTATUS_EXCEPTION_TYPE_GPU_BUS_FAULT; - bool clear_gpu_fault = true; if (bus_fault) { /* If as_valid, reset gpu when ASID is for MCU. */ @@ -76,21 +75,18 @@ static bool kbase_gpu_fault_interrupt(struct kbase_device *kbdev) } else { /* Handle Bus fault */ if (kbase_mmu_bus_fault_interrupt(kbdev, status, as_nr)) - clear_gpu_fault = false; + dev_warn(kbdev->dev, + "fail to handle GPU bus fault ...\n"); } } else kbase_report_gpu_fault(kbdev, status, as_nr, as_valid); - - return clear_gpu_fault; } void kbase_gpu_interrupt(struct kbase_device *kbdev, u32 val) { - bool clear_gpu_fault = false; - KBASE_KTRACE_ADD(kbdev, CORE_GPU_IRQ, NULL, val); if (val & GPU_FAULT) - clear_gpu_fault = kbase_gpu_fault_interrupt(kbdev); + kbase_gpu_fault_interrupt(kbdev); if (val & GPU_PROTECTED_FAULT) { struct kbase_csf_scheduler *scheduler = &kbdev->csf.scheduler; @@ -162,14 +158,5 @@ void kbase_gpu_interrupt(struct kbase_device *kbdev, u32 val) kbase_pm_power_changed(kbdev); } - if (clear_gpu_fault) { - unsigned long flags; - - spin_lock_irqsave(&kbdev->hwaccess_lock, flags); - kbase_reg_write(kbdev, GPU_CONTROL_REG(GPU_COMMAND), - GPU_COMMAND_CLEAR_FAULT); - spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags); - } - KBASE_KTRACE_ADD(kbdev, CORE_GPU_IRQ_DONE, NULL, val); } diff --git a/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_hw_jm.c b/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_hw_jm.c index 33ebe0901fe2..c4e6eb8a680c 100644 --- a/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_hw_jm.c +++ b/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_hw_jm.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_jm.c b/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_jm.c index 4f5de18d3571..aae11a5ec659 100644 --- a/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_jm.c +++ b/drivers/gpu/arm/bifrost/device/backend/mali_kbase_device_jm.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -19,18 +19,15 @@ * */ -#include "../mali_kbase_device_internal.h" -#include "../mali_kbase_device.h" -#include "../mali_kbase_hwaccess_instr.h" +#include +#include +#include #include #include #include #include -#ifdef CONFIG_MALI_BIFROST_NO_MALI -#include -#endif #ifdef CONFIG_MALI_ARBITER_SUPPORT #include @@ -105,6 +102,8 @@ static int kbase_backend_late_init(struct kbase_device *kbdev) /* Idle the GPU and/or cores, if the policy wants it to */ kbase_pm_context_idle(kbdev); + mutex_init(&kbdev->fw_load_lock); + return 0; fail_update_l2_features: @@ -157,63 +156,54 @@ static void kbase_device_hwcnt_backend_jm_term(struct kbase_device *kbdev) } static const struct kbase_device_init dev_init[] = { -#ifdef CONFIG_MALI_BIFROST_NO_MALI - {kbase_gpu_device_create, kbase_gpu_device_destroy, - "Dummy model initialization failed"}, -#else - {assign_irqs, NULL, - "IRQ search failed"}, - {registers_map, registers_unmap, - "Register map failed"}, -#endif - {kbase_device_io_history_init, kbase_device_io_history_term, - "Register access history initialization failed"}, - {kbase_device_pm_init, kbase_device_pm_term, - "Power management initialization failed"}, - {kbase_device_early_init, kbase_device_early_term, - "Early device initialization failed"}, - {kbase_device_populate_max_freq, NULL, - "Populating max frequency failed"}, - {kbase_device_misc_init, kbase_device_misc_term, - "Miscellaneous device initialization failed"}, - {kbase_device_pcm_dev_init, kbase_device_pcm_dev_term, - "Priority control manager initialization failed"}, - {kbase_ctx_sched_init, kbase_ctx_sched_term, - "Context scheduler initialization failed"}, - {kbase_mem_init, kbase_mem_term, - "Memory subsystem initialization failed"}, - {kbase_device_coherency_init, NULL, - "Device coherency init failed"}, - {kbase_protected_mode_init, kbase_protected_mode_term, - "Protected mode subsystem initialization failed"}, - {kbase_device_list_init, kbase_device_list_term, - "Device list setup failed"}, - {kbasep_js_devdata_init, kbasep_js_devdata_term, - "Job JS devdata initialization failed"}, - {kbase_device_timeline_init, kbase_device_timeline_term, - "Timeline stream initialization failed"}, - {kbase_clk_rate_trace_manager_init, - kbase_clk_rate_trace_manager_term, - "Clock rate trace manager initialization failed"}, - {kbase_instr_backend_init, kbase_instr_backend_term, - "Instrumentation backend initialization failed"}, - {kbase_device_hwcnt_backend_jm_init, - kbase_device_hwcnt_backend_jm_term, - "GPU hwcnt backend creation failed"}, - {kbase_device_hwcnt_context_init, kbase_device_hwcnt_context_term, - "GPU hwcnt context initialization failed"}, - {kbase_device_hwcnt_virtualizer_init, - kbase_device_hwcnt_virtualizer_term, - "GPU hwcnt virtualizer initialization failed"}, - {kbase_device_vinstr_init, kbase_device_vinstr_term, - "Virtual instrumentation initialization failed"}, - {kbase_backend_late_init, kbase_backend_late_term, - "Late backend initialization failed"}, + { assign_irqs, NULL, "IRQ search failed" }, + { registers_map, registers_unmap, "Register map failed" }, + { kbase_device_io_history_init, kbase_device_io_history_term, + "Register access history initialization failed" }, + { kbase_device_pm_init, kbase_device_pm_term, + "Power management initialization failed" }, + { kbase_device_early_init, kbase_device_early_term, + "Early device initialization failed" }, + { kbase_device_populate_max_freq, NULL, + "Populating max frequency failed" }, + { kbase_device_misc_init, kbase_device_misc_term, + "Miscellaneous device initialization failed" }, + { kbase_device_pcm_dev_init, kbase_device_pcm_dev_term, + "Priority control manager initialization failed" }, + { kbase_ctx_sched_init, kbase_ctx_sched_term, + "Context scheduler initialization failed" }, + { kbase_mem_init, kbase_mem_term, + "Memory subsystem initialization failed" }, + { kbase_device_coherency_init, NULL, "Device coherency init failed" }, + { kbase_protected_mode_init, kbase_protected_mode_term, + "Protected mode subsystem initialization failed" }, + { kbase_device_list_init, kbase_device_list_term, + "Device list setup failed" }, + { kbasep_js_devdata_init, kbasep_js_devdata_term, + "Job JS devdata initialization failed" }, + { kbase_device_timeline_init, kbase_device_timeline_term, + "Timeline stream initialization failed" }, + { kbase_clk_rate_trace_manager_init, kbase_clk_rate_trace_manager_term, + "Clock rate trace manager initialization failed" }, + { kbase_instr_backend_init, kbase_instr_backend_term, + "Instrumentation backend initialization failed" }, + { kbase_device_hwcnt_backend_jm_init, + kbase_device_hwcnt_backend_jm_term, + "GPU hwcnt backend creation failed" }, + { kbase_device_hwcnt_context_init, kbase_device_hwcnt_context_term, + "GPU hwcnt context initialization failed" }, + { kbase_device_hwcnt_virtualizer_init, + kbase_device_hwcnt_virtualizer_term, + "GPU hwcnt virtualizer initialization failed" }, + { kbase_device_vinstr_init, kbase_device_vinstr_term, + "Virtual instrumentation initialization failed" }, + { kbase_backend_late_init, kbase_backend_late_term, + "Late backend initialization failed" }, #ifdef MALI_KBASE_BUILD - {kbase_debug_job_fault_dev_init, kbase_debug_job_fault_dev_term, - "Job fault debug initialization failed"}, - {kbase_device_debugfs_init, kbase_device_debugfs_term, - "DebugFS initialization failed"}, + { kbase_debug_job_fault_dev_init, kbase_debug_job_fault_dev_term, + "Job fault debug initialization failed" }, + { kbase_device_debugfs_init, kbase_device_debugfs_term, + "DebugFS initialization failed" }, /* Sysfs init needs to happen before registering the device with * misc_register(), otherwise it causes a race condition between * registering the device and a uevent event being generated for @@ -226,14 +216,15 @@ static const struct kbase_device_init dev_init[] = { * paragraph that starts with "Word of warning", currently the * second-last paragraph. */ - {kbase_sysfs_init, kbase_sysfs_term, "SysFS group creation failed"}, - {kbase_device_misc_register, kbase_device_misc_deregister, - "Misc device registration failed"}, - {kbase_gpuprops_populate_user_buffer, kbase_gpuprops_free_user_buffer, - "GPU property population failed"}, + { kbase_sysfs_init, kbase_sysfs_term, "SysFS group creation failed" }, + { kbase_device_misc_register, kbase_device_misc_deregister, + "Misc device registration failed" }, + { kbase_gpuprops_populate_user_buffer, kbase_gpuprops_free_user_buffer, + "GPU property population failed" }, #endif - {kbase_dummy_job_wa_load, kbase_dummy_job_wa_cleanup, - "Dummy job workaround load failed"}, + { NULL, kbase_dummy_job_wa_cleanup, NULL }, + { kbase_device_late_init, kbase_device_late_term, + "Late device initialization failed" }, }; static void kbase_device_term_partial(struct kbase_device *kbdev, @@ -263,15 +254,34 @@ int kbase_device_init(struct kbase_device *kbdev) kbase_disjoint_init(kbdev); for (i = 0; i < ARRAY_SIZE(dev_init); i++) { - err = dev_init[i].init(kbdev); - if (err) { - if (err != -EPROBE_DEFER) - dev_err(kbdev->dev, "%s error = %d\n", + if (dev_init[i].init) { + err = dev_init[i].init(kbdev); + if (err) { + if (err != -EPROBE_DEFER) + dev_err(kbdev->dev, "%s error = %d\n", dev_init[i].err_mes, err); - kbase_device_term_partial(kbdev, i); - break; + kbase_device_term_partial(kbdev, i); + break; + } } } return err; } + +int kbase_device_firmware_init_once(struct kbase_device *kbdev) +{ + int ret = 0; + + mutex_lock(&kbdev->fw_load_lock); + + if (!kbdev->dummy_job_wa_loaded) { + ret = kbase_dummy_job_wa_load(kbdev); + if (!ret) + kbdev->dummy_job_wa_loaded = true; + } + + mutex_unlock(&kbdev->fw_load_lock); + + return ret; +} diff --git a/drivers/gpu/arm/bifrost/device/mali_kbase_device.c b/drivers/gpu/arm/bifrost/device/mali_kbase_device.c index 5e900d0fd0d4..08961d583034 100644 --- a/drivers/gpu/arm/bifrost/device/mali_kbase_device.c +++ b/drivers/gpu/arm/bifrost/device/mali_kbase_device.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -110,7 +111,7 @@ int kbase_device_pcm_dev_init(struct kbase_device *const kbdev) { int err = 0; -#ifdef CONFIG_OF +#if IS_ENABLED(CONFIG_OF) struct device_node *prio_ctrl_node; /* Check to see whether or not a platform specific priority control manager @@ -155,16 +156,70 @@ void kbase_device_pcm_dev_term(struct kbase_device *const kbdev) module_put(kbdev->pcm_dev->owner); } +#define KBASE_PAGES_TO_KIB(pages) (((unsigned int)pages) << (PAGE_SHIFT - 10)) + +/** + * mali_oom_notifier_handler - Mali driver out-of-memory handler + * + * @nb - notifier block - used to retrieve kbdev pointer + * @action - action (unused) + * @data - data pointer (unused) + * This function simply lists memory usage by the Mali driver, per GPU device, + * for diagnostic purposes. + */ +static int mali_oom_notifier_handler(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct kbase_device *kbdev; + struct kbase_context *kctx = NULL; + unsigned long kbdev_alloc_total; + + if (WARN_ON(nb == NULL)) + return NOTIFY_BAD; + + kbdev = container_of(nb, struct kbase_device, oom_notifier_block); + + kbdev_alloc_total = + KBASE_PAGES_TO_KIB(atomic_read(&(kbdev->memdev.used_pages))); + + dev_err(kbdev->dev, "OOM notifier: dev %s %lu kB\n", kbdev->devname, + kbdev_alloc_total); + + mutex_lock(&kbdev->kctx_list_lock); + + list_for_each_entry (kctx, &kbdev->kctx_list, kctx_list_link) { + struct pid *pid_struct; + struct task_struct *task; + unsigned long task_alloc_total = + KBASE_PAGES_TO_KIB(atomic_read(&(kctx->used_pages))); + + rcu_read_lock(); + pid_struct = find_get_pid(kctx->pid); + task = pid_task(pid_struct, PIDTYPE_PID); + + dev_err(kbdev->dev, + "OOM notifier: tsk %s tgid (%u) pid (%u) %lu kB\n", + task ? task->comm : "[null task]", kctx->tgid, + kctx->pid, task_alloc_total); + + put_pid(pid_struct); + rcu_read_unlock(); + } + + mutex_unlock(&kbdev->kctx_list_lock); + return NOTIFY_OK; +} + int kbase_device_misc_init(struct kbase_device * const kbdev) { int err; -#ifdef CONFIG_ARM64 +#if IS_ENABLED(CONFIG_ARM64) struct device_node *np = NULL; #endif /* CONFIG_ARM64 */ spin_lock_init(&kbdev->mmu_mask_change); mutex_init(&kbdev->mmu_hw_mutex); -#ifdef CONFIG_ARM64 +#if IS_ENABLED(CONFIG_ARM64) kbdev->cci_snoop_enabled = false; np = kbdev->dev->of_node; if (np != NULL) { @@ -243,8 +298,15 @@ int kbase_device_misc_init(struct kbase_device * const kbdev) mutex_init(&kbdev->kctx_list_lock); INIT_LIST_HEAD(&kbdev->kctx_list); - spin_lock_init(&kbdev->hwaccess_lock); + dev_dbg(kbdev->dev, "Registering mali_oom_notifier_handlern"); + kbdev->oom_notifier_block.notifier_call = mali_oom_notifier_handler; + err = register_oom_notifier(&kbdev->oom_notifier_block); + if (err) { + dev_err(kbdev->dev, + "Unable to register OOM notifier for Mali - but will continue\n"); + kbdev->oom_notifier_block.notifier_call = NULL; + } return 0; term_as: @@ -267,6 +329,9 @@ void kbase_device_misc_term(struct kbase_device *kbdev) kbase_ktrace_term(kbdev); kbase_device_all_as_term(kbdev); + + if (kbdev->oom_notifier_block.notifier_call) + unregister_oom_notifier(&kbdev->oom_notifier_block); } void kbase_device_free(struct kbase_device *kbdev) @@ -330,6 +395,7 @@ void kbase_device_vinstr_term(struct kbase_device *kbdev) kbase_vinstr_term(kbdev->vinstr_ctx); } +#if defined(CONFIG_DEBUG_FS) && !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) int kbase_device_io_history_init(struct kbase_device *kbdev) { return kbase_io_history_init(&kbdev->io_history, @@ -340,6 +406,7 @@ void kbase_device_io_history_term(struct kbase_device *kbdev) { kbase_io_history_term(&kbdev->io_history); } +#endif int kbase_device_misc_register(struct kbase_device *kbdev) { @@ -405,6 +472,10 @@ int kbase_device_early_init(struct kbase_device *kbdev) /* We're done accessing the GPU registers for now. */ kbase_pm_register_access_disable(kbdev); + /* This spinlock has to be initialized before installing interrupt + * handlers that require to hold it to process interrupts. + */ + spin_lock_init(&kbdev->hwaccess_lock); #ifdef CONFIG_MALI_ARBITER_SUPPORT if (kbdev->arb.arb_if) err = kbase_arbiter_pm_install_interrupts(kbdev); @@ -439,3 +510,17 @@ void kbase_device_early_term(struct kbase_device *kbdev) kbase_pm_runtime_term(kbdev); kbasep_platform_device_term(kbdev); } + +int kbase_device_late_init(struct kbase_device *kbdev) +{ + int err; + + err = kbasep_platform_device_late_init(kbdev); + + return err; +} + +void kbase_device_late_term(struct kbase_device *kbdev) +{ + kbasep_platform_device_late_term(kbdev); +} diff --git a/drivers/gpu/arm/bifrost/device/mali_kbase_device.h b/drivers/gpu/arm/bifrost/device/mali_kbase_device.h index 3a774fc3f9b0..517c16b15fca 100644 --- a/drivers/gpu/arm/bifrost/device/mali_kbase_device.h +++ b/drivers/gpu/arm/bifrost/device/mali_kbase_device.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -46,6 +46,19 @@ void kbase_device_put_list(const struct list_head *dev_list); */ void kbase_increment_device_id(void); +/** + * kbase_device_firmware_init_once - Initialize firmware and HWC + * + * @kbdev: An instance of the GPU platform device, allocated from the probe + * method of the driver. + * + * When a device file is opened for the first time, + * load firmware and initialize hardware counter components. + * + * @return 0 on success. An error code on failure. + */ +int kbase_device_firmware_init_once(struct kbase_device *kbdev); + /** * kbase_device_init - Device initialisation. * diff --git a/drivers/gpu/arm/bifrost/device/mali_kbase_device_hw.c b/drivers/gpu/arm/bifrost/device/mali_kbase_device_hw.c index 4097296952d8..762483123b61 100644 --- a/drivers/gpu/arm/bifrost/device/mali_kbase_device_hw.c +++ b/drivers/gpu/arm/bifrost/device/mali_kbase_device_hw.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2014-2016, 2018-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2016, 2018-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -27,7 +27,7 @@ #include #include -#if !defined(CONFIG_MALI_BIFROST_NO_MALI) +#if !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) void kbase_reg_write(struct kbase_device *kbdev, u32 offset, u32 value) { KBASE_DEBUG_ASSERT(kbdev->pm.backend.gpu_powered); @@ -35,7 +35,7 @@ void kbase_reg_write(struct kbase_device *kbdev, u32 offset, u32 value) writel(value, kbdev->reg + offset); -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) if (unlikely(kbdev->io_history.enabled)) kbase_io_history_add(&kbdev->io_history, kbdev->reg + offset, value, 1); @@ -54,7 +54,7 @@ u32 kbase_reg_read(struct kbase_device *kbdev, u32 offset) val = readl(kbdev->reg + offset); -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) if (unlikely(kbdev->io_history.enabled)) kbase_io_history_add(&kbdev->io_history, kbdev->reg + offset, val, 0); @@ -74,7 +74,7 @@ bool kbase_is_gpu_removed(struct kbase_device *kbdev) return val == 0; } -#endif /* !defined(CONFIG_MALI_BIFROST_NO_MALI) */ +#endif /* !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) */ void kbase_gpu_start_cache_clean_nolock(struct kbase_device *kbdev) { diff --git a/drivers/gpu/arm/bifrost/device/mali_kbase_device_internal.h b/drivers/gpu/arm/bifrost/device/mali_kbase_device_internal.h index 067f33ce0528..b4c063ce5257 100644 --- a/drivers/gpu/arm/bifrost/device/mali_kbase_device_internal.h +++ b/drivers/gpu/arm/bifrost/device/mali_kbase_device_internal.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -51,8 +51,18 @@ void kbase_device_hwcnt_virtualizer_term(struct kbase_device *kbdev); int kbase_device_list_init(struct kbase_device *kbdev); void kbase_device_list_term(struct kbase_device *kbdev); +#if defined(CONFIG_DEBUG_FS) && !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) int kbase_device_io_history_init(struct kbase_device *kbdev); void kbase_device_io_history_term(struct kbase_device *kbdev); +#else +static inline int kbase_device_io_history_init(struct kbase_device *kbdev) +{ + return 0; +} +static inline void kbase_device_io_history_term(struct kbase_device *kbdev) +{ +} +#endif int kbase_device_misc_register(struct kbase_device *kbdev); void kbase_device_misc_deregister(struct kbase_device *kbdev); @@ -72,3 +82,17 @@ int kbase_device_early_init(struct kbase_device *kbdev); * @kbdev: Device pointer */ void kbase_device_early_term(struct kbase_device *kbdev); + +/** + * kbase_device_late_init - Complete any device-specific initialization. + * @kbdev: Device pointer + * + * Return: 0 on success, or an error code on failure. + */ +int kbase_device_late_init(struct kbase_device *kbdev); + +/** + * kbase_device_late_term - Complete any device-specific termination. + * @kbdev: Device pointer + */ +void kbase_device_late_term(struct kbase_device *kbdev); diff --git a/drivers/base/arm/memory_group_manager/Kconfig b/drivers/gpu/arm/bifrost/gpu/Kbuild similarity index 66% rename from drivers/base/arm/memory_group_manager/Kconfig rename to drivers/gpu/arm/bifrost/gpu/Kbuild index de698fa1eb4c..f3a48caf6b2c 100644 --- a/drivers/base/arm/memory_group_manager/Kconfig +++ b/drivers/gpu/arm/bifrost/gpu/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2012, 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -18,10 +18,10 @@ # # +bifrost_kbase-y += gpu/mali_kbase_gpu.o -config MALI_MEMORY_GROUP_MANAGER - tristate "MALI_MEMORY_GROUP_MANAGER" - help - This option enables an example implementation of a memory group manager - for allocation and release of pages for memory pools managed by Mali GPU - device drivers. +ifeq ($(CONFIG_MALI_CSF_SUPPORT),y) + bifrost_kbase-y += gpu/backend/mali_kbase_gpu_fault_csf.o +else + bifrost_kbase-y += gpu/backend/mali_kbase_gpu_fault_jm.o +endif diff --git a/drivers/gpu/arm/bifrost/gpu/backend/mali_kbase_gpu_fault_csf.c b/drivers/gpu/arm/bifrost/gpu/backend/mali_kbase_gpu_fault_csf.c index ab0e3264615c..f6784f1647fc 100644 --- a/drivers/gpu/arm/bifrost/gpu/backend/mali_kbase_gpu_fault_csf.c +++ b/drivers/gpu/arm/bifrost/gpu/backend/mali_kbase_gpu_fault_csf.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -21,7 +21,7 @@ #include #include -#include "../mali_kbase_gpu_fault.h" +#include const char *kbase_gpu_exception_name(u32 const exception_code) { diff --git a/drivers/gpu/arm/bifrost/gpu/backend/mali_kbase_gpu_fault_jm.c b/drivers/gpu/arm/bifrost/gpu/backend/mali_kbase_gpu_fault_jm.c index 110e5b3244b7..37015ccacd7c 100644 --- a/drivers/gpu/arm/bifrost/gpu/backend/mali_kbase_gpu_fault_jm.c +++ b/drivers/gpu/arm/bifrost/gpu/backend/mali_kbase_gpu_fault_jm.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -21,7 +21,7 @@ #include -#include "../mali_kbase_gpu_fault.h" +#include const char *kbase_gpu_exception_name(u32 const exception_code) { diff --git a/drivers/gpu/arm/bifrost/gpu/mali_kbase_gpu.c b/drivers/gpu/arm/bifrost/gpu/mali_kbase_gpu.c index 92aa59373bcd..8a84ef54100a 100644 --- a/drivers/gpu/arm/bifrost/gpu/mali_kbase_gpu.c +++ b/drivers/gpu/arm/bifrost/gpu/mali_kbase_gpu.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/gpu/mali_kbase_gpu_fault.h b/drivers/gpu/arm/bifrost/gpu/mali_kbase_gpu_fault.h index 9f4dc66bed94..d1e9f770384b 100644 --- a/drivers/gpu/arm/bifrost/gpu/mali_kbase_gpu_fault.h +++ b/drivers/gpu/arm/bifrost/gpu/mali_kbase_gpu_fault.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/gpu/mali_kbase_gpu_regmap.h b/drivers/gpu/arm/bifrost/gpu/mali_kbase_gpu_regmap.h index 8e5941ed3f3f..2da05a8bf044 100644 --- a/drivers/gpu/arm/bifrost/gpu/mali_kbase_gpu_regmap.h +++ b/drivers/gpu/arm/bifrost/gpu/mali_kbase_gpu_regmap.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/ipa/Kbuild b/drivers/gpu/arm/bifrost/ipa/Kbuild index 4faa325732c7..0be664c47b54 100644 --- a/drivers/gpu/arm/bifrost/ipa/Kbuild +++ b/drivers/gpu/arm/bifrost/ipa/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2016-2018, 2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2016-2018, 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -19,17 +19,17 @@ # bifrost_kbase-y += \ - ipa/mali_kbase_ipa_simple.o \ - ipa/mali_kbase_ipa.o + ipa/mali_kbase_ipa_simple.o \ + ipa/mali_kbase_ipa.o bifrost_kbase-$(CONFIG_DEBUG_FS) += ipa/mali_kbase_ipa_debugfs.o ifeq ($(MALI_USE_CSF),1) - bifrost_kbase-y += \ - ipa/backend/mali_kbase_ipa_counter_csf.o \ - ipa/backend/mali_kbase_ipa_counter_common_csf.o + bifrost_kbase-y += \ + ipa/backend/mali_kbase_ipa_counter_csf.o \ + ipa/backend/mali_kbase_ipa_counter_common_csf.o else - bifrost_kbase-y += \ - ipa/backend/mali_kbase_ipa_counter_jm.o \ - ipa/backend/mali_kbase_ipa_counter_common_jm.o + bifrost_kbase-y += \ + ipa/backend/mali_kbase_ipa_counter_jm.o \ + ipa/backend/mali_kbase_ipa_counter_common_jm.o endif diff --git a/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_csf.c b/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_csf.c index 89bba49a7c98..81dc56b3d688 100644 --- a/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_csf.c +++ b/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_csf.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_csf.h b/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_csf.h index 8e299314d7de..37d2efc59fcc 100644 --- a/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_csf.h +++ b/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_csf.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_jm.c b/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_jm.c index 076dcd0266df..4737b0eb3dd1 100644 --- a/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_jm.c +++ b/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_jm.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2017-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2017-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_jm.h b/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_jm.h index 24602beed3d2..3486a9be1820 100644 --- a/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_jm.h +++ b/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_common_jm.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2017-2018, 2020-2021 ARM Limited. All rights reserved. @@ -41,7 +41,8 @@ struct kbase_ipa_model_vinstr_data; -typedef u32 (*kbase_ipa_get_active_cycles_callback)(struct kbase_ipa_model_vinstr_data *); +typedef u32 +kbase_ipa_get_active_cycles_callback(struct kbase_ipa_model_vinstr_data *); /** * struct kbase_ipa_model_vinstr_data - IPA context per device @@ -73,7 +74,7 @@ struct kbase_ipa_model_vinstr_data { s32 group_values[KBASE_IPA_MAX_GROUP_DEF_NUM]; const struct kbase_ipa_group *groups_def; size_t groups_def_num; - kbase_ipa_get_active_cycles_callback get_active_cycles; + kbase_ipa_get_active_cycles_callback *get_active_cycles; struct kbase_hwcnt_virtualizer_client *hvirt_cli; struct kbase_hwcnt_dump_buffer dump_buf; s32 reference_voltage; @@ -215,7 +216,7 @@ void kbase_ipa_vinstr_reset_data(struct kbase_ipa_model *model); int kbase_ipa_vinstr_common_model_init(struct kbase_ipa_model *model, const struct kbase_ipa_group *ipa_groups_def, size_t ipa_group_size, - kbase_ipa_get_active_cycles_callback get_active_cycles, + kbase_ipa_get_active_cycles_callback *get_active_cycles, s32 reference_voltage); /** diff --git a/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_csf.c b/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_csf.c index 9326b0195544..1852c3c2b5d1 100644 --- a/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_csf.c +++ b/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_csf.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. @@ -24,11 +24,15 @@ /* MEMSYS counter block offsets */ #define L2_RD_MSG_IN (16) +#define L2_WR_MSG_IN (18) +#define L2_READ_LOOKUP (26) #define L2_EXT_WRITE_NOSNP_FULL (43) /* SC counter block offsets */ #define FRAG_QUADS_EZS_UPDATE (13) +#define FULL_QUAD_WARPS (21) #define EXEC_INSTR_FMA (27) +#define EXEC_INSTR_CVT (28) #define TEX_FILT_NUM_OPS (39) #define LS_MEM_READ_SHORT (45) #define LS_MEM_WRITE_SHORT (47) @@ -38,6 +42,7 @@ #define IDVS_POS_SHAD_STALL (23) #define PREFETCH_STALL (25) #define VFETCH_POS_READ_WAIT (29) +#define VFETCH_VERTEX_WAIT (30) #define IDVS_VAR_SHAD_STALL (38) #define COUNTER_DEF(cnt_name, coeff, cnt_idx, block_type) \ @@ -60,9 +65,9 @@ #define TILER_COUNTER_DEF(cnt_name, coeff, cnt_idx) \ COUNTER_DEF(cnt_name, coeff, cnt_idx, KBASE_IPA_CORE_TYPE_TILER) -/* Table of description of HW counters used by IPA counter model. +/* Tables of description of HW counters used by IPA counter model. * - * This table provides a description of each performance counter + * These tables provide a description of each performance counter * used by the top level counter model for energy estimation. */ static const struct kbase_ipa_counter ipa_top_level_cntrs_def_todx[] = { @@ -75,10 +80,11 @@ static const struct kbase_ipa_counter ipa_top_level_cntrs_def_todx[] = { TILER_COUNTER_DEF("vfetch_pos_read_wait", -119118, VFETCH_POS_READ_WAIT), }; - /* This table provides a description of each performance counter + +/* These tables provide a description of each performance counter * used by the shader cores counter model for energy estimation. */ - static const struct kbase_ipa_counter ipa_shader_core_cntrs_def_todx[] = { +static const struct kbase_ipa_counter ipa_shader_core_cntrs_def_todx[] = { SC_COUNTER_DEF("exec_instr_fma", 505449, EXEC_INSTR_FMA), SC_COUNTER_DEF("tex_filt_num_operations", 574869, TEX_FILT_NUM_OPS), SC_COUNTER_DEF("ls_mem_read_short", 60917, LS_MEM_READ_SHORT), @@ -87,6 +93,7 @@ static const struct kbase_ipa_counter ipa_top_level_cntrs_def_todx[] = { SC_COUNTER_DEF("vary_slot_16", 181069, VARY_SLOT_16), }; + #define IPA_POWER_MODEL_OPS(gpu, init_token) \ const struct kbase_ipa_model_ops kbase_ ## gpu ## _ipa_model_ops = { \ .name = "mali-" #gpu "-power-model", \ @@ -122,12 +129,12 @@ static const struct kbase_ipa_counter ipa_top_level_cntrs_def_todx[] = { */ STANDARD_POWER_MODEL(todx, 750); + /* Assuming LODX is an alias of TODX for IPA */ ALIAS_POWER_MODEL(lodx, todx); static const struct kbase_ipa_model_ops *ipa_counter_model_ops[] = { - &kbase_todx_ipa_model_ops, - &kbase_lodx_ipa_model_ops + &kbase_todx_ipa_model_ops, &kbase_lodx_ipa_model_ops, }; const struct kbase_ipa_model_ops *kbase_ipa_counter_model_ops_find( diff --git a/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_jm.c b/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_jm.c index 8d33b139169f..2f4c9d9dd68b 100644 --- a/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_jm.c +++ b/drivers/gpu/arm/bifrost/ipa/backend/mali_kbase_ipa_counter_jm.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2016-2021 ARM Limited. All rights reserved. @@ -23,9 +23,7 @@ #include "mali_kbase_ipa_counter_common_jm.h" #include "mali_kbase.h" -#ifdef CONFIG_MALI_BIFROST_NO_MALI -#include -#endif + /* Performance counter blocks base offsets */ #define JM_BASE (0 * KBASE_IPA_NR_BYTES_PER_BLOCK) @@ -96,15 +94,9 @@ static u32 kbase_g7x_power_model_get_memsys_counter(struct kbase_ipa_model_vinst static u32 kbase_g7x_power_model_get_sc_counter(struct kbase_ipa_model_vinstr_data *model_data, u32 counter_block_offset) { -#ifdef CONFIG_MALI_BIFROST_NO_MALI - const u32 sc_base = MEMSYS_BASE + - (KBASE_DUMMY_MODEL_MAX_MEMSYS_BLOCKS * - KBASE_IPA_NR_BYTES_PER_BLOCK); -#else const u32 sc_base = MEMSYS_BASE + (model_data->kbdev->gpu_props.props.l2_props.num_l2_slices * KBASE_IPA_NR_BYTES_PER_BLOCK); -#endif return sc_base + counter_block_offset; } diff --git a/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa.c b/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa.c index e86a94317b0b..24d7b06218f2 100644 --- a/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa.c +++ b/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2016-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2016-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -537,7 +537,6 @@ static void opp_translate_freq_voltage(struct kbase_device *kbdev, unsigned long *freqs, unsigned long *volts) { -#ifndef CONFIG_MALI_BIFROST_NO_MALI u64 core_mask; kbase_devfreq_opp_translate(kbdev, nominal_freq, &core_mask, @@ -550,16 +549,6 @@ static void opp_translate_freq_voltage(struct kbase_device *kbdev, volts[KBASE_IPA_BLOCK_TYPE_SHADER_CORES] = volts[KBASE_IPA_BLOCK_TYPE_TOP_LEVEL]; } -#else - /* An arbitrary voltage and frequency value can be chosen for testing - * in no mali configuration which may not match with any OPP level. - */ - freqs[KBASE_IPA_BLOCK_TYPE_TOP_LEVEL] = nominal_freq; - volts[KBASE_IPA_BLOCK_TYPE_TOP_LEVEL] = nominal_voltage; - - freqs[KBASE_IPA_BLOCK_TYPE_SHADER_CORES] = nominal_freq; - volts[KBASE_IPA_BLOCK_TYPE_SHADER_CORES] = nominal_voltage; -#endif } #if KERNEL_VERSION(5, 10, 0) > LINUX_VERSION_CODE diff --git a/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa.h b/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa.h index beceb6ce7b55..1d81ab6ae53f 100644 --- a/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa.h +++ b/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2016-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2016-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_debugfs.c b/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_debugfs.c index 2672146e8e1d..59763896a988 100644 --- a/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_debugfs.c +++ b/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_debugfs.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2017-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2017-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_debugfs.h b/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_debugfs.h index 189b43c609d6..f690367757c9 100644 --- a/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_debugfs.h +++ b/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_debugfs.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2017, 2020-2021 ARM Limited. All rights reserved. @@ -27,7 +27,7 @@ enum kbase_ipa_model_param_type { PARAM_TYPE_STRING, }; -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) void kbase_ipa_debugfs_init(struct kbase_device *kbdev); int kbase_ipa_model_param_add(struct kbase_ipa_model *model, const char *name, diff --git a/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_simple.c b/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_simple.c index dce685a3b072..c90894e934f3 100644 --- a/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_simple.c +++ b/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_simple.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2016-2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2016-2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -22,7 +22,7 @@ #include #include #include -#ifdef CONFIG_DEVFREQ_THERMAL +#if IS_ENABLED(CONFIG_DEVFREQ_THERMAL) #include #endif #include diff --git a/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_simple.h b/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_simple.h index 40cf0d151a32..dd17786a51d9 100644 --- a/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_simple.h +++ b/drivers/gpu/arm/bifrost/ipa/mali_kbase_ipa_simple.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/jm/mali_kbase_jm_defs.h b/drivers/gpu/arm/bifrost/jm/mali_kbase_jm_defs.h index 8b3e03f15964..a44b4b774fe0 100644 --- a/drivers/gpu/arm/bifrost/jm/mali_kbase_jm_defs.h +++ b/drivers/gpu/arm/bifrost/jm/mali_kbase_jm_defs.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -126,7 +126,7 @@ /* Reset the GPU after each atom completion */ #define KBASE_SERIALIZE_RESET (1 << 2) -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) /** * struct base_job_fault_event - keeps track of the atom which faulted or which * completed after the faulty atom but before the @@ -602,7 +602,7 @@ struct kbase_jd_atom { wait_queue_head_t completed; enum kbase_jd_atom_state status; -#ifdef CONFIG_GPU_TRACEPOINTS +#if IS_ENABLED(CONFIG_GPU_TRACEPOINTS) int work_id; #endif int slot_nr; @@ -627,7 +627,7 @@ struct kbase_jd_atom { u32 flush_id; -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) struct base_job_fault_event fault_event; #endif struct list_head queue; @@ -804,7 +804,7 @@ struct kbase_jd_context { u32 job_nr; size_t tb_wrap_offset; -#ifdef CONFIG_GPU_TRACEPOINTS +#if IS_ENABLED(CONFIG_GPU_TRACEPOINTS) atomic_t work_id; #endif diff --git a/drivers/gpu/arm/bifrost/jm/mali_kbase_jm_js.h b/drivers/gpu/arm/bifrost/jm/mali_kbase_jm_js.h index e3275369b459..5e0c4bc9e507 100644 --- a/drivers/gpu/arm/bifrost/jm/mali_kbase_jm_js.h +++ b/drivers/gpu/arm/bifrost/jm/mali_kbase_jm_js.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/jm/mali_kbase_js_defs.h b/drivers/gpu/arm/bifrost/jm/mali_kbase_js_defs.h index 68660a9709c3..405f346f4368 100644 --- a/drivers/gpu/arm/bifrost/jm/mali_kbase_js_defs.h +++ b/drivers/gpu/arm/bifrost/jm/mali_kbase_js_defs.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2011-2018, 2020-2021 ARM Limited. All rights reserved. @@ -37,8 +37,8 @@ typedef u32 kbase_context_flags; * typedef kbasep_js_ctx_job_cb - Callback function run on all of a context's * jobs registered with the Job Scheduler */ -typedef void (*kbasep_js_ctx_job_cb)(struct kbase_device *kbdev, - struct kbase_jd_atom *katom); +typedef void kbasep_js_ctx_job_cb(struct kbase_device *kbdev, + struct kbase_jd_atom *katom); /* * @brief Maximum number of jobs that can be submitted to a job slot whilst diff --git a/drivers/gpu/arm/bifrost/mali_base_hwconfig_features.h b/drivers/gpu/arm/bifrost/mali_base_hwconfig_features.h index bdc769fd4f06..93cd05ff71a0 100644 --- a/drivers/gpu/arm/bifrost/mali_base_hwconfig_features.h +++ b/drivers/gpu/arm/bifrost/mali_base_hwconfig_features.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. @@ -386,5 +386,59 @@ static const enum base_hw_feature base_hw_features_tODx[] = { BASE_HW_FEATURE_END }; +static const enum base_hw_feature base_hw_features_tGRx[] = { + BASE_HW_FEATURE_JOBCHAIN_DISAMBIGUATION, + BASE_HW_FEATURE_PWRON_DURING_PWROFF_TRANS, + BASE_HW_FEATURE_XAFFINITY, + BASE_HW_FEATURE_WARPING, + BASE_HW_FEATURE_INTERPIPE_REG_ALIASING, + BASE_HW_FEATURE_32_BIT_UNIFORM_ADDRESS, + BASE_HW_FEATURE_ATTR_AUTO_TYPE_INFERRAL, + BASE_HW_FEATURE_BRNDOUT_CC, + BASE_HW_FEATURE_BRNDOUT_KILL, + BASE_HW_FEATURE_LD_ST_LEA_TEX, + BASE_HW_FEATURE_LD_ST_TILEBUFFER, + BASE_HW_FEATURE_LINEAR_FILTER_FLOAT, + BASE_HW_FEATURE_MRT, + BASE_HW_FEATURE_MSAA_16X, + BASE_HW_FEATURE_NEXT_INSTRUCTION_TYPE, + BASE_HW_FEATURE_OUT_OF_ORDER_EXEC, + BASE_HW_FEATURE_T7XX_PAIRING_RULES, + BASE_HW_FEATURE_TEST4_DATUM_MODE, + BASE_HW_FEATURE_FLUSH_REDUCTION, + BASE_HW_FEATURE_PROTECTED_DEBUG_MODE, + BASE_HW_FEATURE_COHERENCY_REG, + BASE_HW_FEATURE_L2_CONFIG, + BASE_HW_FEATURE_CLEAN_ONLY_SAFE, + BASE_HW_FEATURE_END +}; + +static const enum base_hw_feature base_hw_features_tVAx[] = { + BASE_HW_FEATURE_JOBCHAIN_DISAMBIGUATION, + BASE_HW_FEATURE_PWRON_DURING_PWROFF_TRANS, + BASE_HW_FEATURE_XAFFINITY, + BASE_HW_FEATURE_WARPING, + BASE_HW_FEATURE_INTERPIPE_REG_ALIASING, + BASE_HW_FEATURE_32_BIT_UNIFORM_ADDRESS, + BASE_HW_FEATURE_ATTR_AUTO_TYPE_INFERRAL, + BASE_HW_FEATURE_BRNDOUT_CC, + BASE_HW_FEATURE_BRNDOUT_KILL, + BASE_HW_FEATURE_LD_ST_LEA_TEX, + BASE_HW_FEATURE_LD_ST_TILEBUFFER, + BASE_HW_FEATURE_LINEAR_FILTER_FLOAT, + BASE_HW_FEATURE_MRT, + BASE_HW_FEATURE_MSAA_16X, + BASE_HW_FEATURE_NEXT_INSTRUCTION_TYPE, + BASE_HW_FEATURE_OUT_OF_ORDER_EXEC, + BASE_HW_FEATURE_T7XX_PAIRING_RULES, + BASE_HW_FEATURE_TEST4_DATUM_MODE, + BASE_HW_FEATURE_FLUSH_REDUCTION, + BASE_HW_FEATURE_PROTECTED_DEBUG_MODE, + BASE_HW_FEATURE_COHERENCY_REG, + BASE_HW_FEATURE_L2_CONFIG, + BASE_HW_FEATURE_CLEAN_ONLY_SAFE, + BASE_HW_FEATURE_END +}; + #endif /* _BASE_HWCONFIG_FEATURES_H_ */ diff --git a/drivers/gpu/arm/bifrost/mali_base_hwconfig_issues.h b/drivers/gpu/arm/bifrost/mali_base_hwconfig_issues.h index a61eeb2ca200..beda1e4bf650 100644 --- a/drivers/gpu/arm/bifrost/mali_base_hwconfig_issues.h +++ b/drivers/gpu/arm/bifrost/mali_base_hwconfig_issues.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. @@ -607,5 +607,35 @@ static const enum base_hw_issue base_hw_issues_model_tODx[] = { BASE_HW_ISSUE_END }; +static const enum base_hw_issue base_hw_issues_tGRx_r0p0[] = { + BASE_HW_ISSUE_9435, + BASE_HW_ISSUE_TSIX_2033, + BASE_HW_ISSUE_TTRX_1337, + BASE_HW_ISSUE_END +}; + +static const enum base_hw_issue base_hw_issues_model_tGRx[] = { + BASE_HW_ISSUE_5736, + BASE_HW_ISSUE_9435, + BASE_HW_ISSUE_TSIX_2033, + BASE_HW_ISSUE_TTRX_1337, + BASE_HW_ISSUE_END +}; + +static const enum base_hw_issue base_hw_issues_tVAx_r0p0[] = { + BASE_HW_ISSUE_9435, + BASE_HW_ISSUE_TSIX_2033, + BASE_HW_ISSUE_TTRX_1337, + BASE_HW_ISSUE_END +}; + +static const enum base_hw_issue base_hw_issues_model_tVAx[] = { + BASE_HW_ISSUE_5736, + BASE_HW_ISSUE_9435, + BASE_HW_ISSUE_TSIX_2033, + BASE_HW_ISSUE_TTRX_1337, + BASE_HW_ISSUE_END +}; + #endif /* _BASE_HWCONFIG_ISSUES_H_ */ diff --git a/drivers/gpu/arm/bifrost/mali_kbase.h b/drivers/gpu/arm/bifrost/mali_kbase.h index 52dfbe4f6e7f..d9bf1f4f8f2d 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase.h +++ b/drivers/gpu/arm/bifrost/mali_kbase.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -74,7 +74,7 @@ #include "ipa/mali_kbase_ipa.h" -#ifdef CONFIG_GPU_TRACEPOINTS +#if IS_ENABLED(CONFIG_GPU_TRACEPOINTS) #include #endif @@ -196,7 +196,7 @@ void kbase_device_pm_term(struct kbase_device *kbdev); int power_control_init(struct kbase_device *kbdev); void power_control_term(struct kbase_device *kbdev); -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) void kbase_device_debugfs_term(struct kbase_device *kbdev); int kbase_device_debugfs_init(struct kbase_device *kbdev); #else /* CONFIG_DEBUG_FS */ diff --git a/drivers/gpu/arm/bifrost/mali_kbase_as_fault_debugfs.c b/drivers/gpu/arm/bifrost/mali_kbase_as_fault_debugfs.c index 18ca56cb7cec..5cf800905335 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_as_fault_debugfs.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_as_fault_debugfs.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2016-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2016-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -25,7 +25,7 @@ #include #include -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) #ifdef CONFIG_MALI_BIFROST_DEBUG static int kbase_as_fault_read(struct seq_file *sfile, void *data) @@ -79,7 +79,7 @@ static const struct file_operations as_fault_fops = { */ void kbase_as_fault_debugfs_init(struct kbase_device *kbdev) { -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) #ifdef CONFIG_MALI_BIFROST_DEBUG uint i; char as_name[64]; diff --git a/drivers/gpu/arm/bifrost/mali_kbase_as_fault_debugfs.h b/drivers/gpu/arm/bifrost/mali_kbase_as_fault_debugfs.h index a9cf99c0aa55..45e48f4d345b 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_as_fault_debugfs.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_as_fault_debugfs.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2016, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2016, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -38,7 +38,7 @@ void kbase_as_fault_debugfs_init(struct kbase_device *kbdev); static inline void kbase_as_fault_debugfs_new(struct kbase_device *kbdev, int as_no) { -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) #ifdef CONFIG_MALI_BIFROST_DEBUG kbdev->debugfs_as_read_bitmap |= (1ULL << as_no); #endif /* CONFIG_DEBUG_FS */ diff --git a/drivers/gpu/arm/bifrost/mali_kbase_bits.h b/drivers/gpu/arm/bifrost/mali_kbase_bits.h index 6f6dba1b2a02..a085fd86c488 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_bits.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_bits.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_cache_policy.c b/drivers/gpu/arm/bifrost/mali_kbase_cache_policy.c index 7f266aa53cac..af51ed8c2dec 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_cache_policy.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_cache_policy.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2012-2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2012-2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_cache_policy.h b/drivers/gpu/arm/bifrost/mali_kbase_cache_policy.h index 6799492be822..598d245383fd 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_cache_policy.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_cache_policy.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2012-2013, 2015, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_caps.h b/drivers/gpu/arm/bifrost/mali_kbase_caps.h index 478a3177e8ec..c232e2183d78 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_caps.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_caps.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_ccswe.c b/drivers/gpu/arm/bifrost/mali_kbase_ccswe.c index 624482ad6c15..6a1e7e4c5ff5 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_ccswe.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_ccswe.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_ccswe.h b/drivers/gpu/arm/bifrost/mali_kbase_ccswe.h index 5c440b8473d3..8e55ffc70e77 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_ccswe.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_ccswe.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_config.c b/drivers/gpu/arm/bifrost/mali_kbase_config.c index fe71526fdf96..37dbca129f86 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_config.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_config.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2011-2015, 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2011-2015, 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -43,3 +43,62 @@ void kbasep_platform_device_term(struct kbase_device *kbdev) platform_funcs_p->platform_term_func(kbdev); } +int kbasep_platform_device_late_init(struct kbase_device *kbdev) +{ + struct kbase_platform_funcs_conf *platform_funcs_p; + + platform_funcs_p = (struct kbase_platform_funcs_conf *)PLATFORM_FUNCS; + if (platform_funcs_p && platform_funcs_p->platform_late_init_func) + platform_funcs_p->platform_late_init_func(kbdev); + + return 0; +} + +void kbasep_platform_device_late_term(struct kbase_device *kbdev) +{ + struct kbase_platform_funcs_conf *platform_funcs_p; + + platform_funcs_p = (struct kbase_platform_funcs_conf *)PLATFORM_FUNCS; + if (platform_funcs_p && platform_funcs_p->platform_late_term_func) + platform_funcs_p->platform_late_term_func(kbdev); +} + +#if !MALI_USE_CSF +int kbasep_platform_context_init(struct kbase_context *kctx) +{ + struct kbase_platform_funcs_conf *platform_funcs_p; + + platform_funcs_p = (struct kbase_platform_funcs_conf *)PLATFORM_FUNCS; + if (platform_funcs_p && platform_funcs_p->platform_handler_context_init_func) + return platform_funcs_p->platform_handler_context_init_func(kctx); + + return 0; +} + +void kbasep_platform_context_term(struct kbase_context *kctx) +{ + struct kbase_platform_funcs_conf *platform_funcs_p; + + platform_funcs_p = (struct kbase_platform_funcs_conf *)PLATFORM_FUNCS; + if (platform_funcs_p && platform_funcs_p->platform_handler_context_term_func) + platform_funcs_p->platform_handler_context_term_func(kctx); +} + +void kbasep_platform_event_atom_submit(struct kbase_jd_atom *katom) +{ + struct kbase_platform_funcs_conf *platform_funcs_p; + + platform_funcs_p = (struct kbase_platform_funcs_conf *)PLATFORM_FUNCS; + if (platform_funcs_p && platform_funcs_p->platform_handler_atom_submit_func) + platform_funcs_p->platform_handler_atom_submit_func(katom); +} + +void kbasep_platform_event_atom_complete(struct kbase_jd_atom *katom) +{ + struct kbase_platform_funcs_conf *platform_funcs_p; + + platform_funcs_p = (struct kbase_platform_funcs_conf *)PLATFORM_FUNCS; + if (platform_funcs_p && platform_funcs_p->platform_handler_atom_complete_func) + platform_funcs_p->platform_handler_atom_complete_func(katom); +} +#endif diff --git a/drivers/gpu/arm/bifrost/mali_kbase_config.h b/drivers/gpu/arm/bifrost/mali_kbase_config.h index fe21cf5fa69f..e7eb3349692f 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_config.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_config.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2010-2017, 2019-2021 ARM Limited. All rights reserved. @@ -28,18 +28,27 @@ #include #include -#include +#include #include /* Forward declaration of struct kbase_device */ struct kbase_device; +#if !MALI_USE_CSF +/* Forward declaration of struct kbase_context */ +struct kbase_context; + +/* Forward declaration of struct kbase_atom */ +struct kbase_jd_atom; +#endif + /** - * struct kbase_platform_funcs_conf - Specifies platform init/term function pointers + * struct kbase_platform_funcs_conf - Specifies platform integration function + * pointers for DDK events such as device init and term. * * Specifies the functions pointers for platform specific initialization and - * termination. By default no functions are required. No additional platform - * specific control is necessary. + * termination as well as other events. By default no functions are required. + * No additional platform specific control is necessary. */ struct kbase_platform_funcs_conf { /** @@ -69,6 +78,84 @@ struct kbase_platform_funcs_conf { * can be accessed (and possibly terminated) in here. */ void (*platform_term_func)(struct kbase_device *kbdev); + + /** + * @platform_late_init_func: platform specific late init function pointer + * @kbdev - kbase_device pointer + * + * Function pointer to inform that the kbase driver initialization completed + * or NULL if no such function is required. At this point the GPU driver will be + * fully initialized. + * + * The platform specific private pointer kbase_device::platform_context + * can be accessed (and possibly terminated) in here. + */ + int (*platform_late_init_func)(struct kbase_device *kbdev); + + /** + * @platform_late_term_func: platform specific late termination function pointer + * @kbdev - kbase_device pointer + * + * Function pointer for platform specific termination or NULL if no + * termination function is required. At this point the GPU driver will complete + * termination process + * + * The platform specific private pointer kbase_device::platform_context + * can be accessed (and possibly terminated) in here. + */ + void (*platform_late_term_func)(struct kbase_device *kbdev); + +#if !MALI_USE_CSF + /** + * @platform_handler_context_init_func: platform specific handler for + * when a new kbase_context is created. + * @kctx - kbase_context pointer + * + * Returns 0 on success, negative error code otherwise. + * + * Function pointer for platform specific initialization of a kernel + * context or NULL if not required. Called at the last stage of kernel + * context initialization. + */ + int (*platform_handler_context_init_func)(struct kbase_context *kctx); + /** + * @platform_handler_context_term_func: platform specific handler for + * when a kbase_context is terminated. + * @kctx - kbase_context pointer + * + * Function pointer for platform specific termination of a kernel + * context or NULL if not required. Called at the first stage of kernel + * context termination. + */ + void (*platform_handler_context_term_func)(struct kbase_context *kctx); + /** + * @platform_handler_atom_submit_func: platform specific handler for + * when a kbase_jd_atom is submitted. + * @katom - kbase_jd_atom pointer + * + * Function pointer for platform specific handling at the point when an + * atom is submitted to the GPU or set to NULL if not required. The + * function cannot assume that it is running in a process context. + * + * Context: The caller must hold the hwaccess_lock. Function must be + * runnable in an interrupt context. + */ + void (*platform_handler_atom_submit_func)(struct kbase_jd_atom *katom); + /** + * @platform_handler_atom_complete_func: platform specific handler for + * when a kbase_jd_atom completes. + * @katom - kbase_jd_atom pointer + * + * Function pointer for platform specific handling at the point when an + * atom stops running on the GPU or set to NULL if not required. The + * function cannot assume that it is running in a process context. + * + * Context: The caller must hold the hwaccess_lock. Function must be + * runnable in an interrupt context. + */ + void (*platform_handler_atom_complete_func)( + struct kbase_jd_atom *katom); +#endif }; /* @@ -212,8 +299,8 @@ struct kbase_pm_callback_conf { * and such alignment should be maintained. * * @gpu_clk_handle: Handle of the GPU clock for which notifier was registered. - * @old_rate: Previous rate of this GPU clock. - * @new_rate: New rate of this GPU clock. + * @old_rate: Previous rate of this GPU clock in Hz. + * @new_rate: New rate of this GPU clock in Hz. */ struct kbase_gpu_clk_notifier_data { void *gpu_clk_handle; @@ -287,7 +374,7 @@ struct kbase_clk_rate_trace_op_conf { void *gpu_clk_handle, struct notifier_block *nb); }; -#ifdef CONFIG_OF +#if IS_ENABLED(CONFIG_OF) struct kbase_platform_config { }; #else @@ -348,6 +435,83 @@ int kbasep_platform_device_init(struct kbase_device *kbdev); */ void kbasep_platform_device_term(struct kbase_device *kbdev); +/** + * kbasep_platform_device_late_init: - Platform specific call to finish hardware + * initialization + * @kbdev: kbase device pointer + * + * Function calls a platform defined routine if specified in the configuration + * attributes. The routine can initialize any hardware and context state that + * is required for the GPU block to function. + * + * Return: 0 if no errors have been found in the config. + * Negative error code otherwise. + */ +int kbasep_platform_device_late_init(struct kbase_device *kbdev); + +/** + * kbasep_platform_device_late_term - Platform specific call to finish hardware + * termination + * @kbdev: Kbase device pointer + * + * Function calls a platform defined routine if specified in the configuration + * attributes. The routine can destroy any platform specific context state and + * shut down any hardware functionality that are outside of the Power Management + * callbacks. + * + */ +void kbasep_platform_device_late_term(struct kbase_device *kbdev); + +#if !MALI_USE_CSF +/** + * kbasep_platform_context_init - Platform specific callback when a kernel + * context is created + * @kctx: kbase_context pointer + * + * Function calls a platform defined routine if specified in the configuration + * attributes. The routine can initialize any per kernel context structures + * that are required for the GPU block to function. + * + * Return: 0 if no errors were encountered. Negative error code otherwise. + */ +int kbasep_platform_context_init(struct kbase_context *kctx); + +/** + * kbasep_platform_context_term - Platform specific callback when a kernel + * context is terminated + * @kctx: kbase_context pointer + * + * Function calls a platform defined routine if specified in the configuration + * attributes. The routine should terminate any per kernel context structures + * created as part of &kbasep_platform_context_init. + * + */ +void kbasep_platform_context_term(struct kbase_context *kctx); + +/** + * kbasep_platform_event_atom_submit - Platform specific callback when an atom + * is submitted to the GPU + * @katom: kbase_jd_atom pointer + * + * Function calls a platform defined routine if specified in the configuration + * attributes. The routine should not assume that it is in a process context. + * + * Return: 0 if no errors were encountered. Negative error code otherwise. + */ +void kbasep_platform_event_atom_submit(struct kbase_jd_atom *katom); + +/** + * kbasep_platform_event_atom_complete - Platform specific callback when an atom + * has stopped running on the GPU + * @katom: kbase_jd_atom pointer + * + * Function calls a platform defined routine if specified in the configuration + * attributes. The routine should not assume that it is in a process context. + * + */ +void kbasep_platform_event_atom_complete(struct kbase_jd_atom *katom); +#endif + #ifndef CONFIG_OF /** * kbase_platform_register - Register a platform device for the GPU diff --git a/drivers/gpu/arm/bifrost/mali_kbase_config_defaults.h b/drivers/gpu/arm/bifrost/mali_kbase_config_defaults.h index aad8e6c88e61..63c36e25899b 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_config_defaults.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_config_defaults.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2013-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_core_linux.c b/drivers/gpu/arm/bifrost/mali_kbase_core_linux.c index 42539832b05e..52c040aeae28 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_core_linux.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_core_linux.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -27,22 +27,15 @@ #ifdef CONFIG_MALI_BIFROST_DEVFREQ #include #include -#ifdef CONFIG_DEVFREQ_THERMAL +#if IS_ENABLED(CONFIG_DEVFREQ_THERMAL) #include #endif /* CONFIG_DEVFREQ_THERMAL */ #endif /* CONFIG_MALI_BIFROST_DEVFREQ */ -#ifdef CONFIG_MALI_BIFROST_NO_MALI -#include "mali_kbase_model_linux.h" -#include -#endif /* CONFIG_MALI_BIFROST_NO_MALI */ #include "mali_kbase_mem_profile_debugfs_buf_size.h" #include "mali_kbase_mem.h" #include "mali_kbase_mem_pool_debugfs.h" #include "mali_kbase_mem_pool_group.h" #include "mali_kbase_debugfs_helper.h" -#if !MALI_CUSTOMER_RELEASE -#include "mali_kbase_regs_dump_debugfs.h" -#endif /* !MALI_CUSTOMER_RELEASE */ #include "mali_kbase_regs_history_debugfs.h" #include #include @@ -76,7 +69,7 @@ #ifdef CONFIG_MALI_CINSTR_GWT #include "mali_kbase_gwt.h" #endif -#include "mali_kbase_pm_internal.h" +#include "backend/gpu/mali_kbase_pm_internal.h" #include "mali_kbase_dvfs_debugfs.h" #include @@ -108,7 +101,6 @@ #include - #include #include #include @@ -344,7 +336,7 @@ static void kbase_file_delete(struct kbase_file *const kfile) if (atomic_read(&kfile->setup_state) == KBASE_FILE_COMPLETE) { struct kbase_context *kctx = kfile->kctx; -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) kbasep_mem_profile_debugfs_remove(kctx); #endif @@ -437,7 +429,7 @@ int assign_irqs(struct kbase_device *kbdev) return -ENOENT; } -#ifdef CONFIG_OF +#if IS_ENABLED(CONFIG_OF) if (!strncasecmp(irq_res->name, "JOB", 4)) { irqtag = JOB_IRQ_TAG; } else if (!strncasecmp(irq_res->name, "MMU", 4)) { @@ -488,7 +480,7 @@ void kbase_release_device(struct kbase_device *kbdev) } EXPORT_SYMBOL(kbase_release_device); -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) #if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE && \ !(KERNEL_VERSION(4, 4, 28) <= LINUX_VERSION_CODE && \ KERNEL_VERSION(4, 5, 0) > LINUX_VERSION_CODE) @@ -605,7 +597,7 @@ static int kbase_file_create_kctx(struct kbase_file *const kfile, { struct kbase_device *kbdev = NULL; struct kbase_context *kctx = NULL; -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) char kctx_name[64]; #endif @@ -636,7 +628,7 @@ static int kbase_file_create_kctx(struct kbase_file *const kfile, if (kbdev->infinite_cache_active_default) kbase_ctx_flag_set(kctx, KCTX_INFINITE_CACHE); -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) snprintf(kctx_name, 64, "%d_%d", kctx->tgid, kctx->id); mutex_init(&kctx->mem_profile_lock); @@ -684,6 +676,13 @@ static int kbase_open(struct inode *inode, struct file *filp) if (!kbdev) return -ENODEV; + /* Device-wide firmware load is moved here from probing to comply with + * Android GKI vendor guideline. + */ + ret = kbase_device_firmware_init_once(kbdev); + if (ret) + goto out; + kfile = kbase_file_new(kbdev, filp); if (!kfile) { ret = -ENOMEM; @@ -695,7 +694,7 @@ static int kbase_open(struct inode *inode, struct file *filp) return 0; - out: +out: kbase_release_device(kbdev); return ret; } @@ -976,17 +975,6 @@ static int kbase_api_get_cpu_gpu_timeinfo(struct kbase_context *kctx, return 0; } -#ifdef CONFIG_MALI_BIFROST_NO_MALI -static int kbase_api_hwcnt_set(struct kbase_context *kctx, - struct kbase_ioctl_hwcnt_values *values) -{ - gpu_model_set_dummy_prfcnt_sample( - (u32 __user *)(uintptr_t)values->data, - values->size); - - return 0; -} -#endif static int kbase_api_disjoint_query(struct kbase_context *kctx, struct kbase_ioctl_disjoint_query *query) @@ -1382,6 +1370,14 @@ static int kbasep_cs_queue_register(struct kbase_context *kctx, return kbase_csf_queue_register(kctx, reg); } +static int kbasep_cs_queue_register_ex(struct kbase_context *kctx, + struct kbase_ioctl_cs_queue_register_ex *reg) +{ + kctx->jit_group_id = BASE_MEM_GROUP_DEFAULT; + + return kbase_csf_queue_register_ex(kctx, reg); +} + static int kbasep_cs_queue_terminate(struct kbase_context *kctx, struct kbase_ioctl_cs_queue_terminate *term) { @@ -1868,14 +1864,6 @@ static long kbase_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) union kbase_ioctl_get_cpu_gpu_timeinfo, kctx); break; -#ifdef CONFIG_MALI_BIFROST_NO_MALI - case KBASE_IOCTL_HWCNT_SET: - KBASE_HANDLE_IOCTL_IN(KBASE_IOCTL_HWCNT_SET, - kbase_api_hwcnt_set, - struct kbase_ioctl_hwcnt_values, - kctx); - break; -#endif #ifdef CONFIG_MALI_CINSTR_GWT case KBASE_IOCTL_CINSTR_GWT_START: KBASE_HANDLE_IOCTL(KBASE_IOCTL_CINSTR_GWT_START, @@ -1906,6 +1894,12 @@ static long kbase_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) struct kbase_ioctl_cs_queue_register, kctx); break; + case KBASE_IOCTL_CS_QUEUE_REGISTER_EX: + KBASE_HANDLE_IOCTL_IN(KBASE_IOCTL_CS_QUEUE_REGISTER_EX, + kbasep_cs_queue_register_ex, + struct kbase_ioctl_cs_queue_register_ex, + kctx); + break; case KBASE_IOCTL_CS_QUEUE_TERMINATE: KBASE_HANDLE_IOCTL_IN(KBASE_IOCTL_CS_QUEUE_TERMINATE, kbasep_cs_queue_terminate, @@ -2462,6 +2456,11 @@ static ssize_t set_core_mask(struct device *dev, struct device_attribute *attr, new_core_mask[i], i, group0_core_mask); err = -EINVAL; goto unlock; + } else if (!(new_core_mask[i] & kbdev->gpu_props.curr_config.shader_present)) { + dev_err(dev, "Invalid core mask 0x%llX for JS %d: No intersection with current core mask 0x%llX\n", + new_core_mask[i], i, kbdev->gpu_props.curr_config.shader_present); + err = -EINVAL; + goto unlock; } } @@ -2939,7 +2938,7 @@ static DEVICE_ATTR(js_softstop_always, S_IRUGO | S_IWUSR, show_js_softstop_alway #endif /* !MALI_USE_CSF */ #ifdef CONFIG_MALI_BIFROST_DEBUG -typedef void (kbasep_debug_command_func) (struct kbase_device *); +typedef void kbasep_debug_command_func(struct kbase_device *); enum kbasep_debug_command_code { KBASEP_DEBUG_COMMAND_DUMPTRACE, @@ -3092,9 +3091,13 @@ static ssize_t kbase_show_gpuinfo(struct device *dev, { .id = GPU_ID2_PRODUCT_TNAX >> GPU_ID_VERSION_PRODUCT_ID_SHIFT, .name = "Mali-G57" }, { .id = GPU_ID2_PRODUCT_TODX >> GPU_ID_VERSION_PRODUCT_ID_SHIFT, - .name = "Mali-TODX" }, + .name = "Mali-G710" }, { .id = GPU_ID2_PRODUCT_LODX >> GPU_ID_VERSION_PRODUCT_ID_SHIFT, - .name = "Mali-LODX" }, + .name = "Mali-G610" }, + { .id = GPU_ID2_PRODUCT_TGRX >> GPU_ID_VERSION_PRODUCT_ID_SHIFT, + .name = "Mali-G510" }, + { .id = GPU_ID2_PRODUCT_TVAX >> GPU_ID_VERSION_PRODUCT_ID_SHIFT, + .name = "Mali-G310" }, }; const char *product_name = "(Unknown Mali GPU)"; struct kbase_device *kbdev; @@ -3237,7 +3240,8 @@ static ssize_t set_pm_poweroff(struct device *dev, stt = &kbdev->pm.backend.shader_tick_timer; stt->configured_interval = HR_TIMER_DELAY_NSEC(gpu_poweroff_time); - stt->configured_ticks = poweroff_shader_ticks; + stt->default_ticks = poweroff_shader_ticks; + stt->configured_ticks = stt->default_ticks; spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags); @@ -3275,7 +3279,7 @@ static ssize_t show_pm_poweroff(struct device *dev, stt = &kbdev->pm.backend.shader_tick_timer; ret = scnprintf(buf, PAGE_SIZE, "%llu %u 0\n", ktime_to_ns(stt->configured_interval), - stt->configured_ticks); + stt->default_ticks); spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags); @@ -3929,7 +3933,7 @@ static ssize_t update_serialize_jobs_setting(struct kbase_device *kbdev, return count; } -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) /** * kbasep_serialize_jobs_seq_debugfs_show - Show callback for the serialize_jobs * debugfs file @@ -4183,15 +4187,6 @@ void kbase_protected_mode_term(struct kbase_device *kbdev) kfree(kbdev->protected_dev); } -#ifdef CONFIG_MALI_BIFROST_NO_MALI -static int kbase_common_reg_map(struct kbase_device *kbdev) -{ - return 0; -} -static void kbase_common_reg_unmap(struct kbase_device * const kbdev) -{ -} -#else /* CONFIG_MALI_BIFROST_NO_MALI */ static int kbase_common_reg_map(struct kbase_device *kbdev) { int err = 0; @@ -4227,7 +4222,6 @@ static void kbase_common_reg_unmap(struct kbase_device * const kbdev) kbdev->reg_size = 0; } } -#endif /* CONFIG_MALI_BIFROST_NO_MALI */ int registers_map(struct kbase_device * const kbdev) { @@ -4382,7 +4376,7 @@ int kbase_device_pm_init(struct kbase_device *kbdev) void kbase_device_pm_term(struct kbase_device *kbdev) { #ifdef CONFIG_MALI_ARBITER_SUPPORT -#ifdef CONFIG_OF +#if IS_ENABLED(CONFIG_OF) if (kbase_is_pv_enabled(kbdev->dev->of_node)) kbase_arbiter_pm_early_term(kbdev); else @@ -4551,7 +4545,7 @@ void power_control_term(struct kbase_device *kbdev) } #ifdef MALI_KBASE_BUILD -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) static void trigger_reset(struct kbase_device *kbdev) { @@ -4736,9 +4730,6 @@ int kbase_device_debugfs_init(struct kbase_device *kbdev) goto out; } -#if !MALI_CUSTOMER_RELEASE - kbasep_regs_dump_debugfs_init(kbdev); -#endif /* !MALI_CUSTOMER_RELEASE */ kbasep_regs_history_debugfs_init(kbdev); #if !MALI_USE_CSF @@ -4792,20 +4783,18 @@ int kbase_device_debugfs_init(struct kbase_device *kbdev) kbase_ktrace_debugfs_init(kbdev); #ifdef CONFIG_MALI_BIFROST_DEVFREQ -#ifdef CONFIG_DEVFREQ_THERMAL +#if IS_ENABLED(CONFIG_DEVFREQ_THERMAL) if (kbdev->devfreq && !kbdev->model_data) kbase_ipa_debugfs_init(kbdev); #endif /* CONFIG_DEVFREQ_THERMAL */ #endif /* CONFIG_MALI_BIFROST_DEVFREQ */ -#if MALI_USE_CSF - kbase_csf_debugfs_init(kbdev); -#else +#if !MALI_USE_CSF debugfs_create_file("serialize_jobs", S_IRUGO | S_IWUSR, kbdev->mali_debugfs_directory, kbdev, &kbasep_serialize_jobs_debugfs_fops); -#endif +#endif kbase_dvfs_status_debugfs_init(kbdev); return 0; @@ -4824,7 +4813,7 @@ void kbase_device_debugfs_term(struct kbase_device *kbdev) int kbase_device_coherency_init(struct kbase_device *kbdev) { -#ifdef CONFIG_OF +#if IS_ENABLED(CONFIG_OF) u32 supported_coherency_bitmap = kbdev->gpu_props.props.raw_props.coherency_mode; const void *coherency_override_dts; @@ -4851,7 +4840,7 @@ int kbase_device_coherency_init(struct kbase_device *kbdev) kbdev->system_coherency = COHERENCY_NONE; /* device tree may override the coherency */ -#ifdef CONFIG_OF +#if IS_ENABLED(CONFIG_OF) coherency_override_dts = of_get_property(kbdev->dev->of_node, "system-coherency", NULL); @@ -4859,7 +4848,7 @@ int kbase_device_coherency_init(struct kbase_device *kbdev) override_coherency = be32_to_cpup(coherency_override_dts); -#if MALI_USE_CSF && !defined(CONFIG_MALI_BIFROST_NO_MALI) +#if MALI_USE_CSF && !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) /* ACE coherency mode is not supported by Driver on CSF GPUs. * Return an error to signal the invalid device tree configuration. */ @@ -5415,7 +5404,7 @@ static const struct dev_pm_ops kbase_pm_ops = { #endif /* KBASE_PM_RUNTIME */ }; -#ifdef CONFIG_OF +#if IS_ENABLED(CONFIG_OF) static const struct of_device_id kbase_dt_ids[] = { { .compatible = "arm,mali-bifrost" }, { /* sentinel */ } @@ -5430,6 +5419,7 @@ static struct platform_driver kbase_platform_driver = { .name = kbase_drv_name, .pm = &kbase_pm_ops, .of_match_table = of_match_ptr(kbase_dt_ids), + .probe_type = PROBE_PREFER_ASYNCHRONOUS, }, }; @@ -5437,7 +5427,7 @@ static struct platform_driver kbase_platform_driver = { * The driver will not provide a shortcut to create the Mali platform device * anymore when using Device Tree. */ -#ifdef CONFIG_OF +#if IS_ENABLED(CONFIG_OF) module_platform_driver(kbase_platform_driver); #else diff --git a/drivers/gpu/arm/bifrost/mali_kbase_cs_experimental.h b/drivers/gpu/arm/bifrost/mali_kbase_cs_experimental.h index 67cd5ee1ece7..4dc09e4a7ed2 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_cs_experimental.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_cs_experimental.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_ctx_sched.c b/drivers/gpu/arm/bifrost/mali_kbase_ctx_sched.c index c63bc8dfa70a..d06380deca41 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_ctx_sched.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_ctx_sched.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2017-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2017-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_ctx_sched.h b/drivers/gpu/arm/bifrost/mali_kbase_ctx_sched.h index cadb73538a85..334724f60837 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_ctx_sched.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_ctx_sched.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2017-2018, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_debug.c b/drivers/gpu/arm/bifrost/mali_kbase_debug.c index 6caf56ca263e..6d3b1093b442 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_debug.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_debug.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2012-2014, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2012-2014, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_debug.h b/drivers/gpu/arm/bifrost/mali_kbase_debug.h index 87d3069d958b..5f04fca9618c 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_debug.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_debug.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2012-2015, 2017, 2020-2021 ARM Limited. All rights reserved. @@ -40,7 +40,7 @@ #endif /* KBASE_DEBUG_DISABLE_ASSERTS */ /** Function type that is called on an KBASE_DEBUG_ASSERT() or KBASE_DEBUG_ASSERT_MSG() */ -typedef void (kbase_debug_assert_hook) (void *); +typedef void kbase_debug_assert_hook(void *); struct kbasep_debug_assert_cb { kbase_debug_assert_hook *func; diff --git a/drivers/gpu/arm/bifrost/mali_kbase_debug_job_fault.c b/drivers/gpu/arm/bifrost/mali_kbase_debug_job_fault.c index 7dfdff1b1f18..4f021b316b83 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_debug_job_fault.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_debug_job_fault.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2012-2016, 2018-2021 ARM Limited. All rights reserved. @@ -23,7 +23,7 @@ #include #include -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) static bool kbase_is_job_fault_event_pending(struct kbase_device *kbdev) { diff --git a/drivers/gpu/arm/bifrost/mali_kbase_debug_job_fault.h b/drivers/gpu/arm/bifrost/mali_kbase_debug_job_fault.h index 63ccb3d86b23..39aeed08a20d 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_debug_job_fault.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_debug_job_fault.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2012-2016, 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2012-2016, 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_debug_mem_view.c b/drivers/gpu/arm/bifrost/mali_kbase_debug_mem_view.c index 9bdb76572df0..5a99b5e5c2d6 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_debug_mem_view.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_debug_mem_view.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2013-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2013-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -29,7 +29,7 @@ #include #include -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) struct debug_mem_mapping { struct list_head node; diff --git a/drivers/gpu/arm/bifrost/mali_kbase_debug_mem_view.h b/drivers/gpu/arm/bifrost/mali_kbase_debug_mem_view.h index c913d5ce36de..d03483219b08 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_debug_mem_view.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_debug_mem_view.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2013-2015, 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2013-2015, 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_debugfs_helper.c b/drivers/gpu/arm/bifrost/mali_kbase_debugfs_helper.c index 28df887b33dc..973739fe6143 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_debugfs_helper.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_debugfs_helper.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -45,10 +45,9 @@ * * Return: 0 if success, negative error code otherwise. */ -static int set_attr_from_string( - char *const buf, - void *const array, size_t const nelems, - kbase_debugfs_helper_set_attr_fn const set_attr_fn) +static int +set_attr_from_string(char *const buf, void *const array, size_t const nelems, + kbase_debugfs_helper_set_attr_fn *const set_attr_fn) { size_t index, err = 0; char *ptr = buf; @@ -144,7 +143,7 @@ int kbase_debugfs_string_validator(char *const buf) int kbase_debugfs_helper_set_attr_from_string( const char *const buf, void *const array, size_t const nelems, - kbase_debugfs_helper_set_attr_fn const set_attr_fn) + kbase_debugfs_helper_set_attr_fn *const set_attr_fn) { char *const wbuf = kstrdup(buf, GFP_KERNEL); int err = 0; @@ -167,9 +166,9 @@ int kbase_debugfs_helper_set_attr_from_string( } ssize_t kbase_debugfs_helper_get_attr_to_string( - char *const buf, size_t const size, - void *const array, size_t const nelems, - kbase_debugfs_helper_get_attr_fn const get_attr_fn) + char *const buf, size_t const size, void *const array, + size_t const nelems, + kbase_debugfs_helper_get_attr_fn *const get_attr_fn) { ssize_t total = 0; size_t index; @@ -187,10 +186,10 @@ ssize_t kbase_debugfs_helper_get_attr_to_string( return total; } -int kbase_debugfs_helper_seq_write(struct file *const file, - const char __user *const ubuf, size_t const count, - size_t const nelems, - kbase_debugfs_helper_set_attr_fn const set_attr_fn) +int kbase_debugfs_helper_seq_write( + struct file *const file, const char __user *const ubuf, + size_t const count, size_t const nelems, + kbase_debugfs_helper_set_attr_fn *const set_attr_fn) { const struct seq_file *const sfile = file->private_data; void *const array = sfile->private; @@ -228,9 +227,9 @@ int kbase_debugfs_helper_seq_write(struct file *const file, return err; } -int kbase_debugfs_helper_seq_read(struct seq_file *const sfile, - size_t const nelems, - kbase_debugfs_helper_get_attr_fn const get_attr_fn) +int kbase_debugfs_helper_seq_read( + struct seq_file *const sfile, size_t const nelems, + kbase_debugfs_helper_get_attr_fn *const get_attr_fn) { void *const array = sfile->private; size_t index; diff --git a/drivers/gpu/arm/bifrost/mali_kbase_debugfs_helper.h b/drivers/gpu/arm/bifrost/mali_kbase_debugfs_helper.h index 5fcbb15b23e2..4c69d8b6991f 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_debugfs_helper.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_debugfs_helper.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -30,8 +30,8 @@ * @index: An element index. The valid range depends on the use-case. * @value: Attribute value to be set. */ -typedef void (*kbase_debugfs_helper_set_attr_fn)( - void *array, size_t index, size_t value); +typedef void kbase_debugfs_helper_set_attr_fn(void *array, size_t index, + size_t value); /** * kbase_debugfs_helper_set_attr_from_string - Parse a string to reconfigure an @@ -55,7 +55,7 @@ typedef void (*kbase_debugfs_helper_set_attr_fn)( */ int kbase_debugfs_helper_set_attr_from_string( const char *buf, void *array, size_t nelems, - kbase_debugfs_helper_set_attr_fn set_attr_fn); + kbase_debugfs_helper_set_attr_fn *set_attr_fn); /** * kbase_debugfs_string_validator - Validate a string to be written to a @@ -89,8 +89,7 @@ int kbase_debugfs_string_validator(char *const buf); * * Return: Value of attribute. */ -typedef size_t (*kbase_debugfs_helper_get_attr_fn)( - void *array, size_t index); +typedef size_t kbase_debugfs_helper_get_attr_fn(void *array, size_t index); /** * kbase_debugfs_helper_get_attr_to_string - Construct a formatted string @@ -111,7 +110,7 @@ typedef size_t (*kbase_debugfs_helper_get_attr_fn)( */ ssize_t kbase_debugfs_helper_get_attr_to_string( char *buf, size_t size, void *array, size_t nelems, - kbase_debugfs_helper_get_attr_fn get_attr_fn); + kbase_debugfs_helper_get_attr_fn *get_attr_fn); /** * kbase_debugfs_helper_seq_read - Implements reads from a virtual file for an @@ -132,8 +131,8 @@ ssize_t kbase_debugfs_helper_get_attr_to_string( * Return: 0 if success, negative error code otherwise. */ int kbase_debugfs_helper_seq_read( - struct seq_file *const sfile, size_t const nelems, - kbase_debugfs_helper_get_attr_fn const get_attr_fn); + struct seq_file *sfile, size_t nelems, + kbase_debugfs_helper_get_attr_fn *get_attr_fn); /** * kbase_debugfs_helper_seq_write - Implements writes to a virtual file for an @@ -154,10 +153,10 @@ int kbase_debugfs_helper_seq_read( * * Return: 0 if success, negative error code otherwise. */ -int kbase_debugfs_helper_seq_write(struct file *const file, - const char __user *const ubuf, size_t const count, - size_t const nelems, - kbase_debugfs_helper_set_attr_fn const set_attr_fn); +int kbase_debugfs_helper_seq_write(struct file *file, + const char __user *ubuf, size_t count, + size_t nelems, + kbase_debugfs_helper_set_attr_fn *set_attr_fn); #endif /*_KBASE_DEBUGFS_HELPER_H_ */ diff --git a/drivers/gpu/arm/bifrost/mali_kbase_defs.h b/drivers/gpu/arm/bifrost/mali_kbase_defs.h index 6cff28c90566..ce0a247cb603 100755 --- a/drivers/gpu/arm/bifrost/mali_kbase_defs.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_defs.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2011-2021 ARM Limited. All rights reserved. @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #if MALI_USE_CSF @@ -55,7 +55,7 @@ #include "mali_kbase_fence_defs.h" #endif -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) #include #endif /* CONFIG_DEBUG_FS */ @@ -315,10 +315,9 @@ struct kbase_clk_rate_listener; * sleep. No clock rate manager functions must be called from here, as * its lock is taken. */ -typedef void (*kbase_clk_rate_listener_on_change_t)( - struct kbase_clk_rate_listener *listener, - u32 clk_index, - u32 clk_rate_hz); +typedef void +kbase_clk_rate_listener_on_change_t(struct kbase_clk_rate_listener *listener, + u32 clk_index, u32 clk_rate_hz); /** * struct kbase_clk_rate_listener - Clock frequency listener @@ -328,7 +327,7 @@ typedef void (*kbase_clk_rate_listener_on_change_t)( */ struct kbase_clk_rate_listener { struct list_head node; - kbase_clk_rate_listener_on_change_t notify; + kbase_clk_rate_listener_on_change_t *notify; }; /** @@ -673,6 +672,7 @@ struct kbase_process { * accesses made by the driver. * @pm: Per device object for storing data for power management * framework. + * @fw_load_lock: Mutex to protect firmware loading in @ref kbase_open. * @csf: CSF object for the GPU device. * @js_data: Per device object encapsulating the current context of * Job Scheduler, which is global to the device and is not @@ -911,8 +911,12 @@ struct kbase_process { * @dummy_job_wa.jc: dummy job workaround job * @dummy_job_wa.slot: dummy job workaround slot * @dummy_job_wa.flags: dummy job workaround flags + * @dummy_job_wa_loaded: Flag for indicating that the workaround blob has + * been loaded. Protected by @fw_load_lock. * @arb: Pointer to the arbiter device * @pcm_dev: The priority control manager device. + * @oom_notifier_block: notifier_block containing kernel-registered out-of- + * memory handler. */ struct kbase_device { u32 hw_quirks_sc; @@ -934,7 +938,7 @@ struct kbase_device { struct clk *clocks[BASE_MAX_NR_CLOCKS_REGULATORS]; unsigned int nr_clocks; -#ifdef CONFIG_REGULATOR +#if IS_ENABLED(CONFIG_REGULATOR) struct regulator *regulators[BASE_MAX_NR_CLOCKS_REGULATORS]; unsigned int nr_regulators; #if (KERNEL_VERSION(4, 10, 0) <= LINUX_VERSION_CODE) @@ -944,16 +948,6 @@ struct kbase_device { char devname[DEVNAME_SIZE]; u32 id; -#ifdef CONFIG_MALI_BIFROST_NO_MALI - void *model; - struct kmem_cache *irq_slab; - struct workqueue_struct *irq_workq; - atomic_t serving_job_irq; - atomic_t serving_gpu_irq; - atomic_t serving_mmu_irq; - spinlock_t reg_op_lock; -#endif /* CONFIG_MALI_BIFROST_NO_MALI */ - struct kbase_pm_device_data pm; struct kbase_mem_pool_group mem_pools; @@ -1032,7 +1026,7 @@ struct kbase_device { struct ipa_power_model_data *model_data; struct kbase_devfreq_queue_info devfreq_queue; -#ifdef CONFIG_DEVFREQ_THERMAL +#if IS_ENABLED(CONFIG_DEVFREQ_THERMAL) struct thermal_cooling_device *devfreq_cooling; bool ipa_protection_mode_switched; struct { @@ -1060,7 +1054,7 @@ struct kbase_device { atomic_t job_fault_debug; -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) struct dentry *mali_debugfs_directory; struct dentry *debugfs_ctx_directory; struct dentry *debugfs_instr_directory; @@ -1084,7 +1078,7 @@ struct kbase_device { atomic_t ctx_num; -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) struct kbase_io_history io_history; #endif /* CONFIG_DEBUG_FS */ @@ -1137,6 +1131,7 @@ struct kbase_device { bool l2_hash_values_override; u32 l2_hash_values[ASN_HASH_COUNT]; + struct mutex fw_load_lock; #if MALI_USE_CSF /* CSF object for the GPU device. */ struct kbase_csf_device csf; @@ -1168,12 +1163,15 @@ struct kbase_device { int slot; u64 flags; } dummy_job_wa; + bool dummy_job_wa_loaded; #ifdef CONFIG_MALI_ARBITER_SUPPORT struct kbase_arbiter_device arb; #endif /* Priority Control Manager device */ struct priority_control_manager_device *pcm_dev; + + struct notifier_block oom_notifier_block; }; /** @@ -1506,6 +1504,8 @@ struct kbase_reg_zone { * evictable/reclaimable. * @evict_list: List head for the list containing the allocations which * can be evicted or freed up in the shrinker callback. + * @evict_nents: Total number of pages allocated by the allocations within + * @evict_list (atomic). * @waiting_soft_jobs: List head for the list containing softjob atoms, which * are either waiting for the event set operation, or waiting * for the signaling of input fence or waiting for the GPU @@ -1673,6 +1673,7 @@ struct kbase_reg_zone { * contexts, for timeline summarization. * @limited_core_mask: The mask that is applied to the affinity in case of atoms * marked with BASE_JD_REQ_LIMITED_CORE_MASK. + * @platform_data: Pointer to platform specific per-context data. * * A kernel base context is an entity among which the GPU is scheduled. * Each context has its own GPU address space. @@ -1748,6 +1749,7 @@ struct kbase_context { struct shrinker reclaim; struct list_head evict_list; + atomic_t evict_nents; struct list_head waiting_soft_jobs; spinlock_t waiting_soft_jobs_lock; @@ -1767,7 +1769,7 @@ struct kbase_context { u64 gpu_va_end; bool jit_va; -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) char *mem_profile_data; size_t mem_profile_size; struct mutex mem_profile_lock; @@ -1821,6 +1823,10 @@ struct kbase_context { struct list_head tl_kctx_list_node; u64 limited_core_mask; + +#if !MALI_USE_CSF + void *platform_data; +#endif }; #ifdef CONFIG_MALI_CINSTR_GWT diff --git a/drivers/gpu/arm/bifrost/mali_kbase_disjoint_events.c b/drivers/gpu/arm/bifrost/mali_kbase_disjoint_events.c index 0b73f558ba06..7d6e475585ae 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_disjoint_events.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_disjoint_events.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2014, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_dma_fence.c b/drivers/gpu/arm/bifrost/mali_kbase_dma_fence.c index 3bf80ea9601a..378f0bad9a3d 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_dma_fence.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_dma_fence.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2011-2016, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2011-2016, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -247,7 +247,12 @@ kbase_dma_fence_add_reservation_callback(struct kbase_jd_atom *katom, unsigned int shared_count = 0; int err, i; - err = reservation_object_get_fences_rcu(resv, +#if (KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE) + err = reservation_object_get_fences_rcu( +#else + err = dma_resv_get_fences_rcu( +#endif + resv, &excl_fence, &shared_count, &shared_fences); @@ -365,7 +370,11 @@ int kbase_dma_fence_wait(struct kbase_jd_atom *katom, struct dma_resv *obj = info->resv_objs[i]; #endif if (!test_bit(i, info->dma_fence_excl_bitmap)) { +#if (KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE) err = reservation_object_reserve_shared(obj); +#else + err = dma_resv_reserve_shared(obj, 0); +#endif if (err) { dev_err(katom->kctx->kbdev->dev, "Error %d reserving space for shared fence.\n", err); @@ -379,7 +388,11 @@ int kbase_dma_fence_wait(struct kbase_jd_atom *katom, goto end; } +#if (KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE) reservation_object_add_shared_fence(obj, fence); +#else + dma_resv_add_shared_fence(obj, fence); +#endif } else { err = kbase_dma_fence_add_reservation_callback(katom, obj, true); if (err) { @@ -388,7 +401,11 @@ int kbase_dma_fence_wait(struct kbase_jd_atom *katom, goto end; } +#if (KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE) reservation_object_add_excl_fence(obj, fence); +#else + dma_resv_add_excl_fence(obj, fence); +#endif } } diff --git a/drivers/gpu/arm/bifrost/mali_kbase_dma_fence.h b/drivers/gpu/arm/bifrost/mali_kbase_dma_fence.h index bedc8c0c5907..dc413f413265 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_dma_fence.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_dma_fence.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2010-2016, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2010-2016, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -25,7 +25,12 @@ #ifdef CONFIG_MALI_BIFROST_DMA_FENCE #include +#include +#if (KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE) #include +#else +#include +#endif #include /* Forward declaration from mali_kbase_defs.h */ diff --git a/drivers/gpu/arm/bifrost/mali_kbase_dummy_job_wa.c b/drivers/gpu/arm/bifrost/mali_kbase_dummy_job_wa.c index e7a87812aafa..1e91ba0b2681 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_dummy_job_wa.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_dummy_job_wa.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -281,6 +281,8 @@ int kbase_dummy_job_wa_load(struct kbase_device *kbdev) int err; struct kbase_context *kctx; + lockdep_assert_held(&kbdev->fw_load_lock); + if (!wa_blob_load_needed(kbdev)) return 0; @@ -426,6 +428,10 @@ void kbase_dummy_job_wa_cleanup(struct kbase_device *kbdev) { struct kbase_context *wa_ctx; + /* return if the dummy job has not been loaded */ + if (kbdev->dummy_job_wa_loaded == false) + return; + /* Can be safely called even if the file wasn't created on probe */ sysfs_remove_file(&kbdev->dev->kobj, &dev_attr_dummy_job_wa_info.attr); diff --git a/drivers/gpu/arm/bifrost/mali_kbase_dummy_job_wa.h b/drivers/gpu/arm/bifrost/mali_kbase_dummy_job_wa.h index 4f3c2275ed44..8713ba1eaa6f 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_dummy_job_wa.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_dummy_job_wa.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_dvfs_debugfs.c b/drivers/gpu/arm/bifrost/mali_kbase_dvfs_debugfs.c index ce23ede7e512..1e584deb0e33 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_dvfs_debugfs.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_dvfs_debugfs.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -23,7 +23,7 @@ #include #include -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) /** * kbasep_dvfs_utilization_debugfs_show() - Print the DVFS utilization info diff --git a/drivers/gpu/arm/bifrost/mali_kbase_dvfs_debugfs.h b/drivers/gpu/arm/bifrost/mali_kbase_dvfs_debugfs.h index 080331f8bdf5..8334db7cc1ed 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_dvfs_debugfs.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_dvfs_debugfs.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_event.c b/drivers/gpu/arm/bifrost/mali_kbase_event.c index 25a379d9f0e1..910c51170ae8 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_event.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_event.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2010-2016,2018-2021 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2010-2016, 2018-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_fence.c b/drivers/gpu/arm/bifrost/mali_kbase_fence.c index d65b4ebf2535..01557cd3ba47 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_fence.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_fence.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2011-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2011-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_fence.h b/drivers/gpu/arm/bifrost/mali_kbase_fence.h index ff7dc8144a50..f46156ba7bb1 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_fence.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_fence.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2010-2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2010-2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_fence_defs.h b/drivers/gpu/arm/bifrost/mali_kbase_fence_defs.h index 006512d461f9..7a150bdf2947 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_fence_defs.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_fence_defs.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2010-2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2010-2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_fence_ops.c b/drivers/gpu/arm/bifrost/mali_kbase_fence_ops.c index 4712ef4f0606..14ddf0308317 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_fence_ops.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_fence_ops.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_gator.h b/drivers/gpu/arm/bifrost/mali_kbase_gator.h index 180beda91252..408ab865fcf8 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_gator.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_gator.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2011-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2011-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_gpu_memory_debugfs.c b/drivers/gpu/arm/bifrost/mali_kbase_gpu_memory_debugfs.c index a10b2bb8a416..cb372ea52aa5 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_gpu_memory_debugfs.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_gpu_memory_debugfs.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2012-2017, 2019-2021 ARM Limited. All rights reserved. @@ -22,7 +22,7 @@ #include #include -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) /** * kbasep_gpu_memory_seq_show - Show callback for the @c gpu_memory debugfs file * @sfile: The debugfs entry diff --git a/drivers/gpu/arm/bifrost/mali_kbase_gpu_memory_debugfs.h b/drivers/gpu/arm/bifrost/mali_kbase_gpu_memory_debugfs.h index 023703bf2e1e..6d5423f379d4 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_gpu_memory_debugfs.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_gpu_memory_debugfs.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2012-2014, 2016, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_gpuprops.c b/drivers/gpu/arm/bifrost/mali_kbase_gpuprops.c index 229188b0db9a..54cf98b4ce32 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_gpuprops.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_gpuprops.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2011-2021 ARM Limited. All rights reserved. @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include @@ -531,6 +531,14 @@ static int num_override_l2_hash_values; module_param_array(l2_hash_values, uint, &num_override_l2_hash_values, 0000); MODULE_PARM_DESC(l2_hash_values, "Override L2 hash values config for testing"); +/* Definitions for range of supported user defined hash functions for GPUs + * that support L2_CONFIG and not ASN_HASH features. Supported hash function + * range from 0b1000-0b1111 inclusive. Selection of any other values will + * lead to undefined behavior. + */ +#define USER_DEFINED_HASH_LO ((u8)0x08) +#define USER_DEFINED_HASH_HI ((u8)0x0F) + enum l2_config_override_result { L2_CONFIG_OVERRIDE_FAIL = -1, L2_CONFIG_OVERRIDE_NONE, @@ -562,7 +570,11 @@ kbase_read_l2_config_from_dt(struct kbase_device *const kbdev) else if (of_property_read_u8(np, "l2-size", &kbdev->l2_size_override)) kbdev->l2_size_override = 0; - if (override_l2_hash) + /* Check overriding value is supported, if not will result in + * undefined behavior. + */ + if (override_l2_hash >= USER_DEFINED_HASH_LO && + override_l2_hash <= USER_DEFINED_HASH_HI) kbdev->l2_hash_override = override_l2_hash; else if (of_property_read_u8(np, "l2-hash", &kbdev->l2_hash_override)) kbdev->l2_hash_override = 0; diff --git a/drivers/gpu/arm/bifrost/mali_kbase_gpuprops.h b/drivers/gpu/arm/bifrost/mali_kbase_gpuprops.h index 72f76c392fa1..b20b99b654a7 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_gpuprops.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_gpuprops.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2011-2015, 2017, 2019-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_gpuprops_types.h b/drivers/gpu/arm/bifrost/mali_kbase_gpuprops_types.h index 1d101e0a3e0c..b8411d37a4ed 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_gpuprops_types.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_gpuprops_types.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2011-2018, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_gwt.c b/drivers/gpu/arm/bifrost/mali_kbase_gwt.c index 93acf8a82b4f..2a20a3da4018 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_gwt.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_gwt.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2010-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_gwt.h b/drivers/gpu/arm/bifrost/mali_kbase_gwt.h index d85833442aa6..a55f9ccc644c 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_gwt.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_gwt.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2010-2017, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hw.c b/drivers/gpu/arm/bifrost/mali_kbase_hw.c index b1758d77aceb..7ad583cdba37 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hw.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_hw.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2012-2021 ARM Limited. All rights reserved. @@ -75,6 +75,12 @@ void kbase_hw_set_features_mask(struct kbase_device *kbdev) case GPU_ID2_PRODUCT_LODX: features = base_hw_features_tODx; break; + case GPU_ID2_PRODUCT_TGRX: + features = base_hw_features_tGRx; + break; + case GPU_ID2_PRODUCT_TVAX: + features = base_hw_features_tVAx; + break; default: features = base_hw_features_generic; break; @@ -211,6 +217,14 @@ static const enum base_hw_issue *kbase_hw_get_issues_for_new_id( { GPU_ID2_PRODUCT_LODX, { { GPU_ID2_VERSION_MAKE(0, 0, 0), base_hw_issues_tODx_r0p0 }, { U32_MAX, NULL } } }, + + { GPU_ID2_PRODUCT_TGRX, + { { GPU_ID2_VERSION_MAKE(0, 0, 0), base_hw_issues_tGRx_r0p0 }, + { U32_MAX, NULL } } }, + + { GPU_ID2_PRODUCT_TVAX, + { { GPU_ID2_VERSION_MAKE(0, 0, 0), base_hw_issues_tVAx_r0p0 }, + { U32_MAX, NULL } } }, }; u32 gpu_id = kbdev->gpu_props.props.raw_props.gpu_id; @@ -360,6 +374,12 @@ int kbase_hw_set_issues_mask(struct kbase_device *kbdev) case GPU_ID2_PRODUCT_LODX: issues = base_hw_issues_model_tODx; break; + case GPU_ID2_PRODUCT_TGRX: + issues = base_hw_issues_model_tGRx; + break; + case GPU_ID2_PRODUCT_TVAX: + issues = base_hw_issues_model_tVAx; + break; default: dev_err(kbdev->dev, "Unknown GPU ID %x", gpu_id); diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hw.h b/drivers/gpu/arm/bifrost/mali_kbase_hw.h index 65b417c95e13..6c04a237577c 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hw.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hw.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2012-2017, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_backend.h b/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_backend.h index 90851e2aa85f..0da4eb258a24 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_backend.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_backend.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014-2015, 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2015, 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_defs.h b/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_defs.h index 97a593fb6dbe..62a6ec51b17f 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_defs.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_defs.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2014, 2016-2018, 2020-2021 ARM Limited. All rights reserved. @@ -26,7 +26,7 @@ #ifndef _KBASE_HWACCESS_DEFS_H_ #define _KBASE_HWACCESS_DEFS_H_ -#include +#include /** * struct kbase_hwaccess_data - object encapsulating the GPU backend specific diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_gpuprops.h b/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_gpuprops.h index 0fca83e4eb2a..71ccc91e6b9d 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_gpuprops.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_gpuprops.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014-2015, 2018, 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2015, 2018, 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_instr.h b/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_instr.h index 959bfeb2096c..f8369536b1dc 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_instr.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_instr.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014-2015, 2017-2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2015, 2017-2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -26,7 +26,7 @@ #ifndef _KBASE_HWACCESS_INSTR_H_ #define _KBASE_HWACCESS_INSTR_H_ -#include +#include /** * struct kbase_instr_hwcnt_enable - Enable hardware counter collection. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_jm.h b/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_jm.h index 0e513c757094..8689647aaa8b 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_jm.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_jm.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_pm.h b/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_pm.h index 4b2a53e960e9..36bbe2d781ab 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_pm.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_pm.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2014-2015, 2018-2021 ARM Limited. All rights reserved. @@ -29,7 +29,7 @@ #include #include -#include +#include /* Forward definition - see mali_kbase.h */ struct kbase_device; diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_time.h b/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_time.h index 8488a321c2ee..8a4ece4417e0 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_time.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_time.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2014, 2018-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt.c b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt.c index 6bd7d5f69663..ea4893ddcf58 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_accumulator.h b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_accumulator.h index fbd13a442691..4887eaa19833 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_accumulator.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_accumulator.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend.h b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend.h index a3013a616579..0b5a188ecaeb 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2018, 2020-2021 ARM Limited. All rights reserved. @@ -56,8 +56,8 @@ struct kbase_hwcnt_backend; * * Return: Non-NULL pointer to immutable hardware counter metadata. */ -typedef const struct kbase_hwcnt_metadata *(*kbase_hwcnt_backend_metadata_fn)( - const struct kbase_hwcnt_backend_info *info); +typedef const struct kbase_hwcnt_metadata * +kbase_hwcnt_backend_metadata_fn(const struct kbase_hwcnt_backend_info *info); /** * typedef kbase_hwcnt_backend_init_fn - Initialise a counter backend. @@ -69,16 +69,15 @@ typedef const struct kbase_hwcnt_metadata *(*kbase_hwcnt_backend_metadata_fn)( * * Return: 0 on success, else error code. */ -typedef int (*kbase_hwcnt_backend_init_fn)( - const struct kbase_hwcnt_backend_info *info, - struct kbase_hwcnt_backend **out_backend); +typedef int +kbase_hwcnt_backend_init_fn(const struct kbase_hwcnt_backend_info *info, + struct kbase_hwcnt_backend **out_backend); /** * typedef kbase_hwcnt_backend_term_fn - Terminate a counter backend. * @backend: Pointer to backend to be terminated. */ -typedef void (*kbase_hwcnt_backend_term_fn)( - struct kbase_hwcnt_backend *backend); +typedef void kbase_hwcnt_backend_term_fn(struct kbase_hwcnt_backend *backend); /** * typedef kbase_hwcnt_backend_timestamp_ns_fn - Get the current backend @@ -87,8 +86,8 @@ typedef void (*kbase_hwcnt_backend_term_fn)( * * Return: Backend timestamp in nanoseconds. */ -typedef u64 (*kbase_hwcnt_backend_timestamp_ns_fn)( - struct kbase_hwcnt_backend *backend); +typedef u64 +kbase_hwcnt_backend_timestamp_ns_fn(struct kbase_hwcnt_backend *backend); /** * typedef kbase_hwcnt_backend_dump_enable_fn - Start counter dumping with the @@ -103,7 +102,7 @@ typedef u64 (*kbase_hwcnt_backend_timestamp_ns_fn)( * * Return: 0 on success, else error code. */ -typedef int (*kbase_hwcnt_backend_dump_enable_fn)( +typedef int kbase_hwcnt_backend_dump_enable_fn( struct kbase_hwcnt_backend *backend, const struct kbase_hwcnt_enable_map *enable_map); @@ -119,7 +118,7 @@ typedef int (*kbase_hwcnt_backend_dump_enable_fn)( * * Return: 0 on success, else error code. */ -typedef int (*kbase_hwcnt_backend_dump_enable_nolock_fn)( +typedef int kbase_hwcnt_backend_dump_enable_nolock_fn( struct kbase_hwcnt_backend *backend, const struct kbase_hwcnt_enable_map *enable_map); @@ -131,8 +130,8 @@ typedef int (*kbase_hwcnt_backend_dump_enable_nolock_fn)( * If the backend is already disabled, does nothing. * Any undumped counter values since the last dump get will be lost. */ -typedef void (*kbase_hwcnt_backend_dump_disable_fn)( - struct kbase_hwcnt_backend *backend); +typedef void +kbase_hwcnt_backend_dump_disable_fn(struct kbase_hwcnt_backend *backend); /** * typedef kbase_hwcnt_backend_dump_clear_fn - Reset all the current undumped @@ -143,8 +142,8 @@ typedef void (*kbase_hwcnt_backend_dump_disable_fn)( * * Return: 0 on success, else error code. */ -typedef int (*kbase_hwcnt_backend_dump_clear_fn)( - struct kbase_hwcnt_backend *backend); +typedef int +kbase_hwcnt_backend_dump_clear_fn(struct kbase_hwcnt_backend *backend); /** * typedef kbase_hwcnt_backend_dump_request_fn - Request an asynchronous counter @@ -158,9 +157,9 @@ typedef int (*kbase_hwcnt_backend_dump_clear_fn)( * * Return: 0 on success, else error code. */ -typedef int (*kbase_hwcnt_backend_dump_request_fn)( - struct kbase_hwcnt_backend *backend, - u64 *dump_time_ns); +typedef int +kbase_hwcnt_backend_dump_request_fn(struct kbase_hwcnt_backend *backend, + u64 *dump_time_ns); /** * typedef kbase_hwcnt_backend_dump_wait_fn - Wait until the last requested @@ -171,8 +170,8 @@ typedef int (*kbase_hwcnt_backend_dump_request_fn)( * * Return: 0 on success, else error code. */ -typedef int (*kbase_hwcnt_backend_dump_wait_fn)( - struct kbase_hwcnt_backend *backend); +typedef int +kbase_hwcnt_backend_dump_wait_fn(struct kbase_hwcnt_backend *backend); /** * typedef kbase_hwcnt_backend_dump_get_fn - Copy or accumulate enable the @@ -190,11 +189,11 @@ typedef int (*kbase_hwcnt_backend_dump_wait_fn)( * * Return: 0 on success, else error code. */ -typedef int (*kbase_hwcnt_backend_dump_get_fn)( - struct kbase_hwcnt_backend *backend, - struct kbase_hwcnt_dump_buffer *dump_buffer, - const struct kbase_hwcnt_enable_map *enable_map, - bool accumulate); +typedef int +kbase_hwcnt_backend_dump_get_fn(struct kbase_hwcnt_backend *backend, + struct kbase_hwcnt_dump_buffer *dump_buffer, + const struct kbase_hwcnt_enable_map *enable_map, + bool accumulate); /** * struct kbase_hwcnt_backend_interface - Hardware counter backend virtual @@ -218,17 +217,17 @@ typedef int (*kbase_hwcnt_backend_dump_get_fn)( */ struct kbase_hwcnt_backend_interface { const struct kbase_hwcnt_backend_info *info; - kbase_hwcnt_backend_metadata_fn metadata; - kbase_hwcnt_backend_init_fn init; - kbase_hwcnt_backend_term_fn term; - kbase_hwcnt_backend_timestamp_ns_fn timestamp_ns; - kbase_hwcnt_backend_dump_enable_fn dump_enable; - kbase_hwcnt_backend_dump_enable_nolock_fn dump_enable_nolock; - kbase_hwcnt_backend_dump_disable_fn dump_disable; - kbase_hwcnt_backend_dump_clear_fn dump_clear; - kbase_hwcnt_backend_dump_request_fn dump_request; - kbase_hwcnt_backend_dump_wait_fn dump_wait; - kbase_hwcnt_backend_dump_get_fn dump_get; + kbase_hwcnt_backend_metadata_fn *metadata; + kbase_hwcnt_backend_init_fn *init; + kbase_hwcnt_backend_term_fn *term; + kbase_hwcnt_backend_timestamp_ns_fn *timestamp_ns; + kbase_hwcnt_backend_dump_enable_fn *dump_enable; + kbase_hwcnt_backend_dump_enable_nolock_fn *dump_enable_nolock; + kbase_hwcnt_backend_dump_disable_fn *dump_disable; + kbase_hwcnt_backend_dump_clear_fn *dump_clear; + kbase_hwcnt_backend_dump_request_fn *dump_request; + kbase_hwcnt_backend_dump_wait_fn *dump_wait; + kbase_hwcnt_backend_dump_get_fn *dump_get; }; #endif /* _KBASE_HWCNT_BACKEND_H_ */ diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf.c b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf.c index d9592fd70529..eb9263f45cd8 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2021 ARM Limited. All rights reserved. @@ -228,7 +228,7 @@ struct kbase_hwcnt_backend_csf { struct work_struct hwc_threshold_work; }; -bool kbasep_hwcnt_backend_csf_backend_exists( +static bool kbasep_hwcnt_backend_csf_backend_exists( struct kbase_hwcnt_backend_csf_info *csf_info) { WARN_ON(!csf_info); @@ -347,8 +347,10 @@ static void kbasep_hwcnt_backend_csf_init_layout( phys_layout->shader_avail_mask = prfcnt_info->core_mask; phys_layout->headers_per_block = KBASE_HWCNT_V5_HEADERS_PER_BLOCK; - phys_layout->counters_per_block = KBASE_HWCNT_V5_COUNTERS_PER_BLOCK; - phys_layout->values_per_block = KBASE_HWCNT_V5_VALUES_PER_BLOCK; + phys_layout->values_per_block = + prfcnt_info->prfcnt_block_size / KBASE_HWCNT_VALUE_BYTES; + phys_layout->counters_per_block = + phys_layout->values_per_block - phys_layout->headers_per_block; phys_layout->offset_enable_mask = KBASE_HWCNT_V5_PRFCNT_EN_HEADER; } @@ -1783,6 +1785,9 @@ int kbase_hwcnt_backend_csf_metadata_init( gpu_info.l2_count = csf_info->prfcnt_info.l2_count; gpu_info.core_mask = csf_info->prfcnt_info.core_mask; gpu_info.clk_cnt = csf_info->prfcnt_info.clk_cnt; + gpu_info.prfcnt_values_per_block = + csf_info->prfcnt_info.prfcnt_block_size / + KBASE_HWCNT_VALUE_BYTES; errcode = kbase_hwcnt_csf_metadata_create( &gpu_info, csf_info->counter_set, &csf_info->metadata); if (errcode) diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf.h b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf.h index 75062744753a..ce1af9a3bf5f 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf_if.h b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf_if.h index b4ddd31d3cb0..f6387c2fcc2b 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf_if.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf_if.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2021 ARM Limited. All rights reserved. @@ -65,6 +65,7 @@ struct kbase_hwcnt_backend_csf_if_enable { * information. * @dump_bytes: Bytes of GPU memory required to perform a performance * counter dump. + * @prfcnt_block_size Bytes of each performance counter block. * @l2_count: The MMU L2 cache count. * @core_mask: Shader core mask. * @clk_cnt: Clock domain count in the system. @@ -73,6 +74,7 @@ struct kbase_hwcnt_backend_csf_if_enable { */ struct kbase_hwcnt_backend_csf_if_prfcnt_info { size_t dump_bytes; + size_t prfcnt_block_size; size_t l2_count; u64 core_mask; u8 clk_cnt; @@ -85,7 +87,7 @@ struct kbase_hwcnt_backend_csf_if_prfcnt_info { * held. * @ctx: Non-NULL pointer to a CSF context. */ -typedef void (*kbase_hwcnt_backend_csf_if_assert_lock_held_fn)( +typedef void kbase_hwcnt_backend_csf_if_assert_lock_held_fn( struct kbase_hwcnt_backend_csf_if_ctx *ctx); /** @@ -95,8 +97,9 @@ typedef void (*kbase_hwcnt_backend_csf_if_assert_lock_held_fn)( * @flags: Pointer to the memory location that would store the previous * interrupt state. */ -typedef void (*kbase_hwcnt_backend_csf_if_lock_fn)( - struct kbase_hwcnt_backend_csf_if_ctx *ctx, unsigned long *flags); +typedef void +kbase_hwcnt_backend_csf_if_lock_fn(struct kbase_hwcnt_backend_csf_if_ctx *ctx, + unsigned long *flags); /** * typedef kbase_hwcnt_backend_csf_if_unlock_fn - Release backend spinlock. @@ -105,8 +108,9 @@ typedef void (*kbase_hwcnt_backend_csf_if_lock_fn)( * @flags: Previously stored interrupt state when Scheduler interrupt * spinlock was acquired. */ -typedef void (*kbase_hwcnt_backend_csf_if_unlock_fn)( - struct kbase_hwcnt_backend_csf_if_ctx *ctx, unsigned long flags); +typedef void +kbase_hwcnt_backend_csf_if_unlock_fn(struct kbase_hwcnt_backend_csf_if_ctx *ctx, + unsigned long flags); /** * typedef kbase_hwcnt_backend_csf_if_get_prfcnt_info_fn - Get performance @@ -115,7 +119,7 @@ typedef void (*kbase_hwcnt_backend_csf_if_unlock_fn)( * @prfcnt_info: Non-NULL pointer to struct where performance counter * information should be stored. */ -typedef void (*kbase_hwcnt_backend_csf_if_get_prfcnt_info_fn)( +typedef void kbase_hwcnt_backend_csf_if_get_prfcnt_info_fn( struct kbase_hwcnt_backend_csf_if_ctx *ctx, struct kbase_hwcnt_backend_csf_if_prfcnt_info *prfcnt_info); @@ -135,7 +139,7 @@ typedef void (*kbase_hwcnt_backend_csf_if_get_prfcnt_info_fn)( * * Return: 0 on success, else error code. */ -typedef int (*kbase_hwcnt_backend_csf_if_ring_buf_alloc_fn)( +typedef int kbase_hwcnt_backend_csf_if_ring_buf_alloc_fn( struct kbase_hwcnt_backend_csf_if_ctx *ctx, u32 buf_count, void **cpu_dump_base, struct kbase_hwcnt_backend_csf_if_ring_buf **ring_buf); @@ -157,7 +161,7 @@ typedef int (*kbase_hwcnt_backend_csf_if_ring_buf_alloc_fn)( * Flush cached HWC dump buffer data to ensure that all writes from GPU and CPU * are correctly observed. */ -typedef void (*kbase_hwcnt_backend_csf_if_ring_buf_sync_fn)( +typedef void kbase_hwcnt_backend_csf_if_ring_buf_sync_fn( struct kbase_hwcnt_backend_csf_if_ctx *ctx, struct kbase_hwcnt_backend_csf_if_ring_buf *ring_buf, u32 buf_index_first, u32 buf_index_last, bool for_cpu); @@ -169,7 +173,7 @@ typedef void (*kbase_hwcnt_backend_csf_if_ring_buf_sync_fn)( * @ctx: Non-NULL pointer to a CSF interface context. * @ring_buf: Non-NULL pointer to the ring buffer which to be freed. */ -typedef void (*kbase_hwcnt_backend_csf_if_ring_buf_free_fn)( +typedef void kbase_hwcnt_backend_csf_if_ring_buf_free_fn( struct kbase_hwcnt_backend_csf_if_ctx *ctx, struct kbase_hwcnt_backend_csf_if_ring_buf *ring_buf); @@ -181,7 +185,7 @@ typedef void (*kbase_hwcnt_backend_csf_if_ring_buf_free_fn)( * * Return: CSF interface timestamp in nanoseconds. */ -typedef u64 (*kbase_hwcnt_backend_csf_if_timestamp_ns_fn)( +typedef u64 kbase_hwcnt_backend_csf_if_timestamp_ns_fn( struct kbase_hwcnt_backend_csf_if_ctx *ctx); /** @@ -193,7 +197,7 @@ typedef u64 (*kbase_hwcnt_backend_csf_if_timestamp_ns_fn)( * * Requires lock to be taken before calling. */ -typedef void (*kbase_hwcnt_backend_csf_if_dump_enable_fn)( +typedef void kbase_hwcnt_backend_csf_if_dump_enable_fn( struct kbase_hwcnt_backend_csf_if_ctx *ctx, struct kbase_hwcnt_backend_csf_if_ring_buf *ring_buf, struct kbase_hwcnt_backend_csf_if_enable *enable); @@ -205,7 +209,7 @@ typedef void (*kbase_hwcnt_backend_csf_if_dump_enable_fn)( * * Requires lock to be taken before calling. */ -typedef void (*kbase_hwcnt_backend_csf_if_dump_disable_fn)( +typedef void kbase_hwcnt_backend_csf_if_dump_disable_fn( struct kbase_hwcnt_backend_csf_if_ctx *ctx); /** @@ -215,7 +219,7 @@ typedef void (*kbase_hwcnt_backend_csf_if_dump_disable_fn)( * * Requires lock to be taken before calling. */ -typedef void (*kbase_hwcnt_backend_csf_if_dump_request_fn)( +typedef void kbase_hwcnt_backend_csf_if_dump_request_fn( struct kbase_hwcnt_backend_csf_if_ctx *ctx); /** @@ -229,7 +233,7 @@ typedef void (*kbase_hwcnt_backend_csf_if_dump_request_fn)( * * Requires lock to be taken before calling. */ -typedef void (*kbase_hwcnt_backend_csf_if_get_indexes_fn)( +typedef void kbase_hwcnt_backend_csf_if_get_indexes_fn( struct kbase_hwcnt_backend_csf_if_ctx *ctx, u32 *extract_index, u32 *insert_index); @@ -243,7 +247,7 @@ typedef void (*kbase_hwcnt_backend_csf_if_get_indexes_fn)( * * Requires lock to be taken before calling. */ -typedef void (*kbase_hwcnt_backend_csf_if_set_extract_index_fn)( +typedef void kbase_hwcnt_backend_csf_if_set_extract_index_fn( struct kbase_hwcnt_backend_csf_if_ctx *ctx, u32 extract_index); /** @@ -258,7 +262,7 @@ typedef void (*kbase_hwcnt_backend_csf_if_set_extract_index_fn)( * * Requires lock to be taken before calling. */ -typedef void (*kbase_hwcnt_backend_csf_if_get_gpu_cycle_count_fn)( +typedef void kbase_hwcnt_backend_csf_if_get_gpu_cycle_count_fn( struct kbase_hwcnt_backend_csf_if_ctx *ctx, u64 *cycle_counts, u64 clk_enable_map); @@ -288,20 +292,20 @@ typedef void (*kbase_hwcnt_backend_csf_if_get_gpu_cycle_count_fn)( */ struct kbase_hwcnt_backend_csf_if { struct kbase_hwcnt_backend_csf_if_ctx *ctx; - kbase_hwcnt_backend_csf_if_assert_lock_held_fn assert_lock_held; - kbase_hwcnt_backend_csf_if_lock_fn lock; - kbase_hwcnt_backend_csf_if_unlock_fn unlock; - kbase_hwcnt_backend_csf_if_get_prfcnt_info_fn get_prfcnt_info; - kbase_hwcnt_backend_csf_if_ring_buf_alloc_fn ring_buf_alloc; - kbase_hwcnt_backend_csf_if_ring_buf_sync_fn ring_buf_sync; - kbase_hwcnt_backend_csf_if_ring_buf_free_fn ring_buf_free; - kbase_hwcnt_backend_csf_if_timestamp_ns_fn timestamp_ns; - kbase_hwcnt_backend_csf_if_dump_enable_fn dump_enable; - kbase_hwcnt_backend_csf_if_dump_disable_fn dump_disable; - kbase_hwcnt_backend_csf_if_dump_request_fn dump_request; - kbase_hwcnt_backend_csf_if_get_indexes_fn get_indexes; - kbase_hwcnt_backend_csf_if_set_extract_index_fn set_extract_index; - kbase_hwcnt_backend_csf_if_get_gpu_cycle_count_fn get_gpu_cycle_count; + kbase_hwcnt_backend_csf_if_assert_lock_held_fn *assert_lock_held; + kbase_hwcnt_backend_csf_if_lock_fn *lock; + kbase_hwcnt_backend_csf_if_unlock_fn *unlock; + kbase_hwcnt_backend_csf_if_get_prfcnt_info_fn *get_prfcnt_info; + kbase_hwcnt_backend_csf_if_ring_buf_alloc_fn *ring_buf_alloc; + kbase_hwcnt_backend_csf_if_ring_buf_sync_fn *ring_buf_sync; + kbase_hwcnt_backend_csf_if_ring_buf_free_fn *ring_buf_free; + kbase_hwcnt_backend_csf_if_timestamp_ns_fn *timestamp_ns; + kbase_hwcnt_backend_csf_if_dump_enable_fn *dump_enable; + kbase_hwcnt_backend_csf_if_dump_disable_fn *dump_disable; + kbase_hwcnt_backend_csf_if_dump_request_fn *dump_request; + kbase_hwcnt_backend_csf_if_get_indexes_fn *get_indexes; + kbase_hwcnt_backend_csf_if_set_extract_index_fn *set_extract_index; + kbase_hwcnt_backend_csf_if_get_gpu_cycle_count_fn *get_gpu_cycle_count; }; #endif /* #define _KBASE_HWCNT_BACKEND_CSF_IF_H_ */ diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf_if_fw.c b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf_if_fw.c index 35f1225acaae..83ae231f523c 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf_if_fw.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf_if_fw.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2021 ARM Limited. All rights reserved. @@ -37,9 +37,7 @@ #include #include "mali_kbase_ccswe.h" -#ifdef CONFIG_MALI_BIFROST_NO_MALI -#include -#endif + /** The number of nanoseconds in a second. */ #define NSECS_IN_SEC 1000000000ull /* ns */ @@ -76,6 +74,7 @@ struct kbase_hwcnt_backend_csf_if_fw_ring_buf { * @buf_bytes: The size in bytes for each buffer in the ring buffer. * @clk_cnt: The number of clock domains in the system. * The maximum is 64. + * @clk_enable_map: Bitmask of enabled clocks * @rate_listener: Clock rate listener callback state. * @ccswe_shader_cores: Shader cores cycle count software estimator. */ @@ -160,8 +159,8 @@ static void kbasep_hwcnt_backend_csf_if_fw_on_freq_change( /** * kbasep_hwcnt_backend_csf_if_fw_cc_enable() - Enable cycle count tracking * - * @fw_ctx: Non-NULL pointer to CSF firmware interface context. - * @enable_map: Non-NULL pointer to enable map specifying enabled counters. + * @fw_ctx: Non-NULL pointer to CSF firmware interface context. + * @clk_enable_map: Non-NULL pointer to enable map specifying enabled counters. */ static void kbasep_hwcnt_backend_csf_if_fw_cc_enable( struct kbase_hwcnt_backend_csf_if_fw_ctx *fw_ctx, u64 clk_enable_map) @@ -218,20 +217,13 @@ static void kbasep_hwcnt_backend_csf_if_fw_get_prfcnt_info( struct kbase_hwcnt_backend_csf_if_ctx *ctx, struct kbase_hwcnt_backend_csf_if_prfcnt_info *prfcnt_info) { -#ifdef CONFIG_MALI_BIFROST_NO_MALI - prfcnt_info->l2_count = KBASE_DUMMY_MODEL_MAX_MEMSYS_BLOCKS; - prfcnt_info->core_mask = - (1ull << KBASE_DUMMY_MODEL_MAX_SHADER_CORES) - 1; - prfcnt_info->dump_bytes = KBASE_DUMMY_MODEL_MAX_NUM_PERF_BLOCKS * - KBASE_DUMMY_MODEL_BLOCK_SIZE; - prfcnt_info->clk_cnt = 1; - prfcnt_info->clearing_samples = false; -#else struct kbase_hwcnt_backend_csf_if_fw_ctx *fw_ctx; struct kbase_device *kbdev; u32 prfcnt_size; u32 prfcnt_hw_size = 0; u32 prfcnt_fw_size = 0; + u32 prfcnt_block_size = KBASE_HWCNT_V5_DEFAULT_VALUES_PER_BLOCK * + KBASE_HWCNT_VALUE_BYTES; WARN_ON(!ctx); WARN_ON(!prfcnt_info); @@ -242,15 +234,23 @@ static void kbasep_hwcnt_backend_csf_if_fw_get_prfcnt_info( prfcnt_hw_size = (prfcnt_size & 0xFF) << 8; prfcnt_fw_size = (prfcnt_size >> 16) << 8; fw_ctx->buf_bytes = prfcnt_hw_size + prfcnt_fw_size; - prfcnt_info->dump_bytes = fw_ctx->buf_bytes; + + prfcnt_info->dump_bytes = fw_ctx->buf_bytes; + prfcnt_info->prfcnt_block_size = prfcnt_block_size; prfcnt_info->l2_count = kbdev->gpu_props.props.l2_props.num_l2_slices; prfcnt_info->core_mask = kbdev->gpu_props.props.coherency_info.group[0].core_mask; prfcnt_info->clk_cnt = fw_ctx->clk_cnt; prfcnt_info->clearing_samples = true; -#endif + + /* Block size must be multiple of counter size. */ + WARN_ON((prfcnt_info->prfcnt_block_size % KBASE_HWCNT_VALUE_BYTES) != + 0); + /* Total size must be multiple of block size. */ + WARN_ON((prfcnt_info->dump_bytes % prfcnt_info->prfcnt_block_size) != + 0); } static int kbasep_hwcnt_backend_csf_if_fw_ring_buf_alloc( @@ -339,6 +339,7 @@ static int kbasep_hwcnt_backend_csf_if_fw_ring_buf_alloc( *out_ring_buf = (struct kbase_hwcnt_backend_csf_if_ring_buf *)fw_ring_buf; + return 0; mmu_insert_failed: @@ -682,9 +683,9 @@ static void kbasep_hwcnt_backend_csf_if_fw_get_gpu_cycle_count( } /** - * @brief Destroy a CSF FW interface context. + * kbasep_hwcnt_backedn_csf_if_fw_cts_destroy() - Destroy a CSF FW interface context. * - * @param[in,out] fw_ctx Pointer to context to destroy. + * @fw_ctx: Pointer to context to destroy. */ static void kbasep_hwcnt_backend_csf_if_fw_ctx_destroy( struct kbase_hwcnt_backend_csf_if_fw_ctx *fw_ctx) diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf_if_fw.h b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf_if_fw.h index f55efb6e896b..b69668b2e822 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf_if_fw.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_csf_if_fw.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_jm.c b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_jm.c index ffacaeb0a748..8e6b25936362 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_jm.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_jm.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. @@ -23,14 +23,11 @@ #include "mali_kbase_hwcnt_gpu.h" #include "mali_kbase_hwcnt_types.h" #include "mali_kbase.h" -#include "mali_kbase_pm_ca.h" +#include "backend/gpu/mali_kbase_pm_ca.h" #include "mali_kbase_hwaccess_instr.h" #include "mali_kbase_hwaccess_time.h" #include "mali_kbase_ccswe.h" -#ifdef CONFIG_MALI_BIFROST_NO_MALI -#include "backend/gpu/mali_kbase_model_dummy.h" -#endif #include "backend/gpu/mali_kbase_clk_rate_trace_mgr.h" #include "backend/gpu/mali_kbase_pm_internal.h" @@ -108,10 +105,6 @@ kbasep_hwcnt_backend_jm_gpu_info_init(struct kbase_device *kbdev, if (!kbdev || !info) return -EINVAL; -#ifdef CONFIG_MALI_BIFROST_NO_MALI - info->l2_count = KBASE_DUMMY_MODEL_MAX_MEMSYS_BLOCKS; - info->core_mask = (1ull << KBASE_DUMMY_MODEL_MAX_SHADER_CORES) - 1; -#else /* CONFIG_MALI_BIFROST_NO_MALI */ { const struct base_gpu_props *props = &kbdev->gpu_props.props; const size_t l2_count = props->l2_props.num_l2_slices; @@ -120,8 +113,9 @@ kbasep_hwcnt_backend_jm_gpu_info_init(struct kbase_device *kbdev, info->l2_count = l2_count; info->core_mask = core_mask; + info->prfcnt_values_per_block = + KBASE_HWCNT_V5_DEFAULT_VALUES_PER_BLOCK; } -#endif /* CONFIG_MALI_BIFROST_NO_MALI */ /* Determine the number of available clock domains. */ for (clk = 0; clk < BASE_MAX_NR_CLOCKS_REGULATORS; clk++) { @@ -483,11 +477,6 @@ static int kbasep_hwcnt_backend_jm_dump_get( struct kbase_hwcnt_backend_jm *backend_jm = (struct kbase_hwcnt_backend_jm *)backend; size_t clk; -#ifdef CONFIG_MALI_BIFROST_NO_MALI - struct kbase_device *kbdev; - unsigned long flags; - int errcode; -#endif if (!backend_jm || !dst || !dst_enable_map || (backend_jm->info->metadata != dst->metadata) || @@ -507,21 +496,6 @@ static int kbasep_hwcnt_backend_jm_dump_get( dst->clk_cnt_buf[clk] = backend_jm->cycle_count_elapsed[clk]; } -#ifdef CONFIG_MALI_BIFROST_NO_MALI - kbdev = backend_jm->kctx->kbdev; - - spin_lock_irqsave(&kbdev->hwaccess_lock, flags); - - /* Update the current configuration information. */ - errcode = kbasep_hwcnt_gpu_update_curr_config(kbdev, - &backend_jm->curr_config); - - spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags); - - if (errcode) - return errcode; -#endif - return kbase_hwcnt_jm_dump_get(dst, backend_jm->cpu_dump_va, dst_enable_map, backend_jm->pm_core_mask, &backend_jm->curr_config, accumulate); @@ -655,10 +629,6 @@ static int kbasep_hwcnt_backend_jm_create( kbase_ccswe_init(&backend->ccswe_shader_cores); backend->rate_listener.notify = kbasep_hwcnt_backend_jm_on_freq_change; -#ifdef CONFIG_MALI_BIFROST_NO_MALI - /* The dummy model needs the CPU mapping. */ - gpu_model_set_dummy_prfcnt_base_cpu(backend->cpu_dump_va); -#endif *out_backend = backend; return 0; diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_jm.h b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_jm.h index 5d1947ea4021..531951611ec4 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_jm.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_backend_jm.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_context.h b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_context.h index 403b1c5ff149..1adf2ef9e8dd 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_context.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_context.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_gpu.c b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_gpu.c index 4fba6b6d33c2..2975269b6ee4 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_gpu.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_gpu.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. @@ -25,13 +25,6 @@ #include #include -#define KBASE_HWCNT_V5_BLOCK_TYPE_COUNT 4 -#define KBASE_HWCNT_V5_HEADERS_PER_BLOCK 4 -#define KBASE_HWCNT_V5_COUNTERS_PER_BLOCK 60 -#define KBASE_HWCNT_V5_VALUES_PER_BLOCK \ - (KBASE_HWCNT_V5_HEADERS_PER_BLOCK + KBASE_HWCNT_V5_COUNTERS_PER_BLOCK) -/* Index of the PRFCNT_EN header into a V5 counter block */ -#define KBASE_HWCNT_V5_PRFCNT_EN_HEADER 2 static void kbasep_get_fe_block_type(u64 *dst, enum kbase_hwcnt_set counter_set, bool is_csf) @@ -160,19 +153,22 @@ static int kbasep_hwcnt_backend_gpu_metadata_create( kbasep_get_fe_block_type(&blks[0].type, counter_set, is_csf); blks[0].inst_cnt = 1; blks[0].hdr_cnt = KBASE_HWCNT_V5_HEADERS_PER_BLOCK; - blks[0].ctr_cnt = KBASE_HWCNT_V5_COUNTERS_PER_BLOCK; + blks[0].ctr_cnt = gpu_info->prfcnt_values_per_block - + KBASE_HWCNT_V5_HEADERS_PER_BLOCK; /* One Tiler block */ kbasep_get_tiler_block_type(&blks[1].type, counter_set); blks[1].inst_cnt = 1; blks[1].hdr_cnt = KBASE_HWCNT_V5_HEADERS_PER_BLOCK; - blks[1].ctr_cnt = KBASE_HWCNT_V5_COUNTERS_PER_BLOCK; + blks[1].ctr_cnt = gpu_info->prfcnt_values_per_block - + KBASE_HWCNT_V5_HEADERS_PER_BLOCK; /* l2_count memsys blks */ kbasep_get_memsys_block_type(&blks[2].type, counter_set); blks[2].inst_cnt = gpu_info->l2_count; blks[2].hdr_cnt = KBASE_HWCNT_V5_HEADERS_PER_BLOCK; - blks[2].ctr_cnt = KBASE_HWCNT_V5_COUNTERS_PER_BLOCK; + blks[2].ctr_cnt = gpu_info->prfcnt_values_per_block - + KBASE_HWCNT_V5_HEADERS_PER_BLOCK; /* * There are as many shader cores in the system as there are bits set in @@ -193,7 +189,8 @@ static int kbasep_hwcnt_backend_gpu_metadata_create( kbasep_get_sc_block_type(&blks[3].type, counter_set, is_csf); blks[3].inst_cnt = sc_block_count; blks[3].hdr_cnt = KBASE_HWCNT_V5_HEADERS_PER_BLOCK; - blks[3].ctr_cnt = KBASE_HWCNT_V5_COUNTERS_PER_BLOCK; + blks[3].ctr_cnt = gpu_info->prfcnt_values_per_block - + KBASE_HWCNT_V5_HEADERS_PER_BLOCK; WARN_ON(KBASE_HWCNT_V5_BLOCK_TYPE_COUNT != 4); @@ -226,7 +223,7 @@ kbasep_hwcnt_backend_jm_dump_bytes(const struct kbase_hwcnt_gpu_info *gpu_info) WARN_ON(!gpu_info); return (2 + gpu_info->l2_count + fls64(gpu_info->core_mask)) * - KBASE_HWCNT_V5_VALUES_PER_BLOCK * KBASE_HWCNT_VALUE_BYTES; + gpu_info->prfcnt_values_per_block * KBASE_HWCNT_VALUE_BYTES; } int kbase_hwcnt_jm_metadata_create( @@ -305,6 +302,127 @@ void kbase_hwcnt_csf_metadata_destroy( kbase_hwcnt_metadata_destroy(metadata); } +int kbase_hwcnt_gpu_metadata_create_truncate_64( + const struct kbase_hwcnt_metadata **dst_md, + const struct kbase_hwcnt_metadata *src_md) +{ + struct kbase_hwcnt_description desc; + struct kbase_hwcnt_group_description group; + struct kbase_hwcnt_block_description + blks[KBASE_HWCNT_V5_BLOCK_TYPE_COUNT]; + size_t prfcnt_values_per_block; + size_t blk; + + if (!dst_md || !src_md || !src_md->grp_metadata || + !src_md->grp_metadata[0].blk_metadata) + return -EINVAL; + + /* Only support 1 group count and KBASE_HWCNT_V5_BLOCK_TYPE_COUNT block + * count in the metadata. + */ + if ((kbase_hwcnt_metadata_group_count(src_md) != 1) || + (kbase_hwcnt_metadata_block_count(src_md, 0) != + KBASE_HWCNT_V5_BLOCK_TYPE_COUNT)) + return -EINVAL; + + /* Get the values count in the first block. */ + prfcnt_values_per_block = + kbase_hwcnt_metadata_block_values_count(src_md, 0, 0); + + /* check all blocks should have same values count. */ + for (blk = 0; blk < KBASE_HWCNT_V5_BLOCK_TYPE_COUNT; blk++) { + size_t val_cnt = + kbase_hwcnt_metadata_block_values_count(src_md, 0, blk); + if (val_cnt != prfcnt_values_per_block) + return -EINVAL; + } + + /* Only support 64 and 128 entries per block. */ + if ((prfcnt_values_per_block != 64) && (prfcnt_values_per_block != 128)) + return -EINVAL; + + if (prfcnt_values_per_block == 64) { + /* If the values per block is 64, no need to truncate. */ + *dst_md = NULL; + return 0; + } + + /* Truncate from 128 to 64 entries per block to keep API backward + * compatibility. + */ + prfcnt_values_per_block = 64; + + for (blk = 0; blk < KBASE_HWCNT_V5_BLOCK_TYPE_COUNT; blk++) { + blks[blk].type = + kbase_hwcnt_metadata_block_type(src_md, 0, blk); + blks[blk].inst_cnt = kbase_hwcnt_metadata_block_instance_count( + src_md, 0, blk); + blks[blk].hdr_cnt = kbase_hwcnt_metadata_block_headers_count( + src_md, 0, blk); + blks[blk].ctr_cnt = prfcnt_values_per_block - blks[blk].hdr_cnt; + } + + group.type = kbase_hwcnt_metadata_group_type(src_md, 0); + group.blk_cnt = KBASE_HWCNT_V5_BLOCK_TYPE_COUNT; + group.blks = blks; + + desc.grp_cnt = kbase_hwcnt_metadata_group_count(src_md); + desc.avail_mask = src_md->avail_mask; + desc.clk_cnt = src_md->clk_cnt; + desc.grps = &group; + + return kbase_hwcnt_metadata_create(&desc, dst_md); +} + +void kbase_hwcnt_dump_buffer_copy_strict_narrow( + struct kbase_hwcnt_dump_buffer *dst, + const struct kbase_hwcnt_dump_buffer *src, + const struct kbase_hwcnt_enable_map *dst_enable_map) +{ + const struct kbase_hwcnt_metadata *metadata; + size_t grp, blk, blk_inst; + size_t clk; + + if (WARN_ON(!dst) || WARN_ON(!src) || WARN_ON(!dst_enable_map) || + WARN_ON(dst == src) || WARN_ON(dst->metadata == src->metadata) || + WARN_ON(dst->metadata->grp_cnt != src->metadata->grp_cnt) || + WARN_ON(src->metadata->grp_cnt != 1) || + WARN_ON(dst->metadata->grp_metadata[0].blk_cnt != + src->metadata->grp_metadata[0].blk_cnt) || + WARN_ON(dst->metadata->grp_metadata[0].blk_cnt != 4) || + WARN_ON(dst->metadata->grp_metadata[0].blk_metadata[0].ctr_cnt > + src->metadata->grp_metadata[0].blk_metadata[0].ctr_cnt)) + return; + + /* Don't use src metadata since src buffer is bigger than dst buffer. */ + metadata = dst->metadata; + + kbase_hwcnt_metadata_for_each_block(metadata, grp, blk, blk_inst) { + u32 *dst_blk = kbase_hwcnt_dump_buffer_block_instance( + dst, grp, blk, blk_inst); + const u32 *src_blk = kbase_hwcnt_dump_buffer_block_instance( + src, grp, blk, blk_inst); + const u64 *blk_em = kbase_hwcnt_enable_map_block_instance( + dst_enable_map, grp, blk, blk_inst); + size_t val_cnt = kbase_hwcnt_metadata_block_values_count( + metadata, grp, blk); + /* Align upwards to include padding bytes */ + val_cnt = KBASE_HWCNT_ALIGN_UPWARDS( + val_cnt, (KBASE_HWCNT_BLOCK_BYTE_ALIGNMENT / + KBASE_HWCNT_VALUE_BYTES)); + + kbase_hwcnt_dump_buffer_block_copy_strict(dst_blk, src_blk, + blk_em, val_cnt); + } + + kbase_hwcnt_metadata_for_each_clock(metadata, clk) { + bool clk_enabled = kbase_hwcnt_clk_enable_map_enabled( + dst_enable_map->clk_enable_map, clk); + + dst->clk_cnt_buf[clk] = clk_enabled ? src->clk_cnt_buf[clk] : 0; + } +} + static bool is_block_type_shader( const u64 grp_type, const u64 blk_type, @@ -594,15 +712,11 @@ void kbase_hwcnt_gpu_enable_map_to_physical( metadata, grp); const u64 blk_type = kbase_hwcnt_metadata_block_type( metadata, grp, blk); - const size_t blk_val_cnt = - kbase_hwcnt_metadata_block_values_count( - metadata, grp, blk); const u64 *blk_map = kbase_hwcnt_enable_map_block_instance( src, grp, blk, blk_inst); if ((enum kbase_hwcnt_gpu_group_type)grp_type == KBASE_HWCNT_GPU_GROUP_TYPE_V5) { - WARN_ON(blk_val_cnt != KBASE_HWCNT_V5_VALUES_PER_BLOCK); switch ((enum kbase_hwcnt_gpu_v5_block_type)blk_type) { case KBASE_HWCNT_GPU_V5_BLOCK_TYPE_PERF_UNDEFINED: /* Nothing to do in this case. */ @@ -692,15 +806,11 @@ void kbase_hwcnt_gpu_enable_map_from_physical( metadata, grp); const u64 blk_type = kbase_hwcnt_metadata_block_type( metadata, grp, blk); - const size_t blk_val_cnt = - kbase_hwcnt_metadata_block_values_count( - metadata, grp, blk); u64 *blk_map = kbase_hwcnt_enable_map_block_instance( dst, grp, blk, blk_inst); if ((enum kbase_hwcnt_gpu_group_type)grp_type == KBASE_HWCNT_GPU_GROUP_TYPE_V5) { - WARN_ON(blk_val_cnt != KBASE_HWCNT_V5_VALUES_PER_BLOCK); switch ((enum kbase_hwcnt_gpu_v5_block_type)blk_type) { case KBASE_HWCNT_GPU_V5_BLOCK_TYPE_PERF_UNDEFINED: /* Nothing to do in this case. */ diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_gpu.h b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_gpu.h index 9b846a94bc3a..50ae80d87e71 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_gpu.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_gpu.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2018, 2020-2021 ARM Limited. All rights reserved. @@ -31,9 +31,10 @@ struct kbase_hwcnt_dump_buffer; #define KBASE_HWCNT_V5_BLOCK_TYPE_COUNT 4 #define KBASE_HWCNT_V5_HEADERS_PER_BLOCK 4 -#define KBASE_HWCNT_V5_COUNTERS_PER_BLOCK 60 -#define KBASE_HWCNT_V5_VALUES_PER_BLOCK \ - (KBASE_HWCNT_V5_HEADERS_PER_BLOCK + KBASE_HWCNT_V5_COUNTERS_PER_BLOCK) +#define KBASE_HWCNT_V5_DEFAULT_COUNTERS_PER_BLOCK 60 +#define KBASE_HWCNT_V5_DEFAULT_VALUES_PER_BLOCK \ + (KBASE_HWCNT_V5_HEADERS_PER_BLOCK + \ + KBASE_HWCNT_V5_DEFAULT_COUNTERS_PER_BLOCK) /** Index of the PRFCNT_EN header into a V5 counter block */ #define KBASE_HWCNT_V5_PRFCNT_EN_HEADER 2 @@ -117,14 +118,17 @@ enum kbase_hwcnt_physical_set { /** * struct kbase_hwcnt_gpu_info - Information about hwcnt blocks on the GPUs. - * @l2_count: L2 cache count. - * @core_mask: Shader core mask. May be sparse. - * @clk_cnt: Number of clock domains available. + * @l2_count: L2 cache count. + * @core_mask: Shader core mask. May be sparse. + * @clk_cnt: Number of clock domains available. + * @prfcnt_values_per_block: Total entries (header + counters) of performance + * counter per block. */ struct kbase_hwcnt_gpu_info { size_t l2_count; u64 core_mask; u8 clk_cnt; + size_t prfcnt_values_per_block; }; /** @@ -220,6 +224,48 @@ int kbase_hwcnt_csf_metadata_create( void kbase_hwcnt_csf_metadata_destroy( const struct kbase_hwcnt_metadata *metadata); +/** + * kbase_hwcnt_gpu_metadata_create_truncate_64() - Create HWC metadata with HWC + * block entries truncated + * to 64. + * + * @dst_md: Non-NULL pointer to where created metadata is stored on success. + * @src_md: Non-NULL pointer to the HWC metadata used as the source to create + * dst_md. + * + * If the total block entries in src_md is 64, metadata dst_md returns NULL + * since no need to truncate. + * if the total block entries in src_md is 128, then a new metadata with block + * entries truncated to 64 will be created for dst_md, which keeps the interface + * to user clients backward compatible. + * If the total block entries in src_md is other values, function returns error + * since it's not supported. + * + * Return: 0 on success, else error code. + */ +int kbase_hwcnt_gpu_metadata_create_truncate_64( + const struct kbase_hwcnt_metadata **dst_md, + const struct kbase_hwcnt_metadata *src_md); + +/** + * kbase_hwcnt_dump_buffer_copy_strict_narrow() - Copy all enabled values from + * src to dst. + * + * @dst: Non-NULL pointer to dst dump buffer. + * @src: Non-NULL pointer to src dump buffer. + * @dst_enable_map: Non-NULL pointer to enable map specifying enabled values. + * + * After the operation, all non-enabled values (including padding bytes) will be + * zero. + * + * The dst and src have different metadata, and the dst metadata is narrower + * than src metadata. + */ +void kbase_hwcnt_dump_buffer_copy_strict_narrow( + struct kbase_hwcnt_dump_buffer *dst, + const struct kbase_hwcnt_dump_buffer *src, + const struct kbase_hwcnt_enable_map *dst_enable_map); + /** * kbase_hwcnt_jm_dump_get() - Copy or accumulate enabled counters from the raw * dump buffer in src into the dump buffer diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_legacy.c b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_legacy.c index 45cd9fb12835..58dec99864f6 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_legacy.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_legacy.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2018, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_legacy.h b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_legacy.h index deaf7eb39236..36ff44d69813 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_legacy.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_legacy.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_types.c b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_types.c index 931fbf3f2051..492f57249291 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_types.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_types.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -23,20 +23,6 @@ #include -/* Minimum alignment of each block of hardware counters */ -#define KBASE_HWCNT_BLOCK_BYTE_ALIGNMENT \ - (KBASE_HWCNT_BITFIELD_BITS * KBASE_HWCNT_VALUE_BYTES) - -/** - * KBASE_HWCNT_ALIGN_UPWARDS() - Align a value to an alignment. - * @value: The value to align upwards. - * @alignment: The alignment. - * - * Return: A number greater than or equal to value that is aligned to alignment. - */ -#define KBASE_HWCNT_ALIGN_UPWARDS(value, alignment) \ - (value + ((alignment - (value % alignment)) % alignment)) - int kbase_hwcnt_metadata_create( const struct kbase_hwcnt_description *desc, const struct kbase_hwcnt_metadata **out_metadata) diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_types.h b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_types.h index e775393b57dc..da1295225ccf 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_types.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_types.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2018, 2020-2021 ARM Limited. All rights reserved. @@ -99,6 +99,21 @@ */ #define KBASE_HWCNT_AVAIL_MASK_BITS (sizeof(u64) * BITS_PER_BYTE) +/* Minimum alignment of each block of hardware counters */ +#define KBASE_HWCNT_BLOCK_BYTE_ALIGNMENT \ + (KBASE_HWCNT_BITFIELD_BITS * KBASE_HWCNT_VALUE_BYTES) + +/** + * KBASE_HWCNT_ALIGN_UPWARDS() - Calculate next aligned value. + * @value: The value to align upwards. + * @alignment: The alignment boundary. + * + * Return: Input value if already aligned to the specified boundary, or next + * (incrementing upwards) aligned value. + */ +#define KBASE_HWCNT_ALIGN_UPWARDS(value, alignment) \ + (value + ((alignment - (value % alignment)) % alignment)) + /** * struct kbase_hwcnt_block_description - Description of one or more identical, * contiguous, Hardware Counter Blocks. @@ -357,8 +372,7 @@ void kbase_hwcnt_metadata_destroy(const struct kbase_hwcnt_metadata *metadata); * @grp: Index of the group in the metadata. * @blk: Index of the block in the group. * - * Return: Number of u32 counter headers in each instance of block blk in - * group grp. + * Return: Number of counter headers in each instance of block blk in group grp. */ #define kbase_hwcnt_metadata_block_headers_count(metadata, grp, blk) \ ((metadata)->grp_metadata[(grp)].blk_metadata[(blk)].hdr_cnt) @@ -369,19 +383,29 @@ void kbase_hwcnt_metadata_destroy(const struct kbase_hwcnt_metadata *metadata); * @grp: Index of the group in the metadata. * @blk: Index of the block in the group. * - * Return: Number of u32 counters in each instance of block blk in group - * grp. + * Return: Number of counters in each instance of block blk in group grp. */ #define kbase_hwcnt_metadata_block_counters_count(metadata, grp, blk) \ ((metadata)->grp_metadata[(grp)].blk_metadata[(blk)].ctr_cnt) +/** + * kbase_hwcnt_metadata_block_enable_map_stride() - Get the enable map stride. + * @metadata: Non-NULL pointer to metadata. + * @grp: Index of the group in the metadata. + * @blk: Index of the block in the group. + * + * Return: enable map stride in each instance of block blk in group grp. + */ +#define kbase_hwcnt_metadata_block_enable_map_stride(metadata, grp, blk) \ + ((metadata)->grp_metadata[(grp)].blk_metadata[(blk)].enable_map_stride) + /** * kbase_hwcnt_metadata_block_values_count() - Get the number of values. * @metadata: Non-NULL pointer to metadata. * @grp: Index of the group in the metadata. * @blk: Index of the block in the group. * - * Return: Number of u32 headers plus counters in each instance of block blk + * Return: Number of headers plus counters in each instance of block blk * in group grp. */ #define kbase_hwcnt_metadata_block_values_count(metadata, grp, blk) \ @@ -777,9 +801,7 @@ void kbase_hwcnt_dump_buffer_free(struct kbase_hwcnt_dump_buffer *dump_buf); * kbase_hwcnt_dump_buffer_array_alloc() - Allocate an array of dump buffers. * @metadata: Non-NULL pointer to metadata describing the system. * @n: Number of dump buffers to allocate - * @dump_bufs: Non-NULL pointer to dump buffer array to be initialised. Each - * dump buffer in the array will be initialised to undefined values, - * so must be used as a copy dest, or cleared before use. + * @dump_bufs: Non-NULL pointer to dump buffer array to be initialised. * * A single zeroed contiguous page allocation will be used for all of the * buffers inside the array, where: diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_virtualizer.c b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_virtualizer.c index 4bb84890fb67..52ecb7bed03f 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_virtualizer.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_virtualizer.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_virtualizer.h b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_virtualizer.h index 1bce6914f11a..e3a8137ced55 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_virtualizer.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_hwcnt_virtualizer.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_jd.c b/drivers/gpu/arm/bifrost/mali_kbase_jd.c index f680a5ee144b..d780a30f230e 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_jd.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_jd.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -20,7 +20,7 @@ */ #include -#ifdef CONFIG_COMPAT +#if IS_ENABLED(CONFIG_COMPAT) #include #endif #include @@ -62,7 +62,7 @@ static void __user * get_compat_pointer(struct kbase_context *kctx, const u64 p) { -#ifdef CONFIG_COMPAT +#if IS_ENABLED(CONFIG_COMPAT) if (kbase_ctx_flag(kctx, KCTX_COMPAT)) return compat_ptr(p); #endif @@ -817,7 +817,7 @@ bool jd_done_nolock(struct kbase_jd_atom *katom, KBASE_EXPORT_TEST_API(jd_done_nolock); -#ifdef CONFIG_GPU_TRACEPOINTS +#if IS_ENABLED(CONFIG_GPU_TRACEPOINTS) enum { CORE_REQ_DEP_ONLY, CORE_REQ_SOFT, @@ -1172,7 +1172,7 @@ static bool jd_submit_atom(struct kbase_context *const kctx, } } -#ifdef CONFIG_GPU_TRACEPOINTS +#if IS_ENABLED(CONFIG_GPU_TRACEPOINTS) katom->work_id = atomic_inc_return(&jctx->work_id); trace_gpu_job_enqueue(kctx->id, katom->work_id, kbasep_map_core_reqs_to_string(katom->core_req)); @@ -1675,7 +1675,7 @@ void kbase_jd_done(struct kbase_jd_atom *katom, int slot_nr, atomic_inc(&kctx->work_count); -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) /* a failed job happened and is waiting for dumping*/ if (!katom->will_fail_event_code && kbase_debug_job_fault_process(katom, katom->event_code)) @@ -1754,7 +1754,7 @@ void kbase_jd_zap_context(struct kbase_context *kctx) flush_workqueue(kctx->dma_fence.wq); #endif -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) kbase_debug_job_fault_kctx_unblock(kctx); #endif diff --git a/drivers/gpu/arm/bifrost/mali_kbase_jd_debugfs.c b/drivers/gpu/arm/bifrost/mali_kbase_jd_debugfs.c index 2fa140cbf64a..7cf038ab12d2 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_jd_debugfs.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_jd_debugfs.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. @@ -19,7 +19,7 @@ * */ -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) #include #include diff --git a/drivers/gpu/arm/bifrost/mali_kbase_jd_debugfs.h b/drivers/gpu/arm/bifrost/mali_kbase_jd_debugfs.h index f183a9fee70e..8e6140c43538 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_jd_debugfs.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_jd_debugfs.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2014-2018, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_jm.c b/drivers/gpu/arm/bifrost/mali_kbase_jm.c index 73e9905ab036..69950508b121 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_jm.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_jm.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_jm.h b/drivers/gpu/arm/bifrost/mali_kbase_jm.h index 47202b9e9bd3..c6b28f3a7fe8 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_jm.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_jm.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2013-2014, 2016, 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2013-2014, 2016, 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_js.c b/drivers/gpu/arm/bifrost/mali_kbase_js.c index c16469d0a1d9..bf11c6dadd25 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_js.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_js.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2011-2021 ARM Limited. All rights reserved. @@ -81,7 +81,7 @@ static int kbase_js_get_slot(struct kbase_device *kbdev, struct kbase_jd_atom *katom); static void kbase_js_foreach_ctx_job(struct kbase_context *kctx, - kbasep_js_ctx_job_cb callback); + kbasep_js_ctx_job_cb *callback); /* Helper for ktrace */ #if KBASE_KTRACE_ENABLE @@ -212,9 +212,8 @@ jsctx_rb_none_to_pull(struct kbase_context *kctx, int js) * * The HW access lock must always be held when calling this function. */ -static void -jsctx_queue_foreach_prio(struct kbase_context *kctx, int js, int prio, - kbasep_js_ctx_job_cb callback) +static void jsctx_queue_foreach_prio(struct kbase_context *kctx, int js, + int prio, kbasep_js_ctx_job_cb *callback) { struct jsctx_queue *queue = &kctx->jsctx_queue[prio][js]; @@ -273,9 +272,8 @@ jsctx_queue_foreach_prio(struct kbase_context *kctx, int js, int prio, * jsctx_queue_foreach_prio() to iterate over the queue and invoke @callback * for each entry, and remove the entry from the queue. */ -static inline void -jsctx_queue_foreach(struct kbase_context *kctx, int js, - kbasep_js_ctx_job_cb callback) +static inline void jsctx_queue_foreach(struct kbase_context *kctx, int js, + kbasep_js_ctx_job_cb *callback) { int prio; @@ -3788,7 +3786,7 @@ static inline int trace_get_refcnt(struct kbase_device *kbdev, * - it will be holding kbasep_js_kctx_info::ctx::jsctx_mutex. */ static void kbase_js_foreach_ctx_job(struct kbase_context *kctx, - kbasep_js_ctx_job_cb callback) + kbasep_js_ctx_job_cb *callback) { struct kbase_device *kbdev; unsigned long flags; diff --git a/drivers/gpu/arm/bifrost/mali_kbase_js.h b/drivers/gpu/arm/bifrost/mali_kbase_js.h index a4dc2079f339..96974c8c6439 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_js.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_js.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2011-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_js_ctx_attr.c b/drivers/gpu/arm/bifrost/mali_kbase_js_ctx_attr.c index 40967cb18597..777564858b27 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_js_ctx_attr.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_js_ctx_attr.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2012-2016, 2018, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_js_ctx_attr.h b/drivers/gpu/arm/bifrost/mali_kbase_js_ctx_attr.h index 1477b1d55659..6f292410d159 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_js_ctx_attr.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_js_ctx_attr.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2012-2015, 2018, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_kinstr_jm.c b/drivers/gpu/arm/bifrost/mali_kbase_kinstr_jm.c index 7b02b681fcf7..ae6197584b56 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_kinstr_jm.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_kinstr_jm.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -30,7 +30,7 @@ #include "mali_kbase.h" #include "mali_kbase_linux.h" -#include +#include #include #include diff --git a/drivers/gpu/arm/bifrost/mali_kbase_kinstr_jm.h b/drivers/gpu/arm/bifrost/mali_kbase_kinstr_jm.h index e2588d704126..6e9a8d23ec10 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_kinstr_jm.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_kinstr_jm.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_linux.h b/drivers/gpu/arm/bifrost/mali_kbase_linux.h index ff29337d70db..1d8d1967eee9 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_linux.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_linux.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2010-2014, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mem.c b/drivers/gpu/arm/bifrost/mali_kbase_mem.c index 326917c9df53..a68e4ea3cea3 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mem.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_mem.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -28,7 +28,7 @@ #include #include #include -#ifdef CONFIG_OF +#if IS_ENABLED(CONFIG_OF) #include #endif @@ -89,7 +89,7 @@ static size_t kbase_get_num_cpu_va_bits(struct kbase_context *kctx) #error "Unknown CPU VA width for this architecture" #endif -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) if (kbase_ctx_flag(kctx, KCTX_COMPAT)) cpu_va_bits = 32; #endif @@ -115,11 +115,11 @@ static struct rb_root *kbase_gpu_va_to_rbtree(struct kbase_context *kctx, else { u64 same_va_end; -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) if (kbase_ctx_flag(kctx, KCTX_COMPAT)) { #endif /* CONFIG_64BIT */ same_va_end = KBASE_REG_ZONE_CUSTOM_VA_BASE; -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) } else { struct kbase_reg_zone *same_va_zone = kbase_ctx_reg_zone_get(kctx, @@ -755,7 +755,7 @@ int kbase_region_tracker_init(struct kbase_context *kctx) kbase_ctx_reg_zone_init(kctx, KBASE_REG_ZONE_SAME_VA, same_va_base, same_va_pages); -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) /* 32-bit clients have custom VA zones */ if (kbase_ctx_flag(kctx, KCTX_COMPAT)) { #endif @@ -782,7 +782,7 @@ int kbase_region_tracker_init(struct kbase_context *kctx) kbase_ctx_reg_zone_init(kctx, KBASE_REG_ZONE_CUSTOM_VA, KBASE_REG_ZONE_CUSTOM_VA_BASE, custom_va_size); -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) } else { custom_va_size = 0; } @@ -901,7 +901,7 @@ static bool kbase_region_tracker_has_allocs(struct kbase_context *kctx) return false; } -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) static int kbase_region_tracker_init_jit_64(struct kbase_context *kctx, u64 jit_va_pages) { @@ -1010,7 +1010,7 @@ int kbase_region_tracker_init_jit(struct kbase_context *kctx, u64 jit_va_pages, goto exit_unlock; } -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) if (!kbase_ctx_flag(kctx, KCTX_COMPAT)) err = kbase_region_tracker_init_jit_64(kctx, jit_va_pages); #endif @@ -1081,12 +1081,12 @@ int kbase_region_tracker_init_exec(struct kbase_context *kctx, u64 exec_va_pages goto exit_unlock; } -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) if (kbase_ctx_flag(kctx, KCTX_COMPAT)) { #endif /* 32-bit client: take from CUSTOM_VA zone */ target_zone_bits = KBASE_REG_ZONE_CUSTOM_VA; -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) } else { /* 64-bit client: take from SAME_VA zone */ target_zone_bits = KBASE_REG_ZONE_SAME_VA; @@ -1180,7 +1180,7 @@ int kbase_mem_init(struct kbase_device *kbdev) { int err = 0; struct kbasep_mem_device *memdev; -#ifdef CONFIG_OF +#if IS_ENABLED(CONFIG_OF) struct device_node *mgm_node = NULL; #endif @@ -1208,7 +1208,7 @@ int kbase_mem_init(struct kbase_device *kbdev) kbdev->mgm_dev = &kbase_native_mgm_dev; -#ifdef CONFIG_OF +#if IS_ENABLED(CONFIG_OF) /* Check to see whether or not a platform-specific memory group manager * is configured and available. */ @@ -3163,7 +3163,7 @@ void kbase_gpu_vm_unlock(struct kbase_context *kctx) KBASE_EXPORT_TEST_API(kbase_gpu_vm_unlock); -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) struct kbase_jit_debugfs_data { int (*func)(struct kbase_jit_debugfs_data *); struct mutex lock; @@ -4269,6 +4269,7 @@ void kbase_jit_free(struct kbase_context *kctx, struct kbase_va_region *reg) /* This allocation can't already be on a list. */ WARN_ON(!list_empty(®->gpu_alloc->evict_node)); list_add(®->gpu_alloc->evict_node, &kctx->evict_list); + atomic_add(reg->gpu_alloc->nents, &kctx->evict_nents); list_move(®->jit_node, &kctx->jit_pool_head); diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mem.h b/drivers/gpu/arm/bifrost/mali_kbase_mem.h index 8a9e93437655..b0852318e425 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mem.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_mem.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -1517,7 +1517,7 @@ void kbase_sync_single_for_device(struct kbase_device *kbdev, dma_addr_t handle, void kbase_sync_single_for_cpu(struct kbase_device *kbdev, dma_addr_t handle, size_t size, enum dma_data_direction dir); -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) /** * kbase_jit_debugfs_init - Add per context debugfs entry for JIT. * @kctx: kbase context diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mem_linux.c b/drivers/gpu/arm/bifrost/mali_kbase_mem_linux.c index f58fdf3c1e3a..a1565c127563 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mem_linux.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_mem_linux.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -327,7 +327,7 @@ struct kbase_va_region *kbase_mem_alloc(struct kbase_context *kctx, goto bad_flags; } -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) if (unlikely(kbase_ctx_flag(kctx, KCTX_INFINITE_CACHE))) { /* Mask coherency flags if infinite cache is enabled to prevent * the skipping of syncs from BASE side. @@ -636,8 +636,6 @@ unsigned long kbase_mem_evictable_reclaim_count_objects(struct shrinker *s, struct shrink_control *sc) { struct kbase_context *kctx; - struct kbase_mem_phy_alloc *alloc; - unsigned long pages = 0; kctx = container_of(s, struct kbase_context, reclaim); @@ -648,13 +646,7 @@ unsigned long kbase_mem_evictable_reclaim_count_objects(struct shrinker *s, "Shrinker called whilst in atomic context. The caller must switch to using GFP_ATOMIC or similar. gfp_mask==%x\n", sc->gfp_mask); - mutex_lock(&kctx->jit_evict_lock); - - list_for_each_entry(alloc, &kctx->evict_list, evict_node) - pages += alloc->nents; - - mutex_unlock(&kctx->jit_evict_lock); - return pages; + return atomic_read(&kctx->evict_nents); } /** @@ -686,6 +678,7 @@ unsigned long kbase_mem_evictable_reclaim_scan_objects(struct shrinker *s, unsigned long freed = 0; kctx = container_of(s, struct kbase_context, reclaim); + mutex_lock(&kctx->jit_evict_lock); list_for_each_entry_safe(alloc, tmp, &kctx->evict_list, evict_node) { @@ -712,6 +705,7 @@ unsigned long kbase_mem_evictable_reclaim_scan_objects(struct shrinker *s, kbase_free_phy_pages_helper(alloc, alloc->evicted); freed += alloc->evicted; + WARN_ON(atomic_sub_return(alloc->evicted, &kctx->evict_nents) < 0); list_del_init(&alloc->evict_node); /* @@ -735,6 +729,8 @@ int kbase_mem_evictable_init(struct kbase_context *kctx) INIT_LIST_HEAD(&kctx->evict_list); mutex_init(&kctx->jit_evict_lock); + atomic_set(&kctx->evict_nents, 0); + kctx->reclaim.count_objects = kbase_mem_evictable_reclaim_count_objects; kctx->reclaim.scan_objects = kbase_mem_evictable_reclaim_scan_objects; kctx->reclaim.seeks = DEFAULT_SEEKS; @@ -818,6 +814,7 @@ int kbase_mem_evictable_make(struct kbase_mem_phy_alloc *gpu_alloc) * can reclaim it. */ list_add(&gpu_alloc->evict_node, &kctx->evict_list); + atomic_add(gpu_alloc->nents, &kctx->evict_nents); mutex_unlock(&kctx->jit_evict_lock); kbase_mem_evictable_mark_reclaim(gpu_alloc); @@ -837,6 +834,7 @@ bool kbase_mem_evictable_unmake(struct kbase_mem_phy_alloc *gpu_alloc) * First remove the allocation from the eviction list as it's no * longer eligible for eviction. */ + WARN_ON(atomic_sub_return(gpu_alloc->nents, &kctx->evict_nents) < 0); list_del_init(&gpu_alloc->evict_node); mutex_unlock(&kctx->jit_evict_lock); @@ -1408,7 +1406,7 @@ static struct kbase_va_region *kbase_mem_from_umm(struct kbase_context *kctx, if (*flags & BASE_MEM_IMPORT_SYNC_ON_MAP_UNMAP) need_sync = true; -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) if (!kbase_ctx_flag(kctx, KCTX_COMPAT)) { /* * 64-bit tasks require us to reserve VA on the CPU that we use @@ -1561,7 +1559,7 @@ static struct kbase_va_region *kbase_mem_from_user_buffer( if (*flags & BASE_MEM_IMPORT_SHARED) shared_zone = true; -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) if (!kbase_ctx_flag(kctx, KCTX_COMPAT)) { /* * 64-bit tasks require us to reserve VA on the CPU that we use @@ -1755,7 +1753,7 @@ u64 kbase_mem_alias(struct kbase_context *kctx, u64 *flags, u64 stride, /* calculate the number of pages this alias will cover */ *num_pages = nents * stride; -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) if (!kbase_ctx_flag(kctx, KCTX_COMPAT)) { /* 64-bit tasks must MMAP anyway, but not expose this address to * clients @@ -1876,7 +1874,7 @@ u64 kbase_mem_alias(struct kbase_context *kctx, u64 *flags, u64 stride, } } -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) if (!kbase_ctx_flag(kctx, KCTX_COMPAT)) { /* Bind to a cookie */ if (bitmap_empty(kctx->cookies, BITS_PER_LONG)) { @@ -1911,7 +1909,7 @@ u64 kbase_mem_alias(struct kbase_context *kctx, u64 *flags, u64 stride, return gpu_va; -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) no_cookie: #endif no_mmap: @@ -1999,7 +1997,7 @@ int kbase_mem_import(struct kbase_context *kctx, enum base_mem_import_type type, sizeof(user_buffer))) { reg = NULL; } else { -#ifdef CONFIG_COMPAT +#if IS_ENABLED(CONFIG_COMPAT) if (kbase_ctx_flag(kctx, KCTX_COMPAT)) uptr = compat_ptr(user_buffer.ptr); else @@ -3191,10 +3189,8 @@ static unsigned long get_queue_doorbell_pfn(struct kbase_device *kbdev, * assigned one, otherwise a dummy page. Always return the * dummy page in no mali builds. */ - if ((queue->doorbell_nr == KBASEP_USER_DB_NR_INVALID) || - IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI)) + if (queue->doorbell_nr == KBASEP_USER_DB_NR_INVALID) return PFN_DOWN(as_phys_addr_t(kbdev->csf.dummy_db_page)); - return (PFN_DOWN(kbdev->reg_start + CSF_HW_DOORBELL_PAGE_OFFSET + (u64)queue->doorbell_nr * CSF_HW_DOORBELL_PAGE_SIZE)); } @@ -3440,7 +3436,7 @@ static vm_fault_t kbase_csf_user_reg_vm_fault(struct vm_fault *vmf) /* Don't map in the actual register page if GPU is powered down. * Always map in the dummy page in no mali builds. */ - if (!kbdev->pm.backend.gpu_powered || IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI)) + if (!kbdev->pm.backend.gpu_powered) pfn = PFN_DOWN(as_phys_addr_t(kbdev->csf.dummy_user_reg_page)); ret = mgm_dev->ops.mgm_vmf_insert_pfn_prot(mgm_dev, diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mem_linux.h b/drivers/gpu/arm/bifrost/mali_kbase_mem_linux.h index c04b7fe59b0a..36159c1b71c1 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mem_linux.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_mem_linux.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2010, 2012-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mem_lowlevel.h b/drivers/gpu/arm/bifrost/mali_kbase_mem_lowlevel.h index ab09ec9b2b34..3f260bf42c4b 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mem_lowlevel.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_mem_lowlevel.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2012-2014, 2016-2018, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mem_pool.c b/drivers/gpu/arm/bifrost/mali_kbase_mem_pool.c index 1874a6f9afd7..a11da825e21c 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mem_pool.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_mem_pool.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2015-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_debugfs.c b/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_debugfs.c index e7d8fdc82e27..cfb43b029c6c 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_debugfs.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_debugfs.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2014-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_debugfs.h b/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_debugfs.h index b2a94d7b775b..207b58536a58 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_debugfs.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_debugfs.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_group.c b/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_group.c index 72a17b268502..8d7bb4d68854 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_group.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_group.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_group.h b/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_group.h index 35333e916ae1..38fd4cad9a77 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_group.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_group.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mem_profile_debugfs.c b/drivers/gpu/arm/bifrost/mali_kbase_mem_profile_debugfs.c index 113b69e4d410..201ff517228c 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mem_profile_debugfs.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_mem_profile_debugfs.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2012-2017, 2019-2021 ARM Limited. All rights reserved. @@ -21,7 +21,7 @@ #include -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) /** * Show callback for the @c mem_profile debugfs file. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mem_profile_debugfs.h b/drivers/gpu/arm/bifrost/mali_kbase_mem_profile_debugfs.h index 7b5695d44ae3..093a65e35f7a 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mem_profile_debugfs.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_mem_profile_debugfs.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2012-2016, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mem_profile_debugfs_buf_size.h b/drivers/gpu/arm/bifrost/mali_kbase_mem_profile_debugfs_buf_size.h index 8489c550fc6b..3184a98f30ce 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mem_profile_debugfs_buf_size.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_mem_profile_debugfs_buf_size.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2014, 2017-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mipe_gen_header.h b/drivers/gpu/arm/bifrost/mali_kbase_mipe_gen_header.h index d1ea7ad24792..f0b385e6e51f 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mipe_gen_header.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_mipe_gen_header.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_mipe_proto.h b/drivers/gpu/arm/bifrost/mali_kbase_mipe_proto.h index ee88ee69c0fc..c35ee61ce5aa 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_mipe_proto.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_mipe_proto.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_native_mgm.c b/drivers/gpu/arm/bifrost/mali_kbase_native_mgm.c index 957d884b9c11..4554bee783e7 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_native_mgm.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_native_mgm.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_native_mgm.h b/drivers/gpu/arm/bifrost/mali_kbase_native_mgm.h index f14fee42ca12..1eae2fcf98b6 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_native_mgm.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_native_mgm.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_platform_fake.c b/drivers/gpu/arm/bifrost/mali_kbase_platform_fake.c index 02bfb256ce2a..bf525ed0ac27 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_platform_fake.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_platform_fake.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2011-2014, 2016-2017, 2020-2021 ARM Limited. All rights reserved. @@ -25,7 +25,6 @@ #include #include - /* * This file is included only for type definitions and functions belonging to * specific platform folders. Do not add dependencies with symbols that are diff --git a/drivers/gpu/arm/bifrost/mali_kbase_pm.c b/drivers/gpu/arm/bifrost/mali_kbase_pm.c index 3ded47ba85c5..de100ddd8767 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_pm.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_pm.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -29,13 +29,13 @@ #include #include -#include +#include #ifdef CONFIG_MALI_ARBITER_SUPPORT #include #endif /* CONFIG_MALI_ARBITER_SUPPORT */ -#include +#include int kbase_pm_powerup(struct kbase_device *kbdev, unsigned int flags) { diff --git a/drivers/gpu/arm/bifrost/mali_kbase_pm.h b/drivers/gpu/arm/bifrost/mali_kbase_pm.h index f7340dd4d903..980a8d19d938 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_pm.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_pm.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_regs_history_debugfs.c b/drivers/gpu/arm/bifrost/mali_kbase_regs_history_debugfs.c index 0e7b7f033fda..d13ab10cb59b 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_regs_history_debugfs.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_regs_history_debugfs.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2014, 2016, 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014, 2016, 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -22,7 +22,7 @@ #include "mali_kbase.h" #include "mali_kbase_regs_history_debugfs.h" -#if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_MALI_BIFROST_NO_MALI) +#if defined(CONFIG_DEBUG_FS) && !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) #include @@ -241,4 +241,4 @@ void kbasep_regs_history_debugfs_init(struct kbase_device *kbdev) kbdev->mali_debugfs_directory, &kbdev->io_history, ®s_history_fops); } -#endif /* defined(CONFIG_DEBUG_FS) && !defined(CONFIG_MALI_BIFROST_NO_MALI) */ +#endif /* defined(CONFIG_DEBUG_FS) && !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) */ diff --git a/drivers/gpu/arm/bifrost/mali_kbase_regs_history_debugfs.h b/drivers/gpu/arm/bifrost/mali_kbase_regs_history_debugfs.h index b202b22256c8..cbe602248836 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_regs_history_debugfs.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_regs_history_debugfs.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014, 2016, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014, 2016, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -36,7 +36,7 @@ struct kbase_device; -#if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_MALI_BIFROST_NO_MALI) +#if defined(CONFIG_DEBUG_FS) && !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) /** * kbase_io_history_init - initialize data struct for register access history @@ -69,16 +69,24 @@ void kbase_io_history_dump(struct kbase_device *kbdev); */ void kbasep_regs_history_debugfs_init(struct kbase_device *kbdev); -#else /* defined(CONFIG_DEBUG_FS) && !defined(CONFIG_MALI_BIFROST_NO_MALI) */ +#else /* defined(CONFIG_DEBUG_FS) && !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) */ +static inline int kbase_io_history_init(struct kbase_io_history *h, u16 n) +{ + return 0; +} -#define kbase_io_history_init(...) ((int)0) +static inline void kbase_io_history_term(struct kbase_io_history *h) +{ +} -#define kbase_io_history_term CSTD_NOP +static inline void kbase_io_history_dump(struct kbase_device *kbdev) +{ +} -#define kbase_io_history_dump CSTD_NOP +static inline void kbasep_regs_history_debugfs_init(struct kbase_device *kbdev) +{ +} -#define kbasep_regs_history_debugfs_init CSTD_NOP - -#endif /* defined(CONFIG_DEBUG_FS) && !defined(CONFIG_MALI_BIFROST_NO_MALI) */ +#endif /* defined(CONFIG_DEBUG_FS) && !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) */ #endif /*_KBASE_REGS_HISTORY_DEBUGFS_H*/ diff --git a/drivers/gpu/arm/bifrost/mali_kbase_reset_gpu.h b/drivers/gpu/arm/bifrost/mali_kbase_reset_gpu.h index cb8a082f6293..292a29cb8b57 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_reset_gpu.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_reset_gpu.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_smc.c b/drivers/gpu/arm/bifrost/mali_kbase_smc.c index 82c5a10a15f5..abbe8d56d082 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_smc.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_smc.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2015, 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2015, 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -19,7 +19,7 @@ * */ -#ifdef CONFIG_ARM64 +#if IS_ENABLED(CONFIG_ARM64) #include #include diff --git a/drivers/gpu/arm/bifrost/mali_kbase_smc.h b/drivers/gpu/arm/bifrost/mali_kbase_smc.h index 9b89c321bf19..d0086dbf38e0 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_smc.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_smc.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2015, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2015, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -22,7 +22,7 @@ #ifndef _KBASE_SMC_H_ #define _KBASE_SMC_H_ -#ifdef CONFIG_ARM64 +#if IS_ENABLED(CONFIG_ARM64) #include diff --git a/drivers/gpu/arm/bifrost/mali_kbase_softjobs.c b/drivers/gpu/arm/bifrost/mali_kbase_softjobs.c index f78063835ddd..490d9e1f0ddc 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_softjobs.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_softjobs.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2011-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_strings.c b/drivers/gpu/arm/bifrost/mali_kbase_strings.c index f38093031494..84784be6f244 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_strings.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_strings.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2010-2016, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2010-2016, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_strings.h b/drivers/gpu/arm/bifrost/mali_kbase_strings.h index e6ec7f3bc050..c3f94f9267d5 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_strings.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_strings.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2010-2016, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2010-2016, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_sync.h b/drivers/gpu/arm/bifrost/mali_kbase_sync.h index ae3601f9bee4..e20edec67761 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_sync.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_sync.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2012-2016, 2018-2021 ARM Limited. All rights reserved. @@ -30,10 +30,10 @@ #include #include -#ifdef CONFIG_SYNC +#if IS_ENABLED(CONFIG_SYNC) #include #endif -#ifdef CONFIG_SYNC_FILE +#if IS_ENABLED(CONFIG_SYNC_FILE) #include "mali_kbase_fence_defs.h" #include #endif diff --git a/drivers/gpu/arm/bifrost/mali_kbase_sync_android.c b/drivers/gpu/arm/bifrost/mali_kbase_sync_android.c index e3d2e5555d23..562cf2dfa4fc 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_sync_android.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_sync_android.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2012-2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2012-2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_sync_common.c b/drivers/gpu/arm/bifrost/mali_kbase_sync_common.c index 39a68c268bd1..5ee7fc3ce72b 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_sync_common.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_sync_common.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2012-2016, 2018-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_kbase_sync_file.c b/drivers/gpu/arm/bifrost/mali_kbase_sync_file.c index 76ce17d4bd1f..3ad64d6e37b9 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_sync_file.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_sync_file.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2012-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2012-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_trace_gpu_mem.c b/drivers/gpu/arm/bifrost/mali_kbase_trace_gpu_mem.c index 0458e17c48a2..3088c41eb464 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_trace_gpu_mem.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_trace_gpu_mem.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_trace_gpu_mem.h b/drivers/gpu/arm/bifrost/mali_kbase_trace_gpu_mem.h index b78b553809b5..fd871fcb352a 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_trace_gpu_mem.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_trace_gpu_mem.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -22,7 +22,7 @@ #ifndef _KBASE_TRACE_GPU_MEM_H_ #define _KBASE_TRACE_GPU_MEM_H_ -#ifdef CONFIG_TRACE_GPU_MEM +#if IS_ENABLED(CONFIG_TRACE_GPU_MEM) #include #endif @@ -31,7 +31,7 @@ static void kbase_trace_gpu_mem_usage(struct kbase_device *kbdev, struct kbase_context *kctx) { -#ifdef CONFIG_TRACE_GPU_MEM +#if IS_ENABLED(CONFIG_TRACE_GPU_MEM) lockdep_assert_held(&kbdev->gpu_mem_usage_lock); trace_gpu_mem_total(kbdev->id, DEVICE_TGID, diff --git a/drivers/gpu/arm/bifrost/mali_kbase_utility.h b/drivers/gpu/arm/bifrost/mali_kbase_utility.h index 5911969d2ecd..2dad49b59f52 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_utility.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_utility.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2012-2013, 2015, 2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2012-2013, 2015, 2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_kbase_vinstr.c b/drivers/gpu/arm/bifrost/mali_kbase_vinstr.c index bc992bb947a0..38de7f6b0467 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_vinstr.c +++ b/drivers/gpu/arm/bifrost/mali_kbase_vinstr.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2011-2021 ARM Limited. All rights reserved. @@ -53,6 +53,10 @@ * counters. * @hvirt: Hardware counter virtualizer used by vinstr. * @metadata: Hardware counter metadata provided by virtualizer. + * @metadata_user: API compatible hardware counter metadata provided by vinstr. + * For compatibility with the user driver interface, this + * contains a "truncated" version of the HWCNT metadata limited + * to 64 entries per block. NULL when not required. * @lock: Lock protecting all vinstr state. * @suspend_count: Suspend reference count. If non-zero, timer and worker are * prevented from being re-scheduled. @@ -64,6 +68,7 @@ struct kbase_vinstr_context { struct kbase_hwcnt_virtualizer *hvirt; const struct kbase_hwcnt_metadata *metadata; + const struct kbase_hwcnt_metadata *metadata_user; struct mutex lock; size_t suspend_count; size_t client_count; @@ -217,9 +222,18 @@ static int kbasep_vinstr_client_dump( /* Copy the temp buffer to the userspace visible buffer. The strict * variant will explicitly zero any non-enabled counters to ensure * nothing except exactly what the user asked for is made visible. + * + * If the metadata in vinstr (vctx->metadata_user) is not NULL, it means + * vinstr has the truncated metadata, so do a narrow copy since + * virtualizer has a bigger buffer but user only needs part of it. + * otherwise we do a full copy. */ - kbase_hwcnt_dump_buffer_copy_strict( - dump_buf, tmp_buf, &vcli->enable_map); + if (vcli->vctx->metadata_user) + kbase_hwcnt_dump_buffer_copy_strict_narrow(dump_buf, tmp_buf, + &vcli->enable_map); + else + kbase_hwcnt_dump_buffer_copy_strict(dump_buf, tmp_buf, + &vcli->enable_map); clk_cnt = vcli->vctx->metadata->clk_cnt; @@ -422,6 +436,9 @@ static int kbasep_vinstr_client_create( phys_em.mmu_l2_bm = setup->mmu_l2_bm; kbase_hwcnt_gpu_enable_map_from_physical(&vcli->enable_map, &phys_em); + /* Use virtualizer's metadata to alloc tmp buffer which interacts with + * the HWC virtualizer. + */ errcode = kbase_hwcnt_dump_buffer_alloc(vctx->metadata, &vcli->tmp_buf); if (errcode) goto error; @@ -429,8 +446,20 @@ static int kbasep_vinstr_client_create( /* Enable all the available clk_enable_map. */ vcli->enable_map.clk_enable_map = (1ull << vctx->metadata->clk_cnt) - 1; - errcode = kbase_hwcnt_dump_buffer_array_alloc( - vctx->metadata, setup->buffer_count, &vcli->dump_bufs); + if (vctx->metadata_user) + /* Use vinstr's truncated metadata to alloc dump buffers which + * interact with clients. + */ + errcode = + kbase_hwcnt_dump_buffer_array_alloc(vctx->metadata_user, + setup->buffer_count, + &vcli->dump_bufs); + else + /* Use metadata from virtualizer to allocate dump buffers if + * vinstr doesn't have the truncated metadata. + */ + errcode = kbase_hwcnt_dump_buffer_array_alloc( + vctx->metadata, setup->buffer_count, &vcli->dump_bufs); if (errcode) goto error; @@ -458,6 +487,7 @@ int kbase_vinstr_init( struct kbase_hwcnt_virtualizer *hvirt, struct kbase_vinstr_context **out_vctx) { + int errcode; struct kbase_vinstr_context *vctx; const struct kbase_hwcnt_metadata *metadata; @@ -474,6 +504,11 @@ int kbase_vinstr_init( vctx->hvirt = hvirt; vctx->metadata = metadata; + vctx->metadata_user = NULL; + errcode = kbase_hwcnt_gpu_metadata_create_truncate_64( + &vctx->metadata_user, metadata); + if (errcode) + goto err_metadata_create; mutex_init(&vctx->lock); INIT_LIST_HEAD(&vctx->clients); @@ -483,6 +518,11 @@ int kbase_vinstr_init( *out_vctx = vctx; return 0; + +err_metadata_create: + kfree(vctx); + + return errcode; } void kbase_vinstr_term(struct kbase_vinstr_context *vctx) @@ -503,6 +543,9 @@ void kbase_vinstr_term(struct kbase_vinstr_context *vctx) } } + if (vctx->metadata_user) + kbase_hwcnt_metadata_destroy(vctx->metadata_user); + WARN_ON(vctx->client_count != 0); kfree(vctx); } @@ -963,9 +1006,14 @@ static long kbasep_vinstr_hwcnt_reader_ioctl( cli, (u32 __user *)arg); break; case _IOC_NR(KBASE_HWCNT_READER_GET_BUFFER_SIZE): - rcode = put_user( - (u32)cli->vctx->metadata->dump_buf_bytes, - (u32 __user *)arg); + if (cli->vctx->metadata_user) + rcode = put_user( + (u32)cli->vctx->metadata_user->dump_buf_bytes, + (u32 __user *)arg); + else + rcode = put_user( + (u32)cli->vctx->metadata->dump_buf_bytes, + (u32 __user *)arg); break; case _IOC_NR(KBASE_HWCNT_READER_DUMP): rcode = kbasep_vinstr_hwcnt_reader_ioctl_dump(cli); diff --git a/drivers/gpu/arm/bifrost/mali_kbase_vinstr.h b/drivers/gpu/arm/bifrost/mali_kbase_vinstr.h index a20f31aaf5d0..6747ec70a406 100644 --- a/drivers/gpu/arm/bifrost/mali_kbase_vinstr.h +++ b/drivers/gpu/arm/bifrost/mali_kbase_vinstr.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2015-2018, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2015-2018, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_linux_trace.h b/drivers/gpu/arm/bifrost/mali_linux_trace.h index 6fe48ff2f7da..52f17390c853 100644 --- a/drivers/gpu/arm/bifrost/mali_linux_trace.h +++ b/drivers/gpu/arm/bifrost/mali_linux_trace.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2011-2016, 2018-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_malisw.h b/drivers/gpu/arm/bifrost/mali_malisw.h index c0640440839d..c0649f2f4be6 100644 --- a/drivers/gpu/arm/bifrost/mali_malisw.h +++ b/drivers/gpu/arm/bifrost/mali_malisw.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2014-2015, 2018, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mali_power_gpu_frequency_trace.c b/drivers/gpu/arm/bifrost/mali_power_gpu_frequency_trace.c index f548b04d9a8c..1db3abe2f9f6 100644 --- a/drivers/gpu/arm/bifrost/mali_power_gpu_frequency_trace.c +++ b/drivers/gpu/arm/bifrost/mali_power_gpu_frequency_trace.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mali_power_gpu_frequency_trace.h b/drivers/gpu/arm/bifrost/mali_power_gpu_frequency_trace.h index d6909a4cf911..ea18fcd01f6e 100644 --- a/drivers/gpu/arm/bifrost/mali_power_gpu_frequency_trace.h +++ b/drivers/gpu/arm/bifrost/mali_power_gpu_frequency_trace.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mmu/Kbuild b/drivers/gpu/arm/bifrost/mmu/Kbuild new file mode 100644 index 000000000000..416432397b5c --- /dev/null +++ b/drivers/gpu/arm/bifrost/mmu/Kbuild @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note +# +# (C) COPYRIGHT 2021 ARM Limited. All rights reserved. +# +# This program is free software and is provided to you under the terms of the +# GNU General Public License version 2 as published by the Free Software +# Foundation, and any use by you of this program is subject to the terms +# of such GNU license. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you can access it online at +# http://www.gnu.org/licenses/gpl-2.0.html. +# +# + +bifrost_kbase-y += \ + mmu/mali_kbase_mmu.o \ + mmu/mali_kbase_mmu_hw_direct.o \ + mmu/mali_kbase_mmu_mode_aarch64.o + +ifeq ($(CONFIG_MALI_CSF_SUPPORT),y) + bifrost_kbase-y += mmu/backend/mali_kbase_mmu_csf.o +else + bifrost_kbase-y += mmu/backend/mali_kbase_mmu_jm.o +endif diff --git a/drivers/gpu/arm/bifrost/mmu/backend/mali_kbase_mmu_csf.c b/drivers/gpu/arm/bifrost/mmu/backend/mali_kbase_mmu_csf.c index 8240817cc135..05253aeb9876 100644 --- a/drivers/gpu/arm/bifrost/mmu/backend/mali_kbase_mmu_csf.c +++ b/drivers/gpu/arm/bifrost/mmu/backend/mali_kbase_mmu_csf.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -28,7 +28,7 @@ #include #include #include -#include "../mali_kbase_mmu_internal.h" +#include void kbase_mmu_get_as_setup(struct kbase_mmu_table *mmut, struct kbase_mmu_setup * const setup) @@ -483,6 +483,15 @@ static void kbase_mmu_gpu_fault_worker(struct work_struct *data) kbase_ctx_sched_release_ctx_lock(kctx); atomic_dec(&kbdev->faults_pending); + + /* A work for GPU fault is complete. + * Till reaching here, no further GPU fault will be reported. + * Now clear the GPU fault to allow next GPU fault interrupt report. + */ + spin_lock_irqsave(&kbdev->hwaccess_lock, flags); + kbase_reg_write(kbdev, GPU_CONTROL_REG(GPU_COMMAND), + GPU_COMMAND_CLEAR_FAULT); + spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags); } /** diff --git a/drivers/gpu/arm/bifrost/mmu/backend/mali_kbase_mmu_jm.c b/drivers/gpu/arm/bifrost/mmu/backend/mali_kbase_mmu_jm.c index ae334c182a69..01ca419af60c 100644 --- a/drivers/gpu/arm/bifrost/mmu/backend/mali_kbase_mmu_jm.c +++ b/drivers/gpu/arm/bifrost/mmu/backend/mali_kbase_mmu_jm.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -28,7 +28,7 @@ #include #include #include -#include "../mali_kbase_mmu_internal.h" +#include void kbase_mmu_get_as_setup(struct kbase_mmu_table *mmut, struct kbase_mmu_setup * const setup) diff --git a/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu.c b/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu.c index 0761f68c1234..85e2d882521e 100644 --- a/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu.c +++ b/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -982,7 +982,11 @@ static phys_addr_t kbase_mmu_alloc_pgd(struct kbase_device *kbdev, int i; struct page *p; +#ifdef CONFIG_MALI_2MB_ALLOC + p = kbase_mem_pool_alloc(&kbdev->mem_pools.large[mmut->group_id]); +#else /* CONFIG_MALI_2MB_ALLOC */ p = kbase_mem_pool_alloc(&kbdev->mem_pools.small[mmut->group_id]); +#endif /* CONFIG_MALI_2MB_ALLOC */ if (!p) return 0; @@ -1019,8 +1023,12 @@ static phys_addr_t kbase_mmu_alloc_pgd(struct kbase_device *kbdev, return page_to_phys(p); alloc_free: - kbase_mem_pool_free(&kbdev->mem_pools.small[mmut->group_id], p, - false); + +#ifdef CONFIG_MALI_2MB_ALLOC + kbase_mem_pool_free(&kbdev->mem_pools.large[mmut->group_id], p, false); +#else /* CONFIG_MALI_2MB_ALLOC */ + kbase_mem_pool_free(&kbdev->mem_pools.small[mmut->group_id], p, false); +#endif /* CONFIG_MALI_2MB_ALLOC */ return 0; } @@ -1246,7 +1254,11 @@ int kbase_mmu_insert_single_page(struct kbase_context *kctx, u64 vpfn, */ mutex_unlock(&kctx->mmu.mmu_lock); err = kbase_mem_pool_grow( +#ifdef CONFIG_MALI_2MB_ALLOC + &kbdev->mem_pools.large[ +#else &kbdev->mem_pools.small[ +#endif kctx->mmu.group_id], MIDGARD_MMU_BOTTOMLEVEL); mutex_lock(&kctx->mmu.mmu_lock); @@ -1325,7 +1337,11 @@ static inline void cleanup_empty_pte(struct kbase_device *kbdev, tmp_pgd = kbdev->mmu_mode->pte_to_phy_addr(*pte); tmp_p = phys_to_page(tmp_pgd); +#ifdef CONFIG_MALI_2MB_ALLOC + kbase_mem_pool_free(&kbdev->mem_pools.large[mmut->group_id], +#else kbase_mem_pool_free(&kbdev->mem_pools.small[mmut->group_id], +#endif tmp_p, false); /* If the MMU tables belong to a context then we accounted the memory @@ -1409,7 +1425,11 @@ int kbase_mmu_insert_pages_no_flush(struct kbase_device *kbdev, */ mutex_unlock(&mmut->mmu_lock); err = kbase_mem_pool_grow( +#ifdef CONFIG_MALI_2MB_ALLOC + &kbdev->mem_pools.large[mmut->group_id], +#else &kbdev->mem_pools.small[mmut->group_id], +#endif cur_level); mutex_lock(&mmut->mmu_lock); } while (!err); @@ -1897,7 +1917,11 @@ static int kbase_mmu_update_pages_no_flush(struct kbase_context *kctx, u64 vpfn, */ mutex_unlock(&kctx->mmu.mmu_lock); err = kbase_mem_pool_grow( +#ifdef CONFIG_MALI_2MB_ALLOC + &kbdev->mem_pools.large[ +#else &kbdev->mem_pools.small[ +#endif kctx->mmu.group_id], MIDGARD_MMU_BOTTOMLEVEL); mutex_lock(&kctx->mmu.mmu_lock); @@ -1992,8 +2016,11 @@ static void mmu_teardown_level(struct kbase_device *kbdev, } p = pfn_to_page(PFN_DOWN(pgd)); - +#ifdef CONFIG_MALI_2MB_ALLOC + kbase_mem_pool_free(&kbdev->mem_pools.large[mmut->group_id], +#else kbase_mem_pool_free(&kbdev->mem_pools.small[mmut->group_id], +#endif p, true); atomic_sub(1, &kbdev->memdev.used_pages); @@ -2036,7 +2063,11 @@ int kbase_mmu_init(struct kbase_device *const kbdev, int err; err = kbase_mem_pool_grow( +#ifdef CONFIG_MALI_2MB_ALLOC + &kbdev->mem_pools.large[mmut->group_id], +#else &kbdev->mem_pools.small[mmut->group_id], +#endif MIDGARD_MMU_BOTTOMLEVEL); if (err) { kbase_mmu_term(kbdev, mmut); diff --git a/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu.h b/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu.h index bf4fd91d27bc..a2d1a8ee8475 100644 --- a/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu.h +++ b/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_hw.h b/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_hw.h index ea088e921b03..d1f1ff2befe5 100644 --- a/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_hw.h +++ b/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_hw.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2014-2015, 2018-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_hw_direct.c b/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_hw_direct.c index 88fd9cf9a864..a99b98852091 100644 --- a/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_hw_direct.c +++ b/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_hw_direct.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_internal.h b/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_internal.h index d3fcd3939ab6..b8cd55f9cb64 100644 --- a/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_internal.h +++ b/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_internal.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_mode_aarch64.c b/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_mode_aarch64.c index fac515cea403..16b928d42e25 100644 --- a/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_mode_aarch64.c +++ b/drivers/gpu/arm/bifrost/mmu/mali_kbase_mmu_mode_aarch64.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2010-2014, 2016-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2010-2014, 2016-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/platform/Kconfig b/drivers/gpu/arm/bifrost/platform/Kconfig index ac385aa6b021..5f0118d98640 100644 --- a/drivers/gpu/arm/bifrost/platform/Kconfig +++ b/drivers/gpu/arm/bifrost/platform/Kconfig @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2012-2013, 2017 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2012-2013, 2017, 2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/platform/devicetree/Kbuild b/drivers/gpu/arm/bifrost/platform/devicetree/Kbuild index f151ee8680ad..2eecd6635948 100644 --- a/drivers/gpu/arm/bifrost/platform/devicetree/Kbuild +++ b/drivers/gpu/arm/bifrost/platform/devicetree/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2012-2017, 2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2012-2017, 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -19,6 +19,7 @@ # bifrost_kbase-y += \ - $(MALI_PLATFORM_DIR)/mali_kbase_config_devicetree.o \ - $(MALI_PLATFORM_DIR)/mali_kbase_runtime_pm.o \ - $(MALI_PLATFORM_DIR)/mali_kbase_clk_rate_trace.o + platform/$(MALI_PLATFORM_DIR)/mali_kbase_config_devicetree.o \ + platform/$(MALI_PLATFORM_DIR)/mali_kbase_config_platform.o \ + platform/$(MALI_PLATFORM_DIR)/mali_kbase_runtime_pm.o \ + platform/$(MALI_PLATFORM_DIR)/mali_kbase_clk_rate_trace.o diff --git a/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_clk_rate_trace.c b/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_clk_rate_trace.c index f149554c28ed..4bcd5854d3a3 100644 --- a/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_clk_rate_trace.c +++ b/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_clk_rate_trace.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2015, 2017-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2015, 2017-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_config_devicetree.c b/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_config_devicetree.c index 5f300b1913e1..a0b4a434e2a7 100644 --- a/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_config_devicetree.c +++ b/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_config_devicetree.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2015, 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2015, 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -19,7 +19,9 @@ * */ +#include #include +#include static struct kbase_platform_config dummy_platform_config; @@ -38,3 +40,14 @@ void kbase_platform_unregister(void) { } #endif + +#ifdef CONFIG_MALI_BIFROST_DVFS +#if MALI_USE_CSF +int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation) +#else +int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation, u32 util_gl_share, u32 util_cl_share[2]) +#endif +{ + return 1; +} +#endif /* CONFIG_MALI_BIFROST_DVFS */ diff --git a/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_config_platform.c b/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_config_platform.c new file mode 100644 index 000000000000..63aa33ffcc4a --- /dev/null +++ b/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_config_platform.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note +/* + * + * (C) COPYRIGHT 2021 ARM Limited. All rights reserved. + * + * This program is free software and is provided to you under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation, and any use by you of this program is subject to the terms + * of such GNU license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you can access it online at + * http://www.gnu.org/licenses/gpl-2.0.html. + * + */ + +#include +#include +#include +#include "mali_kbase_config_platform.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +struct kbase_platform_funcs_conf platform_funcs = { + .platform_init_func = NULL, + .platform_term_func = NULL, + .platform_late_init_func = NULL, + .platform_late_term_func = NULL, +}; diff --git a/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_config_platform.h b/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_config_platform.h index ee9ae52c8608..927d5c274d14 100644 --- a/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_config_platform.h +++ b/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_config_platform.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014-2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -33,13 +33,13 @@ * Attached value: pointer to @ref kbase_platform_funcs_conf * Default value: See @ref kbase_platform_funcs_conf */ -#define PLATFORM_FUNCS (NULL) +#define PLATFORM_FUNCS (&platform_funcs) #define CLK_RATE_TRACE_OPS (&clk_rate_trace_ops) extern struct kbase_pm_callback_conf pm_callbacks; extern struct kbase_clk_rate_trace_op_conf clk_rate_trace_ops; - +extern struct kbase_platform_funcs_conf platform_funcs; /** * Autosuspend delay * diff --git a/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_runtime_pm.c b/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_runtime_pm.c index 008f8a45f86d..3b84d741bc30 100644 --- a/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_runtime_pm.c +++ b/drivers/gpu/arm/bifrost/platform/devicetree/mali_kbase_runtime_pm.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2015-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2015-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -25,6 +25,7 @@ #include #include #include + #include "mali_kbase_config_platform.h" static void enable_gpu_power_control(struct kbase_device *kbdev) diff --git a/drivers/gpu/arm/bifrost/platform/rk/Kbuild b/drivers/gpu/arm/bifrost/platform/rk/Kbuild index 7cc6c59d969f..a1e78cfc4ae7 100755 --- a/drivers/gpu/arm/bifrost/platform/rk/Kbuild +++ b/drivers/gpu/arm/bifrost/platform/rk/Kbuild @@ -13,5 +13,4 @@ # bifrost_kbase-y += \ - $(MALI_PLATFORM_DIR)/mali_kbase_config_rk.o \ - + platform/$(MALI_PLATFORM_DIR)/mali_kbase_config_rk.o diff --git a/drivers/gpu/arm/bifrost/platform/vexpress/Kbuild b/drivers/gpu/arm/bifrost/platform/vexpress/Kbuild index c1646478a9dc..e1398fde3976 100644 --- a/drivers/gpu/arm/bifrost/platform/vexpress/Kbuild +++ b/drivers/gpu/arm/bifrost/platform/vexpress/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2012-2013, 2016-2017, 2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2012-2013, 2016-2017, 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -19,5 +19,5 @@ # bifrost_kbase-y += \ - $(MALI_PLATFORM_DIR)/mali_kbase_config_vexpress.o \ - mali_kbase_platform_fake.o + platform/$(MALI_PLATFORM_DIR)/mali_kbase_config_vexpress.o \ + mali_kbase_platform_fake.o diff --git a/drivers/gpu/arm/bifrost/platform/vexpress/mali_kbase_config_platform.h b/drivers/gpu/arm/bifrost/platform/vexpress/mali_kbase_config_platform.h index 97fdd13f22fb..d8682db25f2b 100644 --- a/drivers/gpu/arm/bifrost/platform/vexpress/mali_kbase_config_platform.h +++ b/drivers/gpu/arm/bifrost/platform/vexpress/mali_kbase_config_platform.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014-2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/platform/vexpress/mali_kbase_config_vexpress.c b/drivers/gpu/arm/bifrost/platform/vexpress/mali_kbase_config_vexpress.c index 181681797030..8add708d0f8a 100644 --- a/drivers/gpu/arm/bifrost/platform/vexpress/mali_kbase_config_vexpress.c +++ b/drivers/gpu/arm/bifrost/platform/vexpress/mali_kbase_config_vexpress.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2011-2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2011-2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -25,6 +25,8 @@ #include #include "mali_kbase_config_platform.h" +#include + #ifndef CONFIG_OF static struct kbase_io_resources io_resources = { .job_irq_number = 68, @@ -64,3 +66,14 @@ struct kbase_platform_config *kbase_get_platform_config(void) { return &versatile_platform_config; } + +#ifdef CONFIG_MALI_BIFROST_DVFS +#if MALI_USE_CSF +int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation) +#else +int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation, u32 util_gl_share, u32 util_cl_share[2]) +#endif +{ + return 1; +} +#endif /* CONFIG_MALI_BIFROST_DVFS */ diff --git a/drivers/gpu/arm/bifrost/platform/vexpress_1xv7_a57/Kbuild b/drivers/gpu/arm/bifrost/platform/vexpress_1xv7_a57/Kbuild index 51ac81b1f189..e1398fde3976 100644 --- a/drivers/gpu/arm/bifrost/platform/vexpress_1xv7_a57/Kbuild +++ b/drivers/gpu/arm/bifrost/platform/vexpress_1xv7_a57/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2013-2014, 2016-2017, 2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2012-2013, 2016-2017, 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -19,5 +19,5 @@ # bifrost_kbase-y += \ - $(MALI_PLATFORM_DIR)/mali_kbase_config_vexpress.o \ - mali_kbase_platform_fake.o + platform/$(MALI_PLATFORM_DIR)/mali_kbase_config_vexpress.o \ + mali_kbase_platform_fake.o diff --git a/drivers/gpu/arm/bifrost/platform/vexpress_1xv7_a57/mali_kbase_config_platform.h b/drivers/gpu/arm/bifrost/platform/vexpress_1xv7_a57/mali_kbase_config_platform.h index 97fdd13f22fb..d8682db25f2b 100644 --- a/drivers/gpu/arm/bifrost/platform/vexpress_1xv7_a57/mali_kbase_config_platform.h +++ b/drivers/gpu/arm/bifrost/platform/vexpress_1xv7_a57/mali_kbase_config_platform.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014-2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/platform/vexpress_1xv7_a57/mali_kbase_config_vexpress.c b/drivers/gpu/arm/bifrost/platform/vexpress_1xv7_a57/mali_kbase_config_vexpress.c index 3bb5caf1bbf6..835b7587cfbf 100644 --- a/drivers/gpu/arm/bifrost/platform/vexpress_1xv7_a57/mali_kbase_config_vexpress.c +++ b/drivers/gpu/arm/bifrost/platform/vexpress_1xv7_a57/mali_kbase_config_vexpress.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2011-2014, 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2011-2014, 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -24,6 +24,8 @@ #include #include +#include + #ifndef CONFIG_OF static struct kbase_io_resources io_resources = { .job_irq_number = 68, @@ -62,3 +64,14 @@ struct kbase_platform_config *kbase_get_platform_config(void) { return &versatile_platform_config; } + +#ifdef CONFIG_MALI_BIFROST_DVFS +#if MALI_USE_CSF +int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation) +#else +int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation, u32 util_gl_share, u32 util_cl_share[2]) +#endif +{ + return 1; +} +#endif /* CONFIG_MALI_BIFROST_DVFS */ diff --git a/drivers/gpu/arm/bifrost/platform/vexpress_6xvirtex7_10mhz/Kbuild b/drivers/gpu/arm/bifrost/platform/vexpress_6xvirtex7_10mhz/Kbuild index 0000b6d8307c..10f7dc8cf22c 100644 --- a/drivers/gpu/arm/bifrost/platform/vexpress_6xvirtex7_10mhz/Kbuild +++ b/drivers/gpu/arm/bifrost/platform/vexpress_6xvirtex7_10mhz/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2012-2013, 2016-2017 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2012-2013, 2016-2017, 2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -19,6 +19,6 @@ # bifrost_kbase-y += \ - $(MALI_PLATFORM_DIR)/mali_kbase_config_vexpress.o \ - $(MALI_PLATFORM_DIR)/mali_kbase_cpu_vexpress.o \ - mali_kbase_platform_fake.o + platform/$(MALI_PLATFORM_DIR)/mali_kbase_config_vexpress.o \ + platform/$(MALI_PLATFORM_DIR)/mali_kbase_cpu_vexpress.o \ + mali_kbase_platform_fake.o diff --git a/drivers/gpu/arm/bifrost/platform/vexpress_6xvirtex7_10mhz/mali_kbase_config_platform.h b/drivers/gpu/arm/bifrost/platform/vexpress_6xvirtex7_10mhz/mali_kbase_config_platform.h index 97fdd13f22fb..d8682db25f2b 100644 --- a/drivers/gpu/arm/bifrost/platform/vexpress_6xvirtex7_10mhz/mali_kbase_config_platform.h +++ b/drivers/gpu/arm/bifrost/platform/vexpress_6xvirtex7_10mhz/mali_kbase_config_platform.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014-2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014-2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/platform/vexpress_6xvirtex7_10mhz/mali_kbase_config_vexpress.c b/drivers/gpu/arm/bifrost/platform/vexpress_6xvirtex7_10mhz/mali_kbase_config_vexpress.c index a7a842abf2d1..8be30fb25bba 100644 --- a/drivers/gpu/arm/bifrost/platform/vexpress_6xvirtex7_10mhz/mali_kbase_config_vexpress.c +++ b/drivers/gpu/arm/bifrost/platform/vexpress_6xvirtex7_10mhz/mali_kbase_config_vexpress.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2011-2014, 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2011-2014, 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -24,6 +24,8 @@ #include #include +#include + #ifndef CONFIG_OF static struct kbase_io_resources io_resources = { .job_irq_number = 75, @@ -62,3 +64,14 @@ struct kbase_platform_config *kbase_get_platform_config(void) { return &versatile_platform_config; } + +#ifdef CONFIG_MALI_BIFROST_DVFS +#if MALI_USE_CSF +int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation) +#else +int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation, u32 util_gl_share, u32 util_cl_share[2]) +#endif +{ + return 1; +} +#endif /* CONFIG_MALI_BIFROST_DVFS */ diff --git a/drivers/gpu/arm/bifrost/protected_mode_switcher.h b/drivers/gpu/arm/bifrost/protected_mode_switcher.h index d9bab5622f4b..9dd9253c7e95 100644 --- a/drivers/gpu/arm/bifrost/protected_mode_switcher.h +++ b/drivers/gpu/arm/bifrost/protected_mode_switcher.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2017, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/tests/Kbuild b/drivers/gpu/arm/bifrost/tests/Kbuild index cf9d7fdc9b17..ee3de7b00652 100644 --- a/drivers/gpu/arm/bifrost/tests/Kbuild +++ b/drivers/gpu/arm/bifrost/tests/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2017, 2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2017, 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -18,6 +18,13 @@ # # +ccflags-y += -I$(src)/include \ + -I$(src) + +subdir-ccflags-y += -I$(src)/include \ + -I$(src) + obj-$(CONFIG_MALI_KUTF) += kutf/ -obj-$(CONFIG_MALI_IRQ_LATENCY) += mali_kutf_irq_test/ -obj-$(CONFIG_MALI_CLK_RATE_TRACE_PORTAL) += mali_kutf_clk_rate_trace/kernel/ +obj-$(CONFIG_MALI_KUTF_IRQ_TEST) += mali_kutf_irq_test/ +obj-$(CONFIG_MALI_KUTF_CLK_RATE_TRACE) += mali_kutf_clk_rate_trace/kernel/ + diff --git a/drivers/gpu/arm/bifrost/tests/Kconfig b/drivers/gpu/arm/bifrost/tests/Kconfig index cf2a23a7df11..820f11e65d87 100644 --- a/drivers/gpu/arm/bifrost/tests/Kconfig +++ b/drivers/gpu/arm/bifrost/tests/Kconfig @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2017, 2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2017, 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -18,6 +18,40 @@ # # -source "drivers/gpu/arm/midgard/tests/kutf/Kconfig" -source "drivers/gpu/arm/midgard/tests/mali_kutf_irq_test/Kconfig" -source "drivers/gpu/arm/midgard/tests/mali_kutf_clk_rate_trace/kernel/Kconfig" +menuconfig MALI_KUTF + bool "Build Mali Kernel Unit Test Framework modules" + depends on MALI_BIFROST && MALI_BIFROST_DEBUG + default y if MALI_BIFROST_DEBUG + help + This option will build the Mali testing framework modules. + + Modules: + - kutf.ko + - kutf_test.ko + +config MALI_KUTF_IRQ_TEST + bool "Build Mali KUTF IRQ test module" + depends on MALI_KUTF + default y + help + This option will build the IRQ latency measurement test module. + It can determine the latency of the Mali GPU IRQ on your system. + + Modules: + - mali_kutf_irq_test.ko + +config MALI_KUTF_CLK_RATE_TRACE + bool "Build Mali KUTF Clock rate trace test module" + depends on MALI_KUTF + default y + help + This option will build the clock rate trace portal test module. + It can test the clocks integration into the platform and exercise some + basic trace test in the system. + + Modules: + - mali_kutf_clk_rate_trace_test_portal.ko + + +comment "Enable MALI_BIFROST_DEBUG for KUTF modules support" + depends on MALI_BIFROST && !MALI_BIFROST_DEBUG && MALI_KUTF diff --git a/drivers/gpu/arm/bifrost/tests/Mconfig b/drivers/gpu/arm/bifrost/tests/Mconfig index e9313ef14fd1..f5fdeffe9b3c 100644 --- a/drivers/gpu/arm/bifrost/tests/Mconfig +++ b/drivers/gpu/arm/bifrost/tests/Mconfig @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # # (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. # @@ -18,32 +18,44 @@ # # +menuconfig MALI_KUTF + bool "Build Mali Kernel Unit Test Framework modules" + depends on MALI_BIFROST && MALI_BIFROST_DEBUG + default y if BACKEND_KERNEL && MALI_BIFROST_DEBUG + help + This option will build the Mali testing framework modules. + + Modules: + - kutf.ko + - kutf_test.ko + +config MALI_KUTF_IRQ_TEST + bool "Build Mali KUTF IRQ test module" + depends on MALI_KUTF + default y + help + This option will build the IRQ latency measurement test module. + It can determine the latency of the Mali GPU IRQ on your system. + + Modules: + - mali_kutf_irq_test.ko + +config MALI_KUTF_CLK_RATE_TRACE + bool "Build Mali KUTF Clock rate trace test module" + depends on MALI_KUTF + default y + help + This option will build the clock rate trace portal test module. + It can test the clocks integration into the platform and exercise some + basic trace test in the system. + + Modules: + - mali_kutf_clk_rate_trace_test_portal.ko + + +# Enable MALI_BIFROST_DEBUG for KUTF modules support + config UNIT_TEST_KERNEL_MODULES - bool - default y if UNIT_TEST_CODE && BACKEND_KERNEL - default n - -config BUILD_IPA_TESTS - bool - default y if UNIT_TEST_KERNEL_MODULES && MALI_BIFROST_DEVFREQ - default n - -config BUILD_IPA_UNIT_TESTS - bool - default y if NO_MALI && BUILD_IPA_TESTS - default n - -config BUILD_CSF_TESTS - bool - default y if UNIT_TEST_KERNEL_MODULES && GPU_HAS_CSF - default n - -config BUILD_ARBIF_TESTS - bool - default y if UNIT_TEST_CODE && MALI_ARBITER_SUPPORT - default n - -config BUILD_ARBIF_KERNEL_TESTS - bool - default y if BUILD_KERNEL_MODULES && BUILD_ARBIF_TESTS - default n + bool + default y if UNIT_TEST_CODE && BACKEND_KERNEL + default n diff --git a/drivers/gpu/arm/bifrost/tests/build.bp b/drivers/gpu/arm/bifrost/tests/build.bp new file mode 100644 index 000000000000..9d6137d17d5f --- /dev/null +++ b/drivers/gpu/arm/bifrost/tests/build.bp @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * + * (C) COPYRIGHT 2021 ARM Limited. All rights reserved. + * + * This program is free software and is provided to you under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation, and any use by you of this program is subject to the terms + * of such GNU license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you can access it online at + * http://www.gnu.org/licenses/gpl-2.0.html. + * + */ + +bob_defaults { + name: "kernel_test_includes", + local_include_dirs: [ + "include", + "./../../", + "./../", + "./" + ], +} + +bob_defaults { + name: "kernel_test_configs", + mali_kutf: { + kbuild_options: ["CONFIG_MALI_KUTF=y"], + }, + unit_test_kernel_modules: { + kbuild_options: ["CONFIG_UNIT_TEST_KERNEL_MODULES=y"], + }, +} diff --git a/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_helpers.h b/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_helpers.h index 3b8613a06f68..c4c713c838cf 100644 --- a/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_helpers.h +++ b/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_helpers.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_helpers_user.h b/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_helpers_user.h index 49aad2921327..e147cbb90154 100644 --- a/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_helpers_user.h +++ b/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_helpers_user.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_mem.h b/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_mem.h index 47c4beacf12f..5d4d96ef39b1 100644 --- a/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_mem.h +++ b/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_mem.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014, 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014, 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_resultset.h b/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_resultset.h index 1f2dcfab49ec..2fb1a47a59b4 100644 --- a/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_resultset.h +++ b/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_resultset.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014, 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014, 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_suite.h b/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_suite.h index 426e435a2c67..b9c333be8f63 100644 --- a/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_suite.h +++ b/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_suite.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014, 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014, 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_utils.h b/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_utils.h index e5e2f02621df..18dcc3dc25f9 100644 --- a/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_utils.h +++ b/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_utils.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2014, 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014, 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/tests/kutf/Kbuild b/drivers/gpu/arm/bifrost/tests/kutf/Kbuild index bd6540c5006e..c4790bc66c23 100644 --- a/drivers/gpu/arm/bifrost/tests/kutf/Kbuild +++ b/drivers/gpu/arm/bifrost/tests/kutf/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2017, 2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2017, 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -18,8 +18,14 @@ # # -ccflags-y += -I$(src)/../include +ifeq ($(CONFIG_MALI_KUTF),y) +obj-m += kutf.o -obj-$(CONFIG_MALI_KUTF) += kutf.o - -kutf-y := kutf_mem.o kutf_resultset.o kutf_suite.o kutf_utils.o kutf_helpers.o kutf_helpers_user.o +kutf-y := \ + kutf_mem.o \ + kutf_resultset.o \ + kutf_suite.o \ + kutf_utils.o \ + kutf_helpers.o \ + kutf_helpers_user.o +endif diff --git a/drivers/gpu/arm/bifrost/tests/kutf/build.bp b/drivers/gpu/arm/bifrost/tests/kutf/build.bp index 707a0531b3b9..89edae9c5e6f 100644 --- a/drivers/gpu/arm/bifrost/tests/kutf/build.bp +++ b/drivers/gpu/arm/bifrost/tests/kutf/build.bp @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2018-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -22,8 +22,9 @@ bob_kernel_module { name: "kutf", defaults: [ - "kernel_defaults", - "kutf_includes", + "mali_kbase_shared_config_defaults", + "kernel_test_configs", + "kernel_test_includes", ], srcs: [ "Kbuild", @@ -34,9 +35,8 @@ bob_kernel_module { "kutf_suite.c", "kutf_utils.c", ], - kbuild_options: ["CONFIG_MALI_KUTF=m"], enabled: false, - base_build_kutf: { + mali_kutf: { enabled: true, }, } diff --git a/drivers/gpu/arm/bifrost/tests/kutf/kutf_helpers.c b/drivers/gpu/arm/bifrost/tests/kutf/kutf_helpers.c index 13923fa3121f..c07542819a01 100644 --- a/drivers/gpu/arm/bifrost/tests/kutf/kutf_helpers.c +++ b/drivers/gpu/arm/bifrost/tests/kutf/kutf_helpers.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/tests/kutf/kutf_helpers_user.c b/drivers/gpu/arm/bifrost/tests/kutf/kutf_helpers_user.c index 84c63be0bed7..a8b59f71c992 100644 --- a/drivers/gpu/arm/bifrost/tests/kutf/kutf_helpers_user.c +++ b/drivers/gpu/arm/bifrost/tests/kutf/kutf_helpers_user.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/tests/kutf/kutf_mem.c b/drivers/gpu/arm/bifrost/tests/kutf/kutf_mem.c index b005b683474c..716970abb8c4 100644 --- a/drivers/gpu/arm/bifrost/tests/kutf/kutf_mem.c +++ b/drivers/gpu/arm/bifrost/tests/kutf/kutf_mem.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2014, 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014, 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/tests/kutf/kutf_resultset.c b/drivers/gpu/arm/bifrost/tests/kutf/kutf_resultset.c index 1eea08c38a85..c7572bde67ae 100644 --- a/drivers/gpu/arm/bifrost/tests/kutf/kutf_resultset.c +++ b/drivers/gpu/arm/bifrost/tests/kutf/kutf_resultset.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2014, 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014, 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/tests/kutf/kutf_suite.c b/drivers/gpu/arm/bifrost/tests/kutf/kutf_suite.c index 4b1dde455e8e..67452995c1fd 100644 --- a/drivers/gpu/arm/bifrost/tests/kutf/kutf_suite.c +++ b/drivers/gpu/arm/bifrost/tests/kutf/kutf_suite.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2014, 2017-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014, 2017-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -1158,7 +1158,7 @@ void kutf_test_abort(struct kutf_context *context) } EXPORT_SYMBOL(kutf_test_abort); -#ifdef CONFIG_DEBUG_FS +#if IS_ENABLED(CONFIG_DEBUG_FS) /** * init_kutf_core() - Module entry point. diff --git a/drivers/gpu/arm/bifrost/tests/kutf/kutf_utils.c b/drivers/gpu/arm/bifrost/tests/kutf/kutf_utils.c index f0dad1f68ffb..c0fb3ba4c10f 100644 --- a/drivers/gpu/arm/bifrost/tests/kutf/kutf_utils.c +++ b/drivers/gpu/arm/bifrost/tests/kutf/kutf_utils.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2014, 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2014, 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/Kbuild b/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/Kbuild index 00b2a41607e1..027bc27c9d3c 100644 --- a/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/Kbuild +++ b/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -18,8 +18,8 @@ # # -ccflags-y += -I$(src)/../include -I$(src)/../../../ -I$(src)/../../ -I$(src)/../../backend/gpu -I$(srctree)/drivers/staging/android - -obj-$(CONFIG_MALI_CLK_RATE_TRACE_PORTAL) += mali_kutf_clk_rate_trace_test_portal.o +ifeq ($(CONFIG_MALI_KUTF_CLK_RATE_TRACE),y) +obj-m += mali_kutf_clk_rate_trace_test_portal.o mali_kutf_clk_rate_trace_test_portal-y := mali_kutf_clk_rate_trace_test.o +endif diff --git a/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/Kconfig b/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/Kconfig deleted file mode 100644 index 17081ba0f6cf..000000000000 --- a/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/Kconfig +++ /dev/null @@ -1,29 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# (C) COPYRIGHT 2020 ARM Limited. All rights reserved. -# -# This program is free software and is provided to you under the terms of the -# GNU General Public License version 2 as published by the Free Software -# Foundation, and any use by you of this program is subject to the terms -# of such GNU license. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, you can access it online at -# http://www.gnu.org/licenses/gpl-2.0.html. -# -# - -config CONFIG_MALI_CLK_RATE_TRACE_PORTAL - tristate "Mali GPU Clock Trace Test portal" - depends on MALI_BIFROST && MALI_BIFROST_DEBUG && MALI_KUTF - default m - help - This option will build a test module mali_kutf_clk_rate_trace_test_portal - that can test the clocks integration into the platform and exercise some - basic trace test in the system. Choosing M here will generate a single - module called mali_kutf_clk_rate_trace_test_portal. diff --git a/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/Makefile b/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/Makefile deleted file mode 100644 index 950acd89b267..000000000000 --- a/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/Makefile +++ /dev/null @@ -1,56 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# (C) COPYRIGHT 2020 ARM Limited. All rights reserved. -# -# This program is free software and is provided to you under the terms of the -# GNU General Public License version 2 as published by the Free Software -# Foundation, and any use by you of this program is subject to the terms -# of such GNU license. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, you can access it online at -# http://www.gnu.org/licenses/gpl-2.0.html. -# -# - -ifneq ($(KERNELRELEASE),) - -ccflags-y := \ - -DMALI_UNIT_TEST=$(MALI_UNIT_TEST) \ - -DMALI_CUSTOMER_RELEASE=$(MALI_CUSTOMER_RELEASE) \ - -I$(src)/../../include \ - -I$(src)/../../../../../../../include \ - -I$(src)/../../../../ \ - -I$(src)/../../../ \ - -I$(src)/../../../backend/gpu \ - -I$(src)/../../../debug \ - -I$(src)/../../../debug/backend \ - -I$(src)/ \ - -I$(srctree)/drivers/staging/android \ - -I$(srctree)/include/linux - -obj-m := mali_kutf_clk_rate_trace_test_portal.o -mali_kutf_clk_rate_trace_test_portal-y := mali_kutf_clk_rate_trace_test.o - -else -# linux build system bootstrap for out-of-tree module - -# default to building for the host -ARCH ?= $(shell uname -m) - -ifeq ($(KDIR),) -$(error Must specify KDIR to point to the kernel to target)) -endif - -all: - $(MAKE) ARCH=$(ARCH) -C $(KDIR) M=$(CURDIR) KBUILD_EXTRA_SYMBOLS="$(CURDIR)/../../kutf/Module.symvers $(CURDIR)/../../../Module.symvers" modules - -clean: - $(MAKE) ARCH=$(ARCH) -C $(KDIR) M=$(CURDIR) clean - -endif diff --git a/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/build.bp b/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/build.bp index c16b3dea0918..225ad69c5042 100644 --- a/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/build.bp +++ b/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/build.bp @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -23,20 +23,21 @@ bob_kernel_module { name: "mali_kutf_clk_rate_trace_test_portal", defaults: [ "mali_kbase_shared_config_defaults", + "kernel_test_configs", "kernel_test_includes", ], srcs: [ - "../mali_kutf_clk_rate_trace_test.h", - "Makefile", + "Kbuild", "mali_kutf_clk_rate_trace_test.c", + "../mali_kutf_clk_rate_trace_test.h", ], extra_symbols: [ "mali_kbase", "kutf", ], enabled: false, - base_build_kutf: { + mali_kutf_clk_rate_trace: { + kbuild_options: ["CONFIG_MALI_KUTF_CLK_RATE_TRACE=y"], enabled: true, - kbuild_options: ["CONFIG_MALI_CLK_RATE_TRACE_PORTAL=m"], }, } diff --git a/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/mali_kutf_clk_rate_trace_test.c b/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/mali_kutf_clk_rate_trace_test.c index bd091fa6bc8f..f9410a5d342a 100644 --- a/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/mali_kutf_clk_rate_trace_test.c +++ b/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/kernel/mali_kutf_clk_rate_trace_test.c @@ -1,7 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -32,9 +32,9 @@ #include #endif #include "mali_kbase.h" -#include "mali_kbase_irq_internal.h" -#include "mali_kbase_pm_internal.h" -#include "mali_kbase_clk_rate_trace_mgr.h" +#include "backend/gpu/mali_kbase_irq_internal.h" +#include "backend/gpu/mali_kbase_pm_internal.h" +#include "backend/gpu/mali_kbase_clk_rate_trace_mgr.h" #include #include @@ -114,14 +114,15 @@ struct kbasep_cmd_name_pair { }; struct kbasep_cmd_name_pair kbasep_portal_cmd_name_map[] = { - {PORTAL_CMD_GET_CLK_RATE_MGR, GET_CLK_RATE_MGR}, - {PORTAL_CMD_GET_CLK_RATE_TRACE, GET_CLK_RATE_TRACE}, - {PORTAL_CMD_GET_TRACE_SNAPSHOT, GET_TRACE_SNAPSHOT}, - {PORTAL_CMD_INC_PM_CTX_CNT, INC_PM_CTX_CNT}, - {PORTAL_CMD_DEC_PM_CTX_CNT, DEC_PM_CTX_CNT}, - {PORTAL_CMD_CLOSE_PORTAL, CLOSE_PORTAL}, - {PORTAL_CMD_INVOKE_NOTIFY_42KHZ, INVOKE_NOTIFY_42KHZ}, - }; + { PORTAL_CMD_GET_PLATFORM, GET_PLATFORM }, + { PORTAL_CMD_GET_CLK_RATE_MGR, GET_CLK_RATE_MGR }, + { PORTAL_CMD_GET_CLK_RATE_TRACE, GET_CLK_RATE_TRACE }, + { PORTAL_CMD_GET_TRACE_SNAPSHOT, GET_TRACE_SNAPSHOT }, + { PORTAL_CMD_INC_PM_CTX_CNT, INC_PM_CTX_CNT }, + { PORTAL_CMD_DEC_PM_CTX_CNT, DEC_PM_CTX_CNT }, + { PORTAL_CMD_CLOSE_PORTAL, CLOSE_PORTAL }, + { PORTAL_CMD_INVOKE_NOTIFY_42KHZ, INVOKE_NOTIFY_42KHZ }, +}; /* Global pointer for the kutf_portal_trace_write() to use. When * this pointer is engaged, new requests for create fixture will fail @@ -137,8 +138,16 @@ static void kutf_portal_trace_write( u32 index, u32 new_rate) { struct clk_trace_snapshot *snapshot; - struct kutf_clk_rate_trace_fixture_data *data = container_of( - listener, struct kutf_clk_rate_trace_fixture_data, listener); + struct kutf_clk_rate_trace_fixture_data *data; + + if (listener == NULL) { + pr_err("%s - index: %u, new_rate: %u, listener is NULL\n", + __func__, index, new_rate); + return; + } + + data = container_of(listener, struct kutf_clk_rate_trace_fixture_data, + listener); lockdep_assert_held(&data->kbdev->pm.clk_rtm.lock); @@ -180,11 +189,10 @@ static void kutf_set_pm_ctx_idle(struct kutf_context *context) if (WARN_ON(data->pm_ctx_cnt > 0)) return; - - kbase_pm_context_idle(data->kbdev); #if !MALI_USE_CSF kbase_pm_release_gpu_cycle_counter(data->kbdev); #endif + kbase_pm_context_idle(data->kbdev); } static char const *kutf_clk_trace_do_change_pm_ctx(struct kutf_context *context, @@ -408,6 +416,63 @@ static char const *kutf_clk_trace_do_close_portal(struct kutf_context *context, return errmsg; } +/** + * kutf_clk_trace_do_get_platform() - Gets platform information + * @context: KUTF context + * @cmd: The decoded portal input request + * + * Checks the gpu node in the device tree to see if arbitration is enabled + * If so determines device tree whether platform is PV or PTM + * + * Return: A string to indicate the platform (PV/PTM/GPU/UNKNOWN) + */ +static char const *kutf_clk_trace_do_get_platform( + struct kutf_context *context, + struct clk_trace_portal_input *cmd) +{ + int seq = cmd->cmd_input.u.val_u64 & 0xFF; + char const *errmsg = NULL; + const void *arbiter_if_node = NULL; + const void *power_node = NULL; + const char *platform = "GPU"; +#if defined(CONFIG_MALI_ARBITER_SUPPORT) && defined(CONFIG_OF) + struct kutf_clk_rate_trace_fixture_data *data = context->fixture; + + arbiter_if_node = + of_get_property(data->kbdev->dev->of_node, "arbiter_if", NULL); +#endif + if (arbiter_if_node) { + power_node = of_find_compatible_node(NULL, NULL, + "arm,mali-gpu-power"); + if (power_node) { + platform = "PV"; + } else { + power_node = of_find_compatible_node(NULL, NULL, + "arm,mali-ptm"); + if (power_node) + platform = "PTM"; + else + platform = "UNKNOWN"; + } + } else { + platform = "GPU"; + } + + pr_debug("%s - platform is %s\n", __func__, platform); + snprintf(portal_msg_buf, PORTAL_MSG_LEN, + "{SEQ:%d, PLATFORM:%s}", seq, platform); + + WARN_ON(cmd->portal_cmd != PORTAL_CMD_GET_PLATFORM); + + if (kutf_helper_send_named_str(context, "ACK", portal_msg_buf)) { + pr_warn("Error in sending ack for " CLOSE_PORTAL "reuquest\n"); + errmsg = kutf_dsprintf(&context->fixture_pool, + "Error in sending ack for " GET_PLATFORM "request"); + } + + return errmsg; +} + static bool kutf_clk_trace_dequeue_portal_cmd(struct kutf_context *context, struct clk_trace_portal_input *cmd) { @@ -461,6 +526,9 @@ static bool kutf_clk_trace_process_portal_cmd(struct kutf_context *context, WARN_ON(cmd->portal_cmd == PORTAL_CMD_INVALID); switch (cmd->portal_cmd) { + case PORTAL_CMD_GET_PLATFORM: + errmsg = kutf_clk_trace_do_get_platform(context, cmd); + break; case PORTAL_CMD_GET_CLK_RATE_MGR: /* Fall through */ case PORTAL_CMD_GET_CLK_RATE_TRACE: @@ -613,7 +681,7 @@ void kutf_clk_trace_barebone_check(struct kutf_context *context) kutf_clk_trace_flag_result(context, KUTF_RESULT_FAIL, msg); else if (!data->total_update_cnt) { msg = kutf_dsprintf(&context->fixture_pool, - "No trace update seen during the test!"); + "No trace update seen during the test!"); kutf_clk_trace_flag_result(context, KUTF_RESULT_WARN, msg); } } diff --git a/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/mali_kutf_clk_rate_trace_test.h b/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/mali_kutf_clk_rate_trace_test.h index 600b025795df..f37efa8bd376 100644 --- a/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/mali_kutf_clk_rate_trace_test.h +++ b/drivers/gpu/arm/bifrost/tests/mali_kutf_clk_rate_trace/mali_kutf_clk_rate_trace_test.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -30,6 +30,8 @@ * enum kbasep_clk_rate_trace_req - request command to the clock rate trace * service portal. * + * @PORTAL_CMD_GET_PLATFORM: Request the platform that the tests are + * to be run on. * @PORTAL_CMD_GET_CLK_RATE_MGR: Request the clock trace manager internal * data record. On a positive acknowledgement * the prevailing clock rates and the GPU idle @@ -73,6 +75,7 @@ */ /* PORTAL_CMD_INVALID must be the last one, serving the size */ enum kbasep_clk_rate_trace_req { + PORTAL_CMD_GET_PLATFORM, PORTAL_CMD_GET_CLK_RATE_MGR, PORTAL_CMD_GET_CLK_RATE_TRACE, PORTAL_CMD_GET_TRACE_SNAPSHOT, @@ -121,6 +124,7 @@ enum kbasep_clk_rate_trace_req { * Note, at the close, PM_CTX_CNT is 1. The PM_CTX_CNT will internally be * dropped down to 0 as part of the portal close clean up. */ +#define GET_PLATFORM "GET_PLATFORM" #define GET_CLK_RATE_MGR "GET_CLK_RATE_MGR" #define GET_CLK_RATE_TRACE "GET_CLK_RATE_TRACE" #define GET_TRACE_SNAPSHOT "GET_TRACE_SNAPSHOT" diff --git a/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/Kbuild b/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/Kbuild index cc38cb84406c..213d6d5ea317 100644 --- a/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/Kbuild +++ b/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/Kbuild @@ -1,6 +1,6 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note # -# (C) COPYRIGHT 2017, 2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2017, 2020-2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -18,8 +18,8 @@ # # -ccflags-y += -I$(src)/../include -I$(src)/../../../ -I$(src)/../../ -I$(src)/../../backend/gpu -I$(srctree)/drivers/staging/android - -obj-$(CONFIG_MALI_IRQ_LATENCY) += mali_kutf_irq_test.o +ifeq ($(CONFIG_MALI_KUTF_IRQ_TEST),y) +obj-m += mali_kutf_irq_test.o mali_kutf_irq_test-y := mali_kutf_irq_test_main.o +endif diff --git a/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/Kconfig b/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/Kconfig deleted file mode 100644 index 90f4ec0a7c7f..000000000000 --- a/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/Kconfig +++ /dev/null @@ -1,28 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# (C) COPYRIGHT 2017, 2020 ARM Limited. All rights reserved. -# -# This program is free software and is provided to you under the terms of the -# GNU General Public License version 2 as published by the Free Software -# Foundation, and any use by you of this program is subject to the terms -# of such GNU license. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, you can access it online at -# http://www.gnu.org/licenses/gpl-2.0.html. -# -# - -config MALI_IRQ_LATENCY - tristate "Mali GPU IRQ latency measurement" - depends on MALI_BIFROST && MALI_BIFROST_DEBUG && MALI_KUTF - default m - help - This option will build a test module mali_kutf_irq_test that - can determine the latency of the Mali GPU IRQ on your system. - Choosing M here will generate a single module called mali_kutf_irq_test. diff --git a/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/Makefile b/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/Makefile deleted file mode 100644 index cbec0d3ce8ca..000000000000 --- a/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# (C) COPYRIGHT 2015, 2017-2018, 2020 ARM Limited. All rights reserved. -# -# This program is free software and is provided to you under the terms of the -# GNU General Public License version 2 as published by the Free Software -# Foundation, and any use by you of this program is subject to the terms -# of such GNU license. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, you can access it online at -# http://www.gnu.org/licenses/gpl-2.0.html. -# -# - -# linux build system bootstrap for out-of-tree module - -# default to building for the host -ARCH ?= $(shell uname -m) - -ifeq ($(KDIR),) -$(error Must specify KDIR to point to the kernel to target)) -endif - -TEST_CCFLAGS := \ - -DMALI_UNIT_TEST=$(MALI_UNIT_TEST) \ - -DMALI_CUSTOMER_RELEASE=$(MALI_CUSTOMER_RELEASE) \ - -DMALI_USE_CSF=$(MALI_USE_CSF) \ - $(SCONS_CFLAGS) \ - -I$(CURDIR)/../include \ - -I$(CURDIR)/../../../../../../include \ - -I$(CURDIR)/../../../ \ - -I$(CURDIR)/../../ \ - -I$(CURDIR)/../../backend/gpu \ - -I$(CURDIR)/../../debug \ - -I$(CURDIR)/../../debug/backend \ - -I$(CURDIR)/ \ - -I$(srctree)/drivers/staging/android \ - -I$(srctree)/include/linux - -all: - $(MAKE) ARCH=$(ARCH) -C $(KDIR) M=$(CURDIR) $(SCONS_CONFIGS) EXTRA_CFLAGS="$(TEST_CCFLAGS)" KBUILD_EXTRA_SYMBOLS="$(CURDIR)/../kutf/Module.symvers $(CURDIR)/../../Module.symvers" modules - -clean: - $(MAKE) ARCH=$(ARCH) -C $(KDIR) M=$(CURDIR) clean diff --git a/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/build.bp b/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/build.bp index 58021c80188c..155875b9d5cc 100644 --- a/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/build.bp +++ b/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/build.bp @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2018-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software @@ -23,6 +23,7 @@ bob_kernel_module { name: "mali_kutf_irq_test", defaults: [ "mali_kbase_shared_config_defaults", + "kernel_test_configs", "kernel_test_includes", ], srcs: [ @@ -34,8 +35,8 @@ bob_kernel_module { "kutf", ], enabled: false, - base_build_kutf: { + mali_kutf_irq_test: { + kbuild_options: ["CONFIG_MALI_KUTF_IRQ_TEST=y"], enabled: true, - kbuild_options: ["CONFIG_MALI_IRQ_LATENCY=m"], }, } diff --git a/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/mali_kutf_irq_test_main.c b/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/mali_kutf_irq_test_main.c index e9f276ec4f92..fdc543790a4f 100644 --- a/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/mali_kutf_irq_test_main.c +++ b/drivers/gpu/arm/bifrost/tests/mali_kutf_irq_test/mali_kutf_irq_test_main.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2016-2018, 2020-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/Makefile.kbase b/drivers/gpu/arm/bifrost/thirdparty/Kbuild similarity index 82% rename from drivers/gpu/arm/bifrost/Makefile.kbase rename to drivers/gpu/arm/bifrost/thirdparty/Kbuild index 6d97f197670b..558be077d483 100644 --- a/drivers/gpu/arm/bifrost/Makefile.kbase +++ b/drivers/gpu/arm/bifrost/thirdparty/Kbuild @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # -# (C) COPYRIGHT 2010, 2013, 2018-2020 ARM Limited. All rights reserved. +# (C) COPYRIGHT 2021 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the # GNU General Public License version 2 as published by the Free Software @@ -18,4 +18,4 @@ # # -EXTRA_CFLAGS += -I$(ROOT) -I$(KBASE_PATH) -I$(KBASE_PATH)/platform_$(PLATFORM) +bifrost_kbase-y += thirdparty/mali_kbase_mmap.o diff --git a/drivers/gpu/arm/bifrost/thirdparty/mali_kbase_mmap.c b/drivers/gpu/arm/bifrost/thirdparty/mali_kbase_mmap.c index a3b4a74ba94a..de1199a76b19 100644 --- a/drivers/gpu/arm/bifrost/thirdparty/mali_kbase_mmap.c +++ b/drivers/gpu/arm/bifrost/thirdparty/mali_kbase_mmap.c @@ -10,7 +10,7 @@ */ #include "linux/mman.h" -#include "../mali_kbase.h" +#include /* mali_kbase_mmap.c * @@ -275,7 +275,7 @@ unsigned long kbase_context_get_unmapped_area(struct kbase_context *const kctx, if ((flags & MAP_FIXED) || addr) return -EINVAL; -#ifdef CONFIG_64BIT +#if IS_ENABLED(CONFIG_64BIT) /* too big? */ if (len > TASK_SIZE - SZ_2M) return -ENOMEM; diff --git a/drivers/gpu/arm/bifrost/tl/Kbuild b/drivers/gpu/arm/bifrost/tl/Kbuild new file mode 100644 index 000000000000..6e472dff8a78 --- /dev/null +++ b/drivers/gpu/arm/bifrost/tl/Kbuild @@ -0,0 +1,32 @@ +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note +# +# (C) COPYRIGHT 2021 ARM Limited. All rights reserved. +# +# This program is free software and is provided to you under the terms of the +# GNU General Public License version 2 as published by the Free Software +# Foundation, and any use by you of this program is subject to the terms +# of such GNU license. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you can access it online at +# http://www.gnu.org/licenses/gpl-2.0.html. +# +# + +bifrost_kbase-y += \ + tl/mali_kbase_timeline.o \ + tl/mali_kbase_timeline_io.o \ + tl/mali_kbase_tlstream.o \ + tl/mali_kbase_tracepoints.o + + +ifeq ($(CONFIG_MALI_CSF_SUPPORT),y) + bifrost_kbase-y += tl/backend/mali_kbase_timeline_csf.o +else + bifrost_kbase-y += tl/backend/mali_kbase_timeline_jm.o +endif diff --git a/drivers/gpu/arm/bifrost/tl/backend/mali_kbase_timeline_csf.c b/drivers/gpu/arm/bifrost/tl/backend/mali_kbase_timeline_csf.c index 7455ce28843d..a2868daea18a 100644 --- a/drivers/gpu/arm/bifrost/tl/backend/mali_kbase_timeline_csf.c +++ b/drivers/gpu/arm/bifrost/tl/backend/mali_kbase_timeline_csf.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -19,9 +19,9 @@ * */ -#include "../mali_kbase_tracepoints.h" -#include "../mali_kbase_timeline.h" -#include "../mali_kbase_timeline_priv.h" +#include +#include +#include #include diff --git a/drivers/gpu/arm/bifrost/tl/backend/mali_kbase_timeline_jm.c b/drivers/gpu/arm/bifrost/tl/backend/mali_kbase_timeline_jm.c index 6659d2dc2eb0..9ba89f59f03b 100644 --- a/drivers/gpu/arm/bifrost/tl/backend/mali_kbase_timeline_jm.c +++ b/drivers/gpu/arm/bifrost/tl/backend/mali_kbase_timeline_jm.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. @@ -19,9 +19,9 @@ * */ -#include "../mali_kbase_tracepoints.h" -#include "../mali_kbase_timeline.h" -#include "../mali_kbase_timeline_priv.h" +#include +#include +#include #include diff --git a/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline.c b/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline.c index 3370343f8020..dfafbccecfed 100644 --- a/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline.c +++ b/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2015-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline.h b/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline.h index 04653521285d..63926ebc63a5 100644 --- a/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline.h +++ b/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2015-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline_io.c b/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline_io.c index e3b6fbc1eaeb..eff30a07c17d 100644 --- a/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline_io.c +++ b/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline_io.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline_priv.h b/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline_priv.h index 8a58a13a78ea..bf2c3855434a 100644 --- a/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline_priv.h +++ b/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline_priv.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/tl/mali_kbase_tl_serialize.h b/drivers/gpu/arm/bifrost/tl/mali_kbase_tl_serialize.h index f8cad4a6f8f8..30d120d7599f 100644 --- a/drivers/gpu/arm/bifrost/tl/mali_kbase_tl_serialize.h +++ b/drivers/gpu/arm/bifrost/tl/mali_kbase_tl_serialize.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/drivers/gpu/arm/bifrost/tl/mali_kbase_tlstream.c b/drivers/gpu/arm/bifrost/tl/mali_kbase_tlstream.c index 202c12f57572..0275bad60410 100644 --- a/drivers/gpu/arm/bifrost/tl/mali_kbase_tlstream.c +++ b/drivers/gpu/arm/bifrost/tl/mali_kbase_tlstream.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2015-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/tl/mali_kbase_tlstream.h b/drivers/gpu/arm/bifrost/tl/mali_kbase_tlstream.h index 2d3bbc8ccac9..6660cf5bc276 100644 --- a/drivers/gpu/arm/bifrost/tl/mali_kbase_tlstream.h +++ b/drivers/gpu/arm/bifrost/tl/mali_kbase_tlstream.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2015-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/tl/mali_kbase_tracepoints.c b/drivers/gpu/arm/bifrost/tl/mali_kbase_tracepoints.c index ece23b318b31..2c0de0196f44 100644 --- a/drivers/gpu/arm/bifrost/tl/mali_kbase_tracepoints.c +++ b/drivers/gpu/arm/bifrost/tl/mali_kbase_tracepoints.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. diff --git a/drivers/gpu/arm/bifrost/tl/mali_kbase_tracepoints.h b/drivers/gpu/arm/bifrost/tl/mali_kbase_tracepoints.h index 7a8164b06291..05dce2064bd0 100644 --- a/drivers/gpu/arm/bifrost/tl/mali_kbase_tracepoints.h +++ b/drivers/gpu/arm/bifrost/tl/mali_kbase_tracepoints.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved. @@ -1932,7 +1932,7 @@ struct kbase_tlstream; * * @kbdev: Kbase device * @kcpu_queue: KCPU queue - * @cqs_obj_gpu_addr: CQS Object GPU ptr + * @cqs_obj_gpu_addr: CQS Object GPU pointer * @cqs_obj_compare_value: Semaphore value that should be exceeded * for the WAIT to pass * @cqs_obj_inherit_error: Indicates the error state should be inherited into the queue or not @@ -1969,7 +1969,7 @@ struct kbase_tlstream; * * @kbdev: Kbase device * @kcpu_queue: KCPU queue - * @cqs_obj_gpu_addr: CQS Object GPU ptr + * @cqs_obj_gpu_addr: CQS Object GPU pointer */ #if MALI_USE_CSF #define KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_CQS_SET( \ @@ -1999,7 +1999,7 @@ struct kbase_tlstream; * * @kbdev: Kbase device * @kcpu_queue: KCPU queue - * @map_import_buf_gpu_addr: Map import buffer GPU ptr + * @map_import_buf_gpu_addr: Map import buffer GPU pointer */ #if MALI_USE_CSF #define KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_MAP_IMPORT( \ @@ -2029,7 +2029,7 @@ struct kbase_tlstream; * * @kbdev: Kbase device * @kcpu_queue: KCPU queue - * @map_import_buf_gpu_addr: Map import buffer GPU ptr + * @map_import_buf_gpu_addr: Map import buffer GPU pointer */ #if MALI_USE_CSF #define KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_UNMAP_IMPORT( \ @@ -2059,7 +2059,7 @@ struct kbase_tlstream; * * @kbdev: Kbase device * @kcpu_queue: KCPU queue - * @map_import_buf_gpu_addr: Map import buffer GPU ptr + * @map_import_buf_gpu_addr: Map import buffer GPU pointer */ #if MALI_USE_CSF #define KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_UNMAP_IMPORT_FORCE( \ diff --git a/include/linux/dma-buf-test-exporter.h b/include/linux/dma-buf-test-exporter.h new file mode 100644 index 000000000000..5a310f6270cc --- /dev/null +++ b/include/linux/dma-buf-test-exporter.h @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * + * (C) COPYRIGHT 2012-2013, 2017, 2020-2021 ARM Limited. All rights reserved. + * + * This program is free software and is provided to you under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation, and any use by you of this program is subject to the terms + * of such GNU license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you can access it online at + * http://www.gnu.org/licenses/gpl-2.0.html. + * + */ + +#ifndef _LINUX_DMA_BUF_TEST_EXPORTER_H_ +#define _LINUX_DMA_BUF_TEST_EXPORTER_H_ + +#include +#include + +#define DMA_BUF_TE_VER_MAJOR 1 +#define DMA_BUF_TE_VER_MINOR 0 +#define DMA_BUF_TE_ENQ 0x642d7465 +#define DMA_BUF_TE_ACK 0x68692100 + +struct dma_buf_te_ioctl_version +{ + int op; /**< Must be set to DMA_BUF_TE_ENQ by client, driver will set it to DMA_BUF_TE_ACK */ + int major; /**< Major version */ + int minor; /**< Minor version */ +}; + +struct dma_buf_te_ioctl_alloc +{ + __u64 size; /* size of buffer to allocate, in pages */ +}; + +struct dma_buf_te_ioctl_status +{ + /* in */ + int fd; /* the dma_buf to query, only dma_buf objects exported by this driver is supported */ + /* out */ + int attached_devices; /* number of devices attached (active 'dma_buf_attach's) */ + int device_mappings; /* number of device mappings (active 'dma_buf_map_attachment's) */ + int cpu_mappings; /* number of cpu mappings (active 'mmap's) */ +}; + +struct dma_buf_te_ioctl_set_failing +{ + /* in */ + int fd; /* the dma_buf to set failure mode for, only dma_buf objects exported by this driver is supported */ + + /* zero = no fail injection, non-zero = inject failure */ + int fail_attach; + int fail_map; + int fail_mmap; +}; + +struct dma_buf_te_ioctl_fill +{ + int fd; + unsigned int value; +}; + +#define DMA_BUF_TE_IOCTL_BASE 'E' +/* Below all returning 0 if successful or -errcode except DMA_BUF_TE_ALLOC which will return fd or -errcode */ +#define DMA_BUF_TE_VERSION _IOR(DMA_BUF_TE_IOCTL_BASE, 0x00, struct dma_buf_te_ioctl_version) +#define DMA_BUF_TE_ALLOC _IOR(DMA_BUF_TE_IOCTL_BASE, 0x01, struct dma_buf_te_ioctl_alloc) +#define DMA_BUF_TE_QUERY _IOR(DMA_BUF_TE_IOCTL_BASE, 0x02, struct dma_buf_te_ioctl_status) +#define DMA_BUF_TE_SET_FAILING _IOW(DMA_BUF_TE_IOCTL_BASE, 0x03, struct dma_buf_te_ioctl_set_failing) +#define DMA_BUF_TE_ALLOC_CONT _IOR(DMA_BUF_TE_IOCTL_BASE, 0x04, struct dma_buf_te_ioctl_alloc) +#define DMA_BUF_TE_FILL _IOR(DMA_BUF_TE_IOCTL_BASE, 0x05, struct dma_buf_te_ioctl_fill) + +#endif /* _LINUX_DMA_BUF_TEST_EXPORTER_H_ */ diff --git a/include/linux/memory_group_manager.h b/include/linux/memory_group_manager.h index 2045840e1742..c0e808b53b78 100644 --- a/include/linux/memory_group_manager.h +++ b/include/linux/memory_group_manager.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/include/linux/priority_control_manager.h b/include/linux/priority_control_manager.h index df3b3cd07a14..002e78b27423 100644 --- a/include/linux/priority_control_manager.h +++ b/include/linux/priority_control_manager.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved. diff --git a/include/linux/protected_memory_allocator.h b/include/linux/protected_memory_allocator.h index 1ccb403cc0d6..1e05bb8c0207 100644 --- a/include/linux/protected_memory_allocator.h +++ b/include/linux/protected_memory_allocator.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2019-2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/include/linux/protected_mode_switcher.h b/include/linux/protected_mode_switcher.h index d2c7eef764a9..1a3c5f786baa 100644 --- a/include/linux/protected_mode_switcher.h +++ b/include/linux/protected_mode_switcher.h @@ -1,7 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * - * (C) COPYRIGHT 2017, 2020 ARM Limited. All rights reserved. + * (C) COPYRIGHT 2017, 2020-2021 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the * GNU General Public License version 2 as published by the Free Software diff --git a/include/uapi/gpu/arm/bifrost/csf/mali_gpu_csf_registers.h b/include/uapi/gpu/arm/bifrost/csf/mali_gpu_csf_registers.h index d3b43fc2ea7d..06cc4c22de56 100644 --- a/include/uapi/gpu/arm/bifrost/csf/mali_gpu_csf_registers.h +++ b/include/uapi/gpu/arm/bifrost/csf/mali_gpu_csf_registers.h @@ -104,6 +104,12 @@ #define CS_USER_INPUT_HI 0x0034 /* () CS user mode input page address, high word */ #define CS_USER_OUTPUT_LO 0x0038 /* () CS user mode input page address, low word */ #define CS_USER_OUTPUT_HI 0x003C /* () CS user mode input page address, high word */ +#define CS_INSTR_CONFIG 0x0040 /* () Instrumentation buffer configuration */ +#define CS_INSTR_BUFFER_SIZE 0x0044 /* () Instrumentation buffer size */ +#define CS_INSTR_BUFFER_BASE_LO 0x0048 /* () Instrumentation buffer base pointer, low word */ +#define CS_INSTR_BUFFER_BASE_HI 0x004C /* () Instrumentation buffer base pointer, high word */ +#define CS_INSTR_BUFFER_OFFSET_POINTER_LO 0x0050 /* () Instrumentation buffer pointer to insert offset, low word */ +#define CS_INSTR_BUFFER_OFFSET_POINTER_HI 0x0054 /* () Instrumentation buffer pointer to insert offset, high word */ /* CS_KERNEL_OUTPUT_BLOCK register offsets */ #define CS_ACK 0x0000 /* () CS acknowledge flags */ @@ -173,7 +179,8 @@ #define GLB_GROUP_NUM 0x0010 /* () Number of CSG interfaces */ #define GLB_GROUP_STRIDE 0x0014 /* () Stride between CSG interfaces */ #define GLB_PRFCNT_SIZE 0x0018 /* () Size of CSF performance counters */ -#define GLB_INSTR_FEATURES 0x001C /* () TRACE_POINT instrumentation features */ +#define GLB_INSTR_FEATURES \ + 0x001C /* () TRACE_POINT instrumentation. (csf >= 1.1.0) */ #define GROUP_CONTROL_0 0x1000 /* () CSG control and capabilities */ #define GROUP_CONTROL(n) (GROUP_CONTROL_0 + (n)*256) #define GROUP_CONTROL_REG(n, r) (GROUP_CONTROL(n) + GROUP_CONTROL_BLOCK_REG(r)) @@ -417,6 +424,57 @@ #define CS_USER_OUTPUT_POINTER_SET(reg_val, value) \ (((reg_val) & ~CS_USER_OUTPUT_POINTER_MASK) | \ (((value) << CS_USER_OUTPUT_POINTER_SHIFT) & CS_USER_OUTPUT_POINTER_MASK)) + +/* CS_INSTR_CONFIG register */ +#define CS_INSTR_CONFIG_JASID_SHIFT (0) +#define CS_INSTR_CONFIG_JASID_MASK ((u32)0xF << CS_INSTR_CONFIG_JASID_SHIFT) +#define CS_INSTR_CONFIG_JASID_GET(reg_val) (((reg_val)&CS_INSTR_CONFIG_JASID_MASK) >> CS_INSTR_CONFIG_JASID_SHIFT) +#define CS_INSTR_CONFIG_JASID_SET(reg_val, value) \ + (((reg_val) & ~CS_INSTR_CONFIG_JASID_MASK) | \ + (((value) << CS_INSTR_CONFIG_JASID_SHIFT) & CS_INSTR_CONFIG_JASID_MASK)) +#define CS_INSTR_CONFIG_EVENT_SIZE_SHIFT (4) +#define CS_INSTR_CONFIG_EVENT_SIZE_MASK ((u32)0xF << CS_INSTR_CONFIG_EVENT_SIZE_SHIFT) +#define CS_INSTR_CONFIG_EVENT_SIZE_GET(reg_val) \ + (((reg_val)&CS_INSTR_CONFIG_EVENT_SIZE_MASK) >> CS_INSTR_CONFIG_EVENT_SIZE_SHIFT) +#define CS_INSTR_CONFIG_EVENT_SIZE_SET(reg_val, value) \ + (((reg_val) & ~CS_INSTR_CONFIG_EVENT_SIZE_MASK) | \ + (((value) << CS_INSTR_CONFIG_EVENT_SIZE_SHIFT) & CS_INSTR_CONFIG_EVENT_SIZE_MASK)) +#define CS_INSTR_CONFIG_EVENT_STATE_SHIFT (16) +#define CS_INSTR_CONFIG_EVENT_STATE_MASK ((u32)0xFF << CS_INSTR_CONFIG_EVENT_STATE_SHIFT) +#define CS_INSTR_CONFIG_EVENT_STATE_GET(reg_val) \ + (((reg_val)&CS_INSTR_CONFIG_EVENT_STATE_MASK) >> CS_INSTR_CONFIG_EVENT_STATE_SHIFT) +#define CS_INSTR_CONFIG_EVENT_STATE_SET(reg_val, value) \ + (((reg_val) & ~CS_INSTR_CONFIG_EVENT_STATE_MASK) | \ + (((value) << CS_INSTR_CONFIG_EVENT_STATE_SHIFT) & CS_INSTR_CONFIG_EVENT_STATE_MASK)) + +/* CS_INSTR_BUFFER_SIZE register */ +#define CS_INSTR_BUFFER_SIZE_SIZE_SHIFT (0) +#define CS_INSTR_BUFFER_SIZE_SIZE_MASK ((u32)0xFFFFFFFF << CS_INSTR_BUFFER_SIZE_SIZE_SHIFT) +#define CS_INSTR_BUFFER_SIZE_SIZE_GET(reg_val) \ + (((reg_val)&CS_INSTR_BUFFER_SIZE_SIZE_MASK) >> CS_INSTR_BUFFER_SIZE_SIZE_SHIFT) +#define CS_INSTR_BUFFER_SIZE_SIZE_SET(reg_val, value) \ + (((reg_val) & ~CS_INSTR_BUFFER_SIZE_SIZE_MASK) | \ + (((value) << CS_INSTR_BUFFER_SIZE_SIZE_SHIFT) & CS_INSTR_BUFFER_SIZE_SIZE_MASK)) + +/* CS_INSTR_BUFFER_BASE register */ +#define CS_INSTR_BUFFER_BASE_POINTER_SHIFT (0) +#define CS_INSTR_BUFFER_BASE_POINTER_MASK ((u64)0xFFFFFFFFFFFFFFFF << CS_INSTR_BUFFER_BASE_POINTER_SHIFT) +#define CS_INSTR_BUFFER_BASE_POINTER_GET(reg_val) \ + (((reg_val)&CS_INSTR_BUFFER_BASE_POINTER_MASK) >> CS_INSTR_BUFFER_BASE_POINTER_SHIFT) +#define CS_INSTR_BUFFER_BASE_POINTER_SET(reg_val, value) \ + (((reg_val) & ~CS_INSTR_BUFFER_BASE_POINTER_MASK) | \ + (((value) << CS_INSTR_BUFFER_BASE_POINTER_SHIFT) & CS_INSTR_BUFFER_BASE_POINTER_MASK)) + +/* CS_INSTR_BUFFER_OFFSET_POINTER register */ +#define CS_INSTR_BUFFER_OFFSET_POINTER_POINTER_SHIFT (0) +#define CS_INSTR_BUFFER_OFFSET_POINTER_POINTER_MASK \ + ((u64)0xFFFFFFFFFFFFFFFF) << CS_INSTR_BUFFER_OFFSET_POINTER_POINTER_SHIFT) +#define CS_INSTR_BUFFER_OFFSET_POINTER_POINTER_GET(reg_val) \ + (((reg_val)&CS_INSTR_BUFFER_OFFSET_POINTER_POINTER_MASK) >> CS_INSTR_BUFFER_OFFSET_POINTER_POINTER_SHIFT) +#define CS_INSTR_BUFFER_OFFSET_POINTER_POINTER_SET(reg_val, value) \ + (((reg_val) & ~CS_INSTR_BUFFER_OFFSET_POINTER_POINTER_MASK) | \ + (((value) << CS_INSTR_BUFFER_OFFSET_POINTER_POINTER_SHIFT) & CS_INSTR_BUFFER_OFFSET_POINTER_POINTER_MASK)) + /* End of CS_KERNEL_INPUT_BLOCK register set definitions */ /* CS_KERNEL_OUTPUT_BLOCK register set definitions */ @@ -1401,6 +1459,22 @@ #define GLB_IDLE_TIMER_TIMER_SOURCE_GPU_COUNTER 0x1 /* End of GLB_IDLE_TIMER_TIMER_SOURCE values */ +/* GLB_INSTR_FEATURES register */ +#define GLB_INSTR_FEATURES_OFFSET_UPDATE_RATE_SHIFT (0) +#define GLB_INSTR_FEATURES_OFFSET_UPDATE_RATE_MASK ((u32)0xF << GLB_INSTR_FEATURES_OFFSET_UPDATE_RATE_SHIFT) +#define GLB_INSTR_FEATURES_OFFSET_UPDATE_RATE_GET(reg_val) \ + (((reg_val)&GLB_INSTR_FEATURES_OFFSET_UPDATE_RATE_MASK) >> GLB_INSTR_FEATURES_OFFSET_UPDATE_RATE_SHIFT) +#define GLB_INSTR_FEATURES_OFFSET_UPDATE_RATE_SET(reg_val, value) \ + (((reg_val) & ~GLB_INSTR_FEATURES_OFFSET_UPDATE_RATE_MASK) | \ + (((value) << GLB_INSTR_FEATURES_OFFSET_UPDATE_RATE_SHIFT) & GLB_INSTR_FEATURES_OFFSET_UPDATE_RATE_MASK)) +#define GLB_INSTR_FEATURES_EVENT_SIZE_MAX_SHIFT (4) +#define GLB_INSTR_FEATURES_EVENT_SIZE_MAX_MASK ((u32)0xF << GLB_INSTR_FEATURES_EVENT_SIZE_MAX_SHIFT) +#define GLB_INSTR_FEATURES_EVENT_SIZE_MAX_GET(reg_val) \ + (((reg_val)&GLB_INSTR_FEATURES_EVENT_SIZE_MAX_MASK) >> GLB_INSTR_FEATURES_EVENT_SIZE_MAX_SHIFT) +#define GLB_INSTR_FEATURES_EVENT_SIZE_MAX_SET(reg_val, value) \ + (((reg_val) & ~GLB_INSTR_FEATURES_EVENT_SIZE_MAX_MASK) | \ + (((value) << GLB_INSTR_FEATURES_EVENT_SIZE_MAX_SHIFT) & GLB_INSTR_FEATURES_EVENT_SIZE_MAX_MASK)) + #define CSG_STATUS_STATE (0x0018) /* CSG state status register */ /* CSG_STATUS_STATE register */ #define CSG_STATUS_STATE_IDLE_SHIFT (0) diff --git a/include/uapi/gpu/arm/bifrost/csf/mali_kbase_csf_ioctl.h b/include/uapi/gpu/arm/bifrost/csf/mali_kbase_csf_ioctl.h index 15fac5e69061..d2d7ce23491b 100644 --- a/include/uapi/gpu/arm/bifrost/csf/mali_kbase_csf_ioctl.h +++ b/include/uapi/gpu/arm/bifrost/csf/mali_kbase_csf_ioctl.h @@ -40,10 +40,14 @@ * 1.4: * - Replace padding in kbase_ioctl_cs_get_glb_iface with * instr_features member of same size + * 1.5: + * - Add ioctl 40: kbase_ioctl_cs_queue_register_ex, this is a new + * queue registration call with extended format for supporting CS + * trace configurations with CSF trace_command. */ #define BASE_UK_VERSION_MAJOR 1 -#define BASE_UK_VERSION_MINOR 4 +#define BASE_UK_VERSION_MINOR 5 /** * struct kbase_ioctl_version_check - Check version compatibility between @@ -69,6 +73,9 @@ struct kbase_ioctl_version_check { * @buffer_size: Size of the buffer in bytes * @priority: Priority of the queue within a group when run within a process * @padding: Currently unused, must be zero + * + * @Note: There is an identical sub-section in kbase_ioctl_cs_queue_register_ex. + * Any change of this struct should also be mirrored to the latter. */ struct kbase_ioctl_cs_queue_register { __u64 buffer_gpu_addr; @@ -120,7 +127,42 @@ union kbase_ioctl_cs_queue_bind { #define KBASE_IOCTL_CS_QUEUE_BIND \ _IOWR(KBASE_IOCTL_TYPE, 39, union kbase_ioctl_cs_queue_bind) -/* ioctl 40 is free to use */ +/** + * struct kbase_ioctl_cs_queue_register_ex - Register a GPU command queue with the + * base back-end in extended format, + * involving trace buffer configuration + * + * @buffer_gpu_addr: GPU address of the buffer backing the queue + * @buffer_size: Size of the buffer in bytes + * @priority: Priority of the queue within a group when run within a process + * @padding: Currently unused, must be zero + * @ex_offset_var_addr: GPU address of the trace buffer write offset variable + * @ex_buffer_base: Trace buffer GPU base address for the queue + * @ex_buffer_size: Size of the trace buffer in bytes + * @ex_event_size: Trace event write size, in log2 designation + * @ex_event_state: Trace event states configuration + * @ex_padding: Currently unused, must be zero + * + * @Note: There is an identical sub-section at the start of this struct to that + * of @ref kbase_ioctl_cs_queue_register. Any change of this sub-section + * must also be mirrored to the latter. Following the said sub-section, + * the remaining fields forms the extension, marked with ex_*. + */ +struct kbase_ioctl_cs_queue_register_ex { + __u64 buffer_gpu_addr; + __u32 buffer_size; + __u8 priority; + __u8 padding[3]; + __u64 ex_offset_var_addr; + __u64 ex_buffer_base; + __u32 ex_buffer_size; + __u8 ex_event_size; + __u8 ex_event_state; + __u8 ex_padding[2]; +}; + +#define KBASE_IOCTL_CS_QUEUE_REGISTER_EX \ + _IOW(KBASE_IOCTL_TYPE, 40, struct kbase_ioctl_cs_queue_register_ex) /** * struct kbase_ioctl_cs_queue_terminate - Terminate a GPU command queue @@ -314,6 +356,7 @@ struct kbase_ioctl_cs_tiler_heap_term { * @out.total_stream_num: Total number of CSs, summed across all groups. * @out.instr_features: Instrumentation features. Bits 7:4 hold the maximum * size of events. Bits 3:0 hold the offset update rate. + * (csf >= 1.1.0) * */ union kbase_ioctl_cs_get_glb_iface { diff --git a/include/uapi/gpu/arm/bifrost/gpu/mali_kbase_gpu_id.h b/include/uapi/gpu/arm/bifrost/gpu/mali_kbase_gpu_id.h index 2f0c065df161..d093ce4f76c7 100644 --- a/include/uapi/gpu/arm/bifrost/gpu/mali_kbase_gpu_id.h +++ b/include/uapi/gpu/arm/bifrost/gpu/mali_kbase_gpu_id.h @@ -106,6 +106,8 @@ #define GPU_ID2_PRODUCT_TBAX GPU_ID2_MODEL_MAKE(9, 5) #define GPU_ID2_PRODUCT_TDUX GPU_ID2_MODEL_MAKE(10, 1) #define GPU_ID2_PRODUCT_TODX GPU_ID2_MODEL_MAKE(10, 2) +#define GPU_ID2_PRODUCT_TGRX GPU_ID2_MODEL_MAKE(10, 3) +#define GPU_ID2_PRODUCT_TVAX GPU_ID2_MODEL_MAKE(10, 4) #define GPU_ID2_PRODUCT_LODX GPU_ID2_MODEL_MAKE(10, 7) /* Helper macro to create a GPU_ID assuming valid values for id, major, diff --git a/include/uapi/gpu/arm/bifrost/gpu/mali_kbase_gpu_regmap.h b/include/uapi/gpu/arm/bifrost/gpu/mali_kbase_gpu_regmap.h index be9c38984d3b..84fad8d72a30 100644 --- a/include/uapi/gpu/arm/bifrost/gpu/mali_kbase_gpu_regmap.h +++ b/include/uapi/gpu/arm/bifrost/gpu/mali_kbase_gpu_regmap.h @@ -67,6 +67,9 @@ #define PWR_OVERRIDE1 0x058 /* (RW) Power manager override settings */ #define GPU_FEATURES_LO 0x060 /* (RO) GPU features, low word */ #define GPU_FEATURES_HI 0x064 /* (RO) GPU features, high word */ +#define PRFCNT_FEATURES 0x068 /* (RO) Performance counter features */ +#define TIMESTAMP_OFFSET_LO 0x088 /* (RW) Global time stamp offset, low word */ +#define TIMESTAMP_OFFSET_HI 0x08C /* (RW) Global time stamp offset, high word */ #define CYCLE_COUNT_LO 0x090 /* (RO) Cycle counter, low word */ #define CYCLE_COUNT_HI 0x094 /* (RO) Cycle counter, high word */ #define TIMESTAMP_LO 0x098 /* (RO) Global time stamp counter, low word */ @@ -285,6 +288,13 @@ #define AS_FAULTSTATUS_SOURCE_ID_GET(reg_val) \ (((reg_val)&AS_FAULTSTATUS_SOURCE_ID_MASK) >> AS_FAULTSTATUS_SOURCE_ID_SHIFT) +#define PRFCNT_FEATURES_COUNTER_BLOCK_SIZE_SHIFT (0) +#define PRFCNT_FEATURES_COUNTER_BLOCK_SIZE_MASK \ + ((0xFF) << PRFCNT_FEATURES_COUNTER_BLOCK_SIZE_SHIFT) +#define PRFCNT_FEATURES_COUNTER_BLOCK_SIZE_GET(reg_val) \ + (((reg_val)&PRFCNT_FEATURES_COUNTER_BLOCK_SIZE_MASK) >> \ + PRFCNT_FEATURES_COUNTER_BLOCK_SIZE_SHIFT) + /* * Begin MMU TRANSCFG register values */