ChangeSet 1.855.9.15, 2002/11/05 14:59:36-08:00, ch@hpl.hp.com

[PATCH] [PATCH] 2.5.44 sa-1111 ohci hcd

Dereferencing hcd.pdev will always oops with SA-1111.  It has to be
treated as a cookie, not a pointer in any common OHCI HCD code.

Apparently we need a clean way to go from struct device * to struct
ohci_hcd *.  I added dev_to_ohci that does the obvious thing and added
separate implementations for PCI and SA-1111.  Two implementations is
ugly but I didn't think it wise (for me) to hack on the PCI/driverfs
interface, so I just cut & paste the old code.

Two patches.  The first is a diff from linux-2.5.44 and
linux-2.5.44-rmk1.  It is from rmk and adds a struct device pointer to
ohci_hcd.  The second depends on the first and contains my changes to
clean up to the pdev oops problems.  (Some fuzz may occur as I have
ohci-1024 applied.)

With these changes, SA111 OHCI-HC/HCD is showing some signs of life on
linux-2.5.44-rmk1.  usb-storage is currentl blowing chunks, but I think
I saw some patches go by against 2.5.44 that I haven't yet tried.


diff -Nru a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
--- a/drivers/usb/core/hcd.h	Tue Nov  5 16:10:07 2002
+++ b/drivers/usb/core/hcd.h	Tue Nov  5 16:10:07 2002
@@ -77,6 +77,7 @@
 
 	/* a few non-PCI controllers exist, mostly for OHCI */
 	struct pci_dev		*pdev;		/* pci is typical */
+	struct device		*parent;	/* parent device driver */
 #ifdef	CONFIG_PCI
 	int			region;		/* pci region for regs */
 	u32			pci_state [16];	/* for PM state save */
diff -Nru a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
--- a/drivers/usb/host/ohci-dbg.c	Tue Nov  5 16:10:07 2002
+++ b/drivers/usb/host/ohci-dbg.c	Tue Nov  5 16:10:07 2002
@@ -394,15 +394,14 @@
 static ssize_t
 show_async (struct device *dev, char *buf, size_t count, loff_t off)
 {
-	struct pci_dev		*pdev;
 	struct ohci_hcd		*ohci;
 	size_t			temp;
 	unsigned long		flags;
 
 	if (off != 0)
 		return 0;
-	pdev = container_of (dev, struct pci_dev, dev);
-	ohci = container_of (pci_get_drvdata (pdev), struct ohci_hcd, hcd);
+
+	ohci = dev_to_ohci(dev);
 
 	/* display control and bulk lists together, for simplicity */
 	spin_lock_irqsave (&ohci->lock, flags);
@@ -420,7 +419,6 @@
 static ssize_t
 show_periodic (struct device *dev, char *buf, size_t count, loff_t off)
 {
-	struct pci_dev		*pdev;
 	struct ohci_hcd		*ohci;
 	struct ed		**seen, *ed;
 	unsigned long		flags;
@@ -434,8 +432,7 @@
 		return 0;
 	seen_count = 0;
 
-	pdev = container_of (dev, struct pci_dev, dev);
-	ohci = container_of (pci_get_drvdata (pdev), struct ohci_hcd, hcd);
+	ohci = dev_to_ohci(dev);
 	next = buf;
 	size = count;
 
@@ -513,16 +510,16 @@
 
 static inline void create_debug_files (struct ohci_hcd *bus)
 {
-	device_create_file (&bus->hcd.pdev->dev, &dev_attr_async);
-	device_create_file (&bus->hcd.pdev->dev, &dev_attr_periodic);
+	device_create_file (bus->hcd.parent, &dev_attr_async);
+	device_create_file (bus->hcd.parent, &dev_attr_periodic);
 	// registers
 	dbg ("%s: created debug files", bus->hcd.self.bus_name);
 }
 
 static inline void remove_debug_files (struct ohci_hcd *bus)
 {
-	device_remove_file (&bus->hcd.pdev->dev, &dev_attr_async);
-	device_remove_file (&bus->hcd.pdev->dev, &dev_attr_periodic);
+	device_remove_file (bus->hcd.parent, &dev_attr_async);
+	device_remove_file (bus->hcd.parent, &dev_attr_periodic);
 }
 
 #else /* empty stubs for creating those files */
diff -Nru a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
--- a/drivers/usb/host/ohci-pci.c	Tue Nov  5 16:10:07 2002
+++ b/drivers/usb/host/ohci-pci.c	Tue Nov  5 16:10:07 2002
@@ -29,6 +29,17 @@
 
 /*-------------------------------------------------------------------------*/
 
+struct ohci_hcd *dev_to_ohci(struct device *dev) {
+	struct pci_dev *pdev = 
+		container_of (dev, struct pci_dev, dev);
+	struct ohci_hcd	*ohci = 
+		container_of (pci_get_drvdata (pdev), struct ohci_hcd, hcd);
+
+	return ohci;
+}
+
+/*-------------------------------------------------------------------------*/
+
 static int __devinit
 ohci_pci_start (struct usb_hcd *hcd)
 {
diff -Nru a/drivers/usb/host/ohci-sa1111.c b/drivers/usb/host/ohci-sa1111.c
--- a/drivers/usb/host/ohci-sa1111.c	Tue Nov  5 16:10:07 2002
+++ b/drivers/usb/host/ohci-sa1111.c	Tue Nov  5 16:10:07 2002
@@ -27,6 +27,14 @@
 
 /*-------------------------------------------------------------------------*/
 
+struct ohci_hcd *dev_to_ohci(struct device *dev) {
+	struct usb_hcd *hcd = dev->driver_data;
+
+	return hcd_to_ohci(hcd);
+}
+
+/*-------------------------------------------------------------------------*/
+
 static void sa1111_start_hc(struct sa1111_dev *dev)
 {
 	unsigned int usb_rst = 0;
@@ -120,7 +128,7 @@
 	}
 #endif
 
-	usb_hcd_irq(irq, __hcd, r);
+	usb_hcd_irq(irq, hcd, r);
 }
 
 /*-------------------------------------------------------------------------*/
diff -Nru a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
--- a/drivers/usb/host/ohci.h	Tue Nov  5 16:10:07 2002
+++ b/drivers/usb/host/ohci.h	Tue Nov  5 16:10:07 2002
@@ -400,3 +400,4 @@
 
 #define hcd_to_ohci(hcd_ptr) container_of(hcd_ptr, struct ohci_hcd, hcd)
 
+struct ohci_hcd *dev_to_ohci(struct device *);
