Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Feb 2010 20:31:56 GMT
From:      Rafal Jaworowski <raj@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 174262 for review
Message-ID:  <201002032031.o13KVuuk007275@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/chv.cgi?CH=174262

Change 174262 by raj@raj_fdt on 2010/02/03 20:31:34

	Optimize {fdt,simple}bus framework.
	
	- Rework simplebus fixups processing: we are now handler list
	  oriented, with individual handlers (platfrom-specific) in
	  dedicated files, only used when needed.
	
	- Eliminate an ugly MPC85XX hack for base address of direct '/'
	  descendants (like localbus and pci nodes).
	
	- Give more generic name to internal registers range: IMMR (Internal
	  Mem-Mapped Registers).

Affected files ...

.. //depot/projects/fdt/sys/arm/include/fdt.h#2 edit
.. //depot/projects/fdt/sys/arm/mv/mv_machdep.c#6 edit
.. //depot/projects/fdt/sys/dev/fdt/fdt_common.c#9 edit
.. //depot/projects/fdt/sys/dev/fdt/fdt_common.h#5 edit
.. //depot/projects/fdt/sys/dev/fdt/fdt_powerpc.c#2 edit
.. //depot/projects/fdt/sys/dev/fdt/fdtbus.c#5 edit
.. //depot/projects/fdt/sys/dev/fdt/simplebus.c#6 edit
.. //depot/projects/fdt/sys/dev/uart/uart_cpu_powerpc.c#5 edit
.. //depot/projects/fdt/sys/powerpc/include/fdt.h#2 edit

Differences ...

==== //depot/projects/fdt/sys/arm/include/fdt.h#2 (text+ko) ====

@@ -37,17 +37,17 @@
 #include <arm/mv/mvwin.h>
 
 /*
- * This is the base virtual address the simple-bus internal registers range is
- * available at.
+ * This is the base virtual address the internal mem-mapped registers (IMMR)
+ * range is available at.
  */
-#define FDT_SIMPLEBUS_VA	MV_BASE
+#define FDT_IMMR_VA	MV_BASE
 
 /* Max interrupt number */
-#define FDT_INTR_MAX		NIRQ
+#define FDT_INTR_MAX	NIRQ
 
 /*
  * Bus space tag. XXX endianess info needs to be derived from the blob.
  */
-#define fdtbus_bs_tag		obio_tag
+#define fdtbus_bs_tag	obio_tag
 
 #endif /* _MACHINE_FDT_H_ */

==== //depot/projects/fdt/sys/arm/mv/mv_machdep.c#6 (text+ko) ====

@@ -63,13 +63,12 @@
 #include <sys/exec.h>
 #include <sys/kdb.h>
 #include <sys/msgbuf.h>
-#include <machine/fdt.h>
 #include <machine/reg.h>
 #include <machine/cpu.h>
+#include <machine/fdt.h>
 
 #include <dev/fdt/fdt_common.h>
 #include <dev/ofw/openfirm.h>
-#include "../../contrib/dtc/libfdt/libfdt_env.h"
 
 #include <vm/vm.h>
 #include <vm/pmap.h>
@@ -724,7 +723,7 @@
 	    &start, &size);
 	if (rv != 0)
 		return (rv);
-	start += FDT_SIMPLEBUS_VA;
+	start += FDT_IMMR_VA;
 
 	/*
 	 * Process 'pin-max' and 'pin-map' props.

==== //depot/projects/fdt/sys/dev/fdt/fdt_common.c#9 (text+ko) ====

@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2009 The FreeBSD Foundation
+ * Copyright (c) 2009-2010 The FreeBSD Foundation
  * All rights reserved.
  *
  * This software was developed by Semihalf under sponsorship from
@@ -38,15 +38,13 @@
 
 #include <machine/resource.h>
 
+#include <dev/fdt/fdt_common.h>
 #include <dev/ofw/ofw_bus.h>
 #include <dev/ofw/ofw_bus_subr.h>
 #include <dev/ofw/openfirm.h>
 
 #include "ofw_bus_if.h"
-#include "fdt_common.h"
 
-#include "../../contrib/dtc/libfdt/libfdt_env.h"
-
 #define DEBUG
 #undef DEBUG
 
@@ -315,6 +313,7 @@
 		reg += addr_cells + size_cells;
 
 		/* Calculate address range relative to base. */
