License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2010-11-14 03:04:32 +08:00
|
|
|
/*
|
|
|
|
* ARMv5 [xscale] Performance counter handling code.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010, ARM Ltd., Will Deacon <will.deacon@arm.com>
|
|
|
|
*
|
|
|
|
* Based on the previous xscale OProfile code.
|
|
|
|
*
|
|
|
|
* There are two variants of the xscale PMU that we support:
|
|
|
|
* - xscale1pmu: 2 event counters and a cycle counter
|
|
|
|
* - xscale2pmu: 4 event counters and a cycle counter
|
|
|
|
* The two variants share event definitions, but have different
|
|
|
|
* PMU structures.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_CPU_XSCALE
|
2015-05-27 00:23:36 +08:00
|
|
|
|
|
|
|
#include <asm/cputype.h>
|
|
|
|
#include <asm/irq_regs.h>
|
|
|
|
|
|
|
|
#include <linux/of.h>
|
2015-07-06 19:23:53 +08:00
|
|
|
#include <linux/perf/arm_pmu.h>
|
2015-05-27 00:23:36 +08:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
2010-11-14 03:04:32 +08:00
|
|
|
enum xscale_perf_types {
|
|
|
|
XSCALE_PERFCTR_ICACHE_MISS = 0x00,
|
|
|
|
XSCALE_PERFCTR_ICACHE_NO_DELIVER = 0x01,
|
|
|
|
XSCALE_PERFCTR_DATA_STALL = 0x02,
|
|
|
|
XSCALE_PERFCTR_ITLB_MISS = 0x03,
|
|
|
|
XSCALE_PERFCTR_DTLB_MISS = 0x04,
|
|
|
|
XSCALE_PERFCTR_BRANCH = 0x05,
|
|
|
|
XSCALE_PERFCTR_BRANCH_MISS = 0x06,
|
|
|
|
XSCALE_PERFCTR_INSTRUCTION = 0x07,
|
|
|
|
XSCALE_PERFCTR_DCACHE_FULL_STALL = 0x08,
|
|
|
|
XSCALE_PERFCTR_DCACHE_FULL_STALL_CONTIG = 0x09,
|
|
|
|
XSCALE_PERFCTR_DCACHE_ACCESS = 0x0A,
|
|
|
|
XSCALE_PERFCTR_DCACHE_MISS = 0x0B,
|
|
|
|
XSCALE_PERFCTR_DCACHE_WRITE_BACK = 0x0C,
|
|
|
|
XSCALE_PERFCTR_PC_CHANGED = 0x0D,
|
|
|
|
XSCALE_PERFCTR_BCU_REQUEST = 0x10,
|
|
|
|
XSCALE_PERFCTR_BCU_FULL = 0x11,
|
|
|
|
XSCALE_PERFCTR_BCU_DRAIN = 0x12,
|
|
|
|
XSCALE_PERFCTR_BCU_ECC_NO_ELOG = 0x14,
|
|
|
|
XSCALE_PERFCTR_BCU_1_BIT_ERR = 0x15,
|
|
|
|
XSCALE_PERFCTR_RMW = 0x16,
|
|
|
|
/* XSCALE_PERFCTR_CCNT is not hardware defined */
|
|
|
|
XSCALE_PERFCTR_CCNT = 0xFE,
|
|
|
|
XSCALE_PERFCTR_UNUSED = 0xFF,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum xscale_counters {
|
2011-07-20 05:41:36 +08:00
|
|
|
XSCALE_CYCLE_COUNTER = 0,
|
2010-11-14 03:04:32 +08:00
|
|
|
XSCALE_COUNTER0,
|
|
|
|
XSCALE_COUNTER1,
|
|
|
|
XSCALE_COUNTER2,
|
|
|
|
XSCALE_COUNTER3,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned xscale_perf_map[PERF_COUNT_HW_MAX] = {
|
2014-05-31 01:00:06 +08:00
|
|
|
PERF_MAP_ALL_UNSUPPORTED,
|
2011-09-30 01:23:39 +08:00
|
|
|
[PERF_COUNT_HW_CPU_CYCLES] = XSCALE_PERFCTR_CCNT,
|
|
|
|
[PERF_COUNT_HW_INSTRUCTIONS] = XSCALE_PERFCTR_INSTRUCTION,
|
|
|
|
[PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = XSCALE_PERFCTR_BRANCH,
|
|
|
|
[PERF_COUNT_HW_BRANCH_MISSES] = XSCALE_PERFCTR_BRANCH_MISS,
|
|
|
|
[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = XSCALE_PERFCTR_ICACHE_NO_DELIVER,
|
2010-11-14 03:04:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned xscale_perf_cache_map[PERF_COUNT_HW_CACHE_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_OP_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_RESULT_MAX] = {
|
2014-05-31 01:00:06 +08:00
|
|
|
PERF_CACHE_MAP_ALL_UNSUPPORTED,
|
|
|
|
|
|
|
|
[C(L1D)][C(OP_READ)][C(RESULT_ACCESS)] = XSCALE_PERFCTR_DCACHE_ACCESS,
|
|
|
|
[C(L1D)][C(OP_READ)][C(RESULT_MISS)] = XSCALE_PERFCTR_DCACHE_MISS,
|
|
|
|
[C(L1D)][C(OP_WRITE)][C(RESULT_ACCESS)] = XSCALE_PERFCTR_DCACHE_ACCESS,
|
|
|
|
[C(L1D)][C(OP_WRITE)][C(RESULT_MISS)] = XSCALE_PERFCTR_DCACHE_MISS,
|
|
|
|
|
|
|
|
[C(L1I)][C(OP_READ)][C(RESULT_MISS)] = XSCALE_PERFCTR_ICACHE_MISS,
|
|
|
|
|
|
|
|
[C(DTLB)][C(OP_READ)][C(RESULT_MISS)] = XSCALE_PERFCTR_DTLB_MISS,
|
|
|
|
[C(DTLB)][C(OP_WRITE)][C(RESULT_MISS)] = XSCALE_PERFCTR_DTLB_MISS,
|
|
|
|
|
|
|
|
[C(ITLB)][C(OP_READ)][C(RESULT_MISS)] = XSCALE_PERFCTR_ITLB_MISS,
|
|
|
|
[C(ITLB)][C(OP_WRITE)][C(RESULT_MISS)] = XSCALE_PERFCTR_ITLB_MISS,
|
2010-11-14 03:04:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define XSCALE_PMU_ENABLE 0x001
|
|
|
|
#define XSCALE_PMN_RESET 0x002
|
|
|
|
#define XSCALE_CCNT_RESET 0x004
|
|
|
|
#define XSCALE_PMU_RESET (CCNT_RESET | PMN_RESET)
|
|
|
|
#define XSCALE_PMU_CNT64 0x008
|
|
|
|
|
|
|
|
#define XSCALE1_OVERFLOWED_MASK 0x700
|
|
|
|
#define XSCALE1_CCOUNT_OVERFLOW 0x400
|
|
|
|
#define XSCALE1_COUNT0_OVERFLOW 0x100
|
|
|
|
#define XSCALE1_COUNT1_OVERFLOW 0x200
|
|
|
|
#define XSCALE1_CCOUNT_INT_EN 0x040
|
|
|
|
#define XSCALE1_COUNT0_INT_EN 0x010
|
|
|
|
#define XSCALE1_COUNT1_INT_EN 0x020
|
|
|
|
#define XSCALE1_COUNT0_EVT_SHFT 12
|
|
|
|
#define XSCALE1_COUNT0_EVT_MASK (0xff << XSCALE1_COUNT0_EVT_SHFT)
|
|
|
|
#define XSCALE1_COUNT1_EVT_SHFT 20
|
|
|
|
#define XSCALE1_COUNT1_EVT_MASK (0xff << XSCALE1_COUNT1_EVT_SHFT)
|
|
|
|
|
|
|
|
static inline u32
|
|
|
|
xscale1pmu_read_pmnc(void)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
asm volatile("mrc p14, 0, %0, c0, c0, 0" : "=r" (val));
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
xscale1pmu_write_pmnc(u32 val)
|
|
|
|
{
|
|
|
|
/* upper 4bits and 7, 11 are write-as-0 */
|
|
|
|
val &= 0xffff77f;
|
|
|
|
asm volatile("mcr p14, 0, %0, c0, c0, 0" : : "r" (val));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
xscale1_pmnc_counter_has_overflowed(unsigned long pmnc,
|
|
|
|
enum xscale_counters counter)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (counter) {
|
|
|
|
case XSCALE_CYCLE_COUNTER:
|
|
|
|
ret = pmnc & XSCALE1_CCOUNT_OVERFLOW;
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER0:
|
|
|
|
ret = pmnc & XSCALE1_COUNT0_OVERFLOW;
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER1:
|
|
|
|
ret = pmnc & XSCALE1_COUNT1_OVERFLOW;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ONCE(1, "invalid counter number (%d)\n", counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t
|
2018-05-10 18:35:15 +08:00
|
|
|
xscale1pmu_handle_irq(struct arm_pmu *cpu_pmu)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
|
|
|
unsigned long pmnc;
|
|
|
|
struct perf_sample_data data;
|
2014-05-14 02:36:31 +08:00
|
|
|
struct pmu_hw_events *cpuc = this_cpu_ptr(cpu_pmu->hw_events);
|
2010-11-14 03:04:32 +08:00
|
|
|
struct pt_regs *regs;
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: there's an A stepping erratum that states if an overflow
|
|
|
|
* bit already exists and another occurs, the previous
|
|
|
|
* Overflow bit gets cleared. There's no workaround.
|
|
|
|
* Fixed in B stepping or later.
|
|
|
|
*/
|
|
|
|
pmnc = xscale1pmu_read_pmnc();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the value back to clear the overflow flags. Overflow
|
|
|
|
* flags remain in pmnc for use below. We also disable the PMU
|
|
|
|
* while we process the interrupt.
|
|
|
|
*/
|
|
|
|
xscale1pmu_write_pmnc(pmnc & ~XSCALE_PMU_ENABLE);
|
|
|
|
|
|
|
|
if (!(pmnc & XSCALE1_OVERFLOWED_MASK))
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
regs = get_irq_regs();
|
|
|
|
|
2011-05-17 18:20:11 +08:00
|
|
|
for (idx = 0; idx < cpu_pmu->num_events; ++idx) {
|
2010-11-14 03:04:32 +08:00
|
|
|
struct perf_event *event = cpuc->events[idx];
|
|
|
|
struct hw_perf_event *hwc;
|
|
|
|
|
2012-03-07 00:34:50 +08:00
|
|
|
if (!event)
|
|
|
|
continue;
|
|
|
|
|
2010-11-14 03:04:32 +08:00
|
|
|
if (!xscale1_pmnc_counter_has_overflowed(pmnc, idx))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hwc = &event->hw;
|
2012-07-30 19:00:02 +08:00
|
|
|
armpmu_event_update(event);
|
2012-04-03 02:19:08 +08:00
|
|
|
perf_sample_data_init(&data, 0, hwc->last_period);
|
2012-07-30 19:00:02 +08:00
|
|
|
if (!armpmu_event_set_period(event))
|
2010-11-14 03:04:32 +08:00
|
|
|
continue;
|
|
|
|
|
2011-06-27 20:41:57 +08:00
|
|
|
if (perf_event_overflow(event, &data, regs))
|
2012-07-30 19:00:02 +08:00
|
|
|
cpu_pmu->disable(event);
|
2010-11-14 03:04:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
irq_work_run();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-enable the PMU.
|
|
|
|
*/
|
|
|
|
pmnc = xscale1pmu_read_pmnc() | XSCALE_PMU_ENABLE;
|
|
|
|
xscale1pmu_write_pmnc(pmnc);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2012-07-30 19:00:02 +08:00
|
|
|
static void xscale1pmu_enable_event(struct perf_event *event)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
|
|
|
unsigned long val, mask, evt, flags;
|
2012-07-30 19:00:02 +08:00
|
|
|
struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
|
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
2014-05-14 02:36:31 +08:00
|
|
|
struct pmu_hw_events *events = this_cpu_ptr(cpu_pmu->hw_events);
|
2012-07-30 19:00:02 +08:00
|
|
|
int idx = hwc->idx;
|
2010-11-14 03:04:32 +08:00
|
|
|
|
|
|
|
switch (idx) {
|
|
|
|
case XSCALE_CYCLE_COUNTER:
|
|
|
|
mask = 0;
|
|
|
|
evt = XSCALE1_CCOUNT_INT_EN;
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER0:
|
|
|
|
mask = XSCALE1_COUNT0_EVT_MASK;
|
|
|
|
evt = (hwc->config_base << XSCALE1_COUNT0_EVT_SHFT) |
|
|
|
|
XSCALE1_COUNT0_INT_EN;
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER1:
|
|
|
|
mask = XSCALE1_COUNT1_EVT_MASK;
|
|
|
|
evt = (hwc->config_base << XSCALE1_COUNT1_EVT_SHFT) |
|
|
|
|
XSCALE1_COUNT1_INT_EN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ONCE(1, "invalid counter number (%d)\n", idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_lock_irqsave(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
val = xscale1pmu_read_pmnc();
|
|
|
|
val &= ~mask;
|
|
|
|
val |= evt;
|
|
|
|
xscale1pmu_write_pmnc(val);
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
}
|
|
|
|
|
2012-07-30 19:00:02 +08:00
|
|
|
static void xscale1pmu_disable_event(struct perf_event *event)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
|
|
|
unsigned long val, mask, evt, flags;
|
2012-07-30 19:00:02 +08:00
|
|
|
struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
|
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
2014-05-14 02:36:31 +08:00
|
|
|
struct pmu_hw_events *events = this_cpu_ptr(cpu_pmu->hw_events);
|
2012-07-30 19:00:02 +08:00
|
|
|
int idx = hwc->idx;
|
2010-11-14 03:04:32 +08:00
|
|
|
|
|
|
|
switch (idx) {
|
|
|
|
case XSCALE_CYCLE_COUNTER:
|
|
|
|
mask = XSCALE1_CCOUNT_INT_EN;
|
|
|
|
evt = 0;
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER0:
|
|
|
|
mask = XSCALE1_COUNT0_INT_EN | XSCALE1_COUNT0_EVT_MASK;
|
|
|
|
evt = XSCALE_PERFCTR_UNUSED << XSCALE1_COUNT0_EVT_SHFT;
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER1:
|
|
|
|
mask = XSCALE1_COUNT1_INT_EN | XSCALE1_COUNT1_EVT_MASK;
|
|
|
|
evt = XSCALE_PERFCTR_UNUSED << XSCALE1_COUNT1_EVT_SHFT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ONCE(1, "invalid counter number (%d)\n", idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_lock_irqsave(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
val = xscale1pmu_read_pmnc();
|
|
|
|
val &= ~mask;
|
|
|
|
val |= evt;
|
|
|
|
xscale1pmu_write_pmnc(val);
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-05-17 18:20:11 +08:00
|
|
|
xscale1pmu_get_event_idx(struct pmu_hw_events *cpuc,
|
2012-07-30 19:00:02 +08:00
|
|
|
struct perf_event *event)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
2012-07-30 19:00:02 +08:00
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
|
|
|
if (XSCALE_PERFCTR_CCNT == hwc->config_base) {
|
2010-11-14 03:04:32 +08:00
|
|
|
if (test_and_set_bit(XSCALE_CYCLE_COUNTER, cpuc->used_mask))
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
return XSCALE_CYCLE_COUNTER;
|
|
|
|
} else {
|
|
|
|
if (!test_and_set_bit(XSCALE_COUNTER1, cpuc->used_mask))
|
|
|
|
return XSCALE_COUNTER1;
|
|
|
|
|
|
|
|
if (!test_and_set_bit(XSCALE_COUNTER0, cpuc->used_mask))
|
|
|
|
return XSCALE_COUNTER0;
|
|
|
|
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-10 16:58:01 +08:00
|
|
|
static void xscalepmu_clear_event_idx(struct pmu_hw_events *cpuc,
|
|
|
|
struct perf_event *event)
|
|
|
|
{
|
|
|
|
clear_bit(event->hw.idx, cpuc->used_mask);
|
|
|
|
}
|
|
|
|
|
2012-07-30 19:00:02 +08:00
|
|
|
static void xscale1pmu_start(struct arm_pmu *cpu_pmu)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
|
|
|
unsigned long flags, val;
|
2014-05-14 02:36:31 +08:00
|
|
|
struct pmu_hw_events *events = this_cpu_ptr(cpu_pmu->hw_events);
|
2010-11-14 03:04:32 +08:00
|
|
|
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_lock_irqsave(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
val = xscale1pmu_read_pmnc();
|
|
|
|
val |= XSCALE_PMU_ENABLE;
|
|
|
|
xscale1pmu_write_pmnc(val);
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
}
|
|
|
|
|
2012-07-30 19:00:02 +08:00
|
|
|
static void xscale1pmu_stop(struct arm_pmu *cpu_pmu)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
|
|
|
unsigned long flags, val;
|
2014-05-14 02:36:31 +08:00
|
|
|
struct pmu_hw_events *events = this_cpu_ptr(cpu_pmu->hw_events);
|
2010-11-14 03:04:32 +08:00
|
|
|
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_lock_irqsave(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
val = xscale1pmu_read_pmnc();
|
|
|
|
val &= ~XSCALE_PMU_ENABLE;
|
|
|
|
xscale1pmu_write_pmnc(val);
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
}
|
|
|
|
|
2018-07-10 16:57:59 +08:00
|
|
|
static inline u64 xscale1pmu_read_counter(struct perf_event *event)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
2012-07-30 19:00:02 +08:00
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
|
|
|
int counter = hwc->idx;
|
2010-11-14 03:04:32 +08:00
|
|
|
u32 val = 0;
|
|
|
|
|
|
|
|
switch (counter) {
|
|
|
|
case XSCALE_CYCLE_COUNTER:
|
|
|
|
asm volatile("mrc p14, 0, %0, c1, c0, 0" : "=r" (val));
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER0:
|
|
|
|
asm volatile("mrc p14, 0, %0, c2, c0, 0" : "=r" (val));
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER1:
|
|
|
|
asm volatile("mrc p14, 0, %0, c3, c0, 0" : "=r" (val));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2018-07-10 16:57:59 +08:00
|
|
|
static inline void xscale1pmu_write_counter(struct perf_event *event, u64 val)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
2012-07-30 19:00:02 +08:00
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
|
|
|
int counter = hwc->idx;
|
|
|
|
|
2010-11-14 03:04:32 +08:00
|
|
|
switch (counter) {
|
|
|
|
case XSCALE_CYCLE_COUNTER:
|
|
|
|
asm volatile("mcr p14, 0, %0, c1, c0, 0" : : "r" (val));
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER0:
|
|
|
|
asm volatile("mcr p14, 0, %0, c2, c0, 0" : : "r" (val));
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER1:
|
|
|
|
asm volatile("mcr p14, 0, %0, c3, c0, 0" : : "r" (val));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-28 22:47:10 +08:00
|
|
|
static int xscale_map_event(struct perf_event *event)
|
|
|
|
{
|
2012-07-29 19:36:28 +08:00
|
|
|
return armpmu_map_event(event, &xscale_perf_map,
|
2011-04-28 22:47:10 +08:00
|
|
|
&xscale_perf_cache_map, 0xFF);
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:02:24 +08:00
|
|
|
static int xscale1pmu_init(struct arm_pmu *cpu_pmu)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
2012-12-20 00:33:24 +08:00
|
|
|
cpu_pmu->name = "armv5_xscale1";
|
2012-07-31 17:11:23 +08:00
|
|
|
cpu_pmu->handle_irq = xscale1pmu_handle_irq;
|
|
|
|
cpu_pmu->enable = xscale1pmu_enable_event;
|
|
|
|
cpu_pmu->disable = xscale1pmu_disable_event;
|
|
|
|
cpu_pmu->read_counter = xscale1pmu_read_counter;
|
|
|
|
cpu_pmu->write_counter = xscale1pmu_write_counter;
|
|
|
|
cpu_pmu->get_event_idx = xscale1pmu_get_event_idx;
|
2018-07-10 16:58:01 +08:00
|
|
|
cpu_pmu->clear_event_idx = xscalepmu_clear_event_idx;
|
2012-07-31 17:11:23 +08:00
|
|
|
cpu_pmu->start = xscale1pmu_start;
|
|
|
|
cpu_pmu->stop = xscale1pmu_stop;
|
|
|
|
cpu_pmu->map_event = xscale_map_event;
|
|
|
|
cpu_pmu->num_events = 3;
|
|
|
|
|
|
|
|
return 0;
|
2010-11-14 03:04:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define XSCALE2_OVERFLOWED_MASK 0x01f
|
|
|
|
#define XSCALE2_CCOUNT_OVERFLOW 0x001
|
|
|
|
#define XSCALE2_COUNT0_OVERFLOW 0x002
|
|
|
|
#define XSCALE2_COUNT1_OVERFLOW 0x004
|
|
|
|
#define XSCALE2_COUNT2_OVERFLOW 0x008
|
|
|
|
#define XSCALE2_COUNT3_OVERFLOW 0x010
|
|
|
|
#define XSCALE2_CCOUNT_INT_EN 0x001
|
|
|
|
#define XSCALE2_COUNT0_INT_EN 0x002
|
|
|
|
#define XSCALE2_COUNT1_INT_EN 0x004
|
|
|
|
#define XSCALE2_COUNT2_INT_EN 0x008
|
|
|
|
#define XSCALE2_COUNT3_INT_EN 0x010
|
|
|
|
#define XSCALE2_COUNT0_EVT_SHFT 0
|
|
|
|
#define XSCALE2_COUNT0_EVT_MASK (0xff << XSCALE2_COUNT0_EVT_SHFT)
|
|
|
|
#define XSCALE2_COUNT1_EVT_SHFT 8
|
|
|
|
#define XSCALE2_COUNT1_EVT_MASK (0xff << XSCALE2_COUNT1_EVT_SHFT)
|
|
|
|
#define XSCALE2_COUNT2_EVT_SHFT 16
|
|
|
|
#define XSCALE2_COUNT2_EVT_MASK (0xff << XSCALE2_COUNT2_EVT_SHFT)
|
|
|
|
#define XSCALE2_COUNT3_EVT_SHFT 24
|
|
|
|
#define XSCALE2_COUNT3_EVT_MASK (0xff << XSCALE2_COUNT3_EVT_SHFT)
|
|
|
|
|
|
|
|
static inline u32
|
|
|
|
xscale2pmu_read_pmnc(void)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
asm volatile("mrc p14, 0, %0, c0, c1, 0" : "=r" (val));
|
|
|
|
/* bits 1-2 and 4-23 are read-unpredictable */
|
|
|
|
return val & 0xff000009;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
xscale2pmu_write_pmnc(u32 val)
|
|
|
|
{
|
|
|
|
/* bits 4-23 are write-as-0, 24-31 are write ignored */
|
|
|
|
val &= 0xf;
|
|
|
|
asm volatile("mcr p14, 0, %0, c0, c1, 0" : : "r" (val));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32
|
|
|
|
xscale2pmu_read_overflow_flags(void)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
asm volatile("mrc p14, 0, %0, c5, c1, 0" : "=r" (val));
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
xscale2pmu_write_overflow_flags(u32 val)
|
|
|
|
{
|
|
|
|
asm volatile("mcr p14, 0, %0, c5, c1, 0" : : "r" (val));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32
|
|
|
|
xscale2pmu_read_event_select(void)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
asm volatile("mrc p14, 0, %0, c8, c1, 0" : "=r" (val));
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
xscale2pmu_write_event_select(u32 val)
|
|
|
|
{
|
|
|
|
asm volatile("mcr p14, 0, %0, c8, c1, 0" : : "r"(val));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32
|
|
|
|
xscale2pmu_read_int_enable(void)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
asm volatile("mrc p14, 0, %0, c4, c1, 0" : "=r" (val));
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xscale2pmu_write_int_enable(u32 val)
|
|
|
|
{
|
|
|
|
asm volatile("mcr p14, 0, %0, c4, c1, 0" : : "r" (val));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
xscale2_pmnc_counter_has_overflowed(unsigned long of_flags,
|
|
|
|
enum xscale_counters counter)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (counter) {
|
|
|
|
case XSCALE_CYCLE_COUNTER:
|
|
|
|
ret = of_flags & XSCALE2_CCOUNT_OVERFLOW;
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER0:
|
|
|
|
ret = of_flags & XSCALE2_COUNT0_OVERFLOW;
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER1:
|
|
|
|
ret = of_flags & XSCALE2_COUNT1_OVERFLOW;
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER2:
|
|
|
|
ret = of_flags & XSCALE2_COUNT2_OVERFLOW;
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER3:
|
|
|
|
ret = of_flags & XSCALE2_COUNT3_OVERFLOW;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ONCE(1, "invalid counter number (%d)\n", counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t
|
2018-05-10 18:35:15 +08:00
|
|
|
xscale2pmu_handle_irq(struct arm_pmu *cpu_pmu)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
|
|
|
unsigned long pmnc, of_flags;
|
|
|
|
struct perf_sample_data data;
|
2014-05-14 02:36:31 +08:00
|
|
|
struct pmu_hw_events *cpuc = this_cpu_ptr(cpu_pmu->hw_events);
|
2010-11-14 03:04:32 +08:00
|
|
|
struct pt_regs *regs;
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
/* Disable the PMU. */
|
|
|
|
pmnc = xscale2pmu_read_pmnc();
|
|
|
|
xscale2pmu_write_pmnc(pmnc & ~XSCALE_PMU_ENABLE);
|
|
|
|
|
|
|
|
/* Check the overflow flag register. */
|
|
|
|
of_flags = xscale2pmu_read_overflow_flags();
|
|
|
|
if (!(of_flags & XSCALE2_OVERFLOWED_MASK))
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
/* Clear the overflow bits. */
|
|
|
|
xscale2pmu_write_overflow_flags(of_flags);
|
|
|
|
|
|
|
|
regs = get_irq_regs();
|
|
|
|
|
2011-05-17 18:20:11 +08:00
|
|
|
for (idx = 0; idx < cpu_pmu->num_events; ++idx) {
|
2010-11-14 03:04:32 +08:00
|
|
|
struct perf_event *event = cpuc->events[idx];
|
|
|
|
struct hw_perf_event *hwc;
|
|
|
|
|
2012-03-07 00:34:50 +08:00
|
|
|
if (!event)
|
|
|
|
continue;
|
|
|
|
|
2012-03-07 00:35:55 +08:00
|
|
|
if (!xscale2_pmnc_counter_has_overflowed(of_flags, idx))
|
2010-11-14 03:04:32 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
hwc = &event->hw;
|
2012-07-30 19:00:02 +08:00
|
|
|
armpmu_event_update(event);
|
2012-04-03 02:19:08 +08:00
|
|
|
perf_sample_data_init(&data, 0, hwc->last_period);
|
2012-07-30 19:00:02 +08:00
|
|
|
if (!armpmu_event_set_period(event))
|
2010-11-14 03:04:32 +08:00
|
|
|
continue;
|
|
|
|
|
2011-06-27 20:41:57 +08:00
|
|
|
if (perf_event_overflow(event, &data, regs))
|
2012-07-30 19:00:02 +08:00
|
|
|
cpu_pmu->disable(event);
|
2010-11-14 03:04:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
irq_work_run();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-enable the PMU.
|
|
|
|
*/
|
|
|
|
pmnc = xscale2pmu_read_pmnc() | XSCALE_PMU_ENABLE;
|
|
|
|
xscale2pmu_write_pmnc(pmnc);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2012-07-30 19:00:02 +08:00
|
|
|
static void xscale2pmu_enable_event(struct perf_event *event)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
|
|
|
unsigned long flags, ien, evtsel;
|
2012-07-30 19:00:02 +08:00
|
|
|
struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
|
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
2014-05-14 02:36:31 +08:00
|
|
|
struct pmu_hw_events *events = this_cpu_ptr(cpu_pmu->hw_events);
|
2012-07-30 19:00:02 +08:00
|
|
|
int idx = hwc->idx;
|
2010-11-14 03:04:32 +08:00
|
|
|
|
|
|
|
ien = xscale2pmu_read_int_enable();
|
|
|
|
evtsel = xscale2pmu_read_event_select();
|
|
|
|
|
|
|
|
switch (idx) {
|
|
|
|
case XSCALE_CYCLE_COUNTER:
|
|
|
|
ien |= XSCALE2_CCOUNT_INT_EN;
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER0:
|
|
|
|
ien |= XSCALE2_COUNT0_INT_EN;
|
|
|
|
evtsel &= ~XSCALE2_COUNT0_EVT_MASK;
|
|
|
|
evtsel |= hwc->config_base << XSCALE2_COUNT0_EVT_SHFT;
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER1:
|
|
|
|
ien |= XSCALE2_COUNT1_INT_EN;
|
|
|
|
evtsel &= ~XSCALE2_COUNT1_EVT_MASK;
|
|
|
|
evtsel |= hwc->config_base << XSCALE2_COUNT1_EVT_SHFT;
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER2:
|
|
|
|
ien |= XSCALE2_COUNT2_INT_EN;
|
|
|
|
evtsel &= ~XSCALE2_COUNT2_EVT_MASK;
|
|
|
|
evtsel |= hwc->config_base << XSCALE2_COUNT2_EVT_SHFT;
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER3:
|
|
|
|
ien |= XSCALE2_COUNT3_INT_EN;
|
|
|
|
evtsel &= ~XSCALE2_COUNT3_EVT_MASK;
|
|
|
|
evtsel |= hwc->config_base << XSCALE2_COUNT3_EVT_SHFT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ONCE(1, "invalid counter number (%d)\n", idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_lock_irqsave(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
xscale2pmu_write_event_select(evtsel);
|
|
|
|
xscale2pmu_write_int_enable(ien);
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
}
|
|
|
|
|
2012-07-30 19:00:02 +08:00
|
|
|
static void xscale2pmu_disable_event(struct perf_event *event)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
2012-03-07 00:35:55 +08:00
|
|
|
unsigned long flags, ien, evtsel, of_flags;
|
2012-07-30 19:00:02 +08:00
|
|
|
struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
|
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
2014-05-14 02:36:31 +08:00
|
|
|
struct pmu_hw_events *events = this_cpu_ptr(cpu_pmu->hw_events);
|
2012-07-30 19:00:02 +08:00
|
|
|
int idx = hwc->idx;
|
2010-11-14 03:04:32 +08:00
|
|
|
|
|
|
|
ien = xscale2pmu_read_int_enable();
|
|
|
|
evtsel = xscale2pmu_read_event_select();
|
|
|
|
|
|
|
|
switch (idx) {
|
|
|
|
case XSCALE_CYCLE_COUNTER:
|
|
|
|
ien &= ~XSCALE2_CCOUNT_INT_EN;
|
2012-03-07 00:35:55 +08:00
|
|
|
of_flags = XSCALE2_CCOUNT_OVERFLOW;
|
2010-11-14 03:04:32 +08:00
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER0:
|
|
|
|
ien &= ~XSCALE2_COUNT0_INT_EN;
|
|
|
|
evtsel &= ~XSCALE2_COUNT0_EVT_MASK;
|
|
|
|
evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT0_EVT_SHFT;
|
2012-03-07 00:35:55 +08:00
|
|
|
of_flags = XSCALE2_COUNT0_OVERFLOW;
|
2010-11-14 03:04:32 +08:00
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER1:
|
|
|
|
ien &= ~XSCALE2_COUNT1_INT_EN;
|
|
|
|
evtsel &= ~XSCALE2_COUNT1_EVT_MASK;
|
|
|
|
evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT1_EVT_SHFT;
|
2012-03-07 00:35:55 +08:00
|
|
|
of_flags = XSCALE2_COUNT1_OVERFLOW;
|
2010-11-14 03:04:32 +08:00
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER2:
|
|
|
|
ien &= ~XSCALE2_COUNT2_INT_EN;
|
|
|
|
evtsel &= ~XSCALE2_COUNT2_EVT_MASK;
|
|
|
|
evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT2_EVT_SHFT;
|
2012-03-07 00:35:55 +08:00
|
|
|
of_flags = XSCALE2_COUNT2_OVERFLOW;
|
2010-11-14 03:04:32 +08:00
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER3:
|
|
|
|
ien &= ~XSCALE2_COUNT3_INT_EN;
|
|
|
|
evtsel &= ~XSCALE2_COUNT3_EVT_MASK;
|
|
|
|
evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT3_EVT_SHFT;
|
2012-03-07 00:35:55 +08:00
|
|
|
of_flags = XSCALE2_COUNT3_OVERFLOW;
|
2010-11-14 03:04:32 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ONCE(1, "invalid counter number (%d)\n", idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_lock_irqsave(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
xscale2pmu_write_event_select(evtsel);
|
|
|
|
xscale2pmu_write_int_enable(ien);
|
2012-03-07 00:35:55 +08:00
|
|
|
xscale2pmu_write_overflow_flags(of_flags);
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-05-17 18:20:11 +08:00
|
|
|
xscale2pmu_get_event_idx(struct pmu_hw_events *cpuc,
|
2012-07-30 19:00:02 +08:00
|
|
|
struct perf_event *event)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
|
|
|
int idx = xscale1pmu_get_event_idx(cpuc, event);
|
|
|
|
if (idx >= 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!test_and_set_bit(XSCALE_COUNTER3, cpuc->used_mask))
|
|
|
|
idx = XSCALE_COUNTER3;
|
|
|
|
else if (!test_and_set_bit(XSCALE_COUNTER2, cpuc->used_mask))
|
|
|
|
idx = XSCALE_COUNTER2;
|
|
|
|
out:
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2012-07-30 19:00:02 +08:00
|
|
|
static void xscale2pmu_start(struct arm_pmu *cpu_pmu)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
|
|
|
unsigned long flags, val;
|
2014-05-14 02:36:31 +08:00
|
|
|
struct pmu_hw_events *events = this_cpu_ptr(cpu_pmu->hw_events);
|
2010-11-14 03:04:32 +08:00
|
|
|
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_lock_irqsave(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
val = xscale2pmu_read_pmnc() & ~XSCALE_PMU_CNT64;
|
|
|
|
val |= XSCALE_PMU_ENABLE;
|
|
|
|
xscale2pmu_write_pmnc(val);
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
}
|
|
|
|
|
2012-07-30 19:00:02 +08:00
|
|
|
static void xscale2pmu_stop(struct arm_pmu *cpu_pmu)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
|
|
|
unsigned long flags, val;
|
2014-05-14 02:36:31 +08:00
|
|
|
struct pmu_hw_events *events = this_cpu_ptr(cpu_pmu->hw_events);
|
2010-11-14 03:04:32 +08:00
|
|
|
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_lock_irqsave(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
val = xscale2pmu_read_pmnc();
|
|
|
|
val &= ~XSCALE_PMU_ENABLE;
|
|
|
|
xscale2pmu_write_pmnc(val);
|
2011-04-28 17:17:04 +08:00
|
|
|
raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
|
2010-11-14 03:04:32 +08:00
|
|
|
}
|
|
|
|
|
2018-07-10 16:57:59 +08:00
|
|
|
static inline u64 xscale2pmu_read_counter(struct perf_event *event)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
2012-07-30 19:00:02 +08:00
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
|
|
|
int counter = hwc->idx;
|
2010-11-14 03:04:32 +08:00
|
|
|
u32 val = 0;
|
|
|
|
|
|
|
|
switch (counter) {
|
|
|
|
case XSCALE_CYCLE_COUNTER:
|
|
|
|
asm volatile("mrc p14, 0, %0, c1, c1, 0" : "=r" (val));
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER0:
|
|
|
|
asm volatile("mrc p14, 0, %0, c0, c2, 0" : "=r" (val));
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER1:
|
|
|
|
asm volatile("mrc p14, 0, %0, c1, c2, 0" : "=r" (val));
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER2:
|
|
|
|
asm volatile("mrc p14, 0, %0, c2, c2, 0" : "=r" (val));
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER3:
|
|
|
|
asm volatile("mrc p14, 0, %0, c3, c2, 0" : "=r" (val));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2018-07-10 16:57:59 +08:00
|
|
|
static inline void xscale2pmu_write_counter(struct perf_event *event, u64 val)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
2012-07-30 19:00:02 +08:00
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
|
|
|
int counter = hwc->idx;
|
|
|
|
|
2010-11-14 03:04:32 +08:00
|
|
|
switch (counter) {
|
|
|
|
case XSCALE_CYCLE_COUNTER:
|
|
|
|
asm volatile("mcr p14, 0, %0, c1, c1, 0" : : "r" (val));
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER0:
|
|
|
|
asm volatile("mcr p14, 0, %0, c0, c2, 0" : : "r" (val));
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER1:
|
|
|
|
asm volatile("mcr p14, 0, %0, c1, c2, 0" : : "r" (val));
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER2:
|
|
|
|
asm volatile("mcr p14, 0, %0, c2, c2, 0" : : "r" (val));
|
|
|
|
break;
|
|
|
|
case XSCALE_COUNTER3:
|
|
|
|
asm volatile("mcr p14, 0, %0, c3, c2, 0" : : "r" (val));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:02:24 +08:00
|
|
|
static int xscale2pmu_init(struct arm_pmu *cpu_pmu)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
2012-12-20 00:33:24 +08:00
|
|
|
cpu_pmu->name = "armv5_xscale2";
|
2012-07-31 17:11:23 +08:00
|
|
|
cpu_pmu->handle_irq = xscale2pmu_handle_irq;
|
|
|
|
cpu_pmu->enable = xscale2pmu_enable_event;
|
|
|
|
cpu_pmu->disable = xscale2pmu_disable_event;
|
|
|
|
cpu_pmu->read_counter = xscale2pmu_read_counter;
|
|
|
|
cpu_pmu->write_counter = xscale2pmu_write_counter;
|
|
|
|
cpu_pmu->get_event_idx = xscale2pmu_get_event_idx;
|
2018-07-10 16:58:01 +08:00
|
|
|
cpu_pmu->clear_event_idx = xscalepmu_clear_event_idx;
|
2012-07-31 17:11:23 +08:00
|
|
|
cpu_pmu->start = xscale2pmu_start;
|
|
|
|
cpu_pmu->stop = xscale2pmu_stop;
|
|
|
|
cpu_pmu->map_event = xscale_map_event;
|
|
|
|
cpu_pmu->num_events = 5;
|
|
|
|
|
|
|
|
return 0;
|
2010-11-14 03:04:32 +08:00
|
|
|
}
|
2015-05-27 00:23:36 +08:00
|
|
|
|
|
|
|
static const struct pmu_probe_info xscale_pmu_probe_table[] = {
|
|
|
|
XSCALE_PMU_PROBE(ARM_CPU_XSCALE_ARCH_V1, xscale1pmu_init),
|
|
|
|
XSCALE_PMU_PROBE(ARM_CPU_XSCALE_ARCH_V2, xscale2pmu_init),
|
|
|
|
{ /* sentinel value */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int xscale_pmu_device_probe(struct platform_device *pdev)
|
2010-11-14 03:04:32 +08:00
|
|
|
{
|
2015-05-27 00:23:36 +08:00
|
|
|
return arm_pmu_device_probe(pdev, NULL, xscale_pmu_probe_table);
|
2010-11-14 03:04:32 +08:00
|
|
|
}
|
|
|
|
|
2015-05-27 00:23:36 +08:00
|
|
|
static struct platform_driver xscale_pmu_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "xscale-pmu",
|
|
|
|
},
|
|
|
|
.probe = xscale_pmu_device_probe,
|
|
|
|
};
|
|
|
|
|
2016-11-23 22:39:52 +08:00
|
|
|
builtin_platform_driver(xscale_pmu_driver);
|
2010-11-14 03:04:32 +08:00
|
|
|
#endif /* CONFIG_CPU_XSCALE */
|