Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 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> |
Erik Arfvidson | c0a1464 | 2015-05-05 18:37:06 -0400 | [diff] [blame] | 34 | #include <linux/poll.h> |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 35 | #include <linux/kernel.h> |
| 36 | #include <linux/uuid.h> |
| 37 | |
| 38 | #include "periodic_work.h" |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 39 | #include "channel.h" |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 40 | |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 41 | struct visor_driver; |
| 42 | struct visor_device; |
Don Zickus | 1fb3016 | 2015-05-13 13:22:18 -0400 | [diff] [blame] | 43 | extern struct bus_type visorbus_type; |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 44 | |
| 45 | typedef void (*visorbus_state_complete_func) (struct visor_device *dev, |
Don Zickus | a298bc0 | 2015-06-04 09:22:42 -0400 | [diff] [blame] | 46 | int status); |
Don Zickus | 1fb3016 | 2015-05-13 13:22:18 -0400 | [diff] [blame] | 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 | }; |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 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; |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 62 | }; |
| 63 | |
Alexander Curtin | b9edaf7 | 2016-04-18 23:22:01 -0400 | [diff] [blame] | 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. |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 97 | */ |
| 98 | struct visor_driver { |
| 99 | const char *name; |
| 100 | const char *version; |
| 101 | const char *vertag; |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 102 | struct module *owner; |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 103 | struct visor_channeltype_descriptor *channel_types; |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 104 | int (*probe)(struct visor_device *dev); |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 105 | void (*remove)(struct visor_device *dev); |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 106 | void (*channel_interrupt)(struct visor_device *dev); |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 107 | int (*pause)(struct visor_device *dev, |
Don Zickus | a298bc0 | 2015-06-04 09:22:42 -0400 | [diff] [blame] | 108 | visorbus_state_complete_func complete_func); |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 109 | int (*resume)(struct visor_device *dev, |
Don Zickus | a298bc0 | 2015-06-04 09:22:42 -0400 | [diff] [blame] | 110 | visorbus_state_complete_func complete_func); |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 111 | |
Alexander Curtin | b9edaf7 | 2016-04-18 23:22:01 -0400 | [diff] [blame] | 112 | /* These fields are for private use by the bus driver only. */ |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 113 | struct device_driver driver; |
| 114 | struct driver_attribute version_attr; |
| 115 | }; |
| 116 | |
Tim Sell | d15a65b | 2015-07-09 13:27:42 -0400 | [diff] [blame] | 117 | #define to_visor_driver(x) ((x) ? \ |
| 118 | (container_of(x, struct visor_driver, driver)) : (NULL)) |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 119 | |
Alexander Curtin | 39b9280 | 2016-04-18 23:22:02 -0400 | [diff] [blame] | 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 | */ |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 153 | |
| 154 | struct visor_device { |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 155 | struct visorchannel *visorchannel; |
| 156 | uuid_le channel_type_guid; |
Alexander Curtin | 39b9280 | 2016-04-18 23:22:02 -0400 | [diff] [blame] | 157 | /* These fields are for private use by the bus driver only. */ |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 158 | struct device device; |
| 159 | struct list_head list_all; |
| 160 | struct periodic_work *periodic_work; |
| 161 | bool being_removed; |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 162 | struct semaphore visordriver_callback_lock; |
| 163 | bool pausing; |
| 164 | bool resuming; |
Don Zickus | 65bd6e4 | 2015-06-04 09:22:40 -0400 | [diff] [blame] | 165 | u32 chipset_bus_no; |
| 166 | u32 chipset_dev_no; |
Don Zickus | 1fb3016 | 2015-05-13 13:22:18 -0400 | [diff] [blame] | 167 | struct visorchipset_state state; |
Don Zickus | 1fb3016 | 2015-05-13 13:22:18 -0400 | [diff] [blame] | 168 | uuid_le inst; |
| 169 | u8 *name; |
Don Zickus | 1fb3016 | 2015-05-13 13:22:18 -0400 | [diff] [blame] | 170 | struct controlvm_message_header *pending_msg_hdr; |
| 171 | void *vbus_hdr_info; |
Don Zickus | 1fb3016 | 2015-05-13 13:22:18 -0400 | [diff] [blame] | 172 | uuid_le partition_uuid; |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 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); |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 188 | void visorbus_enable_channel_interrupts(struct visor_device *dev); |
| 189 | void visorbus_disable_channel_interrupts(struct visor_device *dev); |
| 190 | #endif |
| 191 | |
Jes Sorensen | dd5f938 | 2015-05-05 18:36:20 -0400 | [diff] [blame] | 192 | /* Note that for visorchannel_create() |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 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 | */ |
Erik Arfvidson | d5b3f1d | 2015-05-05 18:37:04 -0400 | [diff] [blame] | 196 | struct visorchannel *visorchannel_create(u64 physaddr, |
Jes Sorensen | df94247 | 2015-05-05 18:37:10 -0400 | [diff] [blame] | 197 | unsigned long channel_bytes, |
| 198 | gfp_t gfp, uuid_le guid); |
Erik Arfvidson | d5b3f1d | 2015-05-05 18:37:04 -0400 | [diff] [blame] | 199 | struct visorchannel *visorchannel_create_with_lock(u64 physaddr, |
Jes Sorensen | df94247 | 2015-05-05 18:37:10 -0400 | [diff] [blame] | 200 | unsigned long channel_bytes, |
| 201 | gfp_t gfp, uuid_le guid); |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 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); |
Prarit Bhargava | 779d075 | 2015-05-05 18:37:01 -0400 | [diff] [blame] | 209 | bool visorchannel_signalremove(struct visorchannel *channel, u32 queue, |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 210 | void *msg); |
Prarit Bhargava | 779d075 | 2015-05-05 18:37:01 -0400 | [diff] [blame] | 211 | bool visorchannel_signalinsert(struct visorchannel *channel, u32 queue, |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 212 | void *msg); |
Neil Horman | fdc792c | 2015-07-31 18:56:32 -0400 | [diff] [blame] | 213 | bool visorchannel_signalempty(struct visorchannel *channel, u32 queue); |
| 214 | |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 215 | int visorchannel_signalqueue_slots_avail(struct visorchannel *channel, |
| 216 | u32 queue); |
| 217 | int visorchannel_signalqueue_max_slots(struct visorchannel *channel, u32 queue); |
Erik Arfvidson | d5b3f1d | 2015-05-05 18:37:04 -0400 | [diff] [blame] | 218 | u64 visorchannel_get_physaddr(struct visorchannel *channel); |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 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); |
Don Zickus | 4f6d8a9 | 2015-05-13 13:22:20 -0400 | [diff] [blame] | 223 | int visorchannel_set_clientpartition(struct visorchannel *channel, |
| 224 | u64 partition_handle); |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 225 | uuid_le visorchannel_get_uuid(struct visorchannel *channel); |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 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); |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 229 | void __iomem *visorchannel_get_header(struct visorchannel *channel); |
| 230 | |
Don Zickus | d32517e | 2015-06-04 09:22:41 -0400 | [diff] [blame] | 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); |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 234 | #endif |