Index: sys/dev/usb/usb_hub_acpi.c =================================================================== --- sys/dev/usb/usb_hub_acpi.c +++ sys/dev/usb/usb_hub_acpi.c @@ -79,6 +79,7 @@ #include #include #include +#include static UINT32 acpi_uhub_find_rh_cb(ACPI_HANDLE ah, UINT32 nl, void *ctx, void **status); static ACPI_STATUS acpi_uhub_find_rh(device_t dev, ACPI_HANDLE * ah); @@ -87,6 +88,7 @@ static ACPI_STATUS acpi_usb_hub_port_probe(device_t dev, ACPI_HANDLE ah); static int acpi_uhub_root_probe(device_t dev); static int acpi_uhub_probe(device_t dev); +static int acpi_uhub_attach_common(device_t dev); static int acpi_uhub_root_attach(device_t dev); static int acpi_uhub_attach(device_t dev); static int acpi_uhub_detach(device_t dev); @@ -96,12 +98,23 @@ static int acpi_uhub_child_location_string(device_t parent, device_t child, char *buf, size_t buflen); -static int acpi_uhub_parse_upc(device_t dev, unsigned int port, ACPI_HANDLE ah); +static int acpi_uhub_parse_upc(device_t dev, unsigned int port, ACPI_HANDLE ah, struct sysctl_oid_list *tree); +static const char *acpi_uhub_upc_type(uint8_t type); +#define ACPI_PLD_SIZE 20 +struct acpi_uhub_port { + ACPI_HANDLE handle; +#define ACPI_UPC_CONNECTABLE 0x80000000 +#define ACPI_UPC_PORTTYPE(x) ((x)&0xff) + uint32_t upc; + uint8_t pld[ACPI_PLD_SIZE]; +}; + struct acpi_uhub_softc { struct uhub_softc usc; uint8_t nports; - ACPI_HANDLE *porthandle; + ACPI_HANDLE ah; + struct acpi_uhub_port *port; }; UINT32 @@ -127,48 +140,156 @@ return ret; } +static const char * +acpi_uhub_upc_type(uint8_t type) +{ + const char *typelist[] = {"TypeA", "MiniAB", "Express", + "USB3-A", "USB3-B", "USB-MicroB", + "USB3-MicroAB", "USB3-PowerB", + "TypeC-USB2", "TypeC-Switch", + "TypeC-nonSwitch"}; + const int last = sizeof(typelist) / sizeof(typelist[0]); + + if (type == 0xff) { + return "Proprietary"; + } + + return (type < last) ? typelist[type] : "Unknown"; +} + static int -acpi_uhub_parse_upc(device_t dev, unsigned int port, ACPI_HANDLE ah) +acpi_uhub_parse_upc(device_t dev, unsigned int p, ACPI_HANDLE ah, struct sysctl_oid_list *poid) { ACPI_BUFFER buf; + struct acpi_uhub_softc *sc = device_get_softc(dev); + struct acpi_uhub_port *port = &sc->port[p - 1]; buf.Pointer = NULL; buf.Length = ACPI_ALLOCATE_BUFFER; if (AcpiEvaluateObject(ah, "_UPC", NULL, &buf) == AE_OK) { - UINT64 porttypenum, conn; - const char *connectable; - const char *typelist[] = {"TypeA", "MiniAB", "Express", - "USB3-A", "USB3-B", "USB-MicroB", - "USB3-MicroAB", "USB3-PowerB", - "TypeC-USB2", "TypeC-Switch", - "TypeC-nonSwitch"}; - const char *porttype; - const int last = sizeof(typelist) / sizeof(typelist[0]); ACPI_OBJECT *obj = buf.Pointer; + UINT64 porttypenum, conn; + uint8_t *connectable; acpi_PkgInt(obj, 0, &conn); acpi_PkgInt(obj, 1, &porttypenum); connectable = conn ? "" : "non"; - if (porttypenum == 0xff) - porttype = "Proprietary"; - else if (porttypenum < last) { - porttype = typelist[porttypenum]; - } else { - porttype = "Unknown"; - } + + port->upc = porttypenum; + port->upc |= (conn) ? (ACPI_UPC_CONNECTABLE) : 0; + if (usb_debug) device_printf(dev, "Port %u %sconnectable %s\n", - port, connectable, porttype); + p, connectable, + acpi_uhub_upc_type(porttypenum)); + + SYSCTL_ADD_U32( + device_get_sysctl_ctx(dev), + poid, OID_AUTO, + "upc", + CTLFLAG_RD | CTLFLAG_MPSAFE, + SYSCTL_NULL_U32_PTR, port->upc, + "UPC value. MSB is visible flag"); } AcpiOsFree(buf.Pointer); return 0; } +static int +acpi_uhub_port_sysctl(SYSCTL_HANDLER_ARGS) +{ + struct acpi_uhub_port *port = oidp->oid_arg1; + struct sbuf sb; + int error; + sbuf_new_for_sysctl(&sb, NULL, 256, req); + sbuf_printf(&sb, "Handle %s\n", acpi_name(port->handle)); + if (port->upc == 0xffffffff) { + sbuf_printf(&sb, "\tNo information\n"); + goto end; + } + sbuf_printf(&sb, "\t"); + if (port->upc & ACPI_UPC_CONNECTABLE) { + sbuf_printf(&sb, "Connectable "); + } + sbuf_printf(&sb, "%s port\n", acpi_uhub_upc_type(port->upc & 0xff)); + + if ((port->pld[0] & 0x80) == 0) { + sbuf_printf(&sb, + "\tColor:#%02x%02x%02x\n", + port->pld[1], port->pld[2], + port->pld[3]); + } + sbuf_printf(&sb, "\tWidth %d mm Height %d mm\n", + port->pld[4] | (port->pld[5] << 8), + port->pld[6] | (port->pld[7] << 8)); + if (port->pld[8] & 1) { + sbuf_printf(&sb, "\tVisible\n"); + } + if (port->pld[8] & 2) { + sbuf_printf(&sb, "\tDock\n"); + } + if (port->pld[8] & 4) { + sbuf_printf(&sb, "\tLid\n"); + } { + int panelpos = (port->pld[8] >> 3) & 7; + const char *panposstr[] = {"Top", "Bottom", "Left", + "Right", "Front", "Back", + "Unknown", "Invalid"}; + const char *shapestr[] = { + "Round", "Oval", "Square", "VRect", "HRect", + "VTrape", "HTrape", "Unknown", "Chamferd", + "Rsvd", "Rsvd", "Rsvd", "Rsvd", + "Rsvd", "Rsvd", "Rsvd", "Rsvd"}; + + sbuf_printf(&sb, "\tPanelPosition: %s\n", panposstr[panelpos]); + if (panelpos < 6) { + const char *posstr[] = {"Upper", "Center", + "Lower", "Invalid"}; + + sbuf_printf(&sb, "\tVertPosition: %s\n", + posstr[(port->pld[8] >> 6) & 3]); + sbuf_printf(&sb, "\tHorizPosition: %s\n", + posstr[(port->pld[9]) & 3]); + + + } + sbuf_printf(&sb, "\tShape: %s\n", + shapestr[(port->pld[9] >> 2) & 0xf]); + sbuf_printf(&sb, "\tGroup Orientation %s\n", + ((port->pld[9] >> 6) & 1) ? "Vertical" : + "Horizontal"); + sbuf_printf(&sb, "\tGroupToken %x\n", + ((port->pld[9] >> 7) + | (port->pld[10] << 1)) & 0xff); + sbuf_printf(&sb, "\tGroupPosition %x\n", + ((port->pld[10] >> 7) + | (port->pld[11] << 1)) & 0xff); + sbuf_printf(&sb, "\t%s %s %s\n", + (port->pld[11] & 0x80) ? + "Bay" : "", + (port->pld[12] & 1) ? "Eject" : "", + (port->pld[12] & 2) ? "OSPM" : "" + ); + } + if ((port->pld[0] & 0x7f) >= 2) { + sbuf_printf(&sb, "\tVOFF%d mm HOFF %dmm", + port->pld[16] | (port->pld[17] << 8), + port->pld[18] | (port->pld[19] << 8)); + } + +end: + error = sbuf_finish(&sb); + sbuf_delete(&sb); + return (error); +} + static int -acpi_uhub_parse_pld(device_t dev, unsigned int port, ACPI_HANDLE ah) +acpi_uhub_parse_pld(device_t dev, unsigned int p, ACPI_HANDLE ah, struct sysctl_oid_list *tree) { ACPI_BUFFER buf; + struct acpi_uhub_softc *sc = device_get_softc(dev); + struct acpi_uhub_port *port = &sc->port[p - 1]; buf.Pointer = NULL; buf.Length = ACPI_ALLOCATE_BUFFER; @@ -192,6 +313,13 @@ } else { goto skip; } + len = (len < ACPI_PLD_SIZE) ? len : ACPI_PLD_SIZE; + memcpy(port->pld, resbuf, len); + SYSCTL_ADD_OPAQUE( + device_get_sysctl_ctx(dev), tree, OID_AUTO, + "pldraw", CTLFLAG_RD | CTLFLAG_MPSAFE, + port->pld, len, "A", "Raw PLD value"); + if (usb_debug) { device_printf(dev, "Revision:%d\n", resbuf[0] & 0x7f); @@ -233,9 +361,9 @@ resbuf[18] | (resbuf[19] << 8)); } } - skip: +skip: AcpiOsFree(buf.Pointer); - + } @@ -243,8 +371,7 @@ } ACPI_STATUS -acpi_uhub_find_rh(device_t dev, ACPI_HANDLE * ah) -{ +acpi_uhub_find_rh(device_t dev, ACPI_HANDLE * ah){ device_t grand; ACPI_HANDLE gah; @@ -258,8 +385,7 @@ } ACPI_STATUS -acpi_usb_hub_port_probe_cb(ACPI_HANDLE ah, UINT32 lv, void *ctx, void **rv) -{ +acpi_usb_hub_port_probe_cb(ACPI_HANDLE ah, UINT32 lv, void *ctx, void **rv){ ACPI_DEVICE_INFO *devinfo; device_t dev = ctx; struct acpi_uhub_softc *sc = device_get_softc(dev); @@ -271,9 +397,28 @@ if ((devinfo->Valid & ACPI_VALID_ADR) && (devinfo->Address > 0) && (devinfo->Address <= (uint64_t)sc->nports)) { - sc->porthandle[devinfo->Address - 1] = ah; - acpi_uhub_parse_upc(dev, devinfo->Address, ah); - acpi_uhub_parse_pld(dev, devinfo->Address, ah); + char buf[] = "portXXX"; + struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev); + struct sysctl_oid *oid; + struct sysctl_oid_list *tree; + + snprintf(buf, sizeof(buf), "port%lu", devinfo->Address); + oid = SYSCTL_ADD_NODE(ctx, + SYSCTL_CHILDREN( + device_get_sysctl_tree(dev)), + OID_AUTO, buf, CTLFLAG_RD, + NULL, "port nodes"); + tree = SYSCTL_CHILDREN(oid); + sc->port[devinfo->Address - 1].handle = ah; + sc->port[devinfo->Address - 1].upc = 0xffffffff; + acpi_uhub_parse_upc(dev, devinfo->Address, ah, tree); + acpi_uhub_parse_pld(dev, devinfo->Address, ah, tree); + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + tree, OID_AUTO, "info", + CTLTYPE_STRING | CTLFLAG_RD, + &sc->port[devinfo->Address - 1], 0, + acpi_uhub_port_sysctl, + "A", "Port information"); } else { device_printf(dev, "Skiping invalid devobj %s\n", acpi_name(ah)); @@ -283,8 +428,7 @@ } ACPI_STATUS -acpi_usb_hub_port_probe(device_t dev, ACPI_HANDLE ah) -{ +acpi_usb_hub_port_probe(device_t dev, ACPI_HANDLE ah){ return AcpiWalkNamespace(ACPI_TYPE_DEVICE, ah, 1, acpi_usb_hub_port_probe_cb, @@ -296,7 +440,7 @@ ACPI_HANDLE ah; ACPI_STATUS status; - if(acpi_disabled("usb")) { + if (acpi_disabled("usb")) { return ENXIO; } status = acpi_uhub_find_rh(dev, &ah); @@ -315,60 +459,65 @@ ACPI_HANDLE ah = acpi_get_handle(dev); if (!acpi_disabled("usb") && ah && (uhub_probe(dev) <= 0)) { - /*success prior than non - acpi hub*/ - return (BUS_PROBE_DEFAULT + 1); + /* success prior than non - acpi hub */ + return (BUS_PROBE_DEFAULT + 1); } return (ENXIO); } -int -acpi_uhub_root_attach(device_t dev) + +static int +acpi_uhub_attach_common(device_t dev) { - ACPI_HANDLE devhandle; struct usb_hub *uh; struct acpi_uhub_softc *sc = device_get_softc(dev); int ret; - if ((ret = uhub_attach(dev)) != 0) { - return (ret); - } uh = sc->usc.sc_udev->hub; - if (ACPI_FAILURE(acpi_uhub_find_rh(dev, &devhandle)) || - (devhandle == NULL)) { - return ENXIO; - } - sc->nports = uh->nports; - sc->porthandle = malloc(sizeof(ACPI_HANDLE) * uh->nports, + sc->port = malloc(sizeof(struct acpi_uhub_port) * uh->nports, M_USBDEV, M_WAITOK | M_ZERO); - acpi_usb_hub_port_probe(dev, devhandle); + ret = acpi_usb_hub_port_probe(dev, sc->ah); - return 0; + return ret; } -int -acpi_uhub_attach(device_t dev) +static int +acpi_uhub_root_attach(device_t dev) { - struct usb_hub *uh; - struct acpi_uhub_softc *sc = device_get_softc(dev); - ACPI_HANDLE devhandle; int ret; + struct acpi_uhub_softc *sc = device_get_softc(dev); + if (ACPI_FAILURE(acpi_uhub_find_rh(dev, &sc->ah)) || + (sc->ah == NULL)) { + return ENXIO; + } if ((ret = uhub_attach(dev)) != 0) { return (ret); } - uh = sc->usc.sc_udev->hub; - devhandle = acpi_get_handle(dev); + ret = acpi_uhub_attach_common(dev); - if (devhandle == NULL) { + return ret; +} + +int +acpi_uhub_attach(device_t dev) +{ + int ret; + struct acpi_uhub_softc *sc = device_get_softc(dev); + + sc->ah = acpi_get_handle(dev); + + if (sc->ah == NULL) { return ENXIO; } - sc->nports = uh->nports; - sc->porthandle = malloc(sizeof(ACPI_HANDLE) * uh->nports, - M_USBDEV, M_WAITOK | M_ZERO); - acpi_usb_hub_port_probe(dev, acpi_get_handle(dev)); - return 0; + if ((ret = uhub_attach(dev)) != 0) { + return (ret); + } + ret = acpi_uhub_attach_common(dev); + + return ret; } int @@ -385,7 +534,7 @@ if ((idx == ACPI_IVAR_HANDLE) && (hres.portno > 0) && (hres.portno <= sc->nports) && - (ah = sc->porthandle[hres.portno - 1])) { + (ah = sc->port[hres.portno - 1].handle)) { *res = (uintptr_t)ah; return (0); } @@ -412,7 +561,7 @@ { struct acpi_uhub_softc *sc = device_get_softc(dev); - free(sc->porthandle, M_USBDEV); + free(sc->port, M_USBDEV); return uhub_detach(dev); }