Rev 4254 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4254 | Rev 4274 | ||
---|---|---|---|
Line 126... | Line 126... | ||
126 | return code; |
126 | return code; |
127 | } |
127 | } |
128 | 128 | ||
129 | /** Register an answerbox as a receiving end for IRQ notifications. |
129 | /** Register an answerbox as a receiving end for IRQ notifications. |
130 | * |
130 | * |
131 | * @param box Receiving answerbox. |
131 | * @param box Receiving answerbox. |
132 | * @param inr IRQ number. |
132 | * @param inr IRQ number. |
133 | * @param devno Device number. |
133 | * @param devno Device number. |
134 | * @param method Method to be associated with the notification. |
134 | * @param method Method to be associated with the notification. |
135 | * @param ucode Uspace pointer to top-half pseudocode. |
135 | * @param ucode Uspace pointer to top-half pseudocode. |
- | 136 | * |
|
- | 137 | * @return EBADMEM, ENOENT or EEXISTS on failure or 0 on success. |
|
136 | * |
138 | * |
137 | * @return EBADMEM, ENOENT or EEXISTS on failure or 0 on success. |
- | |
138 | */ |
139 | */ |
139 | int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, |
140 | int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, |
140 | unative_t method, irq_code_t *ucode) |
141 | unative_t method, irq_code_t *ucode) |
141 | { |
142 | { |
142 | ipl_t ipl; |
143 | ipl_t ipl; |
Line 145... | Line 146... | ||
145 | link_t *hlp; |
146 | link_t *hlp; |
146 | unative_t key[] = { |
147 | unative_t key[] = { |
147 | (unative_t) inr, |
148 | (unative_t) inr, |
148 | (unative_t) devno |
149 | (unative_t) devno |
149 | }; |
150 | }; |
150 | 151 | ||
151 | if (ucode) { |
152 | if (ucode) { |
152 | code = code_from_uspace(ucode); |
153 | code = code_from_uspace(ucode); |
153 | if (!code) |
154 | if (!code) |
154 | return EBADMEM; |
155 | return EBADMEM; |
155 | } else { |
156 | } else { |
156 | code = NULL; |
157 | code = NULL; |
157 | } |
158 | } |
158 | 159 | ||
159 | /* |
160 | /* |
160 | * Allocate and populate the IRQ structure. |
161 | * Allocate and populate the IRQ structure. |
161 | */ |
162 | */ |
162 | irq = malloc(sizeof(irq_t), 0); |
163 | irq = malloc(sizeof(irq_t), 0); |
163 | irq_initialize(irq); |
164 | irq_initialize(irq); |
Line 168... | Line 169... | ||
168 | irq->notif_cfg.notify = true; |
169 | irq->notif_cfg.notify = true; |
169 | irq->notif_cfg.answerbox = box; |
170 | irq->notif_cfg.answerbox = box; |
170 | irq->notif_cfg.method = method; |
171 | irq->notif_cfg.method = method; |
171 | irq->notif_cfg.code = code; |
172 | irq->notif_cfg.code = code; |
172 | irq->notif_cfg.counter = 0; |
173 | irq->notif_cfg.counter = 0; |
173 | 174 | ||
174 | /* |
175 | /* |
175 | * Enlist the IRQ structure in the uspace IRQ hash table and the |
176 | * Enlist the IRQ structure in the uspace IRQ hash table and the |
176 | * answerbox's list. |
177 | * answerbox's list. |
177 | */ |
178 | */ |
178 | ipl = interrupts_disable(); |
179 | ipl = interrupts_disable(); |
179 | spinlock_lock(&irq_uspace_hash_table_lock); |
180 | spinlock_lock(&irq_uspace_hash_table_lock); |
180 | hlp = hash_table_find(&irq_uspace_hash_table, key); |
181 | hlp = hash_table_find(&irq_uspace_hash_table, key); |
181 | if (hlp) { |
182 | if (hlp) { |
- | 183 | irq_t *hirq __attribute__((unused)) |
|
182 | irq_t *hirq = hash_table_get_instance(hlp, irq_t, link); |
184 | = hash_table_get_instance(hlp, irq_t, link); |
- | 185 | ||
183 | /* hirq is locked */ |
186 | /* hirq is locked */ |
184 | spinlock_unlock(&hirq->lock); |
187 | spinlock_unlock(&hirq->lock); |
185 | code_free(code); |
188 | code_free(code); |
186 | spinlock_unlock(&irq_uspace_hash_table_lock); |
189 | spinlock_unlock(&irq_uspace_hash_table_lock); |
187 | free(irq); |
190 | free(irq); |
188 | interrupts_restore(ipl); |
191 | interrupts_restore(ipl); |
189 | return EEXISTS; |
192 | return EEXISTS; |
190 | } |
193 | } |
- | 194 | ||
191 | spinlock_lock(&irq->lock); /* not really necessary, but paranoid */ |
195 | spinlock_lock(&irq->lock); /* Not really necessary, but paranoid */ |
192 | spinlock_lock(&box->irq_lock); |
196 | spinlock_lock(&box->irq_lock); |
193 | hash_table_insert(&irq_uspace_hash_table, key, &irq->link); |
197 | hash_table_insert(&irq_uspace_hash_table, key, &irq->link); |
194 | list_append(&irq->notif_cfg.link, &box->irq_head); |
198 | list_append(&irq->notif_cfg.link, &box->irq_head); |
195 | spinlock_unlock(&box->irq_lock); |
199 | spinlock_unlock(&box->irq_lock); |
196 | spinlock_unlock(&irq->lock); |
200 | spinlock_unlock(&irq->lock); |
197 | spinlock_unlock(&irq_uspace_hash_table_lock); |
201 | spinlock_unlock(&irq_uspace_hash_table_lock); |
198 | 202 | ||
199 | interrupts_restore(ipl); |
203 | interrupts_restore(ipl); |
200 | return EOK; |
204 | return EOK; |
201 | } |
205 | } |
202 | 206 | ||
203 | /** Unregister task from IRQ notification. |
207 | /** Unregister task from IRQ notification. |