tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / mali / common / mali_broadcast.c
1 /*
2  * Copyright (C) 2011-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 {
21         struct mali_hw_core hw_core;
22         u32 current_mask;
23 };
24
25 struct mali_bcast_unit *mali_bcast_unit_create(const _mali_osk_resource_t *resource)
26 {
27         struct mali_bcast_unit *bcast_unit = NULL;
28
29         MALI_DEBUG_ASSERT_POINTER(resource);
30         MALI_DEBUG_PRINT(2, ("Mali Broadcast unit: Creating Mali Broadcast unit: %s\n", resource->description));
31
32         bcast_unit = _mali_osk_malloc(sizeof(struct mali_bcast_unit));
33         if (NULL == bcast_unit)
34         {
35                 return NULL;
36         }
37
38         if (_MALI_OSK_ERR_OK == mali_hw_core_create(&bcast_unit->hw_core, resource, bcast_unit_reg_size))
39         {
40                 bcast_unit->current_mask = 0;
41                 mali_bcast_reset(bcast_unit);
42
43                 return bcast_unit;
44         }
45         else
46         {
47                 MALI_PRINT_ERROR(("Mali Broadcast unit: Failed to allocate memory for Broadcast unit\n"));
48         }
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
57         mali_hw_core_delete(&bcast_unit->hw_core);
58         _mali_osk_free(bcast_unit);
59 }
60
61 void mali_bcast_add_group(struct mali_bcast_unit *bcast_unit, struct mali_group *group)
62 {
63         u32 core_id;
64         u32 broadcast_mask;
65
66         MALI_DEBUG_ASSERT_POINTER(bcast_unit);
67         MALI_DEBUG_ASSERT_POINTER(group);
68
69         core_id = mali_pp_core_get_id(mali_group_get_pp_core(group));
70         broadcast_mask = bcast_unit->current_mask;
71
72         /* set the bit corresponding to the group's core's id to 1 */
73         core_id = 1 << core_id;
74         broadcast_mask |= (core_id); /* add PP core to broadcast */
75         broadcast_mask |= (core_id << 16); /* add MMU to broadcast */
76
77         /* store mask so we can restore on reset */
78         bcast_unit->current_mask = broadcast_mask;
79
80         mali_bcast_reset(bcast_unit);
81 }
82
83 void mali_bcast_remove_group(struct mali_bcast_unit *bcast_unit, struct mali_group *group)
84 {
85         u32 core_id;
86         u32 broadcast_mask;
87
88         MALI_DEBUG_ASSERT_POINTER(bcast_unit);
89         MALI_DEBUG_ASSERT_POINTER(group);
90
91         core_id = mali_pp_core_get_id(mali_group_get_pp_core(group));
92         broadcast_mask = bcast_unit->current_mask;
93
94         /* set the bit corresponding to the group's core's id to 0 */
95         core_id = 1 << core_id;
96         broadcast_mask &= ~((core_id << 16) | core_id);
97
98         /* store mask so we can restore on reset */
99         bcast_unit->current_mask = broadcast_mask;
100
101         mali_bcast_reset(bcast_unit);
102 }
103
104 void mali_bcast_reset(struct mali_bcast_unit *bcast_unit)
105 {
106         MALI_DEBUG_ASSERT_POINTER(bcast_unit);
107
108         /* set broadcast mask */
109         mali_hw_core_register_write(&bcast_unit->hw_core,
110                                     bcast_unit_addr_broadcast_mask,
111                                     bcast_unit->current_mask);
112
113         /* set IRQ override mask */
114         mali_hw_core_register_write(&bcast_unit->hw_core,
115                                     bcast_unit_addr_irq_override_mask,
116                                     bcast_unit->current_mask & 0xFF);
117 }