drm_drv.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. /*
  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. #ifndef _DRM_DRV_H_
  27. #define _DRM_DRV_H_
  28. #include <linux/list.h>
  29. #include <linux/irqreturn.h>
  30. struct drm_device;
  31. struct drm_file;
  32. struct drm_gem_object;
  33. struct drm_master;
  34. struct drm_minor;
  35. struct dma_buf_attachment;
  36. struct drm_display_mode;
  37. struct drm_mode_create_dumb;
  38. /* driver capabilities and requirements mask */
  39. #define DRIVER_USE_AGP 0x1
  40. #define DRIVER_LEGACY 0x2
  41. #define DRIVER_PCI_DMA 0x8
  42. #define DRIVER_SG 0x10
  43. #define DRIVER_HAVE_DMA 0x20
  44. #define DRIVER_HAVE_IRQ 0x40
  45. #define DRIVER_IRQ_SHARED 0x80
  46. #define DRIVER_GEM 0x1000
  47. #define DRIVER_MODESET 0x2000
  48. #define DRIVER_PRIME 0x4000
  49. #define DRIVER_RENDER 0x8000
  50. #define DRIVER_ATOMIC 0x10000
  51. #define DRIVER_KMS_LEGACY_CONTEXT 0x20000
  52. /**
  53. * struct drm_driver - DRM driver structure
  54. *
  55. * This structure represent the common code for a family of cards. There will
  56. * one drm_device for each card present in this family. It contains lots of
  57. * vfunc entries, and a pile of those probably should be moved to more
  58. * appropriate places like &drm_mode_config_funcs or into a new operations
  59. * structure for GEM drivers.
  60. */
  61. struct drm_driver {
  62. /**
  63. * @load:
  64. *
  65. * Backward-compatible driver callback to complete
  66. * initialization steps after the driver is registered. For
  67. * this reason, may suffer from race conditions and its use is
  68. * deprecated for new drivers. It is therefore only supported
  69. * for existing drivers not yet converted to the new scheme.
  70. * See drm_dev_init() and drm_dev_register() for proper and
  71. * race-free way to set up a &struct drm_device.
  72. *
  73. * Returns:
  74. *
  75. * Zero on success, non-zero value on failure.
  76. */
  77. int (*load) (struct drm_device *, unsigned long flags);
  78. int (*firstopen) (struct drm_device *);
  79. int (*open) (struct drm_device *, struct drm_file *);
  80. void (*preclose) (struct drm_device *, struct drm_file *file_priv);
  81. void (*postclose) (struct drm_device *, struct drm_file *);
  82. void (*lastclose) (struct drm_device *);
  83. /**
  84. * @unload:
  85. *
  86. * Reverse the effects of the driver load callback. Ideally,
  87. * the clean up performed by the driver should happen in the
  88. * reverse order of the initialization. Similarly to the load
  89. * hook, this handler is deprecated and its usage should be
  90. * dropped in favor of an open-coded teardown function at the
  91. * driver layer. See drm_dev_unregister() and drm_dev_unref()
  92. * for the proper way to remove a &struct drm_device.
  93. *
  94. * The unload() hook is called right after unregistering
  95. * the device.
  96. *
  97. */
  98. void (*unload) (struct drm_device *);
  99. int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
  100. int (*dma_quiescent) (struct drm_device *);
  101. int (*context_dtor) (struct drm_device *dev, int context);
  102. int (*set_busid)(struct drm_device *dev, struct drm_master *master);
  103. /**
  104. * @get_vblank_counter:
  105. *
  106. * Driver callback for fetching a raw hardware vblank counter for the
  107. * CRTC specified with the pipe argument. If a device doesn't have a
  108. * hardware counter, the driver can simply use
  109. * drm_vblank_no_hw_counter() function. The DRM core will account for
  110. * missed vblank events while interrupts where disabled based on system
  111. * timestamps.
  112. *
  113. * Wraparound handling and loss of events due to modesetting is dealt
  114. * with in the DRM core code, as long as drivers call
  115. * drm_crtc_vblank_off() and drm_crtc_vblank_on() when disabling or
  116. * enabling a CRTC.
  117. *
  118. * Returns:
  119. *
  120. * Raw vblank counter value.
  121. */
  122. u32 (*get_vblank_counter) (struct drm_device *dev, unsigned int pipe);
  123. /**
  124. * @enable_vblank:
  125. *
  126. * Enable vblank interrupts for the CRTC specified with the pipe
  127. * argument.
  128. *
  129. * Returns:
  130. *
  131. * Zero on success, appropriate errno if the given @crtc's vblank
  132. * interrupt cannot be enabled.
  133. */
  134. int (*enable_vblank) (struct drm_device *dev, unsigned int pipe);
  135. /**
  136. * @disable_vblank:
  137. *
  138. * Disable vblank interrupts for the CRTC specified with the pipe
  139. * argument.
  140. */
  141. void (*disable_vblank) (struct drm_device *dev, unsigned int pipe);
  142. /**
  143. * @get_scanout_position:
  144. *
  145. * Called by vblank timestamping code.
  146. *
  147. * Returns the current display scanout position from a crtc, and an
  148. * optional accurate ktime_get() timestamp of when position was
  149. * measured. Note that this is a helper callback which is only used if a
  150. * driver uses drm_calc_vbltimestamp_from_scanoutpos() for the
  151. * @get_vblank_timestamp callback.
  152. *
  153. * Parameters:
  154. *
  155. * dev:
  156. * DRM device.
  157. * pipe:
  158. * Id of the crtc to query.
  159. * flags:
  160. * Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
  161. * vpos:
  162. * Target location for current vertical scanout position.
  163. * hpos:
  164. * Target location for current horizontal scanout position.
  165. * stime:
  166. * Target location for timestamp taken immediately before
  167. * scanout position query. Can be NULL to skip timestamp.
  168. * etime:
  169. * Target location for timestamp taken immediately after
  170. * scanout position query. Can be NULL to skip timestamp.
  171. * mode:
  172. * Current display timings.
  173. *
  174. * Returns vpos as a positive number while in active scanout area.
  175. * Returns vpos as a negative number inside vblank, counting the number
  176. * of scanlines to go until end of vblank, e.g., -1 means "one scanline
  177. * until start of active scanout / end of vblank."
  178. *
  179. * Returns:
  180. *
  181. * Flags, or'ed together as follows:
  182. *
  183. * DRM_SCANOUTPOS_VALID:
  184. * Query successful.
  185. * DRM_SCANOUTPOS_INVBL:
  186. * Inside vblank.
  187. * DRM_SCANOUTPOS_ACCURATE: Returned position is accurate. A lack of
  188. * this flag means that returned position may be offset by a
  189. * constant but unknown small number of scanlines wrt. real scanout
  190. * position.
  191. *
  192. */
  193. int (*get_scanout_position) (struct drm_device *dev, unsigned int pipe,
  194. unsigned int flags, int *vpos, int *hpos,
  195. ktime_t *stime, ktime_t *etime,
  196. const struct drm_display_mode *mode);
  197. /**
  198. * @get_vblank_timestamp:
  199. *
  200. * Called by drm_get_last_vbltimestamp(). Should return a precise
  201. * timestamp when the most recent VBLANK interval ended or will end.
  202. *
  203. * Specifically, the timestamp in @vblank_time should correspond as
  204. * closely as possible to the time when the first video scanline of
  205. * the video frame after the end of VBLANK will start scanning out,
  206. * the time immediately after end of the VBLANK interval. If the
  207. * @crtc is currently inside VBLANK, this will be a time in the future.
  208. * If the @crtc is currently scanning out a frame, this will be the
  209. * past start time of the current scanout. This is meant to adhere
  210. * to the OpenML OML_sync_control extension specification.
  211. *
  212. * Paramters:
  213. *
  214. * dev:
  215. * dev DRM device handle.
  216. * pipe:
  217. * crtc for which timestamp should be returned.
  218. * max_error:
  219. * Maximum allowable timestamp error in nanoseconds.
  220. * Implementation should strive to provide timestamp
  221. * with an error of at most max_error nanoseconds.
  222. * Returns true upper bound on error for timestamp.
  223. * vblank_time:
  224. * Target location for returned vblank timestamp.
  225. * flags:
  226. * 0 = Defaults, no special treatment needed.
  227. * DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
  228. * irq handler. Some drivers need to apply some workarounds
  229. * for gpu-specific vblank irq quirks if flag is set.
  230. *
  231. * Returns:
  232. *
  233. * Zero if timestamping isn't supported in current display mode or a
  234. * negative number on failure. A positive status code on success,
  235. * which describes how the vblank_time timestamp was computed.
  236. */
  237. int (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe,
  238. int *max_error,
  239. struct timeval *vblank_time,
  240. unsigned flags);
  241. /* these have to be filled in */
  242. irqreturn_t(*irq_handler) (int irq, void *arg);
  243. void (*irq_preinstall) (struct drm_device *dev);
  244. int (*irq_postinstall) (struct drm_device *dev);
  245. void (*irq_uninstall) (struct drm_device *dev);
  246. /**
  247. * @master_create:
  248. *
  249. * Called whenever a new master is created. Only used by vmwgfx.
  250. */
  251. int (*master_create)(struct drm_device *dev, struct drm_master *master);
  252. /**
  253. * @master_destroy:
  254. *
  255. * Called whenever a master is destroyed. Only used by vmwgfx.
  256. */
  257. void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
  258. /**
  259. * @master_set:
  260. *
  261. * Called whenever the minor master is set. Only used by vmwgfx.
  262. */
  263. int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
  264. bool from_open);
  265. /**
  266. * @master_drop:
  267. *
  268. * Called whenever the minor master is dropped. Only used by vmwgfx.
  269. */
  270. void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv);
  271. int (*debugfs_init)(struct drm_minor *minor);
  272. void (*debugfs_cleanup)(struct drm_minor *minor);
  273. /**
  274. * @gem_free_object: deconstructor for drm_gem_objects
  275. *
  276. * This is deprecated and should not be used by new drivers. Use
  277. * @gem_free_object_unlocked instead.
  278. */
  279. void (*gem_free_object) (struct drm_gem_object *obj);
  280. /**
  281. * @gem_free_object_unlocked: deconstructor for drm_gem_objects
  282. *
  283. * This is for drivers which are not encumbered with &drm_device.struct_mutex
  284. * legacy locking schemes. Use this hook instead of @gem_free_object.
  285. */
  286. void (*gem_free_object_unlocked) (struct drm_gem_object *obj);
  287. int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  288. void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  289. /**
  290. * @gem_create_object: constructor for gem objects
  291. *
  292. * Hook for allocating the GEM object struct, for use by core
  293. * helpers.
  294. */
  295. struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
  296. size_t size);
  297. /* prime: */
  298. /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
  299. int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
  300. uint32_t handle, uint32_t flags, int *prime_fd);
  301. /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
  302. int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
  303. int prime_fd, uint32_t *handle);
  304. /* export GEM -> dmabuf */
  305. struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
  306. struct drm_gem_object *obj, int flags);
  307. /* import dmabuf -> GEM */
  308. struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
  309. struct dma_buf *dma_buf);
  310. /* low-level interface used by drm_gem_prime_{import,export} */
  311. int (*gem_prime_pin)(struct drm_gem_object *obj);
  312. void (*gem_prime_unpin)(struct drm_gem_object *obj);
  313. struct reservation_object * (*gem_prime_res_obj)(
  314. struct drm_gem_object *obj);
  315. struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
  316. struct drm_gem_object *(*gem_prime_import_sg_table)(
  317. struct drm_device *dev,
  318. struct dma_buf_attachment *attach,
  319. struct sg_table *sgt);
  320. void *(*gem_prime_vmap)(struct drm_gem_object *obj);
  321. void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
  322. int (*gem_prime_mmap)(struct drm_gem_object *obj,
  323. struct vm_area_struct *vma);
  324. /* vga arb irq handler */
  325. void (*vgaarb_irq)(struct drm_device *dev, bool state);
  326. /**
  327. * @dumb_create:
  328. *
  329. * This creates a new dumb buffer in the driver's backing storage manager (GEM,
  330. * TTM or something else entirely) and returns the resulting buffer handle. This
  331. * handle can then be wrapped up into a framebuffer modeset object.
  332. *
  333. * Note that userspace is not allowed to use such objects for render
  334. * acceleration - drivers must create their own private ioctls for such a use
  335. * case.
  336. *
  337. * Width, height and depth are specified in the &drm_mode_create_dumb
  338. * argument. The callback needs to fill the handle, pitch and size for
  339. * the created buffer.
  340. *
  341. * Called by the user via ioctl.
  342. *
  343. * Returns:
  344. *
  345. * Zero on success, negative errno on failure.
  346. */
  347. int (*dumb_create)(struct drm_file *file_priv,
  348. struct drm_device *dev,
  349. struct drm_mode_create_dumb *args);
  350. /**
  351. * @dumb_map_offset:
  352. *
  353. * Allocate an offset in the drm device node's address space to be able to
  354. * memory map a dumb buffer. GEM-based drivers must use
  355. * drm_gem_create_mmap_offset() to implement this.
  356. *
  357. * Called by the user via ioctl.
  358. *
  359. * Returns:
  360. *
  361. * Zero on success, negative errno on failure.
  362. */
  363. int (*dumb_map_offset)(struct drm_file *file_priv,
  364. struct drm_device *dev, uint32_t handle,
  365. uint64_t *offset);
  366. /**
  367. * @dumb_destroy:
  368. *
  369. * This destroys the userspace handle for the given dumb backing storage buffer.
  370. * Since buffer objects must be reference counted in the kernel a buffer object
  371. * won't be immediately freed if a framebuffer modeset object still uses it.
  372. *
  373. * Called by the user via ioctl.
  374. *
  375. * Returns:
  376. *
  377. * Zero on success, negative errno on failure.
  378. */
  379. int (*dumb_destroy)(struct drm_file *file_priv,
  380. struct drm_device *dev,
  381. uint32_t handle);
  382. /* Driver private ops for this object */
  383. const struct vm_operations_struct *gem_vm_ops;
  384. int major;
  385. int minor;
  386. int patchlevel;
  387. char *name;
  388. char *desc;
  389. char *date;
  390. u32 driver_features;
  391. int dev_priv_size;
  392. const struct drm_ioctl_desc *ioctls;
  393. int num_ioctls;
  394. const struct file_operations *fops;
  395. /* List of devices hanging off this driver with stealth attach. */
  396. struct list_head legacy_dev_list;
  397. };
  398. extern __printf(6, 7)
  399. void drm_dev_printk(const struct device *dev, const char *level,
  400. unsigned int category, const char *function_name,
  401. const char *prefix, const char *format, ...);
  402. extern __printf(3, 4)
  403. void drm_printk(const char *level, unsigned int category,
  404. const char *format, ...);
  405. extern unsigned int drm_debug;
  406. int drm_dev_init(struct drm_device *dev,
  407. struct drm_driver *driver,
  408. struct device *parent);
  409. struct drm_device *drm_dev_alloc(struct drm_driver *driver,
  410. struct device *parent);
  411. int drm_dev_register(struct drm_device *dev, unsigned long flags);
  412. void drm_dev_unregister(struct drm_device *dev);
  413. void drm_dev_ref(struct drm_device *dev);
  414. void drm_dev_unref(struct drm_device *dev);
  415. void drm_put_dev(struct drm_device *dev);
  416. void drm_unplug_dev(struct drm_device *dev);
  417. int drm_dev_set_unique(struct drm_device *dev, const char *name);
  418. #endif