rk3288 gpu : update GPU driver r4p0_eac version
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_platform_fake.c
1 /*
2  *
3  * (C) COPYRIGHT ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the
6  * GNU General Public License version 2 as published by the Free Software
7  * Foundation, and any use by you of this program is subject to the terms
8  * of such GNU licence.
9  *
10  * A copy of the licence is included with the program, and can also be obtained
11  * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12  * Boston, MA  02110-1301, USA.
13  *
14  */
15
16
17
18 #ifdef CONFIG_MALI_PLATFORM_FAKE
19
20 #include <linux/errno.h>
21 #include <linux/export.h>
22 #include <linux/ioport.h>
23 #include <linux/platform_device.h>
24 #include <linux/string.h>
25
26 #ifdef CONFIG_MACH_MANTA
27 #include <plat/devs.h>
28 #endif
29
30 /*
31  * This file is included only for type definitions and functions belonging to
32  * specific platform folders. Do not add dependencies with symbols that are
33  * defined somewhere else.
34  */
35 #include <mali_kbase_config.h>
36
37 #define PLATFORM_CONFIG_RESOURCE_COUNT 4
38 #define PLATFORM_CONFIG_IRQ_RES_COUNT  3
39
40 static struct platform_device *mali_device;
41
42 #ifndef CONFIG_OF
43 /**
44  * @brief Convert data in kbase_io_resources struct to Linux-specific resources
45  *
46  * Function converts data in kbase_io_resources struct to an array of Linux resource structures. Note that function
47  * assumes that size of linux_resource array is at least PLATFORM_CONFIG_RESOURCE_COUNT.
48  * Resources are put in fixed order: I/O memory region, job IRQ, MMU IRQ, GPU IRQ.
49  *
50  * @param[in]  io_resource      Input IO resource data
51  * @param[out] linux_resources  Pointer to output array of Linux resource structures
52  */
53 static void kbasep_config_parse_io_resources(const kbase_io_resources *io_resources, struct resource *const linux_resources)
54 {
55         if (!io_resources || !linux_resources) {
56                 pr_err("%s: couldn't find proper resources\n", __func__);
57                 return;
58         }
59
60         memset(linux_resources, 0, PLATFORM_CONFIG_RESOURCE_COUNT * sizeof(struct resource));
61
62         linux_resources[0].start = io_resources->io_memory_region.start;
63         linux_resources[0].end = io_resources->io_memory_region.end;
64         linux_resources[0].flags = IORESOURCE_MEM;
65
66         linux_resources[1].start = linux_resources[1].end = io_resources->job_irq_number;
67         linux_resources[1].flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL;
68
69         linux_resources[2].start = linux_resources[2].end = io_resources->mmu_irq_number;
70         linux_resources[2].flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL;
71
72         linux_resources[3].start = linux_resources[3].end = io_resources->gpu_irq_number;
73         linux_resources[3].flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL;
74 }
75 #endif /* CONFIG_OF */
76
77 int kbase_platform_fake_register(void)
78 {
79         kbase_platform_config *config;
80         int attribute_count;
81 #ifndef CONFIG_OF
82         struct resource resources[PLATFORM_CONFIG_RESOURCE_COUNT];
83 #endif
84         int err;
85
86         config = kbase_get_platform_config(); /* declared in midgard/mali_kbase_config.h but defined in platform folder */
87         if (config == NULL)
88         {
89                 pr_err("%s: couldn't get platform config\n", __func__);
90                 return -ENODEV;
91         }
92
93         attribute_count = kbasep_get_config_attribute_count(config->attributes);
94 #ifdef CONFIG_MACH_MANTA
95         err = platform_device_add_data(&exynos5_device_g3d, config->attributes, attribute_count * sizeof(config->attributes[0]));
96         if (err)
97                 return err;
98 #else
99
100         mali_device = platform_device_alloc("mali", 0);
101         if (mali_device == NULL)
102                 return -ENOMEM;
103
104 #ifndef CONFIG_OF
105         kbasep_config_parse_io_resources(config->io_resources, resources);
106         err = platform_device_add_resources(mali_device, resources, PLATFORM_CONFIG_RESOURCE_COUNT);
107         if (err) {
108                 platform_device_put(mali_device);
109                 mali_device = NULL;
110                 return err;
111         }
112 #endif /* CONFIG_OF */
113
114         err = platform_device_add_data(mali_device, config->attributes, attribute_count * sizeof(config->attributes[0]));
115         if (err) {
116                 platform_device_unregister(mali_device);
117                 mali_device = NULL;
118                 return err;
119         }
120
121         err = platform_device_add(mali_device);
122         if (err) {
123                 platform_device_unregister(mali_device);
124                 mali_device = NULL;
125                 return err;
126         }
127 #endif /* CONFIG_CONFIG_MACH_MANTA */
128
129         return 0;
130 }
131
132 void kbase_platform_fake_unregister(void)
133 {
134         if (mali_device)
135                 platform_device_unregister(mali_device);
136 }
137
138 EXPORT_SYMBOL(kbase_platform_fake_register);
139 EXPORT_SYMBOL(kbase_platform_fake_unregister);
140
141 #endif /* CONFIG_MALI_PLATFORM_FAKE */
142