]> Git Repo - linux.git/blob - drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
drm/amdgpu: switch ih handling to two levels (v3)
[linux.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_ring.h
1 /*
2  * Copyright 2016 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: Christian König
23  */
24 #ifndef __AMDGPU_RING_H__
25 #define __AMDGPU_RING_H__
26
27 #include "gpu_scheduler.h"
28
29 /* max number of rings */
30 #define AMDGPU_MAX_RINGS                16
31 #define AMDGPU_MAX_GFX_RINGS            1
32 #define AMDGPU_MAX_COMPUTE_RINGS        8
33 #define AMDGPU_MAX_VCE_RINGS            3
34
35 /* some special values for the owner field */
36 #define AMDGPU_FENCE_OWNER_UNDEFINED    ((void*)0ul)
37 #define AMDGPU_FENCE_OWNER_VM           ((void*)1ul)
38
39 #define AMDGPU_FENCE_FLAG_64BIT         (1 << 0)
40 #define AMDGPU_FENCE_FLAG_INT           (1 << 1)
41
42 enum amdgpu_ring_type {
43         AMDGPU_RING_TYPE_GFX,
44         AMDGPU_RING_TYPE_COMPUTE,
45         AMDGPU_RING_TYPE_SDMA,
46         AMDGPU_RING_TYPE_UVD,
47         AMDGPU_RING_TYPE_VCE,
48         AMDGPU_RING_TYPE_KIQ
49 };
50
51 struct amdgpu_device;
52 struct amdgpu_ring;
53 struct amdgpu_ib;
54 struct amdgpu_cs_parser;
55
56 /*
57  * Fences.
58  */
59 struct amdgpu_fence_driver {
60         uint64_t                        gpu_addr;
61         volatile uint32_t               *cpu_addr;
62         /* sync_seq is protected by ring emission lock */
63         uint32_t                        sync_seq;
64         atomic_t                        last_seq;
65         bool                            initialized;
66         struct amdgpu_irq_src           *irq_src;
67         unsigned                        irq_type;
68         struct timer_list               fallback_timer;
69         unsigned                        num_fences_mask;
70         spinlock_t                      lock;
71         struct dma_fence                **fences;
72 };
73
74 int amdgpu_fence_driver_init(struct amdgpu_device *adev);
75 void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
76 void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
77
78 int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
79                                   unsigned num_hw_submission);
80 int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
81                                    struct amdgpu_irq_src *irq_src,
82                                    unsigned irq_type);
83 void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
84 void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
85 int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **fence);
86 void amdgpu_fence_process(struct amdgpu_ring *ring);
87 int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
88 unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
89
90 /*
91  * Rings.
92  */
93
94 /* provided by hw blocks that expose a ring buffer for commands */
95 struct amdgpu_ring_funcs {
96         enum amdgpu_ring_type   type;
97         uint32_t                align_mask;
98         u32                     nop;
99         bool                    support_64bit_ptrs;
100
101         /* ring read/write ptr handling */
102         u64 (*get_rptr)(struct amdgpu_ring *ring);
103         u64 (*get_wptr)(struct amdgpu_ring *ring);
104         void (*set_wptr)(struct amdgpu_ring *ring);
105         /* validating and patching of IBs */
106         int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
107         /* constants to calculate how many DW are needed for an emit */
108         unsigned emit_frame_size;
109         unsigned emit_ib_size;
110         /* command emit functions */
111         void (*emit_ib)(struct amdgpu_ring *ring,
112                         struct amdgpu_ib *ib,
113                         unsigned vm_id, bool ctx_switch);
114         void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
115                            uint64_t seq, unsigned flags);
116         void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
117         void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
118                               uint64_t pd_addr);
119         void (*emit_hdp_flush)(struct amdgpu_ring *ring);
120         void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
121         void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
122                                 uint32_t gds_base, uint32_t gds_size,
123                                 uint32_t gws_base, uint32_t gws_size,
124                                 uint32_t oa_base, uint32_t oa_size);
125         /* testing functions */
126         int (*test_ring)(struct amdgpu_ring *ring);
127         int (*test_ib)(struct amdgpu_ring *ring, long timeout);
128         /* insert NOP packets */
129         void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
130         /* pad the indirect buffer to the necessary number of dw */
131         void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
132         unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
133         void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
134         /* note usage for clock and power gating */
135         void (*begin_use)(struct amdgpu_ring *ring);
136         void (*end_use)(struct amdgpu_ring *ring);
137         void (*emit_switch_buffer) (struct amdgpu_ring *ring);
138         void (*emit_cntxcntl) (struct amdgpu_ring *ring, uint32_t flags);
139         void (*emit_rreg)(struct amdgpu_ring *ring, uint32_t reg);
140         void (*emit_wreg)(struct amdgpu_ring *ring, uint32_t reg, uint32_t val);
141 };
142
143 struct amdgpu_ring {
144         struct amdgpu_device            *adev;
145         const struct amdgpu_ring_funcs  *funcs;
146         struct amdgpu_fence_driver      fence_drv;
147         struct amd_gpu_scheduler        sched;
148
149         struct amdgpu_bo        *ring_obj;
150         volatile uint32_t       *ring;
151         unsigned                rptr_offs;
152         u64                     wptr;
153         u64                     wptr_old;
154         unsigned                ring_size;
155         unsigned                max_dw;
156         int                     count_dw;
157         uint64_t                gpu_addr;
158         uint64_t                ptr_mask;
159         uint32_t                buf_mask;
160         bool                    ready;
161         u32                     idx;
162         u32                     me;
163         u32                     pipe;
164         u32                     queue;
165         struct amdgpu_bo        *mqd_obj;
166         uint64_t                mqd_gpu_addr;
167         void                    *mqd_ptr;
168         u32                     doorbell_index;
169         bool                    use_doorbell;
170         unsigned                wptr_offs;
171         unsigned                fence_offs;
172         uint64_t                current_ctx;
173         char                    name[16];
174         unsigned                cond_exe_offs;
175         u64                     cond_exe_gpu_addr;
176         volatile u32            *cond_exe_cpu_addr;
177 #if defined(CONFIG_DEBUG_FS)
178         struct dentry *ent;
179 #endif
180 };
181
182 int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
183 void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
184 void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
185 void amdgpu_ring_commit(struct amdgpu_ring *ring);
186 void amdgpu_ring_undo(struct amdgpu_ring *ring);
187 int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
188                      unsigned ring_size, struct amdgpu_irq_src *irq_src,
189                      unsigned irq_type);
190 void amdgpu_ring_fini(struct amdgpu_ring *ring);
191 static inline void amdgpu_ring_clear_ring(struct amdgpu_ring *ring)
192 {
193         int i = 0;
194         while (i <= ring->ptr_mask)
195                 ring->ring[i++] = ring->funcs->nop;
196
197 }
198
199 #endif
This page took 0.045082 seconds and 4 git commands to generate.