From 6768a184759baf9bdc84185fd6e97407580e1ddb Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 6 Feb 2025 21:41:44 +0200 Subject: [PATCH] Kernel: Don't parse xHCI custom slot_types xHCI spec mandates that slot_type for USB protocol is 0. --- kernel/include/kernel/USB/XHCI/Controller.h | 1 - kernel/kernel/USB/XHCI/Controller.cpp | 14 ++++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/kernel/include/kernel/USB/XHCI/Controller.h b/kernel/include/kernel/USB/XHCI/Controller.h index 70ff3e4e..2d8ba391 100644 --- a/kernel/include/kernel/USB/XHCI/Controller.h +++ b/kernel/include/kernel/USB/XHCI/Controller.h @@ -24,7 +24,6 @@ namespace Kernel { uint8_t revision_major { 0 }; uint8_t revision_minor { 0 }; - uint8_t slot_type { 0 }; uint8_t slot_id { 0 }; }; diff --git a/kernel/kernel/USB/XHCI/Controller.cpp b/kernel/kernel/USB/XHCI/Controller.cpp index a059ad74..3b77e071 100644 --- a/kernel/kernel/USB/XHCI/Controller.cpp +++ b/kernel/kernel/USB/XHCI/Controller.cpp @@ -185,6 +185,12 @@ namespace Kernel return BAN::Error::from_errno(EFAULT); } + if (protocol.protocol_slot_type != 0) + { + dwarnln("Invalid slot type specified in SupportedProtocols"); + return BAN::Error::from_errno(EFAULT); + } + if (protocol.protocol_speed_id_count != 0) overrides_speed_ids = true; @@ -193,7 +199,6 @@ namespace Kernel auto& port = m_ports[protocol.compatible_port_offset + i - 1]; port.revision_major = protocol.major_revision; port.revision_minor = protocol.minor_revision; - port.slot_type = protocol.protocol_slot_type; } } @@ -377,13 +382,14 @@ namespace Kernel XHCI::TRB enable_slot { .enable_slot_command {} }; enable_slot.enable_slot_command.trb_type = XHCI::TRBType::EnableSlotCommand; - enable_slot.enable_slot_command.slot_type = my_port.slot_type; + // 7.2.2.1.4: The Protocol Slot Type field of a USB3 or USB2 xHCI Supported Protocol Capability shall be set to ‘0’. + enable_slot.enable_slot_command.slot_type = 0; auto result = TRY(send_command(enable_slot)); - uint8_t slot_id = result.command_completion_event.slot_id; + const uint8_t slot_id = result.command_completion_event.slot_id; if (slot_id == 0 || slot_id > capability_regs().hcsparams1.max_slots) { - dwarnln("EnableSlot gave an invalid slot {}", slot_id); + dwarnln("EnableSlotCommand returned an invalid slot {}", slot_id); return BAN::Error::from_errno(EFAULT); } dprintln_if(DEBUG_XHCI, "allocated slot {} for port {}", slot_id, port_index + 1);