RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / rogue / generated / devicememhistory_bridge / server_devicememhistory_bridge.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          Server bridge for devicememhistory
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Implements the server side of the bridge for devicememhistory
6 @License        Dual MIT/GPLv2
7
8 The contents of this file are subject to the MIT license as set out below.
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 Alternatively, the contents of this file may be used under the terms of
21 the GNU General Public License Version 2 ("GPL") in which case the provisions
22 of GPL are applicable instead of those above.
23
24 If you wish to allow use of your version of this file only under the terms of
25 GPL, and not to allow others to use your version of this file under the terms
26 of the MIT license, indicate your decision by deleting the provisions above
27 and replace them with the notice and other provisions required by GPL as set
28 out in the file called "GPL-COPYING" included in this distribution. If you do
29 not delete the provisions above, a recipient may use your version of this file
30 under the terms of either the MIT license or GPL.
31
32 This License is also included in this distribution in the file called
33 "MIT-COPYING".
34
35 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
36 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
37 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
39 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
40 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
41 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 */ /**************************************************************************/
43
44 #include <stddef.h>
45 #include <asm/uaccess.h>
46
47 #include "img_defs.h"
48
49 #include "devicemem_history_server.h"
50
51
52 #include "common_devicememhistory_bridge.h"
53
54 #include "allocmem.h"
55 #include "pvr_debug.h"
56 #include "connection_server.h"
57 #include "pvr_bridge.h"
58 #include "rgx_bridge.h"
59 #include "srvcore.h"
60 #include "handle.h"
61
62 #include <linux/slab.h>
63
64 #include "lock.h"
65
66
67 #if defined(SUPPORT_DEVICEMEMHISTORY_BRIDGE)
68
69
70
71 /* ***************************************************************************
72  * Server-side bridge entry points
73  */
74  
75 static IMG_INT
76 PVRSRVBridgeDevicememHistoryMap(IMG_UINT32 ui32DispatchTableEntry,
77                                           PVRSRV_BRIDGE_IN_DEVICEMEMHISTORYMAP *psDevicememHistoryMapIN,
78                                           PVRSRV_BRIDGE_OUT_DEVICEMEMHISTORYMAP *psDevicememHistoryMapOUT,
79                                          CONNECTION_DATA *psConnection)
80 {
81         IMG_CHAR *uiTextInt = NULL;
82
83         IMG_UINT32 ui32NextOffset = 0;
84         IMG_BYTE   *pArrayArgsBuffer = NULL;
85 #if !defined(INTEGRITY_OS)
86         IMG_BOOL bHaveEnoughSpace = IMG_FALSE;
87 #endif
88
89         IMG_UINT32 ui32BufferSize = 
90                         (DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR)) +
91                         0;
92
93
94         PVR_UNREFERENCED_PARAMETER(psConnection);
95
96
97
98         if (ui32BufferSize != 0)
99         {
100 #if !defined(INTEGRITY_OS)
101                 /* Try to use remainder of input buffer for copies if possible, word-aligned for safety. */
102                 IMG_UINT32 ui32InBufferOffset = PVR_ALIGN(sizeof(*psDevicememHistoryMapIN), sizeof(unsigned long));
103                 IMG_UINT32 ui32InBufferExcessSize = ui32InBufferOffset >= PVRSRV_MAX_BRIDGE_IN_SIZE ? 0 :
104                         PVRSRV_MAX_BRIDGE_IN_SIZE - ui32InBufferOffset;
105
106                 bHaveEnoughSpace = ui32BufferSize <= ui32InBufferExcessSize;
107                 if (bHaveEnoughSpace)
108                 {
109                         IMG_BYTE *pInputBuffer = (IMG_BYTE *)psDevicememHistoryMapIN;
110
111                         pArrayArgsBuffer = &pInputBuffer[ui32InBufferOffset];           }
112                 else
113 #endif
114                 {
115                         pArrayArgsBuffer = OSAllocMemNoStats(ui32BufferSize);
116
117                         if(!pArrayArgsBuffer)
118                         {
119                                 psDevicememHistoryMapOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
120                                 goto DevicememHistoryMap_exit;
121                         }
122                 }
123         }
124
125         
126         {
127                 uiTextInt = (IMG_CHAR*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
128                 ui32NextOffset += DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR);
129         }
130
131                         /* Copy the data over */
132                         if (DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR) > 0)
133                         {
134                                 if ( OSCopyFromUser(NULL, uiTextInt, psDevicememHistoryMapIN->puiText, DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR)) != PVRSRV_OK )
135                                 {
136                                         psDevicememHistoryMapOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
137
138                                         goto DevicememHistoryMap_exit;
139                                 }
140                         }
141
142
143         psDevicememHistoryMapOUT->eError =
144                 DevicememHistoryMapKM(
145                                         psDevicememHistoryMapIN->sDevVAddr,
146                                         psDevicememHistoryMapIN->uiSize,
147                                         uiTextInt);
148
149
150
151
152 DevicememHistoryMap_exit:
153
154
155
156         /* Allocated space should be equal to the last updated offset */
157         PVR_ASSERT(ui32BufferSize == ui32NextOffset);
158
159 #if defined(INTEGRITY_OS)
160         if(pArrayArgsBuffer)
161 #else
162         if(!bHaveEnoughSpace && pArrayArgsBuffer)
163 #endif
164                 OSFreeMemNoStats(pArrayArgsBuffer);
165
166
167         return 0;
168 }
169
170
171 static IMG_INT
172 PVRSRVBridgeDevicememHistoryUnmap(IMG_UINT32 ui32DispatchTableEntry,
173                                           PVRSRV_BRIDGE_IN_DEVICEMEMHISTORYUNMAP *psDevicememHistoryUnmapIN,
174                                           PVRSRV_BRIDGE_OUT_DEVICEMEMHISTORYUNMAP *psDevicememHistoryUnmapOUT,
175                                          CONNECTION_DATA *psConnection)
176 {
177         IMG_CHAR *uiTextInt = NULL;
178
179         IMG_UINT32 ui32NextOffset = 0;
180         IMG_BYTE   *pArrayArgsBuffer = NULL;
181 #if !defined(INTEGRITY_OS)
182         IMG_BOOL bHaveEnoughSpace = IMG_FALSE;
183 #endif
184
185         IMG_UINT32 ui32BufferSize = 
186                         (DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR)) +
187                         0;
188
189
190         PVR_UNREFERENCED_PARAMETER(psConnection);
191
192
193
194         if (ui32BufferSize != 0)
195         {
196 #if !defined(INTEGRITY_OS)
197                 /* Try to use remainder of input buffer for copies if possible, word-aligned for safety. */
198                 IMG_UINT32 ui32InBufferOffset = PVR_ALIGN(sizeof(*psDevicememHistoryUnmapIN), sizeof(unsigned long));
199                 IMG_UINT32 ui32InBufferExcessSize = ui32InBufferOffset >= PVRSRV_MAX_BRIDGE_IN_SIZE ? 0 :
200                         PVRSRV_MAX_BRIDGE_IN_SIZE - ui32InBufferOffset;
201
202                 bHaveEnoughSpace = ui32BufferSize <= ui32InBufferExcessSize;
203                 if (bHaveEnoughSpace)
204                 {
205                         IMG_BYTE *pInputBuffer = (IMG_BYTE *)psDevicememHistoryUnmapIN;
206
207                         pArrayArgsBuffer = &pInputBuffer[ui32InBufferOffset];           }
208                 else
209 #endif
210                 {
211                         pArrayArgsBuffer = OSAllocMemNoStats(ui32BufferSize);
212
213                         if(!pArrayArgsBuffer)
214                         {
215                                 psDevicememHistoryUnmapOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
216                                 goto DevicememHistoryUnmap_exit;
217                         }
218                 }
219         }
220
221         
222         {
223                 uiTextInt = (IMG_CHAR*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
224                 ui32NextOffset += DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR);
225         }
226
227                         /* Copy the data over */
228                         if (DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR) > 0)
229                         {
230                                 if ( OSCopyFromUser(NULL, uiTextInt, psDevicememHistoryUnmapIN->puiText, DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR)) != PVRSRV_OK )
231                                 {
232                                         psDevicememHistoryUnmapOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
233
234                                         goto DevicememHistoryUnmap_exit;
235                                 }
236                         }
237
238
239         psDevicememHistoryUnmapOUT->eError =
240                 DevicememHistoryUnmapKM(
241                                         psDevicememHistoryUnmapIN->sDevVAddr,
242                                         psDevicememHistoryUnmapIN->uiSize,
243                                         uiTextInt);
244
245
246
247
248 DevicememHistoryUnmap_exit:
249
250
251
252         /* Allocated space should be equal to the last updated offset */
253         PVR_ASSERT(ui32BufferSize == ui32NextOffset);
254
255 #if defined(INTEGRITY_OS)
256         if(pArrayArgsBuffer)
257 #else
258         if(!bHaveEnoughSpace && pArrayArgsBuffer)
259 #endif
260                 OSFreeMemNoStats(pArrayArgsBuffer);
261
262
263         return 0;
264 }
265
266
267 static IMG_INT
268 PVRSRVBridgeDevicememHistoryMapNew(IMG_UINT32 ui32DispatchTableEntry,
269                                           PVRSRV_BRIDGE_IN_DEVICEMEMHISTORYMAPNEW *psDevicememHistoryMapNewIN,
270                                           PVRSRV_BRIDGE_OUT_DEVICEMEMHISTORYMAPNEW *psDevicememHistoryMapNewOUT,
271                                          CONNECTION_DATA *psConnection)
272 {
273         IMG_HANDLE hPMR = psDevicememHistoryMapNewIN->hPMR;
274         PMR * psPMRInt = NULL;
275         IMG_CHAR *uiTextInt = NULL;
276
277         IMG_UINT32 ui32NextOffset = 0;
278         IMG_BYTE   *pArrayArgsBuffer = NULL;
279 #if !defined(INTEGRITY_OS)
280         IMG_BOOL bHaveEnoughSpace = IMG_FALSE;
281 #endif
282
283         IMG_UINT32 ui32BufferSize = 
284                         (DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR)) +
285                         0;
286
287
288
289
290
291         if (ui32BufferSize != 0)
292         {
293 #if !defined(INTEGRITY_OS)
294                 /* Try to use remainder of input buffer for copies if possible, word-aligned for safety. */
295                 IMG_UINT32 ui32InBufferOffset = PVR_ALIGN(sizeof(*psDevicememHistoryMapNewIN), sizeof(unsigned long));
296                 IMG_UINT32 ui32InBufferExcessSize = ui32InBufferOffset >= PVRSRV_MAX_BRIDGE_IN_SIZE ? 0 :
297                         PVRSRV_MAX_BRIDGE_IN_SIZE - ui32InBufferOffset;
298
299                 bHaveEnoughSpace = ui32BufferSize <= ui32InBufferExcessSize;
300                 if (bHaveEnoughSpace)
301                 {
302                         IMG_BYTE *pInputBuffer = (IMG_BYTE *)psDevicememHistoryMapNewIN;
303
304                         pArrayArgsBuffer = &pInputBuffer[ui32InBufferOffset];           }
305                 else
306 #endif
307                 {
308                         pArrayArgsBuffer = OSAllocMemNoStats(ui32BufferSize);
309
310                         if(!pArrayArgsBuffer)
311                         {
312                                 psDevicememHistoryMapNewOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
313                                 goto DevicememHistoryMapNew_exit;
314                         }
315                 }
316         }
317
318         
319         {
320                 uiTextInt = (IMG_CHAR*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
321                 ui32NextOffset += DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR);
322         }
323
324                         /* Copy the data over */
325                         if (DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR) > 0)
326                         {
327                                 if ( OSCopyFromUser(NULL, uiTextInt, psDevicememHistoryMapNewIN->puiText, DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR)) != PVRSRV_OK )
328                                 {
329                                         psDevicememHistoryMapNewOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
330
331                                         goto DevicememHistoryMapNew_exit;
332                                 }
333                         }
334
335         /* Lock over handle lookup. */
336         LockHandle();
337
338
339
340
341
342                                 {
343                                         /* Look up the address from the handle */
344                                         psDevicememHistoryMapNewOUT->eError =
345                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
346                                                                                         (void **) &psPMRInt,
347                                                                                         hPMR,
348                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR,
349                                                                                         IMG_TRUE);
350                                         if(psDevicememHistoryMapNewOUT->eError != PVRSRV_OK)
351                                         {
352                                                 UnlockHandle();
353                                                 goto DevicememHistoryMapNew_exit;
354                                         }
355                                 }
356         /* Release now we have looked up handles. */
357         UnlockHandle();
358
359         psDevicememHistoryMapNewOUT->eError =
360                 DevicememHistoryMapNewKM(
361                                         psPMRInt,
362                                         psDevicememHistoryMapNewIN->uiOffset,
363                                         psDevicememHistoryMapNewIN->sDevVAddr,
364                                         psDevicememHistoryMapNewIN->uiSize,
365                                         uiTextInt,
366                                         psDevicememHistoryMapNewIN->ui32Log2PageSize,
367                                         psDevicememHistoryMapNewIN->ui32AllocationIndex,
368                                         &psDevicememHistoryMapNewOUT->ui32AllocationIndexOut);
369
370
371
372
373 DevicememHistoryMapNew_exit:
374
375         /* Lock over handle lookup cleanup. */
376         LockHandle();
377
378
379
380
381
382
383                                 {
384                                         /* Unreference the previously looked up handle */
385                                                 if(psPMRInt)
386                                                 {
387                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
388                                                                                         hPMR,
389                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR);
390                                                 }
391                                 }
392         /* Release now we have cleaned up look up handles. */
393         UnlockHandle();
394
395         /* Allocated space should be equal to the last updated offset */
396         PVR_ASSERT(ui32BufferSize == ui32NextOffset);
397
398 #if defined(INTEGRITY_OS)
399         if(pArrayArgsBuffer)
400 #else
401         if(!bHaveEnoughSpace && pArrayArgsBuffer)
402 #endif
403                 OSFreeMemNoStats(pArrayArgsBuffer);
404
405
406         return 0;
407 }
408
409
410 static IMG_INT
411 PVRSRVBridgeDevicememHistoryUnmapNew(IMG_UINT32 ui32DispatchTableEntry,
412                                           PVRSRV_BRIDGE_IN_DEVICEMEMHISTORYUNMAPNEW *psDevicememHistoryUnmapNewIN,
413                                           PVRSRV_BRIDGE_OUT_DEVICEMEMHISTORYUNMAPNEW *psDevicememHistoryUnmapNewOUT,
414                                          CONNECTION_DATA *psConnection)
415 {
416         IMG_HANDLE hPMR = psDevicememHistoryUnmapNewIN->hPMR;
417         PMR * psPMRInt = NULL;
418         IMG_CHAR *uiTextInt = NULL;
419
420         IMG_UINT32 ui32NextOffset = 0;
421         IMG_BYTE   *pArrayArgsBuffer = NULL;
422 #if !defined(INTEGRITY_OS)
423         IMG_BOOL bHaveEnoughSpace = IMG_FALSE;
424 #endif
425
426         IMG_UINT32 ui32BufferSize = 
427                         (DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR)) +
428                         0;
429
430
431
432
433
434         if (ui32BufferSize != 0)
435         {
436 #if !defined(INTEGRITY_OS)
437                 /* Try to use remainder of input buffer for copies if possible, word-aligned for safety. */
438                 IMG_UINT32 ui32InBufferOffset = PVR_ALIGN(sizeof(*psDevicememHistoryUnmapNewIN), sizeof(unsigned long));
439                 IMG_UINT32 ui32InBufferExcessSize = ui32InBufferOffset >= PVRSRV_MAX_BRIDGE_IN_SIZE ? 0 :
440                         PVRSRV_MAX_BRIDGE_IN_SIZE - ui32InBufferOffset;
441
442                 bHaveEnoughSpace = ui32BufferSize <= ui32InBufferExcessSize;
443                 if (bHaveEnoughSpace)
444                 {
445                         IMG_BYTE *pInputBuffer = (IMG_BYTE *)psDevicememHistoryUnmapNewIN;
446
447                         pArrayArgsBuffer = &pInputBuffer[ui32InBufferOffset];           }
448                 else
449 #endif
450                 {
451                         pArrayArgsBuffer = OSAllocMemNoStats(ui32BufferSize);
452
453                         if(!pArrayArgsBuffer)
454                         {
455                                 psDevicememHistoryUnmapNewOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
456                                 goto DevicememHistoryUnmapNew_exit;
457                         }
458                 }
459         }
460
461         
462         {
463                 uiTextInt = (IMG_CHAR*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
464                 ui32NextOffset += DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR);
465         }
466
467                         /* Copy the data over */
468                         if (DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR) > 0)
469                         {
470                                 if ( OSCopyFromUser(NULL, uiTextInt, psDevicememHistoryUnmapNewIN->puiText, DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR)) != PVRSRV_OK )
471                                 {
472                                         psDevicememHistoryUnmapNewOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
473
474                                         goto DevicememHistoryUnmapNew_exit;
475                                 }
476                         }
477
478         /* Lock over handle lookup. */
479         LockHandle();
480
481
482
483
484
485                                 {
486                                         /* Look up the address from the handle */
487                                         psDevicememHistoryUnmapNewOUT->eError =
488                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
489                                                                                         (void **) &psPMRInt,
490                                                                                         hPMR,
491                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR,
492                                                                                         IMG_TRUE);
493                                         if(psDevicememHistoryUnmapNewOUT->eError != PVRSRV_OK)
494                                         {
495                                                 UnlockHandle();
496                                                 goto DevicememHistoryUnmapNew_exit;
497                                         }
498                                 }
499         /* Release now we have looked up handles. */
500         UnlockHandle();
501
502         psDevicememHistoryUnmapNewOUT->eError =
503                 DevicememHistoryUnmapNewKM(
504                                         psPMRInt,
505                                         psDevicememHistoryUnmapNewIN->uiOffset,
506                                         psDevicememHistoryUnmapNewIN->sDevVAddr,
507                                         psDevicememHistoryUnmapNewIN->uiSize,
508                                         uiTextInt,
509                                         psDevicememHistoryUnmapNewIN->ui32Log2PageSize,
510                                         psDevicememHistoryUnmapNewIN->ui32AllocationIndex,
511                                         &psDevicememHistoryUnmapNewOUT->ui32AllocationIndexOut);
512
513
514
515
516 DevicememHistoryUnmapNew_exit:
517
518         /* Lock over handle lookup cleanup. */
519         LockHandle();
520
521
522
523
524
525
526                                 {
527                                         /* Unreference the previously looked up handle */
528                                                 if(psPMRInt)
529                                                 {
530                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
531                                                                                         hPMR,
532                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR);
533                                                 }
534                                 }
535         /* Release now we have cleaned up look up handles. */
536         UnlockHandle();
537
538         /* Allocated space should be equal to the last updated offset */
539         PVR_ASSERT(ui32BufferSize == ui32NextOffset);
540
541 #if defined(INTEGRITY_OS)
542         if(pArrayArgsBuffer)
543 #else
544         if(!bHaveEnoughSpace && pArrayArgsBuffer)
545 #endif
546                 OSFreeMemNoStats(pArrayArgsBuffer);
547
548
549         return 0;
550 }
551
552
553 static IMG_INT
554 PVRSRVBridgeDevicememHistoryMapVRange(IMG_UINT32 ui32DispatchTableEntry,
555                                           PVRSRV_BRIDGE_IN_DEVICEMEMHISTORYMAPVRANGE *psDevicememHistoryMapVRangeIN,
556                                           PVRSRV_BRIDGE_OUT_DEVICEMEMHISTORYMAPVRANGE *psDevicememHistoryMapVRangeOUT,
557                                          CONNECTION_DATA *psConnection)
558 {
559         IMG_CHAR *uiTextInt = NULL;
560
561         IMG_UINT32 ui32NextOffset = 0;
562         IMG_BYTE   *pArrayArgsBuffer = NULL;
563 #if !defined(INTEGRITY_OS)
564         IMG_BOOL bHaveEnoughSpace = IMG_FALSE;
565 #endif
566
567         IMG_UINT32 ui32BufferSize = 
568                         (DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR)) +
569                         0;
570
571
572         PVR_UNREFERENCED_PARAMETER(psConnection);
573
574
575
576         if (ui32BufferSize != 0)
577         {
578 #if !defined(INTEGRITY_OS)
579                 /* Try to use remainder of input buffer for copies if possible, word-aligned for safety. */
580                 IMG_UINT32 ui32InBufferOffset = PVR_ALIGN(sizeof(*psDevicememHistoryMapVRangeIN), sizeof(unsigned long));
581                 IMG_UINT32 ui32InBufferExcessSize = ui32InBufferOffset >= PVRSRV_MAX_BRIDGE_IN_SIZE ? 0 :
582                         PVRSRV_MAX_BRIDGE_IN_SIZE - ui32InBufferOffset;
583
584                 bHaveEnoughSpace = ui32BufferSize <= ui32InBufferExcessSize;
585                 if (bHaveEnoughSpace)
586                 {
587                         IMG_BYTE *pInputBuffer = (IMG_BYTE *)psDevicememHistoryMapVRangeIN;
588
589                         pArrayArgsBuffer = &pInputBuffer[ui32InBufferOffset];           }
590                 else
591 #endif
592                 {
593                         pArrayArgsBuffer = OSAllocMemNoStats(ui32BufferSize);
594
595                         if(!pArrayArgsBuffer)
596                         {
597                                 psDevicememHistoryMapVRangeOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
598                                 goto DevicememHistoryMapVRange_exit;
599                         }
600                 }
601         }
602
603         
604         {
605                 uiTextInt = (IMG_CHAR*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
606                 ui32NextOffset += DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR);
607         }
608
609                         /* Copy the data over */
610                         if (DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR) > 0)
611                         {
612                                 if ( OSCopyFromUser(NULL, uiTextInt, psDevicememHistoryMapVRangeIN->puiText, DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR)) != PVRSRV_OK )
613                                 {
614                                         psDevicememHistoryMapVRangeOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
615
616                                         goto DevicememHistoryMapVRange_exit;
617                                 }
618                         }
619
620
621         psDevicememHistoryMapVRangeOUT->eError =
622                 DevicememHistoryMapVRangeKM(
623                                         psDevicememHistoryMapVRangeIN->sBaseDevVAddr,
624                                         psDevicememHistoryMapVRangeIN->ui32ui32StartPage,
625                                         psDevicememHistoryMapVRangeIN->ui32NumPages,
626                                         psDevicememHistoryMapVRangeIN->uiAllocSize,
627                                         uiTextInt,
628                                         psDevicememHistoryMapVRangeIN->ui32Log2PageSize,
629                                         psDevicememHistoryMapVRangeIN->ui32AllocationIndex,
630                                         &psDevicememHistoryMapVRangeOUT->ui32AllocationIndexOut);
631
632
633
634
635 DevicememHistoryMapVRange_exit:
636
637
638
639         /* Allocated space should be equal to the last updated offset */
640         PVR_ASSERT(ui32BufferSize == ui32NextOffset);
641
642 #if defined(INTEGRITY_OS)
643         if(pArrayArgsBuffer)
644 #else
645         if(!bHaveEnoughSpace && pArrayArgsBuffer)
646 #endif
647                 OSFreeMemNoStats(pArrayArgsBuffer);
648
649
650         return 0;
651 }
652
653
654 static IMG_INT
655 PVRSRVBridgeDevicememHistoryUnmapVRange(IMG_UINT32 ui32DispatchTableEntry,
656                                           PVRSRV_BRIDGE_IN_DEVICEMEMHISTORYUNMAPVRANGE *psDevicememHistoryUnmapVRangeIN,
657                                           PVRSRV_BRIDGE_OUT_DEVICEMEMHISTORYUNMAPVRANGE *psDevicememHistoryUnmapVRangeOUT,
658                                          CONNECTION_DATA *psConnection)
659 {
660         IMG_CHAR *uiTextInt = NULL;
661
662         IMG_UINT32 ui32NextOffset = 0;
663         IMG_BYTE   *pArrayArgsBuffer = NULL;
664 #if !defined(INTEGRITY_OS)
665         IMG_BOOL bHaveEnoughSpace = IMG_FALSE;
666 #endif
667
668         IMG_UINT32 ui32BufferSize = 
669                         (DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR)) +
670                         0;
671
672
673         PVR_UNREFERENCED_PARAMETER(psConnection);
674
675
676
677         if (ui32BufferSize != 0)
678         {
679 #if !defined(INTEGRITY_OS)
680                 /* Try to use remainder of input buffer for copies if possible, word-aligned for safety. */
681                 IMG_UINT32 ui32InBufferOffset = PVR_ALIGN(sizeof(*psDevicememHistoryUnmapVRangeIN), sizeof(unsigned long));
682                 IMG_UINT32 ui32InBufferExcessSize = ui32InBufferOffset >= PVRSRV_MAX_BRIDGE_IN_SIZE ? 0 :
683                         PVRSRV_MAX_BRIDGE_IN_SIZE - ui32InBufferOffset;
684
685                 bHaveEnoughSpace = ui32BufferSize <= ui32InBufferExcessSize;
686                 if (bHaveEnoughSpace)
687                 {
688                         IMG_BYTE *pInputBuffer = (IMG_BYTE *)psDevicememHistoryUnmapVRangeIN;
689
690                         pArrayArgsBuffer = &pInputBuffer[ui32InBufferOffset];           }
691                 else
692 #endif
693                 {
694                         pArrayArgsBuffer = OSAllocMemNoStats(ui32BufferSize);
695
696                         if(!pArrayArgsBuffer)
697                         {
698                                 psDevicememHistoryUnmapVRangeOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
699                                 goto DevicememHistoryUnmapVRange_exit;
700                         }
701                 }
702         }
703
704         
705         {
706                 uiTextInt = (IMG_CHAR*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
707                 ui32NextOffset += DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR);
708         }
709
710                         /* Copy the data over */
711                         if (DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR) > 0)
712                         {
713                                 if ( OSCopyFromUser(NULL, uiTextInt, psDevicememHistoryUnmapVRangeIN->puiText, DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR)) != PVRSRV_OK )
714                                 {
715                                         psDevicememHistoryUnmapVRangeOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
716
717                                         goto DevicememHistoryUnmapVRange_exit;
718                                 }
719                         }
720
721
722         psDevicememHistoryUnmapVRangeOUT->eError =
723                 DevicememHistoryUnmapVRangeKM(
724                                         psDevicememHistoryUnmapVRangeIN->sBaseDevVAddr,
725                                         psDevicememHistoryUnmapVRangeIN->ui32ui32StartPage,
726                                         psDevicememHistoryUnmapVRangeIN->ui32NumPages,
727                                         psDevicememHistoryUnmapVRangeIN->uiAllocSize,
728                                         uiTextInt,
729                                         psDevicememHistoryUnmapVRangeIN->ui32Log2PageSize,
730                                         psDevicememHistoryUnmapVRangeIN->ui32AllocationIndex,
731                                         &psDevicememHistoryUnmapVRangeOUT->ui32AllocationIndexOut);
732
733
734
735
736 DevicememHistoryUnmapVRange_exit:
737
738
739
740         /* Allocated space should be equal to the last updated offset */
741         PVR_ASSERT(ui32BufferSize == ui32NextOffset);
742
743 #if defined(INTEGRITY_OS)
744         if(pArrayArgsBuffer)
745 #else
746         if(!bHaveEnoughSpace && pArrayArgsBuffer)
747 #endif
748                 OSFreeMemNoStats(pArrayArgsBuffer);
749
750
751         return 0;
752 }
753
754
755 static IMG_INT
756 PVRSRVBridgeDevicememHistorySparseChange(IMG_UINT32 ui32DispatchTableEntry,
757                                           PVRSRV_BRIDGE_IN_DEVICEMEMHISTORYSPARSECHANGE *psDevicememHistorySparseChangeIN,
758                                           PVRSRV_BRIDGE_OUT_DEVICEMEMHISTORYSPARSECHANGE *psDevicememHistorySparseChangeOUT,
759                                          CONNECTION_DATA *psConnection)
760 {
761         IMG_HANDLE hPMR = psDevicememHistorySparseChangeIN->hPMR;
762         PMR * psPMRInt = NULL;
763         IMG_CHAR *uiTextInt = NULL;
764         IMG_UINT32 *ui32AllocPageIndicesInt = NULL;
765         IMG_UINT32 *ui32FreePageIndicesInt = NULL;
766
767         IMG_UINT32 ui32NextOffset = 0;
768         IMG_BYTE   *pArrayArgsBuffer = NULL;
769 #if !defined(INTEGRITY_OS)
770         IMG_BOOL bHaveEnoughSpace = IMG_FALSE;
771 #endif
772
773         IMG_UINT32 ui32BufferSize = 
774                         (DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR)) +
775                         (psDevicememHistorySparseChangeIN->ui32AllocPageCount * sizeof(IMG_UINT32)) +
776                         (psDevicememHistorySparseChangeIN->ui32FreePageCount * sizeof(IMG_UINT32)) +
777                         0;
778
779
780
781
782
783         if (ui32BufferSize != 0)
784         {
785 #if !defined(INTEGRITY_OS)
786                 /* Try to use remainder of input buffer for copies if possible, word-aligned for safety. */
787                 IMG_UINT32 ui32InBufferOffset = PVR_ALIGN(sizeof(*psDevicememHistorySparseChangeIN), sizeof(unsigned long));
788                 IMG_UINT32 ui32InBufferExcessSize = ui32InBufferOffset >= PVRSRV_MAX_BRIDGE_IN_SIZE ? 0 :
789                         PVRSRV_MAX_BRIDGE_IN_SIZE - ui32InBufferOffset;
790
791                 bHaveEnoughSpace = ui32BufferSize <= ui32InBufferExcessSize;
792                 if (bHaveEnoughSpace)
793                 {
794                         IMG_BYTE *pInputBuffer = (IMG_BYTE *)psDevicememHistorySparseChangeIN;
795
796                         pArrayArgsBuffer = &pInputBuffer[ui32InBufferOffset];           }
797                 else
798 #endif
799                 {
800                         pArrayArgsBuffer = OSAllocMemNoStats(ui32BufferSize);
801
802                         if(!pArrayArgsBuffer)
803                         {
804                                 psDevicememHistorySparseChangeOUT->eError = PVRSRV_ERROR_OUT_OF_MEMORY;
805                                 goto DevicememHistorySparseChange_exit;
806                         }
807                 }
808         }
809
810         
811         {
812                 uiTextInt = (IMG_CHAR*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
813                 ui32NextOffset += DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR);
814         }
815
816                         /* Copy the data over */
817                         if (DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR) > 0)
818                         {
819                                 if ( OSCopyFromUser(NULL, uiTextInt, psDevicememHistorySparseChangeIN->puiText, DEVICEMEM_HISTORY_TEXT_BUFSZ * sizeof(IMG_CHAR)) != PVRSRV_OK )
820                                 {
821                                         psDevicememHistorySparseChangeOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
822
823                                         goto DevicememHistorySparseChange_exit;
824                                 }
825                         }
826         if (psDevicememHistorySparseChangeIN->ui32AllocPageCount != 0)
827         {
828                 ui32AllocPageIndicesInt = (IMG_UINT32*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
829                 ui32NextOffset += psDevicememHistorySparseChangeIN->ui32AllocPageCount * sizeof(IMG_UINT32);
830         }
831
832                         /* Copy the data over */
833                         if (psDevicememHistorySparseChangeIN->ui32AllocPageCount * sizeof(IMG_UINT32) > 0)
834                         {
835                                 if ( OSCopyFromUser(NULL, ui32AllocPageIndicesInt, psDevicememHistorySparseChangeIN->pui32AllocPageIndices, psDevicememHistorySparseChangeIN->ui32AllocPageCount * sizeof(IMG_UINT32)) != PVRSRV_OK )
836                                 {
837                                         psDevicememHistorySparseChangeOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
838
839                                         goto DevicememHistorySparseChange_exit;
840                                 }
841                         }
842         if (psDevicememHistorySparseChangeIN->ui32FreePageCount != 0)
843         {
844                 ui32FreePageIndicesInt = (IMG_UINT32*)(((IMG_UINT8 *)pArrayArgsBuffer) + ui32NextOffset);
845                 ui32NextOffset += psDevicememHistorySparseChangeIN->ui32FreePageCount * sizeof(IMG_UINT32);
846         }
847
848                         /* Copy the data over */
849                         if (psDevicememHistorySparseChangeIN->ui32FreePageCount * sizeof(IMG_UINT32) > 0)
850                         {
851                                 if ( OSCopyFromUser(NULL, ui32FreePageIndicesInt, psDevicememHistorySparseChangeIN->pui32FreePageIndices, psDevicememHistorySparseChangeIN->ui32FreePageCount * sizeof(IMG_UINT32)) != PVRSRV_OK )
852                                 {
853                                         psDevicememHistorySparseChangeOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
854
855                                         goto DevicememHistorySparseChange_exit;
856                                 }
857                         }
858
859         /* Lock over handle lookup. */
860         LockHandle();
861
862
863
864
865
866                                 {
867                                         /* Look up the address from the handle */
868                                         psDevicememHistorySparseChangeOUT->eError =
869                                                 PVRSRVLookupHandleUnlocked(psConnection->psHandleBase,
870                                                                                         (void **) &psPMRInt,
871                                                                                         hPMR,
872                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR,
873                                                                                         IMG_TRUE);
874                                         if(psDevicememHistorySparseChangeOUT->eError != PVRSRV_OK)
875                                         {
876                                                 UnlockHandle();
877                                                 goto DevicememHistorySparseChange_exit;
878                                         }
879                                 }
880         /* Release now we have looked up handles. */
881         UnlockHandle();
882
883         psDevicememHistorySparseChangeOUT->eError =
884                 DevicememHistorySparseChangeKM(
885                                         psPMRInt,
886                                         psDevicememHistorySparseChangeIN->uiOffset,
887                                         psDevicememHistorySparseChangeIN->sDevVAddr,
888                                         psDevicememHistorySparseChangeIN->uiSize,
889                                         uiTextInt,
890                                         psDevicememHistorySparseChangeIN->ui32Log2PageSize,
891                                         psDevicememHistorySparseChangeIN->ui32AllocPageCount,
892                                         ui32AllocPageIndicesInt,
893                                         psDevicememHistorySparseChangeIN->ui32FreePageCount,
894                                         ui32FreePageIndicesInt,
895                                         psDevicememHistorySparseChangeIN->ui32AllocationIndex,
896                                         &psDevicememHistorySparseChangeOUT->ui32AllocationIndexOut);
897
898
899
900
901 DevicememHistorySparseChange_exit:
902
903         /* Lock over handle lookup cleanup. */
904         LockHandle();
905
906
907
908
909
910
911                                 {
912                                         /* Unreference the previously looked up handle */
913                                                 if(psPMRInt)
914                                                 {
915                                                         PVRSRVReleaseHandleUnlocked(psConnection->psHandleBase,
916                                                                                         hPMR,
917                                                                                         PVRSRV_HANDLE_TYPE_PHYSMEM_PMR);
918                                                 }
919                                 }
920         /* Release now we have cleaned up look up handles. */
921         UnlockHandle();
922
923         /* Allocated space should be equal to the last updated offset */
924         PVR_ASSERT(ui32BufferSize == ui32NextOffset);
925
926 #if defined(INTEGRITY_OS)
927         if(pArrayArgsBuffer)
928 #else
929         if(!bHaveEnoughSpace && pArrayArgsBuffer)
930 #endif
931                 OSFreeMemNoStats(pArrayArgsBuffer);
932
933
934         return 0;
935 }
936
937
938
939
940 /* *************************************************************************** 
941  * Server bridge dispatch related glue 
942  */
943
944 static POS_LOCK pDEVICEMEMHISTORYBridgeLock;
945 static IMG_BOOL bUseLock = IMG_TRUE;
946 #endif /* SUPPORT_DEVICEMEMHISTORY_BRIDGE */
947
948 #if defined(SUPPORT_DEVICEMEMHISTORY_BRIDGE)
949 PVRSRV_ERROR InitDEVICEMEMHISTORYBridge(void);
950 PVRSRV_ERROR DeinitDEVICEMEMHISTORYBridge(void);
951
952 /*
953  * Register all DEVICEMEMHISTORY functions with services
954  */
955 PVRSRV_ERROR InitDEVICEMEMHISTORYBridge(void)
956 {
957         PVR_LOGR_IF_ERROR(OSLockCreate(&pDEVICEMEMHISTORYBridgeLock, LOCK_TYPE_PASSIVE), "OSLockCreate");
958
959         SetDispatchTableEntry(PVRSRV_BRIDGE_DEVICEMEMHISTORY, PVRSRV_BRIDGE_DEVICEMEMHISTORY_DEVICEMEMHISTORYMAP, PVRSRVBridgeDevicememHistoryMap,
960                                         pDEVICEMEMHISTORYBridgeLock, bUseLock);
961
962         SetDispatchTableEntry(PVRSRV_BRIDGE_DEVICEMEMHISTORY, PVRSRV_BRIDGE_DEVICEMEMHISTORY_DEVICEMEMHISTORYUNMAP, PVRSRVBridgeDevicememHistoryUnmap,
963                                         pDEVICEMEMHISTORYBridgeLock, bUseLock);
964
965         SetDispatchTableEntry(PVRSRV_BRIDGE_DEVICEMEMHISTORY, PVRSRV_BRIDGE_DEVICEMEMHISTORY_DEVICEMEMHISTORYMAPNEW, PVRSRVBridgeDevicememHistoryMapNew,
966                                         pDEVICEMEMHISTORYBridgeLock, bUseLock);
967
968         SetDispatchTableEntry(PVRSRV_BRIDGE_DEVICEMEMHISTORY, PVRSRV_BRIDGE_DEVICEMEMHISTORY_DEVICEMEMHISTORYUNMAPNEW, PVRSRVBridgeDevicememHistoryUnmapNew,
969                                         pDEVICEMEMHISTORYBridgeLock, bUseLock);
970
971         SetDispatchTableEntry(PVRSRV_BRIDGE_DEVICEMEMHISTORY, PVRSRV_BRIDGE_DEVICEMEMHISTORY_DEVICEMEMHISTORYMAPVRANGE, PVRSRVBridgeDevicememHistoryMapVRange,
972                                         pDEVICEMEMHISTORYBridgeLock, bUseLock);
973
974         SetDispatchTableEntry(PVRSRV_BRIDGE_DEVICEMEMHISTORY, PVRSRV_BRIDGE_DEVICEMEMHISTORY_DEVICEMEMHISTORYUNMAPVRANGE, PVRSRVBridgeDevicememHistoryUnmapVRange,
975                                         pDEVICEMEMHISTORYBridgeLock, bUseLock);
976
977         SetDispatchTableEntry(PVRSRV_BRIDGE_DEVICEMEMHISTORY, PVRSRV_BRIDGE_DEVICEMEMHISTORY_DEVICEMEMHISTORYSPARSECHANGE, PVRSRVBridgeDevicememHistorySparseChange,
978                                         pDEVICEMEMHISTORYBridgeLock, bUseLock);
979
980
981         return PVRSRV_OK;
982 }
983
984 /*
985  * Unregister all devicememhistory functions with services
986  */
987 PVRSRV_ERROR DeinitDEVICEMEMHISTORYBridge(void)
988 {
989         PVR_LOGR_IF_ERROR(OSLockDestroy(pDEVICEMEMHISTORYBridgeLock), "OSLockDestroy");
990         return PVRSRV_OK;
991 }
992 #else /* SUPPORT_DEVICEMEMHISTORY_BRIDGE */
993 /* This bridge is conditional on SUPPORT_DEVICEMEMHISTORY_BRIDGE - when not defined,
994  * do not populate the dispatch table with its functions
995  */
996 #define InitDEVICEMEMHISTORYBridge() \
997         PVRSRV_OK
998
999 #define DeinitDEVICEMEMHISTORYBridge() \
1000         PVRSRV_OK
1001
1002 #endif /* SUPPORT_DEVICEMEMHISTORY_BRIDGE */