i810_dma.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. /* i810_dma.c -- DMA support for the i810 -*- linux-c -*-
  2. * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
  3. *
  4. * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  5. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  6. * All Rights Reserved.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice (including the next
  16. * paragraph) shall be included in all copies or substantial portions of the
  17. * Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  23. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  24. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  25. * DEALINGS IN THE SOFTWARE.
  26. *
  27. * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
  28. * Jeff Hartmann <jhartmann@valinux.com>
  29. * Keith Whitwell <keith@tungstengraphics.com>
  30. *
  31. */
  32. #include <drm/drmP.h>
  33. #include <drm/i810_drm.h>
  34. #include "i810_drv.h"
  35. #include <linux/interrupt.h> /* For task queue support */
  36. #include <linux/delay.h>
  37. #include <linux/slab.h>
  38. #include <linux/pagemap.h>
  39. #define I810_BUF_FREE 2
  40. #define I810_BUF_CLIENT 1
  41. #define I810_BUF_HARDWARE 0
  42. #define I810_BUF_UNMAPPED 0
  43. #define I810_BUF_MAPPED 1
  44. static struct drm_buf *i810_freelist_get(struct drm_device * dev)
  45. {
  46. struct drm_device_dma *dma = dev->dma;
  47. int i;
  48. int used;
  49. /* Linear search might not be the best solution */
  50. for (i = 0; i < dma->buf_count; i++) {
  51. struct drm_buf *buf = dma->buflist[i];
  52. drm_i810_buf_priv_t *buf_priv = buf->dev_private;
  53. /* In use is already a pointer */
  54. used = cmpxchg(buf_priv->in_use, I810_BUF_FREE,
  55. I810_BUF_CLIENT);
  56. if (used == I810_BUF_FREE)
  57. return buf;
  58. }
  59. return NULL;
  60. }
  61. /* This should only be called if the buffer is not sent to the hardware
  62. * yet, the hardware updates in use for us once its on the ring buffer.
  63. */
  64. static int i810_freelist_put(struct drm_device *dev, struct drm_buf *buf)
  65. {
  66. drm_i810_buf_priv_t *buf_priv = buf->dev_private;
  67. int used;
  68. /* In use is already a pointer */
  69. used = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT, I810_BUF_FREE);
  70. if (used != I810_BUF_CLIENT) {
  71. DRM_ERROR("Freeing buffer thats not in use : %d\n", buf->idx);
  72. return -EINVAL;
  73. }
  74. return 0;
  75. }
  76. static int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
  77. {
  78. struct drm_file *priv = filp->private_data;
  79. struct drm_device *dev;
  80. drm_i810_private_t *dev_priv;
  81. struct drm_buf *buf;
  82. drm_i810_buf_priv_t *buf_priv;
  83. dev = priv->minor->dev;
  84. dev_priv = dev->dev_private;
  85. buf = dev_priv->mmap_buffer;
  86. buf_priv = buf->dev_private;
  87. vma->vm_flags |= VM_DONTCOPY;
  88. buf_priv->currently_mapped = I810_BUF_MAPPED;
  89. if (io_remap_pfn_range(vma, vma->vm_start,
  90. vma->vm_pgoff,
  91. vma->vm_end - vma->vm_start, vma->vm_page_prot))
  92. return -EAGAIN;
  93. return 0;
  94. }
  95. static const struct file_operations i810_buffer_fops = {
  96. .open = drm_open,
  97. .release = drm_release,
  98. .unlocked_ioctl = drm_ioctl,
  99. .mmap = i810_mmap_buffers,
  100. #ifdef CONFIG_COMPAT
  101. .compat_ioctl = drm_compat_ioctl,
  102. #endif
  103. .llseek = noop_llseek,
  104. };
  105. static int i810_map_buffer(struct drm_buf *buf, struct drm_file *file_priv)
  106. {
  107. struct drm_device *dev = file_priv->minor->dev;
  108. drm_i810_buf_priv_t *buf_priv = buf->dev_private;
  109. drm_i810_private_t *dev_priv = dev->dev_private;
  110. const struct file_operations *old_fops;
  111. int retcode = 0;
  112. if (buf_priv->currently_mapped == I810_BUF_MAPPED)
  113. return -EINVAL;
  114. /* This is all entirely broken */
  115. old_fops = file_priv->filp->f_op;
  116. file_priv->filp->f_op = &i810_buffer_fops;
  117. dev_priv->mmap_buffer = buf;
  118. buf_priv->virtual = (void *)vm_mmap(file_priv->filp, 0, buf->total,
  119. PROT_READ | PROT_WRITE,
  120. MAP_SHARED, buf->bus_address);
  121. dev_priv->mmap_buffer = NULL;
  122. file_priv->filp->f_op = old_fops;
  123. if (IS_ERR(buf_priv->virtual)) {
  124. /* Real error */
  125. DRM_ERROR("mmap error\n");
  126. retcode = PTR_ERR(buf_priv->virtual);
  127. buf_priv->virtual = NULL;
  128. }
  129. return retcode;
  130. }
  131. static int i810_unmap_buffer(struct drm_buf *buf)
  132. {
  133. drm_i810_buf_priv_t *buf_priv = buf->dev_private;
  134. int retcode = 0;
  135. if (buf_priv->currently_mapped != I810_BUF_MAPPED)
  136. return -EINVAL;
  137. retcode = vm_munmap((unsigned long)buf_priv->virtual,
  138. (size_t) buf->total);
  139. buf_priv->currently_mapped = I810_BUF_UNMAPPED;
  140. buf_priv->virtual = NULL;
  141. return retcode;
  142. }
  143. static int i810_dma_get_buffer(struct drm_device *dev, drm_i810_dma_t *d,
  144. struct drm_file *file_priv)
  145. {
  146. struct drm_buf *buf;
  147. drm_i810_buf_priv_t *buf_priv;
  148. int retcode = 0;
  149. buf = i810_freelist_get(dev);
  150. if (!buf) {
  151. retcode = -ENOMEM;
  152. DRM_DEBUG("retcode=%d\n", retcode);
  153. return retcode;
  154. }
  155. retcode = i810_map_buffer(buf, file_priv);
  156. if (retcode) {
  157. i810_freelist_put(dev, buf);
  158. DRM_ERROR("mapbuf failed, retcode %d\n", retcode);
  159. return retcode;
  160. }
  161. buf->file_priv = file_priv;
  162. buf_priv = buf->dev_private;
  163. d->granted = 1;
  164. d->request_idx = buf->idx;
  165. d->request_size = buf->total;
  166. d->virtual = buf_priv->virtual;
  167. return retcode;
  168. }
  169. static int i810_dma_cleanup(struct drm_device *dev)
  170. {
  171. struct drm_device_dma *dma = dev->dma;
  172. /* Make sure interrupts are disabled here because the uninstall ioctl
  173. * may not have been called from userspace and after dev_private
  174. * is freed, it's too late.
  175. */
  176. if (drm_core_check_feature(dev, DRIVER_HAVE_IRQ) && dev->irq_enabled)
  177. drm_irq_uninstall(dev);
  178. if (dev->dev_private) {
  179. int i;
  180. drm_i810_private_t *dev_priv =
  181. (drm_i810_private_t *) dev->dev_private;
  182. if (dev_priv->ring.virtual_start)
  183. drm_legacy_ioremapfree(&dev_priv->ring.map, dev);
  184. if (dev_priv->hw_status_page) {
  185. pci_free_consistent(dev->pdev, PAGE_SIZE,
  186. dev_priv->hw_status_page,
  187. dev_priv->dma_status_page);
  188. }
  189. kfree(dev->dev_private);
  190. dev->dev_private = NULL;
  191. for (i = 0; i < dma->buf_count; i++) {
  192. struct drm_buf *buf = dma->buflist[i];
  193. drm_i810_buf_priv_t *buf_priv = buf->dev_private;
  194. if (buf_priv->kernel_virtual && buf->total)
  195. drm_legacy_ioremapfree(&buf_priv->map, dev);
  196. }
  197. }
  198. return 0;
  199. }
  200. static int i810_wait_ring(struct drm_device *dev, int n)
  201. {
  202. drm_i810_private_t *dev_priv = dev->dev_private;
  203. drm_i810_ring_buffer_t *ring = &(dev_priv->ring);
  204. int iters = 0;
  205. unsigned long end;
  206. unsigned int last_head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
  207. end = jiffies + (HZ * 3);
  208. while (ring->space < n) {
  209. ring->head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
  210. ring->space = ring->head - (ring->tail + 8);
  211. if (ring->space < 0)
  212. ring->space += ring->Size;
  213. if (ring->head != last_head) {
  214. end = jiffies + (HZ * 3);
  215. last_head = ring->head;
  216. }
  217. iters++;
  218. if (time_before(end, jiffies)) {
  219. DRM_ERROR("space: %d wanted %d\n", ring->space, n);
  220. DRM_ERROR("lockup\n");
  221. goto out_wait_ring;
  222. }
  223. udelay(1);
  224. }
  225. out_wait_ring:
  226. return iters;
  227. }
  228. static void i810_kernel_lost_context(struct drm_device *dev)
  229. {
  230. drm_i810_private_t *dev_priv = dev->dev_private;
  231. drm_i810_ring_buffer_t *ring = &(dev_priv->ring);
  232. ring->head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
  233. ring->tail = I810_READ(LP_RING + RING_TAIL);
  234. ring->space = ring->head - (ring->tail + 8);
  235. if (ring->space < 0)
  236. ring->space += ring->Size;
  237. }
  238. static int i810_freelist_init(struct drm_device *dev, drm_i810_private_t *dev_priv)
  239. {
  240. struct drm_device_dma *dma = dev->dma;
  241. int my_idx = 24;
  242. u32 *hw_status = (u32 *) (dev_priv->hw_status_page + my_idx);
  243. int i;
  244. if (dma->buf_count > 1019) {
  245. /* Not enough space in the status page for the freelist */
  246. return -EINVAL;
  247. }
  248. for (i = 0; i < dma->buf_count; i++) {
  249. struct drm_buf *buf = dma->buflist[i];
  250. drm_i810_buf_priv_t *buf_priv = buf->dev_private;
  251. buf_priv->in_use = hw_status++;
  252. buf_priv->my_use_idx = my_idx;
  253. my_idx += 4;
  254. *buf_priv->in_use = I810_BUF_FREE;
  255. buf_priv->map.offset = buf->bus_address;
  256. buf_priv->map.size = buf->total;
  257. buf_priv->map.type = _DRM_AGP;
  258. buf_priv->map.flags = 0;
  259. buf_priv->map.mtrr = 0;
  260. drm_legacy_ioremap(&buf_priv->map, dev);
  261. buf_priv->kernel_virtual = buf_priv->map.handle;
  262. }
  263. return 0;
  264. }
  265. static int i810_dma_initialize(struct drm_device *dev,
  266. drm_i810_private_t *dev_priv,
  267. drm_i810_init_t *init)
  268. {
  269. struct drm_map_list *r_list;
  270. memset(dev_priv, 0, sizeof(drm_i810_private_t));
  271. list_for_each_entry(r_list, &dev->maplist, head) {
  272. if (r_list->map &&
  273. r_list->map->type == _DRM_SHM &&
  274. r_list->map->flags & _DRM_CONTAINS_LOCK) {
  275. dev_priv->sarea_map = r_list->map;
  276. break;
  277. }
  278. }
  279. if (!dev_priv->sarea_map) {
  280. dev->dev_private = (void *)dev_priv;
  281. i810_dma_cleanup(dev);
  282. DRM_ERROR("can not find sarea!\n");
  283. return -EINVAL;
  284. }
  285. dev_priv->mmio_map = drm_legacy_findmap(dev, init->mmio_offset);
  286. if (!dev_priv->mmio_map) {
  287. dev->dev_private = (void *)dev_priv;
  288. i810_dma_cleanup(dev);
  289. DRM_ERROR("can not find mmio map!\n");
  290. return -EINVAL;
  291. }
  292. dev->agp_buffer_token = init->buffers_offset;
  293. dev->agp_buffer_map = drm_legacy_findmap(dev, init->buffers_offset);
  294. if (!dev->agp_buffer_map) {
  295. dev->dev_private = (void *)dev_priv;
  296. i810_dma_cleanup(dev);
  297. DRM_ERROR("can not find dma buffer map!\n");
  298. return -EINVAL;
  299. }
  300. dev_priv->sarea_priv = (drm_i810_sarea_t *)
  301. ((u8 *) dev_priv->sarea_map->handle + init->sarea_priv_offset);
  302. dev_priv->ring.Start = init->ring_start;
  303. dev_priv->ring.End = init->ring_end;
  304. dev_priv->ring.Size = init->ring_size;
  305. dev_priv->ring.map.offset = dev->agp->base + init->ring_start;
  306. dev_priv->ring.map.size = init->ring_size;
  307. dev_priv->ring.map.type = _DRM_AGP;
  308. dev_priv->ring.map.flags = 0;
  309. dev_priv->ring.map.mtrr = 0;
  310. drm_legacy_ioremap(&dev_priv->ring.map, dev);
  311. if (dev_priv->ring.map.handle == NULL) {
  312. dev->dev_private = (void *)dev_priv;
  313. i810_dma_cleanup(dev);
  314. DRM_ERROR("can not ioremap virtual address for"
  315. " ring buffer\n");
  316. return -ENOMEM;
  317. }
  318. dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
  319. dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
  320. dev_priv->w = init->w;
  321. dev_priv->h = init->h;
  322. dev_priv->pitch = init->pitch;
  323. dev_priv->back_offset = init->back_offset;
  324. dev_priv->depth_offset = init->depth_offset;
  325. dev_priv->front_offset = init->front_offset;
  326. dev_priv->overlay_offset = init->overlay_offset;
  327. dev_priv->overlay_physical = init->overlay_physical;
  328. dev_priv->front_di1 = init->front_offset | init->pitch_bits;
  329. dev_priv->back_di1 = init->back_offset | init->pitch_bits;
  330. dev_priv->zi1 = init->depth_offset | init->pitch_bits;
  331. /* Program Hardware Status Page */
  332. dev_priv->hw_status_page =
  333. pci_zalloc_consistent(dev->pdev, PAGE_SIZE,
  334. &dev_priv->dma_status_page);
  335. if (!dev_priv->hw_status_page) {
  336. dev->dev_private = (void *)dev_priv;
  337. i810_dma_cleanup(dev);
  338. DRM_ERROR("Can not allocate hardware status page\n");
  339. return -ENOMEM;
  340. }
  341. DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
  342. I810_WRITE(0x02080, dev_priv->dma_status_page);
  343. DRM_DEBUG("Enabled hardware status page\n");
  344. /* Now we need to init our freelist */
  345. if (i810_freelist_init(dev, dev_priv) != 0) {
  346. dev->dev_private = (void *)dev_priv;
  347. i810_dma_cleanup(dev);
  348. DRM_ERROR("Not enough space in the status page for"
  349. " the freelist\n");
  350. return -ENOMEM;
  351. }
  352. dev->dev_private = (void *)dev_priv;
  353. return 0;
  354. }
  355. static int i810_dma_init(struct drm_device *dev, void *data,
  356. struct drm_file *file_priv)
  357. {
  358. drm_i810_private_t *dev_priv;
  359. drm_i810_init_t *init = data;
  360. int retcode = 0;
  361. switch (init->func) {
  362. case I810_INIT_DMA_1_4:
  363. DRM_INFO("Using v1.4 init.\n");
  364. dev_priv = kmalloc(sizeof(drm_i810_private_t), GFP_KERNEL);
  365. if (dev_priv == NULL)
  366. return -ENOMEM;
  367. retcode = i810_dma_initialize(dev, dev_priv, init);
  368. break;
  369. case I810_CLEANUP_DMA:
  370. DRM_INFO("DMA Cleanup\n");
  371. retcode = i810_dma_cleanup(dev);
  372. break;
  373. default:
  374. return -EINVAL;
  375. }
  376. return retcode;
  377. }
  378. /* Most efficient way to verify state for the i810 is as it is
  379. * emitted. Non-conformant state is silently dropped.
  380. *
  381. * Use 'volatile' & local var tmp to force the emitted values to be
  382. * identical to the verified ones.
  383. */
  384. static void i810EmitContextVerified(struct drm_device *dev,
  385. volatile unsigned int *code)
  386. {
  387. drm_i810_private_t *dev_priv = dev->dev_private;
  388. int i, j = 0;
  389. unsigned int tmp;
  390. RING_LOCALS;
  391. BEGIN_LP_RING(I810_CTX_SETUP_SIZE);
  392. OUT_RING(GFX_OP_COLOR_FACTOR);
  393. OUT_RING(code[I810_CTXREG_CF1]);
  394. OUT_RING(GFX_OP_STIPPLE);
  395. OUT_RING(code[I810_CTXREG_ST1]);
  396. for (i = 4; i < I810_CTX_SETUP_SIZE; i++) {
  397. tmp = code[i];
  398. if ((tmp & (7 << 29)) == (3 << 29) &&
  399. (tmp & (0x1f << 24)) < (0x1d << 24)) {
  400. OUT_RING(tmp);
  401. j++;
  402. } else
  403. printk("constext state dropped!!!\n");
  404. }
  405. if (j & 1)
  406. OUT_RING(0);
  407. ADVANCE_LP_RING();
  408. }
  409. static void i810EmitTexVerified(struct drm_device *dev, volatile unsigned int *code)
  410. {
  411. drm_i810_private_t *dev_priv = dev->dev_private;
  412. int i, j = 0;
  413. unsigned int tmp;
  414. RING_LOCALS;
  415. BEGIN_LP_RING(I810_TEX_SETUP_SIZE);
  416. OUT_RING(GFX_OP_MAP_INFO);
  417. OUT_RING(code[I810_TEXREG_MI1]);
  418. OUT_RING(code[I810_TEXREG_MI2]);
  419. OUT_RING(code[I810_TEXREG_MI3]);
  420. for (i = 4; i < I810_TEX_SETUP_SIZE; i++) {
  421. tmp = code[i];
  422. if ((tmp & (7 << 29)) == (3 << 29) &&
  423. (tmp & (0x1f << 24)) < (0x1d << 24)) {
  424. OUT_RING(tmp);
  425. j++;
  426. } else
  427. printk("texture state dropped!!!\n");
  428. }
  429. if (j & 1)
  430. OUT_RING(0);
  431. ADVANCE_LP_RING();
  432. }
  433. /* Need to do some additional checking when setting the dest buffer.
  434. */
  435. static void i810EmitDestVerified(struct drm_device *dev,
  436. volatile unsigned int *code)
  437. {
  438. drm_i810_private_t *dev_priv = dev->dev_private;
  439. unsigned int tmp;
  440. RING_LOCALS;
  441. BEGIN_LP_RING(I810_DEST_SETUP_SIZE + 2);
  442. tmp = code[I810_DESTREG_DI1];
  443. if (tmp == dev_priv->front_di1 || tmp == dev_priv->back_di1) {
  444. OUT_RING(CMD_OP_DESTBUFFER_INFO);
  445. OUT_RING(tmp);
  446. } else
  447. DRM_DEBUG("bad di1 %x (allow %x or %x)\n",
  448. tmp, dev_priv->front_di1, dev_priv->back_di1);
  449. /* invarient:
  450. */
  451. OUT_RING(CMD_OP_Z_BUFFER_INFO);
  452. OUT_RING(dev_priv->zi1);
  453. OUT_RING(GFX_OP_DESTBUFFER_VARS);
  454. OUT_RING(code[I810_DESTREG_DV1]);
  455. OUT_RING(GFX_OP_DRAWRECT_INFO);
  456. OUT_RING(code[I810_DESTREG_DR1]);
  457. OUT_RING(code[I810_DESTREG_DR2]);
  458. OUT_RING(code[I810_DESTREG_DR3]);
  459. OUT_RING(code[I810_DESTREG_DR4]);
  460. OUT_RING(0);
  461. ADVANCE_LP_RING();
  462. }
  463. static void i810EmitState(struct drm_device *dev)
  464. {
  465. drm_i810_private_t *dev_priv = dev->dev_private;
  466. drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
  467. unsigned int dirty = sarea_priv->dirty;
  468. DRM_DEBUG("%x\n", dirty);
  469. if (dirty & I810_UPLOAD_BUFFERS) {
  470. i810EmitDestVerified(dev, sarea_priv->BufferState);
  471. sarea_priv->dirty &= ~I810_UPLOAD_BUFFERS;
  472. }
  473. if (dirty & I810_UPLOAD_CTX) {
  474. i810EmitContextVerified(dev, sarea_priv->ContextState);
  475. sarea_priv->dirty &= ~I810_UPLOAD_CTX;
  476. }
  477. if (dirty & I810_UPLOAD_TEX0) {
  478. i810EmitTexVerified(dev, sarea_priv->TexState[0]);
  479. sarea_priv->dirty &= ~I810_UPLOAD_TEX0;
  480. }
  481. if (dirty & I810_UPLOAD_TEX1) {
  482. i810EmitTexVerified(dev, sarea_priv->TexState[1]);
  483. sarea_priv->dirty &= ~I810_UPLOAD_TEX1;
  484. }
  485. }
  486. /* need to verify
  487. */
  488. static void i810_dma_dispatch_clear(struct drm_device *dev, int flags,
  489. unsigned int clear_color,
  490. unsigned int clear_zval)
  491. {
  492. drm_i810_private_t *dev_priv = dev->dev_private;
  493. drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
  494. int nbox = sarea_priv->nbox;
  495. struct drm_clip_rect *pbox = sarea_priv->boxes;
  496. int pitch = dev_priv->pitch;
  497. int cpp = 2;
  498. int i;
  499. RING_LOCALS;
  500. if (dev_priv->current_page == 1) {
  501. unsigned int tmp = flags;
  502. flags &= ~(I810_FRONT | I810_BACK);
  503. if (tmp & I810_FRONT)
  504. flags |= I810_BACK;
  505. if (tmp & I810_BACK)
  506. flags |= I810_FRONT;
  507. }
  508. i810_kernel_lost_context(dev);
  509. if (nbox > I810_NR_SAREA_CLIPRECTS)
  510. nbox = I810_NR_SAREA_CLIPRECTS;
  511. for (i = 0; i < nbox; i++, pbox++) {
  512. unsigned int x = pbox->x1;
  513. unsigned int y = pbox->y1;
  514. unsigned int width = (pbox->x2 - x) * cpp;
  515. unsigned int height = pbox->y2 - y;
  516. unsigned int start = y * pitch + x * cpp;
  517. if (pbox->x1 > pbox->x2 ||
  518. pbox->y1 > pbox->y2 ||
  519. pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h)
  520. continue;
  521. if (flags & I810_FRONT) {
  522. BEGIN_LP_RING(6);
  523. OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3);
  524. OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch);
  525. OUT_RING((height << 16) | width);
  526. OUT_RING(start);
  527. OUT_RING(clear_color);
  528. OUT_RING(0);
  529. ADVANCE_LP_RING();
  530. }
  531. if (flags & I810_BACK) {
  532. BEGIN_LP_RING(6);
  533. OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3);
  534. OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch);
  535. OUT_RING((height << 16) | width);
  536. OUT_RING(dev_priv->back_offset + start);
  537. OUT_RING(clear_color);
  538. OUT_RING(0);
  539. ADVANCE_LP_RING();
  540. }
  541. if (flags & I810_DEPTH) {
  542. BEGIN_LP_RING(6);
  543. OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3);
  544. OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch);
  545. OUT_RING((height << 16) | width);
  546. OUT_RING(dev_priv->depth_offset + start);
  547. OUT_RING(clear_zval);
  548. OUT_RING(0);
  549. ADVANCE_LP_RING();
  550. }
  551. }
  552. }
  553. static void i810_dma_dispatch_swap(struct drm_device *dev)
  554. {
  555. drm_i810_private_t *dev_priv = dev->dev_private;
  556. drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
  557. int nbox = sarea_priv->nbox;
  558. struct drm_clip_rect *pbox = sarea_priv->boxes;
  559. int pitch = dev_priv->pitch;
  560. int cpp = 2;
  561. int i;
  562. RING_LOCALS;
  563. DRM_DEBUG("swapbuffers\n");
  564. i810_kernel_lost_context(dev);
  565. if (nbox > I810_NR_SAREA_CLIPRECTS)
  566. nbox = I810_NR_SAREA_CLIPRECTS;
  567. for (i = 0; i < nbox; i++, pbox++) {
  568. unsigned int w = pbox->x2 - pbox->x1;
  569. unsigned int h = pbox->y2 - pbox->y1;
  570. unsigned int dst = pbox->x1 * cpp + pbox->y1 * pitch;
  571. unsigned int start = dst;
  572. if (pbox->x1 > pbox->x2 ||
  573. pbox->y1 > pbox->y2 ||
  574. pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h)
  575. continue;
  576. BEGIN_LP_RING(6);
  577. OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_SRC_COPY_BLT | 0x4);
  578. OUT_RING(pitch | (0xCC << 16));
  579. OUT_RING((h << 16) | (w * cpp));
  580. if (dev_priv->current_page == 0)
  581. OUT_RING(dev_priv->front_offset + start);
  582. else
  583. OUT_RING(dev_priv->back_offset + start);
  584. OUT_RING(pitch);
  585. if (dev_priv->current_page == 0)
  586. OUT_RING(dev_priv->back_offset + start);
  587. else
  588. OUT_RING(dev_priv->front_offset + start);
  589. ADVANCE_LP_RING();
  590. }
  591. }
  592. static void i810_dma_dispatch_vertex(struct drm_device *dev,
  593. struct drm_buf *buf, int discard, int used)
  594. {
  595. drm_i810_private_t *dev_priv = dev->dev_private;
  596. drm_i810_buf_priv_t *buf_priv = buf->dev_private;
  597. drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
  598. struct drm_clip_rect *box = sarea_priv->boxes;
  599. int nbox = sarea_priv->nbox;
  600. unsigned long address = (unsigned long)buf->bus_address;
  601. unsigned long start = address - dev->agp->base;
  602. int i = 0;
  603. RING_LOCALS;
  604. i810_kernel_lost_context(dev);
  605. if (nbox > I810_NR_SAREA_CLIPRECTS)
  606. nbox = I810_NR_SAREA_CLIPRECTS;
  607. if (used > 4 * 1024)
  608. used = 0;
  609. if (sarea_priv->dirty)
  610. i810EmitState(dev);
  611. if (buf_priv->currently_mapped == I810_BUF_MAPPED) {
  612. unsigned int prim = (sarea_priv->vertex_prim & PR_MASK);
  613. *(u32 *) buf_priv->kernel_virtual =
  614. ((GFX_OP_PRIMITIVE | prim | ((used / 4) - 2)));
  615. if (used & 4) {
  616. *(u32 *) ((char *) buf_priv->kernel_virtual + used) = 0;
  617. used += 4;
  618. }
  619. i810_unmap_buffer(buf);
  620. }
  621. if (used) {
  622. do {
  623. if (i < nbox) {
  624. BEGIN_LP_RING(4);
  625. OUT_RING(GFX_OP_SCISSOR | SC_UPDATE_SCISSOR |
  626. SC_ENABLE);
  627. OUT_RING(GFX_OP_SCISSOR_INFO);
  628. OUT_RING(box[i].x1 | (box[i].y1 << 16));
  629. OUT_RING((box[i].x2 -
  630. 1) | ((box[i].y2 - 1) << 16));
  631. ADVANCE_LP_RING();
  632. }
  633. BEGIN_LP_RING(4);
  634. OUT_RING(CMD_OP_BATCH_BUFFER);
  635. OUT_RING(start | BB1_PROTECTED);
  636. OUT_RING(start + used - 4);
  637. OUT_RING(0);
  638. ADVANCE_LP_RING();
  639. } while (++i < nbox);
  640. }
  641. if (discard) {
  642. dev_priv->counter++;
  643. (void)cmpxchg(buf_priv->in_use, I810_BUF_CLIENT,
  644. I810_BUF_HARDWARE);
  645. BEGIN_LP_RING(8);
  646. OUT_RING(CMD_STORE_DWORD_IDX);
  647. OUT_RING(20);
  648. OUT_RING(dev_priv->counter);
  649. OUT_RING(CMD_STORE_DWORD_IDX);
  650. OUT_RING(buf_priv->my_use_idx);
  651. OUT_RING(I810_BUF_FREE);
  652. OUT_RING(CMD_REPORT_HEAD);
  653. OUT_RING(0);
  654. ADVANCE_LP_RING();
  655. }
  656. }
  657. static void i810_dma_dispatch_flip(struct drm_device *dev)
  658. {
  659. drm_i810_private_t *dev_priv = dev->dev_private;
  660. int pitch = dev_priv->pitch;
  661. RING_LOCALS;
  662. DRM_DEBUG("page=%d pfCurrentPage=%d\n",
  663. dev_priv->current_page,
  664. dev_priv->sarea_priv->pf_current_page);
  665. i810_kernel_lost_context(dev);
  666. BEGIN_LP_RING(2);
  667. OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
  668. OUT_RING(0);
  669. ADVANCE_LP_RING();
  670. BEGIN_LP_RING(I810_DEST_SETUP_SIZE + 2);
  671. /* On i815 at least ASYNC is buggy */
  672. /* pitch<<5 is from 11.2.8 p158,
  673. its the pitch / 8 then left shifted 8,
  674. so (pitch >> 3) << 8 */
  675. OUT_RING(CMD_OP_FRONTBUFFER_INFO | (pitch << 5) /*| ASYNC_FLIP */ );
  676. if (dev_priv->current_page == 0) {
  677. OUT_RING(dev_priv->back_offset);
  678. dev_priv->current_page = 1;
  679. } else {
  680. OUT_RING(dev_priv->front_offset);
  681. dev_priv->current_page = 0;
  682. }
  683. OUT_RING(0);
  684. ADVANCE_LP_RING();
  685. BEGIN_LP_RING(2);
  686. OUT_RING(CMD_OP_WAIT_FOR_EVENT | WAIT_FOR_PLANE_A_FLIP);
  687. OUT_RING(0);
  688. ADVANCE_LP_RING();
  689. /* Increment the frame counter. The client-side 3D driver must
  690. * throttle the framerate by waiting for this value before
  691. * performing the swapbuffer ioctl.
  692. */
  693. dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
  694. }
  695. static void i810_dma_quiescent(struct drm_device *dev)
  696. {
  697. drm_i810_private_t *dev_priv = dev->dev_private;
  698. RING_LOCALS;
  699. i810_kernel_lost_context(dev);
  700. BEGIN_LP_RING(4);
  701. OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
  702. OUT_RING(CMD_REPORT_HEAD);
  703. OUT_RING(0);
  704. OUT_RING(0);
  705. ADVANCE_LP_RING();
  706. i810_wait_ring(dev, dev_priv->ring.Size - 8);
  707. }
  708. static int i810_flush_queue(struct drm_device *dev)
  709. {
  710. drm_i810_private_t *dev_priv = dev->dev_private;
  711. struct drm_device_dma *dma = dev->dma;
  712. int i, ret = 0;
  713. RING_LOCALS;
  714. i810_kernel_lost_context(dev);
  715. BEGIN_LP_RING(2);
  716. OUT_RING(CMD_REPORT_HEAD);
  717. OUT_RING(0);
  718. ADVANCE_LP_RING();
  719. i810_wait_ring(dev, dev_priv->ring.Size - 8);
  720. for (i = 0; i < dma->buf_count; i++) {
  721. struct drm_buf *buf = dma->buflist[i];
  722. drm_i810_buf_priv_t *buf_priv = buf->dev_private;
  723. int used = cmpxchg(buf_priv->in_use, I810_BUF_HARDWARE,
  724. I810_BUF_FREE);
  725. if (used == I810_BUF_HARDWARE)
  726. DRM_DEBUG("reclaimed from HARDWARE\n");
  727. if (used == I810_BUF_CLIENT)
  728. DRM_DEBUG("still on client\n");
  729. }
  730. return ret;
  731. }
  732. /* Must be called with the lock held */
  733. void i810_driver_reclaim_buffers(struct drm_device *dev,
  734. struct drm_file *file_priv)
  735. {
  736. struct drm_device_dma *dma = dev->dma;
  737. int i;
  738. if (!dma)
  739. return;
  740. if (!dev->dev_private)
  741. return;
  742. if (!dma->buflist)
  743. return;
  744. i810_flush_queue(dev);
  745. for (i = 0; i < dma->buf_count; i++) {
  746. struct drm_buf *buf = dma->buflist[i];
  747. drm_i810_buf_priv_t *buf_priv = buf->dev_private;
  748. if (buf->file_priv == file_priv && buf_priv) {
  749. int used = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT,
  750. I810_BUF_FREE);
  751. if (used == I810_BUF_CLIENT)
  752. DRM_DEBUG("reclaimed from client\n");
  753. if (buf_priv->currently_mapped == I810_BUF_MAPPED)
  754. buf_priv->currently_mapped = I810_BUF_UNMAPPED;
  755. }
  756. }
  757. }
  758. static int i810_flush_ioctl(struct drm_device *dev, void *data,
  759. struct drm_file *file_priv)
  760. {
  761. LOCK_TEST_WITH_RETURN(dev, file_priv);
  762. i810_flush_queue(dev);
  763. return 0;
  764. }
  765. static int i810_dma_vertex(struct drm_device *dev, void *data,
  766. struct drm_file *file_priv)
  767. {
  768. struct drm_device_dma *dma = dev->dma;
  769. drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
  770. u32 *hw_status = dev_priv->hw_status_page;
  771. drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
  772. dev_priv->sarea_priv;
  773. drm_i810_vertex_t *vertex = data;
  774. LOCK_TEST_WITH_RETURN(dev, file_priv);
  775. DRM_DEBUG("idx %d used %d discard %d\n",
  776. vertex->idx, vertex->used, vertex->discard);
  777. if (vertex->idx < 0 || vertex->idx > dma->buf_count)
  778. return -EINVAL;
  779. i810_dma_dispatch_vertex(dev,
  780. dma->buflist[vertex->idx],
  781. vertex->discard, vertex->used);
  782. sarea_priv->last_enqueue = dev_priv->counter - 1;
  783. sarea_priv->last_dispatch = (int)hw_status[5];
  784. return 0;
  785. }
  786. static int i810_clear_bufs(struct drm_device *dev, void *data,
  787. struct drm_file *file_priv)
  788. {
  789. drm_i810_clear_t *clear = data;
  790. LOCK_TEST_WITH_RETURN(dev, file_priv);
  791. /* GH: Someone's doing nasty things... */
  792. if (!dev->dev_private)
  793. return -EINVAL;
  794. i810_dma_dispatch_clear(dev, clear->flags,
  795. clear->clear_color, clear->clear_depth);
  796. return 0;
  797. }
  798. static int i810_swap_bufs(struct drm_device *dev, void *data,
  799. struct drm_file *file_priv)
  800. {
  801. DRM_DEBUG("\n");
  802. LOCK_TEST_WITH_RETURN(dev, file_priv);
  803. i810_dma_dispatch_swap(dev);
  804. return 0;
  805. }
  806. static int i810_getage(struct drm_device *dev, void *data,
  807. struct drm_file *file_priv)
  808. {
  809. drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
  810. u32 *hw_status = dev_priv->hw_status_page;
  811. drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
  812. dev_priv->sarea_priv;
  813. sarea_priv->last_dispatch = (int)hw_status[5];
  814. return 0;
  815. }
  816. static int i810_getbuf(struct drm_device *dev, void *data,
  817. struct drm_file *file_priv)
  818. {
  819. int retcode = 0;
  820. drm_i810_dma_t *d = data;
  821. drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
  822. u32 *hw_status = dev_priv->hw_status_page;
  823. drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
  824. dev_priv->sarea_priv;
  825. LOCK_TEST_WITH_RETURN(dev, file_priv);
  826. d->granted = 0;
  827. retcode = i810_dma_get_buffer(dev, d, file_priv);
  828. DRM_DEBUG("i810_dma: %d returning %d, granted = %d\n",
  829. task_pid_nr(current), retcode, d->granted);
  830. sarea_priv->last_dispatch = (int)hw_status[5];
  831. return retcode;
  832. }
  833. static int i810_copybuf(struct drm_device *dev, void *data,
  834. struct drm_file *file_priv)
  835. {
  836. /* Never copy - 2.4.x doesn't need it */
  837. return 0;
  838. }
  839. static int i810_docopy(struct drm_device *dev, void *data,
  840. struct drm_file *file_priv)
  841. {
  842. /* Never copy - 2.4.x doesn't need it */
  843. return 0;
  844. }
  845. static void i810_dma_dispatch_mc(struct drm_device *dev, struct drm_buf *buf, int used,
  846. unsigned int last_render)
  847. {
  848. drm_i810_private_t *dev_priv = dev->dev_private;
  849. drm_i810_buf_priv_t *buf_priv = buf->dev_private;
  850. drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
  851. unsigned long address = (unsigned long)buf->bus_address;
  852. unsigned long start = address - dev->agp->base;
  853. int u;
  854. RING_LOCALS;
  855. i810_kernel_lost_context(dev);
  856. u = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT, I810_BUF_HARDWARE);
  857. if (u != I810_BUF_CLIENT)
  858. DRM_DEBUG("MC found buffer that isn't mine!\n");
  859. if (used > 4 * 1024)
  860. used = 0;
  861. sarea_priv->dirty = 0x7f;
  862. DRM_DEBUG("addr 0x%lx, used 0x%x\n", address, used);
  863. dev_priv->counter++;
  864. DRM_DEBUG("dispatch counter : %ld\n", dev_priv->counter);
  865. DRM_DEBUG("start : %lx\n", start);
  866. DRM_DEBUG("used : %d\n", used);
  867. DRM_DEBUG("start + used - 4 : %ld\n", start + used - 4);
  868. if (buf_priv->currently_mapped == I810_BUF_MAPPED) {
  869. if (used & 4) {
  870. *(u32 *) ((char *) buf_priv->virtual + used) = 0;
  871. used += 4;
  872. }
  873. i810_unmap_buffer(buf);
  874. }
  875. BEGIN_LP_RING(4);
  876. OUT_RING(CMD_OP_BATCH_BUFFER);
  877. OUT_RING(start | BB1_PROTECTED);
  878. OUT_RING(start + used - 4);
  879. OUT_RING(0);
  880. ADVANCE_LP_RING();
  881. BEGIN_LP_RING(8);
  882. OUT_RING(CMD_STORE_DWORD_IDX);
  883. OUT_RING(buf_priv->my_use_idx);
  884. OUT_RING(I810_BUF_FREE);
  885. OUT_RING(0);
  886. OUT_RING(CMD_STORE_DWORD_IDX);
  887. OUT_RING(16);
  888. OUT_RING(last_render);
  889. OUT_RING(0);
  890. ADVANCE_LP_RING();
  891. }
  892. static int i810_dma_mc(struct drm_device *dev, void *data,
  893. struct drm_file *file_priv)
  894. {
  895. struct drm_device_dma *dma = dev->dma;
  896. drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
  897. u32 *hw_status = dev_priv->hw_status_page;
  898. drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
  899. dev_priv->sarea_priv;
  900. drm_i810_mc_t *mc = data;
  901. LOCK_TEST_WITH_RETURN(dev, file_priv);
  902. if (mc->idx >= dma->buf_count || mc->idx < 0)
  903. return -EINVAL;
  904. i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
  905. mc->last_render);
  906. sarea_priv->last_enqueue = dev_priv->counter - 1;
  907. sarea_priv->last_dispatch = (int)hw_status[5];
  908. return 0;
  909. }
  910. static int i810_rstatus(struct drm_device *dev, void *data,
  911. struct drm_file *file_priv)
  912. {
  913. drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
  914. return (int)(((u32 *) (dev_priv->hw_status_page))[4]);
  915. }
  916. static int i810_ov0_info(struct drm_device *dev, void *data,
  917. struct drm_file *file_priv)
  918. {
  919. drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
  920. drm_i810_overlay_t *ov = data;
  921. ov->offset = dev_priv->overlay_offset;
  922. ov->physical = dev_priv->overlay_physical;
  923. return 0;
  924. }
  925. static int i810_fstatus(struct drm_device *dev, void *data,
  926. struct drm_file *file_priv)
  927. {
  928. drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
  929. LOCK_TEST_WITH_RETURN(dev, file_priv);
  930. return I810_READ(0x30008);
  931. }
  932. static int i810_ov0_flip(struct drm_device *dev, void *data,
  933. struct drm_file *file_priv)
  934. {
  935. drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
  936. LOCK_TEST_WITH_RETURN(dev, file_priv);
  937. /* Tell the overlay to update */
  938. I810_WRITE(0x30000, dev_priv->overlay_physical | 0x80000000);
  939. return 0;
  940. }
  941. /* Not sure why this isn't set all the time:
  942. */
  943. static void i810_do_init_pageflip(struct drm_device *dev)
  944. {
  945. drm_i810_private_t *dev_priv = dev->dev_private;
  946. DRM_DEBUG("\n");
  947. dev_priv->page_flipping = 1;
  948. dev_priv->current_page = 0;
  949. dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
  950. }
  951. static int i810_do_cleanup_pageflip(struct drm_device *dev)
  952. {
  953. drm_i810_private_t *dev_priv = dev->dev_private;
  954. DRM_DEBUG("\n");
  955. if (dev_priv->current_page != 0)
  956. i810_dma_dispatch_flip(dev);
  957. dev_priv->page_flipping = 0;
  958. return 0;
  959. }
  960. static int i810_flip_bufs(struct drm_device *dev, void *data,
  961. struct drm_file *file_priv)
  962. {
  963. drm_i810_private_t *dev_priv = dev->dev_private;
  964. DRM_DEBUG("\n");
  965. LOCK_TEST_WITH_RETURN(dev, file_priv);
  966. if (!dev_priv->page_flipping)
  967. i810_do_init_pageflip(dev);
  968. i810_dma_dispatch_flip(dev);
  969. return 0;
  970. }
  971. int i810_driver_load(struct drm_device *dev, unsigned long flags)
  972. {
  973. /* Our userspace depends upon the agp mapping support. */
  974. if (!dev->agp)
  975. return -EINVAL;
  976. pci_set_master(dev->pdev);
  977. return 0;
  978. }
  979. void i810_driver_lastclose(struct drm_device *dev)
  980. {
  981. i810_dma_cleanup(dev);
  982. }
  983. void i810_driver_preclose(struct drm_device *dev, struct drm_file *file_priv)
  984. {
  985. if (dev->dev_private) {
  986. drm_i810_private_t *dev_priv = dev->dev_private;
  987. if (dev_priv->page_flipping)
  988. i810_do_cleanup_pageflip(dev);
  989. }
  990. if (file_priv->master && file_priv->master->lock.hw_lock) {
  991. drm_legacy_idlelock_take(&file_priv->master->lock);
  992. i810_driver_reclaim_buffers(dev, file_priv);
  993. drm_legacy_idlelock_release(&file_priv->master->lock);
  994. } else {
  995. /* master disappeared, clean up stuff anyway and hope nothing
  996. * goes wrong */
  997. i810_driver_reclaim_buffers(dev, file_priv);
  998. }
  999. }
  1000. int i810_driver_dma_quiescent(struct drm_device *dev)
  1001. {
  1002. i810_dma_quiescent(dev);
  1003. return 0;
  1004. }
  1005. const struct drm_ioctl_desc i810_ioctls[] = {
  1006. DRM_IOCTL_DEF_DRV(I810_INIT, i810_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED),
  1007. DRM_IOCTL_DEF_DRV(I810_VERTEX, i810_dma_vertex, DRM_AUTH|DRM_UNLOCKED),
  1008. DRM_IOCTL_DEF_DRV(I810_CLEAR, i810_clear_bufs, DRM_AUTH|DRM_UNLOCKED),
  1009. DRM_IOCTL_DEF_DRV(I810_FLUSH, i810_flush_ioctl, DRM_AUTH|DRM_UNLOCKED),
  1010. DRM_IOCTL_DEF_DRV(I810_GETAGE, i810_getage, DRM_AUTH|DRM_UNLOCKED),
  1011. DRM_IOCTL_DEF_DRV(I810_GETBUF, i810_getbuf, DRM_AUTH|DRM_UNLOCKED),
  1012. DRM_IOCTL_DEF_DRV(I810_SWAP, i810_swap_bufs, DRM_AUTH|DRM_UNLOCKED),
  1013. DRM_IOCTL_DEF_DRV(I810_COPY, i810_copybuf, DRM_AUTH|DRM_UNLOCKED),
  1014. DRM_IOCTL_DEF_DRV(I810_DOCOPY, i810_docopy, DRM_AUTH|DRM_UNLOCKED),
  1015. DRM_IOCTL_DEF_DRV(I810_OV0INFO, i810_ov0_info, DRM_AUTH|DRM_UNLOCKED),
  1016. DRM_IOCTL_DEF_DRV(I810_FSTATUS, i810_fstatus, DRM_AUTH|DRM_UNLOCKED),
  1017. DRM_IOCTL_DEF_DRV(I810_OV0FLIP, i810_ov0_flip, DRM_AUTH|DRM_UNLOCKED),
  1018. DRM_IOCTL_DEF_DRV(I810_MC, i810_dma_mc, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED),
  1019. DRM_IOCTL_DEF_DRV(I810_RSTATUS, i810_rstatus, DRM_AUTH|DRM_UNLOCKED),
  1020. DRM_IOCTL_DEF_DRV(I810_FLIP, i810_flip_bufs, DRM_AUTH|DRM_UNLOCKED),
  1021. };
  1022. int i810_max_ioctl = ARRAY_SIZE(i810_ioctls);
  1023. /**
  1024. * Determine if the device really is AGP or not.
  1025. *
  1026. * All Intel graphics chipsets are treated as AGP, even if they are really
  1027. * PCI-e.
  1028. *
  1029. * \param dev The device to be tested.
  1030. *
  1031. * \returns
  1032. * A value of 1 is always retured to indictate every i810 is AGP.
  1033. */
  1034. int i810_driver_device_is_agp(struct drm_device *dev)
  1035. {
  1036. return 1;
  1037. }