[PATCH] powerpc: Workaround for offb on 64 bits platforms

Benjamin Herrenschmidt benh at kernel.crashing.org
Thu Nov 17 13:34:57 EST 2005


This fixes a problem with offb not parsing addresses properly on 64 bits
machines, and thus crashing at boot. The problem is worked around by
locating the matching PCI device and using the properly relocated PCI
base addresses instead of misparsing the Open Firmware properties. This
fixes a crash at boot on MAUI among others.

Signed-off-by: Benjamin Herrenschmidt <benh at kernel.crashing.org>

Index: linux-work/drivers/video/offb.c
===================================================================
--- linux-work.orig/drivers/video/offb.c	2005-11-08 11:00:19.000000000 +1100
+++ linux-work/drivers/video/offb.c	2005-11-15 16:19:14.000000000 +1100
@@ -325,8 +325,8 @@
 	int *pp, i;
 	unsigned int len;
 	int width = 640, height = 480, depth = 8, pitch;
-	unsigned *up;
-	unsigned long address;
+	unsigned int rsize, *up;
+	unsigned long address = 0;
 
 	if ((pp = (int *) get_property(dp, "depth", &len)) != NULL
 	    && len == sizeof(int))
@@ -344,10 +344,40 @@
 			pitch = 0x1000;
 	} else
 		pitch = width;
-	if ((up = (unsigned *) get_property(dp, "address", &len)) != NULL
-	    && len == sizeof(unsigned))
+
+       rsize = (unsigned long)pitch * (unsigned long)height *
+               (unsigned long)(depth / 8);
+
+       /* Try to match device to a PCI device in order to get a properly
+	* translated address rather then trying to decode the open firmware
+	* stuff in various incorrect ways
+	*/
+#ifdef CONFIG_PCI
+       /* First try to locate the PCI device if any */
+       {
+               struct pci_dev *pdev = NULL;
+
+	       for_each_pci_dev(pdev) {
+                       if (dp == pci_device_to_OF_node(pdev))
+                               break;
+	       }
+               if (pdev) {
+                       for (i = 0; i < 6 && address == 0; i++) {
+                               if ((pci_resource_flags(pdev, i) &
+				    IORESOURCE_MEM) &&
+				   (pci_resource_len(pdev, i) >= rsize))
+                                       address = pci_resource_start(pdev, i);
+                       }
+		       pci_dev_put(pdev);
+               }
+        }
+#endif /* CONFIG_PCI */
+
+	if (address == 0 &&
+	    (up = (unsigned *) get_property(dp, "address", &len)) != NULL &&
+	    len == sizeof(unsigned))
 		address = (u_long) * up;
-	else {
+	if (address == 0) {
 		for (i = 0; i < dp->n_addrs; ++i)
 			if (dp->addrs[i].size >=
 			    pitch * height * depth / 8)





More information about the Linuxppc64-dev mailing list