Commit | Line | Data |
---|---|---|
3703987c EA |
1 | /* visorbus.h |
2 | * | |
3 | * Copyright (C) 2010 - 2013 UNISYS CORPORATION | |
4 | * All rights reserved. | |
5 | * | |
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. | |
10 | * | |
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 | |
15 | * details. | |
16 | */ | |
17 | ||
18 | /* | |
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. | |
23 | * | |
24 | * There should be nothing in this file that is private to the visorbus | |
25 | * bus implementation itself. | |
26 | * | |
27 | */ | |
28 | ||
29 | #ifndef __VISORBUS_H__ | |
30 | #define __VISORBUS_H__ | |
31 | ||
32 | #include <linux/device.h> | |
33 | #include <linux/module.h> | |
c0a14641 | 34 | #include <linux/poll.h> |
3703987c EA |
35 | #include <linux/kernel.h> |
36 | #include <linux/uuid.h> | |
37 | ||
38 | #include "periodic_work.h" | |
3703987c | 39 | #include "channel.h" |
f6439218 | 40 | |
3703987c EA |
41 | struct visor_driver; |
42 | struct visor_device; | |
1fb3016e | 43 | extern struct bus_type visorbus_type; |
3703987c EA |
44 | |
45 | typedef void (*visorbus_state_complete_func) (struct visor_device *dev, | |
a298bc0b | 46 | int status); |
1fb3016e DZ |
47 | struct visorchipset_state { |
48 | u32 created:1; | |
49 | u32 attached:1; | |
50 | u32 configured:1; | |
51 | u32 running:1; | |
52 | /* Add new fields above. */ | |
53 | /* Remaining bits in this 32-bit word are unused. */ | |
54 | }; | |
3703987c EA |
55 | |
56 | /** This struct describes a specific Supervisor channel, by providing its | |
57 | * GUID, name, and sizes. | |
58 | */ | |
59 | struct visor_channeltype_descriptor { | |
60 | const uuid_le guid; | |
61 | const char *name; | |
3703987c EA |
62 | }; |
63 | ||
b9edaf7c AC |
64 | /** |
65 | * struct visor_driver - Information provided by each visor driver when it | |
66 | * registers with the visorbus driver. | |
67 | * @name: Name of the visor driver. | |
68 | * @version: The numbered version of the driver (x.x.xxx). | |
69 | * @vertag: A human readable version string. | |
70 | * @owner: The module owner. | |
71 | * @channel_types: Types of channels handled by this driver, ending with | |
72 | * a zero GUID. Our specialized BUS.match() method knows | |
73 | * about this list, and uses it to determine whether this | |
74 | * driver will in fact handle a new device that it has | |
75 | * detected. | |
76 | * @probe: Called when a new device comes online, by our probe() | |
77 | * function specified by driver.probe() (triggered | |
78 | * ultimately by some call to driver_register(), | |
79 | * bus_add_driver(), or driver_attach()). | |
80 | * @remove: Called when a new device is removed, by our remove() | |
81 | * function specified by driver.remove() (triggered | |
82 | * ultimately by some call to device_release_driver()). | |
83 | * @channel_interrupt: Called periodically, whenever there is a possiblity | |
84 | * that "something interesting" may have happened to the | |
85 | * channel. | |
86 | * @pause: Called to initiate a change of the device's state. If | |
87 | * the return valu`e is < 0, there was an error and the | |
88 | * state transition will NOT occur. If the return value | |
89 | * is >= 0, then the state transition was INITIATED | |
90 | * successfully, and complete_func() will be called (or | |
91 | * was just called) with the final status when either the | |
92 | * state transition fails or completes successfully. | |
93 | * @resume: Behaves similar to pause. | |
94 | * @driver: Private reference to the device driver. For use by bus | |
95 | * driver only. | |
96 | * @version_attr: Private version field. For use by bus driver only. | |
3703987c EA |
97 | */ |
98 | struct visor_driver { | |
99 | const char *name; | |
100 | const char *version; | |
101 | const char *vertag; | |
3703987c | 102 | struct module *owner; |
3703987c | 103 | struct visor_channeltype_descriptor *channel_types; |
3703987c | 104 | int (*probe)(struct visor_device *dev); |
3703987c | 105 | void (*remove)(struct visor_device *dev); |
3703987c | 106 | void (*channel_interrupt)(struct visor_device *dev); |
3703987c | 107 | int (*pause)(struct visor_device *dev, |
a298bc0b | 108 | visorbus_state_complete_func complete_func); |
3703987c | 109 | int (*resume)(struct visor_device *dev, |
a298bc0b | 110 | visorbus_state_complete_func complete_func); |
3703987c | 111 | |
b9edaf7c | 112 | /* These fields are for private use by the bus driver only. */ |
3703987c EA |
113 | struct device_driver driver; |
114 | struct driver_attribute version_attr; | |
115 | }; | |
116 | ||
d15a65be TS |
117 | #define to_visor_driver(x) ((x) ? \ |
118 | (container_of(x, struct visor_driver, driver)) : (NULL)) | |
3703987c | 119 | |
39b92809 AC |
120 | /** |
121 | * struct visor_device - A device type for things "plugged" into the visorbus | |
122 | * bus | |
123 | * visorchannel: Points to the channel that the device is | |
124 | * associated with. | |
125 | * channel_type_guid: Identifies the channel type to the bus driver. | |
126 | * device: Device struct meant for use by the bus driver | |
127 | * only. | |
128 | * list_all: Used by the bus driver to enumerate devices. | |
129 | * periodic_work: Device work queue. Private use by bus driver | |
130 | * only. | |
131 | * being_removed: Indicates that the device is being removed from | |
132 | * the bus. Private bus driver use only. | |
133 | * visordriver_callback_lock: Used by the bus driver to lock when handling | |
134 | * channel events. | |
135 | * pausing: Indicates that a change towards a paused state. | |
136 | * is in progress. Only modified by the bus driver. | |
137 | * resuming: Indicates that a change towards a running state | |
138 | * is in progress. Only modified by the bus driver. | |
139 | * chipset_bus_no: Private field used by the bus driver. | |
140 | * chipset_dev_no: Private field used the bus driver. | |
141 | * state: Used to indicate the current state of the | |
142 | * device. | |
143 | * inst: Unique GUID for this instance of the device. | |
144 | * name: Name of the device. | |
145 | * pending_msg_hdr: For private use by bus driver to respond to | |
146 | * hypervisor requests. | |
147 | * vbus_hdr_info: A pointer to header info. Private use by bus | |
148 | * driver. | |
149 | * partition_uuid: Indicates client partion id. This should be the | |
150 | * same across all visor_devices in the current | |
151 | * guest. Private use by bus driver only. | |
152 | */ | |
3703987c EA |
153 | |
154 | struct visor_device { | |
3703987c EA |
155 | struct visorchannel *visorchannel; |
156 | uuid_le channel_type_guid; | |
39b92809 | 157 | /* These fields are for private use by the bus driver only. */ |
3703987c EA |
158 | struct device device; |
159 | struct list_head list_all; | |
160 | struct periodic_work *periodic_work; | |
161 | bool being_removed; | |
3703987c EA |
162 | struct semaphore visordriver_callback_lock; |
163 | bool pausing; | |
164 | bool resuming; | |
65bd6e46 DZ |
165 | u32 chipset_bus_no; |
166 | u32 chipset_dev_no; | |
1fb3016e | 167 | struct visorchipset_state state; |
1fb3016e DZ |
168 | uuid_le inst; |
169 | u8 *name; | |
1fb3016e DZ |
170 | struct controlvm_message_header *pending_msg_hdr; |
171 | void *vbus_hdr_info; | |
1fb3016e | 172 | uuid_le partition_uuid; |
3703987c EA |
173 | }; |
174 | ||
175 | #define to_visor_device(x) container_of(x, struct visor_device, device) | |
176 | ||
177 | #ifndef STANDALONE_CLIENT | |
178 | int visorbus_register_visor_driver(struct visor_driver *); | |
179 | void visorbus_unregister_visor_driver(struct visor_driver *); | |
180 | int visorbus_read_channel(struct visor_device *dev, | |
181 | unsigned long offset, void *dest, | |
182 | unsigned long nbytes); | |
183 | int visorbus_write_channel(struct visor_device *dev, | |
184 | unsigned long offset, void *src, | |
185 | unsigned long nbytes); | |
186 | int visorbus_clear_channel(struct visor_device *dev, | |
187 | unsigned long offset, u8 ch, unsigned long nbytes); | |
3703987c EA |
188 | void visorbus_enable_channel_interrupts(struct visor_device *dev); |
189 | void visorbus_disable_channel_interrupts(struct visor_device *dev); | |
190 | #endif | |
191 | ||
dd5f9385 | 192 | /* Note that for visorchannel_create() |
f6439218 DZ |
193 | * <channel_bytes> and <guid> arguments may be 0 if we are a channel CLIENT. |
194 | * In this case, the values can simply be read from the channel header. | |
195 | */ | |
d5b3f1dc | 196 | struct visorchannel *visorchannel_create(u64 physaddr, |
df94247a JS |
197 | unsigned long channel_bytes, |
198 | gfp_t gfp, uuid_le guid); | |
d5b3f1dc | 199 | struct visorchannel *visorchannel_create_with_lock(u64 physaddr, |
df94247a JS |
200 | unsigned long channel_bytes, |
201 | gfp_t gfp, uuid_le guid); | |
f6439218 DZ |
202 | void visorchannel_destroy(struct visorchannel *channel); |
203 | int visorchannel_read(struct visorchannel *channel, ulong offset, | |
204 | void *local, ulong nbytes); | |
205 | int visorchannel_write(struct visorchannel *channel, ulong offset, | |
206 | void *local, ulong nbytes); | |
207 | int visorchannel_clear(struct visorchannel *channel, ulong offset, | |
208 | u8 ch, ulong nbytes); | |
779d0752 | 209 | bool visorchannel_signalremove(struct visorchannel *channel, u32 queue, |
f6439218 | 210 | void *msg); |
779d0752 | 211 | bool visorchannel_signalinsert(struct visorchannel *channel, u32 queue, |
f6439218 | 212 | void *msg); |
fdc792cd NH |
213 | bool visorchannel_signalempty(struct visorchannel *channel, u32 queue); |
214 | ||
f6439218 DZ |
215 | int visorchannel_signalqueue_slots_avail(struct visorchannel *channel, |
216 | u32 queue); | |
217 | int visorchannel_signalqueue_max_slots(struct visorchannel *channel, u32 queue); | |
d5b3f1dc | 218 | u64 visorchannel_get_physaddr(struct visorchannel *channel); |
f6439218 DZ |
219 | ulong visorchannel_get_nbytes(struct visorchannel *channel); |
220 | char *visorchannel_id(struct visorchannel *channel, char *s); | |
221 | char *visorchannel_zoneid(struct visorchannel *channel, char *s); | |
222 | u64 visorchannel_get_clientpartition(struct visorchannel *channel); | |
4f6d8a97 DZ |
223 | int visorchannel_set_clientpartition(struct visorchannel *channel, |
224 | u64 partition_handle); | |
f6439218 | 225 | uuid_le visorchannel_get_uuid(struct visorchannel *channel); |
f6439218 DZ |
226 | char *visorchannel_uuid_id(uuid_le *guid, char *s); |
227 | void visorchannel_debug(struct visorchannel *channel, int num_queues, | |
228 | struct seq_file *seq, u32 off); | |
f6439218 DZ |
229 | void __iomem *visorchannel_get_header(struct visorchannel *channel); |
230 | ||
d32517e3 DZ |
231 | #define BUS_ROOT_DEVICE UINT_MAX |
232 | struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no, | |
233 | struct visor_device *from); | |
3703987c | 234 | #endif |