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

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

Introduce reference-counted kobjects

Capabilities are thus reduced to task-local names for references to kobjects.

  • Property mode set to 100644
File size: 4.3 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_DDI_IRQ_H_
36#define KERN_DDI_IRQ_H_
37
38#include <typedefs.h>
39#include <abi/ddi/irq.h>
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#include <mm/slab.h>
46
47typedef enum {
48 IRQ_HT_KEY_INR,
49 IRQ_HT_KEY_MODE
50} irq_ht_key_t;
51
52typedef enum {
53 IRQ_HT_MODE_CLAIM,
54 IRQ_HT_MODE_NO_CLAIM
55} irq_ht_mode_t;
56
57typedef enum {
58 IRQ_DECLINE, /**< Decline to service. */
59 IRQ_ACCEPT /**< Accept to service. */
60} irq_ownership_t;
61
62typedef enum {
63 IRQ_TRIGGER_LEVEL = 1,
64 IRQ_TRIGGER_EDGE
65} irq_trigger_t;
66
67struct irq;
68
69typedef void (* irq_handler_t)(struct irq *);
70
71/** Type for function used to clear the interrupt. */
72typedef void (* cir_t)(void *, inr_t);
73
74/** IPC notification config structure.
75 *
76 * Primarily, this structure is encapsulated in the irq_t structure.
77 * It is protected by irq_t::lock.
78 *
79 */
80typedef struct {
81 /** When false, notifications are not sent. */
82 bool notify;
83 /** True if the structure is in irq_uspace_hash_table_table */
84 bool hashed_in;
85 /** Answerbox for notifications. */
86 answerbox_t *answerbox;
87 /** Interface and method to be used for the notification. */
88 sysarg_t imethod;
89 /** Arguments that will be sent if the IRQ is claimed. */
90 uint32_t scratch[IPC_CALL_LEN];
91 /** Top-half IRQ code. */
92 irq_code_t *code;
93 /** Counter. */
94 size_t counter;
95} ipc_notif_cfg_t;
96
97/** Structure representing one device IRQ.
98 *
99 * If one device has multiple interrupts, there will be multiple irq_t
100 * instantions.
101 */
102typedef struct irq {
103 /** Hash table link. */
104 link_t link;
105
106 /** Lock protecting everything in this structure
107 * except the link member. When both the IRQ
108 * hash table lock and this lock are to be acquired,
109 * this lock must not be taken first.
110 */
111 IRQ_SPINLOCK_DECLARE(lock);
112
113 /** Send EOI before processing the interrupt.
114 * This is essential for timer interrupt which
115 * has to be acknowledged before doing preemption
116 * to make sure another timer interrupt will
117 * be eventually generated.
118 */
119 bool preack;
120
121 /** Actual IRQ number. -1 if not yet assigned. */
122 inr_t inr;
123 /** Trigger level of the IRQ. */
124 irq_trigger_t trigger;
125 /** Claim ownership of the IRQ. */
126 irq_ownership_t (* claim)(struct irq *);
127 /** Handler for this IRQ and device. */
128 irq_handler_t handler;
129 /** Instance argument for the handler and the claim function. */
130 void *instance;
131
132 /** Clear interrupt routine. */
133 cir_t cir;
134 /** First argument to the clear interrupt routine. */
135 void *cir_arg;
136
137 /** Notification configuration structure. */
138 ipc_notif_cfg_t notif_cfg;
139} irq_t;
140
141IRQ_SPINLOCK_EXTERN(irq_uspace_hash_table_lock);
142extern hash_table_t irq_uspace_hash_table;
143
144extern slab_cache_t *irq_slab;
145
146extern inr_t last_inr;
147
148extern void irq_init(size_t, size_t);
149extern void irq_initialize(irq_t *);
150extern void irq_register(irq_t *);
151extern irq_t *irq_dispatch_and_lock(inr_t);
152
153#endif
154
155/** @}
156 */
Note: See TracBrowser for help on using the repository browser.