1 /**********************************************************
2 * Copyright 2009 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 **********************************************************/
28 * Contains the init code for the VMware Xorg driver.
30 * @author Jakob Bornecrantz <jakob@vmware.com>
34 #include "vmw_driver.h"
35 #include <pipe/p_context.h>
37 #include "cursorstr.h"
38 #include "../../winsys/svga/drm/vmwgfx_drm.h"
40 void vmw_winsys_screen_set_throttling(struct pipe_screen *screen,
41 uint32_t throttle_us);
44 /* modified version of crtc functions */
45 xf86CrtcFuncsRec vmw_screen_crtc_funcs;
48 vmw_screen_cursor_load_argb(xf86CrtcPtr crtc, CARD32 *image)
50 struct vmw_customizer *vmw =
51 vmw_customizer(xorg_customizer(crtc->scrn));
52 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
53 xf86CrtcFuncsPtr funcs = vmw->cursor_priv;
54 CursorPtr c = config->cursor;
56 /* Run the ioctl before uploading the image */
57 vmw_ioctl_cursor_bypass(vmw, c->bits->xhot, c->bits->yhot);
59 funcs->load_cursor_argb(crtc, image);
63 vmw_screen_cursor_init(struct vmw_customizer *vmw)
65 ScrnInfoPtr pScrn = vmw->pScrn;
66 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
69 /* XXX assume that all crtc's have the same function struct */
71 /* Save old struct need to call the old functions as well */
72 vmw->cursor_priv = (void*)(config->crtc[0]->funcs);
73 memcpy(&vmw_screen_crtc_funcs, vmw->cursor_priv, sizeof(xf86CrtcFuncsRec));
74 vmw_screen_crtc_funcs.load_cursor_argb = vmw_screen_cursor_load_argb;
76 for (i = 0; i < config->num_crtc; i++)
77 config->crtc[i]->funcs = &vmw_screen_crtc_funcs;
81 vmw_screen_cursor_close(struct vmw_customizer *vmw)
83 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(vmw->pScrn);
86 vmw_ioctl_cursor_bypass(vmw, 0, 0);
88 for (i = 0; i < config->num_crtc; i++)
89 config->crtc[i]->funcs = vmw->cursor_priv;
93 vmw_context_throttle(CustomizerPtr cust,
94 struct pipe_context *pipe,
95 enum xorg_throttling_reason reason)
99 vmw_winsys_screen_set_throttling(pipe->screen, 20000);
102 vmw_winsys_screen_set_throttling(pipe->screen, 0);
107 vmw_context_no_throttle(CustomizerPtr cust,
108 struct pipe_context *pipe,
109 enum xorg_throttling_reason reason)
111 vmw_winsys_screen_set_throttling(pipe->screen, 0);
115 vmw_check_fb_size(CustomizerPtr cust,
117 unsigned long height)
119 struct vmw_customizer *vmw = vmw_customizer(cust);
122 * 1) Is there a pitch alignment?
123 * 2) The 1024 byte pad is an arbitrary value to be on
126 return ((uint64_t) pitch * height + 1024ULL < vmw->max_fb_size);
130 vmw_pre_init(CustomizerPtr cust, int fd)
132 struct vmw_customizer *vmw = vmw_customizer(cust);
137 ver = drmGetVersion(vmw->fd);
139 (ver->version_major == 1 && ver->version_minor < 1)) {
140 cust->swap_throttling = TRUE;
141 cust->dirty_throttling = TRUE;
142 cust->winsys_context_throttle = vmw_context_no_throttle;
144 cust->swap_throttling = TRUE;
145 cust->dirty_throttling = FALSE;
146 cust->winsys_context_throttle = vmw_context_throttle;
147 debug_printf("%s: Enabling kernel throttling.\n", __func__);
149 if (ver->version_major > 1 ||
150 (ver->version_major == 1 && ver->version_minor >= 3)) {
151 struct drm_vmw_getparam_arg arg;
154 arg.param = DRM_VMW_PARAM_MAX_FB_SIZE;
155 ret = drmCommandWriteRead(fd, DRM_VMW_GET_PARAM, &arg,
158 vmw->max_fb_size = arg.value;
159 cust->winsys_check_fb_size = vmw_check_fb_size;
160 debug_printf("%s: Enabling fb size check.\n", __func__);
172 vmw_screen_init(CustomizerPtr cust)
174 struct vmw_customizer *vmw = vmw_customizer(cust);
176 vmw_screen_cursor_init(vmw);
178 vmw_ctrl_ext_init(vmw);
180 /* if gallium is used then we don't need to do anything more. */
181 if (xorg_has_gallium(vmw->pScrn))
190 vmw_screen_close(CustomizerPtr cust)
192 struct vmw_customizer *vmw = vmw_customizer(cust);
197 vmw_screen_cursor_close(vmw);
199 vmw_video_close(vmw);
205 vmw_screen_enter_vt(CustomizerPtr cust)
207 debug_printf("%s: enter\n", __func__);
213 vmw_screen_leave_vt(CustomizerPtr cust)
215 struct vmw_customizer *vmw = vmw_customizer(cust);
217 debug_printf("%s: enter\n", __func__);
219 vmw_video_stop_all(vmw);
225 * Functions for setting up hooks into the xorg state tracker
228 static Bool (*vmw_screen_pre_init_saved)(ScrnInfoPtr pScrn, int flags) = NULL;
231 vmw_screen_pre_init(ScrnInfoPtr pScrn, int flags)
233 struct vmw_customizer *vmw;
236 vmw = xnfcalloc(1, sizeof(*vmw));
242 cust->winsys_pre_init = vmw_pre_init;
243 cust->winsys_screen_init = vmw_screen_init;
244 cust->winsys_screen_close = vmw_screen_close;
245 cust->winsys_enter_vt = vmw_screen_enter_vt;
246 cust->winsys_leave_vt = vmw_screen_leave_vt;
248 cust->unhidden_hw_cursor_update = TRUE;
251 pScrn->driverPrivate = cust;
253 pScrn->PreInit = vmw_screen_pre_init_saved;
254 if (!pScrn->PreInit(pScrn, flags))
261 vmw_screen_set_functions(ScrnInfoPtr pScrn)
263 assert(!vmw_screen_pre_init_saved);
265 vmw_screen_pre_init_saved = pScrn->PreInit;
266 pScrn->PreInit = vmw_screen_pre_init;