11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/***************************************************************************\
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*                                                                           *|
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*       Copyright 1993-2003 NVIDIA, Corporation.  All rights reserved.      *|
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*                                                                           *|
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     NOTICE TO USER:   The source code  is copyrighted under  U.S. and     *|
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     international laws.  Users and possessors of this source code are     *|
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     hereby granted a nonexclusive,  royalty-free copyright license to     *|
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     use this code in individual and commercial software.                  *|
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*                                                                           *|
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     Any use of this source code must include,  in the user documenta-     *|
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     tion and  internal comments to the code,  notices to the end user     *|
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     as follows:                                                           *|
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*                                                                           *|
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*       Copyright 1993-1999 NVIDIA, Corporation.  All rights reserved.      *|
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*                                                                           *|
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY     *|
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     OF  THIS SOURCE  CODE  FOR ANY PURPOSE.  IT IS  PROVIDED  "AS IS"     *|
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.  NVIDIA, CORPOR-     *|
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     ATION DISCLAIMS ALL WARRANTIES  WITH REGARD  TO THIS SOURCE CODE,     *|
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE-     *|
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     MENT,  AND FITNESS  FOR A PARTICULAR PURPOSE.   IN NO EVENT SHALL     *|
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     NVIDIA, CORPORATION  BE LIABLE FOR ANY SPECIAL,  INDIRECT,  INCI-     *|
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     DENTAL, OR CONSEQUENTIAL DAMAGES,  OR ANY DAMAGES  WHATSOEVER RE-     *|
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     SULTING FROM LOSS OF USE,  DATA OR PROFITS,  WHETHER IN AN ACTION     *|
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,  ARISING OUT OF     *|
261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE.     *|
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*                                                                           *|
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     U.S. Government  End  Users.   This source code  is a "commercial     *|
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     item,"  as that  term is  defined at  48 C.F.R. 2.101 (OCT 1995),     *|
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     consisting  of "commercial  computer  software"  and  "commercial     *|
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     computer  software  documentation,"  as such  terms  are  used in     *|
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     48 C.F.R. 12.212 (SEPT 1995)  and is provided to the U.S. Govern-     *|
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     ment only as  a commercial end item.   Consistent with  48 C.F.R.     *|
341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     12.212 and  48 C.F.R. 227.7202-1 through  227.7202-4 (JUNE 1995),     *|
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     all U.S. Government End Users  acquire the source code  with only     *|
361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*     those rights set forth herein.                                        *|
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds|*                                                                           *|
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \***************************************************************************/
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * GPL Licensing Note - According to Mark Vojkovich, author of the Xorg/
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * XFree86 'nv' driver, this source code is provided under MIT-style licensing
431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * where the source code is provided "as is" without warranty of any kind.
441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The only usage restriction is for the copyright notices to be retained
451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * whenever code is used.
461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Antonino Daplas <adaplas@pol.net> 2005-03-11
481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef __NV_LOCAL_H__
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __NV_LOCAL_H__
521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This file includes any environment or machine specific values to access the
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * HW.  Put all affected includes, typdefs, etc. here so the riva_hw.* files
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * can stay generic in nature.
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * HW access macros.  These assume memory-mapped I/O, and not normal I/O space.
611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NV_WR08(p,i,d)  (__raw_writeb((d), (void __iomem *)(p) + (i)))
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NV_RD08(p,i)    (__raw_readb((void __iomem *)(p) + (i)))
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NV_WR16(p,i,d)  (__raw_writew((d), (void __iomem *)(p) + (i)))
651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NV_RD16(p,i)    (__raw_readw((void __iomem *)(p) + (i)))
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NV_WR32(p,i,d)  (__raw_writel((d), (void __iomem *)(p) + (i)))
671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NV_RD32(p,i)    (__raw_readl((void __iomem *)(p) + (i)))
681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* VGA I/O is now always done through MMIO */
701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define VGA_WR08(p,i,d) (writeb((d), (void __iomem *)(p) + (i)))
711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define VGA_RD08(p,i)   (readb((void __iomem *)(p) + (i)))
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NVDmaNext(par, data) \
741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds     NV_WR32(&(par)->dmaBase[(par)->dmaCurrent++], 0, (data))
751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
76e15de77e74d429f14641ebe7a29ccd8aa6656f3cDave Jones#define NVDmaStart(info, par, tag, size) {    \
771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds     if((par)->dmaFree <= (size))             \
78e15de77e74d429f14641ebe7a29ccd8aa6656f3cDave Jones        NVDmaWait(info, size);                \
791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds     NVDmaNext(par, ((size) << 18) | (tag));  \
801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds     (par)->dmaFree -= ((size) + 1);          \
811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if defined(__i386__)
841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define _NV_FENCE() outb(0, 0x3D0);
851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define _NV_FENCE() mb();
871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define WRITE_PUT(par, data) {                   \
901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds  _NV_FENCE()                                    \
911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds  NV_RD08((par)->FbStart, 0);                    \
921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds  NV_WR32(&(par)->FIFO[0x0010], 0, (data) << 2); \
931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds  mb();                                          \
941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define READ_GET(par) (NV_RD32(&(par)->FIFO[0x0011], 0) >> 2)
971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
987c1cd6fd5efeb95603e37f35b5da293b452d8b64Antonino A. Daplas#ifdef __LITTLE_ENDIAN
991c6676825fe4cc03a71f253fc3e16ec17c6a3195Akinobu Mita
1001c6676825fe4cc03a71f253fc3e16ec17c6a3195Akinobu Mita#include <linux/bitrev.h>
1011c6676825fe4cc03a71f253fc3e16ec17c6a3195Akinobu Mita
1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define reverse_order(l)        \
1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsdo {                            \
1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u8 *a = (u8 *)(l);      \
1051c6676825fe4cc03a71f253fc3e16ec17c6a3195Akinobu Mita	a[0] = bitrev8(a[0]);   \
1061c6676825fe4cc03a71f253fc3e16ec17c6a3195Akinobu Mita	a[1] = bitrev8(a[1]);   \
1071c6676825fe4cc03a71f253fc3e16ec17c6a3195Akinobu Mita	a[2] = bitrev8(a[2]);   \
1081c6676825fe4cc03a71f253fc3e16ec17c6a3195Akinobu Mita	a[3] = bitrev8(a[3]);   \
1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} while(0)
1107c1cd6fd5efeb95603e37f35b5da293b452d8b64Antonino A. Daplas#else
1112fe0175491c4784d95f3237ebdc985da7b26a99dAntonino A. Daplas#define reverse_order(l) do { } while(0)
1127c1cd6fd5efeb95603e37f35b5da293b452d8b64Antonino A. Daplas#endif                          /* __LITTLE_ENDIAN */
1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif				/* __NV_LOCAL_H__ */
115