The Pedigree Project 0.1
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Ps2Controller Class Reference
+ Inheritance diagram for Ps2Controller:
+ Collaboration diagram for Ps2Controller:

Public Member Functions

 Ps2Controller (Controller *pDev)
 
virtual void getName (String &str)
 
virtual void dump (String &str)
 
void initialise ()
 
bool initialise3 ()
 
void uninitialise ()
 
void sendCommand (uint8_t command)
 Send a command with no response or data. A timed-out command is dropped.
 
void sendCommand (uint8_t command, uint8_t data)
 
uint8_t sendCommandWithResponse (uint8_t command)
 Send a command and report its response, or zero if the operation fails.
 
uint8_t sendCommandWithResponse (uint8_t command, uint8_t data)
 
void writeFirstPort (uint8_t byte)
 Send a byte to the first port, dropping it if the controller times out.
 
EXPORTED_PUBLIC void writeSecondPort (uint8_t byte)
 Send a byte to the second port, dropping it on timeout.
 
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 readByte ()
 Reads a single byte from the PS/2 controller by polling.
 
uint8_t readByteNonBlock ()
 
bool readFirstPort (uint8_t &byte, bool block=true)
 Reads a single byte from the first port.
 
EXPORTED_PUBLIC bool readSecondPort (uint8_t &byte, bool block=true)
 Reads a single byte from the second port.
 
EXPORTED_PUBLIC bool readsStopping () const
 Reports that buffered readers must leave their long-lived loops.
 
void setDebugState (bool debugState)
 Selects trap-safe polling without changing controller IRQ state.
 
bool getDebugState () const
 Gets the debug state.
 
- Public Member Functions inherited from Controller
 Controller (Device *pDev)
 
virtual Type getType ()
 
- Public Member Functions inherited from Device
 Device (Device *p)
 
Device * getParent () const
 
void setParent (Device *p)
 
virtual const String & getSpecificType ()
 
virtual void setSpecificType (String str)
 
void setPciPosition (uint32_t bus, uint32_t device, uint32_t func)
 
void setPciIdentifiers (uint8_t classCode, uint8_t subclassCode, uint16_t vendorId, uint16_t deviceId, uint8_t progIf)
 
void setPciConfigHeader (const PciBus::ConfigSpace &space)
 
PciBus::ConfigSpace getPciConfigHeader () const
 
uint8_t getPciClassCode ()
 
uint8_t getPciSubclassCode ()
 
uint16_t getPciVendorId ()
 
uint16_t getPciDeviceId ()
 
uint8_t getPciProgInterface ()
 
uint32_t getPciBusPosition ()
 
uint32_t getPciDevicePosition ()
 
uint32_t getPciFunctionNumber ()
 
Device * getPhysicalFunction () const
 
size_t getVirtualFunctionIndex () const
 
void setVirtualFunction (Device *physicalFunction, size_t index)
 
virtual Vector< Address * > & addresses ()
 
virtual uintptr_t getInterruptNumber ()
 
virtual void setInterruptNumber (uintptr_t n)
 
void addChild (Device *pDevice)
 
Device * getChild (size_t n)
 
size_t getNumChildren ()
 
void removeChild (size_t n)
 
void removeChild (Device *d)
 
void replaceChild (Device *src, Device *dest)
 

Private Member Functions

IrqDisposition irq (irq_id_t number) override
 
bool acquireIoForThread ()
 
void releaseIo ()
 
bool sendCommandLocked (uint8_t command)
 
bool sendCommandLocked (uint8_t command, uint8_t data)
 
bool sendCommandWithResponseLocked (uint8_t command, uint8_t &response)
 
bool sendCommandWithResponseLocked (uint8_t command, uint8_t data, uint8_t &response)
 
bool writeFirstPortLocked (uint8_t byte)
 
bool configureIrqEnable (bool firstEnabled, bool secondEnabled)
 
bool waitForReadingLocked ()
 
bool waitForWritingLocked ()
 
- Private Member Functions inherited from IrqHandler
virtual bool acceptsSpuriousInterrupts () const
 
virtual ~IrqHandler ()
 
- Private Member Functions inherited from IrqHandlerBase
virtual ~IrqHandlerBase ()
 

Private Attributes

IoBase * m_pBase
 
bool m_bHasSecondPort
 
Buffer< uint8_t > m_FirstPortBuffer
 
Buffer< uint8_t > m_SecondPortBuffer
 
irq_id_t m_FirstIrqId
 
irq_id_t m_SecondIrqId
 
Ps2DebuggerPollingState m_DebugState
 
uint8_t m_ConfigByte
 
Ps2IoAdmissionGate m_IoGate
 
Mutex m_DrainLock
 
Atomic< size_t > m_ReadMode
 
