tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / r4p0_rel0 / common / mali_broadcast.c
1 /*
2  * Copyright (C) 2012 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 static const int bcast_unit_reg_size = 0x1000;
16 static const int bcast_unit_addr_broadcast_mask = 0x0;
17 static const int bcast_unit_addr_irq_override_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, ("Mali Broadcast unit: Creating Mali Broadcast unit: %s\n", resource->description));
30
31         bcast_unit = _mali_osk_malloc(sizeof(struct mali_bcast_unit));
32         if (NULL == bcast_unit) {
33                 MALI_PRINT_ERROR(("Mali Broadcast unit: Failed to allocate memory for Broadcast unit\n"));
34                 return NULL;
35         }
36
37         if (_MALI_OSK_ERR_OK == mali_hw_core_create(&bcast_unit->hw_core, resource, bcast_unit_reg_size)) {
38                 bcast_unit->current_mask = 0;
39                 mali_bcast_reset(bcast_unit);
40
41                 return bcast_unit;
42         } else {
43                 MALI_PRINT_ERROR(("Mali Broadcast unit: Failed map broadcast unit\n"));
44         }
45
46         _mali_osk_free(bcast_unit);
47
48         return NULL;
49 }
50
51 void mali_bcast_unit_delete(struct mali_bcast_unit *bcast_unit)
52 {
53         MALI_DEBUG_ASSERT_POINTER(bcast_unit);
54
55         mali_hw_core_delete(&bcast_unit->hw_core);
56         _mali_osk_free(bcast_unit);
57 }
58
59 void mali_bcast_add_group(struct mali_bcast_unit *bcast_unit, struct mali_group *group)
60 {
61         u32 bcast_id;
62         u32 broadcast_mask;
63
64         MALI_DEBUG_ASSERT_POINTER(bcast_unit);
65         MALI_DEBUG_ASSERT_POINTER(group);
66
67         bcast_id = mali_pp_core_get_bcast_id(mali_group_get_pp_core(group));
68
69         broadcast_mask = bcast_unit->current_mask;
70
71         broadcast_mask |= (bcast_id); /* add PP core to broadcast */
72         broadcast_mask |= (bcast_id << 16); /* add MMU to broadcast */
73
74         /* store mask so we can restore on reset */
75         bcast_unit->current_mask = broadcast_mask;
76 }
77
78 void mali_bcast_remove_group(struct mali_bcast_unit *bcast_unit, struct mali_group *group)
79 {
80         u32 bcast_id;
81         u32 broadcast_mask;
82
83         MALI_DEBUG_ASSERT_POINTER(bcast_unit);
84         MALI_DEBUG_ASSERT_POINTER(group);
85
86         bcast_id = mali_pp_core_get_bcast_id(mali_group_get_pp_core(group));
87
88         broadcast_mask = bcast_unit->current_mask;
89
90         broadcast_mask &= ~((bcast_id << 16) | bcast_id);
91
92         /* store mask so we can restore on reset */
93         bcast_unit->current_mask = broadcast_mask;
94 }
95
96 void mali_bcast_reset(struct mali_bcast_unit *bcast_unit)
97 {
98         MALI_DEBUG_ASSERT_POINTER(bcast_unit);
99
100         /* set broadcast mask */
101         mali_hw_core_register_write(&bcast_unit->hw_core,
102                                     bcast_unit_addr_broadcast_mask,
103                                     bcast_unit->current_mask);
104
105         /* set IRQ override mask */
106         mali_hw_core_register_write(&bcast_unit->hw_core,
107                                     bcast_unit_addr_irq_override_mask,
108                                     bcast_unit->current_mask & 0xFF);
109 }
110
111 void mali_bcast_disable(struct mali_bcast_unit *bcast_unit)
112 {
113         MALI_DEBUG_ASSERT_POINTER(bcast_unit);
114
115         /* set broadcast mask */
116         mali_hw_core_register_write(&bcast_unit->hw_core,
117                                     bcast_unit_addr_broadcast_mask,
118                                     0x0);
119
120         /* set IRQ override mask */
121         mali_hw_core_register_write(&bcast_unit->hw_core,
122                                     bcast_unit_addr_irq_override_mask,
123                                     0x0);
124 }