Skip to contentSkip to conversation

Input: add flags bitfield

PATCH In review Henrique de Moraes Holschuh 3 participants 6 messages Mar 16, 2008 – Mar 24, 2008 Input drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: add flags bitfield

Add a flags bitfield to the input_dev structure, which can be used for internal coordination among kernel input devices and input handlers without the need to use ever-expanding blacklists on the input handlers.

Add initial flag bits which allows an input driver to request that joystick emulation (joydev) or mouse emulation (mousedev) not be attached to an input device.

This will be used by accelerometer drivers exporting a raw interface which is not to be used as a joystick device (not to confuse this with the usual fuzzed joystick interface these drivers export for enhanced Neverball productivity), for example.

---
 drivers/input/joydev.c   |    3 +++
 drivers/input/mousedev.c |    3 +++
 include/linux/input.h    |   10 ++++++++++
 3 files changed, 16 insertions(+), 0 deletions(-)
drivers/input/joydev.c +3 -0
index 22b2789..3837389 100644
@@ -727,6 +727,9 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
 	int i, j, t, minor;
 	int error;
 
+	if (dev->flags & EV_F_NOJOYSTICK)
+		return -ENODEV;
+
 	for (minor = 0; minor < JOYDEV_MINORS; minor++)
 		if (!joydev_table[minor])
 			break;
drivers/input/mousedev.c +3 -0
index bbbe5e8..716975f 100644
@@ -962,6 +962,9 @@ static int mousedev_connect(struct input_handler *handler,
 	int minor;
 	int error;
 
+	if (dev->flags & EV_F_NOMOUSE)
+		return -ENODEV;
+
 	for (minor = 0; minor < MOUSEDEV_MINORS; minor++)
 		if (!mousedev_table[minor])
 			break;
include/linux/input.h +10 -0
index 1bdc39a..a5654fe 100644
@@ -951,12 +951,20 @@ struct ff_effect {
 #include <linux/timer.h>
 #include <linux/mod_devicetable.h>
 
+/*
+ * input device special flags
+ */
+
+#define EV_F_NOMOUSE		0x0001	/* Do not attach mousedev */
+#define EV_F_NOJOYSTICK		0x0002	/* Do not attach joydev */
+
 /**
  * struct input_dev - represents an input device
  * @name: name of the device
  * @phys: physical path to the device in the system hierarchy
  * @uniq: unique identification code for the device (if device has it)
  * @id: id of the device (struct input_id)
+ * @flags: bitmap of special flags (EV_F_*)
  * @evbit: bitmap of types of events supported by the device (EV_KEY,
  *	EV_REL, etc.)
  * @keybit: bitmap of keys/buttons this device has
@@ -1034,6 +1042,8 @@ struct input_dev {
 	const char *uniq;
 	struct input_id id;
 
+	unsigned long flags;
+
 	unsigned long evbit[BITS_TO_LONGS(EV_CNT)];
 	unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
 	unsigned long relbit[BITS_TO_LONGS(REL_CNT)];
Signature · 1 line
1.5.4.4
maintainer
#1 lore raw

Hi Henrique,

Quoted 4 lines · Henrique de Moraes Holschuh

Add a flags bitfield to the input_dev structure, which can be used for internal coordination among kernel input devices and input handlers without the need to use ever-expanding blacklists on the input handlers.

Quoted 9 lines

Add initial flag bits which allows an input driver to request that joystick emulation (joydev) or mouse emulation (mousedev) not be attached to an input device.

This will be used by accelerometer drivers exporting a raw interface which is not to be used as a joystick device (not to confuse this with the usual fuzzed joystick interface these drivers export for enhanced Neverball productivity), for example.

I'd rather not apply this patch because it pushes kowledge of existing input interfaces into device drivers. What we could do instead is add a 'type' field to the input device structure and then input interfaces (evdev/mousedev, etc) could have an option of matching either by device type or by device capabilities or both. Your raw devices could have type of accelerometer and joydev would bind to devices with type "joystick" or "unknown" + certain capabilities. Will this work?

Signature · 1 line
Dmitry
#2 lore raw
Quoted 14 lines · Dmitry Torokhov
Quoted 4 lines · Henrique de Moraes Holschuh

Add a flags bitfield to the input_dev structure, which can be used for internal coordination among kernel input devices and input handlers without the need to use ever-expanding blacklists on the input handlers.

Quoted 8 lines

Add initial flag bits which allows an input driver to request that joystick emulation (joydev) or mouse emulation (mousedev) not be attached to an input device.

This will be used by accelerometer drivers exporting a raw interface which is not to be used as a joystick device (not to confuse this with the usual fuzzed joystick interface these drivers export for enhanced Neverball productivity), for example.

Quoted 7 lines

I'd rather not apply this patch because it pushes kowledge of existing input interfaces into device drivers. What we could do instead is add a 'type' field to the input device structure and then input interfaces (evdev/mousedev, etc) could have an option of matching either by device type or by device capabilities or both. Your raw devices could have type of accelerometer and joydev would bind to devices with type "joystick" or "unknown" + certain capabilities. Will this work?

It would solve my problem, yes.

But I'd prefer if joydev and mousedev did not bind to unknown+capabilities,
just in case. Looks like bad form to me, and might bite us back later on.
We can properly fix all drivers in-tree to have suitable types for joydev
and/or mousedev binds, rfkill binds, and so on after all.

What did I miss? Are there drivers for some sort of generic device that would be unable to set their type bitfields at runtime?

BTW: as far as I can see, type should be a bitfield or a list, to allow a
device to have more than one type. Is that fine with you?

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
#3 lore raw
Quoted 24 lines · Henrique de Moraes Holschuh
Quoted 14 lines · Dmitry Torokhov
Quoted 4 lines · Henrique de Moraes Holschuh

Add a flags bitfield to the input_dev structure, which can be used for internal coordination among kernel input devices and input handlers without the need to use ever-expanding blacklists on the input handlers.

Quoted 8 lines

Add initial flag bits which allows an input driver to request that joystick emulation (joydev) or mouse emulation (mousedev) not be attached to an input device.

This will be used by accelerometer drivers exporting a raw interface which is not to be used as a joystick device (not to confuse this with the usual fuzzed joystick interface these drivers export for enhanced Neverball productivity), for example.

Quoted 7 lines

I'd rather not apply this patch because it pushes kowledge of existing input interfaces into device drivers. What we could do instead is add a 'type' field to the input device structure and then input interfaces (evdev/mousedev, etc) could have an option of matching either by device type or by device capabilities or both. Your raw devices could have type of accelerometer and joydev would bind to devices with type "joystick" or "unknown" + certain capabilities. Will this work?

Quoted 7 lines

It would solve my problem, yes.

But I'd prefer if joydev and mousedev did not bind to unknown+capabilities, just in case. Looks like bad form to me, and might bite us back later on. We can properly fix all drivers in-tree to have suitable types for joydev and/or mousedev binds, rfkill binds, and so on after all.

Drat, removing unknown+capabilities means I'd have to hunt down every frigging input device in the tree to annotate its type... otherwise, it would cause regressions re. the handlers. It is a work that needs to be done anyway, only adding type metadata to new devices and leaving the rest to report "unknown" is just icky.

Come to think of it, what about uinput? It would need to be able to set the device type as well, otherwise mousedev and joydev, for example, would not attach to uinput-created input devices.

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
#4 lore raw
Quoted 25 lines · Henrique de Moraes Holschuh
Quoted 24 lines · Henrique de Moraes Holschuh
Quoted 21 lines · Dmitry Torokhov
Quoted 4 lines · Henrique de Moraes Holschuh

Add a flags bitfield to the input_dev structure, which can be used for internal coordination among kernel input devices and input handlers without the need to use ever-expanding blacklists on the input handlers.

Quoted 8 lines

Add initial flag bits which allows an input driver to request that joystick emulation (joydev) or mouse emulation (mousedev) not be attached to an input device.

This will be used by accelerometer drivers exporting a raw interface which is not to be used as a joystick device (not to confuse this with the usual fuzzed joystick interface these drivers export for enhanced Neverball productivity), for example.

I'd rather not apply this patch because it pushes kowledge of existing input interfaces into device drivers. What we could do instead is add a 'type' field to the input device structure and then input interfaces (evdev/mousedev, etc) could have an option of matching either by device type or by device capabilities or both. Your raw devices could have type of accelerometer and joydev would bind to devices with type "joystick" or "unknown" + certain capabilities. Will this work?

Quoted 7 lines
Quoted 7 lines

It would solve my problem, yes.

But I'd prefer if joydev and mousedev did not bind to unknown+capabilities, just in case. Looks like bad form to me, and might bite us back later on. We can properly fix all drivers in-tree to have suitable types for joydev and/or mousedev binds, rfkill binds, and so on after all.

Ohne word - HID.

Quoted 11 lines

Drat, removing unknown+capabilities means I'd have to hunt down every frigging input device in the tree to annotate its type... otherwise, it would cause regressions re. the handlers. It is a work that needs to be done anyway, only adding type metadata to new devices and leaving the rest to report "unknown" is just icky.

Come to think of it, what about uinput? It would need to be able to set the device type as well, otherwise mousedev and joydev, for example, would not attach to uinput-created input devices.

That's why I thinkg unmarked should really be default and only few selected devices should set their type.

Signature · 1 line
Dmitry
#5 lore raw
Quoted 9 lines · Dmitry Torokhov
Quoted 6 lines · Henrique de Moraes Holschuh
Quoted 5 lines · Henrique de Moraes Holschuh

But I'd prefer if joydev and mousedev did not bind to unknown+capabilities, just in case. Looks like bad form to me, and might bite us back later on. We can properly fix all drivers in-tree to have suitable types for joydev and/or mousedev binds, rfkill binds, and so on after all.

Ohne word - HID.

Bleh. In that case, it will be too ugly to have it called a type, most of the input devices will have a type of "generic", which is at the very least damn ugly.

Quoted 2 lines

That's why I thinkg unmarked should really be default and only few selected devices should set their type.

I do think unmarked should be the default, and if it is so hard to have the emulation (and other handlers) ignore unmarked, we can leave that active by default as well. No problems here.

What I don't like is to call it a "input device type", and have bits on it for joystick and mouse, which almost every mouse and joystick will NOT set.

At that point, the difference between the bitfield with a handler whitelist (with blacklist all others implied, "Cisco ACL-style"), and a type bitfield is just in the name. The difference from what I already sent you would be the name, and inverted logic (I sent you a blacklist patch, not a whitelist patch).

IMO, it doesn't make sense to leave people wondering why their HID devices (and most other input devices) have a type of "generic", when they indeed are mouses, joysticks, or whatever.

Another approach would be to call the flags bitfield "emulation type", set it to "any" as default (all bits zeroed), add one bit for every emulation-style handler we add (e.g. mousedev and joydev, but not rfkill), and never bind a handler to a device which has that bitfield nonzero, unless it has the emulation bit for that handler set.

Do you *really* want a device type bitfield?

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh