/* If fd is zero, it means that the parallel device uses the console */ ParallelState *parallel_init(int base, qemu_irq irq, CharDriverState *chr) { ParallelState *s; uint8_t dummy; s = (ParallelState *)qemu_mallocz(sizeof(ParallelState)); if (!s) return NULL; parallel_reset(s, irq, chr); if (qemu_chr_ioctl(chr, CHR_IOCTL_PP_READ_STATUS, &dummy) == 0) { s->hw_driver = 1; s->status = dummy; } if (s->hw_driver) { register_ioport_write(base, 8, 1, parallel_ioport_write_hw, s); register_ioport_read(base, 8, 1, parallel_ioport_read_hw, s); register_ioport_write(base+4, 1, 2, parallel_ioport_eppdata_write_hw2, s); register_ioport_read(base+4, 1, 2, parallel_ioport_eppdata_read_hw2, s); register_ioport_write(base+4, 1, 4, parallel_ioport_eppdata_write_hw4, s); register_ioport_read(base+4, 1, 4, parallel_ioport_eppdata_read_hw4, s); register_ioport_write(base+0x400, 8, 1, parallel_ioport_ecp_write, s); register_ioport_read(base+0x400, 8, 1, parallel_ioport_ecp_read, s); } else { register_ioport_write(base, 8, 1, parallel_ioport_write_sw, s); register_ioport_read(base, 8, 1, parallel_ioport_read_sw, s); } return s; }
static uint32_t parallel_ioport_eppdata_read_hw4(void *opaque, uint32_t addr) { ParallelState *s = (ParallelState *)opaque; uint32_t ret; uint32_t eppdata = ~0U; int err; struct ParallelIOArg ioarg = { buffer : &eppdata, count : sizeof(eppdata) }; if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) { /* Controls not correct for EPP data cycle, so do nothing */ pdebug("re%08x s\n", eppdata); return eppdata; } err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg); ret = le32_to_cpu(eppdata); if (err) { s->epp_timeout = 1; pdebug("re%08x t\n", ret); } else pdebug("re%08x\n", ret); return ret; }
static void slavio_serial_update_parameters(ChannelState *s) { int speed, parity, data_bits, stop_bits; QEMUSerialSetParams ssp; if (!s->chr || s->type != ser) return; if (s->wregs[4] & 1) { if (s->wregs[4] & 2) parity = 'E'; else parity = 'O'; } else { parity = 'N'; } if ((s->wregs[4] & 0x0c) == 0x0c) stop_bits = 2; else stop_bits = 1; switch (s->wregs[5] & 0x60) { case 0x00: data_bits = 5; break; case 0x20: data_bits = 7; break; case 0x40: data_bits = 6; break; default: case 0x60: data_bits = 8; break; } speed = 2457600 / ((s->wregs[12] | (s->wregs[13] << 8)) + 2); switch (s->wregs[4] & 0xc0) { case 0x00: break; case 0x40: speed /= 16; break; case 0x80: speed /= 32; break; default: case 0xc0: speed /= 64; break; } ssp.speed = speed; ssp.parity = parity; ssp.data_bits = data_bits; ssp.stop_bits = stop_bits; SER_DPRINTF("channel %c: speed=%d parity=%c data=%d stop=%d\n", CHN_C(s), speed, parity, data_bits, stop_bits); qemu_chr_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp); }
static void slavio_serial_update_parameters(ChannelState *s) { int speed, parity, data_bits, stop_bits; QEMUSerialSetParams ssp; if (!s->chr || s->type != ser) return; if (s->wregs[W_TXCTRL1] & TXCTRL1_PAREN) { if (s->wregs[W_TXCTRL1] & TXCTRL1_PAREV) parity = 'E'; else parity = 'O'; } else { parity = 'N'; } if ((s->wregs[W_TXCTRL1] & TXCTRL1_STPMSK) == TXCTRL1_2STOP) stop_bits = 2; else stop_bits = 1; switch (s->wregs[W_TXCTRL2] & TXCTRL2_BITMSK) { case TXCTRL2_5BITS: data_bits = 5; break; case TXCTRL2_7BITS: data_bits = 7; break; case TXCTRL2_6BITS: data_bits = 6; break; default: case TXCTRL2_8BITS: data_bits = 8; break; } speed = 2457600 / ((s->wregs[W_BRGLO] | (s->wregs[W_BRGHI] << 8)) + 2); switch (s->wregs[W_TXCTRL1] & TXCTRL1_CLKMSK) { case TXCTRL1_CLK1X: break; case TXCTRL1_CLK16X: speed /= 16; break; case TXCTRL1_CLK32X: speed /= 32; break; default: case TXCTRL1_CLK64X: speed /= 64; break; } ssp.speed = speed; ssp.parity = parity; ssp.data_bits = data_bits; ssp.stop_bits = stop_bits; SER_DPRINTF("channel %c: speed=%d parity=%c data=%d stop=%d\n", CHN_C(s), speed, parity, data_bits, stop_bits); qemu_chr_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp); }
static int parallel_isa_initfn(ISADevice *dev) { static int index; ISAParallelState *isa = DO_UPCAST(ISAParallelState, dev, dev); ParallelState *s = &isa->state; int base; uint8_t dummy; if (!s->chr) { fprintf(stderr, "Can't create parallel device, empty char device\n"); exit(1); } if (isa->index == -1) isa->index = index; if (isa->index >= MAX_PARALLEL_PORTS) return -1; if (isa->iobase == -1) isa->iobase = isa_parallel_io[isa->index]; index++; base = isa->iobase; isa_init_irq(dev, &s->irq, isa->isairq); qemu_register_reset(parallel_reset, s); if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_STATUS, &dummy) == 0) { s->hw_driver = 1; s->status = dummy; } if (s->hw_driver) { register_ioport_write(base, 8, 1, parallel_ioport_write_hw, s); register_ioport_read(base, 8, 1, parallel_ioport_read_hw, s); register_ioport_write(base+4, 1, 2, parallel_ioport_eppdata_write_hw2, s); register_ioport_read(base+4, 1, 2, parallel_ioport_eppdata_read_hw2, s); register_ioport_write(base+4, 1, 4, parallel_ioport_eppdata_write_hw4, s); register_ioport_read(base+4, 1, 4, parallel_ioport_eppdata_read_hw4, s); register_ioport_write(base+0x400, 8, 1, parallel_ioport_ecp_write, s); register_ioport_read(base+0x400, 8, 1, parallel_ioport_ecp_read, s); } else { register_ioport_write(base, 8, 1, parallel_ioport_write_sw, s); register_ioport_read(base, 8, 1, parallel_ioport_read_sw, s); } return 0; }
static void parallel_ioport_eppdata_write_hw4(void *opaque, uint32_t addr, uint32_t val) { ParallelState *s = (ParallelState *)opaque; uint32_t eppdata = cpu_to_le32(val); int err; struct ParallelIOArg ioarg = { buffer : &eppdata, count : sizeof(eppdata) }; if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) { /* Controls not correct for EPP data cycle, so do nothing */ pdebug("we%08x s\n", val); return; } err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg); if (err) { s->epp_timeout = 1; pdebug("we%08x t\n", val); } else pdebug("we%08x\n", val); }
static uint32_t parallel_ioport_read_hw(void *opaque, uint32_t addr) { ParallelState *s = (ParallelState *)opaque; uint8_t ret = 0xff; addr &= 7; switch(addr) { case PARA_REG_DATA: qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_DATA, &ret); if (s->last_read_offset != addr || s->datar != ret) pdebug("rd%02x\n", ret); s->datar = ret; break; case PARA_REG_STS: qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_STATUS, &ret); ret &= ~PARA_STS_TMOUT; if (s->epp_timeout) ret |= PARA_STS_TMOUT; if (s->last_read_offset != addr || s->status != ret) pdebug("rs%02x\n", ret); s->status = ret; break; case PARA_REG_CTR: /* s->control has some bits fixed to 1. It is zero only when it has not been yet written to. */ if (s->control == 0) { qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_CONTROL, &ret); if (s->last_read_offset != addr) pdebug("rc%02x\n", ret); s->control = ret; } else { ret = s->control; if (s->last_read_offset != addr) pdebug("rc%02x\n", ret); } break; case PARA_REG_EPP_ADDR: if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) /* Controls not correct for EPP addr cycle, so do nothing */ pdebug("ra%02x s\n", ret); else { struct ParallelIOArg ioarg = { buffer : &ret, count : 1 }; if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ_ADDR, &ioarg)) { s->epp_timeout = 1; pdebug("ra%02x t\n", ret); } else pdebug("ra%02x\n", ret); } break; case PARA_REG_EPP_DATA: if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) /* Controls not correct for EPP data cycle, so do nothing */ pdebug("re%02x s\n", ret); else { struct ParallelIOArg ioarg = { buffer : &ret, count : 1 }; if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg)) { s->epp_timeout = 1; pdebug("re%02x t\n", ret); } else pdebug("re%02x\n", ret); } break; } s->last_read_offset = addr; return ret; }
static void parallel_ioport_write_hw(void *opaque, uint32_t addr, uint32_t val) { ParallelState *s = (ParallelState *)opaque; uint8_t parm = val; /* Sometimes programs do several writes for timing purposes on old HW. Take care not to waste time on writes that do nothing. */ s->last_read_offset = ~0U; addr &= 7; switch(addr) { case PARA_REG_DATA: if (s->dataw == val) return; pdebug("wd%02x\n", val); qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_WRITE_DATA, &parm); s->dataw = val; break; case PARA_REG_STS: pdebug("ws%02x\n", val); if (val & PARA_STS_TMOUT) s->epp_timeout = 0; break; case PARA_REG_CTR: val |= 0xc0; if (s->control == val) return; pdebug("wc%02x\n", val); qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_WRITE_CONTROL, &parm); s->control = val; break; case PARA_REG_EPP_ADDR: if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) /* Controls not correct for EPP address cycle, so do nothing */ pdebug("wa%02x s\n", val); else { struct ParallelIOArg ioarg = { buffer : &parm, count : 1 }; if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE_ADDR, &ioarg)) { s->epp_timeout = 1; pdebug("wa%02x t\n", val); } else pdebug("wa%02x\n", val); } break; case PARA_REG_EPP_DATA: if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) /* Controls not correct for EPP data cycle, so do nothing */ pdebug("we%02x s\n", val); else { struct ParallelIOArg ioarg = { buffer : &parm, count : 1 }; if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg)) { s->epp_timeout = 1; pdebug("we%02x t\n", val); } else pdebug("we%02x\n", val); } break; } }
static void parallel_ioport_write_hw(void *opaque, uint32_t addr, uint32_t val) { ParallelState *s = opaque; uint8_t parm = val; int dir; /* Sometimes programs do several writes for timing purposes on old HW. Take care not to waste time on writes that do nothing. */ s->last_read_offset = ~0U; addr &= 7; switch(addr) { case PARA_REG_DATA: if (s->dataw == val) return; pdebug("wd%02x\n", val); qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_WRITE_DATA, &parm); s->dataw = val; break; case PARA_REG_STS: pdebug("ws%02x\n", val); if (val & PARA_STS_TMOUT) s->epp_timeout = 0; break; case PARA_REG_CTR: val |= 0xc0; if (s->control == val) return; pdebug("wc%02x\n", val); if ((val & PARA_CTR_DIR) != (s->control & PARA_CTR_DIR)) { if (val & PARA_CTR_DIR) { dir = 1; } else { dir = 0; } qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_DATA_DIR, &dir); parm &= ~PARA_CTR_DIR; } qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_WRITE_CONTROL, &parm); s->control = val; break; case PARA_REG_EPP_ADDR: if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) /* Controls not correct for EPP address cycle, so do nothing */ pdebug("wa%02x s\n", val); else { struct ParallelIOArg ioarg = { .buffer = &parm, .count = 1 }; if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE_ADDR, &ioarg)) { s->epp_timeout = 1; pdebug("wa%02x t\n", val); } else pdebug("wa%02x\n", val); } break; case PARA_REG_EPP_DATA: if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) /* Controls not correct for EPP data cycle, so do nothing */ pdebug("we%02x s\n", val); else { struct ParallelIOArg ioarg = { .buffer = &parm, .count = 1 }; if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg)) { s->epp_timeout = 1; pdebug("we%02x t\n", val); } else pdebug("we%02x\n", val); } break; } } static void parallel_ioport_eppdata_write_hw2(void *opaque, uint32_t addr, uint32_t val) { ParallelState *s = opaque; uint16_t eppdata = cpu_to_le16(val); int err; struct ParallelIOArg ioarg = { .buffer = &eppdata, .count = sizeof(eppdata) }; if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) { /* Controls not correct for EPP data cycle, so do nothing */ pdebug("we%04x s\n", val); return; } err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg); if (err) { s->epp_timeout = 1; pdebug("we%04x t\n", val); } else pdebug("we%04x\n", val); } static void parallel_ioport_eppdata_write_hw4(void *opaque, uint32_t addr, uint32_t val) { ParallelState *s = opaque; uint32_t eppdata = cpu_to_le32(val); int err; struct ParallelIOArg ioarg = { .buffer = &eppdata, .count = sizeof(eppdata) }; if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) { /* Controls not correct for EPP data cycle, so do nothing */ pdebug("we%08x s\n", val); return; } err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg); if (err) { s->epp_timeout = 1; pdebug("we%08x t\n", val); } else pdebug("we%08x\n", val); } static uint32_t parallel_ioport_read_sw(void *opaque, uint32_t addr) { ParallelState *s = opaque; uint32_t ret = 0xff; addr &= 7; switch(addr) { case PARA_REG_DATA: if (s->control & PARA_CTR_DIR) ret = s->datar; else ret = s->dataw; break; case PARA_REG_STS: ret = s->status; s->irq_pending = 0; if ((s->status & PARA_STS_BUSY) == 0 && (s->control & PARA_CTR_STROBE) == 0) { /* XXX Fixme: wait 5 microseconds */ if (s->status & PARA_STS_ACK) s->status &= ~PARA_STS_ACK; else { /* XXX Fixme: wait 5 microseconds */ s->status |= PARA_STS_ACK; s->status |= PARA_STS_BUSY; } } parallel_update_irq(s); break; case PARA_REG_CTR: ret = s->control; break; } pdebug("read addr=0x%02x val=0x%02x\n", addr, ret); return ret; } static uint32_t parallel_ioport_read_hw(void *opaque, uint32_t addr) { ParallelState *s = opaque; uint8_t ret = 0xff; addr &= 7; switch(addr) { case PARA_REG_DATA: qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_DATA, &ret); if (s->last_read_offset != addr || s->datar != ret) pdebug("rd%02x\n", ret); s->datar = ret; break; case PARA_REG_STS: qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_STATUS, &ret); ret &= ~PARA_STS_TMOUT; if (s->epp_timeout) ret |= PARA_STS_TMOUT; if (s->last_read_offset != addr || s->status != ret) pdebug("rs%02x\n", ret); s->status = ret; break; case PARA_REG_CTR: /* s->control has some bits fixed to 1. It is zero only when it has not been yet written to. */ if (s->control == 0) { qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_CONTROL, &ret); if (s->last_read_offset != addr) pdebug("rc%02x\n", ret); s->control = ret; } else { ret = s->control; if (s->last_read_offset != addr) pdebug("rc%02x\n", ret); } break; case PARA_REG_EPP_ADDR: if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) /* Controls not correct for EPP addr cycle, so do nothing */ pdebug("ra%02x s\n", ret); else { struct ParallelIOArg ioarg = { .buffer = &ret, .count = 1 }; if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ_ADDR, &ioarg)) { s->epp_timeout = 1; pdebug("ra%02x t\n", ret); } else pdebug("ra%02x\n", ret); } break; case PARA_REG_EPP_DATA: if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) /* Controls not correct for EPP data cycle, so do nothing */ pdebug("re%02x s\n", ret); else { struct ParallelIOArg ioarg = { .buffer = &ret, .count = 1 }; if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg)) { s->epp_timeout = 1; pdebug("re%02x t\n", ret); } else pdebug("re%02x\n", ret); } break; } s->last_read_offset = addr; return ret; } static uint32_t parallel_ioport_eppdata_read_hw2(void *opaque, uint32_t addr) { ParallelState *s = opaque; uint32_t ret; uint16_t eppdata = ~0; int err; struct ParallelIOArg ioarg = { .buffer = &eppdata, .count = sizeof(eppdata) }; if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) { /* Controls not correct for EPP data cycle, so do nothing */ pdebug("re%04x s\n", eppdata); return eppdata; } err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg); ret = le16_to_cpu(eppdata); if (err) { s->epp_timeout = 1; pdebug("re%04x t\n", ret); } else pdebug("re%04x\n", ret); return ret; } static uint32_t parallel_ioport_eppdata_read_hw4(void *opaque, uint32_t addr) { ParallelState *s = opaque; uint32_t ret; uint32_t eppdata = ~0U; int err; struct ParallelIOArg ioarg = { .buffer = &eppdata, .count = sizeof(eppdata) }; if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) { /* Controls not correct for EPP data cycle, so do nothing */ pdebug("re%08x s\n", eppdata); return eppdata; } err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg); ret = le32_to_cpu(eppdata); if (err) { s->epp_timeout = 1; pdebug("re%08x t\n", ret); } else pdebug("re%08x\n", ret); return ret; } static void parallel_ioport_ecp_write(void *opaque, uint32_t addr, uint32_t val) { addr &= 7; pdebug("wecp%d=%02x\n", addr, val); } static uint32_t parallel_ioport_ecp_read(void *opaque, uint32_t addr) { uint8_t ret = 0xff; addr &= 7; pdebug("recp%d:%02x\n", addr, ret); return ret; }