require libnouveau_drm 0.0.109.1
[nouveau] / src / nv_dma.c
1 /*
2  * Copyright 2007 Ben Skeggs
3  * Copyright 2007 Stephane Marchesin
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
20  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23
24 #include <errno.h>
25 #include "nv_include.h"
26 #include "nvreg.h"
27
28 void NVSync(ScrnInfoPtr pScrn)
29 {
30         NVPtr pNv = NVPTR(pScrn);
31         struct nouveau_channel *chan = pNv->chan;
32         struct nouveau_grobj *gr = pNv->Nv2D ? pNv->Nv2D : pNv->NvImageBlit;
33
34         if (pNv->NoAccel)
35                 return;
36
37         /* Wait for nvchannel to go completely idle */
38         nouveau_notifier_reset(pNv->notify0, 0);
39         BEGIN_RING(chan, gr, 0x104, 1);
40         OUT_RING  (chan, 0);
41         BEGIN_RING(chan, gr, 0x100, 1);
42         OUT_RING  (chan, 0);
43         FIRE_RING (chan);
44         if (nouveau_notifier_wait_status(pNv->notify0, 0,
45                                          NV_NOTIFY_STATE_STATUS_COMPLETED,
46                                          2.0)) {
47                 if (!pNv->LockedUp) {
48                         pNv->LockedUp = TRUE;
49                         FatalError("GPU hang\n");
50                 }
51         }
52 }
53
54 Bool
55 NVInitDma(ScrnInfoPtr pScrn)
56 {
57         NVPtr pNv = NVPTR(pScrn);
58         int ret;
59
60         ret = nouveau_channel_alloc(pNv->dev, NvDmaFB, NvDmaTT, &pNv->chan);
61         if (ret) {
62                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
63                            "Error creating GPU channel: %d\n", ret);
64                 return FALSE;
65         }
66
67         xf86DrvMsg(pScrn->scrnIndex, X_INFO,
68                    "Opened GPU channel %d\n", pNv->chan->id);
69
70         return TRUE;
71 }
72