xref: /openbmc/qemu/include/sysemu/dump.h (revision d12f57ec)
19c17d615SPaolo Bonzini /*
29c17d615SPaolo Bonzini  * QEMU dump
39c17d615SPaolo Bonzini  *
49c17d615SPaolo Bonzini  * Copyright Fujitsu, Corp. 2011, 2012
59c17d615SPaolo Bonzini  *
69c17d615SPaolo Bonzini  * Authors:
79c17d615SPaolo Bonzini  *     Wen Congyang <wency@cn.fujitsu.com>
89c17d615SPaolo Bonzini  *
99c17d615SPaolo Bonzini  * This work is licensed under the terms of the GNU GPL, version 2 or later.
109c17d615SPaolo Bonzini  * See the COPYING file in the top-level directory.
119c17d615SPaolo Bonzini  *
129c17d615SPaolo Bonzini  */
139c17d615SPaolo Bonzini 
149c17d615SPaolo Bonzini #ifndef DUMP_H
159c17d615SPaolo Bonzini #define DUMP_H
169c17d615SPaolo Bonzini 
17fda05387Sqiaonuohan #define MAKEDUMPFILE_SIGNATURE      "makedumpfile"
18fda05387Sqiaonuohan #define MAX_SIZE_MDF_HEADER         (4096) /* max size of makedumpfile_header */
19fda05387Sqiaonuohan #define TYPE_FLAT_HEADER            (1)    /* type of flattened format */
20fda05387Sqiaonuohan #define VERSION_FLAT_HEADER         (1)    /* version of flattened format */
21fda05387Sqiaonuohan #define END_FLAG_FLAT_HEADER        (-1)
22fda05387Sqiaonuohan 
237aad248dSqiaonuohan #define ARCH_PFN_OFFSET             (0)
247aad248dSqiaonuohan 
257aad248dSqiaonuohan #define paddr_to_pfn(X, page_shift) \
267aad248dSqiaonuohan     (((unsigned long long)(X) >> (page_shift)) - ARCH_PFN_OFFSET)
277aad248dSqiaonuohan #define pfn_to_paddr(X, page_shift) \
287aad248dSqiaonuohan     (((unsigned long long)(X) + ARCH_PFN_OFFSET) << (page_shift))
297aad248dSqiaonuohan 
30298f1168Sqiaonuohan /*
31298f1168Sqiaonuohan  * flag for compressed format
32298f1168Sqiaonuohan  */
33298f1168Sqiaonuohan #define DUMP_DH_COMPRESSED_ZLIB     (0x1)
34298f1168Sqiaonuohan #define DUMP_DH_COMPRESSED_LZO      (0x2)
35298f1168Sqiaonuohan #define DUMP_DH_COMPRESSED_SNAPPY   (0x4)
36298f1168Sqiaonuohan 
37298f1168Sqiaonuohan #define KDUMP_SIGNATURE             "KDUMP   "
38298f1168Sqiaonuohan #define SIG_LEN                     (sizeof(KDUMP_SIGNATURE) - 1)
39298f1168Sqiaonuohan #define PHYS_BASE                   (0)
40298f1168Sqiaonuohan #define DUMP_LEVEL                  (1)
41298f1168Sqiaonuohan #define DISKDUMP_HEADER_BLOCKS      (1)
42d0686c72Sqiaonuohan #define BUFSIZE_BITMAP              (TARGET_PAGE_SIZE)
43d0686c72Sqiaonuohan #define PFN_BUFBITMAP               (CHAR_BIT * BUFSIZE_BITMAP)
4464cfba6aSqiaonuohan #define BUFSIZE_DATA_CACHE          (TARGET_PAGE_SIZE * 4)
45298f1168Sqiaonuohan 
469c17d615SPaolo Bonzini typedef struct ArchDumpInfo {
479c17d615SPaolo Bonzini     int d_machine;  /* Architecture */
489c17d615SPaolo Bonzini     int d_endian;   /* ELFDATA2LSB or ELFDATA2MSB */
499c17d615SPaolo Bonzini     int d_class;    /* ELFCLASS32 or ELFCLASS64 */
509c17d615SPaolo Bonzini } ArchDumpInfo;
519c17d615SPaolo Bonzini 
52fda05387Sqiaonuohan typedef struct QEMU_PACKED MakedumpfileHeader {
53fda05387Sqiaonuohan     char signature[16];     /* = "makedumpfile" */
54fda05387Sqiaonuohan     int64_t type;
55fda05387Sqiaonuohan     int64_t version;
56fda05387Sqiaonuohan } MakedumpfileHeader;
57fda05387Sqiaonuohan 
58fda05387Sqiaonuohan typedef struct QEMU_PACKED MakedumpfileDataHeader {
59fda05387Sqiaonuohan     int64_t offset;
60fda05387Sqiaonuohan     int64_t buf_size;
61fda05387Sqiaonuohan } MakedumpfileDataHeader;
62fda05387Sqiaonuohan 
63298f1168Sqiaonuohan typedef struct QEMU_PACKED NewUtsname {
64298f1168Sqiaonuohan     char sysname[65];
65298f1168Sqiaonuohan     char nodename[65];
66298f1168Sqiaonuohan     char release[65];
67298f1168Sqiaonuohan     char version[65];
68298f1168Sqiaonuohan     char machine[65];
69298f1168Sqiaonuohan     char domainname[65];
70298f1168Sqiaonuohan } NewUtsname;
71298f1168Sqiaonuohan 
72298f1168Sqiaonuohan typedef struct QEMU_PACKED DiskDumpHeader32 {
73298f1168Sqiaonuohan     char signature[SIG_LEN];        /* = "KDUMP   " */
74298f1168Sqiaonuohan     uint32_t header_version;        /* Dump header version */
75298f1168Sqiaonuohan     NewUtsname utsname;             /* copy of system_utsname */
76298f1168Sqiaonuohan     char timestamp[10];             /* Time stamp */
77298f1168Sqiaonuohan     uint32_t status;                /* Above flags */
78298f1168Sqiaonuohan     uint32_t block_size;            /* Size of a block in byte */
79298f1168Sqiaonuohan     uint32_t sub_hdr_size;          /* Size of arch dependent header in block */
80298f1168Sqiaonuohan     uint32_t bitmap_blocks;         /* Size of Memory bitmap in block */
81298f1168Sqiaonuohan     uint32_t max_mapnr;             /* = max_mapnr ,
82298f1168Sqiaonuohan                                        obsoleted in header_version 6 */
83298f1168Sqiaonuohan     uint32_t total_ram_blocks;      /* Number of blocks should be written */
84298f1168Sqiaonuohan     uint32_t device_blocks;         /* Number of total blocks in dump device */
85298f1168Sqiaonuohan     uint32_t written_blocks;        /* Number of written blocks */
86298f1168Sqiaonuohan     uint32_t current_cpu;           /* CPU# which handles dump */
87298f1168Sqiaonuohan     uint32_t nr_cpus;               /* Number of CPUs */
88298f1168Sqiaonuohan } DiskDumpHeader32;
89298f1168Sqiaonuohan 
90298f1168Sqiaonuohan typedef struct QEMU_PACKED DiskDumpHeader64 {
91298f1168Sqiaonuohan     char signature[SIG_LEN];        /* = "KDUMP   " */
92298f1168Sqiaonuohan     uint32_t header_version;        /* Dump header version */
93298f1168Sqiaonuohan     NewUtsname utsname;             /* copy of system_utsname */
94298f1168Sqiaonuohan     char timestamp[22];             /* Time stamp */
95298f1168Sqiaonuohan     uint32_t status;                /* Above flags */
96298f1168Sqiaonuohan     uint32_t block_size;            /* Size of a block in byte */
97298f1168Sqiaonuohan     uint32_t sub_hdr_size;          /* Size of arch dependent header in block */
98298f1168Sqiaonuohan     uint32_t bitmap_blocks;         /* Size of Memory bitmap in block */
99298f1168Sqiaonuohan     uint32_t max_mapnr;             /* = max_mapnr,
100298f1168Sqiaonuohan                                        obsoleted in header_version 6 */
101298f1168Sqiaonuohan     uint32_t total_ram_blocks;      /* Number of blocks should be written */
102298f1168Sqiaonuohan     uint32_t device_blocks;         /* Number of total blocks in dump device */
103298f1168Sqiaonuohan     uint32_t written_blocks;        /* Number of written blocks */
104298f1168Sqiaonuohan     uint32_t current_cpu;           /* CPU# which handles dump */
105298f1168Sqiaonuohan     uint32_t nr_cpus;               /* Number of CPUs */
106298f1168Sqiaonuohan } DiskDumpHeader64;
107298f1168Sqiaonuohan 
108298f1168Sqiaonuohan typedef struct QEMU_PACKED KdumpSubHeader32 {
109298f1168Sqiaonuohan     uint32_t phys_base;
110298f1168Sqiaonuohan     uint32_t dump_level;            /* header_version 1 and later */
111298f1168Sqiaonuohan     uint32_t split;                 /* header_version 2 and later */
112298f1168Sqiaonuohan     uint32_t start_pfn;             /* header_version 2 and later,
113298f1168Sqiaonuohan                                        obsoleted in header_version 6 */
114298f1168Sqiaonuohan     uint32_t end_pfn;               /* header_version 2 and later,
115298f1168Sqiaonuohan                                        obsoleted in header_version 6 */
116298f1168Sqiaonuohan     uint64_t offset_vmcoreinfo;     /* header_version 3 and later */
117298f1168Sqiaonuohan     uint32_t size_vmcoreinfo;       /* header_version 3 and later */
118298f1168Sqiaonuohan     uint64_t offset_note;           /* header_version 4 and later */
119298f1168Sqiaonuohan     uint32_t note_size;             /* header_version 4 and later */
120298f1168Sqiaonuohan     uint64_t offset_eraseinfo;      /* header_version 5 and later */
121298f1168Sqiaonuohan     uint32_t size_eraseinfo;        /* header_version 5 and later */
122298f1168Sqiaonuohan     uint64_t start_pfn_64;          /* header_version 6 and later */
123298f1168Sqiaonuohan     uint64_t end_pfn_64;            /* header_version 6 and later */
124298f1168Sqiaonuohan     uint64_t max_mapnr_64;          /* header_version 6 and later */
125298f1168Sqiaonuohan } KdumpSubHeader32;
126298f1168Sqiaonuohan 
127298f1168Sqiaonuohan typedef struct QEMU_PACKED KdumpSubHeader64 {
128298f1168Sqiaonuohan     uint64_t phys_base;
129298f1168Sqiaonuohan     uint32_t dump_level;            /* header_version 1 and later */
130298f1168Sqiaonuohan     uint32_t split;                 /* header_version 2 and later */
131298f1168Sqiaonuohan     uint64_t start_pfn;             /* header_version 2 and later,
132298f1168Sqiaonuohan                                        obsoleted in header_version 6 */
133298f1168Sqiaonuohan     uint64_t end_pfn;               /* header_version 2 and later,
134298f1168Sqiaonuohan                                        obsoleted in header_version 6 */
135298f1168Sqiaonuohan     uint64_t offset_vmcoreinfo;     /* header_version 3 and later */
136298f1168Sqiaonuohan     uint64_t size_vmcoreinfo;       /* header_version 3 and later */
137298f1168Sqiaonuohan     uint64_t offset_note;           /* header_version 4 and later */
138298f1168Sqiaonuohan     uint64_t note_size;             /* header_version 4 and later */
139298f1168Sqiaonuohan     uint64_t offset_eraseinfo;      /* header_version 5 and later */
140298f1168Sqiaonuohan     uint64_t size_eraseinfo;        /* header_version 5 and later */
141298f1168Sqiaonuohan     uint64_t start_pfn_64;          /* header_version 6 and later */
142298f1168Sqiaonuohan     uint64_t end_pfn_64;            /* header_version 6 and later */
143298f1168Sqiaonuohan     uint64_t max_mapnr_64;          /* header_version 6 and later */
144298f1168Sqiaonuohan } KdumpSubHeader64;
145298f1168Sqiaonuohan 
14664cfba6aSqiaonuohan typedef struct DataCache {
14764cfba6aSqiaonuohan     int fd;             /* fd of the file where to write the cached data */
14864cfba6aSqiaonuohan     uint8_t *buf;       /* buffer for cached data */
14964cfba6aSqiaonuohan     size_t buf_size;    /* size of the buf */
15064cfba6aSqiaonuohan     size_t data_size;   /* size of cached data in buf */
15164cfba6aSqiaonuohan     off_t offset;       /* offset of the file */
15264cfba6aSqiaonuohan } DataCache;
15364cfba6aSqiaonuohan 
154*d12f57ecSqiaonuohan typedef struct QEMU_PACKED PageDescriptor {
155*d12f57ecSqiaonuohan     uint64_t offset;                /* the offset of the page data*/
156*d12f57ecSqiaonuohan     uint32_t size;                  /* the size of this dump page */
157*d12f57ecSqiaonuohan     uint32_t flags;                 /* flags */
158*d12f57ecSqiaonuohan     uint64_t page_flags;            /* page flags */
159*d12f57ecSqiaonuohan } PageDescriptor;
160*d12f57ecSqiaonuohan 
16156c4bfb3SLaszlo Ersek struct GuestPhysBlockList; /* memory_mapping.h */
16256c4bfb3SLaszlo Ersek int cpu_get_dump_info(ArchDumpInfo *info,
16356c4bfb3SLaszlo Ersek                       const struct GuestPhysBlockList *guest_phys_blocks);
1649c17d615SPaolo Bonzini ssize_t cpu_get_note_size(int class, int machine, int nr_cpus);
1659c17d615SPaolo Bonzini 
1669c17d615SPaolo Bonzini #endif
167