svn commit: r209908 - in head/sys: conf dev/cfi dev/fdt dev/quicc dev/sec dev/tsec dev/uart powerpc/booke powerpc/conf powerpc/include powerpc/mpc85xx powerpc/powerpc

Rafal Jaworowski raj at FreeBSD.org
Sun Jul 11 21:08:29 UTC 2010


Author: raj
Date: Sun Jul 11 21:08:29 2010
New Revision: 209908
URL: http://svn.freebsd.org/changeset/base/209908

Log:
  Convert Freescale PowerPC platforms to FDT convention.
  
  The following systems are affected:
  
    - MPC8555CDS
    - MPC8572DS
  
  This overhaul covers the following major changes:
  
    - All integrated peripherals drivers for Freescale MPC85XX SoC, which are
      currently in the FreeBSD source tree are reworked and adjusted so they
      derive config data out of the device tree blob (instead of hard coded /
      tabelarized values).
  
    - This includes: LBC, PCI / PCI-Express, I2C, DS1553, OpenPIC, TSEC, SEC,
      QUICC, UART, CFI.
  
    - Thanks to the common FDT infrastrucutre (fdtbus, simplebus) we retire
      ocpbus(4) driver, which was based on hard-coded config data.
  
  Note that world for these platforms has to be built WITH_FDT.
  
  Reviewed by:	imp
  Sponsored by:	The FreeBSD Foundation

Added:
  head/sys/dev/cfi/cfi_bus_fdt.c   (contents, props changed)
  head/sys/dev/quicc/quicc_bfe_fdt.c   (contents, props changed)
  head/sys/dev/tsec/if_tsec_fdt.c   (contents, props changed)
  head/sys/powerpc/include/fdt.h   (contents, props changed)
  head/sys/powerpc/mpc85xx/ds1553_bus_fdt.c   (contents, props changed)
  head/sys/powerpc/mpc85xx/openpic_fdt.c   (contents, props changed)
  head/sys/powerpc/mpc85xx/pci_fdt.c   (contents, props changed)
Deleted:
  head/sys/dev/cfi/cfi_bus_lbc.c
  head/sys/dev/quicc/quicc_bfe_ocp.c
  head/sys/dev/tsec/if_tsec_ocp.c
  head/sys/dev/uart/uart_bus_ocp.c
  head/sys/powerpc/include/bootinfo.h
  head/sys/powerpc/include/ocpbus.h
  head/sys/powerpc/mpc85xx/ds1553_bus_lbc.c
  head/sys/powerpc/mpc85xx/ocpbus.c
  head/sys/powerpc/mpc85xx/ocpbus.h
  head/sys/powerpc/mpc85xx/opic.c
  head/sys/powerpc/mpc85xx/pci_ocp.c
Modified:
  head/sys/conf/Makefile.powerpc
  head/sys/conf/files.powerpc
  head/sys/dev/fdt/fdt_pci.c
  head/sys/dev/sec/sec.c
  head/sys/dev/tsec/if_tsec.c
  head/sys/dev/tsec/if_tsec.h
  head/sys/dev/uart/uart_cpu_powerpc.c
  head/sys/powerpc/booke/locore.S
  head/sys/powerpc/booke/machdep.c
  head/sys/powerpc/booke/platform_bare.c
  head/sys/powerpc/booke/pmap.c
  head/sys/powerpc/conf/MPC85XX
  head/sys/powerpc/include/metadata.h
  head/sys/powerpc/mpc85xx/atpic.c
  head/sys/powerpc/mpc85xx/i2c.c
  head/sys/powerpc/mpc85xx/lbc.c
  head/sys/powerpc/mpc85xx/lbc.h
  head/sys/powerpc/mpc85xx/mpc85xx.c
  head/sys/powerpc/mpc85xx/mpc85xx.h
  head/sys/powerpc/mpc85xx/nexus.c
  head/sys/powerpc/powerpc/intr_machdep.c

Modified: head/sys/conf/Makefile.powerpc
==============================================================================
--- head/sys/conf/Makefile.powerpc	Sun Jul 11 20:55:39 2010	(r209907)
+++ head/sys/conf/Makefile.powerpc	Sun Jul 11 21:08:29 2010	(r209908)
@@ -30,6 +30,8 @@ S=	../../..
 .endif
 .include "$S/conf/kern.pre.mk"
 
+INCLUDES+= -I$S/contrib/libfdt
+
 CFLAGS+= -msoft-float
 
 DDB_ENABLED!=	grep DDB opt_ddb.h || true

Modified: head/sys/conf/files.powerpc
==============================================================================
--- head/sys/conf/files.powerpc	Sun Jul 11 20:55:39 2010	(r209907)
+++ head/sys/conf/files.powerpc	Sun Jul 11 21:08:29 2010	(r209908)
@@ -14,7 +14,6 @@ font.h				optional	sc			\
 	no-obj no-implicit-rule before-depend				\
 	clean	"font.h ${SC_DFLT_FONT}-8x14 ${SC_DFLT_FONT}-8x16 ${SC_DFLT_FONT}-8x8"
 #
