lua: Fixed some cross-platform issues for PPC (and probably other architectures)
[openwrt.git] / target / linux / adm5120 / files / drivers / usb / host / adm5120-dbg.c
index 7a0c73c..a6eb67c 100644 (file)
@@ -1,10 +1,16 @@
 /*
 /*
- * OHCI HCD (Host Controller Driver) for USB.
+ * ADM5120 HCD (Host Controller Driver) for USB
  *
  *
- * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
- * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
+ * Copyright (C) 2007,2008 Gabor Juhos <juhosg at openwrt.org>
+ *
+ * This file was derived from: drivers/usb/host/ohci-dbg.c
+ *   (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
+ *   (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License version 2 as published
+ *  by the Free Software Foundation.
  *
  *
- * This file is licenced under the GPL.
  */
 
 /*-------------------------------------------------------------------------*/
  */
 
 /*-------------------------------------------------------------------------*/
@@ -33,8 +39,6 @@ static inline char *ed_statestring(int state)
                return "UNLINK";
        case ED_OPER:
                return "OPER";
                return "UNLINK";
        case ED_OPER:
                return "OPER";
-       case ED_NEW:
-               return "NEW";
        }
        return "?STATE";
 }
        }
        return "?STATE";
 }
@@ -70,13 +74,15 @@ static inline char *td_togglestring(u32 info)
        return "?TOGGLE";
 }
 
        return "?TOGGLE";
 }
 
+/*-------------------------------------------------------------------------*/
+
 #ifdef DEBUG
 
 /* debug| print the main components of an URB
  * small: 0) header + data packets 1) just header
  */
 static void __attribute__((unused))
 #ifdef DEBUG
 
 /* debug| print the main components of an URB
  * small: 0) header + data packets 1) just header
  */
 static void __attribute__((unused))
-urb_print(struct admhcd *ahcd, struct urb * urb, char * str, int small)
+urb_print(struct admhcd *ahcd, struct urb *urb, char *str, int small, int status)
 {
        unsigned int pipe = urb->pipe;
 
 {
        unsigned int pipe = urb->pipe;
 
@@ -86,40 +92,40 @@ urb_print(struct admhcd *ahcd, struct urb * urb, char * str, int small)
        }
 
 #ifndef        ADMHC_VERBOSE_DEBUG
        }
 
 #ifndef        ADMHC_VERBOSE_DEBUG
-       if (urb->status != 0)
+       if (status != 0)
 #endif
        admhc_dbg(ahcd, "URB-%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d "
                        "stat=%d\n",
                        str,
                        urb,
 #endif
        admhc_dbg(ahcd, "URB-%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d "
                        "stat=%d\n",
                        str,
                        urb,
-                       usb_pipedevice(pipe),
-                       usb_pipeendpoint(pipe),
+                       usb_pipedevice (pipe),
+                       usb_pipeendpoint (pipe),
                        usb_pipeout(pipe)? "out" : "in",
                        pipestring(pipe),
                        urb->transfer_flags,
                        urb->actual_length,
                        urb->transfer_buffer_length,
                        usb_pipeout(pipe)? "out" : "in",
                        pipestring(pipe),
                        urb->transfer_flags,
                        urb->actual_length,
                        urb->transfer_buffer_length,
-                       urb->status);
+                       status);
 
 #ifdef ADMHC_VERBOSE_DEBUG
        if (!small) {
                int i, len;
 
                if (usb_pipecontrol(pipe)) {
 
 #ifdef ADMHC_VERBOSE_DEBUG
        if (!small) {
                int i, len;
 
                if (usb_pipecontrol(pipe)) {
-                       admhc_dbg(admhc, "setup(8): ");
+                       admhc_dbg(ahcd, "setup(8):");
                        for (i = 0; i < 8 ; i++)
                                printk (" %02x", ((__u8 *) urb->setup_packet) [i]);
                        printk ("\n");
                }
                if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) {
                        for (i = 0; i < 8 ; i++)
                                printk (" %02x", ((__u8 *) urb->setup_packet) [i]);
                        printk ("\n");
                }
                if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) {
-                       admhc_dbg(admhc, "data(%d/%d): ",
+                       admhc_dbg(ahcd, "data(%d/%d):",
                                urb->actual_length,
                                urb->transfer_buffer_length);
                        len = usb_pipeout(pipe)?
                                                urb->transfer_buffer_length: urb->actual_length;
                        for (i = 0; i < 16 && i < len; i++)
                                urb->actual_length,
                                urb->transfer_buffer_length);
                        len = usb_pipeout(pipe)?
                                                urb->transfer_buffer_length: urb->actual_length;
                        for (i = 0; i < 16 && i < len; i++)
-                               printk (" %02x", ((__u8 *) urb->transfer_buffer) [i]);
-                       printk ("%s stat:%d\n", i < len? "...": "", urb->status);
+                               printk(" %02x", ((__u8 *)urb->transfer_buffer)[i]);
+                       printk("%s stat:%d\n", i < len? "...": "", status);
                }
        }
 #endif /* ADMHC_VERBOSE_DEBUG */
                }
        }
 #endif /* ADMHC_VERBOSE_DEBUG */
