master
1/* $NetBSD: kcov.h,v 1.10 2020/06/05 17:20:57 maxv Exp $ */
2
3/*
4 * Copyright (c) 2019-2020 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Siddharth Muralee.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef _SYS_KCOV_H_
33#define _SYS_KCOV_H_
34
35#ifdef _KERNEL_OPT
36#include "opt_kcov.h"
37#endif
38
39#include <sys/param.h>
40#include <sys/types.h>
41#include <sys/atomic.h>
42
43#define KCOV_IOC_SETBUFSIZE _IOW('K', 1, uint64_t)
44#define KCOV_IOC_ENABLE _IOW('K', 2, int)
45#define KCOV_IOC_DISABLE _IO('K', 3)
46
47#define KCOV_IOC_REMOTE_ATTACH _IOW('K', 10, struct kcov_ioc_remote_attach)
48#define KCOV_IOC_REMOTE_DETACH _IO('K', 11)
49
50struct kcov_ioc_remote_attach {
51 uint64_t subsystem;
52 uint64_t id;
53};
54
55#define KCOV_REMOTE_VHCI 0
56#define KCOV_REMOTE_VHCI_ID(bus, port) \
57 (((uint64_t)bus << 32ULL) | ((uint64_t)port & 0xFFFFFFFFULL))
58
59#define KCOV_MODE_NONE 0
60#define KCOV_MODE_TRACE_PC 1
61#define KCOV_MODE_TRACE_CMP 2
62
63typedef volatile uint64_t kcov_int_t;
64#define KCOV_ENTRY_SIZE sizeof(kcov_int_t)
65
66#ifdef _KERNEL
67#ifdef KCOV
68void kcov_remote_register(uint64_t, uint64_t);
69void kcov_remote_enter(uint64_t, uint64_t);
70void kcov_remote_leave(uint64_t, uint64_t);
71void kcov_silence_enter(void);
72void kcov_silence_leave(void);
73void kcov_lwp_free(struct lwp *);
74#else
75#define kcov_remote_register(s, i) __nothing
76#define kcov_remote_enter(s, i) __nothing
77#define kcov_remote_leave(s, i) __nothing
78#define kcov_silence_enter() __nothing
79#define kcov_silence_leave() __nothing
80#define kcov_lwp_free(a) __nothing
81#endif
82#endif
83
84#endif /* !_SYS_KCOV_H_ */