-
 crypto/blowfish/bf_enc.c	optional	crypto | ipsec
 crypto/des/des_enc.c		optional	crypto | ipsec | netsmb
 dev/bm/if_bm.c			optional	bm powermac
@@ -23,21 +22,23 @@ dev/adb/adb_kbd.c		optional	adb
 dev/adb/adb_mouse.c		optional	adb
 dev/adb/adb_hb_if.m		optional	adb
 dev/adb/adb_if.m		optional	adb
-dev/cfi/cfi_bus_lbc.c		optional	cfi
+dev/cfi/cfi_bus_fdt.c		optional	cfi fdt
 dev/fb/fb.c			optional	sc
+dev/fdt/fdt_powerpc.c		optional	fdt
 dev/hwpmc/hwpmc_powerpc.c	optional	hwpmc
 dev/kbd/kbd.c			optional	sc
-dev/ofw/openfirm.c		optional	aim
-dev/ofw/openfirmio.c		optional	aim
-dev/ofw/ofw_bus_if.m		optional	aim
-dev/ofw/ofw_if.m		optional	aim
-dev/ofw/ofw_bus_subr.c		optional	aim
+dev/ofw/openfirm.c		optional	aim | fdt
+dev/ofw/openfirmio.c		optional	aim | fdt
+dev/ofw/ofw_bus_if.m		optional	aim | fdt
+dev/ofw/ofw_if.m		optional	aim | fdt
+dev/ofw/ofw_bus_subr.c		optional	aim | fdt
 dev/ofw/ofw_console.c		optional	aim
 dev/ofw/ofw_disk.c		optional	ofwd aim
+dev/ofw/ofw_fdt.c		optional	fdt
 dev/ofw/ofw_iicbus.c		optional	iicbus aim
 dev/ofw/ofw_standard.c		optional	aim
 dev/powermac_nvram/powermac_nvram.c optional	powermac_nvram powermac
-dev/quicc/quicc_bfe_ocp.c	optional	quicc mpc85xx
+dev/quicc/quicc_bfe_fdt.c	optional	quicc mpc85xx
 dev/scc/scc_bfe_macio.c		optional	scc powermac
 dev/sec/sec.c			optional	sec mpc85xx
 dev/sound/macio/aoa.c		optional	snd_davbus | snd_ai2s powermac
@@ -49,9 +50,8 @@ dev/syscons/scgfbrndr.c		optional	sc
 dev/syscons/scterm-teken.c	optional	sc
 dev/syscons/scvtb.c		optional	sc
 dev/tsec/if_tsec.c		optional	tsec
-dev/tsec/if_tsec_ocp.c		optional	tsec mpc85xx
-dev/uart/uart_bus_ocp.c		optional	uart mpc85xx
-dev/uart/uart_cpu_powerpc.c	optional	uart
+dev/tsec/if_tsec_fdt.c		optional	tsec fdt
+dev/uart/uart_cpu_powerpc.c	optional	uart aim
 kern/syscalls.c			optional	ktr
 libkern/ashldi3.c		standard
 libkern/ashrdi3.c		standard
@@ -63,6 +63,7 @@ libkern/ffsl.c			standard
 libkern/fls.c			standard
 libkern/flsl.c			standard
 libkern/lshrdi3.c		standard
+libkern/memchr.c		optional	fdt
 libkern/memmove.c		standard
 libkern/memset.c		standard
 libkern/moddi3.c		standard
@@ -109,16 +110,15 @@ powerpc/fpu/fpu_mul.c		optional	fpu_emu
 powerpc/fpu/fpu_sqrt.c		optional	fpu_emu
 powerpc/fpu/fpu_subr.c		optional	fpu_emu
 powerpc/mpc85xx/atpic.c		optional	mpc85xx isa
-powerpc/mpc85xx/ds1553_bus_lbc.c	optional	ds1553
+powerpc/mpc85xx/ds1553_bus_fdt.c	optional	ds1553 fdt
 powerpc/mpc85xx/ds1553_core.c	optional	ds1553
-powerpc/mpc85xx/i2c.c		optional	iicbus mpc85xx
+powerpc/mpc85xx/i2c.c		optional	iicbus fdt
 powerpc/mpc85xx/isa.c		optional	mpc85xx isa
 powerpc/mpc85xx/lbc.c		optional	mpc85xx
 powerpc/mpc85xx/mpc85xx.c	optional	mpc85xx
 powerpc/mpc85xx/nexus.c		optional	mpc85xx
-powerpc/mpc85xx/ocpbus.c	optional	mpc85xx
-powerpc/mpc85xx/opic.c		optional	mpc85xx
-powerpc/mpc85xx/pci_ocp.c	optional	pci mpc85xx
+powerpc/mpc85xx/openpic_fdt.c	optional	fdt
+powerpc/mpc85xx/pci_fdt.c	optional	pci mpc85xx
 powerpc/ofw/ofw_cpu.c		optional	aim
 powerpc/ofw/ofw_pcibus.c	optional	pci aim
 powerpc/ofw/ofw_pcib_pci.c	optional	pci aim

