1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Thread secured the keyboard driver.

This commit is contained in:
Jonas 'Sortie' Termansen 2012-08-01 20:53:51 +02:00
parent af015491db
commit bf07674d7a
2 changed files with 49 additions and 11 deletions

View file

@ -1,6 +1,6 @@
/****************************************************************************** /*******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012. Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
This file is part of Sortix. This file is part of Sortix.
@ -14,13 +14,13 @@
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details. details.
You should have received a copy of the GNU General Public License along You should have received a copy of the GNU General Public License along with
with Sortix. If not, see <http://www.gnu.org/licenses/>. Sortix. If not, see <http://www.gnu.org/licenses/>.
kb/ps2.cpp kb/ps2.cpp
A driver for the PS2 Keyboard. A driver for the PS2 Keyboard.
******************************************************************************/ *******************************************************************************/
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
@ -58,6 +58,7 @@ namespace Sortix
this->interrupt = interrupt; this->interrupt = interrupt;
this->leds = 0; this->leds = 0;
this->scancodeescaped = false; this->scancodeescaped = false;
this->kblock = KTHREAD_MUTEX_INITIALIZER;
Interrupt::RegisterHandler(interrupt, PS2Keyboard__OnInterrupt, this); Interrupt::RegisterHandler(interrupt, PS2Keyboard__OnInterrupt, this);
// If any scancodes were already pending, our interrupt handler will // If any scancodes were already pending, our interrupt handler will
@ -71,16 +72,43 @@ namespace Sortix
delete[] queue; delete[] queue;
} }
struct PS2KeyboardWork
{
PS2Keyboard* kb;
uint8_t scancode;
};
static void PS2Keyboard__InterruptWork(void* payload, size_t size)
{
ASSERT(size == sizeof(PS2KeyboardWork));
PS2KeyboardWork* work = (PS2KeyboardWork*) payload;
work->kb->InterruptWork(work->scancode);
}
void PS2Keyboard::OnInterrupt(CPU::InterruptRegisters* /*regs*/) void PS2Keyboard::OnInterrupt(CPU::InterruptRegisters* /*regs*/)
{ {
uint8_t scancode = PopScancode(); uint8_t scancode = PopScancode();
#ifdef GOT_ACTUAL_KTHREAD
PS2KeyboardWork work;
work.kb = this;
work.scancode = scancode;
Interrupt::ScheduleWork(PS2Keyboard__InterruptWork, &work, sizeof(work));
#else
InterruptWork(scancode);
#endif
}
void PS2Keyboard::InterruptWork(uint8_t scancode)
{
kthread_mutex_lock(&kblock);
int kbkey = DecodeScancode(scancode); int kbkey = DecodeScancode(scancode);
if ( !kbkey ) { return; } if ( !kbkey ) { kthread_mutex_unlock(&kblock); return; }
if ( !PushKey(kbkey) ) if ( !PushKey(kbkey) )
{ {
Log::PrintF("Warning: dropping keystroke due to insufficient " Log::PrintF("Warning: dropping keystroke due to insufficient "
"storage space in PS2 keyboard driver.\n"); "storage space in PS2 keyboard driver.\n");
kthread_mutex_unlock(&kblock);
return; return;
} }
@ -92,6 +120,8 @@ namespace Sortix
if ( newleds != leds ) { UpdateLEDs(leds = newleds); } if ( newleds != leds ) { UpdateLEDs(leds = newleds); }
kthread_mutex_unlock(&kblock);
NotifyOwner(); NotifyOwner();
} }
@ -137,8 +167,10 @@ namespace Sortix
void PS2Keyboard::SetOwner(KeyboardOwner* owner, void* user) void PS2Keyboard::SetOwner(KeyboardOwner* owner, void* user)
{ {
kthread_mutex_lock(&kblock);
this->owner = owner; this->owner = owner;
this->ownerptr = user; this->ownerptr = user;
kthread_mutex_unlock(&kblock);
if ( queueused ) { NotifyOwner(); } if ( queueused ) { NotifyOwner(); }
} }
@ -177,16 +209,19 @@ namespace Sortix
int PS2Keyboard::Read() int PS2Keyboard::Read()
{ {
ScopedLock lock(&kblock);
return PopKey(); return PopKey();
} }
size_t PS2Keyboard::GetPending() const size_t PS2Keyboard::GetPending() const
{ {
ScopedLock lock(&kblock);
return queueused; return queueused;
} }
bool PS2Keyboard::HasPending() const bool PS2Keyboard::HasPending() const
{ {
ScopedLock lock(&kblock);
return queueused; return queueused;
} }
} }

View file

@ -1,6 +1,6 @@
/****************************************************************************** /*******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012. Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
This file is part of Sortix. This file is part of Sortix.
@ -14,17 +14,18 @@
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details. details.
You should have received a copy of the GNU General Public License along You should have received a copy of the GNU General Public License along with
with Sortix. If not, see <http://www.gnu.org/licenses/>. Sortix. If not, see <http://www.gnu.org/licenses/>.
kb/ps2.h kb/ps2.h
A driver for the PS2 Keyboard. A driver for the PS2 Keyboard.
******************************************************************************/ *******************************************************************************/
#ifndef SORTIX_KB_PS2_H #ifndef SORTIX_KB_PS2_H
#define SORTIX_KB_PS2_H #define SORTIX_KB_PS2_H
#include <sortix/kernel/kthread.h>
#include "../keyboard.h" #include "../keyboard.h"
namespace Sortix namespace Sortix
@ -41,6 +42,7 @@ namespace Sortix
public: public:
void OnInterrupt(CPU::InterruptRegisters* regs); void OnInterrupt(CPU::InterruptRegisters* regs);
void InterruptWork(uint8_t scancode);
private: private:
uint8_t PopScancode(); uint8_t PopScancode();
@ -61,6 +63,7 @@ namespace Sortix
uint8_t interrupt; uint8_t interrupt;
bool scancodeescaped; bool scancodeescaped;
uint8_t leds; uint8_t leds;
mutable kthread_mutex_t kblock;
}; };
} }