ast_tool.c revision b4d38c65
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 "xf86cmap.h"
29#include "compiler.h"
30#include "mibstore.h"
31#include "vgaHW.h"
32#include "mipointer.h"
33#include "micmap.h"
34
35#include "fb.h"
36#include "regionstr.h"
37#include "xf86xv.h"
38#include <X11/extensions/Xv.h>
39#include "vbe.h"
40
41#include "xf86PciInfo.h"
42#include "xf86Pci.h"
43
44/* framebuffer offscreen manager */
45#include "xf86fbman.h"
46
47/* include xaa includes */
48#include "xaarop.h"
49
50/* H/W cursor support */
51#include "xf86Cursor.h"
52
53/* Driver specific headers */
54#include "ast.h"
55
56/* Prototype type declaration*/
57Bool ASTMapMem(ScrnInfoPtr pScrn);
58Bool ASTUnmapMem(ScrnInfoPtr pScrn);
59Bool ASTMapMMIO(ScrnInfoPtr pScrn);
60void ASTUnmapMMIO(ScrnInfoPtr pScrn);
61
62Bool
63ASTMapMem(ScrnInfoPtr pScrn)
64{
65   ASTRecPtr pAST = ASTPTR(pScrn);
66
67#ifndef XSERVER_LIBPCIACCESS
68   pAST->FBVirtualAddr = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_FRAMEBUFFER,
69				 pAST->PciTag,
70				 pAST->FBPhysAddr, pAST->FbMapSize);
71#else
72   {
73     void** result = (void**)&pAST->FBVirtualAddr;
74     int err = pci_device_map_range(pAST->PciInfo,
75				    pAST->FBPhysAddr,
76				    pAST->FbMapSize,
77				    PCI_DEV_MAP_FLAG_WRITABLE |
78				    PCI_DEV_MAP_FLAG_WRITE_COMBINE,
79				    result);
80
81     if (err)
82			return FALSE;
83   }
84#endif
85
86   if (!pAST->FBVirtualAddr)
87      return FALSE;
88
89   return TRUE;
90}
91
92Bool
93ASTUnmapMem(ScrnInfoPtr pScrn)
94{
95   ASTRecPtr pAST = ASTPTR(pScrn);
96
97#ifndef XSERVER_LIBPCIACCESS
98   xf86UnMapVidMem(pScrn->scrnIndex, (pointer) pAST->FBVirtualAddr,
99		   pAST->FbMapSize);
100#else
101   pci_device_unmap_range(pAST->PciInfo, pAST->FBVirtualAddr, pAST->FbMapSize);
102#endif
103
104   pAST->FBVirtualAddr = 0;
105
106   return TRUE;
107}
108
109Bool
110ASTMapMMIO(ScrnInfoPtr pScrn)
111{
112   ASTRecPtr pAST = ASTPTR(pScrn);
113#ifndef XSERVER_LIBPCIACCESS
114   int mmioFlags;
115
116#if !defined(__alpha__)
117   mmioFlags = VIDMEM_MMIO | VIDMEM_READSIDEEFFECT;
118#else
119   mmioFlags = VIDMEM_MMIO | VIDMEM_READSIDEEFFECT | VIDMEM_SPARSE;
120#endif
121
122
123   pAST->MMIOVirtualAddr = xf86MapPciMem(pScrn->scrnIndex, mmioFlags,
124				         pAST->PciTag,
125				         pAST->MMIOPhysAddr, pAST->MMIOMapSize);
126
127#else
128   {
129     void** result = (void**)&pAST->MMIOVirtualAddr;
130     int err = pci_device_map_range(pAST->PciInfo,
131				    pAST->MMIOPhysAddr,
132				    pAST->MMIOMapSize,
133				    PCI_DEV_MAP_FLAG_WRITABLE,
134				    result);
135
136     if (err)
137			return FALSE;
138   }
139
140#endif
141   if (!pAST->MMIOVirtualAddr)
142      return FALSE;
143
144   return TRUE;
145}
146
147void
148ASTUnmapMMIO(ScrnInfoPtr pScrn)
149{
150   ASTRecPtr pAST = ASTPTR(pScrn);
151
152#ifndef XSERVER_LIBPCIACCESS
153   xf86UnMapVidMem(pScrn->scrnIndex, (pointer) pAST->MMIOVirtualAddr,
154		   pAST->MMIOMapSize);
155#else
156   pci_device_unmap_range(pAST->PciInfo, pAST->MMIOVirtualAddr, pAST->MMIOMapSize);
157#endif
158   pAST->MMIOVirtualAddr = 0;
159
160}
161
162
163