| .. | .. |
|---|
| 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-2022 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 |
|---|
| .. | .. |
|---|
| 20 | 20 | */ |
|---|
| 21 | 21 | |
|---|
| 22 | 22 | /** |
|---|
| 23 | | - * @file |
|---|
| 24 | | - * Mali arbiter power manager state machine and APIs |
|---|
| 23 | + * DOC: Mali arbiter power manager state machine and APIs |
|---|
| 25 | 24 | */ |
|---|
| 26 | 25 | |
|---|
| 27 | 26 | #include <mali_kbase.h> |
|---|
| 28 | 27 | #include <mali_kbase_pm.h> |
|---|
| 29 | | -#include <mali_kbase_hwaccess_jm.h> |
|---|
| 30 | 28 | #include <backend/gpu/mali_kbase_irq_internal.h> |
|---|
| 31 | | -#include <mali_kbase_hwcnt_context.h> |
|---|
| 32 | 29 | #include <backend/gpu/mali_kbase_pm_internal.h> |
|---|
| 33 | 30 | #include <tl/mali_kbase_tracepoints.h> |
|---|
| 34 | 31 | #include <mali_kbase_gpuprops.h> |
|---|
| .. | .. |
|---|
| 319 | 316 | if (kbdev->arb.arb_if) { |
|---|
| 320 | 317 | kbase_arbif_gpu_request(kbdev); |
|---|
| 321 | 318 | dev_dbg(kbdev->dev, "Waiting for initial GPU assignment...\n"); |
|---|
| 319 | + |
|---|
| 322 | 320 | err = wait_event_timeout(arb_vm_state->vm_state_wait, |
|---|
| 323 | 321 | arb_vm_state->vm_state == |
|---|
| 324 | 322 | KBASE_VM_STATE_INITIALIZING_WITH_GPU, |
|---|
| .. | .. |
|---|
| 328 | 326 | dev_dbg(kbdev->dev, |
|---|
| 329 | 327 | "Kbase probe Deferred after waiting %d ms to receive GPU_GRANT\n", |
|---|
| 330 | 328 | gpu_req_timeout); |
|---|
| 331 | | - err = -EPROBE_DEFER; |
|---|
| 332 | | - goto arbif_eprobe_defer; |
|---|
| 329 | + |
|---|
| 330 | + err = -ENODEV; |
|---|
| 331 | + goto arbif_timeout; |
|---|
| 333 | 332 | } |
|---|
| 334 | 333 | |
|---|
| 335 | 334 | dev_dbg(kbdev->dev, |
|---|
| .. | .. |
|---|
| 337 | 336 | } |
|---|
| 338 | 337 | return 0; |
|---|
| 339 | 338 | |
|---|
| 340 | | -arbif_eprobe_defer: |
|---|
| 339 | +arbif_timeout: |
|---|
| 341 | 340 | kbase_arbiter_pm_early_term(kbdev); |
|---|
| 342 | 341 | return err; |
|---|
| 342 | + |
|---|
| 343 | 343 | arbif_init_fail: |
|---|
| 344 | 344 | destroy_workqueue(arb_vm_state->vm_arb_wq); |
|---|
| 345 | 345 | kfree(arb_vm_state); |
|---|
| .. | .. |
|---|
| 394 | 394 | * @kbdev: The kbase device structure for the device (must be a valid pointer) |
|---|
| 395 | 395 | * |
|---|
| 396 | 396 | * Install interrupts and set the interrupt_install flag to true. |
|---|
| 397 | + * |
|---|
| 398 | + * Return: 0 if success, or a Linux error code |
|---|
| 397 | 399 | */ |
|---|
| 398 | 400 | int kbase_arbiter_pm_install_interrupts(struct kbase_device *kbdev) |
|---|
| 399 | 401 | { |
|---|
| .. | .. |
|---|
| 924 | 926 | * @kbdev: The kbase device structure for the device (must be a valid pointer) |
|---|
| 925 | 927 | * |
|---|
| 926 | 928 | * Checks if the virtual machine holds VM state lock. |
|---|
| 929 | + * |
|---|
| 930 | + * Return: true if GPU is assigned, else false. |
|---|
| 927 | 931 | */ |
|---|
| 928 | 932 | static inline bool kbase_arbiter_pm_vm_gpu_assigned_lockheld( |
|---|
| 929 | 933 | struct kbase_device *kbdev) |
|---|
| .. | .. |
|---|
| 951 | 955 | int kbase_arbiter_pm_ctx_active_handle_suspend(struct kbase_device *kbdev, |
|---|
| 952 | 956 | enum kbase_pm_suspend_handler suspend_handler) |
|---|
| 953 | 957 | { |
|---|
| 954 | | - struct kbasep_js_device_data *js_devdata = &kbdev->js_data; |
|---|
| 955 | 958 | struct kbase_arbiter_vm_state *arb_vm_state = kbdev->pm.arb_vm_state; |
|---|
| 956 | 959 | int res = 0; |
|---|
| 957 | 960 | |
|---|
| .. | .. |
|---|
| 1004 | 1007 | /* Need to synchronously wait for GPU assignment */ |
|---|
| 1005 | 1008 | atomic_inc(&kbdev->pm.gpu_users_waiting); |
|---|
| 1006 | 1009 | mutex_unlock(&arb_vm_state->vm_state_lock); |
|---|
| 1007 | | - mutex_unlock(&kbdev->pm.lock); |
|---|
| 1008 | | - mutex_unlock(&js_devdata->runpool_mutex); |
|---|
| 1010 | + kbase_pm_unlock(kbdev); |
|---|
| 1009 | 1011 | kbase_arbiter_pm_vm_wait_gpu_assignment(kbdev); |
|---|
| 1010 | | - mutex_lock(&js_devdata->runpool_mutex); |
|---|
| 1011 | | - mutex_lock(&kbdev->pm.lock); |
|---|
| 1012 | + kbase_pm_lock(kbdev); |
|---|
| 1012 | 1013 | mutex_lock(&arb_vm_state->vm_state_lock); |
|---|
| 1013 | 1014 | atomic_dec(&kbdev->pm.gpu_users_waiting); |
|---|
| 1014 | 1015 | } |
|---|
| .. | .. |
|---|
| 1020 | 1021 | /** |
|---|
| 1021 | 1022 | * kbase_arbiter_pm_update_gpu_freq() - Updates GPU clock frequency received |
|---|
| 1022 | 1023 | * from arbiter. |
|---|
| 1023 | | - * @arb_freq - Pointer to struchture holding GPU clock frequenecy data |
|---|
| 1024 | | - * @freq - New frequency value in KHz |
|---|
| 1024 | + * @arb_freq: Pointer to struchture holding GPU clock frequenecy data |
|---|
| 1025 | + * @freq: New frequency value in KHz |
|---|
| 1025 | 1026 | */ |
|---|
| 1026 | 1027 | void kbase_arbiter_pm_update_gpu_freq(struct kbase_arbiter_freq *arb_freq, |
|---|
| 1027 | 1028 | uint32_t freq) |
|---|
| .. | .. |
|---|
| 1030 | 1031 | |
|---|
| 1031 | 1032 | mutex_lock(&arb_freq->arb_freq_lock); |
|---|
| 1032 | 1033 | if (arb_freq->arb_freq != freq) { |
|---|
| 1033 | | - ndata.new_rate = freq * KHZ_TO_HZ; |
|---|
| 1034 | | - ndata.old_rate = arb_freq->arb_freq * KHZ_TO_HZ; |
|---|
| 1034 | + ndata.new_rate = (unsigned long)freq * KHZ_TO_HZ; |
|---|
| 1035 | + ndata.old_rate = (unsigned long)arb_freq->arb_freq * KHZ_TO_HZ; |
|---|
| 1035 | 1036 | ndata.gpu_clk_handle = arb_freq; |
|---|
| 1036 | 1037 | arb_freq->arb_freq = freq; |
|---|
| 1037 | 1038 | arb_freq->freq_updated = true; |
|---|
| .. | .. |
|---|
| 1044 | 1045 | } |
|---|
| 1045 | 1046 | |
|---|
| 1046 | 1047 | /** |
|---|
| 1047 | | - * enumerate_arb_gpu_clk() - Enumerate a GPU clock on the given index |
|---|
| 1048 | | - * @kbdev - kbase_device pointer |
|---|
| 1049 | | - * @index - GPU clock index |
|---|
| 1048 | + * get_arb_gpu_clk() - Enumerate a GPU clock on the given index |
|---|
| 1049 | + * @kbdev: kbase_device pointer |
|---|
| 1050 | + * @index: GPU clock index |
|---|
| 1050 | 1051 | * |
|---|
| 1051 | | - * Returns pointer to structure holding GPU clock frequency data reported from |
|---|
| 1052 | + * Return: Pointer to structure holding GPU clock frequency data reported from |
|---|
| 1052 | 1053 | * arbiter, only index 0 is valid. |
|---|
| 1053 | 1054 | */ |
|---|
| 1054 | | -static void *enumerate_arb_gpu_clk(struct kbase_device *kbdev, |
|---|
| 1055 | +static void *get_arb_gpu_clk(struct kbase_device *kbdev, |
|---|
| 1055 | 1056 | unsigned int index) |
|---|
| 1056 | 1057 | { |
|---|
| 1057 | 1058 | if (index == 0) |
|---|
| .. | .. |
|---|
| 1061 | 1062 | |
|---|
| 1062 | 1063 | /** |
|---|
| 1063 | 1064 | * get_arb_gpu_clk_rate() - Get the current rate of GPU clock frequency value |
|---|
| 1064 | | - * @kbdev - kbase_device pointer |
|---|
| 1065 | | - * @index - GPU clock index |
|---|
| 1065 | + * @kbdev: kbase_device pointer |
|---|
| 1066 | + * @gpu_clk_handle: Handle unique to the enumerated GPU clock |
|---|
| 1066 | 1067 | * |
|---|
| 1067 | | - * Returns the GPU clock frequency value saved when gpu is granted from arbiter |
|---|
| 1068 | + * Return: The GPU clock frequency value saved when gpu is granted from arbiter |
|---|
| 1068 | 1069 | */ |
|---|
| 1069 | 1070 | static unsigned long get_arb_gpu_clk_rate(struct kbase_device *kbdev, |
|---|
| 1070 | 1071 | void *gpu_clk_handle) |
|---|
| .. | .. |
|---|
| 1082 | 1083 | |
|---|
| 1083 | 1084 | /** |
|---|
| 1084 | 1085 | * arb_gpu_clk_notifier_register() - Register a clock rate change notifier. |
|---|
| 1085 | | - * @kbdev - kbase_device pointer |
|---|
| 1086 | | - * @gpu_clk_handle - Handle unique to the enumerated GPU clock |
|---|
| 1087 | | - * @nb - notifier block containing the callback function pointer |
|---|
| 1088 | | - * |
|---|
| 1089 | | - * Returns 0 on success, negative error code otherwise. |
|---|
| 1086 | + * @kbdev: kbase_device pointer |
|---|
| 1087 | + * @gpu_clk_handle: Handle unique to the enumerated GPU clock |
|---|
| 1088 | + * @nb: notifier block containing the callback function pointer |
|---|
| 1090 | 1089 | * |
|---|
| 1091 | 1090 | * This function registers a callback function that is invoked whenever the |
|---|
| 1092 | 1091 | * frequency of the clock corresponding to @gpu_clk_handle changes. |
|---|
| 1092 | + * |
|---|
| 1093 | + * Return: 0 on success, negative error code otherwise. |
|---|
| 1093 | 1094 | */ |
|---|
| 1094 | 1095 | static int arb_gpu_clk_notifier_register(struct kbase_device *kbdev, |
|---|
| 1095 | 1096 | void *gpu_clk_handle, struct notifier_block *nb) |
|---|
| .. | .. |
|---|
| 1107 | 1108 | } |
|---|
| 1108 | 1109 | |
|---|
| 1109 | 1110 | /** |
|---|
| 1110 | | - * gpu_clk_notifier_unregister() - Unregister clock rate change notifier |
|---|
| 1111 | | - * @kbdev - kbase_device pointer |
|---|
| 1112 | | - * @gpu_clk_handle - Handle unique to the enumerated GPU clock |
|---|
| 1113 | | - * @nb - notifier block containing the callback function pointer |
|---|
| 1111 | + * arb_gpu_clk_notifier_unregister() - Unregister clock rate change notifier |
|---|
| 1112 | + * @kbdev: kbase_device pointer |
|---|
| 1113 | + * @gpu_clk_handle: Handle unique to the enumerated GPU clock |
|---|
| 1114 | + * @nb: notifier block containing the callback function pointer |
|---|
| 1114 | 1115 | * |
|---|
| 1115 | 1116 | * This function pointer is used to unregister a callback function that |
|---|
| 1116 | 1117 | * was previously registered to get notified of a frequency change of the |
|---|
| .. | .. |
|---|
| 1131 | 1132 | |
|---|
| 1132 | 1133 | struct kbase_clk_rate_trace_op_conf arb_clk_rate_trace_ops = { |
|---|
| 1133 | 1134 | .get_gpu_clk_rate = get_arb_gpu_clk_rate, |
|---|
| 1134 | | - .enumerate_gpu_clk = enumerate_arb_gpu_clk, |
|---|
| 1135 | + .enumerate_gpu_clk = get_arb_gpu_clk, |
|---|
| 1135 | 1136 | .gpu_clk_notifier_register = arb_gpu_clk_notifier_register, |
|---|
| 1136 | 1137 | .gpu_clk_notifier_unregister = arb_gpu_clk_notifier_unregister |
|---|
| 1137 | 1138 | }; |
|---|