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