1 /* $NetBSD: kfd_mqd_manager.h,v 1.3 2021/12/18 23:44:59 riastradh Exp $ */ 2 3 /* 4 * Copyright 2014 Advanced Micro Devices, Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 * 24 */ 25 26 #ifndef KFD_MQD_MANAGER_H_ 27 #define KFD_MQD_MANAGER_H_ 28 29 #include "kfd_priv.h" 30 31 #define KFD_MAX_NUM_SE 8 32 33 /** 34 * struct mqd_manager 35 * 36 * @init_mqd: Allocates the mqd buffer on local gpu memory and initialize it. 37 * 38 * @load_mqd: Loads the mqd to a concrete hqd slot. Used only for no cp 39 * scheduling mode. 40 * 41 * @update_mqd: Handles a update call for the MQD 42 * 43 * @destroy_mqd: Destroys the HQD slot and by that preempt the relevant queue. 44 * Used only for no cp scheduling. 45 * 46 * @free_mqd: Releases the mqd buffer from local gpu memory. 47 * 48 * @is_occupied: Checks if the relevant HQD slot is occupied. 49 * 50 * @get_wave_state: Retrieves context save state and optionally copies the 51 * control stack, if kept in the MQD, to the given userspace address. 52 * 53 * @mqd_mutex: Mqd manager mutex. 54 * 55 * @dev: The kfd device structure coupled with this module. 56 * 57 * MQD stands for Memory Queue Descriptor which represents the current queue 58 * state in the memory and initiate the HQD (Hardware Queue Descriptor) state. 59 * This structure is actually a base class for the different types of MQDs 60 * structures for the variant ASICs that should be supported in the future. 61 * This base class is also contains all the MQD specific operations. 62 * Another important thing to mention is that each queue has a MQD that keeps 63 * his state (or context) after each preemption or reassignment. 64 * Basically there are a instances of the mqd manager class per MQD type per 65 * ASIC. Currently the kfd driver supports only Kaveri so there are instances 66 * per KFD_MQD_TYPE for each device. 67 * 68 */ 69 extern int pipe_priority_map[]; 70 struct mqd_manager { 71 struct kfd_mem_obj* (*allocate_mqd)(struct kfd_dev *kfd, 72 struct queue_properties *q); 73 74 void (*init_mqd)(struct mqd_manager *mm, void **mqd, 75 struct kfd_mem_obj *mqd_mem_obj, uint64_t *gart_addr, 76 struct queue_properties *q); 77 78 int (*load_mqd)(struct mqd_manager *mm, void *mqd, 79 uint32_t pipe_id, uint32_t queue_id, 80 struct queue_properties *p, 81 struct mm_struct *mms); 82 83 void (*update_mqd)(struct mqd_manager *mm, void *mqd, 84 struct queue_properties *q); 85 86 int (*destroy_mqd)(struct mqd_manager *mm, void *mqd, 87 enum kfd_preempt_type type, 88 unsigned int timeout, uint32_t pipe_id, 89 uint32_t queue_id); 90 91 void (*free_mqd)(struct mqd_manager *mm, void *mqd, 92 struct kfd_mem_obj *mqd_mem_obj); 93 94 bool (*is_occupied)(struct mqd_manager *mm, void *mqd, 95 uint64_t queue_address, uint32_t pipe_id, 96 uint32_t queue_id); 97 98 int (*get_wave_state)(struct mqd_manager *mm, void *mqd, 99 void __user *ctl_stack, 100 u32 *ctl_stack_used_size, 101 u32 *save_area_used_size); 102 103 #if defined(CONFIG_DEBUG_FS) 104 int (*debugfs_show_mqd)(struct seq_file *m, void *data); 105 #endif 106 107 struct mutex mqd_mutex; 108 struct kfd_dev *dev; 109 uint32_t mqd_size; 110 }; 111 112 struct kfd_mem_obj *allocate_hiq_mqd(struct kfd_dev *dev, 113 struct queue_properties *q); 114 115 struct kfd_mem_obj *allocate_sdma_mqd(struct kfd_dev *dev, 116 struct queue_properties *q); 117 void free_mqd_hiq_sdma(struct mqd_manager *mm, void *mqd, 118 struct kfd_mem_obj *mqd_mem_obj); 119 120 void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm, 121 const uint32_t *cu_mask, uint32_t cu_mask_count, 122 uint32_t *se_mask); 123 124 #endif /* KFD_MQD_MANAGER_H_ */ 125