blob: 61bd06f4d37326cb2756207b411e8afe941dcbaf [file] [log] [blame]
Deepak Kumar79908f52018-02-28 11:06:38 +05301/* Copyright (c) 2008-2018, The Linux Foundation. All rights reserved.
Shrenuj Bansala419c792016-10-20 14:05:11 -07002 *
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
14#ifndef ____ADRENO_DISPATCHER_H
15#define ____ADRENO_DISPATCHER_H
16
17extern unsigned int adreno_disp_preempt_fair_sched;
18extern unsigned int adreno_drawobj_timeout;
19extern unsigned int adreno_dispatch_starvation_time;
20extern unsigned int adreno_dispatch_time_slice;
21
22/**
23 * enum adreno_dispatcher_starve_timer_states - Starvation control states of
24 * a RB
25 * @ADRENO_DISPATCHER_RB_STARVE_TIMER_UNINIT: Uninitialized, starvation control
26 * is not operating
27 * @ADRENO_DISPATCHER_RB_STARVE_TIMER_INIT: Starvation timer is initialized
28 * and counting
29 * @ADRENO_DISPATCHER_RB_STARVE_TIMER_ELAPSED: The starvation timer has elapsed
30 * this state indicates that the RB is starved
31 * @ADRENO_DISPATCHER_RB_STARVE_TIMER_SCHEDULED: RB is scheduled on the device
32 * and will remain scheduled for a minimum time slice when in this state.
33 */
34enum adreno_dispatcher_starve_timer_states {
35 ADRENO_DISPATCHER_RB_STARVE_TIMER_UNINIT = 0,
36 ADRENO_DISPATCHER_RB_STARVE_TIMER_INIT = 1,
37 ADRENO_DISPATCHER_RB_STARVE_TIMER_ELAPSED = 2,
38 ADRENO_DISPATCHER_RB_STARVE_TIMER_SCHEDULED = 3,
39};
40
41/*
42 * Maximum size of the dispatcher ringbuffer - the actual inflight size will be
43 * smaller then this but this size will allow for a larger range of inflight
44 * sizes that can be chosen at runtime
45 */
46
47#define ADRENO_DISPATCH_DRAWQUEUE_SIZE 128
48
49#define DRAWQUEUE_NEXT(_i, _s) (((_i) + 1) % (_s))
50
51/**
52 * struct adreno_dispatcher_drawqueue - List of commands for a RB level
53 * @cmd_q: List of command obj's submitted to dispatcher
54 * @inflight: Number of commands inflight in this q
55 * @head: Head pointer to the q
56 * @tail: Queues tail pointer
57 * @active_context_count: Number of active contexts seen in this rb drawqueue
58 * @expires: The jiffies value at which this drawqueue has run too long
59 */
60struct adreno_dispatcher_drawqueue {
61 struct kgsl_drawobj_cmd *cmd_q[ADRENO_DISPATCH_DRAWQUEUE_SIZE];
62 unsigned int inflight;
63 unsigned int head;
64 unsigned int tail;
65 int active_context_count;
66 unsigned long expires;
67};
68
69/**
70 * struct adreno_dispatcher - container for the adreno GPU dispatcher
71 * @mutex: Mutex to protect the structure
72 * @state: Current state of the dispatcher (active or paused)
73 * @timer: Timer to monitor the progress of the drawobjs
74 * @inflight: Number of drawobj operations pending in the ringbuffer
75 * @fault: Non-zero if a fault was detected.
76 * @pending: Priority list of contexts waiting to submit drawobjs
77 * @plist_lock: Spin lock to protect the pending queue
78 * @work: work_struct to put the dispatcher in a work queue
79 * @kobj: kobject for the dispatcher directory in the device sysfs node
80 * @idle_gate: Gate to wait on for dispatcher to idle
81 * @disp_preempt_fair_sched: If set then dispatcher will try to be fair to
82 * starving RB's by scheduling them in and enforcing a minimum time slice
83 * for every RB that is scheduled to run on the device
84 */
85struct adreno_dispatcher {
86 struct mutex mutex;
87 unsigned long priv;
88 struct timer_list timer;
89 struct timer_list fault_timer;
90 unsigned int inflight;
91 atomic_t fault;
92 struct plist_head pending;
93 spinlock_t plist_lock;
Tim Murray85040432017-02-20 15:59:32 +053094 struct kthread_work work;
Shrenuj Bansala419c792016-10-20 14:05:11 -070095 struct kobject kobj;
96 struct completion idle_gate;
97 unsigned int disp_preempt_fair_sched;
98};
99
100enum adreno_dispatcher_flags {
101 ADRENO_DISPATCHER_POWER = 0,
102 ADRENO_DISPATCHER_ACTIVE = 1,
103};
104
105void adreno_dispatcher_start(struct kgsl_device *device);
Deepak Kumar79908f52018-02-28 11:06:38 +0530106void adreno_dispatcher_halt(struct kgsl_device *device);
107void adreno_dispatcher_unhalt(struct kgsl_device *device);
Shrenuj Bansala419c792016-10-20 14:05:11 -0700108int adreno_dispatcher_init(struct adreno_device *adreno_dev);
109void adreno_dispatcher_close(struct adreno_device *adreno_dev);
110int adreno_dispatcher_idle(struct adreno_device *adreno_dev);
111void adreno_dispatcher_irq_fault(struct adreno_device *adreno_dev);
112void adreno_dispatcher_stop(struct adreno_device *adreno_dev);
Hareesh Gundua2fe6ec2017-03-06 14:53:36 +0530113void adreno_dispatcher_stop_fault_timer(struct kgsl_device *device);
Shrenuj Bansala419c792016-10-20 14:05:11 -0700114
115int adreno_dispatcher_queue_cmds(struct kgsl_device_private *dev_priv,
116 struct kgsl_context *context, struct kgsl_drawobj *drawobj[],
117 uint32_t count, uint32_t *timestamp);
118
119void adreno_dispatcher_schedule(struct kgsl_device *device);
120void adreno_dispatcher_pause(struct adreno_device *adreno_dev);
121void adreno_dispatcher_queue_context(struct kgsl_device *device,
122 struct adreno_context *drawctxt);
123void adreno_dispatcher_preempt_callback(struct adreno_device *adreno_dev,
124 int bit);
125void adreno_preempt_process_dispatch_queue(struct adreno_device *adreno_dev,
126 struct adreno_dispatcher_drawqueue *dispatch_q);
127
128static inline bool adreno_drawqueue_is_empty(
129 struct adreno_dispatcher_drawqueue *drawqueue)
130{
131 return (drawqueue != NULL && drawqueue->head == drawqueue->tail);
132}
133#endif /* __ADRENO_DISPATCHER_H */