VirtualBox

source: vbox/trunk/src/VBox/Devices/Input/DevPS2.h@ 82180

最後變更 在這個檔案從82180是 82173,由 vboxsync 提交於 5 年 前

DevPS2: Less opaque and structure duplicatication. (The opaque stuff would become very tedious later when splitting up the state structures.) bugref:9218

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 12.7 KB
 
1/* $Id: DevPS2.h 82173 2019-11-25 13:00:55Z vboxsync $ */
2/** @file
3 * PS/2 devices - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2007-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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#ifndef VBOX_INCLUDED_SRC_Input_DevPS2_h
19#define VBOX_INCLUDED_SRC_Input_DevPS2_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/** @defgroup grp_devps2 PS/2 Device
25 * @{
26 */
27
28/** Pointer to the shared keyboard (PS/2) controller / device state. */
29typedef struct KBDSTATE *PKBDSTATE;
30
31/** Define a simple PS/2 input device queue. */
32#define DEF_PS2Q_TYPE(name, size) \
33 typedef struct { \
34 uint32_t rpos; \
35 uint32_t wpos; \
36 uint32_t cUsed; \
37 uint32_t cSize; \
38 uint8_t abQueue[size]; \
39 } name
40
41DEF_PS2Q_TYPE(GeneriQ, 1);
42
43
44/** @defgroup grp_devps2k DevPS2K - Keyboard
45 * @{
46 */
47
48/** @name HID modifier range.
49 * @{ */
50#define HID_MODIFIER_FIRST 0xE0
51#define HID_MODIFIER_LAST 0xE8
52/** @} */
53
54/** @name USB HID additional constants
55 * @{ */
56/** The highest USB usage code reported by VirtualBox. */
57#define VBOX_USB_MAX_USAGE_CODE 0xE7
58/** The size of an array needed to store all USB usage codes */
59#define VBOX_USB_USAGE_ARRAY_SIZE (VBOX_USB_MAX_USAGE_CODE + 1)
60/** USB HID Keyboard Usage Page. */
61#define USB_HID_KB_PAGE 7
62/** USB HID Consumer Control Usage Page. */
63#define USB_HID_CC_PAGE 12
64/** @} */
65
66/* Internal keyboard queue sizes. The input queue doesn't need to be
67 * extra huge and the command queue only needs to handle a few bytes.
68 */
69#define KBD_KEY_QUEUE_SIZE 64
70#define KBD_CMD_QUEUE_SIZE 4
71
72DEF_PS2Q_TYPE(KbdKeyQ, KBD_KEY_QUEUE_SIZE);
73DEF_PS2Q_TYPE(KbdCmdQ, KBD_CMD_QUEUE_SIZE);
74
75/** Typematic state. */
76typedef enum {
77 KBD_TMS_IDLE = 0, /* No typematic key active. */
78 KBD_TMS_DELAY = 1, /* In the initial delay period. */
79 KBD_TMS_REPEAT = 2, /* Key repeating at set rate. */
80 KBD_TMS_32BIT_HACK = 0x7fffffff
81} tmatic_state_t;
82
83
84/**
85 * The shared PS/2 keyboard instance data.
86 */
87typedef struct PS2K
88{
89 /** Pointer to parent device (keyboard controller). */
90 R3PTRTYPE(PKBDSTATE) pParent;
91 /** Set if keyboard is enabled ('scans' for input). */
92 bool fScanning;
93 /** Set NumLock is on. */
94 bool fNumLockOn;
95 /** Selected scan set. */
96 uint8_t u8ScanSet;
97 /** Modifier key state. */
98 uint8_t u8Modifiers;
99 /** Currently processed command (if any). */
100 uint8_t u8CurrCmd;
101 /** Status indicator (LED) state. */
102 uint8_t u8LEDs;
103 /** Selected typematic delay/rate. */
104 uint8_t u8TypematicCfg;
105 /** Usage code of current typematic key, if any. */
106 uint32_t u32TypematicKey;
107 /** Current typematic repeat state. */
108 tmatic_state_t enmTypematicState;
109 /** Buffer holding scan codes to be sent to the host. */
110 KbdKeyQ keyQ;
111 /** Command response queue (priority). */
112 KbdCmdQ cmdQ;
113 /** Currently depressed keys. */
114 uint8_t abDepressedKeys[VBOX_USB_USAGE_ARRAY_SIZE];
115 /** Typematic delay in milliseconds. */
116 unsigned uTypematicDelay;
117 /** Typematic repeat period in milliseconds. */
118 unsigned uTypematicRepeat;
119 /** Set if the throttle delay is currently active. */
120 bool fThrottleActive;
121 /** Set if the input rate should be throttled. */
122 bool fThrottleEnabled;
123
124 uint8_t Alignment0[2];
125
126 /** Command delay timer - RC Ptr. */
127 PTMTIMERRC pKbdDelayTimerRC;
128 /** Typematic timer - RC Ptr. */
129 PTMTIMERRC pKbdTypematicTimerRC;
130 /** Input throttle timer - RC Ptr. */
131 PTMTIMERRC pThrottleTimerRC;
132
133 /** The device critical section protecting everything - R3 Ptr */
134 R3PTRTYPE(PPDMCRITSECT) pCritSectR3;
135
136 /** Command delay timer - R3 Ptr. */
137 PTMTIMERR3 pKbdDelayTimerR3;
138 /** Typematic timer - R3 Ptr. */
139 PTMTIMERR3 pKbdTypematicTimerR3;
140 /** Input throttle timer - R3 Ptr. */
141 PTMTIMERR3 pThrottleTimerR3;
142
143 /** Command delay timer - R0 Ptr. */
144 PTMTIMERR0 pKbdDelayTimerR0;
145 /** Typematic timer - R0 Ptr. */
146 PTMTIMERR0 pKbdTypematicTimerR0;
147 /** Input throttle timer - R0 Ptr. */
148 PTMTIMERR0 pThrottleTimerR0;
149
150 /**
151 * Keyboard port - LUN#0.
152 *
153 * @implements PDMIBASE
154 * @implements PDMIKEYBOARDPORT
155 */
156 struct
157 {
158 /** The base interface for the keyboard port. */
159 PDMIBASE IBase;
160 /** The keyboard port base interface. */
161 PDMIKEYBOARDPORT IPort;
162
163 /** The base interface of the attached keyboard driver. */
164 R3PTRTYPE(PPDMIBASE) pDrvBase;
165 /** The keyboard interface of the attached keyboard driver. */
166 R3PTRTYPE(PPDMIKEYBOARDCONNECTOR) pDrv;
167 } Keyboard;
168} PS2K;
169/** Pointer to the PS/2 keyboard instance data. */
170typedef PS2K *PPS2K;
171
172
173int PS2KByteToKbd(PPS2K pThis, uint8_t cmd);
174int PS2KByteFromKbd(PPS2K pThis, uint8_t *pVal);
175
176int PS2KConstruct(PPS2K pThis, PPDMDEVINS pDevIns, PKBDSTATE pParent, unsigned iInstance, PCFGMNODE pCfg);
177int PS2KAttach(PPS2K pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags);
178void PS2KReset(PPS2K pThis);
179void PS2KRelocate(PPS2K pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns);
180void PS2KSaveState(PPS2K pThis, PSSMHANDLE pSSM);
181int PS2KLoadState(PPS2K pThis, PSSMHANDLE pSSM, uint32_t uVersion);
182int PS2KLoadDone(PPS2K pThis, PSSMHANDLE pSSM);
183
184PS2K *KBDGetPS2KFromDevIns(PPDMDEVINS pDevIns);
185
186/** @} */
187
188
189/** @defgroup grp_devps2m DevPS2M - Auxiliary Device (Mouse)
190 * @{
191 */
192
193/* Internal mouse queue sizes. The input queue is relatively large,
194 * but the command queue only needs to handle a few bytes.
195 */
196#define AUX_EVT_QUEUE_SIZE 256
197#define AUX_CMD_QUEUE_SIZE 8
198
199DEF_PS2Q_TYPE(AuxEvtQ, AUX_EVT_QUEUE_SIZE);
200DEF_PS2Q_TYPE(AuxCmdQ, AUX_CMD_QUEUE_SIZE);
201
202/** Auxiliary device special modes of operation. */
203typedef enum {
204 AUX_MODE_STD, /* Standard operation. */
205 AUX_MODE_RESET, /* Currently in reset. */
206 AUX_MODE_WRAP /* Wrap mode (echoing input). */
207} PS2M_MODE;
208
209/** Auxiliary device operational state. */
210typedef enum {
211 AUX_STATE_RATE_ERR = RT_BIT(0), /* Invalid rate received. */
212 AUX_STATE_RES_ERR = RT_BIT(1), /* Invalid resolution received. */
213 AUX_STATE_SCALING = RT_BIT(4), /* 2:1 scaling in effect. */
214 AUX_STATE_ENABLED = RT_BIT(5), /* Reporting enabled in stream mode. */
215 AUX_STATE_REMOTE = RT_BIT(6) /* Remote mode (reports on request). */
216} PS2M_STATE;
217
218/** Externally visible state bits. */
219#define AUX_STATE_EXTERNAL (AUX_STATE_SCALING | AUX_STATE_ENABLED | AUX_STATE_REMOTE)
220
221/** Protocols supported by the PS/2 mouse. */
222typedef enum {
223 PS2M_PROTO_PS2STD = 0, /* Standard PS/2 mouse protocol. */
224 PS2M_PROTO_IMPS2 = 3, /* IntelliMouse PS/2 protocol. */
225 PS2M_PROTO_IMEX = 4, /* IntelliMouse Explorer protocol. */
226 PS2M_PROTO_IMEX_HORZ = 5 /* IntelliMouse Explorer with horizontal reports. */
227} PS2M_PROTO;
228
229/** Protocol selection 'knock' states. */
230typedef enum {
231 PS2M_KNOCK_INITIAL,
232 PS2M_KNOCK_1ST,
233 PS2M_KNOCK_IMPS2_2ND,
234 PS2M_KNOCK_IMEX_2ND,
235 PS2M_KNOCK_IMEX_HORZ_2ND
236} PS2M_KNOCK_STATE;
237
238/**
239 * The PS/2 auxiliary device instance data.
240 */
241typedef struct PS2M
242{
243 /** Pointer to parent device (keyboard controller). */
244 R3PTRTYPE(PKBDSTATE) pParent;
245 /** Operational state. */
246 uint8_t u8State;
247 /** Configured sampling rate. */
248 uint8_t u8SampleRate;
249 /** Configured resolution. */
250 uint8_t u8Resolution;
251 /** Currently processed command (if any). */
252 uint8_t u8CurrCmd;
253 /** Set if the throttle delay is active. */
254 bool fThrottleActive;
255 /** Set if the throttle delay is active. */
256 bool fDelayReset;
257 /** Operational mode. */
258 PS2M_MODE enmMode;
259 /** Currently used protocol. */
260 PS2M_PROTO enmProtocol;
261 /** Currently used protocol. */
262 PS2M_KNOCK_STATE enmKnockState;
263 /** Buffer holding mouse events to be sent to the host. */
264 AuxEvtQ evtQ;
265 /** Command response queue (priority). */
266 AuxCmdQ cmdQ;
267 /** Accumulated horizontal movement. */
268 int32_t iAccumX;
269 /** Accumulated vertical movement. */
270 int32_t iAccumY;
271 /** Accumulated Z axis (vertical scroll) movement. */
272 int32_t iAccumZ;
273 /** Accumulated W axis (horizontal scroll) movement. */
274 int32_t iAccumW;
275 /** Accumulated button presses. */
276 uint32_t fAccumB;
277 /** Instantaneous button data. */
278 uint32_t fCurrB;
279 /** Button state last sent to the guest. */
280 uint32_t fReportedB;
281 /** Throttling delay in milliseconds. */
282 uint32_t uThrottleDelay;
283
284 /** The device critical section protecting everything - R3 Ptr */
285 R3PTRTYPE(PPDMCRITSECT) pCritSectR3;
286 /** Command delay timer - R3 Ptr. */
287 PTMTIMERR3 pDelayTimerR3;
288 /** Interrupt throttling timer - R3 Ptr. */
289 PTMTIMERR3 pThrottleTimerR3;
290 RTR3PTR Alignment1;
291
292 /** Command delay timer - RC Ptr. */
293 PTMTIMERRC pDelayTimerRC;
294 /** Interrupt throttling timer - RC Ptr. */
295 PTMTIMERRC pThrottleTimerRC;
296
297 /** Command delay timer - R0 Ptr. */
298 PTMTIMERR0 pDelayTimerR0;
299 /** Interrupt throttling timer - R0 Ptr. */
300 PTMTIMERR0 pThrottleTimerR0;
301
302 /**
303 * Mouse port - LUN#1.
304 *
305 * @implements PDMIBASE
306 * @implements PDMIMOUSEPORT
307 */
308 struct
309 {
310 /** The base interface for the mouse port. */
311 PDMIBASE IBase;
312 /** The keyboard port base interface. */
313 PDMIMOUSEPORT IPort;
314
315 /** The base interface of the attached mouse driver. */
316 R3PTRTYPE(PPDMIBASE) pDrvBase;
317 /** The keyboard interface of the attached mouse driver. */
318 R3PTRTYPE(PPDMIMOUSECONNECTOR) pDrv;
319 } Mouse;
320} PS2M;
321/** Pointer to the PS/2 auxiliary device instance data. */
322typedef PS2M *PPS2M;
323
324int PS2MByteToAux(PPS2M pThis, uint8_t cmd);
325int PS2MByteFromAux(PPS2M pThis, uint8_t *pVal);
326
327int PS2MConstruct(PPS2M pThis, PPDMDEVINS pDevIns, PKBDSTATE pParent, unsigned iInstance);
328int PS2MAttach(PPS2M pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags);
329void PS2MReset(PPS2M pThis);
330void PS2MRelocate(PPS2M pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns);
331void PS2MSaveState(PPS2M pThis, PSSMHANDLE pSSM);
332int PS2MLoadState(PPS2M pThis, PSSMHANDLE pSSM, uint32_t uVersion);
333void PS2MFixupState(PPS2M pThis, uint8_t u8State, uint8_t u8Rate, uint8_t u8Proto);
334
335PS2M *KBDGetPS2MFromDevIns(PPDMDEVINS pDevIns);
336
337/** @} */
338
339
340/**
341 * The shared keyboard controller/device state.
342 *
343 * @note We use the default critical section for serialize data access.
344 */
345typedef struct KBDSTATE
346{
347 uint8_t write_cmd; /* if non zero, write data to port 60 is expected */
348 uint8_t status;
349 uint8_t mode;
350 uint8_t dbbout; /* data buffer byte */
351 /* keyboard state */
352 int32_t translate;
353 int32_t xlat_state;
354
355 /** Pointer to the device instance - RC. */
356 PPDMDEVINSRC pDevInsRC;
357 /** Pointer to the device instance - R3 . */
358 PPDMDEVINSR3 pDevInsR3;
359 /** Pointer to the device instance. */
360 PPDMDEVINSR0 pDevInsR0;
361
362 /** Keyboard state (implemented in separate PS2K module). */
363 PS2K Kbd;
364
365 /** Mouse state (implemented in separate PS2M module). */
366 PS2M Aux;
367} KBDSTATE, KBDState;
368
369
370/* Shared keyboard/aux internal interface. */
371void KBCUpdateInterrupts(void *pKbc);
372
373
374///@todo: This should live with the KBC implementation.
375/** AT to PC scancode translator state. */
376typedef enum
377{
378 XS_IDLE, /**< Starting state. */
379 XS_BREAK, /**< F0 break byte was received. */
380 XS_HIBIT /**< Break code still active. */
381} xlat_state_t;
382
383int32_t XlateAT2PC(int32_t state, uint8_t scanIn, uint8_t *pScanOut);
384
385/** @} */
386
387#endif /* !VBOX_INCLUDED_SRC_Input_DevPS2_h */
388
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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