From a4159ec81308fd72101bef31689934cda48f3a0d Mon Sep 17 00:00:00 2001
From: Julien Cristau <jcristau@debian.org>
Date: Thu, 3 May 2012 21:09:26 +0200
Subject: [PATCH] Use pciaccess for I/O

---
 src/vesa.c |   43 ++++++++++++++++++++-----------------------
 src/vesa.h |    2 +-
 2 files changed, 21 insertions(+), 24 deletions(-)

diff --git a/src/vesa.c b/src/vesa.c
index 23d9e14..fbbc537 100644
--- a/src/vesa.c
+++ b/src/vesa.c
@@ -1302,11 +1302,7 @@ VESAMapVidMem(ScrnInfoPtr pScrn)
     }
 #endif
 
-#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 12
-    pVesa->ioBase = pScrn->domainIOBase;
-#else
-    pVesa->ioBase = 0;
-#endif
+    pVesa->ioBase = pci_legacy_open_io(pVesa->pciInfo, 0, 0);
 
     xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, DEBUG_VERB,
 		   "virtual address = %p,\n"
@@ -1335,6 +1331,7 @@ VESAUnmapVidMem(ScrnInfoPtr pScrn)
 	(void) pci_device_unmap_legacy(pVesa->pciInfo, pVesa->base,
 	                               pVesa->mapSize);
     }
+    pci_close_io(pVesa->pciInfo, pVesa->ioBase);
 #else
     xf86UnMapVidMem(pScrn->scrnIndex, pVesa->base, pVesa->mapSize);
     if (pVesa->mapPhys != 0xa0000)
@@ -1381,51 +1378,51 @@ VESALoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
 static void
 WriteAttr(VESAPtr pVesa, int index, int value)
 {
-    (void) inb(pVesa->ioBase + VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET);
+    pci_io_read8(pVesa->ioBase, VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET);
 
     index |= 0x20;
-    outb(pVesa->ioBase + VGA_ATTR_INDEX, index);
-    outb(pVesa->ioBase + VGA_ATTR_DATA_W, value);
+    pci_io_write8(pVesa->ioBase, VGA_ATTR_INDEX, index);
+    pci_io_write8(pVesa->ioBase, VGA_ATTR_DATA_W, value);
 }
 
 static int
 ReadAttr(VESAPtr pVesa, int index)
 {
-    (void) inb(pVesa->ioBase + VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET);
+    pci_io_read8(pVesa->ioBase, VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET);
 
     index |= 0x20;
-    outb(pVesa->ioBase + VGA_ATTR_INDEX, index);
-    return (inb(pVesa->ioBase + VGA_ATTR_DATA_R));
+    pci_io_write8(pVesa->ioBase, VGA_ATTR_INDEX, index);
+    return pci_io_read8(pVesa->ioBase, VGA_ATTR_DATA_R);
 }
 
-#define WriteMiscOut(value)	outb(pVesa->ioBase + VGA_MISC_OUT_W, value)
-#define ReadMiscOut()		inb(pVesa->ioBase + VGA_MISC_OUT_R)
-#define WriteSeq(index, value)	outb(pVesa->ioBase + VGA_SEQ_INDEX, index);\
-				outb(pVesa->ioBase + VGA_SEQ_DATA, value)
+#define WriteMiscOut(value)	pci_io_write8(pVesa->ioBase, VGA_MISC_OUT_W, value)
+#define ReadMiscOut()		pci_io_read8(pVesa->ioBase, VGA_MISC_OUT_R)
+#define WriteSeq(index, value)	pci_io_write8(pVesa->ioBase, VGA_SEQ_INDEX, index);\
+				pci_io_write8(pVesa->ioBase, VGA_SEQ_DATA, value)
 
 static int
 ReadSeq(VESAPtr pVesa, int index)
 {
-    outb(pVesa->ioBase + VGA_SEQ_INDEX, index);
+    pci_io_write8(pVesa->ioBase, VGA_SEQ_INDEX, index);
 
-    return (inb(pVesa->ioBase + VGA_SEQ_DATA));
+    return pci_io_read8(pVesa->ioBase, VGA_SEQ_DATA);
 }
 
 #define WriteGr(index, value)				\
-    outb(pVesa->ioBase + VGA_GRAPH_INDEX, index);	\
-    outb(pVesa->ioBase + VGA_GRAPH_DATA, value)
+    pci_io_write8(pVesa->ioBase, VGA_GRAPH_INDEX, index);	\
+    pci_io_write8(pVesa->ioBase, VGA_GRAPH_DATA, value)
 
 static int
 ReadGr(VESAPtr pVesa, int index)
 {
-    outb(pVesa->ioBase + VGA_GRAPH_INDEX, index);
+    pci_io_write8(pVesa->ioBase, VGA_GRAPH_INDEX, index);
 
-    return (inb(pVesa->ioBase + VGA_GRAPH_DATA));
+    return pci_io_read8(pVesa->ioBase, VGA_GRAPH_DATA);
 }
 
 #define WriteCrtc(index, value)						     \
-    outb(pVesa->ioBase + (VGA_IOBASE_COLOR + VGA_CRTC_INDEX_OFFSET), index); \
-    outb(pVesa->ioBase + (VGA_IOBASE_COLOR + VGA_CRTC_DATA_OFFSET), value)
+    pci_io_write8(pVesa->ioBase, VGA_IOBASE_COLOR + VGA_CRTC_INDEX_OFFSET, index); \
+    pci_io_write8(pVesa->ioBase, VGA_IOBASE_COLOR + VGA_CRTC_DATA_OFFSET, value)
 
 static void
 SeqReset(VESAPtr pVesa, Bool start)
diff --git a/src/vesa.h b/src/vesa.h
index bcc9e37..8e434c8 100644
--- a/src/vesa.h
+++ b/src/vesa.h
@@ -114,7 +114,7 @@ typedef struct _VESARec
     xf86EnableDisableFBAccessProc *EnableDisableFBAccess;
     Bool accessEnabled;
     OptionInfoPtr Options;
-    unsigned long ioBase;
+    struct pci_io_handle *ioBase;
     Bool ModeSetClearScreen;
     void *shadow;
     ShadowUpdateProc update;
-- 
1.7.10

