diff options
author | Ian Moffett <ian@osmora.org> | 2025-10-11 19:54:48 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-10-11 19:54:48 -0400 |
commit | ec64baba95195e4e124e4c9112fd286677f6fce5 (patch) | |
tree | 2c96719a857563de0398b14da855a1beff5f2d31 /src | |
parent | 0552d8126be3f2ea9f03098afb5cb77049c8d606 (diff) |
kern: usb: Extract HCSPARAMS1 register fields
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/include/io/usb/xhciregs.h | 9 | ||||
-rw-r--r-- | src/sys/include/io/usb/xhcivar.h | 6 | ||||
-rw-r--r-- | src/sys/io/usb/hcd/xhci.c | 14 |
3 files changed, 28 insertions, 1 deletions
diff --git a/src/sys/include/io/usb/xhciregs.h b/src/sys/include/io/usb/xhciregs.h index 85a8630..726d883 100644 --- a/src/sys/include/io/usb/xhciregs.h +++ b/src/sys/include/io/usb/xhciregs.h @@ -85,6 +85,15 @@ struct __packed xhci_opregs { #define USBSTS_CNR BIT(11) /* Controller not ready */ /* + * USB structural parameters 1 register bits + * + * See section 5.3.3 of the xHCI spec + */ +#define HCSPARAMS1_MAXSLOTS(HCSPARAMS1) ((HCSPARAMS1) & 0xFF) +#define HCSPARAMS1_MAXINTRS(HCSPARAMS1) (((HCSPARAMS1) >> 8) & 0x7FF) +#define HCSPARAMS1_MAXPORTS(HCSPARAMS1) (((HCSPARAMS1) >> 24) & 0xFF) + +/* * Macros to get various register spaces */ #define XHCI_OPBASE(CAPBASE) \ diff --git a/src/sys/include/io/usb/xhcivar.h b/src/sys/include/io/usb/xhcivar.h index c0b3a39..bc5f59b 100644 --- a/src/sys/include/io/usb/xhcivar.h +++ b/src/sys/include/io/usb/xhcivar.h @@ -37,9 +37,15 @@ * Represents the host controller * * @io: I/O space + * @max_slots: Max device slots + * @max_intrs: Max interrupters + * @max_ports: Max ports */ struct xhci_hcd { struct xhci_capregs *capspace; + uint8_t max_slots; + uint32_t max_intrs; + uint32_t max_ports; }; #define XHCI_TIMEOUT_MSEC 500 diff --git a/src/sys/io/usb/hcd/xhci.c b/src/sys/io/usb/hcd/xhci.c index f363bcf..0125e96 100644 --- a/src/sys/io/usb/hcd/xhci.c +++ b/src/sys/io/usb/hcd/xhci.c @@ -137,7 +137,8 @@ static int xhci_init_hc(struct xhci_hcd *hcd) { struct xhci_opregs *opregs; - uint32_t usbcmd; + struct xhci_capregs *capspace; + uint32_t usbcmd, hcsparams1; int error; if (hcd == NULL) { @@ -147,6 +148,17 @@ xhci_init_hc(struct xhci_hcd *hcd) if ((error = xhci_reset_hc(hcd)) < 0) { return error; } + + if ((capspace = hcd->capspace) == NULL) { + return -EIO; + } + + /* Get the structural params 1 */ + opregs = XHCI_OPBASE(capspace); + hcsparams1 = mmio_read32(&capspace->hcsparams1); + hcd->max_slots = HCSPARAMS1_MAXSLOTS(hcsparams1); + hcd->max_intrs = HCSPARAMS1_MAXINTRS(hcsparams1); + hcd->max_ports = HCSPARAMS1_MAXPORTS(hcsparams1); return 0; } |