1 /**************************************************************************
3 Copyright 2006 Stephane Marchesin
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 on the rights to use, copy, modify, merge, publish, distribute, sub
10 license, and/or sell copies of the Software, and to permit persons to whom
11 the Software is furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice (including the next
14 paragraph) shall be included in all copies or substantial portions of the
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
21 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
33 #include "swrast/swrast.h"
34 #include "nouveau_context.h"
35 #include "nouveau_msg.h"
36 #include "nouveau_fifo.h"
37 #include "nouveau_lock.h"
38 #include "nouveau_object.h"
39 #include "nouveau_sync.h"
41 #ifdef NOUVEAU_RING_DEBUG
42 int nouveau_fifo_remaining
=0;
48 void WAIT_RING(nouveauContextPtr nmesa
,u_int32_t size
)
50 #ifdef NOUVEAU_RING_DEBUG
54 while(nmesa
->fifo
.free
< size
+1) {
55 fifo_get
= NV_FIFO_READ_GET();
57 if(nmesa
->fifo
.put
>= fifo_get
) {
58 nmesa
->fifo
.free
= nmesa
->fifo
.max
- nmesa
->fifo
.current
;
59 if(nmesa
->fifo
.free
< size
+1) {
60 OUT_RING(NV03_FIFO_CMD_JUMP
|
61 nmesa
->fifo
.drm
.put_base
);
62 if(fifo_get
<= RING_SKIPS
) {
63 if(nmesa
->fifo
.put
<= RING_SKIPS
) /* corner case - will be idle */
64 NV_FIFO_WRITE_PUT(RING_SKIPS
+ 1);
65 do { fifo_get
= NV_FIFO_READ_GET(); }
66 while(fifo_get
<= RING_SKIPS
);
68 NV_FIFO_WRITE_PUT(RING_SKIPS
);
69 nmesa
->fifo
.current
= nmesa
->fifo
.put
= RING_SKIPS
;
70 nmesa
->fifo
.free
= fifo_get
- (RING_SKIPS
+ 1);
73 nmesa
->fifo
.free
= fifo_get
- nmesa
->fifo
.current
- 1;
78 * Wait for the channel to be idle
80 void nouveauWaitForIdleLocked(nouveauContextPtr nmesa
)
82 /* Wait for FIFO idle */
84 while(RING_AHEAD()>0);
86 /* Wait on notifier to indicate all commands in the channel have
89 nouveau_notifier_wait_nop(nmesa
->glCtx
, nmesa
->syncNotifier
, NvSub3D
);
92 void nouveauWaitForIdle(nouveauContextPtr nmesa
)
95 nouveauWaitForIdleLocked(nmesa
);
96 UNLOCK_HARDWARE(nmesa
);
99 // here we call the fifo initialization ioctl and fill in stuff accordingly
100 GLboolean
nouveauFifoInit(nouveauContextPtr nmesa
)
104 #ifdef NOUVEAU_RING_DEBUG
108 nmesa
->fifo
.drm
.fb_ctxdma_handle
= NvDmaFB
;
109 nmesa
->fifo
.drm
.tt_ctxdma_handle
= NvDmaTT
;
110 ret
= drmCommandWriteRead(nmesa
->driFd
, DRM_NOUVEAU_CHANNEL_ALLOC
,
111 &nmesa
->fifo
.drm
, sizeof(nmesa
->fifo
.drm
));
113 FATAL("Fifo initialization ioctl failed (returned %d)\n", ret
);
117 ret
= drmMap(nmesa
->driFd
, nmesa
->fifo
.drm
.cmdbuf
,
118 nmesa
->fifo
.drm
.cmdbuf_size
, &nmesa
->fifo
.pushbuf
);
120 FATAL("Unable to map the fifo (returned %d)\n", ret
);
124 ret
= drmMap(nmesa
->driFd
, nmesa
->fifo
.drm
.ctrl
,
125 nmesa
->fifo
.drm
.ctrl_size
, &nmesa
->fifo
.mmio
);
127 FATAL("Unable to map the control regs (returned %d)\n", ret
);
131 ret
= drmMap(nmesa
->driFd
, nmesa
->fifo
.drm
.notifier
,
132 nmesa
->fifo
.drm
.notifier_size
,
133 &nmesa
->fifo
.notifier_block
);
135 FATAL("Unable to map the notifier block (returned %d)\n", ret
);
139 /* Setup our initial FIFO tracking params */
140 nmesa
->fifo
.current
= 0;
142 nmesa
->fifo
.max
= (nmesa
->fifo
.drm
.cmdbuf_size
>> 2) - 1;
143 nmesa
->fifo
.free
= nmesa
->fifo
.max
- nmesa
->fifo
.current
;
145 for (i
=0; i
<RING_SKIPS
; i
++)
147 nmesa
->fifo
.free
-= RING_SKIPS
;
149 MESSAGE("Fifo init ok. Using context %d\n", nmesa
->fifo
.drm
.channel
);