2 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more
16 #ifndef __CONTROLVMCHANNEL_H__
17 #define __CONTROLVMCHANNEL_H__
19 #include <linux/uuid.h>
22 /* {2B3C2D10-7EF5-4ad8-B966-3448B7386B3D} */
23 #define VISOR_CONTROLVM_CHANNEL_GUID \
24 GUID_INIT(0x2b3c2d10, 0x7ef5, 0x4ad8, \
25 0xb9, 0x66, 0x34, 0x48, 0xb7, 0x38, 0x6b, 0x3d)
27 #define CONTROLVM_MESSAGE_MAX 64
30 * Must increment this whenever you insert or delete fields within this channel
31 * struct. Also increment whenever you change the meaning of fields within this
32 * channel struct so as to break pre-existing software. Note that you can
33 * usually add fields to the END of the channel struct withOUT needing to
36 #define VISOR_CONTROLVM_CHANNEL_VERSIONID 1
38 /* Defines for various channel queues */
39 #define CONTROLVM_QUEUE_REQUEST 0
40 #define CONTROLVM_QUEUE_RESPONSE 1
41 #define CONTROLVM_QUEUE_EVENT 2
42 #define CONTROLVM_QUEUE_ACK 3
44 /* Max num of messages stored during IOVM creation to be reused after crash */
45 #define CONTROLVM_CRASHMSG_MAX 2
48 * struct visor_segment_state
49 * @enabled: May enter other states.
50 * @active: Assigned to active partition.
51 * @alive: Configure message sent to service/server.
52 * @revoked: Similar to partition state ShuttingDown.
53 * @allocated: Memory (device/port number) has been selected by Command.
54 * @known: Has been introduced to the service/guest partition.
55 * @ready: Service/Guest partition has responded to introduction.
56 * @operating: Resource is configured and operating.
57 * @reserved: Natural alignment.
59 * Note: Don't use high bit unless we need to switch to ushort which is
62 struct visor_segment_state {
74 static const struct visor_segment_state segment_state_running = {
75 1, 1, 1, 0, 1, 1, 1, 1
78 static const struct visor_segment_state segment_state_paused = {
79 1, 1, 1, 0, 1, 1, 1, 0
82 static const struct visor_segment_state segment_state_standby = {
83 1, 1, 0, 0, 1, 1, 1, 0
89 * @CONTROLVM_BUS_CREATE: CP --> SP, GP.
90 * @CONTROLVM_BUS_DESTROY: CP --> SP, GP.
91 * @CONTROLVM_BUS_CONFIGURE: CP --> SP.
92 * @CONTROLVM_BUS_CHANGESTATE: CP --> SP, GP.
93 * @CONTROLVM_BUS_CHANGESTATE_EVENT: SP, GP --> CP.
94 * @CONTROLVM_DEVICE_CREATE: CP --> SP, GP.
95 * @CONTROLVM_DEVICE_DESTROY: CP --> SP, GP.
96 * @CONTROLVM_DEVICE_CONFIGURE: CP --> SP.
97 * @CONTROLVM_DEVICE_CHANGESTATE: CP --> SP, GP.
98 * @CONTROLVM_DEVICE_CHANGESTATE_EVENT: SP, GP --> CP.
99 * @CONTROLVM_DEVICE_RECONFIGURE: CP --> Boot.
100 * @CONTROLVM_CHIPSET_INIT: CP --> SP, GP.
101 * @CONTROLVM_CHIPSET_STOP: CP --> SP, GP.
102 * @CONTROLVM_CHIPSET_READY: CP --> SP.
103 * @CONTROLVM_CHIPSET_SELFTEST: CP --> SP.
105 * Ids for commands that may appear in either queue of a ControlVm channel.
107 * Commands that are initiated by the command partition (CP), by an IO or
108 * console service partition (SP), or by a guest partition (GP) are:
109 * - issued on the RequestQueue queue (q #0) in the ControlVm channel
110 * - responded to on the ResponseQueue queue (q #1) in the ControlVm channel
112 * Events that are initiated by an IO or console service partition (SP) or
113 * by a guest partition (GP) are:
114 * - issued on the EventQueue queue (q #2) in the ControlVm channel
115 * - responded to on the EventAckQueue queue (q #3) in the ControlVm channel
118 CONTROLVM_INVALID = 0,
120 * SWITCH commands required Parameter: SwitchNumber.
121 * BUS commands required Parameter: BusNumber
123 CONTROLVM_BUS_CREATE = 0x101,
124 CONTROLVM_BUS_DESTROY = 0x102,
125 CONTROLVM_BUS_CONFIGURE = 0x104,
126 CONTROLVM_BUS_CHANGESTATE = 0x105,
127 CONTROLVM_BUS_CHANGESTATE_EVENT = 0x106,
128 /* DEVICE commands required Parameter: BusNumber, DeviceNumber */
129 CONTROLVM_DEVICE_CREATE = 0x201,
130 CONTROLVM_DEVICE_DESTROY = 0x202,
131 CONTROLVM_DEVICE_CONFIGURE = 0x203,
132 CONTROLVM_DEVICE_CHANGESTATE = 0x204,
133 CONTROLVM_DEVICE_CHANGESTATE_EVENT = 0x205,
134 CONTROLVM_DEVICE_RECONFIGURE = 0x206,
135 /* CHIPSET commands */
136 CONTROLVM_CHIPSET_INIT = 0x301,
137 CONTROLVM_CHIPSET_STOP = 0x302,
138 CONTROLVM_CHIPSET_READY = 0x304,
139 CONTROLVM_CHIPSET_SELFTEST = 0x305,
144 * @reserved1: Natural alignment purposes
145 * @recv_irq_handle: Specifies interrupt handle. It is used to retrieve the
146 * corresponding interrupt pin from Monitor; and the interrupt
147 * pin is used to connect to the corresponding interrupt.
148 * Used by IOPart-GP only.
149 * @recv_irq_vector: Specifies interrupt vector. It, interrupt pin, and shared
150 * are used to connect to the corresponding interrupt.
151 * Used by IOPart-GP only.
152 * @recv_irq_shared: Specifies if the recvInterrupt is shared. It, interrupt
153 * pin and vector are used to connect to 0 = not shared;
154 * 1 = shared the corresponding interrupt.
155 * Used by IOPart-GP only.
156 * @reserved: Natural alignment purposes
167 * struct efi_visor_indication
168 * @boot_to_fw_ui: Stop in UEFI UI
169 * @clear_nvram: Clear NVRAM
170 * @clear_cmos: Clear CMOS
171 * @boot_to_tool: Run install tool
172 * @reserved: Natural alignment
174 struct efi_visor_indication {
179 /* Remaining bits are available */
183 enum visor_chipset_feature {
184 VISOR_CHIPSET_FEATURE_REPLY = 0x00000001,
185 VISOR_CHIPSET_FEATURE_PARA_HOTPLUG = 0x00000002,
189 * struct controlvm_message_header
190 * @id: See CONTROLVM_ID.
191 * @message_size: Includes size of this struct + size of message.
192 * @segment_index: Index of segment containing Vm message/information.
193 * @completion_status: Error status code or result of message completion.
195 * @failed: =1 in a response to signify failure.
196 * @response_expected: =1 in all messages that expect a response.
197 * @server: =1 in all bus & device-related messages where the
198 * message receiver is to act as the bus or device
200 * @test_message: =1 for testing use only (Control and Command
202 * @partial_completion: =1 if there are forthcoming responses/acks
203 * associated with this message.
204 * @preserve: =1 this is to let us know to preserve channel
206 * @writer_in_diag: =1 the DiagWriter is active in the Diagnostic
208 * @reserve: Natural alignment.
209 * @reserved: Natural alignment.
210 * @message_handle: Identifies the particular message instance.
211 * @payload_vm_offset: Offset of payload area from start of this instance.
212 * @payload_max_bytes: Maximum bytes allocated in payload area of ControlVm
214 * @payload_bytes: Actual number of bytes of payload area to copy between
215 * IO/Command. If non-zero, there is a payload to copy.
217 * This is the common structure that is at the beginning of every
218 * ControlVm message (both commands and responses) in any ControlVm
219 * queue. Commands are easily distinguished from responses by
220 * looking at the flags.response field.
222 struct controlvm_message_header {
225 * For requests, indicates the message type. For responses, indicates
226 * the type of message we are responding to.
230 u32 completion_status;
233 u32 response_expected:1;
236 u32 partial_completion:1;
238 u32 writer_in_diag:1;
243 u64 payload_vm_offset;
244 u32 payload_max_bytes;
249 * struct controlvm_packet_device_create - For CONTROLVM_DEVICE_CREATE
250 * @bus_no: Bus # (0..n-1) from the msg receiver's end.
251 * @dev_no: Bus-relative (0..n-1) device number.
252 * @channel_addr: Guest physical address of the channel, which can be
253 * dereferenced by the receiver of this ControlVm command.
254 * @channel_bytes: Specifies size of the channel in bytes.
255 * @data_type_uuid: Specifies format of data in channel.
256 * @dev_inst_uuid: Instance guid for the device.
257 * @irq_info intr: Specifies interrupt information.
259 struct controlvm_packet_device_create {
264 guid_t data_type_guid;
265 guid_t dev_inst_guid;
266 struct irq_info intr;
270 * struct controlvm_packet_device_configure - For CONTROLVM_DEVICE_CONFIGURE
271 * @bus_no: Bus number (0..n-1) from the msg receiver's perspective.
272 * @dev_no: Bus-relative (0..n-1) device number.
274 struct controlvm_packet_device_configure {
279 /* Total 128 bytes */
280 struct controlvm_message_device_create {
281 struct controlvm_message_header header;
282 struct controlvm_packet_device_create packet;
286 struct controlvm_message_device_configure {
287 struct controlvm_message_header header;
288 struct controlvm_packet_device_configure packet;
292 * struct controlvm_message_packet - This is the format for a message in any
294 * @struct create_bus: For CONTROLVM_BUS_CREATE.
295 * @bus_no: Bus # (0..n-1) from the msg receiver's perspective.
296 * @dev_count: Indicates the max number of devices on this bus.
297 * @channel_addr: Guest physical address of the channel, which can be
298 * dereferenced by the receiver of this ControlVM
300 * @channel_bytes: Size of the channel.
301 * @bus_data_type_uuid: Indicates format of data in bus channel.
302 * @bus_inst_uuid: Instance uuid for the bus.
304 * @struct destroy_bus: For CONTROLVM_BUS_DESTROY.
305 * @bus_no: Bus # (0..n-1) from the msg receiver's perspective.
306 * @reserved: Natural alignment purposes.
308 * @struct configure_bus: For CONTROLVM_BUS_CONFIGURE.
309 * @bus_no: Bus # (0..n-1) from the receiver's perspective.
310 * @reserved1: For alignment purposes.
311 * @guest_handle: This is used to convert guest physical address to
313 * @recv_bus_irq_handle: Specifies interrupt info. It is used by SP to
314 * register to receive interrupts from the CP. This
315 * interrupt is used for bus level notifications.
316 * The corresponding sendBusInterruptHandle is kept
319 * @struct create_device: For CONTROLVM_DEVICE_CREATE.
321 * @struct destroy_device: For CONTROLVM_DEVICE_DESTROY.
322 * @bus_no: Bus # (0..n-1) from the msg receiver's perspective.
323 * @dev_no: Bus-relative (0..n-1) device number.
325 * @struct configure_device: For CONTROLVM_DEVICE_CONFIGURE.
327 * @struct reconfigure_device: For CONTROLVM_DEVICE_RECONFIGURE.
328 * @bus_no: Bus # (0..n-1) from the msg receiver's perspective.
329 * @dev_no: Bus-relative (0..n-1) device number.
331 * @struct bus_change_state: For CONTROLVM_BUS_CHANGESTATE.
334 * @reserved: Natural alignment purposes.
336 * @struct device_change_state: For CONTROLVM_DEVICE_CHANGESTATE.
341 * @phys_device: =1 if message is for a physical device.
342 * @reserved: Natural alignment.
343 * @reserved1: Natural alignment.
344 * @reserved: Natural alignment purposes.
346 * @struct device_change_state_event: For CONTROLVM_DEVICE_CHANGESTATE_EVENT.
350 * @reserved: Natural alignment purposes.
352 * @struct init_chipset: For CONTROLVM_CHIPSET_INIT.
353 * @bus_count: Indicates the max number of busses.
354 * @switch_count: Indicates the max number of switches.
358 * @struct chipset_selftest: For CONTROLVM_CHIPSET_SELFTEST.
359 * @options: Reserved.
360 * @test: Bit 0 set to run embedded selftest.
362 * @addr: A physical address of something, that can be dereferenced by the
363 * receiver of this ControlVm command.
365 * @handle: A handle of something (depends on command id).
367 struct controlvm_message_packet {
374 guid_t bus_data_type_guid;
375 guid_t bus_inst_guid;
376 } __packed create_bus;
380 } __packed destroy_bus;
385 u64 recv_bus_irq_handle;
386 } __packed configure_bus;
387 struct controlvm_packet_device_create create_device;
391 } __packed destroy_device;
392 struct controlvm_packet_device_configure configure_device;
396 } __packed reconfigure_device;
399 struct visor_segment_state state;
401 } __packed bus_change_state;
405 struct visor_segment_state state;
412 } __packed device_change_state;
416 struct visor_segment_state state;
418 } __packed device_change_state_event;
422 enum visor_chipset_feature features;
424 } __packed init_chipset;
428 } __packed chipset_selftest;
434 /* All messages in any ControlVm queue have this layout. */
435 struct controlvm_message {
436 struct controlvm_message_header hdr;
437 struct controlvm_message_packet cmd;
441 * struct visor_controlvm_channel
443 * @gp_controlvm: Guest phys addr of this channel.
444 * @gp_partition_tables: Guest phys addr of partition tables.
445 * @gp_diag_guest: Guest phys addr of diagnostic channel.
446 * @gp_boot_romdisk: Guest phys addr of (read* only) Boot
448 * @gp_boot_ramdisk: Guest phys addr of writable Boot RAM
450 * @gp_acpi_table: Guest phys addr of acpi table.
451 * @gp_control_channel: Guest phys addr of control channel.
452 * @gp_diag_romdisk: Guest phys addr of diagnostic ROM disk.
453 * @gp_nvram: Guest phys addr of NVRAM channel.
454 * @request_payload_offset: Offset to request payload area.
455 * @event_payload_offset: Offset to event payload area.
456 * @request_payload_bytes: Bytes available in request payload area.
457 * @event_payload_bytes: Bytes available in event payload area.
458 * @control_channel_bytes:
459 * @nvram_channel_bytes: Bytes in PartitionNvram segment.
460 * @message_bytes: sizeof(CONTROLVM_MESSAGE).
461 * @message_count: CONTROLVM_MESSAGE_MAX.
462 * @gp_smbios_table: Guest phys addr of SMBIOS tables.
463 * @gp_physical_smbios_table: Guest phys addr of SMBIOS table.
464 * @gp_reserved: VISOR_MAX_GUESTS_PER_SERVICE.
465 * @virtual_guest_firmware_image_base: Guest physical address of EFI firmware
467 * @virtual_guest_firmware_entry_point: Guest physical address of EFI firmware
469 * @virtual_guest_firmware_image_size: Guest EFI firmware image size.
470 * @virtual_guest_firmware_boot_base: GPA = 1MB where EFI firmware image is
472 * @virtual_guest_image_base:
473 * @virtual_guest_image_size:
474 * @prototype_control_channel_offset:
475 * @virtual_guest_partition_handle:
476 * @restore_action: Restore Action field to restore the
478 * @dump_action: For Windows guests it shows if the
479 * visordisk is in dump mode.
481 * @saved_crash_message_count: = CONTROLVM_CRASHMSG_MAX.
482 * @saved_crash_message_offset: Offset to request payload area needed
484 * @installation_error: Type of error encountered during
486 * @installation_text_id: Id of string to display.
487 * @installation_remaining_steps: Number of remaining installation steps
488 * (for progress bars).
489 * @tool_action: VISOR_TOOL_ACTIONS Installation Action
491 * @reserved: Alignment.
492 * @struct efi_visor_ind:
494 * @reserved2: Force signals to begin on 128-byte
496 * @struct request_queue: Guest partition uses this queue to send
497 * requests to Control.
498 * @struct response_queue: Control uses this queue to respond to
499 * service or guest partition request.
500 * @struct event_queue: Control uses this queue to send events
501 * to guest partition.
502 * @struct event_ack_queue: Service or guest partition uses this
503 * queue to ack Control events.
504 * @struct request_msg: Request fixed-size message pool -
505 * does not include payload.
506 * @struct response_msg: Response fixed-size message pool -
507 * does not include payload.
508 * @struct event_msg: Event fixed-size message pool -
509 * does not include payload.
510 * @struct event_ack_msg: Ack fixed-size message pool -
511 * does not include payload.
512 * @struct saved_crash_msg: Message stored during IOVM creation to
513 * be reused after crash.
515 struct visor_controlvm_channel {
516 struct channel_header header;
518 u64 gp_partition_tables;
523 u64 gp_control_channel;
526 u64 request_payload_offset;
527 u64 event_payload_offset;
528 u32 request_payload_bytes;
529 u32 event_payload_bytes;
530 u32 control_channel_bytes;
531 u32 nvram_channel_bytes;
535 u64 gp_physical_smbios_table;
536 char gp_reserved[2688];
537 u64 virtual_guest_firmware_image_base;
538 u64 virtual_guest_firmware_entry_point;
539 u64 virtual_guest_firmware_image_size;
540 u64 virtual_guest_firmware_boot_base;
541 u64 virtual_guest_image_base;
542 u64 virtual_guest_image_size;
543 u64 prototype_control_channel_offset;
544 u64 virtual_guest_partition_handle;
547 u16 nvram_fail_count;
548 u16 saved_crash_message_count;
549 u32 saved_crash_message_offset;
550 u32 installation_error;
551 u32 installation_text_id;
552 u16 installation_remaining_steps;
555 struct efi_visor_indication efi_visor_ind;
558 struct signal_queue_header request_queue;
559 struct signal_queue_header response_queue;
560 struct signal_queue_header event_queue;
561 struct signal_queue_header event_ack_queue;
562 struct controlvm_message request_msg[CONTROLVM_MESSAGE_MAX];
563 struct controlvm_message response_msg[CONTROLVM_MESSAGE_MAX];
564 struct controlvm_message event_msg[CONTROLVM_MESSAGE_MAX];
565 struct controlvm_message event_ack_msg[CONTROLVM_MESSAGE_MAX];
566 struct controlvm_message saved_crash_msg[CONTROLVM_CRASHMSG_MAX];
570 * struct visor_controlvm_parameters_header
572 * The following header will be located at the beginning of PayloadVmOffset for
573 * various ControlVm commands. The receiver of a ControlVm command with a
574 * PayloadVmOffset will dereference this address and then use connection_offset,
575 * initiator_offset, and target_offset to get the location of UTF-8 formatted
576 * strings that can be parsed to obtain command-specific information. The value
577 * of total_length should equal PayloadBytes. The format of the strings at
578 * PayloadVmOffset will take different forms depending on the message.
580 struct visor_controlvm_parameters_header {
583 u32 connection_offset;
584 u32 connection_length;
585 u32 initiator_offset;
586 u32 initiator_length;
595 /* Natural alignment */
599 /* General Errors------------------------------------------------------[0-99] */
600 #define CONTROLVM_RESP_SUCCESS 0
601 #define CONTROLVM_RESP_ALREADY_DONE 1
602 #define CONTROLVM_RESP_IOREMAP_FAILED 2
603 #define CONTROLVM_RESP_KMALLOC_FAILED 3
604 #define CONTROLVM_RESP_ID_UNKNOWN 4
605 #define CONTROLVM_RESP_ID_INVALID_FOR_CLIENT 5
606 /* CONTROLVM_INIT_CHIPSET-------------------------------------------[100-199] */
607 #define CONTROLVM_RESP_CLIENT_SWITCHCOUNT_NONZERO 100
608 #define CONTROLVM_RESP_EXPECTED_CHIPSET_INIT 101
609 /* Maximum Limit----------------------------------------------------[200-299] */
611 #define CONTROLVM_RESP_ERROR_MAX_BUSES 201
613 #define CONTROLVM_RESP_ERROR_MAX_DEVICES 202
614 /* Payload and Parameter Related------------------------------------[400-499] */
615 /* SWITCH_ATTACHEXTPORT, DEVICE_CONFIGURE */
616 #define CONTROLVM_RESP_PAYLOAD_INVALID 400
618 #define CONTROLVM_RESP_INITIATOR_PARAMETER_INVALID 401
619 /* DEVICE_CONFIGURE */
620 #define CONTROLVM_RESP_TARGET_PARAMETER_INVALID 402
621 /* DEVICE_CONFIGURE */
622 #define CONTROLVM_RESP_CLIENT_PARAMETER_INVALID 403
623 /* Specified[Packet Structure] Value--------------------------------[500-599] */
624 /* SWITCH_ATTACHINTPORT */
625 /* BUS_CONFIGURE, DEVICE_CREATE, DEVICE_CONFIG, DEVICE_DESTROY */
626 #define CONTROLVM_RESP_BUS_INVALID 500
627 /* SWITCH_ATTACHINTPORT*/
628 /* DEVICE_CREATE, DEVICE_CONFIGURE, DEVICE_DESTROY */
629 #define CONTROLVM_RESP_DEVICE_INVALID 501
630 /* DEVICE_CREATE, DEVICE_CONFIGURE */
631 #define CONTROLVM_RESP_CHANNEL_INVALID 502
632 /* Partition Driver Callback Interface------------------------------[600-699] */
633 /* BUS_CREATE, BUS_DESTROY, DEVICE_CREATE, DEVICE_DESTROY */
634 #define CONTROLVM_RESP_VIRTPCI_DRIVER_FAILURE 604
635 /* Unable to invoke VIRTPCI callback. VIRTPCI Callback returned error. */
636 /* BUS_CREATE, BUS_DESTROY, DEVICE_CREATE, DEVICE_DESTROY */
637 #define CONTROLVM_RESP_VIRTPCI_DRIVER_CALLBACK_ERROR 605
638 /* Generic device callback returned error. */
639 /* SWITCH_ATTACHEXTPORT, SWITCH_DETACHEXTPORT, DEVICE_CONFIGURE */
640 #define CONTROLVM_RESP_GENERIC_DRIVER_CALLBACK_ERROR 606
641 /* Bus Related------------------------------------------------------[700-799] */
643 #define CONTROLVM_RESP_ERROR_BUS_DEVICE_ATTACHED 700
644 /* Channel Related--------------------------------------------------[800-899] */
645 /* GET_CHANNELINFO, DEVICE_DESTROY */
646 #define CONTROLVM_RESP_CHANNEL_TYPE_UNKNOWN 800
648 #define CONTROLVM_RESP_CHANNEL_SIZE_TOO_SMALL 801
649 /* Chipset Shutdown Related---------------------------------------[1000-1099] */
650 #define CONTROLVM_RESP_CHIPSET_SHUTDOWN_FAILED 1000
651 #define CONTROLVM_RESP_CHIPSET_SHUTDOWN_ALREADY_ACTIVE 1001
652 /* Chipset Stop Related-------------------------------------------[1100-1199] */
653 #define CONTROLVM_RESP_CHIPSET_STOP_FAILED_BUS 1100
654 #define CONTROLVM_RESP_CHIPSET_STOP_FAILED_SWITCH 1101
655 /* Device Related-------------------------------------------------[1400-1499] */
656 #define CONTROLVM_RESP_DEVICE_UDEV_TIMEOUT 1400
658 /* __CONTROLVMCHANNEL_H__ */