powerpc/hugetlb: Don't do runtime allocation of 16G pages in LPAR configuration
[linux-2.6-block.git] / include / drm / drm_vblank.h
CommitLineData
3ed4351a
DV
1/*
2 * Copyright 2016 Intel Corp.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24#ifndef _DRM_VBLANK_H_
25#define _DRM_VBLANK_H_
26
27#include <linux/seqlock.h>
28#include <linux/idr.h>
29#include <linux/poll.h>
30
31#include <drm/drm_file.h>
32#include <drm/drm_modes.h>
33#include <uapi/drm/drm.h>
34
35struct drm_device;
36struct drm_crtc;
37
38/**
39 * struct drm_pending_vblank_event - pending vblank event tracking
40 */
41struct drm_pending_vblank_event {
42 /**
43 * @base: Base structure for tracking pending DRM events.
44 */
45 struct drm_pending_event base;
46 /**
47 * @pipe: drm_crtc_index() of the &drm_crtc this event is for.
48 */
49 unsigned int pipe;
570e8696
KP
50 /**
51 * @sequence: frame event should be triggered at
52 */
53 u64 sequence;
3ed4351a
DV
54 /**
55 * @event: Actual event which will be sent to userspace.
56 */
bd386e51 57 union {
83a7dff0
DV
58 /**
59 * @event.base: DRM event base class.
60 */
bd386e51 61 struct drm_event base;
83a7dff0
DV
62
63 /**
64 * @event.vbl:
65 *
66 * Event payload for vblank events, requested through
67 * either the MODE_PAGE_FLIP or MODE_ATOMIC IOCTL. Also
68 * generated by the legacy WAIT_VBLANK IOCTL, but new userspace
69 * should use MODE_QUEUE_SEQUENCE and &event.seq instead.
70 */
bd386e51 71 struct drm_event_vblank vbl;
83a7dff0
DV
72
73 /**
74 * @event.seq: Event payload for the MODE_QUEUEU_SEQUENCE IOCTL.
75 */
3064abfa 76 struct drm_event_crtc_sequence seq;
bd386e51 77 } event;
3ed4351a
DV
78};
79
80/**
81 * struct drm_vblank_crtc - vblank tracking for a CRTC
82 *
83 * This structure tracks the vblank state for one CRTC.
84 *
85 * Note that for historical reasons - the vblank handling code is still shared
86 * with legacy/non-kms drivers - this is a free-standing structure not directly
87 * connected to &struct drm_crtc. But all public interface functions are taking
88 * a &struct drm_crtc to hide this implementation detail.
89 */
90struct drm_vblank_crtc {
91 /**
92 * @dev: Pointer to the &drm_device.
93 */
94 struct drm_device *dev;
95 /**
96 * @queue: Wait queue for vblank waiters.
97 */
9e37ee79 98 wait_queue_head_t queue;
3ed4351a
DV
99 /**
100 * @disable_timer: Disable timer for the delayed vblank disabling
101 * hysteresis logic. Vblank disabling is controlled through the
102 * drm_vblank_offdelay module option and the setting of the
103 * &drm_device.max_vblank_count value.
104 */
105 struct timer_list disable_timer;
106
107 /**
108 * @seqlock: Protect vblank count and time.
109 */
9e37ee79 110 seqlock_t seqlock;
3ed4351a
DV
111
112 /**
113 * @count: Current software vblank counter.
114 */
570e8696 115 u64 count;
3ed4351a
DV
116 /**
117 * @time: Vblank timestamp corresponding to @count.
118 */
67680d3c 119 ktime_t time;
3ed4351a
DV
120
121 /**
122 * @refcount: Number of users/waiters of the vblank interrupt. Only when
123 * this refcount reaches 0 can the hardware interrupt be disabled using
124 * @disable_timer.
125 */
9e37ee79 126 atomic_t refcount;
3ed4351a
DV
127 /**
128 * @last: Protected by &drm_device.vbl_lock, used for wraparound handling.
129 */
130 u32 last;
131 /**
132 * @inmodeset: Tracks whether the vblank is disabled due to a modeset.
133 * For legacy driver bit 2 additionally tracks whether an additional
134 * temporary vblank reference has been acquired to paper over the
135 * hardware counter resetting/jumping. KMS drivers should instead just
136 * call drm_crtc_vblank_off() and drm_crtc_vblank_on(), which explicitly
137 * save and restore the vblank count.
138 */
9e37ee79 139 unsigned int inmodeset;
3ed4351a
DV
140 /**
141 * @pipe: drm_crtc_index() of the &drm_crtc corresponding to this
142 * structure.
143 */
144 unsigned int pipe;
145 /**
146 * @framedur_ns: Frame/Field duration in ns, used by
147 * drm_calc_vbltimestamp_from_scanoutpos() and computed by
148 * drm_calc_timestamping_constants().
149 */
150 int framedur_ns;
151 /**
152 * @linedur_ns: Line duration in ns, used by
153 * drm_calc_vbltimestamp_from_scanoutpos() and computed by
154 * drm_calc_timestamping_constants().
155 */
156 int linedur_ns;
157
158 /**
159 * @hwmode:
160 *
161 * Cache of the current hardware display mode. Only valid when @enabled
162 * is set. This is used by helpers like
163 * drm_calc_vbltimestamp_from_scanoutpos(). We can't just access the
164 * hardware mode by e.g. looking at &drm_crtc_state.adjusted_mode,
165 * because that one is really hard to get from interrupt context.
166 */
167 struct drm_display_mode hwmode;
168
169 /**
170 * @enabled: Tracks the enabling state of the corresponding &drm_crtc to
171 * avoid double-disabling and hence corrupting saved state. Needed by
172 * drivers not using atomic KMS, since those might go through their CRTC
173 * disabling functions multiple times.
174 */
175 bool enabled;
176};
177
178int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs);
570e8696
KP
179u64 drm_crtc_vblank_count(struct drm_crtc *crtc);
180u64 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc,
67680d3c 181 ktime_t *vblanktime);
3ed4351a
DV
182void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
183 struct drm_pending_vblank_event *e);
184void drm_crtc_arm_vblank_event(struct drm_crtc *crtc,
185 struct drm_pending_vblank_event *e);
bd386e51
KP
186void drm_vblank_set_event(struct drm_pending_vblank_event *e,
187 u64 *seq,
188 ktime_t *now);
3ed4351a
DV
189bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe);
190bool drm_crtc_handle_vblank(struct drm_crtc *crtc);
191int drm_crtc_vblank_get(struct drm_crtc *crtc);
192void drm_crtc_vblank_put(struct drm_crtc *crtc);
193void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe);
194void drm_crtc_wait_one_vblank(struct drm_crtc *crtc);
195void drm_crtc_vblank_off(struct drm_crtc *crtc);
196void drm_crtc_vblank_reset(struct drm_crtc *crtc);
197void drm_crtc_vblank_on(struct drm_crtc *crtc);
3b765c0b 198u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc);
d0bb96b4
DP
199void drm_vblank_restore(struct drm_device *dev, unsigned int pipe);
200void drm_crtc_vblank_restore(struct drm_crtc *crtc);
3ed4351a
DV
201
202bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
203 unsigned int pipe, int *max_error,
67680d3c 204 ktime_t *vblank_time,
3ed4351a
DV
205 bool in_vblank_irq);
206void drm_calc_timestamping_constants(struct drm_crtc *crtc,
207 const struct drm_display_mode *mode);
208wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc);
209#endif