Atomic< size_t > m_RejectedThreadIo
 
Atomic< size_t > m_FirstPortDrops
 
Atomic< size_t > m_SecondPortDrops
 
Atomic< size_t > m_EmptyIrqs
 

Static Private Attributes

static constexpr size_t PollingReadMode = 0
 
static constexpr size_t BufferedReadMode = 1
 
static constexpr size_t StoppingReadMode = 2
 
static constexpr uint8_t OutputBufferFull = 1
 
static constexpr uint8_t InputBufferFull = 1 << 1
 
static constexpr uint8_t SecondPortData = 1 << 5
 

Additional Inherited Members

- Public Types inherited from Device
enum  Type {
  Generic , Root , Disk , Bus ,
  Display , Network , Sound , Console ,
  Mouse , Controller , UsbController , UsbGeneric ,
  UsbContainer
}
 
typedef Device *(* Callback) (Device *)
 
- Static Public Member Functions inherited from Device
static bool treeLockHeldByCurrentThread ()
 
static void foreach (Callback callback, Device *root=0)
 
template<class F , class... Args>
static void foreach (pedigree_std::Callable< F > &callback, Device *root, Args... args)
 
static void addToRoot (Device *device)
 
static void searchByVendorId (uint16_t vendorId, void(*callback)(Device *), Device *root=0)
 
static void searchByVendorIdAndDeviceId (uint16_t vendorId, uint16_t deviceId, void(*callback)(Device *), Device *root=0)
 
static void searchByClass (uint16_t classCode, void(*callback)(Device *), Device *root=0)
 
static void searchByClassAndSubclass (uint16_t classCode, uint16_t subclassCode, void(*callback)(Device *), Device *root=0)
 
static void searchByClassSubclassAndProgInterface (uint16_t classCode, uint16_t subclassCode, uint8_t progInterface, void(*callback)(Device *), Device *root=0)
 
- Protected Member Functions inherited from Device
 NOT_COPYABLE_OR_ASSIGNABLE (Device)
 
- Static Protected Member Functions inherited from Device
static Device & root ()
 
- Protected Attributes inherited from Device
Vector< Address * > m_Addresses
 
Vector< Device * > m_Children
 
Device * m_pParent
 
Device * m_PhysicalFunction
 
size_t m_VirtualFunctionIndex
 
uintptr_t m_InterruptNumber
 
String m_SpecificType
 
PciBus::ConfigSpace m_ConfigHeader
 
uint8_t m_ClassCode
 
uint8_t m_SubclassCode
 
uint16_t m_VendorId
 
uint16_t m_DeviceId
 
uint8_t m_ProgInterface
 
uint32_t m_PciBusPos
 
uint32_t m_PciDevicePos
 
uint32_t m_PciFunctionNum
 
- Static Protected Attributes inherited from Device
static Device m_Root
 
static Mutex m_TreeLock
 

Detailed Description

Definition at line 37 of file Ps2Controller.h.

Constructor & Destructor Documentation

◆ Ps2Controller() [1/2]

Ps2Controller::Ps2Controller ( Controller *  pDev)

Definition at line 38 of file Ps2Controller.cc.

◆ Ps2Controller() [2/2]

Ps2Controller::Ps2Controller ( )

Definition at line 57 of file Ps2Controller.cc.

◆ ~Ps2Controller()

Ps2Controller::~Ps2Controller ( )
virtual

Definition at line 76 of file Ps2Controller.cc.

Member Function Documentation

◆ acquireIoForThread()

bool Ps2Controller::acquireIoForThread ( )
private

Definition at line 197 of file Ps2Controller.cc.

◆ configureIrqEnable()

bool Ps2Controller::configureIrqEnable ( bool  firstEnabled,
bool  secondEnabled 
)
private

Definition at line 331 of file Ps2Controller.cc.

◆ dump()

virtual void Ps2Controller::dump ( String &  str)
inlinevirtual

Dumps a textual representation of the device into the given string.

Reimplemented from Controller.

Definition at line 48 of file Ps2Controller.h.

◆ getDebugState()

bool Ps2Controller::getDebugState ( ) const
inline

Gets the debug state.

Definition at line 94 of file Ps2Controller.h.

Referenced by X86Keyboard::getChar(), and X86Keyboard::getCharNonBlock().

+ Here is the caller graph for this function:

◆ getName()

virtual void Ps2Controller::getName ( String &  str)
inlinevirtual

Stores the device's name in str.

Reimplemented from Controller.

Definition at line 44 of file Ps2Controller.h.

◆ hasSecondPort()

bool Ps2Controller::hasSecondPort ( ) const

Reports whether this PS/2 controller has two ports.

Definition at line 319 of file Ps2Controller.cc.

◆ initialise()

