summaryrefslogtreecommitdiffstats
path: root/drivers/visorbus/controlvmchannel.h
blob: c8721355442789a0a4d25a5cdc58973783d2a79d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
 * All rights reserved.
 */

#ifndef __CONTROLVMCHANNEL_H__
#define __CONTROLVMCHANNEL_H__

#include <linux/uuid.h>
#include <linux/visorbus.h>

/* {2B3C2D10-7EF5-4ad8-B966-3448B7386B3D} */
#define VISOR_CONTROLVM_CHANNEL_GUID \
	GUID_INIT(0x2b3c2d10, 0x7ef5, 0x4ad8, \
		  0xb9, 0x66, 0x34, 0x48, 0xb7, 0x38, 0x6b, 0x3d)

#define CONTROLVM_MESSAGE_MAX 64

/*
 * Must increment this whenever you insert or delete fields within this channel
 * struct.  Also increment whenever you change the meaning of fields within this
 * channel struct so as to break pre-existing software. Note that you can
 * usually add fields to the END of the channel struct withOUT needing to
 * increment this.
 */
#define VISOR_CONTROLVM_CHANNEL_VERSIONID 1

/* Defines for various channel queues */
#define CONTROLVM_QUEUE_REQUEST		0
#define CONTROLVM_QUEUE_RESPONSE	1
#define CONTROLVM_QUEUE_EVENT		2
#define CONTROLVM_QUEUE_ACK		3

/* Max num of messages stored during IOVM creation to be reused after crash */
#define CONTROLVM_CRASHMSG_MAX 2

/*
 * struct visor_segment_state
 * @enabled:   May enter other states.
 * @active:    Assigned to active partition.
 * @alive:     Configure message sent to service/server.
 * @revoked:   Similar to partition state ShuttingDown.
 * @allocated: Memory (device/port number) has been selected by Command.
 * @known:     Has been introduced to the service/guest partition.
 * @ready:     Service/Guest partition has responded to introduction.
 * @operating: Resource is configured and operating.
 * @reserved:  Natural alignment.
 *
 * Note: Don't use high bit unless we need to switch to ushort which is
 * non-compliant.
 */
struct visor_segment_state  {
	u16 enabled:1;
	u16 active:1;
	u16 alive:1;
	u16 revoked:1;
	u16 allocated:1;
	u16 known:1;
	u16 ready:1;
	u16 operating:1;
	u16 reserved:8;
} __packed;

static const struct visor_segment_state segment_state_running = {
	1, 1, 1, 0, 1, 1, 1, 1
};

static const struct visor_segment_state segment_state_paused = {
	1, 1, 1, 0, 1, 1, 1, 0
};

static const struct visor_segment_state segment_state_standby = {
	1, 1, 0, 0, 1, 1, 1, 0
};

/*
 * enum controlvm_id
 * @CONTROLVM_INVALID:
 * @CONTROLVM_BUS_CREATE:		CP --> SP, GP.
 * @CONTROLVM_BUS_DESTROY:		CP --> SP, GP.
 * @CONTROLVM_BUS_CONFIGURE:		CP --> SP.
 * @CONTROLVM_BUS_CHANGESTATE:		CP --> SP, GP.
 * @CONTROLVM_BUS_CHANGESTATE_EVENT:	SP, GP --> CP.
 * @CONTROLVM_DEVICE_CREATE:		CP --> SP, GP.
 * @CONTROLVM_DEVICE_DESTROY:		CP --> SP, GP.
 * @CONTROLVM_DEVICE_CONFIGURE:		CP --> SP.
 * @CONTROLVM_DEVICE_CHANGESTATE:	CP --> SP, GP.
 * @CONTROLVM_DEVICE_CHANGESTATE_EVENT:	SP, GP --> CP.
 * @CONTROLVM_DEVICE_RECONFIGURE:	CP --> Boot.
 * @CONTROLVM_CHIPSET_INIT:		CP --> SP, GP.
 * @CONTROLVM_CHIPSET_STOP:		CP --> SP, GP.
 * @CONTROLVM_CHIPSET_READY:		CP --> SP.
 * @CONTROLVM_CHIPSET_SELFTEST:		CP --> SP.
 *
 * Ids for commands that may appear in either queue of a ControlVm channel.
 *
 * Commands that are initiated by the command partition (CP), by an IO or
 * console service partition (SP), or by a guest partition (GP) are:
 * - issued on the RequestQueue queue (q #0) in the ControlVm channel
 * - responded to on the ResponseQueue queue (q #1) in the ControlVm channel
 *
 * Events that are initiated by an IO or console service partition (SP) or
 * by a guest partition (GP) are:
 * - issued on the EventQueue queue (q #2) in the ControlVm channel
 * - responded to on the EventAckQueue queue (q #3) in the ControlVm channel
 */
