136db61ace4a4fc36f6363b35d905b8eaf5e5a27
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / mali400 / mali / common / mali_broadcast.c
1 /*
2  * Copyright (C) 2012-2015 ARM Limited. All rights reserved.
3  * 
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  * 
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9  */
10
11 #include "mali_broadcast.h"
12 #include "mali_kernel_common.h"
13 #include "mali_osk.h"
14
15 #define MALI_BROADCAST_REGISTER_SIZE      0x1000
16 #define MALI_BROADCAST_REG_BROADCAST_MASK    0x0
17 #define MALI_BROADCAST_REG_INTERRUPT_MASK    0x4
18
19 struct mali_bcast_unit {
20         struct mali_hw_core hw_core;
21         u32 current_mask;
22 };
23
24 struct mali_bcast_unit *mali_bcast_unit_create(const _mali_osk_resource_t *resource)
25 {
26         struct mali_bcast_unit *bcast_unit = NULL;
27
28         MALI_DEBUG_ASSERT_POINTER(resource);
29         MALI_DEBUG_PRINT(2, ("Broadcast: Creating Mali Broadcast unit: %s\n",
30                              resource->description));
31
32         bcast_unit = _mali_osk_malloc(sizeof(struct mali_bcast_unit));
33         if (NULL == bcast_unit) {
34                 MALI_PRINT_ERROR(("Broadcast: Failed to allocate memory for Broadcast unit\n"));
35                 return NULL;
36         }
37
38         if (_MALI_OSK_ERR_OK == mali_hw_core_create(&bcast_unit->hw_core,
39                         resource, MALI_BROADCAST_REGISTER_SIZE)) {
40                 bcast_unit->current_mask = 0;
41                 mali_bcast_reset(bcast_unit);
42
43                 return bcast_unit;
44         } else {
45                 MALI_PRINT_ERROR(("Broadcast: Failed map broadcast unit\n"));
46         }
47
48         _mali_osk_free(bcast_unit);
49
50         return NULL;
51 }
52
53 void mali_bcast_unit_delete(struct mali_bcast_unit *bcast_unit)
54 {
55         MALI_DEBUG_ASSERT_POINTER(bcast_unit);
56         mali_hw_core_delete(&bcast_unit->hw_core);
57         _mali_osk_free(bcast_unit);
58 }
59
60 /* Call this function to add the @group's id into bcast mask
61  * Note: redundant calling this function with same @group
62  * doesn't make any difference as calling it once
63  */
64 void mali_bcast_add_group(struct mali_bcast_unit *bcast_unit,
65                           struct mali_group *group)
66 {
67         u32 bcast_id;
68         u32 broadcast_mask;
69
70         MALI_DEBUG_ASSERT_POINTER(bcast_unit);
71         MALI_DEBUG_ASSERT_POINTER(group);
72
73         bcast_id = mali_pp_core_get_bcast_id(mali_group_get_pp_core(group));
74
75         broadcast_mask = bcast_unit->current_mask;
76
77         broadcast_mask |= (bcast_id); /* add PP core to broadcast */
78         broadcast_mask |= (bcast_id << 16); /* add MMU to broadcast */
79
80         /* store mask so we can restore on reset */
81         bcast_unit->current_mask = broadcast_mask;
82 }
83
84 /* Call this function to remove @group's id from bcast mask
85  * Note: redundant calling this function with same @group
86  * doesn't make any difference as calling it once
87  */
88 void mali_bcast_remove_group(struct mali_bcast_unit *bcast_unit,
89                              struct mali_group *group)
90 {
91         u32 bcast_id;
92         u32 broadcast_mask;
93
94         MALI_DEBUG_ASSERT_POINTER(bcast_unit);
95         MALI_DEBUG_ASSERT_POINTER(group);
96
97         bcast_id = mali_pp_core_get_bcast_id(mali_group_get_pp_core(group));
98
99         broadcast_mask = bcast_unit->current_mask;
100
101         broadcast_mask &= ~((bcast_id << 16) | bcast_id);
102
103         /* store mask so we can restore on reset */
104         bcast_unit->current_mask = broadcast_mask;
105 }
106
107 void mali_bcast_reset(struct mali_bcast_unit *bcast_unit)
108 {
109         MALI_DEBUG_ASSERT_POINTER(bcast_unit);
110
111         MALI_DEBUG_PRINT(4,
112                          ("Broadcast: setting mask 0x%08X + 0x%08X (reset)\n",
113                           bcast_unit->current_mask,
114                           bcast_unit->current_mask & 0xFF));
115
116         /* set broadcast mask */
117         mali_hw_core_register_write(&bcast_unit->hw_core,
118                                     MALI_BROADCAST_REG_BROADCAST_MASK,
119                                     bcast_unit->current_mask);
120
121         /* set IRQ override mask */
122         mali_hw_core_register_write(&bcast_unit->hw_core,
123                                     MALI_BROADCAST_REG_INTERRUPT_MASK,
124                                     bcast_unit->current_mask & 0xFF);
125 }
126
127 void mali_bcast_disable(struct mali_bcast_unit *bcast_unit)
128 {
129         MALI_DEBUG_ASSERT_POINTER(bcast_unit);
130
131         MALI_DEBUG_PRINT(4, ("Broadcast: setting mask 0x0 + 0x0 (disable)\n"));
132
133         /* set broadcast mask */
134         mali_hw_core_register_write(&bcast_unit->hw_core,
135                                     MALI_BROADCAST_REG_BROADCAST_MASK,
136                                     0x0);
137
138         /* set IRQ override mask */
139         mali_hw_core_register_write(&bcast_unit->hw_core,
140                                     MALI_BROADCAST_REG_INTERRUPT_MASK,
141                                     0x0);
142 }