diff --git a/projects/rocr-runtime/src/libhsakmt.h b/projects/rocr-runtime/src/libhsakmt.h index f455699c6d..9c7047caa2 100644 --- a/projects/rocr-runtime/src/libhsakmt.h +++ b/projects/rocr-runtime/src/libhsakmt.h @@ -38,6 +38,8 @@ extern bool hsakmt_forked; extern pthread_mutex_t hsakmt_mutex; extern bool is_dgpu; +extern HsaVersionInfo kfd_version_info; + extern int force_asic; extern char force_asic_name[HSA_PUBLIC_NAME_SIZE]; extern struct hsa_gfxip_table force_asic_entry; @@ -54,6 +56,10 @@ extern struct hsa_gfxip_table force_asic_entry; #define CHECK_KFD_OPEN() \ do { if (kfd_open_count == 0 || hsakmt_forked) return HSAKMT_STATUS_KERNEL_IO_CHANNEL_NOT_OPENED; } while (0) +#define CHECK_KFD_MINOR_VERSION(minor) \ + do { if ((minor) > kfd_version_info.KernelInterfaceMinorVersion)\ + return HSAKMT_STATUS_NOT_SUPPORTED; } while (0) + extern int PAGE_SIZE; extern int PAGE_SHIFT; @@ -145,6 +151,8 @@ struct hsa_gfxip_table { enum asic_family_type asic_family; // Device family id }; +HSAKMT_STATUS init_kfd_version(void); + #define IS_SOC15(chip) ((chip) >= CHIP_VEGA10) HSAKMT_STATUS validate_nodeid(uint32_t nodeid, uint32_t *gpu_id); diff --git a/projects/rocr-runtime/src/openclose.c b/projects/rocr-runtime/src/openclose.c index 784ee51f2a..55ba5f23f2 100644 --- a/projects/rocr-runtime/src/openclose.c +++ b/projects/rocr-runtime/src/openclose.c @@ -196,6 +196,10 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtOpenKFD(void) init_page_size(); + result = init_kfd_version(); + if (result != HSAKMT_STATUS_SUCCESS) + goto kfd_version_failed; + result = topology_sysfs_get_system_props(&sys_props); if (result != HSAKMT_STATUS_SUCCESS) goto topology_sysfs_failed; @@ -238,6 +242,7 @@ init_doorbell_failed: fmm_destroy_process_apertures(); init_process_aperture_failed: topology_sysfs_failed: +kfd_version_failed: close(fd); open_failed: pthread_mutex_unlock(&hsakmt_mutex); diff --git a/projects/rocr-runtime/src/version.c b/projects/rocr-runtime/src/version.c index 2de79d0b08..34e51e0811 100644 --- a/projects/rocr-runtime/src/version.c +++ b/projects/rocr-runtime/src/version.c @@ -28,17 +28,29 @@ #include #include "linux/kfd_ioctl.h" +HsaVersionInfo kfd_version_info; + HSAKMT_STATUS HSAKMTAPI hsaKmtGetVersion(HsaVersionInfo *VersionInfo) { CHECK_KFD_OPEN(); + *VersionInfo = kfd_version_info; + + return HSAKMT_STATUS_SUCCESS; +} + +HSAKMT_STATUS init_kfd_version(void) +{ struct kfd_ioctl_get_version_args args = {0}; if (kmtIoctl(kfd_fd, AMDKFD_IOC_GET_VERSION, &args) == -1) return HSAKMT_STATUS_ERROR; - VersionInfo->KernelInterfaceMajorVersion = args.major_version; - VersionInfo->KernelInterfaceMinorVersion = args.minor_version; + kfd_version_info.KernelInterfaceMajorVersion = args.major_version; + kfd_version_info.KernelInterfaceMinorVersion = args.minor_version; + + if (args.major_version != 1) + return HSAKMT_STATUS_DRIVER_MISMATCH; return HSAKMT_STATUS_SUCCESS; }