1 | /* $Id: expandospu_init.c 56922 2015-07-13 10:23:52Z vboxsync $ */
|
---|
2 | /* Copyright (c) 2001, Stanford University
|
---|
3 | * All rights reserved
|
---|
4 | *
|
---|
5 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include <stdio.h>
|
---|
9 | #include "cr_spu.h"
|
---|
10 | #include "cr_dlm.h"
|
---|
11 | #include "cr_hash.h"
|
---|
12 | #include "cr_mem.h"
|
---|
13 | #include "expandospu.h"
|
---|
14 |
|
---|
15 | /* This magic number is used for SSM data consistency check. */
|
---|
16 | #define VBOX_EXPANDOSPU_SSM_MAGIC 0x3d3d3d3d
|
---|
17 | /* Modify VBox Expando SPU SSM version if SSM data structure changed. */
|
---|
18 | #define VBOX_EXPANDOSPU_SSM_VERSION_ONE 1
|
---|
19 | #define VBOX_EXPANDOSPU_SSM_VERSION VBOX_EXPANDOSPU_SSM_VERSION_ONE
|
---|
20 |
|
---|
21 | ExpandoSPU expando_spu;
|
---|
22 |
|
---|
23 | static SPUFunctions expando_functions = {
|
---|
24 | NULL, /* CHILD COPY */
|
---|
25 | NULL, /* DATA */
|
---|
26 | _cr_expando_table /* THE ACTUAL FUNCTIONS */
|
---|
27 | };
|
---|
28 |
|
---|
29 | /*
|
---|
30 | * Structure of SSM data:
|
---|
31 | *
|
---|
32 | * <VBOX_EXPANDOSPU_SSM_MAGIC>
|
---|
33 | * <VBOX_EXPANDOSPU_SSM_VERSION>
|
---|
34 | * <Number of Expando SPU contexts>
|
---|
35 | *
|
---|
36 | * <Context ID>
|
---|
37 | * <CRDLMContextState structure>
|
---|
38 | * <DLM module data>
|
---|
39 | *
|
---|
40 | * <Next context...>
|
---|
41 | *
|
---|
42 | * <VBOX_EXPANDOSPU_SSM_MAGIC>
|
---|
43 | */
|
---|
44 |
|
---|
45 | static void
|
---|
46 | expandoSPUSaveContextCb(unsigned long id, void *pData1, void *pData2)
|
---|
47 | {
|
---|
48 | uint32_t ui32 = (uint32_t)id;
|
---|
49 | PSSMHANDLE pSSM = (PSSMHANDLE)pData2;
|
---|
50 | int32_t rc;
|
---|
51 |
|
---|
52 | ExpandoContextState *pExpandoContextState = (ExpandoContextState *)pData1;
|
---|
53 | CRDLMContextState dlmContextState;
|
---|
54 |
|
---|
55 | /* Save context ID. */
|
---|
56 | rc = SSMR3PutU32(pSSM, ui32); AssertRCReturnVoid(rc);
|
---|
57 |
|
---|
58 | /* Save DLM context state. Clean fields which will not be valid on restore (->dlm and ->currentListInfo).
|
---|
59 | * We interested only in fields: currentListIdentifier, currentListMode and listBase. */
|
---|
60 | crMemcpy(&dlmContextState, pExpandoContextState->dlmContext, sizeof(CRDLMContextState));
|
---|
61 | dlmContextState.dlm = NULL;
|
---|
62 | dlmContextState.currentListInfo = NULL;
|
---|
63 | rc = SSMR3PutMem(pSSM, &dlmContextState, sizeof(CRDLMContextState)); AssertRCReturnVoid(rc);
|
---|
64 |
|
---|
65 | /* Delegate the rest of work to DLM module. */
|
---|
66 | crDLMSaveState(pExpandoContextState->dlmContext->dlm, pSSM);
|
---|
67 | }
|
---|
68 |
|
---|
69 | static int
|
---|
70 | expandoSPUSaveState(void *pData)
|
---|
71 | {
|
---|
72 | uint32_t magic = VBOX_EXPANDOSPU_SSM_MAGIC;
|
---|
73 | uint32_t version = VBOX_EXPANDOSPU_SSM_VERSION;
|
---|
74 | PSSMHANDLE pSSM = (PSSMHANDLE)pData;
|
---|
75 | int32_t rc;
|
---|
76 | uint32_t cStates;
|
---|
77 |
|
---|
78 | crDebug("Saving state of Expando SPU.");
|
---|
79 |
|
---|
80 | AssertReturn(pSSM, 1);
|
---|
81 |
|
---|
82 | /* Magic & version first. */
|
---|
83 | rc = SSMR3PutU32(pSSM, magic); AssertRCReturn(rc, rc);
|
---|
84 | rc = SSMR3PutU32(pSSM, version); AssertRCReturn(rc, rc);
|
---|
85 |
|
---|
86 | /* Store number of Expando SPU contexts. */
|
---|
87 | cStates = (uint32_t)crHashtableNumElements(expando_spu.contextTable);
|
---|
88 | rc = SSMR3PutU32(pSSM, cStates); AssertRCReturn(rc, rc);
|
---|
89 |
|
---|
90 | /* Walk over context table and store required data. */
|
---|
91 | crHashtableWalk(expando_spu.contextTable, expandoSPUSaveContextCb, pSSM);
|
---|
92 |
|
---|
93 | /* Expando SPU and DLM data should end with magic (consistency check). */
|
---|
94 | rc = SSMR3PutU32(pSSM, magic); AssertRCReturn(rc, rc);
|
---|
95 |
|
---|
96 | return 0;
|
---|
97 | }
|
---|
98 |
|
---|
99 | static int
|
---|
100 | expandoSPULoadState(void *pData)
|
---|
101 | {
|
---|
102 | uint32_t magic = 0;
|
---|
103 | uint32_t version = 0;
|
---|
104 | PSSMHANDLE pSSM = (PSSMHANDLE)pData;
|
---|
105 | int32_t rc;
|
---|
106 |
|
---|
107 | crDebug("Loading state of Expando SPU.");
|
---|
108 |
|
---|
109 | AssertReturn(pSSM, 1);
|
---|
110 |
|
---|
111 | /* Check magic and version. */
|
---|
112 | rc = SSMR3GetU32(pSSM, &magic);
|
---|
113 | AssertRCReturn(rc, rc);
|
---|
114 |
|
---|
115 | if (magic == VBOX_EXPANDOSPU_SSM_MAGIC)
|
---|
116 | {
|
---|
117 | rc = SSMR3GetU32(pSSM, &version);
|
---|
118 | AssertRCReturn(rc, rc);
|
---|
119 |
|
---|
120 | if (version >= VBOX_EXPANDOSPU_SSM_VERSION_ONE)
|
---|
121 | {
|
---|
122 | uint32_t cStates = 0;
|
---|
123 | uint32_t i;
|
---|
124 | bool fSuccess = false;
|
---|
125 |
|
---|
126 | /* Restore number of Expando SPU contexts. */
|
---|
127 | rc = SSMR3GetU32(pSSM, &cStates);
|
---|
128 | AssertRCReturn(rc, rc);
|
---|
129 |
|
---|
130 | /* Restore and update Expando SPU contexts one by one. */
|
---|
131 | for (i = 0; i < cStates; i++)
|
---|
132 | {
|
---|
133 | uint32_t idContext = 0;
|
---|
134 | ExpandoContextState *pExpandoContextState;
|
---|
135 |
|
---|
136 | rc = SSMR3GetU32(pSSM, &idContext);
|
---|
137 | AssertRCReturn(rc, rc);
|
---|
138 |
|
---|
139 | /* Find context which was previously created by CR Server. */
|
---|
140 | pExpandoContextState = crHashtableSearch(expando_spu.contextTable, idContext);
|
---|
141 | if (pExpandoContextState)
|
---|
142 | {
|
---|
143 | CRDLMContextState dlmContextState;
|
---|
144 |
|
---|
145 | /* Restore and update DLM context state. */
|
---|
146 | rc = SSMR3GetMem(pSSM, &dlmContextState, sizeof(CRDLMContextState));
|
---|
147 | if (RT_SUCCESS(rc))
|
---|
148 | {
|
---|
149 | pExpandoContextState->dlmContext->currentListIdentifier = dlmContextState.currentListIdentifier;
|
---|
150 | pExpandoContextState->dlmContext->currentListMode = dlmContextState.currentListMode;
|
---|
151 | pExpandoContextState->dlmContext->listBase = dlmContextState.listBase;
|
---|
152 |
|
---|
153 | crDLMSetCurrentState(pExpandoContextState->dlmContext);
|
---|
154 | crStateMakeCurrent(pExpandoContextState->State);
|
---|
155 |
|
---|
156 | /* Delegate the rest of work to DLM module. */
|
---|
157 | fSuccess = crDLMLoadState(pExpandoContextState->dlmContext->dlm, pSSM, &expando_spu.server->dispatch);
|
---|
158 | if (fSuccess)
|
---|
159 | {
|
---|
160 | continue;
|
---|
161 | }
|
---|
162 | else
|
---|
163 | {
|
---|
164 | crError("Expando SPU: stop restoring Display Lists.");
|
---|
165 | break;
|
---|
166 | }
|
---|
167 | }
|
---|
168 | else
|
---|
169 | {
|
---|
170 | crError("Expando SPU: unable to load state: state file structure error (1).");
|
---|
171 | break;
|
---|
172 | }
|
---|
173 | }
|
---|
174 | else
|
---|
175 | {
|
---|
176 | crError("Expando SPU: unable to load state: no context ID %u found.", idContext);
|
---|
177 | break;
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | if (fSuccess)
|
---|
182 | {
|
---|
183 | /* Expando SPU and DLM data should end with magic (consistency check). */
|
---|
184 | magic = 0;
|
---|
185 | rc = SSMR3GetU32(pSSM, &magic);
|
---|
186 | if (RT_SUCCESS(rc))
|
---|
187 | {
|
---|
188 | if (magic == VBOX_EXPANDOSPU_SSM_MAGIC)
|
---|
189 | {
|
---|
190 | crInfo("Expando SPU state loaded.");
|
---|
191 | return 0;
|
---|
192 | }
|
---|
193 | else
|
---|
194 | crError("Expando SPU: unable to load state: SSM data corrupted.");
|
---|
195 | }
|
---|
196 | else
|
---|
197 | crError("Expando SPU: unable to load state: state file structure error (2): no magic.");
|
---|
198 | }
|
---|
199 | else
|
---|
200 | crError("Expando SPU: unable to load state: some list(s) could not be restored.");
|
---|
201 | }
|
---|
202 | else
|
---|
203 | crError("Expando SPU: unable to load state: unexpected SSM version (0x%x).", version);
|
---|
204 | }
|
---|
205 | else
|
---|
206 | crError("Expando SPU: unable to load state: SSM data possibly corrupted.");
|
---|
207 |
|
---|
208 | return VERR_SSM_UNEXPECTED_DATA;
|
---|
209 | }
|
---|
210 |
|
---|
211 | static SPUFunctions *
|
---|
212 | expandoSPUInit(int id, SPU *child, SPU *self, unsigned int context_id, unsigned int num_contexts)
|
---|
213 | {
|
---|
214 |
|
---|
215 | (void)self;
|
---|
216 | (void)context_id;
|
---|
217 | (void)num_contexts;
|
---|
218 |
|
---|
219 | expando_spu.id = id;
|
---|
220 | expando_spu.has_child = 0;
|
---|
221 | expando_spu.server = NULL;
|
---|
222 |
|
---|
223 | if (child)
|
---|
224 | {
|
---|
225 | crSPUInitDispatchTable(&(expando_spu.child));
|
---|
226 | crSPUCopyDispatchTable(&(expando_spu.child), &(child->dispatch_table));
|
---|
227 | expando_spu.has_child = 1;
|
---|
228 | }
|
---|
229 |
|
---|
230 | crSPUInitDispatchTable(&(expando_spu.super));
|
---|
231 | crSPUCopyDispatchTable(&(expando_spu.super), &(self->superSPU->dispatch_table));
|
---|
232 | expandospuGatherConfiguration();
|
---|
233 |
|
---|
234 | /* Expando-specific initialization */
|
---|
235 | expando_spu.contextTable = crAllocHashtable();
|
---|
236 |
|
---|
237 | /* We'll be using the state tracker for each context */
|
---|
238 | crStateInit();
|
---|
239 |
|
---|
240 | /* Export optional interfaces for SPU save/restore. */
|
---|
241 | self->dispatch_table.spu_save_state = expandoSPUSaveState;
|
---|
242 | self->dispatch_table.spu_load_state = expandoSPULoadState;
|
---|
243 |
|
---|
244 | return &expando_functions;
|
---|
245 | }
|
---|
246 |
|
---|
247 | static void
|
---|
248 | expandoSPUSelfDispatch(SPUDispatchTable *self)
|
---|
249 | {
|
---|
250 | crSPUInitDispatchTable(&(expando_spu.self));
|
---|
251 | crSPUCopyDispatchTable(&(expando_spu.self), self);
|
---|
252 |
|
---|
253 | expando_spu.server = (CRServer *)(self->server);
|
---|
254 | }
|
---|
255 |
|
---|
256 |
|
---|
257 | static int
|
---|
258 | expandoSPUCleanup(void)
|
---|
259 | {
|
---|
260 | crFreeHashtable(expando_spu.contextTable, expando_free_context_state);
|
---|
261 | crStateDestroy();
|
---|
262 | return 1;
|
---|
263 | }
|
---|
264 |
|
---|
265 | int
|
---|
266 | SPULoad(char **name, char **super, SPUInitFuncPtr *init, SPUSelfDispatchFuncPtr *self,
|
---|
267 | SPUCleanupFuncPtr *cleanup, SPUOptionsPtr *options, int *flags)
|
---|
268 | {
|
---|
269 | *name = "expando";
|
---|
270 | *super = "render";
|
---|
271 | *init = expandoSPUInit;
|
---|
272 | *self = expandoSPUSelfDispatch;
|
---|
273 | *cleanup = expandoSPUCleanup;
|
---|
274 | *options = expandoSPUOptions;
|
---|
275 | *flags = (SPU_NO_PACKER|SPU_NOT_TERMINAL|SPU_MAX_SERVERS_ZERO);
|
---|
276 |
|
---|
277 | return 1;
|
---|
278 | }
|
---|