XenevaOS
Loading...
Searching...
No Matches
input.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (c) 1999-2002 Vojtech Pavlik
4 */
5#ifndef _INPUT_H
6#define _INPUT_H
7
8#include <linux/types.h>
9#include <linux/time.h>
10#include <linux/list.h>
11#include <uapi/linux/input.h>
12/* Implementation details, userspace should not care about these */
13#define ABS_MT_FIRST ABS_MT_TOUCH_MAJOR
14#define ABS_MT_LAST ABS_MT_TOOL_Y
15
16/*
17 * In-kernel definitions.
18 */
19
20#include <linux/device.h>
21#include <linux/fs.h>
22#include <linux/timer.h>
24
25struct input_dev_poller;
26
33struct input_value {
34 __u16 type;
35 __u16 code;
36 __s32 value;
37};
38
39enum input_clock_type {
40 INPUT_CLK_REAL = 0,
41 INPUT_CLK_MONO,
42 INPUT_CLK_BOOT,
43 INPUT_CLK_MAX
44};
45
138struct input_dev {
139 const char *name;
140 const char *phys;
141 const char *uniq;
142 struct input_id id;
143
144 unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];
145
146 unsigned long evbit[BITS_TO_LONGS(EV_CNT)];
147 unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
148 unsigned long relbit[BITS_TO_LONGS(REL_CNT)];
149 unsigned long absbit[BITS_TO_LONGS(ABS_CNT)];
150 unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];
151 unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];
152 unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];
153 unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
154 unsigned long swbit[BITS_TO_LONGS(SW_CNT)];
155
156 unsigned int hint_events_per_packet;
157
158 unsigned int keycodemax;
159 unsigned int keycodesize;
160 void *keycode;
161
162 int (*setkeycode)(struct input_dev *dev,
163 const struct input_keymap_entry *ke,
164 unsigned int *old_keycode);
165 int (*getkeycode)(struct input_dev *dev,
166 struct input_keymap_entry *ke);
167
168 struct ff_device *ff;
169
170 struct input_dev_poller *poller;
171
172 unsigned int repeat_key;
173 struct timer_list timer;
174
175 int rep[REP_CNT];
176
177 struct input_mt *mt;
178
179 struct input_absinfo *absinfo;
180
181 unsigned long key[BITS_TO_LONGS(KEY_CNT)];
182 unsigned long led[BITS_TO_LONGS(LED_CNT)];
183 unsigned long snd[BITS_TO_LONGS(SND_CNT)];
184 unsigned long sw[BITS_TO_LONGS(SW_CNT)];
185
186 int (*open)(struct input_dev *dev);
187 void (*close)(struct input_dev *dev);
188 int (*flush)(struct input_dev *dev, struct file *file);
189 int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
190
191 struct input_handle __rcu *grab;
192
193 spinlock_t event_lock;
194 struct mutex mutex;
195
196 unsigned int users;
197 bool going_away;
198
199 struct device dev;
200
201 struct list_head h_list;
202 struct list_head node;
203
204 unsigned int num_vals;
205 unsigned int max_vals;
206 struct input_value *vals;
207
208 bool devres_managed;
209
210 ktime_t timestamp[INPUT_CLK_MAX];
211
212 bool inhibited;
213};
214#define to_input_dev(d) container_of(d, struct input_dev, dev)
215
216/*
217 * Verify that we are in sync with input_device_id mod_devicetable.h #defines
218 */
219
220#if EV_MAX != INPUT_DEVICE_ID_EV_MAX
221#error "EV_MAX and INPUT_DEVICE_ID_EV_MAX do not match"
222#endif
223
224#if KEY_MIN_INTERESTING != INPUT_DEVICE_ID_KEY_MIN_INTERESTING
225#error "KEY_MIN_INTERESTING and INPUT_DEVICE_ID_KEY_MIN_INTERESTING do not match"
226#endif
227
228#if KEY_MAX != INPUT_DEVICE_ID_KEY_MAX
229#error "KEY_MAX and INPUT_DEVICE_ID_KEY_MAX do not match"
230#endif
231
232#if REL_MAX != INPUT_DEVICE_ID_REL_MAX
233#error "REL_MAX and INPUT_DEVICE_ID_REL_MAX do not match"
234#endif
235
236#if ABS_MAX != INPUT_DEVICE_ID_ABS_MAX
237#error "ABS_MAX and INPUT_DEVICE_ID_ABS_MAX do not match"
238#endif
239
240#if MSC_MAX != INPUT_DEVICE_ID_MSC_MAX
241#error "MSC_MAX and INPUT_DEVICE_ID_MSC_MAX do not match"
242#endif
243
244#if LED_MAX != INPUT_DEVICE_ID_LED_MAX
245#error "LED_MAX and INPUT_DEVICE_ID_LED_MAX do not match"
246#endif
247
248#if SND_MAX != INPUT_DEVICE_ID_SND_MAX
249#error "SND_MAX and INPUT_DEVICE_ID_SND_MAX do not match"
250#endif
251
252#if FF_MAX != INPUT_DEVICE_ID_FF_MAX
253#error "FF_MAX and INPUT_DEVICE_ID_FF_MAX do not match"
254#endif
255
256#if SW_MAX != INPUT_DEVICE_ID_SW_MAX
257#error "SW_MAX and INPUT_DEVICE_ID_SW_MAX do not match"
258#endif
259
260#if INPUT_PROP_MAX != INPUT_DEVICE_ID_PROP_MAX
261#error "INPUT_PROP_MAX and INPUT_DEVICE_ID_PROP_MAX do not match"
262#endif
263
264#define INPUT_DEVICE_ID_MATCH_DEVICE \
265 (INPUT_DEVICE_ID_MATCH_BUS | INPUT_DEVICE_ID_MATCH_VENDOR | INPUT_DEVICE_ID_MATCH_PRODUCT)
266#define INPUT_DEVICE_ID_MATCH_DEVICE_AND_VERSION \
267 (INPUT_DEVICE_ID_MATCH_DEVICE | INPUT_DEVICE_ID_MATCH_VERSION)
268
269struct input_handle;
270
316struct input_handler {
317
318 void *private;
319
320 void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
321 unsigned int (*events)(struct input_handle *handle,
322 struct input_value *vals, unsigned int count);
323 bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
324 bool (*match)(struct input_handler *handler, struct input_dev *dev);
325 int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
326 void (*disconnect)(struct input_handle *handle);
327 void (*start)(struct input_handle *handle);
328
329 bool passive_observer;
330 bool legacy_minors;
331 int minor;
332 const char *name;
333
334 const struct input_device_id *id_table;
335
336 struct list_head h_list;
337 struct list_head node;
338};
339
357struct input_handle {
358 void *private;
359
360 int open;
361 const char *name;
362
363 struct input_dev *dev;
364 struct input_handler *handler;
365
366 unsigned int (*handle_events)(struct input_handle *handle,
367 struct input_value *vals,
368 unsigned int count);
369
370 struct list_head d_node;
371 struct list_head h_node;
372};
373
374struct input_dev __must_check *input_allocate_device(void);
375struct input_dev __must_check *devm_input_allocate_device(struct device *);
376void input_free_device(struct input_dev *dev);
377
378static inline struct input_dev *input_get_device(struct input_dev *dev)
379{
380 return dev ? to_input_dev(get_device(&dev->dev)) : NULL;
381}
382
383static inline void input_put_device(struct input_dev *dev)
384{
385 if (dev)
386 put_device(&dev->dev);
387}
388
389static inline void *input_get_drvdata(struct input_dev *dev)
390{
391 return dev_get_drvdata(&dev->dev);
392}
393
394static inline void input_set_drvdata(struct input_dev *dev, void *data)
395{
396 dev_set_drvdata(&dev->dev, data);
397}
398
399int __must_check input_register_device(struct input_dev *);
400void input_unregister_device(struct input_dev *);
401
402void input_reset_device(struct input_dev *);
403
404int input_setup_polling(struct input_dev *dev,
405 void (*poll_fn)(struct input_dev *dev));
406void input_set_poll_interval(struct input_dev *dev, unsigned int interval);
407void input_set_min_poll_interval(struct input_dev *dev, unsigned int interval);
408void input_set_max_poll_interval(struct input_dev *dev, unsigned int interval);
409int input_get_poll_interval(struct input_dev *dev);
410
411int __must_check input_register_handler(struct input_handler *);
412void input_unregister_handler(struct input_handler *);
413
414int __must_check input_get_new_minor(int legacy_base, unsigned int legacy_num,
415 bool allow_dynamic);
416void input_free_minor(unsigned int minor);
417
418int input_handler_for_each_handle(struct input_handler *, void *data,
419 int (*fn)(struct input_handle *, void *));
420
421int input_register_handle(struct input_handle *);
422void input_unregister_handle(struct input_handle *);
423
424int input_grab_device(struct input_handle *);
425void input_release_device(struct input_handle *);
426
427int input_open_device(struct input_handle *);
428void input_close_device(struct input_handle *);
429
430int input_flush_device(struct input_handle *handle, struct file *file);
431
432void input_set_timestamp(struct input_dev *dev, ktime_t timestamp);
433ktime_t *input_get_timestamp(struct input_dev *dev);
434
435void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
436void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value);
437
438static inline void input_report_key(struct input_dev *dev, unsigned int code, int value)
439{
440 input_event(dev, EV_KEY, code, !!value);
441}
442
443static inline void input_report_rel(struct input_dev *dev, unsigned int code, int value)
444{
445 input_event(dev, EV_REL, code, value);
446}
447
448static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value)
449{
450 input_event(dev, EV_ABS, code, value);
451}
452
453static inline void input_report_ff_status(struct input_dev *dev, unsigned int code, int value)
454{
455 input_event(dev, EV_FF_STATUS, code, value);
456}
457
458static inline void input_report_switch(struct input_dev *dev, unsigned int code, int value)
459{
460 input_event(dev, EV_SW, code, !!value);
461}
462
463static inline void input_sync(struct input_dev *dev)
464{
466}
467
468static inline void input_mt_sync(struct input_dev *dev)
469{
471}
472
473void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code);
474
485static inline void input_set_events_per_packet(struct input_dev *dev, int n_events)
486{
487 dev->hint_events_per_packet = n_events;
488}
489
490void input_alloc_absinfo(struct input_dev *dev);
491void input_set_abs_params(struct input_dev *dev, unsigned int axis,
492 int min, int max, int fuzz, int flat);
493void input_copy_abs(struct input_dev *dst, unsigned int dst_axis,
494 const struct input_dev *src, unsigned int src_axis);
495
496#define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item) \
497static inline int input_abs_get_##_suffix(struct input_dev *dev, \
498 unsigned int axis) \
499{ \
500 return dev->absinfo ? dev->absinfo[axis]._item : 0; \
501} \
502 \
503static inline void input_abs_set_##_suffix(struct input_dev *dev, \
504 unsigned int axis, int val) \
505{ \
506 input_alloc_absinfo(dev); \
507 if (dev->absinfo) \
508 dev->absinfo[axis]._item = val; \
509}
510
516INPUT_GENERATE_ABS_ACCESSORS(res, resolution)
517
518int input_scancode_to_scalar(const struct input_keymap_entry *ke,
519 unsigned int *scancode);
520
521int input_default_setkeycode(struct input_dev *dev,
522 const struct input_keymap_entry *ke,
523 unsigned int *old_keycode);
524
525int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke);
526int input_set_keycode(struct input_dev *dev,
527 const struct input_keymap_entry *ke);
528
529bool input_match_device_id(const struct input_dev *dev,
530 const struct input_device_id *id);
531
532void input_enable_softrepeat(struct input_dev *dev, int delay, int period);
533
534bool input_device_enabled(struct input_dev *dev);
535
536extern const struct class input_class;
537
567struct ff_device {
568 int (*upload)(struct input_dev *dev, struct ff_effect *effect,
569 struct ff_effect *old);
570 int (*erase)(struct input_dev *dev, int effect_id);
571
572 int (*playback)(struct input_dev *dev, int effect_id, int value);
573 void (*set_gain)(struct input_dev *dev, u16 gain);
574 void (*set_autocenter)(struct input_dev *dev, u16 magnitude);
575
576 void (*destroy)(struct ff_device *);
577 void (*stop)(struct ff_device *);
578
579 void *private;
580
581 unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
582
583 struct mutex mutex;
584
585 int max_effects;
586 struct ff_effect *effects;
587 struct file *effect_owners[] __counted_by(max_effects);
588};
589
590int input_ff_create(struct input_dev *dev, unsigned int max_effects);
591void input_ff_destroy(struct input_dev *dev);
592
593int input_ff_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
594
595int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, struct file *file);
596int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file);
597int input_ff_flush(struct input_dev *dev, struct file *file);
598
599int input_ff_create_memless(struct input_dev *dev, void *data,
600 int (*play_effect)(struct input_dev *, void *, struct ff_effect *));
601
602#endif
#define bool
Definition stdbool.h:35
#define __counted_by(m)
Definition stddef.h:64
XE_LIB int connect(int sockfd, sockaddr_ *addr, socklen_t addrlen)
int snd
Definition main.cpp:68
#define NULL
Definition actypes.h:561
#define open
Definition acwin.h:179
#define close
Definition acwin.h:182
void * fn
Definition audrv.c:980
#define BITS_TO_LONGS(nr)
Definition bordoisila_bits.h:39
#define __must_check
Definition compiler.h:114
#define __rcu
Definition compiler_types.h:72
uint32_t * flat
Definition compose3d.cpp:157
void * get_device(const void *dev)
void put_device(const void *dev)
int32_t __s32
Definition drm.h:41
uint16_t __u16
Definition drm.h:40
struct drm_crtc struct drm_plane struct drm_plane const struct drm_crtc_funcs const char * name
Definition drm_crtc.h:1242
const struct device * dev
Definition drm_print.h:519
#define ABS_CNT
Definition input-event-codes.h:926
#define SYN_REPORT
Definition input-event-codes.h:58
#define INPUT_PROP_CNT
Definition input-event-codes.h:33
#define REP_CNT
Definition input-event-codes.h:992
#define EV_REL
Definition input-event-codes.h:41
#define LED_CNT
Definition input-event-codes.h:983
#define SYN_MT_REPORT
Definition input-event-codes.h:60
#define REL_CNT
Definition input-event-codes.h:862
#define EV_SW
Definition input-event-codes.h:44
#define EV_ABS
Definition input-event-codes.h:42
#define EV_CNT
Definition input-event-codes.h:52
#define SW_CNT
Definition input-event-codes.h:952
#define EV_KEY
Definition input-event-codes.h:40
#define SND_CNT
Definition input-event-codes.h:1002
#define EV_SYN
Definition input-event-codes.h:39
#define MSC_CNT
Definition input-event-codes.h:965
#define KEY_CNT
Definition input-event-codes.h:835
#define EV_FF_STATUS
Definition input-event-codes.h:50
void * data
Definition kthread.h:30
void int node
Definition kthread.h:31
#define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item)
#define to_input_dev(d)
int64_t ktime_t
Definition kernel.h:404
uint16_t u16
Definition kernel.h:15
int spinlock_t
Definition kernel.h:44
char phys[]
#define min(a, b)
Definition minmax.h:24
#define max(a, b)
Definition minmax.h:28
Definition device.h:38
Definition fs.h:255
Definition input.h:473
Definition fs.h:142
Definition input.h:93
Definition input.h:39
Definition input.h:28
Definition input.h:59
Definition input.h:117
Definition mt.h:44
Definition list.h:11
Definition mutex.h:59
Definition timer.h:6
#define FF_CNT
Definition input.h:537