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

📄 devices.c

📁 omap3 linux 2.6 用nocc去除了冗余代码
💻 C
📖 第 1 页 / 共 2 页
字号:
		interface = config->interface[i];		for (j = 0; j < intfc->num_altsetting; j++) {			if (start > end)				return start;			start = usb_dump_interface(speed,				start, end, intfc, interface, j);		}	}	return start;}/* * Dump the different USB descriptors. */static char *usb_dump_device_descriptor(char *start, char *end, const struct usb_device_descriptor *desc){	u16 bcdUSB = le16_to_cpu(desc->bcdUSB);	u16 bcdDevice = le16_to_cpu(desc->bcdDevice);	if (start > end)		return start;	start += sprintf(start, format_device1,			  bcdUSB >> 8, bcdUSB & 0xff,			  desc->bDeviceClass,			  class_decode (desc->bDeviceClass),			  desc->bDeviceSubClass,			  desc->bDeviceProtocol,			  desc->bMaxPacketSize0,			  desc->bNumConfigurations);	if (start > end)		return start;	start += sprintf(start, format_device2,			 le16_to_cpu(desc->idVendor),			 le16_to_cpu(desc->idProduct),			 bcdDevice >> 8, bcdDevice & 0xff);	return start;}/* * Dump the different strings that this device holds. */static char *usb_dump_device_strings(char *start, char *end, struct usb_device *dev){	if (start > end)		return start;	if (dev->manufacturer)		start += sprintf(start, format_string_manufacturer, dev->manufacturer);	if (start > end)		goto out;	if (dev->product)		start += sprintf(start, format_string_product, dev->product);	if (start > end)		goto out;	if (dev->serial)		start += sprintf(start, format_string_serialnumber, dev->serial); out:	return start;}static char *usb_dump_desc(char *start, char *end, struct usb_device *dev){	int i;	if (start > end)		return start;			start = usb_dump_device_descriptor(start, end, &dev->descriptor);	if (start > end)		return start;		start = usb_dump_device_strings(start, end, dev);	for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {		if (start > end)			return start;		start = usb_dump_config(dev->speed,				start, end, dev->config + i,				/* active ? */				(dev->config + i) == dev->actconfig);	}	return start;}/*****************************************************************//* This is a recursive function. Parameters: * buffer - the user-space buffer to write data into * nbytes - the maximum number of bytes to write * skip_bytes - the number of bytes to skip before writing anything * file_offset - the offset into the devices file on completion * The caller must own the device lock. */static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *skip_bytes, loff_t *file_offset,				struct usb_device *usbdev, struct usb_bus *bus, int level, int index, int count){	int chix;	int ret, cnt = 0;	int parent_devnum = 0;	char *pages_start, *data_end, *speed;	unsigned int length;	ssize_t total_written = 0;		/* don't bother with anything else if we're not writing any data */	if (*nbytes <= 0)		return 0;		if (level > MAX_TOPO_LEVEL)		return 0;	/* allocate 2^1 pages = 8K (on i386); should be more than enough for one device */        if (!(pages_start = (char*) __get_free_pages(GFP_KERNEL,1)))                return -ENOMEM;			if (usbdev->parent && usbdev->parent->devnum != -1)		parent_devnum = usbdev->parent->devnum;	/*	 * So the root hub's parent is 0 and any device that is	 * plugged into the root hub has a parent of 0.	 */	switch (usbdev->speed) {	case USB_SPEED_LOW:		speed = "1.5"; break;	case USB_SPEED_UNKNOWN:		/* usb 1.1 root hub code */	case USB_SPEED_FULL:		speed = "12 "; break;	case USB_SPEED_HIGH:		speed = "480"; break;	default:		speed = "?? ";	}	data_end = pages_start + sprintf(pages_start, format_topo,			bus->busnum, level, parent_devnum,			index, count, usbdev->devnum,			speed, usbdev->maxchild);	/*	 * level = topology-tier level;	 * parent_devnum = parent device number;	 * index = parent's connector number;	 * count = device count at this level	 */	/* If this is the root hub, display the bandwidth information */	if (level == 0) {		int	max;		/* high speed reserves 80%, full/low reserves 90% */		if (usbdev->speed == USB_SPEED_HIGH)			max = 800;		else			max = FRAME_TIME_MAX_USECS_ALLOC;		/* report "average" periodic allocation over a microsecond.		 * the schedules are actually bursty, HCDs need to deal with		 * that and just compute/report this average.		 */		data_end += sprintf(data_end, format_bandwidth,				bus->bandwidth_allocated, max,				(100 * bus->bandwidth_allocated + max / 2)					/ max,			         bus->bandwidth_int_reqs,				 bus->bandwidth_isoc_reqs);		}	data_end = usb_dump_desc(data_end, pages_start + (2 * PAGE_SIZE) - 256, usbdev);		if (data_end > (pages_start + (2 * PAGE_SIZE) - 256))		data_end += sprintf(data_end, "(truncated)\n");		length = data_end - pages_start;	/* if we can start copying some data to the user */	if (length > *skip_bytes) {		length -= *skip_bytes;		if (length > *nbytes)			length = *nbytes;		if (copy_to_user(*buffer, pages_start + *skip_bytes, length)) {			free_pages((unsigned long)pages_start, 1);			return -EFAULT;		}		*nbytes -= length;		*file_offset += length;		total_written += length;		*buffer += length;		*skip_bytes = 0;	} else		*skip_bytes -= length;		free_pages((unsigned long)pages_start, 1);		/* Now look at all of this device's children. */	for (chix = 0; chix < usbdev->maxchild; chix++) {		struct usb_device *childdev = usbdev->children[chix];		if (childdev) {			usb_lock_device(childdev);			ret = usb_device_dump(buffer, nbytes, skip_bytes, file_offset, childdev,					bus, level + 1, chix, ++cnt);			usb_unlock_device(childdev);			if (ret == -EFAULT)				return total_written;			total_written += ret;		}	}	return total_written;}static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos){	struct usb_bus *bus;	ssize_t ret, total_written = 0;	loff_t skip_bytes = *ppos;	if (*ppos < 0)		return -EINVAL;	if (nbytes <= 0)		return 0;	if (!access_ok(VERIFY_WRITE, buf, nbytes))		return -EFAULT;	mutex_lock(&usb_bus_list_lock);	/* print devices for all busses */	list_for_each_entry(bus, &usb_bus_list, bus_list) {		/* recurse through all children of the root hub */		if (!bus->root_hub)			continue;		usb_lock_device(bus->root_hub);		ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos, bus->root_hub, bus, 0, 0, 0);		usb_unlock_device(bus->root_hub);		if (ret < 0) {			mutex_unlock(&usb_bus_list_lock);			return ret;		}		total_written += ret;	}	mutex_unlock(&usb_bus_list_lock);	return total_written;}/* Kernel lock for "lastev" protection */static unsigned int usb_device_poll(struct file *file, struct poll_table_struct *wait){	struct usb_device_status *st = file->private_data;	unsigned int mask = 0;	lock_kernel();	if (!st) {		st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL);		/* we may have dropped BKL - need to check for having lost the race */		if (file->private_data) {			kfree(st);			st = file->private_data;			goto lost_race;		}		/* we haven't lost - check for allocation failure now */		if (!st) {			unlock_kernel();			return POLLIN;		}		/*		 * need to prevent the module from being unloaded, since		 * proc_unregister does not call the release method and		 * we would have a memory leak		 */		st->lastev = conndiscevcnt;		file->private_data = st;		mask = POLLIN;	}lost_race:	if (file->f_mode & FMODE_READ)                poll_wait(file, &deviceconndiscwq, wait);	if (st->lastev != conndiscevcnt)		mask |= POLLIN;	st->lastev = conndiscevcnt;	unlock_kernel();	return mask;}static int usb_device_open(struct inode *inode, struct file *file){        file->private_data = NULL;        return 0;}static int usb_device_release(struct inode *inode, struct file *file){	kfree(file->private_data);	file->private_data = NULL;        return 0;}static loff_t usb_device_lseek(struct file * file, loff_t offset, int orig){	loff_t ret;	lock_kernel();	switch (orig) {	case 0:		file->f_pos = offset;		ret = file->f_pos;		break;	case 1:		file->f_pos += offset;		ret = file->f_pos;		break;	case 2:	default:		ret = -EINVAL;	}	unlock_kernel();	return ret;}const struct file_operations usbfs_devices_fops = {	.llseek =	usb_device_lseek,	.read =		usb_device_read,	.poll =		usb_device_poll,	.open =		usb_device_open,	.release =	usb_device_release,};

⌨️ 快捷键说明

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