1 #include "nv_include.h"
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
15 #define NOTIFIER(__v) \
16 NVPtr pNv = NVPTR(pScrn); \
17 volatile uint32_t *__v = (void*)pNv->NotifierBlock + notifier->offset
19 drm_nouveau_notifier_alloc_t *
20 NVNotifierAlloc(ScrnInfoPtr pScrn, uint32_t handle)
22 NVPtr pNv = NVPTR(pScrn);
23 drm_nouveau_notifier_alloc_t *notifier;
26 notifier = xcalloc(1, sizeof(*notifier));
28 NVNotifierDestroy(pScrn, notifier);
32 notifier->channel = pNv->fifo.channel;
33 notifier->handle = handle;
35 ret = drmCommandWriteRead(pNv->drm_fd, DRM_NOUVEAU_NOTIFIER_ALLOC,
36 notifier, sizeof(*notifier));
38 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
39 "Failed to create notifier 0x%08x: %d\n",
41 NVNotifierDestroy(pScrn, notifier);
49 NVNotifierDestroy(ScrnInfoPtr pScrn, drm_nouveau_notifier_alloc_t *notifier)
52 /*XXX: destroy notifier object */
58 NVNotifierReset(ScrnInfoPtr pScrn, drm_nouveau_notifier_alloc_t *notifier)
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);
70 NVNotifierStatus(ScrnInfoPtr pScrn, drm_nouveau_notifier_alloc_t *notifier)
74 return n[NV_NOTIFY_STATE/4] >> NV_NOTIFY_STATE_STATUS_SHIFT;
78 NVNotifierErrorCode(ScrnInfoPtr pScrn, drm_nouveau_notifier_alloc_t *notifier)
82 return n[NV_NOTIFY_STATE/4] & NV_NOTIFY_STATE_ERROR_CODE_MASK;
86 NVNotifierReturnVal(ScrnInfoPtr pScrn, drm_nouveau_notifier_alloc_t *notifier)
90 return n[NV_NOTIFY_RETURN_VALUE/4];
94 NVNotifierWaitStatus(ScrnInfoPtr pScrn, drm_nouveau_notifier_alloc_t *notifier,
95 unsigned int status, unsigned int timeout)
98 unsigned int t_start, time = 0;
100 t_start = GetTimeInMillis();
101 while (time <= timeout) {
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]);
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));
114 if ((n[NV_NOTIFY_STATE/4] >> NV_NOTIFY_STATE_STATUS_SHIFT)
119 time = GetTimeInMillis() - t_start;
122 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
123 "Notifier (0x%08x) timeout!\n", notifier->handle);