ReactOS 0.4.15-dev-8131-g4988de4
i8042prt.h File Reference
#include <ntifs.h>
#include <kbdmou.h>
#include <ntdd8042.h>
Include dependency graph for i8042prt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _I8042_SETTINGS
 
struct  _INTERRUPT_DATA
 
struct  _PORT_DEVICE_EXTENSION
 
struct  _I8042_DRIVER_EXTENSION
 
struct  _FDO_DEVICE_EXTENSION
 
struct  _I8042_KEYBOARD_EXTENSION
 
struct  _I8042_MOUSE_EXTENSION
 
struct  _I8042_HOOK_WORKITEM
 

Macros

#define I8042PRT_TAG   '2408'
 
#define WHEEL_DELTA   120
 
#define KEYBOARD_PRESENT   0x01 /* A keyboard is attached */
 
#define KEYBOARD_CONNECTED   0x02 /* Keyboard received IOCTL_INTERNAL_KEYBOARD_CONNECT */
 
#define KEYBOARD_STARTED   0x04 /* Keyboard FDO received IRP_MN_START_DEVICE */
 
#define KEYBOARD_INITIALIZED   0x08 /* Keyboard interrupt is connected */
 
#define MOUSE_PRESENT   0x10 /* A mouse is attached */
 
#define MOUSE_CONNECTED   0x20 /* Mouse received IOCTL_INTERNAL_MOUSE_CONNECT */
 
#define MOUSE_STARTED   0x40 /* Mouse FDO received IRP_MN_START_DEVICE */
 
#define MOUSE_INITIALIZED   0x80 /* Mouse interrupt is connected */
 
#define MAX(a, b)   ((a) >= (b) ? (a) : (b))
 
#define KEYBOARD_POWER_CODE   0x5E
 
#define KEYBOARD_SLEEP_CODE   0x5F
 
#define KEYBOARD_WAKE_CODE   0x63
 
#define KBD_READ_MODE   0x20
 
#define KBD_WRITE_MODE   0x60
 
#define MOUSE_ENAB   0xA8
 
#define MOUSE_LINE_TEST   0xA9
 
#define CTRL_SELF_TEST   0xAA
 
#define KBD_CLK_DISABLE   0xAD
 
#define KBD_CLK_ENABLE   0xAE
 
#define CTRL_WRITE_MOUSE   0xD4
 
#define KBD_CMD_SET_LEDS   0xED
 
#define KBD_CMD_GET_ID   0xF2
 
#define KBD_SELF_TEST_OK   0x55
 
#define KBD_ACK   0xFA
 
#define KBD_NACK   0xFC
 
#define KBD_RESEND   0xFE
 
#define KBD_OBF   0x01
 
#define KBD_IBF   0x02
 
#define MOU_OBF   0x20
 
#define KBD_PERR   0x80
 
#define CCB_KBD_INT_ENAB   0x01
 
#define CCB_MOUSE_INT_ENAB   0x02
 
#define CCB_SYSTEM_FLAG   0x04
 
#define CCB_KBD_DISAB   0x10
 
#define CCB_MOUSE_DISAB   0x20
 
#define CCB_TRANSLATE   0x40
 
#define KBD_LED_SCROLL   0x01
 
#define KBD_LED_NUM   0x02
 
#define KBD_LED_CAPS   0x04
 
#define MOU_ENAB   0xF4
 
#define MOU_CMD_RESET   0xFF
 
#define MOUSE_ACK   0xFA
 
#define MOUSE_ERROR   0xFC
 
#define MOUSE_NACK   0xFE
 
#define i8042ReadKeyboardData(DeviceExtension, Data)    i8042ReadData(DeviceExtension, KBD_OBF, Data)
 
#define i8042ReadMouseData(DeviceExtension, Data)    i8042ReadData(DeviceExtension, MOU_OBF, Data)
 

Typedefs

typedef struct _I8042_SETTINGS I8042_SETTINGS
 
typedef struct _I8042_SETTINGSPI8042_SETTINGS
 
typedef enum _MOUSE_TIMEOUT_STATE MOUSE_TIMEOUT_STATE
 
typedef enum _MOUSE_TIMEOUT_STATEPMOUSE_TIMEOUT_STATE
 
typedef struct _INTERRUPT_DATA INTERRUPT_DATA
 
typedef struct _INTERRUPT_DATAPINTERRUPT_DATA
 
typedef struct _I8042_KEYBOARD_EXTENSIONPI8042_KEYBOARD_EXTENSION
 
typedef struct _I8042_MOUSE_EXTENSIONPI8042_MOUSE_EXTENSION
 
typedef struct _PORT_DEVICE_EXTENSION PORT_DEVICE_EXTENSION
 
typedef struct _PORT_DEVICE_EXTENSIONPPORT_DEVICE_EXTENSION
 
typedef struct _I8042_DRIVER_EXTENSION I8042_DRIVER_EXTENSION
 
typedef struct _I8042_DRIVER_EXTENSIONPI8042_DRIVER_EXTENSION
 
typedef enum _I8042_DEVICE_TYPE I8042_DEVICE_TYPE
 
typedef enum _I8042_DEVICE_TYPEPI8042_DEVICE_TYPE
 
typedef struct _FDO_DEVICE_EXTENSION FDO_DEVICE_EXTENSION
 
typedef struct _FDO_DEVICE_EXTENSIONPFDO_DEVICE_EXTENSION
 
typedef struct _I8042_KEYBOARD_EXTENSION I8042_KEYBOARD_EXTENSION
 
typedef enum _I8042_MOUSE_TYPE I8042_MOUSE_TYPE
 
typedef enum _I8042_MOUSE_TYPEPI8042_MOUSE_TYPE
 
typedef struct _I8042_MOUSE_EXTENSION I8042_MOUSE_EXTENSION
 
typedef struct _I8042_HOOK_WORKITEM I8042_HOOK_WORKITEM
 
typedef struct _I8042_HOOK_WORKITEMPI8042_HOOK_WORKITEM
 

Enumerations

enum  DEVICE_STATE {
  dsStopped , dsStarted , dsPaused , dsRemoved ,
  dsSurpriseRemoved , NotStarted = 0 , Started , StopPending ,
  Stopped , RemovePending , SurpriseRemovePending , Deleted ,
  dsStopped , dsStarted , dsPaused , dsRemoved ,
  dsSurpriseRemoved , dsStopped , dsStarted , dsPaused ,
  dsRemoved , dsSurpriseRemoved
}
 
enum  _MOUSE_TIMEOUT_STATE { NoChange , TimeoutStart , TimeoutCancel }
 
enum  _I8042_DEVICE_TYPE { Unknown , Keyboard , Mouse , PhysicalDeviceObject }
 
enum  _I8042_MOUSE_TYPE { GenericPS2 , Intellimouse , IntellimouseExplorer , Ps2pp }
 
enum  _FLAGS { FL_NOLOOP = 0x01 , FL_INITHACK = 0x02 }
 

Functions

 _Dispatch_type_ (IRP_MJ_CREATE) DRIVER_DISPATCH i8042Create
 
 _Dispatch_type_ (IRP_MJ_CLEANUP) DRIVER_DISPATCH i8042Cleanup
 
 _Dispatch_type_ (IRP_MJ_CLOSE) DRIVER_DISPATCH i8042Close
 
NTSTATUS NTAPI i8042SynchWritePortKbd (IN PVOID Context, IN UCHAR Value, IN BOOLEAN WaitForAck)
 
BOOLEAN i8042PacketIsr (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Output)
 
NTSTATUS i8042StartPacket (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PFDO_DEVICE_EXTENSION FdoDeviceExtension, IN PUCHAR Bytes, IN ULONG ByteCount, IN PIRP Irp)
 
NTSTATUS DuplicateUnicodeString (IN ULONG Flags, IN PCUNICODE_STRING SourceString, OUT PUNICODE_STRING DestinationString)
 
VOID i8042MouHandle (IN PI8042_MOUSE_EXTENSION DeviceExtension, IN UCHAR Output)
 
VOID i8042MouHandleButtons (IN PI8042_MOUSE_EXTENSION DeviceExtension, IN USHORT Mask)
 
NTSTATUS i8042MouInitialize (IN PI8042_MOUSE_EXTENSION DeviceExtension)
 
BOOLEAN i8042ChangeMode (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR FlagsToDisable, IN UCHAR FlagsToEnable)
 
 _Dispatch_type_ (IRP_MJ_PNP) DRIVER_DISPATCH i8042Pnp
 
VOID i8042MouHandlePs2pp (IN PI8042_MOUSE_EXTENSION DeviceExtension, IN UCHAR Input)
 
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 i8042ReadDataWait (IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Data)
 
NTSTATUS i8042ReadStatus (IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Status)
 
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)
 
NTSTATUS ReadRegistryEntries (IN PUNICODE_STRING RegistryPath, OUT PI8042_SETTINGS Settings)
 
VOID NTAPI i8042InitializeHwHacks (VOID)
 

Variables

IO_WORKITEM_ROUTINE i8042SendHookWorkItem
 
DRIVER_STARTIO i8042KbdStartIo
 
DRIVER_DISPATCH i8042KbdDeviceControl
 
DRIVER_DISPATCH i8042KbdInternalDeviceControl
 
