This commit was manufactured by cvs2svn to create branch
[linux-2.6.git] / include / linux / diskdump.h
1 #ifndef _LINUX_DISKDUMP_H
2 #define _LINUX_DISKDUMP_H
3
4 /*
5  * linux/include/linux/diskdump.h
6  *
7  * Copyright (c) 2004 FUJITSU LIMITED
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2, or (at your option)
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  */
24
25 #include <linux/list.h>
26 #include <linux/blkdev.h>
27 #include <linux/utsname.h>
28 #include <linux/device.h>
29
30 /* The minimum Dump I/O unit. Must be the same of PAGE_SIZE */
31 #define DUMP_BLOCK_SIZE         PAGE_SIZE
32 #define DUMP_BLOCK_SHIFT        PAGE_SHIFT
33
34 int diskdump_register_hook(void (*dump_func)(struct pt_regs *));
35 void diskdump_unregister_hook(void);
36
37 /*
38  * The handler of diskdump module
39  */
40 struct disk_dump_ops {
41         int (*add_dump)(struct device *, struct block_device *);
42         int (*remove_dump)(struct block_device *);
43         int (*find_dump)(struct block_device *);
44 };
45
46 int diskdump_register_ops(struct disk_dump_ops* op);
47 void diskdump_unregister_ops(void);
48
49
50 /*
51  * The handler that adapter driver provides for the common module of
52  * dump
53  */
54 struct disk_dump_partition;
55 struct disk_dump_device;
56
57 struct disk_dump_type {
58         void *(*probe)(struct device *);
59         int (*add_device)(struct disk_dump_device *);
60         void (*remove_device)(struct disk_dump_device *);
61         struct module *owner;
62         struct list_head list;
63 };
64
65 struct disk_dump_device_ops {
66         int (*sanity_check)(struct disk_dump_device *);
67         int (*quiesce)(struct disk_dump_device *);
68         int (*shutdown)(struct disk_dump_device *);
69         int (*rw_block)(struct disk_dump_partition *, int rw, unsigned long block_nr, void *buf, int len);
70 };
71
72 /* The data structure for a dump device */
73 struct disk_dump_device {
74         struct list_head list;
75         struct disk_dump_device_ops ops;
76         struct disk_dump_type *dump_type;
77         void *device;
78         unsigned int max_blocks;
79         struct list_head partitions;
80 };
81
82 /* The data structure for a dump partition */
83 struct disk_dump_partition {
84         struct list_head list;
85         struct disk_dump_device *device;
86         struct block_device *bdev;
87         unsigned long start_sect;
88         unsigned long nr_sects;
89 };
90
91 int register_disk_dump_type(struct disk_dump_type *);
92 int unregister_disk_dump_type(struct disk_dump_type *);
93
94
95 /*
96  * sysfs interface
97  */
98 ssize_t diskdump_sysfs_store(struct device *dev, const char *buf, size_t count);
99 ssize_t diskdump_sysfs_show(struct device *dev, char *buf);
100
101
102 void diskdump_update(void);
103 void diskdump_setup_timestamp(void);
104
105 /* mdelay() is trapped by WARN_ON if we are in the interrupt context. */
106 #define diskdump_mdelay(n) \
107 ({unsigned long __ms=(n); while (__ms--) udelay(1000);})
108
109
110 /*
111  * Architecture-independent dump header
112  */
113
114 /* The signature which is written in each block in the dump partition */
115 #define DISK_DUMP_SIGNATURE             "DISKDUMP"
116 #define DISK_DUMP_HEADER_VERSION        1
117
118 #define DUMP_PARTITION_SIGNATURE        "diskdump"
119
120 #define DUMP_HEADER_COMPLETED   0
121 #define DUMP_HEADER_INCOMPLETED 1
122
123 struct disk_dump_header {
124         char                    signature[8];   /* = "DISKDUMP" */
125         int                     header_version; /* Dump header version */
126         struct new_utsname      utsname;        /* copy of system_utsname */
127         struct timespec         timestamp;      /* Time stamp */
128         unsigned int            status;         /* Above flags */
129         int                     block_size;     /* Size of a block in byte */
130         int                     sub_hdr_size;   /* Size of arch dependent
131                                                    header in blocks */
132         unsigned int            bitmap_blocks;  /* Size of Memory bitmap in
133                                                    block */
134         unsigned int            max_mapnr;      /* = max_mapnr */
135         unsigned int            total_ram_blocks;/* Size of Memory in block */
136         unsigned int            device_blocks;  /* Number of total blocks in
137                                                  * the dump device */
138         unsigned int            written_blocks; /* Number of written blocks */
139         unsigned int            current_cpu;    /* CPU# which handles dump */
140         int                     nr_cpus;        /* Number of CPUs */
141         struct task_struct      *tasks[NR_CPUS];
142 };
143
144 /* Diskdump state */
145 extern enum disk_dump_states {
146         DISK_DUMP_INITIAL,
147         DISK_DUMP_RUNNING,
148         DISK_DUMP_SUCCESS,
149         DISK_DUMP_FAILURE,
150 }  disk_dump_state;
151
152 /*
153  * Calculate the check sum of the whole module
154  */
155 #define get_crc_module()                                                \
156 ({                                                                      \
157         struct module *module = &__this_module;                         \
158         crc32_le(0, (char *)(module->module_core),                      \
159           ((unsigned long)module - (unsigned long)(module->module_core))); \
160 })
161
162 /* Calculate the checksum of the whole module */
163 #define set_crc_modules()                                               \
164 ({                                                                      \
165         module_crc = 0;                                                 \
166         module_crc = get_crc_module();                                  \
167 })
168
169 /*
170  * Compare the checksum value that is stored in module_crc to the check
171  * sum of current whole module. Must be called with holding disk_dump_lock.
172  * Return TRUE if they are the same, else return FALSE
173  *
174  */
175 #define check_crc_module()                                              \
176 ({                                                                      \
177         uint32_t orig_crc, cur_crc;                                     \
178                                                                         \
179         orig_crc = module_crc; module_crc = 0;                          \
180         cur_crc = get_crc_module();                                     \
181         module_crc = orig_crc;                                          \
182         orig_crc == cur_crc;                                            \
183 })
184
185
186 #endif /* _LINUX_DISKDUMP_H */