142a66677SAlex Deucher /* SPDX-License-Identifier: MIT */ 242a66677SAlex Deucher /* 342a66677SAlex Deucher * Copyright 2023 Advanced Micro Devices, Inc. 442a66677SAlex Deucher * 542a66677SAlex Deucher * Permission is hereby granted, free of charge, to any person obtaining a 642a66677SAlex Deucher * copy of this software and associated documentation files (the "Software"), 742a66677SAlex Deucher * to deal in the Software without restriction, including without limitation 842a66677SAlex Deucher * the rights to use, copy, modify, merge, publish, distribute, sublicense, 942a66677SAlex Deucher * and/or sell copies of the Software, and to permit persons to whom the 1042a66677SAlex Deucher * Software is furnished to do so, subject to the following conditions: 1142a66677SAlex Deucher * 1242a66677SAlex Deucher * The above copyright notice and this permission notice shall be included in 1342a66677SAlex Deucher * all copies or substantial portions of the Software. 1442a66677SAlex Deucher * 1542a66677SAlex Deucher * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1642a66677SAlex Deucher * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1742a66677SAlex Deucher * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1842a66677SAlex Deucher * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 1942a66677SAlex Deucher * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 2042a66677SAlex Deucher * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2142a66677SAlex Deucher * OTHER DEALINGS IN THE SOFTWARE. 2242a66677SAlex Deucher * 2342a66677SAlex Deucher */ 2442a66677SAlex Deucher 2542a66677SAlex Deucher #ifndef AMDGPU_USERQ_H_ 2642a66677SAlex Deucher #define AMDGPU_USERQ_H_ 2742a66677SAlex Deucher #include "amdgpu_eviction_fence.h" 2842a66677SAlex Deucher 2942a66677SAlex Deucher #define AMDGPU_MAX_USERQ_COUNT 512 3042a66677SAlex Deucher 3142a66677SAlex Deucher #define to_ev_fence(f) container_of(f, struct amdgpu_eviction_fence, base) 3242a66677SAlex Deucher #define uq_mgr_to_fpriv(u) container_of(u, struct amdgpu_fpriv, userq_mgr) 3342a66677SAlex Deucher #define work_to_uq_mgr(w, name) container_of(w, struct amdgpu_userq_mgr, name) 3442a66677SAlex Deucher 3542a66677SAlex Deucher enum amdgpu_userq_state { 3642a66677SAlex Deucher AMDGPU_USERQ_STATE_UNMAPPED = 0, 3742a66677SAlex Deucher AMDGPU_USERQ_STATE_MAPPED, 3842a66677SAlex Deucher AMDGPU_USERQ_STATE_PREEMPTED, 3942a66677SAlex Deucher AMDGPU_USERQ_STATE_HUNG, 4042a66677SAlex Deucher }; 4142a66677SAlex Deucher 4242a66677SAlex Deucher struct amdgpu_mqd_prop; 4342a66677SAlex Deucher 4442a66677SAlex Deucher struct amdgpu_userq_obj { 4542a66677SAlex Deucher void *cpu_ptr; 4642a66677SAlex Deucher uint64_t gpu_addr; 4742a66677SAlex Deucher struct amdgpu_bo *obj; 4842a66677SAlex Deucher }; 4942a66677SAlex Deucher 5042a66677SAlex Deucher struct amdgpu_usermode_queue { 5142a66677SAlex Deucher int queue_type; 5242a66677SAlex Deucher enum amdgpu_userq_state state; 5342a66677SAlex Deucher uint64_t doorbell_handle; 5442a66677SAlex Deucher uint64_t doorbell_index; 5542a66677SAlex Deucher uint64_t flags; 5642a66677SAlex Deucher struct amdgpu_mqd_prop *userq_prop; 5742a66677SAlex Deucher struct amdgpu_userq_mgr *userq_mgr; 5842a66677SAlex Deucher struct amdgpu_vm *vm; 5942a66677SAlex Deucher struct amdgpu_userq_obj mqd; 6042a66677SAlex Deucher struct amdgpu_userq_obj db_obj; 6142a66677SAlex Deucher struct amdgpu_userq_obj fw_obj; 6242a66677SAlex Deucher struct amdgpu_userq_obj wptr_obj; 6342a66677SAlex Deucher struct xarray fence_drv_xa; 6442a66677SAlex Deucher struct amdgpu_userq_fence_driver *fence_drv; 6542a66677SAlex Deucher struct dma_fence *last_fence; 6642a66677SAlex Deucher u32 xcp_id; 6742a66677SAlex Deucher int priority; 6842a66677SAlex Deucher }; 6942a66677SAlex Deucher 7042a66677SAlex Deucher struct amdgpu_userq_funcs { 7142a66677SAlex Deucher int (*mqd_create)(struct amdgpu_userq_mgr *uq_mgr, 7242a66677SAlex Deucher struct drm_amdgpu_userq_in *args, 7342a66677SAlex Deucher struct amdgpu_usermode_queue *queue); 7442a66677SAlex Deucher void (*mqd_destroy)(struct amdgpu_userq_mgr *uq_mgr, 7542a66677SAlex Deucher struct amdgpu_usermode_queue *uq); 7642a66677SAlex Deucher int (*unmap)(struct amdgpu_userq_mgr *uq_mgr, 7742a66677SAlex Deucher struct amdgpu_usermode_queue *queue); 7842a66677SAlex Deucher int (*map)(struct amdgpu_userq_mgr *uq_mgr, 7942a66677SAlex Deucher struct amdgpu_usermode_queue *queue); 8042a66677SAlex Deucher }; 8142a66677SAlex Deucher 8242a66677SAlex Deucher /* Usermode queues for gfx */ 8342a66677SAlex Deucher struct amdgpu_userq_mgr { 8442a66677SAlex Deucher struct idr userq_idr; 8542a66677SAlex Deucher struct mutex userq_mutex; 8642a66677SAlex Deucher struct amdgpu_device *adev; 8742a66677SAlex Deucher struct delayed_work resume_work; 8842a66677SAlex Deucher struct list_head list; 89*30ff7580SSunil Khatri struct drm_file *file; 9042a66677SAlex Deucher }; 9142a66677SAlex Deucher 9242a66677SAlex Deucher struct amdgpu_db_info { 9342a66677SAlex Deucher uint64_t doorbell_handle; 9442a66677SAlex Deucher uint32_t queue_type; 9542a66677SAlex Deucher uint32_t doorbell_offset; 9642a66677SAlex Deucher struct amdgpu_userq_obj *db_obj; 9742a66677SAlex Deucher }; 9842a66677SAlex Deucher 9942a66677SAlex Deucher int amdgpu_userq_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 10042a66677SAlex Deucher 101*30ff7580SSunil Khatri int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *file_priv, 102*30ff7580SSunil Khatri struct amdgpu_device *adev); 10342a66677SAlex Deucher 10442a66677SAlex Deucher void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr); 10542a66677SAlex Deucher 10642a66677SAlex Deucher int amdgpu_userq_create_object(struct amdgpu_userq_mgr *uq_mgr, 10742a66677SAlex Deucher struct amdgpu_userq_obj *userq_obj, 10842a66677SAlex Deucher int size); 10942a66677SAlex Deucher 11042a66677SAlex Deucher void amdgpu_userq_destroy_object(struct amdgpu_userq_mgr *uq_mgr, 11142a66677SAlex Deucher struct amdgpu_userq_obj *userq_obj); 11242a66677SAlex Deucher 11342a66677SAlex Deucher void amdgpu_userq_evict(struct amdgpu_userq_mgr *uq_mgr, 11442a66677SAlex Deucher struct amdgpu_eviction_fence *ev_fence); 11542a66677SAlex Deucher 11642a66677SAlex Deucher int amdgpu_userq_active(struct amdgpu_userq_mgr *uq_mgr); 11742a66677SAlex Deucher 11842a66677SAlex Deucher void amdgpu_userq_ensure_ev_fence(struct amdgpu_userq_mgr *userq_mgr, 11942a66677SAlex Deucher struct amdgpu_eviction_fence_mgr *evf_mgr); 12042a66677SAlex Deucher 12142a66677SAlex Deucher uint64_t amdgpu_userq_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr, 12242a66677SAlex Deucher struct amdgpu_db_info *db_info, 12342a66677SAlex Deucher struct drm_file *filp); 12442a66677SAlex Deucher 12542a66677SAlex Deucher u32 amdgpu_userq_get_supported_ip_mask(struct amdgpu_device *adev); 12642a66677SAlex Deucher 12742a66677SAlex Deucher int amdgpu_userq_suspend(struct amdgpu_device *adev); 12842a66677SAlex Deucher int amdgpu_userq_resume(struct amdgpu_device *adev); 12942a66677SAlex Deucher 13042a66677SAlex Deucher int amdgpu_userq_stop_sched_for_enforce_isolation(struct amdgpu_device *adev, 13142a66677SAlex Deucher u32 idx); 13242a66677SAlex Deucher int amdgpu_userq_start_sched_for_enforce_isolation(struct amdgpu_device *adev, 13342a66677SAlex Deucher u32 idx); 13442a66677SAlex Deucher 13542a66677SAlex Deucher #endif 136