MALI: midgard: RK: add separate src dir of Midgard driver for RK Linux device
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard_for_linux / backend / gpu / mali_kbase_gpu.c
1 /*
2  *
3  * (C) COPYRIGHT 2014-2015 ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the
6  * GNU General Public License version 2 as published by the Free Software
7  * Foundation, and any use by you of this program is subject to the terms
8  * of such GNU licence.
9  *
10  * A copy of the licence is included with the program, and can also be obtained
11  * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12  * Boston, MA  02110-1301, USA.
13  *
14  */
15
16
17
18
19 /*
20  * Register-based HW access backend APIs
21  */
22 #include <mali_kbase.h>
23 #include <mali_kbase_hwaccess_jm.h>
24 #include <mali_kbase_hwaccess_backend.h>
25 #include <backend/gpu/mali_kbase_irq_internal.h>
26 #include <backend/gpu/mali_kbase_jm_internal.h>
27 #include <backend/gpu/mali_kbase_js_internal.h>
28 #include <backend/gpu/mali_kbase_pm_internal.h>
29
30 int kbase_backend_early_init(struct kbase_device *kbdev)
31 {
32         int err;
33
34         err = kbasep_platform_device_init(kbdev);
35         if (err)
36                 return err;
37
38         /* Ensure we can access the GPU registers */
39         kbase_pm_register_access_enable(kbdev);
40
41         /* Find out GPU properties based on the GPU feature registers */
42         kbase_gpuprops_set(kbdev);
43
44         /* We're done accessing the GPU registers for now. */
45         kbase_pm_register_access_disable(kbdev);
46
47         err = kbase_hwaccess_pm_init(kbdev);
48         if (err)
49                 goto fail_pm;
50
51         err = kbase_install_interrupts(kbdev);
52         if (err)
53                 goto fail_interrupts;
54
55         return 0;
56
57 fail_interrupts:
58         kbase_hwaccess_pm_term(kbdev);
59 fail_pm:
60         kbasep_platform_device_term(kbdev);
61
62         return err;
63 }
64
65 void kbase_backend_early_term(struct kbase_device *kbdev)
66 {
67         kbase_release_interrupts(kbdev);
68         kbase_hwaccess_pm_term(kbdev);
69         kbasep_platform_device_term(kbdev);
70 }
71
72 int kbase_backend_late_init(struct kbase_device *kbdev)
73 {
74         int err;
75
76         err = kbase_hwaccess_pm_powerup(kbdev, PM_HW_ISSUES_DETECT);
77         if (err)
78                 return err;
79
80         err = kbase_backend_timer_init(kbdev);
81         if (err)
82                 goto fail_timer;
83
84 /* Currently disabled on the prototype */
85 #ifdef CONFIG_MALI_DEBUG
86 #ifndef CONFIG_MALI_NO_MALI
87         if (kbasep_common_test_interrupt_handlers(kbdev) != 0) {
88                 dev_err(kbdev->dev, "Interrupt assigment check failed.\n");
89                 err = -EINVAL;
90                 goto fail_interrupt_test;
91         }
92 #endif /* !CONFIG_MALI_NO_MALI */
93 #endif /* CONFIG_MALI_DEBUG */
94
95         err = kbase_job_slot_init(kbdev);
96         if (err)
97                 goto fail_job_slot;
98
99         init_waitqueue_head(&kbdev->hwaccess.backend.reset_wait);
100
101         return 0;
102
103 fail_job_slot:
104 /* Currently disabled on the prototype */
105 #ifdef CONFIG_MALI_DEBUG
106 #ifndef CONFIG_MALI_NO_MALI
107 fail_interrupt_test:
108 #endif /* !CONFIG_MALI_NO_MALI */
109 #endif /* CONFIG_MALI_DEBUG */
110         kbase_backend_timer_term(kbdev);
111 fail_timer:
112         kbase_hwaccess_pm_halt(kbdev);
113
114         return err;
115 }
116
117 void kbase_backend_late_term(struct kbase_device *kbdev)
118 {
119         kbase_job_slot_halt(kbdev);
120         kbase_job_slot_term(kbdev);
121         kbase_backend_timer_term(kbdev);
122         kbase_hwaccess_pm_halt(kbdev);
123 }
124