| .. | .. |
|---|
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note |
|---|
| 2 | 2 | /* |
|---|
| 3 | 3 | * |
|---|
| 4 | | - * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. |
|---|
| 4 | + * (C) COPYRIGHT 2019-2023 ARM Limited. All rights reserved. |
|---|
| 5 | 5 | * |
|---|
| 6 | 6 | * This program is free software and is provided to you under the terms of the |
|---|
| 7 | 7 | * GNU General Public License version 2 as published by the Free Software |
|---|
| .. | .. |
|---|
| 23 | 23 | #include <device/mali_kbase_device.h> |
|---|
| 24 | 24 | |
|---|
| 25 | 25 | #include <mali_kbase_hwaccess_backend.h> |
|---|
| 26 | | -#include <mali_kbase_hwcnt_backend_csf_if_fw.h> |
|---|
| 26 | +#include <hwcnt/backend/mali_kbase_hwcnt_backend_csf_if_fw.h> |
|---|
| 27 | +#include <hwcnt/mali_kbase_hwcnt_watchdog_if_timer.h> |
|---|
| 27 | 28 | #include <mali_kbase_ctx_sched.h> |
|---|
| 28 | 29 | #include <mali_kbase_reset_gpu.h> |
|---|
| 29 | 30 | #include <csf/mali_kbase_csf.h> |
|---|
| 30 | 31 | #include <csf/ipa_control/mali_kbase_csf_ipa_control.h> |
|---|
| 31 | | - |
|---|
| 32 | +#include <backend/gpu/mali_kbase_model_linux.h> |
|---|
| 32 | 33 | |
|---|
| 33 | 34 | #include <mali_kbase.h> |
|---|
| 34 | 35 | #include <backend/gpu/mali_kbase_irq_internal.h> |
|---|
| .. | .. |
|---|
| 36 | 37 | #include <backend/gpu/mali_kbase_js_internal.h> |
|---|
| 37 | 38 | #include <backend/gpu/mali_kbase_clk_rate_trace_mgr.h> |
|---|
| 38 | 39 | #include <csf/mali_kbase_csf_csg_debugfs.h> |
|---|
| 39 | | -#include <mali_kbase_hwcnt_virtualizer.h> |
|---|
| 40 | +#include <hwcnt/mali_kbase_hwcnt_virtualizer.h> |
|---|
| 41 | +#include <mali_kbase_kinstr_prfcnt.h> |
|---|
| 40 | 42 | #include <mali_kbase_vinstr.h> |
|---|
| 43 | +#include <tl/mali_kbase_timeline.h> |
|---|
| 41 | 44 | |
|---|
| 42 | 45 | /** |
|---|
| 43 | 46 | * kbase_device_firmware_hwcnt_term - Terminate CSF firmware and HWC |
|---|
| .. | .. |
|---|
| 51 | 54 | static void kbase_device_firmware_hwcnt_term(struct kbase_device *kbdev) |
|---|
| 52 | 55 | { |
|---|
| 53 | 56 | if (kbdev->csf.firmware_inited) { |
|---|
| 57 | + kbase_kinstr_prfcnt_term(kbdev->kinstr_prfcnt_ctx); |
|---|
| 54 | 58 | kbase_vinstr_term(kbdev->vinstr_ctx); |
|---|
| 55 | 59 | kbase_hwcnt_virtualizer_term(kbdev->hwcnt_gpu_virt); |
|---|
| 56 | 60 | kbase_hwcnt_backend_csf_metadata_term(&kbdev->hwcnt_gpu_iface); |
|---|
| 57 | | - kbase_csf_firmware_term(kbdev); |
|---|
| 61 | + kbase_csf_firmware_unload_term(kbdev); |
|---|
| 58 | 62 | } |
|---|
| 59 | 63 | } |
|---|
| 60 | 64 | |
|---|
| .. | .. |
|---|
| 85 | 89 | goto fail_timer; |
|---|
| 86 | 90 | |
|---|
| 87 | 91 | #ifdef CONFIG_MALI_BIFROST_DEBUG |
|---|
| 88 | | -#ifndef CONFIG_MALI_BIFROST_NO_MALI |
|---|
| 92 | +#if IS_ENABLED(CONFIG_MALI_REAL_HW) |
|---|
| 89 | 93 | if (kbasep_common_test_interrupt_handlers(kbdev) != 0) { |
|---|
| 90 | 94 | dev_err(kbdev->dev, "Interrupt assignment check failed.\n"); |
|---|
| 91 | 95 | err = -EINVAL; |
|---|
| 92 | 96 | goto fail_interrupt_test; |
|---|
| 93 | 97 | } |
|---|
| 94 | | -#endif /* !CONFIG_MALI_BIFROST_NO_MALI */ |
|---|
| 98 | +#endif /* IS_ENABLED(CONFIG_MALI_REAL_HW) */ |
|---|
| 95 | 99 | #endif /* CONFIG_MALI_BIFROST_DEBUG */ |
|---|
| 96 | 100 | |
|---|
| 97 | 101 | kbase_ipa_control_init(kbdev); |
|---|
| .. | .. |
|---|
| 119 | 123 | if (err) |
|---|
| 120 | 124 | goto fail_update_l2_features; |
|---|
| 121 | 125 | |
|---|
| 126 | + err = kbase_backend_time_init(kbdev); |
|---|
| 127 | + if (err) |
|---|
| 128 | + goto fail_update_l2_features; |
|---|
| 129 | + |
|---|
| 122 | 130 | init_waitqueue_head(&kbdev->hwaccess.backend.reset_wait); |
|---|
| 123 | 131 | |
|---|
| 124 | 132 | kbase_pm_context_idle(kbdev); |
|---|
| .. | .. |
|---|
| 135 | 143 | kbase_ipa_control_term(kbdev); |
|---|
| 136 | 144 | |
|---|
| 137 | 145 | #ifdef CONFIG_MALI_BIFROST_DEBUG |
|---|
| 138 | | -#ifndef CONFIG_MALI_BIFROST_NO_MALI |
|---|
| 146 | +#if IS_ENABLED(CONFIG_MALI_REAL_HW) |
|---|
| 139 | 147 | fail_interrupt_test: |
|---|
| 140 | | -#endif /* !CONFIG_MALI_BIFROST_NO_MALI */ |
|---|
| 148 | +#endif /* IS_ENABLED(CONFIG_MALI_REAL_HW) */ |
|---|
| 141 | 149 | #endif /* CONFIG_MALI_BIFROST_DEBUG */ |
|---|
| 142 | 150 | |
|---|
| 143 | 151 | kbase_backend_timer_term(kbdev); |
|---|
| .. | .. |
|---|
| 185 | 193 | } |
|---|
| 186 | 194 | |
|---|
| 187 | 195 | /** |
|---|
| 188 | | - * kbase_csf_early_init - Early termination for firmware & scheduler. |
|---|
| 196 | + * kbase_csf_early_term() - Early termination for firmware & scheduler. |
|---|
| 189 | 197 | * @kbdev: Device pointer |
|---|
| 190 | 198 | */ |
|---|
| 191 | 199 | static void kbase_csf_early_term(struct kbase_device *kbdev) |
|---|
| 192 | 200 | { |
|---|
| 193 | 201 | kbase_csf_scheduler_early_term(kbdev); |
|---|
| 202 | + kbase_csf_firmware_early_term(kbdev); |
|---|
| 203 | +} |
|---|
| 204 | + |
|---|
| 205 | +/** |
|---|
| 206 | + * kbase_csf_late_init - late initialization for firmware. |
|---|
| 207 | + * @kbdev: Device pointer |
|---|
| 208 | + * |
|---|
| 209 | + * Return: 0 on success, error code otherwise. |
|---|
| 210 | + */ |
|---|
| 211 | +static int kbase_csf_late_init(struct kbase_device *kbdev) |
|---|
| 212 | +{ |
|---|
| 213 | + int err = kbase_csf_firmware_late_init(kbdev); |
|---|
| 214 | + |
|---|
| 215 | + return err; |
|---|
| 216 | +} |
|---|
| 217 | + |
|---|
| 218 | +/** |
|---|
| 219 | + * kbase_device_hwcnt_watchdog_if_init - Create hardware counter watchdog |
|---|
| 220 | + * interface. |
|---|
| 221 | + * @kbdev: Device pointer |
|---|
| 222 | + * |
|---|
| 223 | + * Return: 0 if successful or a negative error code on failure. |
|---|
| 224 | + */ |
|---|
| 225 | +static int kbase_device_hwcnt_watchdog_if_init(struct kbase_device *kbdev) |
|---|
| 226 | +{ |
|---|
| 227 | + return kbase_hwcnt_watchdog_if_timer_create( |
|---|
| 228 | + &kbdev->hwcnt_watchdog_timer); |
|---|
| 229 | +} |
|---|
| 230 | + |
|---|
| 231 | +/** |
|---|
| 232 | + * kbase_device_hwcnt_watchdog_if_term - Terminate hardware counter watchdog |
|---|
| 233 | + * interface. |
|---|
| 234 | + * @kbdev: Device pointer |
|---|
| 235 | + */ |
|---|
| 236 | +static void kbase_device_hwcnt_watchdog_if_term(struct kbase_device *kbdev) |
|---|
| 237 | +{ |
|---|
| 238 | + kbase_hwcnt_watchdog_if_timer_destroy(&kbdev->hwcnt_watchdog_timer); |
|---|
| 194 | 239 | } |
|---|
| 195 | 240 | |
|---|
| 196 | 241 | /** |
|---|
| 197 | 242 | * kbase_device_hwcnt_backend_csf_if_init - Create hardware counter backend |
|---|
| 198 | 243 | * firmware interface. |
|---|
| 199 | 244 | * @kbdev: Device pointer |
|---|
| 245 | + * Return: 0 if successful or a negative error code on failure. |
|---|
| 200 | 246 | */ |
|---|
| 201 | 247 | static int kbase_device_hwcnt_backend_csf_if_init(struct kbase_device *kbdev) |
|---|
| 202 | 248 | { |
|---|
| .. | .. |
|---|
| 217 | 263 | /** |
|---|
| 218 | 264 | * kbase_device_hwcnt_backend_csf_init - Create hardware counter backend. |
|---|
| 219 | 265 | * @kbdev: Device pointer |
|---|
| 266 | + * |
|---|
| 267 | + * Return: 0 if successful or a negative error code on failure. |
|---|
| 220 | 268 | */ |
|---|
| 221 | | - |
|---|
| 222 | 269 | static int kbase_device_hwcnt_backend_csf_init(struct kbase_device *kbdev) |
|---|
| 223 | 270 | { |
|---|
| 224 | 271 | return kbase_hwcnt_backend_csf_create( |
|---|
| 225 | 272 | &kbdev->hwcnt_backend_csf_if_fw, |
|---|
| 226 | 273 | KBASE_HWCNT_BACKEND_CSF_RING_BUFFER_COUNT, |
|---|
| 227 | | - &kbdev->hwcnt_gpu_iface); |
|---|
| 274 | + &kbdev->hwcnt_watchdog_timer, &kbdev->hwcnt_gpu_iface); |
|---|
| 228 | 275 | } |
|---|
| 229 | 276 | |
|---|
| 230 | 277 | /** |
|---|
| .. | .. |
|---|
| 237 | 284 | } |
|---|
| 238 | 285 | |
|---|
| 239 | 286 | static const struct kbase_device_init dev_init[] = { |
|---|
| 287 | +#if !IS_ENABLED(CONFIG_MALI_REAL_HW) |
|---|
| 288 | + { kbase_gpu_device_create, kbase_gpu_device_destroy, |
|---|
| 289 | + "Dummy model initialization failed" }, |
|---|
| 290 | +#else /* !IS_ENABLED(CONFIG_MALI_REAL_HW) */ |
|---|
| 240 | 291 | { assign_irqs, NULL, "IRQ search failed" }, |
|---|
| 292 | +#endif /* !IS_ENABLED(CONFIG_MALI_REAL_HW) */ |
|---|
| 293 | +#if !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) |
|---|
| 241 | 294 | { registers_map, registers_unmap, "Register map failed" }, |
|---|
| 242 | | - { power_control_init, power_control_term, |
|---|
| 243 | | - "Power control initialization failed" }, |
|---|
| 295 | +#endif /* !IS_ENABLED(CONFIG_MALI_BIFROST_NO_MALI) */ |
|---|
| 296 | + { power_control_init, power_control_term, "Power control initialization failed" }, |
|---|
| 244 | 297 | { kbase_device_io_history_init, kbase_device_io_history_term, |
|---|
| 245 | 298 | "Register access history initialization failed" }, |
|---|
| 246 | | - { kbase_device_early_init, kbase_device_early_term, |
|---|
| 247 | | - "Early device initialization failed" }, |
|---|
| 248 | | - { kbase_device_populate_max_freq, NULL, |
|---|
| 249 | | - "Populating max frequency failed" }, |
|---|
| 299 | + { kbase_device_early_init, kbase_device_early_term, "Early device initialization failed" }, |
|---|
| 300 | + { kbase_device_populate_max_freq, NULL, "Populating max frequency failed" }, |
|---|
| 301 | + { kbase_pm_lowest_gpu_freq_init, NULL, "Lowest freq initialization failed" }, |
|---|
| 250 | 302 | { kbase_device_misc_init, kbase_device_misc_term, |
|---|
| 251 | 303 | "Miscellaneous device initialization failed" }, |
|---|
| 252 | 304 | { kbase_device_pcm_dev_init, kbase_device_pcm_dev_term, |
|---|
| 253 | 305 | "Priority control manager initialization failed" }, |
|---|
| 254 | | - { kbase_ctx_sched_init, kbase_ctx_sched_term, |
|---|
| 255 | | - "Context scheduler initialization failed" }, |
|---|
| 256 | | - { kbase_mem_init, kbase_mem_term, |
|---|
| 257 | | - "Memory subsystem initialization failed" }, |
|---|
| 306 | + { kbase_ctx_sched_init, kbase_ctx_sched_term, "Context scheduler initialization failed" }, |
|---|
| 307 | + { kbase_mem_init, kbase_mem_term, "Memory subsystem initialization failed" }, |
|---|
| 258 | 308 | { kbase_csf_protected_memory_init, kbase_csf_protected_memory_term, |
|---|
| 259 | 309 | "Protected memory allocator initialization failed" }, |
|---|
| 260 | 310 | { kbase_device_coherency_init, NULL, "Device coherency init failed" }, |
|---|
| 261 | 311 | { kbase_protected_mode_init, kbase_protected_mode_term, |
|---|
| 262 | 312 | "Protected mode subsystem initialization failed" }, |
|---|
| 263 | | - { kbase_device_list_init, kbase_device_list_term, |
|---|
| 264 | | - "Device list setup failed" }, |
|---|
| 313 | + { kbase_device_list_init, kbase_device_list_term, "Device list setup failed" }, |
|---|
| 265 | 314 | { kbase_device_timeline_init, kbase_device_timeline_term, |
|---|
| 266 | 315 | "Timeline stream initialization failed" }, |
|---|
| 267 | 316 | { kbase_clk_rate_trace_manager_init, kbase_clk_rate_trace_manager_term, |
|---|
| 268 | 317 | "Clock rate trace manager initialization failed" }, |
|---|
| 269 | | - { kbase_device_hwcnt_backend_csf_if_init, |
|---|
| 270 | | - kbase_device_hwcnt_backend_csf_if_term, |
|---|
| 318 | + { kbase_device_hwcnt_watchdog_if_init, kbase_device_hwcnt_watchdog_if_term, |
|---|
| 319 | + "GPU hwcnt backend watchdog interface creation failed" }, |
|---|
| 320 | + { kbase_device_hwcnt_backend_csf_if_init, kbase_device_hwcnt_backend_csf_if_term, |
|---|
| 271 | 321 | "GPU hwcnt backend CSF interface creation failed" }, |
|---|
| 272 | | - { kbase_device_hwcnt_backend_csf_init, |
|---|
| 273 | | - kbase_device_hwcnt_backend_csf_term, |
|---|
| 322 | + { kbase_device_hwcnt_backend_csf_init, kbase_device_hwcnt_backend_csf_term, |
|---|
| 274 | 323 | "GPU hwcnt backend creation failed" }, |
|---|
| 275 | 324 | { kbase_device_hwcnt_context_init, kbase_device_hwcnt_context_term, |
|---|
| 276 | 325 | "GPU hwcnt context initialization failed" }, |
|---|
| 277 | | - { kbase_backend_late_init, kbase_backend_late_term, |
|---|
| 278 | | - "Late backend initialization failed" }, |
|---|
| 279 | | - { kbase_csf_early_init, kbase_csf_early_term, |
|---|
| 280 | | - "Early CSF initialization failed" }, |
|---|
| 326 | + { kbase_csf_early_init, kbase_csf_early_term, "Early CSF initialization failed" }, |
|---|
| 327 | + { kbase_backend_late_init, kbase_backend_late_term, "Late backend initialization failed" }, |
|---|
| 328 | + { kbase_csf_late_init, NULL, "Late CSF initialization failed" }, |
|---|
| 281 | 329 | { NULL, kbase_device_firmware_hwcnt_term, NULL }, |
|---|
| 282 | | -#ifdef MALI_KBASE_BUILD |
|---|
| 283 | | - { kbase_device_debugfs_init, kbase_device_debugfs_term, |
|---|
| 284 | | - "DebugFS initialization failed" }, |
|---|
| 330 | + { kbase_debug_csf_fault_init, kbase_debug_csf_fault_term, |
|---|
| 331 | + "CSF fault debug initialization failed" }, |
|---|
| 332 | + { kbase_device_debugfs_init, kbase_device_debugfs_term, "DebugFS initialization failed" }, |
|---|
| 285 | 333 | /* Sysfs init needs to happen before registering the device with |
|---|
| 286 | 334 | * misc_register(), otherwise it causes a race condition between |
|---|
| 287 | 335 | * registering the device and a uevent event being generated for |
|---|
| .. | .. |
|---|
| 299 | 347 | "Misc device registration failed" }, |
|---|
| 300 | 348 | { kbase_gpuprops_populate_user_buffer, kbase_gpuprops_free_user_buffer, |
|---|
| 301 | 349 | "GPU property population failed" }, |
|---|
| 302 | | - { kbase_device_late_init, kbase_device_late_term, |
|---|
| 303 | | - "Late device initialization failed" }, |
|---|
| 304 | | -#endif |
|---|
| 350 | + { kbase_device_late_init, kbase_device_late_term, "Late device initialization failed" }, |
|---|
| 351 | +#if IS_ENABLED(CONFIG_MALI_CORESIGHT) |
|---|
| 352 | + { kbase_debug_coresight_csf_init, kbase_debug_coresight_csf_term, |
|---|
| 353 | + "Coresight initialization failed" }, |
|---|
| 354 | +#endif /* IS_ENABLED(CONFIG_MALI_CORESIGHT) */ |
|---|
| 305 | 355 | }; |
|---|
| 306 | 356 | |
|---|
| 307 | 357 | static void kbase_device_term_partial(struct kbase_device *kbdev, |
|---|
| .. | .. |
|---|
| 315 | 365 | |
|---|
| 316 | 366 | void kbase_device_term(struct kbase_device *kbdev) |
|---|
| 317 | 367 | { |
|---|
| 318 | | - kbdev->csf.mali_file_inode = NULL; |
|---|
| 319 | 368 | kbase_device_term_partial(kbdev, ARRAY_SIZE(dev_init)); |
|---|
| 320 | 369 | kbase_mem_halt(kbdev); |
|---|
| 321 | 370 | } |
|---|
| .. | .. |
|---|
| 354 | 403 | * Hardware counter components depending on firmware are initialized after CSF |
|---|
| 355 | 404 | * firmware is loaded. |
|---|
| 356 | 405 | * |
|---|
| 357 | | - * @return 0 on success. An error code on failure. |
|---|
| 406 | + * Return: 0 on success. An error code on failure. |
|---|
| 358 | 407 | */ |
|---|
| 359 | 408 | static int kbase_device_hwcnt_csf_deferred_init(struct kbase_device *kbdev) |
|---|
| 360 | 409 | { |
|---|
| .. | .. |
|---|
| 390 | 439 | goto vinstr_fail; |
|---|
| 391 | 440 | } |
|---|
| 392 | 441 | |
|---|
| 442 | + ret = kbase_kinstr_prfcnt_init(kbdev->hwcnt_gpu_virt, |
|---|
| 443 | + &kbdev->kinstr_prfcnt_ctx); |
|---|
| 444 | + if (ret) { |
|---|
| 445 | + dev_err(kbdev->dev, |
|---|
| 446 | + "Performance counter instrumentation initialization failed"); |
|---|
| 447 | + goto kinstr_prfcnt_fail; |
|---|
| 448 | + } |
|---|
| 449 | + |
|---|
| 393 | 450 | return ret; |
|---|
| 451 | + |
|---|
| 452 | +kinstr_prfcnt_fail: |
|---|
| 453 | + kbase_vinstr_term(kbdev->vinstr_ctx); |
|---|
| 394 | 454 | |
|---|
| 395 | 455 | vinstr_fail: |
|---|
| 396 | 456 | kbase_hwcnt_virtualizer_term(kbdev->hwcnt_gpu_virt); |
|---|
| .. | .. |
|---|
| 410 | 470 | * To meet Android GKI vendor guideline, firmware load is deferred at |
|---|
| 411 | 471 | * the time when @ref kbase_open is called for the first time. |
|---|
| 412 | 472 | * |
|---|
| 413 | | - * @return 0 on success. An error code on failure. |
|---|
| 473 | + * Return: 0 on success. An error code on failure. |
|---|
| 414 | 474 | */ |
|---|
| 415 | 475 | static int kbase_csf_firmware_deferred_init(struct kbase_device *kbdev) |
|---|
| 416 | 476 | { |
|---|
| .. | .. |
|---|
| 418 | 478 | |
|---|
| 419 | 479 | lockdep_assert_held(&kbdev->fw_load_lock); |
|---|
| 420 | 480 | |
|---|
| 421 | | - kbase_pm_context_active(kbdev); |
|---|
| 422 | | - |
|---|
| 423 | | - err = kbase_csf_firmware_init(kbdev); |
|---|
| 481 | + err = kbase_csf_firmware_load_init(kbdev); |
|---|
| 424 | 482 | if (!err) { |
|---|
| 425 | 483 | unsigned long flags; |
|---|
| 426 | 484 | |
|---|
| .. | .. |
|---|
| 432 | 490 | dev_err(kbdev->dev, "Firmware initialization failed"); |
|---|
| 433 | 491 | } |
|---|
| 434 | 492 | |
|---|
| 435 | | - kbase_pm_context_idle(kbdev); |
|---|
| 436 | | - |
|---|
| 437 | 493 | return err; |
|---|
| 438 | 494 | } |
|---|
| 439 | 495 | |
|---|
| .. | .. |
|---|
| 444 | 500 | mutex_lock(&kbdev->fw_load_lock); |
|---|
| 445 | 501 | |
|---|
| 446 | 502 | if (!kbdev->csf.firmware_inited) { |
|---|
| 503 | + kbase_pm_context_active(kbdev); |
|---|
| 504 | + |
|---|
| 447 | 505 | ret = kbase_csf_firmware_deferred_init(kbdev); |
|---|
| 448 | 506 | if (ret) |
|---|
| 449 | 507 | goto out; |
|---|
| 450 | 508 | |
|---|
| 451 | 509 | ret = kbase_device_hwcnt_csf_deferred_init(kbdev); |
|---|
| 452 | 510 | if (ret) { |
|---|
| 453 | | - kbase_csf_firmware_term(kbdev); |
|---|
| 511 | + kbase_csf_firmware_unload_term(kbdev); |
|---|
| 454 | 512 | goto out; |
|---|
| 455 | 513 | } |
|---|
| 456 | 514 | |
|---|
| 457 | 515 | kbase_csf_debugfs_init(kbdev); |
|---|
| 516 | + kbase_timeline_io_debugfs_init(kbdev); |
|---|
| 517 | +out: |
|---|
| 518 | + kbase_pm_context_idle(kbdev); |
|---|
| 458 | 519 | } |
|---|
| 459 | 520 | |
|---|
| 460 | | -out: |
|---|
| 461 | 521 | mutex_unlock(&kbdev->fw_load_lock); |
|---|
| 462 | 522 | |
|---|
| 463 | 523 | return ret; |
|---|
| 464 | 524 | } |
|---|
| 525 | +KBASE_EXPORT_TEST_API(kbase_device_firmware_init_once); |
|---|