1c349dbc7Sjsg /*
27f4dd379Sjsg * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
37f4dd379Sjsg * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
4c349dbc7Sjsg * Copyright (c) 2009-2010, Code Aurora Forum.
5c349dbc7Sjsg * Copyright 2016 Intel Corp.
67f4dd379Sjsg *
77f4dd379Sjsg * Permission is hereby granted, free of charge, to any person obtaining a
87f4dd379Sjsg * copy of this software and associated documentation files (the "Software"),
97f4dd379Sjsg * to deal in the Software without restriction, including without limitation
107f4dd379Sjsg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
117f4dd379Sjsg * and/or sell copies of the Software, and to permit persons to whom the
127f4dd379Sjsg * Software is furnished to do so, subject to the following conditions:
137f4dd379Sjsg *
147f4dd379Sjsg * The above copyright notice and this permission notice (including the next
157f4dd379Sjsg * paragraph) shall be included in all copies or substantial portions of the
167f4dd379Sjsg * Software.
177f4dd379Sjsg *
187f4dd379Sjsg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
197f4dd379Sjsg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
207f4dd379Sjsg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
217f4dd379Sjsg * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
227f4dd379Sjsg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
237f4dd379Sjsg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
247f4dd379Sjsg * OTHER DEALINGS IN THE SOFTWARE.
257f4dd379Sjsg */
267f4dd379Sjsg
277f4dd379Sjsg #ifndef _DRM_DRV_H_
287f4dd379Sjsg #define _DRM_DRV_H_
297f4dd379Sjsg
307f4dd379Sjsg #include <linux/list.h>
317f4dd379Sjsg #include <linux/irqreturn.h>
327f4dd379Sjsg
33f005ef32Sjsg #include <video/nomodeset.h>
34f005ef32Sjsg
357f4dd379Sjsg #include <drm/drm_device.h>
367f4dd379Sjsg
37c349dbc7Sjsg #include <uvm/uvm_extern.h>
38c349dbc7Sjsg
397f4dd379Sjsg struct drm_file;
407f4dd379Sjsg struct drm_gem_object;
41c349dbc7Sjsg struct drm_master;
42c349dbc7Sjsg struct drm_minor;
435ca02815Sjsg struct dma_buf;
44c349dbc7Sjsg struct dma_buf_attachment;
457f4dd379Sjsg struct drm_display_mode;
467f4dd379Sjsg struct drm_mode_create_dumb;
477f4dd379Sjsg struct drm_printer;
485ca02815Sjsg struct sg_table;
497f4dd379Sjsg
50c349dbc7Sjsg /**
51c349dbc7Sjsg * enum drm_driver_feature - feature flags
52c349dbc7Sjsg *
53c349dbc7Sjsg * See &drm_driver.driver_features, drm_device.driver_features and
54c349dbc7Sjsg * drm_core_check_feature().
55c349dbc7Sjsg */
56c349dbc7Sjsg enum drm_driver_feature {
57c349dbc7Sjsg /**
58c349dbc7Sjsg * @DRIVER_GEM:
59c349dbc7Sjsg *
60c349dbc7Sjsg * Driver use the GEM memory manager. This should be set for all modern
61c349dbc7Sjsg * drivers.
62c349dbc7Sjsg */
63c349dbc7Sjsg DRIVER_GEM = BIT(0),
64c349dbc7Sjsg /**
65c349dbc7Sjsg * @DRIVER_MODESET:
66c349dbc7Sjsg *
67c349dbc7Sjsg * Driver supports mode setting interfaces (KMS).
68c349dbc7Sjsg */
69c349dbc7Sjsg DRIVER_MODESET = BIT(1),
70c349dbc7Sjsg /**
71c349dbc7Sjsg * @DRIVER_RENDER:
72c349dbc7Sjsg *
73c349dbc7Sjsg * Driver supports dedicated render nodes. See also the :ref:`section on
74c349dbc7Sjsg * render nodes <drm_render_node>` for details.
75c349dbc7Sjsg */
76c349dbc7Sjsg DRIVER_RENDER = BIT(3),
77c349dbc7Sjsg /**
78c349dbc7Sjsg * @DRIVER_ATOMIC:
79c349dbc7Sjsg *
80c349dbc7Sjsg * Driver supports the full atomic modesetting userspace API. Drivers
815ca02815Sjsg * which only use atomic internally, but do not support the full
82c349dbc7Sjsg * userspace API (e.g. not all properties converted to atomic, or
83c349dbc7Sjsg * multi-plane updates are not guaranteed to be tear-free) should not
84c349dbc7Sjsg * set this flag.
85c349dbc7Sjsg */
86c349dbc7Sjsg DRIVER_ATOMIC = BIT(4),
87c349dbc7Sjsg /**
88c349dbc7Sjsg * @DRIVER_SYNCOBJ:
89c349dbc7Sjsg *
90c349dbc7Sjsg * Driver supports &drm_syncobj for explicit synchronization of command
91c349dbc7Sjsg * submission.
92c349dbc7Sjsg */
93c349dbc7Sjsg DRIVER_SYNCOBJ = BIT(5),
94c349dbc7Sjsg /**
95c349dbc7Sjsg * @DRIVER_SYNCOBJ_TIMELINE:
96c349dbc7Sjsg *
97c349dbc7Sjsg * Driver supports the timeline flavor of &drm_syncobj for explicit
98c349dbc7Sjsg * synchronization of command submission.
99c349dbc7Sjsg */
100c349dbc7Sjsg DRIVER_SYNCOBJ_TIMELINE = BIT(6),
101f005ef32Sjsg /**
102f005ef32Sjsg * @DRIVER_COMPUTE_ACCEL:
103f005ef32Sjsg *
104f005ef32Sjsg * Driver supports compute acceleration devices. This flag is mutually exclusive with
105f005ef32Sjsg * @DRIVER_RENDER and @DRIVER_MODESET. Devices that support both graphics and compute
106f005ef32Sjsg * acceleration should be handled by two drivers that are connected using auxiliary bus.
107f005ef32Sjsg */
108f005ef32Sjsg DRIVER_COMPUTE_ACCEL = BIT(7),
109f005ef32Sjsg /**
110f005ef32Sjsg * @DRIVER_GEM_GPUVA:
111f005ef32Sjsg *
112f005ef32Sjsg * Driver supports user defined GPU VA bindings for GEM objects.
113f005ef32Sjsg */
114f005ef32Sjsg DRIVER_GEM_GPUVA = BIT(8),
115*cab70de6Sjsg /**
116*cab70de6Sjsg * @DRIVER_CURSOR_HOTSPOT:
117*cab70de6Sjsg *
118*cab70de6Sjsg * Driver supports and requires cursor hotspot information in the
119*cab70de6Sjsg * cursor plane (e.g. cursor plane has to actually track the mouse
120*cab70de6Sjsg * cursor and the clients are required to set hotspot in order for
121*cab70de6Sjsg * the cursor planes to work correctly).
122*cab70de6Sjsg */
123*cab70de6Sjsg DRIVER_CURSOR_HOTSPOT = BIT(9),
1247f4dd379Sjsg
125c349dbc7Sjsg /* IMPORTANT: Below are all the legacy flags, add new ones above. */
126c349dbc7Sjsg
127c349dbc7Sjsg /**
128c349dbc7Sjsg * @DRIVER_USE_AGP:
129c349dbc7Sjsg *
130c349dbc7Sjsg * Set up DRM AGP support, see drm_agp_init(), the DRM core will manage
131c349dbc7Sjsg * AGP resources. New drivers don't need this.
132c349dbc7Sjsg */
133c349dbc7Sjsg DRIVER_USE_AGP = BIT(25),
134c349dbc7Sjsg /**
135c349dbc7Sjsg * @DRIVER_LEGACY:
136c349dbc7Sjsg *
137c349dbc7Sjsg * Denote a legacy driver using shadow attach. Do not use.
138c349dbc7Sjsg */
139c349dbc7Sjsg DRIVER_LEGACY = BIT(26),
140c349dbc7Sjsg /**
141c349dbc7Sjsg * @DRIVER_PCI_DMA:
142c349dbc7Sjsg *
143c349dbc7Sjsg * Driver is capable of PCI DMA, mapping of PCI DMA buffers to userspace
144c349dbc7Sjsg * will be enabled. Only for legacy drivers. Do not use.
145c349dbc7Sjsg */
146c349dbc7Sjsg DRIVER_PCI_DMA = BIT(27),
147c349dbc7Sjsg /**
148c349dbc7Sjsg * @DRIVER_SG:
149c349dbc7Sjsg *
150c349dbc7Sjsg * Driver can perform scatter/gather DMA, allocation and mapping of
151c349dbc7Sjsg * scatter/gather buffers will be enabled. Only for legacy drivers. Do
152c349dbc7Sjsg * not use.
153c349dbc7Sjsg */
154c349dbc7Sjsg DRIVER_SG = BIT(28),
155c349dbc7Sjsg
156c349dbc7Sjsg /**
157c349dbc7Sjsg * @DRIVER_HAVE_DMA:
158c349dbc7Sjsg *
159c349dbc7Sjsg * Driver supports DMA, the userspace DMA API will be supported. Only
160c349dbc7Sjsg * for legacy drivers. Do not use.
161c349dbc7Sjsg */
162c349dbc7Sjsg DRIVER_HAVE_DMA = BIT(29),
163c349dbc7Sjsg /**
164c349dbc7Sjsg * @DRIVER_HAVE_IRQ:
165c349dbc7Sjsg *
166c349dbc7Sjsg * Legacy irq support. Only for legacy drivers. Do not use.
167c349dbc7Sjsg */
168c349dbc7Sjsg DRIVER_HAVE_IRQ = BIT(30),
169c349dbc7Sjsg };
170c349dbc7Sjsg
171c349dbc7Sjsg /**
172c349dbc7Sjsg * struct drm_driver - DRM driver structure
173c349dbc7Sjsg *
174c349dbc7Sjsg * This structure represent the common code for a family of cards. There will be
175c349dbc7Sjsg * one &struct drm_device for each card present in this family. It contains lots
176c349dbc7Sjsg * of vfunc entries, and a pile of those probably should be moved to more
177c349dbc7Sjsg * appropriate places like &drm_mode_config_funcs or into a new operations
178c349dbc7Sjsg * structure for GEM drivers.
179c349dbc7Sjsg */
1807f4dd379Sjsg struct drm_driver {
181c349dbc7Sjsg /**
182c349dbc7Sjsg * @load:
183c349dbc7Sjsg *
184ad8b1aafSjsg * Backward-compatible driver callback to complete initialization steps
185ad8b1aafSjsg * after the driver is registered. For this reason, may suffer from
186ad8b1aafSjsg * race conditions and its use is deprecated for new drivers. It is
187ad8b1aafSjsg * therefore only supported for existing drivers not yet converted to
188ad8b1aafSjsg * the new scheme. See devm_drm_dev_alloc() and drm_dev_register() for
189ad8b1aafSjsg * proper and race-free way to set up a &struct drm_device.
190c349dbc7Sjsg *
191c349dbc7Sjsg * This is deprecated, do not use!
192c349dbc7Sjsg *
193c349dbc7Sjsg * Returns:
194c349dbc7Sjsg *
195c349dbc7Sjsg * Zero on success, non-zero value on failure.
196c349dbc7Sjsg */
197c349dbc7Sjsg int (*load) (struct drm_device *, unsigned long flags);
198c349dbc7Sjsg
199c349dbc7Sjsg /**
200c349dbc7Sjsg * @open:
201c349dbc7Sjsg *
202c349dbc7Sjsg * Driver callback when a new &struct drm_file is opened. Useful for
203c349dbc7Sjsg * setting up driver-private data structures like buffer allocators,
204c349dbc7Sjsg * execution contexts or similar things. Such driver-private resources
205c349dbc7Sjsg * must be released again in @postclose.
206c349dbc7Sjsg *
207c349dbc7Sjsg * Since the display/modeset side of DRM can only be owned by exactly
208c349dbc7Sjsg * one &struct drm_file (see &drm_file.is_master and &drm_device.master)
209c349dbc7Sjsg * there should never be a need to set up any modeset related resources
210c349dbc7Sjsg * in this callback. Doing so would be a driver design bug.
211c349dbc7Sjsg *
212c349dbc7Sjsg * Returns:
213c349dbc7Sjsg *
214c349dbc7Sjsg * 0 on success, a negative error code on failure, which will be
215c349dbc7Sjsg * promoted to userspace as the result of the open() system call.
216c349dbc7Sjsg */
2177f4dd379Sjsg int (*open) (struct drm_device *, struct drm_file *);
218c349dbc7Sjsg
219c349dbc7Sjsg /**
220c349dbc7Sjsg * @postclose:
221c349dbc7Sjsg *
222c349dbc7Sjsg * One of the driver callbacks when a new &struct drm_file is closed.
223c349dbc7Sjsg * Useful for tearing down driver-private data structures allocated in
224c349dbc7Sjsg * @open like buffer allocators, execution contexts or similar things.
225c349dbc7Sjsg *
226c349dbc7Sjsg * Since the display/modeset side of DRM can only be owned by exactly
227c349dbc7Sjsg * one &struct drm_file (see &drm_file.is_master and &drm_device.master)
228c349dbc7Sjsg * there should never be a need to tear down any modeset related
229c349dbc7Sjsg * resources in this callback. Doing so would be a driver design bug.
230c349dbc7Sjsg */
2317f4dd379Sjsg void (*postclose) (struct drm_device *, struct drm_file *);
232c349dbc7Sjsg
233c349dbc7Sjsg /**
234c349dbc7Sjsg * @lastclose:
235c349dbc7Sjsg *
236c349dbc7Sjsg * Called when the last &struct drm_file has been closed and there's
237c349dbc7Sjsg * currently no userspace client for the &struct drm_device.
238c349dbc7Sjsg *
239c349dbc7Sjsg * Modern drivers should only use this to force-restore the fbdev
240c349dbc7Sjsg * framebuffer using drm_fb_helper_restore_fbdev_mode_unlocked().
241c349dbc7Sjsg * Anything else would indicate there's something seriously wrong.
242c349dbc7Sjsg * Modern drivers can also use this to execute delayed power switching
243c349dbc7Sjsg * state changes, e.g. in conjunction with the :ref:`vga_switcheroo`
244c349dbc7Sjsg * infrastructure.
245c349dbc7Sjsg *
246c349dbc7Sjsg * This is called after @postclose hook has been called.
247c349dbc7Sjsg *
248c349dbc7Sjsg * NOTE:
249c349dbc7Sjsg *
250c349dbc7Sjsg * All legacy drivers use this callback to de-initialize the hardware.
251c349dbc7Sjsg * This is purely because of the shadow-attach model, where the DRM
252c349dbc7Sjsg * kernel driver does not really own the hardware. Instead ownershipe is
253c349dbc7Sjsg * handled with the help of userspace through an inheritedly racy dance
254c349dbc7Sjsg * to set/unset the VT into raw mode.
255c349dbc7Sjsg *
256c349dbc7Sjsg * Legacy drivers initialize the hardware in the @firstopen callback,
257c349dbc7Sjsg * which isn't even called for modern drivers.
258c349dbc7Sjsg */
2597f4dd379Sjsg void (*lastclose) (struct drm_device *);
2607f4dd379Sjsg
2617f4dd379Sjsg /**
262c349dbc7Sjsg * @unload:
2637f4dd379Sjsg *
264c349dbc7Sjsg * Reverse the effects of the driver load callback. Ideally,
265c349dbc7Sjsg * the clean up performed by the driver should happen in the
266c349dbc7Sjsg * reverse order of the initialization. Similarly to the load
267c349dbc7Sjsg * hook, this handler is deprecated and its usage should be
268c349dbc7Sjsg * dropped in favor of an open-coded teardown function at the
269c349dbc7Sjsg * driver layer. See drm_dev_unregister() and drm_dev_put()
270c349dbc7Sjsg * for the proper way to remove a &struct drm_device.
2717f4dd379Sjsg *
272c349dbc7Sjsg * The unload() hook is called right after unregistering
273c349dbc7Sjsg * the device.
2747f4dd379Sjsg *
2757f4dd379Sjsg */
276c349dbc7Sjsg void (*unload) (struct drm_device *);
2777f4dd379Sjsg
2787f4dd379Sjsg /**
279c349dbc7Sjsg * @release:
2807f4dd379Sjsg *
281c349dbc7Sjsg * Optional callback for destroying device data after the final
282ad8b1aafSjsg * reference is released, i.e. the device is being destroyed.
283ad8b1aafSjsg *
284ad8b1aafSjsg * This is deprecated, clean up all memory allocations associated with a
285ad8b1aafSjsg * &drm_device using drmm_add_action(), drmm_kmalloc() and related
286ad8b1aafSjsg * managed resources functions.
2877f4dd379Sjsg */
288c349dbc7Sjsg void (*release) (struct drm_device *);
2897f4dd379Sjsg
2907f4dd379Sjsg /**
291c349dbc7Sjsg * @master_set:
292c349dbc7Sjsg *
293c349dbc7Sjsg * Called whenever the minor master is set. Only used by vmwgfx.
294c349dbc7Sjsg */
295ad8b1aafSjsg void (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
296c349dbc7Sjsg bool from_open);
297c349dbc7Sjsg /**
298c349dbc7Sjsg * @master_drop:
299c349dbc7Sjsg *
300c349dbc7Sjsg * Called whenever the minor master is dropped. Only used by vmwgfx.
301c349dbc7Sjsg */
302c349dbc7Sjsg void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv);
303c349dbc7Sjsg
304c349dbc7Sjsg /**
305c349dbc7Sjsg * @debugfs_init:
306c349dbc7Sjsg *
307c349dbc7Sjsg * Allows drivers to create driver-specific debugfs files.
308c349dbc7Sjsg */
309ad8b1aafSjsg void (*debugfs_init)(struct drm_minor *minor);
310c349dbc7Sjsg
311c349dbc7Sjsg /**
312c349dbc7Sjsg * @gem_create_object: constructor for gem objects
313c349dbc7Sjsg *
3141bb76ff1Sjsg * Hook for allocating the GEM object struct, for use by the CMA
3151bb76ff1Sjsg * and SHMEM GEM helpers. Returns a GEM object on success, or an
3161bb76ff1Sjsg * ERR_PTR()-encoded error code otherwise.
317c349dbc7Sjsg */
318c349dbc7Sjsg struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
319c349dbc7Sjsg size_t size);
3205ca02815Sjsg
321c349dbc7Sjsg /**
322c349dbc7Sjsg * @prime_handle_to_fd:
323c349dbc7Sjsg *
324f005ef32Sjsg * PRIME export function. Only used by vmwgfx.
325c349dbc7Sjsg */
3267f4dd379Sjsg int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
3277f4dd379Sjsg uint32_t handle, uint32_t flags, int *prime_fd);
328c349dbc7Sjsg /**
329c349dbc7Sjsg * @prime_fd_to_handle:
330c349dbc7Sjsg *
331f005ef32Sjsg * PRIME import function. Only used by vmwgfx.
332c349dbc7Sjsg */
3337f4dd379Sjsg int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
3347f4dd379Sjsg int prime_fd, uint32_t *handle);
3355ca02815Sjsg
336c349dbc7Sjsg /**
337c349dbc7Sjsg * @gem_prime_import:
338c349dbc7Sjsg *
339c349dbc7Sjsg * Import hook for GEM drivers.
340c349dbc7Sjsg *
341c349dbc7Sjsg * This defaults to drm_gem_prime_import() if not set.
342c349dbc7Sjsg */
3437f4dd379Sjsg struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
3447f4dd379Sjsg struct dma_buf *dma_buf);
345c349dbc7Sjsg /**
346c349dbc7Sjsg * @gem_prime_import_sg_table:
347c349dbc7Sjsg *
348c349dbc7Sjsg * Optional hook used by the PRIME helper functions
349c349dbc7Sjsg * drm_gem_prime_import() respectively drm_gem_prime_import_dev().
350c349dbc7Sjsg */
351c349dbc7Sjsg struct drm_gem_object *(*gem_prime_import_sg_table)(
352c349dbc7Sjsg struct drm_device *dev,
353c349dbc7Sjsg struct dma_buf_attachment *attach,
354c349dbc7Sjsg struct sg_table *sgt);
355c349dbc7Sjsg
356c349dbc7Sjsg #ifdef __OpenBSD__
357c349dbc7Sjsg struct uvm_object *(*mmap)(struct file *, vm_prot_t, voff_t, vsize_t);
3587f4dd379Sjsg size_t gem_size;
359c349dbc7Sjsg #endif
3607f4dd379Sjsg
361c349dbc7Sjsg /**
362c349dbc7Sjsg * @dumb_create:
363c349dbc7Sjsg *
364c349dbc7Sjsg * This creates a new dumb buffer in the driver's backing storage manager (GEM,
365c349dbc7Sjsg * TTM or something else entirely) and returns the resulting buffer handle. This
366c349dbc7Sjsg * handle can then be wrapped up into a framebuffer modeset object.
367c349dbc7Sjsg *
368c349dbc7Sjsg * Note that userspace is not allowed to use such objects for render
369c349dbc7Sjsg * acceleration - drivers must create their own private ioctls for such a use
370c349dbc7Sjsg * case.
371c349dbc7Sjsg *
372c349dbc7Sjsg * Width, height and depth are specified in the &drm_mode_create_dumb
373c349dbc7Sjsg * argument. The callback needs to fill the handle, pitch and size for
374c349dbc7Sjsg * the created buffer.
375c349dbc7Sjsg *
376c349dbc7Sjsg * Called by the user via ioctl.
377c349dbc7Sjsg *
378c349dbc7Sjsg * Returns:
379c349dbc7Sjsg *
380c349dbc7Sjsg * Zero on success, negative errno on failure.
381c349dbc7Sjsg */
382c349dbc7Sjsg int (*dumb_create)(struct drm_file *file_priv,
383c349dbc7Sjsg struct drm_device *dev,
384c349dbc7Sjsg struct drm_mode_create_dumb *args);
385c349dbc7Sjsg /**
386c349dbc7Sjsg * @dumb_map_offset:
387c349dbc7Sjsg *
388c349dbc7Sjsg * Allocate an offset in the drm device node's address space to be able to
389c349dbc7Sjsg * memory map a dumb buffer.
390c349dbc7Sjsg *
391c349dbc7Sjsg * The default implementation is drm_gem_create_mmap_offset(). GEM based
392c349dbc7Sjsg * drivers must not overwrite this.
393c349dbc7Sjsg *
394c349dbc7Sjsg * Called by the user via ioctl.
395c349dbc7Sjsg *
396c349dbc7Sjsg * Returns:
397c349dbc7Sjsg *
398c349dbc7Sjsg * Zero on success, negative errno on failure.
399c349dbc7Sjsg */
400c349dbc7Sjsg int (*dumb_map_offset)(struct drm_file *file_priv,
401c349dbc7Sjsg struct drm_device *dev, uint32_t handle,
402c349dbc7Sjsg uint64_t *offset);
403f005ef32Sjsg
404c349dbc7Sjsg /**
405f005ef32Sjsg * @show_fdinfo:
406c349dbc7Sjsg *
407f005ef32Sjsg * Print device specific fdinfo. See Documentation/gpu/drm-usage-stats.rst.
408c349dbc7Sjsg */
409f005ef32Sjsg void (*show_fdinfo)(struct drm_printer *p, struct drm_file *f);
410c349dbc7Sjsg
411c349dbc7Sjsg #ifdef __OpenBSD__
412c349dbc7Sjsg int (*gem_fault)(struct drm_gem_object *,
413c349dbc7Sjsg struct uvm_faultinfo *, off_t, vaddr_t,
414c349dbc7Sjsg vm_page_t *, int, int, vm_prot_t, int);
415c349dbc7Sjsg #endif
416c349dbc7Sjsg
417c349dbc7Sjsg /** @major: driver major number */
4187f4dd379Sjsg int major;
419c349dbc7Sjsg /** @minor: driver minor number */
4207f4dd379Sjsg int minor;
421c349dbc7Sjsg /** @patchlevel: driver patch level */
4227f4dd379Sjsg int patchlevel;
423c349dbc7Sjsg /** @name: driver name */
424c349dbc7Sjsg char *name;
425c349dbc7Sjsg /** @desc: driver description */
426c349dbc7Sjsg char *desc;
427c349dbc7Sjsg /** @date: driver date */
428c349dbc7Sjsg char *date;
4297f4dd379Sjsg
430c349dbc7Sjsg /**
431c349dbc7Sjsg * @driver_features:
432c349dbc7Sjsg * Driver features, see &enum drm_driver_feature. Drivers can disable
433c349dbc7Sjsg * some features on a per-instance basis using
434c349dbc7Sjsg * &drm_device.driver_features.
435c349dbc7Sjsg */
4367f4dd379Sjsg u32 driver_features;
437c349dbc7Sjsg
438c349dbc7Sjsg /**
439c349dbc7Sjsg * @ioctls:
440c349dbc7Sjsg *
441c349dbc7Sjsg * Array of driver-private IOCTL description entries. See the chapter on
442c349dbc7Sjsg * :ref:`IOCTL support in the userland interfaces
443c349dbc7Sjsg * chapter<drm_driver_ioctl>` for the full details.
444c349dbc7Sjsg */
445c349dbc7Sjsg
4467f4dd379Sjsg const struct drm_ioctl_desc *ioctls;
447c349dbc7Sjsg /** @num_ioctls: Number of entries in @ioctls. */
4487f4dd379Sjsg int num_ioctls;
4497f4dd379Sjsg
450c349dbc7Sjsg /**
451c349dbc7Sjsg * @fops:
452c349dbc7Sjsg *
453c349dbc7Sjsg * File operations for the DRM device node. See the discussion in
454c349dbc7Sjsg * :ref:`file operations<drm_driver_fops>` for in-depth coverage and
455c349dbc7Sjsg * some examples.
456c349dbc7Sjsg */
457c349dbc7Sjsg const struct file_operations *fops;
458c349dbc7Sjsg
4595ca02815Sjsg #ifdef CONFIG_DRM_LEGACY
460c349dbc7Sjsg /* Everything below here is for legacy driver, never use! */
461c349dbc7Sjsg /* private: */
462c349dbc7Sjsg
463c349dbc7Sjsg int (*firstopen) (struct drm_device *);
464c349dbc7Sjsg void (*preclose) (struct drm_device *, struct drm_file *file_priv);
465c349dbc7Sjsg int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
466c349dbc7Sjsg int (*dma_quiescent) (struct drm_device *);
467c349dbc7Sjsg int (*context_dtor) (struct drm_device *dev, int context);
4685ca02815Sjsg irqreturn_t (*irq_handler)(int irq, void *arg);
4695ca02815Sjsg void (*irq_preinstall)(struct drm_device *dev);
4705ca02815Sjsg int (*irq_postinstall)(struct drm_device *dev);
4715ca02815Sjsg void (*irq_uninstall)(struct drm_device *dev);
472c349dbc7Sjsg u32 (*get_vblank_counter)(struct drm_device *dev, unsigned int pipe);
473c349dbc7Sjsg int (*enable_vblank)(struct drm_device *dev, unsigned int pipe);
474c349dbc7Sjsg void (*disable_vblank)(struct drm_device *dev, unsigned int pipe);
475c349dbc7Sjsg int dev_priv_size;
4765ca02815Sjsg #endif
4777f4dd379Sjsg };
4787f4dd379Sjsg
4795ca02815Sjsg void *__devm_drm_dev_alloc(struct device *parent,
4805ca02815Sjsg const struct drm_driver *driver,
481ad8b1aafSjsg size_t size, size_t offset);
482ad8b1aafSjsg
483ad8b1aafSjsg /**
484ad8b1aafSjsg * devm_drm_dev_alloc - Resource managed allocation of a &drm_device instance
485ad8b1aafSjsg * @parent: Parent device object
486ad8b1aafSjsg * @driver: DRM driver
487ad8b1aafSjsg * @type: the type of the struct which contains struct &drm_device
488ad8b1aafSjsg * @member: the name of the &drm_device within @type.
489ad8b1aafSjsg *
490ad8b1aafSjsg * This allocates and initialize a new DRM device. No device registration is done.
491ad8b1aafSjsg * Call drm_dev_register() to advertice the device to user space and register it
492ad8b1aafSjsg * with other core subsystems. This should be done last in the device
493ad8b1aafSjsg * initialization sequence to make sure userspace can't access an inconsistent
494ad8b1aafSjsg * state.
495ad8b1aafSjsg *
496ad8b1aafSjsg * The initial ref-count of the object is 1. Use drm_dev_get() and
497ad8b1aafSjsg * drm_dev_put() to take and drop further ref-counts.
498ad8b1aafSjsg *
499ad8b1aafSjsg * It is recommended that drivers embed &struct drm_device into their own device
500ad8b1aafSjsg * structure.
501ad8b1aafSjsg *
502ad8b1aafSjsg * Note that this manages the lifetime of the resulting &drm_device
503ad8b1aafSjsg * automatically using devres. The DRM device initialized with this function is
504ad8b1aafSjsg * automatically put on driver detach using drm_dev_put().
505ad8b1aafSjsg *
506ad8b1aafSjsg * RETURNS:
507ad8b1aafSjsg * Pointer to new DRM device, or ERR_PTR on failure.
508ad8b1aafSjsg */
509ad8b1aafSjsg #define devm_drm_dev_alloc(parent, driver, type, member) \
510ad8b1aafSjsg ((type *) __devm_drm_dev_alloc(parent, driver, sizeof(type), \
511ad8b1aafSjsg offsetof(type, member)))
51290413e8eSjsg
5135ca02815Sjsg struct drm_device *drm_dev_alloc(const struct drm_driver *driver,
514c349dbc7Sjsg struct device *parent);
515c349dbc7Sjsg int drm_dev_register(struct drm_device *dev, unsigned long flags);
516c349dbc7Sjsg void drm_dev_unregister(struct drm_device *dev);
517c349dbc7Sjsg
518c349dbc7Sjsg void drm_dev_get(struct drm_device *dev);
519c349dbc7Sjsg void drm_dev_put(struct drm_device *dev);
520c349dbc7Sjsg void drm_put_dev(struct drm_device *dev);
521c349dbc7Sjsg bool drm_dev_enter(struct drm_device *dev, int *idx);
522c349dbc7Sjsg void drm_dev_exit(int idx);
523c349dbc7Sjsg void drm_dev_unplug(struct drm_device *dev);
524c349dbc7Sjsg
525c349dbc7Sjsg /**
526c349dbc7Sjsg * drm_dev_is_unplugged - is a DRM device unplugged
527c349dbc7Sjsg * @dev: DRM device
528c349dbc7Sjsg *
529c349dbc7Sjsg * This function can be called to check whether a hotpluggable is unplugged.
530c349dbc7Sjsg * Unplugging itself is singalled through drm_dev_unplug(). If a device is
531c349dbc7Sjsg * unplugged, these two functions guarantee that any store before calling
532c349dbc7Sjsg * drm_dev_unplug() is visible to callers of this function after it completes
533c349dbc7Sjsg *
534c349dbc7Sjsg * WARNING: This function fundamentally races against drm_dev_unplug(). It is
535c349dbc7Sjsg * recommended that drivers instead use the underlying drm_dev_enter() and
536c349dbc7Sjsg * drm_dev_exit() function pairs.
537c349dbc7Sjsg */
drm_dev_is_unplugged(struct drm_device * dev)538c349dbc7Sjsg static inline bool drm_dev_is_unplugged(struct drm_device *dev)
5397f4dd379Sjsg {
540c349dbc7Sjsg int idx;
541c349dbc7Sjsg
542c349dbc7Sjsg if (drm_dev_enter(dev, &idx)) {
543c349dbc7Sjsg drm_dev_exit(idx);
544c349dbc7Sjsg return false;
5457f4dd379Sjsg }
5467f4dd379Sjsg
547c349dbc7Sjsg return true;
548c349dbc7Sjsg }
549c349dbc7Sjsg
550c349dbc7Sjsg /**
551c349dbc7Sjsg * drm_core_check_all_features - check driver feature flags mask
552c349dbc7Sjsg * @dev: DRM device to check
553c349dbc7Sjsg * @features: feature flag(s) mask
554c349dbc7Sjsg *
555c349dbc7Sjsg * This checks @dev for driver features, see &drm_driver.driver_features,
556c349dbc7Sjsg * &drm_device.driver_features, and the various &enum drm_driver_feature flags.
557c349dbc7Sjsg *
558c349dbc7Sjsg * Returns true if all features in the @features mask are supported, false
559c349dbc7Sjsg * otherwise.
560c349dbc7Sjsg */
drm_core_check_all_features(const struct drm_device * dev,u32 features)561c349dbc7Sjsg static inline bool drm_core_check_all_features(const struct drm_device *dev,
562c349dbc7Sjsg u32 features)
5637f4dd379Sjsg {
564c349dbc7Sjsg u32 supported = dev->driver->driver_features & dev->driver_features;
565c349dbc7Sjsg
566c349dbc7Sjsg return features && (supported & features) == features;
5677f4dd379Sjsg }
5687f4dd379Sjsg
5697f4dd379Sjsg /**
5707f4dd379Sjsg * drm_core_check_feature - check driver feature flags
5717f4dd379Sjsg * @dev: DRM device to check
5727f4dd379Sjsg * @feature: feature flag
5737f4dd379Sjsg *
574c349dbc7Sjsg * This checks @dev for driver features, see &drm_driver.driver_features,
575c349dbc7Sjsg * &drm_device.driver_features, and the various &enum drm_driver_feature flags.
5767f4dd379Sjsg *
5777f4dd379Sjsg * Returns true if the @feature is supported, false otherwise.
5787f4dd379Sjsg */
drm_core_check_feature(const struct drm_device * dev,enum drm_driver_feature feature)579c349dbc7Sjsg static inline bool drm_core_check_feature(const struct drm_device *dev,
580c349dbc7Sjsg enum drm_driver_feature feature)
5817f4dd379Sjsg {
582c349dbc7Sjsg return drm_core_check_all_features(dev, feature);
5837f4dd379Sjsg }
5847f4dd379Sjsg
5857f4dd379Sjsg /**
5867f4dd379Sjsg * drm_drv_uses_atomic_modeset - check if the driver implements
5877f4dd379Sjsg * atomic_commit()
5887f4dd379Sjsg * @dev: DRM device
5897f4dd379Sjsg *
5907f4dd379Sjsg * This check is useful if drivers do not have DRIVER_ATOMIC set but
5917f4dd379Sjsg * have atomic modesetting internally implemented.
5927f4dd379Sjsg */
drm_drv_uses_atomic_modeset(struct drm_device * dev)5937f4dd379Sjsg static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
5947f4dd379Sjsg {
5957f4dd379Sjsg return drm_core_check_feature(dev, DRIVER_ATOMIC) ||
5967f4dd379Sjsg (dev->mode_config.funcs && dev->mode_config.funcs->atomic_commit != NULL);
5977f4dd379Sjsg }
5987f4dd379Sjsg
599c349dbc7Sjsg
600f005ef32Sjsg /* TODO: Inline drm_firmware_drivers_only() in all its callers. */
drm_firmware_drivers_only(void)601f005ef32Sjsg static inline bool drm_firmware_drivers_only(void)
602f005ef32Sjsg {
603f005ef32Sjsg return video_firmware_drivers_only();
604f005ef32Sjsg }
605c349dbc7Sjsg
606c349dbc7Sjsg struct drm_file *drm_find_file_by_minor(struct drm_device *, int);
607c349dbc7Sjsg struct drm_device *drm_get_device_from_kdev(dev_t);
608c349dbc7Sjsg
609c349dbc7Sjsg #ifdef __OpenBSD__
610c349dbc7Sjsg
611c349dbc7Sjsg void drm_attach_platform(struct drm_driver *, bus_space_tag_t, bus_dma_tag_t,
612c349dbc7Sjsg struct device *, struct drm_device *);
6135ca02815Sjsg struct drm_device *drm_attach_pci(const struct drm_driver *,
614c349dbc7Sjsg struct pci_attach_args *, int, int, struct device *, struct drm_device *);
615c349dbc7Sjsg
616c349dbc7Sjsg int drm_pciprobe(struct pci_attach_args *, const struct pci_device_id * );
617c349dbc7Sjsg const struct pci_device_id *drm_find_description(int, int,
618c349dbc7Sjsg const struct pci_device_id *);
619c349dbc7Sjsg
6207f4dd379Sjsg int drm_getpciinfo(struct drm_device *, void *, struct drm_file *);
621c349dbc7Sjsg
622c349dbc7Sjsg #endif
6237f4dd379Sjsg
6247f4dd379Sjsg #endif
625