diff options
author | Michael Holzheu <holzheu@linux.vnet.ibm.com> | 2010-05-17 04:00:20 -0400 |
---|---|---|
committer | Martin Schwidefsky <sky@mschwide.boeblingen.de.ibm.com> | 2010-05-17 04:00:17 -0400 |
commit | 57b28f66316d287b9dbf7b28358ca90257230769 (patch) | |
tree | 9486fff9e7c746721dbcbbbeb34ddd1307460e89 /arch/s390/hypfs/hypfs_diag.c | |
parent | cc961d400e06e78c7aa39aeab1f001eb8f76ef90 (diff) |
[S390] s390_hypfs: Add new attributes
In order to access the data of the hypfs diagnose calls from user
space also in binary form, this patch adds two new attributes in
debugfs:
* z/VM: s390_hypfs/d2fc_bin
* LPAR: s390_hypfs/d204_bin
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'arch/s390/hypfs/hypfs_diag.c')
-rw-r--r-- | arch/s390/hypfs/hypfs_diag.c | 123 |
1 files changed, 116 insertions, 7 deletions
diff --git a/arch/s390/hypfs/hypfs_diag.c b/arch/s390/hypfs/hypfs_diag.c index 5b1acdba6495..1211bb1d2f24 100644 --- a/arch/s390/hypfs/hypfs_diag.c +++ b/arch/s390/hypfs/hypfs_diag.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
16 | #include <linux/string.h> | 16 | #include <linux/string.h> |
17 | #include <linux/vmalloc.h> | 17 | #include <linux/vmalloc.h> |
18 | #include <linux/mm.h> | ||
18 | #include <asm/ebcdic.h> | 19 | #include <asm/ebcdic.h> |
19 | #include "hypfs.h" | 20 | #include "hypfs.h" |
20 | 21 | ||
@@ -22,6 +23,8 @@ | |||
22 | #define CPU_NAME_LEN 16 /* type name len of cpus in diag224 name table */ | 23 | #define CPU_NAME_LEN 16 /* type name len of cpus in diag224 name table */ |
23 | #define TMP_SIZE 64 /* size of temporary buffers */ | 24 | #define TMP_SIZE 64 /* size of temporary buffers */ |
24 | 25 | ||
26 | #define DBFS_D204_HDR_VERSION 0 | ||
27 | |||
25 | /* diag 204 subcodes */ | 28 | /* diag 204 subcodes */ |
26 | enum diag204_sc { | 29 | enum diag204_sc { |
27 | SUBC_STIB4 = 4, | 30 | SUBC_STIB4 = 4, |
@@ -47,6 +50,8 @@ static void *diag204_buf; /* 4K aligned buffer for diag204 data */ | |||
47 | static void *diag204_buf_vmalloc; /* vmalloc pointer for diag204 data */ | 50 | static void *diag204_buf_vmalloc; /* vmalloc pointer for diag204 data */ |
48 | static int diag204_buf_pages; /* number of pages for diag204 data */ | 51 | static int diag204_buf_pages; /* number of pages for diag204 data */ |
49 | 52 | ||
53 | static struct dentry *dbfs_d204_file; | ||
54 | |||
50 | /* | 55 | /* |
51 | * DIAG 204 data structures and member access functions. | 56 | * DIAG 204 data structures and member access functions. |
52 | * | 57 | * |
@@ -364,18 +369,21 @@ static void diag204_free_buffer(void) | |||
364 | } else { | 369 | } else { |
365 | free_pages((unsigned long) diag204_buf, 0); | 370 | free_pages((unsigned long) diag204_buf, 0); |
366 | } | 371 | } |
367 | diag204_buf_pages = 0; | ||
368 | diag204_buf = NULL; | 372 | diag204_buf = NULL; |
369 | } | 373 | } |
370 | 374 | ||
375 | static void *page_align_ptr(void *ptr) | ||
376 | { | ||
377 | return (void *) PAGE_ALIGN((unsigned long) ptr); | ||
378 | } | ||
379 | |||
371 | static void *diag204_alloc_vbuf(int pages) | 380 | static void *diag204_alloc_vbuf(int pages) |
372 | { | 381 | { |
373 | /* The buffer has to be page aligned! */ | 382 | /* The buffer has to be page aligned! */ |
374 | diag204_buf_vmalloc = vmalloc(PAGE_SIZE * (pages + 1)); | 383 | diag204_buf_vmalloc = vmalloc(PAGE_SIZE * (pages + 1)); |
375 | if (!diag204_buf_vmalloc) | 384 | if (!diag204_buf_vmalloc) |
376 | return ERR_PTR(-ENOMEM); | 385 | return ERR_PTR(-ENOMEM); |
377 | diag204_buf = (void*)((unsigned long)diag204_buf_vmalloc | 386 | diag204_buf = page_align_ptr(diag204_buf_vmalloc); |
378 | & ~0xfffUL) + 0x1000; | ||
379 | diag204_buf_pages = pages; | 387 | diag204_buf_pages = pages; |
380 | return diag204_buf; | 388 | return diag204_buf; |
381 | } | 389 | } |
@@ -468,17 +476,26 @@ fail_alloc: | |||
468 | return rc; | 476 | return rc; |
469 | } | 477 | } |
470 | 478 | ||
479 | static int diag204_do_store(void *buf, int pages) | ||
480 | { | ||
481 | int rc; | ||
482 | |||
483 | rc = diag204((unsigned long) diag204_store_sc | | ||
484 | (unsigned long) diag204_info_type, pages, buf); | ||
485 | return rc < 0 ? -ENOSYS : 0; | ||
486 | } | ||
487 | |||
471 | static void *diag204_store(void) | 488 | static void *diag204_store(void) |
472 | { | 489 | { |
473 | void *buf; | 490 | void *buf; |
474 | int pages; | 491 | int pages, rc; |
475 | 492 | ||
476 | buf = diag204_get_buffer(diag204_info_type, &pages); | 493 | buf = diag204_get_buffer(diag204_info_type, &pages); |
477 | if (IS_ERR(buf)) | 494 | if (IS_ERR(buf)) |
478 | goto out; | 495 | goto out; |
479 | if (diag204((unsigned long)diag204_store_sc | | 496 | rc = diag204_do_store(buf, pages); |
480 | (unsigned long)diag204_info_type, pages, buf) < 0) | 497 | if (rc) |
481 | return ERR_PTR(-ENOSYS); | 498 | return ERR_PTR(rc); |
482 | out: | 499 | out: |
483 | return buf; | 500 | return buf; |
484 | } | 501 | } |
@@ -526,6 +543,92 @@ static int diag224_idx2name(int index, char *name) | |||
526 | return 0; | 543 | return 0; |
527 | } | 544 | } |
528 | 545 | ||
546 | struct dbfs_d204_hdr { | ||
547 | u64 len; /* Length of d204 buffer without header */ | ||
548 | u16 version; /* Version of header */ | ||
549 | u8 sc; /* Used subcode */ | ||
550 | char reserved[53]; | ||
551 | } __attribute__ ((packed)); | ||
552 | |||
553 | struct dbfs_d204 { | ||
554 | struct dbfs_d204_hdr hdr; /* 64 byte header */ | ||
555 | char buf[]; /* d204 buffer */ | ||
556 | } __attribute__ ((packed)); | ||
557 | |||
558 | struct dbfs_d204_private { | ||
559 | struct dbfs_d204 *d204; /* Aligned d204 data with header */ | ||
560 | void *base; /* Base pointer (needed for vfree) */ | ||
561 | }; | ||
562 | |||
563 | static int dbfs_d204_open(struct inode *inode, struct file *file) | ||
564 | { | ||
565 | struct dbfs_d204_private *data; | ||
566 | struct dbfs_d204 *d204; | ||
567 | int rc, buf_size; | ||
568 | |||
569 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
570 | if (!data) | ||
571 | return -ENOMEM; | ||
572 | buf_size = PAGE_SIZE * (diag204_buf_pages + 1) + sizeof(d204->hdr); | ||
573 | data->base = vmalloc(buf_size); | ||
574 | if (!data->base) { | ||
575 | rc = -ENOMEM; | ||
576 | goto fail_kfree_data; | ||
577 | } | ||
578 | memset(data->base, 0, buf_size); | ||
579 | d204 = page_align_ptr(data->base + sizeof(d204->hdr)) | ||
580 | - sizeof(d204->hdr); | ||
581 | rc = diag204_do_store(&d204->buf, diag204_buf_pages); | ||
582 | if (rc) | ||
583 | goto fail_vfree_base; | ||
584 | d204->hdr.version = DBFS_D204_HDR_VERSION; | ||
585 | d204->hdr.len = PAGE_SIZE * diag204_buf_pages; | ||
586 | d204->hdr.sc = diag204_store_sc; | ||
587 | data->d204 = d204; | ||
588 | file->private_data = data; | ||
589 | return nonseekable_open(inode, file); | ||
590 | |||
591 | fail_vfree_base: | ||
592 | vfree(data->base); | ||
593 | fail_kfree_data: | ||
594 | kfree(data); | ||
595 | return rc; | ||
596 | } | ||
597 | |||
598 | static int dbfs_d204_release(struct inode *inode, struct file *file) | ||
599 | { | ||
600 | struct dbfs_d204_private *data = file->private_data; | ||
601 | |||
602 | vfree(data->base); | ||
603 | kfree(data); | ||
604 | return 0; | ||
605 | } | ||
606 | |||
607 | static ssize_t dbfs_d204_read(struct file *file, char __user *buf, | ||
608 | size_t size, loff_t *ppos) | ||
609 | { | ||
610 | struct dbfs_d204_private *data = file->private_data; | ||
611 | |||
612 | return simple_read_from_buffer(buf, size, ppos, data->d204, | ||
613 | data->d204->hdr.len + | ||
614 | sizeof(data->d204->hdr)); | ||
615 | } | ||
616 | |||
617 | static const struct file_operations dbfs_d204_ops = { | ||
618 | .open = dbfs_d204_open, | ||
619 | .read = dbfs_d204_read, | ||
620 | .release = dbfs_d204_release, | ||
621 | }; | ||
622 | |||
623 | static int hypfs_dbfs_init(void) | ||
624 | { | ||
625 | dbfs_d204_file = debugfs_create_file("diag_204", 0400, hypfs_dbfs_dir, | ||
626 | NULL, &dbfs_d204_ops); | ||
627 | if (IS_ERR(dbfs_d204_file)) | ||
628 | return PTR_ERR(dbfs_d204_file); | ||
629 | return 0; | ||
630 | } | ||
631 | |||
529 | __init int hypfs_diag_init(void) | 632 | __init int hypfs_diag_init(void) |
530 | { | 633 | { |
531 | int rc; | 634 | int rc; |
@@ -540,11 +643,17 @@ __init int hypfs_diag_init(void) | |||
540 | pr_err("The hardware system does not provide all " | 643 | pr_err("The hardware system does not provide all " |
541 | "functions required by hypfs\n"); | 644 | "functions required by hypfs\n"); |
542 | } | 645 | } |
646 | if (diag204_info_type == INFO_EXT) { | ||
647 | rc = hypfs_dbfs_init(); | ||
648 | if (rc) | ||
649 | diag204_free_buffer(); | ||
650 | } | ||
543 | return rc; | 651 | return rc; |
544 | } | 652 | } |
545 | 653 | ||
546 | void hypfs_diag_exit(void) | 654 | void hypfs_diag_exit(void) |
547 | { | 655 | { |
656 | debugfs_remove(dbfs_d204_file); | ||
548 | diag224_delete_name_table(); | 657 | diag224_delete_name_table(); |
549 | diag204_free_buffer(); | 658 | diag204_free_buffer(); |
550 | } | 659 | } |