Subversion Repositories HelenOS

Rev

Rev 4343 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4343 Rev 4344
Line 42... Line 42...
42
 * The structure of a notification message is as follows:
42
 * The structure of a notification message is as follows:
43
 * - METHOD: method as registered by the SYS_IPC_REGISTER_IRQ syscall
43
 * - METHOD: method as registered by the SYS_IPC_REGISTER_IRQ syscall
44
 * - ARG1: payload modified by a 'top-half' handler
44
 * - ARG1: payload modified by a 'top-half' handler
45
 * - ARG2: payload modified by a 'top-half' handler
45
 * - ARG2: payload modified by a 'top-half' handler
46
 * - ARG3: payload modified by a 'top-half' handler
46
 * - ARG3: payload modified by a 'top-half' handler
-
 
47
 * - ARG4: payload modified by a 'top-half' handler
-
 
48
 * - ARG5: payload modified by a 'top-half' handler
47
 * - in_phone_hash: interrupt counter (may be needed to assure correct order
49
 * - in_phone_hash: interrupt counter (may be needed to assure correct order
48
 *         in multithreaded drivers)
50
 *         in multithreaded drivers)
-
 
51
 *
-
 
52
 * Note on synchronization for ipc_irq_register(), ipc_irq_unregister(),
-
 
53
 * ipc_irq_cleanup() and IRQ handlers:
-
 
54
 *
-
 
55
 *   By always taking all of the uspace IRQ hash table lock, IRQ structure lock
-
 
56
 *   and answerbox lock, we can rule out race conditions between the
-
 
57
 *   registration functions and also the cleanup function. Thus the observer can
-
 
58
 *   either see the IRQ structure present in both the hash table and the
-
 
59
 *   answerbox list or absent in both. Views in which the IRQ structure would be
-
 
60
 *   linked in the hash table but not in the answerbox list, or vice versa, are
-
 
61
 *   not possible.
-
 
62
 *
-
 
63
 *   By always taking the hash table lock and the IRQ structure lock, we can
-
 
64
 *   rule out a scenario in which we would free up an IRQ structure, which is
-
 
65
 *   still referenced by, for example, an IRQ handler. The locking scheme forces
-
 
66
 *   us to lock the IRQ structure only after any progressing IRQs on that
-
 
67
 *   structure are finished. Because we hold the hash table lock, we prevent new
-
 
68
 *   IRQs from taking new references to the IRQ structure.
49
 */
69
 */
50
 
70
 
51
#include <arch.h>
71
#include <arch.h>
52
#include <mm/slab.h>
72
#include <mm/slab.h>
53
#include <errno.h>
73
#include <errno.h>
Line 56... Line 76...
56
#include <ipc/irq.h>
76
#include <ipc/irq.h>
57
#include <syscall/copy.h>
77
#include <syscall/copy.h>
58
#include <console/console.h>
78
#include <console/console.h>
59
#include <print.h>
79
#include <print.h>
60
 
80
 
61
/** Execute code associated with IRQ notification.
-
 
62
 *
-
 
63
 * @param call      Notification call.
-
 
64
 * @param code      Top-half pseudocode.
-
 
65
 */
-
 
66
static void code_execute(call_t *call, irq_code_t *code)
-
 
