device/xhci: Add helper method to iterate over xhci_supported_protocl
There is some boilerplate required to iterate over the USB supported protocol structs. Encapsulate all the in a method to make the callers simpler. BUG=b:154756391 TEST=Built test trembyle. Signed-off-by: Raul E Rangel <rrangel@chromium.org> Change-Id: I401f10d242638b0000ba697573856d765333dca0 Reviewed-on: https://review.coreboot.org/c/coreboot/+/43352 Reviewed-by: Furquan Shaikh <furquan@google.com> Reviewed-by: Aaron Durbin <adurbin@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
ae0eeb2ab6
commit
2c952d6bd9
|
@ -1,9 +1,10 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||||
|
|
||||||
#include <device/xhci.h>
|
#include <arch/mmio.h>
|
||||||
#include <console/console.h>
|
#include <console/console.h>
|
||||||
#include <device/pci_def.h>
|
#include <device/pci_def.h>
|
||||||
#include <arch/mmio.h>
|
#include <device/xhci.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
union xhci_ext_caps_header {
|
union xhci_ext_caps_header {
|
||||||
uint32_t val;
|
uint32_t val;
|
||||||
|
@ -75,6 +76,42 @@ enum cb_err xhci_for_each_ext_cap(const struct device *device, void *context,
|
||||||
return CB_SUCCESS;
|
return CB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct supported_usb_cap_context {
|
||||||
|
void *context;
|
||||||
|
void (*callback)(void *context, const struct xhci_supported_protocol *data);
|
||||||
|
};
|
||||||
|
|
||||||
|
static void xhci_supported_usb_cap_handler(void *context, const struct xhci_ext_cap *cap)
|
||||||
|
{
|
||||||
|
const struct xhci_supported_protocol *data;
|
||||||
|
struct supported_usb_cap_context *internal_context = context;
|
||||||
|
|
||||||
|
if (cap->cap_id != XHCI_ECP_CAP_ID_SUPP)
|
||||||
|
return;
|
||||||
|
|
||||||
|
data = &cap->supported_protocol;
|
||||||
|
|
||||||
|
if (memcmp(data->name, "USB ", 4)) {
|
||||||
|
printk(BIOS_DEBUG, "%s: Unknown Protocol: %.*s\n", __func__,
|
||||||
|
(int)sizeof(data->name), data->name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal_context->callback(internal_context->context, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum cb_err xhci_for_each_supported_usb_cap(
|
||||||
|
const struct device *device, void *context,
|
||||||
|
void (*callback)(void *context, const struct xhci_supported_protocol *data))
|
||||||
|
{
|
||||||
|
struct supported_usb_cap_context internal_context = {
|
||||||
|
.context = context,
|
||||||
|
.callback = callback,
|
||||||
|
};
|
||||||
|
|
||||||
|
return xhci_for_each_ext_cap(device, &internal_context, xhci_supported_usb_cap_handler);
|
||||||
|
}
|
||||||
|
|
||||||
void xhci_print_supported_protocol(const struct xhci_supported_protocol *supported_protocol)
|
void xhci_print_supported_protocol(const struct xhci_supported_protocol *supported_protocol)
|
||||||
{
|
{
|
||||||
printk(BIOS_DEBUG, "xHCI Supported Protocol:\n");
|
printk(BIOS_DEBUG, "xHCI Supported Protocol:\n");
|
||||||
|
|
|
@ -52,6 +52,14 @@ enum cb_err xhci_for_each_ext_cap(const struct device *device, void *context,
|
||||||
void (*callback)(void *context,
|
void (*callback)(void *context,
|
||||||
const struct xhci_ext_cap *cap));
|
const struct xhci_ext_cap *cap));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method that iterates over only the USB supported capabilities structures in the
|
||||||
|
* xHCI Extended Capabilities List.
|
||||||
|
*/
|
||||||
|
enum cb_err xhci_for_each_supported_usb_cap(
|
||||||
|
const struct device *device, void *context,
|
||||||
|
void (*callback)(void *context, const struct xhci_supported_protocol *data));
|
||||||
|
|
||||||
void xhci_print_supported_protocol(const struct xhci_supported_protocol *supported_protocol);
|
void xhci_print_supported_protocol(const struct xhci_supported_protocol *supported_protocol);
|
||||||
|
|
||||||
#endif /* __DEVICE_XHCI_H__ */
|
#endif /* __DEVICE_XHCI_H__ */
|
||||||
|
|
Loading…
Reference in New Issue