KSERVICE_ROUTINE i8042KbdInterruptService
 
DRIVER_ADD_DEVICE i8042AddDevice
 
DRIVER_DISPATCH ForwardIrpAndForget
 
DRIVER_DISPATCH i8042MouInternalDeviceControl
 
KSERVICE_ROUTINE i8042MouInterruptService
 
ULONG i8042HwFlags
 

Macro Definition Documentation

◆ CCB_KBD_DISAB

#define CCB_KBD_DISAB   0x10

Definition at line 262 of file i8042prt.h.

◆ CCB_KBD_INT_ENAB

#define CCB_KBD_INT_ENAB   0x01

Definition at line 259 of file i8042prt.h.

◆ CCB_MOUSE_DISAB

#define CCB_MOUSE_DISAB   0x20

Definition at line 263 of file i8042prt.h.

◆ CCB_MOUSE_INT_ENAB

#define CCB_MOUSE_INT_ENAB   0x02

Definition at line 260 of file i8042prt.h.

◆ CCB_SYSTEM_FLAG

#define CCB_SYSTEM_FLAG   0x04

Definition at line 261 of file i8042prt.h.

◆ CCB_TRANSLATE

#define CCB_TRANSLATE   0x40

Definition at line 264 of file i8042prt.h.

◆ CTRL_SELF_TEST

#define CTRL_SELF_TEST   0xAA

Definition at line 225 of file i8042prt.h.

◆ CTRL_WRITE_MOUSE

#define CTRL_WRITE_MOUSE   0xD4

Definition at line 228 of file i8042prt.h.

◆ I8042PRT_TAG

#define I8042PRT_TAG   '2408'

Definition at line 12 of file i8042prt.h.

◆ i8042ReadKeyboardData

#define i8042ReadKeyboardData (   DeviceExtension,
  Data 
)     i8042ReadData(DeviceExtension, KBD_OBF, Data)

Definition at line 403 of file i8042prt.h.

◆ i8042ReadMouseData

#define i8042ReadMouseData (   DeviceExtension,
  Data 
)     i8042ReadData(DeviceExtension, MOU_OBF, Data)

Definition at line 405 of file i8042prt.h.

◆ KBD_ACK

#define KBD_ACK   0xFA

Definition at line 242 of file i8042prt.h.

◆ KBD_CLK_DISABLE

#define KBD_CLK_DISABLE   0xAD

Definition at line 226 of file i8042prt.h.

◆ KBD_CLK_ENABLE

#define KBD_CLK_ENABLE   0xAE

Definition at line 227 of file i8042prt.h.

◆ KBD_CMD_GET_ID

#define KBD_CMD_GET_ID   0xF2

Definition at line 235 of file i8042prt.h.

◆ KBD_CMD_SET_LEDS

#define KBD_CMD_SET_LEDS   0xED

Definition at line 234 of file i8042prt.h.

◆ KBD_IBF

#define KBD_IBF   0x02

Definition at line 251 of file i8042prt.h.

◆ KBD_LED_CAPS

#define KBD_LED_CAPS   0x04

Definition at line 272 of file i8042prt.h.

◆ KBD_LED_NUM

#define KBD_LED_NUM   0x02

Definition at line 271 of file i8042prt.h.

◆ KBD_LED_SCROLL

#define KBD_LED_SCROLL   0x01

Definition at line 270 of file i8042prt.h.

◆ KBD_NACK

#define KBD_NACK   0xFC

Definition at line 243 of file i8042prt.h.

◆ KBD_OBF

#define KBD_OBF   0x01

Definition at line 250 of file i8042prt.h.

◆ KBD_PERR

#define KBD_PERR   0x80

Definition at line 253 of file i8042prt.h.

◆ KBD_READ_MODE

#define KBD_READ_MODE   0x20

Definition at line 221 of file i8042prt.h.

◆ KBD_RESEND

#define KBD_RESEND   0xFE

Definition at line 244 of file i8042prt.h.

◆ KBD_SELF_TEST_OK

#define KBD_SELF_TEST_OK   0x55

Definition at line 241 of file i8042prt.h.

◆ KBD_WRITE_MODE

#define KBD_WRITE_MODE   0x60

Definition at line 222 of file i8042prt.h.

◆ KEYBOARD_CONNECTED

#define KEYBOARD_CONNECTED   0x02 /* Keyboard received IOCTL_INTERNAL_KEYBOARD_CONNECT */

Definition at line 69 of file i8042prt.h.

◆ KEYBOARD_INITIALIZED

#define KEYBOARD_INITIALIZED   0x08 /* Keyboard interrupt is connected */

Definition at line 71 of file i8042prt.h.

◆ KEYBOARD_POWER_CODE

#define KEYBOARD_POWER_CODE   0x5E

Definition at line 213 of file i8042prt.h.

◆ KEYBOARD_PRESENT

#define KEYBOARD_PRESENT   0x01 /* A keyboard is attached */

Definition at line 68 of file i8042prt.h.

◆ KEYBOARD_SLEEP_CODE

#define KEYBOARD_SLEEP_CODE   0x5F

Definition at line 214 of file i8042prt.h.

◆ KEYBOARD_STARTED

#define KEYBOARD_STARTED   0x04 /* Keyboard FDO received IRP_MN_START_DEVICE */

Definition at line 70 of file i8042prt.h.

◆ KEYBOARD_WAKE_CODE

#define KEYBOARD_WAKE_CODE   0x63

Definition at line 215 of file i8042prt.h.

◆ MAX

#define MAX (   a,
  b 
)    ((a) >= (b) ? (a) : (b))

Definition at line 211 of file i8042prt.h.

◆ MOU_CMD_RESET

#define MOU_CMD_RESET   0xFF

Definition at line 279 of file i8042prt.h.

◆ MOU_ENAB

#define MOU_ENAB   0xF4

Definition at line 278 of file i8042prt.h.

◆ MOU_OBF

#define MOU_OBF   0x20

Definition at line 252 of file i8042prt.h.

◆ MOUSE_ACK

#define MOUSE_ACK   0xFA

Definition at line 285 of file i8042prt.h.

◆ MOUSE_CONNECTED

#define MOUSE_CONNECTED   0x20 /* Mouse received IOCTL_INTERNAL_MOUSE_CONNECT */

Definition at line 73 of file i8042prt.h.

◆ MOUSE_ENAB

#define MOUSE_ENAB   0xA8

Definition at line 223 of file i8042prt.h.

◆ MOUSE_ERROR

#define MOUSE_ERROR   0xFC

Definition at line 286 of file i8042prt.h.

◆ MOUSE_INITIALIZED

#define MOUSE_INITIALIZED   0x80 /* Mouse interrupt is connected */

Definition at line 75 of file i8042prt.h.

◆ MOUSE_LINE_TEST

#define MOUSE_LINE_TEST   0xA9

Definition at line 224 of file i8042prt.h.

◆ MOUSE_NACK

#define MOUSE_NACK   0xFE

Definition at line 287 of file i8042prt.h.

◆ MOUSE_PRESENT

#define MOUSE_PRESENT   0x10 /* A mouse is attached */

Definition at line 72 of file i8042prt.h.

◆ MOUSE_STARTED

#define MOUSE_STARTED   0x40 /* Mouse FDO received IRP_MN_START_DEVICE */

Definition at line 74 of file i8042prt.h.

◆ WHEEL_DELTA

#define WHEEL_DELTA   120

Definition at line 60 of file i8042prt.h.

Typedef Documentation

◆ FDO_DEVICE_EXTENSION

◆ I8042_DEVICE_TYPE

◆ I8042_DRIVER_EXTENSION

◆ I8042_HOOK_WORKITEM

◆ I8042_KEYBOARD_EXTENSION

◆ I8042_MOUSE_EXTENSION

◆ I8042_MOUSE_TYPE

◆ I8042_SETTINGS

◆ INTERRUPT_DATA

◆ MOUSE_TIMEOUT_STATE

◆ PFDO_DEVICE_EXTENSION

◆ PI8042_DEVICE_TYPE

◆ PI8042_DRIVER_EXTENSION

◆ PI8042_HOOK_WORKITEM

◆ PI8042_KEYBOARD_EXTENSION

◆ PI8042_MOUSE_EXTENSION

Definition at line 65 of file i8042prt.h.

◆ PI8042_MOUSE_TYPE

◆ PI8042_SETTINGS

◆ PINTERRUPT_DATA

◆ PMOUSE_TIMEOUT_STATE

◆ PORT_DEVICE_EXTENSION

◆ PPORT_DEVICE_EXTENSION

Enumeration Type Documentation

◆ _FLAGS

Enumerator
FL_NOLOOP 
FL_INITHACK 

Definition at line 451 of file i8042prt.h.

452{
453 FL_NOLOOP = 0x01,
454 FL_INITHACK = 0x02,
455};
@ FL_NOLOOP
Definition: i8042prt.h:453
@ FL_INITHACK
Definition: i8042prt.h:454

◆ _I8042_DEVICE_TYPE

Enumerator
Unknown 
Keyboard 
Mouse 
PhysicalDeviceObject 

Definition at line 112 of file i8042prt.h.

