USB: xhci: Fix compile issues with xhci_get_slot_state()
[safe/jmp/linux-2.6] / drivers / usb / host / ehci-dbg.c
index b01efb6..874d200 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2001-2002 by David Brownell
- * 
+ *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
  * Free Software Foundation; either version 2 of the License, or (at your
@@ -27,7 +27,7 @@
 #define ehci_warn(ehci, fmt, args...) \
        dev_warn (ehci_to_hcd(ehci)->self.controller , fmt , ## args )
 
-#ifdef EHCI_VERBOSE_DEBUG
+#ifdef VERBOSE_DEBUG
 #      define vdbg dbg
 #      define ehci_vdbg ehci_dbg
 #else
@@ -43,7 +43,7 @@
  */
 static void dbg_hcs_params (struct ehci_hcd *ehci, char *label)
 {
-       u32     params = readl (&ehci->caps->hcs_params);
+       u32     params = ehci_readl(ehci, &ehci->caps->hcs_params);
 
        ehci_dbg (ehci,
                "%s hcs_params 0x%x dbg=%d%s cc=%d pcc=%d%s%s ports=%d\n",
@@ -52,7 +52,7 @@ static void dbg_hcs_params (struct ehci_hcd *ehci, char *label)
                HCS_INDICATOR (params) ? " ind" : "",
                HCS_N_CC (params),
                HCS_N_PCC (params),
-               HCS_PORTROUTED (params) ? "" : " ordered",
+               HCS_PORTROUTED (params) ? "" : " ordered",
                HCS_PPC (params) ? "" : " !ppc",
                HCS_N_PORTS (params)
                );
@@ -65,7 +65,7 @@ static void dbg_hcs_params (struct ehci_hcd *ehci, char *label)
                for (i = 0; i < HCS_N_PORTS (params); i++) {
                        // FIXME MIPS won't readb() ...
                        byte = readb (&ehci->caps->portroute[(i>>1)]);
-                       sprintf(tmp, "%d ", 
+                       sprintf(tmp, "%d ",
                                ((i & 0x1) ? ((byte)&0xf) : ((byte>>4)&0xf)));
                        strcat(buf, tmp);
                }
@@ -87,24 +87,24 @@ static inline void dbg_hcs_params (struct ehci_hcd *ehci, char *label) {}
  * */
 static void dbg_hcc_params (struct ehci_hcd *ehci, char *label)
 {
-       u32     params = readl (&ehci->caps->hcc_params);
+       u32     params = ehci_readl(ehci, &ehci->caps->hcc_params);
 
        if (HCC_ISOC_CACHE (params)) {
                ehci_dbg (ehci,
-                    "%s hcc_params %04x caching frame %s%s%s\n",
-                    label, params,
-                    HCC_PGM_FRAMELISTLEN (params) ? "256/512/1024" : "1024",
-                    HCC_CANPARK (params) ? " park" : "",
-                    HCC_64BIT_ADDR (params) ? " 64 bit addr" : "");
+                       "%s hcc_params %04x caching frame %s%s%s\n",
+                       label, params,
+                       HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
+                       HCC_CANPARK(params) ? " park" : "",
+                       HCC_64BIT_ADDR(params) ? " 64 bit addr" : "");
        } else {
                ehci_dbg (ehci,
-                    "%s hcc_params %04x thresh %d uframes %s%s%s\n",
-                    label,
-                    params,
-                    HCC_ISOC_THRES (params),
-                    HCC_PGM_FRAMELISTLEN (params) ? "256/512/1024" : "1024",
-                    HCC_CANPARK (params) ? " park" : "",
-                    HCC_64BIT_ADDR (params) ? " 64 bit addr" : "");
+                       "%s hcc_params %04x thresh %d uframes %s%s%s\n",
+                       label,
+                       params,
+                       HCC_ISOC_THRES(params),
+                       HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
+                       HCC_CANPARK(params) ? " park" : "",
+                       HCC_64BIT_ADDR(params) ? " 64 bit addr" : "");
        }
 }
 #else
@@ -115,76 +115,79 @@ static inline void dbg_hcc_params (struct ehci_hcd *ehci, char *label) {}
 
 #ifdef DEBUG
 
-static void __attribute__((__unused__))
+static void __maybe_unused
 dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
 {
-       ehci_dbg (ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
-               le32_to_cpup (&qtd->hw_next),
-               le32_to_cpup (&qtd->hw_alt_next),
-               le32_to_cpup (&qtd->hw_token),
-               le32_to_cpup (&qtd->hw_buf [0]));
+       ehci_dbg(ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
+               hc32_to_cpup(ehci, &qtd->hw_next),
+               hc32_to_cpup(ehci, &qtd->hw_alt_next),
+               hc32_to_cpup(ehci, &qtd->hw_token),
+               hc32_to_cpup(ehci, &qtd->hw_buf [0]));
        if (qtd->hw_buf [1])
-               ehci_dbg (ehci, "  p1=%08x p2=%08x p3=%08x p4=%08x\n",
-                       le32_to_cpup (&qtd->hw_buf [1]),
-                       le32_to_cpup (&qtd->hw_buf [2]),
-                       le32_to_cpup (&qtd->hw_buf [3]),
-                       le32_to_cpup (&qtd->hw_buf [4]));
+               ehci_dbg(ehci, "  p1=%08x p2=%08x p3=%08x p4=%08x\n",
+                       hc32_to_cpup(ehci, &qtd->hw_buf[1]),
+                       hc32_to_cpup(ehci, &qtd->hw_buf[2]),
+                       hc32_to_cpup(ehci, &qtd->hw_buf[3]),
+                       hc32_to_cpup(ehci, &qtd->hw_buf[4]));
 }
 
-static void __attribute__((__unused__))
+static void __maybe_unused
 dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
 {
+       struct ehci_qh_hw *hw = qh->hw;
+
        ehci_dbg (ehci, "%s qh %p n%08x info %x %x qtd %x\n", label,
-               qh, qh->hw_next, qh->hw_info1, qh->hw_info2,
-               qh->hw_current);
-       dbg_qtd ("overlay", ehci, (struct ehci_qtd *) &qh->hw_qtd_next);
+               qh, hw->hw_next, hw->hw_info1, hw->hw_info2, hw->hw_current);
+       dbg_qtd("overlay", ehci, (struct ehci_qtd *) &hw->hw_qtd_next);
 }
 
-static void __attribute__((__unused__))
-dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd) 
+static void __maybe_unused
+dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
 {
        ehci_dbg (ehci, "%s [%d] itd %p, next %08x, urb %p\n",
-               label, itd->frame, itd, le32_to_cpu(itd->hw_next), itd->urb);
+               label, itd->frame, itd, hc32_to_cpu(ehci, itd->hw_next),
+               itd->urb);
        ehci_dbg (ehci,
-               "  trans: %08x %08x %08x %08x %08x %08x %08x %08x\n", 
-               le32_to_cpu(itd->hw_transaction[0]),
-               le32_to_cpu(itd->hw_transaction[1]),
-               le32_to_cpu(itd->hw_transaction[2]),
-               le32_to_cpu(itd->hw_transaction[3]),
-               le32_to_cpu(itd->hw_transaction[4]),
-               le32_to_cpu(itd->hw_transaction[5]),
-               le32_to_cpu(itd->hw_transaction[6]),
-               le32_to_cpu(itd->hw_transaction[7]));
+               "  trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
+               hc32_to_cpu(ehci, itd->hw_transaction[0]),
+               hc32_to_cpu(ehci, itd->hw_transaction[1]),
+               hc32_to_cpu(ehci, itd->hw_transaction[2]),
+               hc32_to_cpu(ehci, itd->hw_transaction[3]),
+               hc32_to_cpu(ehci, itd->hw_transaction[4]),
+               hc32_to_cpu(ehci, itd->hw_transaction[5]),
+               hc32_to_cpu(ehci, itd->hw_transaction[6]),
+               hc32_to_cpu(ehci, itd->hw_transaction[7]));
        ehci_dbg (ehci,
-               "  buf:   %08x %08x %08x %08x %08x %08x %08x\n", 
-               le32_to_cpu(itd->hw_bufp[0]),
-               le32_to_cpu(itd->hw_bufp[1]),
-               le32_to_cpu(itd->hw_bufp[2]),
-               le32_to_cpu(itd->hw_bufp[3]),
-               le32_to_cpu(itd->hw_bufp[4]),
-               le32_to_cpu(itd->hw_bufp[5]),
-               le32_to_cpu(itd->hw_bufp[6]));
+               "  buf:   %08x %08x %08x %08x %08x %08x %08x\n",
+               hc32_to_cpu(ehci, itd->hw_bufp[0]),
+               hc32_to_cpu(ehci, itd->hw_bufp[1]),
+               hc32_to_cpu(ehci, itd->hw_bufp[2]),
+               hc32_to_cpu(ehci, itd->hw_bufp[3]),
+               hc32_to_cpu(ehci, itd->hw_bufp[4]),
+               hc32_to_cpu(ehci, itd->hw_bufp[5]),
+               hc32_to_cpu(ehci, itd->hw_bufp[6]));
        ehci_dbg (ehci, "  index: %d %d %d %d %d %d %d %d\n",
                itd->index[0], itd->index[1], itd->index[2],
                itd->index[3], itd->index[4], itd->index[5],
                itd->index[6], itd->index[7]);
 }
 
-static void __attribute__((__unused__))
-dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd) 
+static void __maybe_unused
+dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd)
 {
        ehci_dbg (ehci, "%s [%d] sitd %p, next %08x, urb %p\n",
-               label, sitd->frame, sitd, le32_to_cpu(sitd->hw_next), sitd->urb);
+               label, sitd->frame, sitd, hc32_to_cpu(ehci, sitd->hw_next),
+               sitd->urb);
        ehci_dbg (ehci,
-               "  addr %08x sched %04x result %08x buf %08x %08x\n", 
-               le32_to_cpu(sitd->hw_fullspeed_ep),
-               le32_to_cpu(sitd->hw_uframe),
-               le32_to_cpu(sitd->hw_results),
-               le32_to_cpu(sitd->hw_buf [0]),
-               le32_to_cpu(sitd->hw_buf [1]));
+               "  addr %08x sched %04x result %08x buf %08x %08x\n",
+               hc32_to_cpu(ehci, sitd->hw_fullspeed_ep),
+               hc32_to_cpu(ehci, sitd->hw_uframe),
+               hc32_to_cpu(ehci, sitd->hw_results),
+               hc32_to_cpu(ehci, sitd->hw_buf[0]),
+               hc32_to_cpu(ehci, sitd->hw_buf[1]));
 }
 
