summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Bornecrantz <wallbraker@gmail.com>2009-03-03 03:22:46 +0100
committerJakob Bornecrantz <wallbraker@gmail.com>2009-03-03 03:22:46 +0100
commit84711c6582d08b8ea0bbdd0acd27d927a9bcbf4f (patch)
treecd044f8152ab63235476c223d0af3ac415787671
parent1d060e36f248b2c1d2575d1e2cbd362b8345ae55 (diff)
st/xorg: Add Xorg state tracker
-rw-r--r--src/gallium/state_trackers/xorg/Makefile29
-rw-r--r--src/gallium/state_trackers/xorg/xorg_crtc.c314
-rw-r--r--src/gallium/state_trackers/xorg/xorg_dri2.c212
-rw-r--r--src/gallium/state_trackers/xorg/xorg_driver.c695
-rw-r--r--src/gallium/state_trackers/xorg/xorg_exa.c534
-rw-r--r--src/gallium/state_trackers/xorg/xorg_output.c296
-rw-r--r--src/gallium/state_trackers/xorg/xorg_tracker.h130
-rw-r--r--src/gallium/state_trackers/xorg/xorg_winsys.h51
8 files changed, 2261 insertions, 0 deletions
diff --git a/src/gallium/state_trackers/xorg/Makefile b/src/gallium/state_trackers/xorg/Makefile
new file mode 100644
index 00000000000..a00ea3e2a4e
--- /dev/null
+++ b/src/gallium/state_trackers/xorg/Makefile
@@ -0,0 +1,29 @@
1TARGET = libxorgtracker.a
2CFILES = $(wildcard ./*.c)
3OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES))
4GALLIUMDIR = ../..
5TOP = ../../../..
6
7include $(TOP)/configs/current
8
9CFLAGS = -DHAVE_CONFIG_H \
10 -g -Wall -Wimplicit-function-declaration -fPIC \
11 $(shell pkg-config --cflags pixman-1 xorg-server libdrm xproto) \
12 -I$(GALLIUMDIR)/include \
13 -I$(GALLIUMDIR)/auxiliary \
14 -I$(TOP)/src/mesa/drivers/dri/common \
15 -I$(TOP)/src/mesa \
16 -I$(TOP)/include \
17 -I$(TOP)/src/egl/main
18
19#############################################
20
21.PHONY = all clean
22
23all: $(TARGET)
24
25$(TARGET): $(OBJECTS)
26 ar rcs $(TARGET) $(OBJECTS)
27
28clean:
29 rm -rf $(OBJECTS) $(TARGET)
diff --git a/src/gallium/state_trackers/xorg/xorg_crtc.c b/src/gallium/state_trackers/xorg/xorg_crtc.c
new file mode 100644
index 00000000000..0765f56ee15
--- /dev/null
+++ b/src/gallium/state_trackers/xorg/xorg_crtc.c
@@ -0,0 +1,314 @@
1/*
2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 *
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
28 *
29 */
30
31#include <unistd.h>
32#include <string.h>
33#include <assert.h>
34#include <stdlib.h>
35#include <math.h>
36#include <stdint.h>
37
38#include "xorg-server.h"
39#include <xf86.h>
40#include <xf86i2c.h>
41#include <xf86Crtc.h>
42#include "xorg_tracker.h"
43#include "xf86Modes.h"
44
45#define DPMS_SERVER
46#include <X11/extensions/dpms.h>
47
48#include "pipe/p_inlines.h"
49
50struct crtc_private
51{
52 drmModeCrtcPtr drm_crtc;
53
54 /* hwcursor */
55 struct pipe_buffer *cursor_buf;
56 unsigned cursor_handle;
57};
58
59static void
60crtc_dpms(xf86CrtcPtr crtc, int mode)
61{
62 //ScrnInfoPtr pScrn = crtc->scrn;
63
64 switch (mode) {
65 case DPMSModeOn:
66 case DPMSModeStandby:
67 case DPMSModeSuspend:
68 break;
69 case DPMSModeOff:
70 break;
71 }
72}
73
74static Bool
75crtc_lock(xf86CrtcPtr crtc)
76{
77 return FALSE;
78}
79
80static void
81crtc_unlock(xf86CrtcPtr crtc)
82{
83}
84
85static void
86crtc_prepare(xf86CrtcPtr crtc)
87{
88}
89
90static void
91crtc_commit(xf86CrtcPtr crtc)
92{
93}
94
95static Bool
96crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode,
97 DisplayModePtr adjusted_mode)
98{
99 return TRUE;
100}
101
102static void
103crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
104 DisplayModePtr adjusted_mode, int x, int y)
105{
106 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
107 modesettingPtr ms = modesettingPTR(crtc->scrn);
108 xf86OutputPtr output = config->output[config->compat_output];
109 drmModeConnectorPtr drm_connector = output->driver_private;
110 struct crtc_private *crtcp = crtc->driver_private;
111 drmModeCrtcPtr drm_crtc = crtcp->drm_crtc;
112 drmModeModeInfo drm_mode;
113
114 drm_mode.clock = mode->Clock;
115 drm_mode.hdisplay = mode->HDisplay;
116 drm_mode.hsync_start = mode->HSyncStart;
117 drm_mode.hsync_end = mode->HSyncEnd;
118 drm_mode.htotal = mode->HTotal;
119 drm_mode.vdisplay = mode->VDisplay;
120 drm_mode.vsync_start = mode->VSyncStart;
121 drm_mode.vsync_end = mode->VSyncEnd;
122 drm_mode.vtotal = mode->VTotal;
123 drm_mode.flags = mode->Flags;
124 drm_mode.hskew = mode->HSkew;
125 drm_mode.vscan = mode->VScan;
126 drm_mode.vrefresh = mode->VRefresh;
127 if (!mode->name)
128 xf86SetModeDefaultName(mode);
129 strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);
130
131 drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
132 &drm_connector->connector_id, 1, &drm_mode);
133}
134
135#if 0
136static void
137crtc_load_lut(xf86CrtcPtr crtc)
138{
139 //ScrnInfoPtr pScrn = crtc->scrn;
140}
141#endif
142
143static void
144crtc_gamma_set(xf86CrtcPtr crtc, CARD16 * red, CARD16 * green, CARD16 * blue,
145 int size)
146{
147}
148
149static void *
150crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
151{
152 //ScrnInfoPtr pScrn = crtc->scrn;
153
154 return NULL;
155}
156
157static PixmapPtr
158crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
159{
160 //ScrnInfoPtr pScrn = crtc->scrn;
161
162 return NULL;
163}
164
165static void
166crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
167{
168 //ScrnInfoPtr pScrn = crtc->scrn;
169}
170
171static void
172crtc_destroy(xf86CrtcPtr crtc)
173{
174 modesettingPtr ms = modesettingPTR(crtc->scrn);
175 struct crtc_private *crtcp = crtc->driver_private;
176
177 if (crtcp->cursor_buf)
178 pipe_buffer_reference(ms->screen, &crtcp->cursor_buf, NULL);
179
180 drmModeFreeCrtc(crtcp->drm_crtc);
181 xfree(crtcp);
182}
183
184static void
185crtc_load_cursor_argb(xf86CrtcPtr crtc, CARD32 * image)
186{
187 unsigned char *ptr;
188 modesettingPtr ms = modesettingPTR(crtc->scrn);
189 struct crtc_private *crtcp = crtc->driver_private;
190
191 if (!crtcp->cursor_buf) {
192 crtcp->cursor_buf = pipe_buffer_create(ms->screen,
193 0,
194 PIPE_BUFFER_USAGE_CPU_WRITE |
195 PIPE_BUFFER_USAGE_GPU_READ,
196 64*64*4);
197 drm_api_hocks.handle_from_buffer(ms->screen,
198 crtcp->cursor_buf,
199 &crtcp->cursor_handle);
200 }
201
202 ptr = pipe_buffer_map(ms->screen, crtcp->cursor_buf, PIPE_BUFFER_USAGE_CPU_WRITE);
203
204 if (ptr)
205 memcpy(ptr, image, 64 * 64 * 4);
206
207 pipe_buffer_unmap(ms->screen, crtcp->cursor_buf);
208}
209
210static void
211crtc_set_cursor_position(xf86CrtcPtr crtc, int x, int y)
212{
213 modesettingPtr ms = modesettingPTR(crtc->scrn);
214 struct crtc_private *crtcp = crtc->driver_private;
215
216 drmModeMoveCursor(ms->fd, crtcp->drm_crtc->crtc_id, x, y);
217}
218
219static void
220crtc_show_cursor(xf86CrtcPtr crtc)
221{
222 modesettingPtr ms = modesettingPTR(crtc->scrn);
223 struct crtc_private *crtcp = crtc->driver_private;
224
225 if (crtcp->cursor_buf)
226 drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id,
227 crtcp->cursor_handle, 64, 64);
228}
229
230static void
231crtc_hide_cursor(xf86CrtcPtr crtc)
232{
233 modesettingPtr ms = modesettingPTR(crtc->scrn);
234 struct crtc_private *crtcp = crtc->driver_private;
235
236 drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, 0, 0, 0);
237}
238
239static const xf86CrtcFuncsRec crtc_funcs = {
240 .dpms = crtc_dpms,
241 .save = NULL,
242 .restore = NULL,
243 .lock = crtc_lock,
244 .unlock = crtc_unlock,
245 .mode_fixup = crtc_mode_fixup,
246 .prepare = crtc_prepare,
247 .mode_set = crtc_mode_set,
248 .commit = crtc_commit,
249 .gamma_set = crtc_gamma_set,
250 .shadow_create = crtc_shadow_create,
251 .shadow_allocate = crtc_shadow_allocate,
252 .shadow_destroy = crtc_shadow_destroy,
253 .set_cursor_position = crtc_set_cursor_position,
254 .show_cursor = crtc_show_cursor,
255 .hide_cursor = crtc_hide_cursor,
256 .load_cursor_image = NULL, /* lets convert to argb only */
257 .set_cursor_colors = NULL, /* using argb only */
258 .load_cursor_argb = crtc_load_cursor_argb,
259 .destroy = crtc_destroy,
260};
261
262void
263cursor_destroy(xf86CrtcPtr crtc)
264{
265 modesettingPtr ms = modesettingPTR(crtc->scrn);
266 struct crtc_private *crtcp = crtc->driver_private;
267
268 if (crtcp->cursor_buf) {
269 pipe_buffer_reference(ms->screen, &crtcp->cursor_buf, NULL);
270 }
271}
272
273void
274crtc_init(ScrnInfoPtr pScrn)
275{
276 modesettingPtr ms = modesettingPTR(pScrn);
277 xf86CrtcPtr crtc;
278 drmModeResPtr res;
279 drmModeCrtcPtr drm_crtc = NULL;
280 struct crtc_private *crtcp;
281 int c;
282
283 res = drmModeGetResources(ms->fd);
284 if (res == 0) {
285 ErrorF("Failed drmModeGetResources %d\n", errno);
286 return;
287 }
288
289 for (c = 0; c < res->count_crtcs; c++) {
290 drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]);
291 if (!drm_crtc)
292 continue;
293
294 crtc = xf86CrtcCreate(pScrn, &crtc_funcs);
295 if (crtc == NULL)
296 goto out;
297
298 crtcp = xcalloc(1, sizeof(struct crtc_private));
299 if (!crtcp) {
300 xf86CrtcDestroy(crtc);
301 goto out;
302 }
303
304 crtcp->drm_crtc = drm_crtc;
305
306 crtc->driver_private = crtcp;
307
308 }
309
310 out:
311 drmModeFreeResources(res);
312}
313
314/* vim: set sw=4 ts=8 sts=4: */
diff --git a/src/gallium/state_trackers/xorg/xorg_dri2.c b/src/gallium/state_trackers/xorg/xorg_dri2.c
new file mode 100644
index 00000000000..72b333eaf18
--- /dev/null
+++ b/src/gallium/state_trackers/xorg/xorg_dri2.c
@@ -0,0 +1,212 @@
1/*
2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 *
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
28 *
29 */
30
31#include "xf86.h"
32#include "xf86_OSproc.h"
33
34#include "xorg_tracker.h"
35
36#include "dri2.h"
37
38#include "pipe/p_state.h"
39#include "pipe/p_inlines.h"
40
41typedef struct {
42 PixmapPtr pPixmap;
43 struct pipe_texture *tex;
44 struct pipe_buffer *buf;
45} *BufferPrivatePtr;
46
47static DRI2BufferPtr
48driCreateBuffers(DrawablePtr pDraw, unsigned int *attachments, int count)
49{
50 struct pipe_texture *depth, *tex;
51 struct pipe_buffer *buf;
52 ScreenPtr pScreen = pDraw->pScreen;
53 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
54 modesettingPtr ms = modesettingPTR(pScrn);
55 BufferPrivatePtr privates;
56 DRI2BufferPtr buffers;
57 PixmapPtr pPixmap;
58 unsigned stride, handle;
59 int i;
60
61 buffers = xcalloc(count, sizeof *buffers);
62 if (!buffers)
63 goto fail_buffers;
64
65 privates = xcalloc(count, sizeof *privates);
66 if (!privates)
67 goto fail_privates;
68
69 depth = NULL;
70 for (i = 0; i < count; i++) {
71 pPixmap = NULL;
72 tex = NULL;
73 buf = NULL;
74 if (attachments[i] == DRI2BufferFrontLeft) {
75 if (pDraw->type == DRAWABLE_PIXMAP)
76 pPixmap = (PixmapPtr) pDraw;
77 else
78 pPixmap = (*pScreen->GetWindowPixmap)((WindowPtr) pDraw);
79 pPixmap->refcnt++;
80 tex = xorg_exa_get_texture(pPixmap);
81 } else if (attachments[i] == DRI2BufferStencil) {
82 pipe_texture_reference(&tex, depth);
83 } else if (attachments[i] == DRI2BufferDepth) {
84 struct pipe_texture template;
85
86 memset(&template, 0, sizeof(template));
87 template.target = PIPE_TEXTURE_2D;
88 template.compressed = 0;
89 template.format = PIPE_FORMAT_S8Z24_UNORM;
90 pf_get_block(template.format, &template.block);
91 template.width[0] = pDraw->width;
92 template.height[0] = pDraw->height;
93 template.depth[0] = 1;
94 template.last_level = 0;
95 template.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
96 tex = ms->screen->texture_create(ms->screen, &template);
97 } else {
98 struct pipe_texture template;
99 memset(&template, 0, sizeof(template));
100 template.target = PIPE_TEXTURE_2D;
101 template.compressed = 0;
102 template.format = PIPE_FORMAT_A8R8G8B8_UNORM;
103 pf_get_block(template.format, &template.block);
104 template.width[0] = pDraw->width;
105 template.height[0] = pDraw->height;
106 template.depth[0] = 1;
107 template.last_level = 0;
108 template.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
109 tex = ms->screen->texture_create(ms->screen, &template);
110 }
111
112 drm_api_hocks.buffer_from_texture(tex, &buf, &stride);
113 drm_api_hocks.global_handle_from_buffer(ms->screen, buf, &handle);
114
115 buffers[i].name = handle;
116 buffers[i].attachment = attachments[i];
117 buffers[i].pitch = stride;
118 buffers[i].cpp = 4;
119 buffers[i].driverPrivate = &privates[i];
120 buffers[i].flags = 0; /* not tiled */
121 privates[i].pPixmap = pPixmap;
122 privates[i].buf = buf;
123 privates[i].tex = tex;
124 }
125
126 return buffers;
127
128fail_privates:
129 xfree(buffers);
130fail_buffers:
131 return NULL;
132}
133
134static void
135driDestroyBuffers(DrawablePtr pDraw, DRI2BufferPtr buffers, int count)
136{
137 ScreenPtr pScreen = pDraw->pScreen;
138 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
139 modesettingPtr ms = modesettingPTR(pScrn);
140 BufferPrivatePtr private;
141 int i;
142
143 for (i = 0; i < count; i++) {
144 private = buffers[i].driverPrivate;
145
146 if (private->pPixmap)
147 (*pScreen->DestroyPixmap)(private->pPixmap);
148
149 pipe_texture_reference(&private->tex, NULL);
150 pipe_buffer_reference(ms->screen, &private->buf, NULL);
151 }
152
153 if (buffers) {
154 xfree(buffers[0].driverPrivate);
155 xfree(buffers);
156 }
157}
158
159static void
160driCopyRegion(DrawablePtr pDraw, RegionPtr pRegion,
161 DRI2BufferPtr pDestBuffer, DRI2BufferPtr pSrcBuffer)
162{
163 ScreenPtr pScreen = pDraw->pScreen;
164 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
165 modesettingPtr ms = modesettingPTR(pScrn);
166 BufferPrivatePtr dst_priv = pDestBuffer->driverPrivate;
167 BufferPrivatePtr src_priv = pSrcBuffer->driverPrivate;
168
169 struct pipe_surface *dst_surf =
170 ms->screen->get_tex_surface(ms->screen, dst_priv->tex, 0, 0, 0,
171 PIPE_BUFFER_USAGE_GPU_WRITE);
172 struct pipe_surface *src_surf =
173 ms->screen->get_tex_surface(ms->screen, src_priv->tex, 0, 0, 0,
174 PIPE_BUFFER_USAGE_GPU_READ);
175
176 ms->ctx->surface_copy(ms->ctx, 0, dst_surf, 0, 0, src_surf,
177 0, 0, pDraw->width, pDraw->height);
178
179 pipe_surface_reference(&dst_surf, NULL);
180 pipe_surface_reference(&src_surf, NULL);
181}
182
183Bool
184driScreenInit(ScreenPtr pScreen)
185{
186 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
187 modesettingPtr ms = modesettingPTR(pScrn);
188 DRI2InfoRec dri2info;
189
190 dri2info.version = 1;
191 dri2info.fd = ms->fd;
192#if 0
193 dri2info.driverName = pScrn->name;
194#else
195 dri2info.driverName = "i915"; /* FIXME */
196#endif
197 dri2info.deviceName = "/dev/dri/card0"; /* FIXME */
198
199 dri2info.CreateBuffers = driCreateBuffers;
200 dri2info.DestroyBuffers = driDestroyBuffers;
201 dri2info.CopyRegion = driCopyRegion;
202
203 return DRI2ScreenInit(pScreen, &dri2info);
204}
205
206void
207driCloseScreen(ScreenPtr pScreen)
208{
209 DRI2CloseScreen(pScreen);
210}
211
212/* vim: set sw=4 ts=8 sts=4: */
diff --git a/src/gallium/state_trackers/xorg/xorg_driver.c b/src/gallium/state_trackers/xorg/xorg_driver.c
new file mode 100644
index 00000000000..d166a365ac5
--- /dev/null
+++ b/src/gallium/state_trackers/xorg/xorg_driver.c
@@ -0,0 +1,695 @@
1/*
2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 *
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
28 *
29 */
30
31
32#include "xorg-server.h"
33#include "xf86.h"
34#include "xf86_OSproc.h"
35#include "compiler.h"
36#include "xf86RAC.h"
37#include "xf86PciInfo.h"
38#include "xf86Pci.h"
39#include "xf86Resources.h"
40#include "mipointer.h"
41#include "micmap.h"
42#include <X11/extensions/randr.h>
43#include "fb.h"
44#include "edid.h"
45#include "xf86i2c.h"
46#include "xf86Crtc.h"
47#include "miscstruct.h"
48#include "dixstruct.h"
49#include "xf86xv.h"
50#include <X11/extensions/Xv.h>
51#ifndef XSERVER_LIBPCIACCESS
52#error "libpciaccess needed"
53#endif
54
55#include <pciaccess.h>
56
57#include "xorg_tracker.h"
58#include "xorg_winsys.h"
59
60static void AdjustFrame(int scrnIndex, int x, int y, int flags);
61static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen);
62static Bool EnterVT(int scrnIndex, int flags);
63static Bool SaveHWState(ScrnInfoPtr pScrn);
64static Bool RestoreHWState(ScrnInfoPtr pScrn);
65
66
67static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose,
68 int flags);
69static void FreeScreen(int scrnIndex, int flags);
70static void LeaveVT(int scrnIndex, int flags);
71static Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
72static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc,
73 char **argv);
74static Bool PreInit(ScrnInfoPtr pScrn, int flags);
75
76typedef enum
77{
78 OPTION_SW_CURSOR,
79} modesettingOpts;
80
81static const OptionInfoRec Options[] = {
82 {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
83 {-1, NULL, OPTV_NONE, {0}, FALSE}
84};
85
86/*
87 * Functions that might be needed
88 */
89
90static const char *exaSymbols[] = {
91 "exaGetVersion",
92 "exaDriverInit",
93 "exaDriverFini",
94 "exaOffscreenAlloc",
95 "exaOffscreenFree",
96 "exaWaitSync",
97 NULL
98};
99
100static const char *fbSymbols[] = {
101 "fbPictureInit",
102 "fbScreenInit",
103 NULL
104};
105
106static const char *ddcSymbols[] = {
107 "xf86PrintEDID",
108 "xf86SetDDCproperties",
109 NULL
110};
111
112/*
113 * Exported Xorg driver functions to winsys
114 */
115
116void
117xorg_tracker_loader_ref_sym_lists()
118{
119 LoaderRefSymLists(exaSymbols, fbSymbols, ddcSymbols, NULL);
120}
121
122const OptionInfoRec *
123xorg_tracker_available_options(int chipid, int busid)
124{
125 return Options;
126}
127
128void
129xorg_tracker_set_functions(ScrnInfoPtr scrn)
130{
131 scrn->PreInit = PreInit;
132 scrn->ScreenInit = ScreenInit;
133 scrn->SwitchMode = SwitchMode;
134 scrn->AdjustFrame = AdjustFrame;
135 scrn->EnterVT = EnterVT;
136 scrn->LeaveVT = LeaveVT;
137 scrn->FreeScreen = FreeScreen;
138 scrn->ValidMode = ValidMode;
139}
140
141/*
142 * Static Xorg funtctions
143 */
144
145static Bool
146GetRec(ScrnInfoPtr pScrn)
147{
148 if (pScrn->driverPrivate)
149 return TRUE;
150
151 pScrn->driverPrivate = xnfcalloc(sizeof(modesettingRec), 1);
152
153 return TRUE;
154}
155
156static void
157FreeRec(ScrnInfoPtr pScrn)
158{
159 if (!pScrn)
160 return;
161
162 if (!pScrn->driverPrivate)
163 return;
164
165 xfree(pScrn->driverPrivate);
166
167 pScrn->driverPrivate = NULL;
168}
169
170static void
171ProbeDDC(ScrnInfoPtr pScrn, int index)
172{
173 ConfiguredMonitor = NULL;
174}
175
176static Bool
177CreateFrontBuffer(ScrnInfoPtr pScrn)
178{
179 modesettingPtr ms = modesettingPTR(pScrn);
180 ScreenPtr pScreen = pScrn->pScreen;
181 PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
182
183 ms->noEvict = TRUE;
184 pScreen->ModifyPixmapHeader(rootPixmap,
185 pScrn->virtualX, pScrn->virtualY,
186 pScrn->depth, pScrn->bitsPerPixel,
187 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
188 NULL);
189 ms->noEvict = FALSE;
190
191 drmModeAddFB(ms->fd,
192 pScrn->virtualX,
193 pScrn->virtualY,
194 pScrn->depth,
195 pScrn->bitsPerPixel,
196 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
197 xorg_exa_get_pixmap_handle(rootPixmap), &ms->fb_id);
198
199 pScrn->frameX0 = 0;
200 pScrn->frameY0 = 0;
201 AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
202
203 return TRUE;
204}
205
206static Bool
207crtc_resize(ScrnInfoPtr pScrn, int width, int height)
208{
209 modesettingPtr ms = modesettingPTR(pScrn);
210 //ScreenPtr pScreen = pScrn->pScreen;
211 //PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
212 //Bool fbAccessDisabled;
213 //CARD8 *fbstart;
214
215 if (width == pScrn->virtualX && height == pScrn->virtualY)
216 return TRUE;
217
218 ErrorF("RESIZING TO %dx%d\n", width, height);
219
220 pScrn->virtualX = width;
221 pScrn->virtualY = height;
222
223 /* HW dependent - FIXME */
224 pScrn->displayWidth = pScrn->virtualX;
225
226 drmModeRmFB(ms->fd, ms->fb_id);
227
228 /* now create new frontbuffer */
229 return CreateFrontBuffer(pScrn);
230}
231
232static const xf86CrtcConfigFuncsRec crtc_config_funcs = {
233 crtc_resize
234};
235
236static Bool
237PreInit(ScrnInfoPtr pScrn, int flags)
238{
239 xf86CrtcConfigPtr xf86_config;
240 modesettingPtr ms;
241 rgb defaultWeight = { 0, 0, 0 };
242 EntityInfoPtr pEnt;
243 EntPtr msEnt = NULL;
244 char *BusID;
245 int max_width, max_height;
246
247 if (pScrn->numEntities != 1)
248 return FALSE;
249
250 pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
251
252 if (flags & PROBE_DETECT) {
253 ProbeDDC(pScrn, pEnt->index);
254 return TRUE;
255 }
256
257 /* Allocate driverPrivate */
258 if (!GetRec(pScrn))
259 return FALSE;
260
261 ms = modesettingPTR(pScrn);
262 ms->SaveGeneration = -1;
263 ms->pEnt = pEnt;
264
265 pScrn->displayWidth = 640; /* default it */
266
267 if (ms->pEnt->location.type != BUS_PCI)
268 return FALSE;
269
270 ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
271
272 /* Allocate an entity private if necessary */
273 if (xf86IsEntityShared(pScrn->entityList[0])) {
274 FatalError("Entity");
275#if 0
276 msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
277 modesettingEntityIndex)->ptr;
278 ms->entityPrivate = msEnt;
279#else
280 (void)msEnt;
281#endif
282 } else
283 ms->entityPrivate = NULL;
284
285 if (xf86RegisterResources(ms->pEnt->index, NULL, ResNone)) {
286 return FALSE;
287 }
288
289 if (xf86IsEntityShared(pScrn->entityList[0])) {
290 if (xf86IsPrimInitDone(pScrn->entityList[0])) {
291 /* do something */
292 } else {
293 xf86SetPrimInitDone(pScrn->entityList[0]);
294 }
295 }
296
297 BusID = xalloc(64);
298 sprintf(BusID, "PCI:%d:%d:%d",
299 ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
300 ms->PciInfo->dev, ms->PciInfo->func
301 );
302
303 ms->fd = drmOpen(NULL, BusID);
304
305 if (ms->fd < 0)
306 return FALSE;
307
308 pScrn->racMemFlags = RAC_FB | RAC_COLORMAP;
309 pScrn->monitor = pScrn->confScreen->monitor;
310 pScrn->progClock = TRUE;
311 pScrn->rgbBits = 8;
312
313 if (!xf86SetDepthBpp
314 (pScrn, 0, 0, 0,
315 PreferConvert24to32 | SupportConvert24to32 | Support32bppFb))
316 return FALSE;
317
318 switch (pScrn->depth) {
319 case 15:
320 case 16:
321 case 24:
322 break;
323 default:
324 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
325 "Given depth (%d) is not supported by the driver\n",
326 pScrn->depth);
327 return FALSE;
328 }
329 xf86PrintDepthBpp(pScrn);
330
331 if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
332 return FALSE;
333 if (!xf86SetDefaultVisual(pScrn, -1))
334 return FALSE;
335
336 /* Process the options */
337 xf86CollectOptions(pScrn, NULL);
338 if (!(ms->Options = xalloc(sizeof(Options))))
339 return FALSE;
340 memcpy(ms->Options, Options, sizeof(Options));
341 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
342
343 /* Allocate an xf86CrtcConfig */
344 xf86CrtcConfigInit(pScrn, &crtc_config_funcs);
345 xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
346
347 max_width = 8192;
348 max_height = 8192;
349 xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height);
350
351 if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
352 ms->SWCursor = TRUE;
353 }
354
355 SaveHWState(pScrn);
356
357 crtc_init(pScrn);
358 output_init(pScrn);
359
360 if (!xf86InitialConfiguration(pScrn, TRUE)) {
361 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n");
362 RestoreHWState(pScrn);
363 return FALSE;
364 }
365
366 RestoreHWState(pScrn);
367
368 /*
369 * If the driver can do gamma correction, it should call xf86SetGamma() here.
370 */
371 {
372 Gamma zeros = { 0.0, 0.0, 0.0 };
373
374 if (!xf86SetGamma(pScrn, zeros)) {
375 return FALSE;
376 }
377 }
378
379 if (pScrn->modes == NULL) {
380 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
381 return FALSE;
382 }
383
384 pScrn->currentMode = pScrn->modes;
385
386 /* Set display resolution */
387 xf86SetDpi(pScrn, 0, 0);
388
389 /* Load the required sub modules */
390 if (!xf86LoadSubModule(pScrn, "fb")) {
391 return FALSE;
392 }
393
394 xf86LoaderReqSymLists(fbSymbols, NULL);
395
396 xf86LoadSubModule(pScrn, "exa");
397
398#ifdef DRI2
399 xf86LoadSubModule(pScrn, "dri2");
400#endif
401
402 return TRUE;
403}
404
405static Bool
406SaveHWState(ScrnInfoPtr pScrn)
407{
408 /*xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);*/
409
410 return TRUE;
411}
412
413static Bool
414RestoreHWState(ScrnInfoPtr pScrn)
415{
416 /*xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);*/
417
418 return TRUE;
419}
420
421static Bool
422CreateScreenResources(ScreenPtr pScreen)
423{
424 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
425 modesettingPtr ms = modesettingPTR(pScrn);
426 PixmapPtr rootPixmap;
427 Bool ret;
428
429 ms->noEvict = TRUE;
430
431 pScreen->CreateScreenResources = ms->createScreenResources;
432 ret = pScreen->CreateScreenResources(pScreen);
433 pScreen->CreateScreenResources = CreateScreenResources;
434
435 rootPixmap = pScreen->GetScreenPixmap(pScreen);
436
437 if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, NULL))
438 FatalError("Couldn't adjust screen pixmap\n");
439
440 ms->noEvict = FALSE;
441
442 drmModeAddFB(ms->fd,
443 pScrn->virtualX,
444 pScrn->virtualY,
445 pScrn->depth,
446 pScrn->bitsPerPixel,
447 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
448 xorg_exa_get_pixmap_handle(rootPixmap), &ms->fb_id);
449
450 AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
451
452 return ret;
453}
454
455static Bool
456ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
457{
458 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
459 modesettingPtr ms = modesettingPTR(pScrn);
460 VisualPtr visual;
461
462 /* deal with server regeneration */
463 if (ms->fd < 0) {
464 char *BusID;
465
466 BusID = xalloc(64);
467 sprintf(BusID, "PCI:%d:%d:%d",
468 ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
469 ms->PciInfo->dev, ms->PciInfo->func
470 );
471
472 ms->fd = drmOpen(NULL, BusID);
473
474 if (ms->fd < 0)
475 return FALSE;
476 }
477
478 if (!ms->screen) {
479 ms->screen = drm_api_hocks.create_screen(ms->fd, ms->PciInfo->device_id);
480
481 if (!ms->screen) {
482 FatalError("Could not init pipe_screen\n");
483 return FALSE;
484 }
485 }
486
487 pScrn->pScreen = pScreen;
488
489 /* HW dependent - FIXME */
490 pScrn->displayWidth = pScrn->virtualX;
491
492 miClearVisualTypes();
493
494 if (!miSetVisualTypes(pScrn->depth,
495 miGetDefaultVisualMask(pScrn->depth),
496 pScrn->rgbBits, pScrn->defaultVisual))
497 return FALSE;
498
499 if (!miSetPixmapDepths())
500 return FALSE;
501
502 pScrn->memPhysBase = 0;
503 pScrn->fbOffset = 0;
504
505 if (!fbScreenInit(pScreen, NULL,
506 pScrn->virtualX, pScrn->virtualY,
507 pScrn->xDpi, pScrn->yDpi,
508 pScrn->displayWidth, pScrn->bitsPerPixel))
509 return FALSE;
510
511 if (pScrn->bitsPerPixel > 8) {
512 /* Fixup RGB ordering */
513 visual = pScreen->visuals + pScreen->numVisuals;
514 while (--visual >= pScreen->visuals) {
515 if ((visual->class | DynamicClass) == DirectColor) {
516 visual->offsetRed = pScrn->offset.red;
517 visual->offsetGreen = pScrn->offset.green;
518 visual->offsetBlue = pScrn->offset.blue;
519 visual->redMask = pScrn->mask.red;
520 visual->greenMask = pScrn->mask.green;
521 visual->blueMask = pScrn->mask.blue;
522 }
523 }
524 }
525
526 fbPictureInit(pScreen, NULL, 0);
527
528 ms->createScreenResources = pScreen->CreateScreenResources;
529 pScreen->CreateScreenResources = CreateScreenResources;
530
531 xf86SetBlackWhitePixels(pScreen);
532
533 ms->exa = xorg_exa_init(pScrn);
534
535 miInitializeBackingStore(pScreen);
536 xf86SetBackingStore(pScreen);
537 xf86SetSilkenMouse(pScreen);
538 miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
539
540 /* Need to extend HWcursor support to handle mask interleave */
541 if (!ms->SWCursor)
542 xf86_cursors_init(pScreen, 64, 64,
543 HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
544 HARDWARE_CURSOR_ARGB);
545
546 /* Must force it before EnterVT, so we are in control of VT and
547 * later memory should be bound when allocating, e.g rotate_mem */
548 pScrn->vtSema = TRUE;
549
550 pScreen->SaveScreen = xf86SaveScreen;
551 ms->CloseScreen = pScreen->CloseScreen;
552 pScreen->CloseScreen = CloseScreen;
553
554 if (!xf86CrtcScreenInit(pScreen))
555 return FALSE;
556
557 if (!miCreateDefColormap(pScreen))
558 return FALSE;
559
560 xf86DPMSInit(pScreen, xf86DPMSSet, 0);
561
562 if (serverGeneration == 1)
563 xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
564
565#if 1
566#ifdef DRI2
567 driScreenInit(pScreen);
568#endif
569#endif
570
571 return EnterVT(scrnIndex, 1);
572}
573
574static void
575AdjustFrame(int scrnIndex, int x, int y, int flags)
576{
577 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
578 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
579 xf86OutputPtr output = config->output[config->compat_output];
580 xf86CrtcPtr crtc = output->crtc;
581
582 if (crtc && crtc->enabled) {
583 crtc->funcs->mode_set(crtc, pScrn->currentMode, pScrn->currentMode, x,
584 y);
585 crtc->x = output->initial_x + x;
586 crtc->y = output->initial_y + y;
587 }
588}
589
590static void
591FreeScreen(int scrnIndex, int flags)
592{
593 FreeRec(xf86Screens[scrnIndex]);
594}
595
596/* HACK */
597void
598cursor_destroy(xf86CrtcPtr crtc);
599
600static void
601LeaveVT(int scrnIndex, int flags)
602{
603 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
604 modesettingPtr ms = modesettingPTR(pScrn);
605 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
606 int o;
607
608 for (o = 0; o < config->num_crtc; o++) {
609 xf86CrtcPtr crtc = config->crtc[o];
610
611 cursor_destroy(crtc);
612
613 if (crtc->rotatedPixmap || crtc->rotatedData) {
614 crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
615 crtc->rotatedData);
616 crtc->rotatedPixmap = NULL;
617 crtc->rotatedData = NULL;
618 }
619 }
620
621 drmModeRmFB(ms->fd, ms->fb_id);
622
623 RestoreHWState(pScrn);
624
625 pScrn->vtSema = FALSE;
626}
627
628/*
629 * This gets called when gaining control of the VT, and from ScreenInit().
630 */
631static Bool
632EnterVT(int scrnIndex, int flags)
633{
634 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
635 modesettingPtr ms = modesettingPTR(pScrn);
636
637 /*
638 * Only save state once per server generation since that's what most
639 * drivers do. Could change this to save state at each VT enter.
640 */
641 if (ms->SaveGeneration != serverGeneration) {
642 ms->SaveGeneration = serverGeneration;
643 SaveHWState(pScrn);
644 }
645
646 if (!flags) /* signals startup as we'll do this in CreateScreenResources */
647 CreateFrontBuffer(pScrn);
648
649 if (!xf86SetDesiredModes(pScrn))
650 return FALSE;
651
652 return TRUE;
653}
654
655static Bool
656SwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
657{
658 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
659
660 return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
661}
662
663static Bool
664CloseScreen(int scrnIndex, ScreenPtr pScreen)
665{
666 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
667 modesettingPtr ms = modesettingPTR(pScrn);
668
669 if (pScrn->vtSema) {
670 LeaveVT(scrnIndex, 0);
671 }
672#ifdef DRI2
673 driCloseScreen(pScreen);
674#endif
675
676 pScreen->CreateScreenResources = ms->createScreenResources;
677
678 if (ms->exa)
679 xorg_exa_close(pScrn);
680
681 drmClose(ms->fd);
682 ms->fd = -1;
683
684 pScrn->vtSema = FALSE;
685 pScreen->CloseScreen = ms->CloseScreen;
686 return (*pScreen->CloseScreen) (scrnIndex, pScreen);
687}
688
689static ModeStatus
690ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
691{
692 return MODE_OK;
693}
694
695/* vim: set sw=4 ts=8 sts=4: */
diff --git a/src/gallium/state_trackers/xorg/xorg_exa.c b/src/gallium/state_trackers/xorg/xorg_exa.c
new file mode 100644
index 00000000000..ac0bfc88a4d
--- /dev/null
+++ b/src/gallium/state_trackers/xorg/xorg_exa.c
@@ -0,0 +1,534 @@
1/*
2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 *
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
28 *
29 */
30
31/* FIXME ! */
32#define DRI_DRIVER_PATH "/ISO/X.Org/modular/i386/lib/dri"
33
34#include "xf86.h"
35//#include "xf86_OSproc.h"
36#include "xorg_tracker.h"
37
38//#include "pipe/p_winsys.h"
39#include "pipe/p_format.h"
40#include "pipe/p_context.h"
41#include "pipe/p_state.h"
42#include "pipe/p_inlines.h"
43
44struct exa_entity
45{
46 ExaDriverPtr pExa;
47 struct pipe_context *ctx;
48 struct pipe_screen *scrn;
49};
50
51struct PixmapPriv
52{
53 int flags;
54 struct pipe_texture *tex;
55 unsigned int color;
56 struct pipe_surface *src_surf; /* for copies */
57 struct pipe_transfer *map_transfer;
58};
59
60/*
61 * Helper functions
62 */
63
64static enum pipe_format
65exa_get_pipe_format(int depth)
66{
67 switch (depth) {
68 case 32:
69 return PIPE_FORMAT_A8R8G8B8_UNORM;
70 case 24:
71 return PIPE_FORMAT_X8R8G8B8_UNORM;
72 case 16:
73 return PIPE_FORMAT_R5G6B5_UNORM;
74 case 15:
75 return PIPE_FORMAT_A1R5G5B5_UNORM;
76 case 8:
77 case 4:
78 case 1:
79 return PIPE_FORMAT_A8R8G8B8_UNORM; /* bad bad bad */
80 default:
81 assert(0);
82 return 0;
83 }
84}
85
86/*
87 * Static exported EXA functions
88 */
89
90static void
91ExaWaitMarker(ScreenPtr pScreen, int marker)
92{
93}
94
95static int
96ExaMarkSync(ScreenPtr pScreen)
97{
98 return 1;
99}
100
101static Bool
102ExaPrepareAccess(PixmapPtr pPix, int index)
103{
104 ScreenPtr pScreen = pPix->drawable.pScreen;
105 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
106 modesettingPtr ms = modesettingPTR(pScrn);
107 //PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
108 struct exa_entity *exa = ms->exa;
109 struct PixmapPriv *priv;
110 //int ret;
111
112 priv = exaGetPixmapDriverPrivate(pPix);
113
114 if (!priv)
115 return FALSE;
116
117 if (!priv->tex)
118 return FALSE;
119 {
120 priv->map_transfer =
121 exa->scrn->get_tex_transfer(exa->scrn, priv->tex, 0, 0, 0,
122 PIPE_TRANSFER_READ_WRITE,
123 0, 0, priv->tex->width[0], priv->tex->height[0]);
124
125 pPix->devPrivate.ptr =
126 exa->scrn->transfer_map(exa->scrn, priv->map_transfer);
127 pPix->devKind = priv->map_transfer->stride;
128 }
129
130 return TRUE;
131}
132
133static void
134ExaFinishAccess(PixmapPtr pPix, int index)
135{
136 ScreenPtr pScreen = pPix->drawable.pScreen;
137 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
138 modesettingPtr ms = modesettingPTR(pScrn);
139 struct exa_entity *exa = ms->exa;
140 struct PixmapPriv *priv;
141 priv = exaGetPixmapDriverPrivate(pPix);
142
143 if (!priv)
144 return;
145
146 if (!priv->map_transfer)
147 return;
148
149 exa->scrn->transfer_unmap(exa->scrn, priv->map_transfer);
150 pipe_transfer_reference(&priv->map_transfer, NULL);
151
152}
153
154static void
155ExaDone(PixmapPtr pPixmap)
156{
157 ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
158 modesettingPtr ms = modesettingPTR(pScrn);
159 struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
160 struct exa_entity *exa = ms->exa;
161
162 if (!priv)
163 return;
164
165 if (priv->src_surf)
166 exa->scrn->tex_surface_release(exa->scrn, &priv->src_surf);
167 priv->src_surf = NULL;
168}
169
170static void
171ExaDoneComposite(PixmapPtr pPixmap)
172{
173
174}
175
176static Bool
177ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
178{
179 ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
180 modesettingPtr ms = modesettingPTR(pScrn);
181 struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
182 struct exa_entity *exa = ms->exa;
183
184 if (1)
185 return FALSE;
186
187 if (pPixmap->drawable.depth < 15)
188 return FALSE;
189
190 if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask))
191 return FALSE;
192
193 if (!priv || !priv->tex)
194 return FALSE;
195
196 if (alu != GXcopy)
197 return FALSE;
198
199 if (!exa->ctx || !exa->ctx->surface_fill)
200 return FALSE;
201
202 priv->color = fg;
203
204 return TRUE;
205}
206
207static void
208ExaSolid(PixmapPtr pPixmap, int x0, int y0, int x1, int y1)
209{
210 ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
211 modesettingPtr ms = modesettingPTR(pScrn);
212 struct exa_entity *exa = ms->exa;
213 struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
214 struct pipe_surface *surf =
215 exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
216 PIPE_BUFFER_USAGE_GPU_READ |
217 PIPE_BUFFER_USAGE_GPU_WRITE);
218
219 exa->ctx->surface_fill(exa->ctx, surf, x0, y0, x1 - x0, y1 - y0,
220 priv->color);
221
222 exa->scrn->tex_surface_release(exa->scrn, &surf);
223}
224
225static Bool
226ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
227 int ydir, int alu, Pixel planeMask)
228{
229 ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
230 modesettingPtr ms = modesettingPTR(pScrn);
231 struct exa_entity *exa = ms->exa;
232 struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
233 struct PixmapPriv *src_priv = exaGetPixmapDriverPrivate(pSrcPixmap);
234
235 if (1)
236 return FALSE;
237
238 if (alu != GXcopy)
239 return FALSE;
240
241 if (pSrcPixmap->drawable.depth < 15 || pDstPixmap->drawable.depth < 15)
242 return FALSE;
243
244 if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask))
245 return FALSE;
246
247 if (!priv || !src_priv)
248 return FALSE;
249
250 if (!priv->tex || !src_priv->tex)
251 return FALSE;
252
253 if (!exa->ctx || !exa->ctx->surface_copy)
254 return FALSE;
255
256 priv->src_surf =
257 exa->scrn->get_tex_surface(exa->scrn, src_priv->tex, 0, 0, 0,
258 PIPE_BUFFER_USAGE_GPU_READ |
259 PIPE_BUFFER_USAGE_GPU_WRITE);
260
261 return FALSE;
262}
263
264static void
265ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY,
266 int width, int height)
267{
268 ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
269 modesettingPtr ms = modesettingPTR(pScrn);
270 struct exa_entity *exa = ms->exa;
271 struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
272 struct pipe_surface *surf =
273 exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
274 PIPE_BUFFER_USAGE_GPU_READ |
275 PIPE_BUFFER_USAGE_GPU_WRITE);
276
277 exa->ctx->surface_copy(exa->ctx, 0, surf, dstX, dstY, priv->src_surf,
278 srcX, srcY, width, height);
279 exa->scrn->tex_surface_release(exa->scrn, &surf);
280}
281
282static Bool
283ExaPrepareComposite(int op, PicturePtr pSrcPicture,
284 PicturePtr pMaskPicture, PicturePtr pDstPicture,
285 PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst)
286{
287 return FALSE;
288}
289
290#if 0
291static Bool
292ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src,
293 int src_pitch)
294{
295 ErrorF("UPLOAD\n");
296
297 return FALSE;
298}
299#endif
300
301static void
302ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY,
303 int dstX, int dstY, int width, int height)
304{
305}
306
307static Bool
308ExaCheckComposite(int op,
309 PicturePtr pSrcPicture, PicturePtr pMaskPicture,
310 PicturePtr pDstPicture)
311{
312 return FALSE;
313}
314
315static void *
316ExaCreatePixmap(ScreenPtr pScreen, int size, int align)
317{
318 struct PixmapPriv *priv;
319
320 priv = xcalloc(1, sizeof(struct PixmapPriv));
321 if (!priv)
322 return NULL;
323
324 return priv;
325}
326
327static void
328ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv)
329{
330 struct PixmapPriv *priv = (struct PixmapPriv *)dPriv;
331 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
332 modesettingPtr ms = modesettingPTR(pScrn);
333 struct exa_entity *exa = ms->exa;
334
335 if (!priv)
336 return;
337
338 if (priv->tex)
339 ms->screen->texture_release(exa->scrn, &priv->tex);
340
341 xfree(priv);
342}
343
344static Bool
345ExaPixmapIsOffscreen(PixmapPtr pPixmap)
346{
347 struct PixmapPriv *priv;
348
349 priv = exaGetPixmapDriverPrivate(pPixmap);
350
351 if (!priv)
352 return FALSE;
353
354 if (priv->tex)
355 return TRUE;
356
357 return FALSE;
358}
359
360unsigned
361xorg_exa_get_pixmap_handle(PixmapPtr pPixmap)
362{
363 ScreenPtr pScreen = pPixmap->drawable.pScreen;
364 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
365 modesettingPtr ms = modesettingPTR(pScrn);
366 struct PixmapPriv *priv;
367 struct pipe_buffer *buffer = NULL;
368 unsigned handle;
369 unsigned stride;
370
371 if (!ms->exa) {
372 FatalError("NO MS->EXA\n");
373 return 0;
374 }
375
376 priv = exaGetPixmapDriverPrivate(pPixmap);
377
378 if (!priv) {
379 FatalError("NO PIXMAP PRIVATE\n");
380 return 0;
381 }
382
383 drm_api_hocks.buffer_from_texture(priv->tex, &buffer, &stride);
384 drm_api_hocks.handle_from_buffer(ms->screen, buffer, &handle);
385 pipe_buffer_reference(ms->screen, &buffer, NULL);
386 return handle;
387}
388
389static Bool
390ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
391 int depth, int bitsPerPixel, int devKind,
392 pointer pPixData)
393{
394 ScreenPtr pScreen = pPixmap->drawable.pScreen;
395 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
396 struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
397 modesettingPtr ms = modesettingPTR(pScrn);
398 //PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
399 struct exa_entity *exa = ms->exa;
400
401 if (!priv)
402 return FALSE;
403
404 if (depth <= 0)
405 depth = pPixmap->drawable.depth;
406
407 if (bitsPerPixel <= 0)
408 bitsPerPixel = pPixmap->drawable.bitsPerPixel;
409
410 if (width <= 0)
411 width = pPixmap->drawable.width;
412
413 if (height <= 0)
414 height = pPixmap->drawable.height;
415
416 if (width <= 0 || height <= 0 || depth <= 0)
417 return FALSE;
418
419 miModifyPixmapHeader(pPixmap, width, height, depth,
420 bitsPerPixel, devKind, NULL);
421
422 /* Deal with screen resize */
423 if (priv->tex && (priv->tex->width[0] != width || priv->tex->height[0] != height)) {
424 pipe_texture_reference(&priv->tex, NULL);
425 }
426
427 if (!priv->tex) {
428 struct pipe_texture template;
429
430 memset(&template, 0, sizeof(template));
431 template.target = PIPE_TEXTURE_2D;
432 template.compressed = 0;
433 template.format = exa_get_pipe_format(depth);
434 pf_get_block(template.format, &template.block);
435 template.width[0] = width;
436 template.height[0] = height;
437 template.depth[0] = 1;
438 template.last_level = 0;
439 template.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
440 priv->tex = exa->scrn->texture_create(exa->scrn, &template);
441 }
442
443 return TRUE;
444}
445
446struct pipe_texture *
447xorg_exa_get_texture(PixmapPtr pPixmap)
448{
449 struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
450 struct pipe_texture *tex = NULL;
451 pipe_texture_reference(&tex, priv->tex);
452 return tex;
453}
454
455void
456xorg_exa_close(ScrnInfoPtr pScrn)
457{
458 modesettingPtr ms = modesettingPTR(pScrn);
459 struct exa_entity *exa = ms->exa;
460
461 if (exa->ctx)
462 exa->ctx->destroy(exa->ctx);
463
464 exaDriverFini(pScrn->pScreen);
465 xfree(exa);
466 ms->exa = NULL;
467}
468
469void *
470xorg_exa_init(ScrnInfoPtr pScrn)
471{
472 modesettingPtr ms = modesettingPTR(pScrn);
473 struct exa_entity *exa;
474 ExaDriverPtr pExa;
475
476 exa = xcalloc(1, sizeof(struct exa_entity));
477 if (!exa)
478 return NULL;
479
480 pExa = exaDriverAlloc();
481 if (!pExa) {
482 goto out_err;
483 }
484
485 memset(pExa, 0, sizeof(*pExa));
486 pExa->exa_major = 2;
487 pExa->exa_minor = 2;
488 pExa->memoryBase = 0;
489 pExa->memorySize = 0;
490 pExa->offScreenBase = 0;
491 pExa->pixmapOffsetAlign = 0;
492 pExa->pixmapPitchAlign = 1;
493 pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS;
494 pExa->maxX = 8191; /* FIXME */
495 pExa->maxY = 8191; /* FIXME */
496 pExa->WaitMarker = ExaWaitMarker;
497 pExa->MarkSync = ExaMarkSync;
498 pExa->PrepareSolid = ExaPrepareSolid;
499 pExa->Solid = ExaSolid;
500 pExa->DoneSolid = ExaDone;
501 pExa->PrepareCopy = ExaPrepareCopy;
502 pExa->Copy = ExaCopy;
503 pExa->DoneCopy = ExaDone;
504 pExa->CheckComposite = ExaCheckComposite;
505 pExa->PrepareComposite = ExaPrepareComposite;
506 pExa->Composite = ExaComposite;
507 pExa->DoneComposite = ExaDoneComposite;
508 pExa->PixmapIsOffscreen = ExaPixmapIsOffscreen;
509 pExa->PrepareAccess = ExaPrepareAccess;
510 pExa->FinishAccess = ExaFinishAccess;
511 //pExa->UploadToScreen = ExaUploadToScreen;
512 pExa->UploadToScreen = NULL;
513 pExa->CreatePixmap = ExaCreatePixmap;
514 pExa->DestroyPixmap = ExaDestroyPixmap;
515 pExa->ModifyPixmapHeader = ExaModifyPixmapHeader;
516
517 if (!exaDriverInit(pScrn->pScreen, pExa)) {
518 goto out_err;
519 }
520
521 exa->scrn = ms->screen;
522 exa->ctx = drm_api_hocks.create_context(exa->scrn);
523 /* Share context with DRI */
524 ms->ctx = exa->ctx;
525
526 return (void *)exa;
527
528 out_err:
529 xorg_exa_close(pScrn);
530
531 return NULL;
532}
533
534/* vim: set sw=4 ts=8 sts=4: */
diff --git a/src/gallium/state_trackers/xorg/xorg_output.c b/src/gallium/state_trackers/xorg/xorg_output.c
new file mode 100644
index 00000000000..950af942f5b
--- /dev/null
+++ b/src/gallium/state_trackers/xorg/xorg_output.c
@@ -0,0 +1,296 @@
1/*
2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 *
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
28 *
29 */
30
31#include "xorg-server.h"
32#include <xf86.h>
33#include <xf86i2c.h>
34#include <xf86Crtc.h>
35#include <errno.h>
36#include <fcntl.h>
37#include <unistd.h>
38#include <stdio.h>
39#include <stdlib.h>
40#include <stdint.h>
41#include <string.h>
42#include <sys/stat.h>
43#include <sys/types.h>
44
45#define DPMS_SERVER
46#include <X11/extensions/dpms.h>
47
48#include "X11/Xatom.h"
49
50#include "xorg_tracker.h"
51
52static char *connector_enum_list[] = {
53 "Unknown",
54 "VGA",
55 "DVI-I",
56 "DVI-D",
57 "DVI-A",
58 "Composite",
59 "SVIDEO",
60 "LVDS",
61 "Component",
62 "9-pin DIN",
63 "DisplayPort",
64 "HDMI Type A",
65 "HDMI Type B",
66};
67
68static void
69dpms(xf86OutputPtr output, int mode)
70{
71}
72
73static void
74save(xf86OutputPtr output)
75{
76}
77
78static void
79restore(xf86OutputPtr output)
80{
81}
82
83static int
84mode_valid(xf86OutputPtr output, DisplayModePtr pMode)
85{
86 return MODE_OK;
87}
88
89static Bool
90mode_fixup(xf86OutputPtr output, DisplayModePtr mode,
91 DisplayModePtr adjusted_mode)
92{
93 return TRUE;
94}
95
96static void
97prepare(xf86OutputPtr output)
98{
99 dpms(output, DPMSModeOff);
100}
101
102static void
103mode_set(xf86OutputPtr output, DisplayModePtr mode,
104 DisplayModePtr adjusted_mode)
105{
106}
107
108static void
109commit(xf86OutputPtr output)
110{
111 dpms(output, DPMSModeOn);
112
113 if (output->scrn->pScreen != NULL)
114 xf86_reload_cursors(output->scrn->pScreen);
115}
116
117static xf86OutputStatus
118detect(xf86OutputPtr output)
119{
120 drmModeConnectorPtr drm_connector = output->driver_private;
121
122 switch (drm_connector->connection) {
123 case DRM_MODE_CONNECTED:
124 return XF86OutputStatusConnected;
125 case DRM_MODE_DISCONNECTED:
126 return XF86OutputStatusDisconnected;
127 default:
128 return XF86OutputStatusUnknown;
129 }
130}
131
132static DisplayModePtr
133get_modes(xf86OutputPtr output)
134{
135 drmModeConnectorPtr drm_connector = output->driver_private;
136 drmModeModeInfoPtr drm_mode = NULL;
137 DisplayModePtr modes = NULL, mode = NULL;
138 int i;
139
140 for (i = 0; i < drm_connector->count_modes; i++) {
141 drm_mode = &drm_connector->modes[i];
142 if (drm_mode) {
143 mode = xcalloc(1, sizeof(DisplayModeRec));
144 if (!mode)
145 continue;
146 mode->type = 0;
147 mode->Clock = drm_mode->clock;
148 mode->HDisplay = drm_mode->hdisplay;
149 mode->HSyncStart = drm_mode->hsync_start;
150 mode->HSyncEnd = drm_mode->hsync_end;
151 mode->HTotal = drm_mode->htotal;
152 mode->VDisplay = drm_mode->vdisplay;
153 mode->VSyncStart = drm_mode->vsync_start;
154 mode->VSyncEnd = drm_mode->vsync_end;
155 mode->VTotal = drm_mode->vtotal;
156 mode->Flags = drm_mode->flags;
157 mode->HSkew = drm_mode->hskew;
158 mode->VScan = drm_mode->vscan;
159 mode->VRefresh = xf86ModeVRefresh(mode);
160 mode->Private = (void *)drm_mode;
161 xf86SetModeDefaultName(mode);
162 modes = xf86ModesAdd(modes, mode);
163 xf86PrintModeline(0, mode);
164 }
165 }
166
167 return modes;
168}
169
170static void
171destroy(xf86OutputPtr output)
172{
173 drmModeFreeConnector(output->driver_private);
174}
175
176static void
177create_resources(xf86OutputPtr output)
178{
179#ifdef RANDR_12_INTERFACE
180#endif /* RANDR_12_INTERFACE */
181}
182
183#ifdef RANDR_12_INTERFACE
184static Bool
185set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value)
186{
187 return TRUE;
188}
189#endif /* RANDR_12_INTERFACE */
190
191#ifdef RANDR_13_INTERFACE
192static Bool
193get_property(xf86OutputPtr output, Atom property)
194{
195 return TRUE;
196}
197#endif /* RANDR_13_INTERFACE */
198
199#ifdef RANDR_GET_CRTC_INTERFACE
200static xf86CrtcPtr
201get_crtc(xf86OutputPtr output)
202{
203 return NULL;
204}
205#endif
206
207static const xf86OutputFuncsRec output_funcs = {
208 .create_resources = create_resources,
209 .dpms = dpms,
210 .save = save,
211 .restore = restore,
212 .mode_valid = mode_valid,
213 .mode_fixup = mode_fixup,
214 .prepare = prepare,
215 .mode_set = mode_set,
216 .commit = commit,
217 .detect = detect,
218 .get_modes = get_modes,
219#ifdef RANDR_12_INTERFACE
220 .set_property = set_property,
221#endif
222#ifdef RANDR_13_INTERFACE
223 .get_property = get_property,
224#endif
225 .destroy = destroy,
226#ifdef RANDR_GET_CRTC_INTERFACE
227 .get_crtc = get_crtc,
228#endif
229};
230
231void
232output_init(ScrnInfoPtr pScrn)
233{
234 modesettingPtr ms = modesettingPTR(pScrn);
235 xf86OutputPtr output;
236 drmModeResPtr res;
237 drmModeConnectorPtr drm_connector = NULL;
238 drmModeEncoderPtr drm_encoder = NULL;
239 char *name;
240 int c, v, p;
241
242 res = drmModeGetResources(ms->fd);
243 if (res == 0) {
244 DRV_ERROR("Failed drmModeGetResources\n");
245 return;
246 }
247
248 for (c = 0; c < res->count_connectors; c++) {
249 drm_connector = drmModeGetConnector(ms->fd, res->connectors[c]);
250 if (!drm_connector)
251 goto out;
252
253#if 0
254 for (p = 0; p < drm_connector->count_props; p++) {
255 drmModePropertyPtr prop;
256
257 prop = drmModeGetProperty(ms->fd, drm_connector->props[p]);
258
259 name = NULL;
260 if (prop) {
261 ErrorF("VALUES %d\n", prop->count_values);
262
263 for (v = 0; v < prop->count_values; v++)
264 ErrorF("%s %lld\n", prop->name, prop->values[v]);
265 }
266 }
267#else
268 (void)p;
269 (void)v;
270#endif
271
272 name = connector_enum_list[drm_connector->connector_type];
273
274 output = xf86OutputCreate(pScrn, &output_funcs, name);
275 if (!output)
276 continue;
277
278 drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]);
279 if (drm_encoder) {
280 output->possible_crtcs = drm_encoder->possible_crtcs;
281 output->possible_clones = drm_encoder->possible_clones;
282 } else {
283 output->possible_crtcs = 0;
284 output->possible_clones = 0;
285 }
286 output->driver_private = drm_connector;
287 output->subpixel_order = SubPixelHorizontalRGB;
288 output->interlaceAllowed = FALSE;
289 output->doubleScanAllowed = FALSE;
290 }
291
292 out:
293 drmModeFreeResources(res);
294}
295
296/* vim: set sw=4 ts=8 sts=4: */
diff --git a/src/gallium/state_trackers/xorg/xorg_tracker.h b/src/gallium/state_trackers/xorg/xorg_tracker.h
new file mode 100644
index 00000000000..82c3890dfbd
--- /dev/null
+++ b/src/gallium/state_trackers/xorg/xorg_tracker.h
@@ -0,0 +1,130 @@
1/*
2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 *
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
28 *
29 */
30
31#ifndef _XORG_TRACKER_H_
32#define _XORG_TRACKER_H_
33
34#include <errno.h>
35#include <drm.h>
36#include <xf86drm.h>
37#include <xf86drmMode.h>
38#include "exa.h"
39
40#include "pipe/p_screen.h"
41#include "state_tracker/drm_api.h"
42
43#define DRV_ERROR(msg) xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
44
45typedef struct
46{
47 int lastInstance;
48 int refCount;
49 ScrnInfoPtr pScrn_1;
50 ScrnInfoPtr pScrn_2;
51} EntRec, *EntPtr;
52
53typedef struct _modesettingRec
54{
55 /* drm */
56 int fd;
57 unsigned fb_id;
58
59 /* X */
60 EntPtr entityPrivate;
61
62 int Chipset;
63 EntityInfoPtr pEnt;
64 struct pci_device *PciInfo;
65
66 Bool noAccel;
67 Bool SWCursor;
68 CloseScreenProcPtr CloseScreen;
69
70 /* Broken-out options. */
71 OptionInfoPtr Options;
72
73 unsigned int SaveGeneration;
74
75 CreateScreenResourcesProcPtr createScreenResources;
76
77 /* gallium */
78 struct pipe_screen *screen;
79 struct pipe_context *ctx;
80
81 /* exa */
82 void *exa;
83 Bool noEvict;
84
85} modesettingRec, *modesettingPtr;
86
87#define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
88
89
90/***********************************************************************
91 * xorg_exa.c
92 */
93struct pipe_texture *
94xorg_exa_get_texture(PixmapPtr pPixmap);
95
96unsigned
97xorg_exa_get_pixmap_handle(PixmapPtr pPixmap);
98
99void *
100xorg_exa_init(ScrnInfoPtr pScrn);
101
102void
103xorg_exa_close(ScrnInfoPtr pScrn);
104
105
106/***********************************************************************
107 * xorg_dri2.c
108 */
109Bool
110driScreenInit(ScreenPtr pScreen);
111
112void
113driCloseScreen(ScreenPtr pScreen);
114
115
116/***********************************************************************
117 * xorg_crtc.c
118 */
119void
120crtc_init(ScrnInfoPtr pScrn);
121
122
123/***********************************************************************
124 * xorg_output.c
125 */
126void
127output_init(ScrnInfoPtr pScrn);
128
129
130#endif /* _XORG_TRACKER_H_ */
diff --git a/src/gallium/state_trackers/xorg/xorg_winsys.h b/src/gallium/state_trackers/xorg/xorg_winsys.h
new file mode 100644
index 00000000000..d523080e90f
--- /dev/null
+++ b/src/gallium/state_trackers/xorg/xorg_winsys.h
@@ -0,0 +1,51 @@
1/*
2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 *
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
28 *
29 */
30
31/*
32 * File with all the junk needed to personalize the a xorg driver.
33 */
34
35#ifndef _XORG_WINSYS_H_
36#define _XORG_WINSYS_H_
37
38#include "xorg-server.h"
39#include "xf86.h"
40#include "xf86Resources.h"
41#include "pciaccess.h"
42
43#ifndef XSERVER_LIBPCIACCESS
44#error "libpciaccess needed"
45#endif
46
47void xorg_tracker_set_functions(ScrnInfoPtr scrn);
48const OptionInfoRec * xorg_tracker_available_options(int chipid, int busid);
49void xorg_tracker_loader_ref_sym_lists(void);
50
51#endif