14
14
15
15
typedef struct
16
16
{
17
+ LIST_ENTRY Entry ;
17
18
PDMA_ADAPTER Adapter ;
18
19
ULONG MapRegisters ;
20
+ PVOID HwDeviceExtension ;
19
21
20
22
}VIP_DMA_ADAPTER , * PVIP_DMA_ADAPTER ;
21
23
@@ -46,7 +48,14 @@ VideoPortAllocateCommonBuffer(IN PVOID HwDeviceExtension,
46
48
{
47
49
PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER )VpDmaAdapter ;
48
50
51
+ /* check for valid arguments */
52
+ if (!Adapter || !Adapter -> Adapter )
53
+ {
54
+ /* invalid parameter */
55
+ return NULL ;
56
+ }
49
57
58
+ /* allocate common buffer */
50
59
return Adapter -> Adapter -> DmaOperations -> AllocateCommonBuffer (Adapter -> Adapter , DesiredLength , LogicalAddress , CacheEnabled );
51
60
}
52
61
@@ -64,6 +73,14 @@ VideoPortReleaseCommonBuffer(IN PVOID HwDeviceExtension,
64
73
{
65
74
PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER )VpDmaAdapter ;
66
75
76
+ /* check for valid arguments */
77
+ if (!Adapter || !Adapter -> Adapter )
78
+ {
79
+ /* invalid parameter */
80
+ return ;
81
+ }
82
+
83
+ /* release common buffer */
67
84
Adapter -> Adapter -> DmaOperations -> FreeCommonBuffer (Adapter -> Adapter , Length , LogicalAddress , VirtualAddress , CacheEnabled );
68
85
}
69
86
75
92
VideoPortPutDmaAdapter (IN PVOID HwDeviceExtension ,
76
93
IN PVP_DMA_ADAPTER VpDmaAdapter )
77
94
{
95
+ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension ;
78
96
PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER )VpDmaAdapter ;
79
97
98
+ /* get hw device extension */
99
+ DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION (HwDeviceExtension );
100
+
101
+ /* sanity check */
102
+ ASSERT (!IsListEmpty (& DeviceExtension -> DmaAdapterList ));
103
+
104
+ /* remove dma adapter from list */
105
+ RemoveEntryList (& Adapter -> Entry );
106
+
107
+ /* release dma adapter */
80
108
Adapter -> Adapter -> DmaOperations -> PutDmaAdapter (Adapter -> Adapter );
109
+
110
+ /* free memory */
81
111
ExFreePool (Adapter );
82
112
}
83
113
@@ -95,13 +125,21 @@ VideoPortGetDmaAdapter(IN PVOID HwDeviceExtension,
95
125
PVIP_DMA_ADAPTER Adapter ;
96
126
PDMA_ADAPTER DmaAdapter ;
97
127
128
+ /* allocate private adapter structure */
129
+ Adapter = ExAllocatePool (NonPagedPool , sizeof (VIP_DMA_ADAPTER ));
130
+ if (!Adapter )
131
+ {
132
+ /* failed to allocate adapter structure */
133
+ return NULL ;
134
+ }
135
+
98
136
/* Zero the structure */
99
137
RtlZeroMemory (& DeviceDescription ,
100
138
sizeof (DEVICE_DESCRIPTION ));
101
139
102
140
/* Initialize the structure */
103
141
DeviceDescription .Version = DEVICE_DESCRIPTION_VERSION ;
104
- DeviceDescription .Master = TRUE /* ?? */ ;
142
+ DeviceDescription .Master = TRUE;
105
143
DeviceDescription .DmaWidth = Width8Bits ;
106
144
DeviceDescription .DmaSpeed = Compatible ;
107
145
@@ -115,21 +153,28 @@ VideoPortGetDmaAdapter(IN PVOID HwDeviceExtension,
115
153
DeviceDescription .BusNumber = DeviceExtension -> SystemIoBusNumber ;
116
154
DeviceDescription .InterfaceType = DeviceExtension -> AdapterInterfaceType ;
117
155
118
- Adapter = ExAllocatePool (NonPagedPool , sizeof (VIP_DMA_ADAPTER ));
119
- if (!Adapter )
120
- return NULL ;
121
-
122
-
156
+ /* acquire dma adapter */
123
157
DmaAdapter = IoGetDmaAdapter (DeviceExtension -> PhysicalDeviceObject , & DeviceDescription , & NumberOfMapRegisters );
124
158
if (!DmaAdapter )
125
159
{
160
+ /* failed to acquire dma */
126
161
ExFreePool (Adapter );
127
162
return NULL ;
128
163
}
129
164
165
+ /* store dma adapter */
130
166
Adapter -> Adapter = DmaAdapter ;
167
+
168
+ /* store map register count */
131
169
Adapter -> MapRegisters = NumberOfMapRegisters ;
132
170
171
+ /* store hw device extension */
172
+ Adapter -> HwDeviceExtension = HwDeviceExtension ;
173
+
174
+ /* store in dma adapter list */
175
+ InsertTailList (& DeviceExtension -> DmaAdapterList , & Adapter -> Entry );
176
+
177
+ /* return result */
133
178
return (PVP_DMA_ADAPTER )Adapter ;
134
179
}
135
180
@@ -144,21 +189,26 @@ VideoPortFreeCommonBuffer(IN PVOID HwDeviceExtension,
144
189
IN PHYSICAL_ADDRESS LogicalAddress ,
145
190
IN BOOLEAN CacheEnabled )
146
191
{
147
- DEVICE_DESCRIPTION DeviceDescription ;
148
- PVP_DMA_ADAPTER VpDmaAdapter ;
192
+ PVIP_DMA_ADAPTER VpDmaAdapter ;
193
+ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION (HwDeviceExtension );
194
+
195
+ /* sanity check */
196
+ ASSERT (!IsListEmpty (& DeviceExtension -> DmaAdapterList ));
197
+
198
+ /* grab first dma adapter */
199
+ VpDmaAdapter = (PVIP_DMA_ADAPTER )CONTAINING_RECORD (DeviceExtension -> DmaAdapterList .Flink , VIP_DMA_ADAPTER , Entry );
200
+
201
+ /* sanity checks */
202
+ ASSERT (VpDmaAdapter -> HwDeviceExtension == HwDeviceExtension );
203
+ ASSERT (VpDmaAdapter -> Adapter != NULL );
204
+ ASSERT (VpDmaAdapter -> MapRegisters != 0 );
205
+
206
+ return VideoPortReleaseCommonBuffer (HwDeviceExtension , (PVP_DMA_ADAPTER )VpDmaAdapter , Length , LogicalAddress , VirtualAddress , CacheEnabled );
149
207
150
- /* FIXME: Broken code*/
151
- VpDmaAdapter = VideoPortGetDmaAdapter (HwDeviceExtension ,
152
- (PVP_DEVICE_DESCRIPTION )& DeviceDescription );
153
- HalFreeCommonBuffer ((PADAPTER_OBJECT )VpDmaAdapter ,
154
- Length ,
155
- LogicalAddress ,
156
- VirtualAddress ,
157
- CacheEnabled );
158
208
}
159
209
160
210
/*
161
- * @unimplemented
211
+ * @implemented
162
212
*/
163
213
PVOID
164
214
NTAPI
@@ -169,8 +219,44 @@ VideoPortGetCommonBuffer(IN PVOID HwDeviceExtension,
169
219
OUT PULONG pActualLength ,
170
220
IN BOOLEAN CacheEnabled )
171
221
{
172
- UNIMPLEMENTED ;
173
- return NULL ;
222
+ PVOID Result ;
223
+ PVIP_DMA_ADAPTER VpDmaAdapter ;
224
+ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION (HwDeviceExtension );
225
+
226
+ /* maximum palette size */
227
+ if (DesiredLength > 262144 )
228
+ {
229
+ /* size exceeded */
230
+ return NULL ;
231
+ }
232
+
233
+ /* sanity check */
234
+ ASSERT (!IsListEmpty (& DeviceExtension -> DmaAdapterList ));
235
+
236
+ /* grab first dma adapter */
237
+ VpDmaAdapter = (PVIP_DMA_ADAPTER )CONTAINING_RECORD (DeviceExtension -> DmaAdapterList .Flink , VIP_DMA_ADAPTER , Entry );
238
+
239
+ /* sanity checks */
240
+ ASSERT (VpDmaAdapter -> HwDeviceExtension == HwDeviceExtension );
241
+ ASSERT (VpDmaAdapter -> Adapter != NULL );
242
+ ASSERT (VpDmaAdapter -> MapRegisters != 0 );
243
+
244
+
245
+ /* allocate common buffer */
246
+ Result = VideoPortAllocateCommonBuffer (HwDeviceExtension , (PVP_DMA_ADAPTER )VpDmaAdapter , DesiredLength , LogicalAddress , CacheEnabled , NULL );
247
+
248
+ if (Result )
249
+ {
250
+ /* store length */
251
+ * pActualLength = DesiredLength ;
252
+ }
253
+ else
254
+ {
255
+ /* failed to allocate common buffer */
256
+ * pActualLength = 0 ;
257
+ }
258
+
259
+ return Result ;
174
260
}
175
261
176
262
/*
@@ -185,7 +271,7 @@ VideoPortUnmapDmaMemory(
185
271
PDMA BoardMemoryHandle )
186
272
{
187
273
/* Deprecated */
188
- return FALSE;
274
+ return FALSE;
189
275
}
190
276
191
277
/*
@@ -203,7 +289,7 @@ VideoPortMapDmaMemory(IN PVOID HwDeviceExtension,
203
289
IN OUT PVOID * VirtualAddress )
204
290
{
205
291
/* Deprecated */
206
- return NULL ;
292
+ return NULL ;
207
293
}
208
294
209
295
/*
@@ -216,7 +302,7 @@ VideoPortSetDmaContext(IN PVOID HwDeviceExtension,
216
302
IN PVOID InstanceContext )
217
303
{
218
304
/* Deprecated */
219
- return ;
305
+ return ;
220
306
}
221
307
222
308
/*
@@ -228,7 +314,7 @@ VideoPortSignalDmaComplete(IN PVOID HwDeviceExtension,
228
314
IN PDMA pDmaHandle )
229
315
{
230
316
/* Deprecated */
231
- return FALSE;
317
+ return FALSE;
232
318
}
233
319
234
320
@@ -327,7 +413,7 @@ VideoPortGetDmaContext(IN PVOID HwDeviceExtension,
327
413
IN PDMA pDma )
328
414
{
329
415
/* Deprecated */
330
- return NULL ;
416
+ return NULL ;
331
417
}
332
418
333
419
/*
@@ -344,7 +430,7 @@ VideoPortDoDma(IN PVOID HwDeviceExtension,
344
430
}
345
431
346
432
/*
347
- * @unimplemented
433
+ * @implemented
348
434
*/
349
435
PDMA
350
436
NTAPI
@@ -353,8 +439,8 @@ VideoPortAssociateEventsWithDmaHandle(IN PVOID HwDeviceExtension,
353
439
IN PVOID MappedUserEvent ,
354
440
IN PVOID DisplayDriverEvent )
355
441
{
356
- UNIMPLEMENTED ;
357
- return NULL ;
442
+ /* Deprecated */
443
+ return NULL ;
358
444
}
359
445
360
446
/*
0 commit comments