Added: head/sys/dev/cfi/cfi_bus_fdt.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/cfi/cfi_bus_fdt.c	Sun Jul 11 21:08:29 2010	(r209908)
@@ -0,0 +1,73 @@
+/*-
+ * Copyright (c) 2007, Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+
+#include <machine/bus.h>
+
+#include <dev/cfi/cfi_var.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+
+static int cfi_fdt_probe(device_t);
+
+static device_method_t cfi_fdt_methods[] = {
+	/* device interface */
+	DEVMETHOD(device_probe,		cfi_fdt_probe),
+	DEVMETHOD(device_attach,	cfi_attach),
+	DEVMETHOD(device_detach,	cfi_detach),
+
+	{0, 0}
+};
+
+static driver_t cfi_fdt_driver = {
+	cfi_driver_name,
+	cfi_fdt_methods,
+	sizeof(struct cfi_softc),
+};
+
+DRIVER_MODULE (cfi, lbc, cfi_fdt_driver, cfi_devclass, 0, 0);
+
+static int
+cfi_fdt_probe(device_t dev)
+{
+
+	if (!ofw_bus_is_compatible(dev, "cfi-flash"))
+		return (ENXIO);
+
+	return (cfi_probe(dev));
+}

Modified: head/sys/dev/fdt/fdt_pci.c
==============================================================================
--- head/sys/dev/fdt/fdt_pci.c	Sun Jul 11 20:55:39 2010	(r209907)
+++ head/sys/dev/fdt/fdt_pci.c	Sun Jul 11 21:08:29 2010	(r209908)
@@ -325,8 +325,9 @@ fdt_pci_route_intr(int bus, int slot, in
 		debugf("decoded intr = %d, trig = %d, pol = %d\n", *interrupt,
 		    trig, pol);
 
-		/* XXX we should probably call powerpc_config() here... */
-
+#if defined(__powerpc__)
+		powerpc_config_intr(INTR_VEC(intr_par, *interrupt), trig, pol);
+#endif
 		return (0);
 
 next:

Added: head/sys/dev/quicc/quicc_bfe_fdt.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/quicc/quicc_bfe_fdt.c	Sun Jul 11 21:08:29 2010	(r209908)
@@ -0,0 +1,90 @@
+/*-
+ * Copyright (c) 2006 Juniper Networks.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+#include <sys/rman.h>
+#include <sys/tty.h>
+#include <machine/bus.h>
+
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/quicc/quicc_bfe.h>
+
+static int quicc_fdt_probe(device_t dev);
+
+static device_method_t quicc_fdt_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		quicc_fdt_probe),
+	DEVMETHOD(device_attach,	quicc_bfe_attach),
+	DEVMETHOD(device_detach,	quicc_bfe_detach),
+
+	DEVMETHOD(bus_alloc_resource,	quicc_bus_alloc_resource),
+	DEVMETHOD(bus_release_resource,	quicc_bus_release_resource),
+	DEVMETHOD(bus_get_resource,	quicc_bus_get_resource),
+	DEVMETHOD(bus_read_ivar,	quicc_bus_read_ivar),
+	DEVMETHOD(bus_setup_intr,	quicc_bus_setup_intr),
+	DEVMETHOD(bus_teardown_intr,	quicc_bus_teardown_intr),
+	DEVMETHOD(bus_print_child,	bus_generic_print_child),
+	DEVMETHOD(bus_driver_added,	bus_generic_driver_added),
+
+	{ 0, 0 }
+};
+
+static driver_t quicc_fdt_driver = {
+	quicc_driver_name,
+	quicc_fdt_methods,
+	sizeof(struct quicc_softc),
+};
+
+static int
+quicc_fdt_probe(device_t dev)
+{
+	phandle_t par;
+	pcell_t clock;
+
+	if (!ofw_bus_is_compatible(dev, "fsl,cpm2"))
+		return (ENXIO);
+
+	par = OF_parent(ofw_bus_get_node(dev));
+	if (OF_getprop(par, "bus-frequency", &clock, sizeof(clock)) <= 0)
+		clock = 0;
+
+	return (quicc_bfe_probe(dev, (uintptr_t)clock));
+}
+
+DRIVER_MODULE(quicc, simplebus, quicc_fdt_driver, quicc_devclass, 0, 0);

Modified: head/sys/dev/sec/sec.c
==============================================================================
--- head/sys/dev/sec/sec.c	Sun Jul 11 20:55:39 2010	(r209907)
+++ head/sys/dev/sec/sec.c	Sun Jul 11 21:08:29 2010	(r209908)
@@ -45,12 +45,12 @@ __FBSDID("$FreeBSD$");
 #include <sys/rman.h>
 
 #include <machine/bus.h>
-#include <machine/ocpbus.h>
 #include <machine/resource.h>
 
 #include <opencrypto/cryptodev.h>
 #include "cryptodev_if.h"
 
+#include <dev/ofw/ofw_bus_subr.h>
 #include <dev/sec/sec.h>
 
 static int	sec_probe(device_t dev);
@@ -153,7 +153,7 @@ static driver_t sec_driver = {
 };
 
 static devclass_t sec_devclass;
-DRIVER_MODULE(sec, ocpbus, sec_driver, sec_devclass, 0, 0);
+DRIVER_MODULE(sec, simplebus, sec_driver, sec_devclass, 0, 0);
 MODULE_DEPEND(sec, crypto, 1, 1, 1);
 
 static struct sec_eu_methods sec_eus[] = {
@@ -201,24 +201,16 @@ static int
 sec_probe(device_t dev)
 {
 	struct sec_softc *sc;
-	device_t parent;
-	uintptr_t devtype;
 	uint64_t id;
-	int error;
 
-	parent = device_get_parent(dev);
-	error = BUS_READ_IVAR(parent, dev, OCPBUS_IVAR_DEVTYPE, &devtype);
-	if (error)
-		return (error);
-
-	if (devtype != OCPBUS_DEVTYPE_SEC)
+	if (!ofw_bus_is_compatible(dev, "fsl,sec2.0"))
 		return (ENXIO);
 
 	sc = device_get_softc(dev);
 
 	sc->sc_rrid = 0;
-	sc->sc_rres = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->sc_rrid,
-	    0ul, ~0ul, SEC_IO_SIZE, RF_ACTIVE);
+	sc->sc_rres = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_rrid,
+	    RF_ACTIVE);
 
 	if (sc->sc_rres == NULL)
 		return (ENXIO);
@@ -276,8 +268,8 @@ sec_attach(device_t dev)
 
 	/* Allocate I/O memory for SEC registers */
 	sc->sc_rrid = 0;
-	sc->sc_rres = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->sc_rrid,
-	    0ul, ~0ul, SEC_IO_SIZE, RF_ACTIVE);
+	sc->sc_rres = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_rrid,
+	    RF_ACTIVE);
 
 	if (sc->sc_rres == NULL) {
 		device_printf(dev, "could not allocate I/O memory!\n");
@@ -295,12 +287,15 @@ sec_attach(device_t dev)
 	if (error)
 		goto fail2;
 
-	sc->sc_sec_irid = 1;
-	error = sec_setup_intr(sc, &sc->sc_sec_ires, &sc->sc_sec_ihand,
-	    &sc->sc_sec_irid, sec_secondary_intr, "secondary");
 
-	if (error)
-		goto fail3;
+	if (sc->sc_version == 3) {
+		sc->sc_sec_irid = 1;
+		error = sec_setup_intr(sc, &sc->sc_sec_ires, &sc->sc_sec_ihand,
+		    &sc->sc_sec_irid, sec_secondary_intr, "secondary");
+
+		if (error)
+			goto fail3;
+	}
 
 	/* Alloc DMA memory for descriptors and link tables */
 	error = sec_alloc_dma_mem(sc, &(sc->sc_desc_dmem),

Modified: head/sys/dev/tsec/if_tsec.c
==============================================================================
--- head/sys/dev/tsec/if_tsec.c	Sun Jul 11 20:55:39 2010	(r209907)
+++ head/sys/dev/tsec/if_tsec.c	Sun Jul 11 21:08:29 2010	(r209908)
@@ -1,6 +1,6 @@
 /*-
- * Copyright (C) 2007-2008 Semihalf, Rafal Jaworowski <raj at semihalf.com>
- * Copyright (C) 2006-2007 Semihalf, Piotr Kruszynski <ppk at semihalf.com>
+ * Copyright (C) 2007-2008 Semihalf, Rafal Jaworowski
+ * Copyright (C) 2006-2007 Semihalf, Piotr Kruszynski
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -1563,7 +1563,7 @@ tsec_miibus_readreg(device_t dev, int ph
 
 	sc = device_get_softc(dev);
 
-	if (device_get_unit(dev) != phy)
+	if (sc->phyaddr != phy)
 		return (0);
 
 	sc = tsec0_sc;
@@ -1591,9 +1591,8 @@ tsec_miibus_writereg(device_t dev, int p
 
 	sc = device_get_softc(dev);
 
-	if (device_get_unit(dev) != phy)
-		device_printf(dev, "Trying to write to an alien PHY(%d)\n",
-		    phy);
+	if (sc->phyaddr != phy)
+		return (0);
 
 	sc = tsec0_sc;
 

Modified: head/sys/dev/tsec/if_tsec.h
==============================================================================
--- head/sys/dev/tsec/if_tsec.h	Sun Jul 11 20:55:39 2010	(r209907)
+++ head/sys/dev/tsec/if_tsec.h	Sun Jul 11 21:08:29 2010	(r209908)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (C) 2006-2007 Semihalf, Piotr Kruszynski <ppk at semihalf.com>
+ * Copyright (C) 2006-2007 Semihalf, Piotr Kruszynski
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,6 +28,8 @@
 #ifndef _IF_TSEC_H
 #define _IF_TSEC_H
 
+#include <dev/ofw/openfirm.h>
+
 #define TSEC_RX_NUM_DESC	256
 #define TSEC_TX_NUM_DESC	256
 
@@ -49,6 +51,7 @@ struct tsec_softc {
 	struct mtx	transmit_lock;	/* transmitter lock */
 	struct mtx	receive_lock;	/* receiver lock */
 
+	phandle_t	node;
 	device_t	dev;
 	device_t	tsec_miibus;
 	struct mii_data	*tsec_mii;	/* MII media control */
@@ -128,6 +131,8 @@ struct tsec_softc {
 
 	/* currently received frame */
 	struct mbuf	*frame;
+
+	int		phyaddr;
 };
 
 /* interface to get/put generic objects */

Added: head/sys/dev/tsec/if_tsec_fdt.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/tsec/if_tsec_fdt.c	Sun Jul 11 21:08:29 2010	(r209908)
@@ -0,0 +1,352 @@
+/*-
+ * Copyright (C) 2007-2008 Semihalf, Rafal Jaworowski
+ * Copyright (C) 2006-2007 Semihalf, Piotr Kruszynski
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * From: FreeBSD: head/sys/dev/tsec/if_tsec_ocp.c 188712 2009-02-17 14:59:47Z raj
+ */
+
+/*
+ * FDT 'simple-bus' attachment for Freescale TSEC controller.
+ */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/endian.h>
+#include <sys/mbuf.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/socket.h>
+#include <sys/sysctl.h>
+
+#include <sys/bus.h>
+#include <machine/bus.h>
+#include <sys/rman.h>
+#include <machine/resource.h>
+
+#include <net/ethernet.h>
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_media.h>
+#include <net/if_arp.h>
+
+#include <dev/fdt/fdt_common.h>
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/openfirm.h>
+
+#include <dev/tsec/if_tsec.h>
+#include <dev/tsec/if_tsecreg.h>
+
+#include "miibus_if.h"
+
+#define	TSEC_RID_TXIRQ	0
+#define	TSEC_RID_RXIRQ	1
+#define	TSEC_RID_ERRIRQ	2
+
+extern struct tsec_softc *tsec0_sc;
+
+static int tsec_fdt_probe(device_t dev);
+static int tsec_fdt_attach(device_t dev);
+static int tsec_fdt_detach(device_t dev);
+static int tsec_setup_intr(struct tsec_softc *sc, struct resource **ires,
+    void **ihand, int *irid, driver_intr_t handler, const char *iname);
+static void tsec_release_intr(struct tsec_softc *sc, struct resource *ires,
+    void *ihand, int irid, const char *iname);
+
+static device_method_t tsec_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		tsec_fdt_probe),
+	DEVMETHOD(device_attach,	tsec_fdt_attach),
+	DEVMETHOD(device_detach,	tsec_fdt_detach),
+
+	DEVMETHOD(device_shutdown,	tsec_shutdown),
+	DEVMETHOD(device_suspend,	tsec_suspend),
+	DEVMETHOD(device_resume,	tsec_resume),
+
+	/* Bus interface */
+	DEVMETHOD(bus_print_child,	bus_generic_print_child),
+	DEVMETHOD(bus_driver_added,	bus_generic_driver_added),
+
+	/* MII interface */
+	DEVMETHOD(miibus_readreg,	tsec_miibus_readreg),
+	DEVMETHOD(miibus_writereg,	tsec_miibus_writereg),
+	DEVMETHOD(miibus_statchg,	tsec_miibus_statchg),
+	{ 0, 0 }
+};
+
+static driver_t tsec_fdt_driver = {
+	"tsec",
+	tsec_methods,
+	sizeof(struct tsec_softc),
+};
+
+DRIVER_MODULE(tsec, simplebus, tsec_fdt_driver, tsec_devclass, 0, 0);
+MODULE_DEPEND(tsec, simplebus, 1, 1, 1);
+MODULE_DEPEND(tsec, ether, 1, 1, 1);
+
+static int
+tsec_fdt_probe(device_t dev)
+{
+	struct tsec_softc *sc;
+	uint32_t id;
+
+	if (!ofw_bus_is_compatible(dev, "gianfar"))
+		return (ENXIO);
+
+	sc = device_get_softc(dev);
+
+	sc->sc_rrid = 0;
+	sc->sc_rres = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_rrid,
+	    RF_ACTIVE);
+	if (sc->sc_rres == NULL)
+		return (ENXIO);
+
+	sc->sc_bas.bsh = rman_get_bushandle(sc->sc_rres);
+	sc->sc_bas.bst = rman_get_bustag(sc->sc_rres);
+
+	/* Check if we are eTSEC (enhanced TSEC) */
+	id = TSEC_READ(sc, TSEC_REG_ID);
+	sc->is_etsec = ((id >> 16) == TSEC_ETSEC_ID) ? 1 : 0;
+	id |= TSEC_READ(sc, TSEC_REG_ID2);
+
+	bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_rrid, sc->sc_rres);
+
+	if (id == 0) {
+		device_printf(dev, "could not identify TSEC type\n");
+		return (ENXIO);
+	}
+
+	if (sc->is_etsec)
+		device_set_desc(dev, "Enhanced Three-Speed Ethernet Controller");
+	else
+		device_set_desc(dev, "Three-Speed Ethernet Controller");
+
+	return (BUS_PROBE_DEFAULT);
+}
+
+static int
+tsec_fdt_attach(device_t dev)
+{
+	struct tsec_softc *sc;
+	int error = 0;
+
+	sc = device_get_softc(dev);
+	sc->dev = dev;
+	sc->node = ofw_bus_get_node(dev);
+
+	/* XXX add comment on weird FSL's MII registers access design */
+	if (device_get_unit(dev) == 0)
+		tsec0_sc = sc;
+
+	/* Get phy address from fdt */
+	if (fdt_get_phyaddr(sc->node, &sc->phyaddr) != 0)
+		return (ENXIO);
+
+	/* Init timer */
+	callout_init(&sc->tsec_callout, 1);
+
+	/* Init locks */
+	mtx_init(&sc->transmit_lock, device_get_nameunit(dev), "TSEC TX lock",
+	    MTX_DEF);
+	mtx_init(&sc->receive_lock, device_get_nameunit(dev), "TSEC RX lock",
+	    MTX_DEF);
+	mtx_init(&sc->ic_lock, device_get_nameunit(dev), "TSEC IC lock",
+	    MTX_DEF);
+
+	/* Allocate IO memory for TSEC registers */
+	sc->sc_rrid = 0;
+	sc->sc_rres = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_rrid,
+	    RF_ACTIVE);
+	if (sc->sc_rres == NULL) {
+		device_printf(dev, "could not allocate IO memory range!\n");
+		goto fail1;
+	}
+	sc->sc_bas.bsh = rman_get_bushandle(sc->sc_rres);
+	sc->sc_bas.bst = rman_get_bustag(sc->sc_rres);
+
+	/* TSEC attach */
+	if (tsec_attach(sc) != 0) {
+		device_printf(dev, "could not be configured\n");
+		goto fail2;
+	}
+
+	/* Set up interrupts (TX/RX/ERR) */
+	sc->sc_transmit_irid = TSEC_RID_TXIRQ;
+	error = tsec_setup_intr(sc, &sc->sc_transmit_ires,
+	    &sc->sc_transmit_ihand, &sc->sc_transmit_irid,
+	    tsec_transmit_intr, "TX");
+	if (error)
+		goto fail2;
+
+	sc->sc_receive_irid = TSEC_RID_RXIRQ;
+	error = tsec_setup_intr(sc, &sc->sc_receive_ires,
+	    &sc->sc_receive_ihand, &sc->sc_receive_irid,
+	    tsec_receive_intr, "RX");
+	if (error)
+		goto fail3;
+
+	sc->sc_error_irid = TSEC_RID_ERRIRQ;
+	error = tsec_setup_intr(sc, &sc->sc_error_ires,
+	    &sc->sc_error_ihand, &sc->sc_error_irid,
+	    tsec_error_intr, "ERR");
+	if (error)
+		goto fail4;
+
+	return (0);
+
+fail4:
+	tsec_release_intr(sc, sc->sc_receive_ires, sc->sc_receive_ihand,
+	    sc->sc_receive_irid, "RX");
+fail3:
+	tsec_release_intr(sc, sc->sc_transmit_ires, sc->sc_transmit_ihand,
+	    sc->sc_transmit_irid, "TX");
+fail2:
+	bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_rrid, sc->sc_rres);
+fail1:
+	mtx_destroy(&sc->receive_lock);
+	mtx_destroy(&sc->transmit_lock);
+	return (ENXIO);
+}
+
+static int
+tsec_setup_intr(struct tsec_softc *sc, struct resource **ires, void **ihand,
+    int *irid, driver_intr_t handler, const char *iname)
+{
+	int error;
+
+	*ires = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, irid, RF_ACTIVE);
+	if (*ires == NULL) {
+		device_printf(sc->dev, "could not allocate %s IRQ\n", iname);
+		return (ENXIO);
+	}
+	error = bus_setup_intr(sc->dev, *ires, INTR_TYPE_NET | INTR_MPSAFE,
+	    NULL, handler, sc, ihand);
+	if (error) {
+		device_printf(sc->dev, "failed to set up %s IRQ\n", iname);
+		if (bus_release_resource(sc->dev, SYS_RES_IRQ, *irid, *ires))
+			device_printf(sc->dev, "could not release %s IRQ\n", iname);
+		*ires = NULL;
+		return (error);
+	}
+	return (0);
+}
+
+static void
+tsec_release_intr(struct tsec_softc *sc, struct resource *ires, void *ihand,
+    int irid, const char *iname)
+{
+	int error;
+
+	if (ires == NULL)
+		return;
+
+	error = bus_teardown_intr(sc->dev, ires, ihand);
+	if (error)
+		device_printf(sc->dev, "bus_teardown_intr() failed for %s intr"
+		    ", error %d\n", iname, error);
+
+	error = bus_release_resource(sc->dev, SYS_RES_IRQ, irid, ires);
+	if (error)
+		device_printf(sc->dev, "bus_release_resource() failed for %s "
+		    "intr, error %d\n", iname, error);
+}
+
+static int
+tsec_fdt_detach(device_t dev)
+{
+	struct tsec_softc *sc;
+	int error;
+
+	sc = device_get_softc(dev);
+
+	/* Wait for stopping watchdog */
+	callout_drain(&sc->tsec_callout);
+
+	/* Stop and release all interrupts */
+	tsec_release_intr(sc, sc->sc_transmit_ires, sc->sc_transmit_ihand,
+	    sc->sc_transmit_irid, "TX");
+	tsec_release_intr(sc, sc->sc_receive_ires, sc->sc_receive_ihand,
+	    sc->sc_receive_irid, "RX");
+	tsec_release_intr(sc, sc->sc_error_ires, sc->sc_error_ihand,
+	    sc->sc_error_irid, "ERR");
+
+	/* TSEC detach */
+	tsec_detach(sc);
+
+	/* Free IO memory handler */
+	if (sc->sc_rres) {
+		error = bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_rrid,
+		    sc->sc_rres);
+		if (error)
+			device_printf(dev, "bus_release_resource() failed for"
+			    " IO memory, error %d\n", error);
+	}
+
+	/* Destroy locks */
+	mtx_destroy(&sc->receive_lock);
+	mtx_destroy(&sc->transmit_lock);
+	mtx_destroy(&sc->ic_lock);
+	return (0);
+}
+
+void
+tsec_get_hwaddr(struct tsec_softc *sc, uint8_t *addr)
+{
+	union {
+		uint32_t reg[2];
+		uint8_t addr[6];
+	} curmac;
+	uint32_t a[6];
+	uint8_t lma[6];
+	int i;
+
+	/*
+	 * Retrieve hw address from the device tree.
+	 */
+	i = OF_getprop(sc->node, "local-mac-address", (void *)lma, 6);
+	if (i == 6) {
+		bcopy(lma, addr, 6);
+		return;
+	}
+
+	/*
+	 * Fall back -- use the currently programmed address in the hope that
+	 * it was set be firmware...
+	 */
+	curmac.reg[0] = TSEC_READ(sc, TSEC_REG_MACSTNADDR1);
+	curmac.reg[1] = TSEC_READ(sc, TSEC_REG_MACSTNADDR2);
+	for (i = 0; i < 6; i++)
+		a[5-i] = curmac.addr[i];
+
+	addr[0] = a[0];
+	addr[1] = a[1];
+	addr[2] = a[2];
+	addr[3] = a[3];
+	addr[4] = a[4];
+	addr[5] = a[5];
+}

