1 /*************************************************************************/ /*!
2 @Title Linked list shared functions implementation
3 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
4 @Description Implementation of the list iterators for types shared among
5 more than one file in the services code.
6 @License Dual MIT/GPLv2
8 The contents of this file are subject to the MIT license as set out below.
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:
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
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.
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.
32 This License is also included in this distribution in the file called
33 "MIT-COPYING".
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 #include "lists.h"
44 #include "services_headers.h"
46 /*===================================================================
47 LIST ITERATOR FUNCTIONS USED IN MORE THAN ONE FILE (those used just
48 once are implemented locally).
49 ===================================================================*/
51 IMPLEMENT_LIST_ANY_VA(BM_HEAP)
52 IMPLEMENT_LIST_ANY_2(BM_HEAP, PVRSRV_ERROR, PVRSRV_OK)
53 IMPLEMENT_LIST_ANY_VA_2(BM_HEAP, PVRSRV_ERROR, PVRSRV_OK)
54 IMPLEMENT_LIST_FOR_EACH_VA(BM_HEAP)
55 IMPLEMENT_LIST_REMOVE(BM_HEAP)
56 IMPLEMENT_LIST_INSERT(BM_HEAP)
58 IMPLEMENT_LIST_ANY_VA(BM_CONTEXT)
59 IMPLEMENT_LIST_ANY_VA_2(BM_CONTEXT, IMG_HANDLE, IMG_NULL)
60 IMPLEMENT_LIST_ANY_VA_2(BM_CONTEXT, PVRSRV_ERROR, PVRSRV_OK)
61 IMPLEMENT_LIST_FOR_EACH(BM_CONTEXT)
62 IMPLEMENT_LIST_REMOVE(BM_CONTEXT)
63 IMPLEMENT_LIST_INSERT(BM_CONTEXT)
65 IMPLEMENT_LIST_ANY_2(PVRSRV_DEVICE_NODE, PVRSRV_ERROR, PVRSRV_OK)
66 IMPLEMENT_LIST_ANY_VA(PVRSRV_DEVICE_NODE)
67 IMPLEMENT_LIST_ANY_VA_2(PVRSRV_DEVICE_NODE, PVRSRV_ERROR, PVRSRV_OK)
68 IMPLEMENT_LIST_FOR_EACH(PVRSRV_DEVICE_NODE)
69 IMPLEMENT_LIST_FOR_EACH_VA(PVRSRV_DEVICE_NODE)
70 IMPLEMENT_LIST_INSERT(PVRSRV_DEVICE_NODE)
71 IMPLEMENT_LIST_REMOVE(PVRSRV_DEVICE_NODE)
73 IMPLEMENT_LIST_ANY_VA(PVRSRV_POWER_DEV)
74 IMPLEMENT_LIST_ANY_VA_2(PVRSRV_POWER_DEV, PVRSRV_ERROR, PVRSRV_OK)
75 IMPLEMENT_LIST_INSERT(PVRSRV_POWER_DEV)
76 IMPLEMENT_LIST_REMOVE(PVRSRV_POWER_DEV)
78 IMPLEMENT_LIST_ANY_2(PVRSRV_KERNEL_SYNC_INFO, PVRSRV_ERROR, PVRSRV_OK);
79 IMPLEMENT_LIST_INSERT(PVRSRV_KERNEL_SYNC_INFO)
80 IMPLEMENT_LIST_REMOVE(PVRSRV_KERNEL_SYNC_INFO)
82 /*===================================================================
83 BELOW ARE IMPLEMENTED SOME COMMON CALLBACKS USED IN DIFFERENT FILES
84 ===================================================================*/
87 /*!
88 ******************************************************************************
89 @Function MatchDeviceKM_AnyVaCb
90 @Description Matchs a device node with an id and optionally a class.
92 @Input psDeviceNode - Pointer to the device node.
93 @Input va - Variable argument list, with te following values:
94 # ui32DevIndex - Index of de device to match.
95 # bIgnoreClass - Flag indicating if there's
96 no need to check the device class.
97 # eDevClass - Device class, ONLY present if
98 bIgnoreClass was IMG_FALSE.
100 @Return The pointer to the device node if it matchs, IMG_NULL
101 otherwise.
102 ******************************************************************************/
103 IMG_VOID* MatchDeviceKM_AnyVaCb(PVRSRV_DEVICE_NODE* psDeviceNode, va_list va)
104 {
105 IMG_UINT32 ui32DevIndex;
106 IMG_BOOL bIgnoreClass;
107 PVRSRV_DEVICE_CLASS eDevClass;
109 ui32DevIndex = va_arg(va, IMG_UINT32);
110 bIgnoreClass = va_arg(va, IMG_BOOL);
111 if (!bIgnoreClass)
112 {
113 eDevClass = va_arg(va, PVRSRV_DEVICE_CLASS);
114 }
115 else
116 {
117 /*this value will never be used, since the short circuit evaluation
118 of the first clause will stop because bIgnoreClass is true, but the
119 compiler complains if it's not initialized.*/
120 eDevClass = PVRSRV_DEVICE_CLASS_FORCE_I32;
121 }
123 if ((bIgnoreClass || psDeviceNode->sDevId.eDeviceClass == eDevClass) &&
124 psDeviceNode->sDevId.ui32DeviceIndex == ui32DevIndex)
125 {
126 return psDeviceNode;
127 }
128 return IMG_NULL;
129 }
131 /*!
132 ******************************************************************************
134 @Function MatchPowerDeviceIndex_AnyVaCb
136 @Description
137 Matches a power device with its device index.
139 @Input va : variable argument list with:
140 ui32DeviceIndex : device index
142 @Return the pointer to the device it matched, IMG_NULL otherwise.
144 ******************************************************************************/
145 IMG_VOID* MatchPowerDeviceIndex_AnyVaCb(PVRSRV_POWER_DEV *psPowerDev, va_list va)
146 {
147 IMG_UINT32 ui32DeviceIndex;
149 ui32DeviceIndex = va_arg(va, IMG_UINT32);
151 if (psPowerDev->ui32DeviceIndex == ui32DeviceIndex)
152 {
153 return psPowerDev;
154 }
155 else
156 {
157 return IMG_NULL;
158 }
159 }