Home | History | Annotate | Line # | Download | only in nvmm
nvmm.h revision 1.14
      1  1.14  maxv /*	$NetBSD: nvmm.h,v 1.14 2020/08/05 16:36:33 maxv Exp $	*/
      2   1.1  maxv 
      3   1.1  maxv /*
      4  1.13  maxv  * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
      5   1.1  maxv  * All rights reserved.
      6   1.1  maxv  *
      7   1.1  maxv  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1  maxv  * by Maxime Villard.
      9   1.1  maxv  *
     10   1.1  maxv  * Redistribution and use in source and binary forms, with or without
     11   1.1  maxv  * modification, are permitted provided that the following conditions
     12   1.1  maxv  * are met:
     13   1.1  maxv  * 1. Redistributions of source code must retain the above copyright
     14   1.1  maxv  *    notice, this list of conditions and the following disclaimer.
     15   1.1  maxv  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1  maxv  *    notice, this list of conditions and the following disclaimer in the
     17   1.1  maxv  *    documentation and/or other materials provided with the distribution.
     18   1.1  maxv  *
     19   1.1  maxv  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1  maxv  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1  maxv  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1  maxv  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1  maxv  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1  maxv  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1  maxv  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1  maxv  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1  maxv  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1  maxv  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1  maxv  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1  maxv  */
     31   1.1  maxv 
     32   1.1  maxv #ifndef _NVMM_H_
     33   1.1  maxv #define _NVMM_H_
     34   1.1  maxv 
     35   1.1  maxv #include <sys/types.h>
     36   1.1  maxv 
     37   1.1  maxv #ifndef _KERNEL
     38   1.1  maxv #include <stdbool.h>
     39   1.1  maxv #endif
     40   1.1  maxv 
     41   1.1  maxv typedef uint64_t	gpaddr_t;
     42   1.1  maxv typedef uint64_t	gvaddr_t;
     43   1.1  maxv 
     44   1.1  maxv typedef uint32_t	nvmm_machid_t;
     45   1.1  maxv typedef uint32_t	nvmm_cpuid_t;
     46   1.1  maxv 
     47  1.13  maxv #if defined(__x86_64__)
     48   1.7  maxv #include <dev/nvmm/x86/nvmm_x86.h>
     49   1.7  maxv #endif
     50   1.1  maxv 
     51  1.11  maxv #define NVMM_KERN_VERSION		1
     52   1.1  maxv 
     53   1.1  maxv struct nvmm_capability {
     54  1.12  maxv 	uint32_t version;
     55  1.12  maxv 	uint32_t state_size;
     56  1.12  maxv 	uint32_t max_machines;
     57  1.12  maxv 	uint32_t max_vcpus;
     58   1.1  maxv 	uint64_t max_ram;
     59   1.7  maxv 	struct nvmm_cap_md arch;
     60   1.1  maxv };
     61   1.1  maxv 
     62  1.11  maxv /* Machine configuration slots. */
     63  1.10  maxv #define NVMM_MACH_CONF_LIBNVMM_BEGIN	0
     64  1.10  maxv #define NVMM_MACH_CONF_MI_BEGIN		100
     65  1.10  maxv #define NVMM_MACH_CONF_MD_BEGIN		200
     66  1.11  maxv #define NVMM_MACH_CONF_MD(op)		(op - NVMM_MACH_CONF_MD_BEGIN)
     67  1.10  maxv 
     68  1.11  maxv /* VCPU configuration slots. */
     69  1.11  maxv #define NVMM_VCPU_CONF_LIBNVMM_BEGIN	0
     70  1.11  maxv #define NVMM_VCPU_CONF_MI_BEGIN		100
     71  1.11  maxv #define NVMM_VCPU_CONF_MD_BEGIN		200
     72  1.11  maxv #define NVMM_VCPU_CONF_MD(op)		(op - NVMM_VCPU_CONF_MD_BEGIN)
     73  1.10  maxv 
     74   1.9  maxv struct nvmm_comm_page {
     75   1.9  maxv 	/* State. */
     76   1.9  maxv 	uint64_t state_wanted;
     77   1.9  maxv 	uint64_t state_cached;
     78   1.9  maxv 	uint64_t state_commit;
     79   1.9  maxv 	struct nvmm_vcpu_state state;
     80   1.9  maxv 
     81   1.9  maxv 	/* Event. */
     82   1.9  maxv 	bool event_commit;
     83  1.11  maxv 	struct nvmm_vcpu_event event;
     84   1.9  maxv };
     85   1.9  maxv 
     86   1.8  maxv /*
     87   1.8  maxv  * Bits 20:27 -> machid
     88   1.8  maxv  * Bits 12:19 -> cpuid
     89   1.8  maxv  */
     90   1.8  maxv #define NVMM_COMM_OFF(machid, cpuid)	\
     91   1.8  maxv 	((((uint64_t)machid & 0xFFULL) << 20) | (((uint64_t)cpuid & 0xFFULL) << 12))
     92   1.8  maxv 
     93   1.8  maxv #define NVMM_COMM_MACHID(off)		\
     94   1.8  maxv 	((off >> 20) & 0xFF)
     95   1.8  maxv 
     96   1.8  maxv #define NVMM_COMM_CPUID(off)		\
     97   1.8  maxv 	((off >> 12) & 0xFF)
     98   1.8  maxv 
     99  1.14  maxv #ifdef _KERNEL
    100  1.14  maxv /* At most one page, for the NVMM_COMM_* macros. */
    101  1.14  maxv CTASSERT(sizeof(struct nvmm_comm_page) <= PAGE_SIZE);
    102  1.14  maxv #endif
    103  1.14  maxv 
    104   1.1  maxv #endif
    105