113{
114 Unknown,
115 Keyboard,
116 Mouse,
enum _I8042_DEVICE_TYPE * PI8042_DEVICE_TYPE
@ Keyboard
Definition: i8042prt.h:115
@ Mouse
Definition: i8042prt.h:116
@ Unknown
Definition: i8042prt.h:114
@ PhysicalDeviceObject
Definition: i8042prt.h:117
enum _I8042_DEVICE_TYPE I8042_DEVICE_TYPE

◆ _I8042_MOUSE_TYPE

Enumerator
GenericPS2 
Intellimouse 
IntellimouseExplorer 
Ps2pp 

Definition at line 167 of file i8042prt.h.

168{
172 Ps2pp
@ Intellimouse
Definition: i8042prt.h:170
@ GenericPS2
Definition: i8042prt.h:169
@ Ps2pp
Definition: i8042prt.h:172
@ IntellimouseExplorer
Definition: i8042prt.h:171
enum _I8042_MOUSE_TYPE I8042_MOUSE_TYPE
enum _I8042_MOUSE_TYPE * PI8042_MOUSE_TYPE

◆ _MOUSE_TIMEOUT_STATE

Enumerator
NoChange 
TimeoutStart 
TimeoutCancel 

Definition at line 43 of file i8042prt.h.

44{
enum _MOUSE_TIMEOUT_STATE MOUSE_TIMEOUT_STATE
@ TimeoutStart
Definition: i8042prt.h:46
@ TimeoutCancel
Definition: i8042prt.h:47
@ NoChange
Definition: i8042prt.h:45
enum _MOUSE_TIMEOUT_STATE * PMOUSE_TIMEOUT_STATE

◆ DEVICE_STATE

Enumerator
dsStopped 
dsStarted 
dsPaused 
dsRemoved 
dsSurpriseRemoved 
NotStarted 
Started 
StopPending 
Stopped 
RemovePending 
SurpriseRemovePending 
Deleted 
dsStopped 
dsStarted 
dsPaused 
dsRemoved 
dsSurpriseRemoved 
dsStopped 
dsStarted 
dsPaused 
dsRemoved 
dsSurpriseRemoved 

Definition at line 14 of file i8042prt.h.

15{
DEVICE_STATE
Definition: i8042prt.h:15
@ dsSurpriseRemoved
Definition: i8042prt.h:20
@ dsStopped
Definition: i8042prt.h:16
@ dsPaused
Definition: i8042prt.h:18
@ dsStarted
Definition: i8042prt.h:17
@ dsRemoved
Definition: i8042prt.h:19

Function Documentation

◆ _Dispatch_type_() [1/4]

_Dispatch_type_ ( IRP_MJ_CLEANUP  )

Definition at line 2438 of file btrfs.c.

2440 {
2444 device_extension* Vcb = DeviceObject->DeviceExtension;
2445 fcb* fcb = FileObject->FsContext;
2446 bool top_level;
2447
2449
2450 TRACE("cleanup\n");
2451
2452 top_level = is_top_level(Irp);
2453
2454 if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
2455 Irp->IoStatus.Information = 0;
2457 goto exit;
2458 } else if (DeviceObject == master_devobj) {
2459 TRACE("closing file system\n");
2461 goto exit;
2462 } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
2464 goto exit;
2465 }
2466
2467 if (FileObject->Flags & FO_CLEANUP_COMPLETE) {
2468 TRACE("FileObject %p already cleaned up\n", FileObject);
2470 goto exit;
2471 }
2472
2473 if (!fcb) {
2474 ERR("fcb was NULL\n");
2476 goto exit;
2477 }
2478
2480
2481 // We have to use the pointer to Vcb stored in the fcb, as we can receive cleanup
2482 // messages belonging to other devices.
2483
2484 if (FileObject && FileObject->FsContext) {
2485 ccb* ccb;
2486 file_ref* fileref;
2487 bool locked = true;
2488
2489 ccb = FileObject->FsContext2;
2490 fileref = ccb ? ccb->fileref : NULL;
2491
2492 TRACE("cleanup called for FileObject %p\n", FileObject);
2493 TRACE("fileref %p, refcount = %li, open_count = %li\n", fileref, fileref ? fileref->refcount : 0, fileref ? fileref->open_count : 0);
2494
2495 ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, true);
2496
2497 ExAcquireResourceExclusiveLite(fcb->Header.Resource, true);
2498
2500
2502
2503 if (ccb)
2504 FsRtlNotifyCleanup(fcb->Vcb->NotifySync, &fcb->Vcb->DirNotifyList, ccb);
2505
2506 if (ccb && ccb->options & FILE_DELETE_ON_CLOSE && fileref)
2507 fileref->delete_on_close = true;
2508
2509 if (fileref && fileref->delete_on_close && fcb->type == BTRFS_TYPE_DIRECTORY && fcb->inode_item.st_size > 0 && fcb != fcb->Vcb->dummy_fcb)
2510 fileref->delete_on_close = false;
2511
2512 if (fcb->Vcb->locked && fcb->Vcb->locked_fileobj == FileObject) {
2513 TRACE("unlocking volume\n");
2516 }
2517
2518 if (ccb && ccb->reserving) {
2519 fcb->subvol->reserved = NULL;
2520 ccb->reserving = false;
2521 // FIXME - flush all of subvol's fcbs
2522 }
2523
2524 if (fileref) {
2525 LONG oc = InterlockedDecrement(&fileref->open_count);
2526#ifdef DEBUG_FCB_REFCOUNTS
2527 ERR("fileref %p: open_count now %i\n", fileref, oc);
2528#endif
2529
2530 if (oc == 0 || (fileref->delete_on_close && fileref->posix_delete)) {
2531 if (!fcb->Vcb->removing) {
2532 if (oc == 0 && fileref->fcb->inode_item.st_nlink == 0 && fileref != fcb->Vcb->root_fileref &&
2533 fcb != fcb->Vcb->volume_fcb && !fcb->ads) { // last handle closed on POSIX-deleted file
2535
2537
2539 if (!NT_SUCCESS(Status)) {
2540 ERR("delete_fileref_fcb returned %08lx\n", Status);
2542 ExReleaseResourceLite(fileref->fcb->Header.Resource);
2543 ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2544 goto exit;
2545 }
2546
2548
2549 mark_fcb_dirty(fileref->fcb);
2550 } else if (fileref->delete_on_close && fileref != fcb->Vcb->root_fileref && fcb != fcb->Vcb->volume_fcb) {
2552
2554
2555 if (!fileref->fcb->ads || fileref->dc) {
2556 if (fileref->fcb->ads) {
2558 FILE_ACTION_REMOVED, &fileref->dc->name);
2559 } else
2561 }
2562
2563 ExReleaseResourceLite(fcb->Header.Resource);
2564 locked = false;
2565
2566 // fileref_lock needs to be acquired before fcb->Header.Resource
2567 ExAcquireResourceExclusiveLite(&fcb->Vcb->fileref_lock, true);
2568
2569 Status = delete_fileref(fileref, FileObject, oc > 0 && fileref->posix_delete, Irp, &rollback);
2570 if (!NT_SUCCESS(Status)) {
2571 ERR("delete_fileref returned %08lx\n", Status);
2573 ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
2574 ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2575 goto exit;
2576 }
2577
2578 ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
2579
2581 } else if (FileObject->Flags & FO_CACHE_SUPPORTED && FileObject->SectionObjectPointer->DataSectionObject) {
2583
2584 if (locked) {
2585 ExReleaseResourceLite(fcb->Header.Resource);
2586 locked = false;
2587 }
2588
2589 CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &iosb);
2590
2591 if (!NT_SUCCESS(iosb.Status))
2592 ERR("CcFlushCache returned %08lx\n", iosb.Status);
2593
2594 if (!ExIsResourceAcquiredSharedLite(fcb->Header.PagingIoResource)) {
2595 ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, true);
2596 ExReleaseResourceLite(fcb->Header.PagingIoResource);
2597 }
2598
2599 CcPurgeCacheSection(FileObject->SectionObjectPointer, NULL, 0, false);
2600
2601 TRACE("flushed cache on close (FileObject = %p, fcb = %p, AllocationSize = %I64x, FileSize = %I64x, ValidDataLength = %I64x)\n",
2602 FileObject, fcb, fcb->Header.AllocationSize.QuadPart, fcb->Header.FileSize.QuadPart, fcb->Header.ValidDataLength.QuadPart);
2603 }
2604 }
2605
2606 if (fcb->Vcb && fcb != fcb->Vcb->volume_fcb)
2608 }
2609 }
2610
2611 if (locked)
2612 ExReleaseResourceLite(fcb->Header.Resource);
2613
2614 ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2615
2617 }
2618
2620
2621exit:
2622 TRACE("returning %08lx\n", Status);
2623
2624 Irp->IoStatus.Status = Status;
2625 Irp->IoStatus.Information = 0;
2626
2628
2629 if (top_level)
2631
2633
2634 return Status;
2635}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define InterlockedDecrement
Definition: armddk.h:52
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
#define ERR(fmt,...)
Definition: debug.h:113
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:689
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: btrfs_drv.h:1365
#define VCB_TYPE_FS
Definition: btrfs_drv.h:687
static __inline POPLOCK fcb_oplock(fcb *fcb)
Definition: btrfs_drv.h:1677
void do_rollback(device_extension *Vcb, LIST_ENTRY *rollback) __attribute__((nonnull(1
struct _ccb ccb
NTSTATUS NTSTATUS void clear_rollback(LIST_ENTRY *rollback) __attribute__((nonnull(1)))
void do_unlock_volume(device_extension *Vcb)
Definition: fsctl.c:2326
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
void mark_fcb_dirty(_In_ fcb *fcb)
Definition: btrfs.c:1695
NTSTATUS delete_fileref(_In_ file_ref *fileref, _In_opt_ PFILE_OBJECT FileObject, _In_ bool make_orphan, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
Definition: btrfs.c:2270
return STATUS_SUCCESS
Definition: btrfs.c:3080
InsertTailList & Vcb
Definition: btrfs.c:3044
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:278
static NTSTATUS delete_fileref_fcb(_In_ file_ref *fileref, _In_opt_ PFILE_OBJECT FileObject, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
Definition: btrfs.c:2214
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:66
void send_notification_fileref(_In_ file_ref *fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream)
Definition: btrfs.c:1517
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define ExAcquireResourceSharedLite(res, wait)
Definition: env_spec_w32.h:621
NTSTATUS NTAPI FsRtlFastUnlockAll(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN PVOID Context OPTIONAL)
Definition: filelock.c:1025
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:286
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:386
Status
Definition: gdiplustypes.h:25
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
#define FSRTL_VOLUME_UNLOCK
Definition: ntifs_ex.h:443
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1663
VOID NTAPI FsRtlNotifyCleanup(IN PNOTIFY_SYNC NotifySync, IN PLIST_ENTRY NotifyList, IN PVOID FsContext)
Definition: notify.c:659
NTSTATUS NTAPI FsRtlNotifyVolumeEvent(IN PFILE_OBJECT FileObject, IN ULONG EventCode)
Definition: pnp.c:38
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3478
#define IoCompleteRequest
Definition: irp.c:1240
PEPROCESS NTAPI IoGetRequestorProcess(IN PIRP Irp)
Definition: irp.c:1782
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
NTSTATUS NTAPI FsRtlCheckOplock(IN POPLOCK Oplock, IN PIRP Irp, IN PVOID Context, IN POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine OPTIONAL, IN POPLOCK_FS_PREPOST_IRP PostIrpRoutine OPTIONAL)
Definition: oplock.c:1170
long LONG
Definition: pedump.c:60
#define exit(n)
Definition: config.h:202
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:86
#define TRACE(s)
Definition: solgame.cpp:4
uint32_t st_nlink
Definition: btrfs.h:292
uint64_t st_size
Definition: btrfs.h:289
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
Definition: typedefs.h:120
bool reserving
Definition: btrfs_drv.h:381
file_ref * fileref
Definition: btrfs_drv.h:383
ULONG options
Definition: btrfs_drv.h:374
bool ads
Definition: btrfs_drv.h:330
FILE_LOCK lock
Definition: btrfs_drv.h:294
INODE_ITEM inode_item
Definition: btrfs_drv.h:292
uint8_t type
Definition: btrfs_drv.h:291
struct _device_extension * Vcb
Definition: btrfs_drv.h:287
struct _root * subvol
Definition: btrfs_drv.h:288
SHARE_ACCESS share_access
Definition: btrfs_drv.h:298
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:283
LONG refcount
Definition: btrfs_drv.h:350
struct _file_ref * parent
Definition: btrfs_drv.h:352
fcb * fcb
Definition: btrfs_drv.h:342
dir_child * dc
Definition: btrfs_drv.h:353
bool posix_delete
Definition: btrfs_drv.h:346
LONG open_count
Definition: btrfs_drv.h:351
bool delete_on_close
Definition: btrfs_drv.h:345
UNICODE_STRING name
Definition: btrfs_drv.h:256
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define FILE_ACTION_REMOVED
#define FILE_NOTIFY_CHANGE_FILE_NAME
#define FO_CLEANUP_COMPLETE
Definition: iotypes.h:1790
* PFILE_OBJECT
Definition: iotypes.h:1998
#define FO_CACHE_SUPPORTED
Definition: iotypes.h:1781
#define FILE_NOTIFY_CHANGE_DIR_NAME

◆ _Dispatch_type_() [2/4]

_Dispatch_type_ ( IRP_MJ_CLOSE  )

Definition at line 503 of file btrfs.c.

505 {
508 device_extension* Vcb = DeviceObject->DeviceExtension;
509 bool top_level;
510
512
513 TRACE("close\n");
514
515 top_level = is_top_level(Irp);
516
518 TRACE("Closing file system\n");
520 goto end;
521 } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
523 goto end;
524 } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
526 goto end;
527 }
528
530
531 // FIXME - call FsRtlNotifyUninitializeSync(&Vcb->NotifySync) if unmounting
532
534
535end:
536 Irp->IoStatus.Status = Status;
537 Irp->IoStatus.Information = 0;
538
540
541 if (top_level)
543
544 TRACE("returning %08lx\n", Status);
545
547
548 return Status;
549}
NTSTATUS vol_close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:95
GLuint GLuint end
Definition: gl.h:1545
static void close_file()
Definition: regtests2xml.c:133
#define IO_DISK_INCREMENT
Definition: iotypes.h:600

◆ _Dispatch_type_() [3/4]

_Dispatch_type_ ( IRP_MJ_CREATE  )

Definition at line 984 of file isapnp.c.

995{
996 PAGED_CODE();
997
998 Irp->IoStatus.Status = STATUS_SUCCESS;
999
1000 DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
1001
1003
1004 return STATUS_SUCCESS;
1005}
#define PAGED_CODE()
#define __FUNCTION__
Definition: types.h:116
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73

◆ _Dispatch_type_() [4/4]

_Dispatch_type_ ( IRP_MJ_PNP  )

Definition at line 1581 of file isapnp.c.

1591{
1593 PISAPNP_COMMON_EXTENSION DevExt = DeviceObject->DeviceExtension;
1594
1595 PAGED_CODE();
1596
1597 if (DevExt->Signature == IsaPnpBus)
1598 return IsaFdoPnp((PISAPNP_FDO_EXTENSION)DevExt, Irp, IrpSp);
1599 else
1600 return IsaPdoPnp((PISAPNP_PDO_EXTENSION)DevExt, Irp, IrpSp);
1601}
NTSTATUS IsaFdoPnp(_In_ PISAPNP_FDO_EXTENSION FdoExt, _Inout_ PIRP Irp, _In_ PIO_STACK_LOCATION IrpSp)
Definition: fdo.c:123
@ IsaPnpBus
Definition: isapnp.h:143
NTSTATUS IsaPdoPnp(_In_ PISAPNP_PDO_EXTENSION PdoDeviceExtension, _Inout_ PIRP Irp, _In_ PIO_STACK_LOCATION IrpSp)
Definition: pdo.c:864
ISAPNP_SIGNATURE Signature
Definition: isapnp.h:150

◆ DuplicateUnicodeString()

NTSTATUS DuplicateUnicodeString ( IN ULONG  Flags,
IN PCUNICODE_STRING  SourceString,
OUT PUNICODE_STRING  DestinationString 
)

Definition at line 31 of file misc.c.

35{
40 {
42 }
43
44
45 if ((SourceString->Length == 0)
48 {
52 }
53 else
54 {
55 USHORT DestMaxLength = SourceString->Length;
56
58 DestMaxLength += sizeof(UNICODE_NULL);
59
62 return STATUS_NO_MEMORY;
63
66 DestinationString->MaximumLength = DestMaxLength;
67
70 }
71
72 return STATUS_SUCCESS;
73}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
Definition: green.h:16
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: green.h:15
#define I8042PRT_TAG
Definition: i8042prt.h:12
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1910
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1909
#define UNICODE_NULL
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
unsigned short USHORT
Definition: pedump.c:61
unsigned short Length
Definition: sprintf.c:451
void * Buffer
Definition: sprintf.c:453
unsigned short MaximumLength
Definition: sprintf.c:452
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by DriverEntry(), FdcPdoQueryId(), PciCreateCompatibleIDsString(), PciCreateHardwareIDsString(), ReportDetectedDevice(), SearchForLegacyDrivers(), and SerenumPdoQueryId().

◆ i8042ChangeMode()

BOOLEAN i8042ChangeMode ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN UCHAR  FlagsToDisable,
IN UCHAR  FlagsToEnable 
)

Definition at line 37 of file pnp.c.

41{
44
45 if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, KBD_READ_MODE))
46 {
47 WARN_(I8042PRT, "Can't read i8042 mode\n");
48 return FALSE;
49 }
50
51 Status = i8042ReadDataWait(DeviceExtension, &Value);
52 if (!NT_SUCCESS(Status))
53 {
54 WARN_(I8042PRT, "No response after read i8042 mode\n");
55 return FALSE;
56 }
57
58 Value &= ~FlagsToDisable;
59 Value |= FlagsToEnable;
60
61 if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, KBD_WRITE_MODE))
62 {
63 WARN_(I8042PRT, "Can't set i8042 mode\n");
64 return FALSE;
65 }
66
67 if (!i8042Write(DeviceExtension, DeviceExtension->DataPort, Value))
68 {
69 WARN_(I8042PRT, "Can't send i8042 mode\n");
70 return FALSE;
71 }
72
73 return TRUE;
74}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
NTSTATUS i8042ReadDataWait(IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Data)
Definition: readwrite.c:95
#define KBD_WRITE_MODE
Definition: i8042prt.h:222
#define KBD_READ_MODE
Definition: i8042prt.h:221
BOOLEAN i8042Write(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PUCHAR addr, IN UCHAR data)
Definition: readwrite.c:199
#define WARN_(ch,...)
Definition: debug.h:157
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
unsigned char UCHAR
Definition: xmlstorage.h:181

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

