Tighten bios reg checks a little
[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 //#define NOUVEAU_MODESET_TRACE
53 #ifdef NOUVEAU_MODESET_TRACE
54 #define DDXMMIOH(f, h, r, v)    ErrorF(f, h, r, v)
55 #define DDXMMIOW(f, r, w)       (ErrorF(f, r, w), w)
56 #else
57 #define DDXMMIOH(f, h, r, v)
58 #define DDXMMIOW(f, r, w)       w
59 #endif
60
61 /*
62  * HW access macros.  These assume memory-mapped I/O, and not normal I/O space.
63  */
64 #define NV_WR08(p,i,d)  MMIO_OUT8((pointer)(p), (i), (d))
65 #define NV_RD08(p,i)    MMIO_IN8((pointer)(p), (i))
66 #define NV_WR16(p,i,d)  MMIO_OUT16((pointer)(p), (i), (d))
67 #define NV_RD16(p,i)    MMIO_IN16((pointer)(p), (i))
68 #define NV_WR32(p,i,d)  MMIO_OUT32((pointer)(p), (i), (d))
69 #define NV_RD32(p,i)    MMIO_IN32((pointer)(p), (i))
70
71 /* VGA I/O is now always done through MMIO */
72 #define VGA_WR08(p,i,d) NV_WR08(p, i, DDXMMIOW("VGA_WR08 port 0x%04x val 0x%02x\n", i, d))
73 #define VGA_RD08(p,i)   DDXMMIOW("VGA_RD08 port 0x%04x val 0x%02x\n", i, NV_RD08(p,i))
74
75 static inline int log2i(int i)
76 {
77         int r = 0;
78
79         if (i & 0xffff0000) {
80                 i >>= 16;
81                 r += 16;
82         }
83         if (i & 0x0000ff00) {
84                 i >>= 8;
85                 r += 8;
86         }
87         if (i & 0x000000f0) {
88                 i >>= 4;
89                 r += 4;
90         }
91         if (i & 0x0000000c) {
92                 i >>= 2;
93                 r += 2;
94         }
95         if (i & 0x00000002) {
96                 r += 1;
97         }
98         return r;
99 }
100
101
102
103 #endif /* __NV_LOCAL_H__ */