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 * @version: The numbered version of the driver (x.x.xxx).
70 * @vertag: A human readable version string.
71 * @owner: The module owner.
72 * @channel_types: Types of channels handled by this driver, ending with
73 * a zero GUID. Our specialized BUS.match() method knows
74 * about this list, and uses it to determine whether this
75 * driver will in fact handle a new device that it has
77 * @probe: Called when a new device comes online, by our probe()
78 * function specified by driver.probe() (triggered
79 * ultimately by some call to driver_register(),
80 * bus_add_driver(), or driver_attach()).
81 * @remove: Called when a new device is removed, by our remove()
82 * function specified by driver.remove() (triggered
83 * ultimately by some call to device_release_driver()).
84 * @channel_interrupt: Called periodically, whenever there is a possiblity
85 * that "something interesting" may have happened to the
87 * @pause: Called to initiate a change of the device's state. If
88 * the return valu`e is < 0, there was an error and the
89 * state transition will NOT occur. If the return value
90 * is >= 0, then the state transition was INITIATED
91 * successfully, and complete_func() will be called (or
92 * was just called) with the final status when either the
93 * state transition fails or completes successfully.
94 * @resume: Behaves similar to pause.
95 * @driver: Private reference to the device driver. For use by bus
97 * @version_attr: Private version field. For use by bus driver only.
103 struct module *owner;
104 struct visor_channeltype_descriptor *channel_types;
105 int (*probe)(struct visor_device *dev);
106 void (*remove)(struct visor_device *dev);
107 void (*channel_interrupt)(struct visor_device *dev);
108 int (*pause)(struct visor_device *dev,
109 visorbus_state_complete_func complete_func);
110 int (*resume)(struct visor_device *dev,
111 visorbus_state_complete_func complete_func);
113 /* These fields are for private use by the bus driver only. */
114 struct device_driver driver;
115 struct driver_attribute version_attr;
118 #define to_visor_driver(x) ((x) ? \
119 (container_of(x, struct visor_driver, driver)) : (NULL))
122 * struct visor_device - A device type for things "plugged" into the visorbus
124 * visorchannel: Points to the channel that the device is
126 * channel_type_guid: Identifies the channel type to the bus driver.
127 * device: Device struct meant for use by the bus driver
129 * list_all: Used by the bus driver to enumerate devices.
130 * timer: Timer fired periodically to do interrupt-type
132 * being_removed: Indicates that the device is being removed from
133 * the bus. Private bus driver use only.
134 * visordriver_callback_lock: Used by the bus driver to lock when handling
136 * pausing: Indicates that a change towards a paused state.
137 * is in progress. Only modified by the bus driver.
138 * resuming: Indicates that a change towards a running state
139 * is in progress. Only modified by the bus driver.
140 * chipset_bus_no: Private field used by the bus driver.
141 * chipset_dev_no: Private field used the bus driver.
142 * state: Used to indicate the current state of the
144 * inst: Unique GUID for this instance of the device.
145 * name: Name of the device.
146 * pending_msg_hdr: For private use by bus driver to respond to
147 * hypervisor requests.
148 * vbus_hdr_info: A pointer to header info. Private use by bus
150 * partition_uuid: Indicates client partion id. This should be the
151 * same across all visor_devices in the current
152 * guest. Private use by bus driver only.
155 struct visor_device {
156 struct visorchannel *visorchannel;
157 uuid_le channel_type_guid;
158 /* These fields are for private use by the bus driver only. */
159 struct device device;
160 struct list_head list_all;
161 struct timer_list timer;
164 struct mutex visordriver_callback_lock;
169 struct visorchipset_state state;
172 struct controlvm_message_header *pending_msg_hdr;
174 uuid_le partition_uuid;
177 #define to_visor_device(x) container_of(x, struct visor_device, device)
179 int visorbus_register_visor_driver(struct visor_driver *);
180 void visorbus_unregister_visor_driver(struct visor_driver *);
181 int visorbus_read_channel(struct visor_device *dev,
182 unsigned long offset, void *dest,
183 unsigned long nbytes);
184 int visorbus_write_channel(struct visor_device *dev,
185 unsigned long offset, void *src,
186 unsigned long nbytes);
187 void visorbus_enable_channel_interrupts(struct visor_device *dev);
188 void visorbus_disable_channel_interrupts(struct visor_device *dev);
190 /* Note that for visorchannel_create()
191 * <channel_bytes> and <guid> arguments may be 0 if we are a channel CLIENT.
192 * In this case, the values can simply be read from the channel header.
194 struct visorchannel *visorchannel_create(u64 physaddr,
195 unsigned long channel_bytes,
196 gfp_t gfp, uuid_le guid);
197 struct visorchannel *visorchannel_create_with_lock(u64 physaddr,
198 unsigned long channel_bytes,
199 gfp_t gfp, uuid_le guid);
200 void visorchannel_destroy(struct visorchannel *channel);
201 int visorchannel_read(struct visorchannel *channel, ulong offset,
202 void *local, ulong nbytes);
203 int visorchannel_write(struct visorchannel *channel, ulong offset,
204 void *local, ulong nbytes);
205 bool visorchannel_signalremove(struct visorchannel *channel, u32 queue,
207 bool visorchannel_signalinsert(struct visorchannel *channel, u32 queue,
209 bool visorchannel_signalempty(struct visorchannel *channel, u32 queue);
211 u64 visorchannel_get_physaddr(struct visorchannel *channel);
212 ulong visorchannel_get_nbytes(struct visorchannel *channel);
213 char *visorchannel_id(struct visorchannel *channel, char *s);
214 char *visorchannel_zoneid(struct visorchannel *channel, char *s);
215 u64 visorchannel_get_clientpartition(struct visorchannel *channel);
216 int visorchannel_set_clientpartition(struct visorchannel *channel,
217 u64 partition_handle);
218 uuid_le visorchannel_get_uuid(struct visorchannel *channel);
219 char *visorchannel_uuid_id(uuid_le *guid, char *s);
220 void __iomem *visorchannel_get_header(struct visorchannel *channel);
222 #define BUS_ROOT_DEVICE UINT_MAX
223 struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no,
224 struct visor_device *from);