| 1 | /* |
| 2 | * ========== Copyright Header Begin ========================================== |
| 3 | * |
| 4 | * OpenSPARC T2 Processor File: system.h |
| 5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. |
| 6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. |
| 7 | * |
| 8 | * The above named program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public |
| 10 | * License version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * The above named program is distributed in the hope that it will be |
| 13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public |
| 18 | * License along with this work; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | * |
| 21 | * ========== Copyright Header End ============================================ |
| 22 | */ |
| 23 | /* |
| 24 | * Copyright (C) 2001, 2005 Sun Microsystems, Inc. |
| 25 | * All rights reserved. |
| 26 | */ |
| 27 | |
| 28 | |
| 29 | #ifndef _SYSTEM_H |
| 30 | #define _SYSTEM_H |
| 31 | |
| 32 | |
| 33 | #include "types.h" |
| 34 | |
| 35 | #include "cpu_interface.h" |
| 36 | |
| 37 | |
| 38 | typedef Vcpu cpuT; |
| 39 | typedef VCPU_InterruptRequest intrT; |
| 40 | |
| 41 | |
| 42 | void SYSTEM_init (); |
| 43 | void * SYSTEM_is_ready (); |
| 44 | |
| 45 | |
| 46 | void SYSTEM_main(void); |
| 47 | |
| 48 | |
| 49 | FILE * SYSTEM_fopen (const char * filename, const char * flags); |
| 50 | int SYSTEM_open (const char * filename, int oflag); |
| 51 | void init_SYSTEM_open (); |
| 52 | |
| 53 | |
| 54 | // |
| 55 | // External API mostly for loadable modules |
| 56 | // |
| 57 | #ifdef __cplusplus |
| 58 | extern "C" { |
| 59 | #endif |
| 60 | #if 0 |
| 61 | } |
| 62 | #endif |
| 63 | |
| 64 | #ifdef NIAGARA |
| 65 | void SYSTEM_interrupt_by_vector (uint32_t tid, uint32_t vnum); |
| 66 | #endif |
| 67 | |
| 68 | bool_t SYSTEM_chplus_mmu (); |
| 69 | bool_t SYSTEM_is_serengeti(); |
| 70 | bool_t SYSTEM_is_480R(); |
| 71 | uint8_t SYSTEM_get_nic_num(); |
| 72 | uint8_t SYSTEM_get_dc_num(); |
| 73 | uint64_t SYSTEM_get_globaltick (); |
| 74 | void SYSTEM_increment_time (); |
| 75 | uint64_t SYSTEM_get_globaltick_per_cpu (); |
| 76 | uint64_t SYSTEM_get_globaltick_per_core (uint32_t cores); |
| 77 | uint32_t SYSTEM_get_ncpu (); |
| 78 | uint32_t SYSTEM_get_ncores(); |
| 79 | char * SYSTEM_get_version (); |
| 80 | double SYSTEM_get_versionnum (); |
| 81 | const char* SYSTEM_get_ramsizeS(); |
| 82 | int SYSTEM_get_tlbsize(); |
| 83 | const char* SYSTEM_get_mmutypeS(); |
| 84 | const char* SYSTEM_get_cputypeS(); |
| 85 | uint64_t SYSTEM_get_cpufreq(); |
| 86 | uint64_t SYSTEM_get_stickfreq(); |
| 87 | int SYSTEM_get_diskdelay(); |
| 88 | int SYSTEM_get_loopticks(); |
| 89 | int SYSTEM_get_stickincr(); |
| 90 | int SYSTEM_get_numthreads(); |
| 91 | int SYSTEM_get_cpus_per_thread(); |
| 92 | int SYSTEM_get_skipmp(); |
| 93 | int SYSTEM_get_blockmp(); |
| 94 | int SYSTEM_get_wrdiskdelay(); |
| 95 | bool_t SYSTEM_get_ce_enable_flag(); |
| 96 | void SYSTEM_set_ce_enable_flag(bool_t flag); |
| 97 | bool_t SYSTEM_get_scsi_disk_enable_flag(); |
| 98 | void SYSTEM_set_scsi_disk_enable_flag(bool_t flag); |
| 99 | void SYSTEM_set_boot_aid_bus(unsigned char aid, unsigned char bus); // cchen |
| 100 | bool_t SYSTEM_get_scsi_boot_enable_flag(); |
| 101 | void SYSTEM_set_scsi_boot_enable_flag(bool_t flag); |
| 102 | bool_t SYSTEM_get_fc_disk_enable_flag(); |
| 103 | void SYSTEM_set_fc_disk_enable_flag(bool_t flag); |
| 104 | bool_t SYSTEM_get_fc_boot_enable_flag(); |
| 105 | void SYSTEM_set_fc_boot_enable_flag(bool_t flag); |
| 106 | int SYSTEM_get_nwins(); |
| 107 | const char* SYSTEM_get_infostr (); |
| 108 | void SYSTEM_free_intr (intrT *); |
| 109 | |
| 110 | |
| 111 | |
| 112 | /* ------ specifically for ui-thread ------ */ |
| 113 | void SYSTEM_stop_UI (); |
| 114 | void SYSTEM_run_UI (); |
| 115 | void SYSTEM_stepi_UI (int64_t ni); |
| 116 | void SYSTEM_stepc_UI (int64_t nc); |
| 117 | typedef void (*doneftn_t)(void *); |
| 118 | void SYSTEM_stept_UI (int64_t usecs, int64_t seqnum, doneftn_t callback); |
| 119 | void SYSTEM_syncon_UI (); |
| 120 | void SYSTEM_syncoff_UI (); |
| 121 | |
| 122 | void SYSTEM_lock_UI (); |
| 123 | void SYSTEM_unlock_UI (); |
| 124 | |
| 125 | // simulate nusecs time of cpu |
| 126 | void SYSTEM_kick_usecs (int64_t nusecs); |
| 127 | // simulate ninstr number of instructions |
| 128 | void SYSTEM_kick_instrs (int64_t ninstrs); |
| 129 | |
| 130 | void SYSTEM_kick_cycles(int64_t ncycles); |
| 131 | |
| 132 | void SYSTEM_wait_worker_threads (); |
| 133 | // get the global system simulated time in usecs |
| 134 | uint64_t SYSTEM_get_global_time(); |
| 135 | int64_t SYSTEM_get_ticks(); |
| 136 | void SYSTEM_kick_with_callback (int64_t ninstrs, doneftn_t callback); |
| 137 | |
| 138 | void SYSTEM_quit_UI(); |
| 139 | |
| 140 | void SYSTEM_quit(); // should be deleted.?. |
| 141 | void SYSTEM_stop(); // should be deleted.!!!. |
| 142 | |
| 143 | bool_t SYSTEM_is_stopped (); // these three are mutually exclusive |
| 144 | bool_t SYSTEM_is_running (); // and taken together are complete. |
| 145 | bool_t SYSTEM_is_notready (); // ie initialization not yet done. |
| 146 | |
| 147 | |
| 148 | |
| 149 | void SYSTEM_dump (FILE*); |
| 150 | bool_t SYSTEM_restore (FILE*); |
| 151 | void SYSTEM_unlock (); |
| 152 | |
| 153 | void SYSTEM_cycle_delay (uint32_t cpuid, uint32_t delay); |
| 154 | |
| 155 | |
| 156 | uint64_t SYSTEM_get_ireg (cpuT *sp, int wp, int regnum); |
| 157 | uint64_t SYSTEM_get_freg (cpuT *sp, int issingle, int regnum); |
| 158 | |
| 159 | |
| 160 | // Is being called when other CPU or SCHIZO(IO) are going to interrupt |
| 161 | // target CPU (dst_cpu) |
| 162 | void SYSTEM_interrupt_by_sid(int dst_aid, int src_aid, intrT *intr); |
| 163 | |
| 164 | // SYSTEM_cpu_by_sid gets the cpu pointer by system id (sid). sid is |
| 165 | // the platforms view of the cpu id which may or may not be sequantial |
| 166 | cpuT *SYSTEM_cpu_by_sid(int n); |
| 167 | |
| 168 | |
| 169 | // Is being called from inside CPU (CPU_cycle) for periodic external |
| 170 | // interrupts handling |
| 171 | void SYSTEM_cpu_interrupt_queue_process(int mid); |
| 172 | void SYSTEM_init_cmp_mod(bool_t restore, char * restore_dir); |
| 173 | void SYSTEM_init_cpu (bool_t restore, char * restore_dir); |
| 174 | |
| 175 | |
| 176 | // physical I/O access from cpu to I/O modules |
| 177 | int SYSTEM_physio_access (uint32_t cpuid, void* obj, uint64_t paddr, bool_t wr, uint32_t size, uint64_t* buf, uint8_t bytemask=PHYSIO_BYTEMASK_ALL); |
| 178 | |
| 179 | // serial console |
| 180 | uint64_t SYSTEM_serial_fake_in (cpuT *sp); |
| 181 | void SYSTEM_serial_fake_out (cpuT *sp, char c); |
| 182 | |
| 183 | void SYSTEM_set_pc (uint32_t cpuid, uint64_t pc); |
| 184 | void SYSTEM_set_npc (uint32_t cpuid, uint64_t npc); |
| 185 | |
| 186 | |
| 187 | bool_t SYSTEM_is_exec_thrd (); |
| 188 | |
| 189 | |
| 190 | |
| 191 | /*timesync ------------------------------------------------------------- */ |
| 192 | |
| 193 | typedef enum { // Whence simulated time is measured from |
| 194 | TW_CURRENT, // time since boot |
| 195 | TW_INTERVAL, // time since last global-sync-interval started |
| 196 | TW_MARK, // the time at which global-sync-interval started |
| 197 | TW_LENGTH // the length of the current global-sync-interval |
| 198 | } timewhence_t; |
| 199 | |
| 200 | |
| 201 | // in MICROSECS simulated time |
| 202 | sint64_t SYSTEM_get_time (timewhence_t whence = TW_CURRENT); |
| 203 | |
| 204 | |
| 205 | |
| 206 | void SYSTEM_mark_intervalstart (sint64_t intervallength); |
| 207 | void SYSTEM_mark_intervalstop (); |
| 208 | |
| 209 | sint64_t SYSTEM_get_sequencenum (); // current global-time-sync interval # |
| 210 | |
| 211 | bool SYSTEM_is_sync_on(); |
| 212 | |
| 213 | sint64_t SYSTEM_usecs2cycles (sint64_t); |
| 214 | sint64_t SYSTEM_usecs2sticks (sint64_t); |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | typedef void (EventFunc_T)(void * arg1, void * arg2); |
| 220 | typedef void (UnloadFunc_T)(sint64_t stime, void * arg1, void * arg2); |
| 221 | |
| 222 | void SYSTEM_register_event ( |
| 223 | uint64_t stime, /* microsecs, simulated time */ |
| 224 | EventFunc_T * callback, void * arg1, void * arg2, |
| 225 | UnloadFunc_T * unloadfunc, |
| 226 | const char * debugstring); |
| 227 | |
| 228 | |
| 229 | /* --------------------------------------------------------------------- */ |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | /* cpu-worker-threads for mp-on-mp -------------------------------------- */ |
| 235 | void SYSTEM_wait_worker_threads (); |
| 236 | /* --------------------------------------------------------------------- */ |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | /* hostconfig ----------------------------------------------------------- */ |
| 242 | // returns config-value, given config-name, simple dictionary/map lookup. |
| 243 | extern const char * SYSTEM_get_hostconfig (const char * configname); |
| 244 | // |
| 245 | extern bool_t SYSTEM_isset_hostconfig (const char * configname); |
| 246 | // used by ... to initially record the hostconfig info |
| 247 | extern void SYSTEM_set_hostconfig (const char * configname, const char * configvalue); |
| 248 | |
| 249 | |
| 250 | // get number-of-cpus available in underlying host system |
| 251 | extern int HOSTINFO_numcpus(); |
| 252 | /* hostconfig ---------------------------------------------------------- */ |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | #if 0 |
| 261 | { |
| 262 | #endif |
| 263 | #ifdef __cplusplus |
| 264 | } |
| 265 | #endif |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | void SYSTEM_set_extend_ready (); |
| 271 | void SYSTEM_set_extend_not_ready (); |
| 272 | |
| 273 | // |
| 274 | // Diskdelay SCSI module support |
| 275 | // |
| 276 | |
| 277 | void SYSTEM_register_dd_handlers ( void * fn1, void * fn2); |
| 278 | |
| 279 | // |
| 280 | // start/stop mechanizm for different threads |
| 281 | // (clean dump/restore and other stuff) |
| 282 | // |
| 283 | typedef void (*ss_action) (void*); |
| 284 | extern void SYSTEM_ss_register (ss_action, ss_action, void*); |
| 285 | extern void SYSTEM_ss_unregister (void*); |
| 286 | |
| 287 | |
| 288 | // |
| 289 | // Misc functions |
| 290 | // |
| 291 | //extern uint64_t SYSTEM_get_int_property (cpuT *sp, uint64_t vaddr); |
| 292 | |
| 293 | extern uint64_t SYSTEM_get_goodtrap_pc(); |
| 294 | extern uint64_t SYSTEM_get_badtrap_pc(); |
| 295 | extern void SYSTEM_set_goodtrap_pc(uint64_t); |
| 296 | extern void SYSTEM_set_badtrap_pc(uint64_t); |
| 297 | |
| 298 | extern sint64_t SYSTEM_Sticks2usecs (sint64_t sticks); |
| 299 | extern sint64_t SYSTEM_Ticks2usecs (sint64_t ticks); |
| 300 | |
| 301 | void SYSTEM_set_memreserve (bool_t flag); |
| 302 | bool_t SYSTEM_get_memreserve(); |
| 303 | |
| 304 | int SYSTEM_in_execution_driven_mode(); |
| 305 | void SYSTEM_enable_execution_driven_mode(); |
| 306 | void SYSTEM_disable_execution_driven_mode(); |
| 307 | |
| 308 | |
| 309 | #endif /* _SYSTEM_H */ |