-static int __attribute__((__unused__))
+static int __maybe_unused
 dbg_status_buf (char *buf, unsigned len, const char *label, u32 status)
 {
        return scnprintf (buf, len,
@@ -203,7 +206,7 @@ dbg_status_buf (char *buf, unsigned len, const char *label, u32 status)
                );
 }
 
-static int __attribute__((__unused__))
+static int __maybe_unused
 dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable)
 {
        return scnprintf (buf, len,
@@ -267,28 +270,27 @@ dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status)
                (status & PORT_PEC) ? " PEC" : "",
                (status & PORT_PE) ? " PE" : "",
                (status & PORT_CSC) ? " CSC" : "",
-               (status & PORT_CONNECT) ? " CONNECT" : ""
-           );
+               (status & PORT_CONNECT) ? " CONNECT" : "");
 }
 
 #else
-static inline void __attribute__((__unused__))
+static inline void __maybe_unused
 dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
 {}
 
-static inline int __attribute__((__unused__))
+static inline int __maybe_unused
 dbg_status_buf (char *buf, unsigned len, const char *label, u32 status)
 { return 0; }
 
-static inline int __attribute__((__unused__))
+static inline int __maybe_unused
 dbg_command_buf (char *buf, unsigned len, const char *label, u32 command)
 { return 0; }
 
-static inline int __attribute__((__unused__))
+static inline int __maybe_unused
 dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable)
 { return 0; }
 
-static inline int __attribute__((__unused__))
+static inline int __maybe_unused
 dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status)
 { return 0; }
 
@@ -322,7 +324,44 @@ static inline void remove_debug_files (struct ehci_hcd *bus) { }
 
 #else
 
-/* troubleshooting help: expose state in driverfs */
+/* troubleshooting help: expose state in debugfs */
+
+static int debug_async_open(struct inode *, struct file *);
+static int debug_periodic_open(struct inode *, struct file *);
+static int debug_registers_open(struct inode *, struct file *);
+static int debug_async_open(struct inode *, struct file *);
+static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
+static int debug_close(struct inode *, struct file *);
+
+static const struct file_operations debug_async_fops = {
+       .owner          = THIS_MODULE,
+       .open           = debug_async_open,
+       .read           = debug_output,
+       .release        = debug_close,
+};
+static const struct file_operations debug_periodic_fops = {
+       .owner          = THIS_MODULE,
+       .open           = debug_periodic_open,
+       .read           = debug_output,
+       .release        = debug_close,
+};
+static const struct file_operations debug_registers_fops = {
+       .owner          = THIS_MODULE,
+       .open           = debug_registers_open,
+       .read           = debug_output,
+       .release        = debug_close,
+};
+
+static struct dentry *ehci_debug_root;
+
+struct debug_buffer {
+       ssize_t (*fill_func)(struct debug_buffer *);    /* fill method */
+       struct usb_bus *bus;
+       struct mutex mutex;     /* protect filling of buffer */
+       size_t count;           /* number of characters filled into buffer */
+       char *output_buf;
+       size_t alloc_size;
+};
 
 #define speed_char(info1) ({ char tmp; \
                switch (info1 & (3 << 12)) { \
@@ -332,9 +371,10 @@ static inline void remove_debug_files (struct ehci_hcd *bus) { }
                default: tmp = '?'; break; \
                }; tmp; })
 
