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"
44 void WAIT_RING(nouveauContextPtr nmesa
,u_int32_t size
)
46 #ifdef NOUVEAU_RING_DEBUG
50 while(nmesa
->fifo
.free
< size
+1) {
51 fifo_get
= NV_FIFO_READ_GET();
53 if(nmesa
->fifo
.put
>= fifo_get
) {
54 nmesa
->fifo
.free
= nmesa
->fifo
.max
- nmesa
->fifo
.current
;
55 if(nmesa
->fifo
.free
< size
+1) {
56 OUT_RING(NV03_FIFO_CMD_JUMP
| nmesa
->fifo
.put_base
);
57 if(fifo_get
<= RING_SKIPS
) {
58 if(nmesa
->fifo
.put
<= RING_SKIPS
) /* corner case - will be idle */
59 NV_FIFO_WRITE_PUT(RING_SKIPS
+ 1);
60 do { fifo_get
= NV_FIFO_READ_GET(); }
61 while(fifo_get
<= RING_SKIPS
);
63 NV_FIFO_WRITE_PUT(RING_SKIPS
);
64 nmesa
->fifo
.current
= nmesa
->fifo
.put
= RING_SKIPS
;
65 nmesa
->fifo
.free
= fifo_get
- (RING_SKIPS
+ 1);
68 nmesa
->fifo
.free
= fifo_get
- nmesa
->fifo
.current
- 1;
73 * Wait for the channel to be idle
75 void nouveauWaitForIdleLocked(nouveauContextPtr nmesa
)
77 /* Wait for FIFO idle */
79 while(RING_AHEAD()>0);
81 /* Wait on notifier to indicate all commands in the channel have
84 nouveau_notifier_wait_nop(nmesa
->glCtx
, nmesa
->syncNotifier
, NvSub3D
);
87 void nouveauWaitForIdle(nouveauContextPtr nmesa
)
90 nouveauWaitForIdleLocked(nmesa
);
91 UNLOCK_HARDWARE(nmesa
);
94 // here we call the fifo initialization ioctl and fill in stuff accordingly
95 GLboolean
nouveauFifoInit(nouveauContextPtr nmesa
)
97 drm_nouveau_fifo_alloc_t fifo_init
;
100 #ifdef NOUVEAU_RING_DEBUG
105 ret
=drmCommandWriteRead(nmesa
->driFd
, DRM_NOUVEAU_FIFO_ALLOC
, &fifo_init
, sizeof(fifo_init
));
107 FATAL("Fifo initialization ioctl failed (returned %d)\n",ret
);
111 ret
= drmMap(nmesa
->driFd
, fifo_init
.cmdbuf
, fifo_init
.cmdbuf_size
, &nmesa
->fifo
.buffer
);
113 FATAL("Unable to map the fifo (returned %d)\n",ret
);
116 ret
= drmMap(nmesa
->driFd
, fifo_init
.ctrl
, fifo_init
.ctrl_size
, &nmesa
->fifo
.mmio
);
118 FATAL("Unable to map the control regs (returned %d)\n",ret
);
122 /* Setup our initial FIFO tracking params */
123 nmesa
->fifo
.put_base
= fifo_init
.put_base
;
124 nmesa
->fifo
.current
= 0;
126 nmesa
->fifo
.max
= (fifo_init
.cmdbuf_size
>> 2) - 1;
127 nmesa
->fifo
.free
= nmesa
->fifo
.max
- nmesa
->fifo
.current
;
129 for (i
=0; i
<RING_SKIPS
; i
++)
131 nmesa
->fifo
.free
-= RING_SKIPS
;
133 MESSAGE("Fifo init ok. Using context %d\n", fifo_init
.channel
);