1/*
2 * Copyright 2016, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(D61_BSD)
11 */
12
13#ifndef _CONSOLE_SERVER_BADGE_H_
14#define _CONSOLE_SERVER_BADGE_H_
15
16#include <refos/refos.h>
17
18/*! @file
19    @brief Console Server badge space definitions.
20
21    Since Console server needs to recieve both asynchronous device IRQ and synchronous syscall
22    messages. This presents an interesting badge space problem, as device IRQs are XOR-ed with each
23    other but synchronous call values are distinct. The Console server needs to tell one from the
24    other.
25
26    Console Server badgespace distinguishes between async notifications and sync notifications using
27    an async signature bit (bit 19). If this signature bit is set, it means the first 18-bit bitmask
28    preceding it contains IRQ async notification data. If this signature bit is not set, it means
29    the 18-bit value preceding it contains numbered badges (which contain both StdIO / timer badges,
30    and client session badges).
31
32    Visualisation of Console server badgespace bits:
33
34    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35
36    CONSERV_DSPACE_BADGE_STDIO:
37                        ������������ lower bits               higher bits ������������
38                        0 0 0 1 0 1    0 0 0 0 0 0 0 0 0 0 0 0 0     0
39                        ���_________���                                  ��� ASYNC_BADGE_MASK = false
40                             ��� 0x28
41
42    CONSERV_DSPACE_BADGE_SCREEN
43                        ������������ lower bits               higher bits ������������
44                        1 1 1 0 0 1    0 0 0 0 0 0 0 0 0 0 0 0 0     0
45                        ���_________���                                  ��� ASYNC_BADGE_MASK = false
46                             ��� 0x27
47
48    CONSERV_CLIENT_BADGE badges:
49                        ������������ lower bits               higher bits ������������
50                        0 0 0 0 0 0    1 0 1 1 0 1 0 0 0 0 0 0 0     0
51                                       ���_______________________���     ��� ASYNC_BADGE_MASK = false
52                                                  ��� Client ID value
53
54    CONSERV_ASYNC_NOTIFY_BADGE:
55                        ������������ lower bits               higher bits ������������
56                        1    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0     1
57                        ���                                            ��� ASYNC_BADGE_MASK = true
58                     0x1 bit set
59
60    CONSERV_IRQ_BADGE badges:
61                        ������������ lower bits               higher bits ������������
62                        0    0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0     1
63                             ���_________________________________���     ��� ASYNC_BADGE_MASK = true
64                                             ���
65                        Bitmask indicating which IRQ channels happened.
66
67    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68*/
69
70#define CONSERV_DSPACE_BADGE_STDIO 0x28    /*!< @brief StdIO dataspace badge value. */
71#define CONSERV_DSPACE_BADGE_SCREEN 0x27    /*!< @brief Screen dataspace badge value. */
72
73/* ---- BadgeID 48 to 4143 : Clients ---- */
74#define CONSERV_CLIENT_BADGE_BASE 0x30
75
76/* ---- Async BadgeIDs  ---- */
77
78#define CONSERV_ASYNC_BADGE_MASK (1 << 19)
79#define CONSERV_ASYNC_NOTIFY_BADGE (1 << 0)
80
81#define CONSERV_IRQ_BADGE_BASE_POW 1
82#define CONSERV_IRQ_BADGE_BASE_POW_TOP 18
83#define CONSERV_IRQ_BADGE_NCHANNELS \
84        ((CONSERV_IRQ_BADGE_BASE_POW_TOP - CONSERV_IRQ_BADGE_BASE_POW) + 1)
85
86#endif /* _CONSOLE_SERVER_BADGE_H_ */
87