void Ps2Controller::initialise ( )

Definition at line 82 of file Ps2Controller.cc.

◆ initialise3()

bool Ps2Controller::initialise3 ( )

Registers threaded IRQ delivery after scheduler initialisation.

Definition at line 138 of file Ps2Controller.cc.

References Buffer< T, allowShortOperation >::enableWrites(), IrqManager::registerIsaIrqHandler(), uninitialise(), and Buffer< T, allowShortOperation >::wipe().

Referenced by Pc::initialise3().

+ Here is the caller graph for this function:

◆ irq()

IrqDisposition Ps2Controller::irq ( irq_id_t  number)
overrideprivatevirtual

Handles a pending IRQ in thread context.

Implements IrqHandler.

Definition at line 447 of file Ps2Controller.cc.

References Scheduler::instance(), Quiesced, IoBase::read8(), Buffer< T, allowShortOperation >::writeAvailable(), and Scheduler::yield().

◆ readByte()

uint8_t Ps2Controller::readByte ( )

Reads a single byte from the PS/2 controller by polling.

Definition at line 373 of file Ps2Controller.cc.

References IoBase::read8().

Referenced by X86Keyboard::getChar(), readFirstPort(), and readSecondPort().

+ Here is the caller graph for this function:

◆ readByteNonBlock()

uint8_t Ps2Controller::readByteNonBlock ( )

Definition at line 392 of file Ps2Controller.cc.

◆ readFirstPort()

bool Ps2Controller::readFirstPort ( uint8_t &  byte,
bool  block = true 
)

Reads a single byte from the first port.

Definition at line 405 of file Ps2Controller.cc.

References Buffer< T, allowShortOperation >::read(), and readByte().

Referenced by X86Keyboard::initialise().

+ Here is the caller graph for this function:

◆ readSecondPort()

bool Ps2Controller::readSecondPort ( uint8_t &  byte,
bool  block = true 
)

Reads a single byte from the second port.

Definition at line 424 of file Ps2Controller.cc.

References Buffer< T, allowShortOperation >::read(), and readByte().

◆ readsStopping()

EXPORTED_PUBLIC bool Ps2Controller::readsStopping ( ) const
inline

Reports that buffered readers must leave their long-lived loops.

Definition at line 86 of file Ps2Controller.h.

◆ releaseIo()

void Ps2Controller::releaseIo ( )
private

Definition at line 227 of file Ps2Controller.cc.

◆ sendCommand() [1/2]

void Ps2Controller::sendCommand ( uint8_t  command)

Send a command with no response or data. A timed-out command is dropped.

Definition at line 267 of file Ps2Controller.cc.

◆ sendCommand() [2/2]

void Ps2Controller::sendCommand ( uint8_t  command,
uint8_t  data 
)

Definition at line 275 of file Ps2Controller.cc.

◆ sendCommandLocked() [1/2]

bool Ps2Controller::sendCommandLocked ( uint8_t  command)
private

Definition at line 231 of file Ps2Controller.cc.

◆ sendCommandLocked() [2/2]

bool Ps2Controller::sendCommandLocked ( uint8_t  command,
uint8_t  data 
)
private

Definition at line 238 of file Ps2Controller.cc.

◆ sendCommandWithResponse() [1/2]

uint8_t Ps2Controller::sendCommandWithResponse ( uint8_t  command)

Send a command and report its response, or zero if the operation fails.

Definition at line 283 of file Ps2Controller.cc.

◆ sendCommandWithResponse() [2/2]

uint8_t Ps2Controller::sendCommandWithResponse ( uint8_t  command,
uint8_t  data 
)

Definition at line 293 of file Ps2Controller.cc.

◆ sendCommandWithResponseLocked() [1/2]

bool Ps2Controller::sendCommandWithResponseLocked ( uint8_t  command,
uint8_t &  response 
)
private

Definition at line 245 of file Ps2Controller.cc.

◆ sendCommandWithResponseLocked() [2/2]

bool Ps2Controller::sendCommandWithResponseLocked ( uint8_t  command,
uint8_t  data,
uint8_t &  response 
)
private

Definition at line 252 of file Ps2Controller.cc.

◆ setDebugState()

void Ps2Controller::setDebugState ( bool  debugState)

Selects trap-safe polling without changing controller IRQ state.

Definition at line 443 of file Ps2Controller.cc.

Referenced by X86Keyboard::setDebugState().

+ Here is the caller graph for this function:

◆ setIrqEnable()

void Ps2Controller::setIrqEnable ( bool  firstEnabled,
bool  secondEnabled 
)

Enables/disables IRQs for the first or second ports.

Definition at line 323 of file Ps2Controller.cc.

◆ uninitialise()

void Ps2Controller::uninitialise ( )

