* [PATCH 1/4] USBHID: use GFP_KERNEL in hid_alloc_buffers
@ 2008-11-24 15:20 Jiri Slaby
2008-11-24 15:20 ` [PATCH 2/4] HID: move usbhid flags to usbhid.h Jiri Slaby
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Jiri Slaby @ 2008-11-24 15:20 UTC (permalink / raw)
To: jkosina; +Cc: linux-input, linux-kernel, Jiri Slaby
We might sleep, so no problem to use GFP_KERNEL.
While at it bring the function to coding style.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
drivers/hid/usbhid/hid-core.c | 17 ++++++++++-------
1 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index b73d917..30f3add 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -650,13 +650,16 @@ static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
{
struct usbhid_device *usbhid = hid->driver_data;
- if (!(usbhid->inbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->inbuf_dma)))
- return -1;
- if (!(usbhid->outbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->outbuf_dma)))
- return -1;
- if (!(usbhid->cr = usb_buffer_alloc(dev, sizeof(*(usbhid->cr)), GFP_ATOMIC, &usbhid->cr_dma)))
- return -1;
- if (!(usbhid->ctrlbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->ctrlbuf_dma)))
+ usbhid->inbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_KERNEL,
+ &usbhid->inbuf_dma);
+ usbhid->outbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_KERNEL,
+ &usbhid->outbuf_dma);
+ usbhid->cr = usb_buffer_alloc(dev, sizeof(*usbhid->cr), GFP_KERNEL,
+ &usbhid->cr_dma);
+ usbhid->ctrlbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_KERNEL,
+ &usbhid->ctrlbuf_dma);
+ if (!usbhid->inbuf || !usbhid->outbuf || !usbhid->cr ||
+ !usbhid->ctrlbuf)
return -1;
return 0;
--
1.6.0.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] HID: move usbhid flags to usbhid.h
2008-11-24 15:20 [PATCH 1/4] USBHID: use GFP_KERNEL in hid_alloc_buffers Jiri Slaby
@ 2008-11-24 15:20 ` Jiri Slaby
2008-11-24 15:20 ` [PATCH 3/4] HID: usbhid, use usb_endpoint_xfer_int Jiri Slaby
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Jiri Slaby @ 2008-11-24 15:20 UTC (permalink / raw)
To: jkosina; +Cc: linux-input, linux-kernel, Jiri Slaby
Move usbhid specific flags from global hid.h into local usbhid.h.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
drivers/hid/usbhid/usbhid.h | 10 ++++++++++
include/linux/hid.h | 9 ---------
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h
index 332abcd..9eb3056 100644
--- a/drivers/hid/usbhid/usbhid.h
+++ b/drivers/hid/usbhid/usbhid.h
@@ -40,6 +40,16 @@ int usbhid_open(struct hid_device *hid);
void usbhid_init_reports(struct hid_device *hid);
void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir);
+/* iofl flags */
+#define HID_CTRL_RUNNING 1
+#define HID_OUT_RUNNING 2
+#define HID_IN_RUNNING 3
+#define HID_RESET_PENDING 4
+#define HID_SUSPENDED 5
+#define HID_CLEAR_HALT 6
+#define HID_DISCONNECTED 7
+#define HID_STARTED 8
+
/*
* USB-specific HID struct, to be pointed to
* from struct hid_device->driver_data
diff --git a/include/linux/hid.h b/include/linux/hid.h
index e5780f8..2c20f20 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -403,15 +403,6 @@ struct hid_output_fifo {
#define HID_STAT_ADDED 1
#define HID_STAT_PARSED 2
-#define HID_CTRL_RUNNING 1
-#define HID_OUT_RUNNING 2
-#define HID_IN_RUNNING 3
-#define HID_RESET_PENDING 4
-#define HID_SUSPENDED 5
-#define HID_CLEAR_HALT 6
-#define HID_DISCONNECTED 7
-#define HID_STARTED 8
-
struct hid_input {
struct list_head list;
struct hid_report *report;
--
1.6.0.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] HID: usbhid, use usb_endpoint_xfer_int
2008-11-24 15:20 [PATCH 1/4] USBHID: use GFP_KERNEL in hid_alloc_buffers Jiri Slaby
2008-11-24 15:20 ` [PATCH 2/4] HID: move usbhid flags to usbhid.h Jiri Slaby
@ 2008-11-24 15:20 ` Jiri Slaby
2008-11-24 15:20 ` [PATCH 4/4] HID: add dynids facility Jiri Slaby
2008-11-25 11:53 ` [PATCH 1/4] USBHID: use GFP_KERNEL in hid_alloc_buffers Jiri Kosina
3 siblings, 0 replies; 5+ messages in thread
From: Jiri Slaby @ 2008-11-24 15:20 UTC (permalink / raw)
To: jkosina; +Cc: linux-input, linux-kernel, Jiri Slaby
Use usb_endpoint_xfer_int() instead of direct use of constants.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
drivers/hid/usbhid/hid-core.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 30f3add..f0a0f72 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -807,7 +807,7 @@ static int usbhid_start(struct hid_device *hid)
int interval;
endpoint = &interface->endpoint[n].desc;
- if ((endpoint->bmAttributes & 3) != 3) /* Not an interrupt endpoint */
+ if (!usb_endpoint_xfer_int(endpoint))
continue;
interval = endpoint->bInterval;
--
1.6.0.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] HID: add dynids facility
2008-11-24 15:20 [PATCH 1/4] USBHID: use GFP_KERNEL in hid_alloc_buffers Jiri Slaby
2008-11-24 15:20 ` [PATCH 2/4] HID: move usbhid flags to usbhid.h Jiri Slaby
2008-11-24 15:20 ` [PATCH 3/4] HID: usbhid, use usb_endpoint_xfer_int Jiri Slaby
@ 2008-11-24 15:20 ` Jiri Slaby
2008-11-25 11:53 ` [PATCH 1/4] USBHID: use GFP_KERNEL in hid_alloc_buffers Jiri Kosina
3 siblings, 0 replies; 5+ messages in thread
From: Jiri Slaby @ 2008-11-24 15:20 UTC (permalink / raw)
To: jkosina; +Cc: linux-input, linux-kernel, Jiri Slaby
Allow adding new devices to the hid drivers on the fly without
a need of kernel recompilation.
Now, one can test a driver e.g. by:
echo 0003:045E:00F0.0003 > ../generic-usb/unbind
echo 0003 045E 00F0 > new_id
from some driver subdir.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
drivers/hid/hid-core.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++-
include/linux/hid.h | 5 ++
2 files changed, 103 insertions(+), 3 deletions(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 1cac775..efcb5b8 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1304,12 +1304,92 @@ static const struct hid_device_id hid_blacklist[] = {
{ }
};
+struct hid_dynid {
+ struct list_head list;
+ struct hid_device_id id;
+};
+
+/**
+ * store_new_id - add a new HID device ID to this driver and re-probe devices
+ * @driver: target device driver
+ * @buf: buffer for scanning device ID data
+ * @count: input size
+ *
+ * Adds a new dynamic hid device ID to this driver,
+ * and causes the driver to probe for all devices again.
+ */
+static ssize_t store_new_id(struct device_driver *drv, const char *buf,
+ size_t count)
+{
+ struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
+ struct hid_dynid *dynid;
+ __u32 bus, vendor, product;
+ unsigned long driver_data = 0;
+ int ret;
+
+ ret = sscanf(buf, "%x %x %x %lx",
+ &bus, &vendor, &product, &driver_data);
+ if (ret < 3)
+ return -EINVAL;
+
+ dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
+ if (!dynid)
+ return -ENOMEM;
+
+ dynid->id.bus = bus;
+ dynid->id.vendor = vendor;
+ dynid->id.product = product;
+ dynid->id.driver_data = driver_data;
+
+ spin_lock(&hdrv->dyn_lock);
+ list_add_tail(&dynid->list, &hdrv->dyn_list);
+ spin_unlock(&hdrv->dyn_lock);
+
+ ret = 0;
+ if (get_driver(&hdrv->driver)) {
+ ret = driver_attach(&hdrv->driver);
+ put_driver(&hdrv->driver);
+ }
+
+ return ret ? : count;
+}
+static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
+
+static void hid_free_dynids(struct hid_driver *hdrv)
+{
+ struct hid_dynid *dynid, *n;
+
+ spin_lock(&hdrv->dyn_lock);
+ list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
+ list_del(&dynid->list);
+ kfree(dynid);
+ }
+ spin_unlock(&hdrv->dyn_lock);
+}
+
+static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
+ struct hid_driver *hdrv)
+{
+ struct hid_dynid *dynid;
+
+ spin_lock(&hdrv->dyn_lock);
+ list_for_each_entry(dynid, &hdrv->dyn_list, list) {
+ if (hid_match_one_id(hdev, &dynid->id)) {
+ spin_unlock(&hdrv->dyn_lock);
+ return &dynid->id;
+ }
+ }
+ spin_unlock(&hdrv->dyn_lock);
+
+ return hid_match_id(hdev, hdrv->id_table);
+}
+
static int hid_bus_match(struct device *dev, struct device_driver *drv)
{
struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
- if (!hid_match_id(hdev, hdrv->id_table))
+ if (!hid_match_device(hdev, hdrv))
return 0;
/* generic wants all non-blacklisted */
@@ -1328,7 +1408,7 @@ static int hid_device_probe(struct device *dev)
int ret = 0;
if (!hdev->driver) {
- id = hid_match_id(hdev, hdrv->id_table);
+ id = hid_match_device(hdev, hdrv);
if (id == NULL)
return -ENODEV;
@@ -1695,18 +1775,33 @@ EXPORT_SYMBOL_GPL(hid_destroy_device);
int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
const char *mod_name)
{
+ int ret;
+
hdrv->driver.name = hdrv->name;
hdrv->driver.bus = &hid_bus_type;
hdrv->driver.owner = owner;
hdrv->driver.mod_name = mod_name;
- return driver_register(&hdrv->driver);
+ INIT_LIST_HEAD(&hdrv->dyn_list);
+ spin_lock_init(&hdrv->dyn_lock);
+
+ ret = driver_register(&hdrv->driver);
+ if (ret)
+ return ret;
+
+ ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
+ if (ret)
+ driver_unregister(&hdrv->driver);
+
+ return ret;
}
EXPORT_SYMBOL_GPL(__hid_register_driver);
void hid_unregister_driver(struct hid_driver *hdrv)
{
+ driver_remove_file(&hdrv->driver, &driver_attr_new_id);
driver_unregister(&hdrv->driver);
+ hid_free_dynids(hdrv);
}
EXPORT_SYMBOL_GPL(hid_unregister_driver);
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 2c20f20..215035b 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -531,6 +531,8 @@ struct hid_usage_id {
* @name: driver name (e.g. "Footech_bar-wheel")
* @id_table: which devices is this driver for (must be non-NULL for probe
* to be called)
+ * @dyn_list: list of dynamically added device ids
+ * @dyn_lock: lock protecting @dyn_list
* @probe: new device inserted
* @remove: device removed (NULL if not a hot-plug capable driver)
* @report_table: on which reports to call raw_event (NULL means all)
@@ -558,6 +560,9 @@ struct hid_driver {
char *name;
const struct hid_device_id *id_table;
+ struct list_head dyn_list;
+ spinlock_t dyn_lock;
+
int (*probe)(struct hid_device *dev, const struct hid_device_id *id);
void (*remove)(struct hid_device *dev);
--
1.6.0.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/4] USBHID: use GFP_KERNEL in hid_alloc_buffers
2008-11-24 15:20 [PATCH 1/4] USBHID: use GFP_KERNEL in hid_alloc_buffers Jiri Slaby
` (2 preceding siblings ...)
2008-11-24 15:20 ` [PATCH 4/4] HID: add dynids facility Jiri Slaby
@ 2008-11-25 11:53 ` Jiri Kosina
3 siblings, 0 replies; 5+ messages in thread
From: Jiri Kosina @ 2008-11-25 11:53 UTC (permalink / raw)
To: Jiri Slaby; +Cc: linux-input, linux-kernel
On Mon, 24 Nov 2008, Jiri Slaby wrote:
> We might sleep, so no problem to use GFP_KERNEL.
>
> While at it bring the function to coding style.
Applied, as well as the other three patches in the series. All queued for
2.6.29.
Thanks!
--
Jiri Kosina
SUSE Labs
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-11-25 11:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-24 15:20 [PATCH 1/4] USBHID: use GFP_KERNEL in hid_alloc_buffers Jiri Slaby
2008-11-24 15:20 ` [PATCH 2/4] HID: move usbhid flags to usbhid.h Jiri Slaby
2008-11-24 15:20 ` [PATCH 3/4] HID: usbhid, use usb_endpoint_xfer_int Jiri Slaby
2008-11-24 15:20 ` [PATCH 4/4] HID: add dynids facility Jiri Slaby
2008-11-25 11:53 ` [PATCH 1/4] USBHID: use GFP_KERNEL in hid_alloc_buffers Jiri Kosina
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).