Blame SOURCES/0303-Allow-IEEE1275-ports-on-path-even-if-it-wasn-t-detec.patch

f96e0b
From 260a00f345f2d355b151d6a7c1f2018cfad8c0fc Mon Sep 17 00:00:00 2001
f96e0b
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
f96e0b
Date: Sun, 14 Apr 2013 17:01:31 +0200
f96e0b
Subject: [PATCH 303/482] 	Allow IEEE1275 ports on path even if it wasn't
f96e0b
 detected automatically. 	Needed on OpenBIOS due to incomplete device
f96e0b
 tree.
f96e0b
f96e0b
---
f96e0b
 ChangeLog                        |  5 +++
f96e0b
 grub-core/term/ieee1275/serial.c | 78 ++++++++++++++++++++++++++--------------
f96e0b
 grub-core/term/serial.c          | 16 +++++++++
f96e0b
 include/grub/ieee1275/console.h  |  3 ++
f96e0b
 4 files changed, 76 insertions(+), 26 deletions(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index 1088061..df9e300 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,5 +1,10 @@
f96e0b
 2013-04-14  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
+	Allow IEEE1275 ports on path even if it wasn't detected automatically.
f96e0b
+	Needed on OpenBIOS due to incomplete device tree.
f96e0b
+
f96e0b
+2013-04-14  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
+
f96e0b
 	* grub-core/disk/ieee1275/ofdisk.c: Iterate over bootpath even if it
f96e0b
 	would be otherwise excluded.
f96e0b
 
f96e0b
diff --git a/grub-core/term/ieee1275/serial.c b/grub-core/term/ieee1275/serial.c
f96e0b
index cda97d0..9e71ca4 100644
f96e0b
--- a/grub-core/term/ieee1275/serial.c
f96e0b
+++ b/grub-core/term/ieee1275/serial.c
f96e0b
@@ -23,6 +23,7 @@
f96e0b
 #include <grub/mm.h>
f96e0b
 #include <grub/time.h>
f96e0b
 #include <grub/i18n.h>
f96e0b
+#include <grub/ieee1275/console.h>
f96e0b
 
f96e0b
 #define IEEE1275_IHANDLE_INVALID  ((grub_ieee1275_cell_t) 0)
f96e0b
 
f96e0b
@@ -216,11 +217,59 @@ dev_iterate (struct grub_ieee1275_devalias *alias)
f96e0b
   return 0;
f96e0b
 }
f96e0b
 
f96e0b
+static const char *
f96e0b
+add_port (struct ofserial_hash_ent *ent)
f96e0b
+{
f96e0b
+  struct grub_serial_port *port;
f96e0b
+  char *ptr;
f96e0b
+  grub_err_t err;
f96e0b
+
f96e0b
+  if (!ent->shortest)
f96e0b
+    return NULL;
f96e0b
+
f96e0b
+  port = grub_zalloc (sizeof (*port));
f96e0b
+  if (!port)
f96e0b
+    return NULL;
f96e0b
+  port->name = grub_malloc (sizeof ("ieee1275/")
f96e0b
+			    + grub_strlen (ent->shortest));
f96e0b
+  port->elem = ent;
f96e0b
+  if (!port->name)
f96e0b
+    return NULL;
f96e0b
+  ptr = grub_stpcpy (port->name, "ieee1275/");
f96e0b
+  grub_strcpy (ptr, ent->shortest);
f96e0b
+
f96e0b
+  port->driver = &grub_ofserial_driver;
f96e0b
+  err = grub_serial_config_defaults (port);
f96e0b
+  if (err)
f96e0b
+    grub_print_error ();
f96e0b
+
f96e0b
+  grub_serial_register (port);
f96e0b
+
f96e0b
+  return port->name;
f96e0b
+}
f96e0b
+
f96e0b
+const char *
f96e0b
+grub_ofserial_add_port (const char *path)
f96e0b
+{
f96e0b
+  struct ofserial_hash_ent *ent;
f96e0b
+  char *name = grub_strdup (path);
f96e0b
+  char *can = grub_strdup (path);
f96e0b
+
f96e0b
+  if (!name || ! can)
f96e0b
+    {
f96e0b
+      grub_free (name);
f96e0b
+      grub_free (can);
f96e0b
+      return NULL;
f96e0b
+    }
f96e0b
+
f96e0b
+  ent = ofserial_hash_add (name, can);
f96e0b
+  return add_port (ent);
f96e0b
+}
f96e0b
+
f96e0b
 void
