update experimental gcc 6 patch to gcc 6.1.0 release
[AROS.git] / workbench / hidds / nouveau / drm / libdrm / arosdrm.c
blob28d6c944857bda19aafc400665805d064310f988
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 struct drm_file * drm_files[128] = {NULL};
14 int
15 drmCommandNone(int fd, unsigned long drmCommandIndex)
17 if (!drm_files[fd])
18 return -EINVAL;
20 if (!current_drm_driver || !current_drm_driver->ioctls)
21 return -EINVAL;
23 return current_drm_driver->ioctls[drmCommandIndex].func(current_drm_driver->dev, NULL, drm_files[fd]);
26 int
27 drmCommandRead(int fd, unsigned long drmCommandIndex, void *data, unsigned long size)
29 if (!drm_files[fd])
30 return -EINVAL;
32 if (!current_drm_driver || !current_drm_driver->ioctls)
33 return -EINVAL;
35 return current_drm_driver->ioctls[drmCommandIndex].func(current_drm_driver->dev, data, drm_files[fd]);
38 int
39 drmCommandWrite(int fd, unsigned long drmCommandIndex, void *data, unsigned long size)
41 if (!drm_files[fd])
42 return -EINVAL;
44 if (!current_drm_driver || !current_drm_driver->ioctls)
45 return -EINVAL;
47 return current_drm_driver->ioctls[drmCommandIndex].func(current_drm_driver->dev, data, drm_files[fd]);
50 int
51 drmCommandWriteRead(int fd, unsigned long drmCommandIndex, void *data, unsigned long size)
53 if (!drm_files[fd])
54 return -EINVAL;
56 if (!current_drm_driver || !current_drm_driver->ioctls)
57 return -EINVAL;
59 return current_drm_driver->ioctls[drmCommandIndex].func(current_drm_driver->dev, data, drm_files[fd]);
62 int
63 drmOpen(const char *name, const char *busid)
65 int i;
67 for (i = 0; i < 128; i++)
69 if (drm_files[i] == NULL)
71 drm_files[i] = HIDDNouveauAlloc(sizeof(struct drm_file));
72 spin_lock_init(&drm_files[i]->table_lock);
73 INIT_LIST_HEAD(&drm_files[i]->fbs);
74 if (current_drm_driver->open)
75 current_drm_driver->open(current_drm_driver->dev, drm_files[i]);
76 return i;
80 return -EINVAL;
83 int
84 drmClose(int fd)
86 struct drm_file * f = NULL;
88 if (!(f = drm_files[fd]))
89 return 0;
91 drm_files[fd] = NULL;
93 if (current_drm_driver->preclose)
94 current_drm_driver->preclose(current_drm_driver->dev, f);
96 if (current_drm_driver->postclose)
97 current_drm_driver->postclose(current_drm_driver->dev, f);
99 HIDDNouveauFree(f);
101 return 0;
104 drmVersionPtr
105 drmGetVersion(int fd)
107 static drmVersion ver;
108 if (current_drm_driver)
109 ver.version_patchlevel = current_drm_driver->version_patchlevel;
110 else
111 ver.version_patchlevel = 0;
113 return &ver;
116 void
117 drmFreeVersion(drmVersionPtr ptr)
119 /* This is a no-op for now */
123 drmCreateContext(int fd, drm_context_t * handle)
125 /* No Op */
126 return 0;
130 drmDestroyContext(int fd, drm_context_t handle)
132 /* No Op */
133 return 0;
136 int drmIoctl(int fd, unsigned long request, void *arg)
138 int ret = -EINVAL;
140 if (!drm_files[fd])
141 return ret;
145 switch(request)
147 case(DRM_IOCTL_GEM_CLOSE):
148 ret = drm_gem_close_ioctl(current_drm_driver->dev, arg, drm_files[fd]);
149 break;
150 case(DRM_IOCTL_GEM_OPEN):
151 ret = drm_gem_open_ioctl(current_drm_driver->dev, arg, drm_files[fd]);
152 break;
153 case(DRM_IOCTL_GEM_FLINK):
154 ret = drm_gem_flink_ioctl(current_drm_driver->dev, arg, drm_files[fd]);
155 break;
156 case(DRM_IOCTL_MODE_ADDFB):
157 ret = drm_mode_addfb(current_drm_driver->dev, arg, drm_files[fd]);
158 break;
159 case(DRM_IOCTL_MODE_RMFB):
160 ret = drm_mode_rmfb(current_drm_driver->dev, arg, drm_files[fd]);
161 break;
162 case(DRM_IOCTL_MODE_SETCRTC):
163 ret = drm_mode_setcrtc(current_drm_driver->dev, arg, drm_files[fd]);
164 break;
165 case(DRM_IOCTL_MODE_GETCRTC):
166 ret = drm_mode_getcrtc(current_drm_driver->dev, arg, drm_files[fd]);
167 break;
168 case(DRM_IOCTL_MODE_GETRESOURCES):
169 ret = drm_mode_getresources(current_drm_driver->dev, arg, drm_files[fd]);
170 break;
171 case(DRM_IOCTL_MODE_GETCONNECTOR):
172 ret = drm_mode_getconnector(current_drm_driver->dev, arg, drm_files[fd]);
173 break;
174 case(DRM_IOCTL_MODE_CURSOR):
175 ret = drm_mode_cursor_ioctl(current_drm_driver->dev, arg, drm_files[fd]);
176 break;
177 case(DRM_IOCTL_MODE_GETENCODER):
178 ret = drm_mode_getencoder(current_drm_driver->dev, arg, drm_files[fd]);
179 break;
180 default:
181 DRM_IMPL("GEM COMMAND %d\n", request);
183 /* FIXME: It is possible that -ERESTARTSYS needs to be translated to -EAGAIN here */
184 } while (ret == -EINTR || ret == -EAGAIN);
186 return ret;
189 void *drmMalloc(int size)
191 return HIDDNouveauAlloc(size);
194 void drmFree(void *pt)
196 HIDDNouveauFree(pt);