[Voyageurs] Send GetDescriptor command to the device.

This commit is contained in:
Drew Galbraith 2024-02-23 11:42:10 -08:00
parent 3d7e911045
commit b0b7e2faff
9 changed files with 192 additions and 6 deletions

View file

@ -1,8 +1,13 @@
#pragma once
#include <glacier/container/hash_map.h>
#include <glacier/memory/shared_ptr.h>
#include <glacier/memory/unique_ptr.h>
#include <mammoth/sync/semaphore.h>
#include <mammoth/util/debug.h>
#include <mammoth/util/memory_region.h>
#include "xhci/control_command.h"
#include "xhci/trb_ring.h"
#include "xhci/xhci.h"
@ -13,17 +18,25 @@ class DeviceSlot {
DeviceSlot(DeviceSlot&&) = delete;
void EnableAndInitializeDataStructures(uint8_t slot_index_,
uint64_t* output_context);
uint64_t* output_context,
volatile uint32_t* doorbell);
XhciTrb CreateAddressDeviceCommand(uint8_t root_port, uint32_t route_string,
uint16_t max_packet_size);
// Caller must keep the command in scope until it completes.
template <typename T>
void ExecuteReadControlCommand(ReadControlCommand<T>& command);
void TransferComplete(uint8_t endpoint_index, uint64_t trb_phys);
uint8_t State();
private:
bool enabled_ = false;
uint8_t slot_index_ = 0;
volatile uint32_t* doorbell_ = nullptr;
uint64_t context_phys_ = 0;
mmth::OwnedMemoryRegion context_memory_;
@ -34,4 +47,19 @@ class DeviceSlot {
XhciInputContext* input_context_;
glcr::UniquePtr<TrbRingWriter> control_endpoint_transfer_trb_;
glcr::HashMap<uint64_t, glcr::SharedPtr<mmth::Semaphore>>
control_completion_sempahores_;
};
template <typename T>
void DeviceSlot::ExecuteReadControlCommand(ReadControlCommand<T>& command) {
control_endpoint_transfer_trb_->EnqueueTrb(command.SetupTrb());
control_endpoint_transfer_trb_->EnqueueTrb(command.DataTrb());
uint64_t last_phys =
control_endpoint_transfer_trb_->EnqueueTrb(command.StatusTrb());
// Ring the control endpoint doorbell.
*doorbell_ = 1;
check(control_completion_sempahores_.Insert(last_phys,
command.CompletionSemaphore()));
}