svn commit: r204577 - in head/sys/mips: include rmi

Randall Stewart rrs at FreeBSD.org
Tue Mar 2 12:11:00 UTC 2010


Author: rrs
Date: Tue Mar  2 12:11:00 2010
New Revision: 204577
URL: http://svn.freebsd.org/changeset/base/204577

Log:
  - Move rmi_pci_bus_space to header and avoid extern
  - remove unused and commented code (MIPS_BUS_SPACE_PCI, pic_usb_ack)
  - use rmi_pci_bus_space for USB too (needs byteswap)
  - uncomment xls_ehci.c in files.xlr
  - changes to xls_ehci.c - updated with dev/usb/controller/ehci_*.c as
  
  Obtained from:	JC - c.jayachandran at gmail.com

Modified:
  head/sys/mips/include/bus.h
  head/sys/mips/rmi/files.xlr
  head/sys/mips/rmi/iodi.c
  head/sys/mips/rmi/xlr_pci.c
  head/sys/mips/rmi/xls_ehci.c

Modified: head/sys/mips/include/bus.h
==============================================================================
--- head/sys/mips/include/bus.h	Tue Mar  2 11:02:59 2010	(r204576)
+++ head/sys/mips/include/bus.h	Tue Mar  2 12:11:00 2010	(r204577)
@@ -721,6 +721,7 @@ extern bus_space_tag_t mips_bus_space_ge
 /* Special bus space for RMI processors */
 #ifdef TARGET_XLR_XLS
 extern bus_space_tag_t rmi_bus_space;
+extern bus_space_tag_t rmi_pci_bus_space;
 #endif
 
 #include <machine/bus_dma.h>

Modified: head/sys/mips/rmi/files.xlr
==============================================================================
--- head/sys/mips/rmi/files.xlr	Tue Mar  2 11:02:59 2010	(r204576)
+++ head/sys/mips/rmi/files.xlr	Tue Mar  2 12:11:00 2010	(r204577)
@@ -15,7 +15,7 @@ mips/rmi/uart_cpu_mips_xlr.c			optional 
 mips/rmi/perfmon_kern.c				optional xlr_perfmon
 mips/rmi/perfmon_percpu.c			optional xlr_perfmon
 mips/rmi/xlr_pci.c				optional pci
-#mips/rmi/xls_ehci.c				optional usb ehci
+mips/rmi/xls_ehci.c				optional usb ehci
 mips/rmi/bus_space_rmi.c			standard
 mips/rmi/bus_space_rmi_pci.c			optional pci
 mips/rmi/dev/sec/rmisec.c			optional rmisec

Modified: head/sys/mips/rmi/iodi.c
==============================================================================
--- head/sys/mips/rmi/iodi.c	Tue Mar  2 11:02:59 2010	(r204576)
+++ head/sys/mips/rmi/iodi.c	Tue Mar  2 12:11:00 2010	(r204577)
@@ -74,8 +74,6 @@ __FBSDID("$FreeBSD$");
 #include <mips/rmi/dev/xlr/atx_cpld.h>
 #include <mips/rmi/dev/xlr/xgmac_mdio.h>
 
-extern void iodi_activateirqs(void);
-
 extern bus_space_tag_t uart_bus_space_mem;
 
 static struct resource *
