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