amdgpu/addrlib: Use namespaces
[mesa.git] / src / amd / addrlib / core / addrobject.cpp
1 /*
2 * Copyright © 2014 Advanced Micro Devices, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
17 * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 */
26
27 /**
28 ****************************************************************************************************
29 * @file Object.cpp
30 * @brief Contains the Object base class implementation.
31 ****************************************************************************************************
32 */
33
34 #include "addrinterface.h"
35 #include "addrobject.h"
36
37 namespace Addr
38 {
39
40 /**
41 ****************************************************************************************************
42 * Object::Object
43 *
44 * @brief
45 * Constructor for the Object class.
46 ****************************************************************************************************
47 */
48 Object::Object()
49 {
50 m_client.handle = NULL;
51 m_client.callbacks.allocSysMem = NULL;
52 m_client.callbacks.freeSysMem = NULL;
53 m_client.callbacks.debugPrint = NULL;
54 }
55
56 /**
57 ****************************************************************************************************
58 * Object::Object
59 *
60 * @brief
61 * Constructor for the Object class.
62 ****************************************************************************************************
63 */
64 Object::Object(const Client* pClient)
65 {
66 m_client = *pClient;
67 }
68
69 /**
70 ****************************************************************************************************
71 * Object::~Object
72 *
73 * @brief
74 * Destructor for the Object class.
75 ****************************************************************************************************
76 */
77 Object::~Object()
78 {
79 }
80
81 /**
82 ****************************************************************************************************
83 * Object::ClientAlloc
84 *
85 * @brief
86 * Calls instanced allocSysMem inside Client
87 ****************************************************************************************************
88 */
89 VOID* Object::ClientAlloc(
90 size_t objSize, ///< [in] Size to allocate
91 const Client* pClient) ///< [in] Client pointer
92 {
93 VOID* pObjMem = NULL;
94
95 if (pClient->callbacks.allocSysMem != NULL)
96 {
97 ADDR_ALLOCSYSMEM_INPUT allocInput = {0};
98
99 allocInput.size = sizeof(ADDR_ALLOCSYSMEM_INPUT);
100 allocInput.flags.value = 0;
101 allocInput.sizeInBytes = static_cast<UINT_32>(objSize);
102 allocInput.hClient = pClient->handle;
103
104 pObjMem = pClient->callbacks.allocSysMem(&allocInput);
105 }
106
107 return pObjMem;
108 }
109
110 /**
111 ****************************************************************************************************
112 * Object::Alloc
113 *
114 * @brief
115 * A wrapper of ClientAlloc
116 ****************************************************************************************************
117 */
118 VOID* Object::Alloc(
119 size_t objSize) const ///< [in] Size to allocate
120 {
121 return ClientAlloc(objSize, &m_client);
122 }
123
124 /**
125 ****************************************************************************************************
126 * Object::ClientFree
127 *
128 * @brief
129 * Calls freeSysMem inside Client
130 ****************************************************************************************************
131 */
132 VOID Object::ClientFree(
133 VOID* pObjMem, ///< [in] User virtual address to free.
134 const Client* pClient) ///< [in] Client pointer
135 {
136 if (pClient->callbacks.freeSysMem != NULL)
137 {
138 if (pObjMem != NULL)
139 {
140 ADDR_FREESYSMEM_INPUT freeInput = {0};
141
142 freeInput.size = sizeof(ADDR_FREESYSMEM_INPUT);
143 freeInput.hClient = pClient->handle;
144 freeInput.pVirtAddr = pObjMem;
145
146 pClient->callbacks.freeSysMem(&freeInput);
147 }
148 }
149 }
150
151 /**
152 ****************************************************************************************************
153 * Object::Free
154 *
155 * @brief
156 * A wrapper of ClientFree
157 ****************************************************************************************************
158 */
159 VOID Object::Free(
160 VOID* pObjMem) const ///< [in] User virtual address to free.
161 {
162 ClientFree(pObjMem, &m_client);
163 }
164
165 /**
166 ****************************************************************************************************
167 * Object::operator new
168 *
169 * @brief
170 * Allocates memory needed for Object object. (with ADDR_CLIENT_HANDLE)
171 *
172 * @return
173 * Returns NULL if unsuccessful.
174 ****************************************************************************************************
175 */
176 VOID* Object::operator new(
177 size_t objSize, ///< [in] Size to allocate
178 const Client* pClient) ///< [in] Client pointer
179 {
180 return ClientAlloc(objSize, pClient);
181 }
182
183
184 /**
185 ****************************************************************************************************
186 * Object::operator delete
187 *
188 * @brief
189 * Frees Object object memory.
190 ****************************************************************************************************
191 */
192 VOID Object::operator delete(
193 VOID* pObjMem, ///< [in] User virtual address to free.
194 const Client* pClient) ///< [in] Client handle
195 {
196 ClientFree(pObjMem, pClient);
197 }
198
199 /**
200 ****************************************************************************************************
201 * Object::operator delete
202 *
203 * @brief
204 * Frees Object object memory.
205 ****************************************************************************************************
206 */
207 VOID Object::operator delete(
208 VOID* pObjMem) ///< [in] User virtual address to free.
209 {
210 Object* pObj = static_cast<Object*>(pObjMem);
211 ClientFree(pObjMem, &pObj->m_client);
212 }
213
214 /**
215 ****************************************************************************************************
216 * Object::DebugPrint
217 *
218 * @brief
219 * Print debug message
220 *
221 * @return
222 * N/A
223 ****************************************************************************************************
224 */
225 VOID Object::DebugPrint(
226 const CHAR* pDebugString, ///< [in] Debug string
227 ...) const
228 {
229 #if DEBUG
230 if (m_client.callbacks.debugPrint != NULL)
231 {
232 va_list ap;
233
234 va_start(ap, pDebugString);
235
236 ADDR_DEBUGPRINT_INPUT debugPrintInput = {0};
237
238 debugPrintInput.size = sizeof(ADDR_DEBUGPRINT_INPUT);
239 debugPrintInput.pDebugString = const_cast<CHAR*>(pDebugString);
240 debugPrintInput.hClient = m_client.handle;
241 va_copy(debugPrintInput.ap, ap);
242
243 m_client.callbacks.debugPrint(&debugPrintInput);
244
245 va_end(ap);
246 }
247 #endif
248 }
249
250 } // Addr