@@ -139,7 +145,7 @@ urb_print(struct admhcd *ahcd, struct urb * urb, char * str, int small)
 static void admhc_dump_intr_mask(struct admhcd *ahcd, char *label, u32 mask,
                char **next, unsigned *size)
 {
 static void admhc_dump_intr_mask(struct admhcd *ahcd, char *label, u32 mask,
                char **next, unsigned *size)
 {
-       admhc_dbg_sw(ahcd, next, size, "%s 0x%08x%s%s%s%s%s%s%s%s%s%s\n",
+       admhc_dbg_sw(ahcd, next, size, "%s 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n",
                label,
                mask,
                (mask & ADMHC_INTR_INTA) ? " INTA" : "",
                label,
                mask,
                (mask & ADMHC_INTR_INTA) ? " INTA" : "",
@@ -150,6 +156,8 @@ static void admhc_dump_intr_mask(struct admhcd *ahcd, char *label, u32 mask,
                (mask & ADMHC_INTR_SO) ? " SO" : "",
                (mask & ADMHC_INTR_INSM) ? " INSM" : "",
                (mask & ADMHC_INTR_BABI) ? " BABI" : "",
                (mask & ADMHC_INTR_SO) ? " SO" : "",
                (mask & ADMHC_INTR_INSM) ? " INSM" : "",
                (mask & ADMHC_INTR_BABI) ? " BABI" : "",
+               (mask & ADMHC_INTR_7) ? " !7!" : "",
+               (mask & ADMHC_INTR_6) ? " !6!" : "",
                (mask & ADMHC_INTR_RESI) ? " RESI" : "",
                (mask & ADMHC_INTR_SOFI) ? " SOFI" : ""
                );
                (mask & ADMHC_INTR_RESI) ? " RESI" : "",
                (mask & ADMHC_INTR_SOFI) ? " SOFI" : ""
                );
@@ -243,7 +251,7 @@ admhc_dump_roothub(
 {
        u32                     temp, i;
 
 {
        u32                     temp, i;
 
-       temp = admhc_get_rhdesc(ahcd);
+       temp = admhc_read_rhdesc(ahcd);
        if (temp == ~(u32)0)
                return;
 
        if (temp == ~(u32)0)
                return;
 
@@ -267,7 +275,7 @@ admhc_dump_roothub(
        }
 
        for (i = 0; i < ahcd->num_ports; i++) {
        }
 
        for (i = 0; i < ahcd->num_ports; i++) {
-               temp = admhc_get_portstatus(ahcd, i);
+               temp = admhc_read_portstatus(ahcd, i);
                dbg_port_sw(ahcd, i, temp, next, size);
        }
 }
                dbg_port_sw(ahcd, i, temp, next, size);
        }
 }
@@ -316,18 +324,6 @@ static void admhc_dump_td(const struct admhcd *ahcd, const char *label,
                (tmp & TD_IE) ? " IE" : "");
 }
 
                (tmp & TD_IE) ? " IE" : "");
 }
 
