xref: /openbmc/qemu/include/sysemu/dump.h (revision 01c22f2c)
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 #define ARCH_PFN_OFFSET             (0)
24 
25 #define paddr_to_pfn(X, page_shift) \
26     (((unsigned long long)(X) >> (page_shift)) - ARCH_PFN_OFFSET)
27 #define pfn_to_paddr(X, page_shift) \
28     (((unsigned long long)(X) + ARCH_PFN_OFFSET) << (page_shift))
29 
30 /*
31  * flag for compressed format
32  */
33 #define DUMP_DH_COMPRESSED_ZLIB     (0x1)
34 #define DUMP_DH_COMPRESSED_LZO      (0x2)
35 #define DUMP_DH_COMPRESSED_SNAPPY   (0x4)
36 
37 #define KDUMP_SIGNATURE             "KDUMP   "
38 #define SIG_LEN                     (sizeof(KDUMP_SIGNATURE) - 1)
39 #define PHYS_BASE                   (0)
40 #define DUMP_LEVEL                  (1)
41 #define DISKDUMP_HEADER_BLOCKS      (1)
42 #define BUFSIZE_BITMAP              (TARGET_PAGE_SIZE)
43 #define PFN_BUFBITMAP               (CHAR_BIT * BUFSIZE_BITMAP)
44 #define BUFSIZE_DATA_CACHE          (TARGET_PAGE_SIZE * 4)
45 
46 typedef struct ArchDumpInfo {
47     int d_machine;  /* Architecture */
48     int d_endian;   /* ELFDATA2LSB or ELFDATA2MSB */
49     int d_class;    /* ELFCLASS32 or ELFCLASS64 */
50 } ArchDumpInfo;
51 
52 typedef struct QEMU_PACKED MakedumpfileHeader {
53     char signature[16];     /* = "makedumpfile" */
54     int64_t type;
55     int64_t version;
56 } MakedumpfileHeader;
57 
58 typedef struct QEMU_PACKED MakedumpfileDataHeader {
59     int64_t offset;
60     int64_t buf_size;
61 } MakedumpfileDataHeader;
62 
63 typedef struct QEMU_PACKED NewUtsname {
64     char sysname[65];
65     char nodename[65];
66     char release[65];
67     char version[65];
68     char machine[65];
69     char domainname[65];
70 } NewUtsname;
71 
72 typedef struct QEMU_PACKED DiskDumpHeader32 {
73     char signature[SIG_LEN];        /* = "KDUMP   " */
74     uint32_t header_version;        /* Dump header version */
75     NewUtsname utsname;             /* copy of system_utsname */
76     char timestamp[10];             /* Time stamp */
77     uint32_t status;                /* Above flags */
78     uint32_t block_size;            /* Size of a block in byte */
79     uint32_t sub_hdr_size;          /* Size of arch dependent header in block */
80     uint32_t bitmap_blocks;         /* Size of Memory bitmap in block */
81     uint32_t max_mapnr;             /* = max_mapnr ,
82                                        obsoleted in header_version 6 */
83     uint32_t total_ram_blocks;      /* Number of blocks should be written */
84     uint32_t device_blocks;         /* Number of total blocks in dump device */
85     uint32_t written_blocks;        /* Number of written blocks */
86     uint32_t current_cpu;           /* CPU# which handles dump */
87     uint32_t nr_cpus;               /* Number of CPUs */
88 } DiskDumpHeader32;
89 
90 typedef struct QEMU_PACKED DiskDumpHeader64 {
91     char signature[SIG_LEN];        /* = "KDUMP   " */
92     uint32_t header_version;        /* Dump header version */
93     NewUtsname utsname;             /* copy of system_utsname */
94     char timestamp[22];             /* Time stamp */
95     uint32_t status;                /* Above flags */
96     uint32_t block_size;            /* Size of a block in byte */
97     uint32_t sub_hdr_size;          /* Size of arch dependent header in block */
98     uint32_t bitmap_blocks;         /* Size of Memory bitmap in block */
99     uint32_t max_mapnr;             /* = max_mapnr,
100                                        obsoleted in header_version 6 */
101     uint32_t total_ram_blocks;      /* Number of blocks should be written */
102     uint32_t device_blocks;         /* Number of total blocks in dump device */
103     uint32_t written_blocks;        /* Number of written blocks */
104     uint32_t current_cpu;           /* CPU# which handles dump */
105     uint32_t nr_cpus;               /* Number of CPUs */
106 } DiskDumpHeader64;
107 
108 typedef struct QEMU_PACKED KdumpSubHeader32 {
109     uint32_t phys_base;
110     uint32_t dump_level;            /* header_version 1 and later */
111     uint32_t split;                 /* header_version 2 and later */
112     uint32_t start_pfn;             /* header_version 2 and later,
113                                        obsoleted in header_version 6 */
114     uint32_t end_pfn;               /* header_version 2 and later,
115                                        obsoleted in header_version 6 */
116     uint64_t offset_vmcoreinfo;     /* header_version 3 and later */
117     uint32_t size_vmcoreinfo;       /* header_version 3 and later */
118     uint64_t offset_note;           /* header_version 4 and later */
119     uint32_t note_size;             /* header_version 4 and later */
120     uint64_t offset_eraseinfo;      /* header_version 5 and later */
121     uint32_t size_eraseinfo;        /* header_version 5 and later */
122     uint64_t start_pfn_64;          /* header_version 6 and later */
123     uint64_t end_pfn_64;            /* header_version 6 and later */
124     uint64_t max_mapnr_64;          /* header_version 6 and later */
125 } KdumpSubHeader32;
126 
127 typedef struct QEMU_PACKED KdumpSubHeader64 {
128     uint64_t phys_base;
129     uint32_t dump_level;            /* header_version 1 and later */
130     uint32_t split;                 /* header_version 2 and later */
131     uint64_t start_pfn;             /* header_version 2 and later,
132                                        obsoleted in header_version 6 */
133     uint64_t end_pfn;               /* header_version 2 and later,
134                                        obsoleted in header_version 6 */
135     uint64_t offset_vmcoreinfo;     /* header_version 3 and later */
136     uint64_t size_vmcoreinfo;       /* header_version 3 and later */
137     uint64_t offset_note;           /* header_version 4 and later */
138     uint64_t note_size;             /* header_version 4 and later */
139     uint64_t offset_eraseinfo;      /* header_version 5 and later */
140     uint64_t size_eraseinfo;        /* header_version 5 and later */
141     uint64_t start_pfn_64;          /* header_version 6 and later */
142     uint64_t end_pfn_64;            /* header_version 6 and later */
143     uint64_t max_mapnr_64;          /* header_version 6 and later */
144 } KdumpSubHeader64;
145 
146 typedef struct DataCache {
147     int fd;             /* fd of the file where to write the cached data */
148     uint8_t *buf;       /* buffer for cached data */
149     size_t buf_size;    /* size of the buf */
150     size_t data_size;   /* size of cached data in buf */
151     off_t offset;       /* offset of the file */
152 } DataCache;
153 
154 typedef struct QEMU_PACKED PageDescriptor {
155     uint64_t offset;                /* the offset of the page data*/
156     uint32_t size;                  /* the size of this dump page */
157     uint32_t flags;                 /* flags */
158     uint64_t page_flags;            /* page flags */
159 } PageDescriptor;
160 
161 struct GuestPhysBlockList; /* memory_mapping.h */
162 int cpu_get_dump_info(ArchDumpInfo *info,
163                       const struct GuestPhysBlockList *guest_phys_blocks);
164 ssize_t cpu_get_note_size(int class, int machine, int nr_cpus);
165 
166 #endif
167