◆ 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 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

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

◆ i8042InitializeHwHacks()

VOID NTAPI i8042InitializeHwHacks ( VOID  )

Definition at line 185 of file hwhacks.c.

187{
189 PVOID DataBlockObject;
190 PWNODE_ALL_DATA AllData;
192
193 /* Open the data block object for the SMBIOS table */
196 &DataBlockObject);
197 if (!NT_SUCCESS(Status))
198 {
199 DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
200 return;
201 }
202
203 /* Query the required buffer size */
204 BufferSize = 0;
205 Status = IoWMIQueryAllData(DataBlockObject, &BufferSize, NULL);
206 if (!NT_SUCCESS(Status))
207 {
208 DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
209 return;
210 }
211
212 AllData = ExAllocatePoolWithTag(PagedPool, BufferSize, 'BTMS');
213 if (AllData == NULL)
214 {
215 DPRINT1("Failed to allocate %lu bytes for SMBIOS tables\n", BufferSize);
216 return;
217 }
218
219 /* Query the buffer data */
220 Status = IoWMIQueryAllData(DataBlockObject, &BufferSize, AllData);
221 if (!NT_SUCCESS(Status))
222 {
223 DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
224 ExFreePoolWithTag(AllData, 'BTMS');
225 return;
226 }
227
228 /* FIXME: This function should be removed once the mssmbios driver is implemented */
229 /* Store SMBios data in registry */
230 i8042StoreSMBiosTables(AllData + 1,
231 AllData->FixedInstanceSize);
232 DPRINT1("SMBiosTables HACK, see CORE-14867\n");
233
234 /* Parse the table */
235 i8042ParseSMBiosTables(AllData + 1,
236 AllData->WnodeHeader.BufferSize);
237
238 /* Free the buffer */
239 ExFreePoolWithTag(AllData, 'BTMS');
240}
#define DPRINT1
Definition: precomp.h:8
#define BufferSize
Definition: mmc.h:75
const GUID MSSmBios_RawSMBiosTables_GUID
Definition: hwhacks.c:20
static VOID i8042StoreSMBiosTables(_In_reads_bytes_(TableSize) PVOID SMBiosTables, _In_ ULONG TableSize)
Definition: hwhacks.c:121
static VOID i8042ParseSMBiosTables(_In_reads_bytes_(TableSize) PVOID SMBiosTables, _In_ ULONG TableSize)
Definition: hwhacks.c:64
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
NTSTATUS NTAPI IoWMIOpenBlock(_In_ LPCGUID DataBlockGuid, _In_ ULONG DesiredAccess, _Out_ PVOID *DataBlockObject)
Definition: wmi.c:140
NTSTATUS NTAPI IoWMIQueryAllData(IN PVOID DataBlockObject, IN OUT ULONG *InOutBufferSize, OUT PVOID OutBuffer)
Definition: wmi.c:169
struct _WNODE_HEADER WnodeHeader
Definition: wmistr.h:112
ULONG FixedInstanceSize
Definition: wmistr.h:118
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
#define WMIGUID_QUERY
Definition: wmistr.h:159

