randr12: Some misc changes.
[nouveau] / src / nv_local.h
1  /***************************************************************************\
2 |*                                                                           *|
3 |*       Copyright 1993-2003 NVIDIA, Corporation.  All rights reserved.      *|
4 |*                                                                           *|
5 |*     NOTICE TO USER:   The source code  is copyrighted under  U.S. and     *|
6 |*     international laws.  Users and possessors of this source code are     *|
7 |*     hereby granted a nonexclusive,  royalty-free copyright license to     *|
8 |*     use this code in individual and commercial software.                  *|
9 |*                                                                           *|
10 |*     Any use of this source code must include,  in the user documenta-     *|
11 |*     tion and  internal comments to the code,  notices to the end user     *|
12 |*     as follows:                                                           *|
13 |*                                                                           *|
14 |*       Copyright 1993-1999 NVIDIA, Corporation.  All rights reserved.      *|
15 |*                                                                           *|
16 |*     NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY     *|
17 |*     OF  THIS SOURCE  CODE  FOR ANY PURPOSE.  IT IS  PROVIDED  "AS IS"     *|
18 |*     WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.  NVIDIA, CORPOR-     *|
19 |*     ATION DISCLAIMS ALL WARRANTIES  WITH REGARD  TO THIS SOURCE CODE,     *|
20 |*     INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE-     *|
21 |*     MENT,  AND FITNESS  FOR A PARTICULAR PURPOSE.   IN NO EVENT SHALL     *|
22 |*     NVIDIA, CORPORATION  BE LIABLE FOR ANY SPECIAL,  INDIRECT,  INCI-     *|
23 |*     DENTAL, OR CONSEQUENTIAL DAMAGES,  OR ANY DAMAGES  WHATSOEVER RE-     *|
24 |*     SULTING FROM LOSS OF USE,  DATA OR PROFITS,  WHETHER IN AN ACTION     *|
25 |*     OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,  ARISING OUT OF     *|
26 |*     OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE.     *|
27 |*                                                                           *|
28 |*     U.S. Government  End  Users.   This source code  is a "commercial     *|
29 |*     item,"  as that  term is  defined at  48 C.F.R. 2.101 (OCT 1995),     *|
30 |*     consisting  of "commercial  computer  software"  and  "commercial     *|
31 |*     computer  software  documentation,"  as such  terms  are  used in     *|
32 |*     48 C.F.R. 12.212 (SEPT 1995)  and is provided to the U.S. Govern-     *|
33 |*     ment only as  a commercial end item.   Consistent with  48 C.F.R.     *|
34 |*     12.212 and  48 C.F.R. 227.7202-1 through  227.7202-4 (JUNE 1995),     *|
35 |*     all U.S. Government End Users  acquire the source code  with only     *|
36 |*     those rights set forth herein.                                        *|
37 |*                                                                           *|
38  \***************************************************************************/
39 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/nv_local.h,v 1.8tsi Exp $ */
40
41 #ifndef __NV_LOCAL_H__
42 #define __NV_LOCAL_H__
43
44 /*
45  * This file includes any environment or machine specific values to access the
46  * HW.  Put all affected includes, typdefs, etc. here so the riva_hw.* files
47  * can stay generic in nature.
48  */ 
49 #include "compiler.h"
50 #include "xf86_OSproc.h"
51
52 /*
53  * HW access macros.  These assume memory-mapped I/O, and not normal I/O space.
54  */
55 #define NV_WR08(p,i,d)  MMIO_OUT8((pointer)(p), (i), (d))
56 #define NV_RD08(p,i)    MMIO_IN8((pointer)(p), (i))
57 #define NV_WR16(p,i,d)  MMIO_OUT16((pointer)(p), (i), (d))
58 #define NV_RD16(p,i)    MMIO_IN16((pointer)(p), (i))
59 #define NV_WR32(p,i,d)  MMIO_OUT32((pointer)(p), (i), (d))
60 #define NV_RD32(p,i)    MMIO_IN32((pointer)(p), (i))
61
62 /* VGA I/O is now always done through MMIO */
63 #define VGA_WR08(p,i,d) NV_WR08(p,i,d)
64 #define VGA_RD08(p,i)   NV_RD08(p,i)
65
66 #if defined(__i386__)
67 #define _NV_FENCE() outb(0x3D0, 0);
68 #else
69 #define _NV_FENCE() mem_barrier();
70 #endif
71
72
73 #define READ_GET(pNv) (((pNv)->FIFO[0x0011] - pNv->fifo.put_base) >> 2)
74 #if NV_DMA_DEBUG == 1
75 #define WRITE_PUT(pNv, data) {       \
76   volatile CARD8 scratch;            \
77   _NV_FENCE()                        \
78   scratch = ((char*)(pNv)->FB->map)[0];       \
79   (pNv)->FIFO[0x0010] = ((data) << 2) + pNv->fifo.put_base; \
80         xf86DrvMsg(0, X_INFO, "WRITE_PUT: 0x%08x\n", ((data) << 2) + pNv->fifo.put_base); \
81   mem_barrier();                     \
82 }
83 #else
84 #define WRITE_PUT(pNv, data) {       \
85   volatile CARD8 scratch;            \
86   _NV_FENCE()                        \
87   scratch = ((char*)(pNv)->FB->map)[0];       \
88   (pNv)->FIFO[0x0010] = ((data) << 2) + pNv->fifo.put_base; \
89   mem_barrier();                     \
90 }
91 #endif
92
93
94 static inline int log2i(int i)
95 {
96         int r = 0;
97
98         if (i & 0xffff0000) {
99                 i >>= 16;
100                 r += 16;
101         }
102         if (i & 0x0000ff00) {
103                 i >>= 8;
104                 r += 8;
105         }
106         if (i & 0x000000f0) {
107                 i >>= 4;
108                 r += 4;
109         }
110         if (i & 0x0000000c) {
111                 i >>= 2;
112                 r += 2;
113         }
114         if (i & 0x00000002) {
115                 r += 1;
116         }
117         return r;
118 }
119
120
121
122 #endif /* __NV_LOCAL_H__ */