-static void admhc_dump_up(const struct admhcd *ahcd, const char *label,
-               const struct urb_priv *up)
-{
-       int i;
-
-       admhc_dbg(ahcd, "%s urb/%p:\n", label, up->urb);
-       for (i = 0; i < up->td_cnt; i++) {
-               struct td *td = up->td[i];
-               admhc_dump_td(ahcd, "    ->", td);
-       }
-}
-
 /* caller MUST own hcd spinlock if verbose is set! */
 static void __attribute__((unused))
 admhc_dump_ed(const struct admhcd *ahcd, const char *label,
 /* caller MUST own hcd spinlock if verbose is set! */
 static void __attribute__((unused))
 admhc_dump_ed(const struct admhcd *ahcd, const char *label,
@@ -350,31 +346,31 @@ admhc_dump_ed(const struct admhcd *ahcd, const char *label,
                ED_FA_GET(tmp));
 
        tmp = hc32_to_cpup(ahcd, &ed->hwHeadP);
                ED_FA_GET(tmp));
 
        tmp = hc32_to_cpup(ahcd, &ed->hwHeadP);
-       admhc_dbg(ahcd, "  tds: head %08x tail %08x %s%s\n",
+       admhc_dbg(ahcd, "  tds: head %08x tail %08x %s%s%s\n",
                tmp & TD_MASK,
                tmp & TD_MASK,
-               hc32_to_cpup(ahcd, &ed->hwTailP),
+               hc32_to_cpup (ahcd, &ed->hwTailP),
                (tmp & ED_C) ? data1 : data0,
                (tmp & ED_C) ? data1 : data0,
-               (tmp & ED_H) ? " HALT" : "");
+               (tmp & ED_H) ? " HALT" : "",
+               verbose ? " td list follows" : " (not listing)");
 
 
-       if (ed->urb_active)
-               admhc_dump_up(ahcd, "  active ", ed->urb_active);
-
-       if ((verbose) && (!list_empty(&ed->urb_pending))) {
-               struct list_head *entry;
-               /* dump pending URBs */
-               list_for_each(entry, &ed->urb_pending) {
-                       struct urb_priv *up;
-                       up = list_entry(entry, struct urb_priv, pending);
-                       admhc_dump_up(ahcd, "  pending ", up);
+       if (verbose) {
+               struct list_head        *tmp;
+
+               /* use ed->td_list because HC concurrently modifies
+                * hwNextTD as it accumulates ed_donelist.
+                */
+               list_for_each(tmp, &ed->td_list) {
+                       struct td               *td;
+                       td = list_entry(tmp, struct td, td_list);
+                       admhc_dump_td (ahcd, "  ->", td);
                }
        }
 }
 
 #else /* ifdef DEBUG */
 
                }
        }
 }
 
 #else /* ifdef DEBUG */
 