67
{
-
 
68
    unsigned int i;
-
 
69
    unative_t dstval = 0;
-
 
70
   
-
 
71
    if (!code)
-
 
72
        return;
-
 
73
   
-
 
74
    for (i = 0; i < code->cmdcount; i++) {
-
 
75
        switch (code->cmds[i].cmd) {
-
 
76
        case CMD_MEM_READ_1:
-
 
77
            dstval = *((uint8_t *) code->cmds[i].addr);
-
 
78
            break;
-
 
79
        case CMD_MEM_READ_2:
-
 
80
            dstval = *((uint16_t *) code->cmds[i].addr);
-
 
81
            break;
-
 
82
        case CMD_MEM_READ_4:
-
 
83
            dstval = *((uint32_t *) code->cmds[i].addr);
-
 
84
            break;
-
 
85
        case CMD_MEM_READ_8:
-
 
86
            dstval = *((uint64_t *) code->cmds[i].addr);
-
 
87
            break;
-
 
88
        case CMD_MEM_WRITE_1:
-
 
89
            *((uint8_t *) code->cmds[i].addr) = code->cmds[i].value;
-
 
90
            break;
-
 
91
        case CMD_MEM_WRITE_2:
-
 
92
            *((uint16_t *) code->cmds[i].addr) =
-
 
93
                code->cmds[i].value;
-
 
94
            break;
-
 
95
        case CMD_MEM_WRITE_4:
-
 
96
            *((uint32_t *) code->cmds[i].addr) =
-
 
97
                code->cmds[i].value;
-
 
98
            break;
-
 
99
        case CMD_MEM_WRITE_8:
-
 
100
            *((uint64_t *) code->cmds[i].addr) =
-
 
101
                code->cmds[i].value;
-
 
102
            break;
-
 
103
        case CMD_PORT_READ_1:
-
 
104
            dstval = pio_read_8((long) code->cmds[i].addr);
-
 
105
            break;
-
 
106
        case CMD_PORT_WRITE_1:
-
 
107
            pio_write_8((long) code->cmds[i].addr, code->cmds[i].value);
-
 
108
            break;
-
 
109
        default:
-
 
110
            break;
-
 
111
        }
-
 
112
        if (code->cmds[i].dstarg && code->cmds[i].dstarg <
-
 
113
            IPC_CALL_LEN) {
-
 
114
            call->data.args[code->cmds[i].dstarg] = dstval;
-
 
115
        }
-
 
116
    }
-
 
117
}
-
 
118
 
-
 
119
/** Free top-half pseudocode.
81
/** Free the top-half pseudocode.
120
 *
82
 *
121
 * @param code      Pointer to the top-half pseudocode.
83
 * @param code      Pointer to the top-half pseudocode.
122
 */
84
 */
123
static void code_free(irq_code_t *code)
85
static void code_free(irq_code_t *code)
124
{
86
{
Line 126... Line 88...
126
        free(code->cmds);
88
        free(code->cmds);
127
        free(code);
89
        free(code);
128
    }
90
    }
129
}
91
}
130
 
92
 
131
/** Copy top-half pseudocode from userspace into the kernel.
93
/** Copy the top-half pseudocode from userspace into the kernel.
132
 *
94
 *
133
 * @param ucode     Userspace address of the top-half pseudocode.
95
 * @param ucode     Userspace address of the top-half pseudocode.
134
 *
96
 *
135
 * @return      Kernel address of the copied pseudocode.
97
 * @return      Kernel address of the copied pseudocode.
136
 */
98
 */
Line 162... Line 124...
162
    }
124
    }
163
 
125
 
164
    return code;
126
    return code;
165
}
127
}
166
 
128
 
167
/** Unregister task from IRQ notification.
-
 
168
 *
-
 
169
 * @param box       Answerbox associated with the notification.
-
 
170
 * @param inr       IRQ number.
-
 
171
 * @param devno     Device number.
-
 
172
 */
-
 
173
void ipc_irq_unregister(answerbox_t *box, inr_t inr, devno_t devno)
-
 
174
{
-
 
175
    ipl_t ipl;
-
 
176
    irq_t *irq;
-
 
177
 
-
 
178
    ipl = interrupts_disable();
-
 
179
    irq = irq_find_and_lock(inr, devno);
-
 
180
    if (irq) {
-
 
181
        if (irq->notif_cfg.answerbox == box) {
-
 
182
            code_free(irq->notif_cfg.code);
-
 
183
            irq->notif_cfg.notify = false;
-
 
184
            irq->notif_cfg.answerbox = NULL;
-
 
185
            irq->notif_cfg.code = NULL;
-
 
186
            irq->notif_cfg.method = 0;
-
 
187
            irq->notif_cfg.counter = 0;
-
 
188
 
-
 
189
            spinlock_lock(&box->irq_lock);
-
 
190
            list_remove(&irq->notif_cfg.link);
-
 
191
            spinlock_unlock(&box->irq_lock);
-
 
192
           
-
 
193
            spinlock_unlock(&irq->lock);
-
 
194
        }
-
 
195
    }
-
 
196
    interrupts_restore(ipl);
-
 
197
}
-
 
198
 
-
 
