From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: migo.oravec@gmail.com
Cc: <linux-usb@vger.kernel.org>, <gregkh@linuxfoundation.org>,
Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [RFT PATCH] usb: early: xhci-dbc: Try smaller early_ioremap size if original size fails
Date: Fri, 24 Oct 2025 18:41:57 +0300 [thread overview]
Message-ID: <20251024154157.40800-1-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <8fe27842-8155-44db-b262-a148b5ce5436@linux.intel.com>
Retry early_ioremap() with smaller sizes down to 4k if original size for
remap fails.
Walk the xHCI capabilitues manually while looking for the DbC capability
offset. Making sure we don't go over the new ioremap size limit.
DbC capability is 64bytes itself.
If we are lucky then the vendor has put DbC capability early in the
mmio range, and we can work with a reduced ioremap size
TESTPATCH, Hack with pr_warn() messages
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
drivers/usb/early/xhci-dbc.c | 38 +++++++++++++++++++++++++++++++++---
drivers/usb/early/xhci-dbc.h | 1 +
2 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c
index 41118bba9197..9a7f3f12f18f 100644
--- a/drivers/usb/early/xhci-dbc.c
+++ b/drivers/usb/early/xhci-dbc.c
@@ -85,8 +85,18 @@ static void __iomem * __init xdbc_map_pci_mmio(u32 bus, u32 dev, u32 func)
xdbc.xhci_start = val64;
xdbc.xhci_length = sz64;
+ xdbc.xhci_orig_length = sz64;
+retry:
base = early_ioremap(val64, sz64);
+ if (!base && sz64 > 0x1000) {
+ pr_warn("Failed to ioremap xhci-dbc with size 0x%llx\n", sz64);
+ sz64 = sz64 >> 1;
+ pr_warn("Retry xhci-dbc ioremap with reduced size 0x%llx\n", sz64);
+ xdbc.xhci_length = sz64;
+ goto retry;
+ }
+
return base;
}
@@ -601,7 +611,8 @@ static int __init xdbc_early_setup(void)
int __init early_xdbc_parse_parameter(char *s, int keep_early)
{
unsigned long dbgp_num = 0;
- u32 bus, dev, func, offset;
+ u32 bus, dev, func, offset = 0;
+ u32 val;
char *e;
int ret;
@@ -640,15 +651,36 @@ int __init early_xdbc_parse_parameter(char *s, int keep_early)
return -EINVAL;
/* Locate DbC registers: */
- offset = xhci_find_next_ext_cap(xdbc.xhci_base, 0, XHCI_EXT_CAPS_DEBUG);
+ if (xdbc.xhci_length == xdbc.xhci_orig_length) {
+ offset = xhci_find_next_ext_cap(xdbc.xhci_base, 0, XHCI_EXT_CAPS_DEBUG);
+ } else {
+ /*
+ * Mapped mmio size cut short from what xhci needs.
+ * Check if this dBc capability is withing the new cut size.
+ * DbC capability needs 64 bytes from its capabilty offset.
+ */
+ do {
+ offset = xhci_find_next_ext_cap(xdbc.xhci_base, offset, 0);
+ if (!offset || (offset + 64 >= xdbc.xhci_length)) {
+ pr_warn("Bad DbC offset 0x%x, max 0x%lx", offset, xdbc.xhci_length);
+ offset = 0;
+ break;
+ }
+ pr_warn("Looking for DbC capability at offset 0x%x", offset);
+ val = readl(xdbc.xhci_base + offset);
+ } while (XHCI_EXT_CAPS_ID(val) != XHCI_EXT_CAPS_DEBUG);
+ }
+
if (!offset) {
- pr_notice("xhci host doesn't support debug capability\n");
+ pr_warn("xhci host doesn't support debug capability\n");
early_iounmap(xdbc.xhci_base, xdbc.xhci_length);
xdbc.xhci_base = NULL;
xdbc.xhci_length = 0;
return -ENODEV;
}
+ pr_warn("DbC capability found at offset 0x%x", offset);
+
xdbc.xdbc_reg = (struct xdbc_regs __iomem *)(xdbc.xhci_base + offset);
return 0;
diff --git a/drivers/usb/early/xhci-dbc.h b/drivers/usb/early/xhci-dbc.h
index 8b4d71de45fc..5c3855862569 100644
--- a/drivers/usb/early/xhci-dbc.h
+++ b/drivers/usb/early/xhci-dbc.h
@@ -146,6 +146,7 @@ struct xdbc_state {
void __iomem *xhci_base;
u64 xhci_start;
size_t xhci_length;
+ size_t xhci_orig_length;
int port_number;
/* DbC register base */
--
2.43.0
next prev parent reply other threads:[~2025-10-24 15:42 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAAcb1K_MJKWz+BYJmx0FDgrBOzzXm71-M7sgHDUOmBRppXWNzA@mail.gmail.com>
2025-10-15 7:43 ` Fwd: USB DBC hang during earlyprintk initialization Milan Oravec
2025-10-15 9:13 ` Greg KH
2025-10-15 19:11 ` Milan Oravec
2025-10-16 13:42 ` Mathias Nyman
2025-10-16 14:31 ` Milan Oravec
2025-10-16 20:49 ` Mathias Nyman
2025-10-20 6:43 ` Milan Oravec
2025-10-24 15:36 ` Mathias Nyman
2025-10-24 15:41 ` Mathias Nyman [this message]
2025-10-26 2:32 ` [RFT PATCH] usb: early: xhci-dbc: Try smaller early_ioremap size if original size fails kernel test robot
2025-10-24 18:48 ` Fwd: USB DBC hang during earlyprintk initialization Milan Oravec
2025-10-27 9:34 ` Mathias Nyman
2025-10-28 10:13 ` Mathias Nyman
2025-10-28 13:29 ` Milan Oravec
2025-10-28 17:19 ` Mathias Nyman
2025-10-28 18:10 ` Milan Oravec
2025-10-31 13:15 ` Milan Oravec
2025-12-04 20:46 ` Mathias Nyman
2025-12-05 7:18 ` Milan Oravec
2025-12-05 18:49 ` Milan Oravec
2025-12-17 9:20 ` Mathias Nyman
2025-12-18 20:03 ` Milan Oravec
2026-01-19 8:18 ` Milan Oravec
2026-01-19 11:01 ` Milan Oravec
2026-04-01 15:58 ` Milan Oravec
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251024154157.40800-1-mathias.nyman@linux.intel.com \
--to=mathias.nyman@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=migo.oravec@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox