2 * Copyright (C) 2010-2012 ARM Limited. All rights reserved.
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.
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.
12 * @file mali_osk_mali.c
13 * Implementation of the OS abstraction layer which is specific for the Mali kernel device driver
15 #include <linux/kernel.h>
16 #include <asm/uaccess.h>
17 #include <linux/platform_device.h>
18 #include <linux/mali/mali_utgard.h>
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"
25 _mali_osk_errcode_t _mali_osk_resource_find(u32 addr, _mali_osk_resource_t *res)
29 if (NULL == mali_platform_device) {
30 /* Not connected to a device */
31 return _MALI_OSK_ERR_ITEM_NOT_FOUND;
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) {
39 res->description = mali_platform_device->resource[i].name;
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;
49 return _MALI_OSK_ERR_OK;
53 return _MALI_OSK_ERR_ITEM_NOT_FOUND;
56 u32 _mali_osk_resource_base_address(void)
58 u32 lowest_addr = 0xFFFFFFFF;
61 if (NULL != mali_platform_device) {
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;
75 _mali_osk_errcode_t _mali_osk_device_data_get(struct _mali_osk_device_data *data)
77 MALI_DEBUG_ASSERT_POINTER(data);
79 if (NULL != mali_platform_device) {
80 struct mali_gpu_device_data* os_data = NULL;
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;
96 memcpy(data->pmu_domain_config, os_data->pmu_domain_config, sizeof(os_data->pmu_domain_config));
97 return _MALI_OSK_ERR_OK;
101 return _MALI_OSK_ERR_ITEM_NOT_FOUND;
104 mali_bool _mali_osk_shared_interrupts(void)
107 u32 i, j, irq, num_irqs_found = 0;
109 MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
110 MALI_DEBUG_ASSERT(128 >= mali_platform_device->num_resources);
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;
116 for (j = 0; j < num_irqs_found; ++j) {
117 if (irq == irqs[j]) {
122 irqs[num_irqs_found++] = irq;