replace nob with ms' build, move disk creation to build.bat, major comment cleanup, remove old and stupid tests, overhaul interrupt management with per-CPU vector allocation, affinity migration and safe teardown, add proper IOAPIC routing and PCI MSI/MSI-X/INTx support, migrate drivers to the new interrupt API, integrate ACPICA with a proper OS services layer, move ACPI firmware events, power button handling and S5 shutdown into acpi.sys, add parallel driver startup and atomic publication, replace PnP arrays with dynamic lists, redesign service startup again to be asynchronous, add delayed startup mode for services, allow omitting keys in services.ini, fix acpi ec deferred work handling, fix kernel threads having garbage exit code.
This commit is contained in:
1 parent
d36f19509c
commit
36eef8f58d
696 files changed
+147281
-7530
No files matched your search
@@ -0,0 +1 @@
|
||||
!include $(BASEDIR)\makefile.def
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "ps2.h"
|
||||
|
||||
static KDPC gKeyboardDpc;
|
||||
static KE_INTERRUPT* gKeyboardInterrupt;
|
||||
static KE_INTERRUPT* gMouseInterrupt;
|
||||
static KDPC gMouseDpc;
|
||||
static volatile bool gKeyboardNextExtended;
|
||||
static INPUT_KEY_EVENT gKeyboardDpcQueue[KEYBOARD_DPC_QUEUE_SIZE];
|
||||
@@ -24,7 +26,6 @@ static volatile uint32_t gMousePacketCount;
|
||||
static volatile uint32_t gKeyboardForeignIrqCount;
|
||||
static volatile uint32_t gMouseForeignIrqCount;
|
||||
|
||||
// Implements the ps2 Set1 To Key operation.
|
||||
static INPUT_KEY Ps2Set1ToKey(uint8_t make, bool extended) {
|
||||
if (extended) {
|
||||
switch (make) {
|
||||
@@ -135,7 +136,6 @@ static INPUT_KEY Ps2Set1ToKey(uint8_t make, bool extended) {
|
||||
}
|
||||
}
|
||||
|
||||
// Implements the ps2 Keyboard Dpc Routine operation.
|
||||
static void Ps2KeyboardDpcRoutine(KDPC* dpc, void* context, void* systemArgument1, void* systemArgument2) {
|
||||
(void)dpc;
|
||||
(void)context;
|
||||
@@ -147,13 +147,12 @@ static void Ps2KeyboardDpcRoutine(KDPC* dpc, void* context, void* systemArgument
|
||||
gKeyboardDpcHead = (gKeyboardDpcHead + 1) & (int)KEYBOARD_DPC_QUEUE_MASK;
|
||||
KeInputSubmitKey(&event);
|
||||
uint32_t n = ++gKeyboardEventCount;
|
||||
if ((n & (n - 1u)) == 0u)
|
||||
DbgPrint("ps2: keyboard progress irq=%u raw=%u events=%u foreign=%u\n",
|
||||
gKeyboardIrqCount, gKeyboardByteCount, n, gKeyboardForeignIrqCount);
|
||||
// if ((n & (n - 1u)) == 0u)
|
||||
// DbgPrint("ps2: keyboard progress irq=%u raw=%u events=%u foreign=%u\n",
|
||||
// gKeyboardIrqCount, gKeyboardByteCount, n, gKeyboardForeignIrqCount);
|
||||
}
|
||||
}
|
||||
|
||||
// Implements the ps2 Queue Keyboard Event operation.
|
||||
static void Ps2QueueKeyboardEvent(INPUT_KEY key, bool pressed) {
|
||||
if (key >= sizeof(gKeyboardDown))
|
||||
return;
|
||||
@@ -173,8 +172,8 @@ static void Ps2QueueKeyboardEvent(INPUT_KEY key, bool pressed) {
|
||||
KeInsertQueueDpc(&gKeyboardDpc, 0, 0);
|
||||
}
|
||||
|
||||
// Implements the ps2 Keyboard Isr operation.
|
||||
static void Ps2KeyboardIsr(void) {
|
||||
static void Ps2KeyboardIsr(void* context) {
|
||||
(void)context;
|
||||
++gKeyboardIrqCount;
|
||||
uint8_t status = __inbyte(PS2_STAT);
|
||||
// The 8042 output buffer is shared; never consume AUX bytes as scancodes.
|
||||
@@ -200,7 +199,6 @@ static void Ps2KeyboardIsr(void) {
|
||||
Ps2QueueKeyboardEvent(key, !released);
|
||||
}
|
||||
|
||||
// Implements the ps2 Mouse Dpc Routine operation.
|
||||
static void Ps2MouseDpcRoutine(KDPC* dpc, void* context, void* systemArgument1, void* systemArgument2) {
|
||||
(void)dpc;
|
||||
(void)context;
|
||||
@@ -219,14 +217,14 @@ static void Ps2MouseDpcRoutine(KDPC* dpc, void* context, void* systemArgument1,
|
||||
};
|
||||
KeInputSubmitMouse(&event);
|
||||
uint32_t n = ++gMousePacketCount;
|
||||
if ((n & (n - 1u)) == 0u)
|
||||
DbgPrint("ps2: mouse progress irq=%u raw=%u packets=%u foreign=%u\n",
|
||||
gMouseIrqCount, gMouseByteCount, n, gMouseForeignIrqCount);
|
||||
// if ((n & (n - 1u)) == 0u)
|
||||
// DbgPrint("ps2: mouse progress irq=%u raw=%u packets=%u foreign=%u\n",
|
||||
// gMouseIrqCount, gMouseByteCount, n, gMouseForeignIrqCount);
|
||||
}
|
||||
}
|
||||
|
||||
// Implements the ps2 Mouse Isr operation.
|
||||
static void Ps2MouseIsr(void) {
|
||||
static void Ps2MouseIsr(void* context) {
|
||||
(void)context;
|
||||
++gMouseIrqCount;
|
||||
uint8_t status = __inbyte(PS2_STAT);
|
||||
if (!(status & PS2_STAT_OUT_FULL) || !(status & PS2_STAT_AUX_DATA)) {
|
||||
@@ -262,7 +260,6 @@ static void Ps2MouseIsr(void) {
|
||||
}
|
||||
}
|
||||
|
||||
// Implements the ps2 Controller Prepare operation.
|
||||
static void Ps2ControllerPrepare(void) {
|
||||
Ps2WriteCommand(0xADu); // disable keyboard port
|
||||
Ps2WriteCommand(0xA7u); // disable aux port
|
||||
@@ -281,7 +278,6 @@ static void Ps2ControllerPrepare(void) {
|
||||
Ps2FlushOutput();
|
||||
}
|
||||
|
||||
// Implements the ps2 Controller Enable Interrupts operation.
|
||||
static void Ps2ControllerEnableInterrupts(void) {
|
||||
uint8_t commandByte = Ps2ReadCommandByte();
|
||||
commandByte |= 0x01u;
|
||||
@@ -289,7 +285,6 @@ static void Ps2ControllerEnableInterrupts(void) {
|
||||
Ps2WriteCommandByte(commandByte);
|
||||
}
|
||||
|
||||
// Implements the ps2 Keyboard Initialize operation.
|
||||
static void Ps2KeyboardInitialize(void) {
|
||||
// Enable scanning. If the keyboard is absent, the timeout/ACK failure is
|
||||
// non-fatal; the IRQ path simply never produces events.
|
||||
@@ -297,7 +292,6 @@ static void Ps2KeyboardInitialize(void) {
|
||||
DbgPrint("ps2: keyboard enable did not ACK\n");
|
||||
}
|
||||
|
||||
// Implements the ps2 Mouse Initialize operation.
|
||||
static void Ps2MouseInitialize(void) {
|
||||
if (!Ps2SendMouse(0xFFu)) {
|
||||
DbgPrint("ps2: mouse reset did not ACK\n");
|
||||
@@ -318,8 +312,10 @@ static KSTATUS DriverInitialize(NTL_MODULE* module) {
|
||||
|
||||
|
||||
uint32_t keyboardId = 0, mouseId = 0;
|
||||
KeInputRegisterDevice("ps2-keyboard", 0, &keyboardId);
|
||||
KeInputRegisterDevice("ps2-mouse", 0, &mouseId);
|
||||
KSTATUS status = KeInputRegisterDevice("ps2-keyboard", 0, &keyboardId);
|
||||
if (!KSUCCESS(status)) return status;
|
||||
status = KeInputRegisterDevice("ps2-mouse", 0, &mouseId);
|
||||
if (!KSUCCESS(status)) return status;
|
||||
|
||||
KeInitializeDpc(&gKeyboardDpc, Ps2KeyboardDpcRoutine, 0);
|
||||
KeInitializeDpc(&gMouseDpc, Ps2MouseDpcRoutine, 0);
|
||||
@@ -332,12 +328,32 @@ static KSTATUS DriverInitialize(NTL_MODULE* module) {
|
||||
Ps2KeyboardInitialize();
|
||||
Ps2MouseInitialize();
|
||||
|
||||
KeIrqRegister(PS2_IRQ_KEYBOARD, Ps2KeyboardIsr);
|
||||
KeIrqRegister(PS2_IRQ_MOUSE, Ps2MouseIsr);
|
||||
Ps2ControllerEnableInterrupts();
|
||||
KSTATUS irqStatus = KeInterruptConnectIsa(PS2_IRQ_KEYBOARD, 0, 0,
|
||||
Ps2KeyboardIsr, 0, &gKeyboardInterrupt);
|
||||
if (!KSUCCESS(irqStatus)) return irqStatus;
|
||||
irqStatus = KeInterruptConnectIsa(PS2_IRQ_MOUSE, 0, 0,
|
||||
Ps2MouseIsr, 0, &gMouseInterrupt);
|
||||
if (!KSUCCESS(irqStatus)) return irqStatus;
|
||||
|
||||
DbgPrint("ps2: initialized keyboard=%u mouse=%u\n", keyboardId, mouseId);
|
||||
DbgPrint("ps2: prepared keyboard=%u mouse=%u\n", keyboardId, mouseId);
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTL_DECLARE_MODULE(DriverInitialize);
|
||||
static void Ps2CommitStart(NTL_MODULE* module) {
|
||||
(void)module;
|
||||
Ps2ControllerEnableInterrupts();
|
||||
}
|
||||
|
||||
static void Ps2AbortStart(NTL_MODULE* module) {
|
||||
(void)module;
|
||||
if (gMouseInterrupt) {
|
||||
KeInterruptDisconnect(gMouseInterrupt);
|
||||
gMouseInterrupt = (KE_INTERRUPT*)0;
|
||||
}
|
||||
if (gKeyboardInterrupt) {
|
||||
KeInterruptDisconnect(gKeyboardInterrupt);
|
||||
gKeyboardInterrupt = (KE_INTERRUPT*)0;
|
||||
}
|
||||
}
|
||||
|
||||
NTL_DECLARE_STAGED_MODULE(DriverInitialize, Ps2CommitStart, Ps2AbortStart);
|
||||
@@ -2,12 +2,10 @@
|
||||
|
||||
#include "ps2.h"
|
||||
|
||||
// Implements the ps2 Pause operation.
|
||||
void Ps2Pause(void) {
|
||||
_mm_pause();
|
||||
}
|
||||
|
||||
// Implements the ps2 Wait Input operation.
|
||||
void Ps2WaitInput(void) {
|
||||
int timeout = 100000;
|
||||
while ((__inbyte(PS2_STAT) & PS2_STAT_IN_FULL) && --timeout) {
|
||||
@@ -15,7 +13,6 @@ void Ps2WaitInput(void) {
|
||||
}
|
||||
}
|
||||
|
||||
// Implements the ps2 Wait Output operation.
|
||||
bool Ps2WaitOutput(void) {
|
||||
int timeout = 5000000;
|
||||
while (!(__inbyte(PS2_STAT) & PS2_STAT_OUT_FULL) && --timeout) {
|
||||
@@ -24,7 +21,6 @@ bool Ps2WaitOutput(void) {
|
||||
return timeout != 0;
|
||||
}
|
||||
|
||||
// Implements the ps2 Flush Output operation.
|
||||
void Ps2FlushOutput(void) {
|
||||
int timeout = 100000;
|
||||
while ((__inbyte(PS2_STAT) & PS2_STAT_OUT_FULL) && --timeout) {
|
||||
@@ -32,43 +28,36 @@ void Ps2FlushOutput(void) {
|
||||
}
|
||||
}
|
||||
|
||||
// Implements the ps2 Read Data operation.
|
||||
uint8_t Ps2ReadData(void) {
|
||||
if (!Ps2WaitOutput()) return 0xFFu;
|
||||
return __inbyte(PS2_DATA);
|
||||
}
|
||||
|
||||
// Implements the ps2 Write Command operation.
|
||||
void Ps2WriteCommand(uint8_t command) {
|
||||
Ps2WaitInput();
|
||||
__outbyte(PS2_CMD, command);
|
||||
}
|
||||
|
||||
// Implements the ps2 Write Data operation.
|
||||
void Ps2WriteData(uint8_t data) {
|
||||
Ps2WaitInput();
|
||||
__outbyte(PS2_DATA, data);
|
||||
}
|
||||
|
||||
// Implements the ps2 Read Command Byte operation.
|
||||
uint8_t Ps2ReadCommandByte(void) {
|
||||
Ps2WriteCommand(0x20u);
|
||||
return Ps2ReadData();
|
||||
}
|
||||
|
||||
// Implements the ps2 Write Command Byte operation.
|
||||
void Ps2WriteCommandByte(uint8_t commandByte) {
|
||||
Ps2WriteCommand(0x60u);
|
||||
Ps2WriteData(commandByte);
|
||||
}
|
||||
|
||||
// Implements the ps2 Send Keyboard operation.
|
||||
bool Ps2SendKeyboard(uint8_t byte) {
|
||||
Ps2WriteData(byte);
|
||||
return Ps2ReadData() == 0xFAu;
|
||||
}
|
||||
|
||||
// Implements the ps2 Send Mouse operation.
|
||||
bool Ps2SendMouse(uint8_t byte) {
|
||||
Ps2WriteCommand(0xD4u);
|
||||
Ps2WriteData(byte);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
TARGETNAME=ps2
|
||||
TARGETPATH=obj
|
||||
TARGETTYPE=DRIVER
|
||||
FLAVOR=DRIVER
|
||||
TARGETLIBS="$(BASEDIR)\bin\kernel.lib" "$(BASEDIR)\bin\libc.lib"
|
||||
EXTRA_LFLAGS=/NOENTRY
|
||||
SOURCES=@/code/drivers/input/ps2/ps2.c @/code/drivers/input/ps2/ps2_i8042.c
|
||||
Reference in new issue
Block a user