drm_drv.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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. * @device_is_agp:
  144. *
  145. * Called by drm_device_is_agp(). Typically used to determine if a card
  146. * is really attached to AGP or not.
  147. *
  148. * Returns:
  149. *
  150. * One of three values is returned depending on whether or not the
  151. * card is absolutely not AGP (return of 0), absolutely is AGP
  152. * (return of 1), or may or may not be AGP (return of 2).
  153. */
  154. int (*device_is_agp) (struct drm_device *dev);
  155. /**
  156. * @get_scanout_position:
  157. *
  158. * Called by vblank timestamping code.
  159. *
  160. * Returns the current display scanout position from a crtc, and an
  161. * optional accurate ktime_get() timestamp of when position was
  162. * measured. Note that this is a helper callback which is only used if a
  163. * driver uses drm_calc_vbltimestamp_from_scanoutpos() for the
  164. * @get_vblank_timestamp callback.
  165. *
  166. * Parameters:
  167. *
  168. * dev:
  169. * DRM device.
  170. * pipe:
  171. * Id of the crtc to query.
  172. * flags:
  173. * Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
  174. * vpos:
  175. * Target location for current vertical scanout position.
  176. * hpos:
  177. * Target location for current horizontal scanout position.
  178. * stime:
  179. * Target location for timestamp taken immediately before
  180. * scanout position query. Can be NULL to skip timestamp.
  181. * etime:
  182. * Target location for timestamp taken immediately after
  183. * scanout position query. Can be NULL to skip timestamp.
  184. * mode:
  185. * Current display timings.
  186. *
  187. * Returns vpos as a positive number while in active scanout area.
  188. * Returns vpos as a negative number inside vblank, counting the number
  189. * of scanlines to go until end of vblank, e.g., -1 means "one scanline
  190. * until start of active scanout / end of vblank."
  191. *
  192. * Returns:
  193. *
  194. * Flags, or'ed together as follows:
  195. *
  196. * DRM_SCANOUTPOS_VALID:
  197. * Query successful.
  198. * DRM_SCANOUTPOS_INVBL:
  199. * Inside vblank.
  200. * DRM_SCANOUTPOS_ACCURATE: Returned position is accurate. A lack of
  201. * this flag means that returned position may be offset by a
  202. * constant but unknown small number of scanlines wrt. real scanout
  203. * position.
  204. *
  205. */
  206. int (*get_scanout_position) (struct drm_device *dev, unsigned int pipe,
  207. unsigned int flags, int *vpos, int *hpos,
  208. ktime_t *stime, ktime_t *etime,
  209. const struct drm_display_mode *mode);
  210. /**
  211. * @get_vblank_timestamp:
  212. *
  213. * Called by drm_get_last_vbltimestamp(). Should return a precise
  214. * timestamp when the most recent VBLANK interval ended or will end.
  215. *
  216. * Specifically, the timestamp in @vblank_time should correspond as
  217. * closely as possible to the time when the first video scanline of
  218. * the video frame after the end of VBLANK will start scanning out,
  219. * the time immediately after end of the VBLANK interval. If the
  220. * @crtc is currently inside VBLANK, this will be a time in the future.
  221. * If the @crtc is currently scanning out a frame, this will be the
  222. * past start time of the current scanout. This is meant to adhere
  223. * to the OpenML OML_sync_control extension specification.
  224. *
  225. * Paramters:
  226. *
  227. * dev:
  228. * dev DRM device handle.
  229. * pipe:
  230. * crtc for which timestamp should be returned.
  231. * max_error:
  232. * Maximum allowable timestamp error in nanoseconds.
  233. * Implementation should strive to provide timestamp
  234. * with an error of at most max_error nanoseconds.
  235. * Returns true upper bound on error for timestamp.
  236. * vblank_time:
  237. * Target location for returned vblank timestamp.
  238. * flags:
  239. * 0 = Defaults, no special treatment needed.
  240. * DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
  241. * irq handler. Some drivers need to apply some workarounds
  242. * for gpu-specific vblank irq quirks if flag is set.
  243. *
  244. * Returns:
  245. *
  246. * Zero if timestamping isn't supported in current display mode or a
  247. * negative number on failure. A positive status code on success,
  248. * which describes how the vblank_time timestamp was computed.
  249. */
  250. int (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe,
  251. int *max_error,
  252. struct timeval *vblank_time,
  253. unsigned flags);
  254. /* these have to be filled in */
  255. irqreturn_t(*irq_handler) (int irq, void *arg);
  256. void (*irq_preinstall) (struct drm_device *dev);
  257. int (*irq_postinstall) (struct drm_device *dev);
  258. void (*irq_uninstall) (struct drm_device *dev);
  259. /**
  260. * @master_create:
  261. *
  262. * Called whenever a new master is created. Only used by vmwgfx.
  263. */
  264. int (*master_create)(struct drm_device *dev, struct drm_master *master);
  265. /**
  266. * @master_destroy:
  267. *
  268. * Called whenever a master is destroyed. Only used by vmwgfx.
  269. */
  270. void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
  271. /**
  272. * @master_set:
  273. *
  274. * Called whenever the minor master is set. Only used by vmwgfx.
  275. */
  276. int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
  277. bool from_open);
  278. /**
  279. * @master_drop:
  280. *
  281. * Called whenever the minor master is dropped. Only used by vmwgfx.
  282. */
  283. void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv);
  284. int (*debugfs_init)(struct drm_minor *minor);
  285. void (*debugfs_cleanup)(struct drm_minor *minor);
  286. /**
  287. * @gem_free_object: deconstructor for drm_gem_objects
  288. *
  289. * This is deprecated and should not be used by new drivers. Use
  290. * @gem_free_object_unlocked instead.
  291. */
  292. void (*gem_free_object) (struct drm_gem_object *obj);
  293. /**
  294. * @gem_free_object_unlocked: deconstructor for drm_gem_objects
  295. *
  296. * This is for drivers which are not encumbered with dev->struct_mutex
  297. * legacy locking schemes. Use this hook instead of @gem_free_object.
  298. */
  299. void (*gem_free_object_unlocked) (struct drm_gem_object *obj);
  300. int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  301. void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  302. /**
  303. * @gem_create_object: constructor for gem objects
  304. *
  305. * Hook for allocating the GEM object struct, for use by core
  306. * helpers.
  307. */
  308. struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
  309. size_t size);
  310. /* prime: */
  311. /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
  312. int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
  313. uint32_t handle, uint32_t flags, int *prime_fd);
  314. /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
  315. int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
  316. int prime_fd, uint32_t *handle);
  317. /* export GEM -> dmabuf */
  318. struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
  319. struct drm_gem_object *obj, int flags);
  320. /* import dmabuf -> GEM */
  321. struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
  322. struct dma_buf *dma_buf);
  323. /* low-level interface used by drm_gem_prime_{import,export} */
  324. int (*gem_prime_pin)(struct drm_gem_object *obj);
  325. void (*gem_prime_unpin)(struct drm_gem_object *obj);
  326. struct reservation_object * (*gem_prime_res_obj)(
  327. struct drm_gem_object *obj);
  328. struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
  329. struct drm_gem_object *(*gem_prime_import_sg_table)(
  330. struct drm_device *dev,
  331. struct dma_buf_attachment *attach,
  332. struct sg_table *sgt);
  333. void *(*gem_prime_vmap)(struct drm_gem_object *obj);
  334. void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
  335. int (*gem_prime_mmap)(struct drm_gem_object *obj,
  336. struct vm_area_struct *vma);
  337. /* vga arb irq handler */
  338. void (*vgaarb_irq)(struct drm_device *dev, bool state);
  339. /**
  340. * @dumb_create:
  341. *
  342. * This creates a new dumb buffer in the driver's backing storage manager (GEM,
  343. * TTM or something else entirely) and returns the resulting buffer handle. This
  344. * handle can then be wrapped up into a framebuffer modeset object.
  345. *
  346. * Note that userspace is not allowed to use such objects for render
  347. * acceleration - drivers must create their own private ioctls for such a use
  348. * case.
  349. *
  350. * Width, height and depth are specified in the &drm_mode_create_dumb
  351. * argument. The callback needs to fill the handle, pitch and size for
  352. * the created buffer.
  353. *
  354. * Called by the user via ioctl.
  355. *
  356. * Returns:
  357. *
  358. * Zero on success, negative errno on failure.
  359. */
  360. int (*dumb_create)(struct drm_file *file_priv,
  361. struct drm_device *dev,
  362. struct drm_mode_create_dumb *args);
  363. /**
  364. * @dumb_map_offset:
  365. *
  366. * Allocate an offset in the drm device node's address space to be able to
  367. * memory map a dumb buffer. GEM-based drivers must use
  368. * drm_gem_create_mmap_offset() to implement this.
  369. *
  370. * Called by the user via ioctl.
  371. *
  372. * Returns:
  373. *
  374. * Zero on success, negative errno on failure.
  375. */
  376. int (*dumb_map_offset)(struct drm_file *file_priv,
  377. struct drm_device *dev, uint32_t handle,
  378. uint64_t *offset);
  379. /**
  380. * @dumb_destroy:
  381. *
  382. * This destroys the userspace handle for the given dumb backing storage buffer.
  383. * Since buffer objects must be reference counted in the kernel a buffer object
  384. * won't be immediately freed if a framebuffer modeset object still uses it.
  385. *
  386. * Called by the user via ioctl.
  387. *
  388. * Returns:
  389. *
  390. * Zero on success, negative errno on failure.
  391. */
  392. int (*dumb_destroy)(struct drm_file *file_priv,
  393. struct drm_device *dev,
  394. uint32_t handle);
  395. /* Driver private ops for this object */
  396. const struct vm_operations_struct *gem_vm_ops;
  397. int major;
  398. int minor;
  399. int patchlevel;
  400. char *name;
  401. char *desc;
  402. char *date;
  403. u32 driver_features;
  404. int dev_priv_size;
  405. const struct drm_ioctl_desc *ioctls;
  406. int num_ioctls;
  407. const struct file_operations *fops;
  408. /* List of devices hanging off this driver with stealth attach. */
  409. struct list_head legacy_dev_list;
  410. };
  411. extern __printf(6, 7)
  412. void drm_dev_printk(const struct device *dev, const char *level,
  413. unsigned int category, const char *function_name,
  414. const char *prefix, const char *format, ...);
  415. extern __printf(3, 4)
  416. void drm_printk(const char *level, unsigned int category,
  417. const char *format, ...);
  418. extern unsigned int drm_debug;
  419. int drm_dev_init(struct drm_device *dev,
  420. struct drm_driver *driver,
  421. struct device *parent);
  422. struct drm_device *drm_dev_alloc(struct drm_driver *driver,
  423. struct device *parent);
  424. int drm_dev_register(struct drm_device *dev, unsigned long flags);
  425. void drm_dev_unregister(struct drm_device *dev);
  426. void drm_dev_ref(struct drm_device *dev);
  427. void drm_dev_unref(struct drm_device *dev);
  428. void drm_put_dev(struct drm_device *dev);
  429. void drm_unplug_dev(struct drm_device *dev);
  430. int drm_dev_set_unique(struct drm_device *dev, const char *name);
  431. #endif