tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / mali / linux / mali_osk_mali.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 /**
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_uk_types.h"
24 #include "mali_kernel_linux.h"
25
26 _mali_osk_errcode_t _mali_osk_resource_find(u32 addr, _mali_osk_resource_t *res)
27 {
28         int i;
29
30         if (NULL == mali_platform_device)
31         {
32                 /* Not connected to a device */
33                 return _MALI_OSK_ERR_ITEM_NOT_FOUND;
34         }
35
36         for (i = 0; i < mali_platform_device->num_resources; i++)
37         {
38                 if (IORESOURCE_MEM == resource_type(&(mali_platform_device->resource[i])) &&
39                     mali_platform_device->resource[i].start == addr)
40                 {
41                         if (NULL != res)
42                         {
43                                 res->base = addr;
44                                 res->description = mali_platform_device->resource[i].name;
45
46                                 /* Any (optional) IRQ resource belonging to this resource will follow */
47                                 if ((i + 1) < mali_platform_device->num_resources &&
48                                     IORESOURCE_IRQ == resource_type(&(mali_platform_device->resource[i+1])))
49                                 {
50                                         res->irq = mali_platform_device->resource[i+1].start;
51                                 }
52                                 else
53                                 {
54                                         res->irq = -1;
55                                 }
56                         }
57                         return _MALI_OSK_ERR_OK;
58                 }
59         }
60
61         return _MALI_OSK_ERR_ITEM_NOT_FOUND;
62 }
63
64 u32 _mali_osk_resource_base_address(void)
65 {
66         u32 lowest_addr = 0xFFFFFFFF;
67         u32 ret = 0;
68
69         if (NULL != mali_platform_device)
70         {
71                 int i;
72                 for (i = 0; i < mali_platform_device->num_resources; i++)
73                 {
74                         if (mali_platform_device->resource[i].flags & IORESOURCE_MEM &&
75                             mali_platform_device->resource[i].start < lowest_addr)
76                         {
77                                 lowest_addr = mali_platform_device->resource[i].start;
78                                 ret = lowest_addr;
79                         }
80                 }
81         }
82
83         return ret;
84 }
85
86 _mali_osk_errcode_t _mali_osk_device_data_get(struct _mali_osk_device_data *data)
87 {
88         MALI_DEBUG_ASSERT_POINTER(data);
89
90         if (NULL != mali_platform_device)
91         {
92                 struct mali_gpu_device_data* os_data = NULL;
93
94                 os_data = (struct mali_gpu_device_data*)mali_platform_device->dev.platform_data;
95                 if (NULL != os_data)
96                 {
97                         /* Copy data from OS dependant struct to Mali neutral struct (identical!) */
98                         data->dedicated_mem_start = os_data->dedicated_mem_start;
99                         data->dedicated_mem_size = os_data->dedicated_mem_size;
100                         data->shared_mem_size = os_data->shared_mem_size;
101                         data->fb_start = os_data->fb_start;
102                         data->fb_size = os_data->fb_size;
103                         data->utilization_interval = os_data->utilization_interval;
104                         data->utilization_handler = os_data->utilization_handler;
105                         return _MALI_OSK_ERR_OK;
106                 }
107         }
108
109         return _MALI_OSK_ERR_ITEM_NOT_FOUND;
110 }