18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2017 Advanced Micro Devices, Inc.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_ci#ifndef __AMDGPU_IDS_H__
248c2ecf20Sopenharmony_ci#define __AMDGPU_IDS_H__
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include <linux/types.h>
278c2ecf20Sopenharmony_ci#include <linux/mutex.h>
288c2ecf20Sopenharmony_ci#include <linux/list.h>
298c2ecf20Sopenharmony_ci#include <linux/dma-fence.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#include "amdgpu_sync.h"
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/* maximum number of VMIDs */
348c2ecf20Sopenharmony_ci#define AMDGPU_NUM_VMID	16
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistruct amdgpu_device;
378c2ecf20Sopenharmony_cistruct amdgpu_vm;
388c2ecf20Sopenharmony_cistruct amdgpu_ring;
398c2ecf20Sopenharmony_cistruct amdgpu_sync;
408c2ecf20Sopenharmony_cistruct amdgpu_job;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct amdgpu_vmid {
438c2ecf20Sopenharmony_ci	struct list_head	list;
448c2ecf20Sopenharmony_ci	struct amdgpu_sync	active;
458c2ecf20Sopenharmony_ci	struct dma_fence	*last_flush;
468c2ecf20Sopenharmony_ci	uint64_t		owner;
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	uint64_t		pd_gpu_addr;
498c2ecf20Sopenharmony_ci	/* last flushed PD/PT update */
508c2ecf20Sopenharmony_ci	struct dma_fence	*flushed_updates;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	uint32_t                current_gpu_reset_count;
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	uint32_t		gds_base;
558c2ecf20Sopenharmony_ci	uint32_t		gds_size;
568c2ecf20Sopenharmony_ci	uint32_t		gws_base;
578c2ecf20Sopenharmony_ci	uint32_t		gws_size;
588c2ecf20Sopenharmony_ci	uint32_t		oa_base;
598c2ecf20Sopenharmony_ci	uint32_t		oa_size;
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	unsigned		pasid;
628c2ecf20Sopenharmony_ci	struct dma_fence	*pasid_mapping;
638c2ecf20Sopenharmony_ci};
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_cistruct amdgpu_vmid_mgr {
668c2ecf20Sopenharmony_ci	struct mutex		lock;
678c2ecf20Sopenharmony_ci	unsigned		num_ids;
688c2ecf20Sopenharmony_ci	struct list_head	ids_lru;
698c2ecf20Sopenharmony_ci	struct amdgpu_vmid	ids[AMDGPU_NUM_VMID];
708c2ecf20Sopenharmony_ci	atomic_t		reserved_vmid_num;
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ciint amdgpu_pasid_alloc(unsigned int bits);
748c2ecf20Sopenharmony_civoid amdgpu_pasid_free(u32 pasid);
758c2ecf20Sopenharmony_civoid amdgpu_pasid_free_delayed(struct dma_resv *resv,
768c2ecf20Sopenharmony_ci			       u32 pasid);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cibool amdgpu_vmid_had_gpu_reset(struct amdgpu_device *adev,
798c2ecf20Sopenharmony_ci			       struct amdgpu_vmid *id);
808c2ecf20Sopenharmony_ciint amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev,
818c2ecf20Sopenharmony_ci			       struct amdgpu_vm *vm,
828c2ecf20Sopenharmony_ci			       unsigned vmhub);
838c2ecf20Sopenharmony_civoid amdgpu_vmid_free_reserved(struct amdgpu_device *adev,
848c2ecf20Sopenharmony_ci			       struct amdgpu_vm *vm,
858c2ecf20Sopenharmony_ci			       unsigned vmhub);
868c2ecf20Sopenharmony_ciint amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
878c2ecf20Sopenharmony_ci		     struct amdgpu_sync *sync, struct dma_fence *fence,
888c2ecf20Sopenharmony_ci		     struct amdgpu_job *job);
898c2ecf20Sopenharmony_civoid amdgpu_vmid_reset(struct amdgpu_device *adev, unsigned vmhub,
908c2ecf20Sopenharmony_ci		       unsigned vmid);
918c2ecf20Sopenharmony_civoid amdgpu_vmid_reset_all(struct amdgpu_device *adev);
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_civoid amdgpu_vmid_mgr_init(struct amdgpu_device *adev);
948c2ecf20Sopenharmony_civoid amdgpu_vmid_mgr_fini(struct amdgpu_device *adev);
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#endif
97