Modified: head/sys/dev/uart/uart_cpu_powerpc.c
==============================================================================
--- head/sys/dev/uart/uart_cpu_powerpc.c	Sun Jul 11 20:55:39 2010	(r209907)
+++ head/sys/dev/uart/uart_cpu_powerpc.c	Sun Jul 11 21:08:29 2010	(r209908)
@@ -27,57 +27,28 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-#include "opt_platform.h"
-
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <vm/vm.h>
 #include <vm/pmap.h>
 
 #include <machine/bus.h>
-
-#ifndef MPC85XX
-#include <dev/ofw/openfirm.h>
 #include <machine/ofw_machdep.h>
-#endif
 
+#include <dev/ofw/openfirm.h>
 #include <dev/uart/uart.h>
 #include <dev/uart/uart_cpu.h>
 
-#ifdef MPC85XX
-bus_space_tag_t uart_bus_space_io = &bs_be_tag;
-bus_space_tag_t uart_bus_space_mem = &bs_be_tag;
-#else
 bus_space_tag_t uart_bus_space_io = &bs_le_tag;
 bus_space_tag_t uart_bus_space_mem = &bs_le_tag;
-#endif
 
 int
 uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2)
 {
-#ifdef MPC85XX
-	return ((b1->bsh == b2->bsh) ? 1 : 0);
-#else
+
 	return ((pmap_kextract(b1->bsh) == pmap_kextract(b2->bsh)) ? 1 : 0);
-#endif
 }
 