199
/** Register an answerbox as a receiving end for IRQ notifications.
129
/** Register an answerbox as a receiving end for IRQ notifications.
200
 *
130
 *
201
 * @param box       Receiving answerbox.
131
 * @param box       Receiving answerbox.
202
 * @param inr       IRQ number.
132
 * @param inr       IRQ number.
203
 * @param devno     Device number.
133
 * @param devno     Device number.
Line 210... Line 140...
210
    unative_t method, irq_code_t *ucode)
140
    unative_t method, irq_code_t *ucode)
211
{
141
{
212
    ipl_t ipl;
142
    ipl_t ipl;
213
    irq_code_t *code;
143
    irq_code_t *code;
214
    irq_t *irq;
144
    irq_t *irq;
-
 
145
    unative_t key[] = {
-
 
146
        (unative_t) inr,
-
 
147
        (unative_t) devno
-
 
148
    };
215
 
149
 
216
    if (ucode) {
150
    if (ucode) {
217
        code = code_from_uspace(ucode);
151
        code = code_from_uspace(ucode);
218
        if (!code)
152
        if (!code)
219
            return EBADMEM;
153
            return EBADMEM;
220
    } else {
154
    } else {
221
        code = NULL;
155
        code = NULL;
222
    }
156
    }
223
 
157
 
224
    ipl = interrupts_disable();
158
    /*
225
    irq = irq_find_and_lock(inr, devno);
159
     * Allocate and populate the IRQ structure.
226
    if (!irq) {
160
     */
227
        interrupts_restore(ipl);
161
    irq = malloc(sizeof(irq_t), 0);
228
        code_free(code);
162
    irq_initialize(irq);
229
        return ENOENT;
163
    irq->devno = devno;
230
    }
-
 
231
   
-
 
232
    if (irq->notif_cfg.answerbox) {
164
    irq->inr = inr;
233
        spinlock_unlock(&irq->lock);
165
    irq->claim = ipc_irq_top_half_claim;
234
        interrupts_restore(ipl);
166
    irq->handler = ipc_irq_top_half_handler;
235
        code_free(code);
-
 
236
        return EEXISTS;
-
 
237
    }
-
 
238
   
-
 
239
    irq->notif_cfg.notify = true;
167
    irq->notif_cfg.notify = true;
240
    irq->notif_cfg.answerbox = box;
168
    irq->notif_cfg.answerbox = box;
241
    irq->notif_cfg.method = method;
169
    irq->notif_cfg.method = method;
242
    irq->notif_cfg.code = code;
170
    irq->notif_cfg.code = code;
243
    irq->notif_cfg.counter = 0;
171
    irq->notif_cfg.counter = 0;
244
 
172
 
-
 
173
    /*
-
 
174
     * Enlist the IRQ structure in the uspace IRQ hash table and the
-
 
175
     * answerbox's list.
-
 
176
     */
-
 
177
    ipl = interrupts_disable();
-
 
178
    spinlock_lock(&irq_uspace_hash_table_lock);
-
 
179
    spinlock_lock(&irq->lock);
245
    spinlock_lock(&box->irq_lock);
180
    spinlock_lock(&box->irq_lock);
-
 
181
    if (hash_table_find(&irq_uspace_hash_table, key)) {
-
 
182
        code_free(code);
-
 
183
        spinlock_unlock(&box->irq_lock);
-
 
184
        spinlock_unlock(&irq->lock);
-
 
185
        spinlock_unlock(&irq_uspace_hash_table_lock);
-
 
186
        free(irq);
-
 
187
        interrupts_restore(ipl);
-
 
188
        return EEXISTS;
-
 
189
    }
-
 
190
    hash_table_insert(&irq_uspace_hash_table, key, &irq->link);
246
    list_append(&irq->notif_cfg.link, &box->irq_head);
191
    list_append(&irq->notif_cfg.link, &box->irq_head);
247
    spinlock_unlock(&box->irq_lock);
192
    spinlock_unlock(&box->irq_lock);
-
 
193
    spinlock_unlock(&irq->lock);
-
 
194
    spinlock_unlock(&irq_uspace_hash_table_lock);
-
 
195
 
-
 
196
    interrupts_restore(ipl);
-
 
197
    return EOK;
-
 
198
}
248
 
199
 
-
 
200
/** Unregister task from IRQ notification.
-
 
201
 *
-
 
202
 * @param box       Answerbox associated with the notification.
-
 
203
 * @param inr       IRQ number.
-
 
204
 * @param devno     Device number.
-
 
205
 */
-
 
206
int ipc_irq_unregister(answerbox_t *box, inr_t inr, devno_t devno)
-
 