+		start &= 0x000ffffful;
 		start = base + start;
 		end = start + count - 1;
 

==== //depot/projects/fdt/sys/dev/fdt/fdt_common.h#5 (text+ko) ====

@@ -27,9 +27,10 @@
  * SUCH DAMAGE.
  */
 
-#ifndef FDT_COMMON_H
-#define FDT_COMMON_H
+#ifndef _FDT_COMMON_H_
+#define _FDT_COMMON_H_
 
+#include "../../contrib/dtc/libfdt/libfdt_env.h"
 #include <dev/ofw/ofw_bus.h>
 
 #define DI_MAX_INTR_NUM	8
@@ -40,8 +41,14 @@
 };
 
 typedef int (*fdt_pic_decode_t)(phandle_t, pcell_t *, int *, int *, int *);
+extern fdt_pic_decode_t fdt_pic_table[];
 
-extern fdt_pic_decode_t fdt_pic_table[];
+typedef void (*fdt_fixup_t)(phandle_t);
+struct fdt_fixup_entry {
+	char		*model;
+	fdt_fixup_t	handler;
+};
+extern struct fdt_fixup_entry fdt_fixup_table[];
 
 int fdt_addrsize_cells(phandle_t, int *, int *);
 u_long fdt_data_get(void *, int);
@@ -55,4 +62,4 @@
 int fdt_is_enabled(phandle_t);
 phandle_t fdt_find_compatible(phandle_t start, const char *compat);
 
-#endif /* FDT_COMMON_H */
+#endif /* _FDT_COMMON_H_ */

==== //depot/projects/fdt/sys/dev/fdt/fdt_powerpc.c#2 (text+ko) ====

@@ -45,6 +45,35 @@
 #include "ofw_bus_if.h"
 #include "fdt_common.h"
 
+static void
+fdt_fixup_busfreq(phandle_t node)
+{
+	phandle_t cpus, child;
+	pcell_t freq;
+
+	/*
+	 * This fixup uses /cpus/ bus-frequency prop value to set simple-bus
+	 * bus-frequency property.
+	 */
+	if ((cpus = OF_finddevice("/cpus")) == 0)
+		panic("simplebus: no /cpus node");
+
+	if ((child = OF_child(cpus)) == 0)
+		return;
+
+	if (OF_getprop(child, "bus-frequency", (void *)&freq,
+	    sizeof(freq)) <= 0)
+		return;
+
+	OF_setprop(node, "bus-frequency", (void *)&freq, sizeof(freq));
+}
+
+struct fdt_fixup_entry fdt_fixup_table[] = {
+	{ "fsl,MPC8572DS", &fdt_fixup_busfreq},
+	{ "MPC8555CDS", &fdt_fixup_busfreq },
+	{ NULL, NULL }
+};
+
 static int
 fdt_pic_decode_iic(phandle_t node, pcell_t *intr, int *interrupt, int *trig,
     int *pol)

==== //depot/projects/fdt/sys/dev/fdt/fdtbus.c#5 (text+ko) ====

