-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvirtio_vmmci.h
80 lines (69 loc) · 2.53 KB
/
virtio_vmmci.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Implementation of an OpenBSD VMM control interface for Linux guests
* running under an OpenBSD host.
*
* Copyright 2019 Dave Voutila
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <linux/version.h>
#ifndef _VIRTIO_VMMCI_H
#define _VIRTIO_VMMCI_H
/* Find if we have an RTC device or not. We should, but Linux gives us two
* possible ways to find it based on how the guest kernel was configured at
* build time.
*/
#if defined(CONFIG_RTC_HCTOSYS_DEVICE)
#define VMMCI_RTC_DEVICE CONFIG_RTC_HCTOSYS_DEVICE
#elif defined(CONFIG_RTC_SYSTOHC_DEVICE)
#define VMMCI_RTC_DEVICE CONFIG_RTC_SYSTOHC_DEVICE
#endif
const char *QNAME_MONITOR = "vmmci-monitor";
/* This should be picked up from the kernel config */
#ifdef CONFIG_HZ
#define HZ CONFIG_HZ
#else
/* fallback to 100, the default in alpine-virt */
#define HZ 100
#endif
/* 1 jiffy = 1 HZ...but that assumes our clock doesn't have issues :-( */
#define DELAY_1s HZ
#define DELAY_20s 20 * HZ
#define VIRTIO_ID_VMMCI 0xffff /* matches OpenBSD's private id */
#define PCI_VENDOR_ID_OPENBSD 0x0b5d
#define PCI_DEVICE_ID_OPENBSD_VMMCI 0x0777
/* Configuration registers */
#define VMMCI_CONFIG_COMMAND 0
#define VMMCI_CONFIG_TIME_SEC 4
#define VMMCI_CONFIG_TIME_USEC 12
/* Features...these get bit-shifted in the Linux virtio code */
#define VMMCI_F_TIMESYNC 0
#define VMMCI_F_ACK 1
#define VMMCI_F_SYNCRTC 2
/*
* Linux is in a 32/64 bit transition phases where v4.17 and below
* seem to define timespec64 as just timespec...ugh. Also, this is
* probably a really bad idea to handle it this way?
*/
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,18,0)
#define TIME_FMT "%ld.%09ld"
#else
#define TIME_FMT "%lld.%09ld"
#endif
#define debug(fmt, ...) \
do { if (debug) pr_info("vmmci: [%s] " fmt, __func__, ##__VA_ARGS__); \
} while (0)
#define log(fmt, ...) pr_info("vmmci: " fmt, ##__VA_ARGS__)
#endif // _VIRTIO_VMMCI_H