vmwgfx_fifo.c 16 KB

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