Introduce the GPU debug operations interface. For ROCm-GDB to extend the GNU Debugger's ability to inspect the AMD GPU instruction set, provide the necessary interface to allow the debugger to HW debug-mode set and query exceptions per HSA queue, process or device. The runtime_enable interface coordinates exception handling with the HSA runtime. Usage is available in the kern docs at uapi/linux/kfd_ioctl.h.
Showing the changes to include/uapi (1 of 2 files). Show all
Unified · Split
| @@ -110,6 +110,32 @@ struct kfd_ioctl_get_available_memory_args { · 109 unmodified lines | ||
| 110 | 110 | __u32 pad; |
| 111 | 111 | }; |
| 112 | 112 | |
| 113 | +struct kfd_dbg_device_info_entry { | |
| 114 | + __u64 exception_status; | |
| 115 | + __u64 lds_base; | |
| 116 | + __u64 lds_limit; | |
| 117 | + __u64 scratch_base; | |
| 118 | + __u64 scratch_limit; | |
| 119 | + __u64 gpuvm_base; | |
| 120 | + __u64 gpuvm_limit; | |
| 121 | + __u32 gpu_id; | |
| 122 | + __u32 location_id; | |
| 123 | + __u32 vendor_id; | |
| 124 | + __u32 device_id; | |
| 125 | + __u32 revision_id; | |
| 126 | + __u32 subsystem_vendor_id; | |
| 127 | + __u32 subsystem_device_id; | |
| 128 | + __u32 fw_version; | |
| 129 | + __u32 gfx_target_version; | |
| 130 | + __u32 simd_count; | |
| 131 | + __u32 max_waves_per_simd; | |
| 132 | + __u32 array_count; | |
| 133 | + __u32 simd_arrays_per_engine; | |
| 134 | + __u32 num_xcc; | |
| 135 | + __u32 capability; | |
| 136 | + __u32 debug_prop; | |
| 137 | +}; | |
| 138 | + | |
| 113 | 139 | /* For kfd_ioctl_set_memory_policy_args.default_policy and alternate_policy */ |
| 114 | 140 | #define KFD_IOC_CACHE_POLICY_COHERENT 0 |
| 115 | 141 | #define KFD_IOC_CACHE_POLICY_NONCOHERENT 1 |
| @@ -773,6 +799,640 @@ struct kfd_ioctl_set_xnack_mode_args { · 657 unmodified lines | ||
| 773 | 799 | __s32 xnack_enabled; |
| 774 | 800 | }; |
| 775 | 801 | |
| 802 | +/* Wave launch override modes */ | |
| 803 | +enum kfd_dbg_trap_override_mode { | |
| 804 | + KFD_DBG_TRAP_OVERRIDE_OR = 0, | |
| 805 | + KFD_DBG_TRAP_OVERRIDE_REPLACE = 1 | |
| 806 | +}; | |
| 807 | + | |
| 808 | +/* Wave launch overrides */ | |
| 809 | +enum kfd_dbg_trap_mask { | |
| 810 | + KFD_DBG_TRAP_MASK_FP_INVALID = 1, | |
| 811 | + KFD_DBG_TRAP_MASK_FP_INPUT_DENORMAL = 2, | |
| 812 | + KFD_DBG_TRAP_MASK_FP_DIVIDE_BY_ZERO = 4, | |
| 813 | + KFD_DBG_TRAP_MASK_FP_OVERFLOW = 8, | |
| 814 | + KFD_DBG_TRAP_MASK_FP_UNDERFLOW = 16, | |
| 815 | + KFD_DBG_TRAP_MASK_FP_INEXACT = 32, | |
| 816 | + KFD_DBG_TRAP_MASK_INT_DIVIDE_BY_ZERO = 64, | |
| 817 | + KFD_DBG_TRAP_MASK_DBG_ADDRESS_WATCH = 128, | |
| 818 | + KFD_DBG_TRAP_MASK_DBG_MEMORY_VIOLATION = 256, | |
| 819 | + KFD_DBG_TRAP_MASK_TRAP_ON_WAVE_START = (1 << 30), | |
| 820 | + KFD_DBG_TRAP_MASK_TRAP_ON_WAVE_END = (1 << 31) | |
| 821 | +}; | |
| 822 | + | |
| 823 | +/* Wave launch modes */ | |
| 824 | +enum kfd_dbg_trap_wave_launch_mode { | |
| 825 | + KFD_DBG_TRAP_WAVE_LAUNCH_MODE_NORMAL = 0, | |
| 826 | + KFD_DBG_TRAP_WAVE_LAUNCH_MODE_HALT = 1, | |
| 827 | + KFD_DBG_TRAP_WAVE_LAUNCH_MODE_DEBUG = 3 | |
| 828 | +}; | |
| 829 | + | |
| 830 | +/* Address watch modes */ | |
| 831 | +enum kfd_dbg_trap_address_watch_mode { | |
| 832 | + KFD_DBG_TRAP_ADDRESS_WATCH_MODE_READ = 0, | |
| 833 | + KFD_DBG_TRAP_ADDRESS_WATCH_MODE_NONREAD = 1, | |
| 834 | + KFD_DBG_TRAP_ADDRESS_WATCH_MODE_ATOMIC = 2, | |
| 835 | + KFD_DBG_TRAP_ADDRESS_WATCH_MODE_ALL = 3 | |
| 836 | +}; | |
| 837 | + | |
| 838 | +/* Additional wave settings */ | |
| 839 | +enum kfd_dbg_trap_flags { | |
| 840 | + KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP = 1, | |
| 841 | +}; | |
| 842 | + | |
| 843 | +/* Trap exceptions */ | |
| 844 | +enum kfd_dbg_trap_exception_code { | |
| 845 | + EC_NONE = 0, | |
| 846 | + /* per queue */ | |
| 847 | + EC_QUEUE_WAVE_ABORT = 1, | |
| 848 | + EC_QUEUE_WAVE_TRAP = 2, | |
| 849 | + EC_QUEUE_WAVE_MATH_ERROR = 3, | |
| 850 | + EC_QUEUE_WAVE_ILLEGAL_INSTRUCTION = 4, | |
| 851 | + EC_QUEUE_WAVE_MEMORY_VIOLATION = 5, | |
| 852 | + EC_QUEUE_WAVE_APERTURE_VIOLATION = 6, | |
| 853 | + EC_QUEUE_PACKET_DISPATCH_DIM_INVALID = 16, | |
| 854 | + EC_QUEUE_PACKET_DISPATCH_GROUP_SEGMENT_SIZE_INVALID = 17, | |
| 855 | + EC_QUEUE_PACKET_DISPATCH_CODE_INVALID = 18, | |
| 856 | + EC_QUEUE_PACKET_RESERVED = 19, | |
| 857 | + EC_QUEUE_PACKET_UNSUPPORTED = 20, | |
| 858 | + EC_QUEUE_PACKET_DISPATCH_WORK_GROUP_SIZE_INVALID = 21, | |
| 859 | + EC_QUEUE_PACKET_DISPATCH_REGISTER_INVALID = 22, | |
| 860 | + EC_QUEUE_PACKET_VENDOR_UNSUPPORTED = 23, | |
| 861 | + EC_QUEUE_PREEMPTION_ERROR = 30, | |
| 862 | + EC_QUEUE_NEW = 31, | |
| 863 | + /* per device */ | |
| 864 | + EC_DEVICE_QUEUE_DELETE = 32, | |
| 865 | + EC_DEVICE_MEMORY_VIOLATION = 33, | |
| 866 | + EC_DEVICE_RAS_ERROR = 34, | |
| 867 | + EC_DEVICE_FATAL_HALT = 35, | |
| 868 | + EC_DEVICE_NEW = 36, | |
| 869 | + /* per process */ | |
| 870 | + EC_PROCESS_RUNTIME = 48, | |
| 871 | + EC_PROCESS_DEVICE_REMOVE = 49, | |
| 872 | + EC_MAX | |
| 873 | +}; | |
| 874 | + | |
| 875 | +/* Mask generated by ecode in kfd_dbg_trap_exception_code */ | |
| 876 | +#define KFD_EC_MASK(ecode) (1ULL << (ecode - 1)) | |
| 877 | + | |
| 878 | +/* Masks for exception code type checks below */ | |
| 879 | +#define KFD_EC_MASK_QUEUE (KFD_EC_MASK(EC_QUEUE_WAVE_ABORT) | \ | |
| 880 | + KFD_EC_MASK(EC_QUEUE_WAVE_TRAP) | \ | |
| 881 | + KFD_EC_MASK(EC_QUEUE_WAVE_MATH_ERROR) | \ | |
| 882 | + KFD_EC_MASK(EC_QUEUE_WAVE_ILLEGAL_INSTRUCTION) | \ | |
| 883 | + KFD_EC_MASK(EC_QUEUE_WAVE_MEMORY_VIOLATION) | \ | |
| 884 | + KFD_EC_MASK(EC_QUEUE_WAVE_APERTURE_VIOLATION) | \ | |
| 885 | + KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_DIM_INVALID) | \ | |
| 886 | + KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_GROUP_SEGMENT_SIZE_INVALID) | \ | |
| 887 | + KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_CODE_INVALID) | \ | |
| 888 | + KFD_EC_MASK(EC_QUEUE_PACKET_RESERVED) | \ | |
| 889 | + KFD_EC_MASK(EC_QUEUE_PACKET_UNSUPPORTED) | \ | |
| 890 | + KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_WORK_GROUP_SIZE_INVALID) | \ | |
| 891 | + KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_REGISTER_INVALID) | \ | |
| 892 | + KFD_EC_MASK(EC_QUEUE_PACKET_VENDOR_UNSUPPORTED) | \ | |
| 893 | + KFD_EC_MASK(EC_QUEUE_PREEMPTION_ERROR) | \ | |
| 894 | + KFD_EC_MASK(EC_QUEUE_NEW)) | |
| 895 | +#define KFD_EC_MASK_DEVICE (KFD_EC_MASK(EC_DEVICE_QUEUE_DELETE) | \ | |
| 896 | + KFD_EC_MASK(EC_DEVICE_RAS_ERROR) | \ | |
| 897 | + KFD_EC_MASK(EC_DEVICE_FATAL_HALT) | \ | |
| 898 | + KFD_EC_MASK(EC_DEVICE_MEMORY_VIOLATION) | \ | |
| 899 | + KFD_EC_MASK(EC_DEVICE_NEW)) | |
| 900 | +#define KFD_EC_MASK_PROCESS (KFD_EC_MASK(EC_PROCESS_RUNTIME) | \ | |
| 901 | + KFD_EC_MASK(EC_PROCESS_DEVICE_REMOVE)) | |
| 902 | + | |
| 903 | +/* Checks for exception code types for KFD search */ | |
| 904 | +#define KFD_DBG_EC_TYPE_IS_QUEUE(ecode) \ | |
| 905 | + (!!(KFD_EC_MASK(ecode) & KFD_EC_MASK_QUEUE)) | |
| 906 | +#define KFD_DBG_EC_TYPE_IS_DEVICE(ecode) \ | |
| 907 | + (!!(KFD_EC_MASK(ecode) & KFD_EC_MASK_DEVICE)) | |
| 908 | +#define KFD_DBG_EC_TYPE_IS_PROCESS(ecode) \ | |
| 909 | + (!!(KFD_EC_MASK(ecode) & KFD_EC_MASK_PROCESS)) | |
| 910 | + | |
| 911 | + | |
| 912 | +/* Runtime enable states */ | |
| 913 | +enum kfd_dbg_runtime_state { | |
| 914 | + DEBUG_RUNTIME_STATE_DISABLED = 0, | |
| 915 | + DEBUG_RUNTIME_STATE_ENABLED = 1, | |
| 916 | + DEBUG_RUNTIME_STATE_ENABLED_BUSY = 2, | |
| 917 | + DEBUG_RUNTIME_STATE_ENABLED_ERROR = 3 | |
| 918 | +}; | |
| 919 | + | |
| 920 | +/* Runtime enable status */ | |
| 921 | +struct kfd_runtime_info { | |
| 922 | + __u64 r_debug; | |
| 923 | + __u32 runtime_state; | |
| 924 | + __u32 ttmp_setup; | |
| 925 | +}; | |
| 926 | + | |
| 927 | +/* Enable modes for runtime enable */ | |
| 928 | +#define KFD_RUNTIME_ENABLE_MODE_ENABLE_MASK 1 | |
| 929 | +#define KFD_RUNTIME_ENABLE_MODE_TTMP_SAVE_MASK 2 | |
| 930 | + | |
| 931 | +/** | |
| 932 | + * kfd_ioctl_runtime_enable_args - Arguments for runtime enable | |
| 933 | + * | |
| 934 | + * Coordinates debug exception signalling and debug device enablement with runtime. | |
| 935 | + * | |
| 936 | + * @r_debug - pointer to user struct for sharing information between ROCr and the debuggger | |
| 937 | + * @mode_mask - mask to set mode | |
| 938 | + * KFD_RUNTIME_ENABLE_MODE_ENABLE_MASK - enable runtime for debugging, otherwise disable | |
| 939 | + * KFD_RUNTIME_ENABLE_MODE_TTMP_SAVE_MASK - enable trap temporary setup (ignore on disable) | |
| 940 | + * @capabilities_mask - mask to notify runtime on what KFD supports | |
| 941 | + * | |
| 942 | + * Return - 0 on SUCCESS. | |
| 943 | + * - EBUSY if runtime enable call already pending. | |
| 944 | + * - EEXIST if user queues already active prior to call. | |
| 945 | + * If process is debug enabled, runtime enable will enable debug devices and | |
| 946 | + * wait for debugger process to send runtime exception EC_PROCESS_RUNTIME | |
| 947 | + * to unblock - see kfd_ioctl_dbg_trap_args. | |
| 948 | + * | |
| 949 | + */ | |
| 950 | +struct kfd_ioctl_runtime_enable_args { | |
| 951 | + __u64 r_debug; | |
| 952 | + __u32 mode_mask; | |
| 953 | + __u32 capabilities_mask; | |
| 954 | +}; | |
| 955 | + | |
| 956 | +/* Queue information */ | |
| 957 | +struct kfd_queue_snapshot_entry { | |
| 958 | + __u64 exception_status; | |
| 959 | + __u64 ring_base_address; | |
| 960 | + __u64 write_pointer_address; | |
| 961 | + __u64 read_pointer_address; | |
| 962 | + __u64 ctx_save_restore_address; | |
| 963 | + __u32 queue_id; | |
| 964 | + __u32 gpu_id; | |
| 965 | + __u32 ring_size; | |
| 966 | + __u32 queue_type; | |
| 967 | + __u32 ctx_save_restore_area_size; | |
| 968 | + __u32 reserved; | |
| 969 | +}; | |
| 970 | + | |
| 971 | +/* Queue status return for suspend/resume */ | |
| 972 | +#define KFD_DBG_QUEUE_ERROR_BIT 30 | |
| 973 | +#define KFD_DBG_QUEUE_INVALID_BIT 31 | |
| 974 | +#define KFD_DBG_QUEUE_ERROR_MASK (1 << KFD_DBG_QUEUE_ERROR_BIT) | |
| 975 | +#define KFD_DBG_QUEUE_INVALID_MASK (1 << KFD_DBG_QUEUE_INVALID_BIT) | |
| 976 | + | |
| 977 | +/* Context save area header information */ | |
| 978 | +struct kfd_context_save_area_header { | |
| 979 | + struct { | |
| 980 | + __u32 control_stack_offset; | |
| 981 | + __u32 control_stack_size; | |
| 982 | + __u32 wave_state_offset; | |
| 983 | + __u32 wave_state_size; | |
| 984 | + } wave_state; | |
| 985 | + __u32 debug_offset; | |
| 986 | + __u32 debug_size; | |
| 987 | + __u64 err_payload_addr; | |
| 988 | + __u32 err_event_id; | |
| 989 | + __u32 reserved1; | |
| 990 | +}; | |
| 991 | + | |
| 992 | +/* | |
| 993 | + * Debug operations | |
| 994 | + * | |
| 995 | + * For specifics on usage and return values, see documentation per operation | |
| 996 | + * below. Otherwise, generic error returns apply: | |
| 997 | + * - ESRCH if the process to debug does not exist. | |
| 998 | + * | |
| 999 | + * - EINVAL (with KFD_IOC_DBG_TRAP_ENABLE exempt) if operation | |
| 1000 | + * KFD_IOC_DBG_TRAP_ENABLE has not succeeded prior. | |
| 1001 | + * Also returns this error if GPU hardware scheduling is not supported. | |
| 1002 | + * | |
| 1003 | + * - EPERM (with KFD_IOC_DBG_TRAP_DISABLE exempt) if target process is not | |
| 1004 | + * PTRACE_ATTACHED. KFD_IOC_DBG_TRAP_DISABLE is exempt to allow | |
| 1005 | + * clean up of debug mode as long as process is debug enabled. | |
| 1006 | + * | |
| 1007 | + * - EACCES if any DBG_HW_OP (debug hardware operation) is requested when | |
| 1008 | + * AMDKFD_IOC_RUNTIME_ENABLE has not succeeded prior. | |
| 1009 | + * | |
| 1010 | + * - ENODEV if any GPU does not support debugging on a DBG_HW_OP call. | |
| 1011 | + * | |
| 1012 | + * - Other errors may be returned when a DBG_HW_OP occurs while the GPU | |
| 1013 | + * is in a fatal state. | |
| 1014 | + * | |
| 1015 | + */ | |
| 1016 | +enum kfd_dbg_trap_operations { | |
| 1017 | + KFD_IOC_DBG_TRAP_ENABLE = 0, | |
| 1018 | + KFD_IOC_DBG_TRAP_DISABLE = 1, | |
| 1019 | + KFD_IOC_DBG_TRAP_SEND_RUNTIME_EVENT = 2, | |
| 1020 | + KFD_IOC_DBG_TRAP_SET_EXCEPTIONS_ENABLED = 3, | |
| 1021 | + KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE = 4, /* DBG_HW_OP */ | |
| 1022 | + KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE = 5, /* DBG_HW_OP */ | |
| 1023 | + KFD_IOC_DBG_TRAP_SUSPEND_QUEUES = 6, /* DBG_HW_OP */ | |
| 1024 | + KFD_IOC_DBG_TRAP_RESUME_QUEUES = 7, /* DBG_HW_OP */ | |
| 1025 | + KFD_IOC_DBG_TRAP_SET_NODE_ADDRESS_WATCH = 8, /* DBG_HW_OP */ | |
| 1026 | + KFD_IOC_DBG_TRAP_CLEAR_NODE_ADDRESS_WATCH = 9, /* DBG_HW_OP */ | |
| 1027 | + KFD_IOC_DBG_TRAP_SET_FLAGS = 10, | |
| 1028 | + KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT = 11, | |
| 1029 | + KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO = 12, | |
| 1030 | + KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT = 13, | |
| 1031 | + KFD_IOC_DBG_TRAP_GET_DEVICE_SNAPSHOT = 14 | |
| 1032 | +}; | |
| 1033 | + | |
| 1034 | +/** | |
| 1035 | + * kfd_ioctl_dbg_trap_enable_args | |
| 1036 | + * | |
| 1037 | + * Arguments for KFD_IOC_DBG_TRAP_ENABLE. | |
| 1038 | + * | |
| 1039 | + * Enables debug session for target process. Call @op KFD_IOC_DBG_TRAP_DISABLE in | |
| 1040 | + * kfd_ioctl_dbg_trap_args to disable debug session. | |
| 1041 | + * | |
| 1042 | + * @exception_mask (IN) - exceptions to raise to the debugger | |
| 1043 | + * @rinfo_ptr (IN) - pointer to runtime info buffer (see kfd_runtime_info) | |
| 1044 | + * @rinfo_size (IN/OUT) - size of runtime info buffer in bytes | |
| 1045 | + * @dbg_fd (IN) - fd the KFD will nofify the debugger with of raised | |
| 1046 | + * exceptions set in exception_mask. | |
| 1047 | + * | |
| 1048 | + * Generic errors apply (see kfd_dbg_trap_operations). | |
| 1049 | + * Return - 0 on SUCCESS. | |
| 1050 | + * Copies KFD saved kfd_runtime_info to @rinfo_ptr on enable. | |
| 1051 | + * Size of kfd_runtime saved by the KFD returned to @rinfo_size. | |
| 1052 | + * - EBADF if KFD cannot get a reference to dbg_fd. | |
| 1053 | + * - EFAULT if KFD cannot copy runtime info to rinfo_ptr. | |
| 1054 | + * - EINVAL if target process is already debug enabled. | |
| 1055 | + * | |
| 1056 | + */ | |
| 1057 | +struct kfd_ioctl_dbg_trap_enable_args { | |
| 1058 | + __u64 exception_mask; | |
| 1059 | + __u64 rinfo_ptr; | |
| 1060 | + __u32 rinfo_size; | |
| 1061 | + __u32 dbg_fd; | |
| 1062 | +}; | |
| 1063 | + | |
| 1064 | +/** | |
| 1065 | + * kfd_ioctl_dbg_trap_send_runtime_event_args | |
| 1066 | + * | |
| 1067 | + * | |
| 1068 | + * Arguments for KFD_IOC_DBG_TRAP_SEND_RUNTIME_EVENT. | |
| 1069 | + * Raises exceptions to runtime. | |
| 1070 | + * | |
| 1071 | + * @exception_mask (IN) - exceptions to raise to runtime | |
| 1072 | + * @gpu_id (IN) - target device id | |
| 1073 | + * @queue_id (IN) - target queue id | |
| 1074 | + * | |
| 1075 | + * Generic errors apply (see kfd_dbg_trap_operations). | |
| 1076 | + * Return - 0 on SUCCESS. | |
| 1077 | + * - ENODEV if gpu_id not found. | |
| 1078 | + * If exception_mask contains EC_PROCESS_RUNTIME, unblocks pending | |
| 1079 | + * AMDKFD_IOC_RUNTIME_ENABLE call - see kfd_ioctl_runtime_enable_args. | |
| 1080 | + * All other exceptions are raised to runtime through err_payload_addr. | |
| 1081 | + * See kfd_context_save_area_header. | |
| 1082 | + */ | |
| 1083 | +struct kfd_ioctl_dbg_trap_send_runtime_event_args { | |
| 1084 | + __u64 exception_mask; | |
| 1085 | + __u32 gpu_id; | |
| 1086 | + __u32 queue_id; | |
| 1087 | +}; | |
| 1088 | + | |
| 1089 | +/** | |
| 1090 | + * kfd_ioctl_dbg_trap_set_exceptions_enabled_args | |
| 1091 | + * | |
| 1092 | + * Arguments for KFD_IOC_SET_EXCEPTIONS_ENABLED | |
| 1093 | + * Set new exceptions to be raised to the debugger. | |
| 1094 | + * | |
| 1095 | + * @exception_mask (IN) - new exceptions to raise the debugger | |
| 1096 | + * | |
| 1097 | + * Generic errors apply (see kfd_dbg_trap_operations). | |
| 1098 | + * Return - 0 on SUCCESS. | |
| 1099 | + */ | |
| 1100 | +struct kfd_ioctl_dbg_trap_set_exceptions_enabled_args { | |
| 1101 | + __u64 exception_mask; | |
| 1102 | +}; | |
| 1103 | + | |
| 1104 | +/** | |
| 1105 | + * kfd_ioctl_dbg_trap_set_wave_launch_override_args | |
| 1106 | + * | |
| 1107 | + * Arguments for KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE | |
| 1108 | + * Enable HW exceptions to raise trap. | |
| 1109 | + * | |
| 1110 | + * @override_mode (IN) - see kfd_dbg_trap_override_mode | |
| 1111 | + * @enable_mask (IN/OUT) - reference kfd_dbg_trap_mask. | |
| 1112 | + * IN is the override modes requested to be enabled. | |
| 1113 | + * OUT is referenced in Return below. | |
| 1114 | + * @support_request_mask (IN/OUT) - reference kfd_dbg_trap_mask. | |
| 1115 | + * IN is the override modes requested for support check. | |
| 1116 | + * OUT is referenced in Return below. | |
| 1117 | + * | |
| 1118 | + * Generic errors apply (see kfd_dbg_trap_operations). | |
| 1119 | + * Return - 0 on SUCCESS. | |
| 1120 | + * Previous enablement is returned in @enable_mask. | |
| 1121 | + * Actual override support is returned in @support_request_mask. | |
| 1122 | + * - EINVAL if override mode is not supported. | |
| 1123 | + * - EACCES if trap support requested is not actually supported. | |
| 1124 | + * i.e. enable_mask (IN) is not a subset of support_request_mask (OUT). | |
| 1125 | + * Otherwise it is considered a generic error (see kfd_dbg_trap_operations). | |
| 1126 | + */ | |
| 1127 | +struct kfd_ioctl_dbg_trap_set_wave_launch_override_args { | |
| 1128 | + __u32 override_mode; | |
| 1129 | + __u32 enable_mask; | |
| 1130 | + __u32 support_request_mask; | |
| 1131 | + __u32 pad; | |
| 1132 | +}; | |
| 1133 | + | |
| 1134 | +/** | |
| 1135 | + * kfd_ioctl_dbg_trap_set_wave_launch_mode_args | |
| 1136 | + * | |
| 1137 | + * Arguments for KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE | |
| 1138 | + * Set wave launch mode. | |
| 1139 | + * | |
| 1140 | + * @mode (IN) - see kfd_dbg_trap_wave_launch_mode | |
| 1141 | + * | |
| 1142 | + * Generic errors apply (see kfd_dbg_trap_operations). | |
| 1143 | + * Return - 0 on SUCCESS. | |
| 1144 | + */ | |
| 1145 | +struct kfd_ioctl_dbg_trap_set_wave_launch_mode_args { | |
| 1146 | + __u32 launch_mode; | |
| 1147 | + __u32 pad; | |
| 1148 | +}; | |
| 1149 | + | |
| 1150 | +/** | |
| 1151 | + * kfd_ioctl_dbg_trap_suspend_queues_ags | |
| 1152 | + * | |
| 1153 | + * Arguments for KFD_IOC_DBG_TRAP_SUSPEND_QUEUES | |
| 1154 | + * Suspend queues. | |
| 1155 | + * | |
| 1156 | + * @exception_mask (IN) - raised exceptions to clear | |
| 1157 | + * @queue_array_ptr (IN) - pointer to array of queue ids (u32 per queue id) | |
| 1158 | + * to suspend | |
| 1159 | + * @num_queues (IN) - number of queues to suspend in @queue_array_ptr | |
| 1160 | + * @grace_period (IN) - wave time allowance before preemption | |
| 1161 | + * per 1K GPU clock cycle unit | |
| 1162 | + * | |
| 1163 | + * Generic errors apply (see kfd_dbg_trap_operations). | |
| 1164 | + * Destruction of a suspended queue is blocked until the queue is | |
| 1165 | + * resumed. This allows the debugger to access queue information and | |
| 1166 | + * the its context save area without running into a race condition on | |
| 1167 | + * queue destruction. | |
| 1168 | + * Automatically copies per queue context save area header information | |
| 1169 | + * into the save area base | |
| 1170 | + * (see kfd_queue_snapshot_entry and kfd_context_save_area_header). | |
| 1171 | + * | |
| 1172 | + * Return - Number of queues suspended on SUCCESS. | |
| 1173 | + * . KFD_DBG_QUEUE_ERROR_MASK and KFD_DBG_QUEUE_INVALID_MASK masked | |
| 1174 | + * for each queue id in @queue_array_ptr array reports unsuccessful | |
| 1175 | + * suspend reason. | |
| 1176 | + * KFD_DBG_QUEUE_ERROR_MASK = HW failure. | |
| 1177 | + * KFD_DBG_QUEUE_INVALID_MASK = queue does not exist, is new or | |
| 1178 | + * is being destroyed. | |
| 1179 | + */ | |
| 1180 | +struct kfd_ioctl_dbg_trap_suspend_queues_args { | |
| 1181 | + __u64 exception_mask; | |
| 1182 | + __u64 queue_array_ptr; | |
| 1183 | + __u32 num_queues; | |
| 1184 | + __u32 grace_period; | |
| 1185 | +}; | |
| 1186 | + | |
| 1187 | +/** | |
| 1188 | + * kfd_ioctl_dbg_trap_resume_queues_args | |
| 1189 | + * | |
| 1190 | + * Arguments for KFD_IOC_DBG_TRAP_RESUME_QUEUES | |
| 1191 | + * Resume queues. | |
| 1192 | + * | |
| 1193 | + * @queue_array_ptr (IN) - pointer to array of queue ids (u32 per queue id) | |
| 1194 | + * to resume | |
| 1195 | + * @num_queues (IN) - number of queues to resume in @queue_array_ptr | |
| 1196 | + * | |
| 1197 | + * Generic errors apply (see kfd_dbg_trap_operations). | |
| 1198 | + * Return - Number of queues resumed on SUCCESS. | |
| 1199 | + * KFD_DBG_QUEUE_ERROR_MASK and KFD_DBG_QUEUE_INVALID_MASK mask | |
| 1200 | + * for each queue id in @queue_array_ptr array reports unsuccessful | |
| 1201 | + * resume reason. | |
| 1202 | + * KFD_DBG_QUEUE_ERROR_MASK = HW failure. | |
| 1203 | + * KFD_DBG_QUEUE_INVALID_MASK = queue does not exist. | |
| 1204 | + */ | |
| 1205 | +struct kfd_ioctl_dbg_trap_resume_queues_args { | |
| 1206 | + __u64 queue_array_ptr; | |
| 1207 | + __u32 num_queues; | |
| 1208 | + __u32 pad; | |
| 1209 | +}; | |
| 1210 | + | |
| 1211 | +/** | |
| 1212 | + * kfd_ioctl_dbg_trap_set_node_address_watch_args | |
| 1213 | + * | |
| 1214 | + * Arguments for KFD_IOC_DBG_TRAP_SET_NODE_ADDRESS_WATCH | |
| 1215 | + * Sets address watch for device. | |
| 1216 | + * | |
| 1217 | + * @address (IN) - watch address to set | |
| 1218 | + * @mode (IN) - see kfd_dbg_trap_address_watch_mode | |
| 1219 | + * @mask (IN) - watch address mask | |
| 1220 | + * @gpu_id (IN) - target gpu to set watch point | |
| 1221 | + * @id (OUT) - watch id allocated | |
| 1222 | + * | |
| 1223 | + * Generic errors apply (see kfd_dbg_trap_operations). | |
| 1224 | + * Return - 0 on SUCCESS. | |
| 1225 | + * Allocated watch ID returned to @id. | |
| 1226 | + * - ENODEV if gpu_id not found. | |
| 1227 | + * - ENOMEM if watch IDs can be allocated | |
| 1228 | + */ | |
| 1229 | +struct kfd_ioctl_dbg_trap_set_node_address_watch_args { | |
| 1230 | + __u64 address; | |
| 1231 | + __u32 mode; | |
| 1232 | + __u32 mask; | |
| 1233 | + __u32 gpu_id; | |
| 1234 | + __u32 id; | |
| 1235 | +}; | |
| 1236 | + | |
| 1237 | +/** | |
| 1238 | + * kfd_ioctl_dbg_trap_clear_node_address_watch_args | |
| 1239 | + * | |
| 1240 | + * Arguments for KFD_IOC_DBG_TRAP_CLEAR_NODE_ADDRESS_WATCH | |
| 1241 | + * Clear address watch for device. | |
| 1242 | + * | |
| 1243 | + * @gpu_id (IN) - target device to clear watch point | |
| 1244 | + * @id (IN) - allocated watch id to clear | |
| 1245 | + * | |
| 1246 | + * Generic errors apply (see kfd_dbg_trap_operations). | |
| 1247 | + * Return - 0 on SUCCESS. | |
| 1248 | + * - ENODEV if gpu_id not found. | |
| 1249 | + * - EINVAL if watch ID has not been allocated. | |
| 1250 | + */ | |
| 1251 | +struct kfd_ioctl_dbg_trap_clear_node_address_watch_args { | |
| 1252 | + __u32 gpu_id; | |
| 1253 | + __u32 id; | |
| 1254 | +}; | |
| 1255 | + | |
| 1256 | +/** | |
| 1257 | + * kfd_ioctl_dbg_trap_set_flags_args | |
| 1258 | + * | |
| 1259 | + * Arguments for KFD_IOC_DBG_TRAP_SET_FLAGS | |
| 1260 | + * Sets flags for wave behaviour. | |
| 1261 | + * | |
| 1262 | + * @flags (IN/OUT) - IN = flags to enable, OUT = flags previously enabled | |
| 1263 | + * | |
| 1264 | + * Generic errors apply (see kfd_dbg_trap_operations). | |
| 1265 | + * Return - 0 on SUCCESS. | |
| 1266 | + * - EACCESS if any debug device does not allow flag options. | |
| 1267 | + */ | |
| 1268 | +struct kfd_ioctl_dbg_trap_set_flags_args { | |
| 1269 | + __u32 flags; | |
| 1270 | + __u32 pad; | |
| 1271 | +}; | |
| 1272 | + | |
| 1273 | +/** | |
| 1274 | + * kfd_ioctl_dbg_trap_query_debug_event_args | |
| 1275 | + * | |
| 1276 | + * Arguments for KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT | |
| 1277 | + * | |
| 1278 | + * Find one or more raised exceptions. This function can return multiple | |
| 1279 | + * exceptions from a single queue or a single device with one call. To find | |
| 1280 | + * all raised exceptions, this function must be called repeatedly until it | |
| 1281 | + * returns -EAGAIN. Returned exceptions can optionally be cleared by | |
| 1282 | + * setting the corresponding bit in the @exception_mask input parameter. | |
| 1283 | + * However, clearing an exception prevents retrieving further information | |
| 1284 | + * about it with KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO. | |
| 1285 | + * | |
| 1286 | + * @exception_mask (IN/OUT) - exception to clear (IN) and raised (OUT) | |
| 1287 | + * @gpu_id (OUT) - gpu id of exceptions raised | |
| 1288 | + * @queue_id (OUT) - queue id of exceptions raised | |
| 1289 | + * | |
| 1290 | + * Generic errors apply (see kfd_dbg_trap_operations). | |
| 1291 | + * Return - 0 on raised exception found | |
| 1292 | + * Raised exceptions found are returned in @exception mask | |
| 1293 | + * with reported source id returned in @gpu_id or @queue_id. | |
| 1294 | + * - EAGAIN if no raised exception has been found | |
| 1295 | + */ | |
| 1296 | +struct kfd_ioctl_dbg_trap_query_debug_event_args { | |
| 1297 | + __u64 exception_mask; | |
| 1298 | + __u32 gpu_id; | |
| 1299 | + __u32 queue_id; | |
| 1300 | +}; | |
| 1301 | + | |
| 1302 | +/** | |
| 1303 | + * kfd_ioctl_dbg_trap_query_exception_info_args | |
| 1304 | + * | |
| 1305 | + * Arguments KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO | |
| 1306 | + * Get additional info on raised exception. | |
| 1307 | + * | |
| 1308 | + * @info_ptr (IN) - pointer to exception info buffer to copy to | |
| 1309 | + * @info_size (IN/OUT) - exception info buffer size (bytes) | |
| 1310 | + * @source_id (IN) - target gpu or queue id | |
| 1311 | + * @exception_code (IN) - target exception | |
| 1312 | + * @clear_exception (IN) - clear raised @exception_code exception | |
| 1313 | + * (0 = false, 1 = true) | |
| 1314 | + * | |
| 1315 | + * Generic errors apply (see kfd_dbg_trap_operations). | |
| 1316 | + * Return - 0 on SUCCESS. | |
| 1317 | + * If @exception_code is EC_DEVICE_MEMORY_VIOLATION, copy @info_size(OUT) | |
| 1318 | + * bytes of memory exception data to @info_ptr. | |
| 1319 | + * If @exception_code is EC_PROCESS_RUNTIME, copy saved | |
| 1320 | + * kfd_runtime_info to @info_ptr. | |
| 1321 | + * Actual required @info_ptr size (bytes) is returned in @info_size. | |
| 1322 | + */ | |
| 1323 | +struct kfd_ioctl_dbg_trap_query_exception_info_args { | |
| 1324 | + __u64 info_ptr; | |
| 1325 | + __u32 info_size; | |
| 1326 | + __u32 source_id; | |
| 1327 | + __u32 exception_code; | |
| 1328 | + __u32 clear_exception; | |
| 1329 | +}; | |
| 1330 | + | |
| 1331 | +/** | |
| 1332 | + * kfd_ioctl_dbg_trap_get_queue_snapshot_args | |
| 1333 | + * | |
| 1334 | + * Arguments KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT | |
| 1335 | + * Get queue information. | |
| 1336 | + * | |
| 1337 | + * @exception_mask (IN) - exceptions raised to clear | |
| 1338 | + * @snapshot_buf_ptr (IN) - queue snapshot entry buffer (see kfd_queue_snapshot_entry) | |
| 1339 | + * @num_queues (IN/OUT) - number of queue snapshot entries | |
| 1340 | + * The debugger specifies the size of the array allocated in @num_queues. | |
| 1341 | + * KFD returns the number of queues that actually existed. If this is | |
| 1342 | + * larger than the size specified by the debugger, KFD will not overflow | |
| 1343 | + * the array allocated by the debugger. | |
| 1344 | + * | |
| 1345 | + * @entry_size (IN/OUT) - size per entry in bytes | |
| 1346 | + * The debugger specifies sizeof(struct kfd_queue_snapshot_entry) in | |
| 1347 | + * @entry_size. KFD returns the number of bytes actually populated per | |
| 1348 | + * entry. The debugger should use the KFD_IOCTL_MINOR_VERSION to determine, | |
| 1349 | + * which fields in struct kfd_queue_snapshot_entry are valid. This allows | |
| 1350 | + * growing the ABI in a backwards compatible manner. | |
| 1351 | + * Note that entry_size(IN) should still be used to stride the snapshot buffer in the | |
| 1352 | + * event that it's larger than actual kfd_queue_snapshot_entry. | |
| 1353 | + * | |
| 1354 | + * Generic errors apply (see kfd_dbg_trap_operations). | |
| 1355 | + * Return - 0 on SUCCESS. | |
| 1356 | + * Copies @num_queues(IN) queue snapshot entries of size @entry_size(IN) | |
| 1357 | + * into @snapshot_buf_ptr if @num_queues(IN) > 0. | |
| 1358 | + * Otherwise return @num_queues(OUT) queue snapshot entries that exist. | |
| 1359 | + */ | |
| 1360 | +struct kfd_ioctl_dbg_trap_queue_snapshot_args { | |
| 1361 | + __u64 exception_mask; | |
| 1362 | + __u64 snapshot_buf_ptr; | |
| 1363 | + __u32 num_queues; | |
| 1364 | + __u32 entry_size; | |
| 1365 | +}; | |
| 1366 | + | |
| 1367 | +/** | |
| 1368 | + * kfd_ioctl_dbg_trap_get_device_snapshot_args | |
| 1369 | + * | |
| 1370 | + * Arguments for KFD_IOC_DBG_TRAP_GET_DEVICE_SNAPSHOT | |
| 1371 | + * Get device information. | |
| 1372 | + * | |
| 1373 | + * @exception_mask (IN) - exceptions raised to clear | |
| 1374 | + * @snapshot_buf_ptr (IN) - pointer to snapshot buffer (see kfd_dbg_device_info_entry) | |
| 1375 | + * @num_devices (IN/OUT) - number of debug devices to snapshot | |
| 1376 | + * The debugger specifies the size of the array allocated in @num_devices. | |
| 1377 | + * KFD returns the number of devices that actually existed. If this is | |
| 1378 | + * larger than the size specified by the debugger, KFD will not overflow | |
| 1379 | + * the array allocated by the debugger. | |
| 1380 | + * | |
| 1381 | + * @entry_size (IN/OUT) - size per entry in bytes | |
| 1382 | + * The debugger specifies sizeof(struct kfd_dbg_device_info_entry) in | |
| 1383 | + * @entry_size. KFD returns the number of bytes actually populated. The | |
| 1384 | + * debugger should use KFD_IOCTL_MINOR_VERSION to determine, which fields | |
| 1385 | + * in struct kfd_dbg_device_info_entry are valid. This allows growing the | |
| 1386 | + * ABI in a backwards compatible manner. | |
| 1387 | + * Note that entry_size(IN) should still be used to stride the snapshot buffer in the | |
| 1388 | + * event that it's larger than actual kfd_dbg_device_info_entry. | |
| 1389 | + * | |
| 1390 | + * Generic errors apply (see kfd_dbg_trap_operations). | |
| 1391 | + * Return - 0 on SUCCESS. | |
| 1392 | + * Copies @num_devices(IN) device snapshot entries of size @entry_size(IN) | |
| 1393 | + * into @snapshot_buf_ptr if @num_devices(IN) > 0. | |
| 1394 | + * Otherwise return @num_devices(OUT) queue snapshot entries that exist. | |
| 1395 | + */ | |
| 1396 | +struct kfd_ioctl_dbg_trap_device_snapshot_args { | |
| 1397 | + __u64 exception_mask; | |
| 1398 | + __u64 snapshot_buf_ptr; | |
| 1399 | + __u32 num_devices; | |
| 1400 | + __u32 entry_size; | |
| 1401 | +}; | |
| 1402 | + | |
| 1403 | +/** | |
| 1404 | + * kfd_ioctl_dbg_trap_args | |
| 1405 | + * | |
| 1406 | + * Arguments to debug target process. | |
| 1407 | + * | |
| 1408 | + * @pid - target process to debug | |
| 1409 | + * @op - debug operation (see kfd_dbg_trap_operations) | |
| 1410 | + * | |
| 1411 | + * @op determines which union struct args to use. | |
| 1412 | + * Refer to kern docs for each kfd_ioctl_dbg_trap_*_args struct. | |
| 1413 | + */ | |
| 1414 | +struct kfd_ioctl_dbg_trap_args { | |
| 1415 | + __u32 pid; | |
| 1416 | + __u32 op; | |
| 1417 | + | |
| 1418 | + union { | |
| 1419 | + struct kfd_ioctl_dbg_trap_enable_args enable; | |
| 1420 | + struct kfd_ioctl_dbg_trap_send_runtime_event_args send_runtime_event; | |
| 1421 | + struct kfd_ioctl_dbg_trap_set_exceptions_enabled_args set_exceptions_enabled; | |
| 1422 | + struct kfd_ioctl_dbg_trap_set_wave_launch_override_args launch_override; | |
| 1423 | + struct kfd_ioctl_dbg_trap_set_wave_launch_mode_args launch_mode; | |
| 1424 | + struct kfd_ioctl_dbg_trap_suspend_queues_args suspend_queues; | |
| 1425 | + struct kfd_ioctl_dbg_trap_resume_queues_args resume_queues; | |
| 1426 | + struct kfd_ioctl_dbg_trap_set_node_address_watch_args set_node_address_watch; | |
| 1427 | + struct kfd_ioctl_dbg_trap_clear_node_address_watch_args clear_node_address_watch; | |
| 1428 | + struct kfd_ioctl_dbg_trap_set_flags_args set_flags; | |
| 1429 | + struct kfd_ioctl_dbg_trap_query_debug_event_args query_debug_event; | |
| 1430 | + struct kfd_ioctl_dbg_trap_query_exception_info_args query_exception_info; | |
| 1431 | + struct kfd_ioctl_dbg_trap_queue_snapshot_args queue_snapshot; | |
| 1432 | + struct kfd_ioctl_dbg_trap_device_snapshot_args device_snapshot; | |
| 1433 | + }; | |
| 1434 | +}; | |
| 1435 | + | |
| 776 | 1436 | #define AMDKFD_IOCTL_BASE 'K' |
| 777 | 1437 | #define AMDKFD_IO(nr) _IO(AMDKFD_IOCTL_BASE, nr) |
| 778 | 1438 | #define AMDKFD_IOR(nr, type) _IOR(AMDKFD_IOCTL_BASE, nr, type) |
| @@ -887,7 +1547,13 @@ struct kfd_ioctl_set_xnack_mode_args { · 108 unmodified lines | ||
| 887 | 1547 | #define AMDKFD_IOC_EXPORT_DMABUF \ |
| 888 | 1548 | AMDKFD_IOWR(0x24, struct kfd_ioctl_export_dmabuf_args) |
| 889 | 1549 | |
| 1550 | +#define AMDKFD_IOC_RUNTIME_ENABLE \ | |
| 1551 | + AMDKFD_IOWR(0x25, struct kfd_ioctl_runtime_enable_args) | |
| 1552 | + | |
| 1553 | +#define AMDKFD_IOC_DBG_TRAP \ | |
| 1554 | + AMDKFD_IOWR(0x26, struct kfd_ioctl_dbg_trap_args) | |
| 1555 | + | |
| 890 | 1556 | #define AMDKFD_COMMAND_START 0x01 |
| 891 | −#define AMDKFD_COMMAND_END 0x25 | |
| 1557 | +#define AMDKFD_COMMAND_END 0x27 | |
| 892 | 1558 | |
| 893 | 1559 | #endif |