20#ifndef MACHINE_X86_PS2CONTROLLER_H
21#define MACHINE_X86_PS2CONTROLLER_H
22#include "pedigree/kernel/Atomic.h"
23#include "pedigree/kernel/compiler.h"
24#include "pedigree/kernel/machine/Controller.h"
25#include "pedigree/kernel/machine/IrqHandler.h"
26#include "pedigree/kernel/machine/Ps2CaptureState.h"
27#include "pedigree/kernel/machine/types.h"
28#include "pedigree/kernel/process/Mutex.h"
29#include "pedigree/kernel/processor/types.h"
30#include "pedigree/kernel/utilities/Buffer.h"
31#include "pedigree/kernel/utilities/String.h"
45 str.assign(
"PS/2 Controller", 16);
49 str.assign(
"PS/2 Controller", 16);
74 EXPORTED_PUBLIC
void setIrqEnable(
bool firstEnabled,
bool secondEnabled);
78 uint8_t readByteNonBlock();
83 EXPORTED_PUBLIC
bool readSecondPort(uint8_t&
byte,
bool block =
true);
87 return m_ReadMode.value() == StoppingReadMode;
95 return m_DebugState.active();
99 static constexpr size_t PollingReadMode = 0;
100 static constexpr size_t BufferedReadMode = 1;
101 static constexpr size_t StoppingReadMode = 2;
102 static constexpr uint8_t OutputBufferFull = 1;
103 static constexpr uint8_t InputBufferFull = 1 << 1;
104 static constexpr uint8_t SecondPortData = 1 << 5;
108 bool acquireIoForThread();
111 bool sendCommandLocked(uint8_t command);
112 bool sendCommandLocked(uint8_t command, uint8_t data);
113 bool sendCommandWithResponseLocked(uint8_t command, uint8_t& response);
114 bool sendCommandWithResponseLocked(uint8_t command, uint8_t data, uint8_t& response);
115 bool writeFirstPortLocked(uint8_t
byte);
116 bool configureIrqEnable(
bool firstEnabled,
bool secondEnabled);
118 bool waitForReadingLocked();
119 bool waitForWritingLocked();
122 bool m_bHasSecondPort;
127 irq_id_t m_FirstIrqId;
128 irq_id_t m_SecondIrqId;
132 uint8_t m_ConfigByte;
Abstrace base class for hardware I/O capabilities.
void sendCommand(uint8_t command)
Send a command with no response or data. A timed-out command is dropped.
uint8_t readByte()
Reads a single byte from the PS/2 controller by polling.
EXPORTED_PUBLIC bool readsStopping() const
Reports that buffered readers must leave their long-lived loops.
void writeFirstPort(uint8_t byte)
Send a byte to the first port, dropping it if the controller times out.
virtual void dump(String &str)
virtual void getName(String &str)
EXPORTED_PUBLIC void writeSecondPort(uint8_t byte)
Send a byte to the second port, dropping it on timeout.
IrqDisposition irq(irq_id_t number) override
bool getDebugState() const
Gets the debug state.
bool readFirstPort(uint8_t &byte, bool block=true)
Reads a single byte from the first port.
EXPORTED_PUBLIC bool hasSecondPort() const
Reports whether this PS/2 controller has two ports.
EXPORTED_PUBLIC void setIrqEnable(bool firstEnabled, bool secondEnabled)
Enables/disables IRQs for the first or second ports.
uint8_t sendCommandWithResponse(uint8_t command)
Send a command and report its response, or zero if the operation fails.
EXPORTED_PUBLIC bool readSecondPort(uint8_t &byte, bool block=true)
Reads a single byte from the second port.
void setDebugState(bool debugState)
Selects trap-safe polling without changing controller IRQ state.