-static inline char token_mark (__le32 token)
+static inline char token_mark(struct ehci_hcd *ehci, __hc32 token)
 {
-       __u32 v = le32_to_cpu (token);
+       __u32 v = hc32_to_cpu(ehci, token);
+
        if (v & QTD_STS_ACTIVE)
                return '*';
        if (v & QTD_STS_HALT)
@@ -360,46 +400,49 @@ static void qh_lines (
        unsigned                size = *sizep;
        char                    *next = *nextp;
        char                    mark;
+       __le32                  list_end = EHCI_LIST_END(ehci);
+       struct ehci_qh_hw       *hw = qh->hw;
 
-       if (qh->hw_qtd_next == EHCI_LIST_END)   /* NEC does this */
+       if (hw->hw_qtd_next == list_end)        /* NEC does this */
                mark = '@';
        else
-               mark = token_mark (qh->hw_token);
+               mark = token_mark(ehci, hw->hw_token);
        if (mark == '/') {      /* qh_alt_next controls qh advance? */
-               if ((qh->hw_alt_next & QTD_MASK) == ehci->async->hw_alt_next)
+               if ((hw->hw_alt_next & QTD_MASK(ehci))
+                               == ehci->async->hw->hw_alt_next)
                        mark = '#';     /* blocked */
-               else if (qh->hw_alt_next == EHCI_LIST_END)
+               else if (hw->hw_alt_next == list_end)
                        mark = '.';     /* use hw_qtd_next */
                /* else alt_next points to some other qtd */
        }
-       scratch = le32_to_cpup (&qh->hw_info1);
-       hw_curr = (mark == '*') ? le32_to_cpup (&qh->hw_current) : 0;
+       scratch = hc32_to_cpup(ehci, &hw->hw_info1);
+       hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &hw->hw_current) : 0;
        temp = scnprintf (next, size,
                        "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)",
                        qh, scratch & 0x007f,
                        speed_char (scratch),
                        (scratch >> 8) & 0x000f,
-                       scratch, le32_to_cpup (&qh->hw_info2),
-                       le32_to_cpup (&qh->hw_token), mark,
-                       (__constant_cpu_to_le32 (QTD_TOGGLE) & qh->hw_token)
+                       scratch, hc32_to_cpup(ehci, &hw->hw_info2),
+                       hc32_to_cpup(ehci, &hw->hw_token), mark,
+                       (cpu_to_hc32(ehci, QTD_TOGGLE) & hw->hw_token)
                                ? "data1" : "data0",
-                       (le32_to_cpup (&qh->hw_alt_next) >> 1) & 0x0f);
+                       (hc32_to_cpup(ehci, &hw->hw_alt_next) >> 1) & 0x0f);
        size -= temp;
        next += temp;
 
        /* hc may be modifying the list as we read it ... */
        list_for_each (entry, &qh->qtd_list) {
                td = list_entry (entry, struct ehci_qtd, qtd_list);
-               scratch = le32_to_cpup (&td->hw_token);
+               scratch = hc32_to_cpup(ehci, &td->hw_token);
                mark = ' ';
                if (hw_curr == td->qtd_dma)
                        mark = '*';
-               else if (qh->hw_qtd_next == cpu_to_le32(td->qtd_dma))
+               else if (hw->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma))
                        mark = '+';
                else if (QTD_LENGTH (scratch)) {
-                       if (td->hw_alt_next == ehci->async->hw_alt_next)
+                       if (td->hw_alt_next == ehci->async->hw->hw_alt_next)
                                mark = '#';
-                       else if (td->hw_alt_next != EHCI_LIST_END)
+                       else if (td->hw_alt_next != list_end)
                                mark = '/';
                }
                temp = snprintf (next, size,
@@ -414,9 +457,7 @@ static void qh_lines (
                                (scratch >> 16) & 0x7fff,
                                scratch,
                                td->urb);
-               if (temp < 0)
-                       temp = 0;
-               else if (size < temp)
+               if (size < temp)
                        temp = size;
                size -= temp;
                next += temp;
@@ -425,9 +466,7 @@ static void qh_lines (
        }
 
        temp = snprintf (next, size, "\n");
-       if (temp < 0)
-               temp = 0;
-       else if (size < temp)
+       if (size < temp)
                temp = size;
        size -= temp;
        next += temp;
@@ -437,10 +476,8 @@ done:
        *nextp = next;
 }
 
