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)
37 #define CHUNK_INFO_SIZE 34 /* 2 16-byte char, each followed by blank */
47 } __attribute__((packed
));
49 static struct debug_info
*zcore_dbf
;
50 static int hsa_available
;
51 static struct dentry
*zcore_dir
;
52 static struct dentry
*zcore_memmap_file
;
53 static struct dentry
*zcore_reipl_file
;
54 static struct dentry
*zcore_hsa_file
;
55 static struct ipl_parameter_block
*ipl_block
;
57 static char hsa_buf
[PAGE_SIZE
] __aligned(PAGE_SIZE
);
60 * Copy memory from HSA to user memory (not reentrant):
62 * @dest: 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
66 int memcpy_hsa_user(void __user
*dest
, unsigned long src
, size_t count
)
68 unsigned long offset
, bytes
;
74 if (sclp_sdias_copy(hsa_buf
, src
/ PAGE_SIZE
+ 2, 1)) {
75 TRACE("sclp_sdias_copy() failed\n");
78 offset
= src
% PAGE_SIZE
;
79 bytes
= min(PAGE_SIZE
- offset
, count
);
80 if (copy_to_user(dest
, hsa_buf
+ offset
, bytes
))
90 * Copy memory from HSA to kernel memory (not reentrant):
92 * @dest: Kernel or user buffer where memory should be copied to
93 * @src: Start address within HSA where data should be copied
94 * @count: Size of buffer, which should be copied
96 int memcpy_hsa_kernel(void *dest
, unsigned long src
, size_t count
)
98 unsigned long offset
, bytes
;
104 if (sclp_sdias_copy(hsa_buf
, src
/ PAGE_SIZE
+ 2, 1)) {
105 TRACE("sclp_sdias_copy() failed\n");
108 offset
= src
% PAGE_SIZE
;
109 bytes
= min(PAGE_SIZE
- offset
, count
);
110 memcpy(dest
, hsa_buf
+ offset
, bytes
);
118 static int __init
init_cpu_info(void)
120 struct save_area
*sa
;
122 /* get info for boot cpu from lowcore, stored in the HSA */
123 sa
= save_area_boot_cpu();
126 if (memcpy_hsa_kernel(hsa_buf
, __LC_FPREGS_SAVE_AREA
, 512) < 0) {
127 TRACE("could not copy from HSA\n");
130 save_area_add_regs(sa
, hsa_buf
); /* vx registers are saved in smp.c */
137 static void release_hsa(void)
139 diag308(DIAG308_REL_HSA
, NULL
);
143 static ssize_t
zcore_memmap_read(struct file
*filp
, char __user
*buf
,
144 size_t count
, loff_t
*ppos
)
146 return simple_read_from_buffer(buf
, count
, ppos
, filp
->private_data
,
147 memblock
.memory
.cnt
* CHUNK_INFO_SIZE
);
150 static int zcore_memmap_open(struct inode
*inode
, struct file
*filp
)
152 struct memblock_region
*reg
;
156 buf
= kzalloc(memblock
.memory
.cnt
* CHUNK_INFO_SIZE
, GFP_KERNEL
);
160 for_each_memblock(memory
, reg
) {
161 sprintf(buf
+ (i
++ * CHUNK_INFO_SIZE
), "%016llx %016llx ",
162 (unsigned long long) reg
->base
,
163 (unsigned long long) reg
->size
);
165 filp
->private_data
= buf
;
166 return nonseekable_open(inode
, filp
);
169 static int zcore_memmap_release(struct inode
*inode
, struct file
*filp
)
171 kfree(filp
->private_data
);
175 static const struct file_operations zcore_memmap_fops
= {
176 .owner
= THIS_MODULE
,
177 .read
= zcore_memmap_read
,
178 .open
= zcore_memmap_open
,
179 .release
= zcore_memmap_release
,
183 static ssize_t
zcore_reipl_write(struct file
*filp
, const char __user
*buf
,
184 size_t count
, loff_t
*ppos
)
187 diag308(DIAG308_SET
, ipl_block
);
188 diag308(DIAG308_IPL
, NULL
);
193 static int zcore_reipl_open(struct inode
*inode
, struct file
*filp
)
195 return nonseekable_open(inode
, filp
);
198 static int zcore_reipl_release(struct inode
*inode
, struct file
*filp
)
203 static const struct file_operations zcore_reipl_fops
= {
204 .owner
= THIS_MODULE
,
205 .write
= zcore_reipl_write
,
206 .open
= zcore_reipl_open
,
207 .release
= zcore_reipl_release
,
211 static ssize_t
zcore_hsa_read(struct file
*filp
, char __user
*buf
,
212 size_t count
, loff_t
*ppos
)
217 snprintf(str
, sizeof(str
), "%lx\n", sclp
.hsa_size
);
219 snprintf(str
, sizeof(str
), "0\n");
220 return simple_read_from_buffer(buf
, count
, ppos
, str
, strlen(str
));
223 static ssize_t
zcore_hsa_write(struct file
*filp
, const char __user
*buf
,
224 size_t count
, loff_t
*ppos
)
230 if (copy_from_user(&value
, buf
, 1))
238 static const struct file_operations zcore_hsa_fops
= {
239 .owner
= THIS_MODULE
,
240 .write
= zcore_hsa_write
,
241 .read
= zcore_hsa_read
,
242 .open
= nonseekable_open
,
246 static int __init
check_sdias(void)
248 if (!sclp
.hsa_size
) {
249 TRACE("Could not determine HSA size\n");
256 * Provide IPL parameter information block from either HSA or memory
259 static int __init
zcore_reipl_init(void)
261 struct ipib_info ipib_info
;
264 rc
= memcpy_hsa_kernel(&ipib_info
, __LC_DUMP_REIPL
, sizeof(ipib_info
));
267 if (ipib_info
.ipib
== 0)
269 ipl_block
= (void *) __get_free_page(GFP_KERNEL
);
272 if (ipib_info
.ipib
< sclp
.hsa_size
)
273 rc
= memcpy_hsa_kernel(ipl_block
, ipib_info
.ipib
, PAGE_SIZE
);
275 rc
= memcpy_real(ipl_block
, (void *) ipib_info
.ipib
, PAGE_SIZE
);
276 if (rc
|| csum_partial(ipl_block
, ipl_block
->hdr
.len
, 0) !=
277 ipib_info
.checksum
) {
278 TRACE("Checksum does not match\n");
279 free_page((unsigned long) ipl_block
);
285 static int __init
zcore_init(void)
290 if (ipl_info
.type
!= IPL_TYPE_FCP_DUMP
)
295 zcore_dbf
= debug_register("zcore", 4, 1, 4 * sizeof(long));
296 debug_register_view(zcore_dbf
, &debug_sprintf_view
);
297 debug_set_level(zcore_dbf
, 6);
299 TRACE("devno: %x\n", ipl_info
.data
.fcp
.dev_id
.devno
);
300 TRACE("wwpn: %llx\n", (unsigned long long) ipl_info
.data
.fcp
.wwpn
);
301 TRACE("lun: %llx\n", (unsigned long long) ipl_info
.data
.fcp
.lun
);
303 rc
= sclp_sdias_init();
312 rc
= memcpy_hsa_kernel(&arch
, __LC_AR_MODE_ID
, 1);
316 if (arch
== ARCH_S390
) {
317 pr_alert("The 64-bit dump tool cannot be used for a "
323 pr_alert("DETECTED 'S390X (64 bit) OS'\n");
324 rc
= init_cpu_info();
328 rc
= zcore_reipl_init();
332 zcore_dir
= debugfs_create_dir("zcore" , NULL
);
337 zcore_memmap_file
= debugfs_create_file("memmap", S_IRUSR
, zcore_dir
,
338 NULL
, &zcore_memmap_fops
);
339 if (!zcore_memmap_file
) {
343 zcore_reipl_file
= debugfs_create_file("reipl", S_IRUSR
, zcore_dir
,
344 NULL
, &zcore_reipl_fops
);
345 if (!zcore_reipl_file
) {
347 goto fail_memmap_file
;
349 zcore_hsa_file
= debugfs_create_file("hsa", S_IRUSR
|S_IWUSR
, zcore_dir
,
350 NULL
, &zcore_hsa_fops
);
351 if (!zcore_hsa_file
) {
353 goto fail_reipl_file
;
358 debugfs_remove(zcore_reipl_file
);
360 debugfs_remove(zcore_memmap_file
);
362 debugfs_remove(zcore_dir
);
364 diag308(DIAG308_REL_HSA
, NULL
);
368 static void __exit
zcore_exit(void)
370 debug_unregister(zcore_dbf
);
372 free_page((unsigned long) ipl_block
);
373 debugfs_remove(zcore_hsa_file
);
374 debugfs_remove(zcore_reipl_file
);
375 debugfs_remove(zcore_memmap_file
);
376 debugfs_remove(zcore_dir
);
377 diag308(DIAG308_REL_HSA
, NULL
);
380 MODULE_AUTHOR("Copyright IBM Corp. 2003,2008");
381 MODULE_DESCRIPTION("zcore module for zfcpdump support");
382 MODULE_LICENSE("GPL");
384 subsys_initcall(zcore_init
);
385 module_exit(zcore_exit
);