2
************************************************************************************************************************
4
* Copyright (C) 2007-2022 Advanced Micro Devices, Inc. All rights reserved.
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the "Software"),
8
* to deal in the Software without restriction, including without limitation
9
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
* and/or sell copies of the Software, and to permit persons to whom the
11
* Software is furnished to do so, subject to the following conditions:
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
* OTHER DEALINGS IN THE SOFTWARE
24
***********************************************************************************************************************/
28
****************************************************************************************************
29
* @file addrobject.cpp
30
* @brief Contains the Object base class implementation.
31
****************************************************************************************************
34
#include "addrinterface.h"
35
#include "addrobject.h"
41
****************************************************************************************************
45
* Constructor for the Object class.
46
****************************************************************************************************
50
m_client.handle = NULL;
51
m_client.callbacks.allocSysMem = NULL;
52
m_client.callbacks.freeSysMem = NULL;
53
m_client.callbacks.debugPrint = NULL;
57
****************************************************************************************************
61
* Constructor for the Object class.
62
****************************************************************************************************
64
Object::Object(const Client* pClient)
70
****************************************************************************************************
74
* Destructor for the Object class.
75
****************************************************************************************************
82
****************************************************************************************************
86
* Calls instanced allocSysMem inside Client
87
****************************************************************************************************
89
VOID* Object::ClientAlloc(
90
size_t objSize, ///< [in] Size to allocate
91
const Client* pClient) ///< [in] Client pointer
95
if (pClient->callbacks.allocSysMem != NULL)
97
ADDR_ALLOCSYSMEM_INPUT allocInput = {0};
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;
104
pObjMem = pClient->callbacks.allocSysMem(&allocInput);
111
****************************************************************************************************
115
* A wrapper of ClientAlloc
116
****************************************************************************************************
119
size_t objSize ///< [in] Size to allocate
122
return ClientAlloc(objSize, &m_client);;
126
****************************************************************************************************
130
* Calls freeSysMem inside Client
131
****************************************************************************************************
133
VOID Object::ClientFree(
134
VOID* pObjMem, ///< [in] User virtual address to free.
135
const Client* pClient) ///< [in] Client pointer
137
if (pClient->callbacks.freeSysMem != NULL)
141
ADDR_FREESYSMEM_INPUT freeInput = {0};
143
freeInput.size = sizeof(ADDR_FREESYSMEM_INPUT);
144
freeInput.hClient = pClient->handle;
145
freeInput.pVirtAddr = pObjMem;
147
pClient->callbacks.freeSysMem(&freeInput);
153
****************************************************************************************************
157
* A wrapper of ClientFree
158
****************************************************************************************************
161
VOID* pObjMem ///< [in] User virtual address to free.
164
ClientFree(pObjMem, &m_client);
168
****************************************************************************************************
169
* Object::operator new
172
* Placement new operator. (with pre-allocated memory pointer)
175
* Returns pre-allocated memory pointer.
176
****************************************************************************************************
178
VOID* Object::operator new(
179
size_t objSize, ///< [in] Size to allocate
180
VOID* pMem ///< [in] Pre-allocated pointer
187
****************************************************************************************************
188
* Object::operator delete
191
* Frees Object object memory.
192
****************************************************************************************************
194
VOID Object::operator delete(
195
VOID* pObjMem) ///< [in] User virtual address to free.
197
Object* pObj = static_cast<Object*>(pObjMem);
198
ClientFree(pObjMem, &pObj->m_client);
202
****************************************************************************************************
206
* Print debug message
210
****************************************************************************************************
212
VOID Object::DebugPrint(
213
const CHAR* pDebugString, ///< [in] Debug string
218
if (m_client.callbacks.debugPrint != NULL)
222
va_start(ap, pDebugString);
224
ADDR_DEBUGPRINT_INPUT debugPrintInput = {0};
226
debugPrintInput.size = sizeof(ADDR_DEBUGPRINT_INPUT);
227
debugPrintInput.pDebugString = const_cast<CHAR*>(pDebugString);
228
debugPrintInput.hClient = m_client.handle;
229
va_copy(debugPrintInput.ap, ap);
231
m_client.callbacks.debugPrint(&debugPrintInput);
234
va_end(debugPrintInput.ap);