From 1eb330f9ef24c301a0b957743403e9191984c2bb Mon Sep 17 00:00:00 2001
From: Blue Swirl <blauwirbel@gmail.com>
Date: Sun, 27 Dec 2009 20:50:46 +0000
Subject: [PATCH] Map VGA buffer only during PCI probe

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 arch/sparc64/entry.S |    2 ++
 drivers/pci.c        |   18 ++++++++++++++----
 drivers/vga_vbe.c    |    7 +++++++
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/arch/sparc64/entry.S b/arch/sparc64/entry.S
index d3075d8..b8c144f 100644
--- a/arch/sparc64/entry.S
+++ b/arch/sparc64/entry.S
@@ -180,6 +180,7 @@ entry:
 	bne	1b
 	 add	%l2, %g5, %l2
 
+#if 0
 	! setup VGA buffer
 	setx	0x1ff004a0000, %g7, %g4
         mov     2, %g6
@@ -197,6 +198,7 @@ entry:
 	deccc	%g6
 	bne	1b
 	 nop
+#endif
 
 #if 1
 	! setup 0-16M
diff --git a/drivers/pci.c b/drivers/pci.c
index 57ad18d..dd6cfe8 100644
--- a/drivers/pci.c
+++ b/drivers/pci.c
@@ -322,6 +322,15 @@ static void pci_host_set_ranges(const pci_config_t *config)
 	set_property(dev, "ranges", (char *)props, ncells * sizeof(props[0]));
 }
 
+static unsigned long pci_bus_addr_to_host_addr(uint32_t ba)
+{
+#ifdef CONFIG_SPARC64
+    return arch->cfg_data + (unsigned long)ba;
+#else
+    return (unsigned long)ba;
+#endif
+}
+
 int host_config_cb(const pci_config_t *config)
 {
 	phandle_t aliases;
@@ -547,10 +556,11 @@ int macio_keylargo_config_cb (const pci_config_t *config)
 int vga_config_cb (const pci_config_t *config)
 {
 	if (config->assigned[0] != 0x00000000)
-		vga_vbe_init(config->path, config->assigned[0] & ~0x0000000F,
-					   config->sizes[0],
-					   config->assigned[1] & ~0x0000000F,
-					   config->sizes[1]);
+            vga_vbe_init(config->path,
+                         pci_bus_addr_to_host_addr(config->assigned[0] & ~0x0000000F),
+                         config->sizes[0],
+                         pci_bus_addr_to_host_addr(config->assigned[1] & ~0x0000000F),
+                         config->sizes[1]);
 	return 0;
 }
 
diff --git a/drivers/vga_vbe.c b/drivers/vga_vbe.c
index 9f01da0..5e9e224 100644
--- a/drivers/vga_vbe.c
+++ b/drivers/vga_vbe.c
@@ -25,6 +25,7 @@
 #include "asm/io.h"
 #include "libc/vsprintf.h"
 #include "video_subr.h"
+#include "ofmem.h"
 
 /* VGA init. We use the Bochs VESA VBE extensions  */
 #define VBE_DISPI_INDEX_ID              0x0
@@ -142,6 +143,12 @@ void vga_vbe_init(const char *path, unsigned long fb, uint32_t fb_size,
 		depth = d;
 		linebytes = (width * ((depth + 7) / 8));
 	}
+#ifdef CONFIG_SPARC64
+        extern void ofmem_map_pages(ucell phys, ucell virt, ucell size, ucell mode);
+
+        ofmem_map_pages(fb, fb, fb_size, 0x36);
+        ofmem_claim_virt(fb, fb_size, 0);
+#endif
 #endif
 
 	vga_vbe_set_mode(width, height, depth);
-- 
1.5.6.5

