2 * Copyright © 2014 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 AddrObject base class implementation.
31 ***************************************************************************************************
34 #include "addrinterface.h"
35 #include "addrobject.h"
38 ***************************************************************************************************
39 * AddrObject::AddrObject
42 * Constructor for the AddrObject class.
43 ***************************************************************************************************
45 AddrObject::AddrObject()
47 m_client
.handle
= NULL
;
48 m_client
.callbacks
.allocSysMem
= NULL
;
49 m_client
.callbacks
.freeSysMem
= NULL
;
50 m_client
.callbacks
.debugPrint
= NULL
;
54 ***************************************************************************************************
55 * AddrObject::AddrObject
58 * Constructor for the AddrObject class.
59 ***************************************************************************************************
61 AddrObject::AddrObject(const AddrClient
* pClient
)
67 ***************************************************************************************************
68 * AddrObject::~AddrObject
71 * Destructor for the AddrObject class.
72 ***************************************************************************************************
74 AddrObject::~AddrObject()
79 ***************************************************************************************************
80 * AddrObject::ClientAlloc
83 * Calls instanced allocSysMem inside AddrClient
84 ***************************************************************************************************
86 VOID
* AddrObject::ClientAlloc(
87 size_t objSize
, ///< [in] Size to allocate
88 const AddrClient
* pClient
) ///< [in] Client pointer
92 if (pClient
->callbacks
.allocSysMem
!= NULL
)
94 ADDR_ALLOCSYSMEM_INPUT allocInput
= {0};
96 allocInput
.size
= sizeof(ADDR_ALLOCSYSMEM_INPUT
);
97 allocInput
.flags
.value
= 0;
98 allocInput
.sizeInBytes
= static_cast<UINT_32
>(objSize
);
99 allocInput
.hClient
= pClient
->handle
;
101 pObjMem
= pClient
->callbacks
.allocSysMem(&allocInput
);
108 ***************************************************************************************************
109 * AddrObject::AddrMalloc
112 * A wrapper of ClientAlloc
113 ***************************************************************************************************
115 VOID
* AddrObject::AddrMalloc(
116 size_t objSize
) const ///< [in] Size to allocate
118 return ClientAlloc(objSize
, &m_client
);
122 ***************************************************************************************************
123 * AddrObject::ClientFree
126 * Calls freeSysMem inside AddrClient
127 ***************************************************************************************************
129 VOID
AddrObject::ClientFree(
130 VOID
* pObjMem
, ///< [in] User virtual address to free.
131 const AddrClient
* pClient
) ///< [in] Client pointer
133 if (pClient
->callbacks
.freeSysMem
!= NULL
)
137 ADDR_FREESYSMEM_INPUT freeInput
= {0};
139 freeInput
.size
= sizeof(ADDR_FREESYSMEM_INPUT
);
140 freeInput
.hClient
= pClient
->handle
;
141 freeInput
.pVirtAddr
= pObjMem
;
143 pClient
->callbacks
.freeSysMem(&freeInput
);
149 ***************************************************************************************************
150 * AddrObject::AddrFree
153 * A wrapper of ClientFree
154 ***************************************************************************************************
156 VOID
AddrObject::AddrFree(
157 VOID
* pObjMem
) const ///< [in] User virtual address to free.
159 ClientFree(pObjMem
, &m_client
);
163 ***************************************************************************************************
164 * AddrObject::operator new
167 * Allocates memory needed for AddrObject object. (with ADDR_CLIENT_HANDLE)
170 * Returns NULL if unsuccessful.
171 ***************************************************************************************************
173 VOID
* AddrObject::operator new(
174 size_t objSize
, ///< [in] Size to allocate
175 const AddrClient
* pClient
) ///< [in] Client pointer
177 return ClientAlloc(objSize
, pClient
);
182 ***************************************************************************************************
183 * AddrObject::operator delete
186 * Frees AddrObject object memory.
187 ***************************************************************************************************
189 VOID
AddrObject::operator delete(
190 VOID
* pObjMem
, ///< [in] User virtual address to free.
191 const AddrClient
* pClient
) ///< [in] Client handle
193 ClientFree(pObjMem
, pClient
);
197 ***************************************************************************************************
198 * AddrObject::operator delete
201 * Frees AddrObject object memory.
202 ***************************************************************************************************
204 VOID
AddrObject::operator delete(
205 VOID
* pObjMem
) ///< [in] User virtual address to free.
207 AddrObject
* pObj
= static_cast<AddrObject
*>(pObjMem
);
208 ClientFree(pObjMem
, &pObj
->m_client
);
212 ***************************************************************************************************
213 * AddrObject::DebugPrint
216 * Print debug message
220 ***************************************************************************************************
222 VOID
AddrObject::DebugPrint(
223 const CHAR
* pDebugString
, ///< [in] Debug string
227 if (m_client
.callbacks
.debugPrint
!= NULL
)
231 va_start(ap
, pDebugString
);
233 ADDR_DEBUGPRINT_INPUT debugPrintInput
= {0};
235 debugPrintInput
.size
= sizeof(ADDR_DEBUGPRINT_INPUT
);
236 debugPrintInput
.pDebugString
= const_cast<CHAR
*>(pDebugString
);
237 debugPrintInput
.hClient
= m_client
.handle
;
238 va_copy(debugPrintInput
.ap
, ap
);
240 m_client
.callbacks
.debugPrint(&debugPrintInput
);