1/*
2 * Copyright (c) 2015 Martin Lucina.  All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
14 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#include <sys/cdefs.h>
27#include <sys/param.h>
28#include <sys/cpu.h>
29#include <sys/kernel.h>
30#include <sys/module.h>
31#include <sys/timetc.h>
32
33#include "bmktc_user.h"
34
35MODULE(MODULE_CLASS_MISC, bmktc, NULL);
36
37static u_int
38bmktc_get(struct timecounter *tc)
39{
40
41	return rumpcomp_bmktc_gettime();
42}
43
44static struct timecounter bmktc = {
45	.tc_get_timecount	= bmktc_get,
46	.tc_poll_pps 		= NULL,
47	.tc_counter_mask	= ~0,
48	.tc_frequency		= 1000000000ULL,
49	.tc_name		= "bmktc",
50	.tc_quality		= 100,
51};
52
53static int
54bmktc_modcmd(modcmd_t cmd, void *arg)
55{
56
57	switch (cmd) {
58	case MODULE_CMD_INIT:
59		tc_init(&bmktc);
60		break;
61
62	case MODULE_CMD_FINI:
63		tc_detach(&bmktc);
64		break;
65
66	default:
67		return ENOTTY;
68	}
69
70	return 0;
71}
72