aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Zieba <robertzieba@google.com>2022-11-18 18:06:28 +0000
committerMartin L Roth <gaumless@gmail.com>2023-03-05 15:32:34 +0000
commit219cb952f8f27552be7a997c608efd46cf28992e (patch)
tree562616dd0c1fd1885765487fb4e3e8267c850d17 /src
parentac8c378777d861000d82eea1c7439f16dcd45797 (diff)
device/xhci: Add functions to work with resource pointers
The XHCI device functions currently use functions that require a access to the device tree. Create variant of these functions that can operate with a resource* as an argument and refactor the existing device*-based functions to operate by calling the resource*-based variants. This is useful for stages like SMM that may not have access to the device tree. BRANCH=guybrush BUG=b:186792595 TEST=Ran on skyrim device, verified that XHCI ACPI tables are still generated correctly. Change-Id: If5a74f9529d5dc6031ec968ef5f40a9cad5ffbc4 Signed-off-by: Robert Zieba <robertzieba@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/69914 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/device/Makefile.inc3
-rw-r--r--src/device/xhci.c110
-rw-r--r--src/device/xhci_resource.c116
-rw-r--r--src/include/device/xhci.h6
4 files changed, 140 insertions, 95 deletions
diff --git a/src/device/Makefile.inc b/src/device/Makefile.inc
index 3018ef9626..7da6ea85d3 100644
--- a/src/device/Makefile.inc
+++ b/src/device/Makefile.inc
@@ -61,7 +61,8 @@ ramstage-y += mmio.c
ramstage-y += resource_allocator_common.c
ramstage-y += resource_allocator_v4.c
-ramstage-$(CONFIG_XHCI_UTILS) += xhci.c
+ramstage-$(CONFIG_XHCI_UTILS) += xhci.c xhci_resource.c
+smm-$(CONFIG_XHCI_UTILS) += xhci_resource.c
ramstage-y += gpio.c
ramstage-y += mdio.c
diff --git a/src/device/xhci.c b/src/device/xhci.c
index f7c5958a6c..0961d0c988 100644
--- a/src/device/xhci.c
+++ b/src/device/xhci.c
@@ -2,31 +2,18 @@
#include <console/console.h>
#include <device/mmio.h>
+#include <device/device.h>
#include <device/pci_def.h>
#include <device/xhci.h>
-#include <string.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;
- uint32_t *ext_cap_ptr;
- uint32_t ext_caps_word_offset;
- union xhci_ext_caps_header header;
- struct xhci_ext_cap cap;
+ const struct resource *res;
- if (!device || !callback)
- return CB_ERR_ARG;
+ if (!device)
+ return CB_ERR;
res = probe_resource(device, PCI_BASE_ADDRESS_0);
if (!res) {
@@ -35,89 +22,24 @@ enum cb_err xhci_for_each_ext_cap(const struct device *device, void *context,
return CB_ERR;
}
- if (!(res->flags & IORESOURCE_ASSIGNED)) {
- printk(BIOS_ERR, "%s: BAR is not assigned\n", __func__);
- return CB_ERR;
- }
-
- if (res->limit > 0xFFFFFFFF) {
- printk(BIOS_ERR, "%s: 64-bit BAR is not supported\n", __func__);
- return CB_ERR;
- }
-
- ext_caps_word_offset = read16(res2mmio(res, XHCI_HCCPARAMS1_XECP, 0));
-
- if (!ext_caps_word_offset) {
- printk(BIOS_ERR, "%s: No extended capabilities defined\n", __func__);
- return CB_ERR;
- }
-
- ext_cap_ptr = res2mmio(res, ext_caps_word_offset << 2, 0);
-
- while ((uintptr_t)ext_cap_ptr < (uintptr_t)res->limit) {
- header.val = read32(ext_cap_ptr);
-
- 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(ext_cap_ptr + 1);
- cap.supported_protocol.reg2 = read32(ext_cap_ptr + 2);
- }
-
- callback(context, &cap);
-
- if (!header.next_ptr)
- break;
-
- ext_cap_ptr += header.next_ptr;
- }
-
- 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);
+ return xhci_resource_for_each_ext_cap(res, context, callback);
}
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,
- };
+ const struct resource *res;
- return xhci_for_each_ext_cap(device, &internal_context, xhci_supported_usb_cap_handler);
-}
+ if (!device)
+ return CB_ERR;
-void xhci_print_supported_protocol(const struct xhci_supported_protocol *supported_protocol)
-{
- printk(BIOS_DEBUG, "xHCI Supported Protocol:\n");
- printk(BIOS_DEBUG, " Major: %#x, Minor: %#x, Protocol: '%.*s'\n",
- supported_protocol->major_rev, supported_protocol->minor_rev,
- (int)sizeof(supported_protocol->name), supported_protocol->name);
- printk(BIOS_DEBUG, " Port Offset: %d, Port Count: %d\n",
- supported_protocol->port_offset, supported_protocol->port_count);
+ res = probe_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;
+ }
+
+ return xhci_resource_for_each_supported_usb_cap(res, context, callback);
}
diff --git a/src/device/xhci_resource.c b/src/device/xhci_resource.c
new file mode 100644
index 0000000000..31f2610823
--- /dev/null
+++ b/src/device/xhci_resource.c
@@ -0,0 +1,116 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <arch/mmio.h>
+#include <console/console.h>
+#include <device/pci_def.h>
+#include <device/xhci.h>
+#include <string.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_resource_for_each_ext_cap(const struct resource *res, void *context,
+ void (*callback)(void *context,
+ const struct xhci_ext_cap *cap))
+{
+ uint32_t *ext_cap_ptr;
+ uint32_t ext_caps_word_offset;
+ union xhci_ext_caps_header header;
+ struct xhci_ext_cap cap;
+
+ if (!res || !callback)
+ return CB_ERR_ARG;
+
+ if (!(res->flags & IORESOURCE_ASSIGNED)) {
+ printk(BIOS_ERR, "%s: BAR is not assigned\n", __func__);
+ return CB_ERR;
+ }
+
+ if (res->limit > 0xFFFFFFFF) {
+ printk(BIOS_ERR, "%s: 64-bit BAR is not supported\n", __func__);
+ return CB_ERR;
+ }
+
+ ext_caps_word_offset = read16(res2mmio(res, XHCI_HCCPARAMS1_XECP, 0));
+
+ if (!ext_caps_word_offset) {
+ printk(BIOS_ERR, "%s: No extended capabilities defined\n", __func__);
+ return CB_ERR;
+ }
+
+ ext_cap_ptr = res2mmio(res, ext_caps_word_offset << 2, 0);
+
+ while ((uintptr_t)ext_cap_ptr < (uintptr_t)res->limit) {
+ header.val = read32(ext_cap_ptr);
+
+ 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(ext_cap_ptr + 1);
+ cap.supported_protocol.reg2 = read32(ext_cap_ptr + 2);
+ }
+
+ callback(context, &cap);
+
+ if (!header.next_ptr)
+ break;
+
+ ext_cap_ptr += header.next_ptr;
+ }
+
+ 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_resource_for_each_supported_usb_cap(
+ const struct resource *res, 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_resource_for_each_ext_cap(res, &internal_context,
+ xhci_supported_usb_cap_handler);
+}
+
+void xhci_print_supported_protocol(const struct xhci_supported_protocol *supported_protocol)
+{
+ printk(BIOS_DEBUG, "xHCI Supported Protocol:\n");
+ printk(BIOS_DEBUG, " Major: %#x, Minor: %#x, Protocol: '%.*s'\n",
+ supported_protocol->major_rev, supported_protocol->minor_rev,
+ (int)sizeof(supported_protocol->name), supported_protocol->name);
+ printk(BIOS_DEBUG, " Port Offset: %d, Port Count: %d\n",
+ supported_protocol->port_offset, supported_protocol->port_count);
+}
diff --git a/src/include/device/xhci.h b/src/include/device/xhci.h
index b9c784ee91..861bf22d42 100644
--- a/src/include/device/xhci.h
+++ b/src/include/device/xhci.h
@@ -97,6 +97,9 @@ struct xhci_usb_info {
/**
* Iterates over the xHCI Extended Capabilities List.
*/
+enum cb_err xhci_resource_for_each_ext_cap(const struct resource *res, void *context,
+ void (*callback)(void *context,
+ const struct xhci_ext_cap *cap));
enum cb_err xhci_for_each_ext_cap(const struct device *device, void *context,
void (*callback)(void *context,
const struct xhci_ext_cap *cap));
@@ -108,6 +111,9 @@ enum cb_err xhci_for_each_ext_cap(const struct device *device, void *context,
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));
+enum cb_err xhci_resource_for_each_supported_usb_cap(
+ const struct resource *res, void *context,
+ void (*callback)(void *context, const struct xhci_supported_protocol *data));
void xhci_print_supported_protocol(const struct xhci_supported_protocol *supported_protocol);