Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / hidds / nouveau / drm / libdrm / arosdrm_nouveau.c
blob87b1c511d639faadbf3ec10c6d8cab97fe6e577d
1 /*
2 Copyright 2010, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "arosdrm.h"
7 #include "drmP.h"
9 extern struct drm_driver * current_drm_driver;
11 /* FIXME: Array for now, list maybe in future */
12 extern struct drm_file * drm_files[128];
14 /* FIXME: this should be generic, not nouveau specific */
15 #include "nouveau_drv.h"
16 void * drmMMap(int fd, uint32_t handle)
18 struct drm_file * f = drm_files[fd];
19 struct drm_gem_object * gem_object = NULL;
20 struct nouveau_bo * nvbo = NULL;
21 void * addr = NULL;
23 if (!f)
24 return NULL;
26 /* Get GEM objects from handle */
27 gem_object = drm_gem_object_lookup(current_drm_driver->dev, f, handle);
28 if (!gem_object)
29 return NULL;
31 /* Translate to nouveau_bo */
32 nvbo = nouveau_gem_object(gem_object);
34 if (nvbo)
36 /* Perform mapping if not already done */
37 if (!nvbo->kmap.virtual)
38 nouveau_bo_map(nvbo);
40 addr = nvbo->kmap.virtual;
43 /* Release the acquired reference */
44 mutex_lock(&current_drm_driver->dev->struct_mutex);
45 drm_gem_object_unreference(gem_object);
46 mutex_unlock(&current_drm_driver->dev->struct_mutex);
48 /* Return virtual address */
49 return addr;
52 void drmMUnmap(int fd, uint32_t handle)
54 struct drm_file * f = drm_files[fd];
55 struct drm_gem_object * gem_object = NULL;
56 struct nouveau_bo * nvbo = NULL;
58 if (!f) return ;
60 /* Get GEM objects from handle */
61 gem_object = drm_gem_object_lookup(current_drm_driver->dev, f, handle);
62 if (!gem_object) return;
64 /* Translate to nouveau_bo */
65 nvbo = nouveau_gem_object(gem_object);
66 if (nvbo)
68 /* Perform unmapping if not already done */
69 if (nvbo->kmap.virtual)
70 nouveau_bo_unmap(nvbo);
73 /* Release the acquired reference */
74 mutex_lock(&current_drm_driver->dev->struct_mutex);
75 drm_gem_object_unreference(gem_object);
76 mutex_unlock(&current_drm_driver->dev->struct_mutex);