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