tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / r4p0_rel0 / linux / mali_osk_mali.c
1 /*
2  * Copyright (C) 2010-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 /**
12  * @file mali_osk_mali.c
13  * Implementation of the OS abstraction layer which is specific for the Mali kernel device driver
14  */
15 #include <linux/kernel.h>
16 #include <asm/uaccess.h>
17 #include <linux/platform_device.h>
18 #include <linux/mali/mali_utgard.h>
19
20 #include "mali_osk_mali.h"
21 #include "mali_kernel_common.h" /* MALI_xxx macros */
22 #include "mali_osk.h"           /* kernel side OS functions */
23 #include "mali_kernel_linux.h"
24
25 _mali_osk_errcode_t _mali_osk_resource_find(u32 addr, _mali_osk_resource_t *res)
26 {
27         int i;
28
29         if (NULL == mali_platform_device) {
30                 /* Not connected to a device */
31                 return _MALI_OSK_ERR_ITEM_NOT_FOUND;
32         }
33
34         for (i = 0; i < mali_platform_device->num_resources; i++) {
35                 if (IORESOURCE_MEM == resource_type(&(mali_platform_device->resource[i])) &&
36                     mali_platform_device->resource[i].start == addr) {
37                         if (NULL != res) {
38                                 res->base = addr;
39                                 res->description = mali_platform_device->resource[i].name;
40
41                                 /* Any (optional) IRQ resource belonging to this resource will follow */
42                                 if ((i + 1) < mali_platform_device->num_resources &&
43                                     IORESOURCE_IRQ == resource_type(&(mali_platform_device->resource[i+1]))) {
44                                         res->irq = mali_platform_device->resource[i+1].start;
45                                 } else {
46                                         res->irq = -1;
47                                 }
48                         }
49                         return _MALI_OSK_ERR_OK;
50                 }
51         }
52
53         return _MALI_OSK_ERR_ITEM_NOT_FOUND;
54 }
55
56 u32 _mali_osk_resource_base_address(void)
57 {
58         u32 lowest_addr = 0xFFFFFFFF;
59         u32 ret = 0;
60
61         if (NULL != mali_platform_device) {
62                 int i;
63                 for (i = 0; i < mali_platform_device->num_resources; i++) {
64                         if (mali_platform_device->resource[i].flags & IORESOURCE_MEM &&
65                             mali_platform_device->resource[i].start < lowest_addr) {
66                                 lowest_addr = mali_platform_device->resource[i].start;
67                                 ret = lowest_addr;
68                         }
69                 }
70         }
71
72         return ret;
73 }
74
75 _mali_osk_errcode_t _mali_osk_device_data_get(struct _mali_osk_device_data *data)
76 {
77         MALI_DEBUG_ASSERT_POINTER(data);
78
79         if (NULL != mali_platform_device) {
80                 struct mali_gpu_device_data* os_data = NULL;
81
82                 os_data = (struct mali_gpu_device_data*)mali_platform_device->dev.platform_data;
83                 if (NULL != os_data) {
84                         /* Copy data from OS dependant struct to Mali neutral struct (identical!) */
85                         data->dedicated_mem_start = os_data->dedicated_mem_start;
86                         data->dedicated_mem_size = os_data->dedicated_mem_size;
87                         data->shared_mem_size = os_data->shared_mem_size;
88                         data->fb_start = os_data->fb_start;
89                         data->fb_size = os_data->fb_size;
90                         data->max_job_runtime = os_data->max_job_runtime;
91                         data->utilization_interval = os_data->utilization_interval;
92                         data->utilization_callback = os_data->utilization_callback;
93                         data->pmu_switch_delay = os_data->pmu_switch_delay;
94                         data->set_freq_callback = os_data->set_freq_callback;
95
96                         memcpy(data->pmu_domain_config, os_data->pmu_domain_config, sizeof(os_data->pmu_domain_config));
97                         return _MALI_OSK_ERR_OK;
98                 }
99         }
100
101         return _MALI_OSK_ERR_ITEM_NOT_FOUND;
102 }
103
104 mali_bool _mali_osk_shared_interrupts(void)
105 {
106         u32 irqs[128];
107         u32 i, j, irq, num_irqs_found = 0;
108
109         MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
110         MALI_DEBUG_ASSERT(128 >= mali_platform_device->num_resources);
111
112         for (i = 0; i < mali_platform_device->num_resources; i++) {
113                 if (IORESOURCE_IRQ & mali_platform_device->resource[i].flags) {
114                         irq = mali_platform_device->resource[i].start;
115
116                         for (j = 0; j < num_irqs_found; ++j) {
117                                 if (irq == irqs[j]) {
118                                         return MALI_TRUE;
119                                 }
120                         }
121
122                         irqs[num_irqs_found++] = irq;
123                 }
124         }
125
126         return MALI_FALSE;
127 }