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