├── lib ├── stub │ └── libmirage-xen_bindings.a ├── xs.mli ├── time.ml ├── bindings │ ├── dune │ ├── Makefile │ ├── clock_stubs.c │ ├── include │ │ └── xen │ │ │ ├── arch-x86_32.h │ │ │ ├── arch-arm │ │ │ ├── hvm │ │ │ │ └── save.h │ │ │ └── smccc.h │ │ │ ├── device_tree_defs.h │ │ │ ├── hvm │ │ │ ├── e820.h │ │ │ ├── pvdrivers.h │ │ │ ├── hvm_info_table.h │ │ │ ├── hvm_vcpu.h │ │ │ ├── hvm_xs_strings.h │ │ │ ├── save.h │ │ │ └── ioreq.h │ │ │ ├── xencomm.h │ │ │ ├── COPYING │ │ │ ├── io │ │ │ ├── 9pfs.h │ │ │ ├── protocols.h │ │ │ ├── console.h │ │ │ ├── xenbus.h │ │ │ ├── libxenvchan.h │ │ │ ├── pciif.h │ │ │ ├── xs_wire.h │ │ │ ├── pvcalls.h │ │ │ ├── tpmif.h │ │ │ ├── fsif.h │ │ │ └── fbif.h │ │ │ ├── arch-x86_64.h │ │ │ ├── xen-compat.h │ │ │ ├── nmi.h │ │ │ ├── version.h │ │ │ ├── tmem.h │ │ │ ├── callback.h │ │ │ ├── dom0_ops.h │ │ │ ├── arch-x86 │ │ │ ├── cpuid.h │ │ │ ├── pmu.h │ │ │ └── xen-x86_32.h │ │ │ ├── features.h │ │ │ ├── xenoprof.h │ │ │ ├── errno.h │ │ │ ├── pmu.h │ │ │ └── xsm │ │ │ └── flask_op.h │ ├── bindings.h │ ├── main.c │ ├── hypercall-x86_64.h │ ├── hypercall.h │ └── bmap.c ├── xen_os.ml ├── device_state.mli ├── dune ├── main.mli ├── generation.ml ├── lifecycle.mli ├── lifecycle.ml ├── device_state.ml ├── eventchn.ml ├── memory.ml ├── main.ml ├── activations.mli ├── eventchn.mli ├── xs.ml └── activations.ml ├── dune-project ├── .gitignore ├── .ocamlformat ├── test ├── manifest.json ├── main.ml └── dune ├── README.md ├── LICENSE.md └── mirage-xen.opam /lib/stub/libmirage-xen_bindings.a: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/xs.mli: -------------------------------------------------------------------------------- 1 | include Xs_client_lwt.S 2 | -------------------------------------------------------------------------------- /dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 2.7) 2 | (name mirage-xen) 3 | -------------------------------------------------------------------------------- /lib/time.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirage/mirage-xen/HEAD/lib/time.ml -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | .*.swp 3 | *.install 4 | .merlin 5 | *.locked 6 | duniverse 7 | -------------------------------------------------------------------------------- /.ocamlformat: -------------------------------------------------------------------------------- 1 | version = 0.26.2 2 | profile = conventional 3 | 4 | parse-docstrings = true 5 | -------------------------------------------------------------------------------- /test/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "solo5.manifest", 3 | "version": 1, 4 | "devices": [] 5 | } -------------------------------------------------------------------------------- /lib/bindings/dune: -------------------------------------------------------------------------------- 1 | (rule 2 | (enabled_if 3 | (= %{context_name} solo5)) 4 | (deps 5 | (source_tree .)) 6 | (targets libmirage-xen_bindings.a) 7 | (action 8 | (no-infer 9 | (progn 10 | (run %{make}))))) 11 | -------------------------------------------------------------------------------- /lib/xen_os.ml: -------------------------------------------------------------------------------- 1 | module Activations = Activations 2 | module Device_state = Device_state 3 | module Eventchn = Eventchn 4 | module Generation = Generation 5 | module Lifecycle = Lifecycle 6 | module Main = Main 7 | module Memory = Memory 8 | module Xen = Xen 9 | module Xs = Xs 10 | -------------------------------------------------------------------------------- /test/main.ml: -------------------------------------------------------------------------------- 1 | let app () = 2 | let open Lwt.Syntax in 3 | Printf.printf "Hello!\n%!"; 4 | let* () = OS.Time.sleep_ns 1_000_000_000L in 5 | Printf.printf "After 1s\n%!"; 6 | let+ () = OS.Time.sleep_ns 1_000_000_000L in 7 | Printf.printf "After 2s\n%!" 8 | 9 | let () = OS.Main.run (app ()) 10 | -------------------------------------------------------------------------------- /lib/device_state.mli: -------------------------------------------------------------------------------- 1 | type state = 2 | | Unknown 3 | | Initialising 4 | | InitWait 5 | | Initialised 6 | | Connected 7 | | Closing 8 | | Closed 9 | | Reconfiguring 10 | | Reconfigured 11 | 12 | val of_string : string -> state 13 | val to_string : state -> string 14 | val prettyprint : state -> string 15 | -------------------------------------------------------------------------------- /lib/bindings/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean 2 | all: libmirage-xen_bindings.a 3 | 4 | CC=ocamlfind -toolchain solo5 ocamlopt 5 | CFLAGS=-ccopt "-I ./include/ -O2 -std=c99 -Wall -D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__" 6 | OBJS=bmap.o clock_stubs.o evtchn.o gnttab.o main.o 7 | 8 | libmirage-xen_bindings.a: $(OBJS) 9 | $(AR) r $@ $^ 10 | 11 | clean: 12 | $(RM) $(OBJS) libmirage-xen_bingings.a 13 | -------------------------------------------------------------------------------- /test/dune: -------------------------------------------------------------------------------- 1 | (executable 2 | (enabled_if 3 | (= %{context_name} solo5)) 4 | (name main) 5 | (link_flags -cclib "-z solo5-abi=xen") 6 | (libraries mirage-xen) 7 | (foreign_stubs 8 | (language c) 9 | (names manifest))) 10 | 11 | (rule 12 | (targets manifest.c) 13 | (enabled_if 14 | (= %{context_name} solo5)) 15 | (deps manifest.json) 16 | (action 17 | (run solo5-elftool gen-manifest manifest.json manifest.c))) 18 | 19 | (rule 20 | (alias runtest) 21 | (deps main.exe) 22 | (enabled_if 23 | (= %{context_name} solo5)) 24 | (action 25 | (run echo OK))) 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mirage-xen -- Xen core platform libraries for MirageOS 2 | 3 | This package provides the MirageOS `OS` library for 4 | Xen targets, which handles the main loop and timers. It also provides 5 | the low level C startup code and C stubs required by the OCaml code. 6 | 7 | [![Build Status](https://travis-ci.org/mirage/mirage-xen.svg)](https://travis-ci.org/mirage/mirage-xen) 8 | 9 | ## Development 10 | 11 | ``` 12 | $ git clone https://github.com/mirage/mirage-xen 13 | $ cd mirage-xen 14 | $ opam monorepo lock 15 | $ opam monorepo pull 16 | $ opam install ocaml-freestanding dune 17 | $ dune build 18 | ``` 19 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Permission to use, copy, modify, and distribute this software for any 2 | purpose with or without fee is hereby granted, provided that the above 3 | copyright notice and this permission notice appear in all copies. 4 | 5 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 6 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 7 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 8 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 9 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 10 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 11 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 12 | -------------------------------------------------------------------------------- /lib/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name xen_os) 3 | (public_name mirage-xen) 4 | (libraries lwt cstruct xenstore.client shared-memory-ring-lwt lwt-dllist 5 | logs io-page fmt mirage-runtime bheap duration metrics metrics-lwt 6 | mirage-sleep) 7 | (no_dynlink) 8 | (foreign_archives mirage-xen_bindings)) 9 | 10 | (rule 11 | (target libmirage-xen_bindings.a) 12 | (deps 13 | (:dep libmirage-xen_bindings.%{context_name}.a)) 14 | (action 15 | (copy %{dep} %{target}))) 16 | 17 | (rule 18 | (enabled_if 19 | (= %{context_name} solo5)) 20 | (target libmirage-xen_bindings.solo5.a) 21 | (action 22 | (copy bindings/libmirage-xen_bindings.a %{target}))) 23 | 24 | (rule 25 | (target libmirage-xen_bindings.default.a) 26 | (action 27 | (copy stub/libmirage-xen_bindings.a %{target}))) 28 | 29 | (include_subdirs unqualified) 30 | -------------------------------------------------------------------------------- /lib/main.mli: -------------------------------------------------------------------------------- 1 | (* 2 | * Copyright (c) 2010-2011 Anil Madhavapeddy 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | *) 16 | 17 | val run : unit Lwt.t -> unit 18 | -------------------------------------------------------------------------------- /lib/generation.ml: -------------------------------------------------------------------------------- 1 | (* Copyright (C) Citrix Inc 2 | * 3 | * Permission to use, copy, modify, and distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | *) 15 | 16 | exception Invalid 17 | 18 | type 'a t = { generation : int; value : 'a } 19 | 20 | let generation = ref 0 21 | let wrap x = { generation = !generation; value = x } 22 | let maybe t f d = if t.generation <> !generation then d else f t.value 23 | let extract t = t.value 24 | let resume () = incr generation 25 | -------------------------------------------------------------------------------- /lib/bindings/clock_stubs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Anil Madhavapeddy 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "solo5.h" 18 | 19 | #include 20 | 21 | #define CAML_NAME_SPACE 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | CAMLprim value 28 | caml_get_monotonic_time(value v_unit) 29 | { 30 | CAMLparam1(v_unit); 31 | CAMLreturn(caml_copy_int64(solo5_clock_monotonic())); 32 | } 33 | -------------------------------------------------------------------------------- /lib/lifecycle.mli: -------------------------------------------------------------------------------- 1 | (* 2 | * Copyright (c) 2015 Thomas Leonard 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | *) 16 | 17 | val await_shutdown_request : 18 | ?can_poweroff:bool -> 19 | ?can_reboot:bool -> 20 | unit -> 21 | [ `Poweroff | `Reboot ] Lwt.t 22 | (** [await_shutdown_request ()] is thread that resolves when the domain is asked 23 | to shut down. The optional [poweroff] (default:[true]) and [reboot] 24 | (default:[false]) arguments can be used to indicate which features the 25 | caller wants to advertise (however, you can still get a request for a mode 26 | you didn't claim to support). *) 27 | -------------------------------------------------------------------------------- /mirage-xen.opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "anil@recoil.org" 3 | authors: "The MirageOS team" 4 | homepage: "https://github.com/mirage/mirage-xen" 5 | bug-reports: "https://github.com/mirage/mirage-xen/issues/" 6 | dev-repo: "git+https://github.com/mirage/mirage-xen.git" 7 | doc: "https://mirage.github.io/mirage-xen/" 8 | license: "ISC" 9 | tags: ["org:mirage"] 10 | 11 | build: [ 12 | [ "dune" "subst" ] {dev} 13 | [ "dune" "build" "-p" name "-j" jobs ] 14 | ] 15 | depends: [ 16 | "ocaml" {>= "4.08.0"} 17 | "dune" {>= "2.7.0"} 18 | "cstruct" {>= "1.0.1"} 19 | "lwt" {>= "2.4.3"} 20 | "shared-memory-ring-lwt" 21 | "xenstore" {>= "1.2.5"} 22 | "lwt-dllist" 23 | "io-page" {>= "2.4.0"} 24 | "mirage-runtime" {>= "4.6.0"} 25 | "logs" 26 | "fmt" {>= "0.8.5"} 27 | "bheap" {>= "2.0.0"} 28 | "duration" 29 | "metrics" 30 | "metrics-lwt" {>= "0.2.0"} 31 | "mirage-sleep" {>= "4.0.0"} 32 | ] 33 | available: [ 34 | (arch = "x86_64" ) & 35 | (os = "linux" | os = "freebsd" | os = "openbsd") 36 | ] 37 | synopsis: "Xen core platform libraries for MirageOS" 38 | description: """ 39 | This package provides the MirageOS `OS` library for 40 | Xen targets, which handles the main loop and timers. It also provides 41 | the low level C startup code and C stubs required by the OCaml code. 42 | """ 43 | x-maintenance-intent: [ "(latest)" ] 44 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/arch-x86_32.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * arch-x86_32.h 3 | * 4 | * Guest OS interface to x86 32-bit Xen. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2004-2006, K A Fraser 25 | */ 26 | 27 | #include "arch-x86/xen.h" 28 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/arch-arm/hvm/save.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Structure definitions for HVM state that is held by Xen and must 3 | * be saved along with the domain's memory and device-model state. 4 | * 5 | * Copyright (c) 2012 Citrix Systems Ltd. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to 9 | * deal in the Software without restriction, including without limitation the 10 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11 | * sell copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __XEN_PUBLIC_HVM_SAVE_ARM_H__ 27 | #define __XEN_PUBLIC_HVM_SAVE_ARM_H__ 28 | 29 | #endif 30 | 31 | /* 32 | * Local variables: 33 | * mode: C 34 | * c-file-style: "BSD" 35 | * c-basic-offset: 4 36 | * tab-width: 4 37 | * indent-tabs-mode: nil 38 | * End: 39 | */ 40 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/device_tree_defs.h: -------------------------------------------------------------------------------- 1 | #ifndef __XEN_DEVICE_TREE_DEFS_H__ 2 | #define __XEN_DEVICE_TREE_DEFS_H__ 3 | 4 | #if defined(__XEN__) || defined(__XEN_TOOLS__) 5 | /* 6 | * The device tree compiler (DTC) is allocating the phandle from 1 to 7 | * onwards. Reserve a high value for the GIC phandle. 8 | */ 9 | #define GUEST_PHANDLE_GIC (65000) 10 | 11 | #define GUEST_ROOT_ADDRESS_CELLS 2 12 | #define GUEST_ROOT_SIZE_CELLS 2 13 | 14 | /** 15 | * IRQ line type. 16 | * 17 | * DT_IRQ_TYPE_NONE - default, unspecified type 18 | * DT_IRQ_TYPE_EDGE_RISING - rising edge triggered 19 | * DT_IRQ_TYPE_EDGE_FALLING - falling edge triggered 20 | * DT_IRQ_TYPE_EDGE_BOTH - rising and falling edge triggered 21 | * DT_IRQ_TYPE_LEVEL_HIGH - high level triggered 22 | * DT_IRQ_TYPE_LEVEL_LOW - low level triggered 23 | * DT_IRQ_TYPE_LEVEL_MASK - Mask to filter out the level bits 24 | * DT_IRQ_TYPE_SENSE_MASK - Mask for all the above bits 25 | * DT_IRQ_TYPE_INVALID - Use to initialize the type 26 | */ 27 | #define DT_IRQ_TYPE_NONE 0x00000000 28 | #define DT_IRQ_TYPE_EDGE_RISING 0x00000001 29 | #define DT_IRQ_TYPE_EDGE_FALLING 0x00000002 30 | #define DT_IRQ_TYPE_EDGE_BOTH \ 31 | (DT_IRQ_TYPE_EDGE_FALLING | DT_IRQ_TYPE_EDGE_RISING) 32 | #define DT_IRQ_TYPE_LEVEL_HIGH 0x00000004 33 | #define DT_IRQ_TYPE_LEVEL_LOW 0x00000008 34 | #define DT_IRQ_TYPE_LEVEL_MASK \ 35 | (DT_IRQ_TYPE_LEVEL_LOW | DT_IRQ_TYPE_LEVEL_HIGH) 36 | #define DT_IRQ_TYPE_SENSE_MASK 0x0000000f 37 | 38 | #define DT_IRQ_TYPE_INVALID 0x00000010 39 | 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/hvm/e820.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Permission is hereby granted, free of charge, to any person obtaining a copy 3 | * of this software and associated documentation files (the "Software"), to 4 | * deal in the Software without restriction, including without limitation the 5 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 6 | * sell copies of the Software, and to permit persons to whom the Software is 7 | * furnished to do so, subject to the following conditions: 8 | * 9 | * The above copyright notice and this permission notice shall be included in 10 | * all copies or substantial portions of the Software. 11 | * 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | * Copyright (c) 2006, Keir Fraser 21 | */ 22 | 23 | #ifndef __XEN_PUBLIC_HVM_E820_H__ 24 | #define __XEN_PUBLIC_HVM_E820_H__ 25 | 26 | #include "../xen.h" 27 | 28 | /* E820 location in HVM virtual address space. */ 29 | #define HVM_E820_PAGE 0x00090000 30 | #define HVM_E820_NR_OFFSET 0x000001E8 31 | #define HVM_E820_OFFSET 0x000002D0 32 | 33 | #define HVM_BELOW_4G_RAM_END 0xF0000000 34 | #define HVM_BELOW_4G_MMIO_START HVM_BELOW_4G_RAM_END 35 | #define HVM_BELOW_4G_MMIO_LENGTH ((xen_mk_ullong(1) << 32) - \ 36 | HVM_BELOW_4G_MMIO_START) 37 | 38 | #endif /* __XEN_PUBLIC_HVM_E820_H__ */ 39 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/xencomm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Permission is hereby granted, free of charge, to any person obtaining a copy 3 | * of this software and associated documentation files (the "Software"), to 4 | * deal in the Software without restriction, including without limitation the 5 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 6 | * sell copies of the Software, and to permit persons to whom the Software is 7 | * furnished to do so, subject to the following conditions: 8 | * 9 | * The above copyright notice and this permission notice shall be included in 10 | * all copies or substantial portions of the Software. 11 | * 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | * Copyright (C) IBM Corp. 2006 21 | */ 22 | 23 | #ifndef _XEN_XENCOMM_H_ 24 | #define _XEN_XENCOMM_H_ 25 | 26 | /* A xencomm descriptor is a scatter/gather list containing physical 27 | * addresses corresponding to a virtually contiguous memory area. The 28 | * hypervisor translates these physical addresses to machine addresses to copy 29 | * to and from the virtually contiguous area. 30 | */ 31 | 32 | #define XENCOMM_MAGIC 0x58434F4D /* 'XCOM' */ 33 | #define XENCOMM_INVALID (~0UL) 34 | 35 | struct xencomm_desc { 36 | uint32_t magic; 37 | uint32_t nr_addrs; /* the number of entries in address[] */ 38 | uint64_t address[0]; 39 | }; 40 | 41 | #endif /* _XEN_XENCOMM_H_ */ 42 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/COPYING: -------------------------------------------------------------------------------- 1 | XEN NOTICE 2 | ========== 3 | 4 | This copyright applies to all files within this subdirectory and its 5 | subdirectories: 6 | include/public/*.h 7 | include/public/hvm/*.h 8 | include/public/io/*.h 9 | 10 | The intention is that these files can be freely copied into the source 11 | tree of an operating system when porting that OS to run on Xen. Doing 12 | so does *not* cause the OS to become subject to the terms of the GPL. 13 | 14 | All other files in the Xen source distribution are covered by version 15 | 2 of the GNU General Public License except where explicitly stated 16 | otherwise within individual source files. 17 | 18 | -- Keir Fraser (on behalf of the Xen team) 19 | 20 | ===================================================================== 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy 23 | of this software and associated documentation files (the "Software"), to 24 | deal in the Software without restriction, including without limitation the 25 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 26 | sell copies of the Software, and to permit persons to whom the Software is 27 | furnished to do so, subject to the following conditions: 28 | 29 | The above copyright notice and this permission notice shall be included in 30 | all copies or substantial portions of the Software. 31 | 32 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 33 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 34 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 35 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 36 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 37 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 38 | DEALINGS IN THE SOFTWARE. 39 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/io/9pfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 9pfs.h -- Xen 9PFS transport 3 | * 4 | * Refer to docs/misc/9pfs.markdown for the specification 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (C) 2017 Stefano Stabellini 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_IO_9PFS_H__ 28 | #define __XEN_PUBLIC_IO_9PFS_H__ 29 | 30 | #include "../grant_table.h" 31 | #include "ring.h" 32 | 33 | /* 34 | * See docs/misc/9pfs.markdown in xen.git for the full specification: 35 | * https://xenbits.xen.org/docs/unstable/misc/9pfs.html 36 | */ 37 | DEFINE_XEN_FLEX_RING_AND_INTF(xen_9pfs); 38 | 39 | #endif 40 | 41 | /* 42 | * Local variables: 43 | * mode: C 44 | * c-file-style: "BSD" 45 | * c-basic-offset: 4 46 | * tab-width: 4 47 | * indent-tabs-mode: nil 48 | * End: 49 | */ 50 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/io/protocols.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * protocols.h 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * 22 | * Copyright (c) 2008, Keir Fraser 23 | */ 24 | 25 | #ifndef __XEN_PROTOCOLS_H__ 26 | #define __XEN_PROTOCOLS_H__ 27 | 28 | #define XEN_IO_PROTO_ABI_X86_32 "x86_32-abi" 29 | #define XEN_IO_PROTO_ABI_X86_64 "x86_64-abi" 30 | #define XEN_IO_PROTO_ABI_ARM "arm-abi" 31 | 32 | #if defined(__i386__) 33 | # define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_X86_32 34 | #elif defined(__x86_64__) 35 | # define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_X86_64 36 | #elif defined(__arm__) || defined(__aarch64__) 37 | # define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_ARM 38 | #else 39 | # error arch fixup needed here 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /lib/lifecycle.ml: -------------------------------------------------------------------------------- 1 | (* 2 | * Copyright (c) 2015 Thomas Leonard 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published 6 | * by the Free Software Foundation; version 2.1 only. with the special 7 | * exception on linking described in file LICENSE. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | *) 14 | 15 | open Lwt.Infix 16 | 17 | let xen_bool = function false -> "0" | true -> "1" 18 | 19 | let await_shutdown_request ?(can_poweroff = true) ?(can_reboot = false) () = 20 | Xs.make () >>= fun xs -> 21 | Lwt.catch 22 | (fun () -> 23 | Xs.immediate xs (fun h -> 24 | Xs.write h "control/feature-poweroff" (xen_bool can_poweroff) 25 | >>= fun () -> 26 | Xs.write h "control/feature-reboot" (xen_bool can_reboot))) 27 | (fun _ex -> 28 | print_endline "Note: cannot write Xen 'control' directory"; 29 | Lwt.return ()) 30 | >>= fun () -> 31 | Xs.wait xs (fun h -> 32 | Xs.read h "control/shutdown" >>= function 33 | | "poweroff" -> Lwt.return `Poweroff 34 | | "reboot" -> Lwt.return `Reboot 35 | | "suspend" | "" -> Lwt.fail Xs_protocol.Eagain 36 | | state -> 37 | (* The Xen documentation says: 38 | "The precise protocol is not yet documented." 39 | http://xenbits.xen.org/docs/unstable/misc/xenstore-paths.html 40 | *) 41 | Printf.printf "Unknown power state %S\n%!" state; 42 | Lwt.fail Xs_protocol.Eagain) 43 | >>= fun reason -> 44 | (* Ack request *) 45 | Xs.immediate xs (fun h -> Xs.write h "control/shutdown" "") >>= fun () -> 46 | Lwt.return reason 47 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/arch-x86_64.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * arch-x86_64.h 3 | * 4 | * Guest OS interface to x86 64-bit Xen. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2004-2006, K A Fraser 25 | */ 26 | 27 | #include "arch-x86/xen.h" 28 | 29 | /* 30 | * ` enum neg_errnoval 31 | * ` HYPERVISOR_set_callbacks(unsigned long event_selector, 32 | * ` unsigned long event_address, 33 | * ` unsigned long failsafe_selector, 34 | * ` unsigned long failsafe_address); 35 | * ` 36 | * Register for callbacks on events. When an event (from an event 37 | * channel) occurs, event_address is used as the value of eip. 38 | * 39 | * A similar callback occurs if the segment selectors are invalid. 40 | * failsafe_address is used as the value of eip. 41 | * 42 | * On x86_64, event_selector and failsafe_selector are ignored (???). 43 | */ 44 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/io/console.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * console.h 3 | * 4 | * Console I/O interface for Xen guest OSes. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2005, Keir Fraser 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_IO_CONSOLE_H__ 28 | #define __XEN_PUBLIC_IO_CONSOLE_H__ 29 | 30 | typedef uint32_t XENCONS_RING_IDX; 31 | 32 | #define MASK_XENCONS_IDX(idx, ring) ((idx) & (sizeof(ring)-1)) 33 | 34 | struct xencons_interface { 35 | char in[1024]; 36 | char out[2048]; 37 | XENCONS_RING_IDX in_cons, in_prod; 38 | XENCONS_RING_IDX out_cons, out_prod; 39 | }; 40 | 41 | #ifdef XEN_WANT_FLEX_CONSOLE_RING 42 | #include "ring.h" 43 | DEFINE_XEN_FLEX_RING(xencons); 44 | #endif 45 | 46 | #endif /* __XEN_PUBLIC_IO_CONSOLE_H__ */ 47 | 48 | /* 49 | * Local variables: 50 | * mode: C 51 | * c-file-style: "BSD" 52 | * c-basic-offset: 4 53 | * tab-width: 4 54 | * indent-tabs-mode: nil 55 | * End: 56 | */ 57 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/xen-compat.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * xen-compat.h 3 | * 4 | * Guest OS interface to Xen. Compatibility layer. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2006, Christian Limpach 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_XEN_COMPAT_H__ 28 | #define __XEN_PUBLIC_XEN_COMPAT_H__ 29 | 30 | #define __XEN_LATEST_INTERFACE_VERSION__ 0x00040d00 31 | 32 | #if defined(__XEN__) || defined(__XEN_TOOLS__) 33 | /* Xen is built with matching headers and implements the latest interface. */ 34 | #define __XEN_INTERFACE_VERSION__ __XEN_LATEST_INTERFACE_VERSION__ 35 | #elif !defined(__XEN_INTERFACE_VERSION__) 36 | /* Guests which do not specify a version get the legacy interface. */ 37 | #define __XEN_INTERFACE_VERSION__ 0x00000000 38 | #endif 39 | 40 | #if __XEN_INTERFACE_VERSION__ > __XEN_LATEST_INTERFACE_VERSION__ 41 | #error "These header files do not support the requested interface version." 42 | #endif 43 | 44 | #define COMPAT_FLEX_ARRAY_DIM XEN_FLEX_ARRAY_DIM 45 | 46 | #endif /* __XEN_PUBLIC_XEN_COMPAT_H__ */ 47 | -------------------------------------------------------------------------------- /lib/device_state.ml: -------------------------------------------------------------------------------- 1 | (* 2 | * Copyright (c) 2010 Anil Madhavapeddy 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | *) 16 | 17 | (* From include/xen/io/xenbus.h *) 18 | type state = 19 | | Unknown 20 | | Initialising 21 | | InitWait 22 | (* Finished early initialisation but waiting for information 23 | * from the peer or hotplug scripts. *) 24 | | Initialised (* Waiting for a connection from the peer *) 25 | | Connected 26 | | Closing (* Device is being closed due to an error or an unplug event *) 27 | | Closed 28 | | Reconfiguring (* The device is being reconfigured *) 29 | | Reconfigured 30 | 31 | let of_string = function 32 | | "0" -> Unknown 33 | | "1" -> Initialising 34 | | "2" -> InitWait 35 | | "3" -> Initialised 36 | | "4" -> Connected 37 | | "5" -> Closing 38 | | "6" -> Closed 39 | | "7" -> Reconfiguring 40 | | "8" -> Reconfigured 41 | | _ -> Unknown 42 | 43 | let to_string = function 44 | | Unknown -> "0" 45 | | Initialising -> "1" 46 | | InitWait -> "2" 47 | | Initialised -> "3" 48 | | Connected -> "4" 49 | | Closing -> "5" 50 | | Closed -> "6" 51 | | Reconfiguring -> "7" 52 | | Reconfigured -> "8" 53 | 54 | let prettyprint = function 55 | | Unknown -> "Unknown" 56 | | Initialising -> "Initialising" 57 | | InitWait -> "InitWait" 58 | | Initialised -> "Initalised" 59 | | Connected -> "Connected" 60 | | Closing -> "Closing" 61 | | Closed -> "Closed" 62 | | Reconfiguring -> "Reconfiguring" 63 | | Reconfigured -> "Reconfigured" 64 | -------------------------------------------------------------------------------- /lib/eventchn.ml: -------------------------------------------------------------------------------- 1 | (* 2 | * Copyright (C) 2006-2014 Citrix Inc. 3 | * Copyright (c) 2010 Anil Madhavapeddy 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | *) 17 | 18 | type handle = int 19 | 20 | let init () = 0 21 | let close _ = 0 22 | 23 | type t = int Generation.t 24 | 25 | external stub_bind_unbound_port : handle -> int -> int 26 | = "mirage_xen_evtchn_alloc_unbound" 27 | 28 | external stub_bind_interdomain : handle -> int -> int -> int 29 | = "mirage_xen_evtchn_bind_interdomain" 30 | 31 | external stub_unmask : handle -> int -> unit = "mirage_xen_evtchn_unmask" 32 | 33 | external stub_notify : handle -> int -> unit = "mirage_xen_evtchn_notify" 34 | [@@noalloc] 35 | 36 | external stub_unbind : handle -> int -> unit = "mirage_xen_evtchn_unbind" 37 | external stub_virq_dom_exc : unit -> int = "mirage_xen_evtchn_virq_dom_exc" 38 | external stub_bind_virq : handle -> int -> int = "mirage_xen_evtchn_bind_virq" 39 | 40 | let construct f x = Generation.wrap (f x) 41 | let bind_unbound_port h = construct (stub_bind_unbound_port h) 42 | 43 | let bind_interdomain h remote_domid = 44 | construct (stub_bind_interdomain h remote_domid) 45 | 46 | let maybe t f d = Generation.maybe t f d 47 | let unmask h t = maybe t (stub_unmask h) () 48 | let notify h t = maybe t (stub_notify h) () 49 | let unbind h t = maybe t (stub_unbind h) () 50 | let is_valid t = maybe t (fun _ -> true) false 51 | let of_int n = Generation.wrap n 52 | let to_int t = Generation.extract t 53 | 54 | let bind_dom_exc_virq h = 55 | let port = stub_bind_virq h (stub_virq_dom_exc ()) in 56 | construct (fun () -> port) () 57 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/hvm/pvdrivers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pvdrivers.h: Register of PV drivers product numbers. 3 | * Copyright (c) 2012, Citrix Systems Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef _XEN_PUBLIC_PVDRIVERS_H_ 25 | #define _XEN_PUBLIC_PVDRIVERS_H_ 26 | 27 | /* 28 | * This is the master registry of product numbers for 29 | * PV drivers. 30 | * If you need a new product number allocating, please 31 | * post to xen-devel@lists.xenproject.org. You should NOT use 32 | * a product number without allocating one. 33 | * If you maintain a separate versioning and distribution path 34 | * for PV drivers you should have a separate product number so 35 | * that your drivers can be separated from others. 36 | * 37 | * During development, you may use the product ID to 38 | * indicate a driver which is yet to be released. 39 | */ 40 | 41 | #define PVDRIVERS_PRODUCT_LIST(EACH) \ 42 | EACH("xensource-windows", 0x0001) /* Citrix */ \ 43 | EACH("gplpv-windows", 0x0002) /* James Harper */ \ 44 | EACH("linux", 0x0003) \ 45 | EACH("xenserver-windows-v7.0+", 0x0004) /* Citrix */ \ 46 | EACH("xenserver-windows-v7.2+", 0x0005) /* Citrix */ \ 47 | EACH("experimental", 0xffff) 48 | 49 | #endif /* _XEN_PUBLIC_PVDRIVERS_H_ */ 50 | -------------------------------------------------------------------------------- /lib/memory.ml: -------------------------------------------------------------------------------- 1 | (* 2 | * Copyright (c) 2020 Martin Lucina 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | *) 16 | 17 | external get_heap_words : unit -> int = "mirage_memory_get_heap_words" 18 | [@@noalloc] 19 | 20 | external get_live_words : unit -> int = "mirage_memory_get_live_words" 21 | [@@noalloc] 22 | 23 | external get_fast_live_words : unit -> int = "mirage_memory_get_fast_live_words" 24 | [@@noalloc] 25 | 26 | external get_stack_words : unit -> int = "mirage_memory_get_stack_words" 27 | [@@noalloc] 28 | 29 | external trim : unit -> unit = "mirage_trim_allocation" [@@noalloc] 30 | 31 | type stat = { 32 | heap_words : int; 33 | live_words : int; 34 | stack_words : int; 35 | free_words : int; 36 | } 37 | 38 | let stat () = 39 | let h = get_heap_words () in 40 | let l = get_live_words () in 41 | let s = get_stack_words () in 42 | { heap_words = h; live_words = l; stack_words = s; free_words = h - l - s } 43 | 44 | let quick_stat () = 45 | let h = get_heap_words () in 46 | let l = get_fast_live_words () in 47 | let s = get_stack_words () in 48 | { heap_words = h; live_words = l; stack_words = s; free_words = h - l - s } 49 | 50 | let metrics ?(quick = true) ~tags () = 51 | let open Metrics in 52 | let doc = "Memory counters" in 53 | let stat = if quick then quick_stat else stat in 54 | let data () = 55 | let stat = stat () in 56 | Data.v 57 | [ 58 | uint "memory heap words" stat.heap_words; 59 | uint "memory live words" stat.live_words; 60 | uint "memory stack words" stat.stack_words; 61 | uint "memory free words" stat.free_words; 62 | ] 63 | in 64 | Src.v ~doc ~tags ~data "memory" 65 | 66 | let () = Metrics_lwt.periodically (metrics ~tags:Metrics.Tags.[] ()) 67 | -------------------------------------------------------------------------------- /lib/main.ml: -------------------------------------------------------------------------------- 1 | (* Lightweight thread library for Objective Caml 2 | * http://www.ocsigen.org/lwt 3 | * Module Lwt_main 4 | * Copyright (C) 2009 Jérémie Dimino 5 | * Copyright (C) 2010 Anil Madhavapeddy 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, with linking exceptions; 10 | * either version 2.1 of the License, or (at your option) any later 11 | * version. See COPYING file for details. 12 | * 13 | * This program is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 21 | * 02111-1307, USA. 22 | *) 23 | 24 | external evtchn_block_domain : Time.t -> unit = "mirage_xen_evtchn_block_domain" 25 | [@@noalloc] 26 | 27 | external evtchn_demux_pending : unit -> bool = "mirage_xen_evtchn_demux_pending" 28 | [@@noalloc] 29 | 30 | let evtchn = Eventchn.init () 31 | 32 | (* Execute one iteration and register a callback function *) 33 | let run t = 34 | let rec aux () = 35 | Lwt.wakeup_paused (); 36 | Time.restart_threads Time.time; 37 | match Lwt.poll t with 38 | | Some () -> () 39 | | None -> 40 | if evtchn_demux_pending () then ( 41 | (* Some event channels have triggered, wake up threads 42 | * and continue without blocking. *) 43 | (* Call enter hooks. *) 44 | Mirage_runtime.run_enter_iter_hooks (); 45 | Activations.run evtchn; 46 | (* Call leave hooks. *) 47 | Mirage_runtime.run_leave_iter_hooks (); 48 | aux ()) 49 | else 50 | let timeout = 51 | if Lwt.paused_count () > 0 then 0L 52 | else 53 | match Time.select_next () with 54 | | None -> Int64.add (Time.time ()) (Duration.of_day 1) 55 | | Some tm -> tm 56 | in 57 | evtchn_block_domain timeout; 58 | aux () 59 | in 60 | aux () 61 | 62 | let () = 63 | at_exit (fun () -> 64 | Lwt.abandon_wakeups (); 65 | run (Mirage_runtime.run_exit_hooks ())) 66 | -------------------------------------------------------------------------------- /lib/activations.mli: -------------------------------------------------------------------------------- 1 | (* 2 | * Copyright (c) 2010-2011 Anil Madhavapeddy 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | *) 16 | 17 | (** Event channels handlers. *) 18 | 19 | type event 20 | (** identifies the an event notification received from xen *) 21 | 22 | val program_start : event 23 | (** represents an event which 'fired' when the program started *) 24 | 25 | val after : Eventchn.t -> event -> event Lwt.t 26 | (** [next channel event] blocks until the system receives an event newer than 27 | [event] on channel [channel]. If an event is received while we aren't 28 | looking then this will be remembered and the next call to [after] will 29 | immediately unblock. If the system is suspended and then resumed, all event 30 | channel bindings are invalidated and this function will fail with 31 | Generation.Invalid *) 32 | 33 | (** {2 Low level interface} *) 34 | 35 | val wait : Eventchn.t -> unit Lwt.t 36 | (** [wait evtchn] is a cancellable thread that will wake up when [evtchn] is 37 | notified. Cancel it if you are no longer interested in waiting on [evtchn]. 38 | Note that if the notification is sent before [wait] is called then the 39 | notification is lost. *) 40 | 41 | val run : Eventchn.handle -> unit 42 | (** [run ()] goes through the event mask and activate any events, potentially 43 | spawning new threads. This function is called by [Main.run]. Do not call it 44 | unless you know what you are doing. *) 45 | 46 | val resume : unit -> unit 47 | (** [resume] needs to be called after the unikernel is resumed. However, this 48 | function is automatically called by {!Sched.suspend}. Do NOT use it unless 49 | you know what you are doing. *) 50 | 51 | val dump : unit -> unit 52 | (** [dump ()] prints internal state to the console for debugging *) 53 | -------------------------------------------------------------------------------- /lib/eventchn.mli: -------------------------------------------------------------------------------- 1 | (* 2 | * Copyright (c) 2010 Anil Madhavapeddy 3 | * Copyright (c) 2013-2014 Citrix Inc 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | *) 17 | 18 | (** Event channels interface. *) 19 | 20 | type handle 21 | (** An initialised event channel interface. *) 22 | 23 | type t 24 | (** A local event channel. *) 25 | 26 | val to_int : t -> int 27 | (** [to_int evtchn] is the port number of [evtchn]. *) 28 | 29 | val of_int : int -> t 30 | (** [of_int n] is the [n]th event channel. *) 31 | 32 | val init : unit -> handle 33 | (** Return an initialised event channel interface. On error it will throw a 34 | Failure exception. *) 35 | 36 | val close : handle -> int 37 | (** Close an event channel interface and return the status code. *) 38 | 39 | val notify : handle -> t -> unit 40 | (** Notify the given event channel. On error it will throw a Failure exception. *) 41 | 42 | val bind_interdomain : handle -> int -> int -> t 43 | (** [bind_interdomain h domid remote_port] returns a local event channel 44 | connected to domid:remote_port. On error it will throw a Failure exception. *) 45 | 46 | val bind_unbound_port : handle -> int -> t 47 | (** [bind_unbound_port h remote_domid] returns a new event channel awaiting an 48 | interdomain connection from [remote_domid]. On error it will throw a Failure 49 | exception. *) 50 | 51 | val bind_dom_exc_virq : handle -> t 52 | (** Binds a local event channel to the VIRQ_DOM_EXC (domain exception VIRQ). On 53 | error it will throw a Failure exception. *) 54 | 55 | val unbind : handle -> t -> unit 56 | (** Unbinds the given event channel. On error it will throw a Failure exception. *) 57 | 58 | val unmask : handle -> t -> unit 59 | (** Unmasks the given event channel. On error it will throw a Failure exception. *) 60 | 61 | val is_valid : t -> bool 62 | (** [is_valid c] is true if [t] is bound. Bindings are invalidated after a 63 | domain resume. *) 64 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/arch-arm/smccc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * smccc.h 3 | * 4 | * SMC/HVC interface in accordance with SMC Calling Convention. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright 2017 (C) EPAM Systems 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_ARCH_ARM_SMCCC_H__ 28 | #define __XEN_PUBLIC_ARCH_ARM_SMCCC_H__ 29 | 30 | #include "public/xen.h" 31 | 32 | /* 33 | * Hypervisor Service version. 34 | * 35 | * We can't use XEN version here, because of SMCCC requirements: 36 | * Major revision should change every time SMC/HVC function is removed. 37 | * Minor revision should change every time SMC/HVC function is added. 38 | * So, it is SMCCC protocol revision code, not XEN version. 39 | * 40 | * Those values are subjected to change, when interface will be extended. 41 | */ 42 | #define XEN_SMCCC_MAJOR_REVISION 0 43 | #define XEN_SMCCC_MINOR_REVISION 1 44 | 45 | /* Hypervisor Service UID. Randomly generated with uuidgen. */ 46 | #define XEN_SMCCC_UID XEN_DEFINE_UUID(0xa71812dc, 0xc698, 0x4369, 0x9acf, \ 47 | 0x79, 0xd1, 0x8d, 0xde, 0xe6, 0x67) 48 | 49 | /* Standard Service Service Call version. */ 50 | #define SSSC_SMCCC_MAJOR_REVISION 0 51 | #define SSSC_SMCCC_MINOR_REVISION 1 52 | 53 | /* Standard Service Call UID. Randomly generated with uuidgen. */ 54 | #define SSSC_SMCCC_UID XEN_DEFINE_UUID(0xf863386f, 0x4b39, 0x4cbd, 0x9220,\ 55 | 0xce, 0x16, 0x41, 0xe5, 0x9f, 0x6f) 56 | 57 | #endif /* __XEN_PUBLIC_ARCH_ARM_SMCCC_H__ */ 58 | 59 | /* 60 | * Local variables: 61 | * mode: C 62 | * c-file-style: "BSD" 63 | * c-basic-offset: 4 64 | * indent-tabs-mode: nil 65 | * End:b 66 | */ 67 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/io/xenbus.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * xenbus.h 3 | * 4 | * Xenbus protocol details. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (C) 2005 XenSource Ltd. 25 | */ 26 | 27 | #ifndef _XEN_PUBLIC_IO_XENBUS_H 28 | #define _XEN_PUBLIC_IO_XENBUS_H 29 | 30 | /* 31 | * The state of either end of the Xenbus, i.e. the current communication 32 | * status of initialisation across the bus. States here imply nothing about 33 | * the state of the connection between the driver and the kernel's device 34 | * layers. 35 | */ 36 | enum xenbus_state { 37 | XenbusStateUnknown = 0, 38 | 39 | XenbusStateInitialising = 1, 40 | 41 | /* 42 | * InitWait: Finished early initialisation but waiting for information 43 | * from the peer or hotplug scripts. 44 | */ 45 | XenbusStateInitWait = 2, 46 | 47 | /* 48 | * Initialised: Waiting for a connection from the peer. 49 | */ 50 | XenbusStateInitialised = 3, 51 | 52 | XenbusStateConnected = 4, 53 | 54 | /* 55 | * Closing: The device is being closed due to an error or an unplug event. 56 | */ 57 | XenbusStateClosing = 5, 58 | 59 | XenbusStateClosed = 6, 60 | 61 | /* 62 | * Reconfiguring: The device is being reconfigured. 63 | */ 64 | XenbusStateReconfiguring = 7, 65 | 66 | XenbusStateReconfigured = 8 67 | }; 68 | typedef enum xenbus_state XenbusState; 69 | 70 | #endif /* _XEN_PUBLIC_IO_XENBUS_H */ 71 | 72 | /* 73 | * Local variables: 74 | * mode: C 75 | * c-file-style: "BSD" 76 | * c-basic-offset: 4 77 | * tab-width: 4 78 | * indent-tabs-mode: nil 79 | * End: 80 | */ 81 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/nmi.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * nmi.h 3 | * 4 | * NMI callback registration and reason codes. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2005, Keir Fraser 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_NMI_H__ 28 | #define __XEN_PUBLIC_NMI_H__ 29 | 30 | #include "xen.h" 31 | 32 | /* 33 | * NMI reason codes: 34 | * Currently these are x86-specific, stored in arch_shared_info.nmi_reason. 35 | */ 36 | /* I/O-check error reported via ISA port 0x61, bit 6. */ 37 | #define _XEN_NMIREASON_io_error 0 38 | #define XEN_NMIREASON_io_error (1UL << _XEN_NMIREASON_io_error) 39 | /* PCI SERR reported via ISA port 0x61, bit 7. */ 40 | #define _XEN_NMIREASON_pci_serr 1 41 | #define XEN_NMIREASON_pci_serr (1UL << _XEN_NMIREASON_pci_serr) 42 | #if __XEN_INTERFACE_VERSION__ < 0x00040300 /* legacy alias of the above */ 43 | /* Parity error reported via ISA port 0x61, bit 7. */ 44 | #define _XEN_NMIREASON_parity_error 1 45 | #define XEN_NMIREASON_parity_error (1UL << _XEN_NMIREASON_parity_error) 46 | #endif 47 | /* Unknown hardware-generated NMI. */ 48 | #define _XEN_NMIREASON_unknown 2 49 | #define XEN_NMIREASON_unknown (1UL << _XEN_NMIREASON_unknown) 50 | 51 | /* 52 | * long nmi_op(unsigned int cmd, void *arg) 53 | * NB. All ops return zero on success, else a negative error code. 54 | */ 55 | 56 | /* 57 | * Register NMI callback for this (calling) VCPU. Currently this only makes 58 | * sense for domain 0, vcpu 0. All other callers will be returned EINVAL. 59 | * arg == pointer to xennmi_callback structure. 60 | */ 61 | #define XENNMI_register_callback 0 62 | struct xennmi_callback { 63 | unsigned long handler_address; 64 | unsigned long pad; 65 | }; 66 | typedef struct xennmi_callback xennmi_callback_t; 67 | DEFINE_XEN_GUEST_HANDLE(xennmi_callback_t); 68 | 69 | /* 70 | * Deregister NMI callback for this (calling) VCPU. 71 | * arg == NULL. 72 | */ 73 | #define XENNMI_unregister_callback 1 74 | 75 | #endif /* __XEN_PUBLIC_NMI_H__ */ 76 | 77 | /* 78 | * Local variables: 79 | * mode: C 80 | * c-file-style: "BSD" 81 | * c-basic-offset: 4 82 | * tab-width: 4 83 | * indent-tabs-mode: nil 84 | * End: 85 | */ 86 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/hvm/hvm_info_table.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * hvm/hvm_info_table.h 3 | * 4 | * HVM parameter and information table, written into guest memory map. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2006, Keir Fraser 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_HVM_HVM_INFO_TABLE_H__ 28 | #define __XEN_PUBLIC_HVM_HVM_INFO_TABLE_H__ 29 | 30 | #define HVM_INFO_PFN 0x09F 31 | #define HVM_INFO_OFFSET 0x800 32 | #define HVM_INFO_PADDR ((HVM_INFO_PFN << 12) + HVM_INFO_OFFSET) 33 | 34 | /* Maximum we can support with current vLAPIC ID mapping. */ 35 | #define HVM_MAX_VCPUS 128 36 | 37 | /* 38 | * In some cases SMP HVM guests may require knowledge of Xen's idea of vCPU ids 39 | * for their vCPUs. For example, HYPERVISOR_vcpu_op and some EVTCHNOP_* 40 | * hypercalls take vcpu id as a parameter. It is valid for HVM guests to assume 41 | * that Xen's vCPU id always equals to ACPI (not APIC!) id in MADT table which 42 | * is always present for SMP guests. 43 | */ 44 | 45 | struct hvm_info_table { 46 | char signature[8]; /* "HVM INFO" */ 47 | uint32_t length; 48 | uint8_t checksum; 49 | 50 | /* Should firmware build APIC descriptors (APIC MADT / MP BIOS)? */ 51 | uint8_t apic_mode; 52 | 53 | /* How many CPUs does this domain have? */ 54 | uint32_t nr_vcpus; 55 | 56 | /* 57 | * MEMORY MAP provided by HVM domain builder. 58 | * Notes: 59 | * 1. page_to_phys(x) = x << 12 60 | * 2. If a field is zero, the corresponding range does not exist. 61 | */ 62 | /* 63 | * 0x0 to page_to_phys(low_mem_pgend)-1: 64 | * RAM below 4GB (except for VGA hole 0xA0000-0xBFFFF) 65 | */ 66 | uint32_t low_mem_pgend; 67 | /* 68 | * page_to_phys(reserved_mem_pgstart) to 0xFFFFFFFF: 69 | * Reserved for special memory mappings 70 | */ 71 | uint32_t reserved_mem_pgstart; 72 | /* 73 | * 0x100000000 to page_to_phys(high_mem_pgend)-1: 74 | * RAM above 4GB 75 | */ 76 | uint32_t high_mem_pgend; 77 | 78 | /* Bitmap of which CPUs are online at boot time. */ 79 | uint8_t vcpu_online[(HVM_MAX_VCPUS + 7)/8]; 80 | }; 81 | 82 | #endif /* __XEN_PUBLIC_HVM_HVM_INFO_TABLE_H__ */ 83 | -------------------------------------------------------------------------------- /lib/xs.ml: -------------------------------------------------------------------------------- 1 | (* 2 | * Copyright (C) 2006-2009 Citrix Systems Inc. 3 | * Copyright (C) 2010 Anil Madhavapeddy 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published 7 | * by the Free Software Foundation; version 2.1 only. with the special 8 | * exception on linking described in file LICENSE. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | *) 15 | 16 | open Lwt 17 | 18 | type page = 19 | (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t 20 | 21 | external mirage_xen_get_xenstore_evtchn : unit -> int 22 | = "mirage_xen_get_xenstore_evtchn" 23 | 24 | external mirage_xen_get_xenstore_page : unit -> page 25 | = "mirage_xen_get_xenstore_page" 26 | 27 | let get_xenstore_evtchn () = 28 | Eventchn.of_int @@ mirage_xen_get_xenstore_evtchn () 29 | 30 | let get_xenstore_page () = 31 | Cstruct.of_bigarray @@ mirage_xen_get_xenstore_page () 32 | 33 | (* Mirage transport for XenStore. *) 34 | module IO = struct 35 | type 'a t = 'a Lwt.t 36 | type channel = { mutable page : Cstruct.t; mutable evtchn : Eventchn.t } 37 | 38 | let return = Lwt.return 39 | let ( >>= ) = Lwt.bind 40 | 41 | exception Cannot_destroy 42 | 43 | let h = Eventchn.init () 44 | 45 | type backend = [ `unix | `xen ] 46 | 47 | let backend = `xen 48 | let singleton_client = ref None 49 | 50 | let create () = 51 | match !singleton_client with 52 | | Some x -> Lwt.return x 53 | | None -> 54 | let page = get_xenstore_page () in 55 | Xenstore_ring.Ring.init page; 56 | let evtchn = get_xenstore_evtchn () in 57 | Eventchn.unmask h evtchn; 58 | let c = { page; evtchn } in 59 | singleton_client := Some c; 60 | Lwt.return c 61 | 62 | let refresh () = 63 | match !singleton_client with 64 | | Some x -> 65 | x.page <- get_xenstore_page (); 66 | Xenstore_ring.Ring.init x.page; 67 | x.evtchn <- get_xenstore_evtchn (); 68 | Eventchn.unmask h x.evtchn 69 | | None -> () 70 | 71 | let destroy _ = 72 | Printf.printf 73 | "ERROR: It's not possible to destroy the default xenstore connection\n%!"; 74 | fail Cannot_destroy 75 | 76 | (* XXX: unify with ocaml-xenstore-xen/xen/lib/xs_transport_domain *) 77 | let read t buf ofs len = 78 | let rec loop event = 79 | let n = Xenstore_ring.Ring.Front.unsafe_read t.page buf ofs len in 80 | if n = 0 then Activations.after t.evtchn event >>= fun event -> loop event 81 | else ( 82 | Eventchn.notify h t.evtchn; 83 | return n) 84 | in 85 | loop Activations.program_start 86 | 87 | (* XXX: unify with ocaml-xenstore-xen/xen/lib/xs_transport_domain *) 88 | let write t buf ofs len = 89 | let rec loop event buf ofs len = 90 | let n = Xenstore_ring.Ring.Front.unsafe_write t.page buf ofs len in 91 | if n > 0 then Eventchn.notify h t.evtchn; 92 | if n < len then 93 | Activations.after t.evtchn event >>= fun event -> 94 | loop event buf (ofs + n) (len - n) 95 | else return () 96 | in 97 | loop Activations.program_start buf ofs len 98 | end 99 | 100 | include Xs_client_lwt.Client (IO) 101 | 102 | let resume client = 103 | IO.refresh (); 104 | resume client 105 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/version.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * version.h 3 | * 4 | * Xen version, type, and compile information. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2005, Nguyen Anh Quynh 25 | * Copyright (c) 2005, Keir Fraser 26 | */ 27 | 28 | #ifndef __XEN_PUBLIC_VERSION_H__ 29 | #define __XEN_PUBLIC_VERSION_H__ 30 | 31 | #include "xen.h" 32 | 33 | /* NB. All ops return zero on success, except XENVER_{version,pagesize} 34 | * XENVER_{version,pagesize,build_id} */ 35 | 36 | /* arg == NULL; returns major:minor (16:16). */ 37 | #define XENVER_version 0 38 | 39 | /* arg == xen_extraversion_t. */ 40 | #define XENVER_extraversion 1 41 | typedef char xen_extraversion_t[16]; 42 | #define XEN_EXTRAVERSION_LEN (sizeof(xen_extraversion_t)) 43 | 44 | /* arg == xen_compile_info_t. */ 45 | #define XENVER_compile_info 2 46 | struct xen_compile_info { 47 | char compiler[64]; 48 | char compile_by[16]; 49 | char compile_domain[32]; 50 | char compile_date[32]; 51 | }; 52 | typedef struct xen_compile_info xen_compile_info_t; 53 | 54 | #define XENVER_capabilities 3 55 | typedef char xen_capabilities_info_t[1024]; 56 | #define XEN_CAPABILITIES_INFO_LEN (sizeof(xen_capabilities_info_t)) 57 | 58 | #define XENVER_changeset 4 59 | typedef char xen_changeset_info_t[64]; 60 | #define XEN_CHANGESET_INFO_LEN (sizeof(xen_changeset_info_t)) 61 | 62 | #define XENVER_platform_parameters 5 63 | struct xen_platform_parameters { 64 | xen_ulong_t virt_start; 65 | }; 66 | typedef struct xen_platform_parameters xen_platform_parameters_t; 67 | 68 | #define XENVER_get_features 6 69 | struct xen_feature_info { 70 | unsigned int submap_idx; /* IN: which 32-bit submap to return */ 71 | uint32_t submap; /* OUT: 32-bit submap */ 72 | }; 73 | typedef struct xen_feature_info xen_feature_info_t; 74 | 75 | /* Declares the features reported by XENVER_get_features. */ 76 | #include "features.h" 77 | 78 | /* arg == NULL; returns host memory page size. */ 79 | #define XENVER_pagesize 7 80 | 81 | /* arg == xen_domain_handle_t. 82 | * 83 | * The toolstack fills it out for guest consumption. It is intended to hold 84 | * the UUID of the guest. 85 | */ 86 | #define XENVER_guest_handle 8 87 | 88 | #define XENVER_commandline 9 89 | typedef char xen_commandline_t[1024]; 90 | 91 | /* 92 | * Return value is the number of bytes written, or XEN_Exx on error. 93 | * Calling with empty parameter returns the size of build_id. 94 | */ 95 | #define XENVER_build_id 10 96 | struct xen_build_id { 97 | uint32_t len; /* IN: size of buf[]. */ 98 | unsigned char buf[XEN_FLEX_ARRAY_DIM]; 99 | /* OUT: Variable length buffer with build_id. */ 100 | }; 101 | typedef struct xen_build_id xen_build_id_t; 102 | 103 | #endif /* __XEN_PUBLIC_VERSION_H__ */ 104 | 105 | /* 106 | * Local variables: 107 | * mode: C 108 | * c-file-style: "BSD" 109 | * c-basic-offset: 4 110 | * tab-width: 4 111 | * indent-tabs-mode: nil 112 | * End: 113 | */ 114 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/io/libxenvchan.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @section AUTHORS 4 | * 5 | * Copyright (C) 2010 Rafal Wojtczuk 6 | * 7 | * Authors: 8 | * Rafal Wojtczuk 9 | * Daniel De Graaf 10 | * 11 | * @section LICENSE 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to 15 | * deal in the Software without restriction, including without limitation the 16 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 17 | * sell copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 29 | * DEALINGS IN THE SOFTWARE. 30 | * 31 | * @section DESCRIPTION 32 | * 33 | * Originally borrowed from the Qubes OS Project, http://www.qubes-os.org, 34 | * this code has been substantially rewritten to use the gntdev and gntalloc 35 | * devices instead of raw MFNs and map_foreign_range. 36 | * 37 | * This is a library for inter-domain communication. A standard Xen ring 38 | * buffer is used, with a datagram-based interface built on top. The grant 39 | * reference and event channels are shared in XenStore under a user-specified 40 | * path. 41 | * 42 | * The ring.h macros define an asymmetric interface to a shared data structure 43 | * that assumes all rings reside in a single contiguous memory space. This is 44 | * not suitable for vchan because the interface to the ring is symmetric except 45 | * for the setup. Unlike the producer-consumer rings defined in ring.h, the 46 | * size of the rings used in vchan are determined at execution time instead of 47 | * compile time, so the macros in ring.h cannot be used to access the rings. 48 | */ 49 | 50 | #include 51 | #include 52 | 53 | struct ring_shared { 54 | uint32_t cons, prod; 55 | }; 56 | 57 | #define VCHAN_NOTIFY_WRITE 0x1 58 | #define VCHAN_NOTIFY_READ 0x2 59 | 60 | /** 61 | * vchan_interface: primary shared data structure 62 | */ 63 | struct vchan_interface { 64 | /** 65 | * Standard consumer/producer interface, one pair per buffer 66 | * left is client write, server read 67 | * right is client read, server write 68 | */ 69 | struct ring_shared left, right; 70 | /** 71 | * size of the rings, which determines their location 72 | * 10 - at offset 1024 in ring's page 73 | * 11 - at offset 2048 in ring's page 74 | * 12+ - uses 2^(N-12) grants to describe the multi-page ring 75 | * These should remain constant once the page is shared. 76 | * Only one of the two orders can be 10 (or 11). 77 | */ 78 | uint16_t left_order, right_order; 79 | /** 80 | * Shutdown detection: 81 | * 0: client (or server) has exited 82 | * 1: client (or server) is connected 83 | * 2: client has not yet connected 84 | */ 85 | uint8_t cli_live, srv_live; 86 | /** 87 | * Notification bits: 88 | * VCHAN_NOTIFY_WRITE: send notify when data is written 89 | * VCHAN_NOTIFY_READ: send notify when data is read (consumed) 90 | * cli_notify is used for the client to inform the server of its action 91 | */ 92 | uint8_t cli_notify, srv_notify; 93 | /** 94 | * Grant list: ordering is left, right. Must not extend into actual ring 95 | * or grow beyond the end of the initial shared page. 96 | * These should remain constant once the page is shared, to allow 97 | * for possible remapping by a client that restarts. 98 | */ 99 | uint32_t grants[0]; 100 | }; 101 | 102 | -------------------------------------------------------------------------------- /lib/bindings/bindings.h: -------------------------------------------------------------------------------- 1 | #ifndef __XEN_BINDINGS_H__ 2 | #define __XEN_BINDINGS_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include "xen/xen.h" 8 | 9 | /* 10 | * Accessors for Xen shared_info and VCPU 0 info structures shared with 11 | * hypervisor. 12 | */ 13 | extern uint8_t solo5__xen_HYPERVISOR_SHARED_INFO[]; 14 | 15 | inline struct shared_info *SHARED_INFO(void) 16 | { 17 | return (struct shared_info *)&solo5__xen_HYPERVISOR_SHARED_INFO; 18 | } 19 | 20 | inline struct vcpu_info *VCPU0_INFO(void) 21 | { 22 | return &(SHARED_INFO()->vcpu_info[0]); 23 | } 24 | 25 | /* 26 | * Initialise grant table functionality; called from solo5_app_main(). 27 | */ 28 | void gnttab_init(void); 29 | 30 | /* 31 | * Low-level definitions specific to the x86_64 architecture. 32 | */ 33 | #if defined(__x86_64__) 34 | 35 | #define PAGE_SIZE 4096 36 | #define PAGE_SHIFT 12 37 | 38 | #define cpu_cli() __asm__ __volatile__("cli") 39 | #define cpu_sti() __asm__ __volatile__("sti") 40 | 41 | /* 42 | * "wait for interrupt". On x86, must be called with interrupts disabled for 43 | * this operation to be race-free. 44 | */ 45 | #define cpu_wfi() __asm__ __volatile__("sti; hlt") 46 | 47 | /* compiler-only memory "barrier" */ 48 | #define cc_barrier() __asm__ __volatile__("" : : : "memory") 49 | 50 | #define cpu_barrier() __asm__ __volatile__("mfence" : : : "memory") 51 | #define cpu_read_barrier() __asm__ __volatile__("lfence" : : : "memory") 52 | #define cpu_write_barrier() __asm__ __volatile__("sfence" : : : "memory") 53 | 54 | /* 55 | * Atomically test-and-set bit (nr) in (*bits). Fully synchronous. 56 | */ 57 | static inline bool atomic_sync_bts(int nr, volatile void *bits) 58 | { 59 | uint8_t *byte = ((uint8_t *)bits) + (nr >> 3); 60 | uint8_t bit = 1 << (nr & 7); 61 | uint8_t orig; 62 | 63 | orig = __atomic_fetch_or(byte, bit, __ATOMIC_SEQ_CST); 64 | return (orig & bit) != 0; 65 | } 66 | 67 | /* 68 | * Atomically test-and-clear bit (nr) in (*bits). Fully synchronous. 69 | */ 70 | static inline bool atomic_sync_btc(int nr, volatile void *bits) 71 | { 72 | uint8_t *byte = ((uint8_t *)bits) + (nr >> 3); 73 | uint8_t bit = 1 << (nr & 7); 74 | uint8_t orig; 75 | 76 | orig = __atomic_fetch_and(byte, ~bit, __ATOMIC_SEQ_CST); 77 | return (orig & bit) != 0; 78 | } 79 | 80 | /* 81 | * Test if bit (nr) in (*bits) is set. Fully synchronous. 82 | */ 83 | static inline bool sync_bt(int nr, const volatile void *bits) 84 | { 85 | const volatile uint8_t *byte = ((const volatile uint8_t *)bits) + (nr >> 3); 86 | uint8_t bit = 1 << (nr & 7); 87 | uint8_t result; 88 | 89 | result = ((bit & *byte) != 0); 90 | cc_barrier(); 91 | return result; 92 | } 93 | 94 | /* 95 | * Atomically exchange (*ptr) with val, storing the result in (*result). 96 | * Fully synchronous. 97 | */ 98 | static inline void atomic_sync_xchg(volatile unsigned long *ptr, 99 | unsigned long val, unsigned long *result) 100 | { 101 | __atomic_exchange(ptr, &val, result, __ATOMIC_SEQ_CST); 102 | } 103 | 104 | /* 105 | * Atomically compare the 16-bit word (*ptr) with (expected) and set (*ptr) to 106 | * (desired) if the comparison succeeds. Returns previous value. Fully 107 | * synchronous. 108 | */ 109 | static inline uint16_t atomic_sync_cmpxchgw(volatile uint16_t *ptr, 110 | uint16_t expected, uint16_t desired) 111 | { 112 | uint16_t prev = expected; 113 | (void)__atomic_compare_exchange_n(ptr, &prev, desired, 114 | false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); 115 | return prev; 116 | } 117 | 118 | #else /* __x86_64__ */ 119 | #error Not implemented 120 | #endif /* __x86_64__ */ 121 | 122 | /* 123 | * Accessor for retrieving guest-virtual memory range suitable for importing 124 | * grant mappings from Solo5. 125 | */ 126 | void solo5__xen_get_gntmap_area(uint64_t *addr, size_t *size); 127 | 128 | /* 129 | * Bitmap allocator for virtual memory used for importing grant mappings. 130 | */ 131 | struct bmap_allocator; 132 | typedef struct bmap_allocator bmap_allocator_t; 133 | 134 | bmap_allocator_t *bmap_init(uint64_t start_addr, size_t n_pages); 135 | void *bmap_alloc(bmap_allocator_t *alloc, size_t n); 136 | void bmap_free(bmap_allocator_t *alloc, void *addr, size_t n); 137 | 138 | #endif /* __XEN_BINDINGS_H__ */ 139 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/tmem.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * tmem.h 3 | * 4 | * Guest OS interface to Xen Transcendent Memory. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2004, K A Fraser 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_TMEM_H__ 28 | #define __XEN_PUBLIC_TMEM_H__ 29 | 30 | #include "xen.h" 31 | 32 | #if __XEN_INTERFACE_VERSION__ < 0x00041300 33 | 34 | /* version of ABI */ 35 | #define TMEM_SPEC_VERSION 1 36 | 37 | #define TMEM_NEW_POOL 1 38 | #define TMEM_DESTROY_POOL 2 39 | #define TMEM_PUT_PAGE 4 40 | #define TMEM_GET_PAGE 5 41 | #define TMEM_FLUSH_PAGE 6 42 | #define TMEM_FLUSH_OBJECT 7 43 | #if __XEN_INTERFACE_VERSION__ < 0x00040400 44 | #define TMEM_NEW_PAGE 3 45 | #define TMEM_READ 8 46 | #define TMEM_WRITE 9 47 | #define TMEM_XCHG 10 48 | #endif 49 | 50 | /* Privileged commands now called via XEN_SYSCTL_tmem_op. */ 51 | #define TMEM_AUTH 101 /* as XEN_SYSCTL_TMEM_OP_SET_AUTH. */ 52 | #define TMEM_RESTORE_NEW 102 /* as XEN_SYSCTL_TMEM_OP_SET_POOL. */ 53 | 54 | /* Bits for HYPERVISOR_tmem_op(TMEM_NEW_POOL) */ 55 | #define TMEM_POOL_PERSIST 1 56 | #define TMEM_POOL_SHARED 2 57 | #define TMEM_POOL_PRECOMPRESSED 4 58 | #define TMEM_POOL_PAGESIZE_SHIFT 4 59 | #define TMEM_POOL_PAGESIZE_MASK 0xf 60 | #define TMEM_POOL_VERSION_SHIFT 24 61 | #define TMEM_POOL_VERSION_MASK 0xff 62 | #define TMEM_POOL_RESERVED_BITS 0x00ffff00 63 | 64 | /* Bits for client flags (save/restore) */ 65 | #define TMEM_CLIENT_COMPRESS 1 66 | #define TMEM_CLIENT_FROZEN 2 67 | 68 | /* Special errno values */ 69 | #define EFROZEN 1000 70 | #define EEMPTY 1001 71 | 72 | struct xen_tmem_oid { 73 | uint64_t oid[3]; 74 | }; 75 | typedef struct xen_tmem_oid xen_tmem_oid_t; 76 | DEFINE_XEN_GUEST_HANDLE(xen_tmem_oid_t); 77 | 78 | #ifndef __ASSEMBLY__ 79 | #if __XEN_INTERFACE_VERSION__ < 0x00040400 80 | typedef xen_pfn_t tmem_cli_mfn_t; 81 | #endif 82 | typedef XEN_GUEST_HANDLE(char) tmem_cli_va_t; 83 | struct tmem_op { 84 | uint32_t cmd; 85 | int32_t pool_id; 86 | union { 87 | struct { 88 | uint64_t uuid[2]; 89 | uint32_t flags; 90 | uint32_t arg1; 91 | } creat; /* for cmd == TMEM_NEW_POOL. */ 92 | struct { 93 | #if __XEN_INTERFACE_VERSION__ < 0x00040600 94 | uint64_t oid[3]; 95 | #else 96 | xen_tmem_oid_t oid; 97 | #endif 98 | uint32_t index; 99 | uint32_t tmem_offset; 100 | uint32_t pfn_offset; 101 | uint32_t len; 102 | xen_pfn_t cmfn; /* client machine page frame */ 103 | } gen; /* for all other cmd ("generic") */ 104 | } u; 105 | }; 106 | typedef struct tmem_op tmem_op_t; 107 | DEFINE_XEN_GUEST_HANDLE(tmem_op_t); 108 | #endif 109 | 110 | #endif /* __XEN_INTERFACE_VERSION__ < 0x00041300 */ 111 | 112 | #endif /* __XEN_PUBLIC_TMEM_H__ */ 113 | 114 | /* 115 | * Local variables: 116 | * mode: C 117 | * c-file-style: "BSD" 118 | * c-basic-offset: 4 119 | * tab-width: 4 120 | * indent-tabs-mode: nil 121 | * End: 122 | */ 123 | -------------------------------------------------------------------------------- /lib/activations.ml: -------------------------------------------------------------------------------- 1 | (* 2 | * Copyright (c) 2010-2011 Anil Madhavapeddy 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | *) 16 | open Lwt.Infix 17 | 18 | external evtchn_get_nr_events : unit -> int = "mirage_xen_evtchn_get_nr_events" 19 | [@@noalloc] 20 | 21 | external evtchn_test_and_clear : int -> bool 22 | = "mirage_xen_evtchn_test_and_clear" 23 | [@@noalloc] 24 | 25 | let nr_events = evtchn_get_nr_events () 26 | let event_cb = Array.init nr_events (fun _ -> Lwt_dllist.create ()) 27 | 28 | (* The high-level interface creates one counter per event channel port. 29 | Every time the system receives a notification it increments the counter. 30 | Threads which have blocked elsewhere call 'after' which blocks until 31 | the stored counter is greater than the value they have already -- so 32 | if an event comes in between calls then it will not be lost. 33 | 34 | In the high-level interface it's almost impossible to miss an event. 35 | The only way you can miss is if you block while your port's counter 36 | wraps. Arguably if you have failed to notice 2bn (32-bit) wakeups then 37 | you have bigger problems. *) 38 | 39 | type event = int 40 | 41 | let program_start = min_int 42 | 43 | type port = { mutable counter : event; c : unit Lwt_condition.t } 44 | 45 | let ports = 46 | Array.init nr_events (fun _port -> 47 | { counter = program_start; c = Lwt_condition.create () }) 48 | 49 | let dump () = 50 | Printf.printf "Number of received event channel events:\n"; 51 | for i = 0 to nr_events - 1 do 52 | if ports.(i).counter <> program_start then 53 | Printf.printf "port %d: %d\n%!" i (ports.(i).counter - program_start) 54 | done 55 | 56 | let after evtchn counter = 57 | let port = Eventchn.to_int evtchn in 58 | let rec loop () = 59 | if ports.(port).counter <= counter && Eventchn.is_valid evtchn then 60 | Lwt_condition.wait ports.(port).c >>= fun () -> loop () 61 | else Lwt.return_unit 62 | in 63 | loop () >>= fun () -> 64 | if Eventchn.is_valid evtchn then Lwt.return ports.(port).counter 65 | else Lwt.fail Generation.Invalid 66 | 67 | (* Low-level interface *) 68 | 69 | (* Block waiting for an event to occur on a particular port. Note 70 | if the event came in when we weren't looking then it is lost and 71 | we will block forever. *) 72 | let wait evtchn = 73 | if Eventchn.is_valid evtchn then ( 74 | let port = Eventchn.to_int evtchn in 75 | let th, u = Lwt.task () in 76 | let node = Lwt_dllist.add_l u event_cb.(port) in 77 | Lwt.on_cancel th (fun _ -> Lwt_dllist.remove node); 78 | th) 79 | else ( 80 | Printf.printf "Activations.wait %d: Generation.Invalid\n%!" 81 | (Eventchn.to_int evtchn); 82 | Lwt.fail Generation.Invalid) 83 | 84 | (* Go through the event mask and activate any events, potentially spawning 85 | new threads *) 86 | let run _ = 87 | for port = 0 to nr_events - 1 do 88 | if evtchn_test_and_clear port then ( 89 | Lwt_dllist.iter_node_l 90 | (fun node -> 91 | let u = Lwt_dllist.get node in 92 | Lwt_dllist.remove node; 93 | Lwt.wakeup_later u ()) 94 | event_cb.(port); 95 | ports.(port).counter <- ports.(port).counter + 1; 96 | Lwt_condition.broadcast ports.(port).c ()) 97 | done 98 | 99 | (* Note, this should be run *after* Generation.resume *) 100 | let resume () = 101 | for port = 0 to nr_events - 1 do 102 | Lwt_dllist.iter_node_l 103 | (fun node -> 104 | let u = Lwt_dllist.get node in 105 | Lwt_dllist.remove node; 106 | Lwt.wakeup_later_exn u Generation.Invalid) 107 | event_cb.(port); 108 | Lwt_condition.broadcast ports.(port).c () 109 | done 110 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/io/pciif.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PCI Backend/Frontend Common Data Structures & Macros 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * 22 | * Author: Ryan Wilson 23 | */ 24 | #ifndef __XEN_PCI_COMMON_H__ 25 | #define __XEN_PCI_COMMON_H__ 26 | 27 | /* Be sure to bump this number if you change this file */ 28 | #define XEN_PCI_MAGIC "7" 29 | 30 | /* xen_pci_sharedinfo flags */ 31 | #define _XEN_PCIF_active (0) 32 | #define XEN_PCIF_active (1<<_XEN_PCIF_active) 33 | #define _XEN_PCIB_AERHANDLER (1) 34 | #define XEN_PCIB_AERHANDLER (1<<_XEN_PCIB_AERHANDLER) 35 | #define _XEN_PCIB_active (2) 36 | #define XEN_PCIB_active (1<<_XEN_PCIB_active) 37 | 38 | /* xen_pci_op commands */ 39 | #define XEN_PCI_OP_conf_read (0) 40 | #define XEN_PCI_OP_conf_write (1) 41 | #define XEN_PCI_OP_enable_msi (2) 42 | #define XEN_PCI_OP_disable_msi (3) 43 | #define XEN_PCI_OP_enable_msix (4) 44 | #define XEN_PCI_OP_disable_msix (5) 45 | #define XEN_PCI_OP_aer_detected (6) 46 | #define XEN_PCI_OP_aer_resume (7) 47 | #define XEN_PCI_OP_aer_mmio (8) 48 | #define XEN_PCI_OP_aer_slotreset (9) 49 | #define XEN_PCI_OP_enable_multi_msi (10) 50 | 51 | /* xen_pci_op error numbers */ 52 | #define XEN_PCI_ERR_success (0) 53 | #define XEN_PCI_ERR_dev_not_found (-1) 54 | #define XEN_PCI_ERR_invalid_offset (-2) 55 | #define XEN_PCI_ERR_access_denied (-3) 56 | #define XEN_PCI_ERR_not_implemented (-4) 57 | /* XEN_PCI_ERR_op_failed - backend failed to complete the operation */ 58 | #define XEN_PCI_ERR_op_failed (-5) 59 | 60 | /* 61 | * it should be PAGE_SIZE-sizeof(struct xen_pci_op))/sizeof(struct msix_entry)) 62 | * Should not exceed 128 63 | */ 64 | #define SH_INFO_MAX_VEC 128 65 | 66 | struct xen_msix_entry { 67 | uint16_t vector; 68 | uint16_t entry; 69 | }; 70 | struct xen_pci_op { 71 | /* IN: what action to perform: XEN_PCI_OP_* */ 72 | uint32_t cmd; 73 | 74 | /* OUT: will contain an error number (if any) from errno.h */ 75 | int32_t err; 76 | 77 | /* IN: which device to touch */ 78 | uint32_t domain; /* PCI Domain/Segment */ 79 | uint32_t bus; 80 | uint32_t devfn; 81 | 82 | /* IN: which configuration registers to touch */ 83 | int32_t offset; 84 | int32_t size; 85 | 86 | /* IN/OUT: Contains the result after a READ or the value to WRITE */ 87 | uint32_t value; 88 | /* IN: Contains extra infor for this operation */ 89 | uint32_t info; 90 | /*IN: param for msi-x */ 91 | struct xen_msix_entry msix_entries[SH_INFO_MAX_VEC]; 92 | }; 93 | 94 | /*used for pcie aer handling*/ 95 | struct xen_pcie_aer_op 96 | { 97 | 98 | /* IN: what action to perform: XEN_PCI_OP_* */ 99 | uint32_t cmd; 100 | /*IN/OUT: return aer_op result or carry error_detected state as input*/ 101 | int32_t err; 102 | 103 | /* IN: which device to touch */ 104 | uint32_t domain; /* PCI Domain/Segment*/ 105 | uint32_t bus; 106 | uint32_t devfn; 107 | }; 108 | struct xen_pci_sharedinfo { 109 | /* flags - XEN_PCIF_* */ 110 | uint32_t flags; 111 | struct xen_pci_op op; 112 | struct xen_pcie_aer_op aer_op; 113 | }; 114 | 115 | #endif /* __XEN_PCI_COMMON_H__ */ 116 | 117 | /* 118 | * Local variables: 119 | * mode: C 120 | * c-file-style: "BSD" 121 | * c-basic-offset: 4 122 | * tab-width: 4 123 | * indent-tabs-mode: nil 124 | * End: 125 | */ 126 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/callback.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * callback.h 3 | * 4 | * Register guest OS callbacks with Xen. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2006, Ian Campbell 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_CALLBACK_H__ 28 | #define __XEN_PUBLIC_CALLBACK_H__ 29 | 30 | #include "xen.h" 31 | 32 | /* 33 | * Prototype for this hypercall is: 34 | * long callback_op(int cmd, void *extra_args) 35 | * @cmd == CALLBACKOP_??? (callback operation). 36 | * @extra_args == Operation-specific extra arguments (NULL if none). 37 | */ 38 | 39 | /* x86: Callback for event delivery. */ 40 | #define CALLBACKTYPE_event 0 41 | 42 | /* x86: Failsafe callback when guest state cannot be restored by Xen. */ 43 | #define CALLBACKTYPE_failsafe 1 44 | 45 | /* x86/64 hypervisor: Syscall by 64-bit guest app ('64-on-64-on-64'). */ 46 | #define CALLBACKTYPE_syscall 2 47 | 48 | /* 49 | * x86/32 hypervisor: Only available on x86/32 when supervisor_mode_kernel 50 | * feature is enabled. Do not use this callback type in new code. 51 | */ 52 | #define CALLBACKTYPE_sysenter_deprecated 3 53 | 54 | /* x86: Callback for NMI delivery. */ 55 | #define CALLBACKTYPE_nmi 4 56 | 57 | /* 58 | * x86: sysenter is only available as follows: 59 | * - 32-bit hypervisor: with the supervisor_mode_kernel feature enabled 60 | * - 64-bit hypervisor: 32-bit guest applications on Intel CPUs 61 | * ('32-on-32-on-64', '32-on-64-on-64') 62 | * [nb. also 64-bit guest applications on Intel CPUs 63 | * ('64-on-64-on-64'), but syscall is preferred] 64 | */ 65 | #define CALLBACKTYPE_sysenter 5 66 | 67 | /* 68 | * x86/64 hypervisor: Syscall by 32-bit guest app on AMD CPUs 69 | * ('32-on-32-on-64', '32-on-64-on-64') 70 | */ 71 | #define CALLBACKTYPE_syscall32 7 72 | 73 | /* 74 | * Disable event deliver during callback? This flag is ignored for event and 75 | * NMI callbacks: event delivery is unconditionally disabled. 76 | */ 77 | #define _CALLBACKF_mask_events 0 78 | #define CALLBACKF_mask_events (1U << _CALLBACKF_mask_events) 79 | 80 | /* 81 | * Register a callback. 82 | */ 83 | #define CALLBACKOP_register 0 84 | struct callback_register { 85 | uint16_t type; 86 | uint16_t flags; 87 | xen_callback_t address; 88 | }; 89 | typedef struct callback_register callback_register_t; 90 | DEFINE_XEN_GUEST_HANDLE(callback_register_t); 91 | 92 | /* 93 | * Unregister a callback. 94 | * 95 | * Not all callbacks can be unregistered. -EINVAL will be returned if 96 | * you attempt to unregister such a callback. 97 | */ 98 | #define CALLBACKOP_unregister 1 99 | struct callback_unregister { 100 | uint16_t type; 101 | uint16_t _unused; 102 | }; 103 | typedef struct callback_unregister callback_unregister_t; 104 | DEFINE_XEN_GUEST_HANDLE(callback_unregister_t); 105 | 106 | #if __XEN_INTERFACE_VERSION__ < 0x00030207 107 | #undef CALLBACKTYPE_sysenter 108 | #define CALLBACKTYPE_sysenter CALLBACKTYPE_sysenter_deprecated 109 | #endif 110 | 111 | #endif /* __XEN_PUBLIC_CALLBACK_H__ */ 112 | 113 | /* 114 | * Local variables: 115 | * mode: C 116 | * c-file-style: "BSD" 117 | * c-basic-offset: 4 118 | * tab-width: 4 119 | * indent-tabs-mode: nil 120 | * End: 121 | */ 122 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/dom0_ops.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * dom0_ops.h 3 | * 4 | * Process command requests from domain-0 guest OS. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2002-2003, B Dragovic 25 | * Copyright (c) 2002-2006, K Fraser 26 | */ 27 | 28 | #ifndef __XEN_PUBLIC_DOM0_OPS_H__ 29 | #define __XEN_PUBLIC_DOM0_OPS_H__ 30 | 31 | #include "xen.h" 32 | #include "platform.h" 33 | 34 | #if __XEN_INTERFACE_VERSION__ >= 0x00030204 35 | #error "dom0_ops.h is a compatibility interface only" 36 | #endif 37 | 38 | #define DOM0_INTERFACE_VERSION XENPF_INTERFACE_VERSION 39 | 40 | #define DOM0_SETTIME XENPF_settime 41 | #define dom0_settime xenpf_settime 42 | #define dom0_settime_t xenpf_settime_t 43 | 44 | #define DOM0_ADD_MEMTYPE XENPF_add_memtype 45 | #define dom0_add_memtype xenpf_add_memtype 46 | #define dom0_add_memtype_t xenpf_add_memtype_t 47 | 48 | #define DOM0_DEL_MEMTYPE XENPF_del_memtype 49 | #define dom0_del_memtype xenpf_del_memtype 50 | #define dom0_del_memtype_t xenpf_del_memtype_t 51 | 52 | #define DOM0_READ_MEMTYPE XENPF_read_memtype 53 | #define dom0_read_memtype xenpf_read_memtype 54 | #define dom0_read_memtype_t xenpf_read_memtype_t 55 | 56 | #define DOM0_MICROCODE XENPF_microcode_update 57 | #define dom0_microcode xenpf_microcode_update 58 | #define dom0_microcode_t xenpf_microcode_update_t 59 | 60 | #define DOM0_PLATFORM_QUIRK XENPF_platform_quirk 61 | #define dom0_platform_quirk xenpf_platform_quirk 62 | #define dom0_platform_quirk_t xenpf_platform_quirk_t 63 | 64 | typedef uint64_t cpumap_t; 65 | 66 | /* Unsupported legacy operation -- defined for API compatibility. */ 67 | #define DOM0_MSR 15 68 | struct dom0_msr { 69 | /* IN variables. */ 70 | uint32_t write; 71 | cpumap_t cpu_mask; 72 | uint32_t msr; 73 | uint32_t in1; 74 | uint32_t in2; 75 | /* OUT variables. */ 76 | uint32_t out1; 77 | uint32_t out2; 78 | }; 79 | typedef struct dom0_msr dom0_msr_t; 80 | DEFINE_XEN_GUEST_HANDLE(dom0_msr_t); 81 | 82 | /* Unsupported legacy operation -- defined for API compatibility. */ 83 | #define DOM0_PHYSICAL_MEMORY_MAP 40 84 | struct dom0_memory_map_entry { 85 | uint64_t start, end; 86 | uint32_t flags; /* reserved */ 87 | uint8_t is_ram; 88 | }; 89 | typedef struct dom0_memory_map_entry dom0_memory_map_entry_t; 90 | DEFINE_XEN_GUEST_HANDLE(dom0_memory_map_entry_t); 91 | 92 | struct dom0_op { 93 | uint32_t cmd; 94 | uint32_t interface_version; /* DOM0_INTERFACE_VERSION */ 95 | union { 96 | struct dom0_msr msr; 97 | struct dom0_settime settime; 98 | struct dom0_add_memtype add_memtype; 99 | struct dom0_del_memtype del_memtype; 100 | struct dom0_read_memtype read_memtype; 101 | struct dom0_microcode microcode; 102 | struct dom0_platform_quirk platform_quirk; 103 | struct dom0_memory_map_entry physical_memory_map; 104 | uint8_t pad[128]; 105 | } u; 106 | }; 107 | typedef struct dom0_op dom0_op_t; 108 | DEFINE_XEN_GUEST_HANDLE(dom0_op_t); 109 | 110 | #endif /* __XEN_PUBLIC_DOM0_OPS_H__ */ 111 | 112 | /* 113 | * Local variables: 114 | * mode: C 115 | * c-file-style: "BSD" 116 | * c-basic-offset: 4 117 | * tab-width: 4 118 | * indent-tabs-mode: nil 119 | * End: 120 | */ 121 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/hvm/hvm_vcpu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Permission is hereby granted, free of charge, to any person obtaining a copy 3 | * of this software and associated documentation files (the "Software"), to 4 | * deal in the Software without restriction, including without limitation the 5 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 6 | * sell copies of the Software, and to permit persons to whom the Software is 7 | * furnished to do so, subject to the following conditions: 8 | * 9 | * The above copyright notice and this permission notice shall be included in 10 | * all copies or substantial portions of the Software. 11 | * 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | * Copyright (c) 2015, Roger Pau Monne 21 | */ 22 | 23 | #ifndef __XEN_PUBLIC_HVM_HVM_VCPU_H__ 24 | #define __XEN_PUBLIC_HVM_HVM_VCPU_H__ 25 | 26 | #include "../xen.h" 27 | 28 | struct vcpu_hvm_x86_32 { 29 | uint32_t eax; 30 | uint32_t ecx; 31 | uint32_t edx; 32 | uint32_t ebx; 33 | uint32_t esp; 34 | uint32_t ebp; 35 | uint32_t esi; 36 | uint32_t edi; 37 | uint32_t eip; 38 | uint32_t eflags; 39 | 40 | uint32_t cr0; 41 | uint32_t cr3; 42 | uint32_t cr4; 43 | 44 | uint32_t pad1; 45 | 46 | /* 47 | * EFER should only be used to set the NXE bit (if required) 48 | * when starting a vCPU in 32bit mode with paging enabled or 49 | * to set the LME/LMA bits in order to start the vCPU in 50 | * compatibility mode. 51 | */ 52 | uint64_t efer; 53 | 54 | uint32_t cs_base; 55 | uint32_t ds_base; 56 | uint32_t ss_base; 57 | uint32_t es_base; 58 | uint32_t tr_base; 59 | uint32_t cs_limit; 60 | uint32_t ds_limit; 61 | uint32_t ss_limit; 62 | uint32_t es_limit; 63 | uint32_t tr_limit; 64 | uint16_t cs_ar; 65 | uint16_t ds_ar; 66 | uint16_t ss_ar; 67 | uint16_t es_ar; 68 | uint16_t tr_ar; 69 | 70 | uint16_t pad2[3]; 71 | }; 72 | 73 | /* 74 | * The layout of the _ar fields of the segment registers is the 75 | * following: 76 | * 77 | * Bits [0,3]: type (bits 40-43). 78 | * Bit 4: s (descriptor type, bit 44). 79 | * Bit [5,6]: dpl (descriptor privilege level, bits 45-46). 80 | * Bit 7: p (segment-present, bit 47). 81 | * Bit 8: avl (available for system software, bit 52). 82 | * Bit 9: l (64-bit code segment, bit 53). 83 | * Bit 10: db (meaning depends on the segment, bit 54). 84 | * Bit 11: g (granularity, bit 55) 85 | * Bits [12,15]: unused, must be blank. 86 | * 87 | * A more complete description of the meaning of this fields can be 88 | * obtained from the Intel SDM, Volume 3, section 3.4.5. 89 | */ 90 | 91 | struct vcpu_hvm_x86_64 { 92 | uint64_t rax; 93 | uint64_t rcx; 94 | uint64_t rdx; 95 | uint64_t rbx; 96 | uint64_t rsp; 97 | uint64_t rbp; 98 | uint64_t rsi; 99 | uint64_t rdi; 100 | uint64_t rip; 101 | uint64_t rflags; 102 | 103 | uint64_t cr0; 104 | uint64_t cr3; 105 | uint64_t cr4; 106 | uint64_t efer; 107 | 108 | /* 109 | * Using VCPU_HVM_MODE_64B implies that the vCPU is launched 110 | * directly in long mode, so the cached parts of the segment 111 | * registers get set to match that environment. 112 | * 113 | * If the user wants to launch the vCPU in compatibility mode 114 | * the 32-bit structure should be used instead. 115 | */ 116 | }; 117 | 118 | struct vcpu_hvm_context { 119 | #define VCPU_HVM_MODE_32B 0 /* 32bit fields of the structure will be used. */ 120 | #define VCPU_HVM_MODE_64B 1 /* 64bit fields of the structure will be used. */ 121 | uint32_t mode; 122 | 123 | uint32_t pad; 124 | 125 | /* CPU registers. */ 126 | union { 127 | struct vcpu_hvm_x86_32 x86_32; 128 | struct vcpu_hvm_x86_64 x86_64; 129 | } cpu_regs; 130 | }; 131 | typedef struct vcpu_hvm_context vcpu_hvm_context_t; 132 | DEFINE_XEN_GUEST_HANDLE(vcpu_hvm_context_t); 133 | 134 | #endif /* __XEN_PUBLIC_HVM_HVM_VCPU_H__ */ 135 | 136 | /* 137 | * Local variables: 138 | * mode: C 139 | * c-file-style: "BSD" 140 | * c-basic-offset: 4 141 | * tab-width: 4 142 | * indent-tabs-mode: nil 143 | * End: 144 | */ 145 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/hvm/hvm_xs_strings.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * hvm/hvm_xs_strings.h 3 | * 4 | * HVM xenstore strings used in HVMLOADER. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2013, Citrix Systems 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_HVM_HVM_XS_STRINGS_H__ 28 | #define __XEN_PUBLIC_HVM_HVM_XS_STRINGS_H__ 29 | 30 | #define HVM_XS_HVMLOADER "hvmloader" 31 | #define HVM_XS_BIOS "hvmloader/bios" 32 | #define HVM_XS_GENERATION_ID_ADDRESS "hvmloader/generation-id-address" 33 | #define HVM_XS_ALLOW_MEMORY_RELOCATE "hvmloader/allow-memory-relocate" 34 | 35 | /* The following values allow additional ACPI tables to be added to the 36 | * virtual ACPI BIOS that hvmloader constructs. The values specify the guest 37 | * physical address and length of a block of ACPI tables to add. The format of 38 | * the block is simply concatenated raw tables (which specify their own length 39 | * in the ACPI header). 40 | */ 41 | #define HVM_XS_ACPI_PT_ADDRESS "hvmloader/acpi/address" 42 | #define HVM_XS_ACPI_PT_LENGTH "hvmloader/acpi/length" 43 | 44 | /* Any number of SMBIOS types can be passed through to an HVM guest using 45 | * the following xenstore values. The values specify the guest physical 46 | * address and length of a block of SMBIOS structures for hvmloader to use. 47 | * The block is formatted in the following way: 48 | * 49 | * ... 50 | * 51 | * Each length separator is a 32b integer indicating the length of the next 52 | * SMBIOS structure. For DMTF defined types (0 - 121), the passed in struct 53 | * will replace the default structure in hvmloader. In addition, any 54 | * OEM/vendortypes (128 - 255) will all be added. 55 | */ 56 | #define HVM_XS_SMBIOS_PT_ADDRESS "hvmloader/smbios/address" 57 | #define HVM_XS_SMBIOS_PT_LENGTH "hvmloader/smbios/length" 58 | 59 | /* Set to 1 to enable SMBIOS default portable battery (type 22) values. */ 60 | #define HVM_XS_SMBIOS_DEFAULT_BATTERY "hvmloader/smbios/default_battery" 61 | 62 | /* The following xenstore values are used to override some of the default 63 | * string values in the SMBIOS table constructed in hvmloader. 64 | */ 65 | #define HVM_XS_BIOS_STRINGS "bios-strings" 66 | #define HVM_XS_BIOS_VENDOR "bios-strings/bios-vendor" 67 | #define HVM_XS_BIOS_VERSION "bios-strings/bios-version" 68 | #define HVM_XS_SYSTEM_MANUFACTURER "bios-strings/system-manufacturer" 69 | #define HVM_XS_SYSTEM_PRODUCT_NAME "bios-strings/system-product-name" 70 | #define HVM_XS_SYSTEM_VERSION "bios-strings/system-version" 71 | #define HVM_XS_SYSTEM_SERIAL_NUMBER "bios-strings/system-serial-number" 72 | #define HVM_XS_BASEBOARD_MANUFACTURER "bios-strings/baseboard-manufacturer" 73 | #define HVM_XS_BASEBOARD_PRODUCT_NAME "bios-strings/baseboard-product-name" 74 | #define HVM_XS_BASEBOARD_VERSION "bios-strings/baseboard-version" 75 | #define HVM_XS_BASEBOARD_SERIAL_NUMBER "bios-strings/baseboard-serial-number" 76 | #define HVM_XS_BASEBOARD_ASSET_TAG "bios-strings/baseboard-asset-tag" 77 | #define HVM_XS_BASEBOARD_LOCATION_IN_CHASSIS "bios-strings/baseboard-location-in-chassis" 78 | #define HVM_XS_ENCLOSURE_MANUFACTURER "bios-strings/enclosure-manufacturer" 79 | #define HVM_XS_ENCLOSURE_SERIAL_NUMBER "bios-strings/enclosure-serial-number" 80 | #define HVM_XS_ENCLOSURE_ASSET_TAG "bios-strings/enclosure-asset-tag" 81 | #define HVM_XS_BATTERY_MANUFACTURER "bios-strings/battery-manufacturer" 82 | #define HVM_XS_BATTERY_DEVICE_NAME "bios-strings/battery-device-name" 83 | 84 | /* 1 to 99 OEM strings can be set in xenstore using values of the form 85 | * below. These strings will be loaded into the SMBIOS type 11 structure. 86 | */ 87 | #define HVM_XS_OEM_STRINGS "bios-strings/oem-%d" 88 | 89 | #endif /* __XEN_PUBLIC_HVM_HVM_XS_STRINGS_H__ */ 90 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/io/xs_wire.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Details of the "wire" protocol between Xen Store Daemon and client 3 | * library or guest kernel. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | * 23 | * Copyright (C) 2005 Rusty Russell IBM Corporation 24 | */ 25 | 26 | #ifndef _XS_WIRE_H 27 | #define _XS_WIRE_H 28 | 29 | enum xsd_sockmsg_type 30 | { 31 | XS_CONTROL, 32 | #define XS_DEBUG XS_CONTROL 33 | XS_DIRECTORY, 34 | XS_READ, 35 | XS_GET_PERMS, 36 | XS_WATCH, 37 | XS_UNWATCH, 38 | XS_TRANSACTION_START, 39 | XS_TRANSACTION_END, 40 | XS_INTRODUCE, 41 | XS_RELEASE, 42 | XS_GET_DOMAIN_PATH, 43 | XS_WRITE, 44 | XS_MKDIR, 45 | XS_RM, 46 | XS_SET_PERMS, 47 | XS_WATCH_EVENT, 48 | XS_ERROR, 49 | XS_IS_DOMAIN_INTRODUCED, 50 | XS_RESUME, 51 | XS_SET_TARGET, 52 | /* XS_RESTRICT has been removed */ 53 | XS_RESET_WATCHES = XS_SET_TARGET + 2, 54 | XS_DIRECTORY_PART, 55 | 56 | XS_TYPE_COUNT, /* Number of valid types. */ 57 | 58 | XS_INVALID = 0xffff /* Guaranteed to remain an invalid type */ 59 | }; 60 | 61 | #define XS_WRITE_NONE "NONE" 62 | #define XS_WRITE_CREATE "CREATE" 63 | #define XS_WRITE_CREATE_EXCL "CREATE|EXCL" 64 | 65 | /* We hand errors as strings, for portability. */ 66 | struct xsd_errors 67 | { 68 | int errnum; 69 | const char *errstring; 70 | }; 71 | #ifdef EINVAL 72 | #define XSD_ERROR(x) { x, #x } 73 | /* LINTED: static unused */ 74 | static struct xsd_errors xsd_errors[] 75 | #if defined(__GNUC__) 76 | __attribute__((unused)) 77 | #endif 78 | = { 79 | XSD_ERROR(EINVAL), 80 | XSD_ERROR(EACCES), 81 | XSD_ERROR(EEXIST), 82 | XSD_ERROR(EISDIR), 83 | XSD_ERROR(ENOENT), 84 | XSD_ERROR(ENOMEM), 85 | XSD_ERROR(ENOSPC), 86 | XSD_ERROR(EIO), 87 | XSD_ERROR(ENOTEMPTY), 88 | XSD_ERROR(ENOSYS), 89 | XSD_ERROR(EROFS), 90 | XSD_ERROR(EBUSY), 91 | XSD_ERROR(EAGAIN), 92 | XSD_ERROR(EISCONN), 93 | XSD_ERROR(E2BIG) 94 | }; 95 | #endif 96 | 97 | struct xsd_sockmsg 98 | { 99 | uint32_t type; /* XS_??? */ 100 | uint32_t req_id;/* Request identifier, echoed in daemon's response. */ 101 | uint32_t tx_id; /* Transaction id (0 if not related to a transaction). */ 102 | uint32_t len; /* Length of data following this. */ 103 | 104 | /* Generally followed by nul-terminated string(s). */ 105 | }; 106 | 107 | enum xs_watch_type 108 | { 109 | XS_WATCH_PATH = 0, 110 | XS_WATCH_TOKEN 111 | }; 112 | 113 | /* 114 | * `incontents 150 xenstore_struct XenStore wire protocol. 115 | * 116 | * Inter-domain shared memory communications. */ 117 | #define XENSTORE_RING_SIZE 1024 118 | typedef uint32_t XENSTORE_RING_IDX; 119 | #define MASK_XENSTORE_IDX(idx) ((idx) & (XENSTORE_RING_SIZE-1)) 120 | struct xenstore_domain_interface { 121 | char req[XENSTORE_RING_SIZE]; /* Requests to xenstore daemon. */ 122 | char rsp[XENSTORE_RING_SIZE]; /* Replies and async watch events. */ 123 | XENSTORE_RING_IDX req_cons, req_prod; 124 | XENSTORE_RING_IDX rsp_cons, rsp_prod; 125 | uint32_t server_features; /* Bitmap of features supported by the server */ 126 | uint32_t connection; 127 | }; 128 | 129 | /* Violating this is very bad. See docs/misc/xenstore.txt. */ 130 | #define XENSTORE_PAYLOAD_MAX 4096 131 | 132 | /* Violating these just gets you an error back */ 133 | #define XENSTORE_ABS_PATH_MAX 3072 134 | #define XENSTORE_REL_PATH_MAX 2048 135 | 136 | /* The ability to reconnect a ring */ 137 | #define XENSTORE_SERVER_FEATURE_RECONNECTION 1 138 | 139 | /* Valid values for the connection field */ 140 | #define XENSTORE_CONNECTED 0 /* the steady-state */ 141 | #define XENSTORE_RECONNECT 1 /* guest has initiated a reconnect */ 142 | 143 | #endif /* _XS_WIRE_H */ 144 | 145 | /* 146 | * Local variables: 147 | * mode: C 148 | * c-file-style: "BSD" 149 | * c-basic-offset: 4 150 | * tab-width: 4 151 | * indent-tabs-mode: nil 152 | * End: 153 | */ 154 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/arch-x86/cpuid.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * arch-x86/cpuid.h 3 | * 4 | * CPUID interface to Xen. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2007 Citrix Systems, Inc. 25 | * 26 | * Authors: 27 | * Keir Fraser 28 | */ 29 | 30 | #ifndef __XEN_PUBLIC_ARCH_X86_CPUID_H__ 31 | #define __XEN_PUBLIC_ARCH_X86_CPUID_H__ 32 | 33 | /* 34 | * For compatibility with other hypervisor interfaces, the Xen cpuid leaves 35 | * can be found at the first otherwise unused 0x100 aligned boundary starting 36 | * from 0x40000000. 37 | * 38 | * e.g If viridian extensions are enabled for an HVM domain, the Xen cpuid 39 | * leaves will start at 0x40000100 40 | */ 41 | 42 | #define XEN_CPUID_FIRST_LEAF 0x40000000 43 | #define XEN_CPUID_LEAF(i) (XEN_CPUID_FIRST_LEAF + (i)) 44 | 45 | /* 46 | * Leaf 1 (0x40000x00) 47 | * EAX: Largest Xen-information leaf. All leaves up to an including @EAX 48 | * are supported by the Xen host. 49 | * EBX-EDX: "XenVMMXenVMM" signature, allowing positive identification 50 | * of a Xen host. 51 | */ 52 | #define XEN_CPUID_SIGNATURE_EBX 0x566e6558 /* "XenV" */ 53 | #define XEN_CPUID_SIGNATURE_ECX 0x65584d4d /* "MMXe" */ 54 | #define XEN_CPUID_SIGNATURE_EDX 0x4d4d566e /* "nVMM" */ 55 | 56 | /* 57 | * Leaf 2 (0x40000x01) 58 | * EAX[31:16]: Xen major version. 59 | * EAX[15: 0]: Xen minor version. 60 | * EBX-EDX: Reserved (currently all zeroes). 61 | */ 62 | 63 | /* 64 | * Leaf 3 (0x40000x02) 65 | * EAX: Number of hypercall transfer pages. This register is always guaranteed 66 | * to specify one hypercall page. 67 | * EBX: Base address of Xen-specific MSRs. 68 | * ECX: Features 1. Unused bits are set to zero. 69 | * EDX: Features 2. Unused bits are set to zero. 70 | */ 71 | 72 | /* Does the host support MMU_PT_UPDATE_PRESERVE_AD for this guest? */ 73 | #define _XEN_CPUID_FEAT1_MMU_PT_UPDATE_PRESERVE_AD 0 74 | #define XEN_CPUID_FEAT1_MMU_PT_UPDATE_PRESERVE_AD (1u<<0) 75 | 76 | /* 77 | * Leaf 4 (0x40000x03) 78 | * Sub-leaf 0: EAX: bit 0: emulated tsc 79 | * bit 1: host tsc is known to be reliable 80 | * bit 2: RDTSCP instruction available 81 | * EBX: tsc_mode: 0=default (emulate if necessary), 1=emulate, 82 | * 2=no emulation, 3=no emulation + TSC_AUX support 83 | * ECX: guest tsc frequency in kHz 84 | * EDX: guest tsc incarnation (migration count) 85 | * Sub-leaf 1: EAX: tsc offset low part 86 | * EBX: tsc offset high part 87 | * ECX: multiplicator for tsc->ns conversion 88 | * EDX: shift amount for tsc->ns conversion 89 | * Sub-leaf 2: EAX: host tsc frequency in kHz 90 | */ 91 | 92 | /* 93 | * Leaf 5 (0x40000x04) 94 | * HVM-specific features 95 | * Sub-leaf 0: EAX: Features 96 | * Sub-leaf 0: EBX: vcpu id (iff EAX has XEN_HVM_CPUID_VCPU_ID_PRESENT flag) 97 | * Sub-leaf 0: ECX: domain id (iff EAX has XEN_HVM_CPUID_DOMID_PRESENT flag) 98 | */ 99 | #define XEN_HVM_CPUID_APIC_ACCESS_VIRT (1u << 0) /* Virtualized APIC registers */ 100 | #define XEN_HVM_CPUID_X2APIC_VIRT (1u << 1) /* Virtualized x2APIC accesses */ 101 | /* Memory mapped from other domains has valid IOMMU entries */ 102 | #define XEN_HVM_CPUID_IOMMU_MAPPINGS (1u << 2) 103 | #define XEN_HVM_CPUID_VCPU_ID_PRESENT (1u << 3) /* vcpu id is present in EBX */ 104 | #define XEN_HVM_CPUID_DOMID_PRESENT (1u << 4) /* domid is present in ECX */ 105 | 106 | /* 107 | * Leaf 6 (0x40000x05) 108 | * PV-specific parameters 109 | * Sub-leaf 0: EAX: max available sub-leaf 110 | * Sub-leaf 0: EBX: bits 0-7: max machine address width 111 | */ 112 | 113 | /* Max. address width in bits taking memory hotplug into account. */ 114 | #define XEN_CPUID_MACHINE_ADDRESS_WIDTH_MASK (0xffu << 0) 115 | 116 | #define XEN_CPUID_MAX_NUM_LEAVES 5 117 | 118 | #endif /* __XEN_PUBLIC_ARCH_X86_CPUID_H__ */ 119 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/io/pvcalls.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pvcalls.h -- Xen PV Calls Protocol 3 | * 4 | * Refer to docs/misc/pvcalls.markdown for the specification 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (C) 2017 Stefano Stabellini 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_IO_PVCALLS_H__ 28 | #define __XEN_PUBLIC_IO_PVCALLS_H__ 29 | 30 | #include "../grant_table.h" 31 | #include "ring.h" 32 | 33 | /* 34 | * See docs/misc/pvcalls.markdown in xen.git for the full specification: 35 | * https://xenbits.xen.org/docs/unstable/misc/pvcalls.html 36 | */ 37 | struct pvcalls_data_intf { 38 | RING_IDX in_cons, in_prod, in_error; 39 | 40 | uint8_t pad1[52]; 41 | 42 | RING_IDX out_cons, out_prod, out_error; 43 | 44 | uint8_t pad2[52]; 45 | 46 | RING_IDX ring_order; 47 | grant_ref_t ref[]; 48 | }; 49 | DEFINE_XEN_FLEX_RING(pvcalls); 50 | 51 | #define PVCALLS_SOCKET 0 52 | #define PVCALLS_CONNECT 1 53 | #define PVCALLS_RELEASE 2 54 | #define PVCALLS_BIND 3 55 | #define PVCALLS_LISTEN 4 56 | #define PVCALLS_ACCEPT 5 57 | #define PVCALLS_POLL 6 58 | 59 | struct xen_pvcalls_request { 60 | uint32_t req_id; /* private to guest, echoed in response */ 61 | uint32_t cmd; /* command to execute */ 62 | union { 63 | struct xen_pvcalls_socket { 64 | uint64_t id; 65 | uint32_t domain; 66 | uint32_t type; 67 | uint32_t protocol; 68 | } socket; 69 | struct xen_pvcalls_connect { 70 | uint64_t id; 71 | uint8_t addr[28]; 72 | uint32_t len; 73 | uint32_t flags; 74 | grant_ref_t ref; 75 | uint32_t evtchn; 76 | } connect; 77 | struct xen_pvcalls_release { 78 | uint64_t id; 79 | uint8_t reuse; 80 | } release; 81 | struct xen_pvcalls_bind { 82 | uint64_t id; 83 | uint8_t addr[28]; 84 | uint32_t len; 85 | } bind; 86 | struct xen_pvcalls_listen { 87 | uint64_t id; 88 | uint32_t backlog; 89 | } listen; 90 | struct xen_pvcalls_accept { 91 | uint64_t id; 92 | uint64_t id_new; 93 | grant_ref_t ref; 94 | uint32_t evtchn; 95 | } accept; 96 | struct xen_pvcalls_poll { 97 | uint64_t id; 98 | } poll; 99 | /* dummy member to force sizeof(struct xen_pvcalls_request) 100 | * to match across archs */ 101 | struct xen_pvcalls_dummy { 102 | uint8_t dummy[56]; 103 | } dummy; 104 | } u; 105 | }; 106 | 107 | struct xen_pvcalls_response { 108 | uint32_t req_id; 109 | uint32_t cmd; 110 | int32_t ret; 111 | uint32_t pad; 112 | union { 113 | struct _xen_pvcalls_socket { 114 | uint64_t id; 115 | } socket; 116 | struct _xen_pvcalls_connect { 117 | uint64_t id; 118 | } connect; 119 | struct _xen_pvcalls_release { 120 | uint64_t id; 121 | } release; 122 | struct _xen_pvcalls_bind { 123 | uint64_t id; 124 | } bind; 125 | struct _xen_pvcalls_listen { 126 | uint64_t id; 127 | } listen; 128 | struct _xen_pvcalls_accept { 129 | uint64_t id; 130 | } accept; 131 | struct _xen_pvcalls_poll { 132 | uint64_t id; 133 | } poll; 134 | struct _xen_pvcalls_dummy { 135 | uint8_t dummy[8]; 136 | } dummy; 137 | } u; 138 | }; 139 | 140 | DEFINE_RING_TYPES(xen_pvcalls, struct xen_pvcalls_request, 141 | struct xen_pvcalls_response); 142 | 143 | #endif 144 | 145 | /* 146 | * Local variables: 147 | * mode: C 148 | * c-file-style: "BSD" 149 | * c-basic-offset: 4 150 | * tab-width: 4 151 | * indent-tabs-mode: nil 152 | * End: 153 | */ 154 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/hvm/save.h: -------------------------------------------------------------------------------- 1 | /* 2 | * hvm/save.h 3 | * 4 | * Structure definitions for HVM state that is held by Xen and must 5 | * be saved along with the domain's memory and device-model state. 6 | * 7 | * Copyright (c) 2007 XenSource Ltd. 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to 11 | * deal in the Software without restriction, including without limitation the 12 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 13 | * sell copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | * DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #ifndef __XEN_PUBLIC_HVM_SAVE_H__ 29 | #define __XEN_PUBLIC_HVM_SAVE_H__ 30 | 31 | /* 32 | * Structures in this header *must* have the same layout in 32bit 33 | * and 64bit environments: this means that all fields must be explicitly 34 | * sized types and aligned to their sizes, and the structs must be 35 | * a multiple of eight bytes long. 36 | * 37 | * Only the state necessary for saving and restoring (i.e. fields 38 | * that are analogous to actual hardware state) should go in this file. 39 | * Internal mechanisms should be kept in Xen-private headers. 40 | */ 41 | 42 | #if !defined(__GNUC__) || defined(__STRICT_ANSI__) 43 | #error "Anonymous structs/unions are a GNU extension." 44 | #endif 45 | 46 | /* 47 | * Each entry is preceded by a descriptor giving its type and length 48 | */ 49 | struct hvm_save_descriptor { 50 | uint16_t typecode; /* Used to demux the various types below */ 51 | uint16_t instance; /* Further demux within a type */ 52 | uint32_t length; /* In bytes, *not* including this descriptor */ 53 | }; 54 | 55 | 56 | /* 57 | * Each entry has a datatype associated with it: for example, the CPU state 58 | * is saved as a HVM_SAVE_TYPE(CPU), which has HVM_SAVE_LENGTH(CPU), 59 | * and is identified by a descriptor with typecode HVM_SAVE_CODE(CPU). 60 | * DECLARE_HVM_SAVE_TYPE binds these things together with some type-system 61 | * ugliness. 62 | */ 63 | 64 | #ifdef __XEN__ 65 | # define DECLARE_HVM_SAVE_TYPE_COMPAT(_x, _code, _type, _ctype, _fix) \ 66 | static inline int __HVM_SAVE_FIX_COMPAT_##_x(void *h, uint32_t size) \ 67 | { return _fix(h, size); } \ 68 | struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[2];}; \ 69 | struct __HVM_SAVE_TYPE_COMPAT_##_x { _ctype t; } 70 | 71 | # include /* BUG() */ 72 | # define DECLARE_HVM_SAVE_TYPE(_x, _code, _type) \ 73 | static inline int __HVM_SAVE_FIX_COMPAT_##_x(void *h, uint32_t size) \ 74 | { BUG(); return -1; } \ 75 | struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[1];}; \ 76 | struct __HVM_SAVE_TYPE_COMPAT_##_x { _type t; } 77 | #else 78 | # define DECLARE_HVM_SAVE_TYPE_COMPAT(_x, _code, _type, _ctype, _fix) \ 79 | struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[2];} 80 | 81 | # define DECLARE_HVM_SAVE_TYPE(_x, _code, _type) \ 82 | struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[1];} 83 | #endif 84 | 85 | #define HVM_SAVE_TYPE(_x) typeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->t) 86 | #define HVM_SAVE_LENGTH(_x) (sizeof (HVM_SAVE_TYPE(_x))) 87 | #define HVM_SAVE_CODE(_x) (sizeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->c)) 88 | 89 | #ifdef __XEN__ 90 | # define HVM_SAVE_TYPE_COMPAT(_x) typeof (((struct __HVM_SAVE_TYPE_COMPAT_##_x *)(0))->t) 91 | # define HVM_SAVE_LENGTH_COMPAT(_x) (sizeof (HVM_SAVE_TYPE_COMPAT(_x))) 92 | 93 | # define HVM_SAVE_HAS_COMPAT(_x) (sizeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->cpt)-1) 94 | # define HVM_SAVE_FIX_COMPAT(_x, _dst, _size) __HVM_SAVE_FIX_COMPAT_##_x(_dst, _size) 95 | #endif 96 | 97 | /* 98 | * The series of save records is teminated by a zero-type, zero-length 99 | * descriptor. 100 | */ 101 | 102 | struct hvm_save_end {}; 103 | DECLARE_HVM_SAVE_TYPE(END, 0, struct hvm_save_end); 104 | 105 | #if defined(__i386__) || defined(__x86_64__) 106 | #include "../arch-x86/hvm/save.h" 107 | #elif defined(__arm__) || defined(__aarch64__) 108 | #include "../arch-arm/hvm/save.h" 109 | #else 110 | #error "unsupported architecture" 111 | #endif 112 | 113 | #endif /* __XEN_PUBLIC_HVM_SAVE_H__ */ 114 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/features.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * features.h 3 | * 4 | * Feature flags, reported by XENVER_get_features. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2006, Keir Fraser 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_FEATURES_H__ 28 | #define __XEN_PUBLIC_FEATURES_H__ 29 | 30 | /* 31 | * `incontents 200 elfnotes_features XEN_ELFNOTE_FEATURES 32 | * 33 | * The list of all the features the guest supports. They are set by 34 | * parsing the XEN_ELFNOTE_FEATURES and XEN_ELFNOTE_SUPPORTED_FEATURES 35 | * string. The format is the feature names (as given here without the 36 | * "XENFEAT_" prefix) separated by '|' characters. 37 | * If a feature is required for the kernel to function then the feature name 38 | * must be preceded by a '!' character. 39 | * 40 | * Note that if XEN_ELFNOTE_SUPPORTED_FEATURES is used, then in the 41 | * XENFEAT_dom0 MUST be set if the guest is to be booted as dom0, 42 | */ 43 | 44 | /* 45 | * If set, the guest does not need to write-protect its pagetables, and can 46 | * update them via direct writes. 47 | */ 48 | #define XENFEAT_writable_page_tables 0 49 | 50 | /* 51 | * If set, the guest does not need to write-protect its segment descriptor 52 | * tables, and can update them via direct writes. 53 | */ 54 | #define XENFEAT_writable_descriptor_tables 1 55 | 56 | /* 57 | * If set, translation between the guest's 'pseudo-physical' address space 58 | * and the host's machine address space are handled by the hypervisor. In this 59 | * mode the guest does not need to perform phys-to/from-machine translations 60 | * when performing page table operations. 61 | */ 62 | #define XENFEAT_auto_translated_physmap 2 63 | 64 | /* If set, the guest is running in supervisor mode (e.g., x86 ring 0). */ 65 | #define XENFEAT_supervisor_mode_kernel 3 66 | 67 | /* 68 | * If set, the guest does not need to allocate x86 PAE page directories 69 | * below 4GB. This flag is usually implied by auto_translated_physmap. 70 | */ 71 | #define XENFEAT_pae_pgdir_above_4gb 4 72 | 73 | /* x86: Does this Xen host support the MMU_PT_UPDATE_PRESERVE_AD hypercall? */ 74 | #define XENFEAT_mmu_pt_update_preserve_ad 5 75 | 76 | /* x86: Does this Xen host support the MMU_{CLEAR,COPY}_PAGE hypercall? */ 77 | #define XENFEAT_highmem_assist 6 78 | 79 | /* 80 | * If set, GNTTABOP_map_grant_ref honors flags to be placed into guest kernel 81 | * available pte bits. 82 | */ 83 | #define XENFEAT_gnttab_map_avail_bits 7 84 | 85 | /* x86: Does this Xen host support the HVM callback vector type? */ 86 | #define XENFEAT_hvm_callback_vector 8 87 | 88 | /* x86: pvclock algorithm is safe to use on HVM */ 89 | #define XENFEAT_hvm_safe_pvclock 9 90 | 91 | /* x86: pirq can be used by HVM guests */ 92 | #define XENFEAT_hvm_pirqs 10 93 | 94 | /* operation as Dom0 is supported */ 95 | #define XENFEAT_dom0 11 96 | 97 | /* Xen also maps grant references at pfn = mfn. 98 | * This feature flag is deprecated and should not be used. 99 | #define XENFEAT_grant_map_identity 12 100 | */ 101 | 102 | /* Guest can use XENMEMF_vnode to specify virtual node for memory op. */ 103 | #define XENFEAT_memory_op_vnode_supported 13 104 | 105 | /* arm: Hypervisor supports ARM SMC calling convention. */ 106 | #define XENFEAT_ARM_SMCCC_supported 14 107 | 108 | /* 109 | * x86/PVH: If set, ACPI RSDP can be placed at any address. Otherwise RSDP 110 | * must be located in lower 1MB, as required by ACPI Specification for IA-PC 111 | * systems. 112 | * This feature flag is only consulted if XEN_ELFNOTE_GUEST_OS contains 113 | * the "linux" string. 114 | */ 115 | #define XENFEAT_linux_rsdp_unrestricted 15 116 | 117 | #define XENFEAT_NR_SUBMAPS 1 118 | 119 | #endif /* __XEN_PUBLIC_FEATURES_H__ */ 120 | 121 | /* 122 | * Local variables: 123 | * mode: C 124 | * c-file-style: "BSD" 125 | * c-basic-offset: 4 126 | * tab-width: 4 127 | * indent-tabs-mode: nil 128 | * End: 129 | */ 130 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/xenoprof.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * xenoprof.h 3 | * 4 | * Interface for enabling system wide profiling based on hardware performance 5 | * counters 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to 9 | * deal in the Software without restriction, including without limitation the 10 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11 | * sell copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | * 25 | * Copyright (C) 2005 Hewlett-Packard Co. 26 | * Written by Aravind Menon & Jose Renato Santos 27 | */ 28 | 29 | #ifndef __XEN_PUBLIC_XENOPROF_H__ 30 | #define __XEN_PUBLIC_XENOPROF_H__ 31 | 32 | #include "xen.h" 33 | 34 | /* 35 | * Commands to HYPERVISOR_xenoprof_op(). 36 | */ 37 | #define XENOPROF_init 0 38 | #define XENOPROF_reset_active_list 1 39 | #define XENOPROF_reset_passive_list 2 40 | #define XENOPROF_set_active 3 41 | #define XENOPROF_set_passive 4 42 | #define XENOPROF_reserve_counters 5 43 | #define XENOPROF_counter 6 44 | #define XENOPROF_setup_events 7 45 | #define XENOPROF_enable_virq 8 46 | #define XENOPROF_start 9 47 | #define XENOPROF_stop 10 48 | #define XENOPROF_disable_virq 11 49 | #define XENOPROF_release_counters 12 50 | #define XENOPROF_shutdown 13 51 | #define XENOPROF_get_buffer 14 52 | #define XENOPROF_set_backtrace 15 53 | 54 | /* AMD IBS support */ 55 | #define XENOPROF_get_ibs_caps 16 56 | #define XENOPROF_ibs_counter 17 57 | #define XENOPROF_last_op 17 58 | 59 | #define MAX_OPROF_EVENTS 32 60 | #define MAX_OPROF_DOMAINS 25 61 | #define XENOPROF_CPU_TYPE_SIZE 64 62 | 63 | /* Xenoprof performance events (not Xen events) */ 64 | struct event_log { 65 | uint64_t eip; 66 | uint8_t mode; 67 | uint8_t event; 68 | }; 69 | 70 | /* PC value that indicates a special code */ 71 | #define XENOPROF_ESCAPE_CODE (~xen_mk_ullong(0)) 72 | /* Transient events for the xenoprof->oprofile cpu buf */ 73 | #define XENOPROF_TRACE_BEGIN 1 74 | 75 | /* Xenoprof buffer shared between Xen and domain - 1 per VCPU */ 76 | struct xenoprof_buf { 77 | uint32_t event_head; 78 | uint32_t event_tail; 79 | uint32_t event_size; 80 | uint32_t vcpu_id; 81 | uint64_t xen_samples; 82 | uint64_t kernel_samples; 83 | uint64_t user_samples; 84 | uint64_t lost_samples; 85 | struct event_log event_log[1]; 86 | }; 87 | #ifndef __XEN__ 88 | typedef struct xenoprof_buf xenoprof_buf_t; 89 | DEFINE_XEN_GUEST_HANDLE(xenoprof_buf_t); 90 | #endif 91 | 92 | struct xenoprof_init { 93 | int32_t num_events; 94 | int32_t is_primary; 95 | char cpu_type[XENOPROF_CPU_TYPE_SIZE]; 96 | }; 97 | typedef struct xenoprof_init xenoprof_init_t; 98 | DEFINE_XEN_GUEST_HANDLE(xenoprof_init_t); 99 | 100 | struct xenoprof_get_buffer { 101 | int32_t max_samples; 102 | int32_t nbuf; 103 | int32_t bufsize; 104 | uint64_t buf_gmaddr; 105 | }; 106 | typedef struct xenoprof_get_buffer xenoprof_get_buffer_t; 107 | DEFINE_XEN_GUEST_HANDLE(xenoprof_get_buffer_t); 108 | 109 | struct xenoprof_counter { 110 | uint32_t ind; 111 | uint64_t count; 112 | uint32_t enabled; 113 | uint32_t event; 114 | uint32_t hypervisor; 115 | uint32_t kernel; 116 | uint32_t user; 117 | uint64_t unit_mask; 118 | }; 119 | typedef struct xenoprof_counter xenoprof_counter_t; 120 | DEFINE_XEN_GUEST_HANDLE(xenoprof_counter_t); 121 | 122 | typedef struct xenoprof_passive { 123 | uint16_t domain_id; 124 | int32_t max_samples; 125 | int32_t nbuf; 126 | int32_t bufsize; 127 | uint64_t buf_gmaddr; 128 | } xenoprof_passive_t; 129 | DEFINE_XEN_GUEST_HANDLE(xenoprof_passive_t); 130 | 131 | struct xenoprof_ibs_counter { 132 | uint64_t op_enabled; 133 | uint64_t fetch_enabled; 134 | uint64_t max_cnt_fetch; 135 | uint64_t max_cnt_op; 136 | uint64_t rand_en; 137 | uint64_t dispatched_ops; 138 | }; 139 | typedef struct xenoprof_ibs_counter xenoprof_ibs_counter_t; 140 | DEFINE_XEN_GUEST_HANDLE(xenoprof_ibs_counter_t); 141 | 142 | #endif /* __XEN_PUBLIC_XENOPROF_H__ */ 143 | 144 | /* 145 | * Local variables: 146 | * mode: C 147 | * c-file-style: "BSD" 148 | * c-basic-offset: 4 149 | * tab-width: 4 150 | * indent-tabs-mode: nil 151 | * End: 152 | */ 153 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/errno.h: -------------------------------------------------------------------------------- 1 | /* 2 | * There are two expected ways of including this header. 3 | * 4 | * 1) The "default" case (expected from tools etc). 5 | * 6 | * Simply #include 7 | * 8 | * In this circumstance, normal header guards apply and the includer shall get 9 | * an enumeration in the XEN_xxx namespace, appropriate for C or assembly. 10 | * 11 | * 2) The special case where the includer provides a XEN_ERRNO() in scope. 12 | * 13 | * In this case, no inclusion guards apply and the caller is responsible for 14 | * their XEN_ERRNO() being appropriate in the included context. The header 15 | * will unilaterally #undef XEN_ERRNO(). 16 | */ 17 | 18 | #ifndef XEN_ERRNO 19 | 20 | /* 21 | * Includer has not provided a custom XEN_ERRNO(). Arrange for normal header 22 | * guards, an automatic enum (for C code) and constants in the XEN_xxx 23 | * namespace. 24 | */ 25 | #ifndef __XEN_PUBLIC_ERRNO_H__ 26 | #define __XEN_PUBLIC_ERRNO_H__ 27 | 28 | #define XEN_ERRNO_DEFAULT_INCLUDE 29 | 30 | #ifndef __ASSEMBLY__ 31 | 32 | #define XEN_ERRNO(name, value) XEN_##name = value, 33 | enum xen_errno { 34 | 35 | #elif __XEN_INTERFACE_VERSION__ < 0x00040700 36 | 37 | #define XEN_ERRNO(name, value) .equ XEN_##name, value 38 | 39 | #endif /* __ASSEMBLY__ */ 40 | 41 | #endif /* __XEN_PUBLIC_ERRNO_H__ */ 42 | #endif /* !XEN_ERRNO */ 43 | 44 | /* ` enum neg_errnoval { [ -Efoo for each Efoo in the list below ] } */ 45 | /* ` enum errnoval { */ 46 | 47 | #ifdef XEN_ERRNO 48 | 49 | /* 50 | * Values originating from x86 Linux. Please consider using respective 51 | * values when adding new definitions here. 52 | * 53 | * The set of identifiers to be added here shouldn't extend beyond what 54 | * POSIX mandates (see e.g. 55 | * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html) 56 | * with the exception that we support some optional (XSR) values 57 | * specified there (but no new ones should be added). 58 | */ 59 | 60 | XEN_ERRNO(EPERM, 1) /* Operation not permitted */ 61 | XEN_ERRNO(ENOENT, 2) /* No such file or directory */ 62 | XEN_ERRNO(ESRCH, 3) /* No such process */ 63 | #ifdef __XEN__ /* Internal only, should never be exposed to the guest. */ 64 | XEN_ERRNO(EINTR, 4) /* Interrupted system call */ 65 | #endif 66 | XEN_ERRNO(EIO, 5) /* I/O error */ 67 | XEN_ERRNO(ENXIO, 6) /* No such device or address */ 68 | XEN_ERRNO(E2BIG, 7) /* Arg list too long */ 69 | XEN_ERRNO(ENOEXEC, 8) /* Exec format error */ 70 | XEN_ERRNO(EBADF, 9) /* Bad file number */ 71 | XEN_ERRNO(ECHILD, 10) /* No child processes */ 72 | XEN_ERRNO(EAGAIN, 11) /* Try again */ 73 | XEN_ERRNO(EWOULDBLOCK, 11) /* Operation would block. Aliases EAGAIN */ 74 | XEN_ERRNO(ENOMEM, 12) /* Out of memory */ 75 | XEN_ERRNO(EACCES, 13) /* Permission denied */ 76 | XEN_ERRNO(EFAULT, 14) /* Bad address */ 77 | XEN_ERRNO(EBUSY, 16) /* Device or resource busy */ 78 | XEN_ERRNO(EEXIST, 17) /* File exists */ 79 | XEN_ERRNO(EXDEV, 18) /* Cross-device link */ 80 | XEN_ERRNO(ENODEV, 19) /* No such device */ 81 | XEN_ERRNO(EISDIR, 21) /* Is a directory */ 82 | XEN_ERRNO(EINVAL, 22) /* Invalid argument */ 83 | XEN_ERRNO(ENFILE, 23) /* File table overflow */ 84 | XEN_ERRNO(EMFILE, 24) /* Too many open files */ 85 | XEN_ERRNO(ENOSPC, 28) /* No space left on device */ 86 | XEN_ERRNO(EROFS, 30) /* Read-only file system */ 87 | XEN_ERRNO(EMLINK, 31) /* Too many links */ 88 | XEN_ERRNO(EDOM, 33) /* Math argument out of domain of func */ 89 | XEN_ERRNO(ERANGE, 34) /* Math result not representable */ 90 | XEN_ERRNO(EDEADLK, 35) /* Resource deadlock would occur */ 91 | XEN_ERRNO(EDEADLOCK, 35) /* Resource deadlock would occur. Aliases EDEADLK */ 92 | XEN_ERRNO(ENAMETOOLONG, 36) /* File name too long */ 93 | XEN_ERRNO(ENOLCK, 37) /* No record locks available */ 94 | XEN_ERRNO(ENOSYS, 38) /* Function not implemented */ 95 | XEN_ERRNO(ENOTEMPTY, 39) /* Directory not empty */ 96 | XEN_ERRNO(ENODATA, 61) /* No data available */ 97 | XEN_ERRNO(ETIME, 62) /* Timer expired */ 98 | XEN_ERRNO(EBADMSG, 74) /* Not a data message */ 99 | XEN_ERRNO(EOVERFLOW, 75) /* Value too large for defined data type */ 100 | XEN_ERRNO(EILSEQ, 84) /* Illegal byte sequence */ 101 | #ifdef __XEN__ /* Internal only, should never be exposed to the guest. */ 102 | XEN_ERRNO(ERESTART, 85) /* Interrupted system call should be restarted */ 103 | #endif 104 | XEN_ERRNO(ENOTSOCK, 88) /* Socket operation on non-socket */ 105 | XEN_ERRNO(EMSGSIZE, 90) /* Message too large. */ 106 | XEN_ERRNO(EOPNOTSUPP, 95) /* Operation not supported on transport endpoint */ 107 | XEN_ERRNO(EADDRINUSE, 98) /* Address already in use */ 108 | XEN_ERRNO(EADDRNOTAVAIL, 99) /* Cannot assign requested address */ 109 | XEN_ERRNO(ENOBUFS, 105) /* No buffer space available */ 110 | XEN_ERRNO(EISCONN, 106) /* Transport endpoint is already connected */ 111 | XEN_ERRNO(ENOTCONN, 107) /* Transport endpoint is not connected */ 112 | XEN_ERRNO(ETIMEDOUT, 110) /* Connection timed out */ 113 | XEN_ERRNO(ECONNREFUSED, 111) /* Connection refused */ 114 | 115 | #undef XEN_ERRNO 116 | #endif /* XEN_ERRNO */ 117 | /* ` } */ 118 | 119 | /* Clean up from a default include. Close the enum (for C). */ 120 | #ifdef XEN_ERRNO_DEFAULT_INCLUDE 121 | #undef XEN_ERRNO_DEFAULT_INCLUDE 122 | #ifndef __ASSEMBLY__ 123 | }; 124 | #endif 125 | 126 | #endif /* XEN_ERRNO_DEFAULT_INCLUDE */ 127 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/pmu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Permission is hereby granted, free of charge, to any person obtaining a copy 3 | * of this software and associated documentation files (the "Software"), to 4 | * deal in the Software without restriction, including without limitation the 5 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 6 | * sell copies of the Software, and to permit persons to whom the Software is 7 | * furnished to do so, subject to the following conditions: 8 | * 9 | * The above copyright notice and this permission notice shall be included in 10 | * all copies or substantial portions of the Software. 11 | * 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. 21 | */ 22 | 23 | #ifndef __XEN_PUBLIC_PMU_H__ 24 | #define __XEN_PUBLIC_PMU_H__ 25 | 26 | #include "xen.h" 27 | #if defined(__i386__) || defined(__x86_64__) 28 | #include "arch-x86/pmu.h" 29 | #elif defined (__arm__) || defined (__aarch64__) 30 | #include "arch-arm.h" 31 | #else 32 | #error "Unsupported architecture" 33 | #endif 34 | 35 | #define XENPMU_VER_MAJ 0 36 | #define XENPMU_VER_MIN 1 37 | 38 | /* 39 | * ` enum neg_errnoval 40 | * ` HYPERVISOR_xenpmu_op(enum xenpmu_op cmd, struct xenpmu_params *args); 41 | * 42 | * @cmd == XENPMU_* (PMU operation) 43 | * @args == struct xenpmu_params 44 | */ 45 | /* ` enum xenpmu_op { */ 46 | #define XENPMU_mode_get 0 /* Also used for getting PMU version */ 47 | #define XENPMU_mode_set 1 48 | #define XENPMU_feature_get 2 49 | #define XENPMU_feature_set 3 50 | #define XENPMU_init 4 51 | #define XENPMU_finish 5 52 | #define XENPMU_lvtpc_set 6 53 | #define XENPMU_flush 7 /* Write cached MSR values to HW */ 54 | /* ` } */ 55 | 56 | /* Parameters structure for HYPERVISOR_xenpmu_op call */ 57 | struct xen_pmu_params { 58 | /* IN/OUT parameters */ 59 | struct { 60 | uint32_t maj; 61 | uint32_t min; 62 | } version; 63 | uint64_t val; 64 | 65 | /* IN parameters */ 66 | uint32_t vcpu; 67 | uint32_t pad; 68 | }; 69 | typedef struct xen_pmu_params xen_pmu_params_t; 70 | DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t); 71 | 72 | /* PMU modes: 73 | * - XENPMU_MODE_OFF: No PMU virtualization 74 | * - XENPMU_MODE_SELF: Guests can profile themselves 75 | * - XENPMU_MODE_HV: Guests can profile themselves, dom0 profiles 76 | * itself and Xen 77 | * - XENPMU_MODE_ALL: Only dom0 has access to VPMU and it profiles 78 | * everyone: itself, the hypervisor and the guests. 79 | */ 80 | #define XENPMU_MODE_OFF 0 81 | #define XENPMU_MODE_SELF (1<<0) 82 | #define XENPMU_MODE_HV (1<<1) 83 | #define XENPMU_MODE_ALL (1<<2) 84 | 85 | /* 86 | * PMU features: 87 | * - XENPMU_FEATURE_INTEL_BTS: Intel BTS support (ignored on AMD) 88 | * - XENPMU_FEATURE_IPC_ONLY: Restrict PMCs to the most minimum set possible. 89 | * Instructions, cycles, and ref cycles. Can be 90 | * used to calculate instructions-per-cycle (IPC) 91 | * (ignored on AMD). 92 | * - XENPMU_FEATURE_ARCH_ONLY: Restrict PMCs to the Intel Pre-Defined 93 | * Architectural Performance Events exposed by 94 | * cpuid and listed in the Intel developer's manual 95 | * (ignored on AMD). 96 | */ 97 | #define XENPMU_FEATURE_INTEL_BTS (1<<0) 98 | #define XENPMU_FEATURE_IPC_ONLY (1<<1) 99 | #define XENPMU_FEATURE_ARCH_ONLY (1<<2) 100 | 101 | /* 102 | * Shared PMU data between hypervisor and PV(H) domains. 103 | * 104 | * The hypervisor fills out this structure during PMU interrupt and sends an 105 | * interrupt to appropriate VCPU. 106 | * Architecture-independent fields of xen_pmu_data are WO for the hypervisor 107 | * and RO for the guest but some fields in xen_pmu_arch can be writable 108 | * by both the hypervisor and the guest (see arch-$arch/pmu.h). 109 | */ 110 | struct xen_pmu_data { 111 | /* Interrupted VCPU */ 112 | uint32_t vcpu_id; 113 | 114 | /* 115 | * Physical processor on which the interrupt occurred. On non-privileged 116 | * guests set to vcpu_id; 117 | */ 118 | uint32_t pcpu_id; 119 | 120 | /* 121 | * Domain that was interrupted. On non-privileged guests set to DOMID_SELF. 122 | * On privileged guests can be DOMID_SELF, DOMID_XEN, or, when in 123 | * XENPMU_MODE_ALL mode, domain ID of another domain. 124 | */ 125 | domid_t domain_id; 126 | 127 | uint8_t pad[6]; 128 | 129 | /* Architecture-specific information */ 130 | struct xen_pmu_arch pmu; 131 | }; 132 | 133 | #endif /* __XEN_PUBLIC_PMU_H__ */ 134 | 135 | /* 136 | * Local variables: 137 | * mode: C 138 | * c-file-style: "BSD" 139 | * c-basic-offset: 4 140 | * tab-width: 4 141 | * indent-tabs-mode: nil 142 | * End: 143 | */ 144 | -------------------------------------------------------------------------------- /lib/bindings/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Martin Lucina 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "solo5.h" 18 | #include "bindings.h" 19 | #include "hypercall.h" 20 | #include "xen/hvm/params.h" 21 | 22 | #include 23 | 24 | #define CAML_NAME_SPACE 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | static char *unused_argv[] = { "mirage", NULL }; 33 | static const char *solo5_cmdline = ""; 34 | static size_t solo5_heap_size; 35 | static uintptr_t sp_at_start; 36 | 37 | CAMLprim value 38 | mirage_xen_get_cmdline(value v_unit) 39 | { 40 | CAMLparam1(v_unit); 41 | 42 | CAMLreturn(caml_copy_string(solo5_cmdline)); 43 | } 44 | 45 | /* 46 | * Bigarrays used to represent "I/O pages", i.e. in this case memory belonging 47 | * to the Xenstore and initial console rings must be declared with the following 48 | * layout and kind, notably CAML_BA_EXTERNAL to ensure that the GC will not 49 | * attempt to call free() on finalise. 50 | */ 51 | #define CAML_BA_IO_PAGE (CAML_BA_UINT8 | CAML_BA_C_LAYOUT | CAML_BA_EXTERNAL) 52 | 53 | CAMLprim value 54 | mirage_xen_get_console_evtchn(value v_unit) 55 | { 56 | CAMLparam1(v_unit); 57 | uint64_t raw_evtchn = 0; 58 | int rc; 59 | 60 | rc = hypercall_hvm_get_param(HVM_PARAM_CONSOLE_EVTCHN, &raw_evtchn); 61 | if (rc) 62 | caml_failwith("hvm_get_param HVM_PARAM_CONSOLE_EVTCHN"); 63 | else 64 | CAMLreturn(Val_int(raw_evtchn)); 65 | } 66 | 67 | CAMLprim value 68 | mirage_xen_get_console_page(value v_unit) 69 | { 70 | CAMLparam1(v_unit); 71 | uint64_t raw_pfn = 0; 72 | int rc; 73 | 74 | rc = hypercall_hvm_get_param(HVM_PARAM_CONSOLE_PFN, &raw_pfn); 75 | if (rc) 76 | caml_failwith("hvm_get_param HVM_PARAM_CONSOLE_PFN"); 77 | else 78 | CAMLreturn(caml_ba_alloc_dims(CAML_BA_IO_PAGE, 1, 79 | (void *)(raw_pfn << PAGE_SHIFT), PAGE_SIZE)); 80 | } 81 | 82 | CAMLprim value 83 | mirage_xen_get_xenstore_evtchn(value v_unit) 84 | { 85 | CAMLparam1(v_unit); 86 | uint64_t raw_evtchn = 0; 87 | int rc; 88 | 89 | rc = hypercall_hvm_get_param(HVM_PARAM_STORE_EVTCHN, &raw_evtchn); 90 | if (rc) 91 | caml_failwith("hvm_get_param HVM_PARAM_STORE_EVTCHN"); 92 | else 93 | CAMLreturn(Val_int(raw_evtchn)); 94 | } 95 | 96 | CAMLprim value 97 | mirage_xen_get_xenstore_page(value v_unit) 98 | { 99 | CAMLparam1(v_unit); 100 | uint64_t raw_pfn = 0; 101 | int rc; 102 | 103 | rc = hypercall_hvm_get_param(HVM_PARAM_STORE_PFN, &raw_pfn); 104 | if (rc) 105 | caml_failwith("hvm_get_param HVM_PARAM_STORE_PFN"); 106 | else 107 | CAMLreturn(caml_ba_alloc_dims(CAML_BA_IO_PAGE, 1, 108 | (void *)(raw_pfn << PAGE_SHIFT), PAGE_SIZE)); 109 | } 110 | 111 | /* 112 | * Caller: OS.Memory, @@noalloc 113 | */ 114 | CAMLprim value 115 | mirage_memory_get_heap_words(value v_unit) 116 | { 117 | return Val_long(solo5_heap_size / sizeof(value)); 118 | } 119 | 120 | /* 121 | * defined in ocaml freestanding dlmalloc.i 122 | */ 123 | extern size_t malloc_footprint(void); 124 | extern size_t malloc_memory_usage(void); 125 | extern int malloc_trim(size_t pad); 126 | 127 | /* 128 | * Caller: OS.Memory, @@noalloc 129 | */ 130 | CAMLprim value 131 | mirage_memory_get_live_words(value v_unit) 132 | { 133 | struct mallinfo m = mallinfo(); 134 | return Val_long(m.uordblks / sizeof(value)); 135 | } 136 | 137 | /* 138 | * Caller: OS.Memory, @@noalloc 139 | */ 140 | CAMLprim value 141 | mirage_memory_get_fast_live_words(value v_unit) 142 | { 143 | return Val_long(malloc_memory_usage() / sizeof(value)); 144 | } 145 | 146 | /* 147 | * Caller: OS.Memory, @@noalloc 148 | * 149 | * The implementation currently uses a hard-coded value for the stack guard 150 | * size; this must be kept in sync with nolibc's sbrk() implementation. 151 | * TODO: Consider providing a formal interface for this. 152 | */ 153 | CAMLprim value 154 | mirage_memory_get_stack_words(value v_unit) 155 | { 156 | int dummy; 157 | 158 | return Val_long((sp_at_start - (uintptr_t)&dummy + 0x100000) 159 | / sizeof(value)); 160 | } 161 | 162 | /* 163 | * Caller: OS.Memory, @@noalloc 164 | */ 165 | CAMLprim value 166 | mirage_trim_allocation(value v_unit) 167 | { 168 | return Val_long(malloc_trim(0)); 169 | } 170 | 171 | extern void _nolibc_init(uintptr_t, size_t); 172 | 173 | int solo5_app_main(const struct solo5_start_info *si) 174 | { 175 | int dummy; 176 | 177 | sp_at_start = (uintptr_t)&dummy; 178 | _nolibc_init(si->heap_start, si->heap_size); 179 | solo5_heap_size = si->heap_size; 180 | gnttab_init(); 181 | solo5_cmdline = si->cmdline; 182 | caml_startup(unused_argv); 183 | 184 | return 0; 185 | } 186 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/hvm/ioreq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ioreq.h: I/O request definitions for device models 3 | * Copyright (c) 2004, Intel Corporation. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef _IOREQ_H_ 25 | #define _IOREQ_H_ 26 | 27 | #define IOREQ_READ 1 28 | #define IOREQ_WRITE 0 29 | 30 | #define STATE_IOREQ_NONE 0 31 | #define STATE_IOREQ_READY 1 32 | #define STATE_IOREQ_INPROCESS 2 33 | #define STATE_IORESP_READY 3 34 | 35 | #define IOREQ_TYPE_PIO 0 /* pio */ 36 | #define IOREQ_TYPE_COPY 1 /* mmio ops */ 37 | #define IOREQ_TYPE_PCI_CONFIG 2 38 | #define IOREQ_TYPE_TIMEOFFSET 7 39 | #define IOREQ_TYPE_INVALIDATE 8 /* mapcache */ 40 | 41 | /* 42 | * VMExit dispatcher should cooperate with instruction decoder to 43 | * prepare this structure and notify service OS and DM by sending 44 | * virq. 45 | * 46 | * For I/O type IOREQ_TYPE_PCI_CONFIG, the physical address is formatted 47 | * as follows: 48 | * 49 | * 63....48|47..40|39..35|34..32|31........0 50 | * SEGMENT |BUS |DEV |FN |OFFSET 51 | */ 52 | struct ioreq { 53 | uint64_t addr; /* physical address */ 54 | uint64_t data; /* data (or paddr of data) */ 55 | uint32_t count; /* for rep prefixes */ 56 | uint32_t size; /* size in bytes */ 57 | uint32_t vp_eport; /* evtchn for notifications to/from device model */ 58 | uint16_t _pad0; 59 | uint8_t state:4; 60 | uint8_t data_is_ptr:1; /* if 1, data above is the guest paddr 61 | * of the real data to use. */ 62 | uint8_t dir:1; /* 1=read, 0=write */ 63 | uint8_t df:1; 64 | uint8_t _pad1:1; 65 | uint8_t type; /* I/O type */ 66 | }; 67 | typedef struct ioreq ioreq_t; 68 | 69 | struct shared_iopage { 70 | struct ioreq vcpu_ioreq[1]; 71 | }; 72 | typedef struct shared_iopage shared_iopage_t; 73 | 74 | struct buf_ioreq { 75 | uint8_t type; /* I/O type */ 76 | uint8_t pad:1; 77 | uint8_t dir:1; /* 1=read, 0=write */ 78 | uint8_t size:2; /* 0=>1, 1=>2, 2=>4, 3=>8. If 8, use two buf_ioreqs */ 79 | uint32_t addr:20;/* physical address */ 80 | uint32_t data; /* data */ 81 | }; 82 | typedef struct buf_ioreq buf_ioreq_t; 83 | 84 | #define IOREQ_BUFFER_SLOT_NUM 511 /* 8 bytes each, plus 2 4-byte indexes */ 85 | struct buffered_iopage { 86 | #ifdef __XEN__ 87 | union bufioreq_pointers { 88 | struct { 89 | #endif 90 | uint32_t read_pointer; 91 | uint32_t write_pointer; 92 | #ifdef __XEN__ 93 | }; 94 | uint64_t full; 95 | } ptrs; 96 | #endif 97 | buf_ioreq_t buf_ioreq[IOREQ_BUFFER_SLOT_NUM]; 98 | }; /* NB. Size of this structure must be no greater than one page. */ 99 | typedef struct buffered_iopage buffered_iopage_t; 100 | 101 | /* 102 | * ACPI Control/Event register locations. Location is controlled by a 103 | * version number in HVM_PARAM_ACPI_IOPORTS_LOCATION. 104 | */ 105 | 106 | /* 107 | * Version 0 (default): Traditional (obsolete) Xen locations. 108 | * 109 | * These are now only used for compatibility with VMs migrated 110 | * from older Xen versions. 111 | */ 112 | #define ACPI_PM1A_EVT_BLK_ADDRESS_V0 0x1f40 113 | #define ACPI_PM1A_CNT_BLK_ADDRESS_V0 (ACPI_PM1A_EVT_BLK_ADDRESS_V0 + 0x04) 114 | #define ACPI_PM_TMR_BLK_ADDRESS_V0 (ACPI_PM1A_EVT_BLK_ADDRESS_V0 + 0x08) 115 | #define ACPI_GPE0_BLK_ADDRESS_V0 (ACPI_PM_TMR_BLK_ADDRESS_V0 + 0x20) 116 | #define ACPI_GPE0_BLK_LEN_V0 0x08 117 | 118 | /* Version 1: Locations preferred by modern Qemu (including Qemu-trad). */ 119 | #define ACPI_PM1A_EVT_BLK_ADDRESS_V1 0xb000 120 | #define ACPI_PM1A_CNT_BLK_ADDRESS_V1 (ACPI_PM1A_EVT_BLK_ADDRESS_V1 + 0x04) 121 | #define ACPI_PM_TMR_BLK_ADDRESS_V1 (ACPI_PM1A_EVT_BLK_ADDRESS_V1 + 0x08) 122 | #define ACPI_GPE0_BLK_ADDRESS_V1 0xafe0 123 | #define ACPI_GPE0_BLK_LEN_V1 0x04 124 | 125 | /* Compatibility definitions for the default location (version 0). */ 126 | #define ACPI_PM1A_EVT_BLK_ADDRESS ACPI_PM1A_EVT_BLK_ADDRESS_V0 127 | #define ACPI_PM1A_CNT_BLK_ADDRESS ACPI_PM1A_CNT_BLK_ADDRESS_V0 128 | #define ACPI_PM_TMR_BLK_ADDRESS ACPI_PM_TMR_BLK_ADDRESS_V0 129 | #define ACPI_GPE0_BLK_ADDRESS ACPI_GPE0_BLK_ADDRESS_V0 130 | #define ACPI_GPE0_BLK_LEN ACPI_GPE0_BLK_LEN_V0 131 | 132 | 133 | #endif /* _IOREQ_H_ */ 134 | 135 | /* 136 | * Local variables: 137 | * mode: C 138 | * c-file-style: "BSD" 139 | * c-basic-offset: 4 140 | * tab-width: 4 141 | * indent-tabs-mode: nil 142 | * End: 143 | */ 144 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/arch-x86/pmu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Permission is hereby granted, free of charge, to any person obtaining a copy 3 | * of this software and associated documentation files (the "Software"), to 4 | * deal in the Software without restriction, including without limitation the 5 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 6 | * sell copies of the Software, and to permit persons to whom the Software is 7 | * furnished to do so, subject to the following conditions: 8 | * 9 | * The above copyright notice and this permission notice shall be included in 10 | * all copies or substantial portions of the Software. 11 | * 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. 21 | */ 22 | 23 | #ifndef __XEN_PUBLIC_ARCH_X86_PMU_H__ 24 | #define __XEN_PUBLIC_ARCH_X86_PMU_H__ 25 | 26 | /* x86-specific PMU definitions */ 27 | 28 | /* AMD PMU registers and structures */ 29 | struct xen_pmu_amd_ctxt { 30 | /* 31 | * Offsets to counter and control MSRs (relative to xen_pmu_arch.c.amd). 32 | * For PV(H) guests these fields are RO. 33 | */ 34 | uint32_t counters; 35 | uint32_t ctrls; 36 | 37 | /* Counter MSRs */ 38 | uint64_t regs[XEN_FLEX_ARRAY_DIM]; 39 | }; 40 | typedef struct xen_pmu_amd_ctxt xen_pmu_amd_ctxt_t; 41 | DEFINE_XEN_GUEST_HANDLE(xen_pmu_amd_ctxt_t); 42 | 43 | /* Intel PMU registers and structures */ 44 | struct xen_pmu_cntr_pair { 45 | uint64_t counter; 46 | uint64_t control; 47 | }; 48 | typedef struct xen_pmu_cntr_pair xen_pmu_cntr_pair_t; 49 | DEFINE_XEN_GUEST_HANDLE(xen_pmu_cntr_pair_t); 50 | 51 | struct xen_pmu_intel_ctxt { 52 | /* 53 | * Offsets to fixed and architectural counter MSRs (relative to 54 | * xen_pmu_arch.c.intel). 55 | * For PV(H) guests these fields are RO. 56 | */ 57 | uint32_t fixed_counters; 58 | uint32_t arch_counters; 59 | 60 | /* PMU registers */ 61 | uint64_t global_ctrl; 62 | uint64_t global_ovf_ctrl; 63 | uint64_t global_status; 64 | uint64_t fixed_ctrl; 65 | uint64_t ds_area; 66 | uint64_t pebs_enable; 67 | uint64_t debugctl; 68 | 69 | /* Fixed and architectural counter MSRs */ 70 | uint64_t regs[XEN_FLEX_ARRAY_DIM]; 71 | }; 72 | typedef struct xen_pmu_intel_ctxt xen_pmu_intel_ctxt_t; 73 | DEFINE_XEN_GUEST_HANDLE(xen_pmu_intel_ctxt_t); 74 | 75 | /* Sampled domain's registers */ 76 | struct xen_pmu_regs { 77 | uint64_t ip; 78 | uint64_t sp; 79 | uint64_t flags; 80 | uint16_t cs; 81 | uint16_t ss; 82 | uint8_t cpl; 83 | uint8_t pad[3]; 84 | }; 85 | typedef struct xen_pmu_regs xen_pmu_regs_t; 86 | DEFINE_XEN_GUEST_HANDLE(xen_pmu_regs_t); 87 | 88 | /* PMU flags */ 89 | #define PMU_CACHED (1<<0) /* PMU MSRs are cached in the context */ 90 | #define PMU_SAMPLE_USER (1<<1) /* Sample is from user or kernel mode */ 91 | #define PMU_SAMPLE_REAL (1<<2) /* Sample is from realmode */ 92 | #define PMU_SAMPLE_PV (1<<3) /* Sample from a PV guest */ 93 | 94 | /* 95 | * Architecture-specific information describing state of the processor at 96 | * the time of PMU interrupt. 97 | * Fields of this structure marked as RW for guest should only be written by 98 | * the guest when PMU_CACHED bit in pmu_flags is set (which is done by the 99 | * hypervisor during PMU interrupt). Hypervisor will read updated data in 100 | * XENPMU_flush hypercall and clear PMU_CACHED bit. 101 | */ 102 | struct xen_pmu_arch { 103 | union { 104 | /* 105 | * Processor's registers at the time of interrupt. 106 | * WO for hypervisor, RO for guests. 107 | */ 108 | struct xen_pmu_regs regs; 109 | /* Padding for adding new registers to xen_pmu_regs in the future */ 110 | #define XENPMU_REGS_PAD_SZ 64 111 | uint8_t pad[XENPMU_REGS_PAD_SZ]; 112 | } r; 113 | 114 | /* WO for hypervisor, RO for guest */ 115 | uint64_t pmu_flags; 116 | 117 | /* 118 | * APIC LVTPC register. 119 | * RW for both hypervisor and guest. 120 | * Only APIC_LVT_MASKED bit is loaded by the hypervisor into hardware 121 | * during XENPMU_flush or XENPMU_lvtpc_set. 122 | */ 123 | union { 124 | uint32_t lapic_lvtpc; 125 | uint64_t pad; 126 | } l; 127 | 128 | /* 129 | * Vendor-specific PMU registers. 130 | * RW for both hypervisor and guest (see exceptions above). 131 | * Guest's updates to this field are verified and then loaded by the 132 | * hypervisor into hardware during XENPMU_flush 133 | */ 134 | union { 135 | struct xen_pmu_amd_ctxt amd; 136 | struct xen_pmu_intel_ctxt intel; 137 | 138 | /* 139 | * Padding for contexts (fixed parts only, does not include MSR banks 140 | * that are specified by offsets) 141 | */ 142 | #define XENPMU_CTXT_PAD_SZ 128 143 | uint8_t pad[XENPMU_CTXT_PAD_SZ]; 144 | } c; 145 | }; 146 | typedef struct xen_pmu_arch xen_pmu_arch_t; 147 | DEFINE_XEN_GUEST_HANDLE(xen_pmu_arch_t); 148 | 149 | #endif /* __XEN_PUBLIC_ARCH_X86_PMU_H__ */ 150 | /* 151 | * Local variables: 152 | * mode: C 153 | * c-file-style: "BSD" 154 | * c-basic-offset: 4 155 | * tab-width: 4 156 | * indent-tabs-mode: nil 157 | * End: 158 | */ 159 | 160 | -------------------------------------------------------------------------------- /lib/bindings/hypercall-x86_64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2020 Contributors as noted in the AUTHORS file 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software 5 | * for any purpose with or without fee is hereby granted, provided 6 | * that the above copyright notice and this permission notice appear 7 | * in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR 13 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 14 | * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 15 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 16 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | /* 20 | * Based on XTF hypercall-x86_64.h, which is: 21 | * 22 | * The Xen Test Framework is licenced under the BSD 2-clause license 23 | * 24 | * Copyright (c) 2014,2015 Citrix Systems Ltd. 25 | * All rights reserved. 26 | * 27 | * Redistribution and use in source and binary forms, with or without 28 | * modification, are permitted provided that the following conditions are met: 29 | * 30 | * 1. Redistributions of source code must retain the above copyright notice, this 31 | * list of conditions and the following disclaimer. 32 | * 2. Redistributions in binary form must reproduce the above copyright notice, 33 | * this list of conditions and the following disclaimer in the documentation 34 | * and/or other materials provided with the distribution. 35 | * 36 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 37 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 38 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 39 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 40 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 41 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 45 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | */ 47 | 48 | #ifndef __XEN_HYPERCALL_X86_64_H__ 49 | #define __XEN_HYPERCALL_X86_64_H__ 50 | 51 | /* 52 | * Hypercall primatives for 64bit 53 | * 54 | * Inputs: %rdi, %rsi, %rdx, %r10, %r8, %r9 (arguments 1-6) 55 | */ 56 | 57 | #define _hypercall64_1(type, hcall, a1) \ 58 | ({ \ 59 | long __res, __ign1; \ 60 | __asm__ __volatile__ ( \ 61 | "call solo5__xen_HYPERCALL_PAGE + %c[offset]" \ 62 | : "=a" (__res), "=D" (__ign1) \ 63 | : [offset] "i" (hcall * 32), \ 64 | "1" ((long)(a1)) \ 65 | : "memory" ); \ 66 | (type)__res; \ 67 | }) 68 | 69 | #define _hypercall64_2(type, hcall, a1, a2) \ 70 | ({ \ 71 | long __res, __ign1, __ign2; \ 72 | __asm__ __volatile__ ( \ 73 | "call solo5__xen_HYPERCALL_PAGE + %c[offset]" \ 74 | : "=a" (__res), "=D" (__ign1), "=S" (__ign2) \ 75 | : [offset] "i" (hcall * 32), \ 76 | "1" ((long)(a1)), "2" ((long)(a2)) \ 77 | : "memory" ); \ 78 | (type)__res; \ 79 | }) 80 | 81 | #define _hypercall64_3(type, hcall, a1, a2, a3) \ 82 | ({ \ 83 | long __res, __ign1, __ign2, __ign3; \ 84 | __asm__ __volatile__ ( \ 85 | "call solo5__xen_HYPERCALL_PAGE + %c[offset]" \ 86 | : "=a" (__res), "=D" (__ign1), "=S" (__ign2), "=d" (__ign3) \ 87 | : [offset] "i" (hcall * 32), \ 88 | "1" ((long)(a1)), "2" ((long)(a2)), "3" ((long)(a3)) \ 89 | : "memory" ); \ 90 | (type)__res; \ 91 | }) 92 | 93 | #define _hypercall64_4(type, hcall, a1, a2, a3, a4) \ 94 | ({ \ 95 | long __res, __ign1, __ign2, __ign3, __ign4; \ 96 | register long _a4 __asm__ ("r10") = ((long)(a4)); \ 97 | __asm__ __volatile__ ( \ 98 | "call solo5__xen_HYPERCALL_PAGE + %c[offset]" \ 99 | : "=a" (__res), "=D" (__ign1), "=S" (__ign2), "=d" (__ign3),\ 100 | "=&r" (__ign4) \ 101 | : [offset] "i" (hcall * 32), \ 102 | "1" ((long)(a1)), "2" ((long)(a2)), "3" ((long)(a3)), \ 103 | "4" (_a4) \ 104 | : "memory" ); \ 105 | (type)__res; \ 106 | }) 107 | 108 | #endif /* __XEN_HYPERCALL_X86_64_H__ */ 109 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/io/tpmif.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * tpmif.h 3 | * 4 | * TPM I/O interface for Xen guest OSes. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2005, IBM Corporation 25 | * 26 | * Author: Stefan Berger, stefanb@us.ibm.com 27 | * Grant table support: Mahadevan Gomathisankaran 28 | * 29 | * This code has been derived from tools/libxc/xen/io/netif.h 30 | * 31 | * Copyright (c) 2003-2004, Keir Fraser 32 | */ 33 | 34 | #ifndef __XEN_PUBLIC_IO_TPMIF_H__ 35 | #define __XEN_PUBLIC_IO_TPMIF_H__ 36 | 37 | #include "../grant_table.h" 38 | 39 | struct tpmif_tx_request { 40 | unsigned long addr; /* Machine address of packet. */ 41 | grant_ref_t ref; /* grant table access reference */ 42 | uint16_t unused; 43 | uint16_t size; /* Packet size in bytes. */ 44 | }; 45 | typedef struct tpmif_tx_request tpmif_tx_request_t; 46 | 47 | /* 48 | * The TPMIF_TX_RING_SIZE defines the number of pages the 49 | * front-end and backend can exchange (= size of array). 50 | */ 51 | typedef uint32_t TPMIF_RING_IDX; 52 | 53 | #define TPMIF_TX_RING_SIZE 1 54 | 55 | /* This structure must fit in a memory page. */ 56 | 57 | struct tpmif_ring { 58 | struct tpmif_tx_request req; 59 | }; 60 | typedef struct tpmif_ring tpmif_ring_t; 61 | 62 | struct tpmif_tx_interface { 63 | struct tpmif_ring ring[TPMIF_TX_RING_SIZE]; 64 | }; 65 | typedef struct tpmif_tx_interface tpmif_tx_interface_t; 66 | 67 | /****************************************************************************** 68 | * TPM I/O interface for Xen guest OSes, v2 69 | * 70 | * Author: Daniel De Graaf 71 | * 72 | * This protocol emulates the request/response behavior of a TPM using a Xen 73 | * shared memory interface. All interaction with the TPM is at the direction 74 | * of the frontend, since a TPM (hardware or virtual) is a passive device - 75 | * the backend only processes commands as requested by the frontend. 76 | * 77 | * The frontend sends a request to the TPM by populating the shared page with 78 | * the request packet, changing the state to TPMIF_STATE_SUBMIT, and sending 79 | * and event channel notification. When the backend is finished, it will set 80 | * the state to TPMIF_STATE_FINISH and send an event channel notification. 81 | * 82 | * In order to allow long-running commands to be canceled, the frontend can 83 | * at any time change the state to TPMIF_STATE_CANCEL and send a notification. 84 | * The TPM can either finish the command (changing state to TPMIF_STATE_FINISH) 85 | * or can cancel the command and change the state to TPMIF_STATE_IDLE. The TPM 86 | * can also change the state to TPMIF_STATE_IDLE instead of TPMIF_STATE_FINISH 87 | * if another reason for cancellation is required - for example, a physical 88 | * TPM may cancel a command if the interface is seized by another locality. 89 | * 90 | * The TPM command format is defined by the TCG, and is available at 91 | * http://www.trustedcomputinggroup.org/resources/tpm_main_specification 92 | */ 93 | 94 | enum tpmif_state { 95 | TPMIF_STATE_IDLE, /* no contents / vTPM idle / cancel complete */ 96 | TPMIF_STATE_SUBMIT, /* request ready / vTPM working */ 97 | TPMIF_STATE_FINISH, /* response ready / vTPM idle */ 98 | TPMIF_STATE_CANCEL, /* cancel requested / vTPM working */ 99 | }; 100 | /* Note: The backend should only change state to IDLE or FINISH, while the 101 | * frontend should only change to SUBMIT or CANCEL. Status changes do not need 102 | * to use atomic operations. 103 | */ 104 | 105 | 106 | /* The shared page for vTPM request/response packets looks like: 107 | * 108 | * Offset Contents 109 | * ================================================= 110 | * 0 struct tpmif_shared_page 111 | * 16 [optional] List of grant IDs 112 | * 16+4*nr_extra_pages TPM packet data 113 | * 114 | * If the TPM packet data extends beyond the end of a single page, the grant IDs 115 | * defined in extra_pages are used as if they were mapped immediately following 116 | * the primary shared page. The grants are allocated by the frontend and mapped 117 | * by the backend. Before sending a request spanning multiple pages, the 118 | * frontend should verify that the TPM supports such large requests by querying 119 | * the TPM_CAP_PROP_INPUT_BUFFER property from the TPM. 120 | */ 121 | struct tpmif_shared_page { 122 | uint32_t length; /* request/response length in bytes */ 123 | 124 | uint8_t state; /* enum tpmif_state */ 125 | uint8_t locality; /* for the current request */ 126 | uint8_t pad; /* should be zero */ 127 | 128 | uint8_t nr_extra_pages; /* extra pages for long packets; may be zero */ 129 | uint32_t extra_pages[0]; /* grant IDs; length is actually nr_extra_pages */ 130 | }; 131 | typedef struct tpmif_shared_page tpmif_shared_page_t; 132 | 133 | #endif 134 | 135 | /* 136 | * Local variables: 137 | * mode: C 138 | * c-file-style: "BSD" 139 | * c-basic-offset: 4 140 | * tab-width: 4 141 | * indent-tabs-mode: nil 142 | * End: 143 | */ 144 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/io/fsif.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * fsif.h 3 | * 4 | * Interface to FS level split device drivers. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2007, Grzegorz Milos, . 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_IO_FSIF_H__ 28 | #define __XEN_PUBLIC_IO_FSIF_H__ 29 | 30 | #include "ring.h" 31 | #include "../grant_table.h" 32 | 33 | #define REQ_FILE_OPEN 1 34 | #define REQ_FILE_CLOSE 2 35 | #define REQ_FILE_READ 3 36 | #define REQ_FILE_WRITE 4 37 | #define REQ_STAT 5 38 | #define REQ_FILE_TRUNCATE 6 39 | #define REQ_REMOVE 7 40 | #define REQ_RENAME 8 41 | #define REQ_CREATE 9 42 | #define REQ_DIR_LIST 10 43 | #define REQ_CHMOD 11 44 | #define REQ_FS_SPACE 12 45 | #define REQ_FILE_SYNC 13 46 | 47 | struct fsif_open_request { 48 | grant_ref_t gref; 49 | }; 50 | 51 | struct fsif_close_request { 52 | uint32_t fd; 53 | }; 54 | 55 | struct fsif_read_request { 56 | uint32_t fd; 57 | int32_t pad; 58 | uint64_t len; 59 | uint64_t offset; 60 | grant_ref_t grefs[1]; /* Variable length */ 61 | }; 62 | 63 | struct fsif_write_request { 64 | uint32_t fd; 65 | int32_t pad; 66 | uint64_t len; 67 | uint64_t offset; 68 | grant_ref_t grefs[1]; /* Variable length */ 69 | }; 70 | 71 | struct fsif_stat_request { 72 | uint32_t fd; 73 | }; 74 | 75 | /* This structure is a copy of some fields from stat structure, returned 76 | * via the ring. */ 77 | struct fsif_stat_response { 78 | int32_t stat_mode; 79 | uint32_t stat_uid; 80 | uint32_t stat_gid; 81 | int32_t stat_ret; 82 | int64_t stat_size; 83 | int64_t stat_atime; 84 | int64_t stat_mtime; 85 | int64_t stat_ctime; 86 | }; 87 | 88 | struct fsif_truncate_request { 89 | uint32_t fd; 90 | int32_t pad; 91 | int64_t length; 92 | }; 93 | 94 | struct fsif_remove_request { 95 | grant_ref_t gref; 96 | }; 97 | 98 | struct fsif_rename_request { 99 | uint16_t old_name_offset; 100 | uint16_t new_name_offset; 101 | grant_ref_t gref; 102 | }; 103 | 104 | struct fsif_create_request { 105 | int8_t directory; 106 | int8_t pad; 107 | int16_t pad2; 108 | int32_t mode; 109 | grant_ref_t gref; 110 | }; 111 | 112 | struct fsif_list_request { 113 | uint32_t offset; 114 | grant_ref_t gref; 115 | }; 116 | 117 | #define NR_FILES_SHIFT 0 118 | #define NR_FILES_SIZE 16 /* 16 bits for the number of files mask */ 119 | #define NR_FILES_MASK (((1ULL << NR_FILES_SIZE) - 1) << NR_FILES_SHIFT) 120 | #define ERROR_SIZE 32 /* 32 bits for the error mask */ 121 | #define ERROR_SHIFT (NR_FILES_SIZE + NR_FILES_SHIFT) 122 | #define ERROR_MASK (((1ULL << ERROR_SIZE) - 1) << ERROR_SHIFT) 123 | #define HAS_MORE_SHIFT (ERROR_SHIFT + ERROR_SIZE) 124 | #define HAS_MORE_FLAG (1ULL << HAS_MORE_SHIFT) 125 | 126 | struct fsif_chmod_request { 127 | uint32_t fd; 128 | int32_t mode; 129 | }; 130 | 131 | struct fsif_space_request { 132 | grant_ref_t gref; 133 | }; 134 | 135 | struct fsif_sync_request { 136 | uint32_t fd; 137 | }; 138 | 139 | 140 | /* FS operation request */ 141 | struct fsif_request { 142 | uint8_t type; /* Type of the request */ 143 | uint8_t pad; 144 | uint16_t id; /* Request ID, copied to the response */ 145 | uint32_t pad2; 146 | union { 147 | struct fsif_open_request fopen; 148 | struct fsif_close_request fclose; 149 | struct fsif_read_request fread; 150 | struct fsif_write_request fwrite; 151 | struct fsif_stat_request fstat; 152 | struct fsif_truncate_request ftruncate; 153 | struct fsif_remove_request fremove; 154 | struct fsif_rename_request frename; 155 | struct fsif_create_request fcreate; 156 | struct fsif_list_request flist; 157 | struct fsif_chmod_request fchmod; 158 | struct fsif_space_request fspace; 159 | struct fsif_sync_request fsync; 160 | } u; 161 | }; 162 | typedef struct fsif_request fsif_request_t; 163 | 164 | /* FS operation response */ 165 | struct fsif_response { 166 | uint16_t id; 167 | uint16_t pad1; 168 | uint32_t pad2; 169 | union { 170 | uint64_t ret_val; 171 | struct fsif_stat_response fstat; 172 | } u; 173 | }; 174 | 175 | typedef struct fsif_response fsif_response_t; 176 | 177 | #define FSIF_RING_ENTRY_SIZE 64 178 | 179 | #define FSIF_NR_READ_GNTS ((FSIF_RING_ENTRY_SIZE - sizeof(struct fsif_read_request)) / \ 180 | sizeof(grant_ref_t) + 1) 181 | #define FSIF_NR_WRITE_GNTS ((FSIF_RING_ENTRY_SIZE - sizeof(struct fsif_write_request)) / \ 182 | sizeof(grant_ref_t) + 1) 183 | 184 | DEFINE_RING_TYPES(fsif, struct fsif_request, struct fsif_response); 185 | 186 | #define STATE_INITIALISED "init" 187 | #define STATE_READY "ready" 188 | #define STATE_CLOSING "closing" 189 | #define STATE_CLOSED "closed" 190 | 191 | 192 | #endif 193 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/io/fbif.h: -------------------------------------------------------------------------------- 1 | /* 2 | * fbif.h -- Xen virtual frame buffer device 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * 22 | * Copyright (C) 2005 Anthony Liguori 23 | * Copyright (C) 2006 Red Hat, Inc., Markus Armbruster 24 | */ 25 | 26 | #ifndef __XEN_PUBLIC_IO_FBIF_H__ 27 | #define __XEN_PUBLIC_IO_FBIF_H__ 28 | 29 | /* Out events (frontend -> backend) */ 30 | 31 | /* 32 | * Out events may be sent only when requested by backend, and receipt 33 | * of an unknown out event is an error. 34 | */ 35 | 36 | /* Event type 1 currently not used */ 37 | /* 38 | * Framebuffer update notification event 39 | * Capable frontend sets feature-update in xenstore. 40 | * Backend requests it by setting request-update in xenstore. 41 | */ 42 | #define XENFB_TYPE_UPDATE 2 43 | 44 | struct xenfb_update 45 | { 46 | uint8_t type; /* XENFB_TYPE_UPDATE */ 47 | int32_t x; /* source x */ 48 | int32_t y; /* source y */ 49 | int32_t width; /* rect width */ 50 | int32_t height; /* rect height */ 51 | }; 52 | 53 | /* 54 | * Framebuffer resize notification event 55 | * Capable backend sets feature-resize in xenstore. 56 | */ 57 | #define XENFB_TYPE_RESIZE 3 58 | 59 | struct xenfb_resize 60 | { 61 | uint8_t type; /* XENFB_TYPE_RESIZE */ 62 | int32_t width; /* width in pixels */ 63 | int32_t height; /* height in pixels */ 64 | int32_t stride; /* stride in bytes */ 65 | int32_t depth; /* depth in bits */ 66 | int32_t offset; /* offset of the framebuffer in bytes */ 67 | }; 68 | 69 | #define XENFB_OUT_EVENT_SIZE 40 70 | 71 | union xenfb_out_event 72 | { 73 | uint8_t type; 74 | struct xenfb_update update; 75 | struct xenfb_resize resize; 76 | char pad[XENFB_OUT_EVENT_SIZE]; 77 | }; 78 | 79 | /* In events (backend -> frontend) */ 80 | 81 | /* 82 | * Frontends should ignore unknown in events. 83 | */ 84 | 85 | /* 86 | * Framebuffer refresh period advice 87 | * Backend sends it to advise the frontend their preferred period of 88 | * refresh. Frontends that keep the framebuffer constantly up-to-date 89 | * just ignore it. Frontends that use the advice should immediately 90 | * refresh the framebuffer (and send an update notification event if 91 | * those have been requested), then use the update frequency to guide 92 | * their periodical refreshs. 93 | */ 94 | #define XENFB_TYPE_REFRESH_PERIOD 1 95 | #define XENFB_NO_REFRESH 0 96 | 97 | struct xenfb_refresh_period 98 | { 99 | uint8_t type; /* XENFB_TYPE_UPDATE_PERIOD */ 100 | uint32_t period; /* period of refresh, in ms, 101 | * XENFB_NO_REFRESH if no refresh is needed */ 102 | }; 103 | 104 | #define XENFB_IN_EVENT_SIZE 40 105 | 106 | union xenfb_in_event 107 | { 108 | uint8_t type; 109 | struct xenfb_refresh_period refresh_period; 110 | char pad[XENFB_IN_EVENT_SIZE]; 111 | }; 112 | 113 | /* shared page */ 114 | 115 | #define XENFB_IN_RING_SIZE 1024 116 | #define XENFB_IN_RING_LEN (XENFB_IN_RING_SIZE / XENFB_IN_EVENT_SIZE) 117 | #define XENFB_IN_RING_OFFS 1024 118 | #define XENFB_IN_RING(page) \ 119 | ((union xenfb_in_event *)((char *)(page) + XENFB_IN_RING_OFFS)) 120 | #define XENFB_IN_RING_REF(page, idx) \ 121 | (XENFB_IN_RING((page))[(idx) % XENFB_IN_RING_LEN]) 122 | 123 | #define XENFB_OUT_RING_SIZE 2048 124 | #define XENFB_OUT_RING_LEN (XENFB_OUT_RING_SIZE / XENFB_OUT_EVENT_SIZE) 125 | #define XENFB_OUT_RING_OFFS (XENFB_IN_RING_OFFS + XENFB_IN_RING_SIZE) 126 | #define XENFB_OUT_RING(page) \ 127 | ((union xenfb_out_event *)((char *)(page) + XENFB_OUT_RING_OFFS)) 128 | #define XENFB_OUT_RING_REF(page, idx) \ 129 | (XENFB_OUT_RING((page))[(idx) % XENFB_OUT_RING_LEN]) 130 | 131 | struct xenfb_page 132 | { 133 | uint32_t in_cons, in_prod; 134 | uint32_t out_cons, out_prod; 135 | 136 | int32_t width; /* the width of the framebuffer (in pixels) */ 137 | int32_t height; /* the height of the framebuffer (in pixels) */ 138 | uint32_t line_length; /* the length of a row of pixels (in bytes) */ 139 | uint32_t mem_length; /* the length of the framebuffer (in bytes) */ 140 | uint8_t depth; /* the depth of a pixel (in bits) */ 141 | 142 | /* 143 | * Framebuffer page directory 144 | * 145 | * Each directory page holds PAGE_SIZE / sizeof(*pd) 146 | * framebuffer pages, and can thus map up to PAGE_SIZE * 147 | * PAGE_SIZE / sizeof(*pd) bytes. With PAGE_SIZE == 4096 and 148 | * sizeof(unsigned long) == 4/8, that's 4 Megs 32 bit and 2 Megs 149 | * 64 bit. 256 directories give enough room for a 512 Meg 150 | * framebuffer with a max resolution of 12,800x10,240. Should 151 | * be enough for a while with room leftover for expansion. 152 | */ 153 | unsigned long pd[256]; 154 | }; 155 | 156 | /* 157 | * Wart: xenkbd needs to know default resolution. Put it here until a 158 | * better solution is found, but don't leak it to the backend. 159 | */ 160 | #ifdef __KERNEL__ 161 | #define XENFB_WIDTH 800 162 | #define XENFB_HEIGHT 600 163 | #define XENFB_DEPTH 32 164 | #endif 165 | 166 | #endif 167 | 168 | /* 169 | * Local variables: 170 | * mode: C 171 | * c-file-style: "BSD" 172 | * c-basic-offset: 4 173 | * tab-width: 4 174 | * indent-tabs-mode: nil 175 | * End: 176 | */ 177 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/xsm/flask_op.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains the flask_op hypercall commands and definitions. 3 | * 4 | * Author: George Coker, 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef __FLASK_OP_H__ 26 | #define __FLASK_OP_H__ 27 | 28 | #include "../event_channel.h" 29 | 30 | #define XEN_FLASK_INTERFACE_VERSION 1 31 | 32 | struct xen_flask_load { 33 | XEN_GUEST_HANDLE(char) buffer; 34 | uint32_t size; 35 | }; 36 | 37 | struct xen_flask_setenforce { 38 | uint32_t enforcing; 39 | }; 40 | 41 | struct xen_flask_sid_context { 42 | /* IN/OUT: sid to convert to/from string */ 43 | uint32_t sid; 44 | /* IN: size of the context buffer 45 | * OUT: actual size of the output context string 46 | */ 47 | uint32_t size; 48 | XEN_GUEST_HANDLE(char) context; 49 | }; 50 | 51 | struct xen_flask_access { 52 | /* IN: access request */ 53 | uint32_t ssid; 54 | uint32_t tsid; 55 | uint32_t tclass; 56 | uint32_t req; 57 | /* OUT: AVC data */ 58 | uint32_t allowed; 59 | uint32_t audit_allow; 60 | uint32_t audit_deny; 61 | uint32_t seqno; 62 | }; 63 | 64 | struct xen_flask_transition { 65 | /* IN: transition SIDs and class */ 66 | uint32_t ssid; 67 | uint32_t tsid; 68 | uint32_t tclass; 69 | /* OUT: new SID */ 70 | uint32_t newsid; 71 | }; 72 | 73 | #if __XEN_INTERFACE_VERSION__ < 0x00040800 74 | struct xen_flask_userlist { 75 | /* IN: starting SID for list */ 76 | uint32_t start_sid; 77 | /* IN: size of user string and output buffer 78 | * OUT: number of SIDs returned */ 79 | uint32_t size; 80 | union { 81 | /* IN: user to enumerate SIDs */ 82 | XEN_GUEST_HANDLE(char) user; 83 | /* OUT: SID list */ 84 | XEN_GUEST_HANDLE(uint32) sids; 85 | } u; 86 | }; 87 | #endif 88 | 89 | struct xen_flask_boolean { 90 | /* IN/OUT: numeric identifier for boolean [GET/SET] 91 | * If -1, name will be used and bool_id will be filled in. */ 92 | uint32_t bool_id; 93 | /* OUT: current enforcing value of boolean [GET/SET] */ 94 | uint8_t enforcing; 95 | /* OUT: pending value of boolean [GET/SET] */ 96 | uint8_t pending; 97 | /* IN: new value of boolean [SET] */ 98 | uint8_t new_value; 99 | /* IN: commit new value instead of only setting pending [SET] */ 100 | uint8_t commit; 101 | /* IN: size of boolean name buffer [GET/SET] 102 | * OUT: actual size of name [GET only] */ 103 | uint32_t size; 104 | /* IN: if bool_id is -1, used to find boolean [GET/SET] 105 | * OUT: textual name of boolean [GET only] 106 | */ 107 | XEN_GUEST_HANDLE(char) name; 108 | }; 109 | 110 | struct xen_flask_setavc_threshold { 111 | /* IN */ 112 | uint32_t threshold; 113 | }; 114 | 115 | struct xen_flask_hash_stats { 116 | /* OUT */ 117 | uint32_t entries; 118 | uint32_t buckets_used; 119 | uint32_t buckets_total; 120 | uint32_t max_chain_len; 121 | }; 122 | 123 | struct xen_flask_cache_stats { 124 | /* IN */ 125 | uint32_t cpu; 126 | /* OUT */ 127 | uint32_t lookups; 128 | uint32_t hits; 129 | uint32_t misses; 130 | uint32_t allocations; 131 | uint32_t reclaims; 132 | uint32_t frees; 133 | }; 134 | 135 | struct xen_flask_ocontext { 136 | /* IN */ 137 | uint32_t ocon; 138 | uint32_t sid; 139 | uint64_t low, high; 140 | }; 141 | 142 | struct xen_flask_peersid { 143 | /* IN */ 144 | evtchn_port_t evtchn; 145 | /* OUT */ 146 | uint32_t sid; 147 | }; 148 | 149 | struct xen_flask_relabel { 150 | /* IN */ 151 | uint32_t domid; 152 | uint32_t sid; 153 | }; 154 | 155 | struct xen_flask_devicetree_label { 156 | /* IN */ 157 | uint32_t sid; 158 | uint32_t length; 159 | XEN_GUEST_HANDLE(char) path; 160 | }; 161 | 162 | struct xen_flask_op { 163 | uint32_t cmd; 164 | #define FLASK_LOAD 1 165 | #define FLASK_GETENFORCE 2 166 | #define FLASK_SETENFORCE 3 167 | #define FLASK_CONTEXT_TO_SID 4 168 | #define FLASK_SID_TO_CONTEXT 5 169 | #define FLASK_ACCESS 6 170 | #define FLASK_CREATE 7 171 | #define FLASK_RELABEL 8 172 | #define FLASK_USER 9 /* No longer implemented */ 173 | #define FLASK_POLICYVERS 10 174 | #define FLASK_GETBOOL 11 175 | #define FLASK_SETBOOL 12 176 | #define FLASK_COMMITBOOLS 13 177 | #define FLASK_MLS 14 178 | #define FLASK_DISABLE 15 179 | #define FLASK_GETAVC_THRESHOLD 16 180 | #define FLASK_SETAVC_THRESHOLD 17 181 | #define FLASK_AVC_HASHSTATS 18 182 | #define FLASK_AVC_CACHESTATS 19 183 | #define FLASK_MEMBER 20 184 | #define FLASK_ADD_OCONTEXT 21 185 | #define FLASK_DEL_OCONTEXT 22 186 | #define FLASK_GET_PEER_SID 23 187 | #define FLASK_RELABEL_DOMAIN 24 188 | #define FLASK_DEVICETREE_LABEL 25 189 | uint32_t interface_version; /* XEN_FLASK_INTERFACE_VERSION */ 190 | union { 191 | struct xen_flask_load load; 192 | struct xen_flask_setenforce enforce; 193 | /* FLASK_CONTEXT_TO_SID and FLASK_SID_TO_CONTEXT */ 194 | struct xen_flask_sid_context sid_context; 195 | struct xen_flask_access access; 196 | /* FLASK_CREATE, FLASK_RELABEL, FLASK_MEMBER */ 197 | struct xen_flask_transition transition; 198 | #if __XEN_INTERFACE_VERSION__ < 0x00040800 199 | struct xen_flask_userlist userlist; 200 | #endif 201 | /* FLASK_GETBOOL, FLASK_SETBOOL */ 202 | struct xen_flask_boolean boolean; 203 | struct xen_flask_setavc_threshold setavc_threshold; 204 | struct xen_flask_hash_stats hash_stats; 205 | struct xen_flask_cache_stats cache_stats; 206 | /* FLASK_ADD_OCONTEXT, FLASK_DEL_OCONTEXT */ 207 | struct xen_flask_ocontext ocontext; 208 | struct xen_flask_peersid peersid; 209 | struct xen_flask_relabel relabel; 210 | struct xen_flask_devicetree_label devicetree_label; 211 | } u; 212 | }; 213 | typedef struct xen_flask_op xen_flask_op_t; 214 | DEFINE_XEN_GUEST_HANDLE(xen_flask_op_t); 215 | 216 | #endif 217 | -------------------------------------------------------------------------------- /lib/bindings/hypercall.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2020 Contributors as noted in the AUTHORS file 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software 5 | * for any purpose with or without fee is hereby granted, provided 6 | * that the above copyright notice and this permission notice appear 7 | * in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR 13 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 14 | * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 15 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 16 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef __XEN_HYPERCALL_H__ 20 | #define __XEN_HYPERCALL_H__ 21 | 22 | #include "bindings.h" 23 | 24 | #if defined(__x86_64__) 25 | #include "hypercall-x86_64.h" 26 | #define HYPERCALL1 _hypercall64_1 27 | #define HYPERCALL2 _hypercall64_2 28 | #define HYPERCALL3 _hypercall64_3 29 | #define HYPERCALL4 _hypercall64_4 30 | #else 31 | #error Not implemented 32 | #endif 33 | 34 | #include "xen/event_channel.h" 35 | #include "xen/grant_table.h" 36 | #include "xen/hvm/hvm_op.h" 37 | #include "xen/memory.h" 38 | #include "xen/sched.h" 39 | #include "xen/vcpu.h" 40 | #include "xen/xen.h" 41 | 42 | /* 43 | * Hypercall primitives. 44 | */ 45 | static inline long hypercall__memory_op(unsigned int cmd, void *arg) 46 | { 47 | return HYPERCALL2(long, __HYPERVISOR_memory_op, cmd, arg); 48 | } 49 | 50 | static inline long hypercall__sched_op(unsigned int cmd, void *arg) 51 | { 52 | return HYPERCALL2(long, __HYPERVISOR_sched_op, cmd, arg); 53 | } 54 | 55 | static inline long hypercall__event_channel_op(unsigned int cmd, void *arg) 56 | { 57 | return HYPERCALL2(long, __HYPERVISOR_event_channel_op, cmd, arg); 58 | } 59 | 60 | static inline long hypercall__hvm_op(unsigned int cmd, void *arg) 61 | { 62 | return HYPERCALL2(long, __HYPERVISOR_hvm_op, cmd, arg); 63 | } 64 | 65 | static inline long hypercall__grant_table_op(unsigned int cmd, void *args, 66 | unsigned int count /* # of entries in args[] */) 67 | { 68 | return HYPERCALL3(long, __HYPERVISOR_grant_table_op, cmd, args, count); 69 | } 70 | 71 | /* 72 | * Higher level hypercall helpers, type-safe. 73 | */ 74 | static inline int hypercall_evtchn_alloc_unbound(domid_t remote, 75 | evtchn_port_t *port) 76 | { 77 | evtchn_alloc_unbound_t op = { 78 | .dom = DOMID_SELF, 79 | .remote_dom = remote 80 | }; 81 | 82 | int rc = hypercall__event_channel_op(EVTCHNOP_alloc_unbound, &op); 83 | 84 | if (rc == 0) 85 | *port = op.port; 86 | return rc; 87 | } 88 | 89 | static inline int hypercall_evtchn_bind_interdomain(domid_t remote, 90 | evtchn_port_t remote_port, evtchn_port_t *local_port) 91 | { 92 | evtchn_bind_interdomain_t op = { 93 | .remote_dom = remote, 94 | .remote_port = remote_port 95 | }; 96 | 97 | int rc = hypercall__event_channel_op(EVTCHNOP_bind_interdomain, &op); 98 | 99 | if (rc == 0) 100 | *local_port = op.local_port; 101 | return rc; 102 | } 103 | 104 | static inline int hypercall_evtchn_bind_virq(uint32_t virq, uint32_t vcpu, 105 | evtchn_port_t *port) 106 | { 107 | evtchn_bind_virq_t op = { 108 | .virq = virq, 109 | .vcpu = vcpu 110 | }; 111 | int rc = hypercall__event_channel_op(EVTCHNOP_bind_virq, &op); 112 | 113 | if (rc == 0) 114 | *port = op.port; 115 | return rc; 116 | } 117 | 118 | static inline int hypercall_evtchn_close(evtchn_port_t port) 119 | { 120 | evtchn_close_t op = { 121 | .port = port 122 | }; 123 | return hypercall__event_channel_op(EVTCHNOP_close, &op); 124 | } 125 | 126 | static inline int hypercall_evtchn_send(evtchn_port_t port) 127 | { 128 | return hypercall__event_channel_op(EVTCHNOP_send, &port); 129 | } 130 | 131 | static inline void hypercall_evtchn_unmask(evtchn_port_t port) 132 | { 133 | evtchn_unmask_t op = { 134 | .port = port 135 | }; 136 | 137 | (void)hypercall__event_channel_op(EVTCHNOP_unmask, &op); 138 | } 139 | 140 | static inline int hypercall_gnttab_map_grant_ref(uint64_t host_addr, 141 | uint32_t flags, grant_ref_t ref, domid_t dom, 142 | grant_handle_t *out_handle, uint64_t *out_dev_bus_addr) 143 | { 144 | gnttab_map_grant_ref_t op = { 145 | .host_addr = host_addr, 146 | .flags = flags, 147 | .ref = ref, 148 | .dom = dom, 149 | }; 150 | int rc = hypercall__grant_table_op(GNTTABOP_map_grant_ref, &op, 1); 151 | /* 152 | * Always set these, otherwise GCC warns that handle may be used 153 | * unitialised in caller. 154 | */ 155 | *out_handle = op.handle; 156 | *out_dev_bus_addr = op.dev_bus_addr; 157 | if (rc == 0 && op.status < 0) 158 | rc = -op.status; 159 | return rc; 160 | } 161 | 162 | static inline int hypercall_gnttab_unmap_grant_ref(uint64_t host_addr, 163 | uint64_t dev_bus_addr, grant_handle_t handle) 164 | { 165 | gnttab_unmap_grant_ref_t op = { 166 | .host_addr = host_addr, 167 | .dev_bus_addr = dev_bus_addr, 168 | .handle = handle 169 | }; 170 | int rc = hypercall__grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); 171 | if (rc == 0 && op.status < 0) 172 | rc = -op.status; 173 | return rc; 174 | } 175 | 176 | static inline int hypercall_hvm_get_param(unsigned int idx, uint64_t *value) 177 | { 178 | xen_hvm_param_t p = { 179 | .domid = DOMID_SELF, 180 | .index = idx 181 | }; 182 | int rc = hypercall__hvm_op(HVMOP_get_param, &p); 183 | 184 | if (rc == 0) 185 | *value = p.value; 186 | return rc; 187 | } 188 | 189 | static inline int hypercall_hvm_set_param(unsigned int idx, uint64_t value) 190 | { 191 | xen_hvm_param_t p = { 192 | .domid = DOMID_SELF, 193 | .index = idx, 194 | .value = value 195 | }; 196 | 197 | return hypercall__hvm_op(HVMOP_set_param, &p); 198 | } 199 | 200 | static inline int hypercall_physmap_add_shared_info(unsigned int idx, 201 | uint64_t gpfn) 202 | { 203 | xen_add_to_physmap_t add = { 204 | .domid = DOMID_SELF, 205 | .space = XENMAPSPACE_shared_info, 206 | .idx = idx, 207 | .gpfn = gpfn 208 | }; 209 | 210 | return hypercall__memory_op(XENMEM_add_to_physmap, &add); 211 | } 212 | 213 | static inline int hypercall_physmap_add_grant_table(unsigned int idx, 214 | uint64_t gpfn) 215 | { 216 | xen_add_to_physmap_t add = { 217 | .domid = DOMID_SELF, 218 | .space = XENMAPSPACE_grant_table, 219 | .idx = idx, 220 | .gpfn = gpfn 221 | }; 222 | 223 | return hypercall__memory_op(XENMEM_add_to_physmap, &add); 224 | } 225 | 226 | static inline int hypercall_set_timer_op(uint64_t deadline) 227 | { 228 | return HYPERCALL1(long, __HYPERVISOR_set_timer_op, deadline); 229 | } 230 | 231 | static inline void hypercall_shutdown(unsigned int reason) 232 | { 233 | (void)hypercall__sched_op(SCHEDOP_shutdown, &reason); 234 | } 235 | 236 | static inline void hypercall_yield(void) 237 | { 238 | (void)hypercall__sched_op(SCHEDOP_yield, NULL); 239 | } 240 | 241 | #endif /* __XEN_HYPERCALL_H__ */ 242 | -------------------------------------------------------------------------------- /lib/bindings/include/xen/arch-x86/xen-x86_32.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * xen-x86_32.h 3 | * 4 | * Guest OS interface to x86 32-bit Xen. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | * 24 | * Copyright (c) 2004-2007, K A Fraser 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__ 28 | #define __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__ 29 | 30 | /* 31 | * Hypercall interface: 32 | * Input: %ebx, %ecx, %edx, %esi, %edi, %ebp (arguments 1-6) 33 | * Output: %eax 34 | * Access is via hypercall page (set up by guest loader or via a Xen MSR): 35 | * call hypercall_page + hypercall-number * 32 36 | * Clobbered: Argument registers (e.g., 2-arg hypercall clobbers %ebx,%ecx) 37 | */ 38 | 39 | /* 40 | * These flat segments are in the Xen-private section of every GDT. Since these 41 | * are also present in the initial GDT, many OSes will be able to avoid 42 | * installing their own GDT. 43 | */ 44 | #define FLAT_RING1_CS 0xe019 /* GDT index 259 */ 45 | #define FLAT_RING1_DS 0xe021 /* GDT index 260 */ 46 | #define FLAT_RING1_SS 0xe021 /* GDT index 260 */ 47 | #define FLAT_RING3_CS 0xe02b /* GDT index 261 */ 48 | #define FLAT_RING3_DS 0xe033 /* GDT index 262 */ 49 | #define FLAT_RING3_SS 0xe033 /* GDT index 262 */ 50 | 51 | #define FLAT_KERNEL_CS FLAT_RING1_CS 52 | #define FLAT_KERNEL_DS FLAT_RING1_DS 53 | #define FLAT_KERNEL_SS FLAT_RING1_SS 54 | #define FLAT_USER_CS FLAT_RING3_CS 55 | #define FLAT_USER_DS FLAT_RING3_DS 56 | #define FLAT_USER_SS FLAT_RING3_SS 57 | 58 | #define __HYPERVISOR_VIRT_START_PAE 0xF5800000 59 | #define __MACH2PHYS_VIRT_START_PAE 0xF5800000 60 | #define __MACH2PHYS_VIRT_END_PAE 0xF6800000 61 | #define HYPERVISOR_VIRT_START_PAE xen_mk_ulong(__HYPERVISOR_VIRT_START_PAE) 62 | #define MACH2PHYS_VIRT_START_PAE xen_mk_ulong(__MACH2PHYS_VIRT_START_PAE) 63 | #define MACH2PHYS_VIRT_END_PAE xen_mk_ulong(__MACH2PHYS_VIRT_END_PAE) 64 | 65 | /* Non-PAE bounds are obsolete. */ 66 | #define __HYPERVISOR_VIRT_START_NONPAE 0xFC000000 67 | #define __MACH2PHYS_VIRT_START_NONPAE 0xFC000000 68 | #define __MACH2PHYS_VIRT_END_NONPAE 0xFC400000 69 | #define HYPERVISOR_VIRT_START_NONPAE \ 70 | xen_mk_ulong(__HYPERVISOR_VIRT_START_NONPAE) 71 | #define MACH2PHYS_VIRT_START_NONPAE \ 72 | xen_mk_ulong(__MACH2PHYS_VIRT_START_NONPAE) 73 | #define MACH2PHYS_VIRT_END_NONPAE \ 74 | xen_mk_ulong(__MACH2PHYS_VIRT_END_NONPAE) 75 | 76 | #define __HYPERVISOR_VIRT_START __HYPERVISOR_VIRT_START_PAE 77 | #define __MACH2PHYS_VIRT_START __MACH2PHYS_VIRT_START_PAE 78 | #define __MACH2PHYS_VIRT_END __MACH2PHYS_VIRT_END_PAE 79 | 80 | #ifndef HYPERVISOR_VIRT_START 81 | #define HYPERVISOR_VIRT_START xen_mk_ulong(__HYPERVISOR_VIRT_START) 82 | #endif 83 | 84 | #define MACH2PHYS_VIRT_START xen_mk_ulong(__MACH2PHYS_VIRT_START) 85 | #define MACH2PHYS_VIRT_END xen_mk_ulong(__MACH2PHYS_VIRT_END) 86 | #define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>2) 87 | #ifndef machine_to_phys_mapping 88 | #define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START) 89 | #endif 90 | 91 | /* 32-/64-bit invariability for control interfaces (domctl/sysctl). */ 92 | #if defined(__XEN__) || defined(__XEN_TOOLS__) 93 | #undef ___DEFINE_XEN_GUEST_HANDLE 94 | #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \ 95 | typedef struct { type *p; } \ 96 | __guest_handle_ ## name; \ 97 | typedef struct { union { type *p; uint64_aligned_t q; }; } \ 98 | __guest_handle_64_ ## name 99 | #undef set_xen_guest_handle_raw 100 | #define set_xen_guest_handle_raw(hnd, val) \ 101 | do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0; \ 102 | (hnd).p = val; \ 103 | } while ( 0 ) 104 | #define int64_aligned_t int64_t __attribute__((aligned(8))) 105 | #define uint64_aligned_t uint64_t __attribute__((aligned(8))) 106 | #define __XEN_GUEST_HANDLE_64(name) __guest_handle_64_ ## name 107 | #define XEN_GUEST_HANDLE_64(name) __XEN_GUEST_HANDLE_64(name) 108 | #endif 109 | 110 | #ifndef __ASSEMBLY__ 111 | 112 | #if defined(XEN_GENERATING_COMPAT_HEADERS) 113 | /* nothing */ 114 | #elif defined(__XEN__) || defined(__XEN_TOOLS__) 115 | /* Anonymous unions include all permissible names (e.g., al/ah/ax/eax). */ 116 | #define __DECL_REG_LO8(which) union { \ 117 | uint32_t e ## which ## x; \ 118 | uint16_t which ## x; \ 119 | struct { \ 120 | uint8_t which ## l; \ 121 | uint8_t which ## h; \ 122 | }; \ 123 | } 124 | #define __DECL_REG_LO16(name) union { \ 125 | uint32_t e ## name, _e ## name; \ 126 | uint16_t name; \ 127 | } 128 | #else 129 | /* Other sources must always use the proper 32-bit name (e.g., eax). */ 130 | #define __DECL_REG_LO8(which) uint32_t e ## which ## x 131 | #define __DECL_REG_LO16(name) uint32_t e ## name 132 | #endif 133 | 134 | struct cpu_user_regs { 135 | __DECL_REG_LO8(b); 136 | __DECL_REG_LO8(c); 137 | __DECL_REG_LO8(d); 138 | __DECL_REG_LO16(si); 139 | __DECL_REG_LO16(di); 140 | __DECL_REG_LO16(bp); 141 | __DECL_REG_LO8(a); 142 | uint16_t error_code; /* private */ 143 | uint16_t entry_vector; /* private */ 144 | __DECL_REG_LO16(ip); 145 | uint16_t cs; 146 | uint8_t saved_upcall_mask; 147 | uint8_t _pad0; 148 | __DECL_REG_LO16(flags); /* eflags.IF == !saved_upcall_mask */ 149 | __DECL_REG_LO16(sp); 150 | uint16_t ss, _pad1; 151 | uint16_t es, _pad2; 152 | uint16_t ds, _pad3; 153 | uint16_t fs, _pad4; 154 | uint16_t gs, _pad5; 155 | }; 156 | typedef struct cpu_user_regs cpu_user_regs_t; 157 | DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t); 158 | 159 | #undef __DECL_REG_LO8 160 | #undef __DECL_REG_LO16 161 | 162 | /* 163 | * Page-directory addresses above 4GB do not fit into architectural %cr3. 164 | * When accessing %cr3, or equivalent field in vcpu_guest_context, guests 165 | * must use the following accessor macros to pack/unpack valid MFNs. 166 | */ 167 | #define xen_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20)) 168 | #define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20)) 169 | 170 | struct arch_vcpu_info { 171 | unsigned long cr2; 172 | unsigned long pad[5]; /* sizeof(vcpu_info_t) == 64 */ 173 | }; 174 | typedef struct arch_vcpu_info arch_vcpu_info_t; 175 | 176 | struct xen_callback { 177 | unsigned long cs; 178 | unsigned long eip; 179 | }; 180 | typedef struct xen_callback xen_callback_t; 181 | 182 | #endif /* !__ASSEMBLY__ */ 183 | 184 | #endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__ */ 185 | 186 | /* 187 | * Local variables: 188 | * mode: C 189 | * c-file-style: "BSD" 190 | * c-basic-offset: 4 191 | * tab-width: 4 192 | * indent-tabs-mode: nil 193 | * End: 194 | */ 195 | -------------------------------------------------------------------------------- /lib/bindings/bmap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Martin Lucina 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #ifndef TEST_STANDALONE 24 | #include "bindings.h" 25 | #else 26 | #define PAGE_SIZE 4096 27 | #endif 28 | 29 | /* 30 | * This is a simple bitmap allocator for virtual memory addresses. Worst-case 31 | * performance for bmap_alloc() is O(n), where n = total_pages / 8. bmap_free() 32 | * is O(1) but requires the caller to keep the size of the allocated block. 33 | */ 34 | struct bmap_allocator { 35 | long *bmap; /* 1 bit per page; 1=free, 0=used */ 36 | size_t bmap_size; /* # of words in bmap[] */ 37 | uint64_t start_addr; /* starting virtual memory address */ 38 | }; 39 | 40 | #define BPW (sizeof(long) * 8) 41 | _Static_assert(sizeof(long) == 8, "long must be 64 bits"); 42 | 43 | /* 44 | * Returns 0-based index of first set bit in (bmap[]), starting with the bit 45 | * index (at), or -1 if none found and end of (bmap[]) was reached. 46 | */ 47 | static int ffs_at(long *bmap, size_t bmap_size, int at) 48 | { 49 | int word = at / BPW; 50 | int shift = at % BPW; 51 | int bit = 0; 52 | int i; 53 | 54 | for (i = word; i < bmap_size; i++) { 55 | if (i == word) 56 | /* (at) is not on a word boundary; shift so we can use ffsl */ 57 | bit = __builtin_ffsl(bmap[i] >> shift); 58 | else 59 | bit = __builtin_ffsl(bmap[i]); 60 | if (bit) 61 | break; 62 | } 63 | 64 | if (bit) { 65 | if (i == word) 66 | /* Restore previous shift if any */ 67 | bit += shift; 68 | return (i * BPW) + (bit - 1); 69 | } 70 | else 71 | return -1; 72 | } 73 | 74 | /* 75 | * Returns 0-based index of first clear bit in (bmap[]), starting with the bit 76 | * index (at), or -1 if none found and end of (bmap[]) was reached. 77 | */ 78 | static int ffc_at(long *bmap, size_t bmap_size, int at) 79 | { 80 | int word = at / BPW; 81 | int shift = at % BPW; 82 | int bit = 0; 83 | int i; 84 | 85 | for (i = word; i < bmap_size; i++) { 86 | if (i == word) 87 | /* (at) is not on a word boundary; shift so we can use ffsl */ 88 | bit = __builtin_ffsl(~bmap[i] >> shift); 89 | else 90 | bit = __builtin_ffsl(~bmap[i]); 91 | if (bit) 92 | break; 93 | } 94 | 95 | if (bit) { 96 | if (i == word) 97 | /* Restore previous shift if any */ 98 | bit += shift; 99 | return (i * BPW) + (bit - 1); 100 | } 101 | else 102 | return -1; 103 | } 104 | 105 | /* 106 | * Set (n) bits in (bmap[]) at 0-based bit index (at). 107 | */ 108 | static void setn_at(long *bmap, size_t bmap_size, int at, int n) 109 | { 110 | assert((at + n - 1) < (bmap_size * BPW)); 111 | while (n > 0) { 112 | n -= 1; 113 | bmap[((at + n) / BPW)] |= (1UL << ((at + n) % BPW)); 114 | } 115 | } 116 | 117 | /* 118 | * Clear (n) bits in (bmap[]) at 0-based bit index (at). 119 | */ 120 | static void clearn_at(long *bmap, size_t bmap_size, int at, int n) 121 | { 122 | assert((at + n - 1) < (bmap_size * BPW)); 123 | while (n > 0) { 124 | n -= 1; 125 | bmap[((at + n) / BPW)] &= ~(1UL << ((at + n) % BPW)); 126 | } 127 | } 128 | 129 | /* 130 | * Allocate (n) pages from (alloc), returns a memory address or NULL if no 131 | * space found. 132 | */ 133 | void *bmap_alloc(bmap_allocator_t *alloc, size_t n) 134 | { 135 | int a = 0, b = 0; 136 | size_t bmap_bits = alloc->bmap_size * BPW; 137 | 138 | /* 139 | * Allocating 0 pages is not allowed. 140 | */ 141 | assert(n >= 1); 142 | 143 | while (1) { 144 | /* 145 | * Look for the first free page starting at (b), initially 0. 146 | */ 147 | a = ffs_at(alloc->bmap, alloc->bmap_size, b); 148 | if (a < 0) 149 | return NULL; 150 | /* 151 | * Look for the first used page after the found free page. 152 | */ 153 | b = ffc_at(alloc->bmap, alloc->bmap_size, a); 154 | if (b < 0) 155 | /* 156 | * Nothing found; all remaining pages from a..bmap_bits are free. 157 | */ 158 | b = bmap_bits; 159 | /* 160 | * Is the block big enough? If yes, mark as used (0) and return it. 161 | */ 162 | if (b - a >= n) { 163 | clearn_at(alloc->bmap, alloc->bmap_size, a, n); 164 | return (void *)(alloc->start_addr + (a * PAGE_SIZE)); 165 | } 166 | /* 167 | * Stop the search if we hit the end of bmap[] and did not find a large 168 | * enough block. 169 | */ 170 | if (b == bmap_bits) 171 | return NULL; 172 | /* 173 | * If we got here, loop with (b) set to the last seen used page. 174 | */ 175 | } 176 | } 177 | 178 | /* 179 | * Free (n) pages at (addr) from (alloc). 180 | */ 181 | void bmap_free(bmap_allocator_t *alloc, void *addr, size_t n) 182 | { 183 | /* 184 | * Verify that: 185 | * addr is page-aligned 186 | * addr is within the range given to alloc 187 | * n is at least 1; the maximum size of n is checked in setn_at(). 188 | */ 189 | assert(((uintptr_t)addr & (PAGE_SIZE - 1)) == 0); 190 | assert((uintptr_t)addr >= alloc->start_addr); 191 | assert(n >= 1); 192 | 193 | int a = ((uintptr_t)addr - alloc->start_addr) / PAGE_SIZE; 194 | setn_at(alloc->bmap, alloc->bmap_size, a, n); 195 | } 196 | 197 | /* 198 | * Initialise the allocator to use (n_pages) at (start_addr). 199 | */ 200 | bmap_allocator_t *bmap_init(uint64_t start_addr, size_t n_pages) 201 | { 202 | bmap_allocator_t *alloc = malloc(sizeof (bmap_allocator_t)); 203 | assert(alloc != NULL); 204 | /* 205 | * n_pages must be a multiple of BPW. 206 | */ 207 | assert((n_pages % BPW) == 0); 208 | alloc->bmap_size = n_pages / BPW; 209 | alloc->bmap = malloc(alloc->bmap_size * sizeof(long)); 210 | assert(alloc->bmap); 211 | alloc->start_addr = start_addr; 212 | /* 213 | * All pages are initially free; set all bits in bmap[]. 214 | */ 215 | memset(alloc->bmap, 0xff, alloc->bmap_size * sizeof(long)); 216 | 217 | return alloc; 218 | } 219 | 220 | #ifdef TEST_STANDALONE 221 | /* 222 | * For standalone testing of the algorithm. 223 | */ 224 | 225 | #include 226 | 227 | int main(int argc, char *argv[]) 228 | { 229 | if (argc != 2) { 230 | printf("need allocation size\n"); 231 | return 1; 232 | } 233 | 234 | int n = atoi(argv[1]); 235 | bmap_allocator_t *alloc = bmap_init(0x100000, 4096); 236 | 237 | char *a; 238 | int c = 0; 239 | do { 240 | a = bmap_alloc(alloc, n); 241 | if (a) 242 | printf ("%d: %p - %p\n", ++c, a, a + (n * PAGE_SIZE) - 1); 243 | } while (a); 244 | 245 | /* Keep valgrind happy when testing standalone. */ 246 | free(alloc->bmap); 247 | free(alloc); 248 | } 249 | 250 | #endif 251 | --------------------------------------------------------------------------------