[Voyageurs] Receive keypress information from the usb keyboard.

This commit is contained in:
Drew Galbraith 2024-02-24 14:18:11 -08:00
parent 2cc9c89051
commit c5f8195255
6 changed files with 77 additions and 5 deletions

View File

@ -1,6 +1,7 @@
add_executable(voyageurs
keyboard/keyboard_driver.cpp
xhci/device_slot.cpp
xhci/endpoint.cpp
xhci/trb.cpp
xhci/trb_ring.cpp
xhci/xhci_driver.cpp

View File

@ -45,6 +45,8 @@ XhciTrb DeviceSlot::CreateAddressDeviceCommand(uint8_t root_port,
input_context_->endpoint_contexts[0].tr_dequeue_ptr =
control_endpoint_transfer_trb_->PhysicalAddress() | 0x1;
endpoints_ = glcr::Array<Endpoint>(32);
return ::CreateAddressDeviceCommand(context_phys_ + kInputSlotContextOffset,
slot_index_);
}
@ -54,8 +56,19 @@ uint8_t DeviceSlot::State() {
}
void DeviceSlot::TransferComplete(uint8_t endpoint_index, uint64_t trb_phys) {
if (endpoint_index >= 32) {
dbgln("ERROR: Received transfer for invalid endpoint {x}", endpoint_index);
return;
}
if (endpoint_index != 1) {
crash("Transfer complete on non control endpoint", glcr::UNIMPLEMENTED);
if (!endpoints_[endpoint_index].Enabled()) {
dbgln("ERROR: XHCI received transfer for disabled endpoint {x}",
endpoint_index);
return;
}
endpoints_[endpoint_index].TransferComplete(trb_phys);
return;
}
if (!control_completion_sempahores_.Contains(trb_phys)) {
@ -80,9 +93,7 @@ mmth::Semaphore DeviceSlot::IssueConfigureDeviceCommand(uint8_t config_value) {
input_context_->slot_context.route_speed_entries |= (max_endpoint << 27);
// TODO: Dont' hardcode this.
other_endpoint_transfer_trb_ = glcr::MakeUnique<TrbRingWriter>();
input_context_->endpoint_contexts[2].tr_dequeue_ptr =
other_endpoint_transfer_trb_->PhysicalAddress() | 0x1;
endpoints_[3].Initialize(input_context_->endpoint_contexts + 2);
xhci_driver_->IssueCommand(CreateConfigureEndpointCommand(
context_phys_ + kInputSlotContextOffset, slot_index_));

View File

@ -8,6 +8,7 @@
#include <mammoth/util/memory_region.h>
#include "xhci/control_command.h"
#include "xhci/endpoint.h"
#include "xhci/trb_ring.h"
#include "xhci/xhci.h"
@ -59,7 +60,7 @@ class DeviceSlot {
mmth::Semaphore configure_device_semaphore_;
glcr::UniquePtr<TrbRingWriter> other_endpoint_transfer_trb_;
glcr::Array<Endpoint> endpoints_;
};
template <typename T>

View File

@ -0,0 +1,31 @@
#include "xhci/endpoint.h"
#include <mammoth/util/debug.h>
void Endpoint::Initialize(XhciEndpointContext* context) {
enabled_ = true;
context_ = context;
trb_ring_ = glcr::MakeUnique<TrbRingWriter>();
recv_mem_ = mmth::OwnedMemoryRegion::ContiguousPhysical(0x1000, &recv_phys_);
context_->tr_dequeue_ptr = trb_ring_->PhysicalAddress() | 1;
context_->error_and_type = (0x3 << 1) | (0x7 << 3) | (0x8 << 16);
trb_ring_->EnqueueTrb({
.parameter = recv_phys_,
.status = 8,
.type_and_cycle = 1 | (1 << 2) | (1 << 5) | (1 << 10),
.control = 0,
});
}
void Endpoint::TransferComplete(uint64_t trb_phys) {
dbgln("Data: {x}", *(uint64_t*)recv_mem_.vaddr());
trb_ring_->EnqueueTrb({
.parameter = recv_phys_,
.status = 8,
.type_and_cycle = 1 | (1 << 2) | (1 << 5) | (1 << 10),
.control = 0,
});
}

View File

@ -0,0 +1,26 @@
#pragma once
#include <glacier/memory/unique_ptr.h>
#include "xhci/trb_ring.h"
#include "xhci/xhci.h"
class Endpoint {
public:
Endpoint() {}
void Initialize(XhciEndpointContext* context);
bool Enabled() { return enabled_; }
void TransferComplete(uint64_t trb_phys);
private:
bool enabled_ = false;
XhciEndpointContext* context_ = nullptr;
glcr::UniquePtr<TrbRingWriter> trb_ring_;
uint64_t recv_phys_;
mmth::OwnedMemoryRegion recv_mem_;
};

View File

@ -205,6 +205,8 @@ glcr::ErrorCode XhciDriver::ParseMmioStructures() {
runtime_ = reinterpret_cast<XhciRuntime*>(mmio_regions_.vaddr() +
capabilities_->runtime_offset);
dbgln("INTTTT: {x}", (uint64_t)runtime_->interrupters);
doorbells_ = reinterpret_cast<XhciDoorbells*>(mmio_regions_.vaddr() +
capabilities_->doorbell_offset);
dbgln("Doorbells: {x}", (uint64_t)doorbells_);