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