1 /* 2 * Copyright (c) 2011-2018 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 29 #ifndef PE_CONSISTENT_DEBUG_H 30 #define PE_CONSISTENT_DEBUG_H 31 32 #include <stdint.h> 33 #include <sys/cdefs.h> 34 35 __BEGIN_DECLS 36 37 #define DEBUG_RECORD_ID_LONG(a, b, c, d, e, f, g, h) \ 38 ( ((uint64_t)( (((h) << 24) & 0xFF000000) | \ 39 (((g) << 16) & 0x00FF0000) | \ 40 (((f) << 8) & 0x0000FF00) | \ 41 ((e) & 0x000000FF) ) << 32) | \ 42 (uint64_t)( (((d) << 24) & 0xFF000000) | \ 43 (((c) << 16) & 0x00FF0000) | \ 44 (((b) << 8) & 0x0000FF00) | \ 45 ((a) & 0x000000FF) ) ) 46 #define DEBUG_RECORD_ID_SHORT(a, b, c, d) DEBUG_RECORD_ID_LONG(a,b,c,d,0,0,0,0) 47 48 typedef enum { 49 DBG_PROCESSOR_AP = 1, 50 DBG_COPROCESSOR_ANS, 51 DBG_COPROCESSOR_SEP, 52 DBG_COPROCESSOR_SIO, 53 DBG_COPROCESSOR_ISP, 54 DBG_COPROCESSOR_OSCAR, 55 DBG_NUM_PROCESSORS 56 } dbg_processor_t; 57 58 #define DbgIdConsoleHeaderForIOP(which_dbg_processor, which_num) (DEBUG_RECORD_ID_LONG('C','O','N',0,0,0,which_dbg_processor,which_num)) 59 60 #define kDbgIdConsoleHeaderAP DbgIdConsoleHeaderForIOP(DBG_PROCESSOR_AP, 0) 61 #define kDbgIdConsoleHeaderANS DbgIdConsoleHeaderForIOP(DBG_COPROCESSOR_ANS, 0) 62 #define kDbgIdConsoleHeaderSIO DbgIdConsoleHeaderForIOP(DBG_COPROCESSOR_SIO, 0) 63 #define kDbgIdConsoleHeaderSEP DbgIdConsoleHeaderForIOP(DBG_COPROCESSOR_SEP, 0) 64 #define kDbgIdConsoleHeaderISP DbgIdConsoleHeaderForIOP(DBG_COPROCESSOR_ISP, 0) 65 #define kDbgIdConsoleHeaderOscar DbgIdConsoleHeaderForIOP(DBG_COPROCESSOR_OSCAR, 0) 66 67 #define kDbgIdAstrisConnection DEBUG_RECORD_ID_LONG('A','S','T','R','C','N','X','N') 68 #define kDbgIdAstrisConnectionVers DEBUG_RECORD_ID_LONG('A','S','T','R','C','V','E','R') 69 70 #define kDbgIdMacOSPanicRegion DEBUG_RECORD_ID_LONG('M','A','C','P','A','N','I','C') 71 72 #define kDbgIdUnusedEntry 0x0ULL 73 #define kDbgIdReservedEntry DEBUG_RECORD_ID_LONG('R','E','S','E','R','V','E', 'D') 74 #define kDbgIdFreeReqEntry DEBUG_RECORD_ID_LONG('F','R','E','E','-','R','E','Q') 75 #define kDbgIdFreeAckEntry DEBUG_RECORD_ID_LONG('F','R','E','E','-','A','C','K') 76 77 #define DEBUG_REGISTRY_MAX_RECORDS 512 78 79 typedef struct { 80 uint64_t record_id; // = kDbgIdTopLevelHeader 81 uint32_t num_records; // = DEBUG_REGISTRY_MAX_RECORDS 82 uint32_t record_size_bytes; // = sizeof(dbg_record_header_t) 83 } dbg_top_level_header_t; 84 85 typedef struct { 86 uint64_t record_id; // 32-bit unique ID identifying the record 87 uint64_t length; // Length of the payload 88 uint64_t physaddr; // System physical address of entry 89 } dbg_record_header_t; 90 91 typedef struct { 92 uint64_t timestamp; 93 uint32_t cp_state; // One of the cp_state_t enumerations 94 uint32_t cp_state_arg; // IOP-defined supplemental value 95 } dbg_cpr_state_entry_t; 96 97 #define CPR_MAX_STATE_ENTRIES 16 // Arbitrary value 98 99 // This second-level struct should be what the Debug Registry record (e.g. kDbgIdCPRHeaderANS) points to. 100 typedef struct { 101 uint32_t rdptr; 102 uint32_t wrptr; 103 uint32_t num_cp_state_entries; 104 uint32_t checksum; 105 dbg_cpr_state_entry_t cp_state_entries[CPR_MAX_STATE_ENTRIES]; 106 } dbg_cpr_t; 107 108 typedef struct { 109 dbg_top_level_header_t top_level_header; 110 dbg_record_header_t records[DEBUG_REGISTRY_MAX_RECORDS]; 111 112 // Stuff the AP's Progress Report buffer at the end of this 113 // structure. It's currently the only processor that doesn't 114 // have some easier form of persistent memory that survives the 115 // iBoot->iOS handoff (e.g. ANS has its private heap) 116 dbg_cpr_t ap_cpr_region; 117 } dbg_registry_t; 118 119 /* 120 * Inherit the consistent debug structure from bootloader 121 */ 122 int PE_consistent_debug_inherit(void); 123 124 /* 125 * Register a region in the consistent debug structure 126 */ 127 int PE_consistent_debug_register(uint64_t record_id, uint64_t physaddr, uint64_t length); 128 129 /* 130 * Lookup an exidting entry from the consistent debug structure, populate the attributes 131 * if it exists. 132 */ 133 boolean_t PE_consistent_debug_lookup_entry(uint64_t record_id, uint64_t *phys_addr, uint64_t *length); 134 135 /* 136 * Returns whether consistent debug is enabled on the current device. 137 */ 138 int PE_consistent_debug_enabled(void); 139 140 __END_DECLS 141 142 #endif // PE_CONSISTENT_DEBUG_H 143