⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ohci-dbg.c

📁 ReactOs中的USB驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
ohci_dump_ed (struct ohci_hcd *ohci, char *label, struct ed *ed, int verbose)
{
	u32	tmp = ed->hwINFO;
	char	*type = "";

	ohci_dbg (ohci, "%s, ed %p state 0x%x type %s; next ed %08x",
		label,
		ed, ed->state, edstring (ed->type),
		le32_to_cpup (&ed->hwNextED));
	switch (tmp & (ED_IN|ED_OUT)) {
	case ED_OUT: type = "-OUT"; break;
	case ED_IN: type = "-IN"; break;
	/* else from TDs ... control */
	}
	ohci_dbg (ohci,
		"  info %08x MAX=%d%s%s%s%s EP=%d%s DEV=%d", le32_to_cpu (tmp),
		0x03ff & (le32_to_cpu (tmp) >> 16),
		(tmp & ED_DEQUEUE) ? " DQ" : "",
		(tmp & ED_ISO) ? " ISO" : "",
		(tmp & ED_SKIP) ? " SKIP" : "",
		(tmp & ED_LOWSPEED) ? " LOW" : "",
		0x000f & (le32_to_cpu (tmp) >> 7),
		type,
		0x007f & le32_to_cpu (tmp));
	ohci_dbg (ohci, "  tds: head %08x %s%s tail %08x%s",
		tmp = le32_to_cpup (&ed->hwHeadP),
		(ed->hwHeadP & ED_C) ? data1 : data0,
		(ed->hwHeadP & ED_H) ? " HALT" : "",
		le32_to_cpup (&ed->hwTailP),
		verbose ? "" : " (not listing)");
	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);
			ohci_dump_td (ohci, "  ->", td);
		}
	}
}

#else
static inline void ohci_dump (struct ohci_hcd *controller, int verbose) {}

#undef OHCI_VERBOSE_DEBUG

#endif /* DEBUG */

/*-------------------------------------------------------------------------*/

#ifdef STUB_DEBUG_FILES

static inline void create_debug_files (struct ohci_hcd *bus) { }
static inline void remove_debug_files (struct ohci_hcd *bus) { }

#else

static inline struct ohci_hcd *dev_to_ohci (struct device *dev)
{
	struct usb_hcd	*hcd = dev_get_drvdata (dev);

	return hcd_to_ohci (hcd);
}

static ssize_t
show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed)
{
	unsigned		temp, size = count;

	if (!ed)
		return 0;

	/* print first --> last */
	while (ed->ed_prev)
		ed = ed->ed_prev;

	/* dump a snapshot of the bulk or control schedule */
	while (ed) {
		u32			info = ed->hwINFO;
		u32			scratch = cpu_to_le32p (&ed->hwINFO);
		struct list_head	*entry;
		struct td		*td;

		temp = snprintf (buf, size,
			"ed/%p %cs dev%d ep%d%s max %d %08x%s%s %s",
			ed,
			(info & ED_LOWSPEED) ? 'l' : 'f',
			scratch & 0x7f,
			(scratch >> 7) & 0xf,
			(info & ED_IN) ? "in" : "out",
			0x03ff & (scratch >> 16),
			scratch,
			(info & ED_SKIP) ? " s" : "",
			(ed->hwHeadP & ED_H) ? " H" : "",
			(ed->hwHeadP & ED_C) ? data1 : data0);
		size -= temp;
		buf += temp;

		list_for_each (entry, &ed->td_list) {
			u32		cbp, be;

			td = list_entry (entry, struct td, td_list);
			scratch = cpu_to_le32p (&td->hwINFO);
			cbp = le32_to_cpup (&td->hwCBP);
			be = le32_to_cpup (&td->hwBE);
			temp = snprintf (buf, size,
					"\n\ttd %p %s %d cc=%x urb %p (%08x)",
					td,
					({ char *pid;
					switch (scratch & TD_DP) {
					case TD_DP_SETUP: pid = "setup"; break;
					case TD_DP_IN: pid = "in"; break;
					case TD_DP_OUT: pid = "out"; break;
					default: pid = "(?)"; break;
					 } pid;}),
					cbp ? (be + 1 - cbp) : 0,
					TD_CC_GET (scratch), td->urb, scratch);
			size -= temp;
			buf += temp;
		}

		temp = snprintf (buf, size, "\n");
		size -= temp;
		buf += temp;

		ed = ed->ed_next;
	}
	return count - size;
}

static ssize_t
show_async (struct device *dev, char *buf)
{
	struct ohci_hcd		*ohci;
	size_t			temp;
	unsigned long		flags;

	ohci = dev_to_ohci(dev);

	/* display control and bulk lists together, for simplicity */
	spin_lock_irqsave (&ohci->lock, flags);
	temp = show_list (ohci, buf, PAGE_SIZE, ohci->ed_controltail);
	temp += show_list (ohci, buf + temp, PAGE_SIZE - temp, ohci->ed_bulktail);
	spin_unlock_irqrestore (&ohci->lock, flags);

	return temp;
}
static DEVICE_ATTR (async, S_IRUGO, show_async, NULL);


#define DBG_SCHED_LIMIT 64

