xref: /linux/arch/um/include/shared/irq_kern.h (revision a1c613ae4c322ddd58d5a8539dbfba2a0380a8c0)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
4  */
5 
6 #ifndef __IRQ_KERN_H__
7 #define __IRQ_KERN_H__
8 
9 #include <linux/interrupt.h>
10 #include <linux/time-internal.h>
11 #include <asm/ptrace.h>
12 #include "irq_user.h"
13 
14 #define UM_IRQ_ALLOC	-1
15 
16 int um_request_irq(int irq, int fd, enum um_irq_type type,
17 		   irq_handler_t handler, unsigned long irqflags,
18 		   const char *devname, void *dev_id);
19 
20 #ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT
21 /**
22  * um_request_irq_tt - request an IRQ with timetravel handler
23  *
24  * @irq: the IRQ number, or %UM_IRQ_ALLOC
25  * @fd: The file descriptor to request an IRQ for
26  * @type: read or write
27  * @handler: the (generic style) IRQ handler
28  * @irqflags: Linux IRQ flags
29  * @devname: name for this to show
30  * @dev_id: data pointer to pass to the IRQ handler
31  * @timetravel_handler: the timetravel interrupt handler, invoked with the IRQ
32  *	number, fd, dev_id and time-travel event pointer.
33  *
34  * Returns: The interrupt number assigned or a negative error.
35  *
36  * Note that the timetravel handler is invoked only if the time_travel_mode is
37  * %TT_MODE_EXTERNAL, and then it is invoked even while the system is suspended!
38  * This function must call time_travel_add_irq_event() for the event passed with
39  * an appropriate delay, before sending an ACK on the socket it was invoked for.
40  *
41  * If this was called while the system is suspended, then adding the event will
42  * cause the system to resume.
43  *
44  * Since this function will almost certainly have to handle the FD's condition,
45  * a read will consume the message, and after that it is up to the code using
46  * it to pass such a message to the @handler in whichever way it can.
47  *
48  * If time_travel_mode is not %TT_MODE_EXTERNAL the @timetravel_handler will
49  * not be invoked at all and the @handler must handle the FD becoming
50  * readable (or writable) instead. Use um_irq_timetravel_handler_used() to
51  * distinguish these cases.
52  *
53  * See virtio_uml.c for an example.
54  */
55 int um_request_irq_tt(int irq, int fd, enum um_irq_type type,
56 		      irq_handler_t handler, unsigned long irqflags,
57 		      const char *devname, void *dev_id,
58 		      void (*timetravel_handler)(int, int, void *,
59 						 struct time_travel_event *));
60 #else
61 static inline
um_request_irq_tt(int irq,int fd,enum um_irq_type type,irq_handler_t handler,unsigned long irqflags,const char * devname,void * dev_id,void (* timetravel_handler)(int,int,void *,struct time_travel_event *))62 int um_request_irq_tt(int irq, int fd, enum um_irq_type type,
63 		      irq_handler_t handler, unsigned long irqflags,
64 		      const char *devname, void *dev_id,
65 		      void (*timetravel_handler)(int, int, void *,
66 						 struct time_travel_event *))
67 {
68 	return um_request_irq(irq, fd, type, handler, irqflags,
69 			      devname, dev_id);
70 }
71 #endif
72 
um_irq_timetravel_handler_used(void)73 static inline bool um_irq_timetravel_handler_used(void)
74 {
75 	return time_travel_mode == TT_MODE_EXTERNAL;
76 }
77 
78 void um_free_irq(int irq, void *dev_id);
79 void free_irqs(void);
80 #endif
81