3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14 * NON INFRINGEMENT. See the GNU General Public License for more
19 * This header file is to be included by other kernel mode components that
20 * implement a particular kind of visor_device. Each of these other kernel
21 * mode components is called a visor device driver. Refer to visortemplate
22 * for a minimal sample visor device driver.
24 * There should be nothing in this file that is private to the visorbus
25 * bus implementation itself.
29 #ifndef __VISORBUS_H__
30 #define __VISORBUS_H__
32 #include <linux/device.h>
33 #include <linux/module.h>
34 #include <linux/poll.h>
35 #include <linux/kernel.h>
36 #include <linux/uuid.h>
37 #include <linux/seq_file.h>
38 #include <linux/slab.h>
44 extern struct bus_type visorbus_type;
46 typedef void (*visorbus_state_complete_func) (struct visor_device *dev,
48 struct visorchipset_state {
53 /* Add new fields above. */
54 /* Remaining bits in this 32-bit word are unused. */
57 /** This struct describes a specific Supervisor channel, by providing its
58 * GUID, name, and sizes.
60 struct visor_channeltype_descriptor {
66 * struct visor_driver - Information provided by each visor driver when it
67 * registers with the visorbus driver.
68 * @name: Name of the visor driver.
69 * @owner: The module owner.
70 * @channel_types: Types of channels handled by this driver, ending with
71 * a zero GUID. Our specialized BUS.match() method knows
72 * about this list, and uses it to determine whether this
73 * driver will in fact handle a new device that it has
75 * @probe: Called when a new device comes online, by our probe()
76 * function specified by driver.probe() (triggered
77 * ultimately by some call to driver_register(),
78 * bus_add_driver(), or driver_attach()).
79 * @remove: Called when a new device is removed, by our remove()
80 * function specified by driver.remove() (triggered
81 * ultimately by some call to device_release_driver()).
82 * @channel_interrupt: Called periodically, whenever there is a possiblity
83 * that "something interesting" may have happened to the
85 * @pause: Called to initiate a change of the device's state. If
86 * the return valu`e is < 0, there was an error and the
87 * state transition will NOT occur. If the return value
88 * is >= 0, then the state transition was INITIATED
89 * successfully, and complete_func() will be called (or
90 * was just called) with the final status when either the
91 * state transition fails or completes successfully.
92 * @resume: Behaves similar to pause.
93 * @driver: Private reference to the device driver. For use by bus
99 struct visor_channeltype_descriptor *channel_types;
100 int (*probe)(struct visor_device *dev);
101 void (*remove)(struct visor_device *dev);
102 void (*channel_interrupt)(struct visor_device *dev);
103 int (*pause)(struct visor_device *dev,
104 visorbus_state_complete_func complete_func);
105 int (*resume)(struct visor_device *dev,
106 visorbus_state_complete_func complete_func);
108 /* These fields are for private use by the bus driver only. */
109 struct device_driver driver;
112 #define to_visor_driver(x) ((x) ? \
113 (container_of(x, struct visor_driver, driver)) : (NULL))
116 * struct visor_device - A device type for things "plugged" into the visorbus
118 * @visorchannel: Points to the channel that the device is
120 * @channel_type_guid: Identifies the channel type to the bus driver.
121 * @device: Device struct meant for use by the bus driver
123 * @list_all: Used by the bus driver to enumerate devices.
124 * @timer: Timer fired periodically to do interrupt-type
126 * @being_removed: Indicates that the device is being removed from
127 * the bus. Private bus driver use only.
128 * @visordriver_callback_lock: Used by the bus driver to lock when handling
130 * @pausing: Indicates that a change towards a paused state.
131 * is in progress. Only modified by the bus driver.
132 * @resuming: Indicates that a change towards a running state
133 * is in progress. Only modified by the bus driver.
134 * @chipset_bus_no: Private field used by the bus driver.
135 * @chipset_dev_no: Private field used the bus driver.
136 * @state: Used to indicate the current state of the
138 * @inst: Unique GUID for this instance of the device.
139 * @name: Name of the device.
140 * @pending_msg_hdr: For private use by bus driver to respond to
141 * hypervisor requests.
142 * @vbus_hdr_info: A pointer to header info. Private use by bus
144 * @partition_uuid: Indicates client partion id. This should be the
145 * same across all visor_devices in the current
146 * guest. Private use by bus driver only.
149 struct visor_device {
150 struct visorchannel *visorchannel;
151 uuid_le channel_type_guid;
152 /* These fields are for private use by the bus driver only. */
153 struct device device;
154 struct list_head list_all;
155 struct timer_list timer;
158 struct mutex visordriver_callback_lock;
163 struct visorchipset_state state;
166 struct controlvm_message_header *pending_msg_hdr;
168 uuid_le partition_uuid;
171 #define to_visor_device(x) container_of(x, struct visor_device, device)
173 int visorbus_register_visor_driver(struct visor_driver *);
174 void visorbus_unregister_visor_driver(struct visor_driver *);
175 int visorbus_read_channel(struct visor_device *dev,
176 unsigned long offset, void *dest,
177 unsigned long nbytes);
178 int visorbus_write_channel(struct visor_device *dev,
179 unsigned long offset, void *src,
180 unsigned long nbytes);
181 void visorbus_enable_channel_interrupts(struct visor_device *dev);
182 void visorbus_disable_channel_interrupts(struct visor_device *dev);
184 /* Levels of severity for diagnostic events, in order from lowest severity to
185 * highest (i.e. fatal errors are the most severe, and should always be logged,
186 * but info events rarely need to be logged except during debugging). The
187 * values DIAG_SEVERITY_ENUM_BEGIN and DIAG_SEVERITY_ENUM_END are not valid
188 * severity values. They exist merely to dilineate the list, so that future
189 * additions won't require changes to the driver (i.e. when checking for
190 * out-of-range severities in SetSeverity). The values DIAG_SEVERITY_OVERRIDE
191 * and DIAG_SEVERITY_SHUTOFF are not valid severity values for logging events
192 * but they are valid for controlling the amount of event data. Changes made
193 * to the enum, need to be reflected in s-Par.
196 DIAG_SEVERITY_VERBOSE = 0,
197 DIAG_SEVERITY_INFO = 1,
198 DIAG_SEVERITY_WARNING = 2,
199 DIAG_SEVERITY_ERR = 3,
200 DIAG_SEVERITY_PRINT = 4,
203 int visorchannel_signalremove(struct visorchannel *channel, u32 queue,
205 int visorchannel_signalinsert(struct visorchannel *channel, u32 queue,
207 bool visorchannel_signalempty(struct visorchannel *channel, u32 queue);
208 uuid_le visorchannel_get_uuid(struct visorchannel *channel);
210 #define BUS_ROOT_DEVICE UINT_MAX
211 struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no,
212 struct visor_device *from);