Kernel: Rename USB initialize_endpoint -> configure_endpoint
This makes more sense as the USB command is CONFIGURE_ENDPOINT Also configure_endpoint can be called multiple times on the same endpoint. There was no reason to limit this to only one call.
This commit is contained in:
parent
a2a7302964
commit
63b15a8855
|
@ -68,7 +68,7 @@ namespace Kernel
|
||||||
|
|
||||||
const BAN::Vector<ConfigurationDescriptor>& configurations() { return m_descriptor.configurations; }
|
const BAN::Vector<ConfigurationDescriptor>& configurations() { return m_descriptor.configurations; }
|
||||||
|
|
||||||
virtual BAN::ErrorOr<void> initialize_endpoint(const USBEndpointDescriptor&) = 0;
|
virtual BAN::ErrorOr<void> configure_endpoint(const USBEndpointDescriptor&) = 0;
|
||||||
virtual BAN::ErrorOr<size_t> send_request(const USBDeviceRequest&, paddr_t buffer) = 0;
|
virtual BAN::ErrorOr<size_t> send_request(const USBDeviceRequest&, paddr_t buffer) = 0;
|
||||||
virtual void send_data_buffer(uint8_t endpoint_id, paddr_t buffer, size_t buffer_len) = 0;
|
virtual void send_data_buffer(uint8_t endpoint_id, paddr_t buffer, size_t buffer_len) = 0;
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace Kernel
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::UniqPtr<XHCIDevice>> create(XHCIController&, uint32_t port_id, uint32_t slot_id);
|
static BAN::ErrorOr<BAN::UniqPtr<XHCIDevice>> create(XHCIController&, uint32_t port_id, uint32_t slot_id);
|
||||||
|
|
||||||
BAN::ErrorOr<void> initialize_endpoint(const USBEndpointDescriptor&) override;
|
BAN::ErrorOr<void> configure_endpoint(const USBEndpointDescriptor&) override;
|
||||||
BAN::ErrorOr<size_t> send_request(const USBDeviceRequest&, paddr_t buffer) override;
|
BAN::ErrorOr<size_t> send_request(const USBDeviceRequest&, paddr_t buffer) override;
|
||||||
void send_data_buffer(uint8_t endpoint_id, paddr_t buffer, size_t buffer_size) override;
|
void send_data_buffer(uint8_t endpoint_id, paddr_t buffer, size_t buffer_size) override;
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,7 @@ namespace Kernel
|
||||||
if ((desc.bmAttributes & 0x03) != 0x03)
|
if ((desc.bmAttributes & 0x03) != 0x03)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
TRY(m_device.initialize_endpoint(desc));
|
TRY(m_device.configure_endpoint(desc));
|
||||||
m_data_buffer = TRY(DMARegion::create(desc.wMaxPacketSize & 0x07FF));
|
m_data_buffer = TRY(DMARegion::create(desc.wMaxPacketSize & 0x07FF));
|
||||||
|
|
||||||
m_data_endpoint_id = (desc.bEndpointAddress & 0x0F) * 2 + !!(desc.bEndpointAddress & 0x80);
|
m_data_endpoint_id = (desc.bEndpointAddress & 0x0F) * 2 + !!(desc.bEndpointAddress & 0x80);
|
||||||
|
|
|
@ -74,8 +74,8 @@ namespace Kernel
|
||||||
return BAN::Error::from_errno(EFAULT);
|
return BAN::Error::from_errno(EFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
TRY(m_device.initialize_endpoint(m_interface.endpoints[bulk_in_index].descriptor));
|
TRY(m_device.configure_endpoint(m_interface.endpoints[bulk_in_index].descriptor));
|
||||||
TRY(m_device.initialize_endpoint(m_interface.endpoints[bulk_out_index].descriptor));
|
TRY(m_device.configure_endpoint(m_interface.endpoints[bulk_out_index].descriptor));
|
||||||
|
|
||||||
{
|
{
|
||||||
const auto& desc = m_interface.endpoints[bulk_in_index].descriptor;
|
const auto& desc = m_interface.endpoints[bulk_in_index].descriptor;
|
||||||
|
|
|
@ -195,18 +195,13 @@ namespace Kernel
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<void> XHCIDevice::initialize_endpoint(const USBEndpointDescriptor& endpoint_descriptor)
|
BAN::ErrorOr<void> XHCIDevice::configure_endpoint(const USBEndpointDescriptor& endpoint_descriptor)
|
||||||
{
|
{
|
||||||
const bool is_control { (endpoint_descriptor.bmAttributes & 0x03) == 0x00 };
|
const bool is_control { (endpoint_descriptor.bmAttributes & 0x03) == 0x00 };
|
||||||
const bool is_isoch { (endpoint_descriptor.bmAttributes & 0x03) == 0x01 };
|
const bool is_isoch { (endpoint_descriptor.bmAttributes & 0x03) == 0x01 };
|
||||||
const bool is_bulk { (endpoint_descriptor.bmAttributes & 0x03) == 0x02 };
|
const bool is_bulk { (endpoint_descriptor.bmAttributes & 0x03) == 0x02 };
|
||||||
const bool is_interrupt { (endpoint_descriptor.bmAttributes & 0x03) == 0x03 };
|
const bool is_interrupt { (endpoint_descriptor.bmAttributes & 0x03) == 0x03 };
|
||||||
|
|
||||||
(void)is_control;
|
|
||||||
(void)is_isoch;
|
|
||||||
(void)is_bulk;
|
|
||||||
(void)is_interrupt;
|
|
||||||
|
|
||||||
XHCI::EndpointType endpoint_type;
|
XHCI::EndpointType endpoint_type;
|
||||||
switch ((endpoint_descriptor.bEndpointAddress & 0x80) | (endpoint_descriptor.bmAttributes & 0x03))
|
switch ((endpoint_descriptor.bEndpointAddress & 0x80) | (endpoint_descriptor.bmAttributes & 0x03))
|
||||||
{
|
{
|
||||||
|
@ -231,20 +226,29 @@ namespace Kernel
|
||||||
const uint32_t average_trb_length = (is_control) ? 8 : max_esit_payload;
|
const uint32_t average_trb_length = (is_control) ? 8 : max_esit_payload;
|
||||||
const uint32_t error_count = (is_isoch) ? 0 : 3;
|
const uint32_t error_count = (is_isoch) ? 0 : 3;
|
||||||
|
|
||||||
auto& endpoint = m_endpoints[endpoint_id - 1];
|
|
||||||
ASSERT(!endpoint.transfer_ring);
|
|
||||||
|
|
||||||
uint32_t last_valid_endpoint_id = endpoint_id;
|
uint32_t last_valid_endpoint_id = endpoint_id;
|
||||||
for (size_t i = endpoint_id; i < m_endpoints.size(); i++)
|
for (size_t i = endpoint_id; i < m_endpoints.size(); i++)
|
||||||
if (m_endpoints[i].transfer_ring)
|
if (m_endpoints[i].transfer_ring)
|
||||||
last_valid_endpoint_id = i + 1;
|
last_valid_endpoint_id = i + 1;
|
||||||
|
|
||||||
|
auto& endpoint = m_endpoints[endpoint_id - 1];
|
||||||
|
LockGuard _(endpoint.mutex);
|
||||||
|
|
||||||
|
if (!endpoint.transfer_ring)
|
||||||
|
{
|
||||||
endpoint.transfer_ring = TRY(DMARegion::create(m_transfer_ring_trb_count * sizeof(XHCI::TRB)));
|
endpoint.transfer_ring = TRY(DMARegion::create(m_transfer_ring_trb_count * sizeof(XHCI::TRB)));
|
||||||
endpoint.max_packet_size = max_packet_size;
|
endpoint.max_packet_size = max_packet_size;
|
||||||
endpoint.dequeue_index = 0;
|
endpoint.dequeue_index = 0;
|
||||||
endpoint.enqueue_index = 0;
|
endpoint.enqueue_index = 0;
|
||||||
endpoint.cycle_bit = 1;
|
endpoint.cycle_bit = 1;
|
||||||
endpoint.callback = (is_interrupt || is_bulk) ? &XHCIDevice::on_interrupt_or_bulk_endpoint_event : nullptr;
|
endpoint.callback = (is_interrupt || is_bulk) ? &XHCIDevice::on_interrupt_or_bulk_endpoint_event : nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
endpoint.dequeue_index = 0;
|
||||||
|
endpoint.enqueue_index = 0;
|
||||||
|
endpoint.cycle_bit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
memset(reinterpret_cast<void*>(endpoint.transfer_ring->vaddr()), 0, endpoint.transfer_ring->size());
|
memset(reinterpret_cast<void*>(endpoint.transfer_ring->vaddr()), 0, endpoint.transfer_ring->size());
|
||||||
|
|
||||||
|
@ -256,9 +260,8 @@ namespace Kernel
|
||||||
auto& endpoint_context = *reinterpret_cast<XHCI::EndpointContext*> (m_input_context->vaddr() + (endpoint_id + 1) * context_size);
|
auto& endpoint_context = *reinterpret_cast<XHCI::EndpointContext*> (m_input_context->vaddr() + (endpoint_id + 1) * context_size);
|
||||||
|
|
||||||
memset(&input_control_context, 0, context_size);
|
memset(&input_control_context, 0, context_size);
|
||||||
input_control_context.add_context_flags = (1u << endpoint_id) | 1;
|
input_control_context.add_context_flags = (1u << endpoint_id) | (1 << 0);
|
||||||
|
|
||||||
memset(&slot_context, 0, context_size);
|
|
||||||
slot_context.context_entries = last_valid_endpoint_id;
|
slot_context.context_entries = last_valid_endpoint_id;
|
||||||
// FIXME: 4.5.2 hub
|
// FIXME: 4.5.2 hub
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue