L4Re - L4 Runtime Environment
icu.h
Go to the documentation of this file.
1 
6 /*
7  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8  * Alexander Warg <warg@os.inf.tu-dresden.de>,
9  * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
10  * economic rights: Technische Universit├Ąt Dresden (Germany)
11  *
12  * This file is part of TUD:OS and distributed under the terms of the
13  * GNU General Public License 2.
14  * Please see the COPYING-GPL-2 file for details.
15  *
16  * As a special exception, you may use this file as part of a free software
17  * library without restriction. Specifically, if other files instantiate
18  * templates or use macros or inline functions from this file, or you compile
19  * this file and link it with other files to produce an executable, this
20  * file does not by itself cause the resulting executable to be covered by
21  * the GNU General Public License. This exception does not however
22  * invalidate any other reasons why the executable file might be covered by
23  * the GNU General Public License.
24  */
25 #pragma once
26 
27 #include <l4/sys/kernel_object.h>
28 #include <l4/sys/ipc.h>
29 
51 {
59  L4_ICU_FLAG_MSI = 0x80000000,
60 };
61 
62 
68 {
72  L4_IRQ_F_EDGE = 0x0,
73  L4_IRQ_F_POS = 0x0,
74  L4_IRQ_F_NEG = 0x4,
75  L4_IRQ_F_BOTH = 0x8,
81  L4_IRQ_F_MASK = 0xf,
86 };
87 
88 
94 {
101 
108 
115 
122 
129 
136 
143 };
144 
145 enum L4_icu_ctl_op
146 {
147  L4_ICU_CTL_UNMASK = 0,
148  L4_ICU_CTL_MASK = 1
149 };
150 
151 
159 typedef struct l4_icu_info_t
160 {
166  unsigned features;
167 
171  unsigned nr_irqs;
172 
176  unsigned nr_msis;
177 } l4_icu_info_t;
178 
180 typedef struct l4_icu_msi_info_t
181 {
187 
204 L4_INLINE l4_msgtag_t
205 l4_icu_bind(l4_cap_idx_t icu, unsigned irqnum, l4_cap_idx_t irq) L4_NOTHROW;
206 
213 L4_INLINE l4_msgtag_t
214 l4_icu_bind_u(l4_cap_idx_t icu, unsigned irqnum, l4_cap_idx_t irq,
215  l4_utcb_t *utcb) L4_NOTHROW;
216 
227 L4_INLINE l4_msgtag_t
228 l4_icu_unbind(l4_cap_idx_t icu, unsigned irqnum, l4_cap_idx_t irq) L4_NOTHROW;
229 
236 L4_INLINE l4_msgtag_t
237 l4_icu_unbind_u(l4_cap_idx_t icu, unsigned irqnum, l4_cap_idx_t irq,
238  l4_utcb_t *utcb) L4_NOTHROW;
239 
250 L4_INLINE l4_msgtag_t
251 l4_icu_set_mode(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t mode) L4_NOTHROW;
252 
259 L4_INLINE l4_msgtag_t
260 l4_icu_set_mode_u(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t mode,
261  l4_utcb_t *utcb) L4_NOTHROW;
262 
274 L4_INLINE l4_msgtag_t
276 
283 L4_INLINE l4_msgtag_t
285  l4_utcb_t *utcb) L4_NOTHROW;
286 
293 L4_INLINE l4_msgtag_t
294 l4_icu_msi_info(l4_cap_idx_t icu, unsigned irqnum, l4_uint64_t source,
295  l4_icu_msi_info_t *msi_info) L4_NOTHROW;
296 
303 L4_INLINE l4_msgtag_t
304 l4_icu_msi_info_u(l4_cap_idx_t icu, unsigned irqnum, l4_uint64_t source,
305  l4_icu_msi_info_t *msi_info, l4_utcb_t *utcb) L4_NOTHROW;
306 
307 
320 L4_INLINE l4_msgtag_t
321 l4_icu_unmask(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t *label,
323 
330 L4_INLINE l4_msgtag_t
331 l4_icu_unmask_u(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t *label,
332  l4_timeout_t to, l4_utcb_t *utcb) L4_NOTHROW;
333 
345 L4_INLINE l4_msgtag_t
346 l4_icu_mask(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t *label,
348 
355 L4_INLINE l4_msgtag_t
356 l4_icu_mask_u(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t *label,
357  l4_timeout_t to, l4_utcb_t *utcb) L4_NOTHROW;
358 
362 L4_INLINE l4_msgtag_t
363 l4_icu_control_u(l4_cap_idx_t icu, unsigned irqnum, unsigned op,
364  l4_umword_t *label,l4_timeout_t to,
365  l4_utcb_t *utcb) L4_NOTHROW;
366 
367 
368 /**************************************************************************
369  * Implementations
370  */
371 
372 L4_INLINE l4_msgtag_t
373 l4_icu_bind_u(l4_cap_idx_t icu, unsigned irqnum, l4_cap_idx_t irq,
374  l4_utcb_t *utcb) L4_NOTHROW
375 {
376  l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
377  m->mr[0] = L4_ICU_OP_BIND;
378  m->mr[1] = irqnum;
379  m->mr[2] = l4_map_obj_control(0, 0);
380  m->mr[3] = l4_obj_fpage(irq, 0, L4_FPAGE_RWX).raw;
381  return l4_ipc_call(icu, utcb, l4_msgtag(L4_PROTO_IRQ, 2, 1, 0), L4_IPC_NEVER);
382 }
383 
384 L4_INLINE l4_msgtag_t
385 l4_icu_unbind_u(l4_cap_idx_t icu, unsigned irqnum, l4_cap_idx_t irq,
386  l4_utcb_t *utcb) L4_NOTHROW
387 {
388  l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
389  m->mr[0] = L4_ICU_OP_UNBIND;
390  m->mr[1] = irqnum;
391  m->mr[2] = l4_map_obj_control(0, 0);
392  m->mr[3] = l4_obj_fpage(irq, 0, L4_FPAGE_RWX).raw;
393  return l4_ipc_call(icu, utcb, l4_msgtag(L4_PROTO_IRQ, 2, 1, 0), L4_IPC_NEVER);
394 }
395 
396 L4_INLINE l4_msgtag_t
398  l4_utcb_t *utcb) L4_NOTHROW
399 {
400  l4_msgtag_t res;
401  l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
402  m->mr[0] = L4_ICU_OP_INFO;
403  res = l4_ipc_call(icu, utcb, l4_msgtag(L4_PROTO_IRQ, 1, 0, 0), L4_IPC_NEVER);
404  info->features = m->mr[0];
405  info->nr_irqs = m->mr[1];
406  info->nr_msis = m->mr[2];
407  return res;
408 }
409 
410 L4_INLINE l4_msgtag_t
411 l4_icu_msi_info_u(l4_cap_idx_t icu, unsigned irqnum, l4_uint64_t source,
412  l4_icu_msi_info_t *msi_info, l4_utcb_t *utcb) L4_NOTHROW
413 {
414  l4_msgtag_t res;
415  l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
416  m->mr[0] = L4_ICU_OP_MSI_INFO;
417  m->mr[1] = irqnum;
418  m->mr64[l4_utcb_mr64_idx(2)] = source;
419  res = l4_ipc_call(icu, utcb, l4_msgtag(L4_PROTO_IRQ,
420  2 + 1 * sizeof(l4_uint64_t)
421  / sizeof(l4_umword_t),
422  0, 0), L4_IPC_NEVER);
424  return res;
425 
426  if (L4_UNLIKELY(l4_msgtag_words(res) * sizeof(l4_umword_t) < sizeof(*msi_info)))
427  return res;
428 
429  __builtin_memcpy(msi_info, &m->mr[0], sizeof(*msi_info));
430  return res;
431 }
432 
433 L4_INLINE l4_msgtag_t
434 l4_icu_set_mode_u(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t mode,
435  l4_utcb_t *utcb) L4_NOTHROW
436 {
437  l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
438  mr->mr[0] = L4_ICU_OP_SET_MODE;
439  mr->mr[1] = irqnum;
440  mr->mr[2] = mode;
441  return l4_ipc_call(icu, utcb, l4_msgtag(L4_PROTO_IRQ, 3, 0, 0), L4_IPC_NEVER);
442 }
443 
444 L4_INLINE l4_msgtag_t
445 l4_icu_control_u(l4_cap_idx_t icu, unsigned irqnum, unsigned op,
446  l4_umword_t *label, l4_timeout_t to,
447  l4_utcb_t *utcb) L4_NOTHROW
448 {
449  l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
450  m->mr[0] = L4_ICU_OP_UNMASK + op;
451  m->mr[1] = irqnum;
452  if (label)
453  return l4_ipc_send_and_wait(icu, utcb, l4_msgtag(L4_PROTO_IRQ, 2, 0, 0),
454  label, to);
455  else
456  return l4_ipc_send(icu, utcb, l4_msgtag(L4_PROTO_IRQ, 2, 0, 0), to);
457 }
458 
459 L4_INLINE l4_msgtag_t
460 l4_icu_mask_u(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t *label,
462 { return l4_icu_control_u(icu, irqnum, L4_ICU_CTL_MASK, label, to, utcb); }
463 
464 L4_INLINE l4_msgtag_t
465 l4_icu_unmask_u(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t *label,
467 { return l4_icu_control_u(icu, irqnum, L4_ICU_CTL_UNMASK, label, to, utcb); }
468 
469 
470 
471 
472 L4_INLINE l4_msgtag_t
474 { return l4_icu_bind_u(icu, irqnum, irq, l4_utcb()); }
475 
476 L4_INLINE l4_msgtag_t
478 { return l4_icu_unbind_u(icu, irqnum, irq, l4_utcb()); }
479 
480 L4_INLINE l4_msgtag_t
482 { return l4_icu_info_u(icu, info, l4_utcb()); }
483 
484 L4_INLINE l4_msgtag_t
485 l4_icu_msi_info(l4_cap_idx_t icu, unsigned irqnum, l4_uint64_t source,
486  l4_icu_msi_info_t *msi_info) L4_NOTHROW
487 { return l4_icu_msi_info_u(icu, irqnum, source, msi_info, l4_utcb()); }
488 
489 L4_INLINE l4_msgtag_t
490 l4_icu_unmask(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t *label,
492 { return l4_icu_control_u(icu, irqnum, L4_ICU_CTL_UNMASK, label, to, l4_utcb()); }
493 
494 L4_INLINE l4_msgtag_t
495 l4_icu_mask(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t *label,
497 { return l4_icu_control_u(icu, irqnum, L4_ICU_CTL_MASK, label, to, l4_utcb()); }
498 
499 L4_INLINE l4_msgtag_t
501 {
502  return l4_icu_set_mode_u(icu, irqnum, mode, l4_utcb());
503 }
Mask opcode.
Definition: icu.h:135
Negative trigger.
Definition: icu.h:74
Encapsulation of the message-register block in the UTCB.
Definition: utcb.h:78
Unmask opcode.
Definition: icu.h:128
l4_msgtag_t l4_icu_unbind(l4_cap_idx_t icu, unsigned irqnum, l4_cap_idx_t irq) L4_NOTHROW
Remove binding of an interrupt line from the interrupt controller object.
Definition: icu.h:477
unsigned features
Feature flags.
Definition: icu.h:166
Do not use irq as wakeup source.
Definition: icu.h:85
unsigned l4_utcb_mr64_idx(unsigned idx) L4_NOTHROW
Get index into 64bit message registers alias from native-sized index.
Definition: utcb.h:386
struct l4_icu_info_t l4_icu_info_t
Info structure for an ICU.
L4_icu_flags
Flags for IRQ numbers used for the ICU.
Definition: icu.h:50
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition: types.h:436
Unbind opcode.
Definition: icu.h:107
l4_msgtag_t l4_ipc_send_and_wait(l4_cap_idx_t dest, l4_utcb_t *utcb, l4_msgtag_t tag, l4_umword_t *label, l4_timeout_t timeout) L4_NOTHROW
Send a message and do an open wait.
Definition: ipc.h:461
Level high trigger.
Definition: icu.h:76
Set-mode opcode.
Definition: icu.h:142
Info to use for a specific MSI.
Definition: icu.h:180
Both edges trigger.
Definition: icu.h:80
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition: utcb.h:80
Read-write-execute flex page.
Definition: __l4_fpage.h:114
l4_msgtag_t l4_ipc_call(l4_cap_idx_t object, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Object call (usual invocation).
Definition: ipc.h:445
l4_msgtag_t l4_icu_bind(l4_cap_idx_t icu, unsigned irqnum, l4_cap_idx_t irq) L4_NOTHROW
Bind an interrupt line of an interrupt controller to an interrupt object.
Definition: icu.h:473
l4_msgtag_t l4_icu_bind_u(l4_cap_idx_t icu, unsigned irqnum, l4_cap_idx_t irq, l4_utcb_t *utcb) L4_NOTHROW
Bind an interrupt line of an interrupt controller to an interrupt object.
Definition: icu.h:373
Level low trigger.
Definition: icu.h:77
Info structure for an ICU.
Definition: icu.h:159
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
l4_msgtag_t l4_icu_unmask_u(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t *label, l4_timeout_t to, l4_utcb_t *utcb) L4_NOTHROW
Acknowledge the given interrupt line.
Definition: icu.h:465
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
#define L4_IPC_NEVER
never timeout
Definition: __timeout.h:80
l4_uint64_t mr64[L4_UTCB_GENERIC_DATA_SIZE/(sizeof(l4_uint64_t)/sizeof(l4_umword_t))]
Message registers 64bit alias.
Definition: utcb.h:81
Flow types.
Definition: icu.h:70
Timeout pair.
Definition: __timeout.h:57
l4_msgtag_t l4_icu_unbind_u(l4_cap_idx_t icu, unsigned irqnum, l4_cap_idx_t irq, l4_utcb_t *utcb) L4_NOTHROW
Remove binding of an interrupt line from the interrupt controller object.
Definition: icu.h:385
Msi-info opcode.
Definition: icu.h:121
Mask.
Definition: icu.h:81
Both edges trigger.
Definition: icu.h:75
l4_msgtag_t l4_icu_msi_info(l4_cap_idx_t icu, unsigned irqnum, l4_uint64_t source, l4_icu_msi_info_t *msi_info) L4_NOTHROW
Get MSI info about IRQ.
Definition: icu.h:485
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
Definition: compiler.h:234
l4_msgtag_t l4_icu_info(l4_cap_idx_t icu, l4_icu_info_t *info) L4_NOTHROW
Get information about the capabilites of the ICU.
Definition: icu.h:481
Flag to denote that the IRQ is actually an MSI.
Definition: icu.h:59
l4_uint64_t msi_addr
Value to use as address when sending this MSI.
Definition: icu.h:183
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
Info opcode.
Definition: icu.h:114
Negative edge trigger.
Definition: icu.h:79
l4_msgtag_t l4_icu_msi_info_u(l4_cap_idx_t icu, unsigned irqnum, l4_uint64_t source, l4_icu_msi_info_t *msi_info, l4_utcb_t *utcb) L4_NOTHROW
Get MSI info about IRQ.
Definition: icu.h:411
l4_msgtag_t l4_icu_set_mode_u(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t mode, l4_utcb_t *utcb) L4_NOTHROW
Set interrupt mode.
Definition: icu.h:434
unsigned l4_msgtag_words(l4_msgtag_t t) L4_NOTHROW
Get the number of untyped words.
Definition: types.h:423
l4_umword_t raw
Raw value.
Definition: __l4_fpage.h:83
l4_uint32_t msi_data
Value to use as data written to msi_addr, when sending this MSI.
Definition: icu.h:185
Wakeup source?
Definition: icu.h:84
L4_icu_opcode
Opcodes to the ICU interface.
Definition: icu.h:93
l4_umword_t l4_map_obj_control(l4_umword_t spot, unsigned grant) L4_NOTHROW
Create the first word for a map item for the object space.
Definition: __l4_fpage.h:679
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
unsigned nr_irqs
The number of IRQ lines supported by the ICU,.
Definition: icu.h:171
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
Definition: types.h:408
l4_msgtag_t l4_ipc_send(l4_cap_idx_t dest, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Send a message to an object (do not wait for a reply).
Definition: ipc.h:470
L4_irq_mode
Interrupt attributes.
Definition: icu.h:67
struct l4_icu_msi_info_t l4_icu_msi_info_t
Info to use for a specific MSI.
Kernel object system calls.
l4_msgtag_t l4_icu_set_mode(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t mode) L4_NOTHROW
Set interrupt mode.
Definition: icu.h:500
IRQ message.
Definition: types.h:55
l4_msgtag_t l4_icu_info_u(l4_cap_idx_t icu, l4_icu_info_t *info, l4_utcb_t *utcb) L4_NOTHROW
Get information about the capabilities of the ICU.
Definition: icu.h:397
Positive edge trigger.
Definition: icu.h:78
unsigned nr_msis
The number of MSI vectors supported by the ICU,.
Definition: icu.h:176
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition: l4int.h:42
Positive trigger.
Definition: icu.h:73
Level triggered.
Definition: icu.h:71
Message tag data structure.
Definition: types.h:159
l4_msgtag_t l4_icu_unmask(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t *label, l4_timeout_t to) L4_NOTHROW
Unmask an IRQ line.
Definition: icu.h:490
Edge triggered.
Definition: icu.h:72
l4_msgtag_t l4_icu_mask(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t *label, l4_timeout_t to) L4_NOTHROW
Mask an IRQ line.
Definition: icu.h:495
l4_msgtag_t l4_icu_mask_u(l4_cap_idx_t icu, unsigned irqnum, l4_umword_t *label, l4_timeout_t to, l4_utcb_t *utcb) L4_NOTHROW
Mask an IRQ line.
Definition: icu.h:460
l4_fpage_t l4_obj_fpage(l4_cap_idx_t obj, unsigned int order, unsigned char rights) L4_NOTHROW
Create a kernel-object flex page.
Definition: __l4_fpage.h:645
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition: l4int.h:40
Bind opcode.
Definition: icu.h:100
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:185