enum controlvm_id {
	CONTROLVM_INVALID = 0,
	/*
	 * SWITCH commands required Parameter: SwitchNumber.
	 * BUS commands required Parameter: BusNumber
	 */
	CONTROLVM_BUS_CREATE = 0x101,
	CONTROLVM_BUS_DESTROY = 0x102,
	CONTROLVM_BUS_CONFIGURE = 0x104,
	CONTROLVM_BUS_CHANGESTATE = 0x105,
	CONTROLVM_BUS_CHANGESTATE_EVENT = 0x106,
	/* DEVICE commands required Parameter: BusNumber, DeviceNumber */
	CONTROLVM_DEVICE_CREATE = 0x201,
	CONTROLVM_DEVICE_DESTROY = 0x202,
	CONTROLVM_DEVICE_CONFIGURE = 0x203,
	CONTROLVM_DEVICE_CHANGESTATE = 0x204,
	CONTROLVM_DEVICE_CHANGESTATE_EVENT = 0x205,
	CONTROLVM_DEVICE_RECONFIGURE = 0x206,
	/* CHIPSET commands */
	CONTROLVM_CHIPSET_INIT = 0x301,
	CONTROLVM_CHIPSET_STOP = 0x302,
	CONTROLVM_CHIPSET_READY = 0x304,
	CONTROLVM_CHIPSET_SELFTEST = 0x305,
};

/*
 * struct irq_info
 * @reserved1:	     Natural alignment purposes
 * @recv_irq_handle: Specifies interrupt handle. It is used to retrieve the
 *		     corresponding interrupt pin from Monitor; and the interrupt
 *		     pin is used to connect to the corresponding interrupt.
 *		     Used by IOPart-GP only.
 * @recv_irq_vector: Specifies interrupt vector. It, interrupt pin, and shared
 *		     are used to connect to the corresponding interrupt.
 *		     Used by IOPart-GP only.
 * @recv_irq_shared: Specifies if the recvInterrupt is shared.  It, interrupt
 *		     pin and vector are used to connect to 0 = not shared;
 *		     1 = shared the corresponding interrupt.
 *		     Used by IOPart-GP only.
 * @reserved:	     Natural alignment purposes
 */
struct irq_info {
	u64 reserved1;
	u64 recv_irq_handle;
	u32 recv_irq_vector;
	u8 recv_irq_shared;
	u8 reserved[3];
} __packed;

/*
 * struct efi_visor_indication
 * @boot_to_fw_ui: Stop in UEFI UI
 * @clear_nvram:   Clear NVRAM
 * @clear_cmos:	   Clear CMOS
 * @boot_to_tool:  Run install tool
 * @reserved:	   Natural alignment
 */
struct efi_visor_indication  {
	u64 boot_to_fw_ui:1;
	u64 clear_nvram:1;
	u64 clear_cmos:1;
	u64 boot_to_tool:1;
	/* Remaining bits are available */
	u64 reserved:60;
} __packed;