-#ifdef MPC85XX
-int
-uart_cpu_getdev(int devtype, struct uart_devinfo *di)
-{
-	struct uart_class *class;
-
-	class = &uart_ns8250_class;
-	if (class == NULL)
-		class = &uart_quicc_class;
-	if (class == NULL)
-		return (ENXIO);
-
-	/* Check the environment. */
-	return (uart_getenv(devtype, di, class));
-}
-#else
 static int
 ofw_get_uart_console(phandle_t opts, phandle_t *result, const char *inputdev,
     const char *outputdev)
@@ -174,4 +145,3 @@ uart_cpu_getdev(int devtype, struct uart
 	di->parity = UART_PARITY_NONE;
 	return (0);
 }
-#endif

Modified: head/sys/powerpc/booke/locore.S
==============================================================================
--- head/sys/powerpc/booke/locore.S	Sun Jul 11 20:55:39 2010	(r209907)
+++ head/sys/powerpc/booke/locore.S	Sun Jul 11 21:08:29 2010	(r209908)
@@ -39,7 +39,6 @@
 #include <machine/trap.h>
 #include <machine/vmparam.h>
 #include <machine/tlb.h>
-#include <machine/bootinfo.h>
 
 #define TMPSTACKSZ	16384
 

Modified: head/sys/powerpc/booke/machdep.c
==============================================================================
--- head/sys/powerpc/booke/machdep.c	Sun Jul 11 20:55:39 2010	(r209907)
+++ head/sys/powerpc/booke/machdep.c	Sun Jul 11 21:08:29 2010	(r209908)
@@ -130,13 +130,14 @@ __FBSDID("$FreeBSD$");
 #include <machine/mmuvar.h>
 #include <machine/sigframe.h>
 #include <machine/metadata.h>