Referenced by DriverEntry().

◆ 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}
BOOLEAN i8042Write(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PUCHAR addr, IN UCHAR data)
Definition: readwrite.c:199

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

◆ i8042MouHandle()

VOID i8042MouHandle ( IN PI8042_MOUSE_EXTENSION  DeviceExtension,
IN UCHAR  Output 
)

Definition at line 68 of file mouse.c.

71{
72 PMOUSE_INPUT_DATA MouseInput;
73 CHAR Scroll;
74
75 MouseInput = DeviceExtension->MouseBuffer + DeviceExtension->MouseInBuffer;
76
77 switch (DeviceExtension->MouseState)
78 {
79 case MouseIdle:
80 /* This bit should be 1, if not drop the packet, we
81 * might be lucky and get in sync again
82 */
83 if (!(Output & 8)) {
84 WARN_(I8042PRT, "Bad input, dropping..\n");
85 return;
86 }
87
88 MouseInput->Buttons = 0;
89 MouseInput->RawButtons = 0;
90 MouseInput->Flags = MOUSE_MOVE_RELATIVE;
91
92 /* Note how we ignore the overflow bits, like Windows
93 * is said to do. There's no reasonable thing to do
94 * anyway.
95 */
96
97 if (Output & 16)
98 MouseInput->LastX = 1;
99 else
100 MouseInput->LastX = 0;
101 if (Output & 32)
102 MouseInput->LastY = 1;
103 else
104 MouseInput->LastY = 0;
105
106 if (Output & 1)
107 MouseInput->RawButtons |= MOUSE_LEFT_BUTTON_DOWN;
108 if (Output & 2)
109 MouseInput->RawButtons |= MOUSE_RIGHT_BUTTON_DOWN;
110 if (Output & 4)
112
113 DeviceExtension->MouseState = XMovement;
114 break;
115
116 case XMovement:
117 if (MouseInput->LastX)
118 MouseInput->LastX = (LONG) Output - 256;
119 else
120 MouseInput->LastX = Output;
121
122 DeviceExtension->MouseState = YMovement;
123 break;
124
125 case YMovement:
126 if (MouseInput->LastY)
127 MouseInput->LastY = (LONG)Output - 256;
128 else
129 MouseInput->LastY = (LONG)Output;
130
131 /* Windows wants it the other way around */
132 MouseInput->LastY = -MouseInput->LastY;
133
134 if (DeviceExtension->MouseType == GenericPS2 ||
135 DeviceExtension->MouseType == Ps2pp)
136 {
138 DeviceExtension,
142 DeviceExtension->MouseHook.QueueMousePacket(DeviceExtension->MouseHook.CallContext);
143 DeviceExtension->MouseState = MouseIdle;
144 }
145 else
146 {
147 DeviceExtension->MouseState = ZMovement;
148 }
149 break;
150
151 case ZMovement:
152 Scroll = Output & 0x0f;
153 if (Scroll & 8)
154 Scroll |= 0xf0;
155
156 if (Scroll)
157 {
158 MouseInput->RawButtons |= MOUSE_WHEEL;
159 MouseInput->ButtonData = (USHORT)(Scroll * -WHEEL_DELTA);
160 }
161
162 if (DeviceExtension->MouseType == IntellimouseExplorer)
163 {
164 if (Output & 16)
165 MouseInput->RawButtons |= MOUSE_BUTTON_4_DOWN;
166 if (Output & 32)
167 MouseInput->RawButtons |= MOUSE_BUTTON_5_DOWN;
168 }
170 DeviceExtension,
176 DeviceExtension->MouseHook.QueueMousePacket(DeviceExtension->MouseHook.CallContext);
177 DeviceExtension->MouseState = MouseIdle;
178 break;
179
180 default:
181 ERR_(I8042PRT, "Unexpected state 0x%lx!\n", DeviceExtension->MouseState);
182 ASSERT(FALSE);
183 }
184}
VOID i8042MouHandleButtons(IN PI8042_MOUSE_EXTENSION DeviceExtension, IN USHORT Mask)
Definition: mouse.c:191
#define ASSERT(a)
Definition: mode.c:44
@ XMovement
Definition: ntdd8042.h:81
@ YMovement
Definition: ntdd8042.h:82
@ ZMovement
Definition: ntdd8042.h:83
@ MouseIdle
Definition: ntdd8042.h:80
#define MOUSE_LEFT_BUTTON_DOWN
Definition: ntddmou.h:46
#define MOUSE_MIDDLE_BUTTON_DOWN
Definition: ntddmou.h:50
#define MOUSE_BUTTON_4_DOWN
Definition: ntddmou.h:52
#define MOUSE_WHEEL
Definition: ntddmou.h:56
#define MOUSE_BUTTON_5_DOWN
Definition: ntddmou.h:54
#define MOUSE_MOVE_RELATIVE
Definition: ntddmou.h:67
#define MOUSE_RIGHT_BUTTON_DOWN
Definition: ntddmou.h:48
@ Output
Definition: arc.h:85
#define ERR_(ch,...)
Definition: debug.h:156
ULONG RawButtons
Definition: ntddmou.h:86
USHORT ButtonData
Definition: ntddmou.h:83
USHORT Flags
Definition: ntddmou.h:78
#define WHEEL_DELTA
Definition: treelist.c:99
char CHAR
Definition: xmlstorage.h:175

Referenced by i8042MouHandlePs2pp(), and i8042MouInterruptService().

◆ i8042MouHandleButtons()

VOID i8042MouHandleButtons ( IN PI8042_MOUSE_EXTENSION  DeviceExtension,
IN USHORT  Mask 
)

Definition at line 191 of file mouse.c.

