1/** 2 * \file 3 * \brief 4 */ 5 6/* 7 * Copyright (c) 2007, 2008, 2009, 2010, 2011, 2016, 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 MONITOR_H 16#define MONITOR_H 17 18#include <stdio.h> 19#include <stdlib.h> 20#include <string.h> 21#include <barrelfish/barrelfish.h> 22#include <spawndomain/spawndomain.h> 23#include <bench/bench_arch.h> 24#include <if/monitor_defs.h> 25#include <if/monitor_blocking_defs.h> 26#include <if/monitor_mem_defs.h> 27#include <monitor_invocations_arch.h> 28#include <queue.h> 29#include <connection.h> 30#include "monitor_debug.h" 31 32STATIC_ASSERT(MON_URPC_SIZE == 2*BASE_PAGE_SIZE, 33 "Change #URPC_SIZE if changing channel length"); 34#define MON_URPC_CHANNEL_LEN (32 * UMP_MSG_BYTES) 35#define MON_RAM_CHANNEL_LEN (2 * UMP_MSG_BYTES) 36 37// XXX: These should match the aliases in intermon.if 38typedef uint64_t state_id_t; 39typedef uint64_t mon_id_t; 40typedef uint64_t con_id_t; 41typedef uint32_t chanid_t; 42typedef uint8_t bool_t; 43 44// XXX: from old routing library, to be removed 45typedef uint32_t recordid_t; 46 47//XXX used to wait until all monitors are up and connected. asq 48extern int seen_connections; 49 50struct intermon_state { 51 struct msg_queue queue; ///< Queue of outgoing messages 52 struct intermon_binding *binding; ///< Back-pointer to binding 53 coreid_t core_id; ///< Core ID of monitor on other end 54 rsrcid_t rsrcid; 55 bool rsrcid_inflight; 56 bool capops_ready; 57 struct monitor_binding *originating_client; 58}; 59 60struct monitor_state { 61 struct msg_queue queue; 62}; 63 64extern iref_t mem_serv_iref; 65extern iref_t name_serv_iref; 66extern iref_t ramfs_serv_iref; 67extern iref_t spawn_iref; 68extern iref_t monitor_rpc_iref; 69extern iref_t monitor_mem_iref; 70extern coreid_t my_core_id; 71extern bool bsp_monitor; 72extern struct capref trace_cap; 73extern struct bootinfo *bi; 74extern bool update_ram_alloc_binding; 75 76union capability_caprep_u { 77 intermon_caprep_t caprep; 78 monitor_mem_caprep_t caprep2; 79 monitor_blocking_caprep_t caprepb; // XXX: identical to intermon_caprep_t 80 struct capability cap; 81}; 82STATIC_ASSERT(sizeof(union capability_caprep_u) >= sizeof(struct capability), \ 83 ASSERT_CONCAT("Size mismatch:", intermon_caprep_t)); 84 85STATIC_ASSERT(sizeof(struct capability) <= sizeof(intermon_caprep_t), 86 ASSERT_CONCAT("Size mismatch:", intermon_caprep_t)); 87 88static inline void capability_to_caprep(struct capability *cap, 89 intermon_caprep_t *caprep) 90{ 91 memcpy(caprep, cap, sizeof(*cap)); 92} 93 94static inline void caprep_to_capability(intermon_caprep_t *caprep, 95 struct capability *cap) 96{ 97 memcpy(cap, caprep, sizeof(*cap)); 98} 99 100static inline void debug_print_caprep(intermon_caprep_t *caprep) 101{ 102 struct capability cap; 103 memcpy(&cap, caprep, sizeof(cap)); 104 char buf[256]; 105 debug_print_cap(buf, 256, &cap); 106 buf[255] = 0; 107 DEBUG_CAPOPS("\t%s\n", buf); 108} 109 110static inline void debug_print_caprep2(monitor_mem_caprep_t *caprep) 111{ 112 struct capability cap; 113 memcpy(&cap, caprep, sizeof(cap)); 114 char buf[256]; 115 debug_print_cap(buf, 256, &cap); 116 buf[255] = 0; 117 DEBUG_CAPOPS("\t%s\n", buf); 118} 119 120#include <ram_alloc.h> 121#include <spawn.h> 122#include <monitor_server.h> 123#include <monitor_invocations.h> 124 125/* boot.c */ 126void boot_core_request(struct monitor_binding *st, coreid_t id, 127 struct capref frame); 128void boot_initialize_request(struct monitor_binding *st); 129 130errval_t spawn_xcore_monitor(coreid_t id, int hwid, enum cpu_type cpu_type, 131 const char *cmdline, 132 struct intermon_binding **ret_binding); 133errval_t boot_arch_app_core(int argc, char *argv[], 134 coreid_t *ret_parent_coreid, 135 struct intermon_binding **ret_binding); 136 137/* main.c */ 138errval_t request_trace_caps(struct intermon_binding *st); 139errval_t request_mem_serv_iref(struct intermon_binding *st); 140errval_t request_name_serv_iref(struct intermon_binding *st); 141errval_t request_ramfs_serv_iref(struct intermon_binding *st); 142 143/* inter.c */ 144errval_t intermon_init(struct intermon_binding *b, coreid_t coreid); 145errval_t arch_intermon_init(struct intermon_binding *b); 146 147/* ump_support.c */ 148errval_t ump_intermon_init(struct intermon_binding *ib); 149errval_t ump_monitor_init(struct monitor_binding *mb); 150 151/* multihop_support.c */ 152errval_t multihop_intermon_init(struct intermon_binding *ib); 153errval_t multihop_monitor_init(struct monitor_binding *mb); 154errval_t multihop_request_routing_table(struct intermon_binding *b); 155 156/* trace_support.c */ 157errval_t trace_intermon_init(struct intermon_binding *ib); 158errval_t trace_monitor_init(struct monitor_binding *mb); 159 160/* bfscope_support.c */ 161errval_t bfscope_intermon_init(struct intermon_binding *ib); 162errval_t bfscope_monitor_init(struct monitor_binding *mb); 163 164/* rck_support.c */ 165errval_t rck_intermon_init(struct intermon_binding *ib); 166errval_t rck_monitor_init(struct monitor_binding *mb); 167 168// Resource control 169errval_t rsrc_new(rsrcid_t *id); 170errval_t rsrc_join_satellite(rsrcid_t id, coreid_t coreid); 171errval_t rsrc_join(rsrcid_t id, struct capref dispcap, 172 struct monitor_blocking_binding *b); 173errval_t rsrc_submit_manifest(rsrcid_t id, char *manifest); 174errval_t rsrc_set_phase(rsrcid_t id, uintptr_t phase); 175errval_t rsrc_set_phase_inter(rsrcid_t id, uintptr_t phase, uint64_t timestamp); 176struct monitor_blocking_binding *rsrc_get_binding(rsrcid_t id); 177errval_t rsrc_set_phase_data(rsrcid_t id, uintptr_t active, void *data, 178 size_t len); 179 180// Time coordination 181errval_t timing_sync_timer(void); 182void timing_sync_timer_reply(errval_t err); 183void timing_sync_bench(void); 184 185/* domain.c */ 186void domain_mgmt_init(void); 187 188/* intermon_bindings.c */ 189errval_t intermon_binding_set(struct intermon_state *st); 190errval_t intermon_binding_get(coreid_t coreid, struct intermon_binding **ret); 191 192/* iref.c */ 193errval_t iref_alloc(struct monitor_binding *binding, uintptr_t service_id, 194 iref_t *iref); 195errval_t iref_get_core_id(iref_t iref, coreid_t *core_id); 196errval_t iref_get_binding(iref_t iref, struct monitor_binding **binding); 197errval_t iref_get_service_id(iref_t iref, uintptr_t *service_id); 198 199/* octopus_client.c */ 200errval_t octopus_client_bind(void); 201errval_t octopus_set_bspkcb(void); 202 203#endif // MONITOR_H 204