1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2020-2021 Collabora, Ltd.
3bf215546Sopenharmony_ci * Author: Antonio Caggiano <antonio.caggiano@collabora.com>
4bf215546Sopenharmony_ci * Author: Rohan Garg <rohan.garg@collabora.com>
5bf215546Sopenharmony_ci * Author: Robert Beckett <bob.beckett@collabora.com>
6bf215546Sopenharmony_ci *
7bf215546Sopenharmony_ci * SPDX-License-Identifier: MIT
8bf215546Sopenharmony_ci */
9bf215546Sopenharmony_ci
10bf215546Sopenharmony_ci#pragma once
11bf215546Sopenharmony_ci
12bf215546Sopenharmony_ci#include <pps/pps_driver.h>
13bf215546Sopenharmony_ci
14bf215546Sopenharmony_ci#include "pan_pps_perf.h"
15bf215546Sopenharmony_ci
16bf215546Sopenharmony_cinamespace pps
17bf215546Sopenharmony_ci{
18bf215546Sopenharmony_ci/// @brief Panfrost implementation of PPS driver.
19bf215546Sopenharmony_ci/// This driver queries the GPU through `drm/panfrost_drm.h`, using performance counters ioctls,
20bf215546Sopenharmony_ci/// which can be enabled by setting a kernel parameter: `modprobe panfrost unstable_ioctls=1`.
21bf215546Sopenharmony_ci/// The ioctl needs a buffer to copy data from kernel to user space.
22bf215546Sopenharmony_ciclass PanfrostDriver : public Driver
23bf215546Sopenharmony_ci{
24bf215546Sopenharmony_ci   public:
25bf215546Sopenharmony_ci   static inline PanfrostDriver &into(Driver &dri);
26bf215546Sopenharmony_ci   static inline const PanfrostDriver &into(const Driver &dri);
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci   /// @param A list of mali counter names
29bf215546Sopenharmony_ci   /// @return A pair with two lists: counter groups and available counters
30bf215546Sopenharmony_ci   static std::pair<std::vector<CounterGroup>, std::vector<Counter>> create_available_counters(
31bf215546Sopenharmony_ci      const PanfrostPerf& perf);
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci   PanfrostDriver();
34bf215546Sopenharmony_ci   ~PanfrostDriver();
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci   uint64_t get_min_sampling_period_ns() override;
37bf215546Sopenharmony_ci   bool init_perfcnt() override;
38bf215546Sopenharmony_ci   void enable_counter(uint32_t counter_id) override;
39bf215546Sopenharmony_ci   void enable_all_counters() override;
40bf215546Sopenharmony_ci   void enable_perfcnt(uint64_t sampling_period_ns) override;
41bf215546Sopenharmony_ci   void disable_perfcnt() override;
42bf215546Sopenharmony_ci   bool dump_perfcnt() override;
43bf215546Sopenharmony_ci   uint64_t next() override;
44bf215546Sopenharmony_ci   uint32_t gpu_clock_id() const override;
45bf215546Sopenharmony_ci   uint64_t gpu_timestamp() const override;
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci   uint64_t last_dump_ts = 0;
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci   std::unique_ptr<PanfrostDevice> dev = nullptr;
50bf215546Sopenharmony_ci   std::unique_ptr<PanfrostPerf> perf = nullptr;
51bf215546Sopenharmony_ci};
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ciPanfrostDriver &PanfrostDriver::into(Driver &dri)
54bf215546Sopenharmony_ci{
55bf215546Sopenharmony_ci   return reinterpret_cast<PanfrostDriver &>(dri);
56bf215546Sopenharmony_ci}
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ciconst PanfrostDriver &PanfrostDriver::into(const Driver &dri)
59bf215546Sopenharmony_ci{
60bf215546Sopenharmony_ci   return reinterpret_cast<const PanfrostDriver &>(dri);
61bf215546Sopenharmony_ci}
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci} // namespace pps
64