-static ssize_t
-show_async (struct class_device *class_dev, char *buf)
+static ssize_t fill_async_buffer(struct debug_buffer *buf)
 {
-       struct usb_bus          *bus;
        struct usb_hcd          *hcd;
        struct ehci_hcd         *ehci;
        unsigned long           flags;
@@ -448,13 +485,12 @@ show_async (struct class_device *class_dev, char *buf)
        char                    *next;
        struct ehci_qh          *qh;
 
-       *buf = 0;
-
-       bus = class_get_devdata(class_dev);
-       hcd = bus->hcpriv;
+       hcd = bus_to_hcd(buf->bus);
        ehci = hcd_to_ehci (hcd);
-       next = buf;
-       size = PAGE_SIZE;
+       next = buf->output_buf;
+       size = buf->alloc_size;
+
+       *next = 0;
 
        /* dumps a snapshot of the async schedule.
         * usually empty except for long-term bulk reads, or head.
@@ -473,16 +509,12 @@ show_async (struct class_device *class_dev, char *buf)
        }
        spin_unlock_irqrestore (&ehci->lock, flags);
 
-       return strlen (buf);
+       return strlen(buf->output_buf);
 }
-static CLASS_DEVICE_ATTR (async, S_IRUGO, show_async, NULL);
 
 #define DBG_SCHED_LIMIT 64
-
-static ssize_t
-show_periodic (struct class_device *class_dev, char *buf)
+static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
 {
-       struct usb_bus          *bus;
        struct usb_hcd          *hcd;
        struct ehci_hcd         *ehci;
        unsigned long           flags;
@@ -490,17 +522,16 @@ show_periodic (struct class_device *class_dev, char *buf)
        unsigned                temp, size, seen_count;
        char                    *next;
        unsigned                i;
-       __le32                  tag;
+       __hc32                  tag;
 
-       if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, SLAB_ATOMIC)))
+       if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC)))
                return 0;
        seen_count = 0;
 
-       bus = class_get_devdata(class_dev);
-       hcd = bus->hcpriv;
+       hcd = bus_to_hcd(buf->bus);
        ehci = hcd_to_ehci (hcd);
-       next = buf;
-       size = PAGE_SIZE;
+       next = buf->output_buf;
+       size = buf->alloc_size;
 
        temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size);
        size -= temp;
@@ -514,18 +545,22 @@ show_periodic (struct class_device *class_dev, char *buf)
                p = ehci->pshadow [i];
                if (likely (!p.ptr))
                        continue;
-               tag = Q_NEXT_TYPE (ehci->periodic [i]);
+               tag = Q_NEXT_TYPE(ehci, ehci->periodic [i]);
 
                temp = scnprintf (next, size, "%4d: ", i);
                size -= temp;
                next += temp;
 
                do {
-                       switch (tag) {
+                       struct ehci_qh_hw *hw;
+
+                       switch (hc32_to_cpu(ehci, tag)) {
                        case Q_TYPE_QH:
+                               hw = p.qh->hw;
                                temp = scnprintf (next, size, " qh%d-%04x/%p",
                                                p.qh->period,
-                                               le32_to_cpup (&p.qh->hw_info2)
+                                               hc32_to_cpup(ehci,
+                                                       &hw->hw_info2)
                                                        /* uframe masks */
                                                        & (QH_CMASK | QH_SMASK),
                                                p.qh);
@@ -535,16 +570,18 @@ show_periodic (struct class_device *class_dev, char *buf)
                                for (temp = 0; temp < seen_count; temp++) {
                                        if (seen [temp].ptr != p.ptr)
                                                continue;
-                                       if (p.qh->qh_next.ptr)
+                                       if (p.qh->qh_next.ptr) {
                                                temp = scnprintf (next, size,
                                                        " ...");
-                                       p.ptr = NULL;
+                                               size -= temp;
+                                               next += temp;
+                                       }
                                        break;
                                }
                                /* show more info the first time around */