@@ -30,7 +30,6 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-#include "opt_platform.h"
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/ktr.h>
@@ -260,7 +259,6 @@
 static device_t
 newbus_device_from_fdt_node(device_t parent, phandle_t node)
 {
-	u_long base;
 	device_t child;
 	struct fdtbus_devinfo *di;
 	char *name, *type, *compat;
@@ -286,17 +284,8 @@
 		di->di_compat = compat;
 
 		resource_list_init(&di->di_res);
-#ifdef MPC85XX
-		/*
-		 * XXX this 0x1ef00000 offset is a gross hack, which assumes:
-		 * - physical addresses in the DTS are 0xe0000000 range, and
-		 * - virtual CCSR base in kernel is 0xfef00000
-		 */
-		base = 0x1ef00000;
-#else
-		base = 0;
-#endif
-		if (fdt_reg_to_rl(node, &di->di_res, base)) {
+
+		if (fdt_reg_to_rl(node, &di->di_res, FDT_IMMR_VA)) {
 			device_printf(child, "could not process 'reg' "
 			    "property\n");
 			newbus_device_destroy(child);

==== //depot/projects/fdt/sys/dev/fdt/simplebus.c#6 (text+ko) ====

@@ -148,7 +148,7 @@
 	device_set_desc(dev, "Flattened device tree simple bus");
 
 	sc = device_get_softc(dev);
-	sc->sc_start_va = FDT_SIMPLEBUS_VA;
+	sc->sc_start_va = FDT_IMMR_VA;
 
 	return (BUS_PROBE_DEFAULT);
 }
@@ -156,34 +156,28 @@
 static void
 simplebus_fixup(phandle_t node)
 {
-	phandle_t cpus, child, root;
+	phandle_t root;
 	char *model;
-	pcell_t freq;
-	int len;
+	int i, len;
 
-	/* Fixup handling is platform specific. */
 	if ((root = OF_finddevice("/")) == 0)
 		panic("simplebus: no root node");
+
 	len = OF_getprop_alloc(root, "model", 1, (void **)&model);
 	if (len <= 0)
 		return;
-	/* XXX this should be a table with {model->fixup_handler} */
-	if (!(strcmp(model, "fsl,MPC8572DS") == 0 ||
-	    strcmp(model, "MPC8555CDS") == 0))
-		goto out;
 
-	if ((cpus = OF_finddevice("/cpus")) == 0)
-		panic("simplebus: no /cpus node");
+	for (i = 0; fdt_fixup_table[i].model != NULL; i++) {
+		if (strcmp(model, fdt_fixup_table[i].model) != 0)
+			continue;
 
-	if ((child = OF_child(cpus)) == 0)
-		return;
-
-	if (OF_getprop(child, "bus-frequency", (void *)&freq,
-	    sizeof(freq)) <= 0)
-		return;
-
-	OF_setprop(node, "bus-frequency", (void *)&freq, sizeof(freq));
-out:
+		if (fdt_fixup_table[i].handler != NULL) {
+			if (bootverbose)
+				printf("simplebus: using fixup for '%s'\n",
+				    model);
+			(*fdt_fixup_table[i].handler)(node);
+		}
+	}
 	free(model, M_OFWPROP);
 }
 

==== //depot/projects/fdt/sys/dev/uart/uart_cpu_powerpc.c#5 (text) ====

@@ -63,7 +63,7 @@
 int
 uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2)
 {
-#ifdef MPC85XX
+#ifdef FDT
 	return ((b1->bsh == b2->bsh) ? 1 : 0);
 #else
 	return ((pmap_kextract(b1->bsh) == pmap_kextract(b2->bsh)) ? 1 : 0);
@@ -140,7 +140,7 @@
 	rv = fdt_data_to_res(prop, par_addr_cells, par_size_cells,
 	    &start, &size);
 
-	start += FDT_SIMPLEBUS_VA;
+	start += FDT_IMMR_VA;
 
 	rv = bus_space_map(*tag, start, size, 0, handle);
 	if (rv)

==== //depot/projects/fdt/sys/powerpc/include/fdt.h#2 (text+ko) ====

@@ -36,17 +36,17 @@
 #include <machine/vmparam.h>
 
 /*
- * This is the base virtual address the simple-bus internal registers range is
- * available at.
+ * This is the base virtual address the internal mem-mapped registers (IMMR)
+ * range is available at.
  */
-#define FDT_SIMPLEBUS_VA	CCSRBAR_VA
+#define FDT_IMMR_VA	CCSRBAR_VA
 
 /* Max interrupt number */
-#define FDT_INTR_MAX		INTR_VECTORS
+#define FDT_INTR_MAX	INTR_VECTORS
 
 /*
  * Bus space tag. XXX endianess info needs to be derived from the blob.
  */
-#define fdtbus_bs_tag		(&bs_be_tag)
+#define fdtbus_bs_tag	(&bs_be_tag)
 
 #endif /* _MACHINE_FDT_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201002032031.o13KVuuk007275>