2021-10-13 21:30:46 +08:00
/*
* Copyright ( C ) 2021 Intel Corporation
*
* SPDX - License - Identifier : MIT
*
*/
# include "shared/source/debug_settings/debug_settings_manager.h"
2021-12-10 20:55:55 +08:00
# include "shared/source/os_interface/linux/cache_info.h"
2021-12-01 19:45:29 +08:00
# include "shared/source/os_interface/linux/ioctl_helper.h"
2021-10-13 21:30:46 +08:00
2021-12-08 18:10:27 +08:00
# include "third_party/uapi/drm/i915_drm.h"
2021-10-13 21:30:46 +08:00
namespace NEO {
2021-12-22 22:25:53 +08:00
uint32_t IoctlHelperUpstream : : createGemExt ( Drm * drm , const std : : vector < MemoryClassInstance > & memClassInstances , size_t allocSize , uint32_t & handle ) {
uint32_t regionsSize = static_cast < uint32_t > ( memClassInstances . size ( ) ) ;
2021-12-28 21:19:45 +08:00
std : : vector < drm_i915_gem_memory_class_instance > regions ( regionsSize ) ;
2021-12-22 22:25:53 +08:00
for ( uint32_t i = 0 ; i < regionsSize ; i + + ) {
2021-12-28 21:19:45 +08:00
regions [ i ] . memory_class = memClassInstances [ i ] . memoryClass ;
regions [ i ] . memory_instance = memClassInstances [ i ] . memoryInstance ;
2021-12-22 22:25:53 +08:00
}
2021-12-14 17:46:01 +08:00
drm_i915_gem_create_ext_memory_regions memRegions { } ;
2021-12-22 22:25:53 +08:00
memRegions . num_regions = regionsSize ;
2021-12-28 21:19:45 +08:00
memRegions . regions = reinterpret_cast < uintptr_t > ( regions . data ( ) ) ;
2021-10-13 21:30:46 +08:00
memRegions . base . name = I915_GEM_CREATE_EXT_MEMORY_REGIONS ;
drm_i915_gem_create_ext createExt { } ;
createExt . size = allocSize ;
createExt . extensions = reinterpret_cast < uintptr_t > ( & memRegions ) ;
printDebugString ( DebugManager . flags . PrintBOCreateDestroyResult . get ( ) , stdout , " Performing GEM_CREATE_EXT with { size: %lu " ,
allocSize ) ;
if ( DebugManager . flags . PrintBOCreateDestroyResult . get ( ) ) {
2021-12-22 22:25:53 +08:00
for ( uint32_t i = 0 ; i < regionsSize ; i + + ) {
2021-12-28 21:19:45 +08:00
auto region = regions [ i ] ;
2021-10-13 21:30:46 +08:00
printDebugString ( DebugManager . flags . PrintBOCreateDestroyResult . get ( ) , stdout , " , memory class: %d, memory instance: %d " ,
region . memory_class , region . memory_instance ) ;
}
printDebugString ( DebugManager . flags . PrintBOCreateDestroyResult . get ( ) , stdout , " %s " , " } \n " ) ;
}
auto ret = ioctl ( drm , DRM_IOCTL_I915_GEM_CREATE_EXT , & createExt ) ;
printDebugString ( DebugManager . flags . PrintBOCreateDestroyResult . get ( ) , stdout , " GEM_CREATE_EXT with EXT_MEMORY_REGIONS has returned: %d BO-%u with size: %lu \n " , ret , createExt . handle , createExt . size ) ;
handle = createExt . handle ;
return ret ;
}
2021-12-22 22:25:53 +08:00
std : : vector < MemoryRegion > IoctlHelperUpstream : : translateToMemoryRegions ( const std : : vector < uint8_t > & regionInfo ) {
auto * data = reinterpret_cast < const drm_i915_query_memory_regions * > ( regionInfo . data ( ) ) ;
auto memRegions = std : : vector < MemoryRegion > ( data - > num_regions ) ;
2021-12-17 21:26:04 +08:00
for ( uint32_t i = 0 ; i < data - > num_regions ; i + + ) {
memRegions [ i ] . probedSize = data - > regions [ i ] . probed_size ;
memRegions [ i ] . unallocatedSize = data - > regions [ i ] . unallocated_size ;
memRegions [ i ] . region . memoryClass = data - > regions [ i ] . region . memory_class ;
memRegions [ i ] . region . memoryInstance = data - > regions [ i ] . region . memory_instance ;
}
return memRegions ;
2021-10-13 21:30:46 +08:00
}
2021-12-10 20:55:55 +08:00
CacheRegion IoctlHelperUpstream : : closAlloc ( Drm * drm ) {
return CacheRegion : : None ;
}
uint16_t IoctlHelperUpstream : : closAllocWays ( Drm * drm , CacheRegion closIndex , uint16_t cacheLevel , uint16_t numWays ) {
return 0 ;
}
CacheRegion IoctlHelperUpstream : : closFree ( Drm * drm , CacheRegion closIndex ) {
return CacheRegion : : None ;
}
2021-12-14 17:46:01 +08:00
int IoctlHelperUpstream : : waitUserFence ( Drm * drm , uint32_t ctxId , uint64_t address ,
uint64_t value , uint32_t dataWidth , int64_t timeout , uint16_t flags ) {
return 0 ;
}
uint32_t IoctlHelperUpstream : : getHwConfigIoctlVal ( ) {
return DRM_I915_QUERY_HWCONFIG_TABLE ;
}
2021-12-14 22:09:19 +08:00
uint32_t IoctlHelperUpstream : : getAtomicAdvise ( bool isNonAtomic ) {
return 0 ;
}
uint32_t IoctlHelperUpstream : : getPreferredLocationAdvise ( ) {
return 0 ;
}
bool IoctlHelperUpstream : : setVmBoAdvise ( Drm * drm , int32_t handle , uint32_t attribute , void * region ) {
return true ;
}
2021-12-14 20:41:38 +08:00
uint32_t IoctlHelperUpstream : : getDirectSubmissionFlag ( ) {
return 0u ;
}
2021-10-13 21:30:46 +08:00
} // namespace NEO