enum visor_chipset_feature {
	VISOR_CHIPSET_FEATURE_REPLY = 0x00000001,
	VISOR_CHIPSET_FEATURE_PARA_HOTPLUG = 0x00000002,
};

/*
 * struct controlvm_message_header
 * @id:		       See CONTROLVM_ID.
 * @message_size:      Includes size of this struct + size of message.
 * @segment_index:     Index of segment containing Vm message/information.
 * @completion_status: Error status code or result of  message completion.
 * @struct flags:
 *	@failed:	     =1 in a response to signify failure.
 *	@response_expected:  =1 in all messages that expect a response.
 *	@server:	     =1 in all bus & device-related messages where the
 *			     message receiver is to act as the bus or device
 *			     server.
 *	@test_message:	     =1 for testing use only (Control and Command
 *			     ignore this).
 *	@partial_completion: =1 if there are forthcoming responses/acks
 *                           associated with this message.
 *      @preserve:	     =1 this is to let us know to preserve channel
 *			     contents.
 *	@writer_in_diag:     =1 the DiagWriter is active in the Diagnostic
 *			     Partition.
 *	@reserve:	     Natural alignment.
 * @reserved:	       Natural alignment.
 * @message_handle:    Identifies the particular message instance.
 * @payload_vm_offset: Offset of payload area from start of this instance.
 * @payload_max_bytes: Maximum bytes allocated in payload area of ControlVm
 *		       segment.
 * @payload_bytes:     Actual number of bytes of payload area to copy between
 *		       IO/Command. If non-zero, there is a payload to copy.
 *
 * This is the common structure that is at the beginning of every
 * ControlVm message (both commands and responses) in any ControlVm
 * queue.  Commands are easily distinguished from responses by
 * looking at the flags.response field.
 */
struct controlvm_message_header  {
	u32 id;
	/*
	 * For requests, indicates the message type. For responses, indicates
	 * the type of message we are responding to.
	 */
	u32 message_size;
	u32 segment_index;
	u32 completion_status;
	struct  {
		u32 failed:1;
		u32 response_expected:1;
		u32 server:1;
		u32 test_message:1;
		u32 partial_completion:1;
		u32 preserve:1;
		u32 writer_in_diag:1;
		u32 reserve:25;
	} __packed flags;
	u32 reserved;
	u64 message_handle;
	u64 payload_vm_offset;
	u32 payload_max_bytes;
	u32 payload_bytes;
} __packed;

/*
 * struct controlvm_packet_device_create - For CONTROLVM_DEVICE_CREATE
 * @bus_no:	    Bus # (0..n-1) from the msg receiver's end.
 * @dev_no:	    Bus-relative (0..n-1) device number.
 * @channel_addr:   Guest physical address of the channel, which can be
 *		    dereferenced by the receiver of this ControlVm command.
 * @channel_bytes:  Specifies size of the channel in bytes.
 * @data_type_uuid: Specifies format of data in channel.
 * @dev_inst_uuid:  Instance guid for the device.
 * @irq_info intr:  Specifies interrupt information.
 */
struct controlvm_packet_device_create  {
	u32 bus_no;
	u32 dev_no;
	u64 channel_addr;
	u64 channel_bytes;
	guid_t data_type_guid;
	guid_t dev_inst_guid;
	struct irq_info intr;
} __packed;

/*
 * struct controlvm_packet_device_configure - For CONTROLVM_DEVICE_CONFIGURE
 * @bus_no: Bus number (0..n-1) from the msg receiver's perspective.
 * @dev_no: Bus-relative (0..n-1) device number.
 */
struct controlvm_packet_device_configure  {
	u32 bus_no;
	u32 dev_no;
} __packed;

/* Total 128 bytes */
struct controlvm_message_device_create {
	struct controlvm_message_header header;
	struct controlvm_packet_device_create packet;
} __packed;

/* Total 56 bytes */
struct controlvm_message_device_configure  {
	struct controlvm_message_header header;
	struct controlvm_packet_device_configure packet;
} __packed;

