/*1* Copyright (c) 2016, Citrix Systems Inc2*3* Permission is hereby granted, free of charge, to any person obtaining a copy4* of this software and associated documentation files (the "Software"), to5* deal in the Software without restriction, including without limitation the6* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or7* sell copies of the Software, and to permit persons to whom the Software is8* furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE16* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING18* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER19* DEALINGS IN THE SOFTWARE.20*21*/2223#ifndef __XEN_PUBLIC_HVM_DM_OP_H__24#define __XEN_PUBLIC_HVM_DM_OP_H__2526#include "../xen.h"27#include "../event_channel.h"2829#ifndef uint64_aligned_t30#define uint64_aligned_t uint64_t31#endif3233/*34* IOREQ Servers35*36* The interface between an I/O emulator an Xen is called an IOREQ Server.37* A domain supports a single 'legacy' IOREQ Server which is instantiated if38* parameter...39*40* HVM_PARAM_IOREQ_PFN is read (to get the gfn containing the synchronous41* ioreq structures), or...42* HVM_PARAM_BUFIOREQ_PFN is read (to get the gfn containing the buffered43* ioreq ring), or...44* HVM_PARAM_BUFIOREQ_EVTCHN is read (to get the event channel that Xen uses45* to request buffered I/O emulation).46*47* The following hypercalls facilitate the creation of IOREQ Servers for48* 'secondary' emulators which are invoked to implement port I/O, memory, or49* PCI config space ranges which they explicitly register.50*/5152typedef uint16_t ioservid_t;5354/*55* XEN_DMOP_create_ioreq_server: Instantiate a new IOREQ Server for a56* secondary emulator.57*58* The <id> handed back is unique for target domain. The valur of59* <handle_bufioreq> should be one of HVM_IOREQSRV_BUFIOREQ_* defined in60* hvm_op.h. If the value is HVM_IOREQSRV_BUFIOREQ_OFF then the buffered61* ioreq ring will not be allocated and hence all emulation requests to62* this server will be synchronous.63*/64#define XEN_DMOP_create_ioreq_server 16566struct xen_dm_op_create_ioreq_server {67/* IN - should server handle buffered ioreqs */68uint8_t handle_bufioreq;69uint8_t pad[3];70/* OUT - server id */71ioservid_t id;72};73typedef struct xen_dm_op_create_ioreq_server xen_dm_op_create_ioreq_server_t;7475/*76* XEN_DMOP_get_ioreq_server_info: Get all the information necessary to77* access IOREQ Server <id>.78*79* If the IOREQ Server is handling buffered emulation requests, the80* emulator needs to bind to event channel <bufioreq_port> to listen for81* them. (The event channels used for synchronous emulation requests are82* specified in the per-CPU ioreq structures).83* In addition, if the XENMEM_acquire_resource memory op cannot be used,84* the emulator will need to map the synchronous ioreq structures and85* buffered ioreq ring (if it exists) from guest memory. If <flags> does86* not contain XEN_DMOP_no_gfns then these pages will be made available and87* the frame numbers passed back in gfns <ioreq_gfn> and <bufioreq_gfn>88* respectively. (If the IOREQ Server is not handling buffered emulation89* only <ioreq_gfn> will be valid).90*91* NOTE: To access the synchronous ioreq structures and buffered ioreq92* ring, it is preferable to use the XENMEM_acquire_resource memory93* op specifying resource type XENMEM_resource_ioreq_server.94*/95#define XEN_DMOP_get_ioreq_server_info 29697struct xen_dm_op_get_ioreq_server_info {98/* IN - server id */99ioservid_t id;100/* IN - flags */101uint16_t flags;102103#define _XEN_DMOP_no_gfns 0104#define XEN_DMOP_no_gfns (1u << _XEN_DMOP_no_gfns)105106/* OUT - buffered ioreq port */107evtchn_port_t bufioreq_port;108/* OUT - sync ioreq gfn (see block comment above) */109uint64_aligned_t ioreq_gfn;110/* OUT - buffered ioreq gfn (see block comment above)*/111uint64_aligned_t bufioreq_gfn;112};113typedef struct xen_dm_op_get_ioreq_server_info xen_dm_op_get_ioreq_server_info_t;114115/*116* XEN_DMOP_map_io_range_to_ioreq_server: Register an I/O range for117* emulation by the client of118* IOREQ Server <id>.119* XEN_DMOP_unmap_io_range_from_ioreq_server: Deregister an I/O range120* previously registered for121* emulation by the client of122* IOREQ Server <id>.123*124* There are three types of I/O that can be emulated: port I/O, memory125* accesses and PCI config space accesses. The <type> field denotes which126* type of range* the <start> and <end> (inclusive) fields are specifying.127* PCI config space ranges are specified by segment/bus/device/function128* values which should be encoded using the DMOP_PCI_SBDF helper macro129* below.130*131* NOTE: unless an emulation request falls entirely within a range mapped132* by a secondary emulator, it will not be passed to that emulator.133*/134#define XEN_DMOP_map_io_range_to_ioreq_server 3135#define XEN_DMOP_unmap_io_range_from_ioreq_server 4136137struct xen_dm_op_ioreq_server_range {138/* IN - server id */139ioservid_t id;140uint16_t pad;141/* IN - type of range */142uint32_t type;143# define XEN_DMOP_IO_RANGE_PORT 0 /* I/O port range */144# define XEN_DMOP_IO_RANGE_MEMORY 1 /* MMIO range */145# define XEN_DMOP_IO_RANGE_PCI 2 /* PCI segment/bus/dev/func range */146/* IN - inclusive start and end of range */147uint64_aligned_t start, end;148};149typedef struct xen_dm_op_ioreq_server_range xen_dm_op_ioreq_server_range_t;150151#define XEN_DMOP_PCI_SBDF(s,b,d,f) \152((((s) & 0xffff) << 16) | \153(((b) & 0xff) << 8) | \154(((d) & 0x1f) << 3) | \155((f) & 0x07))156157/*158* XEN_DMOP_set_ioreq_server_state: Enable or disable the IOREQ Server <id>159*160* The IOREQ Server will not be passed any emulation requests until it is161* in the enabled state.162* Note that the contents of the ioreq_gfn and bufioreq_gfn (see163* XEN_DMOP_get_ioreq_server_info) are not meaningful until the IOREQ Server164* is in the enabled state.165*/166#define XEN_DMOP_set_ioreq_server_state 5167168struct xen_dm_op_set_ioreq_server_state {169/* IN - server id */170ioservid_t id;171/* IN - enabled? */172uint8_t enabled;173uint8_t pad;174};175typedef struct xen_dm_op_set_ioreq_server_state xen_dm_op_set_ioreq_server_state_t;176177/*178* XEN_DMOP_destroy_ioreq_server: Destroy the IOREQ Server <id>.179*180* Any registered I/O ranges will be automatically deregistered.181*/182#define XEN_DMOP_destroy_ioreq_server 6183184struct xen_dm_op_destroy_ioreq_server {185/* IN - server id */186ioservid_t id;187uint16_t pad;188};189typedef struct xen_dm_op_destroy_ioreq_server xen_dm_op_destroy_ioreq_server_t;190191/*192* XEN_DMOP_track_dirty_vram: Track modifications to the specified pfn193* range.194*195* NOTE: The bitmap passed back to the caller is passed in a196* secondary buffer.197*/198#define XEN_DMOP_track_dirty_vram 7199200struct xen_dm_op_track_dirty_vram {201/* IN - number of pages to be tracked */202uint32_t nr;203uint32_t pad;204/* IN - first pfn to track */205uint64_aligned_t first_pfn;206};207typedef struct xen_dm_op_track_dirty_vram xen_dm_op_track_dirty_vram_t;208209/*210* XEN_DMOP_set_pci_intx_level: Set the logical level of one of a domain's211* PCI INTx pins.212*/213#define XEN_DMOP_set_pci_intx_level 8214215struct xen_dm_op_set_pci_intx_level {216/* IN - PCI INTx identification (domain:bus:device:intx) */217uint16_t domain;218uint8_t bus, device, intx;219/* IN - Level: 0 -> deasserted, 1 -> asserted */220uint8_t level;221};222typedef struct xen_dm_op_set_pci_intx_level xen_dm_op_set_pci_intx_level_t;223224/*225* XEN_DMOP_set_isa_irq_level: Set the logical level of a one of a domain's226* ISA IRQ lines.227*/228#define XEN_DMOP_set_isa_irq_level 9229230struct xen_dm_op_set_isa_irq_level {231/* IN - ISA IRQ (0-15) */232uint8_t isa_irq;233/* IN - Level: 0 -> deasserted, 1 -> asserted */234uint8_t level;235};236typedef struct xen_dm_op_set_isa_irq_level xen_dm_op_set_isa_irq_level_t;237238/*239* XEN_DMOP_set_pci_link_route: Map a PCI INTx line to an IRQ line.240*/241#define XEN_DMOP_set_pci_link_route 10242243struct xen_dm_op_set_pci_link_route {244/* PCI INTx line (0-3) */245uint8_t link;246/* ISA IRQ (1-15) or 0 -> disable link */247uint8_t isa_irq;248};249typedef struct xen_dm_op_set_pci_link_route xen_dm_op_set_pci_link_route_t;250251/*252* XEN_DMOP_modified_memory: Notify that a set of pages were modified by253* an emulator.254*255* DMOP buf 1 contains an array of xen_dm_op_modified_memory_extent with256* @nr_extents entries.257*258* On error, @nr_extents will contain the index+1 of the extent that259* had the error. It is not defined if or which pages may have been260* marked as dirty, in this event.261*/262#define XEN_DMOP_modified_memory 11263264struct xen_dm_op_modified_memory {265/*266* IN - Number of extents to be processed267* OUT -returns n+1 for failing extent268*/269uint32_t nr_extents;270/* IN/OUT - Must be set to 0 */271uint32_t opaque;272};273typedef struct xen_dm_op_modified_memory xen_dm_op_modified_memory_t;274275struct xen_dm_op_modified_memory_extent {276/* IN - number of contiguous pages modified */277uint32_t nr;278uint32_t pad;279/* IN - first pfn modified */280uint64_aligned_t first_pfn;281};282283/*284* XEN_DMOP_set_mem_type: Notify that a region of memory is to be treated285* in a specific way. (See definition of286* hvmmem_type_t).287*288* NOTE: In the event of a continuation (return code -ERESTART), the289* @first_pfn is set to the value of the pfn of the remaining290* region and @nr reduced to the size of the remaining region.291*/292#define XEN_DMOP_set_mem_type 12293294struct xen_dm_op_set_mem_type {295/* IN - number of contiguous pages */296uint32_t nr;297/* IN - new hvmmem_type_t of region */298uint16_t mem_type;299uint16_t pad;300/* IN - first pfn in region */301uint64_aligned_t first_pfn;302};303typedef struct xen_dm_op_set_mem_type xen_dm_op_set_mem_type_t;304305/*306* XEN_DMOP_inject_event: Inject an event into a VCPU, which will307* get taken up when it is next scheduled.308*309* Note that the caller should know enough of the state of the CPU before310* injecting, to know what the effect of injecting the event will be.311*/312#define XEN_DMOP_inject_event 13313314struct xen_dm_op_inject_event {315/* IN - index of vCPU */316uint32_t vcpuid;317/* IN - interrupt vector */318uint8_t vector;319/* IN - event type (DMOP_EVENT_* ) */320uint8_t type;321/* NB. This enumeration precisely matches hvm.h:X86_EVENTTYPE_* */322# define XEN_DMOP_EVENT_ext_int 0 /* external interrupt */323# define XEN_DMOP_EVENT_nmi 2 /* nmi */324# define XEN_DMOP_EVENT_hw_exc 3 /* hardware exception */325# define XEN_DMOP_EVENT_sw_int 4 /* software interrupt (CD nn) */326# define XEN_DMOP_EVENT_pri_sw_exc 5 /* ICEBP (F1) */327# define XEN_DMOP_EVENT_sw_exc 6 /* INT3 (CC), INTO (CE) */328/* IN - instruction length */329uint8_t insn_len;330uint8_t pad0;331/* IN - error code (or ~0 to skip) */332uint32_t error_code;333uint32_t pad1;334/* IN - type-specific extra data (%cr2 for #PF, pending_dbg for #DB) */335uint64_aligned_t cr2;336};337typedef struct xen_dm_op_inject_event xen_dm_op_inject_event_t;338339/*340* XEN_DMOP_inject_msi: Inject an MSI for an emulated device.341*/342#define XEN_DMOP_inject_msi 14343344struct xen_dm_op_inject_msi {345/* IN - MSI data (lower 32 bits) */346uint32_t data;347uint32_t pad;348/* IN - MSI address (0xfeexxxxx) */349uint64_aligned_t addr;350};351typedef struct xen_dm_op_inject_msi xen_dm_op_inject_msi_t;352353/*354* XEN_DMOP_map_mem_type_to_ioreq_server : map or unmap the IOREQ Server <id>355* to specific memory type <type>356* for specific accesses <flags>357*358* For now, flags only accept the value of XEN_DMOP_IOREQ_MEM_ACCESS_WRITE,359* which means only write operations are to be forwarded to an ioreq server.360* Support for the emulation of read operations can be added when an ioreq361* server has such requirement in future.362*/363#define XEN_DMOP_map_mem_type_to_ioreq_server 15364365struct xen_dm_op_map_mem_type_to_ioreq_server {366ioservid_t id; /* IN - ioreq server id */367uint16_t type; /* IN - memory type */368uint32_t flags; /* IN - types of accesses to be forwarded to the369ioreq server. flags with 0 means to unmap the370ioreq server */371372#define XEN_DMOP_IOREQ_MEM_ACCESS_READ (1u << 0)373#define XEN_DMOP_IOREQ_MEM_ACCESS_WRITE (1u << 1)374375uint64_t opaque; /* IN/OUT - only used for hypercall continuation,376has to be set to zero by the caller */377};378typedef struct xen_dm_op_map_mem_type_to_ioreq_server xen_dm_op_map_mem_type_to_ioreq_server_t;379380/*381* XEN_DMOP_remote_shutdown : Declare a shutdown for another domain382* Identical to SCHEDOP_remote_shutdown383*/384#define XEN_DMOP_remote_shutdown 16385386struct xen_dm_op_remote_shutdown {387uint32_t reason; /* SHUTDOWN_* => enum sched_shutdown_reason */388/* (Other reason values are not blocked) */389};390typedef struct xen_dm_op_remote_shutdown xen_dm_op_remote_shutdown_t;391392/*393* XEN_DMOP_relocate_memory : Relocate GFNs for the specified guest.394* Identical to XENMEM_add_to_physmap with395* space == XENMAPSPACE_gmfn_range.396*/397#define XEN_DMOP_relocate_memory 17398399struct xen_dm_op_relocate_memory {400/* All fields are IN/OUT, with their OUT state undefined. */401/* Number of GFNs to process. */402uint32_t size;403uint32_t pad;404/* Starting GFN to relocate. */405uint64_aligned_t src_gfn;406/* Starting GFN where GFNs should be relocated. */407uint64_aligned_t dst_gfn;408};409typedef struct xen_dm_op_relocate_memory xen_dm_op_relocate_memory_t;410411/*412* XEN_DMOP_pin_memory_cacheattr : Pin caching type of RAM space.413* Identical to XEN_DOMCTL_pin_mem_cacheattr.414*/415#define XEN_DMOP_pin_memory_cacheattr 18416417struct xen_dm_op_pin_memory_cacheattr {418uint64_aligned_t start; /* Start gfn. */419uint64_aligned_t end; /* End gfn. */420/* Caching types: these happen to be the same as x86 MTRR/PAT type codes. */421#define XEN_DMOP_MEM_CACHEATTR_UC 0422#define XEN_DMOP_MEM_CACHEATTR_WC 1423#define XEN_DMOP_MEM_CACHEATTR_WT 4424#define XEN_DMOP_MEM_CACHEATTR_WP 5425#define XEN_DMOP_MEM_CACHEATTR_WB 6426#define XEN_DMOP_MEM_CACHEATTR_UCM 7427#define XEN_DMOP_DELETE_MEM_CACHEATTR (~(uint32_t)0)428uint32_t type; /* XEN_DMOP_MEM_CACHEATTR_* */429uint32_t pad;430};431typedef struct xen_dm_op_pin_memory_cacheattr xen_dm_op_pin_memory_cacheattr_t;432433/*434* XEN_DMOP_set_irq_level: Set the logical level of a one of a domain's435* IRQ lines (currently Arm only).436* Only SPIs are supported.437*/438#define XEN_DMOP_set_irq_level 19439440struct xen_dm_op_set_irq_level {441uint32_t irq;442/* IN - Level: 0 -> deasserted, 1 -> asserted */443uint8_t level;444uint8_t pad[3];445};446typedef struct xen_dm_op_set_irq_level xen_dm_op_set_irq_level_t;447448/*449* XEN_DMOP_nr_vcpus: Query the number of vCPUs a domain has.450*451* This is the number of vcpu objects allocated in Xen for the domain, and is452* fixed from creation time. This bound is applicable to e.g. the vcpuid453* parameter of XEN_DMOP_inject_event, or number of struct ioreq objects454* mapped via XENMEM_acquire_resource.455*/456#define XEN_DMOP_nr_vcpus 20457458struct xen_dm_op_nr_vcpus {459uint32_t vcpus; /* OUT */460};461typedef struct xen_dm_op_nr_vcpus xen_dm_op_nr_vcpus_t;462463struct xen_dm_op {464uint32_t op;465uint32_t pad;466union {467xen_dm_op_create_ioreq_server_t create_ioreq_server;468xen_dm_op_get_ioreq_server_info_t get_ioreq_server_info;469xen_dm_op_ioreq_server_range_t map_io_range_to_ioreq_server;470xen_dm_op_ioreq_server_range_t unmap_io_range_from_ioreq_server;471xen_dm_op_set_ioreq_server_state_t set_ioreq_server_state;472xen_dm_op_destroy_ioreq_server_t destroy_ioreq_server;473xen_dm_op_track_dirty_vram_t track_dirty_vram;474xen_dm_op_set_pci_intx_level_t set_pci_intx_level;475xen_dm_op_set_isa_irq_level_t set_isa_irq_level;476xen_dm_op_set_irq_level_t set_irq_level;477xen_dm_op_set_pci_link_route_t set_pci_link_route;478xen_dm_op_modified_memory_t modified_memory;479xen_dm_op_set_mem_type_t set_mem_type;480xen_dm_op_inject_event_t inject_event;481xen_dm_op_inject_msi_t inject_msi;482xen_dm_op_map_mem_type_to_ioreq_server_t map_mem_type_to_ioreq_server;483xen_dm_op_remote_shutdown_t remote_shutdown;484xen_dm_op_relocate_memory_t relocate_memory;485xen_dm_op_pin_memory_cacheattr_t pin_memory_cacheattr;486xen_dm_op_nr_vcpus_t nr_vcpus;487} u;488};489490struct xen_dm_op_buf {491XEN_GUEST_HANDLE(void) h;492xen_ulong_t size;493};494typedef struct xen_dm_op_buf xen_dm_op_buf_t;495DEFINE_XEN_GUEST_HANDLE(xen_dm_op_buf_t);496497/* ` enum neg_errnoval498* ` HYPERVISOR_dm_op(domid_t domid,499* ` unsigned int nr_bufs,500* ` xen_dm_op_buf_t bufs[])501* `502*503* @domid is the domain the hypercall operates on.504* @nr_bufs is the number of buffers in the @bufs array.505* @bufs points to an array of buffers where @bufs[0] contains a struct506* xen_dm_op, describing the specific device model operation and its507* parameters.508* @bufs[1..] may be referenced in the parameters for the purposes of509* passing extra information to or from the domain.510*/511512#endif /* __XEN_PUBLIC_HVM_DM_OP_H__ */513514/*515* Local variables:516* mode: C517* c-file-style: "BSD"518* c-basic-offset: 4519* tab-width: 4520* indent-tabs-mode: nil521* End:522*/523524525