1bf215546Sopenharmony_ci#include "pan_pps_perf.h"
2bf215546Sopenharmony_ci
3bf215546Sopenharmony_ci#include <lib/pan_device.h>
4bf215546Sopenharmony_ci#include <perf/pan_perf.h>
5bf215546Sopenharmony_ci#include <util/ralloc.h>
6bf215546Sopenharmony_ci#include <pps/pps.h>
7bf215546Sopenharmony_ci
8bf215546Sopenharmony_cinamespace pps
9bf215546Sopenharmony_ci{
10bf215546Sopenharmony_ciPanfrostDevice::PanfrostDevice(int fd)
11bf215546Sopenharmony_ci   : ctx {ralloc_context(nullptr)}
12bf215546Sopenharmony_ci   , dev {reinterpret_cast<struct panfrost_device*>(new struct panfrost_device())}
13bf215546Sopenharmony_ci{
14bf215546Sopenharmony_ci   assert(fd >= 0);
15bf215546Sopenharmony_ci   panfrost_open_device(ctx, fd, dev);
16bf215546Sopenharmony_ci}
17bf215546Sopenharmony_ci
18bf215546Sopenharmony_ciPanfrostDevice::~PanfrostDevice()
19bf215546Sopenharmony_ci{
20bf215546Sopenharmony_ci   if (ctx) {
21bf215546Sopenharmony_ci      panfrost_close_device(dev);
22bf215546Sopenharmony_ci   }
23bf215546Sopenharmony_ci   if (dev) {
24bf215546Sopenharmony_ci      delete dev;
25bf215546Sopenharmony_ci   }
26bf215546Sopenharmony_ci}
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ciPanfrostDevice::PanfrostDevice(PanfrostDevice &&o)
29bf215546Sopenharmony_ci   : ctx {o.ctx}
30bf215546Sopenharmony_ci   , dev {o.dev}
31bf215546Sopenharmony_ci{
32bf215546Sopenharmony_ci   o.ctx = nullptr;
33bf215546Sopenharmony_ci   o.dev = nullptr;
34bf215546Sopenharmony_ci}
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ciPanfrostDevice &PanfrostDevice::operator=(PanfrostDevice &&o)
37bf215546Sopenharmony_ci{
38bf215546Sopenharmony_ci   std::swap(ctx, o.ctx);
39bf215546Sopenharmony_ci   std::swap(dev, o.dev);
40bf215546Sopenharmony_ci   return *this;
41bf215546Sopenharmony_ci}
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ciPanfrostPerf::PanfrostPerf(const PanfrostDevice& dev)
44bf215546Sopenharmony_ci   : perf {reinterpret_cast<struct panfrost_perf *>(rzalloc(nullptr, struct panfrost_perf))}
45bf215546Sopenharmony_ci{
46bf215546Sopenharmony_ci   assert(perf);
47bf215546Sopenharmony_ci   assert(dev.dev);
48bf215546Sopenharmony_ci   panfrost_perf_init(perf, dev.dev);
49bf215546Sopenharmony_ci}
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ciPanfrostPerf::~PanfrostPerf()
52bf215546Sopenharmony_ci{
53bf215546Sopenharmony_ci   if (perf) {
54bf215546Sopenharmony_ci      panfrost_perf_disable(perf);
55bf215546Sopenharmony_ci      ralloc_free(perf);
56bf215546Sopenharmony_ci   }
57bf215546Sopenharmony_ci}
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ciPanfrostPerf::PanfrostPerf(PanfrostPerf &&o)
60bf215546Sopenharmony_ci   : perf {o.perf}
61bf215546Sopenharmony_ci{
62bf215546Sopenharmony_ci   o.perf = nullptr;
63bf215546Sopenharmony_ci}
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ciPanfrostPerf &PanfrostPerf::operator=(PanfrostPerf &&o)
66bf215546Sopenharmony_ci{
67bf215546Sopenharmony_ci   std::swap(perf, o.perf);
68bf215546Sopenharmony_ci   return *this;
69bf215546Sopenharmony_ci}
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ciint PanfrostPerf::enable() const
72bf215546Sopenharmony_ci{
73bf215546Sopenharmony_ci   assert(perf);
74bf215546Sopenharmony_ci   return panfrost_perf_enable(perf);
75bf215546Sopenharmony_ci}
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_civoid PanfrostPerf::disable() const
78bf215546Sopenharmony_ci{
79bf215546Sopenharmony_ci   assert(perf);
80bf215546Sopenharmony_ci   panfrost_perf_disable(perf);
81bf215546Sopenharmony_ci}
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ciint PanfrostPerf::dump() const
84bf215546Sopenharmony_ci{
85bf215546Sopenharmony_ci   assert(perf);
86bf215546Sopenharmony_ci   return panfrost_perf_dump(perf);
87bf215546Sopenharmony_ci}
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_ci} // namespace pps
90