207
{
-
 
208
    ipl_t ipl;
-
 
209
    unative_t key[] = {
-
 
210
        (unative_t) inr,
-
 
211
        (unative_t) devno
-
 
212
    };
-
 
213
    link_t *lnk;
-
 
214
    irq_t *irq;
-
 
215
 
-
 
216
    ipl = interrupts_disable();
-
 
217
    spinlock_lock(&irq_uspace_hash_table_lock);
-
 
218
    lnk = hash_table_find(&irq_uspace_hash_table, key);
-
 
219
    if (!lnk) {
-
 
220
        spinlock_unlock(&irq_uspace_hash_table_lock);
-
 
221
        interrupts_restore(ipl);
-
 
222
        return ENOENT;
-
 
223
    }
-
 
224
    irq = hash_table_get_instance(lnk, irq_t, link);
-
 
225
    spinlock_lock(&irq->lock);
-
 
226
    spinlock_lock(&box->irq_lock);
-
 
227
   
-
 
228
    ASSERT(irq->notif_cfg.answerbox == box);
-
 
229
   
-
 
230
    /* Free up the pseudo code and associated structures. */
-
 
231
    code_free(irq->notif_cfg.code);
-
 
232
 
-
 
233
    /* Remove the IRQ from the answerbox's list. */
-
 
234
    list_remove(&irq->notif_cfg.link);
-
 
235
 
-
 
236
    /* Remove the IRQ from the uspace IRQ hash table. */
-
 
237
    hash_table_remove(&irq_uspace_hash_table, key, 2);
-
 
238
   
-
 
239
    spinlock_unlock(&irq_uspace_hash_table_lock);
249
    spinlock_unlock(&irq->lock);
240
    spinlock_unlock(&irq->lock);
-
 
241
    spinlock_unlock(&box->irq_lock);
-
 
242
   
-
 
243
    /* Free up the IRQ structure. */
-
 
244
    free(irq);
-
 
245
   
250
    interrupts_restore(ipl);
246
    interrupts_restore(ipl);
-
 
247
    return EOK;
-
 
248
}
-
 
249
 
251
 
250
 
-
 
251
/** Disconnect all IRQ notifications from an answerbox.
-
 
252
 *
-
 
253
 * This function is effective because the answerbox contains
-
 
254
 * list of all irq_t structures that are registered to
-
 
255
 * send notifications to it.
-
 
256
 *
-
 
257
 * @param box       Answerbox for which we want to carry out the cleanup.
-
 
258
 */
-
 
259
void ipc_irq_cleanup(answerbox_t *box)
-
 
260
{
-
 
261
    ipl_t ipl;
-
 
262
   
-
 
263
loop:
-
 
264
    ipl = interrupts_disable();
-
 
265
    spinlock_lock(&irq_uspace_hash_table_lock);
-
 
266
    spinlock_lock(&box->irq_lock);
-
 
267
   
-
 
268
    while (box->irq_head.next != &box->irq_head) {
-
 
269
        link_t *cur = box->irq_head.next;
-
 
270
        irq_t *irq;
-
 
271
        DEADLOCK_PROBE_INIT(p_irqlock);
-
 
272
        unative_t key[2];
-
 
273
       
-
 
274
        irq = list_get_instance(cur, irq_t, notif_cfg.link);
-
 
275
        if (!spinlock_trylock(&irq->lock)) {
-
 
276
            /*
-
 
277
             * Avoid deadlock by trying again.
-
 
278
             */
-
 
279
            spinlock_unlock(&box->irq_lock);
-
 
280
            spinlock_unlock(&irq_uspace_hash_table_lock);
-
 
281
            interrupts_restore(ipl);
-
 
282
            DEADLOCK_PROBE(p_irqlock, DEADLOCK_THRESHOLD);
-
 
283
            goto loop;
-
 
284
        }
-
 
285
        key[0] = irq->inr;
-
 
286
        key[1] = irq->devno;
-
 
287
       
-
 
288
       
-
 
289
        ASSERT(irq->notif_cfg.answerbox == box);
-
 
290
       
-
 
291
        /* Unlist from the answerbox. */
-
 
292
        list_remove(&irq->notif_cfg.link);
-
 
293
       
-
 
294
        /* Remove from the hash table. */
-
 
295
        hash_table_remove(&irq_uspace_hash_table, key, 2);
-
 
296
       
-
 
297
        /* Free up the pseudo code and associated structures. */
-
 
298
        code_free(irq->notif_cfg.code);
-
 
299
       
-
 
300
        spinlock_unlock(&irq->lock);
252
    return 0;
301
        free(irq);
-
 
302
    }
-
 
303
   
-
 
304
    spinlock_unlock(&box->irq_lock);
-
 
305
    spinlock_unlock(&irq_uspace_hash_table_lock);
-
 
306
    interrupts_restore(ipl);
253
}
307
}
254
 
