1 /** @file
2   PS/2 Mouse driver header file.
3 
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #ifndef _PS2MOUSE_H_
10 #define _PS2MOUSE_H_
11 
12 #include <Uefi.h>
13 
14 #include <Protocol/SimplePointer.h>
15 #include <Protocol/SuperIo.h>
16 #include <Protocol/DevicePath.h>
17 
18 #include <Library/DevicePathLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/UefiDriverEntryPoint.h>
21 #include <Library/UefiLib.h>
22 #include <Library/BaseMemoryLib.h>
23 #include <Library/MemoryAllocationLib.h>
24 #include <Library/UefiBootServicesTableLib.h>
25 #include <Library/ReportStatusCodeLib.h>
26 #include <Library/PcdLib.h>
27 #include <Library/IoLib.h>
28 
29 //
30 // Global Variables
31 //
32 extern EFI_DRIVER_BINDING_PROTOCOL   gPS2MouseDriver;
33 extern EFI_COMPONENT_NAME_PROTOCOL   gPs2MouseComponentName;
34 extern EFI_COMPONENT_NAME2_PROTOCOL  gPs2MouseComponentName2;
35 
36 //
37 // PS/2 mouse sample rate
38 //
39 typedef enum {
40   SampleRate10,
41   SampleRate20,
42   SampleRate40,
43   SampleRate60,
44   SampleRate80,
45   SampleRate100,
46   SampleRate200,
47   MaxSampleRate
48 } MOUSE_SR;
49 
50 //
51 // PS/2 mouse resolution
52 //
53 typedef enum {
54   MouseResolution1,
55   MouseResolution2,
56   MouseResolution4,
57   MouseResolution8,
58   MaxResolution
59 } MOUSE_RE;
60 
61 //
62 // PS/2 mouse scaling
63 //
64 typedef enum {
65   Scaling1,
66   Scaling2
67 } MOUSE_SF;
68 
69 //
70 // Driver Private Data
71 //
72 #define PS2_MOUSE_DEV_SIGNATURE SIGNATURE_32 ('p', 's', '2', 'm')
73 
74 typedef struct {
75   UINTN                               Signature;
76 
77   EFI_HANDLE                          Handle;
78   EFI_SIMPLE_POINTER_PROTOCOL         SimplePointerProtocol;
79   EFI_SIMPLE_POINTER_STATE            State;
80   EFI_SIMPLE_POINTER_MODE             Mode;
81   BOOLEAN                             StateChanged;
82 
83   //
84   // PS2 Mouse device specific information
85   //
86   MOUSE_SR                            SampleRate;
87   MOUSE_RE                            Resolution;
88   MOUSE_SF                            Scaling;
89   UINT8                               DataPackageSize;
90 
91   EFI_EVENT                           TimerEvent;
92 
93   EFI_UNICODE_STRING_TABLE            *ControllerNameTable;
94   EFI_DEVICE_PATH_PROTOCOL            *DevicePath;
95 } PS2_MOUSE_DEV;
96 
97 #define PS2_MOUSE_DEV_FROM_THIS(a)  CR (a, PS2_MOUSE_DEV, SimplePointerProtocol, PS2_MOUSE_DEV_SIGNATURE)
98 
99 //
100 // Function prototypes
101 //
102 /**
103   Test to see if this driver supports ControllerHandle. Any ControllerHandle
104   than contains a IsaIo protocol can be supported.
105 
106   @param  This                Protocol instance pointer.
107   @param  ControllerHandle    Handle of device to test
108   @param  RemainingDevicePath Optional parameter use to pick a specific child
109                               device to start.
110 
111   @retval EFI_SUCCESS         This driver supports this device
112   @retval EFI_ALREADY_STARTED This driver is already running on this device
113   @retval other               This driver does not support this device
114 
115 **/
116 EFI_STATUS
117 EFIAPI
118 PS2MouseDriverSupported (
119   IN EFI_DRIVER_BINDING_PROTOCOL    *This,
120   IN EFI_HANDLE                     Controller,
121   IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath
122   );
123 
124 /**
125   Start this driver on ControllerHandle by opening a IsaIo
126   protocol, creating PS2_MOUSE_ABSOLUTE_POINTER_DEV device and install gEfiAbsolutePointerProtocolGuid
127   finally.
128 
129   @param  This                 Protocol instance pointer.
130   @param  ControllerHandle     Handle of device to bind driver to
131   @param  RemainingDevicePath  Optional parameter use to pick a specific child
132                                device to start.
133 
134   @retval EFI_SUCCESS          This driver is added to ControllerHandle
135   @retval EFI_ALREADY_STARTED  This driver is already running on ControllerHandle
136   @retval other                This driver does not support this device
137 
138 **/
139 EFI_STATUS
140 EFIAPI
141 PS2MouseDriverStart (
142   IN EFI_DRIVER_BINDING_PROTOCOL    *This,
143   IN EFI_HANDLE                     Controller,
144   IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath
145   );
146 
147 /**
148   Stop this driver on ControllerHandle. Support stopping any child handles
149   created by this driver.
150 
151   @param  This              Protocol instance pointer.
152   @param  ControllerHandle  Handle of device to stop driver on
153   @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of
154                             children is zero stop the entire bus driver.
155   @param  ChildHandleBuffer List of Child Handles to Stop.
156 
157   @retval EFI_SUCCESS       This driver is removed ControllerHandle
158   @retval other             This driver was not removed from this device
159 
160 **/
161 EFI_STATUS
162 EFIAPI
163 PS2MouseDriverStop (
164   IN EFI_DRIVER_BINDING_PROTOCOL   *This,
165   IN EFI_HANDLE                    Controller,
166   IN UINTN                         NumberOfChildren,
167   IN EFI_HANDLE                    *ChildHandleBuffer
168   );
169 
170 //
171 // EFI Component Name Functions
172 //
173 /**
174   Retrieves a Unicode string that is the user readable name of the driver.
175 
176   This function retrieves the user readable name of a driver in the form of a
177   Unicode string. If the driver specified by This has a user readable name in
178   the language specified by Language, then a pointer to the driver name is
179   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
180   by This does not support the language specified by Language,
181   then EFI_UNSUPPORTED is returned.
182 
183   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
184                                 EFI_COMPONENT_NAME_PROTOCOL instance.
185 
186   @param  Language[in]          A pointer to a Null-terminated ASCII string
187                                 array indicating the language. This is the
188                                 language of the driver name that the caller is
189                                 requesting, and it must match one of the
190                                 languages specified in SupportedLanguages. The
191                                 number of languages supported by a driver is up
192                                 to the driver writer. Language is specified
193                                 in RFC 4646 or ISO 639-2 language code format.
194 
195   @param  DriverName[out]       A pointer to the Unicode string to return.
196                                 This Unicode string is the name of the
197                                 driver specified by This in the language
198                                 specified by Language.
199 
200   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
201                                 This and the language specified by Language was
202                                 returned in DriverName.
203 
204   @retval EFI_INVALID_PARAMETER Language is NULL.
205 
206   @retval EFI_INVALID_PARAMETER DriverName is NULL.
207 
208   @retval EFI_UNSUPPORTED       The driver specified by This does not support
209                                 the language specified by Language.
210 
211 **/
212 EFI_STATUS
213 EFIAPI
214 Ps2MouseComponentNameGetDriverName (
215   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
216   IN  CHAR8                        *Language,
217   OUT CHAR16                       **DriverName
218   );
219 
220 
221 /**
222   Retrieves a Unicode string that is the user readable name of the controller
223   that is being managed by a driver.
224 
225   This function retrieves the user readable name of the controller specified by
226   ControllerHandle and ChildHandle in the form of a Unicode string. If the
227   driver specified by This has a user readable name in the language specified by
228   Language, then a pointer to the controller name is returned in ControllerName,
229   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
230   managing the controller specified by ControllerHandle and ChildHandle,
231   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
232   support the language specified by Language, then EFI_UNSUPPORTED is returned.
233 
234   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
235                                 EFI_COMPONENT_NAME_PROTOCOL instance.
236 
237   @param  ControllerHandle[in]  The handle of a controller that the driver
238                                 specified by This is managing.  This handle
239                                 specifies the controller whose name is to be
240                                 returned.
241 
242   @param  ChildHandle[in]       The handle of the child controller to retrieve
243                                 the name of.  This is an optional parameter that
244                                 may be NULL.  It will be NULL for device
245                                 drivers.  It will also be NULL for a bus drivers
246                                 that wish to retrieve the name of the bus
247                                 controller.  It will not be NULL for a bus
248                                 driver that wishes to retrieve the name of a
249                                 child controller.
250 
251   @param  Language[in]          A pointer to a Null-terminated ASCII string
252                                 array indicating the language.  This is the
253                                 language of the driver name that the caller is
254                                 requesting, and it must match one of the
255                                 languages specified in SupportedLanguages. The
256                                 number of languages supported by a driver is up
257                                 to the driver writer. Language is specified in
258                                 RFC 4646 or ISO 639-2 language code format.
259 
260   @param  ControllerName[out]   A pointer to the Unicode string to return.
261                                 This Unicode string is the name of the
262                                 controller specified by ControllerHandle and
263                                 ChildHandle in the language specified by
264                                 Language from the point of view of the driver
265                                 specified by This.
266 
267   @retval EFI_SUCCESS           The Unicode string for the user readable name in
268                                 the language specified by Language for the
269                                 driver specified by This was returned in
270                                 DriverName.
271 
272   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
273 
274   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
275                                 EFI_HANDLE.
276 
277   @retval EFI_INVALID_PARAMETER Language is NULL.
278 
279   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
280 
281   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
282                                 managing the controller specified by
283                                 ControllerHandle and ChildHandle.
284 
285   @retval EFI_UNSUPPORTED       The driver specified by This does not support
286                                 the language specified by Language.
287 
288 **/
289 EFI_STATUS
290 EFIAPI
291 Ps2MouseComponentNameGetControllerName (
292   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
293   IN  EFI_HANDLE                                      ControllerHandle,
294   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
295   IN  CHAR8                                           *Language,
296   OUT CHAR16                                          **ControllerName
297   );
298 
299 /**
300   Reset the Mouse and do BAT test for it, if ExtendedVerification is TRUE and
301   there is a mouse device connected to system.
302 
303   @param This                 - Pointer of simple pointer Protocol.
304   @param ExtendedVerification - Whether configure mouse parameters. True: do; FALSE: skip.
305 
306 
307   @retval EFI_SUCCESS         - The command byte is written successfully.
308   @retval EFI_DEVICE_ERROR    - Errors occurred during resetting keyboard.
309 
310 **/
311 EFI_STATUS
312 EFIAPI
313 MouseReset (
314   IN EFI_SIMPLE_POINTER_PROTOCOL    *This,
315   IN BOOLEAN                        ExtendedVerification
316   );
317 
318 /**
319   Get and Clear mouse status.
320 
321   @param This                 - Pointer of simple pointer Protocol.
322   @param State                - Output buffer holding status.
323 
324   @retval EFI_INVALID_PARAMETER Output buffer is invalid.
325   @retval EFI_NOT_READY         Mouse is not changed status yet.
326   @retval EFI_SUCCESS           Mouse status is changed and get successful.
327 **/
328 EFI_STATUS
329 EFIAPI
330 MouseGetState (
331   IN EFI_SIMPLE_POINTER_PROTOCOL    *This,
332   IN OUT EFI_SIMPLE_POINTER_STATE   *State
333   );
334 
335 /**
336 
337   Event notification function for SIMPLE_POINTER.WaitForInput event.
338   Signal the event if there is input from mouse.
339 
340   @param Event    event object
341   @param Context  event context
342 
343 **/
344 VOID
345 EFIAPI
346 MouseWaitForInput (
347   IN  EFI_EVENT               Event,
348   IN  VOID                    *Context
349   );
350 
351 /**
352   Event notification function for TimerEvent event.
353   If mouse device is connected to system, try to get the mouse packet data.
354 
355   @param Event      -  TimerEvent in PS2_MOUSE_DEV
356   @param Context    -  Pointer to PS2_MOUSE_DEV structure
357 
358 **/
359 VOID
360 EFIAPI
361 PollMouse (
362   IN EFI_EVENT  Event,
363   IN VOID       *Context
364   );
365 
366 /**
367   I/O work flow of in 8042 data.
368 
369   @param Data    Data value
370 
371   @retval EFI_SUCCESS Success to execute I/O work flow
372   @retval EFI_TIMEOUT Keyboard controller time out.
373 **/
374 EFI_STATUS
375 In8042Data (
376   IN OUT UINT8                            *Data
377   );
378 
379 /**
380   Check whether there is Ps/2 mouse device in system
381 
382   @param MouseDev   - Mouse Private Data Structure
383 
384   @retval TRUE      - Keyboard in System.
385   @retval FALSE     - Keyboard not in System.
386 
387 **/
388 BOOLEAN
389 CheckMouseConnect (
390   IN  PS2_MOUSE_DEV     *MouseDev
391   );
392 
393 #endif
394