]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/s390/char/sclp_vt220.c
Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[linux-2.6-omap-h63xx.git] / drivers / s390 / char / sclp_vt220.c
index 726334757bbf659d17b60d47d65297942ff60cb2..92f527201792971095eea15a1503c0938d1eaeb0 100644 (file)
@@ -3,7 +3,7 @@
  *    SCLP VT220 terminal driver.
  *
  *  S390 version
- *    Copyright (C) 2003 IBM Deutschland Entwicklung GmbH, IBM Corporation
+ *    Copyright IBM Corp. 2003,2008
  *    Author(s): Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>
  */
 
@@ -202,7 +202,7 @@ sclp_vt220_callback(struct sclp_req *request, void *data)
 static int
 __sclp_vt220_emit(struct sclp_vt220_request *request)
 {
-       if (!(sclp_vt220_register.sclp_send_mask & EVTYP_VT220MSG_MASK)) {
+       if (!(sclp_vt220_register.sclp_receive_mask & EVTYP_VT220MSG_MASK)) {
                request->sclp_req.status = SCLP_REQ_FAILED;
                return -EIO;
        }
@@ -400,7 +400,7 @@ __sclp_vt220_write(const unsigned char *buf, int count, int do_schedule,
                        while (list_empty(&sclp_vt220_empty)) {
                                spin_unlock_irqrestore(&sclp_vt220_lock,
                                                       flags);
-                               if (in_interrupt())
+                               if (in_atomic())
                                        sclp_sync_wait();
                                else
                                        wait_event(sclp_vt220_waitq,
@@ -621,11 +621,28 @@ sclp_vt220_flush_buffer(struct tty_struct *tty)
 /*
  * Initialize all relevant components and register driver with system.
  */
-static int
-__sclp_vt220_init(int early)
+static void __init __sclp_vt220_cleanup(void)
+{
+       struct list_head *page, *p;
+
+       list_for_each_safe(page, p, &sclp_vt220_empty) {
+               list_del(page);
+               if (slab_is_available())
+                       free_page((unsigned long) page);
+               else
+                       free_bootmem((unsigned long) page, PAGE_SIZE);
+       }
+       if (!list_empty(&sclp_vt220_register.list))
+               sclp_unregister(&sclp_vt220_register);
+       sclp_vt220_initialized = 0;
+}
+
+static int __init __sclp_vt220_init(void)
 {
        void *page;
        int i;
+       int num_pages;
+       int rc;
 
        if (sclp_vt220_initialized)
                return 0;
@@ -642,16 +659,26 @@ __sclp_vt220_init(int early)
        sclp_vt220_flush_later = 0;
 
        /* Allocate pages for output buffering */
-       for (i = 0; i < (early ? MAX_CONSOLE_PAGES : MAX_KMEM_PAGES); i++) {
-               if (early)
-                       page = alloc_bootmem_low_pages(PAGE_SIZE);
-               else
+       num_pages = slab_is_available() ? MAX_KMEM_PAGES : MAX_CONSOLE_PAGES;
+       for (i = 0; i < num_pages; i++) {
+               if (slab_is_available())
                        page = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
-               if (!page)
+               else
+                       page = alloc_bootmem_low_pages(PAGE_SIZE);
+               if (!page) {
+                       __sclp_vt220_cleanup();
                        return -ENOMEM;
+               }
                list_add_tail((struct list_head *) page, &sclp_vt220_empty);
        }
-       return 0;
+       rc = sclp_register(&sclp_vt220_register);
+       if (rc) {
+               printk(KERN_ERR SCLP_VT220_PRINT_HEADER
+                      "could not register vt220 - "
+                      "sclp_register returned %d\n", rc);
+               __sclp_vt220_cleanup();
+       }
+       return rc;
 }
 
 static const struct tty_operations sclp_vt220_ops = {
@@ -662,36 +689,27 @@ static const struct tty_operations sclp_vt220_ops = {
        .flush_chars = sclp_vt220_flush_chars,
        .write_room = sclp_vt220_write_room,
        .chars_in_buffer = sclp_vt220_chars_in_buffer,
-       .flush_buffer = sclp_vt220_flush_buffer
+       .flush_buffer = sclp_vt220_flush_buffer,
 };
 
 /*
  * Register driver with SCLP and Linux and initialize internal tty structures.
  */
-static int __init
-sclp_vt220_tty_init(void)
+static int __init sclp_vt220_tty_init(void)
 {
        struct tty_driver *driver;
        int rc;
+       int cleanup;
 
        /* Note: we're not testing for CONSOLE_IS_SCLP here to preserve
         * symmetry between VM and LPAR systems regarding ttyS1. */
        driver = alloc_tty_driver(1);
        if (!driver)
                return -ENOMEM;
-       rc = __sclp_vt220_init(0);
-       if (rc) {
-               put_tty_driver(driver);
-               return rc;
-       }
-       rc = sclp_register(&sclp_vt220_register);
-       if (rc) {
-               printk(KERN_ERR SCLP_VT220_PRINT_HEADER
-                      "could not register tty - "
-                      "sclp_register returned %d\n", rc);
-               put_tty_driver(driver);
-               return rc;
-       }
+       cleanup = !sclp_vt220_initialized;
+       rc = __sclp_vt220_init();
+       if (rc)
+               goto out_driver;
 
        driver->owner = THIS_MODULE;
        driver->driver_name = SCLP_VT220_DRIVER_NAME;
@@ -709,14 +727,19 @@ sclp_vt220_tty_init(void)
                printk(KERN_ERR SCLP_VT220_PRINT_HEADER
                       "could not register tty - "
                       "tty_register_driver returned %d\n", rc);
-               put_tty_driver(driver);
-               return rc;
+               goto out_init;
        }
        sclp_vt220_driver = driver;
        return 0;
-}
 
-module_init(sclp_vt220_tty_init);
+out_init:
+       if (cleanup)
+               __sclp_vt220_cleanup();
+out_driver:
+       put_tty_driver(driver);
+       return rc;
+}
+__initcall(sclp_vt220_tty_init);
 
 #ifdef CONFIG_SCLP_VT220_CONSOLE
 
@@ -762,7 +785,7 @@ sclp_vt220_con_init(void)
 
        if (!CONSOLE_IS_SCLP)
                return 0;
-       rc = __sclp_vt220_init(1);
+       rc = __sclp_vt220_init();
        if (rc)
                return rc;
        /* Attach linux console */