194{
195 PMOUSE_INPUT_DATA MouseInput;
196 USHORT NewButtonData;
197 USHORT ButtonDiff;
198
199 MouseInput = DeviceExtension->MouseBuffer + DeviceExtension->MouseInBuffer;
200 NewButtonData = (USHORT)(MouseInput->RawButtons & Mask);
201 ButtonDiff = (NewButtonData ^ DeviceExtension->MouseButtonState) & Mask;
202
203 /* Note that the defines are such:
204 * MOUSE_LEFT_BUTTON_DOWN 1
205 * MOUSE_LEFT_BUTTON_UP 2
206 */
207 MouseInput->ButtonFlags |= (NewButtonData & ButtonDiff) |
208 (((~(NewButtonData)) << 1) & (ButtonDiff << 1)) |
209 (MouseInput->RawButtons & 0xfc00);
210
211 INFO_(I8042PRT, "Left raw/up/down: %u/%u/%u\n",
214 MouseInput->ButtonFlags & MOUSE_LEFT_BUTTON_UP);
215
216 DeviceExtension->MouseButtonState =
217 (DeviceExtension->MouseButtonState & ~Mask) | (NewButtonData & Mask);
218}
unsigned int Mask
Definition: fpcontrol.c:82
#define MOUSE_LEFT_BUTTON_UP
Definition: ntddmou.h:47
#define INFO_(ch,...)
Definition: debug.h:159
USHORT ButtonFlags
Definition: ntddmou.h:82

Referenced by i8042MouHandle(), and i8042MouHandlePs2pp().

◆ i8042MouHandlePs2pp()

VOID i8042MouHandlePs2pp ( IN PI8042_MOUSE_EXTENSION  DeviceExtension,
IN UCHAR  Input 
)

Definition at line 19 of file ps2pp.c.

22{
23 UCHAR PktType;
24 PMOUSE_INPUT_DATA MouseInput;
25
26 MouseInput = DeviceExtension->MouseBuffer + DeviceExtension->MouseInBuffer;
27
28 /* First, collect 3 bytes for a packet
29 * We can detect out-of-sync only by checking
30 * the whole packet anyway.
31 *
32 * If bit 7 and 8 of the first byte are 0, its
33 * a normal packet.
34 *
35 * Otherwise, the packet is different, like this:
36 * 1: E 1 b3 b2 1 x x x
37 * 2: x x b1 b0 x1 x0 1 0
38 * 3: x x x x x x x1 x0
39 *
40 * b3-0 form a code that specifies the packet type:
41 *
42 * 0 Device Type
43 * 1 Rollers and buttons
44 * 2 Reserved
45 * 3 Reserved
46 * 4 Device ID
47 * 5 Channel & Battery
48 * 6 Wireless notifications
49 * 7 Reserved
50 * 8 ShortID LSB (ShortID is a number that is supposed to differentiate
51 * 9 ShortID MSB between your mouse and your neighbours')
52 * 10 Reserved
53 * 11 Mouse capabilities
54 * 12 Remote control LSB
55 * 13 Remote control MSB
56 * 14 Reserved
57 * 15 Extended packet
58 */
59
60 switch (DeviceExtension->MouseState)
61 {
62 case MouseIdle:
63 case XMovement:
64 DeviceExtension->MouseLogiBuffer[DeviceExtension->MouseState] = Input;
65 DeviceExtension->MouseState++;
66 break;
67
68 case YMovement:
69 DeviceExtension->MouseLogiBuffer[2] = Input;
70 DeviceExtension->MouseState = MouseIdle;
71
72 /* first check if it's a normal packet */
73
74 if (!(DeviceExtension->MouseLogiBuffer[0] & 0xC0))
75 {
76 DeviceExtension->MouseState = MouseIdle;
77 i8042MouHandle(DeviceExtension, DeviceExtension->MouseLogiBuffer[0]);
78 i8042MouHandle(DeviceExtension, DeviceExtension->MouseLogiBuffer[1]);
79 i8042MouHandle(DeviceExtension, DeviceExtension->MouseLogiBuffer[2]);
80 /* We could care about wether MouseState really
81 * advances, but we don't need to because we're
82 * only doing three bytes anyway, so the packet
83 * will never complete if it's broken.
84 */
85 return;
86 }
87
88 /* sanity check */
89 if (((DeviceExtension->MouseLogiBuffer[0] & 0x48) != 0x48) ||
90 (((DeviceExtension->MouseLogiBuffer[1] & 0x0C) >> 2) !=
91 (DeviceExtension->MouseLogiBuffer[2] & 0x03)))
92 {
93 WARN_(I8042PRT, "Ps2pp packet fails sanity checks\n");
94 return;
95 }
96
97 /* Now get the packet type */
98 PktType = ((DeviceExtension->MouseLogiBuffer[0] & 0x30) >> 2) |
99 ((DeviceExtension->MouseLogiBuffer[1] & 0x30) >> 4);
100
101 switch (PktType)
102 {
103 case 0:
104 /* The packet contains the device ID, but we
105 * already read that in the initialization
106 * sequence. Ignore it.
107 */
108 return;
109 case 1:
110 RtlZeroMemory(MouseInput, sizeof(MOUSE_INPUT_DATA));
111 if (DeviceExtension->MouseLogiBuffer[2] & 0x10)
112 MouseInput->RawButtons |= MOUSE_BUTTON_4_DOWN;
113
114 if (DeviceExtension->MouseLogiBuffer[2] & 0x20)
115 MouseInput->RawButtons |= MOUSE_BUTTON_5_DOWN;
116
117 if (DeviceExtension->MouseLogiBuffer[2] & 0x0F)
118 {
119 MouseInput->ButtonFlags |= MOUSE_WHEEL;
120 if (DeviceExtension->MouseLogiBuffer[2] & 0x08)
121 MouseInput->ButtonData = (DeviceExtension->MouseLogiBuffer[2] & 0x07) - 8;
122 else
123 MouseInput->ButtonData = DeviceExtension->MouseLogiBuffer[2] & 0x07;
124 }
126 DeviceExtension,
128 DeviceExtension->MouseHook.QueueMousePacket(DeviceExtension->MouseHook.CallContext);
129 return;
130 default:
131 /* These are for things that would probably
132 * be handled by logitechs own driver.
133 */
134 return;
135 }
136
137 default:
138 WARN_(I8042PRT, "Unexpected input state for ps2pp!\n");
139 }
140}
VOID i8042MouHandle(IN PI8042_MOUSE_EXTENSION DeviceExtension, IN UCHAR Output)
Definition: mouse.c:68
VOID i8042MouHandleButtons(IN PI8042_MOUSE_EXTENSION DeviceExtension, IN USHORT Mask)
Definition: mouse.c:191
@ Input
Definition: arc.h:84
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by i8042MouInterruptService().

◆ i8042MouInitialize()

NTSTATUS i8042MouInitialize ( IN PI8042_MOUSE_EXTENSION  DeviceExtension)

Definition at line 224 of file mouse.c.

226{
228 UCHAR Value;
229
230 /* Enable the PS/2 mouse port */
231 i8042Write(DeviceExtension->Common.PortDeviceExtension, DeviceExtension->Common.PortDeviceExtension->ControlPort, MOUSE_ENAB);
232
233 /* Enable the mouse */
234 if(!i8042IsrWritePort(DeviceExtension->Common.PortDeviceExtension, MOU_ENAB, CTRL_WRITE_MOUSE))
235 {
236 WARN_(I8042PRT, "Failed to enable mouse!\n");
238 }
239
240 Status = i8042ReadDataWait(DeviceExtension->Common.PortDeviceExtension, &Value);
241 if (!NT_SUCCESS(Status))
242 {
243 WARN_(I8042PRT, "Failed to read the response of MOU_ENAB, status 0x%08lx\n", Status);
244 return Status;
245 }
246
247 if(Value == MOUSE_ACK)
248 {
249 INFO_(I8042PRT, "Mouse was enabled successfully!\n");
250 return STATUS_SUCCESS;
251 }
252
253 WARN_(I8042PRT, "Got 0x%02x instead of 0xFA\n", Value);
255}
#define MOUSE_ACK
Definition: i8042prt.h:285
#define MOU_ENAB
Definition: i8042prt.h:278
#define CTRL_WRITE_MOUSE
Definition: i8042prt.h:228
BOOLEAN i8042IsrWritePort(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Value, IN UCHAR SelectCmd OPTIONAL)
Definition: readwrite.c:40
#define MOUSE_ENAB
Definition: i8042prt.h:223
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179

Referenced by i8042ConnectMouseInterrupt().

◆ i8042PacketIsr()

BOOLEAN i8042PacketIsr ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN UCHAR  Output 
)

Definition at line 271 of file i8042prt.c.

