1145256Sjkoshy/*-
2145256Sjkoshy * Copyright (c) 2003,2004 Joseph Koshy
3145256Sjkoshy * All rights reserved.
4145256Sjkoshy *
5145256Sjkoshy * Redistribution and use in source and binary forms, with or without
6145256Sjkoshy * modification, are permitted provided that the following conditions
7145256Sjkoshy * are met:
8145256Sjkoshy * 1. Redistributions of source code must retain the above copyright
9145256Sjkoshy *    notice, this list of conditions and the following disclaimer.
10145256Sjkoshy * 2. Redistributions in binary form must reproduce the above copyright
11145256Sjkoshy *    notice, this list of conditions and the following disclaimer in the
12145256Sjkoshy *    documentation and/or other materials provided with the distribution.
13145256Sjkoshy *
14145256Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15145256Sjkoshy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16145256Sjkoshy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17145256Sjkoshy * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18145256Sjkoshy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19145256Sjkoshy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20145256Sjkoshy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21145256Sjkoshy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22145256Sjkoshy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23145256Sjkoshy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24145256Sjkoshy * SUCH DAMAGE.
25145256Sjkoshy *
26145256Sjkoshy * $FreeBSD$
27145256Sjkoshy */
28145256Sjkoshy
29145256Sjkoshy#ifndef _PMC_H_
30145256Sjkoshy#define _PMC_H_
31145256Sjkoshy
32190395Sfabient#include <sys/cdefs.h>
33145256Sjkoshy#include <sys/pmc.h>
34145256Sjkoshy
35145256Sjkoshy/*
36147191Sjkoshy * Driver statistics.
37147191Sjkoshy */
38147191Sjkoshystruct pmc_driverstats {
39147191Sjkoshy	int	pm_intr_ignored;	/* #interrupts ignored */
40147191Sjkoshy	int	pm_intr_processed;	/* #interrupts processed */
41147191Sjkoshy	int	pm_intr_bufferfull;	/* #interrupts with ENOSPC */
42147191Sjkoshy	int	pm_syscalls;		/* #syscalls */
43147191Sjkoshy	int	pm_syscall_errors;	/* #syscalls with errors */
44147191Sjkoshy	int	pm_buffer_requests;	/* #buffer requests */
45147191Sjkoshy	int	pm_buffer_requests_failed; /* #failed buffer requests */
46147191Sjkoshy	int	pm_log_sweeps;		/* #sample buffer processing passes */
47147191Sjkoshy};
48147191Sjkoshy
49147191Sjkoshy/*
50147191Sjkoshy * CPU information.
51147191Sjkoshy */
52147191Sjkoshystruct pmc_cpuinfo {
53147191Sjkoshy	enum pmc_cputype pm_cputype;	/* the kind of CPU */
54147191Sjkoshy	uint32_t	pm_ncpu;	/* number of CPUs */
55147191Sjkoshy	uint32_t	pm_npmc;	/* #PMCs per CPU */
56147191Sjkoshy	uint32_t	pm_nclass;	/* #classes of PMCs */
57147191Sjkoshy	struct pmc_classinfo pm_classes[PMC_CLASS_MAX];
58147191Sjkoshy};
59147191Sjkoshy
60147191Sjkoshy/*
61147191Sjkoshy * Current PMC state.
62147191Sjkoshy */
63147191Sjkoshystruct pmc_pmcinfo {
64147191Sjkoshy	int32_t		pm_cpu;		/* CPU number */
65147191Sjkoshy	struct pmc_info	pm_pmcs[];	/* NPMC structs */
66147191Sjkoshy};
67147191Sjkoshy
68147191Sjkoshy/*
69145256Sjkoshy * Prototypes
70145256Sjkoshy */
71145256Sjkoshy
72190395Sfabient__BEGIN_DECLS
73145256Sjkoshyint	pmc_allocate(const char *_ctrspec, enum pmc_mode _mode, uint32_t _flags,
74145256Sjkoshy    int _cpu, pmc_id_t *_pmcid);
75145256Sjkoshyint	pmc_attach(pmc_id_t _pmcid, pid_t _pid);
76145774Sjkoshyint	pmc_capabilities(pmc_id_t _pmc, uint32_t *_caps);
77145256Sjkoshyint	pmc_configure_logfile(int _fd);
78147191Sjkoshyint	pmc_flush_logfile(void);
79226514Sfabientint	pmc_close_logfile(void);
80145256Sjkoshyint	pmc_detach(pmc_id_t _pmcid, pid_t _pid);
81145256Sjkoshyint	pmc_disable(int _cpu, int _pmc);
82145256Sjkoshyint	pmc_enable(int _cpu, int _pmc);
83147191Sjkoshyint	pmc_get_driver_stats(struct pmc_driverstats *_gms);
84147191Sjkoshyint	pmc_get_msr(pmc_id_t _pmc, uint32_t *_msr);
85145256Sjkoshyint	pmc_init(void);
86145256Sjkoshyint	pmc_read(pmc_id_t _pmc, pmc_value_t *_value);
87145256Sjkoshyint	pmc_release(pmc_id_t _pmc);
88145256Sjkoshyint	pmc_rw(pmc_id_t _pmc, pmc_value_t _newvalue, pmc_value_t *_oldvalue);
89145256Sjkoshyint	pmc_set(pmc_id_t _pmc, pmc_value_t _value);
90145256Sjkoshyint	pmc_start(pmc_id_t _pmc);
91145256Sjkoshyint	pmc_stop(pmc_id_t _pmc);
92145774Sjkoshyint	pmc_width(pmc_id_t _pmc, uint32_t *_width);
93145256Sjkoshyint	pmc_write(pmc_id_t _pmc, pmc_value_t _value);
94147191Sjkoshyint	pmc_writelog(uint32_t _udata);
95145256Sjkoshy
96145256Sjkoshyint	pmc_ncpu(void);
97145256Sjkoshyint	pmc_npmc(int _cpu);
98147191Sjkoshyint	pmc_cpuinfo(const struct pmc_cpuinfo **_cpu_info);
99147191Sjkoshyint	pmc_pmcinfo(int _cpu, struct pmc_pmcinfo **_pmc_info);
100145256Sjkoshy
101233321Sjkoshyconst char	*pmc_name_of_capability(enum pmc_caps _c);
102145256Sjkoshyconst char	*pmc_name_of_class(enum pmc_class _pc);
103145256Sjkoshyconst char	*pmc_name_of_cputype(enum pmc_cputype _cp);
104145256Sjkoshyconst char	*pmc_name_of_disposition(enum pmc_disp _pd);
105145256Sjkoshyconst char	*pmc_name_of_event(enum pmc_event _pe);
106145256Sjkoshyconst char	*pmc_name_of_mode(enum pmc_mode _pm);
107145256Sjkoshyconst char	*pmc_name_of_state(enum pmc_state _ps);
108145256Sjkoshy
109145256Sjkoshyint	pmc_event_names_of_class(enum pmc_class _cl, const char ***_eventnames,
110145256Sjkoshy    int *_nevents);
111190395Sfabient__END_DECLS
112145256Sjkoshy
113145256Sjkoshy#endif
114