xref: /OK3568_Linux_fs/kernel/drivers/video/fbdev/nvidia/nv_local.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /***************************************************************************\
2*4882a593Smuzhiyun |*                                                                           *|
3*4882a593Smuzhiyun |*       Copyright 1993-2003 NVIDIA, Corporation.  All rights reserved.      *|
4*4882a593Smuzhiyun |*                                                                           *|
5*4882a593Smuzhiyun |*     NOTICE TO USER:   The source code  is copyrighted under  U.S. and     *|
6*4882a593Smuzhiyun |*     international laws.  Users and possessors of this source code are     *|
7*4882a593Smuzhiyun |*     hereby granted a nonexclusive,  royalty-free copyright license to     *|
8*4882a593Smuzhiyun |*     use this code in individual and commercial software.                  *|
9*4882a593Smuzhiyun |*                                                                           *|
10*4882a593Smuzhiyun |*     Any use of this source code must include,  in the user documenta-     *|
11*4882a593Smuzhiyun |*     tion and  internal comments to the code,  notices to the end user     *|
12*4882a593Smuzhiyun |*     as follows:                                                           *|
13*4882a593Smuzhiyun |*                                                                           *|
14*4882a593Smuzhiyun |*       Copyright 1993-1999 NVIDIA, Corporation.  All rights reserved.      *|
15*4882a593Smuzhiyun |*                                                                           *|
16*4882a593Smuzhiyun |*     NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY     *|
17*4882a593Smuzhiyun |*     OF  THIS SOURCE  CODE  FOR ANY PURPOSE.  IT IS  PROVIDED  "AS IS"     *|
18*4882a593Smuzhiyun |*     WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.  NVIDIA, CORPOR-     *|
19*4882a593Smuzhiyun |*     ATION DISCLAIMS ALL WARRANTIES  WITH REGARD  TO THIS SOURCE CODE,     *|
20*4882a593Smuzhiyun |*     INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE-     *|
21*4882a593Smuzhiyun |*     MENT,  AND FITNESS  FOR A PARTICULAR PURPOSE.   IN NO EVENT SHALL     *|
22*4882a593Smuzhiyun |*     NVIDIA, CORPORATION  BE LIABLE FOR ANY SPECIAL,  INDIRECT,  INCI-     *|
23*4882a593Smuzhiyun |*     DENTAL, OR CONSEQUENTIAL DAMAGES,  OR ANY DAMAGES  WHATSOEVER RE-     *|
24*4882a593Smuzhiyun |*     SULTING FROM LOSS OF USE,  DATA OR PROFITS,  WHETHER IN AN ACTION     *|
25*4882a593Smuzhiyun |*     OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,  ARISING OUT OF     *|
26*4882a593Smuzhiyun |*     OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE.     *|
27*4882a593Smuzhiyun |*                                                                           *|
28*4882a593Smuzhiyun |*     U.S. Government  End  Users.   This source code  is a "commercial     *|
29*4882a593Smuzhiyun |*     item,"  as that  term is  defined at  48 C.F.R. 2.101 (OCT 1995),     *|
30*4882a593Smuzhiyun |*     consisting  of "commercial  computer  software"  and  "commercial     *|
31*4882a593Smuzhiyun |*     computer  software  documentation,"  as such  terms  are  used in     *|
32*4882a593Smuzhiyun |*     48 C.F.R. 12.212 (SEPT 1995)  and is provided to the U.S. Govern-     *|
33*4882a593Smuzhiyun |*     ment only as  a commercial end item.   Consistent with  48 C.F.R.     *|
34*4882a593Smuzhiyun |*     12.212 and  48 C.F.R. 227.7202-1 through  227.7202-4 (JUNE 1995),     *|
35*4882a593Smuzhiyun |*     all U.S. Government End Users  acquire the source code  with only     *|
36*4882a593Smuzhiyun |*     those rights set forth herein.                                        *|
37*4882a593Smuzhiyun |*                                                                           *|
38*4882a593Smuzhiyun  \***************************************************************************/
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /*
41*4882a593Smuzhiyun  * GPL Licensing Note - According to Mark Vojkovich, author of the Xorg/
42*4882a593Smuzhiyun  * XFree86 'nv' driver, this source code is provided under MIT-style licensing
43*4882a593Smuzhiyun  * where the source code is provided "as is" without warranty of any kind.
44*4882a593Smuzhiyun  * The only usage restriction is for the copyright notices to be retained
45*4882a593Smuzhiyun  * whenever code is used.
46*4882a593Smuzhiyun  *
47*4882a593Smuzhiyun  * Antonino Daplas <adaplas@pol.net> 2005-03-11
48*4882a593Smuzhiyun  */
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun #ifndef __NV_LOCAL_H__
51*4882a593Smuzhiyun #define __NV_LOCAL_H__
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun /*
54*4882a593Smuzhiyun  * This file includes any environment or machine specific values to access the
55*4882a593Smuzhiyun  * HW.  Put all affected includes, typdefs, etc. here so the riva_hw.* files
56*4882a593Smuzhiyun  * can stay generic in nature.
57*4882a593Smuzhiyun  */
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun /*
60*4882a593Smuzhiyun  * HW access macros.  These assume memory-mapped I/O, and not normal I/O space.
61*4882a593Smuzhiyun  */
62*4882a593Smuzhiyun #define NV_WR08(p,i,d)  (__raw_writeb((d), (void __iomem *)(p) + (i)))
63*4882a593Smuzhiyun #define NV_RD08(p,i)    (__raw_readb((void __iomem *)(p) + (i)))
64*4882a593Smuzhiyun #define NV_WR16(p,i,d)  (__raw_writew((d), (void __iomem *)(p) + (i)))
65*4882a593Smuzhiyun #define NV_RD16(p,i)    (__raw_readw((void __iomem *)(p) + (i)))
66*4882a593Smuzhiyun #define NV_WR32(p,i,d)  (__raw_writel((d), (void __iomem *)(p) + (i)))
67*4882a593Smuzhiyun #define NV_RD32(p,i)    (__raw_readl((void __iomem *)(p) + (i)))
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /* VGA I/O is now always done through MMIO */
70*4882a593Smuzhiyun #define VGA_WR08(p,i,d) (writeb((d), (void __iomem *)(p) + (i)))
71*4882a593Smuzhiyun #define VGA_RD08(p,i)   (readb((void __iomem *)(p) + (i)))
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun #define NVDmaNext(par, data) \
74*4882a593Smuzhiyun      NV_WR32(&(par)->dmaBase[(par)->dmaCurrent++], 0, (data))
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun #define NVDmaStart(info, par, tag, size) {    \
77*4882a593Smuzhiyun      if((par)->dmaFree <= (size))             \
78*4882a593Smuzhiyun         NVDmaWait(info, size);                \
79*4882a593Smuzhiyun      NVDmaNext(par, ((size) << 18) | (tag));  \
80*4882a593Smuzhiyun      (par)->dmaFree -= ((size) + 1);          \
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun #if defined(__i386__)
84*4882a593Smuzhiyun #define _NV_FENCE() outb(0, 0x3D0);
85*4882a593Smuzhiyun #else
86*4882a593Smuzhiyun #define _NV_FENCE() mb();
87*4882a593Smuzhiyun #endif
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun #define WRITE_PUT(par, data) {                   \
90*4882a593Smuzhiyun   _NV_FENCE()                                    \
91*4882a593Smuzhiyun   NV_RD08((par)->FbStart, 0);                    \
92*4882a593Smuzhiyun   NV_WR32(&(par)->FIFO[0x0010], 0, (data) << 2); \
93*4882a593Smuzhiyun   mb();                                          \
94*4882a593Smuzhiyun }
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun #define READ_GET(par) (NV_RD32(&(par)->FIFO[0x0011], 0) >> 2)
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun #ifdef __LITTLE_ENDIAN
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun #include <linux/bitrev.h>
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun #define reverse_order(l)        \
103*4882a593Smuzhiyun do {                            \
104*4882a593Smuzhiyun 	u8 *a = (u8 *)(l);      \
105*4882a593Smuzhiyun 	a[0] = bitrev8(a[0]);   \
106*4882a593Smuzhiyun 	a[1] = bitrev8(a[1]);   \
107*4882a593Smuzhiyun 	a[2] = bitrev8(a[2]);   \
108*4882a593Smuzhiyun 	a[3] = bitrev8(a[3]);   \
109*4882a593Smuzhiyun } while(0)
110*4882a593Smuzhiyun #else
111*4882a593Smuzhiyun #define reverse_order(l) do { } while(0)
112*4882a593Smuzhiyun #endif                          /* __LITTLE_ENDIAN */
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun #endif				/* __NV_LOCAL_H__ */
115