1 /*
2  * Copyright (c) 2014 Jean-Sebastien Pedron <dumbbell@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer
10  *    in this position and unchanged.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef _LIBDEVQ_H_
28 #define _LIBDEVQ_H_
29 
30 #define	DEVQ_MAX_DEVS	16
31 
32 typedef enum {
33 	DEVQ_ATTACHED = 1U,
34 	DEVQ_DETACHED,
35 	DEVQ_NOTICE,
36 	DEVQ_UNKNOWN
37 } devq_event_t;
38 
39 typedef enum {
40 	DEVQ_DEVICE_UNKNOWN = 1U,
41 	DEVQ_DEVICE_KEYBOARD,
42 	DEVQ_DEVICE_MOUSE,
43 	DEVQ_DEVICE_JOYSTICK,
44 	DEVQ_DEVICE_TOUCHPAD,
45 	DEVQ_DEVICE_TOUCHSCREEN
46 } devq_device_t;
47 
48 typedef enum {
49 	DEVQ_CLASS_UNKNOWN = 1U,
50 	DEVQ_CLASS_INPUT
51 } devq_class_t;
52 
53 struct devq_evmon;
54 struct devq_event;
55 struct devq_device;
56 
57 int		devq_device_get_devpath_from_fd(int fd,
58 		    char *path, size_t *path_len);
59 int		devq_device_get_pciid_from_fd(int fd,
60 		    int *vendor_id, int *device_id);
61 int		devq_device_get_pciid_full_from_fd(int fd,
62 		    int *vendor_id, int *device_id,
63 		    int *subversion_id, int *subdevice_id,
64 		    int *revision_id);
65 
66 int		devq_device_get_pcibusaddr(int fd,
67 		    int *domain, int *bus,
68 		    int *slot, int *function);
69 
70 int		devq_device_drm_get_drvname_from_fd(int fd,
71 		    char *driver_name, size_t *driver_name_len);
72 devq_device_t	devq_device_get_type(struct devq_device *);
73 devq_class_t	devq_device_get_class(struct devq_device *);
74 const char *	devq_device_get_path(struct devq_device *);
75 const char *	devq_device_get_product(struct devq_device *);
76 const char *	devq_device_get_vendor(struct devq_device *);
77 
78 struct devq_evmon *	devq_event_monitor_init(void);
79 void			devq_event_monitor_fini(struct devq_evmon *);
80 int			devq_event_monitor_get_fd(struct devq_evmon *);
81 int			devq_event_monitor_poll(struct devq_evmon *);
82 struct devq_event *	devq_event_monitor_read(struct devq_evmon *);
83 struct devq_device *	devq_event_get_device(struct devq_event *);
84 devq_event_t		devq_event_get_type(struct devq_event *);
85 const char *		devq_event_dump(struct devq_event *);
86 void			devq_event_free(struct devq_event *);
87 
88 #endif /* _LIBDEVQ_H_ */
89