* [PATCH 0/6] perf: PMU for Arteris FlexNoC
@ 2026-11-30 12:51 Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 1/6] dt-bindings: vendor-prefixes: Add arteris Vladimir Kondratiev
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Vladimir Kondratiev @ 2026-11-30 12:51 UTC (permalink / raw)
To: Will Deacon, Mark Rutland, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Benoît Monin, Gregory CLEMENT, Théo Lebrun,
Thomas Bogendoerfer
Cc: linux-arm-kernel, linux-perf-users, devicetree, linux-kernel,
linux-doc, linux-mips, Vladimir Kondratiev
Arteris FlexNoC interconnects include packet probe units with statistics
counters for observing NoC traffic. Counters are one-shot (no wrap-around
or interrupt) and saturate at all ones (-1), with optional pairing to chain
two counters for double width.
Patch 1 adds the "arteris" Device Tree vendor prefix.
Patch 2 adds the Device Tree binding for Arteris FlexNoC interconnects.
Patch 3 adds the packet probe perf PMU driver and admin-guide
documentation covering the perf interface, events, and packet filters.
Patch 4 adds a MAINTAINERS entry for the binding, driver, and docs.
Patch 5 adds FlexNoC interconnect nodes for the Mobileye EyeQ6H SoC.
Patch 6 enables CONFIG_PERF_EVENTS and builds CONFIG_ARTERIS_FLEXNOC_PMU
as a module in eyeq6_defconfig.
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
Vladimir Kondratiev (6):
dt-bindings: vendor-prefixes: Add arteris
dt-bindings: perf: Add Arteris FlexNoC interconnect
perf: Add Arteris FlexNoC packet probe PMU driver
MAINTAINERS: Add entry for Arteris FlexNoC PMU
mips: dts: eyeq6h: Add FlexNoC interconnects
MIPS: eyeq6_defconfig: Enable Arteris FlexNoC PMU
.../admin-guide/perf/arteris_flexnoc_pmu.rst | 209 +++
Documentation/admin-guide/perf/index.rst | 1 +
.../devicetree/bindings/perf/arteris,flexnoc.yaml | 74 +
.../devicetree/bindings/vendor-prefixes.yaml | 2 +
MAINTAINERS | 7 +
arch/mips/boot/dts/mobileye/eyeq6h.dtsi | 12 +
arch/mips/configs/eyeq6_defconfig | 2 +
drivers/perf/Kconfig | 13 +
drivers/perf/Makefile | 1 +
drivers/perf/arteris_flexnoc_pmu.c | 1486 ++++++++++++++++++++
10 files changed, 1807 insertions(+)
---
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
change-id: 20261123-flexnoc-pmu-b8a6de5f2de4
Best regards,
--
Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/6] dt-bindings: vendor-prefixes: Add arteris
2026-11-30 12:51 [PATCH 0/6] perf: PMU for Arteris FlexNoC Vladimir Kondratiev
@ 2026-11-30 12:51 ` Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 2/6] dt-bindings: perf: Add Arteris FlexNoC interconnect Vladimir Kondratiev
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Vladimir Kondratiev @ 2026-11-30 12:51 UTC (permalink / raw)
To: Will Deacon, Mark Rutland, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Benoît Monin, Gregory CLEMENT, Théo Lebrun,
Thomas Bogendoerfer
Cc: linux-arm-kernel, linux-perf-users, devicetree, linux-kernel,
linux-doc, linux-mips, Vladimir Kondratiev
Add a vendor prefix entry for Arteris, Inc. (https://www.arteris.com/).
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index ba2002969373..70ec986b1aee 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -180,6 +180,8 @@ patternProperties:
description: ArmSoM Technology Co., Ltd.
"^arrow,.*":
description: Arrow Electronics
+ "^arteris,.*":
+ description: Arteris, Inc.
"^artesyn,.*":
description: Artesyn Embedded Technologies Inc.
"^asahi-kasei,.*":
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/6] dt-bindings: perf: Add Arteris FlexNoC interconnect
2026-11-30 12:51 [PATCH 0/6] perf: PMU for Arteris FlexNoC Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 1/6] dt-bindings: vendor-prefixes: Add arteris Vladimir Kondratiev
@ 2026-11-30 12:51 ` Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 3/6] perf: Add Arteris FlexNoC packet probe PMU driver Vladimir Kondratiev
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Vladimir Kondratiev @ 2026-11-30 12:51 UTC (permalink / raw)
To: Will Deacon, Mark Rutland, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Benoît Monin, Gregory CLEMENT, Théo Lebrun,
Thomas Bogendoerfer
Cc: linux-arm-kernel, linux-perf-users, devicetree, linux-kernel,
linux-doc, linux-mips, Vladimir Kondratiev
Add a Device Tree binding for the Arteris FlexNoC interconnect used by
the performance monitoring driver. Each node describes a single service-
network register range where hardware units (including packet probes) are
discovered at runtime.
Document the optional "arteris,counter-bits" property for counter widths
that cannot be read back from hardware, and the optional "label"
property used to name the resulting PMUs.
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
.../devicetree/bindings/perf/arteris,flexnoc.yaml | 74 ++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/Documentation/devicetree/bindings/perf/arteris,flexnoc.yaml b/Documentation/devicetree/bindings/perf/arteris,flexnoc.yaml
new file mode 100644
index 000000000000..ed8f68da7062
--- /dev/null
+++ b/Documentation/devicetree/bindings/perf/arteris,flexnoc.yaml
@@ -0,0 +1,74 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/perf/arteris,flexnoc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Arteris FlexNoC interconnect
+
+maintainers:
+ - Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
+
+description:
+ An Arteris FlexNoC interconnect gives run-time access to the registers of
+ its hardware units, such as observation probes, sideband managers and error
+ loggers, through a service network. The units are mapped one after the
+ other in a single register range, in blocks of 128 to 1024 bytes, each
+ starting with the same identification registers. Units are discovered by
+ reading those registers; a SoC usually has several FlexNoC instances, each
+ with its own set of units. Packet probes with statistics counters are
+ exposed as performance monitoring units.
+
+properties:
+ compatible:
+ oneOf:
+ - items:
+ - enum:
+ - mobileye,eyeq6h-flexnoc
+ - const: arteris,flexnoc
+ - const: arteris,flexnoc
+
+ reg:
+ maxItems: 1
+ description:
+ The range of unit registers of the interconnect. It must not extend
+ past the last unit; registers in gaps between units answer with a bus
+ error, but the range must be backed by the service network.
+
+ arteris,counter-bits:
+ description:
+ Width in bits of the statistics counters of the packet probes of this
+ interconnect, which is a build option of the NoC that cannot be read
+ back from the hardware.
+ minimum: 8
+ maximum: 32
+ default: 32
+
+ label:
+ description:
+ human-readable name for the interconnect node
+
+required:
+ - compatible
+ - reg
+
+additionalProperties: false
+
+examples:
+ - |
+ soc {
+ #address-cells = <2>;
+ #size-cells = <2>;
+
+ noc_ncore_ccti: interconnect@d1d00000 {
+ compatible = "mobileye,eyeq6h-flexnoc", "arteris,flexnoc";
+ reg = <0 0xd1d00000 0 0x1000>;
+ label = "flexnoc_ccti";
+ };
+
+ interconnect@48419000 {
+ compatible = "arteris,flexnoc";
+ reg = <0x0 0x48419000 0x0 0x1000>;
+ arteris,counter-bits = <24>;
+ };
+ };
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/6] perf: Add Arteris FlexNoC packet probe PMU driver
2026-11-30 12:51 [PATCH 0/6] perf: PMU for Arteris FlexNoC Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 1/6] dt-bindings: vendor-prefixes: Add arteris Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 2/6] dt-bindings: perf: Add Arteris FlexNoC interconnect Vladimir Kondratiev
@ 2026-11-30 12:51 ` Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 4/6] MAINTAINERS: Add entry for Arteris FlexNoC PMU Vladimir Kondratiev
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Vladimir Kondratiev @ 2026-11-30 12:51 UTC (permalink / raw)
To: Will Deacon, Mark Rutland, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Benoît Monin, Gregory CLEMENT, Théo Lebrun,
Thomas Bogendoerfer
Cc: linux-arm-kernel, linux-perf-users, devicetree, linux-kernel,
linux-doc, linux-mips, Vladimir Kondratiev
Add a perf PMU driver for packet probes in Arteris FlexNoC interconnects.
For each arteris,flexnoc node, the driver scans the register range by
CoreId and RevisionId, detects statistics counters on packet probes
bounded by the next unit, and registers a PMU per probe with counters.
Counters are one-shot, do not generate interrupts, and saturate at -1.
Adjacent even/odd counters can be chained for 2x width (needed for
high-rate events such as payload bytes). Supported events include
cycle, idle, xfer, busy, wait, pkt, byte, press0-2, and external event
signals (including transaction profiler bins).
On probes with packet filters, filt_pkt and filt_byte count traffic
matching filter 0 with the LUT configured to pass its hits (supporting
trace port, opcode, status, length, address window, and route ID/mask).
Because filter 0 is shared across a probe's events, concurrent filtered
events must share the same filter configuration, and programming a new
filter briefly pauses an active probe.
Events are system-wide; sampling and per-task events are not supported.
Rejected configurations log reasons via dev_dbg(). Include admin-guide
documentation under Documentation/admin-guide/perf/.
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
.../admin-guide/perf/arteris_flexnoc_pmu.rst | 209 +++
Documentation/admin-guide/perf/index.rst | 1 +
drivers/perf/Kconfig | 13 +
drivers/perf/Makefile | 1 +
drivers/perf/arteris_flexnoc_pmu.c | 1486 ++++++++++++++++++++
5 files changed, 1710 insertions(+)
diff --git a/Documentation/admin-guide/perf/arteris_flexnoc_pmu.rst b/Documentation/admin-guide/perf/arteris_flexnoc_pmu.rst
new file mode 100644
index 000000000000..f54ff85e340f
--- /dev/null
+++ b/Documentation/admin-guide/perf/arteris_flexnoc_pmu.rst
@@ -0,0 +1,209 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=================================================
+Arteris FlexNoC packet probe (perf) driver
+=================================================
+
+An Arteris FlexNoC interconnect consists of network interface units (NIUs),
+switches, and optional observation hardware that monitors interconnect traffic.
+A *packet probe* observes one or more probe points in the NoC datapath and,
+when built with statistics collection, provides up to 32 statistics counters.
+Each counter can be programmed at runtime to count a selected event: probe clock
+cycles; idle, transfer, busy, or wait cycles on a probe port; packets or
+payload bytes crossing a probe port; cycles above a QoS pressure threshold; or
+an external event signal. Counters run freely while enabled and can be read
+at any time. Two adjacent counters (even base, odd carry) can be chained to
+form a counter of twice the width.
+
+A SoC typically contains multiple FlexNoC instances. For each instance, the
+driver scans the unit register range, identifies packet probes that have
+statistics counters, and registers one ``perf`` PMU per probe. Events are
+system-wide (uncore); per-task counting and sampling are not supported.
+
+Discovery
+---------
+
+Hardware unit registers in a FlexNoC instance are laid out contiguously in
+blocks of 128 to 1024 bytes within a single ``reg`` range. Every unit begins
+with two identification registers: ``CoreId`` (unit type in bits ``7:0``) and
+``RevisionId`` (FlexNoC release in bits ``31:8``). The driver scans the
+``reg`` range in 128-byte steps and reads these registers. A block is
+treated as a unit if its unit type is valid and its FlexNoC release matches
+the first unit discovered in that NoC instance.
+
+Packet probes (unit type 6) are then probed for statistics counters by
+writing to counter control registers up to the next discovered unit or the
+maximum unit size (1024 bytes). Probes without statistics counters do not get a
+PMU. Other unit types are not registered as PMUs; in particular, a transaction
+profiler (unit type 10) has no counters of its own and instead feeds
+histogram bins as external event signals into a packet probe's counters once
+configured separately.
+
+Use ``dyndbg`` (``dev_dbg``) to inspect discovered units and probes::
+
+ echo 'module arteris_flexnoc_pmu +p' > /sys/kernel/debug/dynamic_debug/control
+
+Counter width and saturation
+----------------------------
+
+Counter width (8 to 32 bits) is a synthesis-time parameter that cannot be read
+back from hardware. Set ``arteris,counter-bits`` in the Device Tree node if
+the width differs from the default of 32 bits.
+
+Counters have no overflow interrupt and do not wrap around; once a counter
+reaches its maximum value (all ones, ``-1``), it saturates and stops
+incrementing.
+
+PMU naming and sysfs attributes
+--------------------------------
+
+Each registered PMU is named ``<prefix>_<n>``, where ``<n>`` is a 0-based
+index of counter-capable probes within that FlexNoC instance (in ascending
+address order), and ``<prefix>`` comes from the node's ``label`` property or
+falls back to ``flexnoc_<address>``. Because PMU names share a single
+namespace, each FlexNoC instance must use a distinct prefix (for example,
+``flexnoc_ccti`` or ``flexnoc_interleaver`` on EyeQ6H, or ``flexnoc_ddr0``,
+``flexnoc_west``, or ``flexnoc_east`` on EyeQ7H).
+
+The ``perf`` tool strips a trailing ``_<n>`` suffix when matching PMU names on
+the command line, so ``flexnoc_ddr0`` targets all probes on ``ddr0``, and
+shell/perf wildcards such as ``flexnoc_ddr*`` can match multiple instances.
+
+Each PMU exposes the following attributes under
+``/sys/bus/event_source/devices/<pmu>/``::
+
+ unit_offset # byte offset of the probe unit within the NoC reg range
+ identifier # FlexNoC release and user ID ("arteris-flexnoc-<fid>-<uid>")
+ num_counters # number of statistics counters available on this probe
+ counter_bits # width in bits of each individual counter
+ port_mask # maximum valid port selector value for unchained/port events
+ num_filters # number of packet filters detected (0 to 4)
+ cpumask # single CPU designated to handle events for this PMU
+
+Events
+------
+
+Events are configured via ``perf_event_attr.config``:
+
+========= =========== ====================================================
+Field Bits Meaning
+========= =========== ====================================================
+``event`` ``0-8`` Counter event source (see below)
+``port`` ``16-23`` Probe port number (for port-scoped events)
+``chain`` ``24`` Pair two counters for ``2 * counter_bits`` width
+========= =========== ====================================================
+
+Port numbering is defined by the NoC's FlexArtist topology; ``port_mask``
+gives the highest selectable port value. Built-in symbolic events:
+
+========== ======== ====== ===============================================
+Event Value Port Counts
+========== ======== ====== ===============================================
+``cycle`` ``0x01`` no Probe clock cycles
+``idle`` ``0x02`` yes Cycles with no packet data on the port
+``xfer`` ``0x03`` yes Cycles with packet data transferred
+``busy`` ``0x04`` yes Cycles with data ready but receiver not ready
+``wait`` ``0x05`` yes Cycles a packet transfer is stalled/suspended
+``pkt`` ``0x06`` yes Packets transferred
+``byte`` ``0x08`` yes Payload bytes transferred (requires ``chain=1``)
+``press0`` ``0x09`` yes Cycles with QoS pressure level > 0
+``press1`` ``0x0a`` yes Cycles with QoS pressure level > 1
+``press2`` ``0x0b`` yes Cycles with QoS pressure level > 2
+========== ======== ====== ===============================================
+
+Event sources ``0x20`` to ``0x11f`` count clock cycles while external event
+signal ``event - 0x20`` (such as a transaction profiler bin) is asserted;
+their meaning is specific to the NoC design. Filter-hit and byte-enable
+sources (``0x0c`` to ``0x0f``, ``0x11``, ``0x13``, and ``0x14``) are not
+supported directly.
+
+Packet filters
+--------------
+
+When a probe includes packet filters (``num_filters`` > 0), the driver uses
+filter 0 together with the filter lookup table (LUT) programmed to pass hits
+from filter 0. Two additional events are exposed on filter-capable probes:
+``filt_pkt`` (``0x07``, matching packets) and ``filt_byte`` (``0x12`` with
+``chain=1``, payload bytes of matching packets). Any filter criterion left
+unset is wildcarded so all packets match that criterion.
+
+============== ================== =========================================
+Field Bits Matches packets
+============== ================== =========================================
+``port`` ``config:16-23`` Observed at this trace port selector
+``rd`` ``config:40`` Read transactions
+``wr`` ``config:41`` Write transactions
+``lock`` ``config:42`` Exclusive accesses and locked sequences
+``urg`` ``config:43`` Urgency packets
+``req`` ``config:44`` Request packets
+``rsp`` ``config:45`` Response packets
+``len_en`` ``config:52`` Length at most ``2^len`` bytes (when set)
+``len`` ``config:48-51`` Power-of-two length exponent for ``len_en``
+``addr_en`` ``config:62`` Within address window (when set)
+``addr`` ``config1:0-63`` Base address of the window (target space)
+``window`` ``config:56-61`` Window size as ``log2(bytes)``
+``route_id`` ``config2:0-31`` Route ID value for masked comparison
+``route_mask`` ``config2:32-63`` Bitmask applied to route ID comparison
+============== ================== =========================================
+
+Setting multiple opcode flags (``rd``, ``wr``, ``lock``, ``urg``) or status
+flags (``req``, ``rsp``) matches any of the selected flags (logical OR).
+Address windows are aligned down to ``2^window`` bytes. Route IDs, masks,
+and address windows are determined by the NoC's FlexArtist configuration;
+values exceeding hardware capabilities or out-of-range window/address
+parameters are rejected with ``-EINVAL``.
+
+Filter 0 and the trace port selector are shared across all events on a probe.
+Concurrent filtered events (including within a group) must specify the same
+filter configuration; an event requesting a different filter is deferred until
+active conflicting events finish and ``perf`` rotates them in. Because filter
+registers must only be modified while the probe is inactive, programming a
+new filter when other events are already running briefly pauses the probe,
+during which running counters may miss traffic.
+
+Examples
+--------
+
+Count packets and payload bytes on port 1 of ``flexnoc_ddr0_0`` for 5
+seconds::
+
+ perf stat -a -e flexnoc_ddr0_0/pkt,port=1/ \
+ -e flexnoc_ddr0_0/byte,port=1/ -- sleep 5
+
+Measure cycle breakdown on port 0::
+
+ perf stat -a -e flexnoc_ddr0_0/cycle/,flexnoc_ddr0_0/busy,port=0/,flexnoc_ddr0_0/idle,port=0/ \
+ -- sleep 5
+
+Sample packet counts across all probes matching ``flexnoc_ddr*``::
+
+ perf stat -a -e 'flexnoc_ddr*/pkt,port=0/' -- sleep 5
+
+Count filtered write packets and bytes up to 64 bytes (``2^6``) on trace
+port 1::
+
+ perf stat -a -e flexnoc_ddr0_0/filt_pkt,port=1,wr=1,len_en=1,len=6/ \
+ -e flexnoc_ddr0_0/filt_byte,port=1,wr=1,len_en=1,len=6/ -- sleep 5
+
+Each unchained event consumes 1 counter and each chained event consumes 2
+counters. Event groups that require more counters than ``num_counters`` or
+mix incompatible filters are rejected.
+
+Hardware behavior and caveats
+-----------------------------
+
+The driver enables ``MainCtl.StatEn`` and ``CfgCtl.GlobalEn`` while events
+are active and leaves counters running between reads. To reach
+``CfgCtl.Active``, the driver configures counter sources first, sets
+``StatEn`` (which clears all counters on the probe), sets ``GlobalEn``, and
+waits for ``Active``. When the last event is removed, it clears ``GlobalEn``
+first and then ``StatEn``. Individual events are started and stopped via their
+counter's source register (``FLEXNOC_SRC_OFF`` freezes the counter while
+preserving its count). Because individual counters cannot be cleared
+independently, the driver snapshots the current counter value on start.
+
+The driver programs filter 0 and ``FilterLUT`` (passing filter 0 hits) and
+leaves other filters, trace units, and alarm logic untouched. Do not run
+concurrent firmware or external tools that modify statistics counters or
+periodic statistics dumps on the same probe, as counter state and values will
+be corrupted.
\ No newline at end of file
diff --git a/Documentation/admin-guide/perf/index.rst b/Documentation/admin-guide/perf/index.rst
index aa12708ddb96..56fda089a4b6 100644
--- a/Documentation/admin-guide/perf/index.rst
+++ b/Documentation/admin-guide/perf/index.rst
@@ -31,3 +31,4 @@ Performance monitor support
ampere_cspmu
mrvl-pem-pmu
fujitsu_uncore_pmu
+ arteris_flexnoc_pmu
diff --git a/drivers/perf/Kconfig b/drivers/perf/Kconfig
index 245e7bb763b9..34915c70853f 100644
--- a/drivers/perf/Kconfig
+++ b/drivers/perf/Kconfig
@@ -325,4 +325,17 @@ config NVIDIA_TEGRA410_C2C_PMU
Enable perf support for counters in NVIDIA C2C interface of NVIDIA
Tegra410 SoC.
+config ARTERIS_FLEXNOC_PMU
+ tristate "Arteris FlexNoC interconnect probe PMU support"
+ help
+ Provide support for the packet probes of Arteris FlexNoC
+ interconnects. The statistics counters of each probe are found by
+ scanning the register space of every FlexNoC instance, and each
+ probe is registered as a perf PMU counting cycles, packets, bytes,
+ idle, busy and wait cycles of its probe ports, QoS pressure and
+ external events, and packets that match a packet filter.
+
+ This driver can also be built as a module. If so, the module will
+ be called arteris_flexnoc_pmu.
+
endmenu
diff --git a/drivers/perf/Makefile b/drivers/perf/Makefile
index eb8a022dad9a..32e782b41594 100644
--- a/drivers/perf/Makefile
+++ b/drivers/perf/Makefile
@@ -37,3 +37,4 @@ obj-$(CONFIG_MESON_DDR_PMU) += amlogic/
obj-$(CONFIG_CXL_PMU) += cxl_pmu.o
obj-$(CONFIG_NVIDIA_TEGRA410_CMEM_LATENCY_PMU) += nvidia_t410_cmem_latency_pmu.o
obj-$(CONFIG_NVIDIA_TEGRA410_C2C_PMU) += nvidia_t410_c2c_pmu.o
+obj-$(CONFIG_ARTERIS_FLEXNOC_PMU) += arteris_flexnoc_pmu.o
diff --git a/drivers/perf/arteris_flexnoc_pmu.c b/drivers/perf/arteris_flexnoc_pmu.c
new file mode 100644
index 000000000000..0d2a3268079a
--- /dev/null
+++ b/drivers/perf/arteris_flexnoc_pmu.c
@@ -0,0 +1,1486 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Arteris FlexNoC packet probe performance monitor driver
+ *
+ * Copyright (C) 2026 Mobileye Corporation
+ *
+ * A FlexNoC interconnect exposes the run-time registers of its hardware
+ * units (probes, sideband managers, error loggers, ...) through a service
+ * network, as a sequence of register blocks of 128 to 1024 bytes in one
+ * contiguous address range. Every block starts with the same two
+ * identification registers:
+ *
+ * - CoreId: the unit type in bits 7:0, a configuration checksum above;
+ * - RevisionId: a user-defined byte, and in bits 31:8 the FlexNoC release
+ * the NoC was generated with, the same value in every unit of one NoC.
+ *
+ * The packet probe (unit type 6) watches one or more probe points in the
+ * datapath and, if built with statistics collection, owns up to 32
+ * statistics counters. Each counter increments on one event picked from
+ * Counters_M_Src: probe clock cycles, idle/transfer/busy/wait cycles of a
+ * probe port, packets and payload bytes crossing a probe port, cycles at
+ * a given QoS pressure level, or an external event signal.
+ * Counters have no overflow interrupt and do not wrap around; once a counter
+ * reaches its maximum value (all ones, ``-1``), it saturates and stops
+ * incrementing. Counters can be read at any time and can be chained in pairs
+ * (the odd one counting the carries of the even one) to get twice the width.
+ * Their width is a build option between 8 and 32 bits.
+ *
+ * Discovery: there is one platform device per FlexNoC instance. The probe
+ * walks the address range one 128-byte block at a time, reading the
+ * identification registers of each block. A block is a unit if the unit type
+ * is valid and its FlexNoC release matches that of the first unit found.
+ * Probes found this way are then checked for statistics counters, which can
+ * be told apart by writing to them, and each probe with at least one counter
+ * registers a perf PMU. The unit extends up to the next unit found, which bounds how
+ * many counters it can hold. Other unit types are skipped; the transaction
+ * profiler (type 10) only feeds histogram bins into the statistics counters
+ * of a packet probe as external events and has no counters of its own.
+ *
+ * The counter width cannot be read back and comes from the optional
+ * "arteris,counter-bits" property, 32 by default.
+ *
+ * A probe may also have up to four packet filters, which select packets by
+ * route ID, address window, opcode, status and length, and a lookup table
+ * (LUT) that combines their hits. The driver programs filter 0 and sets the
+ * LUT to pass exactly its hits, and counts those with the LUT events. Filter
+ * and LUT registers, like the trace port, are shared by all counters of a
+ * probe, so all events using them must ask for the same filter. A criterion
+ * an event does not mention is left out of the filter. Hardware only
+ * guarantees filters to work while the probe is idle, so changing them while
+ * other events run stops the probe for a moment.
+ */
+
+#include <linux/bitfield.h>
+#include <linux/cpuhotplug.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/perf_event.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
+
+#define FLEXNOC_PMU_NAME "arteris_flexnoc_pmu"
+
+/* Address layout of the service network */
+#define FLEXNOC_UNIT_STRIDE 0x80 /* smallest unit */
+#define FLEXNOC_UNIT_MAX_SIZE 0x400 /* largest unit */
+
+/* Standard identification registers, present in every unit */
+#define FLEXNOC_COREID 0x000
+#define FLEXNOC_COREID_TYPE GENMASK(7, 0)
+#define FLEXNOC_REVID 0x004
+#define FLEXNOC_REVID_USERID GENMASK(7, 0)
+#define FLEXNOC_REVID_FLEXCONNECT GENMASK(31, 8)
+
+/* CoreId.CoreTypeId */
+#define FLEXNOC_UT_PACKET_PROBE 6
+#define FLEXNOC_UT_TXN_PROFILER 10
+#define FLEXNOC_UT_MAX 28
+
+/* Packet probe global registers */
+#define FLEXNOC_MAINCTL 0x008
+#define FLEXNOC_MAINCTL_STATEN BIT(3)
+#define FLEXNOC_CFGCTL 0x00c
+#define FLEXNOC_CFGCTL_GLOBALEN BIT(0)
+#define FLEXNOC_CFGCTL_ACTIVE BIT(1)
+#define FLEXNOC_TRACEPORTSEL 0x010
+#define FLEXNOC_FILTERLUT 0x014
+#define FLEXNOC_STATPERIOD 0x024
+
+/*
+ * Registers of packet filter 0. The registers of filter N are 0x60 * N
+ * further, but only filter 0 is used.
+ * Mind the gap between the OPCODE (0x09c) and STATUS (0x100)
+ */
+#define FLEXNOC_F0_ROUTEIDBASE 0x080
+#define FLEXNOC_F0_ROUTEIDMASK 0x084
+#define FLEXNOC_F0_ADDRBASE_LOW 0x088
+#define FLEXNOC_F0_ADDRBASE_HIGH 0x08c
+#define FLEXNOC_F0_WINDOWSIZE 0x090
+#define FLEXNOC_F0_SECURITYBASE 0x094
+#define FLEXNOC_F0_SECURITYMASK 0x098
+#define FLEXNOC_F0_OPCODE 0x09c
+#define FLEXNOC_OPCODE_RD BIT(0)
+#define FLEXNOC_OPCODE_WR BIT(1)
+#define FLEXNOC_OPCODE_LOCK BIT(2)
+#define FLEXNOC_OPCODE_URG BIT(3)
+#define FLEXNOC_F0_STATUS 0x100
+#define FLEXNOC_STATUS_REQ BIT(0)
+#define FLEXNOC_STATUS_RSP BIT(1)
+#define FLEXNOC_F0_LENGTH 0x104
+#define FLEXNOC_F0_URGENCY 0x108
+#define FLEXNOC_F0_USERBASE 0x10c
+#define FLEXNOC_F0_USERMASK 0x110
+#define FLEXNOC_F0_USERBASE_HIGH 0x114
+#define FLEXNOC_F0_USERMASK_HIGH 0x118
+
+/* Values of the filter registers that leave out a criterion (see manual) */
+#define FLEXNOC_FILT_OPCODE_ANY 0xf
+#define FLEXNOC_FILT_STATUS_ANY 0x3
+#define FLEXNOC_FILT_LENGTH_ANY 0xf
+/* WindowSize and the masks are set to all ones, 0 for the masks */
+
+/* The LUT is 2^nFilter bits wide, which is at most 16 */
+#define FLEXNOC_MAX_FILTERS 4
+
+/* Packet probe statistics counter registers, 16 bytes per counter */
+#define FLEXNOC_MAX_COUNTERS 32
+#define FLEXNOC_CNT_BASE 0x200
+#define FLEXNOC_CNT_STRIDE 0x10
+#define FLEXNOC_CNT_PORTSEL(n) (FLEXNOC_CNT_BASE + (n) * FLEXNOC_CNT_STRIDE + 0x0)
+#define FLEXNOC_CNT_SRC(n) (FLEXNOC_CNT_BASE + (n) * FLEXNOC_CNT_STRIDE + 0x4)
+#define FLEXNOC_CNT_VAL(n) (FLEXNOC_CNT_BASE + (n) * FLEXNOC_CNT_STRIDE + 0xc)
+
+/* Counters_M_Src: what the counter counts */
+#define FLEXNOC_SRC_OFF 0x000
+#define FLEXNOC_SRC_CYCLE 0x001
+#define FLEXNOC_SRC_IDLE 0x002
+#define FLEXNOC_SRC_XFER 0x003
+#define FLEXNOC_SRC_BUSY 0x004
+#define FLEXNOC_SRC_WAIT 0x005
+#define FLEXNOC_SRC_PKT 0x006
+#define FLEXNOC_SRC_LUT 0x007
+#define FLEXNOC_SRC_BYTE 0x008
+#define FLEXNOC_SRC_PRESS0 0x009
+#define FLEXNOC_SRC_PRESS1 0x00a
+#define FLEXNOC_SRC_PRESS2 0x00b
+#define FLEXNOC_SRC_CHAIN 0x010
+#define FLEXNOC_SRC_LUT_BYTE 0x012
+#define FLEXNOC_SRC_EXT_FIRST 0x020
+#define FLEXNOC_SRC_EXT_LAST 0x11f
+
+#define FLEXNOC_MIN_COUNTER_BITS 8
+#define FLEXNOC_DEFAULT_COUNTER_BITS 32
+
+/* perf_event_attr.config layout */
+#define FLEXNOC_CFG_EVENT GENMASK_ULL(8, 0)
+#define FLEXNOC_CFG_PORT GENMASK_ULL(23, 16)
+#define FLEXNOC_CFG_CHAIN BIT_ULL(24)
+/* Filter fields of config, only for events counting filtered packets */
+#define FLEXNOC_CFG_RD BIT_ULL(40)
+#define FLEXNOC_CFG_WR BIT_ULL(41)
+#define FLEXNOC_CFG_LOCK BIT_ULL(42)
+#define FLEXNOC_CFG_URG BIT_ULL(43)
+#define FLEXNOC_CFG_REQ BIT_ULL(44)
+#define FLEXNOC_CFG_RSP BIT_ULL(45)
+#define FLEXNOC_CFG_LEN GENMASK_ULL(51, 48)
+#define FLEXNOC_CFG_LEN_EN BIT_ULL(52)
+#define FLEXNOC_CFG_WINDOW GENMASK_ULL(61, 56)
+#define FLEXNOC_CFG_ADDR_EN BIT_ULL(62)
+#define FLEXNOC_CFG_FILTER (FLEXNOC_CFG_RD | FLEXNOC_CFG_WR | \
+ FLEXNOC_CFG_LOCK | FLEXNOC_CFG_URG | \
+ FLEXNOC_CFG_REQ | FLEXNOC_CFG_RSP | \
+ FLEXNOC_CFG_LEN | FLEXNOC_CFG_LEN_EN | \
+ FLEXNOC_CFG_WINDOW | FLEXNOC_CFG_ADDR_EN)
+/* config1 is the address base. config2 is the route ID base and mask */
+#define FLEXNOC_CFG2_ROUTE_BASE GENMASK_ULL(31, 0)
+#define FLEXNOC_CFG2_ROUTE_MASK GENMASK_ULL(63, 32)
+
+/* What an event source needs, see flexnoc_pmu_check_event() */
+#define FLEXNOC_EV_PORT BIT(0) /* counter's own port select */
+#define FLEXNOC_EV_FILTER BIT(1) /* filter 0, trace port select */
+#define FLEXNOC_EV_WIDE BIT(2) /* may count many times a cycle */
+
+/* hw_perf_event.event_base */
+#define FLEXNOC_HW_CHAIN BIT(0)
+#define FLEXNOC_HW_FILTER BIT(1)
+
+/* What the registers of packet filter 0 and the LUT are set to */
+struct flexnoc_filter {
+ u32 trace_port;
+ u32 route_base;
+ u32 route_mask;
+ u32 addr_low;
+ u32 addr_high;
+ u32 window;
+ u32 opcode;
+ u32 status;
+ u32 length;
+};
+
+struct flexnoc_pmu_dev;
+
+struct flexnoc_pmu {
+ struct pmu pmu;
+ struct flexnoc_pmu_dev *fdev;
+ void __iomem *base;
+ const char *name;
+ unsigned int offset; /* of the unit in the NoC address range */
+ u32 flexconnect_id;
+ u32 user_id;
+ unsigned int n_counters;
+ unsigned int counter_bits;
+ u32 port_mask; /* of Counters_M_PortSel */
+
+ /* Packet filter 0, n_filters is 0 if there is no usable filter */
+ unsigned int n_filters;
+ u32 lut_mask;
+ u32 trace_port_mask;
+ u32 route_id_mask;
+ u32 addr_low_mask;
+ u32 addr_high_mask;
+ u32 window_max; /* WindowSize all ones, "any address" */
+ bool has_user_mask;
+ bool has_user_mask_high;
+
+ /*
+ * All of this is only touched with interrupts disabled on the CPU
+ * that handles the PMU's events, by the perf callbacks.
+ * events[] holds the event of the first counter of a chained
+ * pair, the second one is only marked in used_mask.
+ */
+ struct perf_event *events[FLEXNOC_MAX_COUNTERS];
+ DECLARE_BITMAP(used_mask, FLEXNOC_MAX_COUNTERS);
+ unsigned int n_events;
+ struct flexnoc_filter filter; /* in the registers if filter_users */
+ unsigned int filter_users;
+ bool enabled; /* StatEn and GlobalEn are set */
+};
+
+struct flexnoc_pmu_dev {
+ struct device *dev;
+ struct hlist_node node;
+ unsigned int cpu;
+ unsigned int n_pmus;
+ struct flexnoc_pmu *pmus;
+};
+
+#define to_flexnoc_pmu(p) container_of(p, struct flexnoc_pmu, pmu)
+
+static enum cpuhp_state flexnoc_pmu_cpuhp_state;
+
+/* sysfs: format */
+
+PMU_FORMAT_ATTR(event, "config:0-8");
+PMU_FORMAT_ATTR(port, "config:16-23");
+PMU_FORMAT_ATTR(chain, "config:24");
+PMU_FORMAT_ATTR(rd, "config:40");
+PMU_FORMAT_ATTR(wr, "config:41");
+PMU_FORMAT_ATTR(lock, "config:42");
+PMU_FORMAT_ATTR(urg, "config:43");
+PMU_FORMAT_ATTR(req, "config:44");
+PMU_FORMAT_ATTR(rsp, "config:45");
+PMU_FORMAT_ATTR(len, "config:48-51");
+PMU_FORMAT_ATTR(len_en, "config:52");
+PMU_FORMAT_ATTR(window, "config:56-61");
+PMU_FORMAT_ATTR(addr_en, "config:62");
+PMU_FORMAT_ATTR(addr, "config1:0-63");
+PMU_FORMAT_ATTR(route_id, "config2:0-31");
+PMU_FORMAT_ATTR(route_mask, "config2:32-63");
+
+static struct attribute *flexnoc_pmu_format_attrs[] = {
+ &format_attr_event.attr,
+ &format_attr_port.attr,
+ &format_attr_chain.attr,
+ &format_attr_rd.attr,
+ &format_attr_wr.attr,
+ &format_attr_lock.attr,
+ &format_attr_urg.attr,
+ &format_attr_req.attr,
+ &format_attr_rsp.attr,
+ &format_attr_len.attr,
+ &format_attr_len_en.attr,
+ &format_attr_window.attr,
+ &format_attr_addr_en.attr,
+ &format_attr_addr.attr,
+ &format_attr_route_id.attr,
+ &format_attr_route_mask.attr,
+ NULL
+};
+
+static const struct attribute_group flexnoc_pmu_format_group = {
+ .name = "format",
+ .attrs = flexnoc_pmu_format_attrs,
+};
+
+/* sysfs: events */
+
+PMU_EVENT_ATTR_STRING(cycle, flexnoc_ev_cycle, "event=0x01");
+PMU_EVENT_ATTR_STRING(idle, flexnoc_ev_idle, "event=0x02");
+PMU_EVENT_ATTR_STRING(xfer, flexnoc_ev_xfer, "event=0x03");
+PMU_EVENT_ATTR_STRING(busy, flexnoc_ev_busy, "event=0x04");
+PMU_EVENT_ATTR_STRING(wait, flexnoc_ev_wait, "event=0x05");
+PMU_EVENT_ATTR_STRING(pkt, flexnoc_ev_pkt, "event=0x06");
+PMU_EVENT_ATTR_STRING(byte, flexnoc_ev_byte, "event=0x08,chain=1");
+PMU_EVENT_ATTR_STRING(press0, flexnoc_ev_press0, "event=0x09");
+PMU_EVENT_ATTR_STRING(press1, flexnoc_ev_press1, "event=0x0a");
+PMU_EVENT_ATTR_STRING(press2, flexnoc_ev_press2, "event=0x0b");
+PMU_EVENT_ATTR_STRING(filt_pkt, flexnoc_ev_filt_pkt, "event=0x07");
+PMU_EVENT_ATTR_STRING(filt_byte, flexnoc_ev_filt_byte, "event=0x12,chain=1");
+
+static struct attribute *flexnoc_pmu_event_attrs[] = {
+ &flexnoc_ev_cycle.attr.attr,
+ &flexnoc_ev_idle.attr.attr,
+ &flexnoc_ev_xfer.attr.attr,
+ &flexnoc_ev_busy.attr.attr,
+ &flexnoc_ev_wait.attr.attr,
+ &flexnoc_ev_pkt.attr.attr,
+ &flexnoc_ev_byte.attr.attr,
+ &flexnoc_ev_press0.attr.attr,
+ &flexnoc_ev_press1.attr.attr,
+ &flexnoc_ev_press2.attr.attr,
+ &flexnoc_ev_filt_pkt.attr.attr,
+ &flexnoc_ev_filt_byte.attr.attr,
+ NULL
+};
+
+/* Events on filtered packets are there if the probe has a packet filter */
+static umode_t flexnoc_pmu_event_is_visible(struct kobject *kobj,
+ struct attribute *attr, int unused)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(dev_get_drvdata(kobj_to_dev(kobj)));
+
+ if (!fp->n_filters &&
+ (attr == &flexnoc_ev_filt_pkt.attr.attr ||
+ attr == &flexnoc_ev_filt_byte.attr.attr))
+ return 0;
+
+ return attr->mode;
+}
+
+static const struct attribute_group flexnoc_pmu_events_group = {
+ .name = "events",
+ .attrs = flexnoc_pmu_event_attrs,
+ .is_visible = flexnoc_pmu_event_is_visible,
+};
+
+/* sysfs: PMU description */
+
+static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(dev_get_drvdata(dev));
+
+ return sysfs_emit(buf, "%*pbl\n",
+ cpumask_pr_args(cpumask_of(fp->fdev->cpu)));
+}
+static DEVICE_ATTR_RO(cpumask);
+
+static ssize_t identifier_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(dev_get_drvdata(dev));
+
+ return sysfs_emit(buf, "arteris-flexnoc-%06x-%02x\n",
+ fp->flexconnect_id, fp->user_id);
+}
+static DEVICE_ATTR_RO(identifier);
+
+static ssize_t unit_offset_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(dev_get_drvdata(dev));
+
+ return sysfs_emit(buf, "%#x\n", fp->offset);
+}
+static DEVICE_ATTR_RO(unit_offset);
+
+static ssize_t num_counters_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(dev_get_drvdata(dev));
+
+ return sysfs_emit(buf, "%u\n", fp->n_counters);
+}
+static DEVICE_ATTR_RO(num_counters);
+
+static ssize_t counter_bits_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(dev_get_drvdata(dev));
+
+ return sysfs_emit(buf, "%u\n", fp->counter_bits);
+}
+static DEVICE_ATTR_RO(counter_bits);
+
+static ssize_t port_mask_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(dev_get_drvdata(dev));
+
+ return sysfs_emit(buf, "%#x\n", fp->port_mask);
+}
+static DEVICE_ATTR_RO(port_mask);
+
+static ssize_t num_filters_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(dev_get_drvdata(dev));
+
+ return sysfs_emit(buf, "%u\n", fp->n_filters);
+}
+static DEVICE_ATTR_RO(num_filters);
+
+static struct attribute *flexnoc_pmu_dev_attrs[] = {
+ &dev_attr_cpumask.attr,
+ &dev_attr_identifier.attr,
+ &dev_attr_unit_offset.attr,
+ &dev_attr_num_counters.attr,
+ &dev_attr_counter_bits.attr,
+ &dev_attr_port_mask.attr,
+ &dev_attr_num_filters.attr,
+ NULL
+};
+
+static const struct attribute_group flexnoc_pmu_dev_group = {
+ .attrs = flexnoc_pmu_dev_attrs,
+};
+
+static const struct attribute_group *flexnoc_pmu_attr_groups[] = {
+ &flexnoc_pmu_format_group,
+ &flexnoc_pmu_events_group,
+ &flexnoc_pmu_dev_group,
+ NULL
+};
+
+/* Helpers */
+
+static inline bool flexnoc_event_chained(struct perf_event *event)
+{
+ return event->hw.event_base & FLEXNOC_HW_CHAIN;
+}
+
+static inline bool flexnoc_event_filtered(struct perf_event *event)
+{
+ return event->hw.event_base & FLEXNOC_HW_FILTER;
+}
+
+static inline unsigned int flexnoc_event_counters(struct perf_event *event)
+{
+ return flexnoc_event_chained(event) ? 2 : 1;
+}
+
+/* Number of bits of the value an event accumulates */
+static inline unsigned int flexnoc_event_bits(struct flexnoc_pmu *fp,
+ struct perf_event *event)
+{
+ return fp->counter_bits * flexnoc_event_counters(event);
+}
+
+/* Hardware access */
+
+/* Wait for the probe to report that it is (in)active after GlobalEn changes */
+static void flexnoc_pmu_wait_active(struct flexnoc_pmu *fp, bool active)
+{
+ u32 val;
+
+ if (readl_poll_timeout_atomic(fp->base + FLEXNOC_CFGCTL, val,
+ !!(val & FLEXNOC_CFGCTL_ACTIVE) == active,
+ 1, 100))
+ dev_warn_ratelimited(fp->fdev->dev,
+ "%s: probe did not become %sactive\n",
+ fp->name, active ? "" : "in");
+}
+
+/*
+ * GlobalEn gates the whole probe. Counters keep what they counted while it is
+ * off, only setting StatEn clears them. Filters can only be changed while the
+ * probe is inactive, so they are changed in a pause. The probe does not become
+ * active unless a counter source is set and StatEn is set before GlobalEn.
+ */
+static void flexnoc_pmu_resume(struct flexnoc_pmu *fp)
+{
+ writel(FLEXNOC_CFGCTL_GLOBALEN, fp->base + FLEXNOC_CFGCTL);
+ flexnoc_pmu_wait_active(fp, true);
+}
+
+static void flexnoc_pmu_pause(struct flexnoc_pmu *fp)
+{
+ writel(0, fp->base + FLEXNOC_CFGCTL);
+ flexnoc_pmu_wait_active(fp, false);
+}
+
+/*
+ * Statistics collection is on while GlobalEn and StatEn are both set. The
+ * hardware needs them in this order, after the source of a counter is set,
+ * and then takes a moment to report Active. Setting StatEn clears all
+ * counters, so it is done once, while no running event is using any.
+ */
+static void flexnoc_pmu_hw_start(struct flexnoc_pmu *fp)
+{
+ u32 val;
+
+ val = readl(fp->base + FLEXNOC_MAINCTL);
+ writel(val | FLEXNOC_MAINCTL_STATEN, fp->base + FLEXNOC_MAINCTL);
+
+ flexnoc_pmu_resume(fp);
+ fp->enabled = true;
+}
+
+/* In the reverse order: GlobalEn off and probe inactive, then StatEn */
+static void flexnoc_pmu_hw_stop(struct flexnoc_pmu *fp)
+{
+ u32 val;
+
+ flexnoc_pmu_pause(fp);
+
+ val = readl(fp->base + FLEXNOC_MAINCTL);
+ writel(val & ~FLEXNOC_MAINCTL_STATEN, fp->base + FLEXNOC_MAINCTL);
+ fp->enabled = false;
+}
+
+/* Leave a stopped probe with no periodic dump and all its counters off */
+static void flexnoc_pmu_hw_reset(struct flexnoc_pmu *fp)
+{
+ unsigned int i;
+
+ /* A statistics dump would clear the counters */
+ writel(0, fp->base + FLEXNOC_STATPERIOD);
+
+ for (i = 0; i < fp->n_counters; i++)
+ writel(FLEXNOC_SRC_OFF, fp->base + FLEXNOC_CNT_SRC(i));
+}
+
+/*
+ * Make filter 0 select what the filter says, and the LUT pass exactly the
+ * hits of filter 0: LUT bit i is the output for filter hits i, so every bit
+ * whose lowest bit is set. Criteria the PMU has no handle on are left out.
+ * The probe has to be inactive.
+ */
+static void flexnoc_pmu_filter_program(struct flexnoc_pmu *fp,
+ const struct flexnoc_filter *f)
+{
+ void __iomem *base = fp->base;
+
+ writel(f->trace_port, base + FLEXNOC_TRACEPORTSEL);
+ writel(f->route_base, base + FLEXNOC_F0_ROUTEIDBASE);
+ writel(f->route_mask, base + FLEXNOC_F0_ROUTEIDMASK);
+ writel(f->addr_low, base + FLEXNOC_F0_ADDRBASE_LOW);
+ if (fp->addr_high_mask)
+ writel(f->addr_high, base + FLEXNOC_F0_ADDRBASE_HIGH);
+ writel(f->window, base + FLEXNOC_F0_WINDOWSIZE);
+ writel(0, base + FLEXNOC_F0_SECURITYMASK);
+ writel(f->opcode, base + FLEXNOC_F0_OPCODE);
+ writel(f->status, base + FLEXNOC_F0_STATUS);
+ writel(f->length, base + FLEXNOC_F0_LENGTH);
+ writel(0, base + FLEXNOC_F0_URGENCY);
+ if (fp->has_user_mask)
+ writel(0, base + FLEXNOC_F0_USERMASK);
+ if (fp->has_user_mask_high)
+ writel(0, base + FLEXNOC_F0_USERMASK_HIGH);
+
+ writel(0xaaaaaaaa & fp->lut_mask, base + FLEXNOC_FILTERLUT);
+}
+
+static u64 flexnoc_pmu_read_counter(struct flexnoc_pmu *fp,
+ struct perf_event *event)
+{
+ struct hw_perf_event *hwc = &event->hw;
+ u32 mask = GENMASK(fp->counter_bits - 1, 0);
+ u32 lo, hi, hi2;
+
+ if (!flexnoc_event_chained(event))
+ return readl(fp->base + FLEXNOC_CNT_VAL(hwc->idx)) & mask;
+
+ /* Two counters: read again if the low one carried in between */
+ hi = readl(fp->base + FLEXNOC_CNT_VAL(hwc->idx + 1));
+ do {
+ hi2 = hi;
+ lo = readl(fp->base + FLEXNOC_CNT_VAL(hwc->idx));
+ hi = readl(fp->base + FLEXNOC_CNT_VAL(hwc->idx + 1));
+ } while (hi != hi2);
+
+ return ((u64)(hi & mask) << fp->counter_bits) | (lo & mask);
+}
+
+/*
+ * Work out what filter 0 has to be set to for an event counting filtered
+ * packets, from the filter fields of its attributes. The result tells the
+ * same for the same fields, so filters can be compared with memcmp().
+ */
+static int flexnoc_pmu_event_filter(struct flexnoc_pmu *fp,
+ struct perf_event *event,
+ struct flexnoc_filter *f)
+{
+ struct device *dev = fp->fdev->dev;
+ u64 cfg = event->attr.config;
+ u64 base = event->attr.config1;
+ u64 route = event->attr.config2;
+ unsigned int addr_bits = hweight32(fp->addr_low_mask) +
+ hweight32(fp->addr_high_mask);
+ unsigned int window;
+
+ memset(f, 0, sizeof(*f));
+
+ f->trace_port = FIELD_GET(FLEXNOC_CFG_PORT, cfg);
+
+ f->route_mask = FIELD_GET(FLEXNOC_CFG2_ROUTE_MASK, route);
+ if (f->route_mask & ~fp->route_id_mask) {
+ dev_dbg(dev, "%s: route_mask %#x has bits outside of %#x\n",
+ fp->name, f->route_mask, fp->route_id_mask);
+ return -EINVAL;
+ }
+ f->route_base = FIELD_GET(FLEXNOC_CFG2_ROUTE_BASE, route) & f->route_mask;
+
+ if (cfg & FLEXNOC_CFG_ADDR_EN) {
+ window = FIELD_GET(FLEXNOC_CFG_WINDOW, cfg);
+ if (window > addr_bits || window > fp->window_max ||
+ (addr_bits < 64 && base >> addr_bits)) {
+ dev_dbg(dev, "%s: addr %#llx window %u does not fit in %u address bits\n",
+ fp->name, base, window, addr_bits);
+ return -EINVAL;
+ }
+ base &= ~(BIT_ULL(window) - 1);
+ f->window = window;
+ f->addr_low = lower_32_bits(base);
+ f->addr_high = upper_32_bits(base);
+ } else {
+ if (base || (cfg & FLEXNOC_CFG_WINDOW)) {
+ dev_dbg(dev, "%s: addr and window need addr_en=1\n",
+ fp->name);
+ return -EINVAL;
+ }
+ f->window = fp->window_max;
+ }
+
+ f->opcode = (cfg & FLEXNOC_CFG_RD ? FLEXNOC_OPCODE_RD : 0) |
+ (cfg & FLEXNOC_CFG_WR ? FLEXNOC_OPCODE_WR : 0) |
+ (cfg & FLEXNOC_CFG_LOCK ? FLEXNOC_OPCODE_LOCK : 0) |
+ (cfg & FLEXNOC_CFG_URG ? FLEXNOC_OPCODE_URG : 0);
+ if (!f->opcode)
+ f->opcode = FLEXNOC_FILT_OPCODE_ANY;
+
+ f->status = (cfg & FLEXNOC_CFG_REQ ? FLEXNOC_STATUS_REQ : 0) |
+ (cfg & FLEXNOC_CFG_RSP ? FLEXNOC_STATUS_RSP : 0);
+ if (!f->status)
+ f->status = FLEXNOC_FILT_STATUS_ANY;
+
+ if (cfg & FLEXNOC_CFG_LEN_EN) {
+ f->length = FIELD_GET(FLEXNOC_CFG_LEN, cfg);
+ } else {
+ if (cfg & FLEXNOC_CFG_LEN) {
+ dev_dbg(dev, "%s: len needs len_en=1\n", fp->name);
+ return -EINVAL;
+ }
+ f->length = FLEXNOC_FILT_LENGTH_ANY;
+ }
+
+ return 0;
+}
+
+/* perf callbacks */
+
+static void flexnoc_pmu_event_update(struct perf_event *event)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(event->pmu);
+ struct hw_perf_event *hwc = &event->hw;
+ u64 prev, now;
+
+ do {
+ prev = local64_read(&hwc->prev_count);
+ now = flexnoc_pmu_read_counter(fp, event);
+ } while (!local64_try_cmpxchg(&hwc->prev_count, &prev, now));
+
+ local64_add((now - prev) & GENMASK_ULL(flexnoc_event_bits(fp, event) - 1, 0),
+ &event->count);
+}
+
+static void flexnoc_pmu_start(struct perf_event *event, int flags)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(event->pmu);
+ struct hw_perf_event *hwc = &event->hw;
+
+ if (WARN_ON_ONCE(!(hwc->state & PERF_HES_STOPPED)))
+ return;
+
+ hwc->state = 0;
+
+ /*
+ * The counter is off until now and holds whatever it counted before:
+ * counters can only be cleared all at once, so remember where it is.
+ */
+ if (fp->enabled) {
+ local64_set(&hwc->prev_count,
+ flexnoc_pmu_read_counter(fp, event));
+ writel(hwc->config, fp->base + FLEXNOC_CNT_SRC(hwc->idx));
+ } else {
+ /*
+ * The probe starts with the first source set, and that clears
+ * the counters, so the event begins from there.
+ */
+ writel(hwc->config, fp->base + FLEXNOC_CNT_SRC(hwc->idx));
+ flexnoc_pmu_hw_start(fp);
+ local64_set(&hwc->prev_count,
+ flexnoc_pmu_read_counter(fp, event));
+ }
+
+ perf_event_update_userpage(event);
+}
+
+static void flexnoc_pmu_stop(struct perf_event *event, int flags)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(event->pmu);
+ struct hw_perf_event *hwc = &event->hw;
+
+ if (hwc->state & PERF_HES_STOPPED)
+ return;
+
+ writel(FLEXNOC_SRC_OFF, fp->base + FLEXNOC_CNT_SRC(hwc->idx));
+ /* Make sure the counter has stopped before reading its last value */
+ readl(fp->base + FLEXNOC_CNT_SRC(hwc->idx));
+
+ hwc->state |= PERF_HES_STOPPED;
+ flexnoc_pmu_event_update(event);
+ hwc->state |= PERF_HES_UPTODATE;
+}
+
+/*
+ * A chained event takes an even counter and the odd one after it, so a free
+ * pair is looked for from the bottom. Single events are given counters from
+ * the top, to keep pairs free for as long as possible.
+ */
+static int flexnoc_pmu_alloc_counter(struct flexnoc_pmu *fp, bool chained)
+{
+ int idx;
+
+ if (chained) {
+ for (idx = 0; idx + 1 < fp->n_counters; idx += 2) {
+ if (test_bit(idx, fp->used_mask) ||
+ test_bit(idx + 1, fp->used_mask))
+ continue;
+ __set_bit(idx, fp->used_mask);
+ __set_bit(idx + 1, fp->used_mask);
+ return idx;
+ }
+ return -EAGAIN;
+ }
+
+ for (idx = fp->n_counters - 1; idx >= 0; idx--) {
+ if (test_bit(idx, fp->used_mask))
+ continue;
+ __set_bit(idx, fp->used_mask);
+ return idx;
+ }
+
+ return -EAGAIN;
+}
+
+static int flexnoc_pmu_add(struct perf_event *event, int flags)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(event->pmu);
+ struct hw_perf_event *hwc = &event->hw;
+ struct flexnoc_filter filter;
+ bool filtered = flexnoc_event_filtered(event);
+ bool paused = false;
+ int idx;
+
+ /* One filter for the probe: others have to wait for their turn */
+ if (filtered) {
+ flexnoc_pmu_event_filter(fp, event, &filter);
+ if (fp->filter_users &&
+ memcmp(&fp->filter, &filter, sizeof(filter)))
+ return -EAGAIN;
+ }
+
+ idx = flexnoc_pmu_alloc_counter(fp, flexnoc_event_chained(event));
+ if (idx < 0)
+ return idx;
+
+ hwc->idx = idx;
+ fp->events[idx] = event;
+
+ /*
+ * A running probe is paused to change the filter. It is resumed once
+ * the event has its source, which the probe needs to become active.
+ */
+ if (filtered && !fp->filter_users++) {
+ fp->filter = filter;
+ paused = fp->enabled;
+ if (paused)
+ flexnoc_pmu_pause(fp);
+ flexnoc_pmu_filter_program(fp, &filter);
+ }
+
+ /* Both counters of a pair stay off, and so does the chain, until start */
+ writel(hwc->config_base, fp->base + FLEXNOC_CNT_PORTSEL(idx));
+ if (flexnoc_event_chained(event))
+ writel(FLEXNOC_SRC_CHAIN, fp->base + FLEXNOC_CNT_SRC(idx + 1));
+
+ hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE;
+ fp->n_events++;
+
+ if (flags & PERF_EF_START)
+ flexnoc_pmu_start(event, PERF_EF_RELOAD);
+
+ if (paused)
+ flexnoc_pmu_resume(fp);
+
+ perf_event_update_userpage(event);
+
+ return 0;
+}
+
+static void flexnoc_pmu_del(struct perf_event *event, int flags)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(event->pmu);
+ struct hw_perf_event *hwc = &event->hw;
+
+ flexnoc_pmu_stop(event, PERF_EF_UPDATE);
+
+ if (flexnoc_event_chained(event)) {
+ writel(FLEXNOC_SRC_OFF, fp->base + FLEXNOC_CNT_SRC(hwc->idx + 1));
+ __clear_bit(hwc->idx + 1, fp->used_mask);
+ }
+ __clear_bit(hwc->idx, fp->used_mask);
+ fp->events[hwc->idx] = NULL;
+
+ if (flexnoc_event_filtered(event))
+ fp->filter_users--;
+
+ if (!--fp->n_events) {
+ if (fp->enabled)
+ flexnoc_pmu_hw_stop(fp);
+ }
+
+ hwc->idx = -1;
+ perf_event_update_userpage(event);
+}
+
+/*
+ * Take an event of the group in the count of counters it needs, and make sure
+ * it filters like the ones taken before it, as the group is on the probe at
+ * the same time.
+ */
+static bool flexnoc_pmu_group_add(struct flexnoc_pmu *fp,
+ struct perf_event *event, unsigned int *n,
+ struct flexnoc_filter *filter, bool *filtered)
+{
+ struct flexnoc_filter f;
+
+ *n += flexnoc_event_counters(event);
+
+ if (!flexnoc_event_filtered(event))
+ return true;
+
+ /* It was accepted by event_init() already, so this cannot fail */
+ flexnoc_pmu_event_filter(fp, event, &f);
+ if (*filtered && memcmp(filter, &f, sizeof(f)))
+ return false;
+
+ *filter = f;
+ *filtered = true;
+
+ return true;
+}
+
+/* Count the counters a group needs, other PMUs' hardware events not allowed */
+static bool flexnoc_pmu_validate_group(struct perf_event *event)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(event->pmu);
+ struct perf_event *leader = event->group_leader;
+ struct perf_event *sibling;
+ struct flexnoc_filter filter;
+ bool filtered = false;
+ unsigned int n = 0;
+
+ if (!flexnoc_pmu_group_add(fp, event, &n, &filter, &filtered))
+ return false;
+
+ if (leader == event)
+ return n <= fp->n_counters;
+
+ if (leader->pmu == event->pmu) {
+ if (!flexnoc_pmu_group_add(fp, leader, &n, &filter,
+ &filtered))
+ return false;
+ } else if (!is_software_event(leader)) {
+ return false;
+ }
+
+ for_each_sibling_event(sibling, leader) {
+ if (sibling->pmu == event->pmu) {
+ if (!flexnoc_pmu_group_add(fp, sibling, &n, &filter,
+ &filtered))
+ return false;
+ } else if (!is_software_event(sibling)) {
+ return false;
+ }
+ }
+
+ return n <= fp->n_counters;
+}
+
+/*
+ * Tell what an event source needs, as FLEXNOC_EV_* flags. FILTn and the *_EN
+ * sources of the filters other than the LUT are not supported, their filters
+ * are not programmed. CHAIN on its own and other values are reserved.
+ */
+static int flexnoc_pmu_check_event(unsigned int src, unsigned int *flags)
+{
+ switch (src) {
+ case FLEXNOC_SRC_CYCLE:
+ *flags = 0;
+ return 0;
+ case FLEXNOC_SRC_IDLE:
+ case FLEXNOC_SRC_XFER:
+ case FLEXNOC_SRC_BUSY:
+ case FLEXNOC_SRC_WAIT:
+ case FLEXNOC_SRC_PKT:
+ case FLEXNOC_SRC_PRESS0:
+ case FLEXNOC_SRC_PRESS1:
+ case FLEXNOC_SRC_PRESS2:
+ *flags = FLEXNOC_EV_PORT;
+ return 0;
+ case FLEXNOC_SRC_BYTE:
+ *flags = FLEXNOC_EV_PORT | FLEXNOC_EV_WIDE;
+ return 0;
+ case FLEXNOC_SRC_LUT:
+ *flags = FLEXNOC_EV_FILTER;
+ return 0;
+ case FLEXNOC_SRC_LUT_BYTE:
+ *flags = FLEXNOC_EV_FILTER | FLEXNOC_EV_WIDE;
+ return 0;
+ case 0x0c ... 0x0f: /* FILT0-3 */
+ case 0x11: /* LUT_BYTE_EN */
+ case 0x13: /* FILT_BYTE_EN */
+ case 0x14: /* FILT_BYTE */
+ return -EOPNOTSUPP;
+ case FLEXNOC_SRC_EXT_FIRST ... FLEXNOC_SRC_EXT_LAST:
+ *flags = 0;
+ return 0;
+ default:
+ return -EINVAL;
+ }
+}
+
+static int flexnoc_pmu_event_init(struct perf_event *event)
+{
+ struct flexnoc_pmu *fp = to_flexnoc_pmu(event->pmu);
+ struct device *dev = fp->fdev->dev;
+ struct hw_perf_event *hwc = &event->hw;
+ u64 cfg = event->attr.config;
+ unsigned int src = FIELD_GET(FLEXNOC_CFG_EVENT, cfg);
+ unsigned int port = FIELD_GET(FLEXNOC_CFG_PORT, cfg);
+ bool chain = cfg & FLEXNOC_CFG_CHAIN;
+ struct flexnoc_filter filter;
+ u64 known = FLEXNOC_CFG_EVENT | FLEXNOC_CFG_PORT | FLEXNOC_CFG_CHAIN;
+ unsigned int flags, port_max;
+ int ret;
+
+ /* Not ours: perf asks every PMU in turn, so say nothing */
+ if (event->attr.type != event->pmu->type)
+ return -ENOENT;
+
+ /* Shared uncore counters: no sampling, no per-task counting */
+ if (is_sampling_event(event) || event->attach_state & PERF_ATTACH_TASK) {
+ dev_dbg(dev, "%s: sampling and per-task events not supported\n",
+ fp->name);
+ return -EOPNOTSUPP;
+ }
+
+ if (event->cpu < 0) {
+ dev_dbg(dev, "%s: per-task events not supported, use -a\n",
+ fp->name);
+ return -EINVAL;
+ }
+
+ ret = flexnoc_pmu_check_event(src, &flags);
+ if (ret) {
+ dev_dbg(dev, "%s: event %#x %s\n", fp->name, src,
+ ret == -EOPNOTSUPP ? "is not supported" : "is reserved");
+ return ret;
+ }
+
+ /* The filter fields are for the events on filtered packets only */
+ if (flags & FLEXNOC_EV_FILTER) {
+ if (!fp->n_filters) {
+ dev_dbg(dev, "%s: event %#x needs a packet filter, probe has none\n",
+ fp->name, src);
+ return -EOPNOTSUPP;
+ }
+ known |= FLEXNOC_CFG_FILTER;
+ }
+ if (cfg & ~known ||
+ (!(flags & FLEXNOC_EV_FILTER) &&
+ (event->attr.config1 || event->attr.config2))) {
+ dev_dbg(dev, "%s: unknown config bits: config %#llx config1 %#llx config2 %#llx\n",
+ fp->name, cfg, event->attr.config1,
+ event->attr.config2);
+ return -EINVAL;
+ }
+ if (flags & FLEXNOC_EV_FILTER) {
+ ret = flexnoc_pmu_event_filter(fp, event, &filter);
+ if (ret)
+ return ret;
+ }
+
+ /* A filter takes the port from the trace port, others from a counter */
+ port_max = flags & FLEXNOC_EV_FILTER ? fp->trace_port_mask : fp->port_mask;
+ if (port > port_max) {
+ dev_dbg(dev, "%s: port %u out of range, maximum is %#x\n",
+ fp->name, port, port_max);
+ return -EINVAL;
+ }
+ if (port && !(flags & (FLEXNOC_EV_PORT | FLEXNOC_EV_FILTER))) {
+ dev_dbg(dev, "%s: event %#x does not observe a port, port must be 0\n",
+ fp->name, src);
+ return -EINVAL;
+ }
+
+ /* Payload bytes can come in tens per cycle: only a chain lasts */
+ if ((flags & FLEXNOC_EV_WIDE) && !chain) {
+ dev_dbg(dev, "%s: byte event requires chain=1\n", fp->name);
+ return -EINVAL;
+ }
+
+ if (chain && fp->n_counters < 2) {
+ dev_dbg(dev, "%s: chain needs 2 counters, probe has %u\n",
+ fp->name, fp->n_counters);
+ return -EINVAL;
+ }
+
+ hwc->idx = -1;
+ hwc->config = src;
+ /* The counter's port select, a filter has its own, see above */
+ hwc->config_base = flags & FLEXNOC_EV_PORT ? port : 0;
+ hwc->event_base = (chain ? FLEXNOC_HW_CHAIN : 0) |
+ (flags & FLEXNOC_EV_FILTER ? FLEXNOC_HW_FILTER : 0);
+
+ if (!flexnoc_pmu_validate_group(event)) {
+ dev_dbg(dev, "%s: group does not fit in %u counters or has foreign hardware events\n",
+ fp->name, fp->n_counters);
+ return -EINVAL;
+ }
+
+ event->cpu = fp->fdev->cpu;
+
+ return 0;
+}
+
+/* CPU hotplug */
+
+static int flexnoc_pmu_online_cpu(unsigned int cpu, struct hlist_node *node)
+{
+ struct flexnoc_pmu_dev *fd = hlist_entry_safe(node,
+ struct flexnoc_pmu_dev,
+ node);
+
+ if (fd->cpu >= nr_cpu_ids)
+ fd->cpu = cpu;
+
+ return 0;
+}
+
+static int flexnoc_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node)
+{
+ struct flexnoc_pmu_dev *fd = hlist_entry_safe(node,
+ struct flexnoc_pmu_dev,
+ node);
+ unsigned int target, i;
+
+ if (fd->cpu != cpu)
+ return 0;
+
+ target = cpumask_any_but(cpu_online_mask, cpu);
+ if (target >= nr_cpu_ids)
+ return 0;
+
+ for (i = 0; i < fd->n_pmus; i++)
+ perf_pmu_migrate_context(&fd->pmus[i].pmu, cpu, target);
+ fd->cpu = target;
+
+ return 0;
+}
+
+/* Discovery */
+
+/*
+ * Find the units of a NoC. ids[slot] gets the CoreId of the unit starting at
+ * that 128-byte slot, 0 if no unit does. Returns the number of units, and the
+ * release of FlexNoC they come from in *flexconnect_id.
+ */
+static unsigned int flexnoc_pmu_scan(struct device *dev, void __iomem *base,
+ unsigned int n_slots, u32 *ids,
+ u32 *flexconnect_id)
+{
+ unsigned int slot, n_units = 0;
+
+ *flexconnect_id = 0;
+
+ for (slot = 0; slot < n_slots; slot++) {
+ void __iomem *unit = base + slot * FLEXNOC_UNIT_STRIDE;
+ u32 coreid, revid, ut, fid;
+
+ ids[slot] = 0;
+
+ coreid = readl(unit + FLEXNOC_COREID);
+ revid = readl(unit + FLEXNOC_REVID);
+
+ ut = FIELD_GET(FLEXNOC_COREID_TYPE, coreid);
+ fid = FIELD_GET(FLEXNOC_REVID_FLEXCONNECT, revid);
+
+ /*
+ * The registers in the middle of a large unit are not
+ * identification registers. They hardly ever look like them,
+ * and then not with the FlexNoC release of this NoC.
+ */
+ if (!ut || ut > FLEXNOC_UT_MAX ||
+ !fid || fid == FIELD_MAX(FLEXNOC_REVID_FLEXCONNECT))
+ continue;
+ if (!*flexconnect_id)
+ *flexconnect_id = fid;
+ else if (fid != *flexconnect_id)
+ continue;
+
+ ids[slot] = coreid;
+ n_units++;
+ dev_dbg(dev, "[%2u]: unit type %2u\n", slot, ut);
+ }
+
+ return n_units;
+}
+
+/*
+ * A counter is there if its source register accepts the value written to it.
+ * Registers that are not there read as zero. The counter is left off.
+ */
+static bool flexnoc_pmu_counter_present(struct flexnoc_pmu *fp,
+ unsigned int idx)
+{
+ void __iomem *src = fp->base + FLEXNOC_CNT_SRC(idx);
+ u32 val;
+
+ writel(FLEXNOC_SRC_CYCLE, src);
+ val = readl(src);
+ writel(FLEXNOC_SRC_OFF, src);
+
+ return val == FLEXNOC_SRC_CYCLE;
+}
+
+/*
+ * Count the statistics counters a packet probe has, and find the width of the
+ * port select field of its counters. At most max_counters are looked for, so
+ * as not to write to the registers of the next unit.
+ */
+static void flexnoc_pmu_detect_counters(struct flexnoc_pmu *fp,
+ unsigned int max_counters)
+{
+ fp->n_counters = 0;
+ fp->port_mask = 0;
+
+ while (fp->n_counters < max_counters &&
+ flexnoc_pmu_counter_present(fp, fp->n_counters))
+ fp->n_counters++;
+
+ if (!fp->n_counters)
+ return;
+
+ /* PortSel has as many bits as it takes to count the probe ports */
+ writel(~0, fp->base + FLEXNOC_CNT_PORTSEL(0));
+ fp->port_mask = readl(fp->base + FLEXNOC_CNT_PORTSEL(0));
+ writel(0, fp->base + FLEXNOC_CNT_PORTSEL(0));
+}
+
+/*
+ * The width of a register: the bits that stick when ones are written to it.
+ * Registers the probe does not have give 0, they may even fault.
+ */
+static u32 flexnoc_pmu_reg_mask(struct flexnoc_pmu *fp, unsigned int off)
+{
+ void __iomem *reg = fp->base + off;
+ u32 old, mask;
+
+ old = readl(reg);
+ writel(~0, reg);
+ mask = readl(reg);
+ writel(old, reg);
+
+ return mask;
+}
+
+/*
+ * Find out if the probe has packet filters, and how wide the fields of filter
+ * 0 are. The LUT has 2^nFilter bits: 2, 4, 8 or 16 with filters, and just
+ * one without, when it is a gate. The probe must be stopped.
+ */
+static void flexnoc_pmu_detect_filters(struct flexnoc_pmu *fp)
+{
+ u32 lut = flexnoc_pmu_reg_mask(fp, FLEXNOC_FILTERLUT);
+
+ fp->n_filters = 0;
+
+ if (lut < 3 || !is_power_of_2(lut + 1) ||
+ !is_power_of_2(hweight32(lut)) ||
+ hweight32(lut) > BIT(FLEXNOC_MAX_FILTERS))
+ return;
+
+ fp->route_id_mask = flexnoc_pmu_reg_mask(fp, FLEXNOC_F0_ROUTEIDMASK);
+ fp->addr_low_mask = flexnoc_pmu_reg_mask(fp, FLEXNOC_F0_ADDRBASE_LOW);
+ fp->addr_high_mask = flexnoc_pmu_reg_mask(fp, FLEXNOC_F0_ADDRBASE_HIGH);
+ fp->window_max = flexnoc_pmu_reg_mask(fp, FLEXNOC_F0_WINDOWSIZE);
+ /* Not a filter without an address window to be set to "any" */
+ if (!fp->window_max || !fp->addr_low_mask)
+ return;
+
+ fp->has_user_mask = flexnoc_pmu_reg_mask(fp, FLEXNOC_F0_USERMASK);
+ fp->has_user_mask_high = flexnoc_pmu_reg_mask(fp, FLEXNOC_F0_USERMASK_HIGH);
+ fp->trace_port_mask = flexnoc_pmu_reg_mask(fp, FLEXNOC_TRACEPORTSEL);
+ fp->lut_mask = lut;
+ fp->n_filters = ilog2(hweight32(lut));
+}
+
+static int flexnoc_pmu_unit_probe(struct flexnoc_pmu_dev *fd,
+ struct flexnoc_pmu *fp, void __iomem *base,
+ unsigned int slot, unsigned int size,
+ u32 flexconnect_id, unsigned int counter_bits,
+ const char *prefix, unsigned int idx)
+{
+ struct device *dev = fd->dev;
+
+ fp->fdev = fd;
+ fp->base = base + slot * FLEXNOC_UNIT_STRIDE;
+ fp->offset = slot * FLEXNOC_UNIT_STRIDE;
+ fp->flexconnect_id = flexconnect_id;
+ fp->counter_bits = counter_bits;
+
+ fp->name = devm_kasprintf(dev, GFP_KERNEL, "%s_%u", prefix, idx);
+ if (!fp->name)
+ return -ENOMEM;
+
+ /* The scan has read it already, it cannot fail now */
+ fp->user_id = FIELD_GET(FLEXNOC_REVID_USERID,
+ readl(fp->base + FLEXNOC_REVID));
+
+ /*
+ * Probes without statistics collection have no counter registers. Do
+ * not touch such a probe, firmware may be tracing with it.
+ */
+ if (size <= FLEXNOC_CNT_BASE || !flexnoc_pmu_counter_present(fp, 0))
+ return -ENODEV;
+
+ /* Do not count anything while the counters are being poked at */
+ flexnoc_pmu_hw_stop(fp);
+
+ flexnoc_pmu_detect_counters(fp, min_t(unsigned int,
+ (size - FLEXNOC_CNT_BASE) /
+ FLEXNOC_CNT_STRIDE,
+ FLEXNOC_MAX_COUNTERS));
+ if (!fp->n_counters)
+ return -ENODEV;
+
+ flexnoc_pmu_hw_reset(fp);
+ if (size > FLEXNOC_F0_USERMASK_HIGH)
+ flexnoc_pmu_detect_filters(fp);
+
+ fp->pmu = (struct pmu) {
+ .parent = dev,
+ .module = THIS_MODULE,
+ .task_ctx_nr = perf_invalid_context,
+ .capabilities = PERF_PMU_CAP_NO_EXCLUDE |
+ PERF_PMU_CAP_NO_INTERRUPT,
+ .attr_groups = flexnoc_pmu_attr_groups,
+ .event_init = flexnoc_pmu_event_init,
+ .add = flexnoc_pmu_add,
+ .del = flexnoc_pmu_del,
+ .start = flexnoc_pmu_start,
+ .stop = flexnoc_pmu_stop,
+ .read = flexnoc_pmu_event_update,
+ };
+
+ return 0;
+}
+
+static void flexnoc_pmu_unregister_all(struct flexnoc_pmu_dev *fd,
+ unsigned int n)
+{
+ while (n--)
+ perf_pmu_unregister(&fd->pmus[n].pmu);
+}
+
+static int flexnoc_pmu_get_counter_bits(struct device *dev,
+ unsigned int *bits)
+{
+ u32 val = FLEXNOC_DEFAULT_COUNTER_BITS;
+ int ret;
+
+ ret = device_property_read_u32(dev, "arteris,counter-bits", &val);
+ if (ret && ret != -EINVAL)
+ return dev_err_probe(dev, ret, "bad arteris,counter-bits\n");
+ if (val < FLEXNOC_MIN_COUNTER_BITS || val > 32)
+ return dev_err_probe(dev, -EINVAL,
+ "arteris,counter-bits %u not supported\n",
+ val);
+
+ *bits = val;
+
+ return 0;
+}
+
+static int flexnoc_pmu_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct flexnoc_pmu_dev *fd;
+ struct resource *res;
+ void __iomem *base;
+ unsigned int n_slots, n_units, n_probes = 0;
+ unsigned int counter_bits, slot, end, i;
+ const char *prefix;
+ u32 flexconnect_id;
+ int ret;
+
+ ret = flexnoc_pmu_get_counter_bits(dev, &counter_bits);
+ if (ret)
+ return ret;
+
+ base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+ if (IS_ERR(base))
+ return PTR_ERR(base);
+
+ /*
+ * PMU names share one flat sysfs namespace, so a system with several
+ * FlexNoC instances gives each of them its own prefix.
+ */
+ if (device_property_read_string(dev, "label", &prefix)) {
+ prefix = devm_kasprintf(dev, GFP_KERNEL, "flexnoc_%llx",
+ (unsigned long long)res->start);
+ if (!prefix)
+ return -ENOMEM;
+ }
+
+ n_slots = resource_size(res) / FLEXNOC_UNIT_STRIDE;
+
+ u32 *ids __free(kfree) = kcalloc(n_slots, sizeof(*ids), GFP_KERNEL);
+ if (!ids)
+ return -ENOMEM;
+
+ n_units = flexnoc_pmu_scan(dev, base, n_slots, ids, &flexconnect_id);
+
+ for (slot = 0; slot < n_slots; slot++) {
+ if (FIELD_GET(FLEXNOC_COREID_TYPE, ids[slot]) ==
+ FLEXNOC_UT_PACKET_PROBE)
+ n_probes++;
+ else if (FIELD_GET(FLEXNOC_COREID_TYPE, ids[slot]) ==
+ FLEXNOC_UT_TXN_PROFILER)
+ dev_dbg(dev, "[%2u]: transaction profiler, not supported\n",
+ slot);
+ }
+
+ dev_dbg(dev, "%u units, %u packet probes in %pr\n", n_units, n_probes,
+ res);
+
+ if (!n_probes)
+ return -ENODEV;
+
+ fd = devm_kzalloc(dev, sizeof(*fd), GFP_KERNEL);
+ if (!fd)
+ return -ENOMEM;
+
+ fd->dev = dev;
+ fd->cpu = nr_cpu_ids;
+ fd->pmus = devm_kcalloc(dev, n_probes, sizeof(*fd->pmus), GFP_KERNEL);
+ if (!fd->pmus)
+ return -ENOMEM;
+
+ for (slot = 0; slot < n_slots; slot++) {
+ struct flexnoc_pmu *fp = &fd->pmus[fd->n_pmus];
+
+ if (FIELD_GET(FLEXNOC_COREID_TYPE, ids[slot]) !=
+ FLEXNOC_UT_PACKET_PROBE)
+ continue;
+
+ /* The unit ends where the next one starts */
+ for (end = slot + 1; end < n_slots && !ids[end]; end++)
+ ;
+
+ ret = flexnoc_pmu_unit_probe(fd, fp, base, slot,
+ min_t(unsigned int,
+ (end - slot) * FLEXNOC_UNIT_STRIDE,
+ FLEXNOC_UNIT_MAX_SIZE),
+ flexconnect_id, counter_bits, prefix,
+ fd->n_pmus);
+ if (ret == -ENODEV) {
+ dev_dbg(dev, "[%2u]: packet probe without statistics counters\n",
+ slot);
+ continue;
+ }
+ if (ret)
+ return ret;
+ fd->n_pmus++;
+ }
+
+ if (!fd->n_pmus)
+ return -ENODEV;
+
+ ret = cpuhp_state_add_instance(flexnoc_pmu_cpuhp_state, &fd->node);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < fd->n_pmus; i++) {
+ struct flexnoc_pmu *fp = &fd->pmus[i];
+
+ ret = perf_pmu_register(&fp->pmu, fp->name, -1);
+ if (ret) {
+ dev_err(dev, "failed to register %s: %d\n", fp->name,
+ ret);
+ flexnoc_pmu_unregister_all(fd, i);
+ cpuhp_state_remove_instance_nocalls(flexnoc_pmu_cpuhp_state, &fd->node);
+ return ret;
+ }
+
+ dev_dbg(dev, "%s: unit at %#x, %u counters of %u bits, port mask %#x\n",
+ fp->name, fp->offset, fp->n_counters, fp->counter_bits,
+ fp->port_mask);
+ }
+
+ platform_set_drvdata(pdev, fd);
+ dev_info(dev, "registered %u FlexNoC probe PMUs\n", fd->n_pmus);
+
+ return 0;
+}
+
+static void flexnoc_pmu_remove(struct platform_device *pdev)
+{
+ struct flexnoc_pmu_dev *fd = platform_get_drvdata(pdev);
+
+ flexnoc_pmu_unregister_all(fd, fd->n_pmus);
+ cpuhp_state_remove_instance_nocalls(flexnoc_pmu_cpuhp_state, &fd->node);
+}
+
+static const struct of_device_id flexnoc_pmu_of_match[] = {
+ { .compatible = "arteris,flexnoc" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, flexnoc_pmu_of_match);
+
+static struct platform_driver flexnoc_pmu_driver = {
+ .driver = {
+ .name = FLEXNOC_PMU_NAME,
+ .of_match_table = flexnoc_pmu_of_match,
+ .suppress_bind_attrs = true,
+ },
+ .probe = flexnoc_pmu_probe,
+ .remove = flexnoc_pmu_remove,
+};
+
+static int __init flexnoc_pmu_init(void)
+{
+ int ret;
+
+ ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
+ "perf/arteris/flexnoc:online",
+ flexnoc_pmu_online_cpu,
+ flexnoc_pmu_offline_cpu);
+ if (ret < 0)
+ return ret;
+ flexnoc_pmu_cpuhp_state = ret;
+
+ ret = platform_driver_register(&flexnoc_pmu_driver);
+ if (ret)
+ cpuhp_remove_multi_state(flexnoc_pmu_cpuhp_state);
+
+ return ret;
+}
+module_init(flexnoc_pmu_init);
+
+static void __exit flexnoc_pmu_exit(void)
+{
+ platform_driver_unregister(&flexnoc_pmu_driver);
+ cpuhp_remove_multi_state(flexnoc_pmu_cpuhp_state);
+}
+module_exit(flexnoc_pmu_exit);
+
+MODULE_DESCRIPTION("Arteris FlexNoC packet probe perf driver");
+MODULE_LICENSE("GPL");
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 4/6] MAINTAINERS: Add entry for Arteris FlexNoC PMU
2026-11-30 12:51 [PATCH 0/6] perf: PMU for Arteris FlexNoC Vladimir Kondratiev
` (2 preceding siblings ...)
2026-11-30 12:51 ` [PATCH 3/6] perf: Add Arteris FlexNoC packet probe PMU driver Vladimir Kondratiev
@ 2026-11-30 12:51 ` Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 5/6] mips: dts: eyeq6h: Add FlexNoC interconnects Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 6/6] MIPS: eyeq6_defconfig: Enable Arteris FlexNoC PMU Vladimir Kondratiev
5 siblings, 0 replies; 7+ messages in thread
From: Vladimir Kondratiev @ 2026-11-30 12:51 UTC (permalink / raw)
To: Will Deacon, Mark Rutland, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Benoît Monin, Gregory CLEMENT, Théo Lebrun,
Thomas Bogendoerfer
Cc: linux-arm-kernel, linux-perf-users, devicetree, linux-kernel,
linux-doc, linux-mips, Vladimir Kondratiev
Add a MAINTAINERS entry covering the Device Tree binding, admin-guide
documentation, and driver for the Arteris FlexNoC packet probe PMU.
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
MAINTAINERS | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 782389bd5cd3..78802945f19f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3965,6 +3965,13 @@ F: Documentation/devicetree/bindings/net/dsa/arrow,xrs700x.yaml
F: drivers/net/dsa/xrs700x/*
F: net/dsa/tag_xrs700x.c
+ARTERIS FLEXNOC PMU
+M: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
+S: Maintained
+F: Documentation/admin-guide/perf/arteris_flexnoc_pmu.rst
+F: Documentation/devicetree/bindings/perf/arteris,flexnoc.yaml
+F: drivers/perf/arteris_flexnoc_pmu.c
+
AS3645A LED FLASH CONTROLLER DRIVER
M: Sakari Ailus <sakari.ailus@iki.fi>
L: linux-leds@vger.kernel.org
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 5/6] mips: dts: eyeq6h: Add FlexNoC interconnects
2026-11-30 12:51 [PATCH 0/6] perf: PMU for Arteris FlexNoC Vladimir Kondratiev
` (3 preceding siblings ...)
2026-11-30 12:51 ` [PATCH 4/6] MAINTAINERS: Add entry for Arteris FlexNoC PMU Vladimir Kondratiev
@ 2026-11-30 12:51 ` Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 6/6] MIPS: eyeq6_defconfig: Enable Arteris FlexNoC PMU Vladimir Kondratiev
5 siblings, 0 replies; 7+ messages in thread
From: Vladimir Kondratiev @ 2026-11-30 12:51 UTC (permalink / raw)
To: Will Deacon, Mark Rutland, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Benoît Monin, Gregory CLEMENT, Théo Lebrun,
Thomas Bogendoerfer
Cc: linux-arm-kernel, linux-perf-users, devicetree, linux-kernel,
linux-doc, linux-mips, Vladimir Kondratiev
Add FlexNoC interconnect nodes for the Mobileye EyeQ6H SoC so the perf
PMU driver can discover packet probes. Set "label" on each node to give
its PMUs predictable names (such as flexnoc_ccti_0 and
flexnoc_interleaver_0)
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
arch/mips/boot/dts/mobileye/eyeq6h.dtsi | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/arch/mips/boot/dts/mobileye/eyeq6h.dtsi b/arch/mips/boot/dts/mobileye/eyeq6h.dtsi
index 5ae939d25ea8..fe01612e4f9d 100644
--- a/arch/mips/boot/dts/mobileye/eyeq6h.dtsi
+++ b/arch/mips/boot/dts/mobileye/eyeq6h.dtsi
@@ -48,6 +48,12 @@ soc: soc {
#size-cells = <2>;
ranges;
+ noc_ncore_ccti: interconnect@d1d00000 {
+ compatible = "mobileye,eyeq6h-flexnoc", "arteris,flexnoc";
+ reg = <0 0xd1d00000 0 0x1000>;
+ label = "flexnoc_ccti";
+ };
+
olb_acc: system-controller@d2003000 {
compatible = "mobileye,eyeq6h-acc-olb", "syscon";
reg = <0x0 0xd2003000 0x0 0x1000>;
@@ -57,6 +63,12 @@ olb_acc: system-controller@d2003000 {
clock-names = "ref";
};
+ noc_interleaver: interconnect@d2010000 {
+ compatible = "mobileye,eyeq6h-flexnoc", "arteris,flexnoc";
+ reg = <0 0xd2010000 0 0x1000>;
+ label = "flexnoc_interleaver";
+ };
+
olb_central: system-controller@d3100000 {
compatible = "mobileye,eyeq6h-central-olb", "syscon";
reg = <0x0 0xd3100000 0x0 0x1000>;
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 6/6] MIPS: eyeq6_defconfig: Enable Arteris FlexNoC PMU
2026-11-30 12:51 [PATCH 0/6] perf: PMU for Arteris FlexNoC Vladimir Kondratiev
` (4 preceding siblings ...)
2026-11-30 12:51 ` [PATCH 5/6] mips: dts: eyeq6h: Add FlexNoC interconnects Vladimir Kondratiev
@ 2026-11-30 12:51 ` Vladimir Kondratiev
5 siblings, 0 replies; 7+ messages in thread
From: Vladimir Kondratiev @ 2026-11-30 12:51 UTC (permalink / raw)
To: Will Deacon, Mark Rutland, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Benoît Monin, Gregory CLEMENT, Théo Lebrun,
Thomas Bogendoerfer
Cc: linux-arm-kernel, linux-perf-users, devicetree, linux-kernel,
linux-doc, linux-mips, Vladimir Kondratiev
Enable CONFIG_PERF_EVENTS and build CONFIG_ARTERIS_FLEXNOC_PMU as a
module for EyeQ6 platforms.
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
arch/mips/configs/eyeq6_defconfig | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/mips/configs/eyeq6_defconfig b/arch/mips/configs/eyeq6_defconfig
index 0a00a201937b..a3beb0b19806 100644
--- a/arch/mips/configs/eyeq6_defconfig
+++ b/arch/mips/configs/eyeq6_defconfig
@@ -19,6 +19,7 @@ CONFIG_USER_NS=y
CONFIG_SCHED_AUTOGROUP=y
CONFIG_BLK_DEV_INITRD=y
CONFIG_EXPERT=y
+CONFIG_PERF_EVENTS=y
CONFIG_EYEQ=y
CONFIG_MACH_EYEQ6H=y
CONFIG_MIPS_CPS=y
@@ -86,6 +87,7 @@ CONFIG_MMC_SDHCI_PLTFM=y
CONFIG_MMC_SDHCI_CADENCE=y
# CONFIG_IOMMU_SUPPORT is not set
CONFIG_RESET_CONTROLLER=y
+CONFIG_ARTERIS_FLEXNOC_PMU=m
# CONFIG_NVMEM is not set
CONFIG_EXT4_FS=y
CONFIG_EXT4_FS_POSIX_ACL=y
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-30 12:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 12:51 [PATCH 0/6] perf: PMU for Arteris FlexNoC Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 1/6] dt-bindings: vendor-prefixes: Add arteris Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 2/6] dt-bindings: perf: Add Arteris FlexNoC interconnect Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 3/6] perf: Add Arteris FlexNoC packet probe PMU driver Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 4/6] MAINTAINERS: Add entry for Arteris FlexNoC PMU Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 5/6] mips: dts: eyeq6h: Add FlexNoC interconnects Vladimir Kondratiev
2026-11-30 12:51 ` [PATCH 6/6] MIPS: eyeq6_defconfig: Enable Arteris FlexNoC PMU Vladimir Kondratiev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®