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

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

major code revision

  • replace spinlocks taken with interrupts disabled with irq_spinlocks
  • change spacing (not indendation) to be tab-size independent
  • use unsigned integer types where appropriate (especially bit flags)
  • visual separation
  • remove argument names in function prototypes
  • string changes
  • correct some formating directives
  • replace various cryptic single-character variables (t, a, m, c, b, etc.) with proper identifiers (thread, task, timeout, as, itm, itc, etc.)
  • unify some assembler constructs
  • unused page table levels are now optimized out in compile time
  • replace several ints (with boolean semantics) with bools
  • use specifically sized types instead of generic types where appropriate (size_t, uint32_t, btree_key_t)
  • improve comments
  • split asserts with conjuction into multiple independent asserts
  • Property mode set to 100644
File size: 5.2 KB
RevLine 
[0d107f31]1/*
[df4ed85]2 * Copyright (c) 2006 Jakub Jermar
[0d107f31]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
[7dcf22a]29/** @addtogroup genericddi
[0d107f31]30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_IRQ_H_
36#define KERN_IRQ_H_
37
[da1bafb]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
[b3f8fb7]49typedef enum {
[22af3af]50 /** Read 1 byte from the I/O space. */
[cecb0789]51 CMD_PIO_READ_8 = 1,
[22af3af]52 /** Read 2 bytes from the I/O space. */
[cecb0789]53 CMD_PIO_READ_16,
[22af3af]54 /** Read 4 bytes from the I/O space. */
[cecb0789]55 CMD_PIO_READ_32,
[22af3af]56 /** Write 1 byte to the I/O space. */
[cecb0789]57 CMD_PIO_WRITE_8,
[22af3af]58 /** Write 2 bytes to the I/O space. */
[cecb0789]59 CMD_PIO_WRITE_16,
[22af3af]60 /** Write 4 bytes to the I/O space. */
[cecb0789]61 CMD_PIO_WRITE_32,
[da1bafb]62
[22af3af]63 /**
64 * Perform a bit test on the source argument and store the result into
65 * the destination argument.
66 */
[cecb0789]67 CMD_BTEST,
[da1bafb]68
[22af3af]69 /**
70 * Predicate the execution of the following N commands by the boolean
71 * value of the source argument.
72 */
[cecb0789]73 CMD_PREDICATE,
[da1bafb]74
[22af3af]75 /** Accept the interrupt. */
[cecb0789]76 CMD_ACCEPT,
[22af3af]77 /** Decline the interrupt. */
[cecb0789]78 CMD_DECLINE,
[b3f8fb7]79 CMD_LAST
80} irq_cmd_type;
81
82typedef struct {
83 irq_cmd_type cmd;
84 void *addr;
[da1bafb]85 uint32_t value;
86 uintptr_t srcarg;
87 uintptr_t dstarg;
[b3f8fb7]88} irq_cmd_t;
89
90typedef struct {
[da1bafb]91 size_t cmdcount;
[b3f8fb7]92 irq_cmd_t *cmds;
93} irq_code_t;
94
95#ifdef KERNEL
96
[0d107f31]97typedef enum {
[da1bafb]98 IRQ_DECLINE, /**< Decline to service. */
99 IRQ_ACCEPT /**< Accept to service. */
[0d107f31]100} irq_ownership_t;
101
102typedef enum {
103 IRQ_TRIGGER_LEVEL = 1,
104 IRQ_TRIGGER_EDGE
105} irq_trigger_t;
106
[b3f8fb7]107struct irq;
[6cd9aa6]108typedef void (* irq_handler_t)(struct irq *);
[b3f8fb7]109
[8d2760f]110/** Type for function used to clear the interrupt. */
[6cd9aa6]111typedef void (* cir_t)(void *, inr_t);
[8d2760f]112
[b3f8fb7]113/** IPC notification config structure.
114 *
115 * Primarily, this structure is encapsulated in the irq_t structure.
116 * It is protected by irq_t::lock.
[da1bafb]117 *
[b3f8fb7]118 */
119typedef struct {
[80bcaed]120 /** When false, notifications are not sent. */
121 bool notify;
122 /** Answerbox for notifications. */
123 answerbox_t *answerbox;
124 /** Method to be used for the notification. */
125 unative_t method;
[cecb0789]126 /** Arguments that will be sent if the IRQ is claimed. */
[da1bafb]127 uint32_t scratch[IPC_CALL_LEN];
[80bcaed]128 /** Top-half pseudocode. */
129 irq_code_t *code;
130 /** Counter. */
[98000fb]131 size_t counter;
[da1bafb]132
[80bcaed]133 /**
134 * Link between IRQs that are notifying the same answerbox. The list is
135 * protected by the answerbox irq_lock.
136 */
137 link_t link;
[b3f8fb7]138} ipc_notif_cfg_t;
[0d107f31]139
140/** Structure representing one device IRQ.
141 *
[80bcaed]142 * If one device has multiple interrupts, there will be multiple irq_t
143 * instantions with the same devno.
[da1bafb]144 *
[0d107f31]145 */
[b3f8fb7]146typedef struct irq {
[0d107f31]147 /** Hash table link. */
148 link_t link;
[da1bafb]149
[63530c62]150 /** Lock protecting everything in this structure
151 * except the link member. When both the IRQ
152 * hash table lock and this lock are to be acquired,
153 * this lock must not be taken first.
154 */
[da1bafb]155 IRQ_SPINLOCK_DECLARE(lock);
[7bcfbbc]156
157 /** Send EOI before processing the interrupt.
158 * This is essential for timer interrupt which
159 * has to be acknowledged before doing preemption
160 * to make sure another timer interrupt will
161 * be eventually generated.
162 */
163 bool preack;
[da1bafb]164
[0d107f31]165 /** Unique device number. -1 if not yet assigned. */
166 devno_t devno;
[da1bafb]167
[0d107f31]168 /** Actual IRQ number. -1 if not yet assigned. */
169 inr_t inr;
[7bcfbbc]170 /** Trigger level of the IRQ. */
[0d107f31]171 irq_trigger_t trigger;
172 /** Claim ownership of the IRQ. */
[c9b550b]173 irq_ownership_t (* claim)(struct irq *);
[0d107f31]174 /** Handler for this IRQ and device. */
175 irq_handler_t handler;
[6cd9aa6]176 /** Instance argument for the handler and the claim function. */
177 void *instance;
[da1bafb]178
[8d2760f]179 /** Clear interrupt routine. */
180 cir_t cir;
181 /** First argument to the clear interrupt routine. */
182 void *cir_arg;
[da1bafb]183
[2b017ba]184 /** Notification configuration structure. */
185 ipc_notif_cfg_t notif_cfg;
[b3f8fb7]186} irq_t;
[0d107f31]187
[da1bafb]188IRQ_SPINLOCK_EXTERN(irq_uspace_hash_table_lock);
[cecb0789]189extern hash_table_t irq_uspace_hash_table;
190
[98000fb]191extern void irq_init(size_t, size_t);
[6cd9aa6]192extern void irq_initialize(irq_t *);
193extern void irq_register(irq_t *);
194extern irq_t *irq_dispatch_and_lock(inr_t);
[0d107f31]195
[da1bafb]196#endif /* KERNEL */
[0d107f31]197
[b3f8fb7]198#endif
199
[0d107f31]200/** @}
201 */
Note: See TracBrowser for help on using the repository browser.