• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2011 Marek Olšák <maraeo@gmail.com>
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sub license, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16  * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
17  * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20  * USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * The above copyright notice and this permission notice (including the
23  * next paragraph) shall be included in all copies or substantial portions
24  * of the Software.
25  */
26 
27 #ifndef RADEON_DRM_CS_H
28 #define RADEON_DRM_CS_H
29 
30 #include "radeon_drm_bo.h"
31 
32 struct radeon_ctx {
33    struct radeon_drm_winsys *ws;
34    uint32_t gpu_reset_counter;
35 };
36 
37 struct radeon_bo_item {
38    struct radeon_bo    *bo;
39    union {
40       struct {
41          uint32_t    priority_usage;
42       } real;
43       struct {
44          unsigned    real_idx;
45       } slab;
46    } u;
47 };
48 
49 struct radeon_cs_context {
50    uint32_t                    buf[16 * 1024];
51 
52    int                         fd;
53    struct drm_radeon_cs        cs;
54    struct drm_radeon_cs_chunk  chunks[3];
55    uint64_t                    chunk_array[3];
56    uint32_t                    flags[2];
57 
58    /* Buffers. */
59    unsigned                    max_relocs;
60    unsigned                    num_relocs;
61    unsigned                    num_validated_relocs;
62    struct radeon_bo_item       *relocs_bo;
63    struct drm_radeon_cs_reloc  *relocs;
64 
65    unsigned                    num_slab_buffers;
66    unsigned                    max_slab_buffers;
67    struct radeon_bo_item       *slab_buffers;
68 
69    int                         reloc_indices_hashlist[4096];
70 };
71 
72 struct radeon_drm_cs {
73    struct radeon_cmdbuf base;
74    enum ring_type          ring_type;
75 
76    /* We flip between these two CS. While one is being consumed
77     * by the kernel in another thread, the other one is being filled
78     * by the pipe driver. */
79    struct radeon_cs_context csc1;
80    struct radeon_cs_context csc2;
81    /* The currently-used CS. */
82    struct radeon_cs_context *csc;
83    /* The CS being currently-owned by the other thread. */
84    struct radeon_cs_context *cst;
85 
86    /* The winsys. */
87    struct radeon_drm_winsys *ws;
88 
89    /* Flush CS. */
90    void (*flush_cs)(void *ctx, unsigned flags, struct pipe_fence_handle **fence);
91    void *flush_data;
92 
93    struct util_queue_fence flush_completed;
94    struct pipe_fence_handle *next_fence;
95 };
96 
97 int radeon_lookup_buffer(struct radeon_cs_context *csc, struct radeon_bo *bo);
98 
99 static inline struct radeon_drm_cs *
radeon_drm_cs(struct radeon_cmdbuf * base)100 radeon_drm_cs(struct radeon_cmdbuf *base)
101 {
102    return (struct radeon_drm_cs*)base;
103 }
104 
105 static inline bool
radeon_bo_is_referenced_by_cs(struct radeon_drm_cs * cs,struct radeon_bo * bo)106 radeon_bo_is_referenced_by_cs(struct radeon_drm_cs *cs,
107                               struct radeon_bo *bo)
108 {
109    int num_refs = bo->num_cs_references;
110    return num_refs == bo->rws->num_cs ||
111          (num_refs && radeon_lookup_buffer(cs->csc, bo) != -1);
112 }
113 
114 static inline bool
radeon_bo_is_referenced_by_cs_for_write(struct radeon_drm_cs * cs,struct radeon_bo * bo)115 radeon_bo_is_referenced_by_cs_for_write(struct radeon_drm_cs *cs,
116                                         struct radeon_bo *bo)
117 {
118    int index;
119 
120    if (!bo->num_cs_references)
121       return false;
122 
123    index = radeon_lookup_buffer(cs->csc, bo);
124    if (index == -1)
125       return false;
126 
127    if (!bo->handle)
128       index = cs->csc->slab_buffers[index].u.slab.real_idx;
129 
130    return cs->csc->relocs[index].write_domain != 0;
131 }
132 
133 static inline bool
radeon_bo_is_referenced_by_any_cs(struct radeon_bo * bo)134 radeon_bo_is_referenced_by_any_cs(struct radeon_bo *bo)
135 {
136    return bo->num_cs_references != 0;
137 }
138 
139 void radeon_drm_cs_sync_flush(struct radeon_cmdbuf *rcs);
140 void radeon_drm_cs_init_functions(struct radeon_drm_winsys *ws);
141 void radeon_drm_cs_emit_ioctl_oneshot(void *job, int thread_index);
142 
143 #endif
144