xref: /openbmc/qemu/include/sysemu/dump.h (revision 9c4218e9)
1 /*
2  * QEMU dump
3  *
4  * Copyright Fujitsu, Corp. 2011, 2012
5  *
6  * Authors:
7  *     Wen Congyang <wency@cn.fujitsu.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10  * See the COPYING file in the top-level directory.
11  *
12  */
13 
14 #ifndef DUMP_H
15 #define DUMP_H
16 
17 #define MAKEDUMPFILE_SIGNATURE      "makedumpfile"
18 #define MAX_SIZE_MDF_HEADER         (4096) /* max size of makedumpfile_header */
19 #define TYPE_FLAT_HEADER            (1)    /* type of flattened format */
20 #define VERSION_FLAT_HEADER         (1)    /* version of flattened format */
21 #define END_FLAG_FLAT_HEADER        (-1)
22 
23 #ifndef ARCH_PFN_OFFSET
24 #define ARCH_PFN_OFFSET             (0)
25 #endif
26 
27 /*
28  * flag for compressed format
29  */
30 #define DUMP_DH_COMPRESSED_ZLIB     (0x1)
31 #define DUMP_DH_COMPRESSED_LZO      (0x2)
32 #define DUMP_DH_COMPRESSED_SNAPPY   (0x4)
33 
34 #define KDUMP_SIGNATURE             "KDUMP   "
35 #define SIG_LEN                     (sizeof(KDUMP_SIGNATURE) - 1)
36 #define DUMP_LEVEL                  (1)
37 #define DISKDUMP_HEADER_BLOCKS      (1)
38 
39 #include "sysemu/dump-arch.h"
40 #include "sysemu/memory_mapping.h"
41 
42 typedef struct QEMU_PACKED MakedumpfileHeader {
43     char signature[16];     /* = "makedumpfile" */
44     int64_t type;
45     int64_t version;
46 } MakedumpfileHeader;
47 
48 typedef struct QEMU_PACKED MakedumpfileDataHeader {
49     int64_t offset;
50     int64_t buf_size;
51 } MakedumpfileDataHeader;
52 
53 typedef struct QEMU_PACKED NewUtsname {
54     char sysname[65];
55     char nodename[65];
56     char release[65];
57     char version[65];
58     char machine[65];
59     char domainname[65];
60 } NewUtsname;
61 
62 typedef struct QEMU_PACKED DiskDumpHeader32 {
63     char signature[SIG_LEN];        /* = "KDUMP   " */
64     uint32_t header_version;        /* Dump header version */
65     NewUtsname utsname;             /* copy of system_utsname */
66     char timestamp[10];             /* Time stamp */
67     uint32_t status;                /* Above flags */
68     uint32_t block_size;            /* Size of a block in byte */
69     uint32_t sub_hdr_size;          /* Size of arch dependent header in block */
70     uint32_t bitmap_blocks;         /* Size of Memory bitmap in block */
71     uint32_t max_mapnr;             /* = max_mapnr ,
72                                        obsoleted in header_version 6 */
73     uint32_t total_ram_blocks;      /* Number of blocks should be written */
74     uint32_t device_blocks;         /* Number of total blocks in dump device */
75     uint32_t written_blocks;        /* Number of written blocks */
76     uint32_t current_cpu;           /* CPU# which handles dump */
77     uint32_t nr_cpus;               /* Number of CPUs */
78 } DiskDumpHeader32;
79 
80 typedef struct QEMU_PACKED DiskDumpHeader64 {
81     char signature[SIG_LEN];        /* = "KDUMP   " */
82     uint32_t header_version;        /* Dump header version */
83     NewUtsname utsname;             /* copy of system_utsname */
84     char timestamp[22];             /* Time stamp */
85     uint32_t status;                /* Above flags */
86     uint32_t block_size;            /* Size of a block in byte */
87     uint32_t sub_hdr_size;          /* Size of arch dependent header in block */
88     uint32_t bitmap_blocks;         /* Size of Memory bitmap in block */
89     uint32_t max_mapnr;             /* = max_mapnr,
90                                        obsoleted in header_version 6 */
91     uint32_t total_ram_blocks;      /* Number of blocks should be written */
92     uint32_t device_blocks;         /* Number of total blocks in dump device */
93     uint32_t written_blocks;        /* Number of written blocks */
94     uint32_t current_cpu;           /* CPU# which handles dump */
95     uint32_t nr_cpus;               /* Number of CPUs */
96 } DiskDumpHeader64;
97 
98 typedef struct QEMU_PACKED KdumpSubHeader32 {
99     uint32_t phys_base;
100     uint32_t dump_level;            /* header_version 1 and later */
101     uint32_t split;                 /* header_version 2 and later */
102     uint32_t start_pfn;             /* header_version 2 and later,
103                                        obsoleted in header_version 6 */
104     uint32_t end_pfn;               /* header_version 2 and later,
105                                        obsoleted in header_version 6 */
106     uint64_t offset_vmcoreinfo;     /* header_version 3 and later */
107     uint32_t size_vmcoreinfo;       /* header_version 3 and later */
108     uint64_t offset_note;           /* header_version 4 and later */
109     uint32_t note_size;             /* header_version 4 and later */
110     uint64_t offset_eraseinfo;      /* header_version 5 and later */
111     uint32_t size_eraseinfo;        /* header_version 5 and later */
112     uint64_t start_pfn_64;          /* header_version 6 and later */
113     uint64_t end_pfn_64;            /* header_version 6 and later */
114     uint64_t max_mapnr_64;          /* header_version 6 and later */
115 } KdumpSubHeader32;
116 
117 typedef struct QEMU_PACKED KdumpSubHeader64 {
118     uint64_t phys_base;
119     uint32_t dump_level;            /* header_version 1 and later */
120     uint32_t split;                 /* header_version 2 and later */
121     uint64_t start_pfn;             /* header_version 2 and later,
122                                        obsoleted in header_version 6 */
123     uint64_t end_pfn;               /* header_version 2 and later,
124                                        obsoleted in header_version 6 */
125     uint64_t offset_vmcoreinfo;     /* header_version 3 and later */
126     uint64_t size_vmcoreinfo;       /* header_version 3 and later */
127     uint64_t offset_note;           /* header_version 4 and later */
128     uint64_t note_size;             /* header_version 4 and later */
129     uint64_t offset_eraseinfo;      /* header_version 5 and later */
130     uint64_t size_eraseinfo;        /* header_version 5 and later */
131     uint64_t start_pfn_64;          /* header_version 6 and later */
132     uint64_t end_pfn_64;            /* header_version 6 and later */
133     uint64_t max_mapnr_64;          /* header_version 6 and later */
134 } KdumpSubHeader64;
135 
136 typedef struct DataCache {
137     int fd;             /* fd of the file where to write the cached data */
138     uint8_t *buf;       /* buffer for cached data */
139     size_t buf_size;    /* size of the buf */
140     size_t data_size;   /* size of cached data in buf */
141     off_t offset;       /* offset of the file */
142 } DataCache;
143 
144 typedef struct QEMU_PACKED PageDescriptor {
145     uint64_t offset;                /* the offset of the page data*/
146     uint32_t size;                  /* the size of this dump page */
147     uint32_t flags;                 /* flags */
148     uint64_t page_flags;            /* page flags */
149 } PageDescriptor;
150 
151 typedef struct DumpState {
152     GuestPhysBlockList guest_phys_blocks;
153     ArchDumpInfo dump_info;
154     MemoryMappingList list;
155     uint16_t phdr_num;
156     uint32_t sh_info;
157     bool have_section;
158     bool resume;
159     ssize_t note_size;
160     hwaddr memory_offset;
161     int fd;
162 
163     GuestPhysBlock *next_block;
164     ram_addr_t start;
165     bool has_filter;
166     int64_t begin;
167     int64_t length;
168 
169     uint8_t *note_buf;          /* buffer for notes */
170     size_t note_buf_offset;     /* the writing place in note_buf */
171     uint32_t nr_cpus;           /* number of guest's cpu */
172     uint64_t max_mapnr;         /* the biggest guest's phys-mem's number */
173     size_t len_dump_bitmap;     /* the size of the place used to store
174                                    dump_bitmap in vmcore */
175     off_t offset_dump_bitmap;   /* offset of dump_bitmap part in vmcore */
176     off_t offset_page;          /* offset of page part in vmcore */
177     size_t num_dumpable;        /* number of page that can be dumped */
178     uint32_t flag_compress;     /* indicate the compression format */
179 } DumpState;
180 
181 uint16_t cpu_to_dump16(DumpState *s, uint16_t val);
182 uint32_t cpu_to_dump32(DumpState *s, uint32_t val);
183 uint64_t cpu_to_dump64(DumpState *s, uint64_t val);
184 #endif
185