-#include <machine/bootinfo.h>
 #include <machine/platform.h>
 
 #include <sys/linker.h>
 #include <sys/reboot.h>
 
-#include <powerpc/mpc85xx/ocpbus.h>
+#include <dev/fdt/fdt_common.h>
+#include <dev/ofw/openfirm.h>
+
 #include <powerpc/mpc85xx/mpc85xx.h>
 
 #ifdef DDB
@@ -169,8 +170,6 @@ int cold = 1;
 long realmem = 0;
 long Maxmem = 0;
 
-struct bootinfo *bootinfo;
-
 char machine[] = "powerpc";
 SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, "");
 
@@ -185,7 +184,6 @@ static void cpu_e500_startup(void *);
 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_e500_startup, NULL);
 
 void print_kernel_section_addr(void);
-void print_bootinfo(void);
 void print_kenv(void);
 u_int e500_init(u_int32_t, u_int32_t, void *);
 
@@ -259,40 +257,6 @@ print_kenv(void)
 }
 
 void
-print_bootinfo(void)
-{
-	struct bi_mem_region *mr;
-	struct bi_eth_addr *eth;
-	int i, j;
-
-	debugf("bootinfo:\n");
-	if (bootinfo == NULL) {
-		debugf(" no bootinfo, null ptr\n");
-		return;
-	}
-
-	debugf(" version = 0x%08x\n", bootinfo->bi_version);
-	debugf(" ccsrbar = 0x%08x\n", bootinfo->bi_bar_base);
-	debugf(" cpu_clk = 0x%08x\n", bootinfo->bi_cpu_clk);
-	debugf(" bus_clk = 0x%08x\n", bootinfo->bi_bus_clk);
-
-	debugf(" mem regions:\n");
-	mr = (struct bi_mem_region *)bootinfo->bi_data;
-	for (i = 0; i < bootinfo->bi_mem_reg_no; i++, mr++)
-		debugf("    #%d, base = 0x%08x, size = 0x%08x\n", i,
-		    mr->mem_base, mr->mem_size);
-
-	debugf(" eth addresses:\n");
-	eth = (struct bi_eth_addr *)mr;
-	for (i = 0; i < bootinfo->bi_eth_addr_no; i++, eth++) {
-		debugf("    #%d, addr = ", i);
-		for (j = 0; j < 6; j++)
-			debugf("%02x ", eth->mac_addr[j]);
-		debugf("\n");
-	}
-}
-
-void
 print_kernel_section_addr(void)
 {
 
@@ -306,54 +270,29 @@ print_kernel_section_addr(void)
 	debugf(" _end           = 0x%08x\n", (uint32_t)_end);
 }
 
