svn commit: r330371 - head/stand/powerpc/ofw

Nathan Whitehorn nwhitehorn at FreeBSD.org
Sun Mar 4 04:49:10 UTC 2018


Author: nwhitehorn
Date: Sun Mar  4 04:49:09 2018
New Revision: 330371
URL: https://svnweb.freebsd.org/changeset/base/330371

Log:
  Where we can, pass the kernel an FDT facsimile of the OF device tree rather
  than a pointer to Open Firmware by default. This eliminates a number of
  potentially unsafe calls to firmware from the kernel and provides better
  performance.
  
  This feature is meant to be expanded until it is on by default
  unconditionally and, ideally, we can then garbage-collect the
  nightmare pile of hacks required to call into Open Firmware from a live
  kernel.
  
  Reviewed by:	jhibbits

Modified:
  head/stand/powerpc/ofw/main.c

Modified: head/stand/powerpc/ofw/main.c
==============================================================================
--- head/stand/powerpc/ofw/main.c	Sun Mar  4 03:23:19 2018	(r330370)
+++ head/stand/powerpc/ofw/main.c	Sun Mar  4 04:49:09 2018	(r330371)
@@ -33,6 +33,8 @@ __FBSDID("$FreeBSD$");
 #include "libofw.h"
 #include "bootstrap.h"
 
+#include <machine/psl.h>
+
 struct arch_switch	archsw;		/* MI/MD interface boundary */
 
 extern char end[];
@@ -47,6 +49,16 @@ static char heap[HEAP_SIZE]; // In BSS, so uses no spa
 
 #define OF_puts(fd, text) OF_write(fd, text, strlen(text))
 
+static __inline register_t
+mfmsr(void)
+{
+	register_t value;
+
+	__asm __volatile ("mfmsr %0" : "=r"(value));
+
+	return (value);
+}
+
 void
 init_heap(void)
 {
@@ -144,6 +156,15 @@ main(int (*openfirm)(void *))
 	env_setenv("loaddev", EV_VOLATILE, bootpath, env_noset,
 	    env_nounset);
 	setenv("LINES", "24", 1);		/* optional */
+
+	/*
+	 * On non-Apple hardware, where it works reliably, pass flattened
+	 * device trees to the kernel by default instead of OF CI pointers.
+	 * Apple hardware is the only virtual-mode OF implementation in
+	 * existence, so far as I am aware, so use that as a flag.
+	 */
+	if (!(mfmsr() & PSL_DR))
+		setenv("usefdt", "1", 1);
 
 	archsw.arch_getdev = ofw_getdev;
 	archsw.arch_copyin = ofw_copyin;


More information about the svn-src-head mailing list