PatchworkOS  3984a1d
A non-POSIX operating system.
Loading...
Searching...
No Matches
ps2.c File Reference
#include "ps2.h"
#include "ps2_kbd.h"
#include "ps2_mouse.h"
#include <kernel/cpu/irq.h>
#include <kernel/log/log.h>
#include <kernel/log/panic.h>
#include <kernel/module/module.h>
#include <kernel/sched/clock.h>
#include <kernel/sched/timer.h>
#include <kernel/sync/lock.h>
#include <modules/acpi/aml/object.h>
#include <modules/acpi/devices.h>
#include <modules/acpi/resources.h>
#include <modules/acpi/tables.h>
#include <errno.h>
#include <string.h>
#include <time.h>
Include dependency graph for ps2.c:

Go to the source code of this file.

Functions

static const charps2_self_test_response_to_string (ps2_self_test_response_t response)
 
static const charps2_device_test_response_to_string (ps2_device_test_response_t response)
 
static const charps2_device_to_string (ps2_device_t device)
 
static uint64_t ps2_controller_init (void)
 
static void ps2_controller_deinit (void)
 
static uint64_t ps2_self_test (void)
 
static uint64_t ps2_check_if_dual_channel (void)
 
static uint64_t ps2_devices_test (void)
 
void ps2_drain (void)
 Drain the PS/2 output buffer.
 
uint64_t ps2_wait_until_set (ps2_status_bits_t status)
 Wait until status bit(s) are set.
 
uint64_t ps2_wait_until_clear (ps2_status_bits_t status)
 Wait until status bit(s) are clear.
 
uint64_t ps2_read (void)
 Read from the PS/2 controllers data port.
 
uint64_t ps2_read_no_wait (void)
 Read from the PS/2 controllers data port without waiting.
 
uint64_t ps2_write (uint8_t data)
 Write to the PS/2 controllers data port.
 
uint64_t ps2_cmd (ps2_cmd_t command)
 Send a command to the PS/2 controller without reading response.
 
uint64_t ps2_cmd_and_read (ps2_cmd_t command)
 Send a command to the PS/2 controller and read response.
 
uint64_t ps2_cmd_and_write (ps2_cmd_t command, uint8_t data)
 Send a command to the PS/2 controller and write data.
 
static uint64_t ps2_device_init (ps2_device_t device)
 
uint64_t ps2_device_cmd (ps2_device_t device, ps2_device_cmd_t command)
 Send a command to a PS/2 device without reading response.
 
uint64_t ps2_device_cmd_and_read (ps2_device_t device, ps2_device_cmd_t command)
 Send a command to a PS/2 device and read response.
 
uint64_t ps2_device_sub_cmd (ps2_device_t device, ps2_device_cmd_t command, uint8_t subCommand)
 Send a command and a subcommand to a PS/2 device.
 
static uint64_t ps2_attach_device (const char *type, const char *name)
 
uint64_t _module_procedure (const module_event_t *event)
 
 MODULE_INFO ("PS2 Driver", "Kai Norberg", "A PS/2 keyboard and mouse driver", OS_VERSION, "MIT", PS2_KEYBOARD_PNP_IDS ";" PS2_MOUSE_PNP_IDS)
 

Variables

static port_t dataPort = 0
 
static port_t statusPort = 0
 
static port_t commandPort = 0
 
static uint64_t currentConfig = 0
 
static bool isDualChannel = false
 
static bool controllerInitialized = false
 
static ps2_known_device_t knownKeyboards []
 
static ps2_known_device_t knownMice []
 
static ps2_device_info_t devices [PS2_DEV_COUNT]
 
static lock_t attachLock = LOCK_CREATE()
 

Function Documentation

◆ ps2_self_test_response_to_string()

static const char * ps2_self_test_response_to_string ( ps2_self_test_response_t  response)
static

Definition at line 105 of file ps2.c.

Here is the caller graph for this function:

◆ ps2_device_test_response_to_string()

static const char * ps2_device_test_response_to_string ( ps2_device_test_response_t  response)
static

Definition at line 118 of file ps2.c.

Here is the caller graph for this function:

◆ ps2_device_to_string()

static const char * ps2_device_to_string ( ps2_device_t  device)
static

Definition at line 137 of file ps2.c.

Here is the caller graph for this function:

◆ ps2_controller_init()

static uint64_t ps2_controller_init ( void  )
static

