xref: /aosp_15_r20/external/coreboot/src/device/xhci.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <console/console.h>
4 #include <device/mmio.h>
5 #include <device/device.h>
6 #include <device/pci_def.h>
7 #include <device/xhci.h>
8 
xhci_for_each_ext_cap(const struct device * device,void * context,void (* callback)(void * context,const struct xhci_ext_cap * cap))9 enum cb_err xhci_for_each_ext_cap(const struct device *device, void *context,
10 				  void (*callback)(void *context,
11 						   const struct xhci_ext_cap *cap))
12 {
13 	const struct resource *res;
14 
15 	if (!device)
16 		return CB_ERR;
17 
18 	res = probe_resource(device, PCI_BASE_ADDRESS_0);
19 	if (!res) {
20 		printk(BIOS_ERR, "%s: Unable to find BAR resource for %s\n", __func__,
21 		       dev_path(device));
22 		return CB_ERR;
23 	}
24 
25 	return xhci_resource_for_each_ext_cap(res, context, callback);
26 }
27 
xhci_for_each_supported_usb_cap(const struct device * device,void * context,void (* callback)(void * context,const struct xhci_supported_protocol * data))28 enum cb_err xhci_for_each_supported_usb_cap(
29 	const struct device *device, void *context,
30 	void (*callback)(void *context, const struct xhci_supported_protocol *data))
31 {
32 	const struct resource *res;
33 
34 	if (!device)
35 		return CB_ERR;
36 
37 	res = probe_resource(device, PCI_BASE_ADDRESS_0);
38 	if (!res) {
39 		printk(BIOS_ERR, "%s: Unable to find BAR resource for %s\n", __func__,
40 		       dev_path(device));
41 		return CB_ERR;
42 	}
43 
44 	return xhci_resource_for_each_supported_usb_cap(res, context, callback);
45 }
46