-struct bi_mem_region *
-bootinfo_mr(void)
-{
-
-	return ((struct bi_mem_region *)bootinfo->bi_data);
-}
-
-struct bi_eth_addr *
-bootinfo_eth(void)
-{
-	struct bi_mem_region *mr;
-	struct bi_eth_addr *eth;
-	int i;
-
-	/* Advance to the eth section */
-	mr = bootinfo_mr();
-	for (i = 0; i < bootinfo->bi_mem_reg_no; i++, mr++)
-		;
-
-	eth = (struct bi_eth_addr *)mr;
-	return (eth);
-}
-
 u_int
 e500_init(u_int32_t startkernel, u_int32_t endkernel, void *mdp)
 {
 	struct pcpu *pc;
 	void *kmdp;
-	vm_offset_t end;
+	vm_offset_t dtbp, end;
 	uint32_t csr;
 
 	kmdp = NULL;
 
 	end = endkernel;
+	dtbp = (vm_offset_t)NULL;
 
 	/*
-	 * Parse metadata and fetch parameters. This must be done as the first
-	 * step as we need bootinfo data to at least init the console
+	 * Parse metadata and fetch parameters.
 	 */
 	if (mdp != NULL) {
 		preload_metadata = mdp;
 		kmdp = preload_search_by_type("elf kernel");
 		if (kmdp != NULL) {
-			bootinfo = (struct bootinfo *)preload_search_info(kmdp,
-			    MODINFO_METADATA | MODINFOMD_BOOTINFO);
-
 			boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
 			kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *);
+			dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
 			end = MD_FETCH(kmdp, MODINFOMD_KERNEND, vm_offset_t);
 #ifdef DDB
 			ksym_start = MD_FETCH(kmdp, MODINFOMD_SSYM, uintptr_t);
@@ -362,8 +301,7 @@ e500_init(u_int32_t startkernel, u_int32
 		}
 	} else {
 		/*

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-head mailing list