]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/device-ti-proprietary-open.git/blob - jacinto6/sgx_src/eurasia_km/services4/srvkm/env/linux/pvr_drm.c
3aae69e232ee1977ba82f7eaf3ed2077b3c1c895
[android-sdk/device-ti-proprietary-open.git] / jacinto6 / sgx_src / eurasia_km / services4 / srvkm / env / linux / pvr_drm.c
1 /*************************************************************************/ /*!
2 @Title          PowerVR drm driver
3 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
4 @Description    linux module setup
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
32 "MIT-COPYING".
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 */ /**************************************************************************/
42 #if defined(SUPPORT_DRI_DRM)
44 #include <linux/version.h>
46 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38))
47 #ifndef AUTOCONF_INCLUDED
48 #include <linux/config.h>
49 #endif
50 #endif
52 #include <linux/init.h>
53 #include <linux/kernel.h>
54 #include <linux/module.h>
55 #include <linux/fs.h>
56 #include <linux/proc_fs.h>
57 #include <linux/sched.h>
58 #include <asm/ioctl.h>
59 #include <drm/drmP.h>
60 #include <drm/drm.h>
62 #include "img_defs.h"
63 #include "services.h"
64 #include "kerneldisplay.h"
65 #include "kernelbuffer.h"
66 #include "syscommon.h"
67 #include "pvrmmap.h"
68 #include "mm.h"
69 #include "mmap.h"
70 #include "mutex.h"
71 #include "pvr_debug.h"
72 #include "srvkm.h"
73 #include "perproc.h"
74 #include "handle.h"
75 #include "pvr_bridge_km.h"
76 #include "pvr_bridge.h"
77 #include "pvrmodule.h"
78 #include "pvrversion.h"
79 #include "lock.h"
80 #include "linkage.h"
81 #include "pvr_drm.h"
83 #if defined(PVR_DRI_DRM_NOT_PCI)
84 #include "pvr_drm_mod.h"
85 #endif
87 #if (defined(PVR_DRI_DRM_PLATFORM_DEV) && !defined(PVR_LDM_PLATFORM_PRE_REGISTERED)) || defined(NO_HARDWARE)
88 #define PVR_DRM_NAME    SYS_SGX_DEV_NAME
89 #else
90 #define PVR_DRM_NAME    PVRSRV_MODNAME
91 #endif
93 #define PVR_DRM_DESC    "Imagination Technologies PVR DRM"
95 #define PVR_DRM_DATE    "20110701"
97 #if defined(PVR_DRI_DRM_PLATFORM_DEV) && !defined(SUPPORT_DRI_DRM_PLUGIN)
98 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39))
99 #define PVR_NEW_STYLE_DRM_PLATFORM_DEV
100 #else
101 #define PVR_OLD_STYLE_DRM_PLATFORM_DEV
102 #endif
103 #endif
105 /*
106  * Prior to Linux 2.6.36, we couldn't do the release processing in post close
107  * when workqueues were being used, because drm_release held the big kernel
108  * lock (BKL) when it called post close.
109  * If the resman needs to wait for processing being done by a workqueue,
110  * that processing won't complete whilst the lock is held by another thread,
111  * as the workqueue won't get scheduled.
112  */
113 #undef  PVR_DRI_DRM_USE_POST_CLOSE
114 #if (defined(SUPPORT_DRI_DRM_EXT) && !defined(PVR_LINUX_USING_WORKQUEUES)) || \
115         (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36))
116 #define PVR_DRI_DRM_USE_POST_CLOSE
117 #endif
119 DECLARE_WAIT_QUEUE_HEAD(sWaitForInit);
121 #if defined(SUPPORT_DRM_MODESET)
122 static struct drm_driver sPVRDrmDriver;
123 #endif
125 /* Once bInitComplete and bInitFailed are set, they stay set */
126 IMG_BOOL bInitComplete;
127 IMG_BOOL bInitFailed;
129 #if !defined(PVR_DRI_DRM_NOT_PCI) && !defined(SUPPORT_DRI_DRM_PLUGIN)
130 #if defined(PVR_DRI_DRM_PLATFORM_DEV)
131 struct platform_device *gpsPVRLDMDev;
132 #else
133 struct pci_dev *gpsPVRLDMDev;
134 #endif
135 #endif
137 struct drm_device *gpsPVRDRMDev;
139 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,24))
140 #error "Linux kernel version 2.6.25 or later required for PVR DRM support"
141 #endif
143 #define PVR_DRM_FILE struct drm_file *
145 #if !defined(SUPPORT_DRI_DRM_EXT) && !defined(SUPPORT_DRI_DRM_PLUGIN)
146 #if defined(PVR_DRI_DRM_PLATFORM_DEV)
147 static struct platform_device_id asPlatIdList[] = {
148         {SYS_SGX_DEV_NAME, 0},
149         {}
150 };
151 #else   /* defined(PVR_DRI_DRM_PLATFORM_DEV) */
152 static struct pci_device_id asPciIdList[] = {
153 #if defined(PVR_DRI_DRM_NOT_PCI)
154         {1, 1, 1, 1, 0, 0, 0},
155 #else   /* defined(PVR_DRI_DRM_NOT_PCI) */
156         {SYS_SGX_DEV_VENDOR_ID, SYS_SGX_DEV_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
157 #if defined(SYS_SGX_DEV1_DEVICE_ID)
158         {SYS_SGX_DEV_VENDOR_ID, SYS_SGX_DEV1_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
159 #endif  /* defined(SYS_SGX_DEV1_DEVICE_ID) */
160 #endif  /* defined(PVR_DRI_DRM_NOT_PCI) */
161         {0}
162 };
163 #endif  /* defined(PVR_DRI_DRM_PLATFORM_DEV) */
164 #endif  /* !defined(SUPPORT_DRI_DRM_EXT) */
166 DRI_DRM_STATIC int
167 PVRSRVDrmLoad(struct drm_device *dev, unsigned long flags)
169         int iRes = 0;
171         PVR_TRACE(("PVRSRVDrmLoad"));
173         gpsPVRDRMDev = dev;
174 #if !defined(PVR_DRI_DRM_NOT_PCI) && !defined(SUPPORT_DRI_DRM_PLUGIN)
175 #if defined(PVR_DRI_DRM_PLATFORM_DEV)
176         gpsPVRLDMDev = dev->platformdev;
177 #else
178         gpsPVRLDMDev = dev->pdev;
179 #endif
180 #endif
182 #if defined(PDUMP)
183         iRes = dbgdrv_init();
184         if (iRes != 0)
185         {
186                 goto exit;
187         }
188 #endif
189         /* Module initialisation */
190         iRes = PVRCore_Init();
191         if (iRes != 0)
192         {
193                 goto exit_dbgdrv_cleanup;
194         }
196 #if defined(DISPLAY_CONTROLLER)
197         iRes = PVR_DRM_MAKENAME(DISPLAY_CONTROLLER, _Init)(dev);
198         if (iRes != 0)
199         {
200                 goto exit_pvrcore_cleanup;
201         }
202 #endif
203         goto exit;
205 #if defined(DISPLAY_CONTROLLER)
206 exit_pvrcore_cleanup:
207         PVRCore_Cleanup();
208 #endif
209 exit_dbgdrv_cleanup:
210 #if defined(PDUMP)
211         dbgdrv_cleanup();
212 #endif
213 exit:
214         if (iRes != 0)
215         {
216                 bInitFailed = IMG_TRUE;
217         }
218         bInitComplete = IMG_TRUE;
220         wake_up_interruptible(&sWaitForInit);
222         return iRes;
225 DRI_DRM_STATIC int
226 PVRSRVDrmUnload(struct drm_device *dev)
228         PVR_TRACE(("PVRSRVDrmUnload"));
230 #if defined(DISPLAY_CONTROLLER)
231         PVR_DRM_MAKENAME(DISPLAY_CONTROLLER, _Cleanup)(dev);
232 #endif
234         PVRCore_Cleanup();
236 #if defined(PDUMP)
237         dbgdrv_cleanup();
238 #endif
240         return 0;
243 DRI_DRM_STATIC int
244 PVRSRVDrmOpen(struct drm_device *dev, struct drm_file *file)
246         while (!bInitComplete)
247         {
248                 DEFINE_WAIT(sWait);
250                 prepare_to_wait(&sWaitForInit, &sWait, TASK_INTERRUPTIBLE);
252                 if (!bInitComplete)
253                 {
254                         PVR_TRACE(("%s: Waiting for module initialisation to complete", __FUNCTION__));
256                         schedule();
257                 }
259                 finish_wait(&sWaitForInit, &sWait);
261                 if (signal_pending(current))
262                 {
263                         return -ERESTARTSYS;
264                 }
265         }
267         if (bInitFailed)
268         {
269                 PVR_DPF((PVR_DBG_ERROR, "%s: Module initialisation failed", __FUNCTION__));
270                 return -EINVAL;
271         }
273         return PVRSRVOpen(dev, file);
276 #if defined(PVR_DRI_DRM_USE_POST_CLOSE) || defined(SUPPORT_DRI_DRM_PLUGIN)
277 #if defined(SUPPORT_DRI_DRM_PLUGIN)
278 DRI_DRM_STATIC int
279 PVRSRVDrmRelease(struct drm_device *dev, struct drm_file *file)
280 #else
281 DRI_DRM_STATIC void
282 PVRSRVDrmPostClose(struct drm_device *dev, struct drm_file *file)
283 #endif
285         PVRSRVRelease(file->driver_priv);
287         file->driver_priv = NULL;
289 #if defined(SUPPORT_DRI_DRM_PLUGIN)
290         return 0;
291 #endif
293 #else
294 DRI_DRM_STATIC int
295 PVRSRVDrmRelease(struct inode *inode, struct file *filp)
297         struct drm_file *file_priv = filp->private_data;
298         void *psDriverPriv = file_priv->driver_priv;
299         int ret;
301         ret = drm_release(inode, filp);
303         if (ret != 0)
304         {
305                 /*
306                  * An error means drm_release didn't call drm_lastclose,
307                  * but it will have freed file_priv.
308                  */
309                 PVR_DPF((PVR_DBG_ERROR, "%s : drm_release failed: %d",
310                         __FUNCTION__, ret));
311         }
313         PVRSRVRelease(psDriverPriv);
315         return 0;
317 #endif
319 DRI_DRM_STATIC int
320 PVRDRMIsMaster(struct drm_device *dev, void *arg, struct drm_file *pFile)
322         return 0;
325 #if defined(SUPPORT_DRI_DRM_EXT)
326 int
327 PVRDRM_Dummy_ioctl(struct drm_device *dev, void *arg, struct drm_file *pFile)
329         return 0;
331 #endif
333 DRI_DRM_STATIC int
334 PVRDRMUnprivCmd(struct drm_device *dev, void *arg, struct drm_file *pFile)
336         int ret = 0;
338         LinuxLockMutexNested(&gPVRSRVLock, PVRSRV_LOCK_CLASS_BRIDGE);
340         if (arg == NULL)
341         {
342                 ret = -EFAULT;
343         }
344         else
345         {
346                 drm_pvr_unpriv_cmd *psArgs = (drm_pvr_unpriv_cmd *)arg;
348                 switch (psArgs->cmd)
349                 {
350                         case PVR_DRM_UNPRIV_INIT_SUCCESFUL:
351                                 psArgs->res = PVRSRVGetInitServerState(PVRSRV_INIT_SERVER_SUCCESSFUL) ? 1 : 0;
352                                 break;
354                         default:
355                                 ret = -EFAULT;
356                 }
358         }
360         LinuxUnLockMutex(&gPVRSRVLock);
362         return ret;
365 #if defined(DISPLAY_CONTROLLER) && defined(PVR_DISPLAY_CONTROLLER_DRM_IOCTL)
366 static int
367 PVRDRM_Display_ioctl(struct drm_device *dev, void *arg, struct drm_file *pFile)
369         int res;
371         LinuxLockMutexNested(&gPVRSRVLock, PVRSRV_LOCK_CLASS_BRIDGE);
373         res = PVR_DRM_MAKENAME(DISPLAY_CONTROLLER, _Ioctl)(dev, arg, pFile);
375         LinuxUnLockMutex(&gPVRSRVLock);
377         return res;
379 #endif
381 #if defined(SUPPORT_DRM_MODESET)
382 static int
383 PVRSRVPciProbe(struct pci_dev *dev, const struct pci_device_id *id)
385         PVR_TRACE(("PVRSRVPciProbe"));
387 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36))
388         return drm_get_pci_dev(dev, id, &sPVRDrmDriver);
389 #else
390         return drm_get_dev(dev, id, &sPVRDrmDriver);
391 #endif
394 static void
395 PVRSRVPciRemove(struct pci_dev *dev)
397         struct drm_device *psDrmDev;
399         PVR_TRACE(("PVRSRVPciRemove"));
401         psDrmDev = pci_get_drvdata(dev);
402         drm_put_dev(psDrmDev);
404 #endif
406 /*
407  * For Linux 2.6.33 and above, the DRM ioctl entry point is of the unlocked
408  * variety.  The big kernel lock is still taken for ioctls, unless
409  * the DRM_UNLOCKED flag is set.  If you revise one of the driver specific
410  * ioctls, or add a new one, consider whether the gPVRSRVLock mutex needs
411  * to be taken.
412  */
413 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33))
414 #define PVR_DRM_FOPS_IOCTL      .unlocked_ioctl
415 #define PVR_DRM_UNLOCKED        DRM_UNLOCKED
416 #else
417 #define PVR_DRM_FOPS_IOCTL      .ioctl
418 #define PVR_DRM_UNLOCKED        0
419 #endif
421 #if !defined(SUPPORT_DRI_DRM_EXT)
423 #if defined(DRM_IOCTL_DEF)
424 #define PVR_DRM_IOCTL_DEF(ioctl, _func, _flags) DRM_IOCTL_DEF(DRM_##ioctl, _func, _flags)
425 #else
426 #define PVR_DRM_IOCTL_DEF(ioctl, _func, _flags) DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)
427 #endif
429 struct drm_ioctl_desc sPVRDrmIoctls[] = {
430         PVR_DRM_IOCTL_DEF(PVR_SRVKM, PVRSRV_BridgeDispatchKM, PVR_DRM_UNLOCKED),
431         PVR_DRM_IOCTL_DEF(PVR_IS_MASTER, PVRDRMIsMaster, DRM_MASTER | PVR_DRM_UNLOCKED),
432         PVR_DRM_IOCTL_DEF(PVR_UNPRIV, PVRDRMUnprivCmd, PVR_DRM_UNLOCKED),
433 #if defined(PDUMP)
434         PVR_DRM_IOCTL_DEF(PVR_DBGDRV, dbgdrv_ioctl, PVR_DRM_UNLOCKED),
435 #endif
436 #if defined(DISPLAY_CONTROLLER) && defined(PVR_DISPLAY_CONTROLLER_DRM_IOCTL)
437         PVR_DRM_IOCTL_DEF(PVR_DISP, PVRDRM_Display_ioctl, DRM_MASTER | PVR_DRM_UNLOCKED)
438 #endif
439 };
441 #if !defined(SUPPORT_DRI_DRM_PLUGIN)
442 static int pvr_max_ioctl = DRM_ARRAY_SIZE(sPVRDrmIoctls);
443 #endif
445 #if defined(PVR_DRI_DRM_PLATFORM_DEV) && !defined(SUPPORT_DRI_DRM_EXT) && \
446         !defined(SUPPORT_DRI_DRM_PLUGIN)
447 static int PVRSRVDrmProbe(struct platform_device *pDevice);
448 static int PVRSRVDrmRemove(struct platform_device *pDevice);
449 #endif  /* defined(PVR_DRI_DRM_PLATFORM_DEV) && !defined(SUPPORT_DRI_DRM_EXT) */
451 #if defined(SUPPORT_DRI_DRM_PLUGIN)
452 static PVRSRV_DRM_PLUGIN sPVRDrmPlugin =
454         .name = PVR_DRM_NAME,
456         .open = PVRSRVDrmOpen,
457         .load = PVRSRVDrmLoad,
458         .unload = PVRSRVDrmUnload,
460         .release = PVRSRVDrmRelease,
462         .mmap = PVRMMap,
464         .ioctls = sPVRDrmIoctls,
465         .num_ioctls = DRM_ARRAY_SIZE(sPVRDrmIoctls),
466         .ioctl_start = 0
467 };
468 #else   /* defined(SUPPORT_DRI_DRM_PLUGIN) */
470 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
471 static const struct file_operations sPVRFileOps = 
473         .owner = THIS_MODULE,
474         .open = drm_open,
475 #if defined(PVR_DRI_DRM_USE_POST_CLOSE)
476         .release = drm_release,
477 #else
478         .release = PVRSRVDrmRelease,
479 #endif
480         PVR_DRM_FOPS_IOCTL = drm_ioctl,
481         .mmap = PVRMMap,
482         .poll = drm_poll,
483         .fasync = drm_fasync,
484 };
485 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0)) */
487 static struct drm_driver sPVRDrmDriver = 
489 #if defined(PVR_OLD_STYLE_DRM_PLATFORM_DEV)
490         .driver_features = DRIVER_USE_PLATFORM_DEVICE,
491 #else
492         .driver_features = 0,
493 #endif
494         .dev_priv_size = 0,
495         .load = PVRSRVDrmLoad,
496         .unload = PVRSRVDrmUnload,
497         .open = PVRSRVDrmOpen,
498 #if defined(PVR_DRI_DRM_USE_POST_CLOSE)
499         .postclose = PVRSRVDrmPostClose,
500 #endif
501 #if !defined(PVR_DRI_DRM_PLATFORM_DEV) && !defined(SUPPORT_DRM_MODESET)
502         .suspend = PVRSRVDriverSuspend,
503         .resume = PVRSRVDriverResume,
504 #endif
505 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37))
506         .get_map_ofs = drm_core_get_map_ofs,
507         .get_reg_ofs = drm_core_get_reg_ofs,
508 #endif
509         .ioctls = sPVRDrmIoctls,
510 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
511         .fops = &sPVRFileOps,
512 #else
513         .fops = 
514         {
515                 .owner = THIS_MODULE,
516                 .open = drm_open,
517 #if defined(PVR_DRI_DRM_USE_POST_CLOSE)
518                 .release = drm_release,
519 #else
520                 .release = PVRSRVDrmRelease,
521 #endif
522                 PVR_DRM_FOPS_IOCTL = drm_ioctl,
523                 .mmap = PVRMMap,
524                 .poll = drm_poll,
525                 .fasync = drm_fasync,
526         },
527 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0)) */
528 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39))
529 #if defined(PVR_OLD_STYLE_DRM_PLATFORM_DEV)
530         .platform_driver =
531         {
532                 .id_table = asPlatIdList,
533                 .driver =
534                 {
535                         .name = PVR_DRM_NAME,
536                 },
537                 .probe = PVRSRVDrmProbe,
538                 .remove = PVRSRVDrmRemove,
539                 .suspend = PVRSRVDriverSuspend,
540                 .resume = PVRSRVDriverResume,
541                 .shutdown = PVRSRVDriverShutdown,
542         },
543 #else
544         .pci_driver = 
545         {
546                 .name = PVR_DRM_NAME,
547                 .id_table = asPciIdList,
548 #if defined(SUPPORT_DRM_MODESET)
549                 .probe = PVRSRVPciProbe,
550                 .remove = PVRSRVPciRemove,
551                 .suspend = PVRSRVDriverSuspend,
552                 .resume = PVRSRVDriverResume,
553 #endif
554         },
555 #endif
556 #endif
557         .name = PVR_DRM_NAME,
558         .desc = PVR_DRM_DESC,
559         .date = PVR_DRM_DATE,
560         .major = PVRVERSION_MAJ,
561         .minor = PVRVERSION_MIN,
562         .patchlevel = PVRVERSION_BUILD,
563 };
565 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)) && !defined(PVR_DRI_DRM_PLATFORM_DEV)
566 static struct pci_driver sPVRPCIDriver =
568                 .name = PVR_DRM_NAME,
569                 .id_table = asPciIdList,
570 #if defined(SUPPORT_DRM_MODESET)
571                 .probe = PVRSRVPciProbe,
572                 .remove = PVRSRVPciRemove,
573                 .suspend = PVRSRVDriverSuspend,
574                 .resume = PVRSRVDriverResume,
575 #endif
576 };
577 #endif
579 #if defined(PVR_NEW_STYLE_DRM_PLATFORM_DEV)
580 #if !defined(PVR_LDM_PLATFORM_PRE_REGISTERED) || defined(NO_HARDWARE)
581 static void PVRSRVDeviceRelease(struct device unref__ *pDevice)
585 static struct platform_device sPVRPlatDevice = {
586         .name                   = PVR_DRM_NAME,
587         .id                     = -1,
588         .dev                    = {
589                 .release        = PVRSRVDeviceRelease
590         }
591 };
592 #endif
594 static struct platform_driver sPVRPlatDriver =
596         .id_table = asPlatIdList,
597         .driver =
598         {
599                 .name = PVR_DRM_NAME,
600         },
601         .probe = PVRSRVDrmProbe,
602         .remove = PVRSRVDrmRemove,
603         .suspend = PVRSRVDriverSuspend,
604         .resume = PVRSRVDriverResume,
605         .shutdown = PVRSRVDriverShutdown,
606 };
607 #endif
609 #endif  /* defined(SUPPORT_DRI_DRM_PLUGIN) */
611 #if defined(PVR_DRI_DRM_PLATFORM_DEV) && !defined(SUPPORT_DRI_DRM_EXT) && \
612         !defined(SUPPORT_DRI_DRM_PLUGIN)
613 static int
614 PVRSRVDrmProbe(struct platform_device *pDevice)
616         PVR_TRACE(("PVRSRVDrmProbe"));
618 #if defined(PVR_NEW_STYLE_DRM_PLATFORM_DEV)
619         gpsPVRLDMDev = pDevice;
621         return drm_platform_init(&sPVRDrmDriver, gpsPVRLDMDev);
622 #else
623         return drm_get_platform_dev(pDevice, &sPVRDrmDriver);
624 #endif
627 static int
628 PVRSRVDrmRemove(struct platform_device *pDevice)
630         PVR_TRACE(("PVRSRVDrmRemove"));
632 #if defined(PVR_NEW_STYLE_DRM_PLATFORM_DEV)
633         drm_platform_exit(&sPVRDrmDriver, gpsPVRLDMDev);
634 #else
635         drm_put_dev(gpsPVRDRMDev);
636 #endif
637         return 0;
639 #endif
641 static int __init PVRSRVDrmInit(void)
643         int iRes;
644 #if !defined(SUPPORT_DRI_DRM_PLUGIN)
645         sPVRDrmDriver.num_ioctls = pvr_max_ioctl;
646 #endif
648 #if defined(SUPPORT_DRM_MODESET)
649         sPVRDrmDriver.driver_features |= DRIVER_MODESET;
650 #endif
652         /* Must come before attempting to print anything via Services */
653         PVRDPFInit();
655 #if defined(PVR_NEW_STYLE_DRM_PLATFORM_DEV)
656         iRes = platform_driver_register(&sPVRPlatDriver);
657 #if !defined(PVR_LDM_PLATFORM_PRE_REGISTERED) || defined(NO_HARDWARE)
658         if (iRes == 0)
659         {
660                 iRes = platform_device_register(&sPVRPlatDevice);
661                 if (iRes != 0)
662                 {
663                         platform_driver_unregister(&sPVRPlatDriver);
664                 }
665         }
666 #endif
667 #else   /* defined(PVR_NEW_STYLE_DRM_PLATFORM_DEV) */
668 #if defined(SUPPORT_DRI_DRM_PLUGIN)
669         iRes = SysDRMRegisterPlugin(&sPVRDrmPlugin);
670 #else   /* defined(SUPPORT_DRI_DRM_PLUGIN) */
671 #if defined(PVR_DRI_DRM_NOT_PCI)
672         iRes = drm_pvr_dev_add();
673         if (iRes != 0)
674         {
675                 return iRes;
676         }
677 #endif
679 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39))
680 #if defined(PVR_DRI_DRM_PLATFORM_DEV)
681         iRes = drm_platform_init(&sPVRDrmDriver, gpsPVRLDMDev);
682 #else
683         iRes = drm_pci_init(&sPVRDrmDriver, &sPVRPCIDriver);
684 #endif
685 #else   /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)) */
686         iRes = drm_init(&sPVRDrmDriver);
687 #endif  /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)) */
689 #if defined(PVR_DRI_DRM_NOT_PCI)
690         if (iRes != 0)
691         {
692                 drm_pvr_dev_remove();
693         }
694 #endif
695 #endif  /* defined(SUPPORT_DRI_DRM_PLUGIN) */
696 #endif  /* defined(PVR_NEW_STYLE_DRM_PLATFORM_DEV) */
697         return iRes;
699         
700 static void __exit PVRSRVDrmExit(void)
702 #if defined(PVR_NEW_STYLE_DRM_PLATFORM_DEV)
703 #if !defined(PVR_LDM_PLATFORM_PRE_REGISTERED) || defined(NO_HARDWARE)
704         platform_device_unregister(&sPVRPlatDevice);
705 #endif
706         platform_driver_unregister(&sPVRPlatDriver);
707 #else   /* defined(PVR_NEW_STYLE_DRM_PLATFORM_DEV) */
708 #if defined(SUPPORT_DRI_DRM_PLUGIN)
709         SysDRMUnregisterPlugin(&sPVRDrmPlugin);
710 #else   /* defined(SUPPORT_DRI_DRM_PLUGIN) */
711 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39))
712 #if defined(PVR_DRI_DRM_PLATFORM_DEV)
713         drm_platform_exit(&sPVRDrmDriver, gpsPVRLDMDev);
714 #else
715         drm_pci_exit(&sPVRDrmDriver, &sPVRPCIDriver);
716 #endif
717 #else   /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)) */
718         drm_exit(&sPVRDrmDriver);
719 #endif  /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)) */
721 #if defined(PVR_DRI_DRM_NOT_PCI)
722         drm_pvr_dev_remove();
723 #endif
724 #endif  /* defined(SUPPORT_DRI_DRM_PLUGIN) */
725 #endif  /* defined(PVR_NEW_STYLE_DRM_PLATFORM_DEV) */
728 /*
729  * These macro calls define the initialisation and removal functions of the
730  * driver.  Although they are prefixed `module_', they apply when compiling
731  * statically as well; in both cases they define the function the kernel will
732  * run to start/stop the driver.
733 */
734 module_init(PVRSRVDrmInit);
735 module_exit(PVRSRVDrmExit);
736 #endif  /* !defined(SUPPORT_DRI_DRM_EXT) */
737 #endif  /* defined(SUPPORT_DRI_DRM) */