mirror of
https://github.com/torvalds/linux.git
synced 2024-11-07 04:32:03 +00:00
5a0e3ad6af
percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
296 lines
8.1 KiB
C
296 lines
8.1 KiB
C
/*
|
|
* f_serial.c - generic USB serial function driver
|
|
*
|
|
* Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com)
|
|
* Copyright (C) 2008 by David Brownell
|
|
* Copyright (C) 2008 by Nokia Corporation
|
|
*
|
|
* This software is distributed under the terms of the GNU General
|
|
* Public License ("GPL") as published by the Free Software Foundation,
|
|
* either version 2 of that License or (at your option) any later version.
|
|
*/
|
|
|
|
#include <linux/slab.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/device.h>
|
|
|
|
#include "u_serial.h"
|
|
#include "gadget_chips.h"
|
|
|
|
|
|
/*
|
|
* This function packages a simple "generic serial" port with no real
|
|
* control mechanisms, just raw data transfer over two bulk endpoints.
|
|
*
|
|
* Because it's not standardized, this isn't as interoperable as the
|
|
* CDC ACM driver. However, for many purposes it's just as functional
|
|
* if you can arrange appropriate host side drivers.
|
|
*/
|
|
|
|
struct gser_descs {
|
|
struct usb_endpoint_descriptor *in;
|
|
struct usb_endpoint_descriptor *out;
|
|
};
|
|
|
|
struct f_gser {
|
|
struct gserial port;
|
|
u8 data_id;
|
|
u8 port_num;
|
|
|
|
struct gser_descs fs;
|
|
struct gser_descs hs;
|
|
};
|
|
|
|
static inline struct f_gser *func_to_gser(struct usb_function *f)
|
|
{
|
|
return container_of(f, struct f_gser, port.func);
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/* interface descriptor: */
|
|
|
|
static struct usb_interface_descriptor gser_interface_desc __initdata = {
|
|
.bLength = USB_DT_INTERFACE_SIZE,
|
|
.bDescriptorType = USB_DT_INTERFACE,
|
|
/* .bInterfaceNumber = DYNAMIC */
|
|
.bNumEndpoints = 2,
|
|
.bInterfaceClass = USB_CLASS_VENDOR_SPEC,
|
|
.bInterfaceSubClass = 0,
|
|
.bInterfaceProtocol = 0,
|
|
/* .iInterface = DYNAMIC */
|
|
};
|
|
|
|
/* full speed support: */
|
|
|
|
static struct usb_endpoint_descriptor gser_fs_in_desc __initdata = {
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
.bEndpointAddress = USB_DIR_IN,
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
};
|
|
|
|
static struct usb_endpoint_descriptor gser_fs_out_desc __initdata = {
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
.bEndpointAddress = USB_DIR_OUT,
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
};
|
|
|
|
static struct usb_descriptor_header *gser_fs_function[] __initdata = {
|
|
(struct usb_descriptor_header *) &gser_interface_desc,
|
|
(struct usb_descriptor_header *) &gser_fs_in_desc,
|
|
(struct usb_descriptor_header *) &gser_fs_out_desc,
|
|
NULL,
|
|
};
|
|
|
|
/* high speed support: */
|
|
|
|
static struct usb_endpoint_descriptor gser_hs_in_desc __initdata = {
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
.wMaxPacketSize = cpu_to_le16(512),
|
|
};
|
|
|
|
static struct usb_endpoint_descriptor gser_hs_out_desc __initdata = {
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
.wMaxPacketSize = cpu_to_le16(512),
|
|
};
|
|
|
|
static struct usb_descriptor_header *gser_hs_function[] __initdata = {
|
|
(struct usb_descriptor_header *) &gser_interface_desc,
|
|
(struct usb_descriptor_header *) &gser_hs_in_desc,
|
|
(struct usb_descriptor_header *) &gser_hs_out_desc,
|
|
NULL,
|
|
};
|
|
|
|
/* string descriptors: */
|
|
|
|
static struct usb_string gser_string_defs[] = {
|
|
[0].s = "Generic Serial",
|
|
{ } /* end of list */
|
|
};
|
|
|
|
static struct usb_gadget_strings gser_string_table = {
|
|
.language = 0x0409, /* en-us */
|
|
.strings = gser_string_defs,
|
|
};
|
|
|
|
static struct usb_gadget_strings *gser_strings[] = {
|
|
&gser_string_table,
|
|
NULL,
|
|
};
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
static int gser_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
|
|
{
|
|
struct f_gser *gser = func_to_gser(f);
|
|
struct usb_composite_dev *cdev = f->config->cdev;
|
|
|
|
/* we know alt == 0, so this is an activation or a reset */
|
|
|
|
if (gser->port.in->driver_data) {
|
|
DBG(cdev, "reset generic ttyGS%d\n", gser->port_num);
|
|
gserial_disconnect(&gser->port);
|
|
} else {
|
|
DBG(cdev, "activate generic ttyGS%d\n", gser->port_num);
|
|
gser->port.in_desc = ep_choose(cdev->gadget,
|
|
gser->hs.in, gser->fs.in);
|
|
gser->port.out_desc = ep_choose(cdev->gadget,
|
|
gser->hs.out, gser->fs.out);
|
|
}
|
|
gserial_connect(&gser->port, gser->port_num);
|
|
return 0;
|
|
}
|
|
|
|
static void gser_disable(struct usb_function *f)
|
|
{
|
|
struct f_gser *gser = func_to_gser(f);
|
|
struct usb_composite_dev *cdev = f->config->cdev;
|
|
|
|
DBG(cdev, "generic ttyGS%d deactivated\n", gser->port_num);
|
|
gserial_disconnect(&gser->port);
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/* serial function driver setup/binding */
|
|
|
|
static int __init
|
|
gser_bind(struct usb_configuration *c, struct usb_function *f)
|
|
{
|
|
struct usb_composite_dev *cdev = c->cdev;
|
|
struct f_gser *gser = func_to_gser(f);
|
|
int status;
|
|
struct usb_ep *ep;
|
|
|
|
/* allocate instance-specific interface IDs */
|
|
status = usb_interface_id(c, f);
|
|
if (status < 0)
|
|
goto fail;
|
|
gser->data_id = status;
|
|
gser_interface_desc.bInterfaceNumber = status;
|
|
|
|
status = -ENODEV;
|
|
|
|
/* allocate instance-specific endpoints */
|
|
ep = usb_ep_autoconfig(cdev->gadget, &gser_fs_in_desc);
|
|
if (!ep)
|
|
goto fail;
|
|
gser->port.in = ep;
|
|
ep->driver_data = cdev; /* claim */
|
|
|
|
ep = usb_ep_autoconfig(cdev->gadget, &gser_fs_out_desc);
|
|
if (!ep)
|
|
goto fail;
|
|
gser->port.out = ep;
|
|
ep->driver_data = cdev; /* claim */
|
|
|
|
/* copy descriptors, and track endpoint copies */
|
|
f->descriptors = usb_copy_descriptors(gser_fs_function);
|
|
|
|
gser->fs.in = usb_find_endpoint(gser_fs_function,
|
|
f->descriptors, &gser_fs_in_desc);
|
|
gser->fs.out = usb_find_endpoint(gser_fs_function,
|
|
f->descriptors, &gser_fs_out_desc);
|
|
|
|
|
|
/* support all relevant hardware speeds... we expect that when
|
|
* hardware is dual speed, all bulk-capable endpoints work at
|
|
* both speeds
|
|
*/
|
|
if (gadget_is_dualspeed(c->cdev->gadget)) {
|
|
gser_hs_in_desc.bEndpointAddress =
|
|
gser_fs_in_desc.bEndpointAddress;
|
|
gser_hs_out_desc.bEndpointAddress =
|
|
gser_fs_out_desc.bEndpointAddress;
|
|
|
|
/* copy descriptors, and track endpoint copies */
|
|
f->hs_descriptors = usb_copy_descriptors(gser_hs_function);
|
|
|
|
gser->hs.in = usb_find_endpoint(gser_hs_function,
|
|
f->hs_descriptors, &gser_hs_in_desc);
|
|
gser->hs.out = usb_find_endpoint(gser_hs_function,
|
|
f->hs_descriptors, &gser_hs_out_desc);
|
|
}
|
|
|
|
DBG(cdev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n",
|
|
gser->port_num,
|
|
gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
|
|
gser->port.in->name, gser->port.out->name);
|
|
return 0;
|
|
|
|
fail:
|
|
/* we might as well release our claims on endpoints */
|
|
if (gser->port.out)
|
|
gser->port.out->driver_data = NULL;
|
|
if (gser->port.in)
|
|
gser->port.in->driver_data = NULL;
|
|
|
|
ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
|
|
|
|
return status;
|
|
}
|
|
|
|
static void
|
|
gser_unbind(struct usb_configuration *c, struct usb_function *f)
|
|
{
|
|
if (gadget_is_dualspeed(c->cdev->gadget))
|
|
usb_free_descriptors(f->hs_descriptors);
|
|
usb_free_descriptors(f->descriptors);
|
|
kfree(func_to_gser(f));
|
|
}
|
|
|
|
/**
|
|
* gser_bind_config - add a generic serial function to a configuration
|
|
* @c: the configuration to support the serial instance
|
|
* @port_num: /dev/ttyGS* port this interface will use
|
|
* Context: single threaded during gadget setup
|
|
*
|
|
* Returns zero on success, else negative errno.
|
|
*
|
|
* Caller must have called @gserial_setup() with enough ports to
|
|
* handle all the ones it binds. Caller is also responsible
|
|
* for calling @gserial_cleanup() before module unload.
|
|
*/
|
|
int __init gser_bind_config(struct usb_configuration *c, u8 port_num)
|
|
{
|
|
struct f_gser *gser;
|
|
int status;
|
|
|
|
/* REVISIT might want instance-specific strings to help
|
|
* distinguish instances ...
|
|
*/
|
|
|
|
/* maybe allocate device-global string ID */
|
|
if (gser_string_defs[0].id == 0) {
|
|
status = usb_string_id(c->cdev);
|
|
if (status < 0)
|
|
return status;
|
|
gser_string_defs[0].id = status;
|
|
}
|
|
|
|
/* allocate and initialize one new instance */
|
|
gser = kzalloc(sizeof *gser, GFP_KERNEL);
|
|
if (!gser)
|
|
return -ENOMEM;
|
|
|
|
gser->port_num = port_num;
|
|
|
|
gser->port.func.name = "gser";
|
|
gser->port.func.strings = gser_strings;
|
|
gser->port.func.bind = gser_bind;
|
|
gser->port.func.unbind = gser_unbind;
|
|
gser->port.func.set_alt = gser_set_alt;
|
|
gser->port.func.disable = gser_disable;
|
|
|
|
status = usb_add_function(c, &gser->port.func);
|
|
if (status)
|
|
kfree(gser);
|
|
return status;
|
|
}
|