3d005b29d2b9931d27cf388f7f4d51cc0bfe9da4
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / t6xx / kbase / src / linux / 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 #if defined(CONFIG_MALI_PLATFORM_FAKE) || defined(CONFIG_MALI_PLATFORM_FAKE_MODULE)
19
20 #include <linux/errno.h>
21 #include <linux/export.h>
22 #include <linux/ioport.h>
23 #include <linux/module.h>
24 #include <linux/platform_device.h>
25 #include <linux/string.h>
26
27 #ifdef CONFIG_MACH_MANTA
28 #include <plat/devs.h>
29 #endif
30
31 /*
32  * This file is included only for type definitions and functions belonging to
33  * specific platform folders. Do not add dependencies with symbols that are
34  * defined somewhere else.
35  */
36 #include <kbase/mali_kbase_config.h>
37
38 #define PLATFORM_CONFIG_RESOURCE_COUNT 4
39 #define PLATFORM_CONFIG_IRQ_RES_COUNT  3
40
41 static struct platform_device *mali_device;
42
43 #ifndef CONFIG_OF
44 /**
45  * @brief Convert data in kbase_io_resources struct to Linux-specific resources
46  *
47  * Function converts data in kbase_io_resources struct to an array of Linux resource structures. Note that function
48  * assumes that size of linux_resource array is at least PLATFORM_CONFIG_RESOURCE_COUNT.
49  * Resources are put in fixed order: I/O memory region, job IRQ, MMU IRQ, GPU IRQ.
50  *
51  * @param[in]  io_resource      Input IO resource data
52  * @param[out] linux_resources  Pointer to output array of Linux resource structures
53  */
54 static void kbasep_config_parse_io_resources(const kbase_io_resources *io_resources, struct resource *const linux_resources)
55 {
56         if (!io_resources || !linux_resources) {
57                 printk(KERN_ERR "%s: couldn't find proper resources\n", __func__);
58                 return;
59         }
60
61         memset(linux_resources, 0, PLATFORM_CONFIG_RESOURCE_COUNT * sizeof(struct resource));
62
63         linux_resources[0].start = io_resources->io_memory_region.start;
64         linux_resources[0].end = io_resources->io_memory_region.end;
65         linux_resources[0].flags = IORESOURCE_MEM;
66
67         linux_resources[1].start = linux_resources[1].end = io_resources->job_irq_number;
68         linux_resources[1].flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL;
69
70         linux_resources[2].start = linux_resources[2].end = io_resources->mmu_irq_number;
71         linux_resources[2].flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL;
72
73         linux_resources[3].start = linux_resources[3].end = io_resources->gpu_irq_number;
74         linux_resources[3].flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL;
75 }
76 #endif /* CONFIG_OF */
77
78 int kbase_platform_fake_register(void)
79 {
80         kbase_platform_config *config;
81         int attribute_count;
82                 
83 #ifndef CONFIG_OF
84         struct resource resources[PLATFORM_CONFIG_RESOURCE_COUNT];
85 #endif
86         int err;
87
88         config = kbase_get_platform_config(); /* declared in kbase/mali_kbase_config.h but defined in platform folder */
89         if (config == NULL)
90         {
91                 printk(KERN_ERR "%s: couldn't get platform config\n", __func__);
92                 return -ENODEV;
93         }
94
95         attribute_count = kbasep_get_config_attribute_count(config->attributes);
96 #ifdef CONFIG_MACH_MANTA
97         err = platform_device_add_data(&exynos5_device_g3d, config->attributes, attribute_count * sizeof(config->attributes[0]));
98         if (err)
99                 return err;
100 #else
101
102         mali_device = platform_device_alloc("mali", 0);
103         if (mali_device == NULL)
104                 return -ENOMEM;
105
106 #ifndef CONFIG_OF
107         kbasep_config_parse_io_resources(config->io_resources, resources);
108         err = platform_device_add_resources(mali_device, resources, PLATFORM_CONFIG_RESOURCE_COUNT);
109         if (err) {
110                 platform_device_put(mali_device);
111                 mali_device = NULL;
112                 return err;
113         }
114 #endif /* CONFIG_OF */
115
116         err = platform_device_add_data(mali_device, config->attributes, attribute_count * sizeof(config->attributes[0]));
117         if (err) {
118                 platform_device_unregister(mali_device);
119                 mali_device = NULL;
120                 return err;
121         }
122
123         err = platform_device_add(mali_device);
124         if (err) {
125                 platform_device_unregister(mali_device);
126                 mali_device = NULL;
127                 return err;
128         }
129 #endif /* CONFIG_CONFIG_MACH_MANTA */
130         return 0;
131 }
132
133 void kbase_platform_fake_unregister(void)
134 {
135         if (mali_device)
136                 platform_device_unregister(mali_device);
137 }
138
139 #ifdef MALI_PLATFORM_FAKE_MODULE
140 module_init(kbase_platform_fake_register);
141 module_exit(kbase_platform_fake_unregister);
142
143 MODULE_LICENSE("GPL");
144 MODULE_VERSION("mali_kbase_platform_fake");
145 #else
146 EXPORT_SYMBOL(kbase_platform_fake_register);
147 EXPORT_SYMBOL(kbase_platform_fake_unregister);
148 #endif
149
150 #endif /* CONFIG_MALI_PLATFORM_FAKE */
151