-                               if (temp == seen_count && p.ptr) {
-                                       u32     scratch = le32_to_cpup (
-                                                       &p.qh->hw_info1);
+                               if (temp == seen_count) {
+                                       u32     scratch = hc32_to_cpup(ehci,
+                                                       &hw->hw_info1);
                                        struct ehci_qtd *qtd;
                                        char            *type = "";
 
@@ -554,7 +591,8 @@ show_periodic (struct class_device *class_dev, char *buf)
                                                        &p.qh->qtd_list,
                                                        qtd_list) {
                                                temp++;
-                                               switch (0x03 & (le32_to_cpu (
+                                               switch (0x03 & (hc32_to_cpu(
+                                                       ehci,
                                                        qtd->hw_token) >> 8)) {
                                                case 0: type = "out"; continue;
                                                case 1: type = "in"; continue;
@@ -576,7 +614,7 @@ show_periodic (struct class_device *class_dev, char *buf)
                                } else
                                        temp = 0;
                                if (p.qh) {
-                                       tag = Q_NEXT_TYPE (p.qh->hw_next);
+                                       tag = Q_NEXT_TYPE(ehci, hw->hw_next);
                                        p = p.qh->qh_next;
                                }
                                break;
@@ -584,23 +622,23 @@ show_periodic (struct class_device *class_dev, char *buf)
                                temp = scnprintf (next, size,
                                        " fstn-%8x/%p", p.fstn->hw_prev,
                                        p.fstn);
-                               tag = Q_NEXT_TYPE (p.fstn->hw_next);
+                               tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next);
                                p = p.fstn->fstn_next;
                                break;
                        case Q_TYPE_ITD:
                                temp = scnprintf (next, size,
                                        " itd/%p", p.itd);
-                               tag = Q_NEXT_TYPE (p.itd->hw_next);
+                               tag = Q_NEXT_TYPE(ehci, p.itd->hw_next);
                                p = p.itd->itd_next;
                                break;
                        case Q_TYPE_SITD:
                                temp = scnprintf (next, size,
                                        " sitd%d-%04x/%p",
                                        p.sitd->stream->interval,
-                                       le32_to_cpup (&p.sitd->hw_uframe)
+                                       hc32_to_cpup(ehci, &p.sitd->hw_uframe)
                                                & 0x0000ffff,
                                        p.sitd);
-                               tag = Q_NEXT_TYPE (p.sitd->hw_next);
+                               tag = Q_NEXT_TYPE(ehci, p.sitd->hw_next);
                                p = p.sitd->sitd_next;
                                break;
                        }
@@ -615,16 +653,12 @@ show_periodic (struct class_device *class_dev, char *buf)
        spin_unlock_irqrestore (&ehci->lock, flags);
        kfree (seen);
 
-       return PAGE_SIZE - size;
+       return buf->alloc_size - size;
 }
-static CLASS_DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL);
-
 #undef DBG_SCHED_LIMIT
 
-static ssize_t
-show_registers (struct class_device *class_dev, char *buf)
+static ssize_t fill_registers_buffer(struct debug_buffer *buf)
 {
-       struct usb_bus          *bus;
        struct usb_hcd          *hcd;
        struct ehci_hcd         *ehci;
        unsigned long           flags;
@@ -633,33 +667,32 @@ show_registers (struct class_device *class_dev, char *buf)
        static char             fmt [] = "%*s\n";
        static char             label [] = "";
 
-       bus = class_get_devdata(class_dev);
-       hcd = bus->hcpriv;
+       hcd = bus_to_hcd(buf->bus);
        ehci = hcd_to_ehci (hcd);
-       next = buf;
-       size = PAGE_SIZE;
+       next = buf->output_buf;
+       size = buf->alloc_size;
 
        spin_lock_irqsave (&ehci->lock, flags);
 
-       if (bus->controller->power.power_state) {
+       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
                size = scnprintf (next, size,
-                       "bus %s, device %s (driver " DRIVER_VERSION ")\n"
+                       "bus %s, device %s\n"
                        "%s\n"
                        "SUSPENDED (no register access)\n",
                        hcd->self.controller->bus->name,
-                       hcd->self.controller->bus_id,
+                       dev_name(hcd->self.controller),
                        hcd->product_desc);
                goto done;
        }
 
        /* Capability Registers */
-       i = HC_VERSION(readl (&ehci->caps->hc_capbase));
+       i = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase));
        temp = scnprintf (next, size,
-               "bus %s, device %s (driver " DRIVER_VERSION ")\n"
+               "bus %s, device %s\n"
                "%s\n"
                "EHCI %x.%02x, hcd state %d\n",
                hcd->self.controller->bus->name,
-               hcd->self.controller->bus_id,
+               dev_name(hcd->self.controller),
                hcd->product_desc,
                i >> 8, i & 0x0ff, hcd->state);
        size -= temp;
