drivers/usb/pci_xhci: Don't return ACPI names for missing ports

We only want to return an ACPI name for a USB port if the controller
physically has the port. This has the desired side effect of making the
usb_acpi driver skip generating an ACPI node for a device which has
no port. This prevents writing an invalid SSDT table which the OS then
complains about.

BUG=b:154756391, b:158096224
TEST=Boot picasso trembyle and verify HS05, HS06 and SS05 are no longer
generated. Also checked the logs and saw the devices being ignored.
\_SB.PCI0.LPCB.EC0.CREC.TUN0: Cros EC I2C Tunnel at GENERIC: 0.0
\_SB.PCI0.LPCB.EC0.CREC.MSTH: Cros EC I2C Tunnel at GENERIC: 1.0
\_SB.PCI0.LPCB.EC0.CREC.ECA0: Cros EC audio codec at GENERIC: 0.0
\_SB.PCI0.PBRA.XHC0.RHUB.HS01: Left Type-C Port at USB2 port 0
\_SB.PCI0.PBRA.XHC0.RHUB.HS02: Left Type-A Port at USB2 port 1
\_SB.PCI0.PBRA.XHC0.RHUB.HS03: Right Type-A Port at USB2 port 2
\_SB.PCI0.PBRA.XHC0.RHUB.HS04: Right Type-C Port at USB2 port 3
xhci_acpi_name: USB2 port 4 does not exist on xHC PCI: 03:00.3
xhci_acpi_name: USB2 port 5 does not exist on xHC PCI: 03:00.3
\_SB.PCI0.PBRA.XHC0.RHUB.SS01: Left Type-C Port at USB3 port 0
\_SB.PCI0.PBRA.XHC0.RHUB.SS02: Left Type-A Port at USB3 port 1
\_SB.PCI0.PBRA.XHC0.RHUB.SS03: Right Type-A Port at USB3 port 2
\_SB.PCI0.PBRA.XHC0.RHUB.SS04: Right Type-C Port at USB3 port 3
xhci_acpi_name: USB3 port 4 does not exist on xHC PCI: 03:00.3

Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Change-Id: Ia645380bea74f39fd94e2f9cbca3fcd4d18a878e
Reviewed-on: https://review.coreboot.org/c/coreboot/+/43354
Reviewed-by: Furquan Shaikh <furquan@google.com>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Rob Barnes <robbarnes@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Raul E Rangel 2020-07-10 14:30:54 -06:00 committed by Felix Held
parent 9d017d2d29
commit d8bc5c127a
1 changed files with 96 additions and 9 deletions

View File

@ -24,11 +24,72 @@ __weak enum cb_err pci_xhci_get_wake_gpe(const struct device *dev, int *gpe)
return CB_SUCCESS; return CB_SUCCESS;
} }
static void xhci_count_ports(void *context, const struct xhci_supported_protocol *data)
{
struct port_counts *counts = context;
switch (data->major_rev) {
case 3:
counts->super_speed += data->port_count;
return;
case 2:
counts->high_speed += data->port_count;
return;
default:
printk(BIOS_INFO, "%s: Unknown USB Version: %#x\n", __func__, data->major_rev);
return;
}
}
static bool xhci_port_exists(const struct device *dev, const struct usb_path *path)
{
/* Cache the counts so we don't have to iterate on each invocation. */
static struct {
const struct device *dev;
struct port_counts counts;
} cache;
if (cache.dev != dev) {
cache.counts.high_speed = 0;
cache.counts.super_speed = 0;
cache.dev = dev;
xhci_for_each_supported_usb_cap(dev, &cache.counts, xhci_count_ports);
}
/* port_ids are 0 based */
switch (path->port_type) {
case 3:
return path->port_id < cache.counts.super_speed;
case 2:
return path->port_id < cache.counts.high_speed;
default:
printk(BIOS_INFO, "%s: Unknown USB Version: %#x\n", __func__, path->port_type);
return false;
}
}
static const struct device *get_xhci_dev(const struct device *dev)
{
while (dev && dev->ops != &xhci_pci_ops) {
if (dev->path.type == DEVICE_PATH_ROOT)
return NULL;
dev = dev->bus->dev;
}
return dev;
}
static const char *xhci_acpi_name(const struct device *dev) static const char *xhci_acpi_name(const struct device *dev)
{ {
char *name; char *name;
unsigned int port_id; unsigned int port_id;
const char *pattern;
const struct device *xhci_dev;
/* Generate ACPI names for the usb_acpi driver */
if (dev->path.type == DEVICE_PATH_USB) { if (dev->path.type == DEVICE_PATH_USB) {
/* Ports index start at 1 */ /* Ports index start at 1 */
port_id = dev->path.usb.port_id + 1; port_id = dev->path.usb.port_id + 1;
@ -37,22 +98,48 @@ static const char *xhci_acpi_name(const struct device *dev)
case 0: case 0:
return "RHUB"; return "RHUB";
case 2: case 2:
pattern = "HS%02d";
break;
case 3:
pattern = "SS%02d";
break;
default:
printk(BIOS_INFO, "%s: Unknown USB Version: %#x\n", __func__,
dev->path.usb.port_type);
return NULL;
}
xhci_dev = get_xhci_dev(dev);
if (!xhci_dev)
die("%s: xHCI controller not found for %s\n", __func__, dev_path(dev));
/*
* We only want to return an ACPI name for a USB port if the controller
* physically has the port. This has the desired side effect of making the
* usb_acpi driver skip generating an ACPI node for a device which has
* no port. This prevents writing an invalid SSDT table which the OS then
* complains about.
*/
if (!xhci_port_exists(xhci_dev, &dev->path.usb)) {
printk(BIOS_WARNING, "%s: %s does not exist on xHC ", __func__,
dev_path(dev));
/* dev_path uses a static buffer :( */
printk(BIOS_WARNING, "%s\n", dev_path(xhci_dev));
return NULL;
}
name = malloc(ACPI_NAME_BUFFER_SIZE); name = malloc(ACPI_NAME_BUFFER_SIZE);
snprintf(name, ACPI_NAME_BUFFER_SIZE, "HS%02d", port_id); snprintf(name, ACPI_NAME_BUFFER_SIZE, pattern, port_id);
name[4] = '\0'; name[4] = '\0';
return name; return name;
case 3:
name = malloc(ACPI_NAME_BUFFER_SIZE);
snprintf(name, ACPI_NAME_BUFFER_SIZE, "SS%02d", port_id);
name[4] = '\0';
return name;
}
} else if (dev->ops == &xhci_pci_ops) { } else if (dev->ops == &xhci_pci_ops) {
return dev->name; return dev->name;
} }
printk(BIOS_ERR, "%s: Unknown device %s\n", __func__, dev_path(dev)); printk(BIOS_ERR, "%s: Unknown device %s\n", __func__, dev_path(dev));
return NULL; return NULL;
} }