308
 
255
/** Add a call to the proper answerbox queue.
309
/** Add a call to the proper answerbox queue.
256
 *
310
 *
257
 * Assume irq->lock is locked.
311
 * Assume irq->lock is locked.
Line 266... Line 320...
266
    spinlock_unlock(&irq->notif_cfg.answerbox->irq_lock);
320
    spinlock_unlock(&irq->notif_cfg.answerbox->irq_lock);
267
       
321
       
268
    waitq_wakeup(&irq->notif_cfg.answerbox->wq, WAKEUP_FIRST);
322
    waitq_wakeup(&irq->notif_cfg.answerbox->wq, WAKEUP_FIRST);
269
}
323
}
270
 
324
 
271
/** Send notification message.
325
/** Apply the top-half pseudo code to find out whether to accept the IRQ or not.
272
 *
326
 *
273
 * @param irq       IRQ structure.
327
 * @param irq       IRQ structure.
274
 * @param a1        Driver-specific payload argument.
-
 
-
 
328
 *
275
 * @param a2        Driver-specific payload argument.
329
 * @return      IRQ_ACCEPT if the interrupt is accepted by the
276
 * @param a3        Driver-specific payload argument.
330
 *          pseudocode. IRQ_DECLINE otherwise.
277
 * @param a4        Driver-specific payload argument.
-
 
278
 * @param a5        Driver-specific payload argument.
-
 
279
 */
331
 */
280
void ipc_irq_send_msg(irq_t *irq, unative_t a1, unative_t a2, unative_t a3,
332
irq_ownership_t ipc_irq_top_half_claim(irq_t *irq)
281
    unative_t a4, unative_t a5)
-
 
