1 /*
2 * Copyright © 2006 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <anholt@FreeBSD.org>
25 *
26 */
27
28 #ifdef HAVE_XORG_CONFIG_H
29 #include <xorg-config.h>
30 #endif
31
32 #include <string.h>
33
34 #include "exa_priv.h"
35
36 #include "xf86str.h"
37 #include "xf86.h"
38
39 typedef struct _ExaXorgScreenPrivRec {
40 CloseScreenProcPtr SavedCloseScreen;
41 xf86EnableDisableFBAccessProc *SavedEnableDisableFBAccess;
42 OptionInfoPtr options;
43 } ExaXorgScreenPrivRec, *ExaXorgScreenPrivPtr;
44
45 static DevPrivateKeyRec exaXorgScreenPrivateKeyRec;
46
47 #define exaXorgScreenPrivateKey (&exaXorgScreenPrivateKeyRec)
48
49 typedef enum {
50 EXAOPT_MIGRATION_HEURISTIC,
51 EXAOPT_NO_COMPOSITE,
52 EXAOPT_NO_UTS,
53 EXAOPT_NO_DFS,
54 EXAOPT_OPTIMIZE_MIGRATION
55 } EXAOpts;
56
57 static const OptionInfoRec EXAOptions[] = {
58 {EXAOPT_MIGRATION_HEURISTIC, "MigrationHeuristic",
59 OPTV_ANYSTR, {0}, FALSE},
60 {EXAOPT_NO_COMPOSITE, "EXANoComposite",
61 OPTV_BOOLEAN, {0}, FALSE},
62 {EXAOPT_NO_UTS, "EXANoUploadToScreen",
63 OPTV_BOOLEAN, {0}, FALSE},
64 {EXAOPT_NO_DFS, "EXANoDownloadFromScreen",
65 OPTV_BOOLEAN, {0}, FALSE},
66 {EXAOPT_OPTIMIZE_MIGRATION, "EXAOptimizeMigration",
67 OPTV_BOOLEAN, {0}, FALSE},
68 {-1, NULL,
69 OPTV_NONE, {0}, FALSE}
70 };
71
72 static Bool
exaXorgCloseScreen(ScreenPtr pScreen)73 exaXorgCloseScreen(ScreenPtr pScreen)
74 {
75 ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
76 ExaXorgScreenPrivPtr pScreenPriv = (ExaXorgScreenPrivPtr)
77 dixLookupPrivate(&pScreen->devPrivates, exaXorgScreenPrivateKey);
78
79 pScreen->CloseScreen = pScreenPriv->SavedCloseScreen;
80
81 pScrn->EnableDisableFBAccess = pScreenPriv->SavedEnableDisableFBAccess;
82
83 free(pScreenPriv->options);
84 free(pScreenPriv);
85
86 return pScreen->CloseScreen(pScreen);
87 }
88
89 static void
exaXorgEnableDisableFBAccess(ScrnInfoPtr pScrn,Bool enable)90 exaXorgEnableDisableFBAccess(ScrnInfoPtr pScrn, Bool enable)
91 {
92 ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
93 ExaXorgScreenPrivPtr pScreenPriv = (ExaXorgScreenPrivPtr)
94 dixLookupPrivate(&pScreen->devPrivates, exaXorgScreenPrivateKey);
95
96 if (!enable)
97 exaEnableDisableFBAccess(pScreen, enable);
98
99 if (pScreenPriv->SavedEnableDisableFBAccess)
100 pScreenPriv->SavedEnableDisableFBAccess(pScrn, enable);
101
102 if (enable)
103 exaEnableDisableFBAccess(pScreen, enable);
104 }
105
106 /**
107 * This will be called during exaDriverInit, giving us the chance to set options
108 * and hook in our EnableDisableFBAccess.
109 */
110 void
exaDDXDriverInit(ScreenPtr pScreen)111 exaDDXDriverInit(ScreenPtr pScreen)
112 {
113 ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
114 ExaXorgScreenPrivPtr pScreenPriv;
115
116 if (!dixRegisterPrivateKey(&exaXorgScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
117 return;
118
119 pScreenPriv = calloc(1, sizeof(ExaXorgScreenPrivRec));
120 if (pScreenPriv == NULL)
121 return;
122
123 pScreenPriv->options = xnfalloc(sizeof(EXAOptions));
124 memcpy(pScreenPriv->options, EXAOptions, sizeof(EXAOptions));
125 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pScreenPriv->options);
126
127 /* private re-allocated */
128 ExaScreenPriv(pScreen);
129
130 if (pExaScr->info->flags & EXA_OFFSCREEN_PIXMAPS) {
131 if (!(pExaScr->info->flags & EXA_HANDLES_PIXMAPS) &&
132 pExaScr->info->offScreenBase < pExaScr->info->memorySize) {
133 const char *heuristicName;
134
135 heuristicName = xf86GetOptValString(pScreenPriv->options,
136 EXAOPT_MIGRATION_HEURISTIC);
137 if (heuristicName != NULL) {
138 if (strcmp(heuristicName, "greedy") == 0)
139 pExaScr->migration = ExaMigrationGreedy;
140 else if (strcmp(heuristicName, "always") == 0)
141 pExaScr->migration = ExaMigrationAlways;
142 else if (strcmp(heuristicName, "smart") == 0)
143 pExaScr->migration = ExaMigrationSmart;
144 else {
145 xf86DrvMsg(pScreen->myNum, X_WARNING,
146 "EXA: unknown migration heuristic %s\n",
147 heuristicName);
148 }
149 }
150 }
151
152 pExaScr->optimize_migration =
153 xf86ReturnOptValBool(pScreenPriv->options,
154 EXAOPT_OPTIMIZE_MIGRATION, TRUE);
155 }
156
157 if (xf86ReturnOptValBool(pScreenPriv->options, EXAOPT_NO_COMPOSITE, FALSE)) {
158 xf86DrvMsg(pScreen->myNum, X_CONFIG,
159 "EXA: Disabling Composite operation "
160 "(RENDER acceleration)\n");
161 pExaScr->info->CheckComposite = NULL;
162 pExaScr->info->PrepareComposite = NULL;
163 }
164
165 if (xf86ReturnOptValBool(pScreenPriv->options, EXAOPT_NO_UTS, FALSE)) {
166 xf86DrvMsg(pScreen->myNum, X_CONFIG, "EXA: Disabling UploadToScreen\n");
167 pExaScr->info->UploadToScreen = NULL;
168 }
169
170 if (xf86ReturnOptValBool(pScreenPriv->options, EXAOPT_NO_DFS, FALSE)) {
171 xf86DrvMsg(pScreen->myNum, X_CONFIG,
172 "EXA: Disabling DownloadFromScreen\n");
173 pExaScr->info->DownloadFromScreen = NULL;
174 }
175
176 dixSetPrivate(&pScreen->devPrivates, exaXorgScreenPrivateKey, pScreenPriv);
177
178 pScreenPriv->SavedEnableDisableFBAccess = pScrn->EnableDisableFBAccess;
179 pScrn->EnableDisableFBAccess = exaXorgEnableDisableFBAccess;
180
181 pScreenPriv->SavedCloseScreen = pScreen->CloseScreen;
182 pScreen->CloseScreen = exaXorgCloseScreen;
183
184 }
185
186 static XF86ModuleVersionInfo exaVersRec = {
187 "exa",
188 MODULEVENDORSTRING,
189 MODINFOSTRING1,
190 MODINFOSTRING2,
191 XORG_VERSION_CURRENT,
192 EXA_VERSION_MAJOR, EXA_VERSION_MINOR, EXA_VERSION_RELEASE,
193 ABI_CLASS_VIDEODRV, /* requires the video driver ABI */
194 ABI_VIDEODRV_VERSION,
195 MOD_CLASS_NONE,
196 {0, 0, 0, 0}
197 };
198
199 _X_EXPORT XF86ModuleData exaModuleData = { &exaVersRec, NULL, NULL };
200