Quiesces both ports and drains their IRQ callbacks.

Definition at line 166 of file Ps2Controller.cc.

References Buffer< T, allowShortOperation >::disableWrites(), and IrqManager::unregisterHandler().

Referenced by Pc::deinitialise(), and initialise3().

+ Here is the caller graph for this function:

◆ waitForReadingLocked()

bool Ps2Controller::waitForReadingLocked ( )
private

Definition at line 493 of file Ps2Controller.cc.

◆ waitForWritingLocked()

bool Ps2Controller::waitForWritingLocked ( )
private

Definition at line 506 of file Ps2Controller.cc.

◆ writeFirstPort()

void Ps2Controller::writeFirstPort ( uint8_t  byte)

Send a byte to the first port, dropping it if the controller times out.

Definition at line 303 of file Ps2Controller.cc.

Referenced by X86Keyboard::initialise().

+ Here is the caller graph for this function:

◆ writeFirstPortLocked()

bool Ps2Controller::writeFirstPortLocked ( uint8_t  byte)
private

Definition at line 260 of file Ps2Controller.cc.

◆ writeSecondPort()

void Ps2Controller::writeSecondPort ( uint8_t  byte)

Send a byte to the second port, dropping it on timeout.

Definition at line 311 of file Ps2Controller.cc.

Member Data Documentation

◆ BufferedReadMode

constexpr size_t Ps2Controller::BufferedReadMode = 1
staticconstexprprivate

Definition at line 100 of file Ps2Controller.h.

◆ InputBufferFull

constexpr uint8_t Ps2Controller::InputBufferFull = 1 << 1
staticconstexprprivate

Definition at line 103 of file Ps2Controller.h.

◆ m_bHasSecondPort

bool Ps2Controller::m_bHasSecondPort
private

Definition at line 122 of file Ps2Controller.h.

◆ m_ConfigByte

uint8_t Ps2Controller::m_ConfigByte
private

Definition at line 132 of file Ps2Controller.h.

◆ m_DebugState

Ps2DebuggerPollingState Ps2Controller::m_DebugState
private

Definition at line 130 of file Ps2Controller.h.

◆ m_DrainLock

Mutex Ps2Controller::m_DrainLock
private

Definition at line 135 of file Ps2Controller.h.

◆ m_EmptyIrqs

Atomic<size_t> Ps2Controller::m_EmptyIrqs
private

Definition at line 140 of file Ps2Controller.h.

◆ m_FirstIrqId

irq_id_t Ps2Controller::m_FirstIrqId
private

Definition at line 127 of file Ps2Controller.h.

◆ m_FirstPortBuffer

Buffer<uint8_t> Ps2Controller::m_FirstPortBuffer
private

Definition at line 124 of file Ps2Controller.h.

◆ m_FirstPortDrops

Atomic<size_t> Ps2Controller::m_FirstPortDrops
private

Definition at line 138 of file Ps2Controller.h.

◆ m_IoGate

Ps2IoAdmissionGate Ps2Controller::m_IoGate
private

Definition at line 134 of file Ps2Controller.h.

◆ m_pBase

IoBase* Ps2Controller::m_pBase
private

Definition at line 121 of file Ps2Controller.h.

◆ m_ReadMode

Atomic<size_t> Ps2Controller::m_ReadMode
private

Definition at line 136 of file Ps2Controller.h.

◆ m_RejectedThreadIo

Atomic<size_t> Ps2Controller::m_RejectedThreadIo
private

Definition at line 137 of file Ps2Controller.h.

◆ m_SecondIrqId

irq_id_t Ps2Controller::m_SecondIrqId
private

Definition at line 128 of file Ps2Controller.h.

◆ m_SecondPortBuffer

Buffer<uint8_t> Ps2Controller::m_SecondPortBuffer
private

Definition at line 125 of file Ps2Controller.h.

◆ m_SecondPortDrops

Atomic<size_t> Ps2Controller::m_SecondPortDrops
private

Definition at line 139 of file Ps2Controller.h.

◆ OutputBufferFull

constexpr uint8_t Ps2Controller::OutputBufferFull = 1
staticconstexprprivate

Definition at line 102 of file Ps2Controller.h.

◆ PollingReadMode

constexpr size_t Ps2Controller::PollingReadMode = 0
staticconstexprprivate

Definition at line 99 of file Ps2Controller.h.

◆ SecondPortData

constexpr uint8_t Ps2Controller::SecondPortData = 1 << 5
staticconstexprprivate

Definition at line 104 of file Ps2Controller.h.

◆ StoppingReadMode

constexpr size_t Ps2Controller::StoppingReadMode = 2
staticconstexprprivate

Definition at line 101 of file Ps2Controller.h.


The documentation for this class was generated from the following files: