1// Copyright 2017 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#pragma once
6
7#include <stddef.h>
8#include <threads.h>
9
10#include <zircon/types.h>
11
12typedef struct cpu_trace_device {
13    mtx_t lock;
14
15    // Only one open of this device is supported at a time. KISS for now.
16    bool opened;
17
18#ifdef __x86_64__
19    struct insntrace_device* insntrace;
20    struct cpuperf_device* cpuperf;
21#endif
22
23    zx_handle_t bti;
24} cpu_trace_device_t;
25
26#ifdef __x86_64__
27
28// Intel Processor Trace
29
30void insntrace_init_once(void);
31
32zx_status_t insntrace_ioctl(cpu_trace_device_t* dev, uint32_t op,
33                            const void* cmd, size_t cmdlen,
34                            void* reply, size_t replymax,
35                            size_t* out_actual);
36
37
38void insntrace_release(cpu_trace_device_t* dev);
39
40// Intel Performance Monitor
41
42void cpuperf_init_once(void);
43
44zx_status_t cpuperf_ioctl(cpu_trace_device_t* dev, uint32_t op,
45                          const void* cmd, size_t cmdlen,
46                          void* reply, size_t replymax,
47                          size_t* out_actual);
48
49void cpuperf_release(cpu_trace_device_t* dev);
50
51#endif // __x86_64__
52