ast_tool.c revision de78e416
1/*
2 * Copyright (c) 2005 ASPEED Technology Inc.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the authors not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission.  The authors makes no representations
11 * about the suitability of this software for any purpose.  It is provided
12 * "as is" without express or implied warranty.
13 *
14 * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26#include "xf86.h"
27#include "xf86_OSproc.h"
28#include "xf86Resources.h"
29#include "xf86RAC.h"
30#include "xf86cmap.h"
31#include "compiler.h"
32#include "mibstore.h"
33#include "vgaHW.h"
34#include "mipointer.h"
35#include "micmap.h"
36
37#include "fb.h"
38#include "regionstr.h"
39#include "xf86xv.h"
40#include <X11/extensions/Xv.h>
41#include "vbe.h"
42
43#include "xf86PciInfo.h"
44#include "xf86Pci.h"
45
46/* framebuffer offscreen manager */
47#include "xf86fbman.h"
48
49/* include xaa includes */
50#include "xaa.h"
51#include "xaarop.h"
52
53/* H/W cursor support */
54#include "xf86Cursor.h"
55
56/* Driver specific headers */
57#include "ast.h"
58
59/* Prototype type declaration*/
60Bool ASTMapMem(ScrnInfoPtr pScrn);
61Bool ASTUnmapMem(ScrnInfoPtr pScrn);
62Bool ASTMapMMIO(ScrnInfoPtr pScrn);
63void ASTUnmapMMIO(ScrnInfoPtr pScrn);
64
65Bool
66ASTMapMem(ScrnInfoPtr pScrn)
67{
68   ASTRecPtr pAST = ASTPTR(pScrn);
69
70#ifndef XSERVER_LIBPCIACCESS
71   pAST->FBVirtualAddr = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_FRAMEBUFFER,
72				 pAST->PciTag,
73				 pAST->FBPhysAddr, pAST->FbMapSize);
74#else
75   {
76     void** result = (void**)&pAST->FBVirtualAddr;
77     int err = pci_device_map_range(pAST->PciInfo,
78				    pAST->FBPhysAddr,
79				    pAST->FbMapSize,
80				    PCI_DEV_MAP_FLAG_WRITABLE |
81				    PCI_DEV_MAP_FLAG_WRITE_COMBINE,
82				    result);
83
84     if (err)
85			return FALSE;
86   }
87#endif
88
89   if (!pAST->FBVirtualAddr)
90      return FALSE;
91
92   return TRUE;
93}
94
95Bool
96ASTUnmapMem(ScrnInfoPtr pScrn)
97{
98   ASTRecPtr pAST = ASTPTR(pScrn);
99
100#ifndef XSERVER_LIBPCIACCESS
101   xf86UnMapVidMem(pScrn->scrnIndex, (pointer) pAST->FBVirtualAddr,
102		   pAST->FbMapSize);
103#else
104   pci_device_unmap_range(pAST->PciInfo, pAST->FBVirtualAddr, pAST->FbMapSize);
105#endif
106
107   pAST->FBVirtualAddr = 0;
108
109   return TRUE;
110}
111
112Bool
113ASTMapMMIO(ScrnInfoPtr pScrn)
114{
115   ASTRecPtr pAST = ASTPTR(pScrn);
116#ifndef XSERVER_LIBPCIACCESS
117   int mmioFlags;
118
119#if !defined(__alpha__)
120   mmioFlags = VIDMEM_MMIO | VIDMEM_READSIDEEFFECT;
121#else
122   mmioFlags = VIDMEM_MMIO | VIDMEM_READSIDEEFFECT | VIDMEM_SPARSE;
123#endif
124
125
126   pAST->MMIOVirtualAddr = xf86MapPciMem(pScrn->scrnIndex, mmioFlags,
127				         pAST->PciTag,
128				         pAST->MMIOPhysAddr, pAST->MMIOMapSize);
129
130#else
131   {
132     void** result = (void**)&pAST->MMIOVirtualAddr;
133     int err = pci_device_map_range(pAST->PciInfo,
134				    pAST->MMIOPhysAddr,
135				    pAST->MMIOMapSize,
136				    PCI_DEV_MAP_FLAG_WRITABLE,
137				    result);
138
139     if (err)
140			return FALSE;
141   }
142
143#endif
144   if (!pAST->MMIOVirtualAddr)
145      return FALSE;
146
147   return TRUE;
148}
149
150void
151ASTUnmapMMIO(ScrnInfoPtr pScrn)
152{
153   ASTRecPtr pAST = ASTPTR(pScrn);
154
155#ifndef XSERVER_LIBPCIACCESS
156   xf86UnMapVidMem(pScrn->scrnIndex, (pointer) pAST->MMIOVirtualAddr,
157		   pAST->MMIOMapSize);
158#else
159   pci_device_unmap_range(pAST->PciInfo, pAST->MMIOVirtualAddr, pAST->MMIOMapSize);
160#endif
161   pAST->MMIOVirtualAddr = 0;
162
163}
164
165
166