| 51 |
#include <pty.h> |
#include <pty.h> |
| 52 |
#include <malloc.h> |
#include <malloc.h> |
| 53 |
#include <linux/rtc.h> |
#include <linux/rtc.h> |
| 54 |
|
#include <linux/ppdev.h> |
| 55 |
#endif |
#endif |
| 56 |
#endif |
#endif |
| 57 |
|
|
| 1014 |
return s->chr_write(s, buf, len); |
return s->chr_write(s, buf, len); |
| 1015 |
} |
} |
| 1016 |
|
|
| 1017 |
void qemu_chr_set_serial_parameters(CharDriverState *s, |
int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg) |
|
int speed, int parity, |
|
|
int data_bits, int stop_bits) |
|
| 1018 |
{ |
{ |
| 1019 |
if (s->chr_set_serial_parameters) |
if (!s->chr_ioctl) |
| 1020 |
s->chr_set_serial_parameters(s, speed, parity, data_bits, stop_bits); |
return -ENOTSUP; |
| 1021 |
|
return s->chr_ioctl(s, cmd, arg); |
| 1022 |
} |
} |
| 1023 |
|
|
|
void qemu_chr_set_serial_break(CharDriverState *s, int enable) |
|
|
{ |
|
|
if (s->chr_set_serial_break) |
|
|
s->chr_set_serial_break(s, enable); |
|
|
} |
|
|
|
|
|
|
|
| 1024 |
void qemu_chr_printf(CharDriverState *s, const char *fmt, ...) |
void qemu_chr_printf(CharDriverState *s, const char *fmt, ...) |
| 1025 |
{ |
{ |
| 1026 |
char buf[4096]; |
char buf[4096]; |
| 1372 |
struct termios tty; |
struct termios tty; |
| 1373 |
speed_t spd; |
speed_t spd; |
| 1374 |
|
|
| 1375 |
tcgetattr (0, &tty); |
#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); |
| 1380 |
|
|
| 1381 |
switch(speed) { |
switch(speed) { |
| 1382 |
case 50: |
case 50: |
| 1456 |
tcsetattr (fd, TCSANOW, &tty); |
tcsetattr (fd, TCSANOW, &tty); |
| 1457 |
} |
} |
| 1458 |
|
|
| 1459 |
static void tty_set_serial_parameters(CharDriverState *chr, |
static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg) |
|
int speed, int parity, |
|
|
int data_bits, int stop_bits) |
|
| 1460 |
{ |
{ |
| 1461 |
FDCharDriver *s = chr->opaque; |
FDCharDriver *s = chr->opaque; |
| 1462 |
tty_serial_init(s->fd_in, speed, parity, data_bits, stop_bits); |
|
| 1463 |
} |
switch(cmd) { |
| 1464 |
|
case CHR_IOCTL_SERIAL_SET_PARAMS: |
| 1465 |
static void tty_set_serial_break(CharDriverState *chr, int enable) |
{ |
| 1466 |
{ |
QEMUSerialSetParams *ssp = arg; |
| 1467 |
FDCharDriver *s = chr->opaque; |
tty_serial_init(s->fd_in, ssp->speed, ssp->parity, |
| 1468 |
/* XXX: find a better solution */ |
ssp->data_bits, ssp->stop_bits); |
| 1469 |
if (enable) |
} |
| 1470 |
tcsendbreak(s->fd_in, 1); |
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; |
| 1482 |
} |
} |
| 1483 |
|
|
| 1484 |
CharDriverState *qemu_chr_open_tty(const char *filename) |
CharDriverState *qemu_chr_open_tty(const char *filename) |
| 1486 |
CharDriverState *chr; |
CharDriverState *chr; |
| 1487 |
int fd; |
int fd; |
| 1488 |
|
|
| 1489 |
fd = open(filename, O_RDWR); |
fd = open(filename, O_RDWR | O_NONBLOCK); |
| 1490 |
if (fd < 0) |
if (fd < 0) |
| 1491 |
return NULL; |
return NULL; |
| 1492 |
fcntl(fd, F_SETFL, O_NONBLOCK); |
fcntl(fd, F_SETFL, O_NONBLOCK); |
| 1494 |
chr = qemu_chr_open_fd(fd, fd); |
chr = qemu_chr_open_fd(fd, fd); |
| 1495 |
if (!chr) |
if (!chr) |
| 1496 |
return NULL; |
return NULL; |
| 1497 |
chr->chr_set_serial_parameters = tty_set_serial_parameters; |
chr->chr_ioctl = tty_serial_ioctl; |
| 1498 |
chr->chr_set_serial_break = tty_set_serial_break; |
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; |
| 1561 |
return chr; |
return chr; |
| 1562 |
} |
} |
| 1563 |
|
|
| 1590 |
} else |
} else |
| 1591 |
#endif |
#endif |
| 1592 |
#if defined(__linux__) |
#if defined(__linux__) |
| 1593 |
|
if (strstart(filename, "/dev/parport", NULL)) { |
| 1594 |
|
return qemu_chr_open_pp(filename); |
| 1595 |
|
} else |
| 1596 |
if (strstart(filename, "/dev/", NULL)) { |
if (strstart(filename, "/dev/", NULL)) { |
| 1597 |
return qemu_chr_open_tty(filename); |
return qemu_chr_open_tty(filename); |
| 1598 |
} else |
} else |