00c690f44a8842ad81f9536a510a2a63a7f25bd1
[linux-2.6.git] / include / linux / dump.h
1 /*
2  * Kernel header file for Linux crash dumps.
3  *
4  * Created by: Matt Robinson (yakker@sgi.com)
5  * Copyright 1999 - 2002 Silicon Graphics, Inc. All rights reserved.
6  *
7  * vmdump.h to dump.h by: Matt D. Robinson (yakker@sourceforge.net)
8  * Copyright 2001 - 2002 Matt D. Robinson.  All rights reserved.
9  * Copyright (C) 2002 Free Software Foundation, Inc. All rights reserved.
10  *
11  * Most of this is the same old stuff from vmdump.h, except now we're
12  * actually a stand-alone driver plugged into the block layer interface,
13  * with the exception that we now allow for compression modes externally
14  * loaded (e.g., someone can come up with their own).
15  *
16  * This code is released under version 2 of the GNU GPL.
17  */
18
19 /* This header file includes all structure definitions for crash dumps. */
20 #ifndef _DUMP_H
21 #define _DUMP_H
22
23 #if defined(CONFIG_CRASH_DUMP) || defined (CONFIG_CRASH_DUMP_MODULE)
24
25 #include <linux/list.h>
26 #include <linux/notifier.h>
27 #include <linux/dumpdev.h>
28 #include <asm/ioctl.h>
29
30 /* 
31  * Predefine default DUMP_PAGE constants, asm header may override.
32  *
33  * On ia64 discontinuous memory systems it's possible for the memory
34  * banks to stop at 2**12 page alignments, the smallest possible page
35  * size. But the system page size, PAGE_SIZE, is in fact larger.
36  */
37 #define DUMP_PAGE_SHIFT         PAGE_SHIFT
38 #define DUMP_PAGE_MASK          PAGE_MASK
39 #define DUMP_PAGE_ALIGN(addr)   PAGE_ALIGN(addr)
40 #define DUMP_HEADER_OFFSET      PAGE_SIZE
41
42 #define OLDMINORBITS    8
43 #define OLDMINORMASK    ((1U << OLDMINORBITS) -1)
44
45 /* keep DUMP_PAGE_SIZE constant to 4K = 1<<12
46  * it may be different from PAGE_SIZE then.
47  */
48 #define DUMP_PAGE_SIZE          4096
49
50 /* 
51  * Predefined default memcpy() to use when copying memory to the dump buffer.
52  *
53  * On ia64 there is a heads up function that can be called to let the prom
54  * machine check monitor know that the current activity is risky and it should
55  * ignore the fault (nofault). In this case the ia64 header will redefine this
56  * macro to __dump_memcpy() and use it's arch specific version.
57  */
58 #define DUMP_memcpy             memcpy
59
60 /* necessary header files */
61 #include <asm/dump.h>                   /* for architecture-specific header */
62
63 /* 
64  * Size of the buffer that's used to hold:
65  *
66  *      1. the dump header (padded to fill the complete buffer)
67  *      2. the possibly compressed page headers and data
68  */
69 #define DUMP_BUFFER_SIZE        (64 * 1024)  /* size of dump buffer         */
70 #define DUMP_HEADER_SIZE        DUMP_BUFFER_SIZE
71
72 /* standard header definitions */
73 #define DUMP_MAGIC_NUMBER       0xa8190173618f23edULL  /* dump magic number */
74 #define DUMP_MAGIC_LIVE         0xa8190173618f23cdULL  /* live magic number */
75 #define DUMP_VERSION_NUMBER     0x8     /* dump version number              */
76 #define DUMP_PANIC_LEN          0x100   /* dump panic string length         */
77
78 /* dump levels - type specific stuff added later -- add as necessary */
79 #define DUMP_LEVEL_NONE         0x0     /* no dumping at all -- just bail   */
80 #define DUMP_LEVEL_HEADER       0x1     /* kernel dump header only          */
81 #define DUMP_LEVEL_KERN         0x2     /* dump header and kernel pages     */
82 #define DUMP_LEVEL_USED         0x4     /* dump header, kernel/user pages   */
83 #define DUMP_LEVEL_ALL_RAM      0x8     /* dump header, all RAM pages       */
84 #define DUMP_LEVEL_ALL          0x10    /* dump all memory RAM and firmware */
85
86
87 /* dump compression options -- add as necessary */
88 #define DUMP_COMPRESS_NONE      0x0     /* don't compress this dump         */
89 #define DUMP_COMPRESS_RLE       0x1     /* use RLE compression              */
90 #define DUMP_COMPRESS_GZIP      0x2     /* use GZIP compression             */
91
92 /* dump flags - any dump-type specific flags -- add as necessary */
93 #define DUMP_FLAGS_NONE         0x0     /* no flags are set for this dump   */
94 #define DUMP_FLAGS_SOFTBOOT     0x2     /* 2 stage soft-boot based dump     */
95 #define DUMP_FLAGS_NONDISRUPT   0X1     /* non-disruptive dumping           */
96
97 #define DUMP_FLAGS_TARGETMASK   0xf0000000 /* handle special case targets   */
98 #define DUMP_FLAGS_DISKDUMP     0x80000000 /* dump to local disk            */
99 #define DUMP_FLAGS_NETDUMP      0x40000000 /* dump over the network         */
100
101 /* dump header flags -- add as necessary */
102 #define DUMP_DH_FLAGS_NONE      0x0     /* no flags set (error condition!)  */
103 #define DUMP_DH_RAW             0x1     /* raw page (no compression)        */
104 #define DUMP_DH_COMPRESSED      0x2     /* page is compressed               */
105 #define DUMP_DH_END             0x4     /* end marker on a full dump        */
106 #define DUMP_DH_TRUNCATED       0x8     /* dump is incomplete               */
107 #define DUMP_DH_TEST_PATTERN    0x10    /* dump page is a test pattern      */
108 #define DUMP_DH_NOT_USED        0x20    /* 1st bit not used in flags        */
109
110 /* names for various dump parameters in /proc/kernel */
111 #define DUMP_ROOT_NAME          "sys/dump"
112 #define DUMP_DEVICE_NAME        "device"
113 #define DUMP_COMPRESS_NAME      "compress"
114 #define DUMP_LEVEL_NAME         "level"
115 #define DUMP_FLAGS_NAME         "flags"
116 #define DUMP_ADDR_NAME          "addr"
117
118 #define DUMP_SYSRQ_KEY          'd'     /* key to use for MAGIC_SYSRQ key   */
119
120 /* CTL_DUMP names: */
121 enum
122 {
123         CTL_DUMP_DEVICE=1,
124         CTL_DUMP_COMPRESS=3,
125         CTL_DUMP_LEVEL=3,
126         CTL_DUMP_FLAGS=4,
127         CTL_DUMP_ADDR=5,
128         CTL_DUMP_TEST=6,
129 };
130
131
132 /* page size for gzip compression -- buffered slightly beyond hardware PAGE_SIZE used by DUMP */
133 #define DUMP_DPC_PAGE_SIZE      (DUMP_PAGE_SIZE + 512)
134
135 /* dump ioctl() control options */
136 #define DIOSDUMPDEV     _IOW('p', 0xA0, unsigned int)  /* set the dump device              */
137 #define DIOGDUMPDEV     _IOR('p', 0xA1, unsigned int)  /* get the dump device              */
138 #define DIOSDUMPLEVEL   _IOW('p', 0xA2, unsigned int)  /* set the dump level               */
139 #define DIOGDUMPLEVEL   _IOR('p', 0xA3, unsigned int)  /* get the dump level               */
140 #define DIOSDUMPFLAGS   _IOW('p', 0xA4, unsigned int)  /* set the dump flag parameters     */
141 #define DIOGDUMPFLAGS   _IOR('p', 0xA5, unsigned int)  /* get the dump flag parameters     */
142 #define DIOSDUMPCOMPRESS _IOW('p', 0xA6, unsigned int) /* set the dump compress level      */
143 #define DIOGDUMPCOMPRESS _IOR('p', 0xA7, unsigned int) /* get the dump compress level      */
144
145 /* these ioctls are used only by netdump module */
146 #define DIOSTARGETIP    _IOW('p', 0xA8, unsigned int)  /* set the target m/c's ip           */
147 #define DIOGTARGETIP    _IOR('p', 0xA9, unsigned int)  /* get the target m/c's ip           */
148 #define DIOSTARGETPORT  _IOW('p', 0xAA, unsigned int) /* set the target m/c's port          */
149 #define DIOGTARGETPORT  _IOR('p', 0xAB, unsigned int) /* get the target m/c's port          */
150 #define DIOSSOURCEPORT  _IOW('p', 0xAC, unsigned int) /* set the source m/c's port          */
151 #define DIOGSOURCEPORT  _IOR('p', 0xAD, unsigned int) /* get the source m/c's port          */
152 #define DIOSETHADDR     _IOW('p', 0xAE, unsigned int) /* set ethernet address      */
153 #define DIOGETHADDR     _IOR('p', 0xAF, unsigned int) /* get ethernet address       */
154 #define DIOGDUMPOKAY    _IOR('p', 0xB0, unsigned int) /* check if dump is configured      */
155 #define DIOSDUMPTAKE    _IOW('p', 0xB1, unsigned int) /* Take a manual dump               */
156
157 /*
158  * Structure: __dump_header
159  *  Function: This is the header dumped at the top of every valid crash
160  *            dump.  
161  */
162 struct __dump_header {
163         /* the dump magic number -- unique to verify dump is valid */
164         u64     dh_magic_number;
165
166         /* the version number of this dump */
167         u32     dh_version;
168
169         /* the size of this header (in case we can't read it) */
170         u32     dh_header_size;
171
172         /* the level of this dump (just a header?) */
173         u32     dh_dump_level;
174
175         /* 
176          * We assume dump_page_size to be 4K in every case.
177          * Store here the configurable system page size (4K, 8K, 16K, etc.) 
178          */
179         u32     dh_page_size;
180
181         /* the size of all physical memory */
182         u64     dh_memory_size;
183
184         /* the start of physical memory */
185         u64     dh_memory_start;
186
187         /* the end of physical memory */
188         u64     dh_memory_end;
189
190         /* the number of hardware/physical pages in this dump specifically */
191         u32     dh_num_dump_pages;
192
193         /* the panic string, if available */
194         char    dh_panic_string[DUMP_PANIC_LEN];
195
196         /* timeval depends on architecture, two long values */
197         struct {
198                 u64 tv_sec;
199                 u64 tv_usec;
200         } dh_time; /* the time of the system crash */
201
202         /* the NEW utsname (uname) information -- in character form */
203         /* we do this so we don't have to include utsname.h         */
204         /* plus it helps us be more architecture independent        */
205         /* now maybe one day soon they'll make the [65] a #define!  */
206         char    dh_utsname_sysname[65];
207         char    dh_utsname_nodename[65];
208         char    dh_utsname_release[65];
209         char    dh_utsname_version[65];
210         char    dh_utsname_machine[65];
211         char    dh_utsname_domainname[65];
212
213         /* the address of current task (OLD = void *, NEW = u64) */
214         u64     dh_current_task;
215
216         /* what type of compression we're using in this dump (if any) */
217         u32     dh_dump_compress;
218
219         /* any additional flags */
220         u32     dh_dump_flags;
221
222         /* any additional flags */
223         u32     dh_dump_device;
224 } __attribute__((packed));
225
226 /*
227  * Structure: __dump_page
228  *  Function: To act as the header associated to each physical page of
229  *            memory saved in the system crash dump.  This allows for
230  *            easy reassembly of each crash dump page.  The address bits
231  *            are split to make things easier for 64-bit/32-bit system
232  *            conversions.
233  *
234  * dp_byte_offset and dp_page_index are landmarks that are helpful when
235  * looking at a hex dump of /dev/vmdump,
236  */
237 struct __dump_page {
238         /* the address of this dump page */
239         u64     dp_address;
240
241         /* the size of this dump page */
242         u32     dp_size;
243
244         /* flags (currently DUMP_COMPRESSED, DUMP_RAW or DUMP_END) */
245         u32     dp_flags;
246 } __attribute__((packed));
247
248 /*
249  * Structure: __lkcdinfo
250  * Function:  This structure contains information needed for the lkcdutils
251  *            package (particularly lcrash) to determine what information is
252  *            associated to this kernel, specifically.
253  */
254 struct __lkcdinfo {
255         int     arch;
256         int     ptrsz;
257         int     byte_order;
258         int     linux_release;
259         int     page_shift;
260         int     page_size;
261         u64     page_mask;
262         u64     page_offset;
263         int     stack_offset;
264 };
265
266 #ifdef __KERNEL__
267
268 /*
269  * Structure: __dump_compress
270  *  Function: This is what an individual compression mechanism can use
271  *            to plug in their own compression techniques.  It's always
272  *            best to build these as individual modules so that people
273  *            can put in whatever they want.
274  */
275 struct __dump_compress {
276         /* the list_head structure for list storage */
277         struct list_head list;
278
279         /* the type of compression to use (DUMP_COMPRESS_XXX) */
280         int compress_type;
281         const char *compress_name;
282
283         /* the compression function to call */
284         u16 (*compress_func)(const u8 *, u16, u8 *, u16);
285 };
286
287 /* functions for dump compression registration */
288 extern void dump_register_compression(struct __dump_compress *);
289 extern void dump_unregister_compression(int);
290
291 /*
292  * Structure dump_mbank[]:
293  *
294  * For CONFIG_DISCONTIGMEM systems this array specifies the
295  * memory banks/chunks that need to be dumped after a panic.
296  *
297  * For classic systems it specifies a single set of pages from
298  * 0 to max_mapnr.
299  */
300 struct __dump_mbank {
301         u64     start;
302         u64     end;
303         int     type;
304         int     pad1;
305         long    pad2;
306 };
307
308 #define DUMP_MBANK_TYPE_CONVENTIONAL_MEMORY             1
309 #define DUMP_MBANK_TYPE_OTHER                           2
310
311 #define MAXCHUNKS 256
312 extern int dump_mbanks;
313 extern struct __dump_mbank dump_mbank[MAXCHUNKS];
314
315 /* notification event codes */
316 #define DUMP_BEGIN              0x0001  /* dump beginning */
317 #define DUMP_END                0x0002  /* dump ending */
318
319 /* Scheduler soft spin control.
320  *
321  * 0 - no dump in progress
322  * 1 - cpu0 is dumping, ...
323  */
324 extern unsigned long dump_oncpu;
325 extern void dump_execute(const char *, const struct pt_regs *);
326
327 /*
328  *      Notifier list for kernel code which wants to be called
329  *      at kernel dump. 
330  */
331 extern struct notifier_block *dump_notifier_list;
332 static inline int register_dump_notifier(struct notifier_block *nb)
333 {
334         return notifier_chain_register(&dump_notifier_list, nb);
335 }
336 static inline int unregister_dump_notifier(struct notifier_block * nb)
337 {
338         return notifier_chain_unregister(&dump_notifier_list, nb);
339 }
340
341 extern void (*dump_function_ptr)(const char *, const struct pt_regs *);
342 static inline void dump(char * str, struct pt_regs * regs)
343 {
344         if (dump_function_ptr)
345                 dump_function_ptr(str, regs);
346 }
347
348 /*
349  * Common Arch Specific Functions should be declared here.
350  * This allows the C compiler to detect discrepancies.
351  */
352 extern void     __dump_open(void);
353 extern void     __dump_cleanup(void);
354 extern void     __dump_init(u64);
355 extern void     __dump_save_regs(struct pt_regs *, const struct pt_regs *);
356 extern int      __dump_configure_header(const struct pt_regs *);
357 extern int      __dump_irq_enable(void);
358 extern void     __dump_irq_restore(void);
359 extern int      __dump_page_valid(unsigned long index);
360 #ifdef CONFIG_SMP
361 extern void     __dump_save_other_cpus(void);
362 #else
363 #define         __dump_save_other_cpus()
364 #endif
365
366 extern int manual_handle_crashdump(void);
367
368 /* to track all used (compound + zero order) pages */
369 #define PageInuse(p)   (PageCompound(p) || page_count(p))
370
371 #endif /* __KERNEL__ */
372
373 #else   /* !CONFIG_CRASH_DUMP */
374
375 /* If not configured then make code disappear! */
376 #define register_dump_watchdog(x)       do { } while(0)
377 #define unregister_dump_watchdog(x)     do { } while(0)
378 #define register_dump_notifier(x)       do { } while(0)
379 #define unregister_dump_notifier(x)     do { } while(0)
380 #define dump_in_progress()              0
381 #define dump(x, y)                      do { } while(0)
382
383 #endif  /* !CONFIG_CRASH_DUMP */
384
385 #endif /* _DUMP_H */