xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/midgard/mali_kbase_platform_fake.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *
3  * (C) COPYRIGHT 2011-2014, 2016 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 
27 /*
28  * This file is included only for type definitions and functions belonging to
29  * specific platform folders. Do not add dependencies with symbols that are
30  * defined somewhere else.
31  */
32 #include <mali_kbase_config.h>
33 
34 #define PLATFORM_CONFIG_RESOURCE_COUNT 4
35 #define PLATFORM_CONFIG_IRQ_RES_COUNT  3
36 
37 static struct platform_device *mali_device;
38 
39 #ifndef CONFIG_OF
40 /**
41  * @brief Convert data in struct kbase_io_resources struct to Linux-specific resources
42  *
43  * Function converts data in struct kbase_io_resources struct to an array of Linux resource structures. Note that function
44  * assumes that size of linux_resource array is at least PLATFORM_CONFIG_RESOURCE_COUNT.
45  * Resources are put in fixed order: I/O memory region, job IRQ, MMU IRQ, GPU IRQ.
46  *
47  * @param[in]  io_resource      Input IO resource data
48  * @param[out] linux_resources  Pointer to output array of Linux resource structures
49  */
kbasep_config_parse_io_resources(const struct kbase_io_resources * io_resources,struct resource * const linux_resources)50 static void kbasep_config_parse_io_resources(const struct kbase_io_resources *io_resources, struct resource *const linux_resources)
51 {
52 	if (!io_resources || !linux_resources) {
53 		pr_err("%s: couldn't find proper resources\n", __func__);
54 		return;
55 	}
56 
57 	memset(linux_resources, 0, PLATFORM_CONFIG_RESOURCE_COUNT * sizeof(struct resource));
58 
59 	linux_resources[0].start = io_resources->io_memory_region.start;
60 	linux_resources[0].end   = io_resources->io_memory_region.end;
61 	linux_resources[0].flags = IORESOURCE_MEM;
62 
63 	linux_resources[1].start = io_resources->job_irq_number;
64 	linux_resources[1].end   = io_resources->job_irq_number;
65 	linux_resources[1].flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL;
66 
67 	linux_resources[2].start = io_resources->mmu_irq_number;
68 	linux_resources[2].end   = io_resources->mmu_irq_number;
69 	linux_resources[2].flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL;
70 
71 	linux_resources[3].start = io_resources->gpu_irq_number;
72 	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 
kbase_platform_fake_register(void)77 int kbase_platform_fake_register(void)
78 {
79 	struct kbase_platform_config *config;
80 #ifndef CONFIG_OF
81 	struct resource resources[PLATFORM_CONFIG_RESOURCE_COUNT];
82 #endif
83 	int err;
84 
85 	config = kbase_get_platform_config(); /* declared in midgard/mali_kbase_config.h but defined in platform folder */
86 	if (config == NULL) {
87 		pr_err("%s: couldn't get platform config\n", __func__);
88 		return -ENODEV;
89 	}
90 
91 	mali_device = platform_device_alloc("mali", 0);
92 	if (mali_device == NULL)
93 		return -ENOMEM;
94 
95 #ifndef CONFIG_OF
96 	kbasep_config_parse_io_resources(config->io_resources, resources);
97 	err = platform_device_add_resources(mali_device, resources, PLATFORM_CONFIG_RESOURCE_COUNT);
98 	if (err) {
99 		platform_device_put(mali_device);
100 		mali_device = NULL;
101 		return err;
102 	}
103 #endif /* CONFIG_OF */
104 
105 	err = platform_device_add(mali_device);
106 	if (err) {
107 		platform_device_unregister(mali_device);
108 		mali_device = NULL;
109 		return err;
110 	}
111 
112 	return 0;
113 }
114 EXPORT_SYMBOL(kbase_platform_fake_register);
115 
kbase_platform_fake_unregister(void)116 void kbase_platform_fake_unregister(void)
117 {
118 	if (mali_device)
119 		platform_device_unregister(mali_device);
120 }
121 EXPORT_SYMBOL(kbase_platform_fake_unregister);
122 
123 #endif /* CONFIG_MALI_PLATFORM_FAKE */
124 
125