hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
/*
 *
 * (C) COPYRIGHT 2020-2022 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 <mali_kbase.h>
#include <gpu/mali_kbase_gpu_fault.h>
#include <backend/gpu/mali_kbase_instr_internal.h>
#include <backend/gpu/mali_kbase_pm_internal.h>
#include <device/mali_kbase_device.h>
#include <mali_kbase_reset_gpu.h>
#include <mmu/mali_kbase_mmu.h>
 
/**
 * kbase_report_gpu_fault - Report a GPU fault.
 * @kbdev:    Kbase device pointer
 * @multiple: Zero if only GPU_FAULT was raised, non-zero if MULTIPLE_GPU_FAULTS
 *            was also set
 *
 * This function is called from the interrupt handler when a GPU fault occurs.
 * It reports the details of the fault using dev_warn().
 */
static void kbase_report_gpu_fault(struct kbase_device *kbdev, int multiple)
{
   u32 status = kbase_reg_read(kbdev, GPU_CONTROL_REG(GPU_FAULTSTATUS));
   u64 address = (u64) kbase_reg_read(kbdev,
           GPU_CONTROL_REG(GPU_FAULTADDRESS_HI)) << 32;
 
   address |= kbase_reg_read(kbdev,
           GPU_CONTROL_REG(GPU_FAULTADDRESS_LO));
 
   dev_warn(kbdev->dev, "GPU Fault 0x%08x (%s) at 0x%016llx",
       status,
       kbase_gpu_exception_name(status & 0xFF),
       address);
   if (multiple)
       dev_warn(kbdev->dev, "There were multiple GPU faults - some have not been reported\n");
 
}
 
void kbase_gpu_interrupt(struct kbase_device *kbdev, u32 val)
{
   KBASE_KTRACE_ADD(kbdev, CORE_GPU_IRQ, NULL, val);
   if (val & GPU_FAULT)
       kbase_report_gpu_fault(kbdev, val & MULTIPLE_GPU_FAULTS);
 
   if (val & RESET_COMPLETED)
       kbase_pm_reset_done(kbdev);
 
   /* Defer clearing CLEAN_CACHES_COMPLETED to kbase_clean_caches_done.
    * We need to acquire hwaccess_lock to avoid a race condition with
    * kbase_gpu_cache_flush_and_busy_wait
    */
   KBASE_KTRACE_ADD(kbdev, CORE_GPU_IRQ_CLEAR, NULL, val & ~CLEAN_CACHES_COMPLETED);
   kbase_reg_write(kbdev, GPU_CONTROL_REG(GPU_IRQ_CLEAR), val & ~CLEAN_CACHES_COMPLETED);
 
   /* kbase_instr_hwcnt_sample_done frees the HWCNT pipeline to request another
    * sample. Therefore this must be called after clearing the IRQ to avoid a
    * race between clearing and the next sample raising the IRQ again.
    */
   if (val & PRFCNT_SAMPLE_COMPLETED)
       kbase_instr_hwcnt_sample_done(kbdev);
 
   /* kbase_pm_check_transitions (called by kbase_pm_power_changed) must
    * be called after the IRQ has been cleared. This is because it might
    * trigger further power transitions and we don't want to miss the
    * interrupt raised to notify us that these further transitions have
    * finished. The same applies to kbase_clean_caches_done() - if another
    * clean was queued, it might trigger another clean, which might
    * generate another interrupt which shouldn't be missed.
    */
 
   if (val & CLEAN_CACHES_COMPLETED)
       kbase_clean_caches_done(kbdev);
 
   if (val & POWER_CHANGED_ALL) {
       kbase_pm_power_changed(kbdev);
   } else if (val & CLEAN_CACHES_COMPLETED) {
       /* If cache line evict messages can be lost when shader cores
        * power down then we need to flush the L2 cache before powering
        * down cores. When the flush completes, the shaders' state
        * machine needs to be re-invoked to proceed with powering down
        * cores.
        */
       if (kbdev->pm.backend.l2_always_on ||
           kbase_hw_has_issue(kbdev, BASE_HW_ISSUE_TTRX_921))
           kbase_pm_power_changed(kbdev);
   }
 
   KBASE_KTRACE_ADD(kbdev, CORE_GPU_IRQ_DONE, NULL, val);
}
 
#if IS_ENABLED(CONFIG_MALI_REAL_HW)
void kbase_reg_write(struct kbase_device *kbdev, u32 offset, u32 value)
{
   WARN_ON(!kbdev->pm.backend.gpu_powered);
 
   writel(value, kbdev->reg + offset);
 
#if IS_ENABLED(CONFIG_DEBUG_FS)
   if (unlikely(kbdev->io_history.enabled))
       kbase_io_history_add(&kbdev->io_history, kbdev->reg + offset,
                    value, 1);
#endif /* CONFIG_DEBUG_FS */
   dev_dbg(kbdev->dev, "w: reg %08x val %08x", offset, value);
}
KBASE_EXPORT_TEST_API(kbase_reg_write);
 
u32 kbase_reg_read(struct kbase_device *kbdev, u32 offset)
{
   u32 val;
 
   WARN_ON(!kbdev->pm.backend.gpu_powered);
 
   val = readl(kbdev->reg + offset);
 
#if IS_ENABLED(CONFIG_DEBUG_FS)
   if (unlikely(kbdev->io_history.enabled))
       kbase_io_history_add(&kbdev->io_history, kbdev->reg + offset,
                    val, 0);
#endif /* CONFIG_DEBUG_FS */
   dev_dbg(kbdev->dev, "r: reg %08x val %08x", offset, val);
 
   return val;
}
KBASE_EXPORT_TEST_API(kbase_reg_read);
#endif /* IS_ENABLED(CONFIG_MALI_REAL_HW) */