Commit 7d6a31c3 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'x86-debug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 debug updates from Ingo Molnar:
 "The biggest update is the addition of USB3 debug port based
  early-console.

  Greg was fine with the USB changes and with the routing of these
  patches:

    https://www.spinics.net/lists/linux-usb/msg155093.html"

* 'x86-debug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  usb/doc: Add document for USB3 debug port usage
  usb/serial: Add DBC debug device support to usb_debug
  x86/earlyprintk: Add support for earlyprintk via USB3 debug port
  usb/early: Add driver for xhci debug capability
  x86/timers: Add simple udelay calibration
parents 2cc12e2e 1b326277
...@@ -988,6 +988,7 @@ ...@@ -988,6 +988,7 @@
earlyprintk=ttySn[,baudrate] earlyprintk=ttySn[,baudrate]
earlyprintk=dbgp[debugController#] earlyprintk=dbgp[debugController#]
earlyprintk=pciserial,bus:device.function[,baudrate] earlyprintk=pciserial,bus:device.function[,baudrate]
earlyprintk=xdbc[xhciController#]
earlyprintk is useful when the kernel crashes before earlyprintk is useful when the kernel crashes before
the normal console is initialized. It is not enabled by the normal console is initialized. It is not enabled by
......
===============
USB3 debug port
===============
:Author: Lu Baolu <baolu.lu@linux.intel.com>
:Date: March 2017
GENERAL
=======
This is a HOWTO for using the USB3 debug port on x86 systems.
Before using any kernel debugging functionality based on USB3
debug port, you need to::
1) check whether any USB3 debug port is available in
your system;
2) check which port is used for debugging purposes;
3) have a USB 3.0 super-speed A-to-A debugging cable.
INTRODUCTION
============
The xHCI debug capability (DbC) is an optional but standalone
functionality provided by the xHCI host controller. The xHCI
specification describes DbC in the section 7.6.
When DbC is initialized and enabled, it will present a debug
device through the debug port (normally the first USB3
super-speed port). The debug device is fully compliant with
the USB framework and provides the equivalent of a very high
performance full-duplex serial link between the debug target
(the system under debugging) and a debug host.
EARLY PRINTK
============
DbC has been designed to log early printk messages. One use for
this feature is kernel debugging. For example, when your machine
crashes very early before the regular console code is initialized.
Other uses include simpler, lockless logging instead of a full-
blown printk console driver and klogd.
On the debug target system, you need to customize a debugging
kernel with CONFIG_EARLY_PRINTK_USB_XDBC enabled. And, add below
kernel boot parameter::
"earlyprintk=xdbc"
If there are multiple xHCI controllers in your system, you can
append a host contoller index to this kernel parameter. This
index starts from 0.
Current design doesn't support DbC runtime suspend/resume. As
the result, you'd better disable runtime power management for
USB subsystem by adding below kernel boot parameter::
"usbcore.autosuspend=-1"
Before starting the debug target, you should connect the debug
port to a USB port (root port or port of any external hub) on
the debug host. The cable used to connect these two ports
should be a USB 3.0 super-speed A-to-A debugging cable.
During early boot of the debug target, DbC will be detected and
initialized. After initialization, the debug host should be able
to enumerate the debug device in debug target. The debug host
will then bind the debug device with the usb_debug driver module
and create the /dev/ttyUSB device.
If the debug device enumeration goes smoothly, you should be able
to see below kernel messages on the debug host::
# tail -f /var/log/kern.log
[ 1815.983374] usb 4-3: new SuperSpeed USB device number 4 using xhci_hcd
[ 1815.999595] usb 4-3: LPM exit latency is zeroed, disabling LPM.
[ 1815.999899] usb 4-3: New USB device found, idVendor=1d6b, idProduct=0004
[ 1815.999902] usb 4-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1815.999903] usb 4-3: Product: Remote GDB
[ 1815.999904] usb 4-3: Manufacturer: Linux
[ 1815.999905] usb 4-3: SerialNumber: 0001
[ 1816.000240] usb_debug 4-3:1.0: xhci_dbc converter detected
[ 1816.000360] usb 4-3: xhci_dbc converter now attached to ttyUSB0
You can use any communication program, for example minicom, to
read and view the messages. Below simple bash scripts can help
you to check the sanity of the setup.
.. code-block:: sh
===== start of bash scripts =============
#!/bin/bash
while true ; do
while [ ! -d /sys/class/tty/ttyUSB0 ] ; do
:
done
cat /dev/ttyUSB0
done
===== end of bash scripts ===============
...@@ -5,6 +5,9 @@ config TRACE_IRQFLAGS_SUPPORT ...@@ -5,6 +5,9 @@ config TRACE_IRQFLAGS_SUPPORT
source "lib/Kconfig.debug" source "lib/Kconfig.debug"
config EARLY_PRINTK_USB
bool
config X86_VERBOSE_BOOTUP config X86_VERBOSE_BOOTUP
bool "Enable verbose x86 bootup info messages" bool "Enable verbose x86 bootup info messages"
default y default y
...@@ -23,19 +26,20 @@ config EARLY_PRINTK ...@@ -23,19 +26,20 @@ config EARLY_PRINTK
This is useful for kernel debugging when your machine crashes very This is useful for kernel debugging when your machine crashes very
early before the console code is initialized. For normal operation early before the console code is initialized. For normal operation
it is not recommended because it looks ugly and doesn't cooperate it is not recommended because it looks ugly and doesn't cooperate
with klogd/syslogd or the X server. You should normally N here, with klogd/syslogd or the X server. You should normally say N here,
unless you want to debug such a crash. unless you want to debug such a crash.
config EARLY_PRINTK_DBGP config EARLY_PRINTK_DBGP
bool "Early printk via EHCI debug port" bool "Early printk via EHCI debug port"
depends on EARLY_PRINTK && PCI depends on EARLY_PRINTK && PCI
select EARLY_PRINTK_USB
---help--- ---help---
Write kernel log output directly into the EHCI debug port. Write kernel log output directly into the EHCI debug port.
This is useful for kernel debugging when your machine crashes very This is useful for kernel debugging when your machine crashes very
early before the console code is initialized. For normal operation early before the console code is initialized. For normal operation
it is not recommended because it looks ugly and doesn't cooperate it is not recommended because it looks ugly and doesn't cooperate
with klogd/syslogd or the X server. You should normally N here, with klogd/syslogd or the X server. You should normally say N here,
unless you want to debug such a crash. You need usb debug device. unless you want to debug such a crash. You need usb debug device.
config EARLY_PRINTK_EFI config EARLY_PRINTK_EFI
...@@ -48,6 +52,25 @@ config EARLY_PRINTK_EFI ...@@ -48,6 +52,25 @@ config EARLY_PRINTK_EFI
This is useful for kernel debugging when your machine crashes very This is useful for kernel debugging when your machine crashes very
early before the console code is initialized. early before the console code is initialized.
config EARLY_PRINTK_USB_XDBC
bool "Early printk via the xHCI debug port"
depends on EARLY_PRINTK && PCI
select EARLY_PRINTK_USB
---help---
Write kernel log output directly into the xHCI debug port.
One use for this feature is kernel debugging, for example when your
machine crashes very early before the regular console code is
initialized. Other uses include simpler, lockless logging instead of
a full-blown printk console driver + klogd.
For normal production environments this is normally not recommended,
because it doesn't feed events into klogd/syslogd and doesn't try to
print anything on the screen.
You should normally say N here, unless you want to debug early
crashes or need a very simple printk logging facility.
config X86_PTDUMP_CORE config X86_PTDUMP_CORE
def_bool n def_bool n
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <asm/intel-mid.h> #include <asm/intel-mid.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
#include <linux/usb/ehci_def.h> #include <linux/usb/ehci_def.h>
#include <linux/usb/xhci-dbgp.h>
#include <linux/efi.h> #include <linux/efi.h>
#include <asm/efi.h> #include <asm/efi.h>
#include <asm/pci_x86.h> #include <asm/pci_x86.h>
...@@ -381,6 +382,10 @@ static int __init setup_early_printk(char *buf) ...@@ -381,6 +382,10 @@ static int __init setup_early_printk(char *buf)
if (!strncmp(buf, "efi", 3)) if (!strncmp(buf, "efi", 3))
early_console_register(&early_efi_console, keep); early_console_register(&early_efi_console, keep);
#endif #endif
#ifdef CONFIG_EARLY_PRINTK_USB_XDBC
if (!strncmp(buf, "xdbc", 4))
early_xdbc_parse_parameter(buf + 4);
#endif
buf++; buf++;
} }
......
...@@ -70,6 +70,7 @@ ...@@ -70,6 +70,7 @@
#include <linux/tboot.h> #include <linux/tboot.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/usb/xhci-dbgp.h>
#include <video/edid.h> #include <video/edid.h>
#include <asm/mtrr.h> #include <asm/mtrr.h>
...@@ -811,6 +812,26 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p) ...@@ -811,6 +812,26 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
return 0; return 0;
} }
static void __init simple_udelay_calibration(void)
{
unsigned int tsc_khz, cpu_khz;
unsigned long lpj;
if (!boot_cpu_has(X86_FEATURE_TSC))
return;
cpu_khz = x86_platform.calibrate_cpu();
tsc_khz = x86_platform.calibrate_tsc();
tsc_khz = tsc_khz ? : cpu_khz;
if (!tsc_khz)
return;
lpj = tsc_khz * 1000;
do_div(lpj, HZ);
loops_per_jiffy = lpj;
}
/* /*
* Determine if we were loaded by an EFI loader. If so, then we have also been * Determine if we were loaded by an EFI loader. If so, then we have also been
* passed the efi memmap, systab, etc., so we should use these data structures * passed the efi memmap, systab, etc., so we should use these data structures
...@@ -959,6 +980,8 @@ void __init setup_arch(char **cmdline_p) ...@@ -959,6 +980,8 @@ void __init setup_arch(char **cmdline_p)
*/ */
x86_configure_nx(); x86_configure_nx();
simple_udelay_calibration();
parse_early_param(); parse_early_param();
#ifdef CONFIG_MEMORY_HOTPLUG #ifdef CONFIG_MEMORY_HOTPLUG
...@@ -1095,6 +1118,9 @@ void __init setup_arch(char **cmdline_p) ...@@ -1095,6 +1118,9 @@ void __init setup_arch(char **cmdline_p)
memblock_set_current_limit(ISA_END_ADDRESS); memblock_set_current_limit(ISA_END_ADDRESS);
e820__memblock_setup(); e820__memblock_setup();
if (!early_xdbc_setup_hardware())
early_xdbc_register_console();
reserve_bios_regions(); reserve_bios_regions();
if (efi_enabled(EFI_MEMMAP)) { if (efi_enabled(EFI_MEMMAP)) {
......
...@@ -49,7 +49,7 @@ obj-$(CONFIG_USB_MICROTEK) += image/ ...@@ -49,7 +49,7 @@ obj-$(CONFIG_USB_MICROTEK) += image/
obj-$(CONFIG_USB_SERIAL) += serial/ obj-$(CONFIG_USB_SERIAL) += serial/
obj-$(CONFIG_USB) += misc/ obj-$(CONFIG_USB) += misc/
obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/ obj-$(CONFIG_EARLY_PRINTK_USB) += early/
obj-$(CONFIG_USB_ATM) += atm/ obj-$(CONFIG_USB_ATM) += atm/
obj-$(CONFIG_USB_SPEEDTOUCH) += atm/ obj-$(CONFIG_USB_SPEEDTOUCH) += atm/
......
...@@ -3,3 +3,4 @@ ...@@ -3,3 +3,4 @@
# #
obj-$(CONFIG_EARLY_PRINTK_DBGP) += ehci-dbgp.o obj-$(CONFIG_EARLY_PRINTK_DBGP) += ehci-dbgp.o
obj-$(CONFIG_EARLY_PRINTK_USB_XDBC) += xhci-dbc.o
This diff is collapsed.
/*
* xhci-dbc.h - xHCI debug capability early driver
*
* Copyright (C) 2016 Intel Corporation
*
* Author: Lu Baolu <baolu.lu@linux.intel.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef __LINUX_XHCI_DBC_H
#define __LINUX_XHCI_DBC_H
#include <linux/types.h>
#include <linux/usb/ch9.h>
/*
* xHCI Debug Capability Register interfaces:
*/
struct xdbc_regs {
__le32 capability;
__le32 doorbell;
__le32 ersts; /* Event Ring Segment Table Size*/
__le32 __reserved_0; /* 0c~0f reserved bits */
__le64 erstba; /* Event Ring Segment Table Base Address */
__le64 erdp; /* Event Ring Dequeue Pointer */
__le32 control;
__le32 status;
__le32 portsc; /* Port status and control */
__le32 __reserved_1; /* 2b~28 reserved bits */
__le64 dccp; /* Debug Capability Context Pointer */
__le32 devinfo1; /* Device Descriptor Info Register 1 */
__le32 devinfo2; /* Device Descriptor Info Register 2 */
};
#define DEBUG_MAX_BURST(p) (((p) >> 16) & 0xff)
#define CTRL_DBC_RUN BIT(0)
#define CTRL_PORT_ENABLE BIT(1)
#define CTRL_HALT_OUT_TR BIT(2)
#define CTRL_HALT_IN_TR BIT(3)
#define CTRL_DBC_RUN_CHANGE BIT(4)
#define CTRL_DBC_ENABLE BIT(31)
#define DCST_DEBUG_PORT(p) (((p) >> 24) & 0xff)
#define PORTSC_CONN_STATUS BIT(0)
#define PORTSC_CONN_CHANGE BIT(17)
#define PORTSC_RESET_CHANGE BIT(21)
#define PORTSC_LINK_CHANGE BIT(22)
#define PORTSC_CONFIG_CHANGE BIT(23)
/*
* xHCI Debug Capability data structures:
*/
struct xdbc_trb {
__le32 field[4];
};
struct xdbc_erst_entry {
__le64 seg_addr;
__le32 seg_size;
__le32 __reserved_0;
};
struct xdbc_info_context {
__le64 string0;
__le64 manufacturer;
__le64 product;
__le64 serial;
__le32 length;
__le32 __reserved_0[7];
};
struct xdbc_ep_context {
__le32 ep_info1;
__le32 ep_info2;
__le64 deq;
__le32 tx_info;
__le32 __reserved_0[11];
};
struct xdbc_context {
struct xdbc_info_context info;
struct xdbc_ep_context out;
struct xdbc_ep_context in;
};
#define XDBC_INFO_CONTEXT_SIZE 48
#define XDBC_MAX_STRING_LENGTH 64
#define XDBC_STRING_MANUFACTURER "Linux"
#define XDBC_STRING_PRODUCT "Remote GDB"
#define XDBC_STRING_SERIAL "0001"
struct xdbc_strings {
char string0[XDBC_MAX_STRING_LENGTH];
char manufacturer[XDBC_MAX_STRING_LENGTH];
char product[XDBC_MAX_STRING_LENGTH];
char serial[XDBC_MAX_STRING_LENGTH];
};
#define XDBC_PROTOCOL 1 /* GNU Remote Debug Command Set */
#define XDBC_VENDOR_ID 0x1d6b /* Linux Foundation 0x1d6b */
#define XDBC_PRODUCT_ID 0x0004 /* __le16 idProduct; device 0004 */
#define XDBC_DEVICE_REV 0x0010 /* 0.10 */
/*
* xHCI Debug Capability software state structures:
*/
struct xdbc_segment {
struct xdbc_trb *trbs;
dma_addr_t dma;
};
#define XDBC_TRBS_PER_SEGMENT 256
struct xdbc_ring {
struct xdbc_segment *segment;
struct xdbc_trb *enqueue;
struct xdbc_trb *dequeue;
u32 cycle_state;
};
#define XDBC_EPID_OUT 2
#define XDBC_EPID_IN 3
struct xdbc_state {
u16 vendor;
u16 device;
u32 bus;
u32 dev;
u32 func;
void __iomem *xhci_base;
u64 xhci_start;
size_t xhci_length;
int port_number;
/* DbC register base */
struct xdbc_regs __iomem *xdbc_reg;
/* DbC table page */
dma_addr_t table_dma;
void *table_base;
/* event ring segment table */
dma_addr_t erst_dma;
size_t erst_size;
void *erst_base;
/* event ring segments */
struct xdbc_ring evt_ring;
struct xdbc_segment evt_seg;
/* debug capability contexts */
dma_addr_t dbcc_dma;
size_t dbcc_size;
void *dbcc_base;
/* descriptor strings */
dma_addr_t string_dma;
size_t string_size;
void *string_base;
/* bulk OUT endpoint */
struct xdbc_ring out_ring;
struct xdbc_segment out_seg;
void *out_buf;
dma_addr_t out_dma;
/* bulk IN endpoint */
struct xdbc_ring in_ring;
struct xdbc_segment in_seg;
void *in_buf;
dma_addr_t in_dma;
u32 flags;
/* spinlock for early_xdbc_write() reentrancy */
raw_spinlock_t lock;
};
#define XDBC_PCI_MAX_BUSES 256
#define XDBC_PCI_MAX_DEVICES 32
#define XDBC_PCI_MAX_FUNCTION 8
#define XDBC_TABLE_ENTRY_SIZE 64
#define XDBC_ERST_ENTRY_NUM 1
#define XDBC_DBCC_ENTRY_NUM 3
#define XDBC_STRING_ENTRY_NUM 4
/* Bits definitions for xdbc_state.flags: */
#define XDBC_FLAGS_INITIALIZED BIT(0)
#define XDBC_FLAGS_IN_STALL BIT(1)
#define XDBC_FLAGS_OUT_STALL BIT(2)
#define XDBC_FLAGS_IN_PROCESS BIT(3)
#define XDBC_FLAGS_OUT_PROCESS BIT(4)
#define XDBC_FLAGS_CONFIGURED BIT(5)
#define XDBC_MAX_PACKET 1024
/* Door bell target: */
#define OUT_EP_DOORBELL 0
#define IN_EP_DOORBELL 1
#define DOOR_BELL_TARGET(p) (((p) & 0xff) << 8)
#define xdbc_read64(regs) xhci_read_64(NULL, (regs))
#define xdbc_write64(val, regs) xhci_write_64(NULL, (val), (regs))
#endif /* __LINUX_XHCI_DBC_H */
...@@ -32,7 +32,18 @@ static const struct usb_device_id id_table[] = { ...@@ -32,7 +32,18 @@ static const struct usb_device_id id_table[] = {
{ USB_DEVICE(0x0525, 0x127a) }, { USB_DEVICE(0x0525, 0x127a) },
{ }, { },
}; };
MODULE_DEVICE_TABLE(usb, id_table);
static const struct usb_device_id dbc_id_table[] = {
{ USB_DEVICE(0x1d6b, 0x0004) },
{ },
};
static const struct usb_device_id id_table_combined[] = {
{ USB_DEVICE(0x0525, 0x127a) },
{ USB_DEVICE(0x1d6b, 0x0004) },
{ },
};
MODULE_DEVICE_TABLE(usb, id_table_combined);
/* This HW really does not support a serial break, so one will be /* This HW really does not support a serial break, so one will be
* emulated when ever the break state is set to true. * emulated when ever the break state is set to true.
...@@ -71,9 +82,20 @@ static struct usb_serial_driver debug_device = { ...@@ -71,9 +82,20 @@ static struct usb_serial_driver debug_device = {
.process_read_urb = usb_debug_process_read_urb, .process_read_urb = usb_debug_process_read_urb,
}; };
static struct usb_serial_driver dbc_device = {
.driver = {
.owner = THIS_MODULE,
.name = "xhci_dbc",
},
.id_table = dbc_id_table,
.num_ports = 1,
.break_ctl = usb_debug_break_ctl,
.process_read_urb = usb_debug_process_read_urb,
};
static struct usb_serial_driver * const serial_drivers[] = { static struct usb_serial_driver * const serial_drivers[] = {
&debug_device, NULL &debug_device, &dbc_device, NULL
}; };
module_usb_serial_driver(serial_drivers, id_table); module_usb_serial_driver(serial_drivers, id_table_combined);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
/*
* Standalone xHCI debug capability driver
*
* Copyright (C) 2016 Intel Corporation
*
* Author: Lu Baolu <baolu.lu@linux.intel.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef __LINUX_XHCI_DBGP_H
#define __LINUX_XHCI_DBGP_H
#ifdef CONFIG_EARLY_PRINTK_USB_XDBC
int __init early_xdbc_parse_parameter(char *s);
int __init early_xdbc_setup_hardware(void);
void __init early_xdbc_register_console(void);
#else
static inline int __init early_xdbc_setup_hardware(void)
{
return -ENODEV;
}
static inline void __init early_xdbc_register_console(void)
{
}
#endif /* CONFIG_EARLY_PRINTK_USB_XDBC */
#endif /* __LINUX_XHCI_DBGP_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment