xref: /openbmc/linux/drivers/gpu/host1x/intr.h (revision 276e552e)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Tegra host1x Interrupt Management
4  *
5  * Copyright (c) 2010-2013, NVIDIA Corporation.
6  */
7 
8 #ifndef __HOST1X_INTR_H
9 #define __HOST1X_INTR_H
10 
11 #include <linux/interrupt.h>
12 #include <linux/workqueue.h>
13 
14 struct host1x_syncpt;
15 struct host1x;
16 
17 enum host1x_intr_action {
18 	/*
19 	 * Perform cleanup after a submit has completed.
20 	 * 'data' points to a channel
21 	 */
22 	HOST1X_INTR_ACTION_SUBMIT_COMPLETE = 0,
23 
24 	/*
25 	 * Wake up a  task.
26 	 * 'data' points to a wait_queue_head_t
27 	 */
28 	HOST1X_INTR_ACTION_WAKEUP,
29 
30 	/*
31 	 * Wake up a interruptible task.
32 	 * 'data' points to a wait_queue_head_t
33 	 */
34 	HOST1X_INTR_ACTION_WAKEUP_INTERRUPTIBLE,
35 
36 	HOST1X_INTR_ACTION_COUNT
37 };
38 
39 struct host1x_syncpt_intr {
40 	spinlock_t lock;
41 	struct list_head wait_head;
42 	char thresh_irq_name[12];
43 	struct work_struct work;
44 };
45 
46 struct host1x_waitlist {
47 	struct list_head list;
48 	struct kref refcount;
49 	u32 thresh;
50 	enum host1x_intr_action action;
51 	atomic_t state;
52 	void *data;
53 	int count;
54 };
55 
56 /*
57  * Schedule an action to be taken when a sync point reaches the given threshold.
58  *
59  * @id the sync point
60  * @thresh the threshold
61  * @action the action to take
62  * @data a pointer to extra data depending on action, see above
63  * @waiter waiter structure - assumes ownership
64  * @ref must be passed if cancellation is possible, else NULL
65  *
66  * This is a non-blocking api.
67  */
68 int host1x_intr_add_action(struct host1x *host, struct host1x_syncpt *syncpt,
69 			   u32 thresh, enum host1x_intr_action action,
70 			   void *data, struct host1x_waitlist *waiter,
71 			   void **ref);
72 
73 /*
74  * Unreference an action submitted to host1x_intr_add_action().
75  * You must call this if you passed non-NULL as ref.
76  * @ref the ref returned from host1x_intr_add_action()
77  * @flush wait until any pending handlers have completed before returning.
78  */
79 void host1x_intr_put_ref(struct host1x *host, unsigned int id, void *ref,
80 			 bool flush);
81 
82 /* Initialize host1x sync point interrupt */
83 int host1x_intr_init(struct host1x *host, unsigned int irq_sync);
84 
85 /* Deinitialize host1x sync point interrupt */
86 void host1x_intr_deinit(struct host1x *host);
87 
88 /* Enable host1x sync point interrupt */
89 void host1x_intr_start(struct host1x *host);
90 
91 /* Disable host1x sync point interrupt */
92 void host1x_intr_stop(struct host1x *host);
93 
94 irqreturn_t host1x_syncpt_thresh_fn(void *dev_id);
95 #endif
96