static ssize_t
show_periodic (struct device *dev, char *buf)
{
	struct ohci_hcd		*ohci;
	struct ed		**seen, *ed;
	unsigned long		flags;
	unsigned		temp, size, seen_count;
	char			*next;
	unsigned		i;

	if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, SLAB_ATOMIC)))
		return 0;
	seen_count = 0;

	ohci = dev_to_ohci(dev);
	next = buf;
	size = PAGE_SIZE;

	temp = snprintf (next, size, "size = %d\n", NUM_INTS);
	size -= temp;
	next += temp;

	/* dump a snapshot of the periodic schedule (and load) */
	spin_lock_irqsave (&ohci->lock, flags);
	for (i = 0; i < NUM_INTS; i++) {
		if (!(ed = ohci->periodic [i]))
			continue;

		temp = snprintf (next, size, "%2d [%3d]:", i, ohci->load [i]);
		size -= temp;
		next += temp;

		do {
			temp = snprintf (next, size, " ed%d/%p",
				ed->interval, ed);
			size -= temp;
			next += temp;
			for (temp = 0; temp < seen_count; temp++) {
				if (seen [temp] == ed)
					break;
			}

			/* show more info the first time around */
			if (temp == seen_count) {
				u32	info = ed->hwINFO;
				u32	scratch = cpu_to_le32p (&ed->hwINFO);

				temp = snprintf (next, size,
					" (%cs dev%d%s ep%d%s"
					" max %d %08x%s%s)",
					(info & ED_LOWSPEED) ? 'l' : 'f',
					scratch & 0x7f,
					(info & ED_ISO) ? " iso" : "",
					(scratch >> 7) & 0xf,
					(info & ED_IN) ? "in" : "out",
					0x03ff & (scratch >> 16),
					scratch,
					(info & ED_SKIP) ? " s" : "",
					(ed->hwHeadP & ED_H) ? " H" : "");
				size -= temp;
				next += temp;

				// FIXME some TD info too

				if (seen_count < DBG_SCHED_LIMIT)
					seen [seen_count++] = ed;

				ed = ed->ed_next;

			} else {
				/* we've seen it and what's after */
				temp = 0;
				ed = 0;
			}

		} while (ed);

		temp = snprintf (next, size, "\n");
		size -= temp;
		next += temp;
	}
	spin_unlock_irqrestore (&ohci->lock, flags);
	kfree (seen);

	return PAGE_SIZE - size;
}
static DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL);


#undef DBG_SCHED_LIMIT

static ssize_t
show_registers (struct device *dev, char *buf)
{
	struct ohci_hcd		*ohci;
	struct ohci_regs	*regs;
	unsigned long		flags;
	unsigned		temp, size;
	char			*next;
	u32			rdata;

	ohci = dev_to_ohci(dev);
	regs = ohci->regs;
	next = buf;
	size = PAGE_SIZE;

	spin_lock_irqsave (&ohci->lock, flags);

	/* dump driver info, then registers in spec order */

	ohci_dbg_sw (ohci, &next, &size,
		"%s version " DRIVER_VERSION "\n", hcd_name);

	ohci_dump_status(ohci, &next, &size);

	/* hcca */
	if (ohci->hcca)
		ohci_dbg_sw (ohci, &next, &size,
			"hcca frame 0x%04x\n", ohci->hcca->frame_no);

	/* other registers mostly affect frame timings */
	rdata = readl (&regs->fminterval);
	temp = snprintf (next, size,
			"fmintvl 0x%08x %sFSMPS=0x%04x FI=0x%04x\n",
			rdata, (rdata >> 31) ? " FIT" : "",
			(rdata >> 16) & 0xefff, rdata & 0xffff);
	size -= temp;
	next += temp;

	rdata = readl (&regs->fmremaining);
	temp = snprintf (next, size, "fmremaining 0x%08x %sFR=0x%04x\n",
			rdata, (rdata >> 31) ? " FRT" : "",
			rdata & 0x3fff);
	size -= temp;
	next += temp;

	rdata = readl (&regs->periodicstart);
	temp = snprintf (next, size, "periodicstart 0x%04x\n",
			rdata & 0x3fff);
	size -= temp;
	next += temp;

	rdata = readl (&regs->lsthresh);
	temp = snprintf (next, size, "lsthresh 0x%04x\n",
			rdata & 0x3fff);
	size -= temp;
	next += temp;

	/* roothub */
	ohci_dump_roothub (ohci, 1, &next, &size);

	spin_unlock_irqrestore (&ohci->lock, flags);

	return PAGE_SIZE - size;
}
static DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);


static inline void create_debug_files (struct ohci_hcd *bus)
{
	device_create_file (bus->hcd.controller, &dev_attr_async);
	device_create_file (bus->hcd.controller, &dev_attr_periodic);
	device_create_file (bus->hcd.controller, &dev_attr_registers);
	ohci_dbg (bus, "created debug files\n");
}

static inline void remove_debug_files (struct ohci_hcd *bus)
{
	device_remove_file (bus->hcd.controller, &dev_attr_async);
	device_remove_file (bus->hcd.controller, &dev_attr_periodic);
	device_remove_file (bus->hcd.controller, &dev_attr_registers);
}

#endif

/*-------------------------------------------------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -