Revision e57a8c0e vl.c

b/vl.c
51 51
#include <pty.h>
52 52
#include <malloc.h>
53 53
#include <linux/rtc.h>
54
#include <linux/ppdev.h>
54 55
#endif
55 56
#endif
56 57

  
......
1013 1014
    return s->chr_write(s, buf, len);
1014 1015
}
1015 1016

  
1016
void qemu_chr_set_serial_parameters(CharDriverState *s,
1017
                                    int speed, int parity,
1018
                                    int data_bits, int stop_bits)
1017
int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg)
1019 1018
{
1020
    if (s->chr_set_serial_parameters)
1021
        s->chr_set_serial_parameters(s, speed, parity, data_bits, stop_bits);
1019
    if (!s->chr_ioctl)
1020
        return -ENOTSUP;
1021
    return s->chr_ioctl(s, cmd, arg);
1022 1022
}
1023 1023

  
1024
void qemu_chr_set_serial_break(CharDriverState *s, int enable)
1025
{
1026
    if (s->chr_set_serial_break)
1027
        s->chr_set_serial_break(s, enable);
1028
}
1029

  
1030

  
1031 1024
void qemu_chr_printf(CharDriverState *s, const char *fmt, ...)
1032 1025
{
1033 1026
    char buf[4096];
......
1379 1372
    struct termios tty;
1380 1373
    speed_t spd;
1381 1374

  
1382
    tcgetattr (0, &tty);
1375
#if 0
1376
    printf("tty_serial_init: speed=%d parity=%c data=%d stop=%d\n", 
1377
           speed, parity, data_bits, stop_bits);
1378
#endif
1379
    tcgetattr (fd, &tty);
1383 1380

  
1384 1381
    switch(speed) {
1385 1382
    case 50:
......
1459 1456
    tcsetattr (fd, TCSANOW, &tty);
1460 1457
}
1461 1458

  
1462
static void tty_set_serial_parameters(CharDriverState *chr,
1463
                                      int speed, int parity,
1464
                                      int data_bits, int stop_bits)
1459
static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg)
1465 1460
{
1466 1461
    FDCharDriver *s = chr->opaque;
1467
    tty_serial_init(s->fd_in, speed, parity, data_bits, stop_bits);
1468
}
1469

  
1470
static void tty_set_serial_break(CharDriverState *chr, int enable)
1471
{
1472
    FDCharDriver *s = chr->opaque;
1473
    /* XXX: find a better solution */
1474
    if (enable)
1475
        tcsendbreak(s->fd_in, 1);
1462
    
1463
    switch(cmd) {
1464
    case CHR_IOCTL_SERIAL_SET_PARAMS:
1465
        {
1466
            QEMUSerialSetParams *ssp = arg;
1467
            tty_serial_init(s->fd_in, ssp->speed, ssp->parity, 
1468
                            ssp->data_bits, ssp->stop_bits);
1469
        }
1470
        break;
1471
    case CHR_IOCTL_SERIAL_SET_BREAK:
1472
        {
1473
            int enable = *(int *)arg;
1474
            if (enable)
1475
                tcsendbreak(s->fd_in, 1);
1476
        }
1477
        break;
1478
    default:
1479
        return -ENOTSUP;
1480
    }
1481
    return 0;
1476 1482
}
1477 1483

  
1478 1484
CharDriverState *qemu_chr_open_tty(const char *filename)
......
1480 1486
    CharDriverState *chr;
1481 1487
    int fd;
1482 1488

  
1483
    fd = open(filename, O_RDWR);
1489
    fd = open(filename, O_RDWR | O_NONBLOCK);
1484 1490
    if (fd < 0)
1485 1491
        return NULL;
1486 1492
    fcntl(fd, F_SETFL, O_NONBLOCK);
......
1488 1494
    chr = qemu_chr_open_fd(fd, fd);
1489 1495
    if (!chr)
1490 1496
        return NULL;
1491
    chr->chr_set_serial_parameters = tty_set_serial_parameters;
1492
    chr->chr_set_serial_break = tty_set_serial_break;
1497
    chr->chr_ioctl = tty_serial_ioctl;
1498
    return chr;
1499
}
1500

  
1501
static int pp_ioctl(CharDriverState *chr, int cmd, void *arg)
1502
{
1503
    int fd = (int)chr->opaque;
1504
    uint8_t b;
1505

  
1506
    switch(cmd) {
1507
    case CHR_IOCTL_PP_READ_DATA:
1508
        if (ioctl(fd, PPRDATA, &b) < 0)
1509
            return -ENOTSUP;
1510
        *(uint8_t *)arg = b;
1511
        break;
1512
    case CHR_IOCTL_PP_WRITE_DATA:
1513
        b = *(uint8_t *)arg;
1514
        if (ioctl(fd, PPWDATA, &b) < 0)
1515
            return -ENOTSUP;
1516
        break;
1517
    case CHR_IOCTL_PP_READ_CONTROL:
1518
        if (ioctl(fd, PPRCONTROL, &b) < 0)
1519
            return -ENOTSUP;
1520
        *(uint8_t *)arg = b;
1521
        break;
1522
    case CHR_IOCTL_PP_WRITE_CONTROL:
1523
        b = *(uint8_t *)arg;
1524
        if (ioctl(fd, PPWCONTROL, &b) < 0)
1525
            return -ENOTSUP;
1526
        break;
1527
    case CHR_IOCTL_PP_READ_STATUS:
1528
        if (ioctl(fd, PPRSTATUS, &b) < 0)
1529
            return -ENOTSUP;
1530
        *(uint8_t *)arg = b;
1531
        break;
1532
    default:
1533
        return -ENOTSUP;
1534
    }
1535
    return 0;
1536
}
1537

  
1538
CharDriverState *qemu_chr_open_pp(const char *filename)
1539
{
1540
    CharDriverState *chr;
1541
    int fd;
1542

  
1543
    fd = open(filename, O_RDWR);
1544
    if (fd < 0)
1545
        return NULL;
1546

  
1547
    if (ioctl(fd, PPCLAIM) < 0) {
1548
        close(fd);
1549
        return NULL;
1550
    }
1551

  
1552
    chr = qemu_mallocz(sizeof(CharDriverState));
1553
    if (!chr) {
1554
        close(fd);
1555
        return NULL;
1556
    }
1557
    chr->opaque = (void *)fd;
1558
    chr->chr_write = null_chr_write;
1559
    chr->chr_add_read_handler = null_chr_add_read_handler;
1560
    chr->chr_ioctl = pp_ioctl;
1493 1561
    return chr;
1494 1562
}
1495 1563

  
......
1522 1590
    } else 
1523 1591
#endif
1524 1592
#if defined(__linux__)
1593
    if (strstart(filename, "/dev/parport", NULL)) {
1594
        return qemu_chr_open_pp(filename);
1595
    } else 
1525 1596
    if (strstart(filename, "/dev/", NULL)) {
1526 1597
        return qemu_chr_open_tty(filename);
1527 1598
    } else 

Also available in: Unified diff