-static inline void urb_print(struct urb * urb, char * str, int small) {}
-static inline void admhc_dump_up(const struct admhcd *ahcd, const char *label,
-       const struct urb_priv *up) {}
+static inline void urb_print(struct admhcd *ahcd, struct urb * urb, char * str,
+       int small) {}
 static inline void admhc_dump_ed(const struct admhcd *ahcd, const char *label,
        const struct ed *ed, int verbose) {}
 static inline void admhc_dump_td(const struct admhcd *ahcd, const char *label,
 static inline void admhc_dump_ed(const struct admhcd *ahcd, const char *label,
        const struct ed *ed, int verbose) {}
 static inline void admhc_dump_td(const struct admhcd *ahcd, const char *label,
@@ -394,43 +390,41 @@ static inline void remove_debug_files(struct admhcd *bus) { }
 
 #else
 
 
 #else
 
-static ssize_t
-show_urb_priv(struct admhcd *ahcd, char *buf, size_t count,
-               struct urb_priv *up)
-{
-       unsigned temp, size = count;
-       int i;
-
-       if (!up)
-               return 0;
-
-       temp = scnprintf(buf, size,"\n\turb %p ", up->urb);
-       size -= temp;
-       buf += temp;
-
-       for (i = 0; i< up->td_cnt; i++) {
-               struct td *td;
-               u32 dbp, cbl, info;
-
-               td = up->td[i];
-               info = hc32_to_cpup(ahcd, &td->hwINFO);
-               dbp = hc32_to_cpup(ahcd, &td->hwDBP);
-               cbl = hc32_to_cpup(ahcd, &td->hwCBL);
-
-               temp = scnprintf(buf, size,
-                       "\n\t\ttd %p %s %d %s%scc=%x (%08x,%08x)",
-                       td,
-                       td_pidstring(info),
-                       TD_BL_GET(cbl),
-                       (info & TD_OWN) ? "WORK " : "DONE ",
-                       (cbl & TD_IE) ? "IE " : "",
-                       TD_CC_GET(info), info, cbl);
-               size -= temp;
-               buf += temp;
-       }
-
-       return count - size;
-}
+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 *admhc_debug_root;
+
+struct debug_buffer {
+       ssize_t (*fill_func)(struct debug_buffer *);    /* fill method */
+       struct device *dev;
+       struct mutex mutex;     /* protect filling of buffer */
+       size_t count;           /* number of characters filled into buffer */
+       char *page;
+};
 
 static ssize_t
 show_list(struct admhcd *ahcd, char *buf, size_t count, struct ed *ed)
 
 static ssize_t
 show_list(struct admhcd *ahcd, char *buf, size_t count, struct ed *ed)
@@ -444,10 +438,15 @@ show_list(struct admhcd *ahcd, char *buf, size_t count, struct ed *ed)
        while (ed) {
                u32 info = hc32_to_cpu(ahcd, ed->hwINFO);
                u32 headp = hc32_to_cpu(ahcd, ed->hwHeadP);
        while (ed) {
                u32 info = hc32_to_cpu(ahcd, ed->hwINFO);
                u32 headp = hc32_to_cpu(ahcd, ed->hwHeadP);
+               u32 tailp = hc32_to_cpu(ahcd, ed->hwTailP);
+               struct list_head *entry;
+               struct td       *td;
 
                temp = scnprintf(buf, size,
 
                temp = scnprintf(buf, size,
-                       "ed/%p %s %cs dev%d ep%d %s%smax %d %08x%s%s %s",
+                       "ed/%p %s %s %cs dev%d ep%d %s%smax %d %08x%s%s %s"
+                       " h:%08x t:%08x",
                        ed,
                        ed,
+                       ed_statestring(ed->state),
                        ed_typestring (ed->type),
                        (info & ED_SPEED_FULL) ? 'f' : 'l',
                        info & ED_FA_MASK,
                        ed_typestring (ed->type),
                        (info & ED_SPEED_FULL) ? 'f' : 'l',
                        info & ED_FA_MASK,
@@ -458,50 +457,41 @@ show_list(struct admhcd *ahcd, char *buf, size_t count, struct ed *ed)
                        info,
                        (info & ED_SKIP) ? " S" : "",
                        (headp & ED_H) ? " H" : "",
                        info,
                        (info & ED_SKIP) ? " S" : "",
                        (headp & ED_H) ? " H" : "",
-                       (headp & ED_C) ? "DATA1" : "DATA0");
+                       (headp & ED_C) ? data1 : data0,
+                       headp & ED_MASK,tailp);
                size -= temp;
                buf += temp;
 
                size -= temp;
                buf += temp;
 
-               if (ed->urb_active) {
-                       temp = scnprintf(buf, size, "\nactive urb:");
-                       size -= temp;
-                       buf += temp;
-
-                       temp = show_urb_priv(ahcd, buf, size, ed->urb_active);
+               list_for_each(entry, &ed->td_list) {
+                       u32             dbp, cbl;
+
+                       td = list_entry(entry, struct td, td_list);
+                       info = hc32_to_cpup (ahcd, &td->hwINFO);
+                       dbp = hc32_to_cpup (ahcd, &td->hwDBP);
+                       cbl = hc32_to_cpup (ahcd, &td->hwCBL);
+
+                       temp = scnprintf(buf, size,
+                               "\n\ttd/%p %s %d %s%scc=%x urb %p (%08x,%08x)",
+                               td,
+                               td_pidstring(info),
+                               TD_BL_GET(cbl),
+                               (info & TD_OWN) ? "" : "DONE ",
+                               (cbl & TD_IE) ? "IE " : "",
+                               TD_CC_GET (info), td->urb, info, cbl);
                        size -= temp;
                        buf += temp;
                }
 
                        size -= temp;
                        buf += temp;
                }
 
-               if (!list_empty(&ed->urb_pending)) {
-                       struct list_head *entry;
-
-                       temp = scnprintf(buf, size, "\npending urbs:");
-                       size -= temp;
-                       buf += temp;
-
-                       list_for_each(entry, &ed->urb_pending) {
-                               struct urb_priv *up;
-                               up = list_entry(entry, struct urb_priv,
-                                       pending);
-
-                               temp = show_urb_priv(ahcd, buf, size, up);
-                               size -= temp;
-                               buf += temp;
-                       }
-               }
-
                temp = scnprintf(buf, size, "\n");
                size -= temp;
                buf += temp;
 
                ed = ed->ed_next;
        }
                temp = scnprintf(buf, size, "\n");
                size -= temp;
                buf += temp;
 
                ed = ed->ed_next;
        }
-
        return count - size;
 }
 
        return count - size;
 }
 
