Public VCPD mboxes (XCC)
[akaros.git] / kern / include / ros / event.h
1 /* Copyright (c) 2010-2011 The Regents of the University of California
2  * Barret Rhoden <brho@cs.berkeley.edu>
3  * See LICENSE for details.
4  *
5  * Kernel interface for event/notification delivery and preemption. */
6
7 #ifndef ROS_INC_EVENT_H
8 #define ROS_INC_EVENT_H
9
10 #include <ros/common.h>
11 #include <ros/atomic.h>
12 #include <ros/arch/trapframe.h>
13 /* #include <ros/ucq.h> included below */
14
15 /* Event Delivery Flags from the process to the kernel */
16 #define EVENT_IPI                               0x001   /* IPI the vcore (usually with INDIR) */
17 #define EVENT_INDIR                             0x002   /* send an indirection event to vcore */
18 #define EVENT_FALLBACK                  0x004   /* pick another vcore if it's offline */
19 #define EVENT_NOMSG                             0x008   /* just send the bit, not the msg */
20 #define EVENT_NOTHROTTLE                0x010   /* send all alerts (no throttling) */
21 #define EVENT_VCORE_MUST_RUN    0x020   /* Alerts go to a vcore that will run */
22 /* Not seriously used flags */
23 #define EVENT_ROUNDROBIN                0x040   /* pick a vcore, RR style */
24 #define EVENT_VCORE_APPRO               0x080   /* send to where the kernel wants */
25 #define EVENT_VCORE_PRIVATE             0x100   /* Will go to the private VCPD mbox */
26
27 /* Flags from the program to the 2LS */
28 #define EVENT_JUSTHANDLEIT              0x200   /* 2LS should handle the ev_q */
29 #define EVENT_THREAD                    0x400   /* spawn thread to handle ev_q */
30
31 /* Event Message Types */
32 #define EV_NONE                                  0
33 #define EV_PREEMPT_PENDING               1
34 #define EV_GANG_PREMPT_PENDING   2
35 #define EV_VCORE_PREEMPT                 3
36 #define EV_GANG_RETURN                   4
37 #define EV_USER_IPI                              5
38 #define EV_PAGE_FAULT                    6
39 #define EV_ALARM                                 7
40 #define EV_EVENT                                 8
41 #define EV_FREE_APPLE_PIE                9
42 #define EV_SYSCALL                              10
43 #define NR_EVENT_TYPES                  11 /* keep me last */
44
45 /* Will probably have dynamic notifications later */
46 #define MAX_NR_DYN_EVENT                25
47 #define MAX_NR_EVENT                    (NR_EVENT_TYPES + MAX_NR_DYN_EVENT)
48
49 /* Want to keep this small and generic, but add items as you need them.  One
50  * item some will need is an expiration time, which ought to be put in the 64
51  * bit arg.  Will need tweaking / thought as we come up with events.  These are
52  * what get put on the per-core queue in procdata. */
53 struct event_msg {
54         uint16_t                                        ev_type;
55         uint16_t                                        ev_arg1;
56         uint32_t                                        ev_arg2;
57         void                                            *ev_arg3;
58         uint64_t                                        ev_arg4;
59 };
60
61 /* Including here since ucq.h needs to know about struct event_msg */
62 #include <ros/ucq.h>
63
64 /* Structure for storing / receiving event messages.  An overflow causes the
65  * bit of the event to get set in the bitmap.  You can also have just the bit
66  * sent (and no message). */
67 struct event_mbox {
68         struct ucq                                      ev_msgs;
69         uint8_t                                         ev_bitmap[(MAX_NR_EVENT - 1) / 8 + 1];
70 };
71
72 /* The kernel sends messages to this structure, which describes how and where
73  * to receive messages, including optional IPIs. */
74 struct event_queue {
75         struct event_mbox                       *ev_mbox;
76         int                                                     ev_flags;
77         bool                                            ev_alert_pending;
78         uint32_t                                        ev_vcore;
79         void                                            (*ev_handler)(struct event_queue *);
80 };
81
82 /* Big version, contains storage space for the ev_mbox.  Never access the
83  * internal mbox directly. */
84 struct event_queue_big {
85         struct event_mbox                       *ev_mbox;
86         int                                                     ev_flags;
87         uint32_t                                        ev_vcore;
88         void                                            (*ev_handler)(struct event_queue *);
89         struct event_mbox                       ev_imbox;
90 };
91
92 /* Vcore state flags.  K_LOCK means the kernel is writing */
93 #define VC_K_LOCK                               0x001                           /* CASing with the kernel */
94 #define VC_PREEMPTED                    0x002                           /* VC is preempted */
95 #define VC_RECOVERING                   0x004                           /* VC being recovered */
96 #define VC_UTHREAD_STEALING             0x008                           /* Uthread being stolen */
97
98 /* Per-core data about preemptions and notifications */
99 struct preempt_data {
100         struct user_trapframe           preempt_tf;                     /* slot for vcore ctx */
101         struct ancillary_state          preempt_anc;
102         struct user_trapframe           notif_tf;                       /* slot for uthread ctx */
103         uintptr_t                                       transition_stack;       /* advertised by the user */
104         atomic_t                                        flags;
105         bool                                            notif_disabled;         /* vcore unwilling to recv*/
106         bool                                            notif_pending;          /* notif k_msg on the way */
107         bool                                            can_rcv_msg;            /* can receive FALLBACK */
108         struct event_mbox                       ev_mbox_public;         /* can be read remotely */
109         struct event_mbox                       ev_mbox_private;        /* for this vcore only */
110 };
111
112 #endif /* ROS_INC_EVENT_H */