vmwgfx_fifo.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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. #include "vmwgfx_drv.h"
  28. #include <drm/drmP.h>
  29. #include <drm/ttm/ttm_placement.h>
  30. bool vmw_fifo_have_3d(struct vmw_private *dev_priv)
  31. {
  32. __le32 __iomem *fifo_mem = dev_priv->mmio_virt;
  33. uint32_t fifo_min, hwversion;
  34. const struct vmw_fifo_state *fifo = &dev_priv->fifo;
  35. if (!(dev_priv->capabilities & SVGA_CAP_3D))
  36. return false;
  37. if (dev_priv->capabilities & SVGA_CAP_GBOBJECTS) {
  38. uint32_t result;
  39. if (!dev_priv->has_mob)
  40. return false;
  41. mutex_lock(&dev_priv->hw_mutex);
  42. vmw_write(dev_priv, SVGA_REG_DEV_CAP, SVGA3D_DEVCAP_3D);
  43. result = vmw_read(dev_priv, SVGA_REG_DEV_CAP);
  44. mutex_unlock(&dev_priv->hw_mutex);
  45. return (result != 0);
  46. }
  47. if (!(dev_priv->capabilities & SVGA_CAP_EXTENDED_FIFO))
  48. return false;
  49. fifo_min = ioread32(fifo_mem + SVGA_FIFO_MIN);
  50. if (fifo_min <= SVGA_FIFO_3D_HWVERSION * sizeof(unsigned int))
  51. return false;
  52. hwversion = ioread32(fifo_mem +
  53. ((fifo->capabilities &
  54. SVGA_FIFO_CAP_3D_HWVERSION_REVISED) ?
  55. SVGA_FIFO_3D_HWVERSION_REVISED :
  56. SVGA_FIFO_3D_HWVERSION));
  57. if (hwversion == 0)
  58. return false;
  59. if (hwversion < SVGA3D_HWVERSION_WS8_B1)
  60. return false;
  61. /* Non-Screen Object path does not support surfaces */
  62. if (!dev_priv->sou_priv)
  63. return false;
  64. return true;
  65. }
  66. bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv)
  67. {
  68. __le32 __iomem *fifo_mem = dev_priv->mmio_virt;
  69. uint32_t caps;
  70. if (!(dev_priv->capabilities & SVGA_CAP_EXTENDED_FIFO))
  71. return false;
  72. caps = ioread32(fifo_mem + SVGA_FIFO_CAPABILITIES);
  73. if (caps & SVGA_FIFO_CAP_PITCHLOCK)
  74. return true;
  75. return false;
  76. }
  77. int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
  78. {
  79. __le32 __iomem *fifo_mem = dev_priv->mmio_virt;
  80. uint32_t max;
  81. uint32_t min;
  82. uint32_t dummy;
  83. fifo->static_buffer_size = VMWGFX_FIFO_STATIC_SIZE;
  84. fifo->static_buffer = vmalloc(fifo->static_buffer_size);
  85. if (unlikely(fifo->static_buffer == NULL))
  86. return -ENOMEM;
  87. fifo->dynamic_buffer = NULL;
  88. fifo->reserved_size = 0;
  89. fifo->using_bounce_buffer = false;
  90. mutex_init(&fifo->fifo_mutex);
  91. init_rwsem(&fifo->rwsem);
  92. /*
  93. * Allow mapping the first page read-only to user-space.
  94. */
  95. DRM_INFO("width %d\n", vmw_read(dev_priv, SVGA_REG_WIDTH));
  96. DRM_INFO("height %d\n", vmw_read(dev_priv, SVGA_REG_HEIGHT));
  97. DRM_INFO("bpp %d\n", vmw_read(dev_priv, SVGA_REG_BITS_PER_PIXEL));
  98. mutex_lock(&dev_priv->hw_mutex);
  99. dev_priv->enable_state = vmw_read(dev_priv, SVGA_REG_ENABLE);
  100. dev_priv->config_done_state = vmw_read(dev_priv, SVGA_REG_CONFIG_DONE);
  101. dev_priv->traces_state = vmw_read(dev_priv, SVGA_REG_TRACES);
  102. vmw_write(dev_priv, SVGA_REG_ENABLE, 1);
  103. min = 4;
  104. if (dev_priv->capabilities & SVGA_CAP_EXTENDED_FIFO)
  105. min = vmw_read(dev_priv, SVGA_REG_MEM_REGS);
  106. min <<= 2;
  107. if (min < PAGE_SIZE)
  108. min = PAGE_SIZE;
  109. iowrite32(min, fifo_mem + SVGA_FIFO_MIN);
  110. iowrite32(dev_priv->mmio_size, fifo_mem + SVGA_FIFO_MAX);
  111. wmb();
  112. iowrite32(min, fifo_mem + SVGA_FIFO_NEXT_CMD);
  113. iowrite32(min, fifo_mem + SVGA_FIFO_STOP);
  114. iowrite32(0, fifo_mem + SVGA_FIFO_BUSY);
  115. mb();
  116. vmw_write(dev_priv, SVGA_REG_CONFIG_DONE, 1);
  117. mutex_unlock(&dev_priv->hw_mutex);
  118. max = ioread32(fifo_mem + SVGA_FIFO_MAX);
  119. min = ioread32(fifo_mem + SVGA_FIFO_MIN);
  120. fifo->capabilities = ioread32(fifo_mem + SVGA_FIFO_CAPABILITIES);
  121. DRM_INFO("Fifo max 0x%08x min 0x%08x cap 0x%08x\n",
  122. (unsigned int) max,
  123. (unsigned int) min,
  124. (unsigned int) fifo->capabilities);
  125. atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
  126. iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
  127. vmw_marker_queue_init(&fifo->marker_queue);
  128. return vmw_fifo_send_fence(dev_priv, &dummy);
  129. }
  130. void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason)
  131. {
  132. __le32 __iomem *fifo_mem = dev_priv->mmio_virt;
  133. mutex_lock(&dev_priv->hw_mutex);
  134. if (unlikely(ioread32(fifo_mem + SVGA_FIFO_BUSY) == 0)) {
  135. iowrite32(1, fifo_mem + SVGA_FIFO_BUSY);
  136. vmw_write(dev_priv, SVGA_REG_SYNC, reason);
  137. }
  138. mutex_unlock(&dev_priv->hw_mutex);
  139. }
  140. void vmw_fifo_release(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
  141. {
  142. __le32 __iomem *fifo_mem = dev_priv->mmio_virt;
  143. mutex_lock(&dev_priv->hw_mutex);
  144. vmw_write(dev_priv, SVGA_REG_SYNC, SVGA_SYNC_GENERIC);
  145. while (vmw_read(dev_priv, SVGA_REG_BUSY) != 0)
  146. ;
  147. dev_priv->last_read_seqno = ioread32(fifo_mem + SVGA_FIFO_FENCE);
  148. vmw_write(dev_priv, SVGA_REG_CONFIG_DONE,
  149. dev_priv->config_done_state);
  150. vmw_write(dev_priv, SVGA_REG_ENABLE,
  151. dev_priv->enable_state);
  152. vmw_write(dev_priv, SVGA_REG_TRACES,
  153. dev_priv->traces_state);
  154. mutex_unlock(&dev_priv->hw_mutex);
  155. vmw_marker_queue_takedown(&fifo->marker_queue);
  156. if (likely(fifo->static_buffer != NULL)) {
  157. vfree(fifo->static_buffer);
  158. fifo->static_buffer = NULL;
  159. }
  160. if (likely(fifo->dynamic_buffer != NULL)) {
  161. vfree(fifo->dynamic_buffer);
  162. fifo->dynamic_buffer = NULL;
  163. }
  164. }
  165. static bool vmw_fifo_is_full(struct vmw_private *dev_priv, uint32_t bytes)
  166. {
  167. __le32 __iomem *fifo_mem = dev_priv->mmio_virt;
  168. uint32_t max = ioread32(fifo_mem + SVGA_FIFO_MAX);
  169. uint32_t next_cmd = ioread32(fifo_mem + SVGA_FIFO_NEXT_CMD);
  170. uint32_t min = ioread32(fifo_mem + SVGA_FIFO_MIN);
  171. uint32_t stop = ioread32(fifo_mem + SVGA_FIFO_STOP);
  172. return ((max - next_cmd) + (stop - min) <= bytes);
  173. }
  174. static int vmw_fifo_wait_noirq(struct vmw_private *dev_priv,
  175. uint32_t bytes, bool interruptible,
  176. unsigned long timeout)
  177. {
  178. int ret = 0;
  179. unsigned long end_jiffies = jiffies + timeout;
  180. DEFINE_WAIT(__wait);
  181. DRM_INFO("Fifo wait noirq.\n");
  182. for (;;) {
  183. prepare_to_wait(&dev_priv->fifo_queue, &__wait,
  184. (interruptible) ?
  185. TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
  186. if (!vmw_fifo_is_full(dev_priv, bytes))
  187. break;
  188. if (time_after_eq(jiffies, end_jiffies)) {
  189. ret = -EBUSY;
  190. DRM_ERROR("SVGA device lockup.\n");
  191. break;
  192. }
  193. schedule_timeout(1);
  194. if (interruptible && signal_pending(current)) {
  195. ret = -ERESTARTSYS;
  196. break;
  197. }
  198. }
  199. finish_wait(&dev_priv->fifo_queue, &__wait);
  200. wake_up_all(&dev_priv->fifo_queue);
  201. DRM_INFO("Fifo noirq exit.\n");
  202. return ret;
  203. }
  204. static int vmw_fifo_wait(struct vmw_private *dev_priv,
  205. uint32_t bytes, bool interruptible,
  206. unsigned long timeout)
  207. {
  208. long ret = 1L;
  209. unsigned long irq_flags;
  210. if (likely(!vmw_fifo_is_full(dev_priv, bytes)))
  211. return 0;
  212. vmw_fifo_ping_host(dev_priv, SVGA_SYNC_FIFOFULL);
  213. if (!(dev_priv->capabilities & SVGA_CAP_IRQMASK))
  214. return vmw_fifo_wait_noirq(dev_priv, bytes,
  215. interruptible, timeout);
  216. mutex_lock(&dev_priv->hw_mutex);
  217. if (atomic_add_return(1, &dev_priv->fifo_queue_waiters) > 0) {
  218. spin_lock_irqsave(&dev_priv->irq_lock, irq_flags);
  219. outl(SVGA_IRQFLAG_FIFO_PROGRESS,
  220. dev_priv->io_start + VMWGFX_IRQSTATUS_PORT);
  221. dev_priv->irq_mask |= SVGA_IRQFLAG_FIFO_PROGRESS;
  222. vmw_write(dev_priv, SVGA_REG_IRQMASK, dev_priv->irq_mask);
  223. spin_unlock_irqrestore(&dev_priv->irq_lock, irq_flags);
  224. }
  225. mutex_unlock(&dev_priv->hw_mutex);
  226. if (interruptible)
  227. ret = wait_event_interruptible_timeout
  228. (dev_priv->fifo_queue,
  229. !vmw_fifo_is_full(dev_priv, bytes), timeout);
  230. else
  231. ret = wait_event_timeout
  232. (dev_priv->fifo_queue,
  233. !vmw_fifo_is_full(dev_priv, bytes), timeout);
  234. if (unlikely(ret == 0))
  235. ret = -EBUSY;
  236. else if (likely(ret > 0))
  237. ret = 0;
  238. mutex_lock(&dev_priv->hw_mutex);
  239. if (atomic_dec_and_test(&dev_priv->fifo_queue_waiters)) {
  240. spin_lock_irqsave(&dev_priv->irq_lock, irq_flags);
  241. dev_priv->irq_mask &= ~SVGA_IRQFLAG_FIFO_PROGRESS;
  242. vmw_write(dev_priv, SVGA_REG_IRQMASK, dev_priv->irq_mask);
  243. spin_unlock_irqrestore(&dev_priv->irq_lock, irq_flags);
  244. }
  245. mutex_unlock(&dev_priv->hw_mutex);
  246. return ret;
  247. }
  248. /**
  249. * Reserve @bytes number of bytes in the fifo.
  250. *
  251. * This function will return NULL (error) on two conditions:
  252. * If it timeouts waiting for fifo space, or if @bytes is larger than the
  253. * available fifo space.
  254. *
  255. * Returns:
  256. * Pointer to the fifo, or null on error (possible hardware hang).
  257. */
  258. void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
  259. {
  260. struct vmw_fifo_state *fifo_state = &dev_priv->fifo;
  261. __le32 __iomem *fifo_mem = dev_priv->mmio_virt;
  262. uint32_t max;
  263. uint32_t min;
  264. uint32_t next_cmd;
  265. uint32_t reserveable = fifo_state->capabilities & SVGA_FIFO_CAP_RESERVE;
  266. int ret;
  267. mutex_lock(&fifo_state->fifo_mutex);
  268. max = ioread32(fifo_mem + SVGA_FIFO_MAX);
  269. min = ioread32(fifo_mem + SVGA_FIFO_MIN);
  270. next_cmd = ioread32(fifo_mem + SVGA_FIFO_NEXT_CMD);
  271. if (unlikely(bytes >= (max - min)))
  272. goto out_err;
  273. BUG_ON(fifo_state->reserved_size != 0);
  274. BUG_ON(fifo_state->dynamic_buffer != NULL);
  275. fifo_state->reserved_size = bytes;
  276. while (1) {
  277. uint32_t stop = ioread32(fifo_mem + SVGA_FIFO_STOP);
  278. bool need_bounce = false;
  279. bool reserve_in_place = false;
  280. if (next_cmd >= stop) {
  281. if (likely((next_cmd + bytes < max ||
  282. (next_cmd + bytes == max && stop > min))))
  283. reserve_in_place = true;
  284. else if (vmw_fifo_is_full(dev_priv, bytes)) {
  285. ret = vmw_fifo_wait(dev_priv, bytes,
  286. false, 3 * HZ);
  287. if (unlikely(ret != 0))
  288. goto out_err;
  289. } else
  290. need_bounce = true;
  291. } else {
  292. if (likely((next_cmd + bytes < stop)))
  293. reserve_in_place = true;
  294. else {
  295. ret = vmw_fifo_wait(dev_priv, bytes,
  296. false, 3 * HZ);
  297. if (unlikely(ret != 0))
  298. goto out_err;
  299. }
  300. }
  301. if (reserve_in_place) {
  302. if (reserveable || bytes <= sizeof(uint32_t)) {
  303. fifo_state->using_bounce_buffer = false;
  304. if (reserveable)
  305. iowrite32(bytes, fifo_mem +
  306. SVGA_FIFO_RESERVED);
  307. return fifo_mem + (next_cmd >> 2);
  308. } else {
  309. need_bounce = true;
  310. }
  311. }
  312. if (need_bounce) {
  313. fifo_state->using_bounce_buffer = true;
  314. if (bytes < fifo_state->static_buffer_size)
  315. return fifo_state->static_buffer;
  316. else {
  317. fifo_state->dynamic_buffer = vmalloc(bytes);
  318. return fifo_state->dynamic_buffer;
  319. }
  320. }
  321. }
  322. out_err:
  323. fifo_state->reserved_size = 0;
  324. mutex_unlock(&fifo_state->fifo_mutex);
  325. return NULL;
  326. }
  327. static void vmw_fifo_res_copy(struct vmw_fifo_state *fifo_state,
  328. __le32 __iomem *fifo_mem,
  329. uint32_t next_cmd,
  330. uint32_t max, uint32_t min, uint32_t bytes)
  331. {
  332. uint32_t chunk_size = max - next_cmd;
  333. uint32_t rest;
  334. uint32_t *buffer = (fifo_state->dynamic_buffer != NULL) ?
  335. fifo_state->dynamic_buffer : fifo_state->static_buffer;
  336. if (bytes < chunk_size)
  337. chunk_size = bytes;
  338. iowrite32(bytes, fifo_mem + SVGA_FIFO_RESERVED);
  339. mb();
  340. memcpy_toio(fifo_mem + (next_cmd >> 2), buffer, chunk_size);
  341. rest = bytes - chunk_size;
  342. if (rest)
  343. memcpy_toio(fifo_mem + (min >> 2), buffer + (chunk_size >> 2),
  344. rest);
  345. }
  346. static void vmw_fifo_slow_copy(struct vmw_fifo_state *fifo_state,
  347. __le32 __iomem *fifo_mem,
  348. uint32_t next_cmd,
  349. uint32_t max, uint32_t min, uint32_t bytes)
  350. {
  351. uint32_t *buffer = (fifo_state->dynamic_buffer != NULL) ?
  352. fifo_state->dynamic_buffer : fifo_state->static_buffer;
  353. while (bytes > 0) {
  354. iowrite32(*buffer++, fifo_mem + (next_cmd >> 2));
  355. next_cmd += sizeof(uint32_t);
  356. if (unlikely(next_cmd == max))
  357. next_cmd = min;
  358. mb();
  359. iowrite32(next_cmd, fifo_mem + SVGA_FIFO_NEXT_CMD);
  360. mb();
  361. bytes -= sizeof(uint32_t);
  362. }
  363. }
  364. void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes)
  365. {
  366. struct vmw_fifo_state *fifo_state = &dev_priv->fifo;
  367. __le32 __iomem *fifo_mem = dev_priv->mmio_virt;
  368. uint32_t next_cmd = ioread32(fifo_mem + SVGA_FIFO_NEXT_CMD);
  369. uint32_t max = ioread32(fifo_mem + SVGA_FIFO_MAX);
  370. uint32_t min = ioread32(fifo_mem + SVGA_FIFO_MIN);
  371. bool reserveable = fifo_state->capabilities & SVGA_FIFO_CAP_RESERVE;
  372. BUG_ON((bytes & 3) != 0);
  373. BUG_ON(bytes > fifo_state->reserved_size);
  374. fifo_state->reserved_size = 0;
  375. if (fifo_state->using_bounce_buffer) {
  376. if (reserveable)
  377. vmw_fifo_res_copy(fifo_state, fifo_mem,
  378. next_cmd, max, min, bytes);
  379. else
  380. vmw_fifo_slow_copy(fifo_state, fifo_mem,
  381. next_cmd, max, min, bytes);
  382. if (fifo_state->dynamic_buffer) {
  383. vfree(fifo_state->dynamic_buffer);
  384. fifo_state->dynamic_buffer = NULL;
  385. }
  386. }
  387. down_write(&fifo_state->rwsem);
  388. if (fifo_state->using_bounce_buffer || reserveable) {
  389. next_cmd += bytes;
  390. if (next_cmd >= max)
  391. next_cmd -= max - min;
  392. mb();
  393. iowrite32(next_cmd, fifo_mem + SVGA_FIFO_NEXT_CMD);
  394. }
  395. if (reserveable)
  396. iowrite32(0, fifo_mem + SVGA_FIFO_RESERVED);
  397. mb();
  398. up_write(&fifo_state->rwsem);
  399. vmw_fifo_ping_host(dev_priv, SVGA_SYNC_GENERIC);
  400. mutex_unlock(&fifo_state->fifo_mutex);
  401. }
  402. int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
  403. {
  404. struct vmw_fifo_state *fifo_state = &dev_priv->fifo;
  405. struct svga_fifo_cmd_fence *cmd_fence;
  406. void *fm;
  407. int ret = 0;
  408. uint32_t bytes = sizeof(__le32) + sizeof(*cmd_fence);
  409. fm = vmw_fifo_reserve(dev_priv, bytes);
  410. if (unlikely(fm == NULL)) {
  411. *seqno = atomic_read(&dev_priv->marker_seq);
  412. ret = -ENOMEM;
  413. (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
  414. false, 3*HZ);
  415. goto out_err;
  416. }
  417. do {
  418. *seqno = atomic_add_return(1, &dev_priv->marker_seq);
  419. } while (*seqno == 0);
  420. if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
  421. /*
  422. * Don't request hardware to send a fence. The
  423. * waiting code in vmwgfx_irq.c will emulate this.
  424. */
  425. vmw_fifo_commit(dev_priv, 0);
  426. return 0;
  427. }
  428. *(__le32 *) fm = cpu_to_le32(SVGA_CMD_FENCE);
  429. cmd_fence = (struct svga_fifo_cmd_fence *)
  430. ((unsigned long)fm + sizeof(__le32));
  431. iowrite32(*seqno, &cmd_fence->fence);
  432. vmw_fifo_commit(dev_priv, bytes);
  433. (void) vmw_marker_push(&fifo_state->marker_queue, *seqno);
  434. vmw_update_seqno(dev_priv, fifo_state);
  435. out_err:
  436. return ret;
  437. }
  438. /**
  439. * vmw_fifo_emit_dummy_legacy_query - emits a dummy query to the fifo using
  440. * legacy query commands.
  441. *
  442. * @dev_priv: The device private structure.
  443. * @cid: The hardware context id used for the query.
  444. *
  445. * See the vmw_fifo_emit_dummy_query documentation.
  446. */
  447. static int vmw_fifo_emit_dummy_legacy_query(struct vmw_private *dev_priv,
  448. uint32_t cid)
  449. {
  450. /*
  451. * A query wait without a preceding query end will
  452. * actually finish all queries for this cid
  453. * without writing to the query result structure.
  454. */
  455. struct ttm_buffer_object *bo = dev_priv->dummy_query_bo;
  456. struct {
  457. SVGA3dCmdHeader header;
  458. SVGA3dCmdWaitForQuery body;
  459. } *cmd;
  460. cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
  461. if (unlikely(cmd == NULL)) {
  462. DRM_ERROR("Out of fifo space for dummy query.\n");
  463. return -ENOMEM;
  464. }
  465. cmd->header.id = SVGA_3D_CMD_WAIT_FOR_QUERY;
  466. cmd->header.size = sizeof(cmd->body);
  467. cmd->body.cid = cid;
  468. cmd->body.type = SVGA3D_QUERYTYPE_OCCLUSION;
  469. if (bo->mem.mem_type == TTM_PL_VRAM) {
  470. cmd->body.guestResult.gmrId = SVGA_GMR_FRAMEBUFFER;
  471. cmd->body.guestResult.offset = bo->offset;
  472. } else {
  473. cmd->body.guestResult.gmrId = bo->mem.start;
  474. cmd->body.guestResult.offset = 0;
  475. }
  476. vmw_fifo_commit(dev_priv, sizeof(*cmd));
  477. return 0;
  478. }
  479. /**
  480. * vmw_fifo_emit_dummy_gb_query - emits a dummy query to the fifo using
  481. * guest-backed resource query commands.
  482. *
  483. * @dev_priv: The device private structure.
  484. * @cid: The hardware context id used for the query.
  485. *
  486. * See the vmw_fifo_emit_dummy_query documentation.
  487. */
  488. static int vmw_fifo_emit_dummy_gb_query(struct vmw_private *dev_priv,
  489. uint32_t cid)
  490. {
  491. /*
  492. * A query wait without a preceding query end will
  493. * actually finish all queries for this cid
  494. * without writing to the query result structure.
  495. */
  496. struct ttm_buffer_object *bo = dev_priv->dummy_query_bo;
  497. struct {
  498. SVGA3dCmdHeader header;
  499. SVGA3dCmdWaitForGBQuery body;
  500. } *cmd;
  501. cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
  502. if (unlikely(cmd == NULL)) {
  503. DRM_ERROR("Out of fifo space for dummy query.\n");
  504. return -ENOMEM;
  505. }
  506. cmd->header.id = SVGA_3D_CMD_WAIT_FOR_GB_QUERY;
  507. cmd->header.size = sizeof(cmd->body);
  508. cmd->body.cid = cid;
  509. cmd->body.type = SVGA3D_QUERYTYPE_OCCLUSION;
  510. BUG_ON(bo->mem.mem_type != VMW_PL_MOB);
  511. cmd->body.mobid = bo->mem.start;
  512. cmd->body.offset = 0;
  513. vmw_fifo_commit(dev_priv, sizeof(*cmd));
  514. return 0;
  515. }
  516. /**
  517. * vmw_fifo_emit_dummy_gb_query - emits a dummy query to the fifo using
  518. * appropriate resource query commands.
  519. *
  520. * @dev_priv: The device private structure.
  521. * @cid: The hardware context id used for the query.
  522. *
  523. * This function is used to emit a dummy occlusion query with
  524. * no primitives rendered between query begin and query end.
  525. * It's used to provide a query barrier, in order to know that when
  526. * this query is finished, all preceding queries are also finished.
  527. *
  528. * A Query results structure should have been initialized at the start
  529. * of the dev_priv->dummy_query_bo buffer object. And that buffer object
  530. * must also be either reserved or pinned when this function is called.
  531. *
  532. * Returns -ENOMEM on failure to reserve fifo space.
  533. */
  534. int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
  535. uint32_t cid)
  536. {
  537. if (dev_priv->has_mob)
  538. return vmw_fifo_emit_dummy_gb_query(dev_priv, cid);
  539. return vmw_fifo_emit_dummy_legacy_query(dev_priv, cid);
  540. }