-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 usb_bus          *bus;
        struct usb_hcd          *hcd;
@@ -509,26 +499,23 @@ show_async(struct class_device *class_dev, char *buf)
        size_t                  temp;
        unsigned long           flags;
 
        size_t                  temp;
        unsigned long           flags;
 
-       bus = class_get_devdata(class_dev);
+       bus = dev_get_drvdata(buf->dev);
        hcd = bus_to_hcd(bus);
        ahcd = hcd_to_admhcd(hcd);
 
        /* display control and bulk lists together, for simplicity */
        spin_lock_irqsave(&ahcd->lock, flags);
        hcd = bus_to_hcd(bus);
        ahcd = hcd_to_admhcd(hcd);
 
        /* display control and bulk lists together, for simplicity */
        spin_lock_irqsave(&ahcd->lock, flags);
-       temp = show_list(ahcd, buf, PAGE_SIZE, ahcd->ed_head);
+       temp = show_list(ahcd, buf->page, buf->count, ahcd->ed_head);
        spin_unlock_irqrestore(&ahcd->lock, flags);
 
        return temp;
 }
        spin_unlock_irqrestore(&ahcd->lock, flags);
 
        return temp;
 }
-static CLASS_DEVICE_ATTR(async, S_IRUGO, show_async, NULL);
 
 
 #define DBG_SCHED_LIMIT 64
 
 
 
 #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)
 {
 {
-#if 0
        struct usb_bus          *bus;
        struct usb_hcd          *hcd;
        struct admhcd           *ahcd;
        struct usb_bus          *bus;
        struct usb_hcd          *hcd;
        struct admhcd           *ahcd;
@@ -542,10 +529,10 @@ show_periodic(struct class_device *class_dev, char *buf)
                return 0;
        seen_count = 0;
 
                return 0;
        seen_count = 0;
 
-       bus = class_get_devdata(class_dev);
+       bus = dev_get_drvdata(buf->dev);
        hcd = bus_to_hcd(bus);
        ahcd = hcd_to_admhcd(hcd);
        hcd = bus_to_hcd(bus);
        ahcd = hcd_to_admhcd(hcd);
-       next = buf;
+       next = buf->page;
        size = PAGE_SIZE;
 
        temp = scnprintf(next, size, "size = %d\n", NUM_INTS);
        size = PAGE_SIZE;
 
        temp = scnprintf(next, size, "size = %d\n", NUM_INTS);
@@ -619,17 +606,12 @@ show_periodic(struct class_device *class_dev, char *buf)
        kfree (seen);
 
        return PAGE_SIZE - size;
        kfree (seen);
 
        return PAGE_SIZE - size;
-#else
-       return 0;
-#endif
 }
 }
-static CLASS_DEVICE_ATTR(periodic, S_IRUGO, show_periodic, NULL);
 
 
 #undef DBG_SCHED_LIMIT
 
 
 
 #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 usb_bus          *bus;
        struct usb_hcd          *hcd;
@@ -640,11 +622,11 @@ show_registers(struct class_device *class_dev, char *buf)
        char                    *next;
        u32                     rdata;
 
        char                    *next;
        u32                     rdata;
 
-       bus = class_get_devdata(class_dev);
+       bus = dev_get_drvdata(buf->dev);
        hcd = bus_to_hcd(bus);
        ahcd = hcd_to_admhcd(hcd);
        regs = ahcd->regs;
        hcd = bus_to_hcd(bus);
        ahcd = hcd_to_admhcd(hcd);
        regs = ahcd->regs;
-       next = buf;
+       next = buf->page;
        size = PAGE_SIZE;
 
        spin_lock_irqsave(&ahcd->lock, flags);
        size = PAGE_SIZE;
 
        spin_lock_irqsave(&ahcd->lock, flags);
@@ -705,30 +687,156 @@ done:
        spin_unlock_irqrestore(&ahcd->lock, flags);
        return PAGE_SIZE - size;
 }
        spin_unlock_irqrestore(&ahcd->lock, flags);
        return PAGE_SIZE - size;
 }
