[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 |
|
---|
[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>
|
---|
| 45 |
|
---|
[0d107f31] | 46 | typedef enum {
|
---|
[da1bafb] | 47 | IRQ_DECLINE, /**< Decline to service. */
|
---|
| 48 | IRQ_ACCEPT /**< Accept to service. */
|
---|
[0d107f31] | 49 | } irq_ownership_t;
|
---|
| 50 |
|
---|
| 51 | typedef enum {
|
---|
| 52 | IRQ_TRIGGER_LEVEL = 1,
|
---|
| 53 | IRQ_TRIGGER_EDGE
|
---|
| 54 | } irq_trigger_t;
|
---|
| 55 |
|
---|
[b3f8fb7] | 56 | struct irq;
|
---|
[c0699467] | 57 |
|
---|
[6cd9aa6] | 58 | typedef void (* irq_handler_t)(struct irq *);
|
---|
[b3f8fb7] | 59 |
|
---|
[8d2760f] | 60 | /** Type for function used to clear the interrupt. */
|
---|
[6cd9aa6] | 61 | typedef void (* cir_t)(void *, inr_t);
|
---|
[8d2760f] | 62 |
|
---|
[b3f8fb7] | 63 | /** IPC notification config structure.
|
---|
| 64 | *
|
---|
| 65 | * Primarily, this structure is encapsulated in the irq_t structure.
|
---|
| 66 | * It is protected by irq_t::lock.
|
---|
[da1bafb] | 67 | *
|
---|
[b3f8fb7] | 68 | */
|
---|
| 69 | typedef struct {
|
---|
[80bcaed] | 70 | /** When false, notifications are not sent. */
|
---|
| 71 | bool notify;
|
---|
| 72 | /** Answerbox for notifications. */
|
---|
| 73 | answerbox_t *answerbox;
|
---|
[228e490] | 74 | /** Interface and method to be used for the notification. */
|
---|
| 75 | sysarg_t imethod;
|
---|
[cecb0789] | 76 | /** Arguments that will be sent if the IRQ is claimed. */
|
---|
[da1bafb] | 77 | uint32_t scratch[IPC_CALL_LEN];
|
---|
[80bcaed] | 78 | /** Top-half pseudocode. */
|
---|
| 79 | irq_code_t *code;
|
---|
| 80 | /** Counter. */
|
---|
[98000fb] | 81 | size_t counter;
|
---|
[da1bafb] | 82 |
|
---|
[80bcaed] | 83 | /**
|
---|
| 84 | * Link between IRQs that are notifying the same answerbox. The list is
|
---|
| 85 | * protected by the answerbox irq_lock.
|
---|
| 86 | */
|
---|
| 87 | link_t link;
|
---|
[b3f8fb7] | 88 | } ipc_notif_cfg_t;
|
---|
[0d107f31] | 89 |
|
---|
| 90 | /** Structure representing one device IRQ.
|
---|
| 91 | *
|
---|
[80bcaed] | 92 | * If one device has multiple interrupts, there will be multiple irq_t
|
---|
| 93 | * instantions with the same devno.
|
---|
[da1bafb] | 94 | *
|
---|
[0d107f31] | 95 | */
|
---|
[b3f8fb7] | 96 | typedef struct irq {
|
---|
[0d107f31] | 97 | /** Hash table link. */
|
---|
| 98 | link_t link;
|
---|
[da1bafb] | 99 |
|
---|
[63530c62] | 100 | /** Lock protecting everything in this structure
|
---|
| 101 | * except the link member. When both the IRQ
|
---|
| 102 | * hash table lock and this lock are to be acquired,
|
---|
| 103 | * this lock must not be taken first.
|
---|
| 104 | */
|
---|
[da1bafb] | 105 | IRQ_SPINLOCK_DECLARE(lock);
|
---|
[7bcfbbc] | 106 |
|
---|
| 107 | /** Send EOI before processing the interrupt.
|
---|
| 108 | * This is essential for timer interrupt which
|
---|
| 109 | * has to be acknowledged before doing preemption
|
---|
| 110 | * to make sure another timer interrupt will
|
---|
| 111 | * be eventually generated.
|
---|
| 112 | */
|
---|
| 113 | bool preack;
|
---|
[da1bafb] | 114 |
|
---|
[0d107f31] | 115 | /** Unique device number. -1 if not yet assigned. */
|
---|
| 116 | devno_t devno;
|
---|
[da1bafb] | 117 |
|
---|
[0d107f31] | 118 | /** Actual IRQ number. -1 if not yet assigned. */
|
---|
| 119 | inr_t inr;
|
---|
[7bcfbbc] | 120 | /** Trigger level of the IRQ. */
|
---|
[0d107f31] | 121 | irq_trigger_t trigger;
|
---|
| 122 | /** Claim ownership of the IRQ. */
|
---|
[c9b550b] | 123 | irq_ownership_t (* claim)(struct irq *);
|
---|
[0d107f31] | 124 | /** Handler for this IRQ and device. */
|
---|
| 125 | irq_handler_t handler;
|
---|
[6cd9aa6] | 126 | /** Instance argument for the handler and the claim function. */
|
---|
| 127 | void *instance;
|
---|
[da1bafb] | 128 |
|
---|
[8d2760f] | 129 | /** Clear interrupt routine. */
|
---|
| 130 | cir_t cir;
|
---|
| 131 | /** First argument to the clear interrupt routine. */
|
---|
| 132 | void *cir_arg;
|
---|
[da1bafb] | 133 |
|
---|
[2b017ba] | 134 | /** Notification configuration structure. */
|
---|
| 135 | ipc_notif_cfg_t notif_cfg;
|
---|
[b3f8fb7] | 136 | } irq_t;
|
---|
[0d107f31] | 137 |
|
---|
[da1bafb] | 138 | IRQ_SPINLOCK_EXTERN(irq_uspace_hash_table_lock);
|
---|
[cecb0789] | 139 | extern hash_table_t irq_uspace_hash_table;
|
---|
| 140 |
|
---|
[78ffb70] | 141 | extern inr_t last_inr;
|
---|
| 142 |
|
---|
[98000fb] | 143 | extern void irq_init(size_t, size_t);
|
---|
[6cd9aa6] | 144 | extern void irq_initialize(irq_t *);
|
---|
| 145 | extern void irq_register(irq_t *);
|
---|
| 146 | extern irq_t *irq_dispatch_and_lock(inr_t);
|
---|
[0d107f31] | 147 |
|
---|
[b3f8fb7] | 148 | #endif
|
---|
| 149 |
|
---|
[0d107f31] | 150 | /** @}
|
---|
| 151 | */
|
---|