/*
 * struct controlvm_message_packet - This is the format for a message in any
 *                                   ControlVm queue.
 * @struct create_bus:		For CONTROLVM_BUS_CREATE.
 *	@bus_no:	     Bus # (0..n-1) from the msg receiver's perspective.
 *	@dev_count:	     Indicates the max number of devices on this bus.
 *	@channel_addr:	     Guest physical address of the channel, which can be
 *			     dereferenced by the receiver of this ControlVM
 *			     command.
 *	@channel_bytes:	     Size of the channel.
 *	@bus_data_type_uuid: Indicates format of data in bus channel.
 *	@bus_inst_uuid:	     Instance uuid for the bus.
 *
 * @struct destroy_bus:		For CONTROLVM_BUS_DESTROY.
 *	@bus_no: Bus # (0..n-1) from the msg receiver's perspective.
 *	@reserved: Natural alignment purposes.
 *
 * @struct configure_bus:	For CONTROLVM_BUS_CONFIGURE.
 *	@bus_no:	      Bus # (0..n-1) from the receiver's perspective.
 *	@reserved1:	      For alignment purposes.
 *	@guest_handle:	      This is used to convert guest physical address to
 *			      physical address.
 *	@recv_bus_irq_handle: Specifies interrupt info. It is used by SP to
 *			      register to receive interrupts from the CP. This
 *			      interrupt is used for bus level notifications.
 *			      The corresponding sendBusInterruptHandle is kept
 *			      in CP.
 *
 * @struct create_device:	For CONTROLVM_DEVICE_CREATE.
 *
 * @struct destroy_device:	For CONTROLVM_DEVICE_DESTROY.
 *	@bus_no: Bus # (0..n-1) from the msg receiver's perspective.
 *	@dev_no: Bus-relative (0..n-1) device number.
 *
 * @struct configure_device:	For CONTROLVM_DEVICE_CONFIGURE.
 *
 * @struct reconfigure_device:	For CONTROLVM_DEVICE_RECONFIGURE.
 *	@bus_no: Bus # (0..n-1) from the msg receiver's perspective.
 *	@dev_no: Bus-relative (0..n-1) device number.
 *
 * @struct bus_change_state:	For CONTROLVM_BUS_CHANGESTATE.
 *	@bus_no:
 *	@struct state:
 *	@reserved: Natural alignment purposes.
 *
 * @struct device_change_state:	For CONTROLVM_DEVICE_CHANGESTATE.
 *	@bus_no:
 *	@dev_no:
 *	@struct state:
 *	@struct flags:
 *		@phys_device: =1 if message is for a physical device.
 *		@reserved:    Natural alignment.
 *		@reserved1:   Natural alignment.
 *	@reserved:    Natural alignment purposes.
 *
 * @struct device_change_state_event:	For CONTROLVM_DEVICE_CHANGESTATE_EVENT.
 *	@bus_no:
 *	@dev_no:
 *	@struct state:
 *	@reserved:     Natural alignment purposes.
 *
 * @struct init_chipset:	For CONTROLVM_CHIPSET_INIT.
 *	@bus_count:	  Indicates the max number of busses.
 *	@switch_count:    Indicates the max number of switches.
 *	@enum features:
 *	@platform_number:
 *
 * @struct chipset_selftest:	For CONTROLVM_CHIPSET_SELFTEST.
 *      @options: Reserved.
 *      @test:	  Bit 0 set to run embedded selftest.
 *
 * @addr:   A physical address of something, that can be dereferenced by the
 *	    receiver of this ControlVm command.
 *
 * @handle: A handle of something (depends on command id).
 */
struct controlvm_message_packet  {
	union  {
		struct  {
			u32 bus_no;
			u32 dev_count;
			u64 channel_addr;
			u64 channel_bytes;
			guid_t bus_data_type_guid;
			guid_t bus_inst_guid;
		} __packed create_bus;
		struct  {
			u32 bus_no;
			u32 reserved;
		} __packed