Raul Rangel has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/41899 )
Change subject: device/xhci: Add an xhci driver to enumerate capabilities ......................................................................
device/xhci: Add an xhci driver to enumerate capabilities
This will allow enumerating an xHCI controller to allow dynamically generating the ACPI device nodes.
BUG=b:154756391 TEST=Boot trembyle and check the ACPI tables for XHCI nodes
Signed-off-by: Raul E Rangel rrangel@chromium.org Change-Id: I3065c3fffad01b5378a55cfe904f971079b13d0f --- M src/device/Makefile.inc A src/device/xhci.c A src/include/device/xhci.h 3 files changed, 126 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/99/41899/1
diff --git a/src/device/Makefile.inc b/src/device/Makefile.inc index 2e62d42..7fc303b 100644 --- a/src/device/Makefile.inc +++ b/src/device/Makefile.inc @@ -62,3 +62,5 @@ ramstage-y += resource_allocator_common.c ramstage-$(CONFIG_RESOURCE_ALLOCATOR_V3) += resource_allocator_v3.c ramstage-$(CONFIG_RESOURCE_ALLOCATOR_V4) += resource_allocator_v4.c + +ramstage-y += xhci.c diff --git a/src/device/xhci.c b/src/device/xhci.c new file mode 100644 index 0000000..6c3dcb9 --- /dev/null +++ b/src/device/xhci.c @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <device/xhci.h> +#include <console/console.h> +#include <device/pci_def.h> +#include <arch/mmio.h> + +union xhci_ext_caps_header { + uint32_t val; + struct { + uint32_t cap_id : 8; + uint32_t next_ptr : 8; + uint32_t reserved : 16; + }; +}; + +enum cb_err xhci_for_each_ext_cap(const struct device *device, void *context, + void (*callback)(void *context, + const struct xhci_ext_cap *cap)) +{ + struct resource *res; + uint8_t *bar; + uint32_t ext_caps_offset; + + if (!device || !callback) + return CB_ERR_ARG; + + res = find_resource(device, PCI_BASE_ADDRESS_0); + if (!res) { + printk(BIOS_ERR, "%s: Unable to find BAR resource for %s\n", __func__, + dev_path(device)); + return CB_ERR; + } + + if (res->limit > 0xFFFFFFFF) { + printk(BIOS_DEBUG, "%s: 64-bit BAR is not supported\n", __func__); + return CB_ERR; + } + + bar = (uint8_t *)(uintptr_t)res->base; + + ext_caps_offset = read16(bar + XHCI_HCCPARAMS1_XECP); + + /* Value is in units of words, so need to multiply by 4 to get the pointer value. */ + ext_caps_offset <<= 2; + + union xhci_ext_caps_header header; + struct xhci_ext_cap cap; + + while (ext_caps_offset) { + header.val = read32(bar + ext_caps_offset); + + cap.cap_id = header.cap_id; + + if (header.cap_id == XHCI_ECP_CAP_ID_SUPP) { + cap.supported_protocol.reg0 = header.val; + cap.supported_protocol.reg1 = read32(bar + ext_caps_offset + 0x4); + cap.supported_protocol.reg2 = read32(bar + ext_caps_offset + 0x8); + } + + callback(context, &cap); + + if (header.next_ptr) + ext_caps_offset += (header.next_ptr << 2); + else + ext_caps_offset = 0; + } + + return CB_SUCCESS; +} diff --git a/src/include/device/xhci.h b/src/include/device/xhci.h new file mode 100644 index 0000000..e49c1cc --- /dev/null +++ b/src/include/device/xhci.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __DEVICE_XHCI_H__ +#define __DEVICE_XHCI_H__ + +#include <stdint.h> +#include <device/device.h> +#include <commonlib/bsd/cb_err.h> + +#define XHCI_HCCPARAMS1_XECP 0x12 + +#define XHCI_ECP_CAP_ID_LEGACY 1 +#define XHCI_ECP_CAP_ID_SUPP 2 + +struct xhci_supported_protocol { + union { + uint32_t reg0; + struct { + uint32_t cap_id : 8; + uint32_t next_ptr : 8; + uint32_t minor_rev : 8; + uint32_t major_rev : 8; + }; + }; + union { + uint32_t reg1; + char name[4]; + }; + union { + uint32_t reg2; + struct { + uint32_t port_offset : 8; + uint32_t port_count : 8; + uint32_t reserved : 12; + uint32_t protocol_speed_id_count : 4; + }; + }; +}; + +struct xhci_ext_cap { + uint32_t cap_id; + union { + struct xhci_supported_protocol supported_protocol; + }; +}; + +/** + * Iterates over the xHCI Extended Capabilities List. + */ +enum cb_err xhci_for_each_ext_cap(const struct device *device, void *context, + void (*callback)(void *context, + const struct xhci_ext_cap *cap)); + +#endif /* __DEVICE_XHCI_H__ */