55 *
66 */
77
8- #include " drm_neo.h"
8+ #include " shared/source/os_interface/linux/drm_debug.h"
9+
10+ #include " shared/source/helpers/string.h"
11+ #include " shared/source/os_interface/linux/drm_neo.h"
12+
13+ #include < string>
14+ #include < utility>
915
1016namespace NEO {
1117
1218bool Drm::registerResourceClasses () {
13- return false ;
19+ for (auto classNameUUID : classNamesToUuid) {
20+ auto className = classNameUUID.first ;
21+ auto uuid = classNameUUID.second ;
22+
23+ const auto result = ioctlHelper->registerStringClassUuid (this , uuid, (uintptr_t )className, strnlen_s (className, 100 ));
24+ if (result.retVal != 0 ) {
25+ return false ;
26+ }
27+
28+ classHandles.push_back (result.handle );
29+ }
30+ return true ;
1431}
1532
1633uint32_t Drm::registerResource (ResourceClass classType, const void *data, size_t size) {
17- return 0 ;
34+ if (classHandles.size () < static_cast <uint32_t >(classType)) {
35+ return 0 ;
36+ }
37+
38+ std::string uuid;
39+ if (classType == NEO::Drm::ResourceClass::Elf) {
40+ uuid = generateElfUUID (data);
41+ } else {
42+ uuid = generateUUID ();
43+ }
44+
45+ const auto uuidClass = classHandles[static_cast <uint32_t >(classType)];
46+ const auto ptr = size > 0 ? (uintptr_t )data : 0 ;
47+ const auto result = ioctlHelper->registerUuid (this , uuid, uuidClass, ptr, size);
48+
49+ PRINT_DEBUGGER_INFO_LOG (" PRELIM_DRM_IOCTL_I915_UUID_REGISTER: classType = %d, uuid = %s, data = %p, handle = %lu, ret = %d\n " , (int )classType, std::string (uuid, 36 ).c_str (), ptr, result.handle , result.retVal );
50+ DEBUG_BREAK_IF (result.retVal != 0 );
51+
52+ return result.handle ;
1853}
1954
2055uint32_t Drm::registerIsaCookie (uint32_t isaHandle) {
21- return 0 ;
56+ auto uuid = generateUUID ();
57+
58+ const auto result = ioctlHelper->registerUuid (this , uuid, isaHandle, 0 , 0 );
59+
60+ PRINT_DEBUGGER_INFO_LOG (" PRELIM_DRM_IOCTL_I915_UUID_REGISTER: isa handle = %lu, uuid = %s, data = %p, handle = %lu, ret = %d\n " , isaHandle, std::string (uuid, 36 ).c_str (), 0 , result.handle , result.retVal );
61+ DEBUG_BREAK_IF (result.retVal != 0 );
62+
63+ return result.handle ;
2264}
2365
2466void Drm::unregisterResource (uint32_t handle) {
67+ PRINT_DEBUGGER_INFO_LOG (" PRELIM_DRM_IOCTL_I915_UUID_UNREGISTER: handle = %lu\n " , handle);
68+ [[maybe_unused]] const auto ret = ioctlHelper->unregisterUuid (this , handle);
69+ DEBUG_BREAK_IF (ret != 0 );
2570}
2671
2772std::string Drm::generateUUID () {
@@ -40,12 +85,37 @@ std::string Drm::generateUUID() {
4085}
4186
4287std::string Drm::generateElfUUID (const void *data) {
43- return generateUUID ();
88+ std::string elf_class_uuid = classNamesToUuid[static_cast <uint32_t >(Drm::ResourceClass::Elf)].second ;
89+ std::string UUID1st = elf_class_uuid.substr (0 , 18 );
90+
91+ const char uuidString[] = " %s-%04" SCNx64 " -%012" SCNx64;
92+ char buffer[36 + 1 ] = " 00000000-0000-0000-0000-000000000000" ;
93+
94+ uint64_t parts[2 ] = {0 , 0 };
95+ parts[0 ] = reinterpret_cast <uintptr_t >(data) & 0xFFFFFFFFFFFF ;
96+ parts[1 ] = (reinterpret_cast <uintptr_t >(data) & 0xFFFF000000000000 ) >> 48 ;
97+ snprintf (buffer, sizeof (buffer), uuidString, UUID1st.c_str (), parts[1 ], parts[0 ]);
98+
99+ return std::string (buffer, 36 );
100+ }
101+
102+ void Drm::checkContextDebugSupport () {
103+ contextDebugSupported = ioctlHelper->isContextDebugSupported (this );
104+ }
105+
106+ void Drm::setContextDebugFlag (uint32_t drmContextId) {
107+ [[maybe_unused]] const auto retVal = ioctlHelper->setContextDebugFlag (this , drmContextId);
108+ DEBUG_BREAK_IF (retVal != 0 && contextDebugSupported);
44109}
45110
46- void Drm::checkContextDebugSupport () {}
47- void Drm::setContextDebugFlag (uint32_t drmContextId) {}
48- uint32_t Drm::notifyFirstCommandQueueCreated () { return 0 ; }
49- void Drm::notifyLastCommandQueueDestroyed (uint32_t handle) {}
111+ uint32_t Drm::notifyFirstCommandQueueCreated () {
112+ const auto result = ioctlHelper->registerStringClassUuid (this , uuidL0CommandQueueHash, (uintptr_t )uuidL0CommandQueueName, strnlen_s (uuidL0CommandQueueName, 100 ));
113+ DEBUG_BREAK_IF (result.retVal );
114+ return result.handle ;
115+ }
116+
117+ void Drm::notifyLastCommandQueueDestroyed (uint32_t handle) {
118+ unregisterResource (handle);
119+ }
50120
51121} // namespace NEO
0 commit comments