SWDEV-558848 - Move DRM calls to thunk for better abstraction (#1912)

* SWDEV-558848 - Move DRM calls to thunk for better abstraction

* Use thunk device handle instead of drm inside agent

* Update IPC functions with new thunk calls

* create hsaKmtHandleImport interface to support ipc

* Reset metadata inside hsaKmtMemHandleFree

* remove whitespaces and NULL usage

* Add thunk apis to libhsakmt.ver

* Add comments to new structs in thunk

* Minor fixes to declarations

* resolve merge conflicts in amd_kfd_driver

---------

Co-authored-by: Rahul Manocha <rmanocha@amd.com>
This commit is contained in:
Rahul Manocha
2026-01-27 08:56:57 -08:00
committed by GitHub
parent 3a479a25ad
commit 324a864bc4
13 changed files with 576 additions and 248 deletions
@@ -1254,10 +1254,10 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtAisReadWriteFile(
/**
* Check if the HSA KMT Model is enabled
*
*
* Arguments:
* @enable (OUT) - true if the HSA KMT Model is enabled, false otherwise
*
*
* Return:
* HSAKMT_STATUS_ERROR - failed
* HSAKMT_STATUS_SUCCESS - successfully complete
@@ -1269,6 +1269,59 @@ hsaKmtModelEnabled(
bool* enable // OUT
);
/**
* Experimental APIs to abstract DRM calls to thunk
*/
HSAKMT_STATUS
HSAKMTAPI
hsaKmtHandleImport(
const HsaExternalHandleDesc* ImportDesc,
HsaHandleImportResult* ImportResult,
HsaHandleImportFlags* Flags
);
HSAKMT_STATUS
HSAKMTAPI
hsaKmtMemoryVaMap(
HsaMemoryObjectHandle Handle,
HSAuint64 offset,
HSAuint64 size,
HSAuint64 addr,
HsaMemoryMapFlags flags
);
HSAKMT_STATUS
HSAKMTAPI
hsaKmtMemoryVaUnmap(
HsaMemoryObjectHandle Handle,
HSAuint64 offset,
HSAuint64 size,
HSAuint64 addr
);
HSAKMT_STATUS
HSAKMTAPI
hsaKmtMemoryCpuMap(
HsaMemoryObjectHandle Handle,
void** out_cpu_ptr
);
HSAKMT_STATUS
HSAKMTAPI
hsaKmtMemHandleFree(
HsaMemoryObjectHandle Handle
);
HSAKMT_STATUS
HSAKMTAPI
hsaKmtMemoryGetCpuAddr(
HsaAMDGPUDeviceHandle DeviceHandle,
HsaMemoryObjectHandle MemoryHandle,
HSAint32* fd, // OUT
HSAuint64* cpu_addr // OUT
);
#ifdef __cplusplus
} //extern "C"
#endif
@@ -355,6 +355,7 @@ typedef struct _HsaNodeProperties
HSAuint32 LuidLowPart; // Windows Locally Unique Identifier Low 4 bytes
HSAuint32 LuidHighPart; // Windows Locally Unique Identifier High 4 bytes
HSAuint64 WallClockKHz; // Wall Clock Frequency in KHz
} HsaNodeProperties;
@@ -1053,7 +1054,7 @@ typedef enum _HSA_EVENTID_MEMORYFLAGS
typedef struct _HsaAccessAttributeFailure
{
unsigned int NotPresent : 1; // Page not present or supervisor privilege
unsigned int NotPresent : 1; // Page not present or supervisor privilege
unsigned int ReadOnly : 1; // Write access to a read-only page
unsigned int NoExecute : 1; // Execute access to a page marked NX
unsigned int GpuAccess : 1; // Host access only
@@ -1527,6 +1528,49 @@ typedef enum _HsaAisFlags {
HSA_AIS_WRITE= 0x2
} HsaAisFlags;
/* memory object handle used for translating drm BO object*/
typedef struct _HsaMemoryObjectHandle* HsaMemoryObjectHandle;
/* Access Permissions for memory mapping */
typedef enum _HsaMemoryMapFlags {
HSA_MEMORY_ACCESS_NONE = 0,
HSA_MEMORY_ACCESS_RO = 1,
HSA_MEMORY_ACCESS_WO = 2,
HSA_MEMORY_ACCESS_RW = 3
} HsaMemoryMapFlags;
/* Handle type for import */
typedef enum _HsaExternalHandleType{
HSA_EXTERNAL_HANDLE_GEM_FLINK_NAME = 0,
HSA_EXTERNAL_HANDLE_KMS = 1,
HSA_EXTERNAL_HANDLE_DMA_BUF = 2
} HsaExternalHandleType;
typedef struct _HsaExternalHandleDesc {
HsaAMDGPUDeviceHandle device_handle; // GPU device handle (used for import only)
HSAint32 fd; // dmabuf fd
HsaExternalHandleType type; // handle type
HSAuint32 metadata; // Used for IPC handles
} HsaExternalHandleDesc;
typedef struct _HsaHandleImportResult {
HsaMemoryObjectHandle buf_handle; // Thunk buffer object handle
HSAuint64 alloc_size; // allocation size for import
HSAuint32 metadata; // Used for IPC handles
} HsaHandleImportResult;
typedef struct _HsaMemoryExportResult {
HSAint32 fd; // dmabuf fd
} HsaMemoryExportResult;
typedef struct _HsaHandleImportFlags {
struct {
unsigned int IPCHandle : 1; // Handle type is IPC
unsigned int SysMem : 1; // Memory type is System Memory
unsigned int UpdateMetadata : 1; // Update metadata with IPC handle
unsigned int Reserved : 29;
} ui32;
} HsaHandleImportFlags;
#ifdef __cplusplus
} //extern "C"