blob: 0d8bd6769b13d2ffda7173b09bc3cdb7090c39f9 [file] [log] [blame]
Greg Kroah-Hartmanb79c0f42017-11-07 14:58:47 +01001// SPDX-License-Identifier: GPL-2.0+
David Kershnera595a7f2017-08-22 13:27:11 -04002/*
Erik Arfvidson37039872015-05-05 18:36:00 -04003 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
4 * All rights reserved.
Erik Arfvidson37039872015-05-05 18:36:00 -04005 */
6
7/*
8 * This header file is to be included by other kernel mode components that
9 * implement a particular kind of visor_device. Each of these other kernel
10 * mode components is called a visor device driver. Refer to visortemplate
11 * for a minimal sample visor device driver.
12 *
13 * There should be nothing in this file that is private to the visorbus
14 * bus implementation itself.
Erik Arfvidson37039872015-05-05 18:36:00 -040015 */
16
17#ifndef __VISORBUS_H__
18#define __VISORBUS_H__
19
20#include <linux/device.h>
Erik Arfvidson37039872015-05-05 18:36:00 -040021
David Kershnerf09177a2017-12-06 11:05:27 -050022#define VISOR_CHANNEL_SIGNATURE ('L' << 24 | 'N' << 16 | 'C' << 8 | 'E')
Don Zickusf6439212015-05-05 18:36:02 -040023
David Kershnerf09177a2017-12-06 11:05:27 -050024/*
25 * enum channel_serverstate
26 * @CHANNELSRV_UNINITIALIZED: Channel is in an undefined state.
27 * @CHANNELSRV_READY: Channel has been initialized by server.
28 */
29enum channel_serverstate {
30 CHANNELSRV_UNINITIALIZED = 0,
31 CHANNELSRV_READY = 1
32};
33
34/*
35 * enum channel_clientstate
36 * @CHANNELCLI_DETACHED:
37 * @CHANNELCLI_DISABLED: Client can see channel but is NOT allowed to use it
38 * unless given TBD* explicit request
39 * (should actually be < DETACHED).
40 * @CHANNELCLI_ATTACHING: Legacy EFI client request for EFI server to attach.
41 * @CHANNELCLI_ATTACHED: Idle, but client may want to use channel any time.
42 * @CHANNELCLI_BUSY: Client either wants to use or is using channel.
43 * @CHANNELCLI_OWNED: "No worries" state - client can access channel
44 * anytime.
45 */
46enum channel_clientstate {
47 CHANNELCLI_DETACHED = 0,
48 CHANNELCLI_DISABLED = 1,
49 CHANNELCLI_ATTACHING = 2,
50 CHANNELCLI_ATTACHED = 3,
51 CHANNELCLI_BUSY = 4,
52 CHANNELCLI_OWNED = 5
53};
54
55/*
56 * Values for VISOR_CHANNEL_PROTOCOL.Features: This define exists so that
57 * a guest can look at the FeatureFlags in the io channel, and configure the
58 * driver to use interrupts or not based on this setting. All feature bits for
59 * all channels should be defined here. The io channel feature bits are defined
60 * below.
61 */
62#define VISOR_DRIVER_ENABLES_INTS (0x1ULL << 1)
63#define VISOR_CHANNEL_IS_POLLING (0x1ULL << 3)
64#define VISOR_IOVM_OK_DRIVER_DISABLING_INTS (0x1ULL << 4)
65#define VISOR_DRIVER_DISABLES_INTS (0x1ULL << 5)
66#define VISOR_DRIVER_ENHANCED_RCVBUF_CHECKING (0x1ULL << 6)
67
68/*
69 * struct channel_header - Common Channel Header
70 * @signature: Signature.
71 * @legacy_state: DEPRECATED - being replaced by.
72 * @header_size: sizeof(struct channel_header).
73 * @size: Total size of this channel in bytes.
74 * @features: Flags to modify behavior.
75 * @chtype: Channel type: data, bus, control, etc..
76 * @partition_handle: ID of guest partition.
77 * @handle: Device number of this channel in client.
78 * @ch_space_offset: Offset in bytes to channel specific area.
79 * @version_id: Struct channel_header Version ID.
80 * @partition_index: Index of guest partition.
81 * @zone_uuid: Guid of Channel's zone.
82 * @cli_str_offset: Offset from channel header to null-terminated
83 * ClientString (0 if ClientString not present).
84 * @cli_state_boot: CHANNEL_CLIENTSTATE of pre-boot EFI client of this
85 * channel.
86 * @cmd_state_cli: CHANNEL_COMMANDSTATE (overloaded in Windows drivers, see
87 * ServerStateUp, ServerStateDown, etc).
88 * @cli_state_os: CHANNEL_CLIENTSTATE of Guest OS client of this channel.
89 * @ch_characteristic: CHANNEL_CHARACTERISTIC_<xxx>.
90 * @cmd_state_srv: CHANNEL_COMMANDSTATE (overloaded in Windows drivers, see
91 * ServerStateUp, ServerStateDown, etc).
92 * @srv_state: CHANNEL_SERVERSTATE.
93 * @cli_error_boot: Bits to indicate err states for boot clients, so err
94 * messages can be throttled.
95 * @cli_error_os: Bits to indicate err states for OS clients, so err
96 * messages can be throttled.
97 * @filler: Pad out to 128 byte cacheline.
98 * @recover_channel: Please add all new single-byte values below here.
99 */
100struct channel_header {
101 u64 signature;
102 u32 legacy_state;
103 /* SrvState, CliStateBoot, and CliStateOS below */
104 u32 header_size;
105 u64 size;
106 u64 features;
107 guid_t chtype;
108 u64 partition_handle;
109 u64 handle;
110 u64 ch_space_offset;
111 u32 version_id;
112 u32 partition_index;
113 guid_t zone_guid;
114 u32 cli_str_offset;
115 u32 cli_state_boot;
116 u32 cmd_state_cli;
117 u32 cli_state_os;
118 u32 ch_characteristic;
119 u32 cmd_state_srv;
120 u32 srv_state;
121 u8 cli_error_boot;
122 u8 cli_error_os;
123 u8 filler[1];
124 u8 recover_channel;
125} __packed;
126
127#define VISOR_CHANNEL_ENABLE_INTS (0x1ULL << 0)
128
129/*
130 * struct signal_queue_header - Subheader for the Signal Type variation of the
131 * Common Channel.
132 * @version: SIGNAL_QUEUE_HEADER Version ID.
133 * @chtype: Queue type: storage, network.
134 * @size: Total size of this queue in bytes.
135 * @sig_base_offset: Offset to signal queue area.
136 * @features: Flags to modify behavior.
137 * @num_sent: Total # of signals placed in this queue.
138 * @num_overflows: Total # of inserts failed due to full queue.
139 * @signal_size: Total size of a signal for this queue.
140 * @max_slots: Max # of slots in queue, 1 slot is always empty.
141 * @max_signals: Max # of signals in queue (MaxSignalSlots-1).
142 * @head: Queue head signal #.
143 * @num_received: Total # of signals removed from this queue.
144 * @tail: Queue tail signal.
145 * @reserved1: Reserved field.
146 * @reserved2: Reserved field.
147 * @client_queue:
148 * @num_irq_received: Total # of Interrupts received. This is incremented by the
149 * ISR in the guest windows driver.
150 * @num_empty: Number of times that visor_signal_remove is called and
151 * returned Empty Status.
152 * @errorflags: Error bits set during SignalReinit to denote trouble with
153 * client's fields.
154 * @filler: Pad out to 64 byte cacheline.
155 */
156struct signal_queue_header {
157 /* 1st cache line */
158 u32 version;
159 u32 chtype;
160 u64 size;
161 u64 sig_base_offset;
162 u64 features;
163 u64 num_sent;
164 u64 num_overflows;
165 u32 signal_size;
166 u32 max_slots;
167 u32 max_signals;
168 u32 head;
169 /* 2nd cache line */
170 u64 num_received;
171 u32 tail;
172 u32 reserved1;
173 u64 reserved2;
174 u64 client_queue;
175 u64 num_irq_received;
176 u64 num_empty;
177 u32 errorflags;
178 u8 filler[12];
179} __packed;
180
181/* VISORCHANNEL Guids */
182/* {414815ed-c58c-11da-95a9-00e08161165f} */
183#define VISOR_VHBA_CHANNEL_GUID \
184 GUID_INIT(0x414815ed, 0xc58c, 0x11da, \
185 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f)
186#define VISOR_VHBA_CHANNEL_GUID_STR \
187 "414815ed-c58c-11da-95a9-00e08161165f"
Don Zickus1fb30162015-05-13 13:22:18 -0400188struct visorchipset_state {
189 u32 created:1;
190 u32 attached:1;
191 u32 configured:1;
192 u32 running:1;
Sameer Wadgaonkarb2d06ca2017-09-27 13:14:46 -0400193 /* Remaining bits in this 32-bit word are reserved. */
Don Zickus1fb30162015-05-13 13:22:18 -0400194};
Erik Arfvidson37039872015-05-05 18:36:00 -0400195
Alexander Curtin39b92802016-04-18 23:22:02 -0400196/**
197 * struct visor_device - A device type for things "plugged" into the visorbus
Sameer Wadgaonkarb2d06ca2017-09-27 13:14:46 -0400198 * bus
David Bindereafc6a92016-06-10 21:48:20 -0400199 * @visorchannel: Points to the channel that the device is
Alexander Curtin39b92802016-04-18 23:22:02 -0400200 * associated with.
David Bindereafc6a92016-06-10 21:48:20 -0400201 * @channel_type_guid: Identifies the channel type to the bus driver.
202 * @device: Device struct meant for use by the bus driver
Alexander Curtin39b92802016-04-18 23:22:02 -0400203 * only.
David Bindereafc6a92016-06-10 21:48:20 -0400204 * @list_all: Used by the bus driver to enumerate devices.
205 * @timer: Timer fired periodically to do interrupt-type
Tim Sell9ebab642016-06-10 21:48:08 -0400206 * activity.
David Bindereafc6a92016-06-10 21:48:20 -0400207 * @being_removed: Indicates that the device is being removed from
Alexander Curtin39b92802016-04-18 23:22:02 -0400208 * the bus. Private bus driver use only.
David Kershnereaec40a2017-08-30 13:36:18 -0400209 * @visordriver_callback_lock: Used by the bus driver to lock when adding and
210 * removing devices.
David Bindereafc6a92016-06-10 21:48:20 -0400211 * @pausing: Indicates that a change towards a paused state.
Alexander Curtin39b92802016-04-18 23:22:02 -0400212 * is in progress. Only modified by the bus driver.
David Bindereafc6a92016-06-10 21:48:20 -0400213 * @resuming: Indicates that a change towards a running state
Alexander Curtin39b92802016-04-18 23:22:02 -0400214 * is in progress. Only modified by the bus driver.
David Bindereafc6a92016-06-10 21:48:20 -0400215 * @chipset_bus_no: Private field used by the bus driver.
216 * @chipset_dev_no: Private field used the bus driver.
217 * @state: Used to indicate the current state of the
Alexander Curtin39b92802016-04-18 23:22:02 -0400218 * device.
David Bindereafc6a92016-06-10 21:48:20 -0400219 * @inst: Unique GUID for this instance of the device.
220 * @name: Name of the device.
221 * @pending_msg_hdr: For private use by bus driver to respond to
Alexander Curtin39b92802016-04-18 23:22:02 -0400222 * hypervisor requests.
David Bindereafc6a92016-06-10 21:48:20 -0400223 * @vbus_hdr_info: A pointer to header info. Private use by bus
Alexander Curtin39b92802016-04-18 23:22:02 -0400224 * driver.
Andy Shevchenkob32c5cb2017-08-22 13:26:54 -0400225 * @partition_guid: Indicates client partion id. This should be the
Alexander Curtin39b92802016-04-18 23:22:02 -0400226 * same across all visor_devices in the current
227 * guest. Private use by bus driver only.
228 */
Erik Arfvidson37039872015-05-05 18:36:00 -0400229struct visor_device {
Erik Arfvidson37039872015-05-05 18:36:00 -0400230 struct visorchannel *visorchannel;
Andy Shevchenkob32c5cb2017-08-22 13:26:54 -0400231 guid_t channel_type_guid;
Alexander Curtin39b92802016-04-18 23:22:02 -0400232 /* These fields are for private use by the bus driver only. */
Erik Arfvidson37039872015-05-05 18:36:00 -0400233 struct device device;
234 struct list_head list_all;
Tim Sell9ebab642016-06-10 21:48:08 -0400235 struct timer_list timer;
236 bool timer_active;
Erik Arfvidson37039872015-05-05 18:36:00 -0400237 bool being_removed;
David Kershnereaec40a2017-08-30 13:36:18 -0400238 struct mutex visordriver_callback_lock; /* synchronize probe/remove */
Erik Arfvidson37039872015-05-05 18:36:00 -0400239 bool pausing;
240 bool resuming;
Don Zickus65bd6e42015-06-04 09:22:40 -0400241 u32 chipset_bus_no;
242 u32 chipset_dev_no;
Don Zickus1fb30162015-05-13 13:22:18 -0400243 struct visorchipset_state state;
Andy Shevchenkob32c5cb2017-08-22 13:26:54 -0400244 guid_t inst;
Don Zickus1fb30162015-05-13 13:22:18 -0400245 u8 *name;
Don Zickus1fb30162015-05-13 13:22:18 -0400246 struct controlvm_message_header *pending_msg_hdr;
247 void *vbus_hdr_info;
Andy Shevchenkob32c5cb2017-08-22 13:26:54 -0400248 guid_t partition_guid;
Tim Sell8217bec2016-11-03 11:44:16 -0400249 struct dentry *debugfs_dir;
David Kershner1c218002017-09-27 13:14:21 -0400250 struct dentry *debugfs_bus_info;
Erik Arfvidson37039872015-05-05 18:36:00 -0400251};
252
253#define to_visor_device(x) container_of(x, struct visor_device, device)
254
David Kershner6db43252017-09-27 13:14:32 -0400255typedef void (*visorbus_state_complete_func) (struct visor_device *dev,
256 int status);
257
258/*
Sameer Wadgaonkarb2d06ca2017-09-27 13:14:46 -0400259 * This struct describes a specific visor channel, by providing its GUID, name,
260 * and sizes.
David Kershner6db43252017-09-27 13:14:32 -0400261 */
262struct visor_channeltype_descriptor {
263 const guid_t guid;
264 const char *name;
265 u64 min_bytes;
266 u32 version;
267};
268
269/**
270 * struct visor_driver - Information provided by each visor driver when it
Sameer Wadgaonkarb2d06ca2017-09-27 13:14:46 -0400271 * registers with the visorbus driver
David Kershner6db43252017-09-27 13:14:32 -0400272 * @name: Name of the visor driver.
273 * @owner: The module owner.
274 * @channel_types: Types of channels handled by this driver, ending with
275 * a zero GUID. Our specialized BUS.match() method knows
276 * about this list, and uses it to determine whether this
277 * driver will in fact handle a new device that it has
278 * detected.
279 * @probe: Called when a new device comes online, by our probe()
280 * function specified by driver.probe() (triggered
281 * ultimately by some call to driver_register(),
282 * bus_add_driver(), or driver_attach()).
283 * @remove: Called when a new device is removed, by our remove()
284 * function specified by driver.remove() (triggered
285 * ultimately by some call to device_release_driver()).
286 * @channel_interrupt: Called periodically, whenever there is a possiblity
287 * that "something interesting" may have happened to the
288 * channel.
289 * @pause: Called to initiate a change of the device's state. If
290 * the return valu`e is < 0, there was an error and the
291 * state transition will NOT occur. If the return value
292 * is >= 0, then the state transition was INITIATED
293 * successfully, and complete_func() will be called (or
294 * was just called) with the final status when either the
295 * state transition fails or completes successfully.
296 * @resume: Behaves similar to pause.
297 * @driver: Private reference to the device driver. For use by bus
298 * driver only.
299 */
300struct visor_driver {
301 const char *name;
302 struct module *owner;
303 struct visor_channeltype_descriptor *channel_types;
304 int (*probe)(struct visor_device *dev);
305 void (*remove)(struct visor_device *dev);
306 void (*channel_interrupt)(struct visor_device *dev);
307 int (*pause)(struct visor_device *dev,
308 visorbus_state_complete_func complete_func);
309 int (*resume)(struct visor_device *dev,
310 visorbus_state_complete_func complete_func);
311
312 /* These fields are for private use by the bus driver only. */
313 struct device_driver driver;
314};
315
316#define to_visor_driver(x) (container_of(x, struct visor_driver, driver))
317
Sameer Wadgaonkare25201d2017-08-30 13:36:35 -0400318int visor_check_channel(struct channel_header *ch, struct device *dev,
319 const guid_t *expected_uuid, char *chname,
320 u64 expected_min_bytes, u32 expected_version,
321 u64 expected_signature);
Sameer Wadgaonkar403043c2017-07-17 16:17:02 -0400322
David Binder3cda79c2017-03-17 11:27:09 -0400323int visorbus_register_visor_driver(struct visor_driver *drv);
324void visorbus_unregister_visor_driver(struct visor_driver *drv);
Erik Arfvidson37039872015-05-05 18:36:00 -0400325int visorbus_read_channel(struct visor_device *dev,
326 unsigned long offset, void *dest,
327 unsigned long nbytes);
328int visorbus_write_channel(struct visor_device *dev,
329 unsigned long offset, void *src,
330 unsigned long nbytes);
David Kershner5dca9b22017-03-28 09:34:44 -0400331int visorbus_enable_channel_interrupts(struct visor_device *dev);
Erik Arfvidson37039872015-05-05 18:36:00 -0400332void visorbus_disable_channel_interrupts(struct visor_device *dev);
Erik Arfvidson37039872015-05-05 18:36:00 -0400333
David Binderf621a962016-09-26 11:03:48 -0400334int visorchannel_signalremove(struct visorchannel *channel, u32 queue,
335 void *msg);
David Binder264f7b82016-09-26 11:03:49 -0400336int visorchannel_signalinsert(struct visorchannel *channel, u32 queue,
337 void *msg);
Neil Hormanfdc792c2015-07-31 18:56:32 -0400338bool visorchannel_signalempty(struct visorchannel *channel, u32 queue);
Andy Shevchenkob32c5cb2017-08-22 13:26:54 -0400339const guid_t *visorchannel_get_guid(struct visorchannel *channel);
Don Zickusf6439212015-05-05 18:36:02 -0400340
David Binder4830aec2017-03-17 11:27:26 -0400341#define BUS_ROOT_DEVICE UINT_MAX
Don Zickusd32517e2015-06-04 09:22:41 -0400342struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no,
343 struct visor_device *from);
Erik Arfvidson37039872015-05-05 18:36:00 -0400344#endif