#include <linux/mutex.h>
#include <linux/log2.h>
#include <linux/sched.h>
#include <linux/sched/mm.h>
#include <linux/sched/task.h>
#include <linux/mmu_context.h>
#include <linux/slab.h>
#include <linux/notifier.h>
#include <linux/compat.h>
#include <linux/mman.h>
#include <linux/file.h>
#include <linux/pm_runtime.h>
#include "amdgpu_amdkfd.h"
#include "amdgpu.h"
struct mm_struct;
#include "kfd_priv.h"
#include "kfd_device_queue_manager.h"
#include "kfd_svm.h"
#include "kfd_smi_events.h"
#include "kfd_debug.h"
DEFINE_HASHTABLE(kfd_processes_table, KFD_PROCESS_TABLE_SIZE);
DEFINE_MUTEX(…) …;
DEFINE_SRCU(…);
static struct workqueue_struct *kfd_process_wq;
static struct workqueue_struct *kfd_restore_wq;
static struct kfd_process *find_process(const struct task_struct *thread,
bool ref);
static void kfd_process_ref_release(struct kref *ref);
static struct kfd_process *create_process(const struct task_struct *thread);
static void evict_process_worker(struct work_struct *work);
static void restore_process_worker(struct work_struct *work);
static void kfd_process_device_destroy_cwsr_dgpu(struct kfd_process_device *pdd);
struct kfd_procfs_tree { … };
static struct kfd_procfs_tree procfs;
struct kfd_sdma_activity_handler_workarea { … };
struct temp_sdma_queue_list { … };
static void kfd_sdma_activity_worker(struct work_struct *work)
{ … }
static int kfd_get_cu_occupancy(struct attribute *attr, char *buffer)
{ … }
static ssize_t kfd_procfs_show(struct kobject *kobj, struct attribute *attr,
char *buffer)
{ … }
static void kfd_procfs_kobj_release(struct kobject *kobj)
{ … }
static const struct sysfs_ops kfd_procfs_ops = …;
static const struct kobj_type procfs_type = …;
void kfd_procfs_init(void)
{ … }
void kfd_procfs_shutdown(void)
{ … }
static ssize_t kfd_procfs_queue_show(struct kobject *kobj,
struct attribute *attr, char *buffer)
{ … }
static ssize_t kfd_procfs_stats_show(struct kobject *kobj,
struct attribute *attr, char *buffer)
{ … }
static ssize_t kfd_sysfs_counters_show(struct kobject *kobj,
struct attribute *attr, char *buf)
{ … }
static struct attribute attr_queue_size = …;
static struct attribute attr_queue_type = …;
static struct attribute attr_queue_gpuid = …;
static struct attribute *procfs_queue_attrs[] = …;
ATTRIBUTE_GROUPS(…);
static const struct sysfs_ops procfs_queue_ops = …;
static const struct kobj_type procfs_queue_type = …;
static const struct sysfs_ops procfs_stats_ops = …;
static const struct kobj_type procfs_stats_type = …;
static const struct sysfs_ops sysfs_counters_ops = …;
static const struct kobj_type sysfs_counters_type = …;
int kfd_procfs_add_queue(struct queue *q)
{ … }
static void kfd_sysfs_create_file(struct kobject *kobj, struct attribute *attr,
char *name)
{ … }
static void kfd_procfs_add_sysfs_stats(struct kfd_process *p)
{ … }
static void kfd_procfs_add_sysfs_counters(struct kfd_process *p)
{ … }
static void kfd_procfs_add_sysfs_files(struct kfd_process *p)
{ … }
void kfd_procfs_del_queue(struct queue *q)
{ … }
int kfd_process_create_wq(void)
{ … }
void kfd_process_destroy_wq(void)
{ … }
static void kfd_process_free_gpuvm(struct kgd_mem *mem,
struct kfd_process_device *pdd, void **kptr)
{ … }
static int kfd_process_alloc_gpuvm(struct kfd_process_device *pdd,
uint64_t gpu_va, uint32_t size,
uint32_t flags, struct kgd_mem **mem, void **kptr)
{ … }
static int kfd_process_device_reserve_ib_mem(struct kfd_process_device *pdd)
{ … }
static void kfd_process_device_destroy_ib_mem(struct kfd_process_device *pdd)
{ … }
struct kfd_process *kfd_create_process(struct task_struct *thread)
{ … }
struct kfd_process *kfd_get_process(const struct task_struct *thread)
{ … }
static struct kfd_process *find_process_by_mm(const struct mm_struct *mm)
{ … }
static struct kfd_process *find_process(const struct task_struct *thread,
bool ref)
{ … }
void kfd_unref_process(struct kfd_process *p)
{ … }
struct kfd_process *kfd_lookup_process_by_pid(struct pid *pid)
{ … }
static void kfd_process_device_free_bos(struct kfd_process_device *pdd)
{ … }
static void kfd_process_kunmap_signal_bo(struct kfd_process *p)
{ … }
static void kfd_process_free_outstanding_kfd_bos(struct kfd_process *p)
{ … }
static void kfd_process_destroy_pdds(struct kfd_process *p)
{ … }
static void kfd_process_remove_sysfs(struct kfd_process *p)
{ … }
static void kfd_process_wq_release(struct work_struct *work)
{ … }
static void kfd_process_ref_release(struct kref *ref)
{ … }
static struct mmu_notifier *kfd_process_alloc_notifier(struct mm_struct *mm)
{ … }
static void kfd_process_free_notifier(struct mmu_notifier *mn)
{ … }
static void kfd_process_notifier_release_internal(struct kfd_process *p)
{ … }
static void kfd_process_notifier_release(struct mmu_notifier *mn,
struct mm_struct *mm)
{ … }
static const struct mmu_notifier_ops kfd_process_mmu_notifier_ops = …;
void kfd_cleanup_processes(void)
{ … }
int kfd_process_init_cwsr_apu(struct kfd_process *p, struct file *filep)
{ … }
static int kfd_process_device_init_cwsr_dgpu(struct kfd_process_device *pdd)
{ … }
static void kfd_process_device_destroy_cwsr_dgpu(struct kfd_process_device *pdd)
{ … }
void kfd_process_set_trap_handler(struct qcm_process_device *qpd,
uint64_t tba_addr,
uint64_t tma_addr)
{ … }
bool kfd_process_xnack_mode(struct kfd_process *p, bool supported)
{ … }
void kfd_process_set_trap_debug_flag(struct qcm_process_device *qpd,
bool enabled)
{ … }
static struct kfd_process *create_process(const struct task_struct *thread)
{ … }
struct kfd_process_device *kfd_get_process_device_data(struct kfd_node *dev,
struct kfd_process *p)
{ … }
struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev,
struct kfd_process *p)
{ … }
int kfd_process_device_init_vm(struct kfd_process_device *pdd,
struct file *drm_file)
{ … }
struct kfd_process_device *kfd_bind_process_to_device(struct kfd_node *dev,
struct kfd_process *p)
{ … }
int kfd_process_device_create_obj_handle(struct kfd_process_device *pdd,
void *mem)
{ … }
void *kfd_process_device_translate_handle(struct kfd_process_device *pdd,
int handle)
{ … }
void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,
int handle)
{ … }
struct kfd_process *kfd_lookup_process_by_pasid(u32 pasid)
{ … }
struct kfd_process *kfd_lookup_process_by_mm(const struct mm_struct *mm)
{ … }
int kfd_process_evict_queues(struct kfd_process *p, uint32_t trigger)
{ … }
int kfd_process_restore_queues(struct kfd_process *p)
{ … }
int kfd_process_gpuidx_from_gpuid(struct kfd_process *p, uint32_t gpu_id)
{ … }
int
kfd_process_gpuid_from_node(struct kfd_process *p, struct kfd_node *node,
uint32_t *gpuid, uint32_t *gpuidx)
{ … }
static int signal_eviction_fence(struct kfd_process *p)
{ … }
static void evict_process_worker(struct work_struct *work)
{ … }
static int restore_process_helper(struct kfd_process *p)
{ … }
static void restore_process_worker(struct work_struct *work)
{ … }
void kfd_suspend_all_processes(void)
{ … }
int kfd_resume_all_processes(void)
{ … }
int kfd_reserved_mem_mmap(struct kfd_node *dev, struct kfd_process *process,
struct vm_area_struct *vma)
{ … }
int kfd_process_drain_interrupts(struct kfd_process_device *pdd)
{ … }
void kfd_process_close_interrupt_drain(unsigned int pasid)
{ … }
struct send_exception_work_handler_workarea { … };
static void send_exception_work_handler(struct work_struct *work)
{ … }
int kfd_send_exception_to_runtime(struct kfd_process *p,
unsigned int queue_id,
uint64_t error_reason)
{ … }
struct kfd_process_device *kfd_process_device_data_by_id(struct kfd_process *p, uint32_t gpu_id)
{ … }
int kfd_process_get_user_gpu_id(struct kfd_process *p, uint32_t actual_gpu_id)
{ … }
#if defined(CONFIG_DEBUG_FS)
int kfd_debugfs_mqds_by_process(struct seq_file *m, void *data)
{ … }
#endif