ReactOS 0.4.15-dev-7931-gfd331f1
ps2.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PS2_DATA_PORT   0x60
 
#define PS2_CONTROL_PORT   0x64
 
#define PS2_STAT_OUT_BUF_FULL   (1 << 0)
 
#define PS2_STAT_SYSTEM   (1 << 2)
 
#define PS2_STAT_COMMAND   (1 << 3)
 
#define PS2_STAT_KBD_ENABLE   (1 << 4)
 
#define PS2_STAT_AUX_OUT_BUF_FULL   (1 << 5)
 
#define PS2_STAT_GEN_TIMEOUT   (1 << 6)
 
#define PS2_STAT_PARITY_ERROR   (1 << 7)
 
#define PS2_CONFIG_KBD_INT   (1 << 0)
 
#define PS2_CONFIG_AUX_INT   (1 << 1)
 
#define PS2_CONFIG_SYSTEM   (1 << 2)
 
#define PS2_CONFIG_NO_KEYLOCK   (1 << 3)
 
#define PS2_CONFIG_KBD_DISABLE   (1 << 4)
 
#define PS2_CONFIG_AUX_DISABLE   (1 << 5)
 
#define PS2_OUT_CPU_NO_RESET   (1 << 0)
 
#define PS2_OUT_A20_SET   (1 << 1)
 
#define PS2_OUT_AUX_DATA   (1 << 2)
 
#define PS2_OUT_IRQ01   (1 << 4)
 
#define PS2_OUT_IRQ12   (1 << 5)
 
#define PS2_OUT_KBD_DATA   (1 << 7)
 

Typedefs

typedef VOID(WINAPIPS2_DEVICE_CMDPROC) (LPVOID Param, BYTE Command)
 

Functions

VOID PS2SetDeviceCmdProc (BYTE PS2Port, LPVOID Param, PS2_DEVICE_CMDPROC DeviceCommand)
 
BOOLEAN PS2QueuePush (BYTE PS2Port, BYTE Data)
 
BOOLEAN PS2PortQueueRead (BYTE PS2Port)
 
BOOLEAN PS2Initialize (VOID)
 
VOID PS2Cleanup (VOID)
 

Macro Definition Documentation

◆ PS2_CONFIG_AUX_DISABLE

#define PS2_CONFIG_AUX_DISABLE   (1 << 5)

Definition at line 35 of file ps2.h.

◆ PS2_CONFIG_AUX_INT

#define PS2_CONFIG_AUX_INT   (1 << 1)

Definition at line 31 of file ps2.h.

◆ PS2_CONFIG_KBD_DISABLE

#define PS2_CONFIG_KBD_DISABLE   (1 << 4)

Definition at line 34 of file ps2.h.

◆ PS2_CONFIG_KBD_INT

#define PS2_CONFIG_KBD_INT   (1 << 0)

Definition at line 30 of file ps2.h.

◆ PS2_CONFIG_NO_KEYLOCK

#define PS2_CONFIG_NO_KEYLOCK   (1 << 3)

Definition at line 33 of file ps2.h.

◆ PS2_CONFIG_SYSTEM

#define PS2_CONFIG_SYSTEM   (1 << 2)

Definition at line 32 of file ps2.h.

◆ PS2_CONTROL_PORT

#define PS2_CONTROL_PORT   0x64

Definition at line 17 of file ps2.h.

◆ PS2_DATA_PORT

#define PS2_DATA_PORT   0x60

Definition at line 16 of file ps2.h.

◆ PS2_OUT_A20_SET

#define PS2_OUT_A20_SET   (1 << 1)

Definition at line 40 of file ps2.h.

◆ PS2_OUT_AUX_DATA

#define PS2_OUT_AUX_DATA   (1 << 2)

Definition at line 41 of file ps2.h.

◆ PS2_OUT_CPU_NO_RESET

#define PS2_OUT_CPU_NO_RESET   (1 << 0)

Definition at line 39 of file ps2.h.

◆ PS2_OUT_IRQ01

#define PS2_OUT_IRQ01   (1 << 4)

Definition at line 43 of file ps2.h.

◆ PS2_OUT_IRQ12

#define PS2_OUT_IRQ12   (1 << 5)

Definition at line 44 of file ps2.h.

◆ PS2_OUT_KBD_DATA

#define PS2_OUT_KBD_DATA   (1 << 7)

Definition at line 46 of file ps2.h.

◆ PS2_STAT_AUX_OUT_BUF_FULL

#define PS2_STAT_AUX_OUT_BUF_FULL   (1 << 5)

Definition at line 25 of file ps2.h.