274{
275 if (DeviceExtension->Packet.State == Idle)
276 return FALSE;
277
278 switch (Output)
279 {
280 case KBD_RESEND:
281 DeviceExtension->PacketResends++;
282 if (DeviceExtension->PacketResends > DeviceExtension->Settings.ResendIterations)
283 {
284 DeviceExtension->Packet.State = Idle;
285 DeviceExtension->PacketComplete = TRUE;
286 DeviceExtension->PacketResult = STATUS_IO_TIMEOUT;
287 DeviceExtension->PacketResends = 0;
288 return TRUE;
289 }
290 DeviceExtension->Packet.CurrentByte--;
291 break;
292
293 case KBD_NACK:
294 DeviceExtension->Packet.State = Idle;
295 DeviceExtension->PacketComplete = TRUE;
296 DeviceExtension->PacketResult = STATUS_UNEXPECTED_IO_ERROR;
297 DeviceExtension->PacketResends = 0;
298 return TRUE;
299
300 default:
301 DeviceExtension->PacketResends = 0;
302 }
303
304 if (DeviceExtension->Packet.CurrentByte >= DeviceExtension->Packet.ByteCount)
305 {
306 DeviceExtension->Packet.State = Idle;
307 DeviceExtension->PacketComplete = TRUE;
308 DeviceExtension->PacketResult = STATUS_SUCCESS;
309 return TRUE;
310 }
311
312 if (!i8042PacketWrite(DeviceExtension))
313 {
314 DeviceExtension->Packet.State = Idle;
315 DeviceExtension->PacketComplete = TRUE;
316 DeviceExtension->PacketResult = STATUS_IO_TIMEOUT;
317 return TRUE;
318 }
319 DeviceExtension->Packet.CurrentByte++;
320
321 return TRUE;
322}
static BOOLEAN i8042PacketWrite(IN PPORT_DEVICE_EXTENSION DeviceExtension)
Definition: i8042prt.c:248
#define KBD_NACK
Definition: i8042prt.h:243
#define KBD_RESEND
Definition: i8042prt.h:244
@ Idle
Definition: ntdd8042.h:62
#define STATUS_UNEXPECTED_IO_ERROR
Definition: ntstatus.h:469
#define STATUS_IO_TIMEOUT
Definition: udferr_usr.h:163

Referenced by i8042KbdInterruptService(), and i8042MouInterruptService().

◆ 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}
NTSTATUS i8042ReadStatus(IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Status)
Definition: readwrite.c:82
_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 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

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}

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

◆ i8042StartPacket()

NTSTATUS i8042StartPacket ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN PFDO_DEVICE_EXTENSION  FdoDeviceExtension,
IN PUCHAR  Bytes,
IN ULONG  ByteCount,
IN PIRP  Irp 
)

Definition at line 329 of file i8042prt.c.

335{
336 KIRQL Irql;
338
339 Irql = KeAcquireInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt);
340
341 if (DeviceExtension->Packet.State != Idle)
342 {
344 goto done;
345 }
346
347 switch (FdoDeviceExtension->Type)
348 {
349 case Keyboard: DeviceExtension->PacketPort = 0; break;
350 case Mouse: DeviceExtension->PacketPort = CTRL_WRITE_MOUSE; break;
351 default:
352 ERR_(I8042PRT, "Unknown FDO type %u\n", FdoDeviceExtension->Type);
353 ASSERT(FALSE);
355 goto done;
356 }
357
358 DeviceExtension->Packet.Bytes = Bytes;
359 DeviceExtension->Packet.CurrentByte = 0;
360 DeviceExtension->Packet.ByteCount = ByteCount;
361 DeviceExtension->Packet.State = SendingBytes;
362 DeviceExtension->PacketResult = Status = STATUS_PENDING;
363 DeviceExtension->CurrentIrp = Irp;
364 DeviceExtension->CurrentIrpDevice = FdoDeviceExtension->Fdo;
365
366 if (!i8042PacketWrite(DeviceExtension))
367 {
369 DeviceExtension->Packet.State = Idle;
370 DeviceExtension->PacketResult = STATUS_ABANDONED;
371 goto done;
372 }
373
374 DeviceExtension->Packet.CurrentByte++;
375
376done:
377 KeReleaseInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt, Irql);
378
379 if (Status != STATUS_PENDING)
380 {
381 DeviceExtension->CurrentIrp = NULL;
382 DeviceExtension->CurrentIrpDevice = NULL;
383 Irp->IoStatus.Status = Status;
385 }
386 return Status;
387}
_Out_ PKIRQL Irql
Definition: csq.h:179
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ UINT Bytes
Definition: mmcopy.h:9
@ SendingBytes
Definition: ntdd8042.h:63
KIRQL NTAPI KeAcquireInterruptSpinLock(IN PKINTERRUPT Interrupt)
Definition: spinlock.c:154
VOID NTAPI KeReleaseInterruptSpinLock(IN PKINTERRUPT Interrupt, IN KIRQL OldIrql)
Definition: spinlock.c:171
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:465
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_ABANDONED
Definition: ntstatus.h:75
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1099

Referenced by i8042KbdStartIo().

◆ 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_ACK
Definition: i8042prt.h:242

Referenced by i8042DetectKeyboard(), and i8042SynchWritePortKbd().

◆ i8042SynchWritePortKbd()

NTSTATUS NTAPI i8042SynchWritePortKbd ( IN PVOID  Context,
IN UCHAR  Value,
IN BOOLEAN  WaitForAck 
)

Definition at line 87 of file keyboard.c.

91{
94 0,
95 Value,
96 WaitForAck);
97}
NTSTATUS NTAPI i8042SynchWritePort(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Port, IN UCHAR Value, IN BOOLEAN WaitForAck)
Definition: readwrite.c:144

Referenced by i8042SendHookWorkItem().

◆ 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}
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().

◆ ReadRegistryEntries()

NTSTATUS ReadRegistryEntries ( IN PUNICODE_STRING  RegistryPath,
OUT PI8042_SETTINGS  Settings 
)

Definition at line 21 of file registry.c.