-static CLASS_DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
 
 
 
 
-static inline void create_debug_files (struct admhcd *ahcd)
+static struct debug_buffer *alloc_buffer(struct device *dev,
+                               ssize_t (*fill_func)(struct debug_buffer *))
 {
 {
-       struct class_device *cldev = admhcd_to_hcd(ahcd)->self.class_dev;
-       int retval;
+       struct debug_buffer *buf;
 
 
-       retval = class_device_create_file(cldev, &class_device_attr_async);
-       retval = class_device_create_file(cldev, &class_device_attr_periodic);
-       retval = class_device_create_file(cldev, &class_device_attr_registers);
-       admhc_dbg(ahcd, "created debug files\n");
+       buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
+
+       if (buf) {
+               buf->dev = dev;
+               buf->fill_func = fill_func;
+               mutex_init(&buf->mutex);
+       }
+
+       return buf;
+}
+
+static int fill_buffer(struct debug_buffer *buf)
+{
+       int ret = 0;
+
+       if (!buf->page)
+               buf->page = (char *)get_zeroed_page(GFP_KERNEL);
+
+       if (!buf->page) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ret = buf->fill_func(buf);
+
+       if (ret >= 0) {
+               buf->count = ret;
+               ret = 0;
+       }
+
+out:
+       return ret;
+}
+
+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->page, buf->count);
+
+out:
+       return ret;
+}
+
+static int debug_close(struct inode *inode, struct file *file)
+{
+       struct debug_buffer *buf = file->private_data;
+
+       if (buf) {
+               if (buf->page)
+                       free_page((unsigned long)buf->page);
+               kfree(buf);
+       }
+
+       return 0;
 }
 
 }
 
-static inline void remove_debug_files (struct admhcd *ahcd)
+static int debug_async_open(struct inode *inode, struct file *file)
 {
 {
-       struct class_device *cldev = admhcd_to_hcd(ahcd)->self.class_dev;
+       file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
 
 
-       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);
+       return file->private_data ? 0 : -ENOMEM;
+}
+
+static int debug_periodic_open(struct inode *inode, struct file *file)
+{
+       file->private_data = alloc_buffer(inode->i_private,
+                                               fill_periodic_buffer);
+
+       return file->private_data ? 0 : -ENOMEM;
+}
+
+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 admhcd *ahcd)
+{
+       struct usb_bus *bus = &admhcd_to_hcd(ahcd)->self;
+       struct device *dev = bus->dev;
+
+       ahcd->debug_dir = debugfs_create_dir(bus->bus_name, admhc_debug_root);
+       if (!ahcd->debug_dir)
+               goto dir_error;
+
+       ahcd->debug_async = debugfs_create_file("async", S_IRUGO,
+                                               ahcd->debug_dir, dev,
+                                               &debug_async_fops);
+       if (!ahcd->debug_async)
+               goto async_error;
+
+       ahcd->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
+                                               ahcd->debug_dir, dev,
+                                               &debug_periodic_fops);
+       if (!ahcd->debug_periodic)
+               goto periodic_error;
+
+       ahcd->debug_registers = debugfs_create_file("registers", S_IRUGO,
+                                               ahcd->debug_dir, dev,
+                                               &debug_registers_fops);
+       if (!ahcd->debug_registers)
+               goto registers_error;
+
+       admhc_dbg(ahcd, "created debug files\n");
+       return;
+
+registers_error:
+       debugfs_remove(ahcd->debug_periodic);
+periodic_error:
+       debugfs_remove(ahcd->debug_async);
+async_error:
+       debugfs_remove(ahcd->debug_dir);
+dir_error:
+       ahcd->debug_periodic = NULL;
+       ahcd->debug_async = NULL;
+       ahcd->debug_dir = NULL;
+}
+
+static inline void remove_debug_files(struct admhcd *ahcd)
+{
+       debugfs_remove(ahcd->debug_registers);
+       debugfs_remove(ahcd->debug_periodic);
+       debugfs_remove(ahcd->debug_async);
+       debugfs_remove(ahcd->debug_dir);
 }
 
 #endif
 
 /*-------------------------------------------------------------------------*/
 }
 
 #endif
 
 /*-------------------------------------------------------------------------*/
-
This page took 0.040319 seconds and 4 git commands to generate.