source: mainline/kernel/generic/include/ddi/irq.h@ 97186929

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 97186929 was 9cdac5a, checked in by martin@…>, 15 years ago

add CMD_PIO_WRITE_A_x commands which store values from scratch space to I/O space

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*
2 * Copyright (c) 2006 Jakub Jermar
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 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - 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 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup genericddi
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_IRQ_H_
36#define KERN_IRQ_H_
37
38#ifdef KERNEL
39
40#include <typedefs.h>
41#include <adt/list.h>
42#include <adt/hash_table.h>
43#include <synch/spinlock.h>
44#include <proc/task.h>
45#include <ipc/ipc.h>
46
47#endif /* KERNEL */
48
49typedef enum {
50 /** Read 1 byte from the I/O space. */
51 CMD_PIO_READ_8 = 1,
52 /** Read 2 bytes from the I/O space. */
53 CMD_PIO_READ_16,
54 /** Read 4 bytes from the I/O space. */
55 CMD_PIO_READ_32,
56
57 /** Write 1 byte to the I/O space. */
58 CMD_PIO_WRITE_8,
59 /** Write 2 bytes to the I/O space. */
60 CMD_PIO_WRITE_16,
61 /** Write 4 bytes to the I/O space. */
62 CMD_PIO_WRITE_32,
63
64 /**
65 * Write 1 byte from the source argument
66 * to the I/O space.
67 */
68 CMD_PIO_WRITE_A_8,
69 /**
70 * Write 2 bytes from the source argument
71 * to the I/O space.
72 */
73 CMD_PIO_WRITE_A_16,
74 /**
75 * Write 4 bytes from the source argument
76 * to the I/O space.
77 */
78 CMD_PIO_WRITE_A_32,
79
80 /**
81 * Perform a bit masking on the source argument
82 * and store the result into the destination argument.
83 */
84 CMD_BTEST,
85
86 /**
87 * Predicate the execution of the following
88 * N commands by the boolean value of the source
89 * argument.
90 */
91 CMD_PREDICATE,
92
93 /** Accept the interrupt. */
94 CMD_ACCEPT,
95
96 /** Decline the interrupt. */
97 CMD_DECLINE,
98 CMD_LAST
99} irq_cmd_type;
100
101typedef struct {
102 irq_cmd_type cmd;
103 void *addr;
104 uint32_t value;
105 uintptr_t srcarg;
106 uintptr_t dstarg;
107} irq_cmd_t;
108
109typedef struct {
110 size_t cmdcount;
111 irq_cmd_t *cmds;
112} irq_code_t;
113
114#ifdef KERNEL
115
116typedef enum {
117 IRQ_DECLINE, /**< Decline to service. */
118 IRQ_ACCEPT /**< Accept to service. */
119} irq_ownership_t;
120
121typedef enum {
122 IRQ_TRIGGER_LEVEL = 1,
123 IRQ_TRIGGER_EDGE
124} irq_trigger_t;
125
126struct irq;
127typedef void (* irq_handler_t)(struct irq *);
128
129/** Type for function used to clear the interrupt. */
130typedef void (* cir_t)(void *, inr_t);
131
132/** IPC notification config structure.
133 *
134 * Primarily, this structure is encapsulated in the irq_t structure.
135 * It is protected by irq_t::lock.
136 *
137 */
138typedef struct {
139 /** When false, notifications are not sent. */
140 bool notify;
141 /** Answerbox for notifications. */
142 answerbox_t *answerbox;
143 /** Interface and method to be used for the notification. */
144 sysarg_t imethod;
145 /** Arguments that will be sent if the IRQ is claimed. */
146 uint32_t scratch[IPC_CALL_LEN];
147 /** Top-half pseudocode. */
148 irq_code_t *code;
149 /** Counter. */
150 size_t counter;
151
152 /**
153 * Link between IRQs that are notifying the same answerbox. The list is
154 * protected by the answerbox irq_lock.
155 */
156 link_t link;
157} ipc_notif_cfg_t;
158
159/** Structure representing one device IRQ.
160 *
161 * If one device has multiple interrupts, there will be multiple irq_t
162 * instantions with the same devno.
163 *
164 */
165typedef struct irq {
166 /** Hash table link. */
167 link_t link;
168
169 /** Lock protecting everything in this structure
170 * except the link member. When both the IRQ
171 * hash table lock and this lock are to be acquired,
172 * this lock must not be taken first.
173 */
174 IRQ_SPINLOCK_DECLARE(lock);
175
176 /** Send EOI before processing the interrupt.
177 * This is essential for timer interrupt which
178 * has to be acknowledged before doing preemption
179 * to make sure another timer interrupt will
180 * be eventually generated.
181 */
182 bool preack;
183
184 /** Unique device number. -1 if not yet assigned. */
185 devno_t devno;
186
187 /** Actual IRQ number. -1 if not yet assigned. */
188 inr_t inr;
189 /** Trigger level of the IRQ. */
190 irq_trigger_t trigger;
191 /** Claim ownership of the IRQ. */
192 irq_ownership_t (* claim)(struct irq *);
193 /** Handler for this IRQ and device. */
194 irq_handler_t handler;
195 /** Instance argument for the handler and the claim function. */
196 void *instance;
197
198 /** Clear interrupt routine. */
199 cir_t cir;
200 /** First argument to the clear interrupt routine. */
201 void *cir_arg;
202
203 /** Notification configuration structure. */
204 ipc_notif_cfg_t notif_cfg;
205} irq_t;
206
207IRQ_SPINLOCK_EXTERN(irq_uspace_hash_table_lock);
208extern hash_table_t irq_uspace_hash_table;
209
210extern inr_t last_inr;
211
212extern void irq_init(size_t, size_t);
213extern void irq_initialize(irq_t *);
214extern void irq_register(irq_t *);
215extern irq_t *irq_dispatch_and_lock(inr_t);
216
217#endif /* KERNEL */
218
219#endif
220
221/** @}
222 */
Note: See TracBrowser for help on using the repository browser.