Remove some unused cruft
[nouveau] / src / nv_notifier.c
1 #include "nv_include.h"
2
3 #define NV_NOTIFIER_SIZE                                                      32
4 #define NV_NOTIFY_TIME_0                                              0x00000000
5 #define NV_NOTIFY_TIME_1                                              0x00000004
6 #define NV_NOTIFY_RETURN_VALUE                                        0x00000008
7 #define NV_NOTIFY_STATE                                               0x0000000C
8 #define NV_NOTIFY_STATE_STATUS_MASK                                   0xFF000000
9 #define NV_NOTIFY_STATE_STATUS_SHIFT                                          24
10 #define NV_NOTIFY_STATE_STATUS_COMPLETED                                    0x00
11 #define NV_NOTIFY_STATE_STATUS_IN_PROCESS                                   0x01
12 #define NV_NOTIFY_STATE_ERROR_CODE_MASK                               0x0000FFFF
13 #define NV_NOTIFY_STATE_ERROR_CODE_SHIFT                                       0
14
15 #define NOTIFIER(__v) \
16         NVPtr pNv = NVPTR(pScrn); \
17         volatile uint32_t *__v = (void*)pNv->NotifierBlock + notifier->offset
18
19 drm_nouveau_notifier_alloc_t *
20 NVNotifierAlloc(ScrnInfoPtr pScrn, uint32_t handle)
21 {
22         NVPtr pNv = NVPTR(pScrn);
23         drm_nouveau_notifier_alloc_t *notifier;
24         int ret;
25
26         notifier = xcalloc(1, sizeof(*notifier));
27         if (!notifier) {
28                 NVNotifierDestroy(pScrn, notifier);
29                 return NULL;
30         }
31
32         notifier->channel = pNv->fifo.channel;
33         notifier->handle  = handle;
34         notifier->count   = 1;
35         ret = drmCommandWriteRead(pNv->drm_fd, DRM_NOUVEAU_NOTIFIER_ALLOC,
36                                   notifier, sizeof(*notifier));
37         if (ret) {
38                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
39                            "Failed to create notifier 0x%08x: %d\n",
40                            handle, ret);
41                 NVNotifierDestroy(pScrn, notifier);
42                 return NULL;
43         }
44
45         return notifier;
46 }
47
48 void
49 NVNotifierDestroy(ScrnInfoPtr pScrn, drm_nouveau_notifier_alloc_t *notifier)
50 {
51         if (notifier) {
52                 /*XXX: destroy notifier object */
53                 xfree(notifier);
54         }
55 }
56
57 void
58 NVNotifierReset(ScrnInfoPtr pScrn, drm_nouveau_notifier_alloc_t *notifier)
59 {
60         NOTIFIER(n);
61
62         n[NV_NOTIFY_TIME_0      /4] =
63         n[NV_NOTIFY_TIME_1      /4] =
64         n[NV_NOTIFY_RETURN_VALUE/4] = 0;
65         n[NV_NOTIFY_STATE       /4] = (NV_NOTIFY_STATE_STATUS_IN_PROCESS <<
66                                        NV_NOTIFY_STATE_STATUS_SHIFT);
67 }
68
69 uint32_t
70 NVNotifierStatus(ScrnInfoPtr pScrn, drm_nouveau_notifier_alloc_t *notifier)
71 {
72         NOTIFIER(n);
73
74         return n[NV_NOTIFY_STATE/4] >> NV_NOTIFY_STATE_STATUS_SHIFT;
75 }
76
77 uint32_t
78 NVNotifierErrorCode(ScrnInfoPtr pScrn, drm_nouveau_notifier_alloc_t *notifier)
79 {
80         NOTIFIER(n);
81
82         return n[NV_NOTIFY_STATE/4] & NV_NOTIFY_STATE_ERROR_CODE_MASK;
83 }
84
85 uint32_t
86 NVNotifierReturnVal(ScrnInfoPtr pScrn, drm_nouveau_notifier_alloc_t *notifier)
87 {
88         NOTIFIER(n);
89
90         return n[NV_NOTIFY_RETURN_VALUE/4];
91 }
92
93 Bool
94 NVNotifierWaitStatus(ScrnInfoPtr pScrn, drm_nouveau_notifier_alloc_t *notifier,
95                      unsigned int status, unsigned int timeout)
96 {
97         NOTIFIER(n);
98         unsigned int t_start, time = 0;
99
100         t_start = GetTimeInMillis();
101         while (time <= timeout) {
102 #if 0
103                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
104                            "N(0x%08x)/%d = 0x%08x/0x%08x/0x%08x/0x%08x\n",
105                            notifier->handle, time, n[0], n[1], n[2], n[3]);
106 #endif
107                 if (n[NV_NOTIFY_STATE/4] & NV_NOTIFY_STATE_ERROR_CODE_MASK) {
108                         xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
109                                    "Notifier returned error: 0x%04x\n",
110                                    NVNotifierErrorCode(pScrn, notifier));
111                         return FALSE;
112                 }
113
114                 if ((n[NV_NOTIFY_STATE/4] >> NV_NOTIFY_STATE_STATUS_SHIFT)
115                                 == status)
116                         return TRUE;
117
118                 if (timeout)
119                         time = GetTimeInMillis() - t_start;
120         }
121
122         xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
123                    "Notifier (0x%08x) timeout!\n", notifier->handle);
124         return FALSE;
125 }
126