2 * Copyright © 2007-2019 Advanced Micro Devices, Inc.
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:
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.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
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
186 ****************************************************************************************************
187 * Object::operator delete
190 * Frees Object object memory.
191 ****************************************************************************************************
193 VOID
Object::operator delete(
194 VOID
* pObjMem
) ///< [in] User virtual address to free.
196 Object
* pObj
= static_cast<Object
*>(pObjMem
);
197 ClientFree(pObjMem
, &pObj
->m_client
);
201 ****************************************************************************************************
205 * Print debug message
209 ****************************************************************************************************
211 VOID
Object::DebugPrint(
212 const CHAR
* pDebugString
, ///< [in] Debug string
217 if (m_client
.callbacks
.debugPrint
!= NULL
)
221 va_start(ap
, pDebugString
);
223 ADDR_DEBUGPRINT_INPUT debugPrintInput
= {0};
225 debugPrintInput
.size
= sizeof(ADDR_DEBUGPRINT_INPUT
);
226 debugPrintInput
.pDebugString
= const_cast<CHAR
*>(pDebugString
);
227 debugPrintInput
.hClient
= m_client
.handle
;
228 va_copy(debugPrintInput
.ap
, ap
);
230 m_client
.callbacks
.debugPrint(&debugPrintInput
);