@@ -91,19 +89,6 @@ iodi_setup_intr(device_t, device_t, stru
 
 struct iodi_softc *iodi_softc;	/* There can be only one. */
 
-/*
-static void pic_usb_ack(void *arg)
-{
-	xlr_reg_t *mmio = xlr_io_mmio(XLR_IO_PIC_OFFSET);
-	int irq = PIC_USB_IRQ ;
-
-	mtx_lock_spin(&xlr_pic_lock);
-	xlr_write_reg(mmio, PIC_INT_ACK, (1 << (irq - PIC_IRQ_BASE)));
-	mtx_unlock_spin(&xlr_pic_lock);
-}
-*/
-
-
 static int
 iodi_setup_intr(device_t dev, device_t child,
     struct resource *ires, int flags, driver_filter_t * filt, driver_intr_t * intr, void *arg,
@@ -157,11 +142,6 @@ iodi_setup_intr(device_t dev, device_t c
 	return (0);
 }
 
-/* Strange hook found in mips/include/bus.h */
-#ifndef MIPS_BUS_SPACE_PCI
-#define MIPS_BUS_SPACE_PCI	10
-#endif
-
 static struct resource *
 iodi_alloc_resource(device_t bus, device_t child, int type, int *rid,
     u_long start, u_long end, u_long count, u_int flags)
@@ -199,7 +179,7 @@ iodi_alloc_resource(device_t bus, device
 		res->r_bustag = uart_bus_space_mem;
 	} else if (strcmp(device_get_name(child), "ehci") == 0) {
 		res->r_bushandle = 0xbef24000;
-		res->r_bustag = (bus_space_tag_t) MIPS_BUS_SPACE_PCI;
+		res->r_bustag = rmi_pci_bus_space;
 	} else if (strcmp(device_get_name(child), "cfi") == 0) {
 		res->r_bushandle = 0xbc000000;
 		res->r_bustag = 0;

Modified: head/sys/mips/rmi/xlr_pci.c
==============================================================================
--- head/sys/mips/rmi/xlr_pci.c	Tue Mar  2 11:02:59 2010	(r204576)
+++ head/sys/mips/rmi/xlr_pci.c	Tue Mar  2 12:11:00 2010	(r204577)
@@ -115,7 +115,6 @@ struct xlr_pcib_softc {
 	int junk;		/* no softc */
 };
 
-extern bus_space_tag_t rmi_pci_bus_space;
 static devclass_t pcib_devclass;
 static void *xlr_pci_config_base;
 static struct rman irq_rman, port_rman, mem_rman;

Modified: head/sys/mips/rmi/xls_ehci.c
==============================================================================
--- head/sys/mips/rmi/xls_ehci.c	Tue Mar  2 11:02:59 2010	(r204576)
+++ head/sys/mips/rmi/xls_ehci.c	Tue Mar  2 12:11:00 2010	(r204577)
@@ -38,58 +38,50 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-/*
- * USB Enhanced Host Controller Driver, a.k.a. USB 2.0 controller.
- *
- * The EHCI 1.0 spec can be found at
- * http://developer.intel.com/technology/usb/download/ehci-r10.pdf
- * and the USB 2.0 spec at
- * http://www.usb.org/developers/docs/usb_20.zip
- */
-
-/* The low level controller code for EHCI has been split into
- * PCI probes and EHCI specific code. This was done to facilitate the
- * sharing of code between *BSD's
- */
-
 #include "opt_bus.h"
 
+#include <sys/stdint.h>
+#include <sys/stddef.h>
 #include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/types.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
-#include <sys/module.h>
 #include <sys/bus.h>
-#include <sys/queue.h>
+#include <sys/linker_set.h>
+#include <sys/module.h>
 #include <sys/lock.h>
-#include <sys/lockmgr.h>
-#include <machine/bus.h>
+#include <sys/mutex.h>
+#include <sys/condvar.h>
+#include <sys/sysctl.h>
+#include <sys/sx.h>
+#include <sys/unistd.h>
+#include <sys/callout.h>
+#include <sys/malloc.h>
+#include <sys/priv.h>
+
 #include <sys/rman.h>
 #include <machine/resource.h>
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
-/*#include <dev/usb/usbdivar.h>  */
-/*#include <dev/usb/usb_mem.h>   */
-
-#include <mips/rmi/ehcireg.h>
-#include <mips/rmi/ehcivar.h>
 
-#ifdef USB_DEBUG
-#define EHCI_DEBUG USB_DEBUG
-#define DPRINTF(x)	do { if (ehcidebug) logprintf x; } while (0)
-extern int ehcidebug;
-
-#else
-#define DPRINTF(x)
-#endif
+#include <dev/usb/usb_core.h>
+#include <dev/usb/usb_busdma.h>
+#include <dev/usb/usb_process.h>
+#include <dev/usb/usb_util.h>
+
+#include <dev/usb/usb_controller.h>
+#include <dev/usb/usb_bus.h>
+#include <dev/usb/controller/ehci.h>
+#include <dev/usb/controller/ehcireg.h>
+#include <mips/rmi/pic.h>
 
 static int ehci_xls_attach(device_t self);
 static int ehci_xls_detach(device_t self);
 static int ehci_xls_shutdown(device_t self);
 static int ehci_xls_suspend(device_t self);
 static int ehci_xls_resume(device_t self);
-static void ehci_xls_givecontroller(device_t self);
-static void ehci_xls_takecontroller(device_t self);
 
 static int
 ehci_xls_suspend(device_t self)
@@ -100,9 +92,8 @@ ehci_xls_suspend(device_t self)
 	err = bus_generic_suspend(self);
 	if (err)
 		return (err);
-	ehci_power(PWR_SUSPEND, sc);
-
-	return 0;
+	ehci_suspend(sc);
+	return (0);
 }
 
 static int
@@ -110,11 +101,11 @@ ehci_xls_resume(device_t self)
 {
 	ehci_softc_t *sc = device_get_softc(self);
 
-	ehci_xls_takecontroller(self);
-	ehci_power(PWR_RESUME, sc);
+	ehci_resume(sc);
+
 	bus_generic_resume(self);
 
-	return 0;
+	return (0);
 }
 
 static int
@@ -127,18 +118,16 @@ ehci_xls_shutdown(device_t self)
 	if (err)
 		return (err);
 	ehci_shutdown(sc);
-	ehci_xls_givecontroller(self);
 
-	return 0;
+	return (0);
 }
 
-
 static const char *xlr_usb_dev_desc = "RMI XLR USB 2.0 controller";
 static const char *xlr_vendor_desc = "RMI Corp";
+
 static int
 ehci_xls_probe(device_t self)
 {
-
 	/* TODO see if usb is enabled on the board */
 	device_set_desc(self, xlr_usb_dev_desc);
 	return BUS_PROBE_DEFAULT;
@@ -148,132 +137,125 @@ static int
 ehci_xls_attach(device_t self)
 {
 	ehci_softc_t *sc = device_get_softc(self);
-	device_t parent;
-	device_t *neighbors;
 	int err;
 	int rid;
-	int count;
-	int res;
 
-
-	sc->sc_bus.usbrev = USBREV_2_0;
+	sc->sc_bus.parent = self;
+	sc->sc_bus.devices = sc->sc_devices;
+	sc->sc_bus.devices_max = EHCI_MAX_DEVICES;
+
+	/* get all DMA memory */
+	if (usb_bus_mem_alloc_all(&sc->sc_bus,
+	    USB_GET_DMA_TAG(self), &ehci_iterate_hw_softc)) {
+		return (ENOMEM);
+	}
 
 	rid = 0;
-	sc->io_res = bus_alloc_resource(self, SYS_RES_MEMORY, &rid,
-	    0ul, ~0ul, 0x400, RF_ACTIVE);
-	if (!sc->io_res) {
+	sc->sc_io_res = bus_alloc_resource_any(self, SYS_RES_MEMORY, &rid,
+	    RF_ACTIVE);
+	if (!sc->sc_io_res) {
 		device_printf(self, "Could not map memory\n");
-		return ENXIO;
+		goto error;
 	}
-	sc->iot = rman_get_bustag(sc->io_res);
-	sc->ioh = rman_get_bushandle(sc->io_res);
+	sc->sc_io_tag = rman_get_bustag(sc->sc_io_res);
+	sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res);
+	printf("IO Resource tag %lx, hdl %lx, size %lx\n",
+	       (u_long)sc->sc_io_tag, (u_long)sc->sc_io_hdl, 
+	       (u_long)sc->sc_io_size);
 
 	rid = 0;
-	sc->irq_res = bus_alloc_resource(self, SYS_RES_IRQ, &rid,
-	    39, 39, 1, RF_SHAREABLE | RF_ACTIVE);
-	if (sc->irq_res == NULL) {
+	sc->sc_irq_res = bus_alloc_resource(self, SYS_RES_IRQ, &rid,
+	    PIC_USB_IRQ, PIC_USB_IRQ, 1, RF_SHAREABLE | RF_ACTIVE);
+	if (sc->sc_irq_res == NULL) {
 		device_printf(self, "Could not allocate irq\n");
-		ehci_xls_detach(self);
-		return ENXIO;
+		goto error;
 	}
-	sc->sc_bus.bdev = device_add_child(self, "usb", -1);
+
+	sc->sc_bus.bdev = device_add_child(self, "usbus", -1);
 	if (!sc->sc_bus.bdev) {
 		device_printf(self, "Could not add USB device\n");
-		ehci_xls_detach(self);
-		return ENOMEM;
+		goto error;
 	}
 	device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
-
-	/* ehci_pci_match will never return NULL if ehci_pci_probe succeeded */
 	device_set_desc(sc->sc_bus.bdev, xlr_usb_dev_desc);
+
 	sprintf(sc->sc_vendor, xlr_vendor_desc);
 
-	err = bus_setup_intr(self, sc->irq_res, INTR_TYPE_BIO,
-	    (driver_intr_t *) ehci_intr, sc, &sc->ih);
+	err = bus_setup_intr(self, sc->sc_irq_res,
+	    INTR_TYPE_BIO | INTR_MPSAFE, NULL,
+	    (driver_intr_t *) ehci_interrupt, sc, &sc->sc_intr_hdl);
 	if (err) {
 		device_printf(self, "Could not setup irq, %d\n", err);
-		sc->ih = NULL;
-		ehci_xls_detach(self);
-		return ENXIO;
+		sc->sc_intr_hdl = NULL;
+		goto error;
 	}
-	/*
-	 * Find companion controllers.  According to the spec they always
-	 * have lower function numbers so they should be enumerated already.
-	 */
-	parent = device_get_parent(self);
-	res = device_get_children(parent, &neighbors, &count);
-	if (res != 0) {
-		device_printf(self, "Error finding companion busses\n");
-		ehci_xls_detach(self);
-		return ENXIO;
-	}
-	sc->sc_ncomp = 0;
 
-	ehci_xls_takecontroller(self);
 	err = ehci_init(sc);
-	if (!err) {
-		sc->sc_flags |= EHCI_SCFLG_DONEINIT;
-		err = device_probe_and_attach(sc->sc_bus.bdev);
-	}
 	if (err) {
 		device_printf(self, "USB init failed err=%d\n", err);
-		ehci_xls_detach(self);
-		return EIO;
+		goto error;
 	}
-	return 0;
+
+	err = device_probe_and_attach(sc->sc_bus.bdev);
+	if (err) {
+		device_printf(self, "USB probe and attach failed err=%d\n", err);
+		goto error;
+	}
+
+	return (0);
+
+error:
+	ehci_xls_detach(self);
+	return (ENXIO);
 }
 
 static int
 ehci_xls_detach(device_t self)
 {
 	ehci_softc_t *sc = device_get_softc(self);
+	device_t bdev;
+	int err;
 
-	if (sc->sc_flags & EHCI_SCFLG_DONEINIT) {
-		ehci_detach(sc, 0);
-		sc->sc_flags &= ~EHCI_SCFLG_DONEINIT;
+ 	if (sc->sc_bus.bdev) {
+		bdev = sc->sc_bus.bdev;
+		device_detach(bdev);
+		device_delete_child(self, bdev);
 	}
+	/* during module unload there are lots of children leftover */
+	device_delete_all_children(self);
+
 	/*
 	 * disable interrupts that might have been switched on in ehci_init
 	 */
-	if (sc->iot && sc->ioh)
-		bus_space_write_4(sc->iot, sc->ioh, EHCI_USBINTR, 0);
+	if (sc->sc_io_res) {
+		EWRITE4(sc, EHCI_USBINTR, 0);
+	}
 
-	if (sc->irq_res && sc->ih) {
-		int err = bus_teardown_intr(self, sc->irq_res, sc->ih);
+	if (sc->sc_irq_res && sc->sc_intr_hdl) {
+		ehci_detach(sc);
 
+		err = bus_teardown_intr(self, sc->sc_irq_res, sc->sc_intr_hdl);
 		if (err)
-			/* XXX or should we panic? */
 			device_printf(self, "Could not tear down irq, %d\n",
 			    err);
-		sc->ih = NULL;
+		sc->sc_intr_hdl = 0;
 	}
-	if (sc->sc_bus.bdev) {
-		device_delete_child(self, sc->sc_bus.bdev);
-		sc->sc_bus.bdev = NULL;
-	}
-	if (sc->irq_res) {
-		bus_release_resource(self, SYS_RES_IRQ, 0, sc->irq_res);
-		sc->irq_res = NULL;
-	}
-	if (sc->io_res) {
-		bus_release_resource(self, SYS_RES_MEMORY, PCI_CBMEM, sc->io_res);
-		sc->io_res = NULL;
-		sc->iot = 0;
-		sc->ioh = 0;
+
+	if (sc->sc_irq_res) {
+		bus_release_resource(self, SYS_RES_IRQ, 0, sc->sc_irq_res);
+		sc->sc_irq_res = NULL;
+	}
+	if (sc->sc_io_res) {
+		bus_release_resource(self, SYS_RES_MEMORY, 0,
+		    sc->sc_io_res);
+		sc->sc_io_res = NULL;
+		sc->sc_io_tag = 0;
+		sc->sc_io_hdl = 0;
 	}
-	return 0;
-}
 
-static void
-ehci_xls_takecontroller(device_t self)
-{
-	//device_printf(self, "In func %s\n", __func__);
-}
+	usb_bus_mem_free_all(&sc->sc_bus, &ehci_iterate_hw_softc);
 
-static void
-ehci_xls_givecontroller(device_t self)
-{
-	//device_printf(self, "In func %s\n", __func__);
+	return (0);
 }
 
 static device_method_t ehci_methods[] = {
@@ -294,10 +276,10 @@ static device_method_t ehci_methods[] = 
 static driver_t ehci_driver = {
 	"ehci",
 	ehci_methods,
-	sizeof(ehci_softc_t),
+	sizeof(struct ehci_softc),
 };
 
 static devclass_t ehci_devclass;
 
 DRIVER_MODULE(ehci, iodi, ehci_driver, ehci_devclass, 0, 0);
-/* DRIVER_MODULE(ehci, cardbus, ehci_driver, ehci_devclass, 0, 0); */
+MODULE_DEPEND(ehci, usb, 1, 1, 1);


More information about the svn-src-head mailing list