f96e0b
 grub_ofserial_init (void)
f96e0b
 {
f96e0b
   unsigned i;
f96e0b
-  grub_err_t err;
f96e0b
   struct grub_ieee1275_devalias alias;
f96e0b
 
f96e0b
   FOR_IEEE1275_DEVALIASES(alias)
f96e0b
@@ -230,32 +279,9 @@ grub_ofserial_init (void)
f96e0b
   
f96e0b
   for (i = 0; i < ARRAY_SIZE (ofserial_hash); i++)
f96e0b
     {
f96e0b
-      static struct ofserial_hash_ent *ent;
f96e0b
+      struct ofserial_hash_ent *ent;
f96e0b
       for (ent = ofserial_hash[i]; ent; ent = ent->next)
f96e0b
-	{
f96e0b
-	  struct grub_serial_port *port;
f96e0b
-	  char *ptr;
f96e0b
-	  if (!ent->shortest)
f96e0b
-	    continue;
f96e0b
-
f96e0b
-	  port = grub_zalloc (sizeof (*port));
f96e0b
-	  if (!port)
f96e0b
-	    return;
f96e0b
-	  port->name = grub_malloc (sizeof ("ieee1275/")
f96e0b
-				    + grub_strlen (ent->shortest));
f96e0b
-	  port->elem = ent;
f96e0b
-	  if (!port->name)
f96e0b
-	    return;
f96e0b
-	  ptr = grub_stpcpy (port->name, "ieee1275/");
f96e0b
-	  grub_strcpy (ptr, ent->shortest);
f96e0b
-
f96e0b
-	  port->driver = &grub_ofserial_driver;
f96e0b
-	  err = grub_serial_config_defaults (port);
f96e0b
-	  if (err)
f96e0b
-	    grub_print_error ();
f96e0b
-
f96e0b
-	  grub_serial_register (port);
f96e0b
-	}
f96e0b
+	add_port (ent);
f96e0b
     }
f96e0b
 }
f96e0b
 
f96e0b
diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c
f96e0b
index cfcfe84..96f9d7f 100644
f96e0b
--- a/grub-core/term/serial.c
f96e0b
+++ b/grub-core/term/serial.c
f96e0b
@@ -31,6 +31,9 @@
f96e0b
 #ifdef GRUB_MACHINE_MIPS_LOONGSON
f96e0b
 #include <grub/machine/kernel.h>
f96e0b
 #endif
f96e0b
+#ifdef GRUB_MACHINE_IEEE1275
f96e0b
+#include <grub/ieee1275/console.h>
f96e0b
+#endif
f96e0b
 
f96e0b
 GRUB_MOD_LICENSE ("GPLv3+");
f96e0b
 
f96e0b
@@ -149,6 +152,19 @@ grub_serial_find (const char *name)
f96e0b
     }
f96e0b
 #endif
f96e0b
 
f96e0b
+#ifdef GRUB_MACHINE_IEEE1275
f96e0b
+  if (!port && grub_memcmp (name, "ieee1275/", sizeof ("ieee1275/") - 1) == 0)
f96e0b
+    {
f96e0b
+      name = grub_ofserial_add_port (&name[sizeof ("ieee1275/") - 1]);
f96e0b
+      if (!name)
f96e0b
+	return NULL;
f96e0b
+
f96e0b
+      FOR_SERIAL_PORTS (port)
f96e0b
+	if (grub_strcmp (port->name, name) == 0)
f96e0b
+	  break;
f96e0b
+    }
f96e0b
+#endif
f96e0b
+
f96e0b
   return port;
f96e0b
 }
f96e0b
 
f96e0b
diff --git a/include/grub/ieee1275/console.h b/include/grub/ieee1275/console.h
f96e0b
index e054f54..bdd98fe 100644
f96e0b
--- a/include/grub/ieee1275/console.h
f96e0b
+++ b/include/grub/ieee1275/console.h
f96e0b
@@ -28,4 +28,7 @@ void grub_console_init_lately (void);
f96e0b
 /* Finish the console system.  */
f96e0b
 void grub_console_fini (void);
f96e0b
 
f96e0b
+const char *
f96e0b
+grub_ofserial_add_port (const char *name);
f96e0b
+
f96e0b
 #endif /* ! GRUB_CONSOLE_MACHINE_HEADER */
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b