Loading...
1#ifndef _INPUT_COMPAT_H
2#define _INPUT_COMPAT_H
3
4/*
5 * 32bit compatibility wrappers for the input subsystem.
6 *
7 * Very heavily based on evdev.c - Copyright (c) 1999-2002 Vojtech Pavlik
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published by
11 * the Free Software Foundation.
12 */
13
14#include <linux/compiler.h>
15#include <linux/compat.h>
16#include <linux/input.h>
17
18#ifdef CONFIG_COMPAT
19
20/* Note to the author of this code: did it ever occur to
21 you why the ifdefs are needed? Think about it again. -AK */
22#if defined(CONFIG_X86_64) || defined(CONFIG_TILE)
23# define INPUT_COMPAT_TEST is_compat_task()
24#elif defined(CONFIG_S390)
25# define INPUT_COMPAT_TEST test_thread_flag(TIF_31BIT)
26#elif defined(CONFIG_MIPS)
27# define INPUT_COMPAT_TEST test_thread_flag(TIF_32BIT_ADDR)
28#else
29# define INPUT_COMPAT_TEST test_thread_flag(TIF_32BIT)
30#endif
31
32struct input_event_compat {
33 struct compat_timeval time;
34 __u16 type;
35 __u16 code;
36 __s32 value;
37};
38
39struct ff_periodic_effect_compat {
40 __u16 waveform;
41 __u16 period;
42 __s16 magnitude;
43 __s16 offset;
44 __u16 phase;
45
46 struct ff_envelope envelope;
47
48 __u32 custom_len;
49 compat_uptr_t custom_data;
50};
51
52struct ff_effect_compat {
53 __u16 type;
54 __s16 id;
55 __u16 direction;
56 struct ff_trigger trigger;
57 struct ff_replay replay;
58
59 union {
60 struct ff_constant_effect constant;
61 struct ff_ramp_effect ramp;
62 struct ff_periodic_effect_compat periodic;
63 struct ff_condition_effect condition[2]; /* One for each axis */
64 struct ff_rumble_effect rumble;
65 } u;
66};
67
68static inline size_t input_event_size(void)
69{
70 return INPUT_COMPAT_TEST ?
71 sizeof(struct input_event_compat) : sizeof(struct input_event);
72}
73
74#else
75
76static inline size_t input_event_size(void)
77{
78 return sizeof(struct input_event);
79}
80
81#endif /* CONFIG_COMPAT */
82
83int input_event_from_user(const char __user *buffer,
84 struct input_event *event);
85
86int input_event_to_user(char __user *buffer,
87 const struct input_event *event);
88
89int input_ff_effect_from_user(const char __user *buffer, size_t size,
90 struct ff_effect *effect);
91
92#endif /* _INPUT_COMPAT_H */
1/* SPDX-License-Identifier: GPL-2.0-only */
2#ifndef _INPUT_COMPAT_H
3#define _INPUT_COMPAT_H
4
5/*
6 * 32bit compatibility wrappers for the input subsystem.
7 *
8 * Very heavily based on evdev.c - Copyright (c) 1999-2002 Vojtech Pavlik
9 */
10
11#include <linux/compiler.h>
12#include <linux/compat.h>
13#include <linux/input.h>
14
15#ifdef CONFIG_COMPAT
16
17struct input_event_compat {
18 compat_ulong_t sec;
19 compat_ulong_t usec;
20 __u16 type;
21 __u16 code;
22 __s32 value;
23};
24
25struct ff_periodic_effect_compat {
26 __u16 waveform;
27 __u16 period;
28 __s16 magnitude;
29 __s16 offset;
30 __u16 phase;
31
32 struct ff_envelope envelope;
33
34 __u32 custom_len;
35 compat_uptr_t custom_data;
36};
37
38struct ff_effect_compat {
39 __u16 type;
40 __s16 id;
41 __u16 direction;
42 struct ff_trigger trigger;
43 struct ff_replay replay;
44
45 union {
46 struct ff_constant_effect constant;
47 struct ff_ramp_effect ramp;
48 struct ff_periodic_effect_compat periodic;
49 struct ff_condition_effect condition[2]; /* One for each axis */
50 struct ff_rumble_effect rumble;
51 } u;
52};
53
54static inline size_t input_event_size(void)
55{
56 return (in_compat_syscall() && !COMPAT_USE_64BIT_TIME) ?
57 sizeof(struct input_event_compat) : sizeof(struct input_event);
58}
59
60#else
61
62static inline size_t input_event_size(void)
63{
64 return sizeof(struct input_event);
65}
66
67#endif /* CONFIG_COMPAT */
68
69int input_event_from_user(const char __user *buffer,
70 struct input_event *event);
71
72int input_event_to_user(char __user *buffer,
73 const struct input_event *event);
74
75int input_ff_effect_from_user(const char __user *buffer, size_t size,
76 struct ff_effect *effect);
77
78#endif /* _INPUT_COMPAT_H */