Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
0002 /*
0003  * Copyright 2014-2022 Advanced Micro Devices, Inc.
0004  *
0005  * Permission is hereby granted, free of charge, to any person obtaining a
0006  * copy of this software and associated documentation files (the "Software"),
0007  * to deal in the Software without restriction, including without limitation
0008  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0009  * and/or sell copies of the Software, and to permit persons to whom the
0010  * Software is furnished to do so, subject to the following conditions:
0011  *
0012  * The above copyright notice and this permission notice shall be included in
0013  * all copies or substantial portions of the Software.
0014  *
0015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0018  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0019  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0020  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0021  * OTHER DEALINGS IN THE SOFTWARE.
0022  *
0023  */
0024 
0025 #ifndef KFD_MQD_MANAGER_H_
0026 #define KFD_MQD_MANAGER_H_
0027 
0028 #include "kfd_priv.h"
0029 
0030 #define KFD_MAX_NUM_SE 8
0031 #define KFD_MAX_NUM_SH_PER_SE 2
0032 
0033 /**
0034  * struct mqd_manager
0035  *
0036  * @init_mqd: Allocates the mqd buffer on local gpu memory and initialize it.
0037  *
0038  * @load_mqd: Loads the mqd to a concrete hqd slot. Used only for no cp
0039  * scheduling mode.
0040  *
0041  * @update_mqd: Handles a update call for the MQD
0042  *
0043  * @destroy_mqd: Destroys the HQD slot and by that preempt the relevant queue.
0044  * Used only for no cp scheduling.
0045  *
0046  * @free_mqd: Releases the mqd buffer from local gpu memory.
0047  *
0048  * @is_occupied: Checks if the relevant HQD slot is occupied.
0049  *
0050  * @get_wave_state: Retrieves context save state and optionally copies the
0051  * control stack, if kept in the MQD, to the given userspace address.
0052  *
0053  * @mqd_mutex: Mqd manager mutex.
0054  *
0055  * @dev: The kfd device structure coupled with this module.
0056  *
0057  * MQD stands for Memory Queue Descriptor which represents the current queue
0058  * state in the memory and initiate the HQD (Hardware Queue Descriptor) state.
0059  * This structure is actually a base class for the different types of MQDs
0060  * structures for the variant ASICs that should be supported in the future.
0061  * This base class is also contains all the MQD specific operations.
0062  * Another important thing to mention is that each queue has a MQD that keeps
0063  * his state (or context) after each preemption or reassignment.
0064  * Basically there are a instances of the mqd manager class per MQD type per
0065  * ASIC. Currently the kfd driver supports only Kaveri so there are instances
0066  * per KFD_MQD_TYPE for each device.
0067  *
0068  */
0069 extern int pipe_priority_map[];
0070 struct mqd_manager {
0071     struct kfd_mem_obj* (*allocate_mqd)(struct kfd_dev *kfd,
0072         struct queue_properties *q);
0073 
0074     void    (*init_mqd)(struct mqd_manager *mm, void **mqd,
0075             struct kfd_mem_obj *mqd_mem_obj, uint64_t *gart_addr,
0076             struct queue_properties *q);
0077 
0078     int (*load_mqd)(struct mqd_manager *mm, void *mqd,
0079                 uint32_t pipe_id, uint32_t queue_id,
0080                 struct queue_properties *p,
0081                 struct mm_struct *mms);
0082 
0083     void    (*update_mqd)(struct mqd_manager *mm, void *mqd,
0084                 struct queue_properties *q,
0085                 struct mqd_update_info *minfo);
0086 
0087     int (*destroy_mqd)(struct mqd_manager *mm, void *mqd,
0088                 enum kfd_preempt_type type,
0089                 unsigned int timeout, uint32_t pipe_id,
0090                 uint32_t queue_id);
0091 
0092     void    (*free_mqd)(struct mqd_manager *mm, void *mqd,
0093                 struct kfd_mem_obj *mqd_mem_obj);
0094 
0095     bool    (*is_occupied)(struct mqd_manager *mm, void *mqd,
0096                 uint64_t queue_address, uint32_t pipe_id,
0097                 uint32_t queue_id);
0098 
0099     int (*get_wave_state)(struct mqd_manager *mm, void *mqd,
0100                   void __user *ctl_stack,
0101                   u32 *ctl_stack_used_size,
0102                   u32 *save_area_used_size);
0103 
0104     void    (*get_checkpoint_info)(struct mqd_manager *mm, void *mqd, uint32_t *ctl_stack_size);
0105 
0106     void    (*checkpoint_mqd)(struct mqd_manager *mm,
0107                   void *mqd,
0108                   void *mqd_dst,
0109                   void *ctl_stack_dst);
0110 
0111     void    (*restore_mqd)(struct mqd_manager *mm, void **mqd,
0112                 struct kfd_mem_obj *mqd_mem_obj, uint64_t *gart_addr,
0113                 struct queue_properties *p,
0114                 const void *mqd_src,
0115                 const void *ctl_stack_src,
0116                 const u32 ctl_stack_size);
0117 
0118 #if defined(CONFIG_DEBUG_FS)
0119     int (*debugfs_show_mqd)(struct seq_file *m, void *data);
0120 #endif
0121     uint32_t (*read_doorbell_id)(void *mqd);
0122 
0123     struct mutex    mqd_mutex;
0124     struct kfd_dev  *dev;
0125     uint32_t mqd_size;
0126 };
0127 
0128 struct kfd_mem_obj *allocate_hiq_mqd(struct kfd_dev *dev,
0129                 struct queue_properties *q);
0130 
0131 struct kfd_mem_obj *allocate_sdma_mqd(struct kfd_dev *dev,
0132                     struct queue_properties *q);
0133 void free_mqd_hiq_sdma(struct mqd_manager *mm, void *mqd,
0134                 struct kfd_mem_obj *mqd_mem_obj);
0135 
0136 void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm,
0137         const uint32_t *cu_mask, uint32_t cu_mask_count,
0138         uint32_t *se_mask);
0139 
0140 int kfd_hiq_load_mqd_kiq(struct mqd_manager *mm, void *mqd,
0141         uint32_t pipe_id, uint32_t queue_id,
0142         struct queue_properties *p, struct mm_struct *mms);
0143 
0144 int kfd_destroy_mqd_cp(struct mqd_manager *mm, void *mqd,
0145         enum kfd_preempt_type type, unsigned int timeout,
0146         uint32_t pipe_id, uint32_t queue_id);
0147 
0148 void kfd_free_mqd_cp(struct mqd_manager *mm, void *mqd,
0149         struct kfd_mem_obj *mqd_mem_obj);
0150 
0151 bool kfd_is_occupied_cp(struct mqd_manager *mm, void *mqd,
0152          uint64_t queue_address, uint32_t pipe_id,
0153          uint32_t queue_id);
0154 
0155 int kfd_load_mqd_sdma(struct mqd_manager *mm, void *mqd,
0156         uint32_t pipe_id, uint32_t queue_id,
0157         struct queue_properties *p, struct mm_struct *mms);
0158 
0159 int kfd_destroy_mqd_sdma(struct mqd_manager *mm, void *mqd,
0160         enum kfd_preempt_type type, unsigned int timeout,
0161         uint32_t pipe_id, uint32_t queue_id);
0162 
0163 bool kfd_is_occupied_sdma(struct mqd_manager *mm, void *mqd,
0164         uint64_t queue_address, uint32_t pipe_id,
0165         uint32_t queue_id);
0166 
0167 #endif /* KFD_MQD_MANAGER_H_ */