◆ PS2_STAT_COMMAND

#define PS2_STAT_COMMAND   (1 << 3)

Definition at line 23 of file ps2.h.

◆ PS2_STAT_GEN_TIMEOUT

#define PS2_STAT_GEN_TIMEOUT   (1 << 6)

Definition at line 26 of file ps2.h.

◆ PS2_STAT_KBD_ENABLE

#define PS2_STAT_KBD_ENABLE   (1 << 4)

Definition at line 24 of file ps2.h.

◆ PS2_STAT_OUT_BUF_FULL

#define PS2_STAT_OUT_BUF_FULL   (1 << 0)

Definition at line 20 of file ps2.h.

◆ PS2_STAT_PARITY_ERROR

#define PS2_STAT_PARITY_ERROR   (1 << 7)

Definition at line 27 of file ps2.h.

◆ PS2_STAT_SYSTEM

#define PS2_STAT_SYSTEM   (1 << 2)

Definition at line 22 of file ps2.h.

Typedef Documentation

◆ PS2_DEVICE_CMDPROC

typedef VOID(WINAPI * PS2_DEVICE_CMDPROC) (LPVOID Param, BYTE Command)

Definition at line 48 of file ps2.h.

Function Documentation

◆ PS2Cleanup()

VOID PS2Cleanup ( VOID  )

Definition at line 546 of file ps2.c.

547{
549
550 CloseHandle(Ports[1].QueueMutex);
551 CloseHandle(Ports[0].QueueMutex);
552}
#define CloseHandle
Definition: compat.h:739
static PHARDWARE_TIMER IrqTimer
Definition: ps2.c:63
static PS2_PORT Ports[PS2_PORTS]
Definition: ps2.c:52
VOID DestroyHardwareTimer(PHARDWARE_TIMER Timer)
Definition: clock.c:210

Referenced by EmulatorCleanup().

◆ PS2Initialize()

BOOLEAN PS2Initialize ( VOID  )

Definition at line 520 of file ps2.c.

521{
522 /* Initialize the PS/2 ports */
523 Ports[0].IsEnabled = FALSE;
524 Ports[0].QueueEmpty = TRUE;
525 Ports[0].QueueStart = 0;
526 Ports[0].QueueEnd = 0;
528
529 Ports[1].IsEnabled = FALSE;
530 Ports[1].QueueEmpty = TRUE;
531 Ports[1].QueueStart = 0;
532 Ports[1].QueueEnd = 0;
534
535 /* Register the I/O Ports */
538
540 HZ_TO_NS(100),
542
543 return TRUE;
544}
#define HARDWARE_TIMER_ONESHOT
Definition: clock.h:16
#define HZ_TO_NS(Freq)
Definition: clock.h:20
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static BYTE WINAPI PS2ReadControl(USHORT Port)
Definition: ps2.c:90
static VOID FASTCALL GeneratePS2Irq(ULONGLONG ElapsedTime)
Definition: ps2.c:392
static BYTE WINAPI PS2ReadData(USHORT Port)
Definition: ps2.c:109
static VOID WINAPI PS2WriteControl(USHORT Port, BYTE Data)
Definition: ps2.c:130
static VOID WINAPI PS2WriteData(USHORT Port, BYTE Data)
Definition: ps2.c:278
#define PS2_DATA_PORT
Definition: ps2.h:16
#define PS2_CONTROL_PORT
Definition: ps2.h:17
HANDLE QueueMutex
Definition: ps2.c:41
UINT QueueStart
Definition: ps2.c:39
UINT QueueEnd
Definition: ps2.c:40
BOOLEAN QueueEmpty
Definition: ps2.c:37
BOOLEAN IsEnabled
Definition: ps2.c:35
PHARDWARE_TIMER CreateHardwareTimer(ULONG Flags, ULONGLONG Delay, PHARDWARE_TIMER_PROC Callback)
Definition: clock.c:144
VOID RegisterIoPort(USHORT Port, EMULATOR_INB_PROC InHandler, EMULATOR_OUTB_PROC OutHandler)
Definition: io.c:320
#define CreateMutex
Definition: winbase.h:3756

Referenced by EmulatorInitialize().

◆ PS2PortQueueRead()

BOOLEAN PS2PortQueueRead ( BYTE  PS2Port)

Definition at line 415 of file ps2.c.

