• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2010 - 2015 UNISYS CORPORATION
2  * All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms and conditions of the GNU General Public License,
6  * version 2, as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11  * NON INFRINGEMENT.  See the GNU General Public License for more
12  * details.
13  */
14 
15 #ifndef __CONTROLVMCHANNEL_H__
16 #define __CONTROLVMCHANNEL_H__
17 
18 #include <linux/uuid.h>
19 #include "channel.h"
20 
21 /* {2B3C2D10-7EF5-4ad8-B966-3448B7386B3D} */
22 #define SPAR_CONTROLVM_CHANNEL_PROTOCOL_UUID	\
23 		UUID_LE(0x2b3c2d10, 0x7ef5, 0x4ad8, \
24 			0xb9, 0x66, 0x34, 0x48, 0xb7, 0x38, 0x6b, 0x3d)
25 
26 #define ULTRA_CONTROLVM_CHANNEL_PROTOCOL_SIGNATURE \
27 	ULTRA_CHANNEL_PROTOCOL_SIGNATURE
28 #define CONTROLVM_MESSAGE_MAX 64
29 
30 /* Must increment this whenever you insert or delete fields within
31  * this channel struct.  Also increment whenever you change the meaning
32  * of fields within this channel struct so as to break pre-existing
33  * software.  Note that you can usually add fields to the END of the
34  * channel struct withOUT needing to increment this.
35  */
36 #define ULTRA_CONTROLVM_CHANNEL_PROTOCOL_VERSIONID  1
37 
38 #define SPAR_CONTROLVM_CHANNEL_OK_CLIENT(ch)           \
39 	spar_check_channel_client(ch, \
40 		SPAR_CONTROLVM_CHANNEL_PROTOCOL_UUID, \
41 		"controlvm", \
42 		sizeof(struct spar_controlvm_channel_protocol), \
43 		ULTRA_CONTROLVM_CHANNEL_PROTOCOL_VERSIONID, \
44 		ULTRA_CONTROLVM_CHANNEL_PROTOCOL_SIGNATURE)
45 
46 #define MAX_SERIAL_NUM	32
47 
48 /* Defines for various channel queues */
49 #define CONTROLVM_QUEUE_REQUEST		0
50 #define CONTROLVM_QUEUE_RESPONSE	1
51 #define CONTROLVM_QUEUE_EVENT		2
52 #define CONTROLVM_QUEUE_ACK		3
53 
54 /* Max num of messages stored during IOVM creation to be reused after crash */
55 #define CONTROLVM_CRASHMSG_MAX		2
56 
57 struct spar_segment_state  {
58 	u16 enabled:1;		/* Bit 0: May enter other states */
59 	u16 active:1;		/* Bit 1: Assigned to active partition */
60 	u16 alive:1;		/* Bit 2: Configure message sent to
61 				 * service/server */
62 	u16 revoked:1;		/* Bit 3: similar to partition state
63 				 * ShuttingDown */
64 	u16 allocated:1;	/* Bit 4: memory (device/port number)
65 				 * has been selected by Command */
66 	u16 known:1;		/* Bit 5: has been introduced to the
67 				 * service/guest partition */
68 	u16 ready:1;		/* Bit 6: service/Guest partition has
69 				 * responded to introduction */
70 	u16 operating:1;	/* Bit 7: resource is configured and
71 				 * operating */
72 	/* Note: don't use high bit unless we need to switch to ushort
73 	 * which is non-compliant */
74 };
75 
76 static const struct spar_segment_state segment_state_running = {
77 	1, 1, 1, 0, 1, 1, 1, 1
78 };
79 
80 static const struct spar_segment_state segment_state_paused = {
81 	1, 1, 1, 0, 1, 1, 1, 0
82 };
83 
84 static const struct spar_segment_state segment_state_standby = {
85 	1, 1, 0, 0, 1, 1, 1, 0
86 };
87 
88 /* Ids for commands that may appear in either queue of a ControlVm channel.
89  *
90  *  Commands that are initiated by the command partition (CP), by an IO or
91  *  console service partition (SP), or by a guest partition (GP)are:
92  *  - issued on the RequestQueue queue (q #0) in the ControlVm channel
93  *  - responded to on the ResponseQueue queue (q #1) in the ControlVm channel
94  *
95  *  Events that are initiated by an IO or console service partition (SP) or
96  *  by a guest partition (GP) are:
97  *  - issued on the EventQueue queue (q #2) in the ControlVm channel
98  *  - responded to on the EventAckQueue queue (q #3) in the ControlVm channel
99  */
100 enum controlvm_id {
101 	CONTROLVM_INVALID = 0,
102 	/* SWITCH commands required Parameter: SwitchNumber */
103 	/* BUS commands required Parameter: BusNumber */
104 	CONTROLVM_BUS_CREATE = 0x101,			/* CP --> SP, GP */
105 	CONTROLVM_BUS_DESTROY = 0x102,			/* CP --> SP, GP */
106 	CONTROLVM_BUS_CONFIGURE = 0x104,		/* CP --> SP */
107 	CONTROLVM_BUS_CHANGESTATE = 0x105,		/* CP --> SP, GP */
108 	CONTROLVM_BUS_CHANGESTATE_EVENT = 0x106,	/* SP, GP --> CP */
109 /* DEVICE commands required Parameter: BusNumber, DeviceNumber */
110 
111 	CONTROLVM_DEVICE_CREATE = 0x201,		/* CP --> SP, GP */
112 	CONTROLVM_DEVICE_DESTROY = 0x202,		/* CP --> SP, GP */
113 	CONTROLVM_DEVICE_CONFIGURE = 0x203,		/* CP --> SP */
114 	CONTROLVM_DEVICE_CHANGESTATE = 0x204,		/* CP --> SP, GP */
115 	CONTROLVM_DEVICE_CHANGESTATE_EVENT = 0x205,	/* SP, GP --> CP */
116 	CONTROLVM_DEVICE_RECONFIGURE = 0x206,		/* CP --> Boot */
117 /* CHIPSET commands */
118 	CONTROLVM_CHIPSET_INIT = 0x301,			/* CP --> SP, GP */
119 	CONTROLVM_CHIPSET_STOP = 0x302,			/* CP --> SP, GP */
120 	CONTROLVM_CHIPSET_READY = 0x304,		/* CP --> SP */
121 	CONTROLVM_CHIPSET_SELFTEST = 0x305,		/* CP --> SP */
122 
123 };
124 
125 struct irq_info {
126 	u64 reserved1;
127 
128 	 /* specifies interrupt handle. It is used to retrieve the
129 	  *   corresponding interrupt pin from Monitor; and the
130 	  *   interrupt pin is used to connect to the corresponding
131 	  *   interrupt.  Used by IOPart-GP only.
132 	  */
133 	u64 recv_irq_handle;
134 
135 	 /* specifies interrupt vector. It, interrupt pin, and shared are
136 	  *   used to connect to the corresponding interrupt.  Used by
137 	  *   IOPart-GP only.
138 	  */
139 	u32 recv_irq_vector;
140 
141     /* specifies if the recvInterrupt is shared.  It, interrupt pin
142      * and vector are used to connect to 0 = not shared; 1 = shared.
143      * the corresponding interrupt.  Used by IOPart-GP only.
144      */
145 	u8 recv_irq_shared;
146 	u8 reserved[3];	/* Natural alignment purposes */
147 };
148 
149 struct pci_id {
150 	u16 domain;
151 	u8 bus;
152 	u8 slot;
153 	u8 func;
154 	u8 reserved[3];	/* Natural alignment purposes */
155 };
156 
157 struct efi_spar_indication  {
158 	u64 boot_to_fw_ui:1;		/* Bit 0: Stop in uefi ui */
159 	u64 clear_nvram:1;		/* Bit 1: Clear NVRAM */
160 	u64 clear_cmos:1;		/* Bit 2: Clear CMOS */
161 	u64 boot_to_tool:1;		/* Bit 3: Run install tool */
162 	/* remaining bits are available */
163 };
164 
165 enum ultra_chipset_feature {
166 	ULTRA_CHIPSET_FEATURE_REPLY = 0x00000001,
167 	ULTRA_CHIPSET_FEATURE_PARA_HOTPLUG = 0x00000002,
168 };
169 
170 /* This is the common structure that is at the beginning of every
171  *  ControlVm message (both commands and responses) in any ControlVm
172  *  queue.  Commands are easily distinguished from responses by
173  *  looking at the flags.response field.
174  */
175 struct controlvm_message_header  {
176 	u32 id;		/* See CONTROLVM_ID. */
177 	/* For requests, indicates the message type. */
178 	/* For responses, indicates the type of message we are responding to. */
179 
180 	u32 message_size;	/* Includes size of this struct + size
181 				 * of message */
182 	u32 segment_index;	/* Index of segment containing Vm
183 				 * message/information */
184 	u32 completion_status;	/* Error status code or result of
185 				 * message completion */
186 	struct  {
187 		u32 failed:1;		   /* =1 in a response to * signify
188 					    * failure */
189 		u32 response_expected:1;   /* =1 in all messages that expect a
190 					    * response (Control ignores this
191 					    * bit) */
192 		u32 server:1;		   /* =1 in all bus & device-related
193 					    * messages where the message
194 					    * receiver is to act as the bus or
195 					    * device server */
196 		u32 test_message:1;	   /* =1 for testing use only
197 					    * (Control and Command ignore this
198 					    * bit) */
199 		u32 partial_completion:1;  /* =1 if there are forthcoming
200 					    * responses/acks associated
201 					    * with this message */
202 		u32 preserve:1;		   /* =1 this is to let us know to
203 					    * preserve channel contents
204 					    * (for running guests)*/
205 		u32 writer_in_diag:1;	   /* =1 the DiagWriter is active in the
206 					    * Diagnostic Partition*/
207 	} flags;
208 	u32 reserved;		/* Natural alignment */
209 	u64 message_handle;	/* Identifies the particular message instance,
210 				 * and is used to match particular */
211 	/* request instances with the corresponding response instance. */
212 	u64 payload_vm_offset;	/* Offset of payload area from start of this
213 				 * instance of ControlVm segment */
214 	u32 payload_max_bytes;	/* Maximum bytes allocated in payload
215 				 * area of ControlVm segment */
216 	u32 payload_bytes;	/* Actual number of bytes of payload
217 				 * area to copy between IO/Command; */
218 	/* if non-zero, there is a payload to copy. */
219 };
220 
221 struct controlvm_packet_device_create  {
222 	u32 bus_no;		/* bus # (0..n-1) from the msg receiver's end */
223 	u32 dev_no;		/* bus-relative (0..n-1) device number */
224 	u64 channel_addr;	/* Guest physical address of the channel, which
225 				 * can be dereferenced by the receiver of this
226 				 * ControlVm command */
227 	u64 channel_bytes;	/* specifies size of the channel in bytes */
228 	uuid_le data_type_uuid;	/* specifies format of data in channel */
229 	uuid_le dev_inst_uuid;	/* instance guid for the device */
230 	struct irq_info intr;	/* specifies interrupt information */
231 };	/* for CONTROLVM_DEVICE_CREATE */
232 
233 struct controlvm_packet_device_configure  {
234 	u32 bus_no;	      /* bus # (0..n-1) from the msg
235 			       * receiver's perspective */
236 	/* Control uses header SegmentIndex field to access bus number... */
237 	u32 dev_no;	      /* bus-relative (0..n-1) device number */
238 } ;	/* for CONTROLVM_DEVICE_CONFIGURE */
239 
240 struct controlvm_message_device_create {
241 	struct controlvm_message_header header;
242 	struct controlvm_packet_device_create packet;
243 };	/* total 128 bytes */
244 
245 struct controlvm_message_device_configure  {
246 	struct controlvm_message_header header;
247 	struct controlvm_packet_device_configure packet;
248 };	/* total 56 bytes */
249 
250 /* This is the format for a message in any ControlVm queue. */
251 struct controlvm_message_packet  {
252 	union  {
253 		struct  {
254 			u32 bus_no;	/* bus # (0..n-1) from the msg
255 					 * receiver's perspective */
256 			u32 dev_count;	/* indicates the max number of
257 					 * devices on this bus */
258 			u64 channel_addr;	/* Guest physical address of
259 						 * the channel, which can be
260 						 * dereferenced by the receiver
261 						 * of this ControlVm command */
262 			u64 channel_bytes;	/* size of the channel */
263 			uuid_le bus_data_type_uuid;	/* indicates format of
264 							 * data in bus channel*/
265 			uuid_le bus_inst_uuid;	/* instance uuid for the bus */
266 		} create_bus;	/* for CONTROLVM_BUS_CREATE */
267 		struct  {
268 			u32 bus_no;	/* bus # (0..n-1) from the msg
269 					 * receiver's perspective */
270 			u32 reserved;	/* Natural alignment purposes */
271 		} destroy_bus;	/* for CONTROLVM_BUS_DESTROY */
272 		struct  {
273 			u32 bus_no;	/* bus # (0..n-1) from the receiver's
274 					 * perspective */
275 			u32 reserved1;	/* for alignment purposes */
276 			u64 guest_handle;	/* This is used to convert
277 						 * guest physical address to
278 						 * physical address */
279 			u64 recv_bus_irq_handle;
280 				/* specifies interrupt info. It is used by SP
281 				 * to register to receive interrupts from the
282 				 * CP. This interrupt is used for bus level
283 				 * notifications.  The corresponding
284 				 * sendBusInterruptHandle is kept in CP. */
285 		} configure_bus;	/* for CONTROLVM_BUS_CONFIGURE */
286 		/* for CONTROLVM_DEVICE_CREATE */
287 		struct controlvm_packet_device_create create_device;
288 		struct  {
289 			u32 bus_no;	/* bus # (0..n-1) from the msg
290 					 * receiver's perspective */
291 			u32 dev_no;	/* bus-relative (0..n-1) device # */
292 		} destroy_device;	/* for CONTROLVM_DEVICE_DESTROY */
293 		/* for CONTROLVM_DEVICE_CONFIGURE */
294 		struct controlvm_packet_device_configure configure_device;
295 		struct  {
296 			u32 bus_no;	/* bus # (0..n-1) from the msg
297 					 * receiver's perspective */
298 			u32 dev_no;	/* bus-relative (0..n-1) device # */
299 		} reconfigure_device;	/* for CONTROLVM_DEVICE_RECONFIGURE */
300 		struct  {
301 			u32 bus_no;
302 			struct spar_segment_state state;
303 			u8 reserved[2];	/* Natural alignment purposes */
304 		} bus_change_state;	/* for CONTROLVM_BUS_CHANGESTATE */
305 		struct  {
306 			u32 bus_no;
307 			u32 dev_no;
308 			struct spar_segment_state state;
309 			struct  {
310 				u32 phys_device:1;	/* =1 if message is for
311 							 * a physical device */
312 			} flags;
313 			u8 reserved[2];	/* Natural alignment purposes */
314 		} device_change_state;	/* for CONTROLVM_DEVICE_CHANGESTATE */
315 		struct  {
316 			u32 bus_no;
317 			u32 dev_no;
318 			struct spar_segment_state state;
319 			u8 reserved[6];	/* Natural alignment purposes */
320 		} device_change_state_event;
321 			/* for CONTROLVM_DEVICE_CHANGESTATE_EVENT */
322 		struct  {
323 			u32 bus_count;	/* indicates the max number of busses */
324 			u32 switch_count; /* indicates the max number of
325 					   * switches if a service partition */
326 			enum ultra_chipset_feature features;
327 			u32 platform_number;	/* Platform Number */
328 		} init_chipset;	/* for CONTROLVM_CHIPSET_INIT */
329 		struct  {
330 			u32 options;	/* reserved */
331 			u32 test;	/* bit 0 set to run embedded selftest */
332 		} chipset_selftest;	/* for CONTROLVM_CHIPSET_SELFTEST */
333 		u64 addr;	/* a physical address of something, that can be
334 				 * dereferenced by the receiver of this
335 				 * ControlVm command (depends on command id) */
336 		u64 handle;	/* a handle of something (depends on command
337 				 * id) */
338 	};
339 };
340 
341 /* All messages in any ControlVm queue have this layout. */
342 struct controlvm_message {
343 	struct controlvm_message_header hdr;
344 	struct controlvm_message_packet cmd;
345 };
346 
347 struct spar_controlvm_channel_protocol {
348 	struct channel_header header;
349 	u64 gp_controlvm;	/* guest phys addr of this channel */
350 	u64 gp_partition_tables;/* guest phys addr of partition tables */
351 	u64 gp_diag_guest;	/* guest phys addr of diagnostic channel */
352 	u64 gp_boot_romdisk;/* guest phys addr of (read* only) Boot ROM disk */
353 	u64 gp_boot_ramdisk;/* guest phys addr of writable Boot RAM disk */
354 	u64 gp_acpi_table;	/* guest phys addr of acpi table */
355 	u64 gp_control_channel;/* guest phys addr of control channel */
356 	u64 gp_diag_romdisk;/* guest phys addr of diagnostic ROM disk */
357 	u64 gp_nvram;	/* guest phys addr of NVRAM channel */
358 	u64 request_payload_offset;	/* Offset to request payload area */
359 	u64 event_payload_offset;	/* Offset to event payload area */
360 	u32 request_payload_bytes;	/* Bytes available in request payload
361 					 * area */
362 	u32 event_payload_bytes;/* Bytes available in event payload area */
363 	u32 control_channel_bytes;
364 	u32 nvram_channel_bytes;	/* Bytes in PartitionNvram segment */
365 	u32 message_bytes;		/* sizeof(CONTROLVM_MESSAGE) */
366 	u32 message_count;		/* CONTROLVM_MESSAGE_MAX */
367 	u64 gp_smbios_table;		/* guest phys addr of SMBIOS tables */
368 	u64 gp_physical_smbios_table;	/* guest phys addr of SMBIOS table  */
369 	/* ULTRA_MAX_GUESTS_PER_SERVICE */
370 	char gp_reserved[2688];
371 
372 	/* guest physical address of EFI firmware image base  */
373 	u64 virtual_guest_firmware_image_base;
374 
375 	/* guest physical address of EFI firmware entry point  */
376 	u64 virtual_guest_firmware_entry_point;
377 
378 	/* guest EFI firmware image size  */
379 	u64 virtual_guest_firmware_image_size;
380 
381 	/* GPA = 1MB where EFI firmware image is copied to  */
382 	u64 virtual_guest_firmware_boot_base;
383 	u64 virtual_guest_image_base;
384 	u64 virtual_guest_image_size;
385 	u64 prototype_control_channel_offset;
386 	u64 virtual_guest_partition_handle;
387 
388 	u16 restore_action;	/* Restore Action field to restore the guest
389 				 * partition */
390 	u16 dump_action;	/* For Windows guests it shows if the visordisk
391 				 * is running in dump mode */
392 	u16 nvram_fail_count;
393 	u16 saved_crash_message_count;	/* = CONTROLVM_CRASHMSG_MAX */
394 	u32 saved_crash_message_offset;	/* Offset to request payload area needed
395 					 * for crash dump */
396 	u32 installation_error;	/* Type of error encountered during
397 				 * installation */
398 	u32 installation_text_id;	/* Id of string to display */
399 	u16 installation_remaining_steps;/* Number of remaining installation
400 					  * steps (for progress bars) */
401 	u8 tool_action;		/* ULTRA_TOOL_ACTIONS Installation Action
402 				 * field */
403 	u8 reserved;		/* alignment */
404 	struct efi_spar_indication efi_spar_ind;
405 	struct efi_spar_indication efi_spar_ind_supported;
406 	u32 sp_reserved;
407 	u8 reserved2[28];	/* Force signals to begin on 128-byte cache
408 				 * line */
409 	struct signal_queue_header request_queue;/* Service or guest partition
410 						  * uses this queue to send
411 						  * requests to Control */
412 	struct signal_queue_header response_queue;/* Control uses this queue to
413 						   * respond to service or guest
414 						   * partition requests */
415 	struct signal_queue_header event_queue;	/* Control uses this queue to
416 						 * send events to service or
417 						 * guest partition */
418 	struct signal_queue_header event_ack_queue;/* Service or guest partition
419 						    * uses this queue to ack
420 						    * Control events */
421 
422 	 /* Request fixed-size message pool - does not include payload */
423 	 struct controlvm_message request_msg[CONTROLVM_MESSAGE_MAX];
424 
425 	 /* Response fixed-size message pool - does not include payload */
426 	 struct controlvm_message response_msg[CONTROLVM_MESSAGE_MAX];
427 
428 	 /* Event fixed-size message pool - does not include payload */
429 	 struct controlvm_message event_msg[CONTROLVM_MESSAGE_MAX];
430 
431 	 /* Ack fixed-size message pool - does not include payload */
432 	 struct controlvm_message event_ack_msg[CONTROLVM_MESSAGE_MAX];
433 
434 	 /* Message stored during IOVM creation to be reused after crash */
435 	 struct controlvm_message saved_crash_msg[CONTROLVM_CRASHMSG_MAX];
436 };
437 
438 /* Offsets for VM channel attributes */
439 #define VM_CH_REQ_QUEUE_OFFSET \
440 	offsetof(struct spar_controlvm_channel_protocol, request_queue)
441 #define VM_CH_RESP_QUEUE_OFFSET \
442 	offsetof(struct spar_controlvm_channel_protocol, response_queue)
443 #define VM_CH_EVENT_QUEUE_OFFSET \
444 	offsetof(struct spar_controlvm_channel_protocol, event_queue)
445 #define VM_CH_ACK_QUEUE_OFFSET \
446 	offsetof(struct spar_controlvm_channel_protocol, event_ack_queue)
447 #define VM_CH_REQ_MSG_OFFSET \
448 	offsetof(struct spar_controlvm_channel_protocol, request_msg)
449 #define VM_CH_RESP_MSG_OFFSET \
450 	offsetof(struct spar_controlvm_channel_protocol, response_msg)
451 #define VM_CH_EVENT_MSG_OFFSET \
452 	offsetof(struct spar_controlvm_channel_protocol, event_msg)
453 #define VM_CH_ACK_MSG_OFFSET \
454 	offsetof(struct spar_controlvm_channel_protocol, event_ack_msg)
455 #define VM_CH_CRASH_MSG_OFFSET \
456 	offsetof(struct spar_controlvm_channel_protocol, saved_crash_msg)
457 
458 /* The following header will be located at the beginning of PayloadVmOffset for
459  * various ControlVm commands. The receiver of a ControlVm command with a
460  * PayloadVmOffset will dereference this address and then use connection_offset,
461  * initiator_offset, and target_offset to get the location of UTF-8 formatted
462  * strings that can be parsed to obtain command-specific information. The value
463  * of total_length should equal PayloadBytes. The format of the strings at
464  * PayloadVmOffset will take different forms depending on the message.
465  */
466 struct spar_controlvm_parameters_header {
467 	u32 total_length;
468 	u32 header_length;
469 	u32 connection_offset;
470 	u32 connection_length;
471 	u32 initiator_offset;
472 	u32 initiator_length;
473 	u32 target_offset;
474 	u32 target_length;
475 	u32 client_offset;
476 	u32 client_length;
477 	u32 name_offset;
478 	u32 name_length;
479 	uuid_le id;
480 	u32 revision;
481 	u32 reserved;		/* Natural alignment */
482 };
483 
484 #endif				/* __CONTROLVMCHANNEL_H__ */
485