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