1/**
2 * \file
3 * \brief Generic dispatcher struct shared between kernel and user
4 */
5
6/*
7 * Copyright (c) 2007, 2008, 2009, 2010, 2011, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#ifndef BARRELFISH_KPI_DISPATCHER_SHARED_H
16#define BARRELFISH_KPI_DISPATCHER_SHARED_H
17
18#ifndef __ASSEMBLER__
19
20#include <barrelfish_kpi/dispatcher_handle.h>
21
22/**
23 * \brief Amount of space required for the dispatcher frame.
24 * This should be at least greater than the memory required for
25 * struct disp_priv.
26 * Keeping it as a power of 2 allows using a single cap for dispatcher frame
27 *
28 * \bug Make this arch specific
29 */
30#define DISPATCHER_FRAME_BITS 18
31#define DISP_NAME_LEN   16
32
33enum task_type {
34    TASK_TYPE_BEST_EFFORT,
35    TASK_TYPE_SOFT_REALTIME,
36    TASK_TYPE_HARD_REALTIME
37};
38
39///< Architecture generic kernel/user shared dispatcher struct
40struct dispatcher_shared_generic {
41    uint32_t   disabled;                        ///< Disabled flag (Must be able to change atomically)
42    uint32_t   haswork;                         ///< Has work (ie. is runnable) (Must be able to change atomically)
43
44    lvaddr_t    udisp;                          ///< User-mode pointer to dispatcher
45    uint32_t    lmp_delivered, lmp_seen;        ///< # LMP words delivered and seen
46    lvaddr_t    lmp_hint;                       ///< Hint for location of LMP
47    lvaddr_t    dispatcher_run;                 ///< Run entry
48    lvaddr_t    dispatcher_lrpc;                ///< LRPC entry
49    lvaddr_t    dispatcher_pagefault;           ///< Pagefault entry
50    lvaddr_t    dispatcher_pagefault_disabled;  ///< Disabled pagefault entry
51    lvaddr_t    dispatcher_trap;                ///< Trap entry
52
53    systime_t   systime;                        ///< System time when last dispatched/resumed (W/O to kernel)
54    systime_t   wakeup;                         ///< System time at which to wake dispatcher from sleep (R/O by kernel, on yield)
55
56    char        name[DISP_NAME_LEN];            ///< Name of domain, for debugging purposes
57
58    uint64_t    systime_frequency;              ///< Systime frequency
59    coreid_t    curr_core_id;                   ///< Core id of current core, in this part so kernel can update
60#ifdef __k1om__
61    uint8_t     xeon_phi_id;
62#endif
63};
64
65static inline struct dispatcher_shared_generic*
66get_dispatcher_shared_generic(dispatcher_handle_t handle)
67{
68    return (struct dispatcher_shared_generic*)handle;
69}
70
71static inline lvaddr_t get_dispatcher_vaddr(dispatcher_handle_t handle)
72{
73    return (lvaddr_t)handle;
74}
75
76#include <stdio.h>
77static inline void dump_dispatcher(struct dispatcher_shared_generic *disp)
78{
79    printf("Dump of dispatcher at address %p:\n", disp);
80    printf("  disabled      = %d (%s)\n", disp->disabled, disp->disabled ? "RESUME" : "UPCALL" );
81    printf("  haswork       = %d\n", disp->haswork );
82    printf("  udisp         = 0x%"PRIxLVADDR"\n", disp->udisp );
83    printf("  lmp_delivered = %d\n", disp->lmp_delivered );
84    printf("  lmp_seen      = %d\n", disp->lmp_seen );
85    printf("  lpm_hint      = 0x%"PRIxLVADDR"\n", disp->lmp_hint );
86    printf("  dispatcher_run                = 0x%"PRIxLVADDR"\n", disp->dispatcher_run );
87    printf("  dispatcher_pagefault          = 0x%"PRIxLVADDR"\n", disp->dispatcher_pagefault );
88    printf("  dispatcher_pagefault_disabled = 0x%"PRIxLVADDR"\n", disp->dispatcher_pagefault_disabled );
89    printf("  dispatcher_trap               = 0x%"PRIxLVADDR"\n", disp->dispatcher_trap );
90    printf("  systime      = 0x%" PRIuSYSTIME "\n", disp->systime );
91    printf("  wakeup       = 0x%" PRIuSYSTIME "\n", disp->wakeup );
92    printf("  name         = %.*s\n", DISP_NAME_LEN, disp->name );
93    printf("  curr_core_id = 0x%" PRIxCOREID "\n", disp->curr_core_id );
94}
95
96
97#endif //__ASSEMBLER__
98#endif // BARRELFISH_KPI_DISPATCHER_SHARED_H
99