~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/tty/hvc/hvcs.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
 * arch/powerepc/include/asm/hvcserver.h
119
119
 *
120
120
 * 1.3.2 -> 1.3.3 Replaced yield() in hvcs_close() with tty_wait_until_sent() to
121
 
 * prevent possible lockup with realtime scheduling as similarily pointed out by
 
121
 * prevent possible lockup with realtime scheduling as similarly pointed out by
122
122
 * akpm in hvc_console.  Changed resulted in the removal of hvcs_final_close()
123
123
 * to reorder cleanup operations and prevent discarding of pending data during
124
124
 * an hvcs_close().  Removed spinlock protection of hvcs_struct data members in
292
292
        /*
293
293
         * Any variable below the kref is valid before a tty is connected and
294
294
         * stays valid after the tty is disconnected.  These shouldn't be
295
 
         * whacked until the koject refcount reaches zero though some entries
 
295
         * whacked until the kobject refcount reaches zero though some entries
296
296
         * may be changed via sysfs initiatives.
297
297
         */
298
298
        struct kref kref; /* ref count & hvcs_struct lifetime */
309
309
 
310
310
static LIST_HEAD(hvcs_structs);
311
311
static DEFINE_SPINLOCK(hvcs_structs_lock);
 
312
static DEFINE_MUTEX(hvcs_init_mutex);
312
313
 
313
314
static void hvcs_unthrottle(struct tty_struct *tty);
314
315
static void hvcs_throttle(struct tty_struct *tty);
340
341
static int __devexit hvcs_remove(struct vio_dev *dev);
341
342
static int __init hvcs_module_init(void);
342
343
static void __exit hvcs_module_exit(void);
 
344
static int __devinit hvcs_initialize(void);
343
345
 
344
346
#define HVCS_SCHED_READ 0x00000001
345
347
#define HVCS_QUICK_READ 0x00000002
579
581
                        /*
580
582
                         * We are still obligated to deliver the data to the
581
583
                         * hypervisor even if the tty has been closed because
582
 
                         * we commited to delivering it.  But don't try to wake
 
584
                         * we committed to delivering it.  But don't try to wake
583
585
                         * a non-existent tty.
584
586
                         */
585
587
                        if (tty) {
762
764
        const struct vio_device_id *id)
763
765
{
764
766
        struct hvcs_struct *hvcsd;
765
 
        int index;
 
767
        int index, rc;
766
768
        int retval;
767
769
 
768
770
        if (!dev || !id) {
770
772
                return -EPERM;
771
773
        }
772
774
 
 
775
        /* Make sure we are properly initialized */
 
776
        rc = hvcs_initialize();
 
777
        if (rc) {
 
778
                pr_err("HVCS: Failed to initialize core driver.\n");
 
779
                return rc;
 
780
        }
 
781
 
773
782
        /* early to avoid cleanup on failure */
774
783
        index = hvcs_get_index();
775
784
        if (index < 0) {
1340
1349
        spin_lock_irqsave(&hvcsd->lock, flags);
1341
1350
 
1342
1351
        /*
1343
 
         * Somehow an open succedded but the device was removed or the
 
1352
         * Somehow an open succeeded but the device was removed or the
1344
1353
         * connection terminated between the vty-server and partner vty during
1345
1354
         * the middle of a write operation?  This is a crummy place to do this
1346
1355
         * but we want to keep it all in the spinlock.
1411
1420
}
1412
1421
 
1413
1422
/*
1414
 
 * This is really asking how much can we guarentee that we can send or that we
 
1423
 * This is really asking how much can we guarantee that we can send or that we
1415
1424
 * absolutely WILL BUFFER if we can't send it.  This driver MUST honor the
1416
1425
 * return value, hence the reason for hvcs_struct buffering.
1417
1426
 */
1464
1473
        hvcs_index_count = 0;
1465
1474
}
1466
1475
 
1467
 
static int __init hvcs_module_init(void)
 
1476
static int __devinit hvcs_initialize(void)
1468
1477
{
1469
 
        int rc;
1470
 
        int num_ttys_to_alloc;
 
1478
        int rc, num_ttys_to_alloc;
1471
1479
 
1472
 
        printk(KERN_INFO "Initializing %s\n", hvcs_driver_string);
 
1480
        mutex_lock(&hvcs_init_mutex);
 
1481
        if (hvcs_task) {
 
1482
                mutex_unlock(&hvcs_init_mutex);
 
1483
                return 0;
 
1484
        }
1473
1485
 
1474
1486
        /* Has the user specified an overload with an insmod param? */
1475
1487
        if (hvcs_parm_num_devs <= 0 ||
1528
1540
 
1529
1541
        hvcs_task = kthread_run(khvcsd, NULL, "khvcsd");
1530
1542
        if (IS_ERR(hvcs_task)) {
1531
 
                printk(KERN_ERR "HVCS: khvcsd creation failed.  Driver not loaded.\n");
 
1543
                printk(KERN_ERR "HVCS: khvcsd creation failed.\n");
1532
1544
                rc = -EIO;
1533
1545
                goto kthread_fail;
1534
1546
        }
1535
 
 
1536
 
        rc = vio_register_driver(&hvcs_vio_driver);
1537
 
        if (rc) {
1538
 
                printk(KERN_ERR "HVCS: can't register vio driver\n");
1539
 
                goto vio_fail;
1540
 
        }
1541
 
 
1542
 
        /*
1543
 
         * This needs to be done AFTER the vio_register_driver() call or else
1544
 
         * the kobjects won't be initialized properly.
1545
 
         */
1546
 
        rc = driver_create_file(&(hvcs_vio_driver.driver), &driver_attr_rescan);
1547
 
        if (rc) {
1548
 
                printk(KERN_ERR "HVCS: sysfs attr create failed\n");
1549
 
                goto attr_fail;
1550
 
        }
1551
 
 
1552
 
        printk(KERN_INFO "HVCS: driver module inserted.\n");
1553
 
 
 
1547
        mutex_unlock(&hvcs_init_mutex);
1554
1548
        return 0;
1555
1549
 
1556
 
attr_fail:
1557
 
        vio_unregister_driver(&hvcs_vio_driver);
1558
 
vio_fail:
1559
 
        kthread_stop(hvcs_task);
1560
1550
kthread_fail:
1561
1551
        kfree(hvcs_pi_buff);
1562
1552
buff_alloc_fail:
1566
1556
index_fail:
1567
1557
        put_tty_driver(hvcs_tty_driver);
1568
1558
        hvcs_tty_driver = NULL;
 
1559
        mutex_unlock(&hvcs_init_mutex);
1569
1560
        return rc;
1570
1561
}
1571
1562
 
 
1563
static int __init hvcs_module_init(void)
 
1564
{
 
1565
        int rc = vio_register_driver(&hvcs_vio_driver);
 
1566
        if (rc) {
 
1567
                printk(KERN_ERR "HVCS: can't register vio driver\n");
 
1568
                return rc;
 
1569
        }
 
1570
 
 
1571
        pr_info("HVCS: Driver registered.\n");
 
1572
 
 
1573
        /* This needs to be done AFTER the vio_register_driver() call or else
 
1574
         * the kobjects won't be initialized properly.
 
1575
         */
 
1576
        rc = driver_create_file(&(hvcs_vio_driver.driver), &driver_attr_rescan);
 
1577
        if (rc)
 
1578
                pr_warning(KERN_ERR "HVCS: Failed to create rescan file (err %d)\n", rc);
 
1579
 
 
1580
        return 0;
 
1581
}
 
1582
 
1572
1583
static void __exit hvcs_module_exit(void)
1573
1584
{
1574
1585
        /*
1575
1586
         * This driver receives hvcs_remove callbacks for each device upon
1576
1587
         * module removal.
1577
1588
         */
 
1589
        vio_unregister_driver(&hvcs_vio_driver);
 
1590
        if (!hvcs_task)
 
1591
                return;
1578
1592
 
1579
1593
        /*
1580
1594
         * This synchronous operation  will wake the khvcsd kthread if it is
1589
1603
 
1590
1604
        driver_remove_file(&hvcs_vio_driver.driver, &driver_attr_rescan);
1591
1605
 
1592
 
        vio_unregister_driver(&hvcs_vio_driver);
1593
 
 
1594
1606
        tty_unregister_driver(hvcs_tty_driver);
1595
1607
 
1596
1608
        hvcs_free_index_list();