ipcns: extract create_ipc_ns()
[safe/jmp/linux-2.6] / arch / s390 / hypfs / hypfs_diag.c
index 684384f..704dd39 100644 (file)
@@ -3,12 +3,17 @@
  *    Hypervisor filesystem for Linux on s390. Diag 204 and 224
  *    implementation.
  *
- *    Copyright (C) IBM Corp. 2006
+ *    Copyright IBM Corp. 2006, 2008
  *    Author(s): Michael Holzheu <holzheu@de.ibm.com>
  */
 
+#define KMSG_COMPONENT "hypfs"
+#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
+
 #include <linux/types.h>
 #include <linux/errno.h>
+#include <linux/gfp.h>
+#include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/vmalloc.h>
 #include <asm/ebcdic.h>
@@ -333,22 +338,14 @@ static int diag204(unsigned long subcode, unsigned long size, void *addr)
        register unsigned long _subcode asm("0") = subcode;
        register unsigned long _size asm("1") = size;
 
-       asm volatile ("   diag    %2,%0,0x204\n"
-                     "0: \n" ".section __ex_table,\"a\"\n"
-#ifndef __s390x__
-                     "    .align 4\n"
-                     "    .long  0b,0b\n"
-#else
-                     "    .align 8\n"
-                     "    .quad  0b,0b\n"
-#endif
-                     ".previous":"+d" (_subcode), "+d"(_size)
-                     :"d"(addr)
-                     :"memory");
+       asm volatile(
+               "       diag    %2,%0,0x204\n"
+               "0:\n"
+               EX_TABLE(0b,0b)
+               : "+d" (_subcode), "+d" (_size) : "d" (addr) : "memory");
        if (_subcode)
                return -1;
-       else
-               return _size;
+       return _size;
 }
 
 /*
@@ -387,7 +384,7 @@ static void *diag204_alloc_vbuf(int pages)
 static void *diag204_alloc_rbuf(void)
 {
        diag204_buf = (void*)__get_free_pages(GFP_KERNEL,0);
-       if (diag204_buf)
+       if (!diag204_buf)
                return ERR_PTR(-ENOMEM);
        diag204_buf_pages = 1;
        return diag204_buf;
@@ -489,10 +486,17 @@ out:
 
 /* Diagnose 224 functions */
 
-static void diag224(void *ptr)
+static int diag224(void *ptr)
 {
-       asm volatile("   diag    %0,%1,0x224\n"
-                    : :"d" (0), "d"(ptr) : "memory");
+       int rc = -ENOTSUPP;
+
+       asm volatile(
+               "       diag    %1,%2,0x224\n"
+               "0:     lhi     %0,0x0\n"
+               "1:\n"
+               EX_TABLE(0b,1b)
+               : "+d" (rc) :"d" (0), "d" (ptr) : "memory");
+       return rc;
 }
 
 static int diag224_get_name_table(void)
@@ -501,7 +505,10 @@ static int diag224_get_name_table(void)
        diag224_cpu_names = kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA);
        if (!diag224_cpu_names)
                return -ENOMEM;
-       diag224(diag224_cpu_names);
+       if (diag224(diag224_cpu_names)) {
+               kfree(diag224_cpu_names);
+               return -ENOTSUPP;
+       }
        EBCASC(diag224_cpu_names + 16, (*diag224_cpu_names + 1) * 16);
        return 0;
 }
@@ -525,13 +532,14 @@ __init int hypfs_diag_init(void)
        int rc;
 
        if (diag204_probe()) {
-               printk(KERN_ERR "hypfs: diag 204 not working.");
+               pr_err("The hardware system does not support hypfs\n");
                return -ENODATA;
        }
        rc = diag224_get_name_table();
        if (rc) {
-               diag224_delete_name_table();
-               printk(KERN_ERR "hypfs: could not get name table.\n");
+               diag204_free_buffer();
+               pr_err("The hardware system does not provide all "
+                      "functions required by hypfs\n");
        }
        return rc;
 }