Lynus Vaz | c031a9b | 2017-01-25 13:00:13 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __KGSL_DRAWOBJ_H |
| 14 | #define __KGSL_DRAWOBJ_H |
| 15 | |
| 16 | #define DRAWOBJ(obj) (&obj->base) |
| 17 | #define SYNCOBJ(obj) \ |
| 18 | container_of(obj, struct kgsl_drawobj_sync, base) |
| 19 | #define CMDOBJ(obj) \ |
| 20 | container_of(obj, struct kgsl_drawobj_cmd, base) |
Tarun Karra | 2b8b363 | 2016-11-14 16:38:27 -0800 | [diff] [blame] | 21 | #define SPARSEOBJ(obj) \ |
| 22 | container_of(obj, struct kgsl_drawobj_sparse, base) |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 23 | |
| 24 | #define CMDOBJ_TYPE BIT(0) |
| 25 | #define MARKEROBJ_TYPE BIT(1) |
| 26 | #define SYNCOBJ_TYPE BIT(2) |
Tarun Karra | 2b8b363 | 2016-11-14 16:38:27 -0800 | [diff] [blame] | 27 | #define SPARSEOBJ_TYPE BIT(3) |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * struct kgsl_drawobj - KGSL drawobj descriptor |
| 31 | * @device: KGSL GPU device that the command was created for |
| 32 | * @context: KGSL context that created the command |
| 33 | * @type: Object type |
| 34 | * @timestamp: Timestamp assigned to the command |
| 35 | * @flags: flags |
| 36 | * @refcount: kref structure to maintain the reference count |
| 37 | */ |
| 38 | struct kgsl_drawobj { |
| 39 | struct kgsl_device *device; |
| 40 | struct kgsl_context *context; |
| 41 | uint32_t type; |
| 42 | uint32_t timestamp; |
| 43 | unsigned long flags; |
| 44 | struct kref refcount; |
| 45 | }; |
| 46 | |
| 47 | /** |
| 48 | * struct kgsl_drawobj_cmd - KGSL command obj, This covers marker |
| 49 | * cmds also since markers are special form of cmds that do not |
| 50 | * need their cmds to be executed. |
Tarun Karra | 2b8b363 | 2016-11-14 16:38:27 -0800 | [diff] [blame] | 51 | * @base: Base kgsl_drawobj, this needs to be the first entry |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 52 | * @priv: Internal flags |
| 53 | * @global_ts: The ringbuffer timestamp corresponding to this |
| 54 | * command obj |
| 55 | * @fault_policy: Internal policy describing how to handle this command in case |
| 56 | * of a fault |
| 57 | * @fault_recovery: recovery actions actually tried for this batch |
| 58 | * be hung |
| 59 | * @refcount: kref structure to maintain the reference count |
| 60 | * @cmdlist: List of IBs to issue |
| 61 | * @memlist: List of all memory used in this command batch |
| 62 | * @marker_timestamp: For markers, the timestamp of the last "real" command that |
| 63 | * was queued |
| 64 | * @profiling_buf_entry: Mem entry containing the profiling buffer |
| 65 | * @profiling_buffer_gpuaddr: GPU virt address of the profile buffer added here |
| 66 | * for easy access |
| 67 | * @profile_index: Index to store the start/stop ticks in the kernel profiling |
| 68 | * buffer |
| 69 | * @submit_ticks: Variable to hold ticks at the time of |
| 70 | * command obj submit. |
| 71 | |
| 72 | */ |
| 73 | struct kgsl_drawobj_cmd { |
| 74 | struct kgsl_drawobj base; |
| 75 | unsigned long priv; |
| 76 | unsigned int global_ts; |
| 77 | unsigned long fault_policy; |
| 78 | unsigned long fault_recovery; |
| 79 | struct list_head cmdlist; |
| 80 | struct list_head memlist; |
| 81 | unsigned int marker_timestamp; |
| 82 | struct kgsl_mem_entry *profiling_buf_entry; |
| 83 | uint64_t profiling_buffer_gpuaddr; |
| 84 | unsigned int profile_index; |
| 85 | uint64_t submit_ticks; |
| 86 | }; |
| 87 | |
| 88 | /** |
| 89 | * struct kgsl_drawobj_sync - KGSL sync object |
| 90 | * @base: Base kgsl_drawobj, this needs to be the first entry |
| 91 | * @synclist: Array of context/timestamp tuples to wait for before issuing |
| 92 | * @numsyncs: Number of sync entries in the array |
| 93 | * @pending: Bitmask of sync events that are active |
| 94 | * @timer: a timer used to track possible sync timeouts for this |
| 95 | * sync obj |
| 96 | * @timeout_jiffies: For a sync obj the jiffies at |
| 97 | * which the timer will expire |
| 98 | */ |
| 99 | struct kgsl_drawobj_sync { |
| 100 | struct kgsl_drawobj base; |
| 101 | struct kgsl_drawobj_sync_event *synclist; |
| 102 | unsigned int numsyncs; |
| 103 | unsigned long pending; |
| 104 | struct timer_list timer; |
| 105 | unsigned long timeout_jiffies; |
| 106 | }; |
| 107 | |
Lynus Vaz | e99b92b | 2017-04-24 18:04:54 +0530 | [diff] [blame] | 108 | #define KGSL_FENCE_NAME_LEN 74 |
| 109 | |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 110 | /** |
| 111 | * struct kgsl_drawobj_sync_event |
| 112 | * @id: identifer (positiion within the pending bitmap) |
| 113 | * @type: Syncpoint type |
| 114 | * @syncobj: Pointer to the syncobj that owns the sync event |
| 115 | * @context: KGSL context for whose timestamp we want to |
| 116 | * register this event |
| 117 | * @timestamp: Pending timestamp for the event |
| 118 | * @handle: Pointer to a sync fence handle |
Lynus Vaz | e99b92b | 2017-04-24 18:04:54 +0530 | [diff] [blame] | 119 | * @fence_name: A fence name string to describe the fence |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 120 | * @device: Pointer to the KGSL device |
| 121 | */ |
| 122 | struct kgsl_drawobj_sync_event { |
| 123 | unsigned int id; |
| 124 | int type; |
| 125 | struct kgsl_drawobj_sync *syncobj; |
| 126 | struct kgsl_context *context; |
| 127 | unsigned int timestamp; |
Lynus Vaz | c031a9b | 2017-01-25 13:00:13 +0530 | [diff] [blame] | 128 | struct kgsl_sync_fence_cb *handle; |
Lynus Vaz | e99b92b | 2017-04-24 18:04:54 +0530 | [diff] [blame] | 129 | char fence_name[KGSL_FENCE_NAME_LEN]; |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 130 | struct kgsl_device *device; |
| 131 | }; |
| 132 | |
Tarun Karra | 2b8b363 | 2016-11-14 16:38:27 -0800 | [diff] [blame] | 133 | /** |
| 134 | * struct kgsl_drawobj_sparse - KGSl sparse obj descriptor |
| 135 | * @base: Base kgsl_obj, this needs to be the first entry |
| 136 | * @id: virtual id of the bind/unbind |
| 137 | * @sparselist: list of binds/unbinds |
| 138 | * @size: Size of kgsl_sparse_bind_object |
| 139 | * @count: Number of elements in list |
| 140 | */ |
| 141 | struct kgsl_drawobj_sparse { |
| 142 | struct kgsl_drawobj base; |
| 143 | unsigned int id; |
| 144 | struct list_head sparselist; |
| 145 | unsigned int size; |
| 146 | unsigned int count; |
| 147 | }; |
| 148 | |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 149 | #define KGSL_DRAWOBJ_FLAGS \ |
| 150 | { KGSL_DRAWOBJ_MARKER, "MARKER" }, \ |
| 151 | { KGSL_DRAWOBJ_CTX_SWITCH, "CTX_SWITCH" }, \ |
| 152 | { KGSL_DRAWOBJ_SYNC, "SYNC" }, \ |
| 153 | { KGSL_DRAWOBJ_END_OF_FRAME, "EOF" }, \ |
| 154 | { KGSL_DRAWOBJ_PWR_CONSTRAINT, "PWR_CONSTRAINT" }, \ |
| 155 | { KGSL_DRAWOBJ_SUBMIT_IB_LIST, "IB_LIST" } |
| 156 | |
| 157 | /** |
| 158 | * enum kgsl_drawobj_cmd_priv - Internal command obj flags |
| 159 | * @CMDOBJ_SKIP - skip the entire command obj |
| 160 | * @CMDOBJ_FORCE_PREAMBLE - Force the preamble on for |
| 161 | * command obj |
| 162 | * @CMDOBJ_WFI - Force wait-for-idle for the submission |
| 163 | * @CMDOBJ_PROFILE - store the start / retire ticks for |
| 164 | * the command obj in the profiling buffer |
| 165 | */ |
| 166 | enum kgsl_drawobj_cmd_priv { |
| 167 | CMDOBJ_SKIP = 0, |
| 168 | CMDOBJ_FORCE_PREAMBLE, |
| 169 | CMDOBJ_WFI, |
| 170 | CMDOBJ_PROFILE, |
| 171 | }; |
| 172 | |
| 173 | struct kgsl_drawobj_cmd *kgsl_drawobj_cmd_create(struct kgsl_device *device, |
| 174 | struct kgsl_context *context, unsigned int flags, |
| 175 | unsigned int type); |
| 176 | int kgsl_drawobj_cmd_add_ibdesc(struct kgsl_device *device, |
| 177 | struct kgsl_drawobj_cmd *cmdobj, struct kgsl_ibdesc *ibdesc); |
| 178 | int kgsl_drawobj_cmd_add_ibdesc_list(struct kgsl_device *device, |
| 179 | struct kgsl_drawobj_cmd *cmdobj, void __user *ptr, int count); |
| 180 | int kgsl_drawobj_cmd_add_cmdlist(struct kgsl_device *device, |
| 181 | struct kgsl_drawobj_cmd *cmdobj, void __user *ptr, |
| 182 | unsigned int size, unsigned int count); |
| 183 | int kgsl_drawobj_cmd_add_memlist(struct kgsl_device *device, |
| 184 | struct kgsl_drawobj_cmd *cmdobj, void __user *ptr, |
| 185 | unsigned int size, unsigned int count); |
| 186 | |
| 187 | struct kgsl_drawobj_sync *kgsl_drawobj_sync_create(struct kgsl_device *device, |
| 188 | struct kgsl_context *context); |
| 189 | int kgsl_drawobj_sync_add_syncpoints(struct kgsl_device *device, |
| 190 | struct kgsl_drawobj_sync *syncobj, void __user *ptr, |
| 191 | int count); |
| 192 | int kgsl_drawobj_sync_add_synclist(struct kgsl_device *device, |
| 193 | struct kgsl_drawobj_sync *syncobj, void __user *ptr, |
| 194 | unsigned int size, unsigned int count); |
| 195 | int kgsl_drawobj_sync_add_sync(struct kgsl_device *device, |
| 196 | struct kgsl_drawobj_sync *syncobj, |
| 197 | struct kgsl_cmd_syncpoint *sync); |
Tarun Karra | 2b8b363 | 2016-11-14 16:38:27 -0800 | [diff] [blame] | 198 | struct kgsl_drawobj_sparse *kgsl_drawobj_sparse_create( |
| 199 | struct kgsl_device *device, |
| 200 | struct kgsl_context *context, unsigned int flags); |
| 201 | int kgsl_drawobj_sparse_add_sparselist(struct kgsl_device *device, |
| 202 | struct kgsl_drawobj_sparse *sparseobj, unsigned int id, |
| 203 | void __user *ptr, unsigned int size, unsigned int count); |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 204 | |
Tarun Karra | 2b8b363 | 2016-11-14 16:38:27 -0800 | [diff] [blame] | 205 | int kgsl_drawobjs_cache_init(void); |
| 206 | void kgsl_drawobjs_cache_exit(void); |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 207 | |
| 208 | void kgsl_dump_syncpoints(struct kgsl_device *device, |
| 209 | struct kgsl_drawobj_sync *syncobj); |
| 210 | |
| 211 | void kgsl_drawobj_destroy(struct kgsl_drawobj *drawobj); |
| 212 | |
Lynus Vaz | e99b92b | 2017-04-24 18:04:54 +0530 | [diff] [blame] | 213 | void kgsl_drawobj_destroy_object(struct kref *kref); |
| 214 | |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 215 | static inline bool kgsl_drawobj_events_pending( |
| 216 | struct kgsl_drawobj_sync *syncobj) |
| 217 | { |
| 218 | return !bitmap_empty(&syncobj->pending, KGSL_MAX_SYNCPOINTS); |
| 219 | } |
| 220 | |
| 221 | static inline bool kgsl_drawobj_event_pending( |
| 222 | struct kgsl_drawobj_sync *syncobj, unsigned int bit) |
| 223 | { |
| 224 | if (bit >= KGSL_MAX_SYNCPOINTS) |
| 225 | return false; |
| 226 | |
| 227 | return test_bit(bit, &syncobj->pending); |
| 228 | } |
Lynus Vaz | e99b92b | 2017-04-24 18:04:54 +0530 | [diff] [blame] | 229 | |
| 230 | static inline void kgsl_drawobj_put(struct kgsl_drawobj *drawobj) |
| 231 | { |
| 232 | if (drawobj) |
| 233 | kref_put(&drawobj->refcount, kgsl_drawobj_destroy_object); |
| 234 | } |
| 235 | |
Shrenuj Bansal | a419c79 | 2016-10-20 14:05:11 -0700 | [diff] [blame] | 236 | #endif /* __KGSL_DRAWOBJ_H */ |