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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6ab8697 was 22af3af, checked in by Jakub Jermar <jakub@…>, 16 years ago

Add basic description of the pseudocode commands.

  • Property mode set to 100644
File size: 5.2 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
38typedef enum {
39 /** Read 1 byte from the I/O space. */
40 CMD_PIO_READ_8 = 1,
41 /** Read 2 bytes from the I/O space. */
42 CMD_PIO_READ_16,
43 /** Read 4 bytes from the I/O space. */
44 CMD_PIO_READ_32,
45 /** Write 1 byte to the I/O space. */
46 CMD_PIO_WRITE_8,
47 /** Write 2 bytes to the I/O space. */
48 CMD_PIO_WRITE_16,
49 /** Write 4 bytes to the I/O space. */
50 CMD_PIO_WRITE_32,
51 /**
52 * Perform a bit test on the source argument and store the result into
53 * the destination argument.
54 */
55 CMD_BTEST,
56 /**
57 * Predicate the execution of the following N commands by the boolean
58 * value of the source argument.
59 */
60 CMD_PREDICATE,
61 /** Accept the interrupt. */
62 CMD_ACCEPT,
63 /** Decline the interrupt. */
64 CMD_DECLINE,
65 CMD_LAST
66} irq_cmd_type;
67
68typedef struct {
69 irq_cmd_type cmd;
70 void *addr;
71 unsigned long long value;
72 unsigned int srcarg;
73 unsigned int dstarg;
74} irq_cmd_t;
75
76typedef struct {
77 unsigned int cmdcount;
78 irq_cmd_t *cmds;
79} irq_code_t;
80
81#ifdef KERNEL
82
83#include <arch/types.h>
84#include <adt/list.h>
85#include <adt/hash_table.h>
86#include <synch/spinlock.h>
87#include <proc/task.h>
88#include <ipc/ipc.h>
89
90typedef enum {
91 IRQ_DECLINE, /**< Decline to service. */
92 IRQ_ACCEPT /**< Accept to service. */
93} irq_ownership_t;
94
95typedef enum {
96 IRQ_TRIGGER_LEVEL = 1,
97 IRQ_TRIGGER_EDGE
98} irq_trigger_t;
99
100struct irq;
101typedef void (* irq_handler_t)(struct irq *);
102
103/** Type for function used to clear the interrupt. */
104typedef void (* cir_t)(void *, inr_t);
105
106/** IPC notification config structure.
107 *
108 * Primarily, this structure is encapsulated in the irq_t structure.
109 * It is protected by irq_t::lock.
110 */
111typedef struct {
112 /** When false, notifications are not sent. */
113 bool notify;
114 /** Answerbox for notifications. */
115 answerbox_t *answerbox;
116 /** Method to be used for the notification. */
117 unative_t method;
118 /** Arguments that will be sent if the IRQ is claimed. */
119 unative_t scratch[IPC_CALL_LEN];
120 /** Top-half pseudocode. */
121 irq_code_t *code;
122 /** Counter. */
123 size_t counter;
124 /**
125 * Link between IRQs that are notifying the same answerbox. The list is
126 * protected by the answerbox irq_lock.
127 */
128 link_t link;
129} ipc_notif_cfg_t;
130
131/** Structure representing one device IRQ.
132 *
133 * If one device has multiple interrupts, there will be multiple irq_t
134 * instantions with the same devno.
135 */
136typedef struct irq {
137 /** Hash table link. */
138 link_t link;
139
140 /** Lock protecting everything in this structure
141 * except the link member. When both the IRQ
142 * hash table lock and this lock are to be acquired,
143 * this lock must not be taken first.
144 */
145 SPINLOCK_DECLARE(lock);
146
147 /** Send EOI before processing the interrupt.
148 * This is essential for timer interrupt which
149 * has to be acknowledged before doing preemption
150 * to make sure another timer interrupt will
151 * be eventually generated.
152 */
153 bool preack;
154
155 /** Unique device number. -1 if not yet assigned. */
156 devno_t devno;
157
158 /** Actual IRQ number. -1 if not yet assigned. */
159 inr_t inr;
160 /** Trigger level of the IRQ. */
161 irq_trigger_t trigger;
162 /** Claim ownership of the IRQ. */
163 irq_ownership_t (* claim)(struct irq *);
164 /** Handler for this IRQ and device. */
165 irq_handler_t handler;
166 /** Instance argument for the handler and the claim function. */
167 void *instance;
168
169 /** Clear interrupt routine. */
170 cir_t cir;
171 /** First argument to the clear interrupt routine. */
172 void *cir_arg;
173
174 /** Notification configuration structure. */
175 ipc_notif_cfg_t notif_cfg;
176} irq_t;
177
178SPINLOCK_EXTERN(irq_uspace_hash_table_lock);
179extern hash_table_t irq_uspace_hash_table;
180
181extern void irq_init(size_t, size_t);
182extern void irq_initialize(irq_t *);
183extern void irq_register(irq_t *);
184extern irq_t *irq_dispatch_and_lock(inr_t);
185
186#endif
187
188#endif
189
190/** @}
191 */
Note: See TracBrowser for help on using the repository browser.