1 // Copyright 2016 The Fuchsia Authors 2 // 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file or at 5 // https://opensource.org/licenses/MIT 6 7 #pragma once 8 9 #include <zircon/compiler.h> 10 #include <zircon/types.h> 11 #include <kernel/event.h> 12 #include <kernel/mutex.h> 13 #include <list.h> 14 #include <stdint.h> 15 16 __BEGIN_CDECLS 17 18 typedef struct dlog dlog_t; 19 typedef struct dlog_header dlog_header_t; 20 typedef struct dlog_record dlog_record_t; 21 typedef struct dlog_reader dlog_reader_t; 22 23 struct dlog { 24 spin_lock_t lock; 25 26 size_t head; 27 size_t tail; 28 29 uint8_t* data; 30 31 bool panic; 32 33 event_t event; 34 35 mutex_t readers_lock; 36 struct list_node readers; 37 }; 38 39 struct dlog_reader { 40 struct list_node node; 41 42 dlog_t* log; 43 size_t tail; 44 45 void (*notify)(void* cookie); 46 void *cookie; 47 }; 48 49 #define DLOG_HDR_SET(fifosize, readsize) \ 50 ((((readsize) & 0xFFF) << 12) | ((fifosize) & 0xFFF)) 51 52 #define DLOG_HDR_GET_FIFOLEN(n) ((n) & 0xFFF) 53 #define DLOG_HDR_GET_READLEN(n) (((n) >> 12) & 0xFFF) 54 55 #define DLOG_MIN_RECORD (32u) 56 #define DLOG_MAX_DATA (224u) 57 #define DLOG_MAX_RECORD (DLOG_MIN_RECORD + DLOG_MAX_DATA) 58 59 struct dlog_header { 60 uint32_t header; 61 uint16_t datalen; 62 uint16_t flags; 63 uint64_t timestamp; 64 uint64_t pid; 65 uint64_t tid; 66 }; 67 68 struct dlog_record { 69 dlog_header_t hdr; 70 char data[DLOG_MAX_DATA]; 71 }; 72 73 static_assert(sizeof(dlog_header_t) == DLOG_MIN_RECORD, ""); 74 static_assert(sizeof(dlog_record_t) == DLOG_MAX_RECORD, ""); 75 76 void dlog_reader_init(dlog_reader_t* rdr, void (*notify)(void*), void* cookie); 77 void dlog_reader_destroy(dlog_reader_t* rdr); 78 zx_status_t dlog_write(uint32_t flags, const void* ptr, size_t len); 79 zx_status_t dlog_read(dlog_reader_t* rdr, uint32_t flags, void* ptr, size_t len, size_t* actual); 80 81 // used by sys_debug_write() 82 void dlog_serial_write(const char* data, size_t len); 83 84 // bluescreen_init should be called at the "start" of a fatal fault or 85 // panic to ensure that the fault output (via kernel printf/dprintf) 86 // is captured or displayed to the user 87 void dlog_bluescreen_init(void); 88 89 // bluescreen_halt should be called from inside platform_halt to allow 90 // the bluescreen service to finalize the display of the panic data 91 // (for example, creating a qrcode) 92 void dlog_bluescreen_halt(void); 93 94 // Shutdown the debuglog subsystem. 95 // 96 // Note: This may block for an extended period of time. 97 void dlog_shutdown(void); 98 99 void dlog_bypass_init_early(void); 100 void dlog_bypass_init(void); 101 bool dlog_bypass(void); 102 103 __END_CDECLS 104