[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 |
|
---|
[b3f8fb7] | 38 | typedef enum {
|
---|
[22af3af] | 39 | /** Read 1 byte from the I/O space. */
|
---|
[cecb0789] | 40 | CMD_PIO_READ_8 = 1,
|
---|
[22af3af] | 41 | /** Read 2 bytes from the I/O space. */
|
---|
[cecb0789] | 42 | CMD_PIO_READ_16,
|
---|
[22af3af] | 43 | /** Read 4 bytes from the I/O space. */
|
---|
[cecb0789] | 44 | CMD_PIO_READ_32,
|
---|
[22af3af] | 45 | /** Write 1 byte to the I/O space. */
|
---|
[cecb0789] | 46 | CMD_PIO_WRITE_8,
|
---|
[22af3af] | 47 | /** Write 2 bytes to the I/O space. */
|
---|
[cecb0789] | 48 | CMD_PIO_WRITE_16,
|
---|
[22af3af] | 49 | /** Write 4 bytes to the I/O space. */
|
---|
[cecb0789] | 50 | CMD_PIO_WRITE_32,
|
---|
[22af3af] | 51 | /**
|
---|
| 52 | * Perform a bit test on the source argument and store the result into
|
---|
| 53 | * the destination argument.
|
---|
| 54 | */
|
---|
[cecb0789] | 55 | CMD_BTEST,
|
---|
[22af3af] | 56 | /**
|
---|
| 57 | * Predicate the execution of the following N commands by the boolean
|
---|
| 58 | * value of the source argument.
|
---|
| 59 | */
|
---|
[cecb0789] | 60 | CMD_PREDICATE,
|
---|
[22af3af] | 61 | /** Accept the interrupt. */
|
---|
[cecb0789] | 62 | CMD_ACCEPT,
|
---|
[22af3af] | 63 | /** Decline the interrupt. */
|
---|
[cecb0789] | 64 | CMD_DECLINE,
|
---|
[b3f8fb7] | 65 | CMD_LAST
|
---|
| 66 | } irq_cmd_type;
|
---|
| 67 |
|
---|
| 68 | typedef struct {
|
---|
| 69 | irq_cmd_type cmd;
|
---|
| 70 | void *addr;
|
---|
[cecb0789] | 71 | unsigned long long value;
|
---|
| 72 | unsigned int srcarg;
|
---|
| 73 | unsigned int dstarg;
|
---|
[b3f8fb7] | 74 | } irq_cmd_t;
|
---|
| 75 |
|
---|
| 76 | typedef struct {
|
---|
| 77 | unsigned int cmdcount;
|
---|
| 78 | irq_cmd_t *cmds;
|
---|
| 79 | } irq_code_t;
|
---|
| 80 |
|
---|
| 81 | #ifdef KERNEL
|
---|
| 82 |
|
---|
[d99c1d2] | 83 | #include <typedefs.h>
|
---|
[0d107f31] | 84 | #include <adt/list.h>
|
---|
[cecb0789] | 85 | #include <adt/hash_table.h>
|
---|
[63530c62] | 86 | #include <synch/spinlock.h>
|
---|
[b3f8fb7] | 87 | #include <proc/task.h>
|
---|
[cecb0789] | 88 | #include <ipc/ipc.h>
|
---|
[0d107f31] | 89 |
|
---|
| 90 | typedef enum {
|
---|
| 91 | IRQ_DECLINE, /**< Decline to service. */
|
---|
| 92 | IRQ_ACCEPT /**< Accept to service. */
|
---|
| 93 | } irq_ownership_t;
|
---|
| 94 |
|
---|
| 95 | typedef enum {
|
---|
| 96 | IRQ_TRIGGER_LEVEL = 1,
|
---|
| 97 | IRQ_TRIGGER_EDGE
|
---|
| 98 | } irq_trigger_t;
|
---|
| 99 |
|
---|
[b3f8fb7] | 100 | struct irq;
|
---|
[6cd9aa6] | 101 | typedef void (* irq_handler_t)(struct irq *);
|
---|
[b3f8fb7] | 102 |
|
---|
[8d2760f] | 103 | /** Type for function used to clear the interrupt. */
|
---|
[6cd9aa6] | 104 | typedef void (* cir_t)(void *, inr_t);
|
---|
[8d2760f] | 105 |
|
---|
[b3f8fb7] | 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 | */
|
---|
| 111 | typedef struct {
|
---|
[80bcaed] | 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;
|
---|
[cecb0789] | 118 | /** Arguments that will be sent if the IRQ is claimed. */
|
---|
| 119 | unative_t scratch[IPC_CALL_LEN];
|
---|
[80bcaed] | 120 | /** Top-half pseudocode. */
|
---|
| 121 | irq_code_t *code;
|
---|
| 122 | /** Counter. */
|
---|
[98000fb] | 123 | size_t counter;
|
---|
[80bcaed] | 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;
|
---|
[b3f8fb7] | 129 | } ipc_notif_cfg_t;
|
---|
[0d107f31] | 130 |
|
---|
| 131 | /** Structure representing one device IRQ.
|
---|
| 132 | *
|
---|
[80bcaed] | 133 | * If one device has multiple interrupts, there will be multiple irq_t
|
---|
| 134 | * instantions with the same devno.
|
---|
[0d107f31] | 135 | */
|
---|
[b3f8fb7] | 136 | typedef struct irq {
|
---|
[0d107f31] | 137 | /** Hash table link. */
|
---|
| 138 | link_t link;
|
---|
| 139 |
|
---|
[63530c62] | 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);
|
---|
[7bcfbbc] | 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;
|
---|
[63530c62] | 154 |
|
---|
[0d107f31] | 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;
|
---|
[7bcfbbc] | 160 | /** Trigger level of the IRQ. */
|
---|
[0d107f31] | 161 | irq_trigger_t trigger;
|
---|
| 162 | /** Claim ownership of the IRQ. */
|
---|
[c9b550b] | 163 | irq_ownership_t (* claim)(struct irq *);
|
---|
[0d107f31] | 164 | /** Handler for this IRQ and device. */
|
---|
| 165 | irq_handler_t handler;
|
---|
[6cd9aa6] | 166 | /** Instance argument for the handler and the claim function. */
|
---|
| 167 | void *instance;
|
---|
[63530c62] | 168 |
|
---|
[8d2760f] | 169 | /** Clear interrupt routine. */
|
---|
| 170 | cir_t cir;
|
---|
| 171 | /** First argument to the clear interrupt routine. */
|
---|
| 172 | void *cir_arg;
|
---|
| 173 |
|
---|
[2b017ba] | 174 | /** Notification configuration structure. */
|
---|
| 175 | ipc_notif_cfg_t notif_cfg;
|
---|
[b3f8fb7] | 176 | } irq_t;
|
---|
[0d107f31] | 177 |
|
---|
[cecb0789] | 178 | SPINLOCK_EXTERN(irq_uspace_hash_table_lock);
|
---|
| 179 | extern hash_table_t irq_uspace_hash_table;
|
---|
| 180 |
|
---|
[98000fb] | 181 | extern void irq_init(size_t, size_t);
|
---|
[6cd9aa6] | 182 | extern void irq_initialize(irq_t *);
|
---|
| 183 | extern void irq_register(irq_t *);
|
---|
| 184 | extern irq_t *irq_dispatch_and_lock(inr_t);
|
---|
[0d107f31] | 185 |
|
---|
| 186 | #endif
|
---|
| 187 |
|
---|
[b3f8fb7] | 188 | #endif
|
---|
| 189 |
|
---|
[0d107f31] | 190 | /** @}
|
---|
| 191 | */
|
---|