1/*-
2 * Copyright (c) 2003,2004 Joseph Koshy
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29#ifndef _PMC_H_
30#define _PMC_H_
31
32#include <sys/cdefs.h>
33#include <sys/types.h>
34#include <sys/pmc.h>
35
36/*
37 * Driver statistics.
38 */
39struct pmc_driverstats {
40	unsigned int	pm_intr_ignored;	/* #interrupts ignored */
41	unsigned int	pm_intr_processed;	/* #interrupts processed */
42	unsigned int	pm_intr_bufferfull;	/* #interrupts with ENOSPC */
43	unsigned int	pm_syscalls;		/* #syscalls */
44	unsigned int	pm_syscall_errors;	/* #syscalls with errors */
45	unsigned int	pm_buffer_requests;	/* #buffer requests */
46	unsigned int	pm_buffer_requests_failed; /* #failed buffer requests */
47	unsigned int	pm_log_sweeps;		/* #sample buffer processing
48						   passes */
49};
50
51/*
52 * CPU information.
53 */
54struct pmc_cpuinfo {
55	enum pmc_cputype pm_cputype;	/* the kind of CPU */
56	uint32_t	pm_ncpu;	/* number of CPUs */
57	uint32_t	pm_npmc;	/* #PMCs per CPU */
58	uint32_t	pm_nclass;	/* #classes of PMCs */
59	struct pmc_classinfo pm_classes[PMC_CLASS_MAX];
60};
61
62/*
63 * Current PMC state.
64 */
65struct pmc_pmcinfo {
66	int32_t		pm_cpu;		/* CPU number */
67	struct pmc_info	pm_pmcs[];	/* NPMC structs */
68};
69
70/*
71 * Prototypes
72 */
73
74__BEGIN_DECLS
75int	pmc_allocate(const char *_ctrspec, enum pmc_mode _mode, uint32_t _flags,
76    int _cpu, pmc_id_t *_pmcid);
77int	pmc_attach(pmc_id_t _pmcid, pid_t _pid);
78int	pmc_capabilities(pmc_id_t _pmc, uint32_t *_caps);
79int	pmc_configure_logfile(int _fd);
80int	pmc_flush_logfile(void);
81int	pmc_close_logfile(void);
82int	pmc_detach(pmc_id_t _pmcid, pid_t _pid);
83int	pmc_disable(int _cpu, int _pmc);
84int	pmc_enable(int _cpu, int _pmc);
85int	pmc_get_driver_stats(struct pmc_driverstats *_gms);
86int	pmc_get_msr(pmc_id_t _pmc, uint32_t *_msr);
87int	pmc_init(void);
88int	pmc_read(pmc_id_t _pmc, pmc_value_t *_value);
89int	pmc_release(pmc_id_t _pmc);
90int	pmc_rw(pmc_id_t _pmc, pmc_value_t _newvalue, pmc_value_t *_oldvalue);
91int	pmc_set(pmc_id_t _pmc, pmc_value_t _value);
92int	pmc_start(pmc_id_t _pmc);
93int	pmc_stop(pmc_id_t _pmc);
94int	pmc_width(pmc_id_t _pmc, uint32_t *_width);
95int	pmc_write(pmc_id_t _pmc, pmc_value_t _value);
96int	pmc_writelog(uint32_t _udata);
97
98int	pmc_ncpu(void);
99int	pmc_npmc(int _cpu);
100int	pmc_cpuinfo(const struct pmc_cpuinfo **_cpu_info);
101int	pmc_pmcinfo(int _cpu, struct pmc_pmcinfo **_pmc_info);
102
103const char	*pmc_name_of_capability(enum pmc_caps _c);
104const char	*pmc_name_of_class(enum pmc_class _pc);
105const char	*pmc_name_of_cputype(enum pmc_cputype _cp);
106const char	*pmc_name_of_disposition(enum pmc_disp _pd);
107const char	*pmc_name_of_event(enum pmc_event _pe);
108const char	*pmc_name_of_mode(enum pmc_mode _pm);
109const char	*pmc_name_of_state(enum pmc_state _ps);
110
111int	pmc_event_names_of_class(enum pmc_class _cl, const char ***_eventnames,
112    int *_nevents);
113__END_DECLS
114
115#endif
116