12a6505b0SSven Schnelle /* 22a6505b0SSven Schnelle * QEMU HP Lasi PS/2 interface emulation 32a6505b0SSven Schnelle * 42a6505b0SSven Schnelle * Copyright (c) 2019 Sven Schnelle 52a6505b0SSven Schnelle * 62a6505b0SSven Schnelle * Permission is hereby granted, free of charge, to any person obtaining a copy 72a6505b0SSven Schnelle * of this software and associated documentation files (the "Software"), to deal 82a6505b0SSven Schnelle * in the Software without restriction, including without limitation the rights 92a6505b0SSven Schnelle * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 102a6505b0SSven Schnelle * copies of the Software, and to permit persons to whom the Software is 112a6505b0SSven Schnelle * furnished to do so, subject to the following conditions: 122a6505b0SSven Schnelle * 132a6505b0SSven Schnelle * The above copyright notice and this permission notice shall be included in 142a6505b0SSven Schnelle * all copies or substantial portions of the Software. 152a6505b0SSven Schnelle * 162a6505b0SSven Schnelle * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 172a6505b0SSven Schnelle * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 182a6505b0SSven Schnelle * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 192a6505b0SSven Schnelle * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 202a6505b0SSven Schnelle * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 212a6505b0SSven Schnelle * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 222a6505b0SSven Schnelle * THE SOFTWARE. 232a6505b0SSven Schnelle */ 242a6505b0SSven Schnelle #include "qemu/osdep.h" 252a6505b0SSven Schnelle #include "qemu/log.h" 262a6505b0SSven Schnelle #include "hw/qdev-properties.h" 27653b388cSMark Cave-Ayland #include "hw/sysbus.h" 282a6505b0SSven Schnelle #include "hw/input/ps2.h" 292a6505b0SSven Schnelle #include "hw/input/lasips2.h" 302a6505b0SSven Schnelle #include "exec/hwaddr.h" 312a6505b0SSven Schnelle #include "trace.h" 322a6505b0SSven Schnelle #include "exec/address-spaces.h" 332a6505b0SSven Schnelle #include "migration/vmstate.h" 342a6505b0SSven Schnelle #include "hw/irq.h" 35653b388cSMark Cave-Ayland #include "qapi/error.h" 362a6505b0SSven Schnelle 372a6505b0SSven Schnelle 382a6505b0SSven Schnelle static const VMStateDescription vmstate_lasips2 = { 392a6505b0SSven Schnelle .name = "lasips2", 402a6505b0SSven Schnelle .version_id = 0, 412a6505b0SSven Schnelle .minimum_version_id = 0, 422a6505b0SSven Schnelle .fields = (VMStateField[]) { 43b7047733SMark Cave-Ayland VMSTATE_UINT8(kbd_port.parent_obj.control, LASIPS2State), 44b7047733SMark Cave-Ayland VMSTATE_UINT8(kbd_port.parent_obj.id, LASIPS2State), 45c553d6c0SMark Cave-Ayland VMSTATE_BOOL(kbd_port.parent_obj.birq, LASIPS2State), 46a088ce9bSMark Cave-Ayland VMSTATE_UINT8(mouse_port.parent_obj.control, LASIPS2State), 47a088ce9bSMark Cave-Ayland VMSTATE_UINT8(mouse_port.parent_obj.id, LASIPS2State), 48c553d6c0SMark Cave-Ayland VMSTATE_BOOL(mouse_port.parent_obj.birq, LASIPS2State), 492a6505b0SSven Schnelle VMSTATE_END_OF_LIST() 502a6505b0SSven Schnelle } 512a6505b0SSven Schnelle }; 522a6505b0SSven Schnelle 532a6505b0SSven Schnelle typedef enum { 542a6505b0SSven Schnelle REG_PS2_ID = 0, 552a6505b0SSven Schnelle REG_PS2_RCVDATA = 4, 562a6505b0SSven Schnelle REG_PS2_CONTROL = 8, 572a6505b0SSven Schnelle REG_PS2_STATUS = 12, 582a6505b0SSven Schnelle } lasips2_read_reg_t; 592a6505b0SSven Schnelle 602a6505b0SSven Schnelle typedef enum { 612a6505b0SSven Schnelle REG_PS2_RESET = 0, 622a6505b0SSven Schnelle REG_PS2_XMTDATA = 4, 632a6505b0SSven Schnelle } lasips2_write_reg_t; 642a6505b0SSven Schnelle 652a6505b0SSven Schnelle typedef enum { 662a6505b0SSven Schnelle LASIPS2_CONTROL_ENABLE = 0x01, 672a6505b0SSven Schnelle LASIPS2_CONTROL_LOOPBACK = 0x02, 682a6505b0SSven Schnelle LASIPS2_CONTROL_DIAG = 0x20, 692a6505b0SSven Schnelle LASIPS2_CONTROL_DATDIR = 0x40, 702a6505b0SSven Schnelle LASIPS2_CONTROL_CLKDIR = 0x80, 712a6505b0SSven Schnelle } lasips2_control_reg_t; 722a6505b0SSven Schnelle 732a6505b0SSven Schnelle typedef enum { 742a6505b0SSven Schnelle LASIPS2_STATUS_RBNE = 0x01, 752a6505b0SSven Schnelle LASIPS2_STATUS_TBNE = 0x02, 762a6505b0SSven Schnelle LASIPS2_STATUS_TERR = 0x04, 772a6505b0SSven Schnelle LASIPS2_STATUS_PERR = 0x08, 782a6505b0SSven Schnelle LASIPS2_STATUS_CMPINTR = 0x10, 792a6505b0SSven Schnelle LASIPS2_STATUS_DATSHD = 0x40, 802a6505b0SSven Schnelle LASIPS2_STATUS_CLKSHD = 0x80, 812a6505b0SSven Schnelle } lasips2_status_reg_t; 822a6505b0SSven Schnelle 835d2bd735SPhilippe Mathieu-Daudé static const char *lasips2_read_reg_name(uint64_t addr) 842a6505b0SSven Schnelle { 852a6505b0SSven Schnelle switch (addr & 0xc) { 862a6505b0SSven Schnelle case REG_PS2_ID: 872a6505b0SSven Schnelle return " PS2_ID"; 882a6505b0SSven Schnelle 892a6505b0SSven Schnelle case REG_PS2_RCVDATA: 902a6505b0SSven Schnelle return " PS2_RCVDATA"; 912a6505b0SSven Schnelle 922a6505b0SSven Schnelle case REG_PS2_CONTROL: 932a6505b0SSven Schnelle return " PS2_CONTROL"; 942a6505b0SSven Schnelle 952a6505b0SSven Schnelle case REG_PS2_STATUS: 962a6505b0SSven Schnelle return " PS2_STATUS"; 972a6505b0SSven Schnelle 982a6505b0SSven Schnelle default: 992a6505b0SSven Schnelle return ""; 1002a6505b0SSven Schnelle } 1012a6505b0SSven Schnelle } 1022a6505b0SSven Schnelle 1035d2bd735SPhilippe Mathieu-Daudé static const char *lasips2_write_reg_name(uint64_t addr) 1042a6505b0SSven Schnelle { 1052a6505b0SSven Schnelle switch (addr & 0x0c) { 1062a6505b0SSven Schnelle case REG_PS2_RESET: 1072a6505b0SSven Schnelle return " PS2_RESET"; 1082a6505b0SSven Schnelle 1092a6505b0SSven Schnelle case REG_PS2_XMTDATA: 1102a6505b0SSven Schnelle return " PS2_XMTDATA"; 1112a6505b0SSven Schnelle 1122a6505b0SSven Schnelle case REG_PS2_CONTROL: 1132a6505b0SSven Schnelle return " PS2_CONTROL"; 1142a6505b0SSven Schnelle 1152a6505b0SSven Schnelle default: 1162a6505b0SSven Schnelle return ""; 1172a6505b0SSven Schnelle } 1182a6505b0SSven Schnelle } 1192a6505b0SSven Schnelle 1202a6505b0SSven Schnelle static void lasips2_update_irq(LASIPS2State *s) 1212a6505b0SSven Schnelle { 122c553d6c0SMark Cave-Ayland trace_lasips2_intr(s->kbd_port.parent_obj.birq | 123c553d6c0SMark Cave-Ayland s->mouse_port.parent_obj.birq); 124c553d6c0SMark Cave-Ayland qemu_set_irq(s->irq, s->kbd_port.parent_obj.birq | 125c553d6c0SMark Cave-Ayland s->mouse_port.parent_obj.birq); 1262a6505b0SSven Schnelle } 1272a6505b0SSven Schnelle 128*ca735a81SMark Cave-Ayland static void lasips2_set_irq(void *opaque, int n, int level) 129*ca735a81SMark Cave-Ayland { 130*ca735a81SMark Cave-Ayland LASIPS2State *s = LASIPS2(opaque); 131*ca735a81SMark Cave-Ayland 132*ca735a81SMark Cave-Ayland if (level) { 133*ca735a81SMark Cave-Ayland s->int_status |= BIT(n); 134*ca735a81SMark Cave-Ayland } else { 135*ca735a81SMark Cave-Ayland s->int_status &= ~BIT(n); 136*ca735a81SMark Cave-Ayland } 137*ca735a81SMark Cave-Ayland 138*ca735a81SMark Cave-Ayland lasips2_update_irq(s); 139*ca735a81SMark Cave-Ayland } 140*ca735a81SMark Cave-Ayland 1412a6505b0SSven Schnelle static void lasips2_reg_write(void *opaque, hwaddr addr, uint64_t val, 1422a6505b0SSven Schnelle unsigned size) 1432a6505b0SSven Schnelle { 1442a6505b0SSven Schnelle LASIPS2Port *port = opaque; 1452a6505b0SSven Schnelle 1462a6505b0SSven Schnelle trace_lasips2_reg_write(size, port->id, addr, 1475d2bd735SPhilippe Mathieu-Daudé lasips2_write_reg_name(addr), val); 1482a6505b0SSven Schnelle 1492a6505b0SSven Schnelle switch (addr & 0xc) { 1502a6505b0SSven Schnelle case REG_PS2_CONTROL: 1512a6505b0SSven Schnelle port->control = val; 1522a6505b0SSven Schnelle break; 1532a6505b0SSven Schnelle 1542a6505b0SSven Schnelle case REG_PS2_XMTDATA: 1552a6505b0SSven Schnelle if (port->control & LASIPS2_CONTROL_LOOPBACK) { 1562a6505b0SSven Schnelle port->buf = val; 157c553d6c0SMark Cave-Ayland port->birq = true; 1582a6505b0SSven Schnelle port->loopback_rbne = true; 1592a6505b0SSven Schnelle lasips2_update_irq(port->parent); 1602a6505b0SSven Schnelle break; 1612a6505b0SSven Schnelle } 1622a6505b0SSven Schnelle 1632a6505b0SSven Schnelle if (port->id) { 164f4907cb5SMark Cave-Ayland ps2_write_mouse(PS2_MOUSE_DEVICE(port->ps2dev), val); 1652a6505b0SSven Schnelle } else { 166f4907cb5SMark Cave-Ayland ps2_write_keyboard(PS2_KBD_DEVICE(port->ps2dev), val); 1672a6505b0SSven Schnelle } 1682a6505b0SSven Schnelle break; 1692a6505b0SSven Schnelle 1702a6505b0SSven Schnelle case REG_PS2_RESET: 1712a6505b0SSven Schnelle break; 1722a6505b0SSven Schnelle 1732a6505b0SSven Schnelle default: 1742a6505b0SSven Schnelle qemu_log_mask(LOG_UNIMP, "%s: unknown register 0x%02" HWADDR_PRIx "\n", 1752a6505b0SSven Schnelle __func__, addr); 1762a6505b0SSven Schnelle break; 1772a6505b0SSven Schnelle } 1782a6505b0SSven Schnelle } 1792a6505b0SSven Schnelle 1802a6505b0SSven Schnelle static uint64_t lasips2_reg_read(void *opaque, hwaddr addr, unsigned size) 1812a6505b0SSven Schnelle { 1822a6505b0SSven Schnelle LASIPS2Port *port = opaque; 1832a6505b0SSven Schnelle uint64_t ret = 0; 1842a6505b0SSven Schnelle 1852a6505b0SSven Schnelle switch (addr & 0xc) { 1862a6505b0SSven Schnelle case REG_PS2_ID: 1872a6505b0SSven Schnelle ret = port->id; 1882a6505b0SSven Schnelle break; 1892a6505b0SSven Schnelle 1902a6505b0SSven Schnelle case REG_PS2_RCVDATA: 1912a6505b0SSven Schnelle if (port->control & LASIPS2_CONTROL_LOOPBACK) { 192c553d6c0SMark Cave-Ayland port->birq = false; 1932a6505b0SSven Schnelle port->loopback_rbne = false; 1942a6505b0SSven Schnelle lasips2_update_irq(port->parent); 1952a6505b0SSven Schnelle ret = port->buf; 1962a6505b0SSven Schnelle break; 1972a6505b0SSven Schnelle } 1982a6505b0SSven Schnelle 199f4907cb5SMark Cave-Ayland ret = ps2_read_data(port->ps2dev); 2002a6505b0SSven Schnelle break; 2012a6505b0SSven Schnelle 2022a6505b0SSven Schnelle case REG_PS2_CONTROL: 2032a6505b0SSven Schnelle ret = port->control; 2042a6505b0SSven Schnelle break; 2052a6505b0SSven Schnelle 2062a6505b0SSven Schnelle case REG_PS2_STATUS: 2072a6505b0SSven Schnelle ret = LASIPS2_STATUS_DATSHD | LASIPS2_STATUS_CLKSHD; 2082a6505b0SSven Schnelle 2092a6505b0SSven Schnelle if (port->control & LASIPS2_CONTROL_DIAG) { 2102a6505b0SSven Schnelle if (!(port->control & LASIPS2_CONTROL_DATDIR)) { 2112a6505b0SSven Schnelle ret &= ~LASIPS2_STATUS_DATSHD; 2122a6505b0SSven Schnelle } 2132a6505b0SSven Schnelle 2142a6505b0SSven Schnelle if (!(port->control & LASIPS2_CONTROL_CLKDIR)) { 2152a6505b0SSven Schnelle ret &= ~LASIPS2_STATUS_CLKSHD; 2162a6505b0SSven Schnelle } 2172a6505b0SSven Schnelle } 2182a6505b0SSven Schnelle 2192a6505b0SSven Schnelle if (port->control & LASIPS2_CONTROL_LOOPBACK) { 2202a6505b0SSven Schnelle if (port->loopback_rbne) { 2212a6505b0SSven Schnelle ret |= LASIPS2_STATUS_RBNE; 2222a6505b0SSven Schnelle } 2232a6505b0SSven Schnelle } else { 224f4907cb5SMark Cave-Ayland if (!ps2_queue_empty(port->ps2dev)) { 2252a6505b0SSven Schnelle ret |= LASIPS2_STATUS_RBNE; 2262a6505b0SSven Schnelle } 2272a6505b0SSven Schnelle } 2282a6505b0SSven Schnelle 229c553d6c0SMark Cave-Ayland if (port->parent->kbd_port.parent_obj.birq || 230c553d6c0SMark Cave-Ayland port->parent->mouse_port.parent_obj.birq) { 2312a6505b0SSven Schnelle ret |= LASIPS2_STATUS_CMPINTR; 2322a6505b0SSven Schnelle } 2332a6505b0SSven Schnelle break; 2342a6505b0SSven Schnelle 2352a6505b0SSven Schnelle default: 2362a6505b0SSven Schnelle qemu_log_mask(LOG_UNIMP, "%s: unknown register 0x%02" HWADDR_PRIx "\n", 2372a6505b0SSven Schnelle __func__, addr); 2382a6505b0SSven Schnelle break; 2392a6505b0SSven Schnelle } 2402a93d3c1SMark Cave-Ayland 2412a6505b0SSven Schnelle trace_lasips2_reg_read(size, port->id, addr, 2425d2bd735SPhilippe Mathieu-Daudé lasips2_read_reg_name(addr), ret); 2432a6505b0SSven Schnelle return ret; 2442a6505b0SSven Schnelle } 2452a6505b0SSven Schnelle 2462a6505b0SSven Schnelle static const MemoryRegionOps lasips2_reg_ops = { 2472a6505b0SSven Schnelle .read = lasips2_reg_read, 2482a6505b0SSven Schnelle .write = lasips2_reg_write, 2492a6505b0SSven Schnelle .impl = { 2502a6505b0SSven Schnelle .min_access_size = 1, 2512a6505b0SSven Schnelle .max_access_size = 4, 2522a6505b0SSven Schnelle }, 2532a6505b0SSven Schnelle .endianness = DEVICE_NATIVE_ENDIAN, 2542a6505b0SSven Schnelle }; 2552a6505b0SSven Schnelle 2560d1ac496SMark Cave-Ayland static void lasips2_set_kbd_irq(void *opaque, int n, int level) 2572a6505b0SSven Schnelle { 2580d1ac496SMark Cave-Ayland LASIPS2State *s = LASIPS2(opaque); 259b7047733SMark Cave-Ayland LASIPS2Port *port = LASIPS2_PORT(&s->kbd_port); 2600d1ac496SMark Cave-Ayland 261c553d6c0SMark Cave-Ayland port->birq = level; 2620d1ac496SMark Cave-Ayland lasips2_update_irq(port->parent); 2630d1ac496SMark Cave-Ayland } 2640d1ac496SMark Cave-Ayland 2650d1ac496SMark Cave-Ayland static void lasips2_set_mouse_irq(void *opaque, int n, int level) 2660d1ac496SMark Cave-Ayland { 2670d1ac496SMark Cave-Ayland LASIPS2State *s = LASIPS2(opaque); 268a088ce9bSMark Cave-Ayland LASIPS2Port *port = LASIPS2_PORT(&s->mouse_port); 2692a93d3c1SMark Cave-Ayland 270c553d6c0SMark Cave-Ayland port->birq = level; 2712a6505b0SSven Schnelle lasips2_update_irq(port->parent); 2722a6505b0SSven Schnelle } 2732a6505b0SSven Schnelle 2741702627cSMark Cave-Ayland static void lasips2_realize(DeviceState *dev, Error **errp) 2751702627cSMark Cave-Ayland { 2761702627cSMark Cave-Ayland LASIPS2State *s = LASIPS2(dev); 277b7047733SMark Cave-Ayland LASIPS2Port *lp; 2781702627cSMark Cave-Ayland 279b7047733SMark Cave-Ayland lp = LASIPS2_PORT(&s->kbd_port); 280b7047733SMark Cave-Ayland if (!(qdev_realize(DEVICE(lp), NULL, errp))) { 281b7047733SMark Cave-Ayland return; 282b7047733SMark Cave-Ayland } 283b7047733SMark Cave-Ayland 284b7047733SMark Cave-Ayland qdev_connect_gpio_out(DEVICE(lp->ps2dev), PS2_DEVICE_IRQ, 2850d1ac496SMark Cave-Ayland qdev_get_gpio_in_named(dev, "ps2-kbd-input-irq", 2860d1ac496SMark Cave-Ayland 0)); 287a088ce9bSMark Cave-Ayland 288a088ce9bSMark Cave-Ayland lp = LASIPS2_PORT(&s->mouse_port); 289a088ce9bSMark Cave-Ayland if (!(qdev_realize(DEVICE(lp), NULL, errp))) { 290a088ce9bSMark Cave-Ayland return; 291a088ce9bSMark Cave-Ayland } 292a088ce9bSMark Cave-Ayland 293a088ce9bSMark Cave-Ayland qdev_connect_gpio_out(DEVICE(lp->ps2dev), PS2_DEVICE_IRQ, 2940d1ac496SMark Cave-Ayland qdev_get_gpio_in_named(dev, "ps2-mouse-input-irq", 2950d1ac496SMark Cave-Ayland 0)); 2962a6505b0SSven Schnelle } 297653b388cSMark Cave-Ayland 29863195aa5SMark Cave-Ayland static void lasips2_init(Object *obj) 29963195aa5SMark Cave-Ayland { 30063195aa5SMark Cave-Ayland LASIPS2State *s = LASIPS2(obj); 301b7047733SMark Cave-Ayland LASIPS2Port *lp; 30263195aa5SMark Cave-Ayland 303b7047733SMark Cave-Ayland object_initialize_child(obj, "lasips2-kbd-port", &s->kbd_port, 304b7047733SMark Cave-Ayland TYPE_LASIPS2_KBD_PORT); 305a088ce9bSMark Cave-Ayland object_initialize_child(obj, "lasips2-mouse-port", &s->mouse_port, 306a088ce9bSMark Cave-Ayland TYPE_LASIPS2_MOUSE_PORT); 30763195aa5SMark Cave-Ayland 308b7047733SMark Cave-Ayland lp = LASIPS2_PORT(&s->kbd_port); 309b7047733SMark Cave-Ayland sysbus_init_mmio(SYS_BUS_DEVICE(obj), &lp->reg); 310a088ce9bSMark Cave-Ayland lp = LASIPS2_PORT(&s->mouse_port); 311a088ce9bSMark Cave-Ayland sysbus_init_mmio(SYS_BUS_DEVICE(obj), &lp->reg); 31297bc0597SMark Cave-Ayland 31397bc0597SMark Cave-Ayland sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq); 3140d1ac496SMark Cave-Ayland 3150d1ac496SMark Cave-Ayland qdev_init_gpio_in_named(DEVICE(obj), lasips2_set_kbd_irq, 3160d1ac496SMark Cave-Ayland "ps2-kbd-input-irq", 1); 3170d1ac496SMark Cave-Ayland qdev_init_gpio_in_named(DEVICE(obj), lasips2_set_mouse_irq, 3180d1ac496SMark Cave-Ayland "ps2-mouse-input-irq", 1); 319*ca735a81SMark Cave-Ayland qdev_init_gpio_in_named(DEVICE(obj), lasips2_set_irq, 320*ca735a81SMark Cave-Ayland "lasips2-port-input-irq", 2); 32163195aa5SMark Cave-Ayland } 32263195aa5SMark Cave-Ayland 32342119fdbSMark Cave-Ayland static void lasips2_class_init(ObjectClass *klass, void *data) 32442119fdbSMark Cave-Ayland { 32542119fdbSMark Cave-Ayland DeviceClass *dc = DEVICE_CLASS(klass); 32642119fdbSMark Cave-Ayland 3271702627cSMark Cave-Ayland dc->realize = lasips2_realize; 32817b8013aSMark Cave-Ayland dc->vmsd = &vmstate_lasips2; 32942119fdbSMark Cave-Ayland set_bit(DEVICE_CATEGORY_INPUT, dc->categories); 33042119fdbSMark Cave-Ayland } 33142119fdbSMark Cave-Ayland 332653b388cSMark Cave-Ayland static const TypeInfo lasips2_info = { 333653b388cSMark Cave-Ayland .name = TYPE_LASIPS2, 334653b388cSMark Cave-Ayland .parent = TYPE_SYS_BUS_DEVICE, 33563195aa5SMark Cave-Ayland .instance_init = lasips2_init, 33642119fdbSMark Cave-Ayland .instance_size = sizeof(LASIPS2State), 33742119fdbSMark Cave-Ayland .class_init = lasips2_class_init, 338653b388cSMark Cave-Ayland }; 339653b388cSMark Cave-Ayland 340d0af5d6aSMark Cave-Ayland static void lasips2_port_set_irq(void *opaque, int n, int level) 341d0af5d6aSMark Cave-Ayland { 342d0af5d6aSMark Cave-Ayland LASIPS2Port *s = LASIPS2_PORT(opaque); 343d0af5d6aSMark Cave-Ayland 344d0af5d6aSMark Cave-Ayland qemu_set_irq(s->irq, level); 345d0af5d6aSMark Cave-Ayland } 346d0af5d6aSMark Cave-Ayland 347d0af5d6aSMark Cave-Ayland static void lasips2_port_realize(DeviceState *dev, Error **errp) 348d0af5d6aSMark Cave-Ayland { 349d0af5d6aSMark Cave-Ayland LASIPS2Port *s = LASIPS2_PORT(dev); 350d0af5d6aSMark Cave-Ayland 351d0af5d6aSMark Cave-Ayland qdev_connect_gpio_out(DEVICE(s->ps2dev), PS2_DEVICE_IRQ, 352d0af5d6aSMark Cave-Ayland qdev_get_gpio_in_named(dev, "ps2-input-irq", 0)); 353d0af5d6aSMark Cave-Ayland } 354d0af5d6aSMark Cave-Ayland 3558db817beSMark Cave-Ayland static void lasips2_port_init(Object *obj) 3568db817beSMark Cave-Ayland { 3578db817beSMark Cave-Ayland LASIPS2Port *s = LASIPS2_PORT(obj); 3588db817beSMark Cave-Ayland 3598db817beSMark Cave-Ayland qdev_init_gpio_out(DEVICE(obj), &s->irq, 1); 360d0af5d6aSMark Cave-Ayland qdev_init_gpio_in_named(DEVICE(obj), lasips2_port_set_irq, 361d0af5d6aSMark Cave-Ayland "ps2-input-irq", 1); 362d0af5d6aSMark Cave-Ayland } 363d0af5d6aSMark Cave-Ayland 364d0af5d6aSMark Cave-Ayland static void lasips2_port_class_init(ObjectClass *klass, void *data) 365d0af5d6aSMark Cave-Ayland { 366d0af5d6aSMark Cave-Ayland DeviceClass *dc = DEVICE_CLASS(klass); 367d0af5d6aSMark Cave-Ayland 368d0af5d6aSMark Cave-Ayland dc->realize = lasips2_port_realize; 3698db817beSMark Cave-Ayland } 3708db817beSMark Cave-Ayland 371f8d89a7dSMark Cave-Ayland static const TypeInfo lasips2_port_info = { 372f8d89a7dSMark Cave-Ayland .name = TYPE_LASIPS2_PORT, 373f8d89a7dSMark Cave-Ayland .parent = TYPE_DEVICE, 3748db817beSMark Cave-Ayland .instance_init = lasips2_port_init, 375f8d89a7dSMark Cave-Ayland .instance_size = sizeof(LASIPS2Port), 37662201e43SMark Cave-Ayland .class_init = lasips2_port_class_init, 37762201e43SMark Cave-Ayland .class_size = sizeof(LASIPS2PortDeviceClass), 378f8d89a7dSMark Cave-Ayland .abstract = true, 379f8d89a7dSMark Cave-Ayland }; 380f8d89a7dSMark Cave-Ayland 381b41eee94SMark Cave-Ayland static void lasips2_kbd_port_realize(DeviceState *dev, Error **errp) 382b41eee94SMark Cave-Ayland { 383b41eee94SMark Cave-Ayland LASIPS2Port *lp = LASIPS2_PORT(dev); 384b41eee94SMark Cave-Ayland 385b41eee94SMark Cave-Ayland lp->ps2dev = ps2_kbd_init(); 386b41eee94SMark Cave-Ayland } 387b41eee94SMark Cave-Ayland 388b7047733SMark Cave-Ayland static void lasips2_kbd_port_init(Object *obj) 389b7047733SMark Cave-Ayland { 390b7047733SMark Cave-Ayland LASIPS2KbdPort *s = LASIPS2_KBD_PORT(obj); 391b7047733SMark Cave-Ayland LASIPS2Port *lp = LASIPS2_PORT(obj); 392b7047733SMark Cave-Ayland 393b7047733SMark Cave-Ayland memory_region_init_io(&lp->reg, obj, &lasips2_reg_ops, lp, "lasips2-kbd", 394b7047733SMark Cave-Ayland 0x100); 395b7047733SMark Cave-Ayland lp->id = 0; 396b7047733SMark Cave-Ayland lp->parent = container_of(s, LASIPS2State, kbd_port); 397b7047733SMark Cave-Ayland } 398b7047733SMark Cave-Ayland 399b41eee94SMark Cave-Ayland static void lasips2_kbd_port_class_init(ObjectClass *klass, void *data) 400b41eee94SMark Cave-Ayland { 401b41eee94SMark Cave-Ayland DeviceClass *dc = DEVICE_CLASS(klass); 402d0af5d6aSMark Cave-Ayland LASIPS2PortDeviceClass *lpdc = LASIPS2_PORT_CLASS(klass); 403b41eee94SMark Cave-Ayland 404d0af5d6aSMark Cave-Ayland device_class_set_parent_realize(dc, lasips2_kbd_port_realize, 405d0af5d6aSMark Cave-Ayland &lpdc->parent_realize); 406b41eee94SMark Cave-Ayland } 407b41eee94SMark Cave-Ayland 408ef90a06fSMark Cave-Ayland static const TypeInfo lasips2_kbd_port_info = { 409ef90a06fSMark Cave-Ayland .name = TYPE_LASIPS2_KBD_PORT, 410ef90a06fSMark Cave-Ayland .parent = TYPE_LASIPS2_PORT, 411ef90a06fSMark Cave-Ayland .instance_size = sizeof(LASIPS2KbdPort), 412b7047733SMark Cave-Ayland .instance_init = lasips2_kbd_port_init, 413b41eee94SMark Cave-Ayland .class_init = lasips2_kbd_port_class_init, 414ef90a06fSMark Cave-Ayland }; 415ef90a06fSMark Cave-Ayland 4168d490f8dSMark Cave-Ayland static void lasips2_mouse_port_realize(DeviceState *dev, Error **errp) 4178d490f8dSMark Cave-Ayland { 4188d490f8dSMark Cave-Ayland LASIPS2Port *lp = LASIPS2_PORT(dev); 4198d490f8dSMark Cave-Ayland 4208d490f8dSMark Cave-Ayland lp->ps2dev = ps2_mouse_init(); 4218d490f8dSMark Cave-Ayland } 4228d490f8dSMark Cave-Ayland 423a088ce9bSMark Cave-Ayland static void lasips2_mouse_port_init(Object *obj) 424a088ce9bSMark Cave-Ayland { 425a088ce9bSMark Cave-Ayland LASIPS2MousePort *s = LASIPS2_MOUSE_PORT(obj); 426a088ce9bSMark Cave-Ayland LASIPS2Port *lp = LASIPS2_PORT(obj); 427a088ce9bSMark Cave-Ayland 428a088ce9bSMark Cave-Ayland memory_region_init_io(&lp->reg, obj, &lasips2_reg_ops, lp, "lasips2-mouse", 429a088ce9bSMark Cave-Ayland 0x100); 430a088ce9bSMark Cave-Ayland lp->id = 1; 431a088ce9bSMark Cave-Ayland lp->parent = container_of(s, LASIPS2State, mouse_port); 432a088ce9bSMark Cave-Ayland } 433a088ce9bSMark Cave-Ayland 4348d490f8dSMark Cave-Ayland static void lasips2_mouse_port_class_init(ObjectClass *klass, void *data) 4358d490f8dSMark Cave-Ayland { 4368d490f8dSMark Cave-Ayland DeviceClass *dc = DEVICE_CLASS(klass); 437d0af5d6aSMark Cave-Ayland LASIPS2PortDeviceClass *lpdc = LASIPS2_PORT_CLASS(klass); 4388d490f8dSMark Cave-Ayland 439d0af5d6aSMark Cave-Ayland device_class_set_parent_realize(dc, lasips2_mouse_port_realize, 440d0af5d6aSMark Cave-Ayland &lpdc->parent_realize); 4418d490f8dSMark Cave-Ayland } 4428d490f8dSMark Cave-Ayland 443cb5827ceSMark Cave-Ayland static const TypeInfo lasips2_mouse_port_info = { 444cb5827ceSMark Cave-Ayland .name = TYPE_LASIPS2_MOUSE_PORT, 445cb5827ceSMark Cave-Ayland .parent = TYPE_LASIPS2_PORT, 446cb5827ceSMark Cave-Ayland .instance_size = sizeof(LASIPS2MousePort), 447a088ce9bSMark Cave-Ayland .instance_init = lasips2_mouse_port_init, 4488d490f8dSMark Cave-Ayland .class_init = lasips2_mouse_port_class_init, 449cb5827ceSMark Cave-Ayland }; 450cb5827ceSMark Cave-Ayland 451653b388cSMark Cave-Ayland static void lasips2_register_types(void) 452653b388cSMark Cave-Ayland { 453653b388cSMark Cave-Ayland type_register_static(&lasips2_info); 454f8d89a7dSMark Cave-Ayland type_register_static(&lasips2_port_info); 455ef90a06fSMark Cave-Ayland type_register_static(&lasips2_kbd_port_info); 456cb5827ceSMark Cave-Ayland type_register_static(&lasips2_mouse_port_info); 457653b388cSMark Cave-Ayland } 458653b388cSMark Cave-Ayland 459653b388cSMark Cave-Ayland type_init(lasips2_register_types) 460