1d87f36a0SRajneesh Bhardwaj /* SPDX-License-Identifier: GPL-2.0 OR MIT */ 26e99df57SBen Goz /* 3d87f36a0SRajneesh Bhardwaj * Copyright 2014-2022 Advanced Micro Devices, Inc. 46e99df57SBen Goz * 56e99df57SBen Goz * Permission is hereby granted, free of charge, to any person obtaining a 66e99df57SBen Goz * copy of this software and associated documentation files (the "Software"), 76e99df57SBen Goz * to deal in the Software without restriction, including without limitation 86e99df57SBen Goz * the rights to use, copy, modify, merge, publish, distribute, sublicense, 96e99df57SBen Goz * and/or sell copies of the Software, and to permit persons to whom the 106e99df57SBen Goz * Software is furnished to do so, subject to the following conditions: 116e99df57SBen Goz * 126e99df57SBen Goz * The above copyright notice and this permission notice shall be included in 136e99df57SBen Goz * all copies or substantial portions of the Software. 146e99df57SBen Goz * 156e99df57SBen Goz * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 166e99df57SBen Goz * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 176e99df57SBen Goz * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 186e99df57SBen Goz * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 196e99df57SBen Goz * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 206e99df57SBen Goz * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 216e99df57SBen Goz * OTHER DEALINGS IN THE SOFTWARE. 226e99df57SBen Goz * 236e99df57SBen Goz */ 246e99df57SBen Goz 256e99df57SBen Goz #ifndef KFD_MQD_MANAGER_H_ 266e99df57SBen Goz #define KFD_MQD_MANAGER_H_ 276e99df57SBen Goz 286e99df57SBen Goz #include "kfd_priv.h" 296e99df57SBen Goz 305145d57eSJay Cornwall #define KFD_MAX_NUM_SE 8 311ec06c2dSSean Keely #define KFD_MAX_NUM_SH_PER_SE 2 325145d57eSJay Cornwall 336e99df57SBen Goz /** 346e99df57SBen Goz * struct mqd_manager 356e99df57SBen Goz * 366e99df57SBen Goz * @init_mqd: Allocates the mqd buffer on local gpu memory and initialize it. 376e99df57SBen Goz * 386e99df57SBen Goz * @load_mqd: Loads the mqd to a concrete hqd slot. Used only for no cp 396e99df57SBen Goz * scheduling mode. 406e99df57SBen Goz * 416e99df57SBen Goz * @update_mqd: Handles a update call for the MQD 426e99df57SBen Goz * 436e99df57SBen Goz * @destroy_mqd: Destroys the HQD slot and by that preempt the relevant queue. 446e99df57SBen Goz * Used only for no cp scheduling. 456e99df57SBen Goz * 468636e53cSOak Zeng * @free_mqd: Releases the mqd buffer from local gpu memory. 476e99df57SBen Goz * 486e99df57SBen Goz * @is_occupied: Checks if the relevant HQD slot is occupied. 496e99df57SBen Goz * 505df099e8SJay Cornwall * @get_wave_state: Retrieves context save state and optionally copies the 515df099e8SJay Cornwall * control stack, if kept in the MQD, to the given userspace address. 525df099e8SJay Cornwall * 536e99df57SBen Goz * @mqd_mutex: Mqd manager mutex. 546e99df57SBen Goz * 556e99df57SBen Goz * @dev: The kfd device structure coupled with this module. 566e99df57SBen Goz * 576e99df57SBen Goz * MQD stands for Memory Queue Descriptor which represents the current queue 586e99df57SBen Goz * state in the memory and initiate the HQD (Hardware Queue Descriptor) state. 596e99df57SBen Goz * This structure is actually a base class for the different types of MQDs 606e99df57SBen Goz * structures for the variant ASICs that should be supported in the future. 616e99df57SBen Goz * This base class is also contains all the MQD specific operations. 626e99df57SBen Goz * Another important thing to mention is that each queue has a MQD that keeps 636e99df57SBen Goz * his state (or context) after each preemption or reassignment. 646e99df57SBen Goz * Basically there are a instances of the mqd manager class per MQD type per 656e99df57SBen Goz * ASIC. Currently the kfd driver supports only Kaveri so there are instances 666e99df57SBen Goz * per KFD_MQD_TYPE for each device. 676e99df57SBen Goz * 686e99df57SBen Goz */ 690ccbc7cdSOak Zeng extern int pipe_priority_map[]; 706e99df57SBen Goz struct mqd_manager { 718dc1db31SMukul Joshi struct kfd_mem_obj* (*allocate_mqd)(struct kfd_node *kfd, 728636e53cSOak Zeng struct queue_properties *q); 738636e53cSOak Zeng 748636e53cSOak Zeng void (*init_mqd)(struct mqd_manager *mm, void **mqd, 758636e53cSOak Zeng struct kfd_mem_obj *mqd_mem_obj, uint64_t *gart_addr, 766e99df57SBen Goz struct queue_properties *q); 776e99df57SBen Goz 786e99df57SBen Goz int (*load_mqd)(struct mqd_manager *mm, void *mqd, 796e99df57SBen Goz uint32_t pipe_id, uint32_t queue_id, 8070539bd7SFelix Kuehling struct queue_properties *p, 8170539bd7SFelix Kuehling struct mm_struct *mms); 826e99df57SBen Goz 838636e53cSOak Zeng void (*update_mqd)(struct mqd_manager *mm, void *mqd, 84c6e559ebSLang Yu struct queue_properties *q, 85c6e559ebSLang Yu struct mqd_update_info *minfo); 866e99df57SBen Goz 876e99df57SBen Goz int (*destroy_mqd)(struct mqd_manager *mm, void *mqd, 886e99df57SBen Goz enum kfd_preempt_type type, 896e99df57SBen Goz unsigned int timeout, uint32_t pipe_id, 906e99df57SBen Goz uint32_t queue_id); 916e99df57SBen Goz 928636e53cSOak Zeng void (*free_mqd)(struct mqd_manager *mm, void *mqd, 936e99df57SBen Goz struct kfd_mem_obj *mqd_mem_obj); 946e99df57SBen Goz 956e99df57SBen Goz bool (*is_occupied)(struct mqd_manager *mm, void *mqd, 966e99df57SBen Goz uint64_t queue_address, uint32_t pipe_id, 976e99df57SBen Goz uint32_t queue_id); 986e99df57SBen Goz 995df099e8SJay Cornwall int (*get_wave_state)(struct mqd_manager *mm, void *mqd, 1007fe51e6fSMukul Joshi struct queue_properties *q, 1015df099e8SJay Cornwall void __user *ctl_stack, 1025df099e8SJay Cornwall u32 *ctl_stack_used_size, 1035df099e8SJay Cornwall u32 *save_area_used_size); 1045df099e8SJay Cornwall 1053a9822d7SDavid Yat Sin void (*get_checkpoint_info)(struct mqd_manager *mm, void *mqd, uint32_t *ctl_stack_size); 1063a9822d7SDavid Yat Sin 1073a9822d7SDavid Yat Sin void (*checkpoint_mqd)(struct mqd_manager *mm, 1083a9822d7SDavid Yat Sin void *mqd, 1093a9822d7SDavid Yat Sin void *mqd_dst, 1103a9822d7SDavid Yat Sin void *ctl_stack_dst); 11142c6c482SDavid Yat Sin 11242c6c482SDavid Yat Sin void (*restore_mqd)(struct mqd_manager *mm, void **mqd, 11342c6c482SDavid Yat Sin struct kfd_mem_obj *mqd_mem_obj, uint64_t *gart_addr, 11442c6c482SDavid Yat Sin struct queue_properties *p, 1153a9822d7SDavid Yat Sin const void *mqd_src, 1163a9822d7SDavid Yat Sin const void *ctl_stack_src, 1173a9822d7SDavid Yat Sin const u32 ctl_stack_size); 11842c6c482SDavid Yat Sin 119851a645eSFelix Kuehling #if defined(CONFIG_DEBUG_FS) 120851a645eSFelix Kuehling int (*debugfs_show_mqd)(struct seq_file *m, void *data); 121851a645eSFelix Kuehling #endif 12251a0f459SOak Zeng uint32_t (*read_doorbell_id)(void *mqd); 1232f77b9a2SMukul Joshi uint64_t (*mqd_stride)(struct mqd_manager *mm, 1242f77b9a2SMukul Joshi struct queue_properties *p); 125851a645eSFelix Kuehling 1266e99df57SBen Goz struct mutex mqd_mutex; 1278dc1db31SMukul Joshi struct kfd_node *dev; 1286c6cde55SOak Zeng uint32_t mqd_size; 1296e99df57SBen Goz }; 1306e99df57SBen Goz 1318dc1db31SMukul Joshi struct kfd_mem_obj *allocate_hiq_mqd(struct kfd_node *dev, 1328636e53cSOak Zeng struct queue_properties *q); 1330803e7a9SOak Zeng 1348dc1db31SMukul Joshi struct kfd_mem_obj *allocate_sdma_mqd(struct kfd_node *dev, 1350803e7a9SOak Zeng struct queue_properties *q); 1368636e53cSOak Zeng void free_mqd_hiq_sdma(struct mqd_manager *mm, void *mqd, 1370803e7a9SOak Zeng struct kfd_mem_obj *mqd_mem_obj); 1380803e7a9SOak Zeng 13939e7f331SFelix Kuehling void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm, 14039e7f331SFelix Kuehling const uint32_t *cu_mask, uint32_t cu_mask_count, 141*fc6efed2SMukul Joshi uint32_t *se_mask, uint32_t inst); 14239e7f331SFelix Kuehling 143a439b890SMukul Joshi int kfd_hiq_load_mqd_kiq(struct mqd_manager *mm, void *mqd, 144a439b890SMukul Joshi uint32_t pipe_id, uint32_t queue_id, 145a439b890SMukul Joshi struct queue_properties *p, struct mm_struct *mms); 146a439b890SMukul Joshi 147a439b890SMukul Joshi int kfd_destroy_mqd_cp(struct mqd_manager *mm, void *mqd, 148a439b890SMukul Joshi enum kfd_preempt_type type, unsigned int timeout, 149a439b890SMukul Joshi uint32_t pipe_id, uint32_t queue_id); 150a439b890SMukul Joshi 151a439b890SMukul Joshi void kfd_free_mqd_cp(struct mqd_manager *mm, void *mqd, 152a439b890SMukul Joshi struct kfd_mem_obj *mqd_mem_obj); 153a439b890SMukul Joshi 154a439b890SMukul Joshi bool kfd_is_occupied_cp(struct mqd_manager *mm, void *mqd, 155a439b890SMukul Joshi uint64_t queue_address, uint32_t pipe_id, 156a439b890SMukul Joshi uint32_t queue_id); 157a439b890SMukul Joshi 158a439b890SMukul Joshi int kfd_load_mqd_sdma(struct mqd_manager *mm, void *mqd, 159a439b890SMukul Joshi uint32_t pipe_id, uint32_t queue_id, 160a439b890SMukul Joshi struct queue_properties *p, struct mm_struct *mms); 161a439b890SMukul Joshi 162a439b890SMukul Joshi int kfd_destroy_mqd_sdma(struct mqd_manager *mm, void *mqd, 163a439b890SMukul Joshi enum kfd_preempt_type type, unsigned int timeout, 164a439b890SMukul Joshi uint32_t pipe_id, uint32_t queue_id); 165a439b890SMukul Joshi 166a439b890SMukul Joshi bool kfd_is_occupied_sdma(struct mqd_manager *mm, void *mqd, 167a439b890SMukul Joshi uint64_t queue_address, uint32_t pipe_id, 168a439b890SMukul Joshi uint32_t queue_id); 169a439b890SMukul Joshi 1702f77b9a2SMukul Joshi void kfd_get_hiq_xcc_mqd(struct kfd_node *dev, 1712f77b9a2SMukul Joshi struct kfd_mem_obj *mqd_mem_obj, uint32_t virtual_xcc_id); 1722f77b9a2SMukul Joshi 1732f77b9a2SMukul Joshi uint64_t kfd_hiq_mqd_stride(struct kfd_node *dev); 1742f77b9a2SMukul Joshi uint64_t kfd_mqd_stride(struct mqd_manager *mm, 1752f77b9a2SMukul Joshi struct queue_properties *q); 1766e99df57SBen Goz #endif /* KFD_MQD_MANAGER_H_ */ 177