From 4fd4f46f016ea6a46823f6d7ea8b75f93c9a51c1 Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Thu, 4 Nov 2021 22:31:28 +0800 Subject: [PATCH] driver/ps2: remove irq_ from names --- driver/irq/pic/ps2/internal.h | 22 +++++----- driver/irq/pic/ps2/ps2.c | 72 ++++++++++++++++----------------- driver/irq/pic/ps2/ps2.h | 76 +++++++++++++++++------------------ kernel/kmain.c | 2 +- 4 files changed, 86 insertions(+), 86 deletions(-) diff --git a/driver/irq/pic/ps2/internal.h b/driver/irq/pic/ps2/internal.h index c562c20..83c53f5 100644 --- a/driver/irq/pic/ps2/internal.h +++ b/driver/irq/pic/ps2/internal.h @@ -9,52 +9,52 @@ extern "C" { #endif -SYSV_ABI void irq_pic_ps2_IRQHandlerK(); // keyboard IRQ1 -SYSV_ABI void irq_pic_ps2_IRQHandlerM(); // mouse IRQ12 +SYSV_ABI void pic_ps2_IRQHandlerK(); // keyboard IRQ1 +SYSV_ABI void pic_ps2_IRQHandlerM(); // mouse IRQ12 // waits until the Output Buffer Status (bit 0) of the Status Register is set // and port 0x60 is ready for data read static inline void __ps2_PollWait_ReadReady() { - while ((inb(IRQ_PIC_PS2_STATUSPORT) & IRQ_PIC_PS2_STATUS_OUTPUT_BUFFER) == 0) + while ((inb(PIC_PS2_STATUSPORT) & PIC_PS2_STATUS_OUTPUT_BUFFER) == 0) asm("pause"); } // waits until the Input Buffer Status (bit 1) of the Status Register is clear // and ports 0x60/0x64 are ready for data write static inline void __ps2_PollWait_WriteReady() { - while ((inb(IRQ_PIC_PS2_STATUSPORT) & IRQ_PIC_PS2_STATUS_INPUT_BUFFER) != 0) + while ((inb(PIC_PS2_STATUSPORT) & PIC_PS2_STATUS_INPUT_BUFFER) != 0) asm("pause"); } // waits until port 0x60 is ready and reads the byte in it static inline uint8_t __ps2_ReadData() { __ps2_PollWait_ReadReady(); - return inb(IRQ_PIC_PS2_IOPORT); + return inb(PIC_PS2_IOPORT); } // waits until port 0x64 is ready for write, OUTB to it. static inline void __ps2_WriteCommand(uint8_t cmd) { __ps2_PollWait_WriteReady(); - outb(IRQ_PIC_PS2_CMDPORT, cmd); + outb(PIC_PS2_CMDPORT, cmd); } // waits until port 0x64 is ready, OUTB to it, OUTB to 0x60 for data byte. static inline void __ps2_WriteCommandData(uint8_t cmd, uint8_t data) { __ps2_PollWait_WriteReady(); - outb(IRQ_PIC_PS2_CMDPORT, cmd); + outb(PIC_PS2_CMDPORT, cmd); __ps2_PollWait_WriteReady(); - outb(IRQ_PIC_PS2_IOPORT, data); + outb(PIC_PS2_IOPORT, data); } static inline void __ps2_ReadACK() { - while (__ps2_ReadData() != IRQ_PIC_PS2_ACK) {} + while (__ps2_ReadData() != PIC_PS2_ACK) {} } // sets the sample rate of the mouse static inline void __ps2_SetMouseRate(uint8_t rate) { - __ps2_WriteCommandData(IRQ_PIC_PS2_CMD_SEND_MOUSE, 0xf3); // command to the mouse + __ps2_WriteCommandData(PIC_PS2_CMD_SEND_MOUSE, 0xf3); // command to the mouse __ps2_ReadACK(); // read the ACK - __ps2_WriteCommandData(IRQ_PIC_PS2_CMD_SEND_MOUSE, rate); // send the rate + __ps2_WriteCommandData(PIC_PS2_CMD_SEND_MOUSE, rate); // send the rate __ps2_ReadACK(); // read the ACK } diff --git a/driver/irq/pic/ps2/ps2.c b/driver/irq/pic/ps2/ps2.c index 383bff1..533e31e 100644 --- a/driver/irq/pic/ps2/ps2.c +++ b/driver/irq/pic/ps2/ps2.c @@ -10,38 +10,38 @@ #include "../../../../driver/input/source.h" -bool irq_pic_ps2_HasMouse; -bool irq_pic_ps2_Mouse4Bytes; // the mouse has 4-byte data packages instead of 3 +bool pic_ps2_HasMouse; +bool pic_ps2_Mouse4Bytes; // the mouse has 4-byte data packages instead of 3 -queue irq_pic_ps2_QueueKeyboard, irq_pic_ps2_QueueMouse; -uint8_t __irq_pic_ps2_QueueBufferK[IRQ_PIC_PS2_QUEUESIZE_KEYBOARD], __irq_pic_ps2_QueueBufferM[IRQ_PIC_PS2_QUEUESIZE_MOUSE]; +queue pic_ps2_QueueKeyboard, pic_ps2_QueueMouse; +uint8_t __pic_ps2_QueueBufferK[PIC_PS2_QUEUESIZE_KEYBOARD], __pic_ps2_QueueBufferM[PIC_PS2_QUEUESIZE_MOUSE]; -void irq_pic_ps2_Init() { - assert(irq_pic_Enabled && "irq_pic_ps2_Init() requires PIC to be enabled"); +void pic_ps2_Init() { + assert(irq_pic_Enabled && "pic_ps2_Init() requires PIC to be enabled"); // init the Keyboard and Mouse queues - queue_InitBuffered(&irq_pic_ps2_QueueKeyboard, __irq_pic_ps2_QueueBufferK, IRQ_PIC_PS2_QUEUESIZE_KEYBOARD); - queue_InitBuffered(&irq_pic_ps2_QueueMouse, __irq_pic_ps2_QueueBufferM, IRQ_PIC_PS2_QUEUESIZE_MOUSE); + queue_InitBuffered(&pic_ps2_QueueKeyboard, __pic_ps2_QueueBufferK, PIC_PS2_QUEUESIZE_KEYBOARD); + queue_InitBuffered(&pic_ps2_QueueMouse, __pic_ps2_QueueBufferM, PIC_PS2_QUEUESIZE_MOUSE); uint8_t data; INTERRUPT_DISABLE; - irq_pic_IRQHandler[IRQ_PIC_PS2_KEYBOARD] = irq_pic_ps2_IRQHandlerK; - irq_pic_Mask(IRQ_PIC_PS2_KEYBOARD, false); + irq_pic_IRQHandler[PIC_PS2_KEYBOARD] = pic_ps2_IRQHandlerK; + irq_pic_Mask(PIC_PS2_KEYBOARD, false); // enable second PS/2 port io_WriteConsoleASCII("ENABLE_MOUSE... "); - __ps2_WriteCommand(IRQ_PIC_PS2_CMD_ENABLE_MOUSE); + __ps2_WriteCommand(PIC_PS2_CMD_ENABLE_MOUSE); io_WriteConsoleASCII("CONTROLLER_READ_CONFIGBYTE... "); - __ps2_WriteCommand(IRQ_PIC_PS2_CMD_READ_CONFIGBYTE); + __ps2_WriteCommand(PIC_PS2_CMD_READ_CONFIGBYTE); uint8_t config = __ps2_ReadData(); // write controller mode (|= Port1Translation) io_WriteConsoleASCII("CONTROLLER_WRITE_CONFIGBYTE... "); - __ps2_WriteCommandData(IRQ_PIC_PS2_CMD_WRITE_CONFIGBYTE, config | IRQ_PIC_PS2_CONFIG_PORT1_TRANSLATION); + __ps2_WriteCommandData(PIC_PS2_CMD_WRITE_CONFIGBYTE, config | PIC_PS2_CONFIG_PORT1_TRANSLATION); - if (config & IRQ_PIC_PS2_CONFIG_PORT1_CLOCK) { // mouse not present - irq_pic_ps2_HasMouse = false; + if (config & PIC_PS2_CONFIG_PORT1_CLOCK) { // mouse not present + pic_ps2_HasMouse = false; io_WriteConsoleASCII("PS/2 Controller has no mouse\n"); INTERRUPT_RESTORE; return; // early out @@ -50,62 +50,62 @@ void irq_pic_ps2_Init() { // initialize the mouse // reset mouse io_WriteConsoleASCII("DEVICE_RESET... "); - __ps2_WriteCommandData(IRQ_PIC_PS2_CMD_SEND_MOUSE, IRQ_PIC_PS2_CMD_DEVICE_RESET); - while ((data = __ps2_ReadData()) != IRQ_PIC_PS2_RESET_OK) { + __ps2_WriteCommandData(PIC_PS2_CMD_SEND_MOUSE, PIC_PS2_CMD_DEVICE_RESET); + while ((data = __ps2_ReadData()) != PIC_PS2_RESET_OK) { io_Printf("%X ", data); } io_Printf("%X ", data); // enable 4-byte mode for mouse, pure magic! - irq_pic_ps2_Mouse4Bytes = false; + pic_ps2_Mouse4Bytes = false; __ps2_SetMouseRate(200); __ps2_SetMouseRate(100); __ps2_SetMouseRate(80); io_WriteConsoleASCII("SEND_MOUSE(PS2_DEVICE_ID)"); - __ps2_WriteCommandData(IRQ_PIC_PS2_CMD_SEND_MOUSE, 0xf2); // get device ID + __ps2_WriteCommandData(PIC_PS2_CMD_SEND_MOUSE, 0xf2); // get device ID __ps2_ReadACK(); uint8_t id = __ps2_ReadData(); // receive device ID io_Printf(", MOUSE PS/2 ID=%d\n", id); - irq_pic_ps2_Mouse4Bytes = (id == 3); // Z-axis is enabled + pic_ps2_Mouse4Bytes = (id == 3); // Z-axis is enabled - irq_pic_IRQHandler[IRQ_PIC_PS2_MOUSE] = irq_pic_ps2_IRQHandlerM; - irq_pic_Mask(IRQ_PIC_PS2_MOUSE, false); + irq_pic_IRQHandler[PIC_PS2_MOUSE] = pic_ps2_IRQHandlerM; + irq_pic_Mask(PIC_PS2_MOUSE, false); // set the actual mouse sample rate - __ps2_SetMouseRate(IRQ_PIC_PS2_MOUSE_SAMPLERATE); + __ps2_SetMouseRate(PIC_PS2_MOUSE_SAMPLERATE); // enable mouse reporting io_WriteConsoleASCII("MOUSE_ENABLE_REPORTING... "); - __ps2_WriteCommandData(IRQ_PIC_PS2_CMD_SEND_MOUSE, IRQ_PIC_PS2_CMD_DEVICE_MOUSE_ENABLE_REPORTING); + __ps2_WriteCommandData(PIC_PS2_CMD_SEND_MOUSE, PIC_PS2_CMD_DEVICE_MOUSE_ENABLE_REPORTING); __ps2_ReadACK(); // receive ACK INTERRUPT_RESTORE; } -SYSV_ABI void irq_pic_ps2_IRQHandlerK() { - queue_PushByte(&irq_pic_ps2_QueueKeyboard, inb(IRQ_PIC_PS2_IOPORT)); +SYSV_ABI void pic_ps2_IRQHandlerK() { + queue_PushByte(&pic_ps2_QueueKeyboard, inb(PIC_PS2_IOPORT)); } -SYSV_ABI void irq_pic_ps2_IRQHandlerM() { - queue_PushByte(&irq_pic_ps2_QueueMouse, inb(IRQ_PIC_PS2_IOPORT)); +SYSV_ABI void pic_ps2_IRQHandlerM() { + queue_PushByte(&pic_ps2_QueueMouse, inb(PIC_PS2_IOPORT)); - while (queue_Size(&irq_pic_ps2_QueueMouse) && !(queue_FrontByte(&irq_pic_ps2_QueueMouse) & (1u << 3))) - queue_PopByte(&irq_pic_ps2_QueueMouse); + while (queue_Size(&pic_ps2_QueueMouse) && !(queue_FrontByte(&pic_ps2_QueueMouse) & (1u << 3))) + queue_PopByte(&pic_ps2_QueueMouse); - while (queue_Size(&irq_pic_ps2_QueueMouse) >= (irq_pic_ps2_Mouse4Bytes ? 4 : 3)) { + while (queue_Size(&pic_ps2_QueueMouse) >= (pic_ps2_Mouse4Bytes ? 4 : 3)) { unsigned int moveX, moveY, state; - state = queue_PopByte(&irq_pic_ps2_QueueMouse); + state = queue_PopByte(&pic_ps2_QueueMouse); - unsigned int d = queue_PopByte(&irq_pic_ps2_QueueMouse); + unsigned int d = queue_PopByte(&pic_ps2_QueueMouse); moveX = d - ((state << 4) & 0x100); - d = queue_PopByte(&irq_pic_ps2_QueueMouse); + d = queue_PopByte(&pic_ps2_QueueMouse); moveY = d - ((state << 3) & 0x100); input_source_MoveMouse(moveX, -moveY); - if (irq_pic_ps2_Mouse4Bytes) - queue_PopByte(&irq_pic_ps2_QueueMouse); + if (pic_ps2_Mouse4Bytes) + queue_PopByte(&pic_ps2_QueueMouse); } } diff --git a/driver/irq/pic/ps2/ps2.h b/driver/irq/pic/ps2/ps2.h index 15fd075..1fcd4c0 100644 --- a/driver/irq/pic/ps2/ps2.h +++ b/driver/irq/pic/ps2/ps2.h @@ -7,59 +7,59 @@ extern "C" { #endif -#define IRQ_PIC_PS2_MOUSE_SAMPLERATE 60 // the sample rate of the mouse +#define PIC_PS2_MOUSE_SAMPLERATE 60 // the sample rate of the mouse -#define IRQ_PIC_PS2_KEYBOARD 1 // Keyboard IRQ number -#define IRQ_PIC_PS2_MOUSE 12 // Mouse IRQ number +#define PIC_PS2_KEYBOARD 1 // Keyboard IRQ number +#define PIC_PS2_MOUSE 12 // Mouse IRQ number -#define IRQ_PIC_PS2_IOPORT 0x0060 -#define IRQ_PIC_PS2_STATUSPORT 0x0064 -#define IRQ_PIC_PS2_CMDPORT 0x0064 +#define PIC_PS2_IOPORT 0x0060 +#define PIC_PS2_STATUSPORT 0x0064 +#define PIC_PS2_CMDPORT 0x0064 -#define IRQ_PIC_PS2_STATUS_OUTPUT_BUFFER (1 << 0) -#define IRQ_PIC_PS2_STATUS_INPUT_BUFFER (1 << 1) -#define IRQ_PIC_PS2_STATUS_SYSTEM_FLAG (1 << 2) -#define IRQ_PIC_PS2_STATUS_INPUT_BUFFER_IS_COMMAND (1 << 3) // (0 = data written to input buffer is data for PS/2 device, 1 = data written to input buffer is data for PS/2 controller command) -#define IRQ_PIC_PS2_STATUS_UNUSED_4 (1 << 4) -#define IRQ_PIC_PS2_STATUS_UNUSED_5 (1 << 5) -#define IRQ_PIC_PS2_STATUS_TIMEOUT_ERROR (1 << 6) -#define IRQ_PIC_PS2_STATUS_PARITY_ERROR (1 << 7) +#define PIC_PS2_STATUS_OUTPUT_BUFFER (1 << 0) +#define PIC_PS2_STATUS_INPUT_BUFFER (1 << 1) +#define PIC_PS2_STATUS_SYSTEM_FLAG (1 << 2) +#define PIC_PS2_STATUS_INPUT_BUFFER_IS_COMMAND (1 << 3) // (0 = data written to input buffer is data for PS/2 device, 1 = data written to input buffer is data for PS/2 controller command) +#define PIC_PS2_STATUS_UNUSED_4 (1 << 4) +#define PIC_PS2_STATUS_UNUSED_5 (1 << 5) +#define PIC_PS2_STATUS_TIMEOUT_ERROR (1 << 6) +#define PIC_PS2_STATUS_PARITY_ERROR (1 << 7) -#define IRQ_PIC_PS2_CONFIG_PORT1_INTERRUPT (1 << 0) // PS/2 port interrupt (1=Enabled, 0=Disabled) -#define IRQ_PIC_PS2_CONFIG_PORT2_INTERRUPT (1 << 1) // PS/2 port interrupt (1=Enabled, 0=Disabled) -#define IRQ_PIC_PS2_CONFIG_SYSTEM_POST_OK (1 << 2) // If the system have passed POST -#define IRQ_PIC_PS2_CONFIG_PORT1_CLOCK (1 << 4) // PS/2 port clock (1=Disabled, 0=Enabled) -#define IRQ_PIC_PS2_CONFIG_PORT2_CLOCK (1 << 5) // PS/2 port clock (1=Disabled, 0=Enabled) -#define IRQ_PIC_PS2_CONFIG_PORT1_TRANSLATION (1 << 6) // PS/2 keyboard scancode translation (from Set 2 to Set 1) +#define PIC_PS2_CONFIG_PORT1_INTERRUPT (1 << 0) // PS/2 port interrupt (1=Enabled, 0=Disabled) +#define PIC_PS2_CONFIG_PORT2_INTERRUPT (1 << 1) // PS/2 port interrupt (1=Enabled, 0=Disabled) +#define PIC_PS2_CONFIG_SYSTEM_POST_OK (1 << 2) // If the system have passed POST +#define PIC_PS2_CONFIG_PORT1_CLOCK (1 << 4) // PS/2 port clock (1=Disabled, 0=Enabled) +#define PIC_PS2_CONFIG_PORT2_CLOCK (1 << 5) // PS/2 port clock (1=Disabled, 0=Enabled) +#define PIC_PS2_CONFIG_PORT1_TRANSLATION (1 << 6) // PS/2 keyboard scancode translation (from Set 2 to Set 1) -#define IRQ_PIC_PS2_ACK 0xfa // ACK code for keyboard and mouse (controller cmds have no ack) -#define IRQ_PIC_PS2_RESET_OK 0xaa // the last output byte when a PS/2 device is reset +#define PIC_PS2_ACK 0xfa // ACK code for keyboard and mouse (controller cmds have no ack) +#define PIC_PS2_RESET_OK 0xaa // the last output byte when a PS/2 device is reset -#define IRQ_PIC_PS2_CMD_READ_CONFIGBYTE 0x20 // Read byte 0 from controller RAM (configuration byte) -#define IRQ_PIC_PS2_CMD_WRITE_CONFIGBYTE 0x60 // Write byte 0 to controller RAM (config byte) -#define IRQ_PIC_PS2_CMD_DISABLE_MOUSE 0xa9 // Disable second PS/2 port (usually mouse) -#define IRQ_PIC_PS2_CMD_ENABLE_MOUSE 0xa8 // Enable second PS/2 port (usually mouse) -#define IRQ_PIC_PS2_CMD_SEND_MOUSE 0xd4 // Send a data byte to the second PS/2 port (usually mouse) +#define PIC_PS2_CMD_READ_CONFIGBYTE 0x20 // Read byte 0 from controller RAM (configuration byte) +#define PIC_PS2_CMD_WRITE_CONFIGBYTE 0x60 // Write byte 0 to controller RAM (config byte) +#define PIC_PS2_CMD_DISABLE_MOUSE 0xa9 // Disable second PS/2 port (usually mouse) +#define PIC_PS2_CMD_ENABLE_MOUSE 0xa8 // Enable second PS/2 port (usually mouse) +#define PIC_PS2_CMD_SEND_MOUSE 0xd4 // Send a data byte to the second PS/2 port (usually mouse) -#define IRQ_PIC_PS2_CMD_DEVICE_GETID 0xf2 -#define IRQ_PIC_PS2_CMD_DEVICE_RESET 0xff -#define IRQ_PIC_PS2_CMD_DEVICE_MOUSE_DISABLE_REPORTING 0xf5 -#define IRQ_PIC_PS2_CMD_DEVICE_MOUSE_ENABLE_REPORTING 0xf4 -#define IRQ_PIC_PS2_CMD_DEVICE_MOUSE_REQUEST_PACKET 0xeb +#define PIC_PS2_CMD_DEVICE_GETID 0xf2 +#define PIC_PS2_CMD_DEVICE_RESET 0xff +#define PIC_PS2_CMD_DEVICE_MOUSE_DISABLE_REPORTING 0xf5 +#define PIC_PS2_CMD_DEVICE_MOUSE_ENABLE_REPORTING 0xf4 +#define PIC_PS2_CMD_DEVICE_MOUSE_REQUEST_PACKET 0xeb -void irq_pic_ps2_Init(); +void pic_ps2_Init(); -extern bool irq_pic_ps2_HasMouse; // does the PS/2 controller have 2 channels? -extern bool irq_pic_ps2_Mouse4Bytes; // the mouse has 4-byte data packages instead of 3; mouse wheel enabled +extern bool pic_ps2_HasMouse; // does the PS/2 controller have 2 channels? +extern bool pic_ps2_Mouse4Bytes; // the mouse has 4-byte data packages instead of 3; mouse wheel enabled // size in bytes of the Keyboard/Mouse FIFO buffers -#define IRQ_PIC_PS2_QUEUESIZE_KEYBOARD 64 -#define IRQ_PIC_PS2_QUEUESIZE_MOUSE 256 +#define PIC_PS2_QUEUESIZE_KEYBOARD 64 +#define PIC_PS2_QUEUESIZE_MOUSE 256 // data queue in bytes for the Keyboard and Mouse IRQs -extern queue irq_pic_ps2_QueueKeyboard, irq_pic_ps2_QueueMouse; +extern queue pic_ps2_QueueKeyboard, irq_pic_ps2_QueueMouse; #ifdef __cplusplus diff --git a/kernel/kmain.c b/kernel/kmain.c index ce86c3c..b761a9c 100644 --- a/kernel/kmain.c +++ b/kernel/kmain.c @@ -53,7 +53,7 @@ SYSV_ABI void kMain() { irq_pic_Init(); io_WriteConsoleASCII("PIC IRQ OK\n"); - irq_pic_ps2_Init(); + pic_ps2_Init(); io_WriteConsoleASCII("PIC PS/2 OK\n"); xcursor_Xcursor cursor;