282
{
333
{
-
 
334
    unsigned int i;
283
    call_t *call;
335
    unative_t dstval;
284
 
-
 
285
    spinlock_lock(&irq->lock);
336
    irq_code_t *code = irq->notif_cfg.code;
-
 
337
    unative_t *scratch = irq->notif_cfg.scratch;
286
 
338
 
-
 
339
   
287
    if (irq->notif_cfg.answerbox) {
340
    if (!irq->notif_cfg.notify)
288
        call = ipc_call_alloc(FRAME_ATOMIC);
341
        return IRQ_DECLINE;
-
 
342
   
289
        if (!call) {
343
    if (!code)
290
            spinlock_unlock(&irq->lock);
-
 
291
            return;
344
        return IRQ_DECLINE;
292
        }
345
   
293
        call->flags |= IPC_CALL_NOTIF;
-
 
294
        IPC_SET_METHOD(call->data, irq->notif_cfg.method);
-
 
295
        IPC_SET_ARG1(call->data, a1);
-
 
296
        IPC_SET_ARG2(call->data, a2);
-
 
297
        IPC_SET_ARG3(call->data, a3);
-
 
298
        IPC_SET_ARG4(call->data, a4);
-
 
299
        IPC_SET_ARG5(call->data, a5);
346
    for (i = 0; i < code->cmdcount; i++) {
300
        /* Put a counter to the message */
347
        unsigned int srcarg = code->cmds[i].srcarg;
301
        call->priv = ++irq->notif_cfg.counter;
348
        unsigned int dstarg = code->cmds[i].dstarg;
302
       
349
       
-
 
350
        if (srcarg >= IPC_CALL_LEN)
-
 
351
            break;
-
 
352
        if (dstarg >= IPC_CALL_LEN)
-
 
353
            break;
-
 
354
   
-
 
355
        switch (code->cmds[i].cmd) {
-
 
356
        case CMD_PIO_READ_8:
-
 
357
            dstval = pio_read_8((ioport8_t *) code->cmds[i].addr);
-
 
358
            if (dstarg)
-
 
359
                scratch[dstarg] = dstval;
-
 
360
            break;
-
 
361
        case CMD_PIO_READ_16:
-
 
362
            dstval = pio_read_16((ioport16_t *) code->cmds[i].addr);
-
 
363
            if (dstarg)
-
 
364
                scratch[dstarg] = dstval;
-
 
365
            break;
-
 
366
        case CMD_PIO_READ_32:
-
 
367
            dstval = pio_read_32((ioport32_t *) code->cmds[i].addr);
-
 
368
            if (dstarg)
-
 
369
                scratch[dstarg] = dstval;
-
 
370
            break;
-
 
371
        case CMD_PIO_WRITE_8:
-
 
372
            pio_write_8((ioport8_t *) code->cmds[i].addr,
-
 
373
                (uint8_t) code->cmds[i].value);
-
 
374
            break;
-
 
375
        case CMD_PIO_WRITE_16:
-
 
376
            pio_write_16((ioport16_t *) code->cmds[i].addr,
-
 
377
                (uint16_t) code->cmds[i].value);
-
 
378
            break;
-
 
379
        case CMD_PIO_WRITE_32:
-
 
380
            pio_write_32((ioport32_t *) code->cmds[i].addr,
-
 
381
                (uint32_t) code->cmds[i].value);
-
 
382
            break;
-
 
383
        case CMD_BTEST:
303
        send_call(irq, call);
384
            if (srcarg && dstarg) {
-
 
385
                dstval = scratch[srcarg] & code->cmds[i].value;
-
 
386
                scratch[dstarg] = dstval;
-
 
387
            }
-
 
388
            break;
-
 
389
        case CMD_PREDICATE:
-
 
390
            if (srcarg && !scratch[srcarg]) {
-
 
391
                i += code->cmds[i].value;
-
 
392
                continue;
-
 
393
            }
-
 
394
            break;
-
 
395
        case CMD_ACCEPT:
-
 
396
            return IRQ_ACCEPT;
-
 
397
            break;
-
 
398
        case CMD_DECLINE:
-
 
399
        default:
-
 
400
            return IRQ_DECLINE;
-
 
401
        }
304
    }
402
    }
-
 
403
   
305
    spinlock_unlock(&irq->lock);
404
    return IRQ_DECLINE;
306
}
405
}
307
 
406
 
-
 
407
 
308
/** Notify a task that an IRQ had occurred.
408
/* IRQ top-half handler.
309
 *
409
 *
310
 * We expect interrupts to be disabled and the irq->lock already held.
410
 * We expect interrupts to be disabled and the irq->lock already held.
311
 *
411
 *
312
 * @param irq       IRQ structure.
412
 * @param irq       IRQ structure.
313
 */
413
 */
314
void ipc_irq_send_notif(irq_t *irq)
414
void ipc_irq_top_half_handler(irq_t *irq)
315
{
415
{
316
    call_t *call;
-
 
317
 
-
 
318
    ASSERT(irq);
416
    ASSERT(irq);
319
 
417
 
320
    if (irq->notif_cfg.answerbox) {
418
    if (irq->notif_cfg.answerbox) {
-
 
419
        call_t *call;
-
 
420
 
321
        call = ipc_call_alloc(FRAME_ATOMIC);
421
        call = ipc_call_alloc(FRAME_ATOMIC);
322
        if (!call) {
422
        if (!call)
323
            return;
423
            return;
324
        }
424
       
325
        call->flags |= IPC_CALL_NOTIF;
425
        call->flags |= IPC_CALL_NOTIF;
326
        /* Put a counter to the message */
426
        /* Put a counter to the message */
327
        call->priv = ++irq->notif_cfg.counter;
427
        call->priv = ++irq->notif_cfg.counter;
-
 
428
 
328
        /* Set up args */
429
        /* Set up args */
329
        IPC_SET_METHOD(call->data, irq->notif_cfg.method);
430
        IPC_SET_METHOD(call->data, irq->notif_cfg.method);
-
 
431
        IPC_SET_ARG1(call->data, irq->notif_cfg.scratch[1]);
-
 
432
        IPC_SET_ARG2(call->data, irq->notif_cfg.scratch[2]);
-
 
433
        IPC_SET_ARG3(call->data, irq->notif_cfg.scratch[3]);
-
 
434
        IPC_SET_ARG4(call->data, irq->notif_cfg.scratch[4]);
-
 
435
        IPC_SET_ARG5(call->data, irq->notif_cfg.scratch[5]);
330
 
436
 
331
        /* Execute code to handle irq */
-
 
332
        code_execute(call, irq->notif_cfg.code);
-
 
333
       
-
 
334
        send_call(irq, call);
437
        send_call(irq, call);
335
    }
438
    }
336
}
439
}
337
 
