2004-03-14 13:20:30 +01:00
|
|
|
/*
|
|
|
|
* QEMU PC keyboard emulation
|
2007-09-16 23:08:06 +02:00
|
|
|
*
|
2004-03-14 13:20:30 +01:00
|
|
|
* Copyright (c) 2003 Fabrice Bellard
|
2007-09-16 23:08:06 +02:00
|
|
|
*
|
2004-03-14 13:20:30 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2007-11-17 18:14:51 +01:00
|
|
|
#include "hw.h"
|
|
|
|
#include "isa.h"
|
|
|
|
#include "pc.h"
|
|
|
|
#include "ps2.h"
|
|
|
|
#include "sysemu.h"
|
2004-03-14 13:20:30 +01:00
|
|
|
|
|
|
|
/* debug PC keyboard */
|
|
|
|
//#define DEBUG_KBD
|
|
|
|
|
|
|
|
/* debug PC keyboard : only mouse */
|
|
|
|
//#define DEBUG_MOUSE
|
|
|
|
|
|
|
|
/* Keyboard Controller Commands */
|
|
|
|
#define KBD_CCMD_READ_MODE 0x20 /* Read mode bits */
|
|
|
|
#define KBD_CCMD_WRITE_MODE 0x60 /* Write mode bits */
|
|
|
|
#define KBD_CCMD_GET_VERSION 0xA1 /* Get controller version */
|
|
|
|
#define KBD_CCMD_MOUSE_DISABLE 0xA7 /* Disable mouse interface */
|
|
|
|
#define KBD_CCMD_MOUSE_ENABLE 0xA8 /* Enable mouse interface */
|
|
|
|
#define KBD_CCMD_TEST_MOUSE 0xA9 /* Mouse interface test */
|
|
|
|
#define KBD_CCMD_SELF_TEST 0xAA /* Controller self test */
|
|
|
|
#define KBD_CCMD_KBD_TEST 0xAB /* Keyboard interface test */
|
|
|
|
#define KBD_CCMD_KBD_DISABLE 0xAD /* Keyboard interface disable */
|
|
|
|
#define KBD_CCMD_KBD_ENABLE 0xAE /* Keyboard interface enable */
|
|
|
|
#define KBD_CCMD_READ_INPORT 0xC0 /* read input port */
|
|
|
|
#define KBD_CCMD_READ_OUTPORT 0xD0 /* read output port */
|
|
|
|
#define KBD_CCMD_WRITE_OUTPORT 0xD1 /* write output port */
|
|
|
|
#define KBD_CCMD_WRITE_OBUF 0xD2
|
|
|
|
#define KBD_CCMD_WRITE_AUX_OBUF 0xD3 /* Write to output buffer as if
|
|
|
|
initiated by the auxiliary device */
|
|
|
|
#define KBD_CCMD_WRITE_MOUSE 0xD4 /* Write the following byte to the mouse */
|
|
|
|
#define KBD_CCMD_DISABLE_A20 0xDD /* HP vectra only ? */
|
|
|
|
#define KBD_CCMD_ENABLE_A20 0xDF /* HP vectra only ? */
|
|
|
|
#define KBD_CCMD_RESET 0xFE
|
|
|
|
|
|
|
|
/* Keyboard Commands */
|
|
|
|
#define KBD_CMD_SET_LEDS 0xED /* Set keyboard leds */
|
|
|
|
#define KBD_CMD_ECHO 0xEE
|
|
|
|
#define KBD_CMD_GET_ID 0xF2 /* get keyboard ID */
|
|
|
|
#define KBD_CMD_SET_RATE 0xF3 /* Set typematic rate */
|
|
|
|
#define KBD_CMD_ENABLE 0xF4 /* Enable scanning */
|
|
|
|
#define KBD_CMD_RESET_DISABLE 0xF5 /* reset and disable scanning */
|
|
|
|
#define KBD_CMD_RESET_ENABLE 0xF6 /* reset and enable scanning */
|
|
|
|
#define KBD_CMD_RESET 0xFF /* Reset */
|
|
|
|
|
|
|
|
/* Keyboard Replies */
|
|
|
|
#define KBD_REPLY_POR 0xAA /* Power on reset */
|
|
|
|
#define KBD_REPLY_ACK 0xFA /* Command ACK */
|
|
|
|
#define KBD_REPLY_RESEND 0xFE /* Command NACK, send the cmd again */
|
|
|
|
|
|
|
|
/* Status Register Bits */
|
|
|
|
#define KBD_STAT_OBF 0x01 /* Keyboard output buffer full */
|
|
|
|
#define KBD_STAT_IBF 0x02 /* Keyboard input buffer full */
|
|
|
|
#define KBD_STAT_SELFTEST 0x04 /* Self test successful */
|
|
|
|
#define KBD_STAT_CMD 0x08 /* Last write was a command write (0=data) */
|
|
|
|
#define KBD_STAT_UNLOCKED 0x10 /* Zero if keyboard locked */
|
|
|
|
#define KBD_STAT_MOUSE_OBF 0x20 /* Mouse output buffer full */
|
|
|
|
#define KBD_STAT_GTO 0x40 /* General receive/xmit timeout */
|
|
|
|
#define KBD_STAT_PERR 0x80 /* Parity error */
|
|
|
|
|
|
|
|
/* Controller Mode Register Bits */
|
|
|
|
#define KBD_MODE_KBD_INT 0x01 /* Keyboard data generate IRQ1 */
|
|
|
|
#define KBD_MODE_MOUSE_INT 0x02 /* Mouse data generate IRQ12 */
|
|
|
|
#define KBD_MODE_SYS 0x04 /* The system flag (?) */
|
|
|
|
#define KBD_MODE_NO_KEYLOCK 0x08 /* The keylock doesn't affect the keyboard if set */
|
|
|
|
#define KBD_MODE_DISABLE_KBD 0x10 /* Disable keyboard interface */
|
|
|
|
#define KBD_MODE_DISABLE_MOUSE 0x20 /* Disable mouse interface */
|
|
|
|
#define KBD_MODE_KCC 0x40 /* Scan code conversion to PC format */
|
|
|
|
#define KBD_MODE_RFU 0x80
|
|
|
|
|
|
|
|
/* Mouse Commands */
|
|
|
|
#define AUX_SET_SCALE11 0xE6 /* Set 1:1 scaling */
|
|
|
|
#define AUX_SET_SCALE21 0xE7 /* Set 2:1 scaling */
|
|
|
|
#define AUX_SET_RES 0xE8 /* Set resolution */
|
|
|
|
#define AUX_GET_SCALE 0xE9 /* Get scaling factor */
|
|
|
|
#define AUX_SET_STREAM 0xEA /* Set stream mode */
|
|
|
|
#define AUX_POLL 0xEB /* Poll */
|
|
|
|
#define AUX_RESET_WRAP 0xEC /* Reset wrap mode */
|
|
|
|
#define AUX_SET_WRAP 0xEE /* Set wrap mode */
|
|
|
|
#define AUX_SET_REMOTE 0xF0 /* Set remote mode */
|
|
|
|
#define AUX_GET_TYPE 0xF2 /* Get type */
|
|
|
|
#define AUX_SET_SAMPLE 0xF3 /* Set sample rate */
|
|
|
|
#define AUX_ENABLE_DEV 0xF4 /* Enable aux device */
|
|
|
|
#define AUX_DISABLE_DEV 0xF5 /* Disable aux device */
|
|
|
|
#define AUX_SET_DEFAULT 0xF6
|
|
|
|
#define AUX_RESET 0xFF /* Reset aux device */
|
|
|
|
#define AUX_ACK 0xFA /* Command byte ACK. */
|
|
|
|
|
|
|
|
#define MOUSE_STATUS_REMOTE 0x40
|
|
|
|
#define MOUSE_STATUS_ENABLED 0x20
|
|
|
|
#define MOUSE_STATUS_SCALE21 0x10
|
|
|
|
|
|
|
|
#define KBD_QUEUE_SIZE 256
|
|
|
|
|
2005-11-26 11:14:03 +01:00
|
|
|
#define KBD_PENDING_KBD 1
|
|
|
|
#define KBD_PENDING_AUX 2
|
2004-03-14 13:20:30 +01:00
|
|
|
|
|
|
|
typedef struct KBDState {
|
|
|
|
uint8_t write_cmd; /* if non zero, write data to port 60 is expected */
|
|
|
|
uint8_t status;
|
|
|
|
uint8_t mode;
|
2005-11-26 11:14:03 +01:00
|
|
|
/* Bitmask of devices with data available. */
|
2006-04-08 16:12:31 +02:00
|
|
|
uint8_t pending;
|
2005-11-26 11:14:03 +01:00
|
|
|
void *kbd;
|
|
|
|
void *mouse;
|
2007-02-18 01:08:44 +01:00
|
|
|
|
2007-04-07 20:14:41 +02:00
|
|
|
qemu_irq irq_kbd;
|
|
|
|
qemu_irq irq_mouse;
|
2007-04-16 19:20:48 +02:00
|
|
|
target_phys_addr_t base;
|
2007-04-17 00:47:54 +02:00
|
|
|
int it_shift;
|
2004-03-14 13:20:30 +01:00
|
|
|
} KBDState;
|
|
|
|
|
|
|
|
KBDState kbd_state;
|
|
|
|
|
|
|
|
/* update irq and KBD_STAT_[MOUSE_]OBF */
|
|
|
|
/* XXX: not generating the irqs if KBD_MODE_DISABLE_KBD is set may be
|
|
|
|
incorrect, but it avoids having to simulate exact delays */
|
|
|
|
static void kbd_update_irq(KBDState *s)
|
|
|
|
{
|
2007-02-18 01:08:44 +01:00
|
|
|
int irq_kbd_level, irq_mouse_level;
|
2004-03-14 13:20:30 +01:00
|
|
|
|
2007-02-18 01:08:44 +01:00
|
|
|
irq_kbd_level = 0;
|
|
|
|
irq_mouse_level = 0;
|
2004-03-14 13:20:30 +01:00
|
|
|
s->status &= ~(KBD_STAT_OBF | KBD_STAT_MOUSE_OBF);
|
2005-11-26 11:14:03 +01:00
|
|
|
if (s->pending) {
|
2004-03-14 13:20:30 +01:00
|
|
|
s->status |= KBD_STAT_OBF;
|
2007-04-16 19:20:48 +02:00
|
|
|
/* kbd data takes priority over aux data. */
|
2005-11-26 11:14:03 +01:00
|
|
|
if (s->pending == KBD_PENDING_AUX) {
|
2004-03-14 13:20:30 +01:00
|
|
|
s->status |= KBD_STAT_MOUSE_OBF;
|
|
|
|
if (s->mode & KBD_MODE_MOUSE_INT)
|
2007-02-18 01:08:44 +01:00
|
|
|
irq_mouse_level = 1;
|
2004-03-14 13:20:30 +01:00
|
|
|
} else {
|
2007-09-16 23:08:06 +02:00
|
|
|
if ((s->mode & KBD_MODE_KBD_INT) &&
|
2004-03-14 13:20:30 +01:00
|
|
|
!(s->mode & KBD_MODE_DISABLE_KBD))
|
2007-02-18 01:08:44 +01:00
|
|
|
irq_kbd_level = 1;
|
2004-03-14 13:20:30 +01:00
|
|
|
}
|
|
|
|
}
|
2007-04-07 20:14:41 +02:00
|
|
|
qemu_set_irq(s->irq_kbd, irq_kbd_level);
|
|
|
|
qemu_set_irq(s->irq_mouse, irq_mouse_level);
|
2004-03-14 13:20:30 +01:00
|
|
|
}
|
|
|
|
|
2005-11-26 11:14:03 +01:00
|
|
|
static void kbd_update_kbd_irq(void *opaque, int level)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2005-11-26 11:14:03 +01:00
|
|
|
KBDState *s = (KBDState *)opaque;
|
2004-03-14 13:20:30 +01:00
|
|
|
|
2005-11-26 11:14:03 +01:00
|
|
|
if (level)
|
|
|
|
s->pending |= KBD_PENDING_KBD;
|
2004-03-14 13:20:30 +01:00
|
|
|
else
|
2005-11-26 11:14:03 +01:00
|
|
|
s->pending &= ~KBD_PENDING_KBD;
|
2004-03-14 13:20:30 +01:00
|
|
|
kbd_update_irq(s);
|
|
|
|
}
|
|
|
|
|
2005-11-26 11:14:03 +01:00
|
|
|
static void kbd_update_aux_irq(void *opaque, int level)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2005-11-26 11:14:03 +01:00
|
|
|
KBDState *s = (KBDState *)opaque;
|
|
|
|
|
|
|
|
if (level)
|
|
|
|
s->pending |= KBD_PENDING_AUX;
|
|
|
|
else
|
|
|
|
s->pending &= ~KBD_PENDING_AUX;
|
|
|
|
kbd_update_irq(s);
|
2004-03-14 13:20:30 +01:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
static uint32_t kbd_read_status(void *opaque, uint32_t addr)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2004-03-14 22:46:48 +01:00
|
|
|
KBDState *s = opaque;
|
2004-03-14 13:20:30 +01:00
|
|
|
int val;
|
|
|
|
val = s->status;
|
|
|
|
#if defined(DEBUG_KBD)
|
|
|
|
printf("kbd: read status=0x%02x\n", val);
|
|
|
|
#endif
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2005-11-26 11:14:03 +01:00
|
|
|
static void kbd_queue(KBDState *s, int b, int aux)
|
|
|
|
{
|
|
|
|
if (aux)
|
|
|
|
ps2_queue(s->mouse, b);
|
|
|
|
else
|
|
|
|
ps2_queue(s->kbd, b);
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
static void kbd_write_command(void *opaque, uint32_t addr, uint32_t val)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2004-03-14 22:46:48 +01:00
|
|
|
KBDState *s = opaque;
|
2004-03-14 13:20:30 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG_KBD
|
|
|
|
printf("kbd: write cmd=0x%02x\n", val);
|
|
|
|
#endif
|
|
|
|
switch(val) {
|
|
|
|
case KBD_CCMD_READ_MODE:
|
2007-10-20 22:48:09 +02:00
|
|
|
kbd_queue(s, s->mode, 1);
|
2004-03-14 13:20:30 +01:00
|
|
|
break;
|
|
|
|
case KBD_CCMD_WRITE_MODE:
|
|
|
|
case KBD_CCMD_WRITE_OBUF:
|
|
|
|
case KBD_CCMD_WRITE_AUX_OBUF:
|
|
|
|
case KBD_CCMD_WRITE_MOUSE:
|
|
|
|
case KBD_CCMD_WRITE_OUTPORT:
|
|
|
|
s->write_cmd = val;
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_MOUSE_DISABLE:
|
|
|
|
s->mode |= KBD_MODE_DISABLE_MOUSE;
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_MOUSE_ENABLE:
|
|
|
|
s->mode &= ~KBD_MODE_DISABLE_MOUSE;
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_TEST_MOUSE:
|
|
|
|
kbd_queue(s, 0x00, 0);
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_SELF_TEST:
|
|
|
|
s->status |= KBD_STAT_SELFTEST;
|
|
|
|
kbd_queue(s, 0x55, 0);
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_KBD_TEST:
|
|
|
|
kbd_queue(s, 0x00, 0);
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_KBD_DISABLE:
|
|
|
|
s->mode |= KBD_MODE_DISABLE_KBD;
|
|
|
|
kbd_update_irq(s);
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_KBD_ENABLE:
|
|
|
|
s->mode &= ~KBD_MODE_DISABLE_KBD;
|
|
|
|
kbd_update_irq(s);
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_READ_INPORT:
|
|
|
|
kbd_queue(s, 0x00, 0);
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_READ_OUTPORT:
|
|
|
|
/* XXX: check that */
|
|
|
|
#ifdef TARGET_I386
|
2005-11-22 00:33:12 +01:00
|
|
|
val = 0x01 | (ioport_get_a20() << 1);
|
2004-03-14 13:20:30 +01:00
|
|
|
#else
|
|
|
|
val = 0x01;
|
|
|
|
#endif
|
|
|
|
if (s->status & KBD_STAT_OBF)
|
|
|
|
val |= 0x10;
|
|
|
|
if (s->status & KBD_STAT_MOUSE_OBF)
|
|
|
|
val |= 0x20;
|
|
|
|
kbd_queue(s, val, 0);
|
|
|
|
break;
|
|
|
|
#ifdef TARGET_I386
|
|
|
|
case KBD_CCMD_ENABLE_A20:
|
2005-11-22 00:33:12 +01:00
|
|
|
ioport_set_a20(1);
|
2004-03-14 13:20:30 +01:00
|
|
|
break;
|
|
|
|
case KBD_CCMD_DISABLE_A20:
|
2005-11-22 00:33:12 +01:00
|
|
|
ioport_set_a20(0);
|
2004-03-14 13:20:30 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case KBD_CCMD_RESET:
|
2004-06-20 14:58:36 +02:00
|
|
|
qemu_system_reset_request();
|
2004-03-14 13:20:30 +01:00
|
|
|
break;
|
|
|
|
case 0xff:
|
|
|
|
/* ignore that - I don't know what is its use */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "qemu: unsupported keyboard cmd=0x%02x\n", val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
static uint32_t kbd_read_data(void *opaque, uint32_t addr)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2004-06-03 20:45:02 +02:00
|
|
|
KBDState *s = opaque;
|
2004-03-14 13:20:30 +01:00
|
|
|
|
2005-11-26 11:14:03 +01:00
|
|
|
if (s->pending == KBD_PENDING_AUX)
|
|
|
|
return ps2_read_data(s->mouse);
|
2004-03-14 13:20:30 +01:00
|
|
|
|
2005-11-26 11:14:03 +01:00
|
|
|
return ps2_read_data(s->kbd);
|
2004-03-14 13:20:30 +01:00
|
|
|
}
|
|
|
|
|
2007-11-18 02:44:38 +01:00
|
|
|
static void kbd_write_data(void *opaque, uint32_t addr, uint32_t val)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2004-03-14 22:46:48 +01:00
|
|
|
KBDState *s = opaque;
|
2004-03-14 13:20:30 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG_KBD
|
|
|
|
printf("kbd: write data=0x%02x\n", val);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch(s->write_cmd) {
|
|
|
|
case 0:
|
2005-11-26 11:14:03 +01:00
|
|
|
ps2_write_keyboard(s->kbd, val);
|
2004-03-14 13:20:30 +01:00
|
|
|
break;
|
|
|
|
case KBD_CCMD_WRITE_MODE:
|
|
|
|
s->mode = val;
|
2006-02-08 05:42:17 +01:00
|
|
|
ps2_keyboard_set_translation(s->kbd, (s->mode & KBD_MODE_KCC) != 0);
|
2005-11-26 11:14:03 +01:00
|
|
|
/* ??? */
|
2004-03-14 13:20:30 +01:00
|
|
|
kbd_update_irq(s);
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_WRITE_OBUF:
|
|
|
|
kbd_queue(s, val, 0);
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_WRITE_AUX_OBUF:
|
|
|
|
kbd_queue(s, val, 1);
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_WRITE_OUTPORT:
|
|
|
|
#ifdef TARGET_I386
|
2005-11-22 00:33:12 +01:00
|
|
|
ioport_set_a20((val >> 1) & 1);
|
2004-03-14 13:20:30 +01:00
|
|
|
#endif
|
|
|
|
if (!(val & 1)) {
|
2004-06-20 14:58:36 +02:00
|
|
|
qemu_system_reset_request();
|
2004-03-14 13:20:30 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_WRITE_MOUSE:
|
2005-11-26 11:14:03 +01:00
|
|
|
ps2_write_mouse(s->mouse, val);
|
2004-03-14 13:20:30 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s->write_cmd = 0;
|
|
|
|
}
|
|
|
|
|
2004-06-20 14:58:36 +02:00
|
|
|
static void kbd_reset(void *opaque)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2004-06-20 14:58:36 +02:00
|
|
|
KBDState *s = opaque;
|
2004-03-14 13:20:30 +01:00
|
|
|
|
|
|
|
s->mode = KBD_MODE_KBD_INT | KBD_MODE_MOUSE_INT;
|
|
|
|
s->status = KBD_STAT_CMD | KBD_STAT_UNLOCKED;
|
|
|
|
}
|
|
|
|
|
2004-07-10 15:39:53 +02:00
|
|
|
static void kbd_save(QEMUFile* f, void* opaque)
|
|
|
|
{
|
|
|
|
KBDState *s = (KBDState*)opaque;
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2004-07-10 15:39:53 +02:00
|
|
|
qemu_put_8s(f, &s->write_cmd);
|
|
|
|
qemu_put_8s(f, &s->status);
|
|
|
|
qemu_put_8s(f, &s->mode);
|
2006-04-08 16:12:31 +02:00
|
|
|
qemu_put_8s(f, &s->pending);
|
2004-07-10 15:39:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int kbd_load(QEMUFile* f, void* opaque, int version_id)
|
|
|
|
{
|
|
|
|
KBDState *s = (KBDState*)opaque;
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2006-04-08 16:12:31 +02:00
|
|
|
if (version_id != 3)
|
2004-07-10 15:39:53 +02:00
|
|
|
return -EINVAL;
|
|
|
|
qemu_get_8s(f, &s->write_cmd);
|
|
|
|
qemu_get_8s(f, &s->status);
|
|
|
|
qemu_get_8s(f, &s->mode);
|
2006-04-08 16:12:31 +02:00
|
|
|
qemu_get_8s(f, &s->pending);
|
2004-07-10 15:39:53 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-07 20:14:41 +02:00
|
|
|
void i8042_init(qemu_irq kbd_irq, qemu_irq mouse_irq, uint32_t io_base)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2004-03-14 22:46:48 +01:00
|
|
|
KBDState *s = &kbd_state;
|
2007-02-18 01:08:44 +01:00
|
|
|
|
2007-04-07 20:14:41 +02:00
|
|
|
s->irq_kbd = kbd_irq;
|
|
|
|
s->irq_mouse = mouse_irq;
|
2007-04-16 19:20:48 +02:00
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
kbd_reset(s);
|
2006-04-08 16:12:31 +02:00
|
|
|
register_savevm("pckbd", 0, 3, kbd_save, kbd_load, s);
|
2007-02-18 01:08:44 +01:00
|
|
|
register_ioport_read(io_base, 1, 1, kbd_read_data, s);
|
|
|
|
register_ioport_write(io_base, 1, 1, kbd_write_data, s);
|
|
|
|
register_ioport_read(io_base + 4, 1, 1, kbd_read_status, s);
|
|
|
|
register_ioport_write(io_base + 4, 1, 1, kbd_write_command, s);
|
2004-06-03 20:45:02 +02:00
|
|
|
|
2005-11-26 11:14:03 +01:00
|
|
|
s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
|
|
|
|
s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
|
2007-03-20 17:45:27 +01:00
|
|
|
#ifdef TARGET_I386
|
|
|
|
vmmouse_init(s->mouse);
|
|
|
|
#endif
|
2004-06-20 14:58:36 +02:00
|
|
|
qemu_register_reset(kbd_reset, s);
|
2004-03-14 13:20:30 +01:00
|
|
|
}
|
2007-04-16 19:20:48 +02:00
|
|
|
|
|
|
|
/* Memory mapped interface */
|
2007-11-18 02:44:38 +01:00
|
|
|
static uint32_t kbd_mm_readb (void *opaque, target_phys_addr_t addr)
|
2007-04-16 19:20:48 +02:00
|
|
|
{
|
|
|
|
KBDState *s = opaque;
|
|
|
|
|
2007-04-17 00:47:54 +02:00
|
|
|
switch ((addr - s->base) >> s->it_shift) {
|
|
|
|
case 0:
|
|
|
|
return kbd_read_data(s, 0) & 0xff;
|
|
|
|
case 1:
|
|
|
|
return kbd_read_status(s, 0) & 0xff;
|
|
|
|
default:
|
|
|
|
return 0xff;
|
|
|
|
}
|
2007-04-16 19:20:48 +02:00
|
|
|
}
|
|
|
|
|
2007-11-18 02:44:38 +01:00
|
|
|
static void kbd_mm_writeb (void *opaque, target_phys_addr_t addr, uint32_t value)
|
2007-04-16 19:20:48 +02:00
|
|
|
{
|
|
|
|
KBDState *s = opaque;
|
|
|
|
|
2007-04-17 00:47:54 +02:00
|
|
|
switch ((addr - s->base) >> s->it_shift) {
|
|
|
|
case 0:
|
|
|
|
kbd_write_data(s, 0, value & 0xff);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
kbd_write_command(s, 0, value & 0xff);
|
|
|
|
break;
|
|
|
|
}
|
2007-04-16 19:20:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static CPUReadMemoryFunc *kbd_mm_read[] = {
|
|
|
|
&kbd_mm_readb,
|
|
|
|
&kbd_mm_readb,
|
|
|
|
&kbd_mm_readb,
|
|
|
|
};
|
|
|
|
|
|
|
|
static CPUWriteMemoryFunc *kbd_mm_write[] = {
|
|
|
|
&kbd_mm_writeb,
|
|
|
|
&kbd_mm_writeb,
|
|
|
|
&kbd_mm_writeb,
|
|
|
|
};
|
|
|
|
|
2007-06-08 18:45:23 +02:00
|
|
|
void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
|
|
|
|
target_phys_addr_t base, int it_shift)
|
2007-04-16 19:20:48 +02:00
|
|
|
{
|
|
|
|
KBDState *s = &kbd_state;
|
|
|
|
int s_io_memory;
|
|
|
|
|
|
|
|
s->irq_kbd = kbd_irq;
|
|
|
|
s->irq_mouse = mouse_irq;
|
|
|
|
s->base = base;
|
2007-04-17 00:47:54 +02:00
|
|
|
s->it_shift = it_shift;
|
2007-04-16 19:20:48 +02:00
|
|
|
|
|
|
|
kbd_reset(s);
|
|
|
|
register_savevm("pckbd", 0, 3, kbd_save, kbd_load, s);
|
|
|
|
s_io_memory = cpu_register_io_memory(0, kbd_mm_read, kbd_mm_write, s);
|
2007-04-17 00:47:54 +02:00
|
|
|
cpu_register_physical_memory(base, 8 << it_shift, s_io_memory);
|
2007-04-16 19:20:48 +02:00
|
|
|
|
|
|
|
s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
|
|
|
|
s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
|
|
|
|
#ifdef TARGET_I386
|
|
|
|
vmmouse_init(s->mouse);
|
|
|
|
#endif
|
|
|
|
qemu_register_reset(kbd_reset, s);
|
|
|
|
}
|