1050d9d43SChristian König /*
2050d9d43SChristian König * Copyright 2018 Advanced Micro Devices, Inc.
3050d9d43SChristian König *
4050d9d43SChristian König * Permission is hereby granted, free of charge, to any person obtaining a
5050d9d43SChristian König * copy of this software and associated documentation files (the "Software"),
6050d9d43SChristian König * to deal in the Software without restriction, including without limitation
7050d9d43SChristian König * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8050d9d43SChristian König * and/or sell copies of the Software, and to permit persons to whom the
9050d9d43SChristian König * Software is furnished to do so, subject to the following conditions:
10050d9d43SChristian König *
11050d9d43SChristian König * The above copyright notice and this permission notice shall be included in
12050d9d43SChristian König * all copies or substantial portions of the Software.
13050d9d43SChristian König *
14050d9d43SChristian König * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15050d9d43SChristian König * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16050d9d43SChristian König * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17050d9d43SChristian König * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18050d9d43SChristian König * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19050d9d43SChristian König * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20050d9d43SChristian König * OTHER DEALINGS IN THE SOFTWARE.
21050d9d43SChristian König *
22050d9d43SChristian König */
23050d9d43SChristian König #ifndef __AMDGPU_JOB_H__
24050d9d43SChristian König #define __AMDGPU_JOB_H__
25050d9d43SChristian König
26a190f8dcSChristian König #include <drm/gpu_scheduler.h>
27a190f8dcSChristian König #include "amdgpu_sync.h"
286103b2f2SChristian König #include "amdgpu_ring.h"
29a190f8dcSChristian König
30050d9d43SChristian König /* bit set means command submit involves a preamble IB */
31050d9d43SChristian König #define AMDGPU_PREAMBLE_IB_PRESENT (1 << 0)
32050d9d43SChristian König /* bit set means preamble IB is first presented in belonging context */
33050d9d43SChristian König #define AMDGPU_PREAMBLE_IB_PRESENT_FIRST (1 << 1)
34050d9d43SChristian König /* bit set means context switch occured */
35050d9d43SChristian König #define AMDGPU_HAVE_CTX_SWITCH (1 << 2)
36d8780dc7SJack Xiao /* bit set means IB is preempted */
37d8780dc7SJack Xiao #define AMDGPU_IB_PREEMPTED (1 << 3)
38050d9d43SChristian König
39050d9d43SChristian König #define to_amdgpu_job(sched_job) \
40050d9d43SChristian König container_of((sched_job), struct amdgpu_job, base)
41050d9d43SChristian König
4234955e03SRex Zhu #define AMDGPU_JOB_GET_VMID(job) ((job) ? (job)->vmid : 0)
4334955e03SRex Zhu
44ee913fd9SChristian König struct amdgpu_fence;
45c8e42d57Sxinhui pan enum amdgpu_ib_pool_type;
46ee913fd9SChristian König
47050d9d43SChristian König struct amdgpu_job {
48050d9d43SChristian König struct drm_sched_job base;
49050d9d43SChristian König struct amdgpu_vm *vm;
501b2d5edaSChristian König struct amdgpu_sync explicit_sync;
51c530b02fSJack Zhang struct dma_fence hw_fence;
5268ce8b24SChristian König struct dma_fence *gang_submit;
53050d9d43SChristian König uint32_t preamble_status;
54d8780dc7SJack Xiao uint32_t preemption_status;
55050d9d43SChristian König bool vm_needs_flush;
5656b0989eSChristian König bool gds_switch_needed;
575f3c40e9SChristian König bool spm_update_needed;
58050d9d43SChristian König uint64_t vm_pd_addr;
59050d9d43SChristian König unsigned vmid;
60050d9d43SChristian König unsigned pasid;
61050d9d43SChristian König uint32_t gds_base, gds_size;
62050d9d43SChristian König uint32_t gws_base, gws_size;
63050d9d43SChristian König uint32_t oa_base, oa_size;
64f88e295eSChristian König uint64_t generation;
65050d9d43SChristian König
66050d9d43SChristian König /* user fence handling */
67050d9d43SChristian König uint64_t uf_addr;
68050d9d43SChristian König uint64_t uf_sequence;
69c530b02fSJack Zhang
70ac928705SChristian König /* virtual addresses for shadow/GDS/CSA */
71ac928705SChristian König uint64_t shadow_va;
72ac928705SChristian König uint64_t csa_va;
73ac928705SChristian König uint64_t gds_va;
74ac928705SChristian König bool init_shadow;
75ac928705SChristian König
76c530b02fSJack Zhang /* job_run_counter >= 1 means a resubmit job */
77c530b02fSJack Zhang uint32_t job_run_counter;
786103b2f2SChristian König
79*dba1a6cfSSrinivasan Shanmugam /* enforce isolation */
80*dba1a6cfSSrinivasan Shanmugam bool enforce_isolation;
81*dba1a6cfSSrinivasan Shanmugam
826103b2f2SChristian König uint32_t num_ibs;
836103b2f2SChristian König struct amdgpu_ib ibs[];
84050d9d43SChristian König };
85050d9d43SChristian König
amdgpu_job_ring(struct amdgpu_job * job)86c2b08e7aSChristian König static inline struct amdgpu_ring *amdgpu_job_ring(struct amdgpu_job *job)
87c2b08e7aSChristian König {
88c2b08e7aSChristian König return to_amdgpu_ring(job->base.entity->rq->sched);
89c2b08e7aSChristian König }
90c2b08e7aSChristian König
91f7d66fb2SChristian König int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
92f7d66fb2SChristian König struct drm_sched_entity *entity, void *owner,
93f7d66fb2SChristian König unsigned int num_ibs, struct amdgpu_job **job);
94f7d66fb2SChristian König int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,
95f7d66fb2SChristian König struct drm_sched_entity *entity, void *owner,
96f7d66fb2SChristian König size_t size, enum amdgpu_ib_pool_type pool_type,
97f7d66fb2SChristian König struct amdgpu_job **job);
98736ec9faSChristian König void amdgpu_job_set_resources(struct amdgpu_job *job, struct amdgpu_bo *gds,
99736ec9faSChristian König struct amdgpu_bo *gws, struct amdgpu_bo *oa);
100050d9d43SChristian König void amdgpu_job_free_resources(struct amdgpu_job *job);
10168ce8b24SChristian König void amdgpu_job_set_gang_leader(struct amdgpu_job *job,
10268ce8b24SChristian König struct amdgpu_job *leader);
103050d9d43SChristian König void amdgpu_job_free(struct amdgpu_job *job);
104f7d66fb2SChristian König struct dma_fence *amdgpu_job_submit(struct amdgpu_job *job);
105ee913fd9SChristian König int amdgpu_job_submit_direct(struct amdgpu_job *job, struct amdgpu_ring *ring,
106ee913fd9SChristian König struct dma_fence **fence);
1077c6e68c7SAndrey Grodzovsky
1087c6e68c7SAndrey Grodzovsky void amdgpu_job_stop_all_jobs_on_sched(struct drm_gpu_scheduler *sched);
1097c6e68c7SAndrey Grodzovsky
110050d9d43SChristian König #endif
111