ReactOS 0.4.15-dev-7660-g0086d05
readwrite.c File Reference
#include "i8042prt.h"
#include <debug.h>
Include dependency graph for readwrite.c:

Go to the source code of this file.

Functions

VOID i8042Flush (IN PPORT_DEVICE_EXTENSION DeviceExtension)
 
BOOLEAN i8042IsrWritePort (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Value, IN UCHAR SelectCmd OPTIONAL)
 
NTSTATUS i8042ReadData (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR StatusFlags, OUT PUCHAR Data)
 
NTSTATUS i8042ReadStatus (IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Status)
 
NTSTATUS i8042ReadDataWait (IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Data)
 
NTSTATUS NTAPI i8042SynchReadPort (IN PVOID Context, OUT PUCHAR Value, IN BOOLEAN WaitForAck)
 
NTSTATUS NTAPI i8042SynchWritePort (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Port, IN UCHAR Value, IN BOOLEAN WaitForAck)
 
BOOLEAN i8042Write (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PUCHAR addr, IN UCHAR data)
 

Function Documentation

◆ i8042Flush()

VOID i8042Flush ( IN PPORT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 21 of file readwrite.c.

23{
24 UCHAR Ignore;
25
26 /* Flush output buffer */
27 while (NT_SUCCESS(i8042ReadData(DeviceExtension, KBD_OBF /* | MOU_OBF*/, &Ignore))) {
29 TRACE_(I8042PRT, "Output data flushed\n");
30 }
31
32 /* Flush input buffer */
33 while (NT_SUCCESS(i8042ReadData(DeviceExtension, KBD_IBF, &Ignore))) {
35 TRACE_(I8042PRT, "Input data flushed\n");
36 }
37}
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:81
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define TRACE_(x)
Definition: compat.h:76
NTSTATUS i8042ReadData(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR StatusFlags, OUT PUCHAR Data)
Definition: readwrite.c:56
#define KBD_IBF
Definition: i8042prt.h:251
#define KBD_OBF
Definition: i8042prt.h:250
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by EnableInterrupts(), i8042BasicDetect(), and i8042DetectMouse().

◆ i8042IsrWritePort()

BOOLEAN i8042IsrWritePort ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN UCHAR  Value,
IN UCHAR SelectCmd  OPTIONAL 
)

Definition at line 40 of file readwrite.c.

44{
45 if (SelectCmd)
46 if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, SelectCmd))
47 return FALSE;
48
49 return i8042Write(DeviceExtension, DeviceExtension->DataPort, Value);
50}
#define FALSE
Definition: types.h:117
BOOLEAN i8042Write(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PUCHAR addr, IN UCHAR data)
Definition: readwrite.c:199
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by i8042DetectMouse(), i8042MouInitialize(), i8042MouIsrWritePort(), and StartProcedure().

◆ i8042ReadData()

NTSTATUS i8042ReadData ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN UCHAR  StatusFlags,
OUT PUCHAR  Data 
)

Definition at line 56 of file readwrite.c.

60{
63
64 Status = i8042ReadStatus(DeviceExtension, &PortStatus);
65 if (!NT_SUCCESS(Status))
66 return Status;
67
68 // If data is available
69 if (PortStatus & StatusFlags)
70 {
71 *Data = READ_PORT_UCHAR(DeviceExtension->DataPort);
72 INFO_(I8042PRT, "Read: 0x%02x (status: 0x%x)\n", Data[0], PortStatus);
73
74 // If the data is valid (not timeout, not parity error)
75 if ((PortStatus & KBD_PERR) == 0)
76 return STATUS_SUCCESS;
77 }
79}
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS i8042ReadStatus(IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Status)
Definition: readwrite.c:82
Status
Definition: gdiplustypes.h:25
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
Definition: hubbusif.h:42
#define KBD_PERR
Definition: i8042prt.h:253
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
#define INFO_(ch,...)
Definition: debug.h:159
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by i8042Flush().

◆ i8042ReadDataWait()

NTSTATUS i8042ReadDataWait ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
OUT PUCHAR  Data 
)

Definition at line 95 of file readwrite.c.

98{
101
102 Counter = DeviceExtension->Settings.PollingIterations;
103
104 while (Counter--)
105 {
106 Status = i8042ReadKeyboardData(DeviceExtension, Data);
107
108 if (NT_SUCCESS(Status))
109 return Status;
110
112 }
113
114 /* Timed out */
115 return STATUS_IO_TIMEOUT;
116}
#define i8042ReadKeyboardData(DeviceExtension, Data)
Definition: i8042prt.h:403
static LARGE_INTEGER Counter
Definition: clock.c:43
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_IO_TIMEOUT
Definition: udferr_usr.h:163

