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"
42 void WAIT_RING(nouveauContextPtr nmesa
,u_int32_t size
)
44 #ifdef NOUVEAU_RING_DEBUG
48 while(nmesa
->fifo
.free
< size
+1) {
49 fifo_get
= NV_FIFO_READ(NV03_FIFO_REGS_DMAGET
);
51 if(nmesa
->fifo
.put
>= fifo_get
) {
52 nmesa
->fifo
.free
= nmesa
->fifo
.max
- nmesa
->fifo
.current
;
53 if(nmesa
->fifo
.free
< size
+1) {
54 OUT_RING(NV03_FIFO_CMD_REWIND
); \
55 if(fifo_get
<= RING_SKIPS
) {
56 if(nmesa
->fifo
.put
<= RING_SKIPS
) /* corner case - will be idle */
57 NV_FIFO_WRITE(NV03_FIFO_REGS_DMAPUT
, RING_SKIPS
+ 1);
58 do { fifo_get
= NV_FIFO_READ(NV03_FIFO_REGS_DMAGET
); }
59 while(fifo_get
<= RING_SKIPS
);
61 NV_FIFO_WRITE(NV03_FIFO_REGS_DMAPUT
, RING_SKIPS
);
62 nmesa
->fifo
.current
= nmesa
->fifo
.put
= RING_SKIPS
;
63 nmesa
->fifo
.free
= fifo_get
- (RING_SKIPS
+ 1);
66 nmesa
->fifo
.free
= fifo_get
- nmesa
->fifo
.current
- 1;
71 * Wait for the card to be idle
73 void nouveauWaitForIdleLocked(nouveauContextPtr nmesa
)
78 while(RING_AHEAD()>0);
80 for(i
=0;i
<1000000;i
++) /* 1 second */
82 switch(nmesa
->screen
->card
->type
)
85 status
=NV_READ(NV03_STATUS
);
95 status
=NV_READ(NV04_STATUS
);
104 void nouveauWaitForIdle(nouveauContextPtr nmesa
)
106 LOCK_HARDWARE(nmesa
);
107 nouveauWaitForIdleLocked(nmesa
);
108 UNLOCK_HARDWARE(nmesa
);
111 // here we call the fifo initialization ioctl and fill in stuff accordingly
112 GLboolean
nouveauFifoInit(nouveauContextPtr nmesa
)
114 drm_nouveau_fifo_alloc_t fifo_init
;
117 ret
=drmCommandWriteRead(nmesa
->driFd
, DRM_NOUVEAU_FIFO_ALLOC
, &fifo_init
, sizeof(fifo_init
));
119 FATAL("Fifo initialization ioctl failed (returned %d)\n",ret
);
123 if (drmMap(nmesa
->driFd
, fifo_init
.cmdbuf
, fifo_init
.cmdbuf_size
, &nmesa
->fifo
.buffer
)) {
124 FATAL("Unable to map the fifo\n",ret
);
127 if (drmMap(nmesa
->driFd
, fifo_init
.ctrl
, fifo_init
.ctrl_size
, &nmesa
->fifo
.mmio
)) {
128 FATAL("Unable to map the control regs\n",ret
);
132 MESSAGE("Fifo init ok. Using context %d\n", fifo_init
.channel
);