440
 
338
/** Disconnect all IRQ notifications from an answerbox.
-
 
339
 *
-
 
340
 * This function is effective because the answerbox contains
-
 
341
 * list of all irq_t structures that are registered to
-
 
342
 * send notifications to it.
441
/** Send notification message.
343
 *
442
 *
-
 
443
 * @param irq       IRQ structure.
-
 
444
 * @param a1        Driver-specific payload argument.
-
 
445
 * @param a2        Driver-specific payload argument.
344
 * @param box       Answerbox for which we want to carry out the cleanup.
446
 * @param a3        Driver-specific payload argument.
-
 
447
 * @param a4        Driver-specific payload argument.
-
 
448
 * @param a5        Driver-specific payload argument.
345
 */
449
 */
-
 
450
void ipc_irq_send_msg(irq_t *irq, unative_t a1, unative_t a2, unative_t a3,
346
void ipc_irq_cleanup(answerbox_t *box)
451
    unative_t a4, unative_t a5)
347
{
452
{
348
    ipl_t ipl;
453
    call_t *call;
349
   
454
 
350
loop:
-
 
351
    ipl = interrupts_disable();
-
 
352
    spinlock_lock(&box->irq_lock);
455
    spinlock_lock(&irq->lock);
353
   
456
 
354
    while (box->irq_head.next != &box->irq_head) {
457
    if (irq->notif_cfg.answerbox) {
355
        link_t *cur = box->irq_head.next;
458
        call = ipc_call_alloc(FRAME_ATOMIC);
356
        irq_t *irq;
459
        if (!call) {
357
        DEADLOCK_PROBE_INIT(p_irqlock);
-
 
358
       
-
 
359
        irq = list_get_instance(cur, irq_t, notif_cfg.link);
-
 
360
        if (!spinlock_trylock(&irq->lock)) {
-
 
361
            /*
-
 
362
             * Avoid deadlock by trying again.
-
 
363
             */
-
 
364
            spinlock_unlock(&box->irq_lock);
460
            spinlock_unlock(&irq->lock);
365
            interrupts_restore(ipl);
-
 
366
            DEADLOCK_PROBE(p_irqlock, DEADLOCK_THRESHOLD);
-
 
367
            goto loop;
461
            return;
368
        }
462
        }
369
       
-
 
370
        ASSERT(irq->notif_cfg.answerbox == box);
-
 
371
       
-
 
372
        list_remove(&irq->notif_cfg.link);
463
        call->flags |= IPC_CALL_NOTIF;
373
       
-
 
374
        /*
-
 
375
         * Don't forget to free any top-half pseudocode.
464
        /* Put a counter to the message */
376
         */
-
 
377
        code_free(irq->notif_cfg.code);
465
        call->priv = ++irq->notif_cfg.counter;
378
       
-
 
379
        irq->notif_cfg.notify = false;
-
 
380
        irq->notif_cfg.answerbox = NULL;
-
 
381
        irq->notif_cfg.code = NULL;
-
 
382
        irq->notif_cfg.method = 0;
-
 
383
        irq->notif_cfg.counter = 0;
-
 
384
 
466
 
-
 
467
        IPC_SET_METHOD(call->data, irq->notif_cfg.method);
-
 
468
        IPC_SET_ARG1(call->data, a1);
-
 
469
        IPC_SET_ARG2(call->data, a2);
-
 
470
        IPC_SET_ARG3(call->data, a3);
-
 
471
        IPC_SET_ARG4(call->data, a4);
-
 
472
        IPC_SET_ARG5(call->data, a5);
-
 
473
       
385
        spinlock_unlock(&irq->lock);
474
        send_call(irq, call);
386
    }
475
    }
387
   
-
 
388
    spinlock_unlock(&box->irq_lock);
476
    spinlock_unlock(&irq->lock);
389
    interrupts_restore(ipl);
-
 
390
}
477
}
391
 
478
 
392
/** @}
479
/** @}
393
 */
480
 */