Changes in 5.15.47
pcmcia: db1xxx_ss: restrict to MIPS_DB1XXX boards
staging: greybus: codecs: fix type confusion of list iterator variable
iio: adc: ad7124: Remove shift from scan_type
lkdtm/bugs: Check for the NULL pointer after calling kmalloc
lkdtm/bugs: Don't expect thread termination without CONFIG_UBSAN_TRAP
tty: goldfish: Use tty_port_destroy() to destroy port
tty: serial: owl: Fix missing clk_disable_unprepare() in owl_uart_probe
tty: n_tty: Restore EOF push handling behavior
serial: 8250_aspeed_vuart: Fix potential NULL dereference in aspeed_vuart_probe
tty: serial: fsl_lpuart: fix potential bug when using both of_alias_get_id and ida_simple_get
remoteproc: imx_rproc: Ignore create mem entry for resource table
usb: usbip: fix a refcount leak in stub_probe()
usb: usbip: add missing device lock on tweak configuration cmd
USB: storage: karma: fix rio_karma_init return
usb: musb: Fix missing of_node_put() in omap2430_probe
staging: fieldbus: Fix the error handling path in anybuss_host_common_probe()
pwm: lp3943: Fix duty calculation in case period was clamped
pwm: raspberrypi-poe: Fix endianness in firmware struct
rpmsg: qcom_smd: Fix irq_of_parse_and_map() return value
usb: dwc3: gadget: Replace list_for_each_entry_safe() if using giveback
usb: dwc3: pci: Fix pm_runtime_get_sync() error checking
misc: fastrpc: fix an incorrect NULL check on list iterator
firmware: stratix10-svc: fix a missing check on list iterator
usb: typec: mux: Check dev_set_name() return value
rpmsg: virtio: Fix possible double free in rpmsg_probe()
rpmsg: virtio: Fix possible double free in rpmsg_virtio_add_ctrl_dev()
rpmsg: virtio: Fix the unregistration of the device rpmsg_ctrl
iio: adc: stmpe-adc: Fix wait_for_completion_timeout return value check
iio: proximity: vl53l0x: Fix return value check of wait_for_completion_timeout
iio: adc: sc27xx: fix read big scale voltage not right
iio: adc: sc27xx: Fine tune the scale calibration values
rpmsg: qcom_smd: Fix returning 0 if irq_of_parse_and_map() fails
pvpanic: Fix typos in the comments
misc/pvpanic: Convert regular spinlock into trylock on panic path
phy: qcom-qmp: fix pipe-clock imbalance on power-on failure
power: supply: axp288_fuel_gauge: Drop BIOS version check from "T3 MRD" DMI quirk
serial: sifive: Report actual baud base rather than fixed 115200
export: fix string handling of namespace in EXPORT_SYMBOL_NS
soundwire: intel: prevent pm_runtime resume prior to system suspend
coresight: cpu-debug: Replace mutex with mutex_trylock on panic notifier
ksmbd: fix reference count leak in smb_check_perm_dacl()
extcon: ptn5150: Add queue work sync before driver release
soc: rockchip: Fix refcount leak in rockchip_grf_init
clocksource/drivers/riscv: Events are stopped during CPU suspend
ARM: dts: aspeed: ast2600-evb: Enable RX delay for MAC0/MAC1
rtc: mt6397: check return value after calling platform_get_resource()
rtc: ftrtc010: Use platform_get_irq() to get the interrupt
rtc: ftrtc010: Fix error handling in ftrtc010_rtc_probe
staging: r8188eu: add check for kzalloc
tty: n_gsm: Don't ignore write return value in gsmld_output()
tty: n_gsm: Fix packet data hex dump output
serial: meson: acquire port->lock in startup()
serial: 8250_fintek: Check SER_RS485_RTS_* only with RS485
serial: cpm_uart: Fix build error without CONFIG_SERIAL_CPM_CONSOLE
serial: digicolor-usart: Don't allow CS5-6
serial: rda-uart: Don't allow CS5-6
serial: txx9: Don't allow CS5-6
serial: sh-sci: Don't allow CS5-6
serial: sifive: Sanitize CSIZE and c_iflag
serial: st-asc: Sanitize CSIZE and correct PARENB for CS7
serial: stm32-usart: Correct CSIZE, bits, and parity
firmware: dmi-sysfs: Fix memory leak in dmi_sysfs_register_handle
bus: ti-sysc: Fix warnings for unbind for serial
driver: base: fix UAF when driver_attach failed
driver core: fix deadlock in __device_attach
watchdog: rti-wdt: Fix pm_runtime_get_sync() error checking
watchdog: ts4800_wdt: Fix refcount leak in ts4800_wdt_probe
blk-mq: don't touch ->tagset in blk_mq_get_sq_hctx
ASoC: fsl_sai: Fix FSL_SAI_xDR/xFR definition
clocksource/drivers/oxnas-rps: Fix irq_of_parse_and_map() return value
s390/crypto: fix scatterwalk_unmap() callers in AES-GCM
net: sched: fixed barrier to prevent skbuff sticking in qdisc backlog
net: ethernet: mtk_eth_soc: out of bounds read in mtk_hwlro_get_fdir_entry()
net: ethernet: ti: am65-cpsw-nuss: Fix some refcount leaks
net: dsa: mv88e6xxx: Fix refcount leak in mv88e6xxx_mdios_register
modpost: fix removing numeric suffixes
jffs2: fix memory leak in jffs2_do_fill_super
ubi: fastmap: Fix high cpu usage of ubi_bgt by making sure wl_pool not empty
ubi: ubi_create_volume: Fix use-after-free when volume creation failed
selftests/bpf: fix selftest after random: Urandom_read tracepoint removal
selftests/bpf: fix stacktrace_build_id with missing kprobe/urandom_read
bpf: Fix probe read error in ___bpf_prog_run()
block: take destination bvec offsets into account in bio_copy_data_iter
riscv: read-only pages should not be writable
net/smc: fixes for converting from "struct smc_cdc_tx_pend **" to "struct smc_wr_tx_pend_priv *"
tcp: add accessors to read/set tp->snd_cwnd
nfp: only report pause frame configuration for physical device
sfc: fix considering that all channels have TX queues
sfc: fix wrong tx channel offset with efx_separate_tx_channels
block: make bioset_exit() fully resilient against being called twice
vdpa: Fix error logic in vdpa_nl_cmd_dev_get_doit
virtio: pci: Fix an error handling path in vp_modern_probe()
net/mlx5: Don't use already freed action pointer
net/mlx5e: TC NIC mode, fix tc chains miss table
net/mlx5: CT: Fix header-rewrite re-use for tupels
net/mlx5: correct ECE offset in query qp output
net/mlx5e: Update netdev features after changing XDP state
net: sched: add barrier to fix packet stuck problem for lockless qdisc
tcp: tcp_rtx_synack() can be called from process context
vdpa: ifcvf: set pci driver data in probe
octeontx2-af: fix error code in is_valid_offset()
s390/mcck: isolate SIE instruction when setting CIF_MCCK_GUEST flag
regulator: mt6315-regulator: fix invalid allowed mode
gpio: pca953x: use the correct register address to do regcache sync
afs: Fix infinite loop found by xfstest generic/676
scsi: sd: Fix potential NULL pointer dereference
tipc: check attribute length for bearer name
driver core: Fix wait_for_device_probe() & deferred_probe_timeout interaction
perf c2c: Fix sorting in percent_rmt_hitm_cmp()
dmaengine: idxd: set DMA_INTERRUPT cap bit
mips: cpc: Fix refcount leak in mips_cpc_default_phys_base
bootconfig: Make the bootconfig.o as a normal object file
tracing: Make tp_printk work on syscall tracepoints
tracing: Fix sleeping function called from invalid context on RT kernel
tracing: Avoid adding tracer option before update_tracer_options
iommu/arm-smmu: fix possible null-ptr-deref in arm_smmu_device_probe()
iommu/arm-smmu-v3: check return value after calling platform_get_resource()
f2fs: remove WARN_ON in f2fs_is_valid_blkaddr
i2c: cadence: Increase timeout per message if necessary
m68knommu: set ZERO_PAGE() to the allocated zeroed page
m68knommu: fix undefined reference to `_init_sp'
dmaengine: zynqmp_dma: In struct zynqmp_dma_chan fix desc_size data type
NFSv4: Don't hold the layoutget locks across multiple RPC calls
video: fbdev: hyperv_fb: Allow resolutions with size > 64 MB for Gen1
video: fbdev: pxa3xx-gcu: release the resources correctly in pxa3xx_gcu_probe/remove()
RISC-V: use memcpy for kexec_file mode
m68knommu: fix undefined reference to `mach_get_rtc_pll'
f2fs: fix to tag gcing flag on page during file defragment
xprtrdma: treat all calls not a bcall when bc_serv is NULL
drm/bridge: sn65dsi83: Fix an error handling path in sn65dsi83_probe()
drm/bridge: ti-sn65dsi83: Handle dsi_lanes == 0 as invalid
netfilter: nat: really support inet nat without l3 address
netfilter: nf_tables: use kfree_rcu(ptr, rcu) to release hooks in clean_net path
netfilter: nf_tables: delete flowtable hooks via transaction list
powerpc/kasan: Force thread size increase with KASAN
SUNRPC: Trap RDMA segment overflows
netfilter: nf_tables: always initialize flowtable hook list in transaction
ata: pata_octeon_cf: Fix refcount leak in octeon_cf_probe
netfilter: nf_tables: release new hooks on unsupported flowtable flags
netfilter: nf_tables: memleak flow rule from commit path
netfilter: nf_tables: bail out early if hardware offload is not supported
xen: unexport __init-annotated xen_xlate_map_ballooned_pages()
stmmac: intel: Fix an error handling path in intel_eth_pci_probe()
af_unix: Fix a data-race in unix_dgram_peer_wake_me().
bpf, arm64: Clear prog->jited_len along prog->jited
net: dsa: lantiq_gswip: Fix refcount leak in gswip_gphy_fw_list
net/mlx4_en: Fix wrong return value on ioctl EEPROM query failure
i40e: xsk: Move tmp desc array from driver to pool
xsk: Fix handling of invalid descriptors in XSK TX batching API
SUNRPC: Fix the calculation of xdr->end in xdr_get_next_encode_buffer()
net: mdio: unexport __init-annotated mdio_bus_init()
net: xfrm: unexport __init-annotated xfrm4_protocol_init()
net: ipv6: unexport __init-annotated seg6_hmac_init()
net/mlx5: Lag, filter non compatible devices
net/mlx5: Fix mlx5_get_next_dev() peer device matching
net/mlx5: Rearm the FW tracer after each tracer event
net/mlx5: fs, fail conflicting actions
ip_gre: test csum_start instead of transport header
net: altera: Fix refcount leak in altera_tse_mdio_create
net: dsa: mv88e6xxx: use BMSR_ANEGCOMPLETE bit for filling an_complete
tcp: use alloc_large_system_hash() to allocate table_perturb
drm: imx: fix compiler warning with gcc-12
nfp: flower: restructure flow-key for gre+vlan combination
iov_iter: Fix iter_xarray_get_pages{,_alloc}()
iio: dummy: iio_simple_dummy: check the return value of kstrdup()
staging: rtl8712: fix a potential memory leak in r871xu_drv_init()
iio: st_sensors: Add a local lock for protecting odr
lkdtm/usercopy: Expand size of "out of frame" object
drivers: staging: rtl8723bs: Fix deadlock in rtw_surveydone_event_callback()
drivers: staging: rtl8192bs: Fix deadlock in rtw_joinbss_event_prehandle()
tty: synclink_gt: Fix null-pointer-dereference in slgt_clean()
tty: Fix a possible resource leak in icom_probe
thunderbolt: Use different lane for second DisplayPort tunnel
drivers: staging: rtl8192u: Fix deadlock in ieee80211_beacons_stop()
drivers: staging: rtl8192e: Fix deadlock in rtllib_beacons_stop()
USB: host: isp116x: check return value after calling platform_get_resource()
drivers: tty: serial: Fix deadlock in sa1100_set_termios()
drivers: usb: host: Fix deadlock in oxu_bus_suspend()
USB: hcd-pci: Fully suspend across freeze/thaw cycle
char: xillybus: fix a refcount leak in cleanup_dev()
sysrq: do not omit current cpu when showing backtrace of all active CPUs
usb: dwc2: gadget: don't reset gadget's driver->bus
soundwire: qcom: adjust autoenumeration timeout
misc: rtsx: set NULL intfdata when probe fails
extcon: Fix extcon_get_extcon_dev() error handling
extcon: Modify extcon device to be created after driver data is set
clocksource/drivers/sp804: Avoid error on multiple instances
staging: rtl8712: fix uninit-value in usb_read8() and friends
staging: rtl8712: fix uninit-value in r871xu_drv_init()
serial: msm_serial: disable interrupts in __msm_console_write()
kernfs: Separate kernfs_pr_cont_buf and rename_lock.
watchdog: wdat_wdt: Stop watchdog when rebooting the system
md: protect md_unregister_thread from reentrancy
scsi: myrb: Fix up null pointer access on myrb_cleanup()
Revert "net: af_key: add check for pfkey_broadcast in function pfkey_process"
ceph: allow ceph.dir.rctime xattr to be updatable
ceph: flush the mdlog for filesystem sync
drm/amd/display: Check if modulo is 0 before dividing.
drm/radeon: fix a possible null pointer dereference
drm/amd/pm: Fix missing thermal throttler status
um: line: Use separate IRQs per line
modpost: fix undefined behavior of is_arm_mapping_symbol()
x86/cpu: Elide KCSAN for cpu_has() and friends
jump_label,noinstr: Avoid instrumentation for JUMP_LABEL=n builds
nbd: call genl_unregister_family() first in nbd_cleanup()
nbd: fix race between nbd_alloc_config() and module removal
nbd: fix io hung while disconnecting device
s390/gmap: voluntarily schedule during key setting
cifs: version operations for smb20 unneeded when legacy support disabled
drm/amd/pm: use bitmap_{from,to}_arr32 where appropriate
nodemask: Fix return values to be unsigned
vringh: Fix loop descriptors check in the indirect cases
scripts/gdb: change kernel config dumping method
ALSA: usb-audio: Skip generic sync EP parse for secondary EP
ALSA: usb-audio: Set up (implicit) sync for Saffire 6
ALSA: hda/conexant - Fix loopback issue with CX20632
ALSA: hda/realtek: Fix for quirk to enable speaker output on the Lenovo Yoga DuetITL 2021
ALSA: hda/realtek: Add quirk for HP Dev One
cifs: return errors during session setup during reconnects
cifs: fix reconnect on smb3 mount types
KEYS: trusted: tpm2: Fix migratable logic
ata: libata-transport: fix {dma|pio|xfer}_mode sysfs files
mmc: block: Fix CQE recovery reset success
net: phy: dp83867: retrigger SGMII AN when link change
net: openvswitch: fix misuse of the cached connection on tuple changes
writeback: Fix inode->i_io_list not be protected by inode->i_lock error
nfc: st21nfca: fix incorrect validating logic in EVT_TRANSACTION
nfc: st21nfca: fix memory leaks in EVT_TRANSACTION handling
nfc: st21nfca: fix incorrect sizing calculations in EVT_TRANSACTION
ixgbe: fix bcast packets Rx on VF after promisc removal
ixgbe: fix unexpected VLAN Rx in promisc mode on VF
Input: bcm5974 - set missing URB_NO_TRANSFER_DMA_MAP urb flag
vduse: Fix NULL pointer dereference on sysfs access
powerpc: Don't select HAVE_IRQ_EXIT_ON_IRQ_STACK
drm/bridge: analogix_dp: Support PSR-exit to disable transition
drm/atomic: Force bridge self-refresh-exit on CRTC switch
drm/amdgpu: update VCN codec support for Yellow Carp
powerpc/32: Fix overread/overwrite of thread_struct via ptrace
powerpc/mm: Switch obsolete dssall to .long
drm/ast: Create threshold values for AST2600
random: avoid checking crng_ready() twice in random_init()
random: mark bootloader randomness code as __init
random: account for arch randomness in bits
md/raid0: Ignore RAID0 layout if the second zone has only one device
net/sched: act_police: more accurate MTU policing
PCI: qcom: Fix pipe clock imbalance
zonefs: fix handling of explicit_open option on mount
iov_iter: fix build issue due to possible type mis-match
dmaengine: idxd: add missing callback function to support DMA_INTERRUPT
tcp: fix tcp_mtup_probe_success vs wrong snd_cwnd
xsk: Fix possible crash when multiple sockets are created
Linux 5.15.47
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I40e7672edf2bd713fee775919d062e2934d9103d
685 lines
16 KiB
C
685 lines
16 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright (c) 2017 Linaro Limited. All rights reserved.
|
|
*
|
|
* Author: Leo Yan <leo.yan@linaro.org>
|
|
*/
|
|
#include <linux/amba/bus.h>
|
|
#include <linux/coresight.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/debugfs.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/device.h>
|
|
#include <linux/err.h>
|
|
#include <linux/init.h>
|
|
#include <linux/io.h>
|
|
#include <linux/iopoll.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/moduleparam.h>
|
|
#include <linux/panic_notifier.h>
|
|
#include <linux/pm_qos.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/smp.h>
|
|
#include <linux/types.h>
|
|
#include <linux/uaccess.h>
|
|
|
|
#include "coresight-priv.h"
|
|
|
|
#define EDPCSR 0x0A0
|
|
#define EDCIDSR 0x0A4
|
|
#define EDVIDSR 0x0A8
|
|
#define EDPCSR_HI 0x0AC
|
|
#define EDOSLAR 0x300
|
|
#define EDPRCR 0x310
|
|
#define EDPRSR 0x314
|
|
#define EDDEVID1 0xFC4
|
|
#define EDDEVID 0xFC8
|
|
|
|
#define EDPCSR_PROHIBITED 0xFFFFFFFF
|
|
|
|
/* bits definition for EDPCSR */
|
|
#define EDPCSR_THUMB BIT(0)
|
|
#define EDPCSR_ARM_INST_MASK GENMASK(31, 2)
|
|
#define EDPCSR_THUMB_INST_MASK GENMASK(31, 1)
|
|
|
|
/* bits definition for EDPRCR */
|
|
#define EDPRCR_COREPURQ BIT(3)
|
|
#define EDPRCR_CORENPDRQ BIT(0)
|
|
|
|
/* bits definition for EDPRSR */
|
|
#define EDPRSR_DLK BIT(6)
|
|
#define EDPRSR_PU BIT(0)
|
|
|
|
/* bits definition for EDVIDSR */
|
|
#define EDVIDSR_NS BIT(31)
|
|
#define EDVIDSR_E2 BIT(30)
|
|
#define EDVIDSR_E3 BIT(29)
|
|
#define EDVIDSR_HV BIT(28)
|
|
#define EDVIDSR_VMID GENMASK(7, 0)
|
|
|
|
/*
|
|
* bits definition for EDDEVID1:PSCROffset
|
|
*
|
|
* NOTE: armv8 and armv7 have different definition for the register,
|
|
* so consolidate the bits definition as below:
|
|
*
|
|
* 0b0000 - Sample offset applies based on the instruction state, we
|
|
* rely on EDDEVID to check if EDPCSR is implemented or not
|
|
* 0b0001 - No offset applies.
|
|
* 0b0010 - No offset applies, but do not use in AArch32 mode
|
|
*
|
|
*/
|
|
#define EDDEVID1_PCSR_OFFSET_MASK GENMASK(3, 0)
|
|
#define EDDEVID1_PCSR_OFFSET_INS_SET (0x0)
|
|
#define EDDEVID1_PCSR_NO_OFFSET_DIS_AARCH32 (0x2)
|
|
|
|
/* bits definition for EDDEVID */
|
|
#define EDDEVID_PCSAMPLE_MODE GENMASK(3, 0)
|
|
#define EDDEVID_IMPL_EDPCSR (0x1)
|
|
#define EDDEVID_IMPL_EDPCSR_EDCIDSR (0x2)
|
|
#define EDDEVID_IMPL_FULL (0x3)
|
|
|
|
#define DEBUG_WAIT_SLEEP 1000
|
|
#define DEBUG_WAIT_TIMEOUT 32000
|
|
|
|
struct debug_drvdata {
|
|
void __iomem *base;
|
|
struct device *dev;
|
|
int cpu;
|
|
|
|
bool edpcsr_present;
|
|
bool edcidsr_present;
|
|
bool edvidsr_present;
|
|
bool pc_has_offset;
|
|
|
|
u32 edpcsr;
|
|
u32 edpcsr_hi;
|
|
u32 edprsr;
|
|
u32 edvidsr;
|
|
u32 edcidsr;
|
|
};
|
|
|
|
static DEFINE_MUTEX(debug_lock);
|
|
static DEFINE_PER_CPU(struct debug_drvdata *, debug_drvdata);
|
|
static int debug_count;
|
|
static struct dentry *debug_debugfs_dir;
|
|
|
|
static bool debug_enable = IS_ENABLED(CONFIG_CORESIGHT_CPU_DEBUG_DEFAULT_ON);
|
|
module_param_named(enable, debug_enable, bool, 0600);
|
|
MODULE_PARM_DESC(enable, "Control to enable coresight CPU debug functionality");
|
|
|
|
static void debug_os_unlock(struct debug_drvdata *drvdata)
|
|
{
|
|
/* Unlocks the debug registers */
|
|
writel_relaxed(0x0, drvdata->base + EDOSLAR);
|
|
|
|
/* Make sure the registers are unlocked before accessing */
|
|
wmb();
|
|
}
|
|
|
|
/*
|
|
* According to ARM DDI 0487A.k, before access external debug
|
|
* registers should firstly check the access permission; if any
|
|
* below condition has been met then cannot access debug
|
|
* registers to avoid lockup issue:
|
|
*
|
|
* - CPU power domain is powered off;
|
|
* - The OS Double Lock is locked;
|
|
*
|
|
* By checking EDPRSR can get to know if meet these conditions.
|
|
*/
|
|
static bool debug_access_permitted(struct debug_drvdata *drvdata)
|
|
{
|
|
/* CPU is powered off */
|
|
if (!(drvdata->edprsr & EDPRSR_PU))
|
|
return false;
|
|
|
|
/* The OS Double Lock is locked */
|
|
if (drvdata->edprsr & EDPRSR_DLK)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
static void debug_force_cpu_powered_up(struct debug_drvdata *drvdata)
|
|
{
|
|
u32 edprcr;
|
|
|
|
try_again:
|
|
|
|
/*
|
|
* Send request to power management controller and assert
|
|
* DBGPWRUPREQ signal; if power management controller has
|
|
* sane implementation, it should enable CPU power domain
|
|
* in case CPU is in low power state.
|
|
*/
|
|
edprcr = readl_relaxed(drvdata->base + EDPRCR);
|
|
edprcr |= EDPRCR_COREPURQ;
|
|
writel_relaxed(edprcr, drvdata->base + EDPRCR);
|
|
|
|
/* Wait for CPU to be powered up (timeout~=32ms) */
|
|
if (readx_poll_timeout_atomic(readl_relaxed, drvdata->base + EDPRSR,
|
|
drvdata->edprsr, (drvdata->edprsr & EDPRSR_PU),
|
|
DEBUG_WAIT_SLEEP, DEBUG_WAIT_TIMEOUT)) {
|
|
/*
|
|
* Unfortunately the CPU cannot be powered up, so return
|
|
* back and later has no permission to access other
|
|
* registers. For this case, should disable CPU low power
|
|
* states to ensure CPU power domain is enabled!
|
|
*/
|
|
dev_err(drvdata->dev, "%s: power up request for CPU%d failed\n",
|
|
__func__, drvdata->cpu);
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* At this point the CPU is powered up, so set the no powerdown
|
|
* request bit so we don't lose power and emulate power down.
|
|
*/
|
|
edprcr = readl_relaxed(drvdata->base + EDPRCR);
|
|
edprcr |= EDPRCR_COREPURQ | EDPRCR_CORENPDRQ;
|
|
writel_relaxed(edprcr, drvdata->base + EDPRCR);
|
|
|
|
drvdata->edprsr = readl_relaxed(drvdata->base + EDPRSR);
|
|
|
|
/* The core power domain got switched off on use, try again */
|
|
if (unlikely(!(drvdata->edprsr & EDPRSR_PU)))
|
|
goto try_again;
|
|
}
|
|
|
|
static void debug_read_regs(struct debug_drvdata *drvdata)
|
|
{
|
|
u32 save_edprcr;
|
|
|
|
CS_UNLOCK(drvdata->base);
|
|
|
|
/* Unlock os lock */
|
|
debug_os_unlock(drvdata);
|
|
|
|
/* Save EDPRCR register */
|
|
save_edprcr = readl_relaxed(drvdata->base + EDPRCR);
|
|
|
|
/*
|
|
* Ensure CPU power domain is enabled to let registers
|
|
* are accessiable.
|
|
*/
|
|
debug_force_cpu_powered_up(drvdata);
|
|
|
|
if (!debug_access_permitted(drvdata))
|
|
goto out;
|
|
|
|
drvdata->edpcsr = readl_relaxed(drvdata->base + EDPCSR);
|
|
|
|
/*
|
|
* As described in ARM DDI 0487A.k, if the processing
|
|
* element (PE) is in debug state, or sample-based
|
|
* profiling is prohibited, EDPCSR reads as 0xFFFFFFFF;
|
|
* EDCIDSR, EDVIDSR and EDPCSR_HI registers also become
|
|
* UNKNOWN state. So directly bail out for this case.
|
|
*/
|
|
if (drvdata->edpcsr == EDPCSR_PROHIBITED)
|
|
goto out;
|
|
|
|
/*
|
|
* A read of the EDPCSR normally has the side-effect of
|
|
* indirectly writing to EDCIDSR, EDVIDSR and EDPCSR_HI;
|
|
* at this point it's safe to read value from them.
|
|
*/
|
|
if (IS_ENABLED(CONFIG_64BIT))
|
|
drvdata->edpcsr_hi = readl_relaxed(drvdata->base + EDPCSR_HI);
|
|
|
|
if (drvdata->edcidsr_present)
|
|
drvdata->edcidsr = readl_relaxed(drvdata->base + EDCIDSR);
|
|
|
|
if (drvdata->edvidsr_present)
|
|
drvdata->edvidsr = readl_relaxed(drvdata->base + EDVIDSR);
|
|
|
|
out:
|
|
/* Restore EDPRCR register */
|
|
writel_relaxed(save_edprcr, drvdata->base + EDPRCR);
|
|
|
|
CS_LOCK(drvdata->base);
|
|
}
|
|
|
|
#ifdef CONFIG_64BIT
|
|
static unsigned long debug_adjust_pc(struct debug_drvdata *drvdata)
|
|
{
|
|
return (unsigned long)drvdata->edpcsr_hi << 32 |
|
|
(unsigned long)drvdata->edpcsr;
|
|
}
|
|
#else
|
|
static unsigned long debug_adjust_pc(struct debug_drvdata *drvdata)
|
|
{
|
|
unsigned long arm_inst_offset = 0, thumb_inst_offset = 0;
|
|
unsigned long pc;
|
|
|
|
pc = (unsigned long)drvdata->edpcsr;
|
|
|
|
if (drvdata->pc_has_offset) {
|
|
arm_inst_offset = 8;
|
|
thumb_inst_offset = 4;
|
|
}
|
|
|
|
/* Handle thumb instruction */
|
|
if (pc & EDPCSR_THUMB) {
|
|
pc = (pc & EDPCSR_THUMB_INST_MASK) - thumb_inst_offset;
|
|
return pc;
|
|
}
|
|
|
|
/*
|
|
* Handle arm instruction offset, if the arm instruction
|
|
* is not 4 byte alignment then it's possible the case
|
|
* for implementation defined; keep original value for this
|
|
* case and print info for notice.
|
|
*/
|
|
if (pc & BIT(1))
|
|
dev_emerg(drvdata->dev,
|
|
"Instruction offset is implementation defined\n");
|
|
else
|
|
pc = (pc & EDPCSR_ARM_INST_MASK) - arm_inst_offset;
|
|
|
|
return pc;
|
|
}
|
|
#endif
|
|
|
|
static void debug_dump_regs(struct debug_drvdata *drvdata)
|
|
{
|
|
struct device *dev = drvdata->dev;
|
|
unsigned long pc;
|
|
|
|
dev_emerg(dev, " EDPRSR: %08x (Power:%s DLK:%s)\n",
|
|
drvdata->edprsr,
|
|
drvdata->edprsr & EDPRSR_PU ? "On" : "Off",
|
|
drvdata->edprsr & EDPRSR_DLK ? "Lock" : "Unlock");
|
|
|
|
if (!debug_access_permitted(drvdata)) {
|
|
dev_emerg(dev, "No permission to access debug registers!\n");
|
|
return;
|
|
}
|
|
|
|
if (drvdata->edpcsr == EDPCSR_PROHIBITED) {
|
|
dev_emerg(dev, "CPU is in Debug state or profiling is prohibited!\n");
|
|
return;
|
|
}
|
|
|
|
pc = debug_adjust_pc(drvdata);
|
|
dev_emerg(dev, " EDPCSR: %pS\n", (void *)pc);
|
|
|
|
if (drvdata->edcidsr_present)
|
|
dev_emerg(dev, " EDCIDSR: %08x\n", drvdata->edcidsr);
|
|
|
|
if (drvdata->edvidsr_present)
|
|
dev_emerg(dev, " EDVIDSR: %08x (State:%s Mode:%s Width:%dbits VMID:%x)\n",
|
|
drvdata->edvidsr,
|
|
drvdata->edvidsr & EDVIDSR_NS ?
|
|
"Non-secure" : "Secure",
|
|
drvdata->edvidsr & EDVIDSR_E3 ? "EL3" :
|
|
(drvdata->edvidsr & EDVIDSR_E2 ?
|
|
"EL2" : "EL1/0"),
|
|
drvdata->edvidsr & EDVIDSR_HV ? 64 : 32,
|
|
drvdata->edvidsr & (u32)EDVIDSR_VMID);
|
|
}
|
|
|
|
static void debug_init_arch_data(void *info)
|
|
{
|
|
struct debug_drvdata *drvdata = info;
|
|
u32 mode, pcsr_offset;
|
|
u32 eddevid, eddevid1;
|
|
|
|
CS_UNLOCK(drvdata->base);
|
|
|
|
/* Read device info */
|
|
eddevid = readl_relaxed(drvdata->base + EDDEVID);
|
|
eddevid1 = readl_relaxed(drvdata->base + EDDEVID1);
|
|
|
|
CS_LOCK(drvdata->base);
|
|
|
|
/* Parse implementation feature */
|
|
mode = eddevid & EDDEVID_PCSAMPLE_MODE;
|
|
pcsr_offset = eddevid1 & EDDEVID1_PCSR_OFFSET_MASK;
|
|
|
|
drvdata->edpcsr_present = false;
|
|
drvdata->edcidsr_present = false;
|
|
drvdata->edvidsr_present = false;
|
|
drvdata->pc_has_offset = false;
|
|
|
|
switch (mode) {
|
|
case EDDEVID_IMPL_FULL:
|
|
drvdata->edvidsr_present = true;
|
|
fallthrough;
|
|
case EDDEVID_IMPL_EDPCSR_EDCIDSR:
|
|
drvdata->edcidsr_present = true;
|
|
fallthrough;
|
|
case EDDEVID_IMPL_EDPCSR:
|
|
/*
|
|
* In ARM DDI 0487A.k, the EDDEVID1.PCSROffset is used to
|
|
* define if has the offset for PC sampling value; if read
|
|
* back EDDEVID1.PCSROffset == 0x2, then this means the debug
|
|
* module does not sample the instruction set state when
|
|
* armv8 CPU in AArch32 state.
|
|
*/
|
|
drvdata->edpcsr_present =
|
|
((IS_ENABLED(CONFIG_64BIT) && pcsr_offset != 0) ||
|
|
(pcsr_offset != EDDEVID1_PCSR_NO_OFFSET_DIS_AARCH32));
|
|
|
|
drvdata->pc_has_offset =
|
|
(pcsr_offset == EDDEVID1_PCSR_OFFSET_INS_SET);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Dump out information on panic.
|
|
*/
|
|
static int debug_notifier_call(struct notifier_block *self,
|
|
unsigned long v, void *p)
|
|
{
|
|
int cpu;
|
|
struct debug_drvdata *drvdata;
|
|
|
|
/* Bail out if we can't acquire the mutex or the functionality is off */
|
|
if (!mutex_trylock(&debug_lock))
|
|
return NOTIFY_DONE;
|
|
|
|
if (!debug_enable)
|
|
goto skip_dump;
|
|
|
|
pr_emerg("ARM external debug module:\n");
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
drvdata = per_cpu(debug_drvdata, cpu);
|
|
if (!drvdata)
|
|
continue;
|
|
|
|
dev_emerg(drvdata->dev, "CPU[%d]:\n", drvdata->cpu);
|
|
|
|
debug_read_regs(drvdata);
|
|
debug_dump_regs(drvdata);
|
|
}
|
|
|
|
skip_dump:
|
|
mutex_unlock(&debug_lock);
|
|
return NOTIFY_DONE;
|
|
}
|
|
|
|
static struct notifier_block debug_notifier = {
|
|
.notifier_call = debug_notifier_call,
|
|
};
|
|
|
|
static int debug_enable_func(void)
|
|
{
|
|
struct debug_drvdata *drvdata;
|
|
int cpu, ret = 0;
|
|
cpumask_t mask;
|
|
|
|
/*
|
|
* Use cpumask to track which debug power domains have
|
|
* been powered on and use it to handle failure case.
|
|
*/
|
|
cpumask_clear(&mask);
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
drvdata = per_cpu(debug_drvdata, cpu);
|
|
if (!drvdata)
|
|
continue;
|
|
|
|
ret = pm_runtime_get_sync(drvdata->dev);
|
|
if (ret < 0)
|
|
goto err;
|
|
else
|
|
cpumask_set_cpu(cpu, &mask);
|
|
}
|
|
|
|
return 0;
|
|
|
|
err:
|
|
/*
|
|
* If pm_runtime_get_sync() has failed, need rollback on
|
|
* all the other CPUs that have been enabled before that.
|
|
*/
|
|
for_each_cpu(cpu, &mask) {
|
|
drvdata = per_cpu(debug_drvdata, cpu);
|
|
pm_runtime_put_noidle(drvdata->dev);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int debug_disable_func(void)
|
|
{
|
|
struct debug_drvdata *drvdata;
|
|
int cpu, ret, err = 0;
|
|
|
|
/*
|
|
* Disable debug power domains, records the error and keep
|
|
* circling through all other CPUs when an error has been
|
|
* encountered.
|
|
*/
|
|
for_each_possible_cpu(cpu) {
|
|
drvdata = per_cpu(debug_drvdata, cpu);
|
|
if (!drvdata)
|
|
continue;
|
|
|
|
ret = pm_runtime_put(drvdata->dev);
|
|
if (ret < 0)
|
|
err = ret;
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
static ssize_t debug_func_knob_write(struct file *f,
|
|
const char __user *buf, size_t count, loff_t *ppos)
|
|
{
|
|
u8 val;
|
|
int ret;
|
|
|
|
ret = kstrtou8_from_user(buf, count, 2, &val);
|
|
if (ret)
|
|
return ret;
|
|
|
|
mutex_lock(&debug_lock);
|
|
|
|
if (val == debug_enable)
|
|
goto out;
|
|
|
|
if (val)
|
|
ret = debug_enable_func();
|
|
else
|
|
ret = debug_disable_func();
|
|
|
|
if (ret) {
|
|
pr_err("%s: unable to %s debug function: %d\n",
|
|
__func__, val ? "enable" : "disable", ret);
|
|
goto err;
|
|
}
|
|
|
|
debug_enable = val;
|
|
out:
|
|
ret = count;
|
|
err:
|
|
mutex_unlock(&debug_lock);
|
|
return ret;
|
|
}
|
|
|
|
static ssize_t debug_func_knob_read(struct file *f,
|
|
char __user *ubuf, size_t count, loff_t *ppos)
|
|
{
|
|
ssize_t ret;
|
|
char buf[3];
|
|
|
|
mutex_lock(&debug_lock);
|
|
snprintf(buf, sizeof(buf), "%d\n", debug_enable);
|
|
mutex_unlock(&debug_lock);
|
|
|
|
ret = simple_read_from_buffer(ubuf, count, ppos, buf, sizeof(buf));
|
|
return ret;
|
|
}
|
|
|
|
static const struct file_operations debug_func_knob_fops = {
|
|
.open = simple_open,
|
|
.read = debug_func_knob_read,
|
|
.write = debug_func_knob_write,
|
|
};
|
|
|
|
static int debug_func_init(void)
|
|
{
|
|
int ret;
|
|
|
|
/* Create debugfs node */
|
|
debug_debugfs_dir = debugfs_create_dir("coresight_cpu_debug", NULL);
|
|
debugfs_create_file("enable", 0644, debug_debugfs_dir, NULL,
|
|
&debug_func_knob_fops);
|
|
|
|
/* Register function to be called for panic */
|
|
ret = atomic_notifier_chain_register(&panic_notifier_list,
|
|
&debug_notifier);
|
|
if (ret) {
|
|
pr_err("%s: unable to register notifier: %d\n",
|
|
__func__, ret);
|
|
goto err;
|
|
}
|
|
|
|
return 0;
|
|
|
|
err:
|
|
debugfs_remove_recursive(debug_debugfs_dir);
|
|
return ret;
|
|
}
|
|
|
|
static void debug_func_exit(void)
|
|
{
|
|
atomic_notifier_chain_unregister(&panic_notifier_list,
|
|
&debug_notifier);
|
|
debugfs_remove_recursive(debug_debugfs_dir);
|
|
}
|
|
|
|
static int debug_probe(struct amba_device *adev, const struct amba_id *id)
|
|
{
|
|
void __iomem *base;
|
|
struct device *dev = &adev->dev;
|
|
struct debug_drvdata *drvdata;
|
|
struct resource *res = &adev->res;
|
|
int ret;
|
|
|
|
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
|
|
if (!drvdata)
|
|
return -ENOMEM;
|
|
|
|
drvdata->cpu = coresight_get_cpu(dev);
|
|
if (drvdata->cpu < 0)
|
|
return drvdata->cpu;
|
|
|
|
if (per_cpu(debug_drvdata, drvdata->cpu)) {
|
|
dev_err(dev, "CPU%d drvdata has already been initialized\n",
|
|
drvdata->cpu);
|
|
return -EBUSY;
|
|
}
|
|
|
|
drvdata->dev = &adev->dev;
|
|
amba_set_drvdata(adev, drvdata);
|
|
|
|
/* Validity for the resource is already checked by the AMBA core */
|
|
base = devm_ioremap_resource(dev, res);
|
|
if (IS_ERR(base))
|
|
return PTR_ERR(base);
|
|
|
|
drvdata->base = base;
|
|
|
|
cpus_read_lock();
|
|
per_cpu(debug_drvdata, drvdata->cpu) = drvdata;
|
|
ret = smp_call_function_single(drvdata->cpu, debug_init_arch_data,
|
|
drvdata, 1);
|
|
cpus_read_unlock();
|
|
|
|
if (ret) {
|
|
dev_err(dev, "CPU%d debug arch init failed\n", drvdata->cpu);
|
|
goto err;
|
|
}
|
|
|
|
if (!drvdata->edpcsr_present) {
|
|
dev_err(dev, "CPU%d sample-based profiling isn't implemented\n",
|
|
drvdata->cpu);
|
|
ret = -ENXIO;
|
|
goto err;
|
|
}
|
|
|
|
if (!debug_count++) {
|
|
ret = debug_func_init();
|
|
if (ret)
|
|
goto err_func_init;
|
|
}
|
|
|
|
mutex_lock(&debug_lock);
|
|
/* Turn off debug power domain if debugging is disabled */
|
|
if (!debug_enable)
|
|
pm_runtime_put(dev);
|
|
mutex_unlock(&debug_lock);
|
|
|
|
dev_info(dev, "Coresight debug-CPU%d initialized\n", drvdata->cpu);
|
|
return 0;
|
|
|
|
err_func_init:
|
|
debug_count--;
|
|
err:
|
|
per_cpu(debug_drvdata, drvdata->cpu) = NULL;
|
|
return ret;
|
|
}
|
|
|
|
static void debug_remove(struct amba_device *adev)
|
|
{
|
|
struct device *dev = &adev->dev;
|
|
struct debug_drvdata *drvdata = amba_get_drvdata(adev);
|
|
|
|
per_cpu(debug_drvdata, drvdata->cpu) = NULL;
|
|
|
|
mutex_lock(&debug_lock);
|
|
/* Turn off debug power domain before rmmod the module */
|
|
if (debug_enable)
|
|
pm_runtime_put(dev);
|
|
mutex_unlock(&debug_lock);
|
|
|
|
if (!--debug_count)
|
|
debug_func_exit();
|
|
}
|
|
|
|
static const struct amba_cs_uci_id uci_id_debug[] = {
|
|
{
|
|
/* CPU Debug UCI data */
|
|
.devarch = 0x47706a15,
|
|
.devarch_mask = 0xfff0ffff,
|
|
.devtype = 0x00000015,
|
|
}
|
|
};
|
|
|
|
static const struct amba_id debug_ids[] = {
|
|
CS_AMBA_ID(0x000bbd03), /* Cortex-A53 */
|
|
CS_AMBA_ID(0x000bbd07), /* Cortex-A57 */
|
|
CS_AMBA_ID(0x000bbd08), /* Cortex-A72 */
|
|
CS_AMBA_ID(0x000bbd09), /* Cortex-A73 */
|
|
CS_AMBA_UCI_ID(0x000f0205, uci_id_debug), /* Qualcomm Kryo */
|
|
CS_AMBA_UCI_ID(0x000f0211, uci_id_debug), /* Qualcomm Kryo */
|
|
{},
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(amba, debug_ids);
|
|
|
|
static struct amba_driver debug_driver = {
|
|
.drv = {
|
|
.name = "coresight-cpu-debug",
|
|
.suppress_bind_attrs = true,
|
|
},
|
|
.probe = debug_probe,
|
|
.remove = debug_remove,
|
|
.id_table = debug_ids,
|
|
};
|
|
|
|
module_amba_driver(debug_driver);
|
|
|
|
MODULE_AUTHOR("Leo Yan <leo.yan@linaro.org>");
|
|
MODULE_DESCRIPTION("ARM Coresight CPU Debug Driver");
|
|
MODULE_LICENSE("GPL");
|