vmwgfx_drv.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /**************************************************************************
  2. *
  3. * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
  21. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  22. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  24. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. #ifndef _VMWGFX_DRV_H_
  28. #define _VMWGFX_DRV_H_
  29. #include "vmwgfx_reg.h"
  30. #include "drmP.h"
  31. #include "vmwgfx_drm.h"
  32. #include "drm_hashtab.h"
  33. #include "ttm/ttm_bo_driver.h"
  34. #include "ttm/ttm_object.h"
  35. #include "ttm/ttm_lock.h"
  36. #include "ttm/ttm_execbuf_util.h"
  37. #include "ttm/ttm_module.h"
  38. #define VMWGFX_DRIVER_DATE "20090724"
  39. #define VMWGFX_DRIVER_MAJOR 0
  40. #define VMWGFX_DRIVER_MINOR 1
  41. #define VMWGFX_DRIVER_PATCHLEVEL 2
  42. #define VMWGFX_FILE_PAGE_OFFSET 0x00100000
  43. #define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
  44. #define VMWGFX_MAX_RELOCATIONS 2048
  45. #define VMWGFX_MAX_GMRS 2048
  46. struct vmw_fpriv {
  47. struct drm_master *locked_master;
  48. struct ttm_object_file *tfile;
  49. };
  50. struct vmw_dma_buffer {
  51. struct ttm_buffer_object base;
  52. struct list_head validate_list;
  53. struct list_head gmr_lru;
  54. uint32_t gmr_id;
  55. bool gmr_bound;
  56. uint32_t cur_validate_node;
  57. bool on_validate_list;
  58. };
  59. struct vmw_resource {
  60. struct kref kref;
  61. struct vmw_private *dev_priv;
  62. struct idr *idr;
  63. int id;
  64. enum ttm_object_type res_type;
  65. bool avail;
  66. void (*hw_destroy) (struct vmw_resource *res);
  67. void (*res_free) (struct vmw_resource *res);
  68. /* TODO is a generic snooper needed? */
  69. #if 0
  70. void (*snoop)(struct vmw_resource *res,
  71. struct ttm_object_file *tfile,
  72. SVGA3dCmdHeader *header);
  73. void *snoop_priv;
  74. #endif
  75. };
  76. struct vmw_cursor_snooper {
  77. struct drm_crtc *crtc;
  78. size_t age;
  79. uint32_t *image;
  80. };
  81. struct vmw_surface {
  82. struct vmw_resource res;
  83. uint32_t flags;
  84. uint32_t format;
  85. uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
  86. struct drm_vmw_size *sizes;
  87. uint32_t num_sizes;
  88. /* TODO so far just a extra pointer */
  89. struct vmw_cursor_snooper snooper;
  90. };
  91. struct vmw_fifo_state {
  92. unsigned long reserved_size;
  93. __le32 *dynamic_buffer;
  94. __le32 *static_buffer;
  95. __le32 *last_buffer;
  96. uint32_t last_data_size;
  97. uint32_t last_buffer_size;
  98. bool last_buffer_add;
  99. unsigned long static_buffer_size;
  100. bool using_bounce_buffer;
  101. uint32_t capabilities;
  102. struct rw_semaphore rwsem;
  103. };
  104. struct vmw_relocation {
  105. SVGAGuestPtr *location;
  106. uint32_t index;
  107. };
  108. struct vmw_sw_context{
  109. struct ida bo_list;
  110. uint32_t last_cid;
  111. bool cid_valid;
  112. uint32_t last_sid;
  113. uint32_t sid_translation;
  114. bool sid_valid;
  115. struct ttm_object_file *tfile;
  116. struct list_head validate_nodes;
  117. struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
  118. uint32_t cur_reloc;
  119. struct ttm_validate_buffer val_bufs[VMWGFX_MAX_GMRS];
  120. uint32_t cur_val_buf;
  121. };
  122. struct vmw_legacy_display;
  123. struct vmw_overlay;
  124. struct vmw_master {
  125. struct ttm_lock lock;
  126. };
  127. struct vmw_private {
  128. struct ttm_bo_device bdev;
  129. struct ttm_bo_global_ref bo_global_ref;
  130. struct ttm_global_reference mem_global_ref;
  131. struct vmw_fifo_state fifo;
  132. struct drm_device *dev;
  133. unsigned long vmw_chipset;
  134. unsigned int io_start;
  135. uint32_t vram_start;
  136. uint32_t vram_size;
  137. uint32_t mmio_start;
  138. uint32_t mmio_size;
  139. uint32_t fb_max_width;
  140. uint32_t fb_max_height;
  141. __le32 __iomem *mmio_virt;
  142. int mmio_mtrr;
  143. uint32_t capabilities;
  144. uint32_t max_gmr_descriptors;
  145. uint32_t max_gmr_ids;
  146. struct mutex hw_mutex;
  147. /*
  148. * VGA registers.
  149. */
  150. uint32_t vga_width;
  151. uint32_t vga_height;
  152. uint32_t vga_depth;
  153. uint32_t vga_bpp;
  154. uint32_t vga_pseudo;
  155. uint32_t vga_red_mask;
  156. uint32_t vga_blue_mask;
  157. uint32_t vga_green_mask;
  158. /*
  159. * Framebuffer info.
  160. */
  161. void *fb_info;
  162. struct vmw_legacy_display *ldu_priv;
  163. struct vmw_overlay *overlay_priv;
  164. /*
  165. * Context and surface management.
  166. */
  167. rwlock_t resource_lock;
  168. struct idr context_idr;
  169. struct idr surface_idr;
  170. struct idr stream_idr;
  171. /*
  172. * Block lastclose from racing with firstopen.
  173. */
  174. struct mutex init_mutex;
  175. /*
  176. * A resource manager for kernel-only surfaces and
  177. * contexts.
  178. */
  179. struct ttm_object_device *tdev;
  180. /*
  181. * Fencing and IRQs.
  182. */
  183. uint32_t fence_seq;
  184. wait_queue_head_t fence_queue;
  185. wait_queue_head_t fifo_queue;
  186. atomic_t fence_queue_waiters;
  187. atomic_t fifo_queue_waiters;
  188. uint32_t last_read_sequence;
  189. spinlock_t irq_lock;
  190. /*
  191. * Device state
  192. */
  193. uint32_t traces_state;
  194. uint32_t enable_state;
  195. uint32_t config_done_state;
  196. /**
  197. * Execbuf
  198. */
  199. /**
  200. * Protected by the cmdbuf mutex.
  201. */
  202. struct vmw_sw_context ctx;
  203. uint32_t val_seq;
  204. struct mutex cmdbuf_mutex;
  205. /**
  206. * GMR management. Protected by the lru spinlock.
  207. */
  208. struct ida gmr_ida;
  209. struct list_head gmr_lru;
  210. /**
  211. * Operating mode.
  212. */
  213. bool stealth;
  214. bool is_opened;
  215. /**
  216. * Master management.
  217. */
  218. struct vmw_master *active_master;
  219. struct vmw_master fbdev_master;
  220. };
  221. static inline struct vmw_private *vmw_priv(struct drm_device *dev)
  222. {
  223. return (struct vmw_private *)dev->dev_private;
  224. }
  225. static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
  226. {
  227. return (struct vmw_fpriv *)file_priv->driver_priv;
  228. }
  229. static inline struct vmw_master *vmw_master(struct drm_master *master)
  230. {
  231. return (struct vmw_master *) master->driver_priv;
  232. }
  233. static inline void vmw_write(struct vmw_private *dev_priv,
  234. unsigned int offset, uint32_t value)
  235. {
  236. outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
  237. outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
  238. }
  239. static inline uint32_t vmw_read(struct vmw_private *dev_priv,
  240. unsigned int offset)
  241. {
  242. uint32_t val;
  243. outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
  244. val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
  245. return val;
  246. }
  247. /**
  248. * GMR utilities - vmwgfx_gmr.c
  249. */
  250. extern int vmw_gmr_bind(struct vmw_private *dev_priv,
  251. struct ttm_buffer_object *bo);
  252. extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
  253. /**
  254. * Resource utilities - vmwgfx_resource.c
  255. */
  256. extern struct vmw_resource *vmw_context_alloc(struct vmw_private *dev_priv);
  257. extern void vmw_resource_unreference(struct vmw_resource **p_res);
  258. extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
  259. extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
  260. struct drm_file *file_priv);
  261. extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
  262. struct drm_file *file_priv);
  263. extern int vmw_context_check(struct vmw_private *dev_priv,
  264. struct ttm_object_file *tfile,
  265. int id);
  266. extern void vmw_surface_res_free(struct vmw_resource *res);
  267. extern int vmw_surface_init(struct vmw_private *dev_priv,
  268. struct vmw_surface *srf,
  269. void (*res_free) (struct vmw_resource *res));
  270. extern int vmw_user_surface_lookup_handle(struct vmw_private *dev_priv,
  271. struct ttm_object_file *tfile,
  272. uint32_t handle,
  273. struct vmw_surface **out);
  274. extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
  275. struct drm_file *file_priv);
  276. extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
  277. struct drm_file *file_priv);
  278. extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
  279. struct drm_file *file_priv);
  280. extern int vmw_surface_check(struct vmw_private *dev_priv,
  281. struct ttm_object_file *tfile,
  282. uint32_t handle, int *id);
  283. extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
  284. extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
  285. struct vmw_dma_buffer *vmw_bo,
  286. size_t size, struct ttm_placement *placement,
  287. bool interuptable,
  288. void (*bo_free) (struct ttm_buffer_object *bo));
  289. extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
  290. struct drm_file *file_priv);
  291. extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
  292. struct drm_file *file_priv);
  293. extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
  294. uint32_t cur_validate_node);
  295. extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
  296. extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
  297. uint32_t id, struct vmw_dma_buffer **out);
  298. extern uint32_t vmw_dmabuf_gmr(struct ttm_buffer_object *bo);
  299. extern void vmw_dmabuf_set_gmr(struct ttm_buffer_object *bo, uint32_t id);
  300. extern int vmw_gmr_id_alloc(struct vmw_private *dev_priv, uint32_t *p_id);
  301. extern int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv,
  302. struct vmw_dma_buffer *bo);
  303. extern int vmw_dmabuf_from_vram(struct vmw_private *vmw_priv,
  304. struct vmw_dma_buffer *bo);
  305. extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
  306. struct drm_file *file_priv);
  307. extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
  308. struct drm_file *file_priv);
  309. extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
  310. struct ttm_object_file *tfile,
  311. uint32_t *inout_id,
  312. struct vmw_resource **out);
  313. /**
  314. * Misc Ioctl functionality - vmwgfx_ioctl.c
  315. */
  316. extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
  317. struct drm_file *file_priv);
  318. extern int vmw_fifo_debug_ioctl(struct drm_device *dev, void *data,
  319. struct drm_file *file_priv);
  320. /**
  321. * Fifo utilities - vmwgfx_fifo.c
  322. */
  323. extern int vmw_fifo_init(struct vmw_private *dev_priv,
  324. struct vmw_fifo_state *fifo);
  325. extern void vmw_fifo_release(struct vmw_private *dev_priv,
  326. struct vmw_fifo_state *fifo);
  327. extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
  328. extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
  329. extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
  330. uint32_t *sequence);
  331. extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
  332. extern int vmw_fifo_mmap(struct file *filp, struct vm_area_struct *vma);
  333. /**
  334. * TTM glue - vmwgfx_ttm_glue.c
  335. */
  336. extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
  337. extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
  338. extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
  339. /**
  340. * TTM buffer object driver - vmwgfx_buffer.c
  341. */
  342. extern struct ttm_placement vmw_vram_placement;
  343. extern struct ttm_placement vmw_vram_ne_placement;
  344. extern struct ttm_placement vmw_sys_placement;
  345. extern struct ttm_bo_driver vmw_bo_driver;
  346. extern int vmw_dma_quiescent(struct drm_device *dev);
  347. /**
  348. * Command submission - vmwgfx_execbuf.c
  349. */
  350. extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
  351. struct drm_file *file_priv);
  352. /**
  353. * IRQs and wating - vmwgfx_irq.c
  354. */
  355. extern irqreturn_t vmw_irq_handler(DRM_IRQ_ARGS);
  356. extern int vmw_wait_fence(struct vmw_private *dev_priv, bool lazy,
  357. uint32_t sequence, bool interruptible,
  358. unsigned long timeout);
  359. extern void vmw_irq_preinstall(struct drm_device *dev);
  360. extern int vmw_irq_postinstall(struct drm_device *dev);
  361. extern void vmw_irq_uninstall(struct drm_device *dev);
  362. extern bool vmw_fence_signaled(struct vmw_private *dev_priv,
  363. uint32_t sequence);
  364. extern int vmw_fence_wait_ioctl(struct drm_device *dev, void *data,
  365. struct drm_file *file_priv);
  366. extern int vmw_fallback_wait(struct vmw_private *dev_priv,
  367. bool lazy,
  368. bool fifo_idle,
  369. uint32_t sequence,
  370. bool interruptible,
  371. unsigned long timeout);
  372. /**
  373. * Kernel framebuffer - vmwgfx_fb.c
  374. */
  375. int vmw_fb_init(struct vmw_private *vmw_priv);
  376. int vmw_fb_close(struct vmw_private *dev_priv);
  377. int vmw_fb_off(struct vmw_private *vmw_priv);
  378. int vmw_fb_on(struct vmw_private *vmw_priv);
  379. /**
  380. * Kernel modesetting - vmwgfx_kms.c
  381. */
  382. int vmw_kms_init(struct vmw_private *dev_priv);
  383. int vmw_kms_close(struct vmw_private *dev_priv);
  384. int vmw_kms_save_vga(struct vmw_private *vmw_priv);
  385. int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
  386. int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
  387. struct drm_file *file_priv);
  388. void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
  389. void vmw_kms_cursor_snoop(struct vmw_surface *srf,
  390. struct ttm_object_file *tfile,
  391. struct ttm_buffer_object *bo,
  392. SVGA3dCmdHeader *header);
  393. /**
  394. * Overlay control - vmwgfx_overlay.c
  395. */
  396. int vmw_overlay_init(struct vmw_private *dev_priv);
  397. int vmw_overlay_close(struct vmw_private *dev_priv);
  398. int vmw_overlay_ioctl(struct drm_device *dev, void *data,
  399. struct drm_file *file_priv);
  400. int vmw_overlay_stop_all(struct vmw_private *dev_priv);
  401. int vmw_overlay_resume_all(struct vmw_private *dev_priv);
  402. int vmw_overlay_pause_all(struct vmw_private *dev_priv);
  403. int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
  404. int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
  405. int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
  406. int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
  407. /**
  408. * Inline helper functions
  409. */
  410. static inline void vmw_surface_unreference(struct vmw_surface **srf)
  411. {
  412. struct vmw_surface *tmp_srf = *srf;
  413. struct vmw_resource *res = &tmp_srf->res;
  414. *srf = NULL;
  415. vmw_resource_unreference(&res);
  416. }
  417. static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
  418. {
  419. (void) vmw_resource_reference(&srf->res);
  420. return srf;
  421. }
  422. static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
  423. {
  424. struct vmw_dma_buffer *tmp_buf = *buf;
  425. struct ttm_buffer_object *bo = &tmp_buf->base;
  426. *buf = NULL;
  427. ttm_bo_unref(&bo);
  428. }
  429. static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
  430. {
  431. if (ttm_bo_reference(&buf->base))
  432. return buf;
  433. return NULL;
  434. }
  435. #endif