1 #ifndef	INTERRUPT_H
2 #define	INTERRUPT_H
3 
4 /*
5  *  Copyright (C) 2006-2010  Anders Gavare.  All rights reserved.
6  *
7  *  Redistribution and use in source and binary forms, with or without
8  *  modification, are permitted provided that the following conditions are met:
9  *
10  *  1. Redistributions of source code must retain the above copyright
11  *     notice, this list of conditions and the following disclaimer.
12  *  2. Redistributions in binary form must reproduce the above copyright
13  *     notice, this list of conditions and the following disclaimer in the
14  *     documentation and/or other materials provided with the distribution.
15  *  3. The name of the author may not be used to endorse or promote products
16  *     derived from this software without specific prior written permission.
17  *
18  *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  *  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  *  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  *  SUCH DAMAGE.
29  *
30  *
31  *  Definitions related to the Interrupt subsystem.
32  */
33 
34 #include "misc.h"
35 
36 struct interrupt {
37 	/*  Functions used to assert and deassert the interrupt.  */
38 	void		(*interrupt_assert)(struct interrupt *);
39 	void		(*interrupt_deassert)(struct interrupt *);
40 
41 	/*
42 	 *  The interrupt "line" number, or "pin" number, is an internal number
43 	 *  used by interrupt_assert() and interrupt_deassert(). It may
44 	 *  correspond to a physical interrupt number, or it may be ignored
45 	 *  completely.
46 	 *
47 	 *  This can either be a small integer corresponding to the interrupt
48 	 *  pin number, or an entire interrupt mask (for controllers with at
49 	 *  most 32 interrupts).
50 	 */
51 	uint32_t	line;
52 
53 	/*
54 	 *  The extra pointer is a pointer to the (conceptual) interrupt
55 	 *  handler. For a CPU interrupt, this is a pointer to the CPU. For
56 	 *  e.g. a 8259 interrupt, it is a pointer to the dev_8259 which will
57 	 *  handle it.
58 	 */
59 	void		*extra;
60 
61 	/*
62 	 *  Actual name of the interrupt. This is a complete "path", e.g.
63 	 *  "machine[0].cpu[1].irq[3].isa[14]". It is used for
64 	 *  connecting/disconnecting, and debug output.
65 	 */
66 	char		*name;
67 };
68 
69 
70 /*
71  *  Macros to make code using the interrupt struct a bit more consise:
72  */
73 
74 #define	INTERRUPT_ASSERT(istruct)	(istruct).interrupt_assert(&(istruct))
75 #define	INTERRUPT_DEASSERT(istruct)	(istruct).interrupt_deassert(&(istruct))
76 
77 #define	INTERRUPT_CONNECT(name,istruct)		{		\
78 	interrupt_handler_lookup(name, &(istruct));		\
79 	interrupt_connect(&(istruct), 0);			\
80 	}
81 
82 #define	INTERRUPT_CONNECT_EXCLUSIVE(name,istruct)	{	\
83 	interrupt_handler_lookup(name, &(istruct));		\
84 	interrupt_connect(&(istruct), 1);			\
85 	}
86 
87 
88 /*
89  *  Registration of interrupt handlers:
90  *
91  *  Each interrupt handler (i.e. CPUs, interrupt controllers, various bus
92  *  controllers) should call interrupt_handler_register() to register itself.
93  */
94 
95 void interrupt_handler_register(struct interrupt *templ);
96 void interrupt_handler_remove(const char *name);
97 int interrupt_handler_lookup(const char *name, struct interrupt *templ);
98 
99 
100 /*
101  *  Functions used to keep track of exclusive and non-exclusive users,
102  *  respectively, of an interrupt.
103  *
104  *  If interrupt_connect() returns, it means it succeeded. On failure, the
105  *  emulator exits. There may be up to 1 exclusive user and no non-exclusive
106  *  users, or 0 exclusive users and any number of non-exclusive users.
107  */
108 
109 void interrupt_connect(struct interrupt *i, int exclusive);
110 void interrupt_disconnect(struct interrupt *i, int exclusive);
111 
112 
113 #endif	/*  INTERRUPT_H  */
114