24{
27
28 ULONG DefaultKeyboardDataQueueSize = 0x64;
29 PCWSTR DefaultKeyboardDeviceBaseName = L"KeyboardPort";
30 ULONG DefaultMouseDataQueueSize = 0x64;
31 ULONG DefaultMouseResolution = 3;
32 ULONG DefaultMouseSynchIn100ns = 20000000;
33 ULONG DefaultNumberOfButtons = 2;
34 PCWSTR DefaultPointerDeviceBaseName = L"PointerPort";
35 ULONG DefaultPollStatusIterations = 1;
36 ULONG DefaultOverrideKeyboardType = 4;
37 ULONG DefaultOverrideKeyboardSubtype = 0;
38 ULONG DefaultPollingIterations = 12000;
39 ULONG DefaultPollingIterationsMaximum = 12000;
40 ULONG DefaultResendIterations = 0x3;
41 ULONG DefaultSampleRate = 60;
42 ULONG DefaultCrashOnCtrlScroll;
43
44 /* Default value for CrashOnCtrlScroll depends if we're
45 * running a debug build or a normal build.
46 */
47#if DBG
48 DefaultCrashOnCtrlScroll = 1;
49#else
50 DefaultCrashOnCtrlScroll = 0;
51#endif
52
54
56 Parameters[0].Name = L"Parameters";
57
59 Parameters[1].Name = L"KeyboardDataQueueSize";
60 Parameters[1].EntryContext = &Settings->KeyboardDataQueueSize;
61 Parameters[1].DefaultType = REG_DWORD;
62 Parameters[1].DefaultData = &DefaultKeyboardDataQueueSize;
63 Parameters[1].DefaultLength = sizeof(ULONG);
64
66 Parameters[2].Name = L"KeyboardDeviceBaseName";
67 Parameters[2].EntryContext = &Settings->KeyboardDeviceBaseName;
68 Parameters[2].DefaultType = REG_SZ;
69 Parameters[2].DefaultData = (PVOID)DefaultKeyboardDeviceBaseName;
70 Parameters[2].DefaultLength = 0;
71
73 Parameters[3].Name = L"MouseDataQueueSize";
74 Parameters[3].EntryContext = &Settings->MouseDataQueueSize;
75 Parameters[3].DefaultType = REG_DWORD;
76 Parameters[3].DefaultData = &DefaultMouseDataQueueSize;
77 Parameters[3].DefaultLength = sizeof(ULONG);
78
80 Parameters[4].Name = L"MouseResolution";
81 Parameters[4].EntryContext = &Settings->MouseResolution;
82 Parameters[4].DefaultType = REG_DWORD;
83 Parameters[4].DefaultData = &DefaultMouseResolution;
84 Parameters[4].DefaultLength = sizeof(ULONG);
85
87 Parameters[5].Name = L"MouseSynchIn100ns";
88 Parameters[5].EntryContext = &Settings->MouseSynchIn100ns;
89 Parameters[5].DefaultType = REG_DWORD;
90 Parameters[5].DefaultData = &DefaultMouseSynchIn100ns;
91 Parameters[5].DefaultLength = sizeof(ULONG);
92
94 Parameters[6].Name = L"NumberOfButtons";
95 Parameters[6].EntryContext = &Settings->NumberOfButtons;
96 Parameters[6].DefaultType = REG_DWORD;
97 Parameters[6].DefaultData = &DefaultNumberOfButtons;
98 Parameters[6].DefaultLength = sizeof(ULONG);
99
101 Parameters[7].Name = L"PointerDeviceBaseName";
102 Parameters[7].EntryContext = &Settings->PointerDeviceBaseName;
103 Parameters[7].DefaultType = REG_SZ;
104 Parameters[7].DefaultData = (PVOID)DefaultPointerDeviceBaseName;
105 Parameters[7].DefaultLength = 0;
106
108 Parameters[8].Name = L"PollStatusIterations";
109 Parameters[8].EntryContext = &Settings->PollStatusIterations;
110 Parameters[8].DefaultType = REG_DWORD;
111 Parameters[8].DefaultData = &DefaultPollStatusIterations;
112 Parameters[8].DefaultLength = sizeof(ULONG);
113
115 Parameters[9].Name = L"OverrideKeyboardType";
116 Parameters[9].EntryContext = &Settings->OverrideKeyboardType;
117 Parameters[9].DefaultType = REG_DWORD;
118 Parameters[9].DefaultData = &DefaultOverrideKeyboardType;
119 Parameters[9].DefaultLength = sizeof(ULONG);
120
122 Parameters[10].Name = L"OverrideKeyboardSubtype";
123 Parameters[10].EntryContext = &Settings->OverrideKeyboardSubtype;
124 Parameters[10].DefaultType = REG_DWORD;
125 Parameters[10].DefaultData = &DefaultOverrideKeyboardSubtype;
126 Parameters[10].DefaultLength = sizeof(ULONG);
127
129 Parameters[11].Name = L"PollingIterations";
130 Parameters[11].EntryContext = &Settings->PollingIterations;
131 Parameters[11].DefaultType = REG_DWORD;
132 Parameters[11].DefaultData = &DefaultPollingIterations;
133 Parameters[11].DefaultLength = sizeof(ULONG);
134
136 Parameters[12].Name = L"PollingIterationsMaximum";
137 Parameters[12].EntryContext = &Settings->PollingIterationsMaximum;
138 Parameters[12].DefaultType = REG_DWORD;
139 Parameters[12].DefaultData = &DefaultPollingIterationsMaximum;
140 Parameters[12].DefaultLength = sizeof(ULONG);
141
143 Parameters[13].Name = L"ResendIterations";
144 Parameters[13].EntryContext = &Settings->ResendIterations;
145 Parameters[13].DefaultType = REG_DWORD;
146 Parameters[13].DefaultData = &DefaultResendIterations;
147 Parameters[13].DefaultLength = sizeof(ULONG);
148
150 Parameters[14].Name = L"SampleRate";
151 Parameters[14].EntryContext = &Settings->SampleRate;
152 Parameters[14].DefaultType = REG_DWORD;
153 Parameters[14].DefaultData = &DefaultSampleRate;
154 Parameters[14].DefaultLength = sizeof(ULONG);
155
157 Parameters[15].Name = L"CrashOnCtrlScroll";
158 Parameters[15].EntryContext = &Settings->CrashOnCtrlScroll;
159 Parameters[15].DefaultType = REG_DWORD;
160 Parameters[15].DefaultData = &DefaultCrashOnCtrlScroll;
161 Parameters[15].DefaultLength = sizeof(ULONG);
162
165 RegistryPath->Buffer,
167 NULL,
168 NULL);
169
170 if (NT_SUCCESS(Status))
171 {
172 /* Check values */
173 if (Settings->KeyboardDataQueueSize < 1)
174 Settings->KeyboardDataQueueSize = DefaultKeyboardDataQueueSize;
175 if (Settings->MouseDataQueueSize < 1)
176 Settings->MouseDataQueueSize = DefaultMouseDataQueueSize;
177 if (Settings->NumberOfButtons < 1)
178 Settings->NumberOfButtons = DefaultNumberOfButtons;
179 if (Settings->PollingIterations < 0x400)
180 Settings->PollingIterations = DefaultPollingIterations;
181 if (Settings->PollingIterationsMaximum < 0x400)
182 Settings->PollingIterationsMaximum = DefaultPollingIterationsMaximum;
183 if (Settings->ResendIterations < 1)
184 Settings->ResendIterations = DefaultResendIterations;
185 }
187 {
188 /* Registry path doesn't exist. Set defaults */
189 Settings->KeyboardDataQueueSize = DefaultKeyboardDataQueueSize;
190 Settings->MouseDataQueueSize = DefaultMouseDataQueueSize;
191 Settings->MouseResolution = DefaultMouseResolution;
192 Settings->MouseSynchIn100ns = DefaultMouseSynchIn100ns;
193 Settings->NumberOfButtons = DefaultNumberOfButtons;
194 Settings->PollStatusIterations = DefaultPollStatusIterations;
195 Settings->OverrideKeyboardType = DefaultOverrideKeyboardType;
196 Settings->OverrideKeyboardSubtype = DefaultOverrideKeyboardSubtype;
197 Settings->PollingIterations = DefaultPollingIterations;
198 Settings->PollingIterationsMaximum = DefaultPollingIterationsMaximum;
199 Settings->ResendIterations = DefaultResendIterations;
200 Settings->SampleRate = DefaultSampleRate;
201 Settings->CrashOnCtrlScroll = DefaultCrashOnCtrlScroll;
202 if (!RtlCreateUnicodeString(&Settings->KeyboardDeviceBaseName, DefaultKeyboardDeviceBaseName)
203 || !RtlCreateUnicodeString(&Settings->PointerDeviceBaseName, DefaultPointerDeviceBaseName))
204 {
205 WARN_(I8042PRT, "RtlCreateUnicodeString() failed\n");
207 }
208 else
209 {
211 }
212 }
213
214 if (NT_SUCCESS(Status))
215 {
216 INFO_(I8042PRT, "KeyboardDataQueueSize : 0x%lx\n", Settings->KeyboardDataQueueSize);
217 INFO_(I8042PRT, "KeyboardDeviceBaseName : %wZ\n", &Settings->KeyboardDeviceBaseName);
218 INFO_(I8042PRT, "MouseDataQueueSize : 0x%lx\n", Settings->MouseDataQueueSize);
219 INFO_(I8042PRT, "MouseResolution : 0x%lx\n", Settings->MouseResolution);
220 INFO_(I8042PRT, "MouseSynchIn100ns : %lu\n", Settings->MouseSynchIn100ns);
221 INFO_(I8042PRT, "NumberOfButtons : 0x%lx\n", Settings->NumberOfButtons);
222 INFO_(I8042PRT, "PointerDeviceBaseName : %wZ\n", &Settings->PointerDeviceBaseName);
223 INFO_(I8042PRT, "PollStatusIterations : 0x%lx\n", Settings->PollStatusIterations);
224 INFO_(I8042PRT, "OverrideKeyboardType : 0x%lx\n", Settings->OverrideKeyboardType);
225 INFO_(I8042PRT, "OverrideKeyboardSubtype : 0x%lx\n", Settings->OverrideKeyboardSubtype);
226 INFO_(I8042PRT, "PollingIterations : 0x%lx\n", Settings->PollingIterations);
227 INFO_(I8042PRT, "PollingIterationsMaximum : %lu\n", Settings->PollingIterationsMaximum);
228 INFO_(I8042PRT, "ResendIterations : 0x%lx\n", Settings->ResendIterations);
229 INFO_(I8042PRT, "SampleRate : %lu\n", Settings->SampleRate);
230 }
231
232 return Status;
233}
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
#define REG_SZ
Definition: layer.c:22
#define RTL_QUERY_REGISTRY_SUBKEY
Definition: nt_native.h:125
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
#define RTL_REGISTRY_OPTIONAL
Definition: nt_native.h:169
#define L(x)
Definition: ntvdm.h:50
#define REG_DWORD
Definition: sdbapi.c:596
const uint16_t * PCWSTR
Definition: typedefs.h:57
void * PVOID
Definition: typedefs.h:50
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_POWER_POLICY_IDLE_SETTINGS Settings
Definition: wdfdevice.h:2595
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869

Referenced by DriverEntry().

Variable Documentation

◆ ForwardIrpAndForget

◆ i8042AddDevice

DRIVER_ADD_DEVICE i8042AddDevice

Definition at line 324 of file i8042prt.h.

Referenced by DriverEntry().

◆ i8042HwFlags

ULONG i8042HwFlags
extern

Definition at line 22 of file hwhacks.c.

Referenced by i8042ParseSMBiosTables(), and StartProcedure().

◆ i8042KbdDeviceControl

DRIVER_DISPATCH i8042KbdDeviceControl

Definition at line 316 of file i8042prt.h.

Referenced by i8042DeviceControl().

◆ i8042KbdInternalDeviceControl

DRIVER_DISPATCH i8042KbdInternalDeviceControl

Definition at line 318 of file i8042prt.h.

Referenced by i8042InternalDeviceControl().

◆ i8042KbdInterruptService

KSERVICE_ROUTINE i8042KbdInterruptService

Definition at line 320 of file i8042prt.h.

Referenced by i8042ConnectKeyboardInterrupt().

◆ i8042KbdStartIo

DRIVER_STARTIO i8042KbdStartIo

Definition at line 314 of file i8042prt.h.

Referenced by i8042StartIo().

◆ i8042MouInternalDeviceControl

DRIVER_DISPATCH i8042MouInternalDeviceControl

Definition at line 365 of file i8042prt.h.

Referenced by i8042InternalDeviceControl().

◆ i8042MouInterruptService

KSERVICE_ROUTINE i8042MouInterruptService

Definition at line 367 of file i8042prt.h.

Referenced by i8042ConnectMouseInterrupt().

◆ i8042SendHookWorkItem

IO_WORKITEM_ROUTINE i8042SendHookWorkItem

Definition at line 295 of file i8042prt.h.

Referenced by i8042KbdInternalDeviceControl(), and i8042MouInternalDeviceControl().