2014-07-17 05:45:35 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Advanced Micro Devices, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KFD_DEVICE_QUEUE_MANAGER_H_
|
|
|
|
#define KFD_DEVICE_QUEUE_MANAGER_H_
|
|
|
|
|
|
|
|
#include <linux/rwsem.h>
|
|
|
|
#include <linux/list.h>
|
2018-07-12 10:32:44 +08:00
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/sched/mm.h>
|
2014-07-17 05:45:35 +08:00
|
|
|
#include "kfd_priv.h"
|
|
|
|
#include "kfd_mqd_manager.h"
|
|
|
|
|
|
|
|
|
|
|
|
struct device_process_node {
|
|
|
|
struct qcm_process_device *qpd;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
2014-07-17 06:27:00 +08:00
|
|
|
/**
|
2015-01-12 20:26:10 +08:00
|
|
|
* struct device_queue_manager_ops
|
2014-07-17 06:27:00 +08:00
|
|
|
*
|
|
|
|
* @create_queue: Queue creation routine.
|
|
|
|
*
|
|
|
|
* @destroy_queue: Queue destruction routine.
|
|
|
|
*
|
|
|
|
* @update_queue: Queue update routine.
|
|
|
|
*
|
|
|
|
* @exeute_queues: Dispatches the queues list to the H/W.
|
|
|
|
*
|
|
|
|
* @register_process: This routine associates a specific process with device.
|
|
|
|
*
|
|
|
|
* @unregister_process: destroys the associations between process to device.
|
|
|
|
*
|
|
|
|
* @initialize: Initializes the pipelines and memory module for that device.
|
|
|
|
*
|
|
|
|
* @start: Initializes the resources/modules the the device needs for queues
|
|
|
|
* execution. This function is called on device initialization and after the
|
|
|
|
* system woke up after suspension.
|
|
|
|
*
|
|
|
|
* @stop: This routine stops execution of all the active queue running on the
|
|
|
|
* H/W and basically this function called on system suspend.
|
|
|
|
*
|
|
|
|
* @uninitialize: Destroys all the device queue manager resources allocated in
|
|
|
|
* initialize routine.
|
|
|
|
*
|
|
|
|
* @create_kernel_queue: Creates kernel queue. Used for debug queue.
|
|
|
|
*
|
|
|
|
* @destroy_kernel_queue: Destroys kernel queue. Used for debug queue.
|
|
|
|
*
|
|
|
|
* @set_cache_memory_policy: Sets memory policy (cached/ non cached) for the
|
|
|
|
* memory apertures.
|
|
|
|
*
|
2017-09-27 12:09:52 +08:00
|
|
|
* @process_termination: Clears all process queues belongs to that device.
|
|
|
|
*
|
2018-02-07 09:32:45 +08:00
|
|
|
* @evict_process_queues: Evict all active queues of a process
|
|
|
|
*
|
|
|
|
* @restore_process_queues: Restore all evicted queues queues of a process
|
|
|
|
*
|
2017-05-03 06:39:37 +08:00
|
|
|
* @get_wave_state: Retrieves context save state and optionally copies the
|
|
|
|
* control stack, if kept in the MQD, to the given userspace address.
|
2014-07-17 06:27:00 +08:00
|
|
|
*/
|
|
|
|
|
2015-01-12 20:26:10 +08:00
|
|
|
struct device_queue_manager_ops {
|
2014-07-17 05:45:35 +08:00
|
|
|
int (*create_queue)(struct device_queue_manager *dqm,
|
|
|
|
struct queue *q,
|
2017-11-25 07:10:54 +08:00
|
|
|
struct qcm_process_device *qpd);
|
2015-05-20 18:43:04 +08:00
|
|
|
|
2014-07-17 05:45:35 +08:00
|
|
|
int (*destroy_queue)(struct device_queue_manager *dqm,
|
|
|
|
struct qcm_process_device *qpd,
|
|
|
|
struct queue *q);
|
2015-05-20 18:43:04 +08:00
|
|
|
|
2014-07-17 05:45:35 +08:00
|
|
|
int (*update_queue)(struct device_queue_manager *dqm,
|
|
|
|
struct queue *q);
|
2014-07-17 06:27:00 +08:00
|
|
|
|
2014-07-17 05:45:35 +08:00
|
|
|
int (*register_process)(struct device_queue_manager *dqm,
|
|
|
|
struct qcm_process_device *qpd);
|
2015-05-20 18:43:04 +08:00
|
|
|
|
2014-07-17 05:45:35 +08:00
|
|
|
int (*unregister_process)(struct device_queue_manager *dqm,
|
|
|
|
struct qcm_process_device *qpd);
|
2015-05-20 18:43:04 +08:00
|
|
|
|
2014-07-17 05:45:35 +08:00
|
|
|
int (*initialize)(struct device_queue_manager *dqm);
|
|
|
|
int (*start)(struct device_queue_manager *dqm);
|
|
|
|
int (*stop)(struct device_queue_manager *dqm);
|
|
|
|
void (*uninitialize)(struct device_queue_manager *dqm);
|
|
|
|
int (*create_kernel_queue)(struct device_queue_manager *dqm,
|
|
|
|
struct kernel_queue *kq,
|
|
|
|
struct qcm_process_device *qpd);
|
2015-05-20 18:43:04 +08:00
|
|
|
|
2014-07-17 05:45:35 +08:00
|
|
|
void (*destroy_kernel_queue)(struct device_queue_manager *dqm,
|
|
|
|
struct kernel_queue *kq,
|
|
|
|
struct qcm_process_device *qpd);
|
2015-05-20 18:43:04 +08:00
|
|
|
|
2014-07-17 05:45:35 +08:00
|
|
|
bool (*set_cache_memory_policy)(struct device_queue_manager *dqm,
|
|
|
|
struct qcm_process_device *qpd,
|
|
|
|
enum cache_policy default_policy,
|
|
|
|
enum cache_policy alternate_policy,
|
|
|
|
void __user *alternate_aperture_base,
|
|
|
|
uint64_t alternate_aperture_size);
|
2017-09-27 12:09:52 +08:00
|
|
|
|
2017-11-15 05:41:20 +08:00
|
|
|
int (*set_trap_handler)(struct device_queue_manager *dqm,
|
|
|
|
struct qcm_process_device *qpd,
|
|
|
|
uint64_t tba_addr,
|
|
|
|
uint64_t tma_addr);
|
|
|
|
|
2017-09-27 12:09:52 +08:00
|
|
|
int (*process_termination)(struct device_queue_manager *dqm,
|
|
|
|
struct qcm_process_device *qpd);
|
2018-02-07 09:32:45 +08:00
|
|
|
|
|
|
|
int (*evict_process_queues)(struct device_queue_manager *dqm,
|
|
|
|
struct qcm_process_device *qpd);
|
|
|
|
int (*restore_process_queues)(struct device_queue_manager *dqm,
|
|
|
|
struct qcm_process_device *qpd);
|
2017-05-03 06:39:37 +08:00
|
|
|
|
|
|
|
int (*get_wave_state)(struct device_queue_manager *dqm,
|
|
|
|
struct queue *q,
|
|
|
|
void __user *ctl_stack,
|
|
|
|
u32 *ctl_stack_used_size,
|
|
|
|
u32 *save_area_used_size);
|
2015-01-12 20:26:10 +08:00
|
|
|
};
|
|
|
|
|
2015-05-05 16:51:31 +08:00
|
|
|
struct device_queue_manager_asic_ops {
|
2017-11-02 07:21:31 +08:00
|
|
|
int (*update_qpd)(struct device_queue_manager *dqm,
|
2015-05-05 16:51:31 +08:00
|
|
|
struct qcm_process_device *qpd);
|
|
|
|
bool (*set_cache_memory_policy)(struct device_queue_manager *dqm,
|
|
|
|
struct qcm_process_device *qpd,
|
|
|
|
enum cache_policy default_policy,
|
|
|
|
enum cache_policy alternate_policy,
|
|
|
|
void __user *alternate_aperture_base,
|
|
|
|
uint64_t alternate_aperture_size);
|
2015-05-05 16:51:39 +08:00
|
|
|
void (*init_sdma_vm)(struct device_queue_manager *dqm,
|
|
|
|
struct queue *q,
|
|
|
|
struct qcm_process_device *qpd);
|
2018-12-04 03:56:14 +08:00
|
|
|
struct mqd_manager * (*mqd_manager_init)(enum KFD_MQD_TYPE type,
|
|
|
|
struct kfd_dev *dev);
|
2015-05-05 16:51:31 +08:00
|
|
|
};
|
|
|
|
|
2015-01-12 20:26:10 +08:00
|
|
|
/**
|
|
|
|
* struct device_queue_manager
|
|
|
|
*
|
|
|
|
* This struct is a base class for the kfd queues scheduler in the
|
|
|
|
* device level. The device base class should expose the basic operations
|
|
|
|
* for queue creation and queue destruction. This base class hides the
|
|
|
|
* scheduling mode of the driver and the specific implementation of the
|
|
|
|
* concrete device. This class is the only class in the queues scheduler
|
|
|
|
* that configures the H/W.
|
|
|
|
*
|
|
|
|
*/
|
2014-07-17 05:45:35 +08:00
|
|
|
|
2015-01-12 20:26:10 +08:00
|
|
|
struct device_queue_manager {
|
|
|
|
struct device_queue_manager_ops ops;
|
2017-11-02 07:21:31 +08:00
|
|
|
struct device_queue_manager_asic_ops asic_ops;
|
2014-07-17 05:45:35 +08:00
|
|
|
|
2018-07-12 10:33:07 +08:00
|
|
|
struct mqd_manager *mqd_mgrs[KFD_MQD_TYPE_MAX];
|
2014-07-17 05:45:35 +08:00
|
|
|
struct packet_manager packets;
|
|
|
|
struct kfd_dev *dev;
|
2018-07-12 10:32:44 +08:00
|
|
|
struct mutex lock_hidden; /* use dqm_lock/unlock(dqm) */
|
2014-07-17 05:45:35 +08:00
|
|
|
struct list_head queues;
|
2018-07-12 10:32:44 +08:00
|
|
|
unsigned int saved_flags;
|
2014-07-17 05:45:35 +08:00
|
|
|
unsigned int processes_count;
|
|
|
|
unsigned int queue_count;
|
2015-01-04 04:12:32 +08:00
|
|
|
unsigned int sdma_queue_count;
|
2019-02-08 04:02:27 +08:00
|
|
|
unsigned int xgmi_sdma_queue_count;
|
2015-01-18 19:18:01 +08:00
|
|
|
unsigned int total_queue_count;
|
2014-07-17 05:45:35 +08:00
|
|
|
unsigned int next_pipe_to_allocate;
|
|
|
|
unsigned int *allocated_queues;
|
2018-11-01 23:06:25 +08:00
|
|
|
uint64_t sdma_bitmap;
|
2019-02-08 04:02:27 +08:00
|
|
|
uint64_t xgmi_sdma_bitmap;
|
2014-07-17 05:45:35 +08:00
|
|
|
unsigned int vmid_bitmap;
|
|
|
|
uint64_t pipelines_addr;
|
|
|
|
struct kfd_mem_obj *pipeline_mem;
|
|
|
|
uint64_t fence_gpu_addr;
|
|
|
|
unsigned int *fence_addr;
|
|
|
|
struct kfd_mem_obj *fence_mem;
|
|
|
|
bool active_runlist;
|
2018-01-05 06:17:43 +08:00
|
|
|
int sched_policy;
|
2018-07-12 10:32:58 +08:00
|
|
|
|
|
|
|
/* hw exception */
|
|
|
|
bool is_hws_hang;
|
|
|
|
struct work_struct hw_exception_work;
|
2018-11-28 11:58:54 +08:00
|
|
|
struct kfd_mem_obj hiq_sdma_mqd;
|
2014-07-17 05:45:35 +08:00
|
|
|
};
|
|
|
|
|
2017-11-02 07:21:31 +08:00
|
|
|
void device_queue_manager_init_cik(
|
|
|
|
struct device_queue_manager_asic_ops *asic_ops);
|
2018-01-05 06:17:44 +08:00
|
|
|
void device_queue_manager_init_cik_hawaii(
|
|
|
|
struct device_queue_manager_asic_ops *asic_ops);
|
2017-11-02 07:21:31 +08:00
|
|
|
void device_queue_manager_init_vi(
|
|
|
|
struct device_queue_manager_asic_ops *asic_ops);
|
2018-01-05 06:17:44 +08:00
|
|
|
void device_queue_manager_init_vi_tonga(
|
|
|
|
struct device_queue_manager_asic_ops *asic_ops);
|
2018-04-11 05:33:09 +08:00
|
|
|
void device_queue_manager_init_v9(
|
|
|
|
struct device_queue_manager_asic_ops *asic_ops);
|
2019-05-30 12:03:45 +08:00
|
|
|
void device_queue_manager_init_v10_navi10(
|
|
|
|
struct device_queue_manager_asic_ops *asic_ops);
|
2015-01-12 20:28:46 +08:00
|
|
|
void program_sh_mem_settings(struct device_queue_manager *dqm,
|
|
|
|
struct qcm_process_device *qpd);
|
2017-02-04 05:28:48 +08:00
|
|
|
unsigned int get_queues_num(struct device_queue_manager *dqm);
|
|
|
|
unsigned int get_queues_per_pipe(struct device_queue_manager *dqm);
|
|
|
|
unsigned int get_pipes_per_mec(struct device_queue_manager *dqm);
|
2018-07-14 04:17:44 +08:00
|
|
|
unsigned int get_num_sdma_queues(struct device_queue_manager *dqm);
|
2019-02-08 04:02:27 +08:00
|
|
|
unsigned int get_num_xgmi_sdma_queues(struct device_queue_manager *dqm);
|
2015-01-22 19:42:28 +08:00
|
|
|
|
2016-06-21 17:10:26 +08:00
|
|
|
static inline unsigned int get_sh_mem_bases_32(struct kfd_process_device *pdd)
|
2015-01-22 19:42:28 +08:00
|
|
|
{
|
|
|
|
return (pdd->lds_base >> 16) & 0xFF;
|
|
|
|
}
|
|
|
|
|
2016-06-21 17:10:26 +08:00
|
|
|
static inline unsigned int
|
2015-01-22 19:42:28 +08:00
|
|
|
get_sh_mem_bases_nybble_64(struct kfd_process_device *pdd)
|
|
|
|
{
|
|
|
|
return (pdd->lds_base >> 60) & 0x0E;
|
|
|
|
}
|
|
|
|
|
2018-07-12 10:32:44 +08:00
|
|
|
/* The DQM lock can be taken in MMU notifiers. Make sure no reclaim-FS
|
|
|
|
* happens while holding this lock anywhere to prevent deadlocks when
|
|
|
|
* an MMU notifier runs in reclaim-FS context.
|
|
|
|
*/
|
|
|
|
static inline void dqm_lock(struct device_queue_manager *dqm)
|
|
|
|
{
|
|
|
|
mutex_lock(&dqm->lock_hidden);
|
|
|
|
dqm->saved_flags = memalloc_nofs_save();
|
|
|
|
}
|
|
|
|
static inline void dqm_unlock(struct device_queue_manager *dqm)
|
|
|
|
{
|
|
|
|
memalloc_nofs_restore(dqm->saved_flags);
|
|
|
|
mutex_unlock(&dqm->lock_hidden);
|
|
|
|
}
|
|
|
|
|
2014-07-17 05:45:35 +08:00
|
|
|
#endif /* KFD_DEVICE_QUEUE_MANAGER_H_ */
|