2017-12-21 07:45:38 +08:00
/*
2024-12-31 21:48:34 +08:00
* Copyright ( C ) 2018 - 2025 Intel Corporation
2017-12-21 07:45:38 +08:00
*
2018-09-18 15:11:08 +08:00
* SPDX - License - Identifier : MIT
2017-12-21 07:45:38 +08:00
*
*/
2020-02-24 05:44:01 +08:00
# include "shared/source/os_interface/linux/drm_buffer_object.h"
2019-02-27 18:39:32 +08:00
2025-02-11 22:31:01 +08:00
# include "shared/source/command_stream/command_stream_receiver.h"
2022-11-22 21:53:59 +08:00
# include "shared/source/command_stream/task_count_helper.h"
2024-08-30 06:35:24 +08:00
# include "shared/source/execution_environment/execution_environment.h"
2022-12-07 19:51:44 +08:00
# include "shared/source/execution_environment/root_device_environment.h"
2022-11-18 22:38:56 +08:00
# include "shared/source/gmm_helper/gmm_helper.h"
2020-05-06 18:37:15 +08:00
# include "shared/source/helpers/aligned_memory.h"
2020-02-24 05:44:01 +08:00
# include "shared/source/helpers/debug_helpers.h"
# include "shared/source/os_interface/linux/drm_memory_manager.h"
2021-06-17 22:14:05 +08:00
# include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
2020-05-06 18:37:15 +08:00
# include "shared/source/os_interface/linux/drm_neo.h"
2022-05-18 01:16:13 +08:00
# include "shared/source/os_interface/linux/drm_wrappers.h"
2022-01-20 02:14:10 +08:00
# include "shared/source/os_interface/linux/ioctl_helper.h"
2021-09-03 19:40:34 +08:00
# include "shared/source/os_interface/linux/os_context_linux.h"
2020-08-11 20:00:41 +08:00
# include "shared/source/os_interface/os_context.h"
2017-12-21 07:45:38 +08:00
# include <errno.h>
2020-05-06 18:37:15 +08:00
# include <string.h>
2019-02-27 18:39:32 +08:00
# include <sys/ioctl.h>
2017-12-21 07:45:38 +08:00
# include <unistd.h>
2019-03-26 18:59:46 +08:00
namespace NEO {
2017-12-21 07:45:38 +08:00
2023-02-01 23:58:22 +08:00
BufferObjectHandleWrapper BufferObjectHandleWrapper : : acquireSharedOwnership ( ) {
if ( controlBlock = = nullptr ) {
controlBlock = new ControlBlock { 1 , 0 } ;
}
std : : lock_guard lock { controlBlock - > blockMutex } ;
controlBlock - > refCount + + ;
2024-09-10 08:41:25 +08:00
return BufferObjectHandleWrapper { boHandle , rootDeviceIndex , Ownership : : strong , controlBlock } ;
2023-02-01 23:58:22 +08:00
}
BufferObjectHandleWrapper BufferObjectHandleWrapper : : acquireWeakOwnership ( ) {
if ( controlBlock = = nullptr ) {
controlBlock = new ControlBlock { 1 , 0 } ;
}
std : : lock_guard lock { controlBlock - > blockMutex } ;
controlBlock - > weakRefCount + + ;
2024-09-10 08:41:25 +08:00
return BufferObjectHandleWrapper { boHandle , rootDeviceIndex , Ownership : : weak , controlBlock } ;
2023-02-01 23:58:22 +08:00
}
BufferObjectHandleWrapper : : ~ BufferObjectHandleWrapper ( ) {
if ( controlBlock = = nullptr ) {
return ;
}
std : : unique_lock lock { controlBlock - > blockMutex } ;
2023-12-19 18:17:17 +08:00
if ( ownership = = Ownership : : strong ) {
2023-02-01 23:58:22 +08:00
controlBlock - > refCount - - ;
} else {
controlBlock - > weakRefCount - - ;
}
if ( controlBlock - > refCount = = 0 & & controlBlock - > weakRefCount = = 0 ) {
lock . unlock ( ) ;
delete controlBlock ;
2024-08-29 15:52:13 +08:00
controlBlock = nullptr ;
2023-02-01 23:58:22 +08:00
}
}
bool BufferObjectHandleWrapper : : canCloseBoHandle ( ) {
if ( controlBlock = = nullptr ) {
return true ;
}
std : : lock_guard lock { controlBlock - > blockMutex } ;
return controlBlock - > refCount = = 1 ;
}
2023-04-26 18:36:25 +08:00
BufferObject : : BufferObject ( uint32_t rootDeviceIndex , Drm * drm , uint64_t patIndex , int handle , size_t size , size_t maxOsContextCount )
2024-09-10 08:41:25 +08:00
: BufferObject ( rootDeviceIndex , drm , patIndex , BufferObjectHandleWrapper { handle , rootDeviceIndex } , size , maxOsContextCount ) { }
2023-02-01 23:58:22 +08:00
2023-04-26 18:36:25 +08:00
BufferObject : : BufferObject ( uint32_t rootDeviceIndex , Drm * drm , uint64_t patIndex , BufferObjectHandleWrapper & & handle , size_t size , size_t maxOsContextCount )
2024-03-25 18:39:49 +08:00
: drm ( drm ) , handle ( std : : move ( handle ) ) , size ( size ) , refCount ( 1 ) , rootDeviceIndex ( rootDeviceIndex ) {
2023-02-01 23:58:22 +08:00
2022-06-21 23:41:40 +08:00
auto ioctlHelper = drm - > getIoctlHelper ( ) ;
2023-12-13 17:05:31 +08:00
this - > tilingMode = ioctlHelper - > getDrmParamValue ( DrmParam : : tilingNone ) ;
2018-02-27 06:23:43 +08:00
this - > lockedAddress = nullptr ;
2022-04-20 03:24:19 +08:00
this - > patIndex = patIndex ;
2020-08-11 20:00:41 +08:00
perContextVmsUsed = drm - > isPerContextVMRequired ( ) ;
2021-11-09 05:42:07 +08:00
requiresExplicitResidency = drm - > hasPageFaultSupport ( ) ;
2020-08-11 20:00:41 +08:00
if ( perContextVmsUsed ) {
2020-08-20 19:20:20 +08:00
bindInfo . resize ( maxOsContextCount ) ;
2020-08-11 20:00:41 +08:00
for ( auto & iter : bindInfo ) {
iter . fill ( false ) ;
}
} else {
bindInfo . resize ( 1 ) ;
bindInfo [ 0 ] . fill ( false ) ;
}
2017-12-21 07:45:38 +08:00
}
uint32_t BufferObject : : getRefCount ( ) const {
return this - > refCount . load ( ) ;
}
2022-05-11 22:59:23 +08:00
void BufferObject : : setAddress ( uint64_t address ) {
auto gmmHelper = drm - > getRootDeviceEnvironment ( ) . getGmmHelper ( ) ;
this - > gpuAddress = gmmHelper - > canonize ( address ) ;
}
2017-12-21 07:45:38 +08:00
bool BufferObject : : close ( ) {
2023-02-01 23:58:22 +08:00
if ( ! this - > handle . canCloseBoHandle ( ) ) {
2023-11-30 16:32:25 +08:00
PRINT_DEBUG_STRING ( debugManager . flags . PrintBOCreateDestroyResult . get ( ) , stdout , " Skipped closing BO-%d - more shared users! \n " , this - > handle . getBoHandle ( ) ) ;
2023-02-01 23:58:22 +08:00
return true ;
}
2022-05-25 00:13:02 +08:00
GemClose close { } ;
2023-02-01 23:58:22 +08:00
close . handle = this - > handle . getBoHandle ( ) ;
2024-03-22 18:57:14 +08:00
close . userptr = this - > userptr ;
2017-12-21 07:45:38 +08:00
2023-11-30 16:32:25 +08:00
PRINT_DEBUG_STRING ( debugManager . flags . PrintBOCreateDestroyResult . get ( ) , stdout , " Calling gem close on handle: BO-%d \n " , this - > handle . getBoHandle ( ) ) ;
2020-08-13 16:10:48 +08:00
2022-06-29 01:56:14 +08:00
auto ioctlHelper = this - > drm - > getIoctlHelper ( ) ;
2023-12-12 16:48:32 +08:00
int ret = ioctlHelper - > ioctl ( DrmIoctl : : gemClose , & close ) ;
2017-12-21 07:45:38 +08:00
if ( ret ! = 0 ) {
int err = errno ;
2024-08-30 06:35:24 +08:00
CREATE_DEBUG_STRING ( str , " ioctl(GEM_CLOSE) failed with %d. errno=%d(%s) \n " , ret , err , strerror ( err ) ) ;
drm - > getRootDeviceEnvironment ( ) . executionEnvironment . setErrorDescription ( std : : string ( str . get ( ) ) ) ;
PRINT_DEBUG_STRING ( debugManager . flags . PrintDebugMessages . get ( ) , stderr , str . get ( ) ) ;
2017-12-20 21:28:42 +08:00
DEBUG_BREAK_IF ( true ) ;
2024-08-30 06:35:24 +08:00
2017-12-21 07:45:38 +08:00
return false ;
}
2023-02-01 23:58:22 +08:00
this - > handle . setBoHandle ( - 1 ) ;
2017-12-21 07:45:38 +08:00
return true ;
}
int BufferObject : : wait ( int64_t timeoutNs ) {
2021-04-29 16:58:16 +08:00
if ( this - > drm - > isVmBindAvailable ( ) ) {
2021-02-16 23:25:26 +08:00
return 0 ;
}
2023-02-01 23:58:22 +08:00
int ret = this - > drm - > waitHandle ( this - > handle . getBoHandle ( ) , - 1 ) ;
2017-12-21 07:45:38 +08:00
UNRECOVERABLE_IF ( ret ! = 0 ) ;
return ret ;
}
bool BufferObject : : setTiling ( uint32_t mode , uint32_t stride ) {
2022-01-21 02:13:07 +08:00
if ( this - > tilingMode = = mode ) {
2017-12-21 07:45:38 +08:00
return true ;
}
2022-05-16 22:41:00 +08:00
GemSetTiling setTiling { } ;
2023-02-01 23:58:22 +08:00
setTiling . handle = this - > handle . getBoHandle ( ) ;
2022-05-16 22:41:00 +08:00
setTiling . tilingMode = mode ;
2022-05-12 22:04:41 +08:00
setTiling . stride = stride ;
2022-06-29 01:56:14 +08:00
auto ioctlHelper = this - > drm - > getIoctlHelper ( ) ;
2017-12-21 07:45:38 +08:00
2023-09-12 22:57:55 +08:00
if ( ! ioctlHelper - > setGemTiling ( & setTiling ) ) {
2017-12-21 07:45:38 +08:00
return false ;
}
2022-05-16 22:41:00 +08:00
this - > tilingMode = setTiling . tilingMode ;
2017-12-21 07:45:38 +08:00
2022-05-16 22:41:00 +08:00
return setTiling . tilingMode = = mode ;
2018-02-27 06:23:43 +08:00
}
2017-12-21 07:45:38 +08:00
2020-10-15 14:48:58 +08:00
uint32_t BufferObject : : getOsContextId ( OsContext * osContext ) {
return perContextVmsUsed ? osContext - > getContextId ( ) : 0u ;
}
2022-05-11 23:06:01 +08:00
void BufferObject : : fillExecObject ( ExecObject & execObject , OsContext * osContext , uint32_t vmHandleId , uint32_t drmContextId ) {
2022-02-15 23:50:04 +08:00
const auto osContextId = drm - > isPerContextVMRequired ( ) ? osContext - > getContextId ( ) : 0 ;
2022-05-11 23:06:01 +08:00
auto ioctlHelper = drm - > getIoctlHelper ( ) ;
2023-02-01 23:58:22 +08:00
ioctlHelper - > fillExecObject ( execObject , this - > handle . getBoHandle ( ) , this - > gpuAddress , drmContextId , this - > bindInfo [ osContextId ] [ vmHandleId ] , this - > isMarkedForCapture ( ) ) ;
2017-12-21 07:45:38 +08:00
}
2022-01-20 02:14:10 +08:00
int BufferObject : : exec ( uint32_t used , size_t startOffset , unsigned int flags , bool requiresCoherency , OsContext * osContext , uint32_t vmHandleId , uint32_t drmContextId ,
2022-11-22 21:53:59 +08:00
BufferObject * const residency [ ] , size_t residencyCount , ExecObject * execObjectsStorage , uint64_t completionGpuAddress , TaskCountType completionValue ) {
2020-05-06 18:37:15 +08:00
for ( size_t i = 0 ; i < residencyCount ; i + + ) {
2020-08-11 20:00:41 +08:00
residency [ i ] - > fillExecObject ( execObjectsStorage [ i ] , osContext , vmHandleId , drmContextId ) ;
2020-05-06 18:37:15 +08:00
}
2020-08-11 20:00:41 +08:00
this - > fillExecObject ( execObjectsStorage [ residencyCount ] , osContext , vmHandleId , drmContextId ) ;
2022-05-12 23:56:50 +08:00
auto ioctlHelper = drm - > getIoctlHelper ( ) ;
2020-05-06 18:37:15 +08:00
2022-05-12 23:56:50 +08:00
ExecBuffer execbuf { } ;
ioctlHelper - > fillExecBuffer ( execbuf , reinterpret_cast < uintptr_t > ( execObjectsStorage ) ,
static_cast < uint32_t > ( residencyCount + 1u ) , static_cast < uint32_t > ( startOffset ) ,
alignUp ( used , 8 ) , flags , drmContextId ) ;
2020-05-06 18:37:15 +08:00
2023-11-30 16:32:25 +08:00
if ( debugManager . flags . PrintExecutionBuffer . get ( ) ) {
PRINT_DEBUG_STRING ( debugManager . flags . PrintExecutionBuffer . get ( ) , stdout , " Exec called with drmVmId = %u \n " ,
2021-09-03 19:40:34 +08:00
static_cast < const OsContextLinux * > ( osContext ) - > getDrmVmIds ( ) . size ( ) ? static_cast < const OsContextLinux * > ( osContext ) - > getDrmVmIds ( ) [ vmHandleId ] : 0 ) ;
2020-08-13 16:10:48 +08:00
printExecutionBuffer ( execbuf , residencyCount , execObjectsStorage , residency ) ;
2020-06-09 16:00:59 +08:00
}
2022-06-30 00:49:29 +08:00
int ret = ioctlHelper - > execBuffer ( & execbuf , completionGpuAddress , completionValue ) ;
2021-05-27 17:41:28 +08:00
2021-06-17 22:14:05 +08:00
if ( ret ! = 0 ) {
2022-10-01 17:39:49 +08:00
int err = this - > drm - > getErrno ( ) ;
if ( err = = EOPNOTSUPP ) {
2023-11-30 16:32:25 +08:00
PRINT_DEBUG_STRING ( debugManager . flags . PrintDebugMessages . get ( ) , stderr , " ioctl(I915_GEM_EXECBUFFER2) failed with %d. errno=%d(%s) \n " , ret , err , strerror ( err ) ) ;
2022-10-01 17:39:49 +08:00
return err ;
}
evictUnusedAllocations ( false , true ) ;
ret = ioctlHelper - > execBuffer ( & execbuf , completionGpuAddress , completionValue ) ;
}
if ( ret ! = 0 ) {
const auto status = evictUnusedAllocations ( true , true ) ;
2023-12-13 17:17:24 +08:00
if ( status = = MemoryOperationsStatus : : gpuHangDetectedDuringOperation ) {
2023-11-30 16:32:25 +08:00
PRINT_DEBUG_STRING ( debugManager . flags . PrintDebugMessages . get ( ) , stderr , " Error! GPU hang detected in BufferObject::exec(). Returning %d \n " , gpuHangDetected ) ;
2022-10-01 17:39:49 +08:00
return gpuHangDetected ;
}
ret = ioctlHelper - > execBuffer ( & execbuf , completionGpuAddress , completionValue ) ;
2021-06-17 22:14:05 +08:00
}
2020-05-06 18:37:15 +08:00
if ( ret = = 0 ) {
return 0 ;
}
int err = this - > drm - > getErrno ( ) ;
2023-11-30 16:32:25 +08:00
PRINT_DEBUG_STRING ( debugManager . flags . PrintDebugMessages . get ( ) , stderr , " ioctl(I915_GEM_EXECBUFFER2) failed with %d. errno=%d(%s) \n " , ret , err , strerror ( err ) ) ;
2020-05-06 18:37:15 +08:00
return err ;
}
2022-04-13 18:42:27 +08:00
MemoryOperationsStatus BufferObject : : evictUnusedAllocations ( bool waitForCompletion , bool isLockNeeded ) {
return static_cast < DrmMemoryOperationsHandler * > ( this - > drm - > getRootDeviceEnvironment ( ) . memoryOperationsInterface . get ( ) ) - > evictUnusedAllocations ( waitForCompletion , isLockNeeded ) ;
}
2022-02-04 23:28:20 +08:00
void BufferObject : : printBOBindingResult ( OsContext * osContext , uint32_t vmHandleId , bool bind , int retVal ) {
if ( retVal = = 0 ) {
if ( bind ) {
2023-11-30 16:32:25 +08:00
PRINT_DEBUG_STRING ( debugManager . flags . PrintBOBindingResult . get ( ) , stdout , " bind BO-%d to VM %u, drmVmId = %u, range: %llx - %llx, size: %lld, result: %d \n " ,
2023-02-01 23:58:22 +08:00
this - > handle . getBoHandle ( ) , vmHandleId , static_cast < const OsContextLinux * > ( osContext ) - > getDrmVmIds ( ) . size ( ) ? static_cast < const OsContextLinux * > ( osContext ) - > getDrmVmIds ( ) [ vmHandleId ] : 0 , this - > gpuAddress , ptrOffset ( this - > gpuAddress , this - > size ) , this - > size , retVal ) ;
2022-02-04 23:28:20 +08:00
} else {
2023-11-30 16:32:25 +08:00
PRINT_DEBUG_STRING ( debugManager . flags . PrintBOBindingResult . get ( ) , stdout , " unbind BO-%d from VM %u, drmVmId = %u, range: %llx - %llx, size: %lld, result: %d \n " ,
2023-02-01 23:58:22 +08:00
this - > handle . getBoHandle ( ) , vmHandleId , static_cast < const OsContextLinux * > ( osContext ) - > getDrmVmIds ( ) . size ( ) ? static_cast < const OsContextLinux * > ( osContext ) - > getDrmVmIds ( ) [ vmHandleId ] : 0 , this - > gpuAddress , ptrOffset ( this - > gpuAddress , this - > size ) , this - > size , retVal ) ;
2022-02-04 23:28:20 +08:00
}
} else {
auto err = this - > drm - > getErrno ( ) ;
if ( bind ) {
2023-11-30 16:32:25 +08:00
PRINT_DEBUG_STRING ( debugManager . flags . PrintBOBindingResult . get ( ) , stderr , " bind BO-%d to VM %u, drmVmId = %u, range: %llx - %llx, size: %lld, result: %d, errno: %d(%s) \n " ,
2023-02-01 23:58:22 +08:00
this - > handle . getBoHandle ( ) , vmHandleId , static_cast < const OsContextLinux * > ( osContext ) - > getDrmVmIds ( ) . size ( ) ? static_cast < const OsContextLinux * > ( osContext ) - > getDrmVmIds ( ) [ vmHandleId ] : 0 , this - > gpuAddress , ptrOffset ( this - > gpuAddress , this - > size ) , this - > size , retVal , err , strerror ( err ) ) ;
2022-02-04 23:28:20 +08:00
} else {
2023-11-30 16:32:25 +08:00
PRINT_DEBUG_STRING ( debugManager . flags . PrintBOBindingResult . get ( ) , stderr , " unbind BO-%d from VM %u, drmVmId = %u, range: %llx - %llx, size: %lld, result: %d, errno: %d(%s) \n " ,
2023-02-01 23:58:22 +08:00
this - > handle . getBoHandle ( ) , vmHandleId , static_cast < const OsContextLinux * > ( osContext ) - > getDrmVmIds ( ) . size ( ) ? static_cast < const OsContextLinux * > ( osContext ) - > getDrmVmIds ( ) [ vmHandleId ] : 0 , this - > gpuAddress , ptrOffset ( this - > gpuAddress , this - > size ) , this - > size , retVal , err , strerror ( err ) ) ;
2022-02-04 23:28:20 +08:00
}
}
}
2025-02-05 14:40:13 +08:00
int BufferObject : : bind ( OsContext * osContext , uint32_t vmHandleId , const bool forcePagingFence ) {
2020-10-16 18:59:27 +08:00
int retVal = 0 ;
2020-10-15 14:48:58 +08:00
auto contextId = getOsContextId ( osContext ) ;
2020-08-11 20:00:41 +08:00
if ( ! this - > bindInfo [ contextId ] [ vmHandleId ] ) {
2025-02-05 14:40:13 +08:00
retVal = this - > drm - > bindBufferObject ( osContext , vmHandleId , this , forcePagingFence ) ;
2023-11-30 16:32:25 +08:00
if ( debugManager . flags . PrintBOBindingResult . get ( ) ) {
2022-02-04 23:28:20 +08:00
printBOBindingResult ( osContext , vmHandleId , true , retVal ) ;
}
2020-10-16 18:59:27 +08:00
if ( ! retVal ) {
this - > bindInfo [ contextId ] [ vmHandleId ] = true ;
}
2020-07-28 13:48:41 +08:00
}
2020-10-16 18:59:27 +08:00
return retVal ;
2020-07-02 17:49:46 +08:00
}
2020-10-16 18:59:27 +08:00
int BufferObject : : unbind ( OsContext * osContext , uint32_t vmHandleId ) {
int retVal = 0 ;
2020-10-15 14:48:58 +08:00
auto contextId = getOsContextId ( osContext ) ;
2020-08-11 20:00:41 +08:00
if ( this - > bindInfo [ contextId ] [ vmHandleId ] ) {
2020-10-16 18:59:27 +08:00
retVal = this - > drm - > unbindBufferObject ( osContext , vmHandleId , this ) ;
2023-11-30 16:32:25 +08:00
if ( debugManager . flags . PrintBOBindingResult . get ( ) ) {
2022-02-04 23:28:20 +08:00
printBOBindingResult ( osContext , vmHandleId , false , retVal ) ;
}
2020-10-16 18:59:27 +08:00
if ( ! retVal ) {
this - > bindInfo [ contextId ] [ vmHandleId ] = false ;
}
2020-07-28 13:48:41 +08:00
}
2020-10-16 18:59:27 +08:00
return retVal ;
2020-07-02 17:49:46 +08:00
}
2022-05-12 23:56:50 +08:00
void BufferObject : : printExecutionBuffer ( ExecBuffer & execbuf , const size_t & residencyCount , ExecObject * execObjectsStorage , BufferObject * const residency [ ] ) {
2022-05-11 23:06:01 +08:00
auto ioctlHelper = drm - > getIoctlHelper ( ) ;
2020-08-13 16:10:48 +08:00
std : : stringstream logger ;
2022-05-12 23:56:50 +08:00
ioctlHelper - > logExecBuffer ( execbuf , logger ) ;
2020-08-13 16:10:48 +08:00
size_t i ;
for ( i = 0 ; i < residencyCount ; i + + ) {
2022-05-11 23:06:01 +08:00
ioctlHelper - > logExecObject ( execObjectsStorage [ i ] , logger , residency [ i ] - > peekSize ( ) ) ;
2020-06-09 16:00:59 +08:00
}
2022-05-11 23:06:01 +08:00
logger < < " Command " ;
ioctlHelper - > logExecObject ( execObjectsStorage [ i ] , logger , this - > peekSize ( ) ) ;
2020-08-13 16:10:48 +08:00
2021-05-27 17:41:28 +08:00
printf ( " %s \n " , logger . str ( ) . c_str ( ) ) ;
2020-06-09 16:00:59 +08:00
}
2025-02-05 14:40:13 +08:00
int bindBOsWithinContext ( BufferObject * const boToPin [ ] , size_t numberOfBos , OsContext * osContext , uint32_t vmHandleId , const bool forcePagingFence ) {
2020-09-30 14:29:12 +08:00
auto retVal = 0 ;
2020-10-15 14:48:58 +08:00
2020-10-16 19:46:25 +08:00
for ( auto drmIterator = 0u ; drmIterator < osContext - > getDeviceBitfield ( ) . size ( ) ; drmIterator + + ) {
if ( osContext - > getDeviceBitfield ( ) . test ( drmIterator ) ) {
for ( size_t i = 0 ; i < numberOfBos ; i + + ) {
2025-02-05 14:40:13 +08:00
retVal | = boToPin [ i ] - > bind ( osContext , drmIterator , forcePagingFence ) ;
2020-09-30 14:29:12 +08:00
}
}
2020-10-16 19:46:25 +08:00
}
return retVal ;
}
int BufferObject : : pin ( BufferObject * const boToPin [ ] , size_t numberOfBos , OsContext * osContext , uint32_t vmHandleId , uint32_t drmContextId ) {
auto retVal = 0 ;
2020-11-20 04:43:01 +08:00
if ( this - > drm - > isVmBindAvailable ( ) ) {
2025-03-07 01:04:43 +08:00
auto lock = static_cast < DrmMemoryOperationsHandler * > ( this - > drm - > getRootDeviceEnvironment ( ) . memoryOperationsInterface . get ( ) ) - > lockHandlerIfUsed ( ) ;
2025-02-05 14:40:13 +08:00
retVal = bindBOsWithinContext ( boToPin , numberOfBos , osContext , vmHandleId , false ) ;
2020-10-16 19:46:25 +08:00
} else {
2022-05-11 23:06:01 +08:00
StackVec < ExecObject , maxFragmentsCount + 1 > execObject ( numberOfBos + 1 ) ;
2022-01-20 02:14:10 +08:00
retVal = this - > exec ( 4u , 0u , 0u , false , osContext , vmHandleId , drmContextId , boToPin , numberOfBos , & execObject [ 0 ] , 0 , 0 ) ;
2020-10-16 19:46:25 +08:00
}
return retVal ;
}
int BufferObject : : validateHostPtr ( BufferObject * const boToPin [ ] , size_t numberOfBos , OsContext * osContext , uint32_t vmHandleId , uint32_t drmContextId ) {
auto retVal = 0 ;
2021-05-13 22:28:51 +08:00
if ( this - > drm - > isVmBindAvailable ( ) ) {
2025-03-07 01:04:43 +08:00
auto lock = static_cast < DrmMemoryOperationsHandler * > ( this - > drm - > getRootDeviceEnvironment ( ) . memoryOperationsInterface . get ( ) ) - > lockHandlerIfUsed ( ) ;
2021-08-04 19:56:36 +08:00
for ( size_t i = 0 ; i < numberOfBos ; i + + ) {
2025-02-05 14:40:13 +08:00
retVal = boToPin [ i ] - > bind ( osContext , vmHandleId , false ) ;
2021-08-04 19:56:36 +08:00
if ( retVal ) {
break ;
}
}
2020-09-30 14:29:12 +08:00
} else {
2025-04-07 21:54:45 +08:00
StackVec < std : : unique_lock < NEO : : CommandStreamReceiver : : MutexType > , 1 > locks { } ;
2025-02-17 23:13:21 +08:00
if ( this - > drm - > getRootDeviceEnvironment ( ) . executionEnvironment . memoryManager . get ( ) ) {
2025-02-11 22:31:01 +08:00
const auto & engines = this - > drm - > getRootDeviceEnvironment ( ) . executionEnvironment . memoryManager - > getRegisteredEngines ( osContext - > getRootDeviceIndex ( ) ) ;
2025-02-17 23:13:21 +08:00
for ( const auto & engine : engines ) {
if ( engine . osContext - > isDirectSubmissionLightActive ( ) ) {
2025-04-07 21:54:45 +08:00
locks . push_back ( engine . commandStreamReceiver - > obtainUniqueOwnership ( ) ) ;
engine . commandStreamReceiver - > stopDirectSubmission ( false , false ) ;
2025-02-17 23:13:21 +08:00
}
2025-02-11 22:31:01 +08:00
}
}
2022-05-11 23:06:01 +08:00
StackVec < ExecObject , maxFragmentsCount + 1 > execObject ( numberOfBos + 1 ) ;
2022-01-20 02:14:10 +08:00
retVal = this - > exec ( 4u , 0u , 0u , false , osContext , vmHandleId , drmContextId , boToPin , numberOfBos , & execObject [ 0 ] , 0 , 0 ) ;
2020-09-30 14:29:12 +08:00
}
2020-10-15 14:48:58 +08:00
2020-09-30 14:29:12 +08:00
return retVal ;
2017-12-21 07:45:38 +08:00
}
2018-02-28 19:09:48 +08:00
2020-09-14 19:28:47 +08:00
void BufferObject : : addBindExtHandle ( uint32_t handle ) {
bindExtHandles . push_back ( handle ) ;
}
2019-03-26 18:59:46 +08:00
} // namespace NEO