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 | |
| 64 | /** Information provided by each visor driver when it registers with the |
| 65 | * visorbus driver. |
| 66 | */ |
| 67 | struct visor_driver { |
| 68 | const char *name; |
| 69 | const char *version; |
| 70 | const char *vertag; |
| 71 | const char *build_date; |
| 72 | const char *build_time; |
| 73 | struct module *owner; |
| 74 | |
| 75 | /** Types of channels handled by this driver, ending with 0 GUID. |
| 76 | * Our specialized BUS.match() method knows about this list, and |
| 77 | * uses it to determine whether this driver will in fact handle a |
| 78 | * new device that it has detected. |
| 79 | */ |
| 80 | struct visor_channeltype_descriptor *channel_types; |
| 81 | |
| 82 | /** Called when a new device comes online, by our probe() function |
| 83 | * specified by driver.probe() (triggered ultimately by some call |
| 84 | * to driver_register() / bus_add_driver() / driver_attach()). |
| 85 | */ |
| 86 | int (*probe)(struct visor_device *dev); |
| 87 | |
| 88 | /** Called when a new device is removed, by our remove() function |
| 89 | * specified by driver.remove() (triggered ultimately by some call |
| 90 | * to device_release_driver()). |
| 91 | */ |
| 92 | void (*remove)(struct visor_device *dev); |
| 93 | |
| 94 | /** Called periodically, whenever there is a possibility that |
| 95 | * "something interesting" may have happened to the channel state. |
| 96 | */ |
| 97 | void (*channel_interrupt)(struct visor_device *dev); |
| 98 | |
| 99 | /** Called to initiate a change of the device's state. If the return |
| 100 | * valu`e is < 0, there was an error and the state transition will NOT |
| 101 | * occur. If the return value is >= 0, then the state transition was |
| 102 | * INITIATED successfully, and complete_func() will be called (or was |
| 103 | * just called) with the final status when either the state transition |
| 104 | * fails or completes successfully. |
| 105 | */ |
| 106 | int (*pause)(struct visor_device *dev, |
Don Zickus | a298bc0 | 2015-06-04 09:22:42 -0400 | [diff] [blame] | 107 | visorbus_state_complete_func complete_func); |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 108 | int (*resume)(struct visor_device *dev, |
Don Zickus | a298bc0 | 2015-06-04 09:22:42 -0400 | [diff] [blame] | 109 | visorbus_state_complete_func complete_func); |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 110 | |
| 111 | /** These fields are for private use by the bus driver only. */ |
| 112 | struct device_driver driver; |
| 113 | struct driver_attribute version_attr; |
| 114 | }; |
| 115 | |
Tim Sell | d15a65b | 2015-07-09 13:27:42 -0400 | [diff] [blame] | 116 | #define to_visor_driver(x) ((x) ? \ |
| 117 | (container_of(x, struct visor_driver, driver)) : (NULL)) |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 118 | |
| 119 | /** A device type for things "plugged" into the visorbus bus */ |
| 120 | |
| 121 | struct visor_device { |
| 122 | /** visor driver can use the visorchannel member with the functions |
| 123 | * defined in visorchannel.h to access the channel |
| 124 | */ |
| 125 | struct visorchannel *visorchannel; |
| 126 | uuid_le channel_type_guid; |
| 127 | u64 channel_bytes; |
| 128 | |
| 129 | /** These fields are for private use by the bus driver only. |
| 130 | * A notable exception is that the visor driver can use |
| 131 | * visor_get_drvdata() and visor_set_drvdata() to retrieve or stash |
| 132 | * private visor driver specific data within the device member. |
| 133 | */ |
| 134 | struct device device; |
| 135 | struct list_head list_all; |
| 136 | struct periodic_work *periodic_work; |
| 137 | bool being_removed; |
| 138 | bool responded_to_device_create; |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 139 | struct kobject kobjdevmajorminor; /* visorbus<x>/dev<y>/devmajorminor/*/ |
| 140 | struct { |
| 141 | int major, minor; |
| 142 | void *attr; /* private use by devmajorminor_attr.c you can |
| 143 | * change this constant to whatever you |
| 144 | * want; */ |
| 145 | } devnodes[5]; |
| 146 | /* the code will detect and behave appropriately) */ |
| 147 | struct semaphore visordriver_callback_lock; |
| 148 | bool pausing; |
| 149 | bool resuming; |
Don Zickus | 65bd6e4 | 2015-06-04 09:22:40 -0400 | [diff] [blame] | 150 | u32 chipset_bus_no; |
| 151 | u32 chipset_dev_no; |
Don Zickus | 1fb3016 | 2015-05-13 13:22:18 -0400 | [diff] [blame] | 152 | struct visorchipset_state state; |
| 153 | uuid_le type; |
| 154 | uuid_le inst; |
| 155 | u8 *name; |
| 156 | u8 *description; |
| 157 | struct controlvm_message_header *pending_msg_hdr; |
| 158 | void *vbus_hdr_info; |
| 159 | u32 switch_no; |
| 160 | u32 internal_port_no; |
| 161 | uuid_le partition_uuid; |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | #define to_visor_device(x) container_of(x, struct visor_device, device) |
| 165 | |
| 166 | #ifndef STANDALONE_CLIENT |
| 167 | int visorbus_register_visor_driver(struct visor_driver *); |
| 168 | void visorbus_unregister_visor_driver(struct visor_driver *); |
| 169 | int visorbus_read_channel(struct visor_device *dev, |
| 170 | unsigned long offset, void *dest, |
| 171 | unsigned long nbytes); |
| 172 | int visorbus_write_channel(struct visor_device *dev, |
| 173 | unsigned long offset, void *src, |
| 174 | unsigned long nbytes); |
| 175 | int visorbus_clear_channel(struct visor_device *dev, |
| 176 | unsigned long offset, u8 ch, unsigned long nbytes); |
| 177 | int visorbus_registerdevnode(struct visor_device *dev, |
| 178 | const char *name, int major, int minor); |
| 179 | void visorbus_enable_channel_interrupts(struct visor_device *dev); |
| 180 | void visorbus_disable_channel_interrupts(struct visor_device *dev); |
| 181 | #endif |
| 182 | |
Jes Sorensen | dd5f938 | 2015-05-05 18:36:20 -0400 | [diff] [blame] | 183 | /* Note that for visorchannel_create() |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 184 | * <channel_bytes> and <guid> arguments may be 0 if we are a channel CLIENT. |
| 185 | * In this case, the values can simply be read from the channel header. |
| 186 | */ |
Erik Arfvidson | d5b3f1d | 2015-05-05 18:37:04 -0400 | [diff] [blame] | 187 | struct visorchannel *visorchannel_create(u64 physaddr, |
Jes Sorensen | df94247 | 2015-05-05 18:37:10 -0400 | [diff] [blame] | 188 | unsigned long channel_bytes, |
| 189 | gfp_t gfp, uuid_le guid); |
Erik Arfvidson | d5b3f1d | 2015-05-05 18:37:04 -0400 | [diff] [blame] | 190 | struct visorchannel *visorchannel_create_with_lock(u64 physaddr, |
Jes Sorensen | df94247 | 2015-05-05 18:37:10 -0400 | [diff] [blame] | 191 | unsigned long channel_bytes, |
| 192 | gfp_t gfp, uuid_le guid); |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 193 | void visorchannel_destroy(struct visorchannel *channel); |
| 194 | int visorchannel_read(struct visorchannel *channel, ulong offset, |
| 195 | void *local, ulong nbytes); |
| 196 | int visorchannel_write(struct visorchannel *channel, ulong offset, |
| 197 | void *local, ulong nbytes); |
| 198 | int visorchannel_clear(struct visorchannel *channel, ulong offset, |
| 199 | u8 ch, ulong nbytes); |
Prarit Bhargava | 779d075 | 2015-05-05 18:37:01 -0400 | [diff] [blame] | 200 | bool visorchannel_signalremove(struct visorchannel *channel, u32 queue, |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 201 | void *msg); |
Prarit Bhargava | 779d075 | 2015-05-05 18:37:01 -0400 | [diff] [blame] | 202 | bool visorchannel_signalinsert(struct visorchannel *channel, u32 queue, |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 203 | void *msg); |
| 204 | int visorchannel_signalqueue_slots_avail(struct visorchannel *channel, |
| 205 | u32 queue); |
| 206 | int visorchannel_signalqueue_max_slots(struct visorchannel *channel, u32 queue); |
Erik Arfvidson | d5b3f1d | 2015-05-05 18:37:04 -0400 | [diff] [blame] | 207 | u64 visorchannel_get_physaddr(struct visorchannel *channel); |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 208 | ulong visorchannel_get_nbytes(struct visorchannel *channel); |
| 209 | char *visorchannel_id(struct visorchannel *channel, char *s); |
| 210 | char *visorchannel_zoneid(struct visorchannel *channel, char *s); |
| 211 | u64 visorchannel_get_clientpartition(struct visorchannel *channel); |
Don Zickus | 4f6d8a9 | 2015-05-13 13:22:20 -0400 | [diff] [blame] | 212 | int visorchannel_set_clientpartition(struct visorchannel *channel, |
| 213 | u64 partition_handle); |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 214 | uuid_le visorchannel_get_uuid(struct visorchannel *channel); |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 215 | char *visorchannel_uuid_id(uuid_le *guid, char *s); |
| 216 | void visorchannel_debug(struct visorchannel *channel, int num_queues, |
| 217 | struct seq_file *seq, u32 off); |
Don Zickus | f643921 | 2015-05-05 18:36:02 -0400 | [diff] [blame] | 218 | void __iomem *visorchannel_get_header(struct visorchannel *channel); |
| 219 | |
Don Zickus | d32517e | 2015-06-04 09:22:41 -0400 | [diff] [blame] | 220 | #define BUS_ROOT_DEVICE UINT_MAX |
| 221 | struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no, |
| 222 | struct visor_device *from); |
Erik Arfvidson | 3703987 | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 223 | #endif |