[PATCH] vgahw: Assert that IOBase is set and in sync with hardware

Egbert Eich eich at freedesktop.org
Tue Aug 13 12:52:34 PDT 2013


When NDEBUG is not defined, assert that the IOBase is set
correctly and is in sync MiscOut register bit 1.
This is to catch issues in drivers.

Signed-off-by: Egbert Eich <eich at freedesktop.org>
---
 hw/xfree86/vgahw/vgaHW.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/hw/xfree86/vgahw/vgaHW.c b/hw/xfree86/vgahw/vgaHW.c
index a64f4f8..947d242 100644
--- a/hw/xfree86/vgahw/vgaHW.c
+++ b/hw/xfree86/vgahw/vgaHW.c
@@ -565,6 +565,28 @@ vgaHWSetMmioFuncs(vgaHWPtr hwp, CARD8 *base, int offset)
     hwp->writeEnable = mmioWriteEnable;
 }
 
+static
+void vgaHWAssertIOBase(vgaHWPtr hwp)
+{
+#ifndef NDEBUG
+    int scrnIndex = hwp->pScrn->scrnIndex;
+    switch (hwp->IOBase) {
+    case VGA_IOBASE_COLOR:
+        if ((hwp->readMiscOut(hwp) & 0x01) == 0)
+            xf86DrvMsg(scrnIndex, X_ERROR,
+                       "VGA IOBase set to COLOR but hardware set to MONO\n");
+        break;
+    case VGA_IOBASE_MONO:
+        if ((hwp->readMiscOut(hwp) & 0x01))
+            xf86DrvMsg(scrnIndex, X_ERROR,
+                       "VGA IOBase set to MONO but hardware set to COLOR\n");
+        break;
+    default:
+        xf86DrvMsg(scrnIndex, X_ERROR, "VGA IOBase not initialized\n");
+    }
+#endif
+}
+
 /*
  * vgaHWProtect --
  *	Protect VGA registers and memory from corruption during loads.
@@ -578,6 +600,9 @@ vgaHWProtect(ScrnInfoPtr pScrn, Bool on)
     unsigned char tmp;
 
     if (pScrn->vtSema) {
+
+        vgaHWAssertIOBase(hwp);
+
         if (on) {
             /*
              * Turn off screen and disable sequencer.
@@ -683,6 +708,8 @@ vgaHWDPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
     if (!pScrn->vtSema)
         return;
 
+    vgaHWAssertIOBase(hwp);
+
     switch (PowerManagementMode) {
     case DPMSModeOn:
         /* Screen: On; HSync: On, VSync: On */
@@ -878,6 +905,7 @@ vgaHWRestoreColormap(ScrnInfoPtr scrninfp, vgaRegPtr restore)
     vgaHWPtr hwp = VGAHWPTR(scrninfp);
     int i;
 
+    vgaHWAssertIOBase(hwp);
 #if 0
     hwp->enablePalette(hwp);
 #endif
@@ -1054,6 +1082,8 @@ vgaHWSaveColormap(ScrnInfoPtr scrninfp, vgaRegPtr save)
     Bool readError = FALSE;
     int i;
 
+    vgaHWAssertIOBase(hwp);
+
 #ifdef NEED_SAVED_CMAP
     /*
      * Some ET4000 chips from 1991 have a HW bug that prevents the reading
@@ -1826,6 +1856,8 @@ vgaHWLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, LOCO * colors,
     vgaHWPtr hwp = VGAHWPTR(pScrn);
     int i, index;
 
+    vgaHWAssertIOBase(hwp);
+
     for (i = 0; i < numColors; i++) {
         index = indices[i];
         hwp->writeDacWriteAddr(hwp, index);
@@ -1847,6 +1879,8 @@ vgaHWSetOverscan(ScrnInfoPtr pScrn, int overscan)
 {
     vgaHWPtr hwp = VGAHWPTR(pScrn);
 
+    vgaHWAssertIOBase(hwp);
+
     if (overscan < 0 || overscan > 255)
         return;
 
@@ -1920,6 +1954,8 @@ vgaHWddc1SetSpeed(ScrnInfoPtr pScrn, xf86ddcSpeed speed)
     unsigned char tmp;
     struct _vgaDdcSave *save;
 
+    vgaHWAssertIOBase(hwp);
+
     switch (speed) {
     case DDC_FAST:
 
-- 
1.8.1.4



More information about the xorg-devel mailing list