Definition at line 150 of file ps2.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ps2_controller_deinit()

static void ps2_controller_deinit ( void  )
static

Definition at line 191 of file ps2.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ps2_self_test()

static uint64_t ps2_self_test ( void  )
static

Definition at line 220 of file ps2.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ps2_check_if_dual_channel()

static uint64_t ps2_check_if_dual_channel ( void  )
static

Definition at line 251 of file ps2.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ps2_devices_test()

static uint64_t ps2_devices_test ( void  )
static

Definition at line 301 of file ps2.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ps2_device_init()

static uint64_t ps2_device_init ( ps2_device_t  device)
static

Definition at line 426 of file ps2.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ps2_attach_device()

static uint64_t ps2_attach_device ( const char type,
const char name 
)
static

Definition at line 548 of file ps2.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _module_procedure()

uint64_t _module_procedure ( const module_event_t event)

Definition at line 754 of file ps2.c.

Here is the call graph for this function:

◆ MODULE_INFO()

MODULE_INFO ( "PS2 Driver"  ,
"Kai Norberg"  ,
"A PS/2 keyboard and mouse driver"  ,
OS_VERSION  ,
"MIT"  ,
PS2_KEYBOARD_PNP_IDS ";"  PS2_MOUSE_PNP_IDS 
)

Variable Documentation

◆ dataPort

port_t dataPort = 0
static

Definition at line 21 of file ps2.c.

◆ statusPort

port_t statusPort = 0
static

Definition at line 22 of file ps2.c.

◆ commandPort

port_t commandPort = 0
static

Definition at line 23 of file ps2.c.

◆ currentConfig

uint64_t currentConfig = 0
static

Definition at line 25 of file ps2.c.

◆ isDualChannel

bool isDualChannel = false
static

Definition at line 27 of file ps2.c.

◆ controllerInitialized

bool controllerInitialized = false
static

Definition at line 28 of file ps2.c.

◆ knownKeyboards

ps2_known_device_t knownKeyboards[]
static
Initial value:
= {
{"PNP0300", "IBM PC/XT keyboard controller (83-key)"},
{"PNP0301", "IBM PC/AT keyboard controller (86-key)"},
{"PNP0302", "IBM PC/XT keyboard controller (84-key)"},
{"PNP0303", "IBM Enhanced (101/102-key, PS/2 mouse support)"},
{"PNP0304", "Olivetti Keyboard (83-key)"},
{"PNP0305", "Olivetti Keyboard (102-key)"},
{"PNP0306", "Olivetti Keyboard (86-key)"},
{"PNP0307", "Microsoft Windows(R) Keyboard"},
{"PNP0308", "General Input Device Emulation Interface (GIDEI) legacy"},
{"PNP0309", "Olivetti Keyboard (A101/102 key)"},
{"PNP030A", "AT&T 302 keyboard"},
{"PNP030B", "Reserved by Microsoft"},
{"PNP0320", "Japanese 101-key keyboard"},
{"PNP0321", "Japanese AX keyboard"},
{"PNP0322", "Japanese 106-key keyboard A01"},
{"PNP0323", "Japanese 106-key keyboard 002/003"},
{"PNP0324", "Japanese 106-key keyboard 001"},
{"PNP0325", "Japanese Toshiba Desktop keyboard"},
{"PNP0326", "Japanese Toshiba Laptop keyboard"},
{"PNP0327", "Japanese Toshiba Notebook keyboard"},
{"PNP0340", "Korean 84-key keyboard"},
{"PNP0341", "Korean 86-key keyboard"},
{"PNP0342", "Korean Enhanced keyboard"},
{"PNP0343", "Korean Enhanced keyboard 101(b/c)"},
{"PNP0344", "Korean Enhanced keyboard 103"},
}

Definition at line 30 of file ps2.c.

◆ knownMice

ps2_known_device_t knownMice[]
static

Definition at line 58 of file ps2.c.

◆ devices

Initial value:
= {
[0] = {.device = PS2_DEV_FIRST},
[1] = {.device = PS2_DEV_SECOND},
}
@ PS2_DEV_SECOND
Definition ps2.h:134
@ PS2_DEV_FIRST
Definition ps2.h:133

Definition at line 99 of file ps2.c.

◆ attachLock

lock_t attachLock = LOCK_CREATE()
static

Definition at line 103 of file ps2.c.