Referenced by i8042BasicDetect(), i8042ChangeMode(), i8042DetectMouse(), i8042MouInitialize(), i8042SynchReadPort(), and i8042SynchWritePort().

◆ i8042ReadStatus()

NTSTATUS i8042ReadStatus ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
OUT PUCHAR  Status 
)

Definition at line 82 of file readwrite.c.

85{
86 ASSERT(DeviceExtension->ControlPort != NULL);
87 *Status = READ_PORT_UCHAR(DeviceExtension->ControlPort);
88 return STATUS_SUCCESS;
89}
#define NULL
Definition: types.h:112
#define ASSERT(a)
Definition: mode.c:44

Referenced by i8042KbdInterruptService(), i8042MouInterruptService(), and i8042ReadData().

◆ i8042SynchReadPort()

NTSTATUS NTAPI i8042SynchReadPort ( IN PVOID  Context,
OUT PUCHAR  Value,
IN BOOLEAN  WaitForAck 
)

Definition at line 125 of file readwrite.c.

129{
130 PPORT_DEVICE_EXTENSION DeviceExtension;
131
132 UNREFERENCED_PARAMETER(WaitForAck);
133
134 DeviceExtension = (PPORT_DEVICE_EXTENSION)Context;
135
136 return i8042ReadDataWait(DeviceExtension, Value);
137}
NTSTATUS i8042ReadDataWait(IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Data)
Definition: readwrite.c:95
struct _PORT_DEVICE_EXTENSION * PPORT_DEVICE_EXTENSION
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317

Referenced by i8042SendHookWorkItem().

◆ i8042SynchWritePort()

NTSTATUS NTAPI i8042SynchWritePort ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN UCHAR  Port,
IN UCHAR  Value,
IN BOOLEAN  WaitForAck 
)

Definition at line 144 of file readwrite.c.

149{
151 UCHAR Ack;
152 ULONG ResendIterations;
153
154 ResendIterations = DeviceExtension->Settings.ResendIterations + 1;
155
156 do
157 {
158 if (Port)
159 if (!i8042Write(DeviceExtension, DeviceExtension->DataPort, Port))
160 {
161 WARN_(I8042PRT, "Failed to write Port\n");
162 return STATUS_IO_TIMEOUT;
163 }
164
165 if (!i8042Write(DeviceExtension, DeviceExtension->DataPort, Value))
166 {
167 WARN_(I8042PRT, "Failed to write Value\n");
168 return STATUS_IO_TIMEOUT;
169 }
170
171 if (WaitForAck)
172 {
173 Status = i8042ReadDataWait(DeviceExtension, &Ack);
174 if (!NT_SUCCESS(Status))
175 {
176 WARN_(I8042PRT, "Failed to read Ack\n");
177 return Status;
178 }
179 if (Ack == KBD_ACK)
180 return STATUS_SUCCESS;
181 else if (Ack == KBD_RESEND)
182 INFO_(I8042PRT, "i8042 asks for a data resend\n");
183 }
184 else
185 {
186 return STATUS_SUCCESS;
187 }
188 TRACE_(I8042PRT, "Reiterating\n");
189 ResendIterations--;
190 } while (ResendIterations);
191
192 return STATUS_IO_TIMEOUT;
193}
CPPORT Port[4]
Definition: headless.c:35
#define KBD_RESEND
Definition: i8042prt.h:244
#define KBD_ACK
Definition: i8042prt.h:242
#define WARN_(ch,...)
Definition: debug.h:157

Referenced by i8042DetectKeyboard(), and i8042SynchWritePortKbd().

◆ i8042Write()

BOOLEAN i8042Write ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN PUCHAR  addr,
IN UCHAR  data 
)

Definition at line 199 of file readwrite.c.

203{
205
206 ASSERT(addr);
207 ASSERT(DeviceExtension->ControlPort != NULL);
208
209 Counter = DeviceExtension->Settings.PollingIterations;
210
211 while ((KBD_IBF & READ_PORT_UCHAR(DeviceExtension->ControlPort)) &&
212 (Counter--))
213 {
215 }
216
217 if (Counter)
218 {
220 INFO_(I8042PRT, "Sent 0x%x to port %p\n", data, addr);
221 return TRUE;
222 }
223 return FALSE;
224}
#define TRUE
Definition: types.h:120
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum const GLvoid * addr
Definition: glext.h:9621
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21

Referenced by i8042BasicDetect(), i8042ChangeMode(), i8042ConnectKeyboardInterrupt(), i8042DetectMouse(), i8042IsrWritePort(), i8042MouInitialize(), i8042PacketWrite(), and i8042SynchWritePort().