VirtualBox

source: vbox/trunk/src/VBox/Devices/Input/DevPS2.cpp@ 44516

Last change on this file since 44516 was 41560, checked in by vboxsync, 13 years ago

Log which device triggered a reset.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 54.7 KB
Line 
1/* $Id: DevPS2.cpp 41560 2012-06-04 12:07:32Z vboxsync $ */
2/** @file
3 * DevPS2 - PS/2 keyboard & mouse controller device.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 * --------------------------------------------------------------------
17 *
18 * This code is based on:
19 *
20 * QEMU PC keyboard emulation (revision 1.12)
21 *
22 * Copyright (c) 2003 Fabrice Bellard
23 *
24 * Permission is hereby granted, free of charge, to any person obtaining a copy
25 * of this software and associated documentation files (the "Software"), to deal
26 * in the Software without restriction, including without limitation the rights
27 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28 * copies of the Software, and to permit persons to whom the Software is
29 * furnished to do so, subject to the following conditions:
30 *
31 * The above copyright notice and this permission notice shall be included in
32 * all copies or substantial portions of the Software.
33 *
34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
37 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
40 * THE SOFTWARE.
41 *
42 */
43
44/*******************************************************************************
45* Header Files *
46*******************************************************************************/
47#define LOG_GROUP LOG_GROUP_DEV_KBD
48#include "vl_vbox.h"
49#include <VBox/vmm/pdmdev.h>
50#include <iprt/assert.h>
51#include <iprt/uuid.h>
52
53#include "VBoxDD.h"
54#include "PS2Dev.h"
55
56#define PCKBD_SAVED_STATE_VERSION 6
57
58
59#ifndef VBOX_DEVICE_STRUCT_TESTCASE
60/*******************************************************************************
61* Internal Functions *
62*******************************************************************************/
63RT_C_DECLS_BEGIN
64PDMBOTHCBDECL(int) kbdIOPortDataRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
65PDMBOTHCBDECL(int) kbdIOPortDataWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
66PDMBOTHCBDECL(int) kbdIOPortStatusRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
67PDMBOTHCBDECL(int) kbdIOPortCommandWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
68RT_C_DECLS_END
69#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
70
71/* debug PC keyboard */
72#define DEBUG_KBD
73
74/* debug PC keyboard : only mouse */
75#define DEBUG_MOUSE
76
77/* Keyboard Controller Commands */
78#define KBD_CCMD_READ_MODE 0x20 /* Read mode bits */
79#define KBD_CCMD_WRITE_MODE 0x60 /* Write mode bits */
80#define KBD_CCMD_GET_VERSION 0xA1 /* Get controller version */
81#define KBD_CCMD_MOUSE_DISABLE 0xA7 /* Disable mouse interface */
82#define KBD_CCMD_MOUSE_ENABLE 0xA8 /* Enable mouse interface */
83#define KBD_CCMD_TEST_MOUSE 0xA9 /* Mouse interface test */
84#define KBD_CCMD_SELF_TEST 0xAA /* Controller self test */
85#define KBD_CCMD_KBD_TEST 0xAB /* Keyboard interface test */
86#define KBD_CCMD_KBD_DISABLE 0xAD /* Keyboard interface disable */
87#define KBD_CCMD_KBD_ENABLE 0xAE /* Keyboard interface enable */
88#define KBD_CCMD_READ_INPORT 0xC0 /* read input port */
89#define KBD_CCMD_READ_OUTPORT 0xD0 /* read output port */
90#define KBD_CCMD_WRITE_OUTPORT 0xD1 /* write output port */
91#define KBD_CCMD_WRITE_OBUF 0xD2
92#define KBD_CCMD_WRITE_AUX_OBUF 0xD3 /* Write to output buffer as if
93 initiated by the auxiliary device */
94#define KBD_CCMD_WRITE_MOUSE 0xD4 /* Write the following byte to the mouse */
95#define KBD_CCMD_DISABLE_A20 0xDD /* HP vectra only ? */
96#define KBD_CCMD_ENABLE_A20 0xDF /* HP vectra only ? */
97#define KBD_CCMD_READ_TSTINP 0xE0 /* Read test inputs T0, T1 */
98#define KBD_CCMD_RESET 0xFE
99
100/* Status Register Bits */
101#define KBD_STAT_OBF 0x01 /* Keyboard output buffer full */
102#define KBD_STAT_IBF 0x02 /* Keyboard input buffer full */
103#define KBD_STAT_SELFTEST 0x04 /* Self test successful */
104#define KBD_STAT_CMD 0x08 /* Last write was a command write (0=data) */
105#define KBD_STAT_UNLOCKED 0x10 /* Zero if keyboard locked */
106#define KBD_STAT_MOUSE_OBF 0x20 /* Mouse output buffer full */
107#define KBD_STAT_GTO 0x40 /* General receive/xmit timeout */
108#define KBD_STAT_PERR 0x80 /* Parity error */
109
110/* Controller Mode Register Bits */
111#define KBD_MODE_KBD_INT 0x01 /* Keyboard data generate IRQ1 */
112#define KBD_MODE_MOUSE_INT 0x02 /* Mouse data generate IRQ12 */
113#define KBD_MODE_SYS 0x04 /* The system flag (?) */
114#define KBD_MODE_NO_KEYLOCK 0x08 /* The keylock doesn't affect the keyboard if set */
115#define KBD_MODE_DISABLE_KBD 0x10 /* Disable keyboard interface */
116#define KBD_MODE_DISABLE_MOUSE 0x20 /* Disable mouse interface */
117#define KBD_MODE_KCC 0x40 /* Scan code conversion to PC format */
118#define KBD_MODE_RFU 0x80
119
120/* Mouse Commands */
121#define AUX_SET_SCALE11 0xE6 /* Set 1:1 scaling */
122#define AUX_SET_SCALE21 0xE7 /* Set 2:1 scaling */
123#define AUX_SET_RES 0xE8 /* Set resolution */
124#define AUX_GET_SCALE 0xE9 /* Get scaling factor */
125#define AUX_SET_STREAM 0xEA /* Set stream mode */
126#define AUX_POLL 0xEB /* Poll */
127#define AUX_RESET_WRAP 0xEC /* Reset wrap mode */
128#define AUX_SET_WRAP 0xEE /* Set wrap mode */
129#define AUX_SET_REMOTE 0xF0 /* Set remote mode */
130#define AUX_GET_TYPE 0xF2 /* Get type */
131#define AUX_SET_SAMPLE 0xF3 /* Set sample rate */
132#define AUX_ENABLE_DEV 0xF4 /* Enable aux device */
133#define AUX_DISABLE_DEV 0xF5 /* Disable aux device */
134#define AUX_SET_DEFAULT 0xF6
135#define AUX_RESET 0xFF /* Reset aux device */
136#define AUX_ACK 0xFA /* Command byte ACK. */
137#define AUX_NACK 0xFE /* Command byte NACK. */
138
139#define MOUSE_STATUS_REMOTE 0x40
140#define MOUSE_STATUS_ENABLED 0x20
141#define MOUSE_STATUS_SCALE21 0x10
142
143/** Supported mouse protocols */
144enum
145{
146 MOUSE_PROT_PS2 = 0,
147 MOUSE_PROT_IMPS2 = 3,
148 MOUSE_PROT_IMEX = 4
149};
150
151/** @name Mouse flags */
152/** @{ */
153/** IMEX horizontal scroll-wheel mode is active */
154# define MOUSE_REPORT_HORIZONTAL 0x01
155/** @} */
156
157#define MOUSE_CMD_QUEUE_SIZE 8
158
159typedef struct {
160 uint8_t data[MOUSE_CMD_QUEUE_SIZE];
161 int rptr, wptr, count;
162} MouseCmdQueue;
163
164
165#define MOUSE_EVENT_QUEUE_SIZE 256
166
167typedef struct {
168 uint8_t data[MOUSE_EVENT_QUEUE_SIZE];
169 int rptr, wptr, count;
170} MouseEventQueue;
171
172typedef struct KBDState {
173 MouseCmdQueue mouse_command_queue;
174 MouseEventQueue mouse_event_queue;
175 uint8_t write_cmd; /* if non zero, write data to port 60 is expected */
176 uint8_t status;
177 uint8_t mode;
178 uint8_t dbbout; /* data buffer byte */
179 /* keyboard state */
180 int32_t translate;
181 int32_t xlat_state;
182 /* mouse state */
183 int32_t mouse_write_cmd;
184 uint8_t mouse_status;
185 uint8_t mouse_resolution;
186 uint8_t mouse_sample_rate;
187 uint8_t mouse_wrap;
188 uint8_t mouse_type; /* MOUSE_PROT_PS2, *_IMPS/2, *_IMEX */
189 uint8_t mouse_detect_state;
190 int32_t mouse_dx; /* current values, needed for 'poll' mode */
191 int32_t mouse_dy;
192 int32_t mouse_dz;
193 int32_t mouse_dw;
194 int32_t mouse_flags;
195 uint8_t mouse_buttons;
196 uint8_t mouse_buttons_reported;
197
198 uint32_t Alignment0;
199
200 /** Pointer to the device instance - RC. */
201 PPDMDEVINSRC pDevInsRC;
202 /** Pointer to the device instance - R3 . */
203 PPDMDEVINSR3 pDevInsR3;
204 /** Pointer to the device instance. */
205 PPDMDEVINSR0 pDevInsR0;
206
207 /** Critical section protecting the state. */
208 PDMCRITSECT CritSect;
209
210 /** Keyboard state (implemented in separate PS2K module). */
211#ifdef VBOX_DEVICE_STRUCT_TESTCASE
212 uint8_t KbdFiller[PS2K_STRUCT_FILLER];
213#else
214 PS2K Kbd;
215#endif
216
217 /**
218 * Mouse port - LUN#1.
219 *
220 * @implements PDMIBASE
221 * @implements PDMIMOUSEPORT
222 */
223 struct
224 {
225 /** The base interface for the mouse port. */
226 PDMIBASE IBase;
227 /** The mouse port base interface. */
228 PDMIMOUSEPORT IPort;
229
230 /** The base interface of the attached mouse driver. */
231 R3PTRTYPE(PPDMIBASE) pDrvBase;
232 /** The mouse interface of the attached mouse driver. */
233 R3PTRTYPE(PPDMIMOUSECONNECTOR) pDrv;
234 } Mouse;
235} KBDState;
236
237#ifndef VBOX_DEVICE_STRUCT_TESTCASE
238
239/* update irq and KBD_STAT_[MOUSE_]OBF */
240static void kbd_update_irq(KBDState *s)
241{
242 MouseCmdQueue *mcq = &s->mouse_command_queue;
243 MouseEventQueue *meq = &s->mouse_event_queue;
244 int irq12_level, irq1_level;
245 uint8_t val;
246
247 irq1_level = 0;
248 irq12_level = 0;
249
250 /* Determine new OBF state, but only if OBF is clear. If OBF was already
251 * set, we cannot risk changing the event type after an ISR potentially
252 * started executing! Only kbd_read_data() clears the OBF bits.
253 */
254 if (!(s->status & KBD_STAT_OBF)) {
255 s->status &= ~KBD_STAT_MOUSE_OBF;
256 /* Keyboard data has priority if both kbd and aux data is available. */
257 if (!(s->mode & KBD_MODE_DISABLE_KBD) && PS2KByteFromKbd(&s->Kbd, &val) == VINF_SUCCESS)
258 {
259 bool fHaveData = true;
260
261 /* If scancode translation is on (it usually is), there's more work to do. */
262 if (s->translate)
263 {
264 uint8_t xlated_val;
265
266 s->xlat_state = XlateAT2PC(s->xlat_state, val, &xlated_val);
267 val = xlated_val;
268
269 /* If the translation state is XS_BREAK, there's nothing to report
270 * and we keep going until the state changes or there's no more data.
271 */
272 while (s->xlat_state == XS_BREAK && PS2KByteFromKbd(&s->Kbd, &val) == VINF_SUCCESS)
273 {
274 s->xlat_state = XlateAT2PC(s->xlat_state, val, &xlated_val);
275 val = xlated_val;
276 }
277 /* This can happen if the last byte in the queue is F0... */
278 if (s->xlat_state == XS_BREAK)
279 fHaveData = false;
280 }
281 if (fHaveData)
282 {
283 s->dbbout = val;
284 s->status |= KBD_STAT_OBF;
285 }
286 }
287 else if ((mcq->count || meq->count) && !(s->mode & KBD_MODE_DISABLE_MOUSE))
288 {
289 s->status |= KBD_STAT_OBF | KBD_STAT_MOUSE_OBF;
290 if (mcq->count)
291 {
292 s->dbbout = mcq->data[mcq->rptr];
293 if (++mcq->rptr == MOUSE_CMD_QUEUE_SIZE)
294 mcq->rptr = 0;
295 mcq->count--;
296 }
297 else
298 {
299 s->dbbout = meq->data[meq->rptr];
300 if (++meq->rptr == MOUSE_EVENT_QUEUE_SIZE)
301 meq->rptr = 0;
302 meq->count--;
303 }
304 }
305 }
306 /* Determine new IRQ state. */
307 if (s->status & KBD_STAT_OBF) {
308 if (s->status & KBD_STAT_MOUSE_OBF)
309 {
310 if (s->mode & KBD_MODE_MOUSE_INT)
311 irq12_level = 1;
312 }
313 else
314 { /* KBD_STAT_OBF set but KBD_STAT_MOUSE_OBF isn't. */
315 if (s->mode & KBD_MODE_KBD_INT)
316 irq1_level = 1;
317 }
318 }
319 PDMDevHlpISASetIrq(s->CTX_SUFF(pDevIns), 1, irq1_level);
320 PDMDevHlpISASetIrq(s->CTX_SUFF(pDevIns), 12, irq12_level);
321}
322
323void KBCUpdateInterrupts(void *pKbc)
324{
325 KBDState *s = (KBDState *)pKbc;
326 kbd_update_irq(s);
327}
328
329static void kbd_queue(KBDState *s, int b, int aux)
330{
331 MouseCmdQueue *mcq = &s->mouse_command_queue;
332 MouseEventQueue *meq = &s->mouse_event_queue;
333
334#if defined(DEBUG_MOUSE) || defined(DEBUG_KBD)
335 if (aux == 1)
336 LogRel3(("%s: mouse command response: 0x%02x\n", __PRETTY_FUNCTION__, b));
337 else if (aux == 2)
338 LogRel3(("%s: mouse event data: 0x%02x\n", __PRETTY_FUNCTION__, b));
339#ifdef DEBUG_KBD
340 else
341 LogRel3(("%s: kbd event: 0x%02x\n", __PRETTY_FUNCTION__, b));
342#endif
343#endif
344 switch (aux)
345 {
346 case 0: /* keyboard */
347 AssertMsgFailed(("kbd_queue() no longer supported for keyboard!\n"));
348 break;
349 case 1: /* mouse command response */
350 if (mcq->count >= MOUSE_CMD_QUEUE_SIZE)
351 return;
352 mcq->data[mcq->wptr] = b;
353 if (++mcq->wptr == MOUSE_CMD_QUEUE_SIZE)
354 mcq->wptr = 0;
355 mcq->count++;
356 break;
357 case 2: /* mouse event data */
358 if (meq->count >= MOUSE_EVENT_QUEUE_SIZE)
359 return;
360 meq->data[meq->wptr] = b;
361 if (++meq->wptr == MOUSE_EVENT_QUEUE_SIZE)
362 meq->wptr = 0;
363 meq->count++;
364 break;
365 default:
366 AssertMsgFailed(("aux=%d\n", aux));
367 }
368 kbd_update_irq(s);
369}
370
371static void kbc_dbb_out(void *opaque, uint8_t val)
372{
373 KBDState *s = (KBDState*)opaque;
374
375 s->dbbout = val;
376 /* Set the OBF and raise IRQ. */
377 s->status |= KBD_STAT_OBF;
378 if (s->mode & KBD_MODE_KBD_INT)
379 PDMDevHlpISASetIrq(s->CTX_SUFF(pDevIns), 1, 1);
380}
381
382static uint32_t kbd_read_status(void *opaque, uint32_t addr)
383{
384 KBDState *s = (KBDState*)opaque;
385 int val = s->status;
386 NOREF(addr);
387
388#if defined(DEBUG_KBD)
389 Log(("kbd: read status=0x%02x\n", val));
390#endif
391 return val;
392}
393
394static int kbd_write_command(void *opaque, uint32_t addr, uint32_t val)
395{
396 int rc = VINF_SUCCESS;
397 KBDState *s = (KBDState*)opaque;
398 NOREF(addr);
399
400#ifdef DEBUG_KBD
401 Log(("kbd: write cmd=0x%02x\n", val));
402#endif
403 switch(val) {
404 case KBD_CCMD_READ_MODE:
405 kbc_dbb_out(s, s->mode);
406 break;
407 case KBD_CCMD_WRITE_MODE:
408 case KBD_CCMD_WRITE_OBUF:
409 case KBD_CCMD_WRITE_AUX_OBUF:
410 case KBD_CCMD_WRITE_MOUSE:
411 case KBD_CCMD_WRITE_OUTPORT:
412 s->write_cmd = val;
413 break;
414 case KBD_CCMD_MOUSE_DISABLE:
415 s->mode |= KBD_MODE_DISABLE_MOUSE;
416 break;
417 case KBD_CCMD_MOUSE_ENABLE:
418 s->mode &= ~KBD_MODE_DISABLE_MOUSE;
419 /* Check for queued input. */
420 kbd_update_irq(s);
421 break;
422 case KBD_CCMD_TEST_MOUSE:
423 kbc_dbb_out(s, 0x00);
424 break;
425 case KBD_CCMD_SELF_TEST:
426 /* Enable the A20 line - that is the power-on state(!). */
427# ifndef IN_RING3
428 if (!PDMDevHlpA20IsEnabled(s->CTX_SUFF(pDevIns)))
429 {
430 rc = VINF_IOM_R3_IOPORT_WRITE;
431 break;
432 }
433# else /* IN_RING3 */
434 PDMDevHlpA20Set(s->CTX_SUFF(pDevIns), true);
435# endif /* IN_RING3 */
436 s->status |= KBD_STAT_SELFTEST;
437 s->mode |= KBD_MODE_DISABLE_KBD;
438 kbc_dbb_out(s, 0x55);
439 break;
440 case KBD_CCMD_KBD_TEST:
441 kbc_dbb_out(s, 0x00);
442 break;
443 case KBD_CCMD_KBD_DISABLE:
444 s->mode |= KBD_MODE_DISABLE_KBD;
445 break;
446 case KBD_CCMD_KBD_ENABLE:
447 s->mode &= ~KBD_MODE_DISABLE_KBD;
448 /* Check for queued input. */
449 kbd_update_irq(s);
450 break;
451 case KBD_CCMD_READ_INPORT:
452 kbc_dbb_out(s, 0x00);
453 break;
454 case KBD_CCMD_READ_OUTPORT:
455 /* XXX: check that */
456#ifdef TARGET_I386
457 val = 0x01 | (PDMDevHlpA20IsEnabled(s->CTX_SUFF(pDevIns)) << 1);
458#else
459 val = 0x01;
460#endif
461 if (s->status & KBD_STAT_OBF)
462 val |= 0x10;
463 if (s->status & KBD_STAT_MOUSE_OBF)
464 val |= 0x20;
465 kbc_dbb_out(s, val);
466 break;
467#ifdef TARGET_I386
468 case KBD_CCMD_ENABLE_A20:
469# ifndef IN_RING3
470 if (!PDMDevHlpA20IsEnabled(s->CTX_SUFF(pDevIns)))
471 rc = VINF_IOM_R3_IOPORT_WRITE;
472# else /* IN_RING3 */
473 PDMDevHlpA20Set(s->CTX_SUFF(pDevIns), true);
474# endif /* IN_RING3 */
475 break;
476 case KBD_CCMD_DISABLE_A20:
477# ifndef IN_RING3
478 if (PDMDevHlpA20IsEnabled(s->CTX_SUFF(pDevIns)))
479 rc = VINF_IOM_R3_IOPORT_WRITE;
480# else /* IN_RING3 */
481 PDMDevHlpA20Set(s->CTX_SUFF(pDevIns), false);
482# endif /* !IN_RING3 */
483 break;
484#endif
485 case KBD_CCMD_READ_TSTINP:
486 /* Keyboard clock line is zero IFF keyboard is disabled */
487 val = (s->mode & KBD_MODE_DISABLE_KBD) ? 0 : 1;
488 kbc_dbb_out(s, val);
489 break;
490 case KBD_CCMD_RESET:
491#ifndef IN_RING3
492 rc = VINF_IOM_R3_IOPORT_WRITE;
493#else /* IN_RING3 */
494 LogRel(("Reset initiated by keyboard controller\n"));
495 rc = PDMDevHlpVMReset(s->CTX_SUFF(pDevIns));
496#endif /* !IN_RING3 */
497 break;
498 case 0xff:
499 /* ignore that - I don't know what is its use */
500 break;
501 /* Make OS/2 happy. */
502 /* The 8042 RAM is readable using commands 0x20 thru 0x3f, and writable
503 by 0x60 thru 0x7f. Now days only the firs byte, the mode, is used.
504 We'll ignore the writes (0x61..7f) and return 0 for all the reads
505 just to make some OS/2 debug stuff a bit happier. */
506 case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
507 case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
508 case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37:
509 case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f:
510 kbc_dbb_out(s, 0);
511 Log(("kbd: reading non-standard RAM addr %#x\n", val & 0x1f));
512 break;
513 default:
514 Log(("kbd: unsupported keyboard cmd=0x%02x\n", val));
515 break;
516 }
517 return rc;
518}
519
520static uint32_t kbd_read_data(void *opaque, uint32_t addr)
521{
522 KBDState *s = (KBDState*)opaque;
523 uint32_t val;
524 NOREF(addr);
525
526 /* Return the current DBB contents. */
527 val = s->dbbout;
528
529 /* Reading the DBB deasserts IRQs... */
530 if (s->status & KBD_STAT_MOUSE_OBF)
531 PDMDevHlpISASetIrq(s->CTX_SUFF(pDevIns), 12, 0);
532 else
533 PDMDevHlpISASetIrq(s->CTX_SUFF(pDevIns), 1, 0);
534 /* ...and clears the OBF bits. */
535 s->status &= ~(KBD_STAT_OBF | KBD_STAT_MOUSE_OBF);
536
537 /* Check if more data is available. */
538 kbd_update_irq(s);
539#ifdef DEBUG_KBD
540 Log(("kbd: read data=0x%02x\n", val));
541#endif
542 return val;
543}
544
545PS2K *GetPS2KFromDevIns(PPDMDEVINS pDevIns)
546{
547 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
548 return &pThis->Kbd;
549}
550
551static void kbd_mouse_set_reported_buttons(KBDState *s, unsigned fButtons, unsigned fButtonMask)
552{
553 s->mouse_buttons_reported |= (fButtons & fButtonMask);
554 s->mouse_buttons_reported &= (fButtons | ~fButtonMask);
555}
556
557/**
558 * Send a single relative packet in 3-byte PS/2 format to the PS/2 controller.
559 * @param s keyboard state object
560 * @param dx relative X value, must be between -256 and +255
561 * @param dy relative y value, must be between -256 and +255
562 * @param fButtonsLow the state of the two first mouse buttons
563 * @param fButtonsPacked the state of the upper three mouse buttons and
564 * scroll wheel movement, packed as per the
565 * MOUSE_EXT_* defines. For standard PS/2 packets
566 * only pass the value of button 3 here.
567 */
568static void kbd_mouse_send_rel3_packet(KBDState *s, bool fToCmdQueue)
569{
570 int aux = fToCmdQueue ? 1 : 2;
571 int dx1 = s->mouse_dx < 0 ? RT_MAX(s->mouse_dx, -256)
572 : RT_MIN(s->mouse_dx, 255);
573 int dy1 = s->mouse_dy < 0 ? RT_MAX(s->mouse_dy, -256)
574 : RT_MIN(s->mouse_dy, 255);
575 unsigned int b;
576 unsigned fButtonsLow = s->mouse_buttons & 0x07;
577 s->mouse_dx -= dx1;
578 s->mouse_dy -= dy1;
579 kbd_mouse_set_reported_buttons(s, fButtonsLow, 0x07);
580 LogRel3(("%s: dx1=%d, dy1=%d, fButtonsLow=0x%x\n",
581 __PRETTY_FUNCTION__, dx1, dy1, fButtonsLow));
582 b = 0x08 | ((dx1 < 0 ? 1 : 0) << 4) | ((dy1 < 0 ? 1 : 0) << 5)
583 | fButtonsLow;
584 kbd_queue(s, b, aux);
585 kbd_queue(s, dx1 & 0xff, aux);
586 kbd_queue(s, dy1 & 0xff, aux);
587}
588
589static void kbd_mouse_send_imps2_byte4(KBDState *s, bool fToCmdQueue)
590{
591 int aux = fToCmdQueue ? 1 : 2;
592
593 int dz1 = s->mouse_dz < 0 ? RT_MAX(s->mouse_dz, -127)
594 : RT_MIN(s->mouse_dz, 127);
595 LogRel3(("%s: dz1=%d\n", __PRETTY_FUNCTION__, dz1));
596 s->mouse_dz -= dz1;
597 kbd_queue(s, dz1 & 0xff, aux);
598}
599
600static void kbd_mouse_send_imex_byte4(KBDState *s, bool fToCmdQueue)
601{
602 int aux = fToCmdQueue ? 1 : 2;
603 int dz1 = 0, dw1 = 0;
604 unsigned fButtonsHigh = s->mouse_buttons & 0x18;
605
606 if (s->mouse_dw > 0)
607 dw1 = 1;
608 else if (s->mouse_dw < 0)
609 dw1 = -1;
610 else if (s->mouse_dz > 0)
611 dz1 = 1;
612 else if (s->mouse_dz < 0)
613 dz1 = -1;
614 if (s->mouse_dw && s->mouse_flags & MOUSE_REPORT_HORIZONTAL)
615 {
616 LogRel3(("%s: dw1=%d\n", __PRETTY_FUNCTION__, dw1));
617 kbd_queue(s, 0x40 | (dw1 & 0x3f), aux);
618 }
619 else
620 {
621 LogRel3(("%s: dz1=%d, dw1=%d, fButtonsHigh=0x%x\n",
622 __PRETTY_FUNCTION__, dz1, dw1, fButtonsHigh));
623 unsigned u4Low = dw1 > 0 ? 9 /* -7 & 0xf */
624 : dw1 < 0 ? 7
625 : dz1 > 0 ? 1
626 : dz1 < 0 ? 0xf /* -1 & 0xf */
627 : 0;
628 kbd_mouse_set_reported_buttons(s, fButtonsHigh, 0x18);
629 kbd_queue(s, (fButtonsHigh << 1) | u4Low, aux);
630 }
631 s->mouse_dz -= dz1;
632 s->mouse_dw -= dw1;
633}
634
635/**
636 * Send a single relative packet in (IM)PS/2 or IMEX format to the PS/2
637 * controller.
638 * @param s keyboard state object
639 * @param fToCmdQueue should this packet go to the command queue (or the
640 * event queue)?
641 */
642static void kbd_mouse_send_packet(KBDState *s, bool fToCmdQueue)
643{
644 kbd_mouse_send_rel3_packet(s, fToCmdQueue);
645 if (s->mouse_type == MOUSE_PROT_IMPS2)
646 kbd_mouse_send_imps2_byte4(s, fToCmdQueue);
647 if (s->mouse_type == MOUSE_PROT_IMEX)
648 kbd_mouse_send_imex_byte4(s, fToCmdQueue);
649}
650
651#ifdef IN_RING3
652
653static bool kbd_mouse_unreported(KBDState *s)
654{
655 return s->mouse_dx
656 || s->mouse_dy
657 || s->mouse_dz
658 || s->mouse_dw
659 || s->mouse_buttons != s->mouse_buttons_reported;
660}
661
662static size_t kbd_mouse_event_queue_free(KBDState *s)
663{
664 AssertReturn(s->mouse_event_queue.count <= MOUSE_EVENT_QUEUE_SIZE, 0);
665 return MOUSE_EVENT_QUEUE_SIZE - s->mouse_event_queue.count;
666}
667
668static void pc_kbd_mouse_event(void *opaque, int dx, int dy, int dz, int dw,
669 int buttons_state)
670{
671 LogRel3(("%s: dx=%d, dy=%d, dz=%d, dw=%d, buttons_state=0x%x\n",
672 __PRETTY_FUNCTION__, dx, dy, dz, dw, buttons_state));
673 KBDState *s = (KBDState*)opaque;
674
675 /* check if deltas are recorded when disabled */
676 if (!(s->mouse_status & MOUSE_STATUS_ENABLED))
677 return;
678 AssertReturnVoid((buttons_state & ~0x1f) == 0);
679
680 s->mouse_dx += dx;
681 s->mouse_dy -= dy;
682 if ( (s->mouse_type == MOUSE_PROT_IMPS2)
683 || (s->mouse_type == MOUSE_PROT_IMEX))
684 s->mouse_dz += dz;
685 if (s->mouse_type == MOUSE_PROT_IMEX)
686 s->mouse_dw += dw;
687 s->mouse_buttons = buttons_state;
688 if (!(s->mouse_status & MOUSE_STATUS_REMOTE))
689 /* if not remote, send event. Multiple events are sent if
690 too big deltas */
691 while ( kbd_mouse_unreported(s)
692 && kbd_mouse_event_queue_free(s) > 4)
693 kbd_mouse_send_packet(s, false);
694}
695
696/* Report a change in status down the driver chain */
697static void kbd_mouse_update_downstream_status(KBDState *pThis)
698{
699 PPDMIMOUSECONNECTOR pDrv = pThis->Mouse.pDrv;
700 bool fEnabled = !!(pThis->mouse_status & MOUSE_STATUS_ENABLED);
701 pDrv->pfnReportModes(pDrv, fEnabled, false);
702}
703
704#endif /* IN_RING3 */
705
706static int kbd_write_mouse(KBDState *s, int val)
707{
708#ifdef DEBUG_MOUSE
709 LogRelFlowFunc(("kbd: write mouse 0x%02x\n", val));
710#endif
711 int rc = VINF_SUCCESS;
712 /* Flush the mouse command response queue. */
713 s->mouse_command_queue.count = 0;
714 s->mouse_command_queue.rptr = 0;
715 s->mouse_command_queue.wptr = 0;
716 switch(s->mouse_write_cmd) {
717 default:
718 case -1:
719 /* mouse command */
720 if (s->mouse_wrap) {
721 if (val == AUX_RESET_WRAP) {
722 s->mouse_wrap = 0;
723 kbd_queue(s, AUX_ACK, 1);
724 return VINF_SUCCESS;
725 } else if (val != AUX_RESET) {
726 kbd_queue(s, val, 1);
727 return VINF_SUCCESS;
728 }
729 }
730 switch(val) {
731 case AUX_SET_SCALE11:
732 s->mouse_status &= ~MOUSE_STATUS_SCALE21;
733 kbd_queue(s, AUX_ACK, 1);
734 break;
735 case AUX_SET_SCALE21:
736 s->mouse_status |= MOUSE_STATUS_SCALE21;
737 kbd_queue(s, AUX_ACK, 1);
738 break;
739 case AUX_SET_STREAM:
740 s->mouse_status &= ~MOUSE_STATUS_REMOTE;
741 kbd_queue(s, AUX_ACK, 1);
742 break;
743 case AUX_SET_WRAP:
744 s->mouse_wrap = 1;
745 kbd_queue(s, AUX_ACK, 1);
746 break;
747 case AUX_SET_REMOTE:
748 s->mouse_status |= MOUSE_STATUS_REMOTE;
749 kbd_queue(s, AUX_ACK, 1);
750 break;
751 case AUX_GET_TYPE:
752 kbd_queue(s, AUX_ACK, 1);
753 kbd_queue(s, s->mouse_type, 1);
754 break;
755 case AUX_SET_RES:
756 case AUX_SET_SAMPLE:
757 s->mouse_write_cmd = val;
758 kbd_queue(s, AUX_ACK, 1);
759 break;
760 case AUX_GET_SCALE:
761 kbd_queue(s, AUX_ACK, 1);
762 kbd_queue(s, s->mouse_status, 1);
763 kbd_queue(s, s->mouse_resolution, 1);
764 kbd_queue(s, s->mouse_sample_rate, 1);
765 break;
766 case AUX_POLL:
767 kbd_queue(s, AUX_ACK, 1);
768 kbd_mouse_send_packet(s, true);
769 break;
770 case AUX_ENABLE_DEV:
771#ifdef IN_RING3
772 LogRelFlowFunc(("Enabling mouse device\n"));
773 s->mouse_status |= MOUSE_STATUS_ENABLED;
774 kbd_queue(s, AUX_ACK, 1);
775 kbd_mouse_update_downstream_status(s);
776#else
777 LogRelFlowFunc(("Enabling mouse device, R0 stub\n"));
778 rc = VINF_IOM_R3_IOPORT_WRITE;
779#endif
780 break;
781 case AUX_DISABLE_DEV:
782#ifdef IN_RING3
783 s->mouse_status &= ~MOUSE_STATUS_ENABLED;
784 kbd_queue(s, AUX_ACK, 1);
785 /* Flush the mouse events queue. */
786 s->mouse_event_queue.count = 0;
787 s->mouse_event_queue.rptr = 0;
788 s->mouse_event_queue.wptr = 0;
789 kbd_mouse_update_downstream_status(s);
790#else
791 rc = VINF_IOM_R3_IOPORT_WRITE;
792#endif
793 break;
794 case AUX_SET_DEFAULT:
795#ifdef IN_RING3
796 s->mouse_sample_rate = 100;
797 s->mouse_resolution = 2;
798 s->mouse_status = 0;
799 kbd_queue(s, AUX_ACK, 1);
800 kbd_mouse_update_downstream_status(s);
801#else
802 rc = VINF_IOM_R3_IOPORT_WRITE;
803#endif
804 break;
805 case AUX_RESET:
806#ifdef IN_RING3
807 s->mouse_sample_rate = 100;
808 s->mouse_resolution = 2;
809 s->mouse_status = 0;
810 s->mouse_type = MOUSE_PROT_PS2;
811 kbd_queue(s, AUX_ACK, 1);
812 kbd_queue(s, 0xaa, 1);
813 kbd_queue(s, s->mouse_type, 1);
814 /* Flush the mouse events queue. */
815 s->mouse_event_queue.count = 0;
816 s->mouse_event_queue.rptr = 0;
817 s->mouse_event_queue.wptr = 0;
818 kbd_mouse_update_downstream_status(s);
819#else
820 rc = VINF_IOM_R3_IOPORT_WRITE;
821#endif
822 break;
823 default:
824 /* NACK all commands we don't know.
825
826 The usecase for this is the OS/2 mouse driver which will try
827 read 0xE2 in order to figure out if it's a trackpoint device
828 or not. If it doesn't get a NACK (or ACK) on the command it'll
829 do several hundred thousand status reads before giving up. This
830 is slows down the OS/2 boot up considerably. (It also seems that
831 the code is somehow vulnerable while polling like this and that
832 mouse or keyboard input at this point might screw things up badly.)
833
834 From http://www.win.tue.nl/~aeb/linux/kbd/scancodes-13.html:
835
836 Every command or data byte sent to the mouse (except for the
837 resend command fe) is ACKed with fa. If the command or data
838 is invalid, it is NACKed with fe. If the next byte is again
839 invalid, the reply is ERROR: fc. */
840 /** @todo send error if we NACKed the previous command? */
841 kbd_queue(s, AUX_NACK, 1);
842 break;
843 }
844 break;
845 case AUX_SET_SAMPLE:
846 s->mouse_sample_rate = val;
847 /* detect IMPS/2 or IMEX */
848 /* And enable horizontal scrolling reporting when requested */
849 switch(s->mouse_detect_state) {
850 default:
851 case 0:
852 if (val == 200)
853 s->mouse_detect_state = 1;
854 break;
855 case 1:
856 if (val == 100)
857 s->mouse_detect_state = 2;
858 else if (val == 200)
859 s->mouse_detect_state = 3;
860 else if ((val == 80) && s->mouse_type == MOUSE_PROT_IMEX)
861 /* enable horizontal scrolling, byte two */
862 s->mouse_detect_state = 4;
863 else
864 s->mouse_detect_state = 0;
865 break;
866 case 2:
867 if (val == 80 && s->mouse_type < MOUSE_PROT_IMEX)
868 {
869 LogRelFlowFunc(("switching mouse device to IMPS/2 mode\n"));
870 s->mouse_type = MOUSE_PROT_IMPS2;
871 }
872 s->mouse_detect_state = 0;
873 break;
874 case 3:
875 if (val == 80)
876 {
877 LogRelFlowFunc(("switching mouse device to IMEX mode\n"));
878 s->mouse_type = MOUSE_PROT_IMEX;
879 }
880 s->mouse_detect_state = 0;
881 break;
882 case 4:
883 if (val == 40)
884 {
885 LogRelFlowFunc(("enabling IMEX horizontal scrolling reporting\n"));
886 s->mouse_flags |= MOUSE_REPORT_HORIZONTAL;
887 }
888 s->mouse_detect_state = 0;
889 break;
890 }
891 kbd_queue(s, AUX_ACK, 1);
892 s->mouse_write_cmd = -1;
893 break;
894 case AUX_SET_RES:
895 if (0 <= val && val < 4)
896 {
897 s->mouse_resolution = val;
898 kbd_queue(s, AUX_ACK, 1);
899 }
900 else
901 kbd_queue(s, AUX_NACK, 1);
902 s->mouse_write_cmd = -1;
903 break;
904 }
905 return rc;
906}
907
908static int kbd_write_data(void *opaque, uint32_t addr, uint32_t val)
909{
910 int rc = VINF_SUCCESS;
911 KBDState *s = (KBDState*)opaque;
912 NOREF(addr);
913
914#ifdef DEBUG_KBD
915 Log(("kbd: write data=0x%02x\n", val));
916#endif
917
918 switch(s->write_cmd) {
919 case 0:
920 /* Automatically enables keyboard interface. */
921 s->mode &= ~KBD_MODE_DISABLE_KBD;
922 rc = PS2KByteToKbd(&s->Kbd, val);
923 if (rc == VINF_SUCCESS)
924 kbd_update_irq(s);
925 break;
926 case KBD_CCMD_WRITE_MODE:
927 s->mode = val;
928 s->translate = (s->mode & KBD_MODE_KCC) == KBD_MODE_KCC;
929 kbd_update_irq(s);
930 break;
931 case KBD_CCMD_WRITE_OBUF:
932 kbc_dbb_out(s, val);
933 break;
934 case KBD_CCMD_WRITE_AUX_OBUF:
935 kbd_queue(s, val, 1);
936 break;
937 case KBD_CCMD_WRITE_OUTPORT:
938#ifdef TARGET_I386
939# ifndef IN_RING3
940 if (PDMDevHlpA20IsEnabled(s->CTX_SUFF(pDevIns)) != !!(val & 2))
941 rc = VINF_IOM_R3_IOPORT_WRITE;
942# else /* IN_RING3 */
943 PDMDevHlpA20Set(s->CTX_SUFF(pDevIns), !!(val & 2));
944# endif /* !IN_RING3 */
945#endif
946 if (!(val & 1)) {
947# ifndef IN_RING3
948 rc = VINF_IOM_R3_IOPORT_WRITE;
949# else
950 rc = PDMDevHlpVMReset(s->CTX_SUFF(pDevIns));
951# endif
952 }
953 break;
954 case KBD_CCMD_WRITE_MOUSE:
955 /* Automatically enables aux interface. */
956 s->mode &= ~KBD_MODE_DISABLE_MOUSE;
957 rc = kbd_write_mouse(s, val);
958 break;
959 default:
960 break;
961 }
962 if (rc != VINF_IOM_R3_IOPORT_WRITE)
963 s->write_cmd = 0;
964 return rc;
965}
966
967#ifdef IN_RING3
968
969static void kbd_reset(void *opaque)
970{
971 KBDState *s = (KBDState*)opaque;
972 MouseCmdQueue *mcq;
973 MouseEventQueue *meq;
974
975 s->mouse_write_cmd = -1;
976 s->mode = KBD_MODE_KBD_INT | KBD_MODE_MOUSE_INT;
977 s->status = KBD_STAT_CMD | KBD_STAT_UNLOCKED;
978 /* Resetting everything, keyword was not working right on NT4 reboot. */
979 s->write_cmd = 0;
980 s->translate = 0;
981 if (s->mouse_status)
982 {
983 s->mouse_status = 0;
984 kbd_mouse_update_downstream_status(s);
985 }
986 s->mouse_resolution = 0;
987 s->mouse_sample_rate = 0;
988 s->mouse_wrap = 0;
989 s->mouse_type = MOUSE_PROT_PS2;
990 s->mouse_detect_state = 0;
991 s->mouse_dx = 0;
992 s->mouse_dy = 0;
993 s->mouse_dz = 0;
994 s->mouse_dw = 0;
995 s->mouse_flags = 0;
996 s->mouse_buttons = 0;
997 s->mouse_buttons_reported = 0;
998 mcq = &s->mouse_command_queue;
999 mcq->rptr = 0;
1000 mcq->wptr = 0;
1001 mcq->count = 0;
1002 meq = &s->mouse_event_queue;
1003 meq->rptr = 0;
1004 meq->wptr = 0;
1005 meq->count = 0;
1006}
1007
1008static void kbd_save(QEMUFile* f, void* opaque)
1009{
1010 uint32_t cItems;
1011 int i;
1012 KBDState *s = (KBDState*)opaque;
1013
1014 qemu_put_8s(f, &s->write_cmd);
1015 qemu_put_8s(f, &s->status);
1016 qemu_put_8s(f, &s->mode);
1017 qemu_put_8s(f, &s->dbbout);
1018 qemu_put_be32s(f, &s->mouse_write_cmd);
1019 qemu_put_8s(f, &s->mouse_status);
1020 qemu_put_8s(f, &s->mouse_resolution);
1021 qemu_put_8s(f, &s->mouse_sample_rate);
1022 qemu_put_8s(f, &s->mouse_wrap);
1023 qemu_put_8s(f, &s->mouse_type);
1024 qemu_put_8s(f, &s->mouse_detect_state);
1025 qemu_put_be32s(f, &s->mouse_dx);
1026 qemu_put_be32s(f, &s->mouse_dy);
1027 qemu_put_be32s(f, &s->mouse_dz);
1028 qemu_put_be32s(f, &s->mouse_dw);
1029 qemu_put_be32s(f, &s->mouse_flags);
1030 qemu_put_8s(f, &s->mouse_buttons);
1031 qemu_put_8s(f, &s->mouse_buttons_reported);
1032
1033 cItems = s->mouse_command_queue.count;
1034 SSMR3PutU32(f, cItems);
1035 for (i = s->mouse_command_queue.rptr; cItems-- > 0; i = (i + 1) % RT_ELEMENTS(s->mouse_command_queue.data))
1036 SSMR3PutU8(f, s->mouse_command_queue.data[i]);
1037 Log(("kbd_save: %d mouse command queue items stored\n", s->mouse_command_queue.count));
1038
1039 cItems = s->mouse_event_queue.count;
1040 SSMR3PutU32(f, cItems);
1041 for (i = s->mouse_event_queue.rptr; cItems-- > 0; i = (i + 1) % RT_ELEMENTS(s->mouse_event_queue.data))
1042 SSMR3PutU8(f, s->mouse_event_queue.data[i]);
1043 Log(("kbd_save: %d mouse event queue items stored\n", s->mouse_event_queue.count));
1044
1045 /* terminator */
1046 SSMR3PutU32(f, ~0);
1047}
1048
1049static int kbd_load(QEMUFile* f, void* opaque, int version_id)
1050{
1051 uint32_t u32, i;
1052 uint8_t u8Dummy;
1053 uint32_t u32Dummy;
1054 int rc;
1055 KBDState *s = (KBDState*)opaque;
1056
1057#if 0
1058 /** @todo enable this and remove the "if (version_id == 4)" code at some
1059 * later time */
1060 /* Version 4 was never created by any publicly released version of VBox */
1061 AssertReturn(version_id != 4, VERR_NOT_SUPPORTED);
1062#endif
1063 if (version_id < 2 || version_id > PCKBD_SAVED_STATE_VERSION)
1064 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
1065 qemu_get_8s(f, &s->write_cmd);
1066 qemu_get_8s(f, &s->status);
1067 qemu_get_8s(f, &s->mode);
1068 if (version_id <= 5)
1069 {
1070 qemu_get_be32s(f, (uint32_t *)&u32Dummy);
1071 qemu_get_be32s(f, (uint32_t *)&u32Dummy);
1072 }
1073 else
1074 {
1075 qemu_get_8s(f, &s->dbbout);
1076 }
1077 qemu_get_be32s(f, (uint32_t *)&s->mouse_write_cmd);
1078 qemu_get_8s(f, &s->mouse_status);
1079 qemu_get_8s(f, &s->mouse_resolution);
1080 qemu_get_8s(f, &s->mouse_sample_rate);
1081 qemu_get_8s(f, &s->mouse_wrap);
1082 qemu_get_8s(f, &s->mouse_type);
1083 qemu_get_8s(f, &s->mouse_detect_state);
1084 qemu_get_be32s(f, (uint32_t *)&s->mouse_dx);
1085 qemu_get_be32s(f, (uint32_t *)&s->mouse_dy);
1086 qemu_get_be32s(f, (uint32_t *)&s->mouse_dz);
1087 if (version_id > 2)
1088 {
1089 SSMR3GetS32(f, &s->mouse_dw);
1090 SSMR3GetS32(f, &s->mouse_flags);
1091 }
1092 qemu_get_8s(f, &s->mouse_buttons);
1093 if (version_id == 4)
1094 {
1095 SSMR3GetU32(f, &u32Dummy);
1096 SSMR3GetU32(f, &u32Dummy);
1097 }
1098 if (version_id > 3)
1099 SSMR3GetU8(f, &s->mouse_buttons_reported);
1100 if (version_id == 4)
1101 SSMR3GetU8(f, &u8Dummy);
1102 s->mouse_command_queue.count = 0;
1103 s->mouse_command_queue.rptr = 0;
1104 s->mouse_command_queue.wptr = 0;
1105 s->mouse_event_queue.count = 0;
1106 s->mouse_event_queue.rptr = 0;
1107 s->mouse_event_queue.wptr = 0;
1108
1109 /* Determine the translation state. */
1110 s->translate = (s->mode & KBD_MODE_KCC) == KBD_MODE_KCC;
1111
1112 /*
1113 * Load the queues
1114 */
1115 if (version_id <= 5)
1116 {
1117 rc = SSMR3GetU32(f, &u32);
1118 if (RT_FAILURE(rc))
1119 return rc;
1120 for (i = 0; i < u32; i++)
1121 {
1122 rc = SSMR3GetU8(f, &u8Dummy);
1123 if (RT_FAILURE(rc))
1124 return rc;
1125 }
1126 Log(("kbd_load: %d keyboard queue items discarded from old saved state\n", u32));
1127 }
1128
1129 rc = SSMR3GetU32(f, &u32);
1130 if (RT_FAILURE(rc))
1131 return rc;
1132 if (u32 > RT_ELEMENTS(s->mouse_command_queue.data))
1133 {
1134 AssertMsgFailed(("u32=%#x\n", u32));
1135 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
1136 }
1137 for (i = 0; i < u32; i++)
1138 {
1139 rc = SSMR3GetU8(f, &s->mouse_command_queue.data[i]);
1140 if (RT_FAILURE(rc))
1141 return rc;
1142 }
1143 s->mouse_command_queue.wptr = u32 % RT_ELEMENTS(s->mouse_command_queue.data);
1144 s->mouse_command_queue.count = u32;
1145 Log(("kbd_load: %d mouse command queue items loaded\n", u32));
1146
1147 rc = SSMR3GetU32(f, &u32);
1148 if (RT_FAILURE(rc))
1149 return rc;
1150 if (u32 > RT_ELEMENTS(s->mouse_event_queue.data))
1151 {
1152 AssertMsgFailed(("u32=%#x\n", u32));
1153 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
1154 }
1155 for (i = 0; i < u32; i++)
1156 {
1157 rc = SSMR3GetU8(f, &s->mouse_event_queue.data[i]);
1158 if (RT_FAILURE(rc))
1159 return rc;
1160 }
1161 s->mouse_event_queue.wptr = u32 % RT_ELEMENTS(s->mouse_event_queue.data);
1162 s->mouse_event_queue.count = u32;
1163 Log(("kbd_load: %d mouse event queue items loaded\n", u32));
1164
1165 /* terminator */
1166 rc = SSMR3GetU32(f, &u32);
1167 if (RT_FAILURE(rc))
1168 return rc;
1169 if (u32 != ~0U)
1170 {
1171 AssertMsgFailed(("u32=%#x\n", u32));
1172 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
1173 }
1174 /* Resend a notification to Main if the device is active */
1175 kbd_mouse_update_downstream_status(s);
1176 return 0;
1177}
1178#endif /* IN_RING3 */
1179
1180
1181/* VirtualBox code start */
1182
1183/* -=-=-=-=-=- wrappers -=-=-=-=-=- */
1184
1185/**
1186 * Port I/O Handler for keyboard data IN operations.
1187 *
1188 * @returns VBox status code.
1189 *
1190 * @param pDevIns The device instance.
1191 * @param pvUser User argument - ignored.
1192 * @param Port Port number used for the IN operation.
1193 * @param pu32 Where to store the result.
1194 * @param cb Number of bytes read.
1195 */
1196PDMBOTHCBDECL(int) kbdIOPortDataRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
1197{
1198 NOREF(pvUser);
1199 if (cb == 1)
1200 {
1201 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
1202 int rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_R3_IOPORT_READ);
1203 if (RT_LIKELY(rc == VINF_SUCCESS))
1204 {
1205 *pu32 = kbd_read_data(pThis, Port);
1206 PDMCritSectLeave(&pThis->CritSect);
1207 Log2(("kbdIOPortDataRead: Port=%#x cb=%d *pu32=%#x\n", Port, cb, *pu32));
1208 }
1209 return rc;
1210 }
1211 AssertMsgFailed(("Port=%#x cb=%d\n", Port, cb));
1212 return VERR_IOM_IOPORT_UNUSED;
1213}
1214
1215/**
1216 * Port I/O Handler for keyboard data OUT operations.
1217 *
1218 * @returns VBox status code.
1219 *
1220 * @param pDevIns The device instance.
1221 * @param pvUser User argument - ignored.
1222 * @param Port Port number used for the IN operation.
1223 * @param u32 The value to output.
1224 * @param cb The value size in bytes.
1225 */
1226PDMBOTHCBDECL(int) kbdIOPortDataWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
1227{
1228 int rc = VINF_SUCCESS;
1229 NOREF(pvUser);
1230 if (cb == 1)
1231 {
1232 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
1233 rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_R3_IOPORT_WRITE);
1234 if (RT_LIKELY(rc == VINF_SUCCESS))
1235 {
1236 rc = kbd_write_data(pThis, Port, u32);
1237 PDMCritSectLeave(&pThis->CritSect);
1238 Log2(("kbdIOPortDataWrite: Port=%#x cb=%d u32=%#x\n", Port, cb, u32));
1239 }
1240 }
1241 else
1242 AssertMsgFailed(("Port=%#x cb=%d\n", Port, cb));
1243 return rc;
1244}
1245
1246/**
1247 * Port I/O Handler for keyboard status IN operations.
1248 *
1249 * @returns VBox status code.
1250 *
1251 * @param pDevIns The device instance.
1252 * @param pvUser User argument - ignored.
1253 * @param Port Port number used for the IN operation.
1254 * @param pu32 Where to store the result.
1255 * @param cb Number of bytes read.
1256 */
1257PDMBOTHCBDECL(int) kbdIOPortStatusRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
1258{
1259 NOREF(pvUser);
1260 if (cb == 1)
1261 {
1262 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
1263 int rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_R3_IOPORT_READ);
1264 if (RT_LIKELY(rc == VINF_SUCCESS))
1265 {
1266 *pu32 = kbd_read_status(pThis, Port);
1267 PDMCritSectLeave(&pThis->CritSect);
1268 Log2(("kbdIOPortStatusRead: Port=%#x cb=%d -> *pu32=%#x\n", Port, cb, *pu32));
1269 }
1270 return rc;
1271 }
1272 AssertMsgFailed(("Port=%#x cb=%d\n", Port, cb));
1273 return VERR_IOM_IOPORT_UNUSED;
1274}
1275
1276/**
1277 * Port I/O Handler for keyboard command OUT operations.
1278 *
1279 * @returns VBox status code.
1280 *
1281 * @param pDevIns The device instance.
1282 * @param pvUser User argument - ignored.
1283 * @param Port Port number used for the IN operation.
1284 * @param u32 The value to output.
1285 * @param cb The value size in bytes.
1286 */
1287PDMBOTHCBDECL(int) kbdIOPortCommandWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
1288{
1289 int rc = VINF_SUCCESS;
1290 NOREF(pvUser);
1291 if (cb == 1)
1292 {
1293 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
1294 rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_R3_IOPORT_WRITE);
1295 if (RT_LIKELY(rc == VINF_SUCCESS))
1296 {
1297 rc = kbd_write_command(pThis, Port, u32);
1298 PDMCritSectLeave(&pThis->CritSect);
1299 Log2(("kbdIOPortCommandWrite: Port=%#x cb=%d u32=%#x rc=%Rrc\n", Port, cb, u32, rc));
1300 }
1301 }
1302 else
1303 AssertMsgFailed(("Port=%#x cb=%d\n", Port, cb));
1304 return rc;
1305}
1306
1307#ifdef IN_RING3
1308
1309/**
1310 * Saves a state of the keyboard device.
1311 *
1312 * @returns VBox status code.
1313 * @param pDevIns The device instance.
1314 * @param pSSMHandle The handle to save the state to.
1315 */
1316static DECLCALLBACK(int) kbdSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
1317{
1318 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
1319 kbd_save(pSSMHandle, pThis);
1320 PS2KSaveState(pSSMHandle, &pThis->Kbd);
1321 return VINF_SUCCESS;
1322}
1323
1324
1325/**
1326 * Loads a saved keyboard device state.
1327 *
1328 * @returns VBox status code.
1329 * @param pDevIns The device instance.
1330 * @param pSSMHandle The handle to the saved state.
1331 * @param uVersion The data unit version number.
1332 * @param uPass The data pass.
1333 */
1334static DECLCALLBACK(int) kbdLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle, uint32_t uVersion, uint32_t uPass)
1335{
1336 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
1337 int rc;
1338
1339 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
1340 rc = kbd_load(pSSMHandle, pThis, uVersion);
1341 if (uVersion >= 6)
1342 rc = PS2KLoadState(pSSMHandle, &pThis->Kbd, uVersion);
1343 return rc;
1344}
1345
1346/**
1347 * Reset notification.
1348 *
1349 * @returns VBox status.
1350 * @param pDevIns The device instance data.
1351 */
1352static DECLCALLBACK(void) kbdReset(PPDMDEVINS pDevIns)
1353{
1354 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
1355
1356 kbd_reset(pThis);
1357 PS2KReset(&pThis->Kbd);
1358}
1359
1360
1361/* -=-=-=-=-=- Mouse: IBase -=-=-=-=-=- */
1362
1363/**
1364 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
1365 */
1366static DECLCALLBACK(void *) kbdMouseQueryInterface(PPDMIBASE pInterface, const char *pszIID)
1367{
1368 KBDState *pThis = RT_FROM_MEMBER(pInterface, KBDState, Mouse.IBase);
1369 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->Mouse.IBase);
1370 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSEPORT, &pThis->Mouse.IPort);
1371 return NULL;
1372}
1373
1374
1375/* -=-=-=-=-=- Mouse: IMousePort -=-=-=-=-=- */
1376
1377/**
1378 * @interface_method_impl{PDMIMOUSEPORT, pfnPutEvent}
1379 */
1380static DECLCALLBACK(int) kbdMousePutEvent(PPDMIMOUSEPORT pInterface, int32_t iDeltaX, int32_t iDeltaY,
1381 int32_t iDeltaZ, int32_t iDeltaW, uint32_t fButtonStates)
1382{
1383 KBDState *pThis = RT_FROM_MEMBER(pInterface, KBDState, Mouse.IPort);
1384 int rc = PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
1385 AssertReleaseRC(rc);
1386
1387 pc_kbd_mouse_event(pThis, iDeltaX, iDeltaY, iDeltaZ, iDeltaW, fButtonStates);
1388
1389 PDMCritSectLeave(&pThis->CritSect);
1390 return VINF_SUCCESS;
1391}
1392
1393/**
1394 * @interface_method_impl{PDMIMOUSEPORT, pfnPutEventAbs}
1395 */
1396static DECLCALLBACK(int) kbdMousePutEventAbs(PPDMIMOUSEPORT pInterface, uint32_t uX, uint32_t uY, int32_t iDeltaZ, int32_t iDeltaW, uint32_t fButtons)
1397{
1398 AssertFailedReturn(VERR_NOT_SUPPORTED);
1399 NOREF(pInterface); NOREF(uX); NOREF(uY); NOREF(iDeltaZ); NOREF(iDeltaW); NOREF(fButtons);
1400}
1401
1402
1403/* -=-=-=-=-=- real code -=-=-=-=-=- */
1404
1405
1406/**
1407 * Attach command.
1408 *
1409 * This is called to let the device attach to a driver for a specified LUN
1410 * during runtime. This is not called during VM construction, the device
1411 * constructor have to attach to all the available drivers.
1412 *
1413 * This is like plugging in the keyboard or mouse after turning on the PC.
1414 *
1415 * @returns VBox status code.
1416 * @param pDevIns The device instance.
1417 * @param iLUN The logical unit which is being detached.
1418 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
1419 * @remark The keyboard controller doesn't support this action, this is just
1420 * implemented to try out the driver<->device structure.
1421 */
1422static DECLCALLBACK(int) kbdAttach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
1423{
1424 int rc;
1425 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
1426
1427 AssertMsgReturn(fFlags & PDM_TACH_FLAGS_NOT_HOT_PLUG,
1428 ("PS/2 device does not support hotplugging\n"),
1429 VERR_INVALID_PARAMETER);
1430
1431 switch (iLUN)
1432 {
1433 /* LUN #0: keyboard */
1434 case 0:
1435 rc = PS2KAttach(pDevIns, &pThis->Kbd, iLUN, fFlags);
1436 if (RT_FAILURE(rc))
1437 return rc;
1438 break;
1439
1440 /* LUN #1: aux/mouse */
1441 case 1:
1442 rc = PDMDevHlpDriverAttach(pDevIns, iLUN, &pThis->Mouse.IBase, &pThis->Mouse.pDrvBase, "Aux (Mouse) Port");
1443 if (RT_SUCCESS(rc))
1444 {
1445 pThis->Mouse.pDrv = PDMIBASE_QUERY_INTERFACE(pThis->Mouse.pDrvBase, PDMIMOUSECONNECTOR);
1446 if (!pThis->Mouse.pDrv)
1447 {
1448 AssertLogRelMsgFailed(("LUN #1 doesn't have a mouse interface! rc=%Rrc\n", rc));
1449 rc = VERR_PDM_MISSING_INTERFACE;
1450 }
1451 }
1452 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
1453 {
1454 Log(("%s/%d: warning: no driver attached to LUN #1!\n", pDevIns->pReg->szName, pDevIns->iInstance));
1455 rc = VINF_SUCCESS;
1456 }
1457 else
1458 AssertLogRelMsgFailed(("Failed to attach LUN #1! rc=%Rrc\n", rc));
1459 break;
1460
1461 default:
1462 AssertMsgFailed(("Invalid LUN #%d\n", iLUN));
1463 return VERR_PDM_NO_SUCH_LUN;
1464 }
1465
1466 return rc;
1467}
1468
1469
1470/**
1471 * Detach notification.
1472 *
1473 * This is called when a driver is detaching itself from a LUN of the device.
1474 * The device should adjust it's state to reflect this.
1475 *
1476 * This is like unplugging the network cable to use it for the laptop or
1477 * something while the PC is still running.
1478 *
1479 * @param pDevIns The device instance.
1480 * @param iLUN The logical unit which is being detached.
1481 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
1482 * @remark The keyboard controller doesn't support this action, this is just
1483 * implemented to try out the driver<->device structure.
1484 */
1485static DECLCALLBACK(void) kbdDetach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
1486{
1487#if 0
1488 /*
1489 * Reset the interfaces and update the controller state.
1490 */
1491 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
1492 switch (iLUN)
1493 {
1494 /* LUN #0: keyboard */
1495 case 0:
1496 pThis->Keyboard.pDrv = NULL;
1497 pThis->Keyboard.pDrvBase = NULL;
1498 break;
1499
1500 /* LUN #1: aux/mouse */
1501 case 1:
1502 pThis->Mouse.pDrv = NULL;
1503 pThis->Mouse.pDrvBase = NULL;
1504 break;
1505
1506 default:
1507 AssertMsgFailed(("Invalid LUN #%d\n", iLUN));
1508 break;
1509 }
1510#else
1511 NOREF(pDevIns); NOREF(iLUN); NOREF(fFlags);
1512#endif
1513}
1514
1515
1516/**
1517 * @copydoc FNPDMDEVRELOCATE
1518 */
1519static DECLCALLBACK(void) kbdRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
1520{
1521 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
1522 pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
1523 PS2KRelocate(&pThis->Kbd, offDelta);
1524}
1525
1526
1527/**
1528 * Destruct a device instance for a VM.
1529 *
1530 * @returns VBox status.
1531 * @param pDevIns The device instance data.
1532 */
1533static DECLCALLBACK(int) kbdDestruct(PPDMDEVINS pDevIns)
1534{
1535 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
1536 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
1537
1538 PDMR3CritSectDelete(&pThis->CritSect);
1539
1540 return VINF_SUCCESS;
1541}
1542
1543
1544/**
1545 * @interface_method_impl{PDMDEVREG,pfnConstruct}
1546 */
1547static DECLCALLBACK(int) kbdConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
1548{
1549 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
1550 int rc;
1551 bool fGCEnabled;
1552 bool fR0Enabled;
1553 Assert(iInstance == 0);
1554
1555 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
1556
1557 /*
1558 * Validate and read the configuration.
1559 */
1560 if (!CFGMR3AreValuesValid(pCfg, "GCEnabled\0R0Enabled\0"))
1561 return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
1562 rc = CFGMR3QueryBoolDef(pCfg, "GCEnabled", &fGCEnabled, true);
1563 if (RT_FAILURE(rc))
1564 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to query \"GCEnabled\" from the config"));
1565 rc = CFGMR3QueryBoolDef(pCfg, "R0Enabled", &fR0Enabled, true);
1566 if (RT_FAILURE(rc))
1567 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to query \"R0Enabled\" from the config"));
1568 Log(("pckbd: fGCEnabled=%RTbool fR0Enabled=%RTbool\n", fGCEnabled, fR0Enabled));
1569
1570
1571 /*
1572 * Initialize the interfaces.
1573 */
1574 pThis->pDevInsR3 = pDevIns;
1575 pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
1576 pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
1577
1578 rc = PS2KConstruct(pDevIns, &pThis->Kbd, pThis, iInstance);
1579 if (RT_FAILURE(rc))
1580 return rc;
1581
1582 pThis->Mouse.IBase.pfnQueryInterface = kbdMouseQueryInterface;
1583 pThis->Mouse.IPort.pfnPutEvent = kbdMousePutEvent;
1584 pThis->Mouse.IPort.pfnPutEventAbs = kbdMousePutEventAbs;
1585
1586 /*
1587 * Initialize the critical section.
1588 */
1589 rc = PDMDevHlpCritSectInit(pDevIns, &pThis->CritSect, RT_SRC_POS, "PS2KM#%u", iInstance);
1590 if (RT_FAILURE(rc))
1591 return rc;
1592
1593 /*
1594 * Register I/O ports, save state, keyboard event handler and mouse event handlers.
1595 */
1596 rc = PDMDevHlpIOPortRegister(pDevIns, 0x60, 1, NULL, kbdIOPortDataWrite, kbdIOPortDataRead, NULL, NULL, "PC Keyboard - Data");
1597 if (RT_FAILURE(rc))
1598 return rc;
1599 rc = PDMDevHlpIOPortRegister(pDevIns, 0x64, 1, NULL, kbdIOPortCommandWrite, kbdIOPortStatusRead, NULL, NULL, "PC Keyboard - Command / Status");
1600 if (RT_FAILURE(rc))
1601 return rc;
1602 if (fGCEnabled)
1603 {
1604 rc = PDMDevHlpIOPortRegisterRC(pDevIns, 0x60, 1, 0, "kbdIOPortDataWrite", "kbdIOPortDataRead", NULL, NULL, "PC Keyboard - Data");
1605 if (RT_FAILURE(rc))
1606 return rc;
1607 rc = PDMDevHlpIOPortRegisterRC(pDevIns, 0x64, 1, 0, "kbdIOPortCommandWrite", "kbdIOPortStatusRead", NULL, NULL, "PC Keyboard - Command / Status");
1608 if (RT_FAILURE(rc))
1609 return rc;
1610 }
1611 if (fR0Enabled)
1612 {
1613 rc = PDMDevHlpIOPortRegisterR0(pDevIns, 0x60, 1, 0, "kbdIOPortDataWrite", "kbdIOPortDataRead", NULL, NULL, "PC Keyboard - Data");
1614 if (RT_FAILURE(rc))
1615 return rc;
1616 rc = PDMDevHlpIOPortRegisterR0(pDevIns, 0x64, 1, 0, "kbdIOPortCommandWrite", "kbdIOPortStatusRead", NULL, NULL, "PC Keyboard - Command / Status");
1617 if (RT_FAILURE(rc))
1618 return rc;
1619 }
1620 rc = PDMDevHlpSSMRegister(pDevIns, PCKBD_SAVED_STATE_VERSION, sizeof(*pThis), kbdSaveExec, kbdLoadExec);
1621 if (RT_FAILURE(rc))
1622 return rc;
1623
1624 /*
1625 * Attach to the keyboard and mouse drivers.
1626 */
1627 rc = kbdAttach(pDevIns, 0 /* keyboard LUN # */, PDM_TACH_FLAGS_NOT_HOT_PLUG);
1628 if (RT_FAILURE(rc))
1629 return rc;
1630 rc = kbdAttach(pDevIns, 1 /* aux/mouse LUN # */, PDM_TACH_FLAGS_NOT_HOT_PLUG);
1631 if (RT_FAILURE(rc))
1632 return rc;
1633
1634 /*
1635 * Initialize the device state.
1636 */
1637 kbdReset(pDevIns);
1638
1639 return VINF_SUCCESS;
1640}
1641
1642
1643/**
1644 * The device registration structure.
1645 */
1646const PDMDEVREG g_DevicePS2KeyboardMouse =
1647{
1648 /* u32Version */
1649 PDM_DEVREG_VERSION,
1650 /* szName */
1651 "pckbd",
1652 /* szRCMod */
1653 "VBoxDDGC.gc",
1654 /* szR0Mod */
1655 "VBoxDDR0.r0",
1656 /* pszDescription */
1657 "PS/2 Keyboard and Mouse device. Emulates both the keyboard, mouse and the keyboard controller. "
1658 "LUN #0 is the keyboard connector. "
1659 "LUN #1 is the aux/mouse connector.",
1660 /* fFlags */
1661 PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_32_64 | PDM_DEVREG_FLAGS_PAE36 | PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0,
1662 /* fClass */
1663 PDM_DEVREG_CLASS_INPUT,
1664 /* cMaxInstances */
1665 1,
1666 /* cbInstance */
1667 sizeof(KBDState),
1668 /* pfnConstruct */
1669 kbdConstruct,
1670 /* pfnDestruct */
1671 kbdDestruct,
1672 /* pfnRelocate */
1673 kbdRelocate,
1674 /* pfnIOCtl */
1675 NULL,
1676 /* pfnPowerOn */
1677 NULL,
1678 /* pfnReset */
1679 kbdReset,
1680 /* pfnSuspend */
1681 NULL,
1682 /* pfnResume */
1683 NULL,
1684 /* pfnAttach */
1685 kbdAttach,
1686 /* pfnDetach */
1687 kbdDetach,
1688 /* pfnQueryInterface. */
1689 NULL,
1690 /* pfnInitComplete */
1691 NULL,
1692 /* pfnPowerOff */
1693 NULL,
1694 /* pfnSoftReset */
1695 NULL,
1696 /* u32VersionEnd */
1697 PDM_DEVREG_VERSION
1698};
1699
1700#endif /* IN_RING3 */
1701#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
1702
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette