2 * zcore module to export memory content and register sets for creating system
3 * dumps on SCSI disks (zfcpdump). The "zcore/mem" debugfs file shows the same
4 * dump format as s390 standalone dumps.
6 * For more information please refer to Documentation/s390/zfcpdump.txt
8 * Copyright IBM Corp. 2003, 2008
9 * Author(s): Michael Holzheu
12 #define KMSG_COMPONENT "zdump"
13 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <linux/miscdevice.h>
18 #include <linux/debugfs.h>
19 #include <linux/module.h>
20 #include <linux/memblock.h>
22 #include <asm/asm-offsets.h>
25 #include <asm/setup.h>
26 #include <asm/uaccess.h>
27 #include <asm/debug.h>
28 #include <asm/processor.h>
29 #include <asm/irqflags.h>
30 #include <asm/checksum.h>
31 #include <asm/os_info.h>
32 #include <asm/switch_to.h>
35 #define TRACE(x...) debug_sprintf_event(zcore_dbf, 1, x)
39 #define CHUNK_INFO_SIZE 34 /* 2 16-byte char, each followed by blank */
49 } __attribute__((packed
));
51 static struct debug_info
*zcore_dbf
;
52 static int hsa_available
;
53 static struct dentry
*zcore_dir
;
54 static struct dentry
*zcore_memmap_file
;
55 static struct dentry
*zcore_reipl_file
;
56 static struct dentry
*zcore_hsa_file
;
57 static struct ipl_parameter_block
*ipl_block
;
60 * Copy memory from HSA to kernel or user memory (not reentrant):
62 * @dest: Kernel or user buffer where memory should be copied to
63 * @src: Start address within HSA where data should be copied
64 * @count: Size of buffer, which should be copied
65 * @mode: Either TO_KERNEL or TO_USER
67 static int memcpy_hsa(void *dest
, unsigned long src
, size_t count
, int mode
)
70 static char buf
[PAGE_SIZE
] __attribute__((__aligned__(PAGE_SIZE
)));
77 /* copy first block */
79 if ((src
% PAGE_SIZE
) != 0) {
80 blk_num
= src
/ PAGE_SIZE
+ 2;
81 if (sclp_sdias_copy(buf
, blk_num
, 1)) {
82 TRACE("sclp_sdias_copy() failed\n");
85 offs
= min((PAGE_SIZE
- (src
% PAGE_SIZE
)), count
);
86 if (mode
== TO_USER
) {
87 if (copy_to_user((__force __user
void*) dest
,
88 buf
+ (src
% PAGE_SIZE
), offs
))
91 memcpy(dest
, buf
+ (src
% PAGE_SIZE
), offs
);
97 for (; (offs
+ PAGE_SIZE
) <= count
; offs
+= PAGE_SIZE
) {
98 blk_num
= (src
+ offs
) / PAGE_SIZE
+ 2;
99 if (sclp_sdias_copy(buf
, blk_num
, 1)) {
100 TRACE("sclp_sdias_copy() failed\n");
103 if (mode
== TO_USER
) {
104 if (copy_to_user((__force __user
void*) dest
+ offs
,
108 memcpy(dest
+ offs
, buf
, PAGE_SIZE
);
113 /* copy last block */
114 blk_num
= (src
+ offs
) / PAGE_SIZE
+ 2;
115 if (sclp_sdias_copy(buf
, blk_num
, 1)) {
116 TRACE("sclp_sdias_copy() failed\n");
119 if (mode
== TO_USER
) {
120 if (copy_to_user((__force __user
void*) dest
+ offs
, buf
,
124 memcpy(dest
+ offs
, buf
, count
- offs
);
130 * Copy memory from HSA to user memory (not reentrant):
132 * @dest: Kernel or user buffer where memory should be copied to
133 * @src: Start address within HSA where data should be copied
134 * @count: Size of buffer, which should be copied
136 int memcpy_hsa_user(void __user
*dest
, unsigned long src
, size_t count
)
138 return memcpy_hsa((void __force
*) dest
, src
, count
, TO_USER
);
142 * Copy memory from HSA to kernel memory (not reentrant):
144 * @dest: Kernel or user buffer where memory should be copied to
145 * @src: Start address within HSA where data should be copied
146 * @count: Size of buffer, which should be copied
148 int memcpy_hsa_kernel(void *dest
, unsigned long src
, size_t count
)
150 return memcpy_hsa(dest
, src
, count
, TO_KERNEL
);
153 static int __init
init_cpu_info(void)
155 struct save_area_ext
*sa_ext
;
157 /* get info for boot cpu from lowcore, stored in the HSA */
159 sa_ext
= dump_save_areas
.areas
[0];
162 if (memcpy_hsa_kernel(&sa_ext
->sa
, SAVE_AREA_BASE
,
163 sizeof(struct save_area
)) < 0) {
164 TRACE("could not copy from HSA\n");
168 save_vx_regs_safe(sa_ext
->vx_regs
);
175 static void release_hsa(void)
177 diag308(DIAG308_REL_HSA
, NULL
);
181 static ssize_t
zcore_memmap_read(struct file
*filp
, char __user
*buf
,
182 size_t count
, loff_t
*ppos
)
184 return simple_read_from_buffer(buf
, count
, ppos
, filp
->private_data
,
185 memblock
.memory
.cnt
* CHUNK_INFO_SIZE
);
188 static int zcore_memmap_open(struct inode
*inode
, struct file
*filp
)
190 struct memblock_region
*reg
;
194 buf
= kzalloc(memblock
.memory
.cnt
* CHUNK_INFO_SIZE
, GFP_KERNEL
);
198 for_each_memblock(memory
, reg
) {
199 sprintf(buf
+ (i
++ * CHUNK_INFO_SIZE
), "%016llx %016llx ",
200 (unsigned long long) reg
->base
,
201 (unsigned long long) reg
->size
);
203 filp
->private_data
= buf
;
204 return nonseekable_open(inode
, filp
);
207 static int zcore_memmap_release(struct inode
*inode
, struct file
*filp
)
209 kfree(filp
->private_data
);
213 static const struct file_operations zcore_memmap_fops
= {
214 .owner
= THIS_MODULE
,
215 .read
= zcore_memmap_read
,
216 .open
= zcore_memmap_open
,
217 .release
= zcore_memmap_release
,
221 static ssize_t
zcore_reipl_write(struct file
*filp
, const char __user
*buf
,
222 size_t count
, loff_t
*ppos
)
225 diag308(DIAG308_SET
, ipl_block
);
226 diag308(DIAG308_IPL
, NULL
);
231 static int zcore_reipl_open(struct inode
*inode
, struct file
*filp
)
233 return nonseekable_open(inode
, filp
);
236 static int zcore_reipl_release(struct inode
*inode
, struct file
*filp
)
241 static const struct file_operations zcore_reipl_fops
= {
242 .owner
= THIS_MODULE
,
243 .write
= zcore_reipl_write
,
244 .open
= zcore_reipl_open
,
245 .release
= zcore_reipl_release
,
249 static ssize_t
zcore_hsa_read(struct file
*filp
, char __user
*buf
,
250 size_t count
, loff_t
*ppos
)
255 snprintf(str
, sizeof(str
), "%lx\n", sclp
.hsa_size
);
257 snprintf(str
, sizeof(str
), "0\n");
258 return simple_read_from_buffer(buf
, count
, ppos
, str
, strlen(str
));
261 static ssize_t
zcore_hsa_write(struct file
*filp
, const char __user
*buf
,
262 size_t count
, loff_t
*ppos
)
268 if (copy_from_user(&value
, buf
, 1))
276 static const struct file_operations zcore_hsa_fops
= {
277 .owner
= THIS_MODULE
,
278 .write
= zcore_hsa_write
,
279 .read
= zcore_hsa_read
,
280 .open
= nonseekable_open
,
284 static int __init
check_sdias(void)
286 if (!sclp
.hsa_size
) {
287 TRACE("Could not determine HSA size\n");
294 * Provide IPL parameter information block from either HSA or memory
297 static int __init
zcore_reipl_init(void)
299 struct ipib_info ipib_info
;
302 rc
= memcpy_hsa_kernel(&ipib_info
, __LC_DUMP_REIPL
, sizeof(ipib_info
));
305 if (ipib_info
.ipib
== 0)
307 ipl_block
= (void *) __get_free_page(GFP_KERNEL
);
310 if (ipib_info
.ipib
< sclp
.hsa_size
)
311 rc
= memcpy_hsa_kernel(ipl_block
, ipib_info
.ipib
, PAGE_SIZE
);
313 rc
= memcpy_real(ipl_block
, (void *) ipib_info
.ipib
, PAGE_SIZE
);
314 if (rc
|| csum_partial(ipl_block
, ipl_block
->hdr
.len
, 0) !=
315 ipib_info
.checksum
) {
316 TRACE("Checksum does not match\n");
317 free_page((unsigned long) ipl_block
);
323 static int __init
zcore_init(void)
328 if (ipl_info
.type
!= IPL_TYPE_FCP_DUMP
)
333 zcore_dbf
= debug_register("zcore", 4, 1, 4 * sizeof(long));
334 debug_register_view(zcore_dbf
, &debug_sprintf_view
);
335 debug_set_level(zcore_dbf
, 6);
337 TRACE("devno: %x\n", ipl_info
.data
.fcp
.dev_id
.devno
);
338 TRACE("wwpn: %llx\n", (unsigned long long) ipl_info
.data
.fcp
.wwpn
);
339 TRACE("lun: %llx\n", (unsigned long long) ipl_info
.data
.fcp
.lun
);
341 rc
= sclp_sdias_init();
350 rc
= memcpy_hsa_kernel(&arch
, __LC_AR_MODE_ID
, 1);
354 if (arch
== ARCH_S390
) {
355 pr_alert("The 64-bit dump tool cannot be used for a "
361 pr_alert("DETECTED 'S390X (64 bit) OS'\n");
362 rc
= init_cpu_info();
366 rc
= zcore_reipl_init();
370 zcore_dir
= debugfs_create_dir("zcore" , NULL
);
375 zcore_memmap_file
= debugfs_create_file("memmap", S_IRUSR
, zcore_dir
,
376 NULL
, &zcore_memmap_fops
);
377 if (!zcore_memmap_file
) {
381 zcore_reipl_file
= debugfs_create_file("reipl", S_IRUSR
, zcore_dir
,
382 NULL
, &zcore_reipl_fops
);
383 if (!zcore_reipl_file
) {
385 goto fail_memmap_file
;
387 zcore_hsa_file
= debugfs_create_file("hsa", S_IRUSR
|S_IWUSR
, zcore_dir
,
388 NULL
, &zcore_hsa_fops
);
389 if (!zcore_hsa_file
) {
391 goto fail_reipl_file
;
396 debugfs_remove(zcore_reipl_file
);
398 debugfs_remove(zcore_memmap_file
);
400 debugfs_remove(zcore_dir
);
402 diag308(DIAG308_REL_HSA
, NULL
);
406 static void __exit
zcore_exit(void)
408 debug_unregister(zcore_dbf
);
410 free_page((unsigned long) ipl_block
);
411 debugfs_remove(zcore_hsa_file
);
412 debugfs_remove(zcore_reipl_file
);
413 debugfs_remove(zcore_memmap_file
);
414 debugfs_remove(zcore_dir
);
415 diag308(DIAG308_REL_HSA
, NULL
);
418 MODULE_AUTHOR("Copyright IBM Corp. 2003,2008");
419 MODULE_DESCRIPTION("zcore module for zfcpdump support");
420 MODULE_LICENSE("GPL");
422 subsys_initcall(zcore_init
);
423 module_exit(zcore_exit
);