From b067811d50a710a4c2abf78249cc3ed113d521cf Mon Sep 17 00:00:00 2001
Message-Id: <b067811d50a710a4c2abf78249cc3ed113d521cf.1336840066.git.blauwirbel@gmail.com>
In-Reply-To: <048481a74dc3663467e73c6bf2e2c061b0d3fb72.1336840066.git.blauwirbel@gmail.com>
References: <048481a74dc3663467e73c6bf2e2c061b0d3fb72.1336840066.git.blauwirbel@gmail.com>
From: Blue Swirl <blauwirbel@gmail.com>
Date: Sat, 12 May 2012 11:15:50 +0000
Subject: [PATCH 2/2] Sparc64: fix interrupt properties

Add interrupt-map and interrupt-mask properties to host and ebus
bridges and sprinkle interrupt properties to various devices.
Based on hacks by Artyom Tarasenko.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 drivers/ide.c          |    2 ++
 drivers/pc_serial.c    |    3 +++
 drivers/pci.c          |   38 ++++++++++++++++++++++++++++++++++++++
 drivers/pci_database.c |    2 +-
 drivers/pci_database.h |    1 +
 5 files changed, 45 insertions(+), 1 deletions(-)

diff --git a/drivers/ide.c b/drivers/ide.c
index 0d09bcd..90138ff 100644
--- a/drivers/ide.c
+++ b/drivers/ide.c
@@ -1432,6 +1432,8 @@ int ob_ide_init(const char *path, uint32_t io_port0, uint32_t ctl_port0,
 		props[0]=14; props[1]=0;
 		set_property(dnode, "interrupts",
 			     (char *)&props, 2*sizeof(props[0]));
+#elif defined(CONFIG_SPARC64)
+                set_int_property(get_cur_dev(), "interrupts", 0);
 #endif
 
 		props[0] = __cpu_to_be32(chan->io_regs[0]);
diff --git a/drivers/pc_serial.c b/drivers/pc_serial.c
index 583d1c0..5882a05 100644
--- a/drivers/pc_serial.c
+++ b/drivers/pc_serial.c
@@ -190,6 +190,9 @@ ob_pc_serial_init(const char *path, const char *dev_name, uint64_t base,
     fword("encode+");
     push_str("reg");
     fword("property");
+#if defined(CONFIG_SPARC64)
+    set_int_property(get_cur_dev(), "interrupts", 1);
+#endif
 
     aliases = find_dev("/aliases");
     set_property(aliases, "ttya", nodebuff, strlen(nodebuff) + 1);
diff --git a/drivers/pci.c b/drivers/pci.c
index e270a73..d6c5e51 100644
--- a/drivers/pci.c
+++ b/drivers/pci.c
@@ -401,6 +401,21 @@ static void pci_host_set_interrupt_map(const pci_config_t *config)
 	props[PCI_INT_MAP_PCI_INT] = 0x7;
 
 	set_property(dev, "interrupt-map-mask", (char *)props, 4 * sizeof(props[0]));
+#elif defined(CONFIG_SPARC64)
+	phandle_t dev = get_cur_dev();
+	uint32_t props[5];
+
+	props[0] = 0x000001fe;
+	props[1] = 0x020003f8;
+	props[2] = 1;
+	props[3] = find_dev("/");
+	props[4] = 0x2b;
+	set_property(dev, "interrupt-map", (char *)props, 5 * sizeof(props[0]));
+
+	props[0] = 0x000001ff;
+	props[1] = 0xffffffff;
+	props[2] = 3;
+	set_property(dev, "interrupt-map-mask", (char *)props, 3 * sizeof(props[0]));
 #endif
 }
 
@@ -522,6 +537,14 @@ int bridge_config_cb(const pci_config_t *config)
 	return 0;
 }
 
+int virtio_config_cb(const pci_config_t *config)
+{
+#if defined(CONFIG_SPARC64)
+    set_int_property(get_cur_dev(), "interrupts", 0);
+#endif
+    return 0;
+}
+
 int ide_config_cb2 (const pci_config_t *config)
 {
 	ob_ide_init(config->path,
@@ -756,6 +779,21 @@ int vga_config_cb (const pci_config_t *config)
 int ebus_config_cb(const pci_config_t *config)
 {
 #ifdef CONFIG_DRIVER_EBUS
+    phandle_t dev = get_cur_dev();
+    uint32_t props[5];
+
+    props[0] = 0x000001fe;
+    props[1] = 0x020003f8;
+    props[2] = 1;
+    props[3] = find_dev("/");
+    props[4] = 0x2b;
+    set_property(dev, "interrupt-map", (char *)props, 5 * sizeof(props[0]));
+
+    props[0] = 0x000001ff;
+    props[1] = 0xffffffff;
+    props[2] = 3;
+    set_property(dev, "interrupt-map-mask", (char *)props, 3 * sizeof(props[0]));
+
 #ifdef CONFIG_DRIVER_FLOPPY
     ob_floppy_init(config->path, "fdthree", 0x3f0ULL, 0);
 #endif
diff --git a/drivers/pci_database.c b/drivers/pci_database.c
index 7d420c3..1d2958c 100644
--- a/drivers/pci_database.c
+++ b/drivers/pci_database.c
@@ -52,7 +52,7 @@ static const pci_dev_t scsi_devices[] = {
         NULL, "virtio-scsi", NULL,
         "pci1af4,1001\0pci1af4,1001\0pciclass,01018f\0",
         0, 0, 0,
-        NULL, NULL,
+        virtio_config_cb, NULL,
     },
     {
         0xFFFF, 0xFFFF,
diff --git a/drivers/pci_database.h b/drivers/pci_database.h
index 5ddbb20..5459032 100644
--- a/drivers/pci_database.h
+++ b/drivers/pci_database.h
@@ -28,6 +28,7 @@ struct pci_dev_t {
     const void *private;
 };
 
+extern int virtio_config_cb(const pci_config_t *config);
 extern int ide_config_cb2(const pci_config_t *config);
 extern int eth_config_cb(const pci_config_t *config);
 extern int macio_heathrow_config_cb(const pci_config_t *config);
-- 
1.7.2.5

