summaryrefslogtreecommitdiff
path: root/src/rdc_tool.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rdc_tool.c')
-rw-r--r--src/rdc_tool.c259
1 files changed, 259 insertions, 0 deletions
diff --git a/src/rdc_tool.c b/src/rdc_tool.c
new file mode 100644
index 0000000..4ba363a
--- /dev/null
+++ b/src/rdc_tool.c
@@ -0,0 +1,259 @@
+/*
+ * Copyright (C) 2009 RDC Semiconductor Co.,Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For technical support :
+ * <jason.lin@rdc.com.tw>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+
+#include "xf86.h"
+#include "xf86_OSproc.h"
+#include "xf86Resources.h"
+#include "xf86RAC.h"
+#include "xf86cmap.h"
+#include "compiler.h"
+#include "mibstore.h"
+#include "vgaHW.h"
+#include "mipointer.h"
+#include "micmap.h"
+
+#include "fb.h"
+#include "regionstr.h"
+#include "xf86xv.h"
+#include <X11/extensions/Xv.h>
+#include "vbe.h"
+
+#include "xf86PciInfo.h"
+#include "xf86Pci.h"
+
+/* framebuffer offscreen manager */
+#include "xf86fbman.h"
+
+/* include xaa includes */
+#include "xaa.h"
+#include "xaarop.h"
+
+/* H/W cursor support */
+#include "xf86Cursor.h"
+
+/* Driver specific headers */
+#include "rdc.h"
+
+/* Prototype type declaration*/
+Bool RDCMapMem(ScrnInfoPtr pScrn);
+Bool RDCUnmapMem(ScrnInfoPtr pScrn);
+Bool RDCMapMMIO(ScrnInfoPtr pScrn);
+void RDCUnmapMMIO(ScrnInfoPtr pScrn);
+Bool RDCMapVBIOS(ScrnInfoPtr pScrn);
+Bool RDCUnmapVBIOS(ScrnInfoPtr pScrn);
+
+
+// map, unmap frame buffer
+Bool
+RDCMapMem(ScrnInfoPtr pScrn)
+{
+ RDCRecPtr pRDC = RDCPTR(pScrn);
+
+#if XSERVER_LIBPCIACCESS
+ struct pci_device *const device = pRDC->PciInfo;
+ int err;
+
+ err = pci_device_map_range(device, pRDC->FBPhysAddr, pRDC->FbMapSize,
+ PCI_DEV_MAP_FLAG_WRITABLE | PCI_DEV_MAP_FLAG_WRITE_COMBINE,
+ (void **) &pRDC->FBVirtualAddr);
+
+ if (err)
+ {
+ xf86DrvMsg (pScrn->scrnIndex, X_ERROR,
+ "Unable to map frame buffer BAR. %s (%d)\n",
+ strerror (err), err);
+ return FALSE;
+ }
+#else
+ pRDC->FBVirtualAddr = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_FRAMEBUFFER,
+ pRDC->PciTag,
+ pRDC->FBPhysAddr, pRDC->FbMapSize);
+#endif
+
+ if (!pRDC->FBVirtualAddr)
+ return FALSE;
+
+ return TRUE;
+}
+
+Bool
+RDCUnmapMem(ScrnInfoPtr pScrn)
+{
+ RDCRecPtr pRDC = RDCPTR(pScrn);
+
+#if XSERVER_LIBPCIACCESS
+ pci_device_unmap_range (pRDC->PciInfo, pRDC->FBVirtualAddr, pRDC->FbMapSize);
+#else
+ xf86UnMapVidMem(pScrn->scrnIndex, (pointer) pRDC->FBVirtualAddr,
+ pRDC->FbMapSize);
+#endif
+
+ pRDC->FBVirtualAddr = 0;
+
+ return TRUE;
+}
+
+// map, ummap MMIO
+Bool
+RDCMapMMIO(ScrnInfoPtr pScrn)
+{
+ int mmioFlags;
+ RDCRecPtr pRDC = RDCPTR(pScrn);
+
+#if !defined(__alpha__)
+ mmioFlags = VIDMEM_MMIO | VIDMEM_READSIDEEFFECT;
+#else
+ mmioFlags = VIDMEM_MMIO | VIDMEM_READSIDEEFFECT | VIDMEM_SPARSE;
+#endif
+
+#if XSERVER_LIBPCIACCESS
+ struct pci_device *const device = pRDC->PciInfo;
+
+ pci_device_map_range(device, pRDC->MMIOPhysAddr, pRDC->MMIOMapSize,
+ PCI_DEV_MAP_FLAG_WRITABLE | PCI_DEV_MAP_FLAG_WRITE_COMBINE,
+ (void **) &pRDC->MMIOVirtualAddr);
+#else
+ pRDC->MMIOVirtualAddr = xf86MapPciMem(pScrn->scrnIndex, mmioFlags,
+ pRDC->PciTag,
+ pRDC->MMIOPhysAddr, pRDC->MMIOMapSize);
+#endif
+
+ if (!pRDC->MMIOVirtualAddr)
+ return FALSE;
+
+ return TRUE;
+}
+
+void
+RDCUnmapMMIO(ScrnInfoPtr pScrn)
+{
+ RDCRecPtr pRDC = RDCPTR(pScrn);
+
+#if XSERVER_LIBPCIACCESS
+ pci_device_unmap_range (pRDC->PciInfo, pRDC->MMIOVirtualAddr, pRDC->MMIOMapSize);
+#else
+ xf86UnMapVidMem(pScrn->scrnIndex, (pointer) pRDC->MMIOVirtualAddr,
+ pRDC->MMIOMapSize);
+#endif
+
+ pRDC->MMIOVirtualAddr = 0;
+
+}
+
+// map, unmap VBIOS
+Bool RDCMapVBIOS(ScrnInfoPtr pScrn)
+{
+ RDCRecPtr pRDC = RDCPTR(pScrn);
+ FILE *fpVBIOS;
+ int i;
+
+ xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, ErrorLevel, "==Enter RDCMapVBIOS()==\n");
+ pRDC->ulROMType = 0;
+
+ // Map C000
+ if (pRDC->ulROMType == 0)
+ {
+ pRDC->BIOSVirtualAddr = xf86MapVidMem(pScrn->scrnIndex, VIDMEM_READONLY, BIOS_ROM_PHY_BASE, BIOS_ROM_SIZE);
+ if (pRDC->BIOSVirtualAddr)
+ {
+ xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 0, "pRDC->BIOSVirtualAddr = 0x%08x\n", pRDC->BIOSVirtualAddr);
+ pRDC->ulROMType = 1;
+ }
+ else
+ {
+ xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, InfoLevel, "==BIOS ROM not found()==\n");
+ }
+ }
+
+ // read ROM file
+ if (pRDC->ulROMType == 0)
+ {
+ // open BIOS ROM file
+ fpVBIOS = fopen(BIOS_ROM_PATH_FILE, "r");
+ if (!fpVBIOS)
+ {
+ xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, InfoLevel, "BIOS ROM file \"/root/RDCVBIOS.ROM\" not found()==\n");
+ }
+
+ // memory allocate
+ pRDC->BIOSVirtualAddr = xnfalloc(BIOS_ROM_SIZE);
+ if (!pRDC->BIOSVirtualAddr)
+ {
+ xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, InfoLevel, "Read BIOS ROM file: Mem Allocate Fail!!==\n");
+ fclose (fpVBIOS);
+ }
+
+ // set ROM type
+ if (fpVBIOS && pRDC->BIOSVirtualAddr)
+ {
+ pRDC->ulROMType = 2;
+ for (i = 0; i < BIOS_ROM_SIZE; i++)
+ {
+ fscanf(fpVBIOS, "%c", pRDC->BIOSVirtualAddr+i);
+ }
+ fclose (fpVBIOS);
+ }
+ }
+
+ if (pRDC->ulROMType == 0)
+ {
+ xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, ErrorLevel, "==Exit1 RDCMapVBIOS()== No VBIOS\n");
+ return false; // no VBIOS and ROM file
+ }
+
+ xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, InfoLevel, "pRDC->ulROMType = %d\n", pRDC->ulROMType);
+
+ if ((*(USHORT*)pRDC->BIOSVirtualAddr == 0xAA55) && (*(USHORT*)(pRDC->BIOSVirtualAddr+0x40) == PCI_VENDOR_RDC))
+ {
+ xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, ErrorLevel, "==Exit RDCMapVBIOS()== return TRUE\n");
+ return TRUE;
+ }
+ else
+ {
+ RDCUnmapVBIOS(pScrn);
+
+ xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, ErrorLevel, "==Exit2 RDCMapVBIOS()== Not RDC VBIOS\n");
+ return false; // not RDC VGA BIOS
+ }
+}
+
+Bool RDCUnmapVBIOS(ScrnInfoPtr pScrn)
+{
+ RDCRecPtr pRDC = RDCPTR(pScrn);
+
+ if (pRDC->ulROMType == 1)
+ {
+ xf86UnMapVidMem(pScrn->scrnIndex, (pointer) pRDC->BIOSVirtualAddr, BIOS_ROM_SIZE);
+ }
+ else if (pRDC->ulROMType == 2)
+ {
+ xfree(pRDC->BIOSVirtualAddr);
+ }
+ pRDC->BIOSVirtualAddr = 0;
+
+ return TRUE;
+}
+