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