mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 23:18:21 +00:00
xhci: fix not doing two-stage device descriptor fetch
This commit is contained in:
@@ -189,6 +189,26 @@ static void address_device_failed_before_slot(xhci_ctrl_t *xhci, xhci_device_t *
|
|||||||
callback(hub, port, NULL);
|
callback(hub, port, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void address_device_get_full_descriptor_callback(usb_device_t *device, void *ctx, usb_status_t status, size_t transferred) {
|
||||||
|
usb_address_device_callback_t callback = ctx;
|
||||||
|
xhci_device_t *xhci_dev = container_of(device, xhci_device_t, device);
|
||||||
|
|
||||||
|
if (status != USB_STATUS_SUCCESS) {
|
||||||
|
printf("xhci: failed to get full device descriptor on slot %u\n", xhci_dev->slot_id);
|
||||||
|
address_device_failed_cleanup(device, callback);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!usb_device_desc_valid(&device->desc, device->speed, transferred)) {
|
||||||
|
printf("xhci: malformed device descriptor\n");
|
||||||
|
address_device_failed_cleanup(device, callback);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tell the original caller that the device has been addressed.
|
||||||
|
callback(xhci_dev->device.hub, xhci_dev->device.port_number, &xhci_dev->device);
|
||||||
|
}
|
||||||
|
|
||||||
static void address_device_evaluate_ctx_callback(usb_device_t *device, void *ctx, usb_status_t status, size_t) {
|
static void address_device_evaluate_ctx_callback(usb_device_t *device, void *ctx, usb_status_t status, size_t) {
|
||||||
usb_address_device_callback_t callback = ctx;
|
usb_address_device_callback_t callback = ctx;
|
||||||
xhci_device_t *xhci_dev = container_of(device, xhci_device_t, device);
|
xhci_device_t *xhci_dev = container_of(device, xhci_device_t, device);
|
||||||
@@ -202,23 +222,35 @@ static void address_device_evaluate_ctx_callback(usb_device_t *device, void *ctx
|
|||||||
// Update the input context again.
|
// Update the input context again.
|
||||||
xhci_update_input_context(xhci, xhci_dev);
|
xhci_update_input_context(xhci, xhci_dev);
|
||||||
|
|
||||||
// Tell the original caller that the device has been addresses
|
if (usb_get_device_descriptor(
|
||||||
callback(xhci_dev->device.hub, xhci_dev->device.port_number, &xhci_dev->device);
|
&xhci_dev->device,
|
||||||
|
USB_DESCRIPTOR_TYPE_DEVICE,
|
||||||
|
0,
|
||||||
|
&xhci_dev->device.desc,
|
||||||
|
sizeof(xhci_dev->device.desc),
|
||||||
|
address_device_get_full_descriptor_callback,
|
||||||
|
callback
|
||||||
|
)) {
|
||||||
|
printf("xhci: usb_get_device_descriptor failed\n");
|
||||||
|
address_device_failed_cleanup(device, callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void address_device_get_descriptor_callback(usb_device_t *device, void *ctx, usb_status_t status, size_t transferred) {
|
static void address_device_get_initial_descriptor_callback(usb_device_t *device, void *ctx, usb_status_t status, size_t transferred) {
|
||||||
usb_address_device_callback_t callback = ctx;
|
usb_address_device_callback_t callback = ctx;
|
||||||
xhci_device_t *xhci_dev = container_of(device, xhci_device_t, device);
|
xhci_device_t *xhci_dev = container_of(device, xhci_device_t, device);
|
||||||
xhci_ctrl_t *xhci = (xhci_ctrl_t *)xhci_dev->device.hub->ctrl;
|
xhci_ctrl_t *xhci = (xhci_ctrl_t *)xhci_dev->device.hub->ctrl;
|
||||||
|
|
||||||
if (status != USB_STATUS_SUCCESS) {
|
if (status != USB_STATUS_SUCCESS) {
|
||||||
printf("xhci: failed to get device descriptor on slot %u\n", xhci_dev->slot_id);
|
printf("xhci: failed to get initial device descriptor on slot %u\n", xhci_dev->slot_id);
|
||||||
address_device_failed_cleanup(device, callback);
|
address_device_failed_cleanup(device, callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!usb_device_desc_valid(&device->desc, device->speed, transferred)) {
|
if (transferred < 8 ||
|
||||||
printf("xhci: malformed device descriptor\n");
|
device->desc.bLength != sizeof(usb_device_desc_t) ||
|
||||||
|
device->desc.bDescriptorType != USB_DESCRIPTOR_TYPE_DEVICE) {
|
||||||
|
printf("xhci: malformed initial device descriptor\n");
|
||||||
address_device_failed_cleanup(device, callback);
|
address_device_failed_cleanup(device, callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -271,8 +303,8 @@ static void address_device_addressed_callback(usb_device_t *device, void *ctx, u
|
|||||||
USB_DESCRIPTOR_TYPE_DEVICE,
|
USB_DESCRIPTOR_TYPE_DEVICE,
|
||||||
0,
|
0,
|
||||||
&xhci_dev->device.desc,
|
&xhci_dev->device.desc,
|
||||||
sizeof(xhci_dev->device.desc),
|
8,
|
||||||
address_device_get_descriptor_callback,
|
address_device_get_initial_descriptor_callback,
|
||||||
callback
|
callback
|
||||||
)) {
|
)) {
|
||||||
printf("xhci: usb_get_device_descriptor failed\n");
|
printf("xhci: usb_get_device_descriptor failed\n");
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
name=astral
|
name=astral
|
||||||
revision=9
|
revision=10
|
||||||
from_source=astral
|
from_source=astral
|
||||||
imagedeps="build-essential nasm"
|
imagedeps="build-essential nasm"
|
||||||
hostdeps="xgcc xbinutils limine"
|
hostdeps="xgcc xbinutils limine"
|
||||||
|
|||||||
Reference in New Issue
Block a user