2019-05-19 15:08:20 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* drivers/macintosh/mac_hid.c
|
|
|
|
*
|
|
|
|
* HID support stuff for Macintosh computers.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000 Franz Sirl.
|
|
|
|
*
|
|
|
|
* This file will soon be removed in favor of an uinput userspace tool.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/sysctl.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
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>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-01-30 12:44:20 +03:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2007-02-10 23:35:12 +03:00
|
|
|
static int mouse_emulate_buttons;
|
2005-04-17 02:20:36 +04:00
|
|
|
static int mouse_button2_keycode = KEY_RIGHTCTRL; /* right control key */
|
|
|
|
static int mouse_button3_keycode = KEY_RIGHTALT; /* right option key */
|
|
|
|
|
2010-01-30 11:53:29 +03:00
|
|
|
static struct input_dev *mac_hid_emumouse_dev;
|
|
|
|
|
2010-11-12 09:03:59 +03:00
|
|
|
static DEFINE_MUTEX(mac_hid_emumouse_mutex);
|
|
|
|
|
2010-01-30 11:53:29 +03:00
|
|
|
static int mac_hid_create_emumouse(void)
|
|
|
|
{
|
|
|
|
static struct lock_class_key mac_hid_emumouse_dev_event_class;
|
|
|
|
static struct lock_class_key mac_hid_emumouse_dev_mutex_class;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
mac_hid_emumouse_dev = input_allocate_device();
|
|
|
|
if (!mac_hid_emumouse_dev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
lockdep_set_class(&mac_hid_emumouse_dev->event_lock,
|
|
|
|
&mac_hid_emumouse_dev_event_class);
|
|
|
|
lockdep_set_class(&mac_hid_emumouse_dev->mutex,
|
|
|
|
&mac_hid_emumouse_dev_mutex_class);
|
|
|
|
|
|
|
|
mac_hid_emumouse_dev->name = "Macintosh mouse button emulation";
|
|
|
|
mac_hid_emumouse_dev->id.bustype = BUS_ADB;
|
|
|
|
mac_hid_emumouse_dev->id.vendor = 0x0001;
|
|
|
|
mac_hid_emumouse_dev->id.product = 0x0001;
|
|
|
|
mac_hid_emumouse_dev->id.version = 0x0100;
|
|
|
|
|
|
|
|
mac_hid_emumouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
|
|
|
|
mac_hid_emumouse_dev->keybit[BIT_WORD(BTN_MOUSE)] =
|
|
|
|
BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
|
|
|
|
mac_hid_emumouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
|
|
|
|
|
|
|
|
err = input_register_device(mac_hid_emumouse_dev);
|
|
|
|
if (err) {
|
|
|
|
input_free_device(mac_hid_emumouse_dev);
|
|
|
|
mac_hid_emumouse_dev = NULL;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mac_hid_destroy_emumouse(void)
|
|
|
|
{
|
|
|
|
input_unregister_device(mac_hid_emumouse_dev);
|
|
|
|
mac_hid_emumouse_dev = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool mac_hid_emumouse_filter(struct input_handle *handle,
|
|
|
|
unsigned int type, unsigned int code,
|
|
|
|
int value)
|
|
|
|
{
|
|
|
|
unsigned int btn;
|
|
|
|
|
|
|
|
if (type != EV_KEY)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (code == mouse_button2_keycode)
|
|
|
|
btn = BTN_MIDDLE;
|
|
|
|
else if (code == mouse_button3_keycode)
|
|
|
|
btn = BTN_RIGHT;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
input_report_key(mac_hid_emumouse_dev, btn, value);
|
|
|
|
input_sync(mac_hid_emumouse_dev);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mac_hid_emumouse_connect(struct input_handler *handler,
|
|
|
|
struct input_dev *dev,
|
|
|
|
const struct input_device_id *id)
|
|
|
|
{
|
|
|
|
struct input_handle *handle;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* Don't bind to ourselves */
|
|
|
|
if (dev == mac_hid_emumouse_dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
|
|
|
|
if (!handle)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
handle->dev = dev;
|
|
|
|
handle->handler = handler;
|
|
|
|
handle->name = "mac-button-emul";
|
|
|
|
|
|
|
|
error = input_register_handle(handle);
|
|
|
|
if (error) {
|
|
|
|
printk(KERN_ERR
|
|
|
|
"mac_hid: Failed to register button emulation handle, "
|
|
|
|
"error %d\n", error);
|
|
|
|
goto err_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = input_open_device(handle);
|
|
|
|
if (error) {
|
|
|
|
printk(KERN_ERR
|
|
|
|
"mac_hid: Failed to open input device, error %d\n",
|
|
|
|
error);
|
|
|
|
goto err_unregister;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_unregister:
|
|
|
|
input_unregister_handle(handle);
|
|
|
|
err_free:
|
|
|
|
kfree(handle);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mac_hid_emumouse_disconnect(struct input_handle *handle)
|
|
|
|
{
|
|
|
|
input_close_device(handle);
|
|
|
|
input_unregister_handle(handle);
|
|
|
|
kfree(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct input_device_id mac_hid_emumouse_ids[] = {
|
|
|
|
{
|
|
|
|
.flags = INPUT_DEVICE_ID_MATCH_EVBIT,
|
|
|
|
.evbit = { BIT_MASK(EV_KEY) },
|
|
|
|
},
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(input, mac_hid_emumouse_ids);
|
|
|
|
|
|
|
|
static struct input_handler mac_hid_emumouse_handler = {
|
|
|
|
.filter = mac_hid_emumouse_filter,
|
|
|
|
.connect = mac_hid_emumouse_connect,
|
|
|
|
.disconnect = mac_hid_emumouse_disconnect,
|
|
|
|
.name = "mac-button-emul",
|
|
|
|
.id_table = mac_hid_emumouse_ids,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int mac_hid_start_emulation(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = mac_hid_create_emumouse();
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = input_register_handler(&mac_hid_emumouse_handler);
|
|
|
|
if (err) {
|
|
|
|
mac_hid_destroy_emumouse();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mac_hid_stop_emulation(void)
|
|
|
|
{
|
|
|
|
input_unregister_handler(&mac_hid_emumouse_handler);
|
|
|
|
mac_hid_destroy_emumouse();
|
|
|
|
}
|
|
|
|
|
2013-06-14 06:37:37 +04:00
|
|
|
static int mac_hid_toggle_emumouse(struct ctl_table *table, int write,
|
2020-04-24 09:43:38 +03:00
|
|
|
void *buffer, size_t *lenp, loff_t *ppos)
|
2010-01-30 11:53:29 +03:00
|
|
|
{
|
|
|
|
int *valp = table->data;
|
|
|
|
int old_val = *valp;
|
|
|
|
int rc;
|
|
|
|
|
2010-11-12 09:03:59 +03:00
|
|
|
rc = mutex_lock_killable(&mac_hid_emumouse_mutex);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2010-01-30 11:53:29 +03:00
|
|
|
rc = proc_dointvec(table, write, buffer, lenp, ppos);
|
|
|
|
|
|
|
|
if (rc == 0 && write && *valp != old_val) {
|
|
|
|
if (*valp == 1)
|
|
|
|
rc = mac_hid_start_emulation();
|
|
|
|
else if (*valp == 0)
|
|
|
|
mac_hid_stop_emulation();
|
|
|
|
else
|
|
|
|
rc = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore the old value in case of error */
|
|
|
|
if (rc)
|
|
|
|
*valp = old_val;
|
|
|
|
|
2010-11-12 09:03:59 +03:00
|
|
|
mutex_unlock(&mac_hid_emumouse_mutex);
|
|
|
|
|
2010-01-30 11:53:29 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* file(s) in /proc/sys/dev/mac_hid */
|
2013-06-14 06:37:37 +04:00
|
|
|
static struct ctl_table mac_hid_files[] = {
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
.procname = "mouse_button_emulation",
|
|
|
|
.data = &mouse_emulate_buttons,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2010-01-30 11:53:29 +03:00
|
|
|
.proc_handler = mac_hid_toggle_emumouse,
|
2005-04-17 02:20:36 +04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "mouse_button2_keycode",
|
|
|
|
.data = &mouse_button2_keycode,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2009-11-16 14:11:48 +03:00
|
|
|
.proc_handler = proc_dointvec,
|
2005-04-17 02:20:36 +04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "mouse_button3_keycode",
|
|
|
|
.data = &mouse_button3_keycode,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2009-11-16 14:11:48 +03:00
|
|
|
.proc_handler = proc_dointvec,
|
2005-04-17 02:20:36 +04:00
|
|
|
},
|
2009-11-06 01:34:02 +03:00
|
|
|
{ }
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* dir in /proc/sys/dev */
|
2013-06-14 06:37:37 +04:00
|
|
|
static struct ctl_table mac_hid_dir[] = {
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
.procname = "mac_hid",
|
|
|
|
.maxlen = 0,
|
|
|
|
.mode = 0555,
|
|
|
|
.child = mac_hid_files,
|
|
|
|
},
|
2009-11-06 01:34:02 +03:00
|
|
|
{ }
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* /proc/sys/dev itself, in case that is not there yet */
|
2013-06-14 06:37:37 +04:00
|
|
|
static struct ctl_table mac_hid_root_dir[] = {
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
.procname = "dev",
|
|
|
|
.maxlen = 0,
|
|
|
|
.mode = 0555,
|
|
|
|
.child = mac_hid_dir,
|
|
|
|
},
|
2009-11-06 01:34:02 +03:00
|
|
|
{ }
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct ctl_table_header *mac_hid_sysctl_header;
|
|
|
|
|
2007-03-08 01:41:07 +03:00
|
|
|
static int __init mac_hid_init(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2007-02-14 11:34:09 +03:00
|
|
|
mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir);
|
2010-01-30 11:53:29 +03:00
|
|
|
if (!mac_hid_sysctl_header)
|
|
|
|
return -ENOMEM;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-01-30 12:44:20 +03:00
|
|
|
module_init(mac_hid_init);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-01-30 12:44:20 +03:00
|
|
|
static void __exit mac_hid_exit(void)
|
|
|
|
{
|
|
|
|
unregister_sysctl_table(mac_hid_sysctl_header);
|
|
|
|
|
|
|
|
if (mouse_emulate_buttons)
|
|
|
|
mac_hid_stop_emulation();
|
|
|
|
}
|
|
|
|
module_exit(mac_hid_exit);
|