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