1 /*************************************************************************/ /*!
3 @Title Linux module setup
4 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @License Dual MIT/GPLv2
7 The contents of this file are subject to the MIT license as set out below.
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
19 Alternatively, the contents of this file may be used under the terms of
20 the GNU General Public License Version 2 ("GPL") in which case the provisions
21 of GPL are applicable instead of those above.
23 If you wish to allow use of your version of this file only under the terms of
24 GPL, and not to allow others to use your version of this file under the terms
25 of the MIT license, indicate your decision by deleting the provisions above
26 and replace them with the notice and other provisions required by GPL as set
27 out in the file called "GPL-COPYING" included in this distribution. If you do
28 not delete the provisions above, a recipient may use your version of this file
29 under the terms of either the MIT license or GPL.
31 This License is also included in this distribution in the file called
34 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
35 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
36 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
37 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
38 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
39 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
40 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 */ /**************************************************************************/
43 #include <linux/version.h>
45 #if defined(PVR_LDM_PLATFORM_PRE_REGISTERED)
46 #define PVR_USE_PRE_REGISTERED_PLATFORM_DEV
49 #include <linux/module.h>
50 #include <linux/device.h>
54 #if defined(LDM_PLATFORM)
55 #include <linux/dma-mapping.h>
58 #include "pvr_debug.h"
60 #include "pvrmodule.h"
63 #include "module_common.h"
65 #if defined(SUPPORT_SYSTEM_INTERRUPT_HANDLING)
66 #include "syscommon.h"
69 #if defined(SUPPORT_SHARED_SLC)
70 #include "rgxapi_km.h"
73 #if defined(SUPPORT_DISPLAY_CLASS)
74 #include "kerneldisplay.h"
78 * DRVNAME is the name we use to register our driver.
79 * DEVNAME is the name we use to register actual device nodes.
81 #define DRVNAME PVR_LDM_DRIVER_REGISTRATION_NAME
82 #define DEVNAME PVRSRV_MODNAME
85 * This is all module configuration stuff required by the linux kernel.
87 MODULE_SUPPORTED_DEVICE(DEVNAME);
89 #if defined(SUPPORT_DISPLAY_CLASS)
90 /* Display class interface */
91 #include "kerneldisplay.h"
92 EXPORT_SYMBOL(DCRegisterDevice);
93 EXPORT_SYMBOL(DCUnregisterDevice);
94 EXPORT_SYMBOL(DCDisplayConfigurationRetired);
95 EXPORT_SYMBOL(DCDisplayHasPendingCommand);
96 EXPORT_SYMBOL(DCImportBufferAcquire);
97 EXPORT_SYMBOL(DCImportBufferRelease);
99 /* Physmem interface (required by LMA DC drivers) */
100 #include "physheap.h"
101 EXPORT_SYMBOL(PhysHeapAcquire);
102 EXPORT_SYMBOL(PhysHeapRelease);
103 EXPORT_SYMBOL(PhysHeapGetType);
104 EXPORT_SYMBOL(PhysHeapGetAddress);
105 EXPORT_SYMBOL(PhysHeapGetSize);
106 EXPORT_SYMBOL(PhysHeapCpuPAddrToDevPAddr);
109 /* System interface (required by DC drivers) */
110 #if defined(SUPPORT_SYSTEM_INTERRUPT_HANDLING)
111 EXPORT_SYMBOL(SysInstallDeviceLISR);
112 EXPORT_SYMBOL(SysUninstallDeviceLISR);
115 #if defined(SUPPORT_SHARED_SLC)
116 EXPORT_SYMBOL(RGXInitSLC);
118 #include "pvrversion.h" //add by zxl
120 #if defined(CONFIG_OF)
121 #include <linux/of.h>
122 #include <linux/of_device.h>
125 struct device *psDev;
128 * Device class used for /sys entries (and udev device node creation)
130 static struct class *psPvrClass;
133 * This is the major number we use for all nodes in /dev.
135 static int AssignedMajorNumber;
137 static const struct of_device_id rockchip_gpu_dt_ids[] = {
138 { .compatible = "arm,rogue-G6110", },
139 { .compatible = "arm,rk3368-gpu", },
144 * These are the operations that will be associated with the device node
147 * With gcc -W, specifying only the non-null members produces "missing
148 * initializer" warnings.
150 static int PVRSRVOpen(struct inode* pInode, struct file* pFile);
151 static int PVRSRVRelease(struct inode* pInode, struct file* pFile);
153 static struct file_operations pvrsrv_fops =
155 .owner = THIS_MODULE,
156 .unlocked_ioctl = PVRSRV_BridgeDispatchKM,
157 #if defined(CONFIG_COMPAT)
158 .compat_ioctl = PVRSRV_BridgeCompatDispatchKM,
161 .release = PVRSRVRelease,
165 #if defined(LDM_PLATFORM)
166 #define LDM_DRV struct platform_driver
167 #endif /*LDM_PLATFORM */
170 #define LDM_DRV struct pci_driver
173 #if defined(LDM_PLATFORM)
174 static int PVRSRVDriverRemove(LDM_DEV *device);
175 static int PVRSRVDriverProbe(LDM_DEV *device);
179 static void PVRSRVDriverRemove(LDM_DEV *device);
180 static int PVRSRVDriverProbe(LDM_DEV *device, const struct pci_device_id *id);
184 /* This structure is used by the Linux module code */
185 struct pci_device_id powervr_id_table[] __devinitdata = {
186 {PCI_DEVICE(SYS_RGX_DEV_VENDOR_ID, SYS_RGX_DEV_DEVICE_ID)},
187 #if defined (SYS_RGX_DEV1_DEVICE_ID)
188 {PCI_DEVICE(SYS_RGX_DEV_VENDOR_ID, SYS_RGX_DEV1_DEVICE_ID)},
192 MODULE_DEVICE_TABLE(pci, powervr_id_table);
193 #endif /*defined(LDM_PCI) */
195 #if defined(PVR_USE_PRE_REGISTERED_PLATFORM_DEV)
196 static struct platform_device_id powervr_id_table[] __devinitdata = {
197 {SYS_RGX_DEV_NAME, 0},
202 static struct dev_pm_ops powervr_dev_pm_ops = {
203 .suspend = PVRSRVDriverSuspend,
204 .resume = PVRSRVDriverResume,
207 static LDM_DRV powervr_driver = {
208 #if defined(LDM_PLATFORM)
211 .pm = &powervr_dev_pm_ops,
212 .of_match_table = of_match_ptr(rockchip_gpu_dt_ids),
217 .driver.pm = &powervr_dev_pm_ops,
219 #if defined(LDM_PCI) || defined(PVR_USE_PRE_REGISTERED_PLATFORM_DEV)
220 .id_table = powervr_id_table,
222 .probe = PVRSRVDriverProbe,
223 #if defined(LDM_PLATFORM)
224 .remove = PVRSRVDriverRemove,
227 .remove = __devexit_p(PVRSRVDriverRemove),
229 .shutdown = PVRSRVDriverShutdown,
232 #if defined(LDM_PLATFORM)
233 #if defined(MODULE) && !defined(PVR_USE_PRE_REGISTERED_PLATFORM_DEV)
234 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0))
235 /*static void PVRSRVDeviceRelease(struct device unref__ *pDevice)
239 static struct platform_device powervr_device =
244 .release = PVRSRVDeviceRelease
248 //move platform_device_register from devices.c to sgx
249 static struct resource resources_sgx[] = {
254 .flags = IORESOURCE_IRQ,
258 .start = RK30_GPU_PHYS ,
259 .end = RK30_GPU_PHYS + RK30_GPU_SIZE - 1,
260 .flags = IORESOURCE_MEM,
263 static struct platform_device powervr_device = {
266 .num_resources = ARRAY_SIZE(resources_sgx),
267 .resource = resources_sgx,
270 static struct platform_device_info powervr_device_info =
274 .dma_mask = DMA_BIT_MASK(32),
276 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0)) */
277 #endif /* defined(MODULE) && !defined(PVR_USE_PRE_REGISTERED_PLATFORM_DEV) */
278 #endif /* defined(LDM_PLATFORM) */
280 static IMG_BOOL bCalledSysInit = IMG_FALSE;
281 static IMG_BOOL bDriverProbeSucceeded = IMG_FALSE;
284 ******************************************************************************
286 @Function PVRSRVSystemInit
290 Wrapper for PVRSRVInit.
292 @input pDevice - the device for which a probe is requested
294 @Return 0 for success or <0 for an error.
296 *****************************************************************************/
297 static int PVRSRVSystemInit(LDM_DEV *pDevice)
299 PVR_TRACE(("PVRSRVSystemInit (pDevice=%p)", pDevice));
301 gpsPVRLDMDev = pDevice;
302 bCalledSysInit = IMG_TRUE;
304 if (PVRSRVInit(pDevice) != PVRSRV_OK)
313 ******************************************************************************
315 @Function PVRSRVSystemDeInit
319 Wrapper for PVRSRVDeInit.
321 @input pDevice - the device for which a probe is requested
324 *****************************************************************************/
325 static void PVRSRVSystemDeInit(LDM_DEV *pDevice)
327 PVR_TRACE(("PVRSRVSystemDeInit"));
329 PVRSRVDeInit(pDevice);
331 #if !defined(LDM_PLATFORM) || (LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0))
332 gpsPVRLDMDev = IMG_NULL;
337 ******************************************************************************
339 @Function PVRSRVDriverProbe
343 See whether a given device is really one we can drive.
345 @input pDevice - the device for which a probe is requested
347 @Return 0 for success or <0 for an error.
349 *****************************************************************************/
350 #if defined(LDM_PLATFORM)
351 static int PVRSRVDriverProbe(LDM_DEV *pDevice)
354 static int __devinit PVRSRVDriverProbe(LDM_DEV *pDevice, const struct pci_device_id *pID)
359 PVR_TRACE(("PVRSRVDriverProbe (pDevice=%p)", pDevice));
361 //zxl:print gpu version on boot time
362 printk("PVR_K: sys.gpvr.version=%s\n",RKVERSION);
364 result = PVRSRVSystemInit(pDevice);
365 bDriverProbeSucceeded = (result == 0);
371 ******************************************************************************
373 @Function PVRSRVDriverRemove
377 This call is the opposite of the probe call; it is called when the device is
378 being removed from the driver's control.
380 @input pDevice - the device for which driver detachment is happening
382 @Return 0, or no return value at all, depending on the device type.
384 *****************************************************************************/
385 #if defined (LDM_PLATFORM)
386 static int PVRSRVDriverRemove(LDM_DEV *pDevice)
389 static void __devexit PVRSRVDriverRemove(LDM_DEV *pDevice)
392 PVR_TRACE(("PVRSRVDriverRemove (pDevice=%p)", pDevice));
394 PVRSRVSystemDeInit(pDevice);
396 #if defined(LDM_PLATFORM)
402 ******************************************************************************
408 Open the PVR services node.
410 @input pInode - the inode for the file being openeded.
411 @input dev - the DRM device corresponding to this driver.
413 @input pFile - the file handle data for the actual file being opened
415 @Return 0 for success or <0 for an error.
417 *****************************************************************************/
418 static int PVRSRVOpen(struct inode unref__ *pInode, struct file *pFile)
422 if (!try_module_get(THIS_MODULE))
424 PVR_DPF((PVR_DBG_ERROR, "Failed to get module"));
428 if ((err = PVRSRVCommonOpen(pFile)) != 0)
430 module_put(THIS_MODULE);
437 ******************************************************************************
439 @Function PVRSRVRelease
443 Release access the PVR services node - called when a file is closed, whether
444 at exit or using close(2) system call.
446 @input pInode - the inode for the file being released
447 @input pvPrivData - driver private data
449 @input pFile - the file handle data for the actual file being released
451 @Return 0 for success or <0 for an error.
453 *****************************************************************************/
454 static int PVRSRVRelease(struct inode unref__ *pInode, struct file *pFile)
456 PVRSRVCommonRelease(pFile);
458 module_put(THIS_MODULE);
464 ******************************************************************************
466 @Function PVRCore_Init
470 Insert the driver into the kernel.
472 Readable and/or writable debugfs entries under /sys/kernel/debug/pvr are
473 created with PVRDebugFSCreateEntry(). These can be read at runtime to get
474 information about the device (eg. 'cat /sys/kernel/debug/pvr/nodes')
476 __init places the function in a special memory section that the kernel frees
477 once the function has been run. Refer also to module_init() macro call below.
483 *****************************************************************************/
484 static int __init PVRCore_Init(void)
488 PVR_TRACE(("PVRCore_Init"));
490 if ((error = PVRSRVDriverInit()) != 0)
495 AssignedMajorNumber = register_chrdev(0, DEVNAME, &pvrsrv_fops);
496 if (AssignedMajorNumber <= 0)
498 PVR_DPF((PVR_DBG_ERROR, "PVRCore_Init: unable to get major number"));
502 PVR_TRACE(("PVRCore_Init: major device %d", AssignedMajorNumber));
505 * This code facilitates automatic device node creation on platforms
506 * with udev (or similar).
508 psPvrClass = class_create(THIS_MODULE, "pvr");
509 if (IS_ERR(psPvrClass))
511 PVR_DPF((PVR_DBG_ERROR, "PVRCore_Init: unable to create class (%ld)", PTR_ERR(psPvrClass)));
515 psDev = device_create(psPvrClass, NULL, MKDEV(AssignedMajorNumber, 0),
519 PVR_DPF((PVR_DBG_ERROR, "PVRCore_Init: unable to create device (%ld)", PTR_ERR(psDev)));
523 #if defined(LDM_PLATFORM)
524 error = platform_driver_register(&powervr_driver);
527 PVR_DPF((PVR_DBG_ERROR, "PVRCore_Init: unable to register platform driver (%d)", error));
531 #if defined(MODULE) && !defined(PVR_USE_PRE_REGISTERED_PLATFORM_DEV)
532 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0))
533 error = platform_device_register(&powervr_device);
535 gpsPVRLDMDev = platform_device_register_full(&powervr_device_info);
536 error = IS_ERR(gpsPVRLDMDev) ? PTR_ERR(gpsPVRLDMDev) : 0;
540 PVR_DPF((PVR_DBG_ERROR, "PVRCore_Init: unable to register platform device (%d)", error));
543 #endif /* defined(MODULE) && !defined(PVR_USE_PRE_REGISTERED_PLATFORM_DEV) */
544 #endif /* defined(LDM_PLATFORM) */
547 error = pci_register_driver(&powervr_driver);
550 PVR_DPF((PVR_DBG_ERROR, "PVRCore_Init: unable to register PCI driver (%d)", error));
553 #endif /* defined(LDM_PCI) */
555 /* Check that the driver probe function was called */
556 if (!bDriverProbeSucceeded)
558 PVR_TRACE(("PVRCore_Init: PVRSRVDriverProbe has not been called or did not succeed - check that hardware is detected"));
562 return PVRSRVDeviceInit();
567 *****************************************************************************
569 @Function PVRCore_Cleanup
573 Remove the driver from the kernel.
575 There's no way we can get out of being unloaded other than panicking; we
576 just do everything and plough on regardless of error.
578 __exit places the function in a special memory section that the kernel frees
579 once the function has been run. Refer also to module_exit() macro call below.
585 *****************************************************************************/
586 static void __exit PVRCore_Cleanup(void)
588 PVR_TRACE(("PVRCore_Cleanup"));
590 PVRSRVDeviceDeinit();
594 device_destroy(psPvrClass, MKDEV(AssignedMajorNumber, 0));
599 class_destroy(psPvrClass);
602 if (AssignedMajorNumber > 0)
604 unregister_chrdev((IMG_UINT)AssignedMajorNumber, DEVNAME);
608 pci_unregister_driver(&powervr_driver);
609 #endif /* defined(LDM_PCI) */
611 #if defined (LDM_PLATFORM)
612 #if defined(MODULE) && !defined(PVR_USE_PRE_REGISTERED_PLATFORM_DEV)
613 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0))
614 platform_device_unregister(&powervr_device);
616 PVR_ASSERT(gpsPVRLDMDev != NULL);
617 platform_device_unregister(gpsPVRLDMDev);
618 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0)) */
619 #endif /* defined(MODULE) && !defined(PVR_USE_PRE_REGISTERED_PLATFORM_DEV) */
620 platform_driver_unregister(&powervr_driver);
621 #endif /* defined (LDM_PLATFORM) */
623 PVRSRVDriverDeinit();
625 PVR_TRACE(("PVRCore_Cleanup: unloading"));
629 * These macro calls define the initialisation and removal functions of the
630 * driver. Although they are prefixed `module_', they apply when compiling
631 * statically as well; in both cases they define the function the kernel will
632 * run to start/stop the driver.
634 module_init(PVRCore_Init);
635 module_exit(PVRCore_Cleanup);