blob: 0faf5ec72d1963047cb3495029a1d8acc98c8449 [file] [log] [blame]
Daniel Vetter85e634b2016-11-14 12:58:19 +01001/*
2 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
4 * Copyright (c) 2009-2010, Code Aurora Forum.
5 * Copyright 2016 Intel Corp.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27#ifndef _DRM_DRV_H_
28#define _DRM_DRV_H_
29
30#include <linux/list.h>
31#include <linux/irqreturn.h>
32
33struct drm_device;
34struct drm_file;
35struct drm_gem_object;
36struct drm_master;
37struct drm_minor;
38struct dma_buf_attachment;
39struct drm_display_mode;
40struct drm_mode_create_dumb;
41
42/* driver capabilities and requirements mask */
43#define DRIVER_USE_AGP 0x1
44#define DRIVER_LEGACY 0x2
45#define DRIVER_PCI_DMA 0x8
46#define DRIVER_SG 0x10
47#define DRIVER_HAVE_DMA 0x20
48#define DRIVER_HAVE_IRQ 0x40
49#define DRIVER_IRQ_SHARED 0x80
50#define DRIVER_GEM 0x1000
51#define DRIVER_MODESET 0x2000
52#define DRIVER_PRIME 0x4000
53#define DRIVER_RENDER 0x8000
54#define DRIVER_ATOMIC 0x10000
55#define DRIVER_KMS_LEGACY_CONTEXT 0x20000
56
57/**
58 * struct drm_driver - DRM driver structure
59 *
60 * This structure represent the common code for a family of cards. There will
61 * one drm_device for each card present in this family. It contains lots of
62 * vfunc entries, and a pile of those probably should be moved to more
63 * appropriate places like &drm_mode_config_funcs or into a new operations
64 * structure for GEM drivers.
65 */
66struct drm_driver {
67 int (*load) (struct drm_device *, unsigned long flags);
68 int (*firstopen) (struct drm_device *);
69 int (*open) (struct drm_device *, struct drm_file *);
70 void (*preclose) (struct drm_device *, struct drm_file *file_priv);
71 void (*postclose) (struct drm_device *, struct drm_file *);
72 void (*lastclose) (struct drm_device *);
73 int (*unload) (struct drm_device *);
74 int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
75 int (*dma_quiescent) (struct drm_device *);
76 int (*context_dtor) (struct drm_device *dev, int context);
77 int (*set_busid)(struct drm_device *dev, struct drm_master *master);
78
79 /**
80 * get_vblank_counter - get raw hardware vblank counter
81 * @dev: DRM device
82 * @pipe: counter to fetch
83 *
84 * Driver callback for fetching a raw hardware vblank counter for @crtc.
85 * If a device doesn't have a hardware counter, the driver can simply
86 * use drm_vblank_no_hw_counter() function. The DRM core will account for
87 * missed vblank events while interrupts where disabled based on system
88 * timestamps.
89 *
90 * Wraparound handling and loss of events due to modesetting is dealt
91 * with in the DRM core code.
92 *
93 * RETURNS
94 * Raw vblank counter value.
95 */
96 u32 (*get_vblank_counter) (struct drm_device *dev, unsigned int pipe);
97
98 /**
99 * enable_vblank - enable vblank interrupt events
100 * @dev: DRM device
101 * @pipe: which irq to enable
102 *
103 * Enable vblank interrupts for @crtc. If the device doesn't have
104 * a hardware vblank counter, the driver should use the
105 * drm_vblank_no_hw_counter() function that keeps a virtual counter.
106 *
107 * RETURNS
108 * Zero on success, appropriate errno if the given @crtc's vblank
109 * interrupt cannot be enabled.
110 */
111 int (*enable_vblank) (struct drm_device *dev, unsigned int pipe);
112
113 /**
114 * disable_vblank - disable vblank interrupt events
115 * @dev: DRM device
116 * @pipe: which irq to enable
117 *
118 * Disable vblank interrupts for @crtc. If the device doesn't have
119 * a hardware vblank counter, the driver should use the
120 * drm_vblank_no_hw_counter() function that keeps a virtual counter.
121 */
122 void (*disable_vblank) (struct drm_device *dev, unsigned int pipe);
123
124 /**
125 * Called by \c drm_device_is_agp. Typically used to determine if a
126 * card is really attached to AGP or not.
127 *
128 * \param dev DRM device handle
129 *
130 * \returns
131 * One of three values is returned depending on whether or not the
132 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
133 * (return of 1), or may or may not be AGP (return of 2).
134 */
135 int (*device_is_agp) (struct drm_device *dev);
136
137 /**
138 * Called by vblank timestamping code.
139 *
140 * Return the current display scanout position from a crtc, and an
141 * optional accurate ktime_get timestamp of when position was measured.
142 *
143 * \param dev DRM device.
144 * \param pipe Id of the crtc to query.
145 * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
146 * \param *vpos Target location for current vertical scanout position.
147 * \param *hpos Target location for current horizontal scanout position.
148 * \param *stime Target location for timestamp taken immediately before
149 * scanout position query. Can be NULL to skip timestamp.
150 * \param *etime Target location for timestamp taken immediately after
151 * scanout position query. Can be NULL to skip timestamp.
152 * \param mode Current display timings.
153 *
154 * Returns vpos as a positive number while in active scanout area.
155 * Returns vpos as a negative number inside vblank, counting the number
156 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
157 * until start of active scanout / end of vblank."
158 *
159 * \return Flags, or'ed together as follows:
160 *
161 * DRM_SCANOUTPOS_VALID = Query successful.
162 * DRM_SCANOUTPOS_INVBL = Inside vblank.
163 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
164 * this flag means that returned position may be offset by a constant
165 * but unknown small number of scanlines wrt. real scanout position.
166 *
167 */
168 int (*get_scanout_position) (struct drm_device *dev, unsigned int pipe,
169 unsigned int flags, int *vpos, int *hpos,
170 ktime_t *stime, ktime_t *etime,
171 const struct drm_display_mode *mode);
172
173 /**
174 * Called by \c drm_get_last_vbltimestamp. Should return a precise
175 * timestamp when the most recent VBLANK interval ended or will end.
176 *
177 * Specifically, the timestamp in @vblank_time should correspond as
178 * closely as possible to the time when the first video scanline of
179 * the video frame after the end of VBLANK will start scanning out,
180 * the time immediately after end of the VBLANK interval. If the
181 * @crtc is currently inside VBLANK, this will be a time in the future.
182 * If the @crtc is currently scanning out a frame, this will be the
183 * past start time of the current scanout. This is meant to adhere
184 * to the OpenML OML_sync_control extension specification.
185 *
186 * \param dev dev DRM device handle.
187 * \param pipe crtc for which timestamp should be returned.
188 * \param *max_error Maximum allowable timestamp error in nanoseconds.
189 * Implementation should strive to provide timestamp
190 * with an error of at most *max_error nanoseconds.
191 * Returns true upper bound on error for timestamp.
192 * \param *vblank_time Target location for returned vblank timestamp.
193 * \param flags 0 = Defaults, no special treatment needed.
194 * \param DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
195 * irq handler. Some drivers need to apply some workarounds
196 * for gpu-specific vblank irq quirks if flag is set.
197 *
198 * \returns
199 * Zero if timestamping isn't supported in current display mode or a
200 * negative number on failure. A positive status code on success,
201 * which describes how the vblank_time timestamp was computed.
202 */
203 int (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe,
204 int *max_error,
205 struct timeval *vblank_time,
206 unsigned flags);
207
208 /* these have to be filled in */
209
210 irqreturn_t(*irq_handler) (int irq, void *arg);
211 void (*irq_preinstall) (struct drm_device *dev);
212 int (*irq_postinstall) (struct drm_device *dev);
213 void (*irq_uninstall) (struct drm_device *dev);
214
215 /* Master routines */
216 int (*master_create)(struct drm_device *dev, struct drm_master *master);
217 void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
218 /**
219 * master_set is called whenever the minor master is set.
220 * master_drop is called whenever the minor master is dropped.
221 */
222
223 int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
224 bool from_open);
225 void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv);
226
227 int (*debugfs_init)(struct drm_minor *minor);
228 void (*debugfs_cleanup)(struct drm_minor *minor);
229
230 /**
231 * @gem_free_object: deconstructor for drm_gem_objects
232 *
233 * This is deprecated and should not be used by new drivers. Use
234 * @gem_free_object_unlocked instead.
235 */
236 void (*gem_free_object) (struct drm_gem_object *obj);
237
238 /**
239 * @gem_free_object_unlocked: deconstructor for drm_gem_objects
240 *
241 * This is for drivers which are not encumbered with dev->struct_mutex
242 * legacy locking schemes. Use this hook instead of @gem_free_object.
243 */
244 void (*gem_free_object_unlocked) (struct drm_gem_object *obj);
245
246 int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
247 void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
248
249 /**
250 * Hook for allocating the GEM object struct, for use by core
251 * helpers.
252 */
253 struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
254 size_t size);
255
256 /* prime: */
257 /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
258 int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
259 uint32_t handle, uint32_t flags, int *prime_fd);
260 /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
261 int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
262 int prime_fd, uint32_t *handle);
263 /* export GEM -> dmabuf */
264 struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
265 struct drm_gem_object *obj, int flags);
266 /* import dmabuf -> GEM */
267 struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
268 struct dma_buf *dma_buf);
269 /* low-level interface used by drm_gem_prime_{import,export} */
270 int (*gem_prime_pin)(struct drm_gem_object *obj);
271 void (*gem_prime_unpin)(struct drm_gem_object *obj);
272 struct reservation_object * (*gem_prime_res_obj)(
273 struct drm_gem_object *obj);
274 struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
275 struct drm_gem_object *(*gem_prime_import_sg_table)(
276 struct drm_device *dev,
277 struct dma_buf_attachment *attach,
278 struct sg_table *sgt);
279 void *(*gem_prime_vmap)(struct drm_gem_object *obj);
280 void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
281 int (*gem_prime_mmap)(struct drm_gem_object *obj,
282 struct vm_area_struct *vma);
283
284 /* vga arb irq handler */
285 void (*vgaarb_irq)(struct drm_device *dev, bool state);
286
287 /* dumb alloc support */
288 int (*dumb_create)(struct drm_file *file_priv,
289 struct drm_device *dev,
290 struct drm_mode_create_dumb *args);
291 int (*dumb_map_offset)(struct drm_file *file_priv,
292 struct drm_device *dev, uint32_t handle,
293 uint64_t *offset);
294 int (*dumb_destroy)(struct drm_file *file_priv,
295 struct drm_device *dev,
296 uint32_t handle);
297
298 /* Driver private ops for this object */
299 const struct vm_operations_struct *gem_vm_ops;
300
301 int major;
302 int minor;
303 int patchlevel;
304 char *name;
305 char *desc;
306 char *date;
307
308 u32 driver_features;
309 int dev_priv_size;
310 const struct drm_ioctl_desc *ioctls;
311 int num_ioctls;
312 const struct file_operations *fops;
313
314 /* List of devices hanging off this driver with stealth attach. */
315 struct list_head legacy_dev_list;
316};
317
318extern __printf(6, 7)
319void drm_dev_printk(const struct device *dev, const char *level,
320 unsigned int category, const char *function_name,
321 const char *prefix, const char *format, ...);
322extern __printf(3, 4)
323void drm_printk(const char *level, unsigned int category,
324 const char *format, ...);
325extern unsigned int drm_debug;
326
327int drm_dev_init(struct drm_device *dev,
328 struct drm_driver *driver,
329 struct device *parent);
330struct drm_device *drm_dev_alloc(struct drm_driver *driver,
331 struct device *parent);
332int drm_dev_register(struct drm_device *dev, unsigned long flags);
333void drm_dev_unregister(struct drm_device *dev);
334
335void drm_dev_ref(struct drm_device *dev);
336void drm_dev_unref(struct drm_device *dev);
337void drm_put_dev(struct drm_device *dev);
338void drm_unplug_dev(struct drm_device *dev);
339
340#endif