@@ -673,7 +706,8 @@ show_registers (struct class_device *class_dev, char *buf)
                unsigned        count = 256/4;
 
                pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
-               offset = HCC_EXT_CAPS (readl (&ehci->caps->hcc_params));
+               offset = HCC_EXT_CAPS(ehci_readl(ehci,
+                               &ehci->caps->hcc_params));
                while (offset && count--) {
                        pci_read_config_dword (pdev, offset, &cap);
                        switch (cap & 0xff) {
@@ -704,59 +738,59 @@ show_registers (struct class_device *class_dev, char *buf)
 #endif
 
        // FIXME interpret both types of params
-       i = readl (&ehci->caps->hcs_params);
+       i = ehci_readl(ehci, &ehci->caps->hcs_params);
        temp = scnprintf (next, size, "structural params 0x%08x\n", i);
        size -= temp;
        next += temp;
 
-       i = readl (&ehci->caps->hcc_params);
+       i = ehci_readl(ehci, &ehci->caps->hcc_params);
        temp = scnprintf (next, size, "capability params 0x%08x\n", i);
        size -= temp;
        next += temp;
 
        /* Operational Registers */
        temp = dbg_status_buf (scratch, sizeof scratch, label,
-                       readl (&ehci->regs->status));
+                       ehci_readl(ehci, &ehci->regs->status));
        temp = scnprintf (next, size, fmt, temp, scratch);
        size -= temp;
        next += temp;
 
        temp = dbg_command_buf (scratch, sizeof scratch, label,
-                       readl (&ehci->regs->command));
+                       ehci_readl(ehci, &ehci->regs->command));
        temp = scnprintf (next, size, fmt, temp, scratch);
        size -= temp;
        next += temp;
 
        temp = dbg_intr_buf (scratch, sizeof scratch, label,
-                       readl (&ehci->regs->intr_enable));
+                       ehci_readl(ehci, &ehci->regs->intr_enable));
        temp = scnprintf (next, size, fmt, temp, scratch);
        size -= temp;
        next += temp;
 
        temp = scnprintf (next, size, "uframe %04x\n",
-                       readl (&ehci->regs->frame_index));
+                       ehci_readl(ehci, &ehci->regs->frame_index));
        size -= temp;
        next += temp;
 
        for (i = 1; i <= HCS_N_PORTS (ehci->hcs_params); i++) {
                temp = dbg_port_buf (scratch, sizeof scratch, label, i,
-                               readl (&ehci->regs->port_status [i - 1]));
+                               ehci_readl(ehci,
+                                       &ehci->regs->port_status[i - 1]));
                temp = scnprintf (next, size, fmt, temp, scratch);
                size -= temp;
                next += temp;
                if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) {
                        temp = scnprintf (next, size,
                                        "    debug control %08x\n",
-                                       readl (&ehci->debug->control));
+                                       ehci_readl(ehci,
+                                               &ehci->debug->control));
                        size -= temp;
                        next += temp;
                }
        }
 
        if (ehci->reclaim) {
-               temp = scnprintf (next, size, "reclaim qh %p%s\n",
-                               ehci->reclaim,
-                               ehci->reclaim_ready ? " ready" : "");
+               temp = scnprintf(next, size, "reclaim qh %p\n", ehci->reclaim);
                size -= temp;
                next += temp;
        }
@@ -778,27 +812,156 @@ show_registers (struct class_device *class_dev, char *buf)
 done:
        spin_unlock_irqrestore (&ehci->lock, flags);
 
-       return PAGE_SIZE - size;
+       return buf->alloc_size - size;
 }
-static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
 