416{
419
420 // NOTE: The first PS/2 port (keyboard) has priority over the second one (mouse).
421
422 Port = &Ports[PS2Port];
423
424 if (!Port->IsEnabled) return FALSE;
425
426 /* Make sure the queue is not empty (fast check) */
427 if (Port->QueueEmpty)
428 {
429 /* Only the keyboard should have its last data latched */
430 // FIXME: Alternatively this can be done in PS2ReadData when
431 // we read PS2_DATA_PORT. What is the best solution??
432 if (PS2Port == 0)
433 {
434 OutputBuffer = Port->Queue[(Port->QueueStart - 1) % BUFFER_SIZE];
435 StatusRegister &= ~PS2_STAT_AUX_OUT_BUF_FULL; // Clear flag: keyboard data
436 }
437
438 return FALSE;
439 }
440
441 WaitForSingleObject(Port->QueueMutex, INFINITE);
442
443 /*
444 * Recheck whether the queue is not empty (it may
445 * have changed after having grabbed the mutex).
446 */
447 if (Port->QueueEmpty) goto Done;
448
449 /* Get the data */
450 OutputBuffer = Port->Queue[Port->QueueStart];
451
452 // StatusRegister &= ~(PS2_STAT_AUX_OUT_BUF_FULL | PS2_STAT_OUT_BUF_FULL);
453
454 /* Always set the "Output buffer full" flag */
456
457 /* Set the "Auxiliary output buffer full" flag according to where the data came from */
458 if (PS2Port == 0)
459 StatusRegister &= ~PS2_STAT_AUX_OUT_BUF_FULL; // Clear flag: keyboard data
460 else // if (PS2Port == 1)
461 StatusRegister |= PS2_STAT_AUX_OUT_BUF_FULL; // Set flag: mouse data
462
463 /* Remove the value from the queue */
464 Port->QueueStart++;
465 Port->QueueStart %= BUFFER_SIZE;
466
467 /* Check if the queue is now empty */
468 if (Port->QueueStart == Port->QueueEnd)
469 Port->QueueEmpty = TRUE;
470
471 Result = TRUE;
472
473Done:
474 ReleaseMutex(Port->QueueMutex);
475 return Result;
476}
unsigned char BOOLEAN
#define INFINITE
Definition: serial.h:102
CPPORT Port[4]
Definition: headless.c:35
#define BUFFER_SIZE
Definition: ps2.c:31
static BYTE StatusRegister
Definition: ps2.c:57
#define PS2_STAT_OUT_BUF_FULL
Definition: ps2.h:20
#define PS2_STAT_AUX_OUT_BUF_FULL
Definition: ps2.h:25
Definition: ps2.c:34
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:618
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by DisableMouseInt(), DosMouseIrq(), EnableMouseInt(), GeneratePS2Irq(), ReadMouseData(), and SendMouseCommand().

◆ PS2QueuePush()

BOOLEAN PS2QueuePush ( BYTE  PS2Port,
BYTE  Data 
)

Definition at line 486 of file ps2.c.

487{
490
491 ASSERT(PS2Port < PS2_PORTS);
492 Port = &Ports[PS2Port];
493
494 if (!Port->IsEnabled) return FALSE;
495
496 WaitForSingleObject(Port->QueueMutex, INFINITE);
497
498 /* Check if the queue is full */
499 if (!Port->QueueEmpty && (Port->QueueStart == Port->QueueEnd))
500 goto Done;
501
502 /* Insert the value in the queue */
503 Port->Queue[Port->QueueEnd] = Data;
504 Port->QueueEnd++;
505 Port->QueueEnd %= BUFFER_SIZE;
506
507 /* The queue is not empty anymore */
508 Port->QueueEmpty = FALSE;
509
510 /* Schedule the IRQ */
512
513 Result = TRUE;
514
515Done:
516 ReleaseMutex(Port->QueueMutex);
517 return Result;
518}
#define ASSERT(a)
Definition: mode.c:44
#define PS2_PORTS
Definition: ps2.c:51
VOID EnableHardwareTimer(PHARDWARE_TIMER Timer)
Definition: clock.c:161

Referenced by KeyboardCommand(), KeyboardEventHandler(), MouseCommand(), MouseDispatchPacket(), and PS2WriteData().

◆ PS2SetDeviceCmdProc()

VOID PS2SetDeviceCmdProc ( BYTE  PS2Port,
LPVOID  Param,
PS2_DEVICE_CMDPROC  DeviceCommand 
)

Definition at line 478 of file ps2.c.

479{
480 ASSERT(PS2Port < PS2_PORTS);
481 Ports[PS2Port].Param = Param;
482 Ports[PS2Port].DeviceCommand = DeviceCommand;
483}
LPVOID Param
Definition: ps2.c:43
PS2_DEVICE_CMDPROC DeviceCommand
Definition: ps2.c:44

Referenced by KeyboardInit(), and MouseInit().