1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
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.
13 * There should be nothing in this file that is private to the visorbus
14 * bus implementation itself.
17 #ifndef __VISORBUS_H__
18 #define __VISORBUS_H__
20 #include <linux/device.h>
22 #define VISOR_CHANNEL_SIGNATURE ('L' << 24 | 'N' << 16 | 'C' << 8 | 'E')
25 * enum channel_serverstate
26 * @CHANNELSRV_UNINITIALIZED: Channel is in an undefined state.
27 * @CHANNELSRV_READY: Channel has been initialized by server.
29 enum channel_serverstate {
30 CHANNELSRV_UNINITIALIZED = 0,
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
46 enum channel_clientstate {
47 CHANNELCLI_DETACHED = 0,
48 CHANNELCLI_DISABLED = 1,
49 CHANNELCLI_ATTACHING = 2,
50 CHANNELCLI_ATTACHED = 3,
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
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)
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
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.
100 struct channel_header {
103 /* SrvState, CliStateBoot, and CliStateOS below */
108 u64 partition_handle;
118 u32 ch_characteristic;
127 #define VISOR_CHANNEL_ENABLE_INTS (0x1ULL << 0)
130 * struct signal_queue_header - Subheader for the Signal Type variation of the
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.
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
154 * @filler: Pad out to 64 byte cacheline.
156 struct signal_queue_header {
175 u64 num_irq_received;
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"
188 struct visorchipset_state {
193 /* Remaining bits in this 32-bit word are reserved. */
197 * struct visor_device - A device type for things "plugged" into the visorbus
199 * @visorchannel: Points to the channel that the device is
201 * @channel_type_guid: Identifies the channel type to the bus driver.
202 * @device: Device struct meant for use by the bus driver
204 * @list_all: Used by the bus driver to enumerate devices.
205 * @timer: Timer fired periodically to do interrupt-type
207 * @being_removed: Indicates that the device is being removed from
208 * the bus. Private bus driver use only.
209 * @visordriver_callback_lock: Used by the bus driver to lock when adding and
211 * @pausing: Indicates that a change towards a paused state.
212 * is in progress. Only modified by the bus driver.
213 * @resuming: Indicates that a change towards a running state
214 * is in progress. Only modified by the bus driver.
215 * @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
219 * @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
222 * hypervisor requests.
223 * @vbus_hdr_info: A pointer to header info. Private use by bus
225 * @partition_guid: Indicates client partion id. This should be the
226 * same across all visor_devices in the current
227 * guest. Private use by bus driver only.
229 struct visor_device {
230 struct visorchannel *visorchannel;
231 guid_t channel_type_guid;
232 /* These fields are for private use by the bus driver only. */
233 struct device device;
234 struct list_head list_all;
235 struct timer_list timer;
238 struct mutex visordriver_callback_lock; /* synchronize probe/remove */
243 struct visorchipset_state state;
246 struct controlvm_message_header *pending_msg_hdr;
248 guid_t partition_guid;
249 struct dentry *debugfs_dir;
250 struct dentry *debugfs_bus_info;
253 #define to_visor_device(x) container_of(x, struct visor_device, device)
255 typedef void (*visorbus_state_complete_func) (struct visor_device *dev,
259 * This struct describes a specific visor channel, by providing its GUID, name,
262 struct visor_channeltype_descriptor {
270 * struct visor_driver - Information provided by each visor driver when it
271 * registers with the visorbus driver
272 * @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
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
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
300 struct visor_driver {
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);
312 /* These fields are for private use by the bus driver only. */
313 struct device_driver driver;
316 #define to_visor_driver(x) (container_of(x, struct visor_driver, driver))
318 int 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);
323 int visorbus_register_visor_driver(struct visor_driver *drv);
324 void visorbus_unregister_visor_driver(struct visor_driver *drv);
325 int visorbus_read_channel(struct visor_device *dev,
326 unsigned long offset, void *dest,
327 unsigned long nbytes);
328 int visorbus_write_channel(struct visor_device *dev,
329 unsigned long offset, void *src,
330 unsigned long nbytes);
331 int visorbus_enable_channel_interrupts(struct visor_device *dev);
332 void visorbus_disable_channel_interrupts(struct visor_device *dev);
334 int visorchannel_signalremove(struct visorchannel *channel, u32 queue,
336 int visorchannel_signalinsert(struct visorchannel *channel, u32 queue,
338 bool visorchannel_signalempty(struct visorchannel *channel, u32 queue);
339 const guid_t *visorchannel_get_guid(struct visorchannel *channel);
341 #define BUS_ROOT_DEVICE UINT_MAX
342 struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no,
343 struct visor_device *from);