[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 |
|
---|
[174156fd] | 29 | /** @addtogroup kernel_generic_ddi
|
---|
[0d107f31] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[c0699467] | 35 | #ifndef KERN_DDI_IRQ_H_
|
---|
| 36 | #define KERN_DDI_IRQ_H_
|
---|
[da1bafb] | 37 |
|
---|
| 38 | #include <typedefs.h>
|
---|
[c0699467] | 39 | #include <abi/ddi/irq.h>
|
---|
[da1bafb] | 40 | #include <adt/list.h>
|
---|
| 41 | #include <adt/hash_table.h>
|
---|
| 42 | #include <synch/spinlock.h>
|
---|
| 43 | #include <proc/task.h>
|
---|
| 44 | #include <ipc/ipc.h>
|
---|
[431c402] | 45 | #include <mm/slab.h>
|
---|
[da1bafb] | 46 |
|
---|
[0d107f31] | 47 | typedef enum {
|
---|
[da1bafb] | 48 | IRQ_DECLINE, /**< Decline to service. */
|
---|
| 49 | IRQ_ACCEPT /**< Accept to service. */
|
---|
[0d107f31] | 50 | } irq_ownership_t;
|
---|
| 51 |
|
---|
| 52 | typedef enum {
|
---|
| 53 | IRQ_TRIGGER_LEVEL = 1,
|
---|
| 54 | IRQ_TRIGGER_EDGE
|
---|
| 55 | } irq_trigger_t;
|
---|
| 56 |
|
---|
[b3f8fb7] | 57 | struct irq;
|
---|
[c0699467] | 58 |
|
---|
[1433ecda] | 59 | typedef void (*irq_handler_t)(struct irq *);
|
---|
[b3f8fb7] | 60 |
|
---|
[8d2760f] | 61 | /** Type for function used to clear the interrupt. */
|
---|
[1433ecda] | 62 | typedef void (*cir_t)(void *, inr_t);
|
---|
[8d2760f] | 63 |
|
---|
[b3f8fb7] | 64 | /** IPC notification config structure.
|
---|
| 65 | *
|
---|
| 66 | * Primarily, this structure is encapsulated in the irq_t structure.
|
---|
| 67 | * It is protected by irq_t::lock.
|
---|
[da1bafb] | 68 | *
|
---|
[b3f8fb7] | 69 | */
|
---|
| 70 | typedef struct {
|
---|
[80bcaed] | 71 | /** When false, notifications are not sent. */
|
---|
| 72 | bool notify;
|
---|
[48bcf49] | 73 | /** True if the structure is in irq_uspace_hash_table_table */
|
---|
| 74 | bool hashed_in;
|
---|
[80bcaed] | 75 | /** Answerbox for notifications. */
|
---|
| 76 | answerbox_t *answerbox;
|
---|
[228e490] | 77 | /** Interface and method to be used for the notification. */
|
---|
| 78 | sysarg_t imethod;
|
---|
[cecb0789] | 79 | /** Arguments that will be sent if the IRQ is claimed. */
|
---|
[da1bafb] | 80 | uint32_t scratch[IPC_CALL_LEN];
|
---|
[8a45bf09] | 81 | /** Top-half IRQ code. */
|
---|
[80bcaed] | 82 | irq_code_t *code;
|
---|
| 83 | /** Counter. */
|
---|
[98000fb] | 84 | size_t counter;
|
---|
[b3f8fb7] | 85 | } ipc_notif_cfg_t;
|
---|
[0d107f31] | 86 |
|
---|
| 87 | /** Structure representing one device IRQ.
|
---|
| 88 | *
|
---|
[80bcaed] | 89 | * If one device has multiple interrupts, there will be multiple irq_t
|
---|
[24abb85d] | 90 | * instantions.
|
---|
[0d107f31] | 91 | */
|
---|
[b3f8fb7] | 92 | typedef struct irq {
|
---|
[0d107f31] | 93 | /** Hash table link. */
|
---|
[82cbf8c6] | 94 | ht_link_t link;
|
---|
[a35b458] | 95 |
|
---|
[63530c62] | 96 | /** Lock protecting everything in this structure
|
---|
| 97 | * except the link member. When both the IRQ
|
---|
| 98 | * hash table lock and this lock are to be acquired,
|
---|
| 99 | * this lock must not be taken first.
|
---|
| 100 | */
|
---|
[da1bafb] | 101 | IRQ_SPINLOCK_DECLARE(lock);
|
---|
[a35b458] | 102 |
|
---|
[7bcfbbc] | 103 | /** Send EOI before processing the interrupt.
|
---|
| 104 | * This is essential for timer interrupt which
|
---|
| 105 | * has to be acknowledged before doing preemption
|
---|
| 106 | * to make sure another timer interrupt will
|
---|
| 107 | * be eventually generated.
|
---|
| 108 | */
|
---|
| 109 | bool preack;
|
---|
[a35b458] | 110 |
|
---|
[0d107f31] | 111 | /** Actual IRQ number. -1 if not yet assigned. */
|
---|
| 112 | inr_t inr;
|
---|
[7bcfbbc] | 113 | /** Trigger level of the IRQ. */
|
---|
[0d107f31] | 114 | irq_trigger_t trigger;
|
---|
| 115 | /** Claim ownership of the IRQ. */
|
---|
[1433ecda] | 116 | irq_ownership_t (*claim)(struct irq *);
|
---|
[0d107f31] | 117 | /** Handler for this IRQ and device. */
|
---|
| 118 | irq_handler_t handler;
|
---|
[6cd9aa6] | 119 | /** Instance argument for the handler and the claim function. */
|
---|
| 120 | void *instance;
|
---|
[a35b458] | 121 |
|
---|
[8d2760f] | 122 | /** Clear interrupt routine. */
|
---|
| 123 | cir_t cir;
|
---|
| 124 | /** First argument to the clear interrupt routine. */
|
---|
| 125 | void *cir_arg;
|
---|
[a35b458] | 126 |
|
---|
[2b017ba] | 127 | /** Notification configuration structure. */
|
---|
[1b20da0] | 128 | ipc_notif_cfg_t notif_cfg;
|
---|
[b3f8fb7] | 129 | } irq_t;
|
---|
[0d107f31] | 130 |
|
---|
[da1bafb] | 131 | IRQ_SPINLOCK_EXTERN(irq_uspace_hash_table_lock);
|
---|
[cecb0789] | 132 | extern hash_table_t irq_uspace_hash_table;
|
---|
| 133 |
|
---|
[82d515e9] | 134 | extern slab_cache_t *irq_cache;
|
---|
[431c402] | 135 |
|
---|
[78ffb70] | 136 | extern inr_t last_inr;
|
---|
| 137 |
|
---|
[98000fb] | 138 | extern void irq_init(size_t, size_t);
|
---|
[6cd9aa6] | 139 | extern void irq_initialize(irq_t *);
|
---|
| 140 | extern void irq_register(irq_t *);
|
---|
| 141 | extern irq_t *irq_dispatch_and_lock(inr_t);
|
---|
[0d107f31] | 142 |
|
---|
[b3f8fb7] | 143 | #endif
|
---|
| 144 |
|
---|
[0d107f31] | 145 | /** @}
|
---|
| 146 | */
|
---|