ReactOS  0.4.14-dev-297-g23e575c
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 }
#define KBD_OBF
Definition: i8042prt.h:250
#define KBD_IBF
Definition: i8042prt.h:251
#define TRACE_(x)
Definition: compat.h:66
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned char UCHAR
Definition: xmlstorage.h:181
NTSTATUS i8042ReadData(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR StatusFlags, OUT PUCHAR Data)
Definition: readwrite.c:56
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:99

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 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
BOOLEAN i8042Write(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PUCHAR addr, IN UCHAR data)
Definition: readwrite.c:199

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  }
78  return STATUS_UNSUCCESSFUL;
79 }
#define INFO_(ch,...)
Definition: debug.h:159
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:528
LONG NTSTATUS
Definition: precomp.h:26
#define KBD_PERR
Definition: i8042prt.h:253
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
unsigned char UCHAR
Definition: xmlstorage.h:181
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
Definition: hubbusif.h:40
Status
Definition: gdiplustypes.h:24
NTSTATUS i8042ReadStatus(IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Status)
Definition: readwrite.c:82
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by i8042Flush().

◆ i8042ReadDataWait()

NTSTATUS i8042ReadDataWait ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
OUT PUCHAR  Data 
)

Definition at line 95 of file readwrite.c.

98 {
99  ULONG Counter;
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 }
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define i8042ReadKeyboardData(DeviceExtension, Data)
Definition: i8042prt.h:405
Status
Definition: gdiplustypes.h:24
#define STATUS_IO_TIMEOUT
Definition: udferr_usr.h:163
static LARGE_INTEGER Counter
Definition: clock.c:43
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:99

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 }
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:528
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2966

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 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
struct _PORT_DEVICE_EXTENSION * PPORT_DEVICE_EXTENSION
NTSTATUS i8042ReadDataWait(IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Data)
Definition: readwrite.c:95

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 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
CPPORT Port[4]
Definition: headless.c:34
#define INFO_(ch,...)
Definition: debug.h:159
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN i8042Write(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PUCHAR addr, IN UCHAR data)
Definition: readwrite.c:199
#define TRACE_(x)
Definition: compat.h:66
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define KBD_ACK
Definition: i8042prt.h:242
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
NTSTATUS i8042ReadDataWait(IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Data)
Definition: readwrite.c:95
#define KBD_RESEND
Definition: i8042prt.h:244
#define STATUS_IO_TIMEOUT
Definition: udferr_usr.h:163
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966
#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 {
204  ULONG Counter;
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
#define INFO_(ch,...)
Definition: debug.h:159
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:528
#define KBD_IBF
Definition: i8042prt.h:251
smooth NULL
Definition: ftsmooth.c:416
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
GLenum const GLvoid * addr
Definition: glext.h:9621
static LARGE_INTEGER Counter
Definition: clock.c:43
unsigned int ULONG
Definition: retypes.h:1
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:532
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:99

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