-static inline void create_debug_files (struct ehci_hcd *ehci)
+static struct debug_buffer *alloc_buffer(struct usb_bus *bus,
+                               ssize_t (*fill_func)(struct debug_buffer *))
 {
-       struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev;
+       struct debug_buffer *buf;
+
+       buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
 
-       class_device_create_file(cldev, &class_device_attr_async);
-       class_device_create_file(cldev, &class_device_attr_periodic);
-       class_device_create_file(cldev, &class_device_attr_registers);
+       if (buf) {
+               buf->bus = bus;
+               buf->fill_func = fill_func;
+               mutex_init(&buf->mutex);
+               buf->alloc_size = PAGE_SIZE;
+       }
+
+       return buf;
 }
 
-static inline void remove_debug_files (struct ehci_hcd *ehci)
+static int fill_buffer(struct debug_buffer *buf)
 {
-       struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev;
+       int ret = 0;
 
-       class_device_remove_file(cldev, &class_device_attr_async);
-       class_device_remove_file(cldev, &class_device_attr_periodic);
-       class_device_remove_file(cldev, &class_device_attr_registers);
+       if (!buf->output_buf)
+               buf->output_buf = (char *)vmalloc(buf->alloc_size);
+
+       if (!buf->output_buf) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ret = buf->fill_func(buf);
+
+       if (ret >= 0) {
+               buf->count = ret;
+               ret = 0;
+       }
+
+out:
+       return ret;
 }
 
-#endif /* STUB_DEBUG_FILES */
+static ssize_t debug_output(struct file *file, char __user *user_buf,
+                           size_t len, loff_t *offset)
+{
+       struct debug_buffer *buf = file->private_data;
+       int ret = 0;
+
+       mutex_lock(&buf->mutex);
+       if (buf->count == 0) {
+               ret = fill_buffer(buf);
+               if (ret != 0) {
+                       mutex_unlock(&buf->mutex);
+                       goto out;
+               }
+       }
+       mutex_unlock(&buf->mutex);
 
+       ret = simple_read_from_buffer(user_buf, len, offset,
+                                     buf->output_buf, buf->count);
+
+out:
+       return ret;
+
+}
+
+static int debug_close(struct inode *inode, struct file *file)
+{
+       struct debug_buffer *buf = file->private_data;
+
+       if (buf) {
+               vfree(buf->output_buf);
+               kfree(buf);
+       }
+
+       return 0;
+}
+static int debug_async_open(struct inode *inode, struct file *file)
+{
+       file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
+
+       return file->private_data ? 0 : -ENOMEM;
+}
+
+static int debug_periodic_open(struct inode *inode, struct file *file)
+{
+       struct debug_buffer *buf;
+       buf = alloc_buffer(inode->i_private, fill_periodic_buffer);
+       if (!buf)
+               return -ENOMEM;
+
+       buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8)*PAGE_SIZE;
+       file->private_data = buf;
+       return 0;
+}
+
+static int debug_registers_open(struct inode *inode, struct file *file)
+{
+       file->private_data = alloc_buffer(inode->i_private,
+                                         fill_registers_buffer);
+
+       return file->private_data ? 0 : -ENOMEM;
+}
+
+static inline void create_debug_files (struct ehci_hcd *ehci)
+{
+       struct usb_bus *bus = &ehci_to_hcd(ehci)->self;
+
+       ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root);
+       if (!ehci->debug_dir)
+               goto dir_error;
+
+       ehci->debug_async = debugfs_create_file("async", S_IRUGO,
+                                               ehci->debug_dir, bus,
+                                               &debug_async_fops);
+       if (!ehci->debug_async)
+               goto async_error;
+
+       ehci->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
+                                                  ehci->debug_dir, bus,
+                                                  &debug_periodic_fops);
+       if (!ehci->debug_periodic)
+               goto periodic_error;
+
+       ehci->debug_registers = debugfs_create_file("registers", S_IRUGO,
+                                                   ehci->debug_dir, bus,
+                                                   &debug_registers_fops);
+       if (!ehci->debug_registers)
+               goto registers_error;
+       return;
+
+registers_error:
+       debugfs_remove(ehci->debug_periodic);
+periodic_error:
+       debugfs_remove(ehci->debug_async);
+async_error:
+       debugfs_remove(ehci->debug_dir);
+dir_error:
+       ehci->debug_periodic = NULL;
+       ehci->debug_async = NULL;
+       ehci->debug_dir = NULL;
+}
+
+static inline void remove_debug_files (struct ehci_hcd *ehci)
+{
+       debugfs_remove(ehci->debug_registers);
+       debugfs_remove(ehci->debug_periodic);
+       debugfs_remove(ehci->debug_async);
+       debugfs_remove(ehci->debug_dir);
+}
+
+#endif /* STUB_DEBUG_FILES */