blob: eef506ff46f047647954de6cfb719301879985fd [file] [log] [blame]
Shrenuj Bansala419c792016-10-20 14:05:11 -07001/* Copyright (c) 2002,2007-2017, The Linux Foundation. All rights reserved.
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 __ADRENO_DRAWCTXT_H
14#define __ADRENO_DRAWCTXT_H
15
16struct adreno_context_type {
17 unsigned int type;
18 const char *str;
19};
20
21#define ADRENO_CONTEXT_DRAWQUEUE_SIZE 128
22#define SUBMIT_RETIRE_TICKS_SIZE 7
23
24struct kgsl_device;
25struct adreno_device;
26struct kgsl_device_private;
27struct kgsl_context;
28
29/**
30 * struct adreno_context - Adreno GPU draw context
31 * @timestamp: Last issued context-specific timestamp
32 * @internal_timestamp: Global timestamp of the last issued command
33 * NOTE: guarded by device->mutex, not drawctxt->mutex!
34 * @type: Context type (GL, CL, RS)
35 * @mutex: Mutex to protect the drawqueue
36 * @drawqueue: Queue of drawobjs waiting to be dispatched for this
37 * context
38 * @drawqueue_head: Head of the drawqueue queue
39 * @drawqueue_tail: Tail of the drawqueue queue
40 * @pending: Priority list node for the dispatcher list of pending contexts
41 * @wq: Workqueue structure for contexts to sleep pending room in the queue
42 * @waiting: Workqueue structure for contexts waiting for a timestamp or event
Hareesh Gundu28b9efd2017-08-24 23:11:09 +053043 * @timeout: Workqueue structure for contexts waiting to invalidate
Shrenuj Bansala419c792016-10-20 14:05:11 -070044 * @queued: Number of commands queued in the drawqueue
45 * @fault_policy: GFT fault policy set in _skip_cmd();
46 * @debug_root: debugfs entry for this context.
47 * @queued_timestamp: The last timestamp that was queued on this context
48 * @rb: The ringbuffer in which this context submits commands.
49 * @submitted_timestamp: The last timestamp that was submitted for this context
50 * @submit_retire_ticks: Array to hold command obj execution times from submit
51 * to retire
52 * @ticks_index: The index into submit_retire_ticks[] where the new delta will
53 * be written.
54 * @active_node: Linkage for nodes in active_list
55 * @active_time: Time when this context last seen
56 */
57struct adreno_context {
58 struct kgsl_context base;
59 unsigned int timestamp;
60 unsigned int internal_timestamp;
61 unsigned int type;
62 spinlock_t lock;
63
64 /* Dispatcher */
65 struct kgsl_drawobj *drawqueue[ADRENO_CONTEXT_DRAWQUEUE_SIZE];
66 unsigned int drawqueue_head;
67 unsigned int drawqueue_tail;
68
69 struct plist_node pending;
70 wait_queue_head_t wq;
71 wait_queue_head_t waiting;
Hareesh Gundu28b9efd2017-08-24 23:11:09 +053072 wait_queue_head_t timeout;
Shrenuj Bansala419c792016-10-20 14:05:11 -070073
74 int queued;
75 unsigned int fault_policy;
76 struct dentry *debug_root;
77 unsigned int queued_timestamp;
78 struct adreno_ringbuffer *rb;
79 unsigned int submitted_timestamp;
80 uint64_t submit_retire_ticks[SUBMIT_RETIRE_TICKS_SIZE];
81 int ticks_index;
82
83 struct list_head active_node;
84 unsigned long active_time;
85};
86
87/* Flag definitions for flag field in adreno_context */
88
89/**
90 * enum adreno_context_priv - Private flags for an adreno draw context
91 * @ADRENO_CONTEXT_FAULT - set if the context has faulted (and recovered)
92 * @ADRENO_CONTEXT_GPU_HANG - Context has caused a GPU hang
93 * @ADRENO_CONTEXT_GPU_HANG_FT - Context has caused a GPU hang
94 * and fault tolerance was successful
95 * @ADRENO_CONTEXT_SKIP_EOF - Context skip IBs until the next end of frame
96 * marker.
97 * @ADRENO_CONTEXT_FORCE_PREAMBLE - Force the preamble for the next submission.
98 * @ADRENO_CONTEXT_SKIP_CMD - Context's drawobj's skipped during
99 fault tolerance.
100 * @ADRENO_CONTEXT_FENCE_LOG - Dump fences on this context.
101 */
102enum adreno_context_priv {
103 ADRENO_CONTEXT_FAULT = KGSL_CONTEXT_PRIV_DEVICE_SPECIFIC,
104 ADRENO_CONTEXT_GPU_HANG,
105 ADRENO_CONTEXT_GPU_HANG_FT,
106 ADRENO_CONTEXT_SKIP_EOF,
107 ADRENO_CONTEXT_FORCE_PREAMBLE,
108 ADRENO_CONTEXT_SKIP_CMD,
109 ADRENO_CONTEXT_FENCE_LOG,
110};
111
112/* Flags for adreno_drawctxt_switch() */
113#define ADRENO_CONTEXT_SWITCH_FORCE_GPU BIT(0)
114
115struct kgsl_context *adreno_drawctxt_create(
116 struct kgsl_device_private *dev_priv,
117 uint32_t *flags);
118
119void adreno_drawctxt_detach(struct kgsl_context *context);
120
121void adreno_drawctxt_destroy(struct kgsl_context *context);
122
123void adreno_drawctxt_sched(struct kgsl_device *device,
124 struct kgsl_context *context);
125
126struct adreno_ringbuffer;
127int adreno_drawctxt_switch(struct adreno_device *adreno_dev,
128 struct adreno_ringbuffer *rb,
129 struct adreno_context *drawctxt,
130 unsigned int flags);
131
132int adreno_drawctxt_wait(struct adreno_device *adreno_dev,
133 struct kgsl_context *context,
134 uint32_t timestamp, unsigned int timeout);
135
136void adreno_drawctxt_invalidate(struct kgsl_device *device,
137 struct kgsl_context *context);
138
139void adreno_drawctxt_dump(struct kgsl_device *device,
140 struct kgsl_context *context);
141
142#endif /* __ADRENO_DRAWCTXT_H */