Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1 | /* visorchipset_main.c |
| 2 | * |
Benjamin Romer | f6d0c1e | 2014-04-23 14:58:34 -0400 | [diff] [blame] | 3 | * Copyright (C) 2010 - 2013 UNISYS CORPORATION |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 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 | #include "globals.h" |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 19 | #include "visorchipset.h" |
| 20 | #include "procobjecttree.h" |
| 21 | #include "visorchannel.h" |
| 22 | #include "periodic_work.h" |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 23 | #include "file.h" |
| 24 | #include "parser.h" |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 25 | #include "uisutils.h" |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 26 | #include "controlvmcompletionstatus.h" |
| 27 | #include "guestlinuxdebug.h" |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 28 | |
| 29 | #include <linux/nls.h> |
| 30 | #include <linux/netdevice.h> |
| 31 | #include <linux/platform_device.h> |
Benjamin Romer | 90addb0 | 2014-05-06 09:58:23 -0400 | [diff] [blame] | 32 | #include <linux/uuid.h> |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 33 | |
| 34 | #define CURRENT_FILE_PC VISOR_CHIPSET_PC_visorchipset_main_c |
| 35 | #define TEST_VNIC_PHYSITF "eth0" /* physical network itf for |
| 36 | * vnic loopback test */ |
| 37 | #define TEST_VNIC_SWITCHNO 1 |
| 38 | #define TEST_VNIC_BUSNO 9 |
| 39 | |
| 40 | #define MAX_NAME_SIZE 128 |
| 41 | #define MAX_IP_SIZE 50 |
| 42 | #define MAXOUTSTANDINGCHANNELCOMMAND 256 |
| 43 | #define POLLJIFFIES_CONTROLVMCHANNEL_FAST 1 |
| 44 | #define POLLJIFFIES_CONTROLVMCHANNEL_SLOW 100 |
| 45 | |
| 46 | /* When the controlvm channel is idle for at least MIN_IDLE_SECONDS, |
| 47 | * we switch to slow polling mode. As soon as we get a controlvm |
| 48 | * message, we switch back to fast polling mode. |
| 49 | */ |
| 50 | #define MIN_IDLE_SECONDS 10 |
Benjamin Romer | 911e213 | 2015-03-16 13:57:47 -0400 | [diff] [blame] | 51 | static ulong poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST; |
Benjamin Romer | b53e0e9 | 2015-03-16 13:57:56 -0400 | [diff] [blame] | 52 | static ulong most_recent_message_jiffies; /* when we got our last |
Ken Cox | bd5b9b3 | 2014-03-13 15:39:22 -0500 | [diff] [blame] | 53 | * controlvm message */ |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 54 | static inline char * |
| 55 | NONULLSTR(char *s) |
| 56 | { |
| 57 | if (s) |
| 58 | return s; |
Benjamin Romer | e22a4a0 | 2014-08-18 09:34:54 -0400 | [diff] [blame] | 59 | return ""; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static int serverregistered; |
| 63 | static int clientregistered; |
| 64 | |
| 65 | #define MAX_CHIPSET_EVENTS 2 |
Benjamin Romer | c242233 | 2014-07-29 15:09:40 -0400 | [diff] [blame] | 66 | static u8 chipset_events[MAX_CHIPSET_EVENTS] = { 0, 0 }; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 67 | |
Benjamin Romer | 9232d2d | 2015-03-16 13:57:57 -0400 | [diff] [blame] | 68 | static struct delayed_work periodic_controlvm_work; |
| 69 | static struct workqueue_struct *periodic_controlvm_workqueue; |
Benjamin Romer | 8f1947a | 2015-03-16 13:57:59 -0400 | [diff] [blame] | 70 | static DEFINE_SEMAPHORE(notifier_lock); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 71 | |
Benjamin Romer | da021f0 | 2015-03-16 13:57:58 -0400 | [diff] [blame] | 72 | static struct controlvm_message_header g_diag_msg_hdr; |
| 73 | static struct controlvm_message_header g_chipset_msg_hdr; |
| 74 | static struct controlvm_message_header g_del_dump_msg_hdr; |
Benjamin Romer | 59827f0 | 2015-03-16 13:58:00 -0400 | [diff] [blame] | 75 | static const uuid_le spar_diag_pool_channel_protocol_uuid = |
Benjamin Romer | 9eee5d1 | 2014-10-23 14:29:47 -0400 | [diff] [blame] | 76 | SPAR_DIAG_POOL_CHANNEL_PROTOCOL_UUID; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 77 | /* 0xffffff is an invalid Bus/Device number */ |
Benjamin Romer | 83d4890 | 2015-03-16 13:58:01 -0400 | [diff] [blame] | 78 | static ulong g_diagpool_bus_no = 0xffffff; |
| 79 | static ulong g_diagpool_dev_no = 0xffffff; |
Benjamin Romer | 4f44b72 | 2015-03-16 13:58:02 -0400 | [diff] [blame] | 80 | static struct controlvm_message_packet g_devicechangestate_packet; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 81 | |
| 82 | /* Only VNIC and VHBA channels are sent to visorclientbus (aka |
| 83 | * "visorhackbus") |
| 84 | */ |
| 85 | #define FOR_VISORHACKBUS(channel_type_guid) \ |
Benjamin Romer | 9eee5d1 | 2014-10-23 14:29:47 -0400 | [diff] [blame] | 86 | (((uuid_le_cmp(channel_type_guid,\ |
Benjamin Romer | 0639ba6 | 2015-03-16 13:58:04 -0400 | [diff] [blame] | 87 | spar_vnic_channel_protocol_uuid) == 0) ||\ |
| 88 | (uuid_le_cmp(channel_type_guid,\ |
Benjamin Romer | 9eee5d1 | 2014-10-23 14:29:47 -0400 | [diff] [blame] | 89 | spar_vhba_channel_protocol_uuid) == 0))) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 90 | #define FOR_VISORBUS(channel_type_guid) (!(FOR_VISORHACKBUS(channel_type_guid))) |
| 91 | |
| 92 | #define is_diagpool_channel(channel_type_guid) \ |
Benjamin Romer | 59827f0 | 2015-03-16 13:58:00 -0400 | [diff] [blame] | 93 | (uuid_le_cmp(channel_type_guid,\ |
| 94 | spar_diag_pool_channel_protocol_uuid) == 0) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 95 | |
Benjamin Romer | 1390b88 | 2015-03-16 13:58:03 -0400 | [diff] [blame] | 96 | static LIST_HEAD(bus_info_list); |
| 97 | static LIST_HEAD(dev_info_list); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 98 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 99 | static struct visorchannel *controlvm_channel; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 100 | |
Benjamin Romer | 84982fb | 2015-03-16 13:58:07 -0400 | [diff] [blame] | 101 | /* Manages the request payload in the controlvm channel */ |
| 102 | static struct controlvm_payload_info { |
Benjamin Romer | c242233 | 2014-07-29 15:09:40 -0400 | [diff] [blame] | 103 | u8 __iomem *ptr; /* pointer to base address of payload pool */ |
Benjamin Romer | 5fc0229 | 2014-07-31 12:00:51 -0400 | [diff] [blame] | 104 | u64 offset; /* offset from beginning of controlvm |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 105 | * channel to beginning of payload * pool */ |
Benjamin Romer | b3c55b1 | 2014-07-31 12:00:50 -0400 | [diff] [blame] | 106 | u32 bytes; /* number of bytes in payload pool */ |
Benjamin Romer | 84982fb | 2015-03-16 13:58:07 -0400 | [diff] [blame] | 107 | } controlvm_payload_info; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 108 | |
Benjamin Romer | ea33b4ee5 | 2015-03-16 13:58:08 -0400 | [diff] [blame] | 109 | /* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE / |
| 110 | * CONTROLVM_DUMP_GETTEXTDUMP / CONTROLVM_DUMP_COMPLETE conversation. |
| 111 | */ |
| 112 | static struct livedump_info { |
| 113 | struct controlvm_message_header dumpcapture_header; |
| 114 | struct controlvm_message_header gettextdump_header; |
| 115 | struct controlvm_message_header dumpcomplete_header; |
| 116 | BOOL gettextdump_outstanding; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 117 | u32 crc32; |
| 118 | ulong length; |
| 119 | atomic_t buffers_in_use; |
| 120 | ulong destination; |
Benjamin Romer | ea33b4ee5 | 2015-03-16 13:58:08 -0400 | [diff] [blame] | 121 | } livedump_info; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 122 | |
| 123 | /* The following globals are used to handle the scenario where we are unable to |
| 124 | * offload the payload from a controlvm message due to memory requirements. In |
| 125 | * this scenario, we simply stash the controlvm message, then attempt to |
| 126 | * process it again the next time controlvm_periodic_work() runs. |
| 127 | */ |
Benjamin Romer | 7166ed1 | 2015-03-16 13:58:38 -0400 | [diff] [blame] | 128 | static struct controlvm_message controlvm_pending_msg; |
| 129 | static BOOL controlvm_pending_msg_valid = FALSE; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 130 | |
| 131 | /* Pool of struct putfile_buffer_entry, for keeping track of pending (incoming) |
| 132 | * TRANSMIT_FILE PutFile payloads. |
| 133 | */ |
Benjamin Romer | 1eee001 | 2015-03-16 13:58:39 -0400 | [diff] [blame] | 134 | static struct kmem_cache *putfile_buffer_list_pool; |
| 135 | static const char putfile_buffer_list_pool_name[] = |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 136 | "controlvm_putfile_buffer_list_pool"; |
| 137 | |
| 138 | /* This identifies a data buffer that has been received via a controlvm messages |
| 139 | * in a remote --> local CONTROLVM_TRANSMIT_FILE conversation. |
| 140 | */ |
| 141 | struct putfile_buffer_entry { |
| 142 | struct list_head next; /* putfile_buffer_entry list */ |
Benjamin Romer | 317d961 | 2015-03-16 13:57:51 -0400 | [diff] [blame] | 143 | struct parser_context *parser_ctx; /* points to input data buffer */ |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | /* List of struct putfile_request *, via next_putfile_request member. |
| 147 | * Each entry in this list identifies an outstanding TRANSMIT_FILE |
| 148 | * conversation. |
| 149 | */ |
Benjamin Romer | 1eee001 | 2015-03-16 13:58:39 -0400 | [diff] [blame] | 150 | static LIST_HEAD(putfile_request_list); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 151 | |
| 152 | /* This describes a buffer and its current state of transfer (e.g., how many |
| 153 | * bytes have already been supplied as putfile data, and how many bytes are |
| 154 | * remaining) for a putfile_request. |
| 155 | */ |
| 156 | struct putfile_active_buffer { |
| 157 | /* a payload from a controlvm message, containing a file data buffer */ |
Benjamin Romer | 317d961 | 2015-03-16 13:57:51 -0400 | [diff] [blame] | 158 | struct parser_context *parser_ctx; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 159 | /* points within data area of parser_ctx to next byte of data */ |
| 160 | u8 *pnext; |
| 161 | /* # bytes left from <pnext> to the end of this data buffer */ |
| 162 | size_t bytes_remaining; |
| 163 | }; |
| 164 | |
| 165 | #define PUTFILE_REQUEST_SIG 0x0906101302281211 |
| 166 | /* This identifies a single remote --> local CONTROLVM_TRANSMIT_FILE |
| 167 | * conversation. Structs of this type are dynamically linked into |
| 168 | * <Putfile_request_list>. |
| 169 | */ |
| 170 | struct putfile_request { |
| 171 | u64 sig; /* PUTFILE_REQUEST_SIG */ |
| 172 | |
| 173 | /* header from original TransmitFile request */ |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 174 | struct controlvm_message_header controlvm_header; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 175 | u64 file_request_number; /* from original TransmitFile request */ |
| 176 | |
| 177 | /* link to next struct putfile_request */ |
| 178 | struct list_head next_putfile_request; |
| 179 | |
| 180 | /* most-recent sequence number supplied via a controlvm message */ |
| 181 | u64 data_sequence_number; |
| 182 | |
| 183 | /* head of putfile_buffer_entry list, which describes the data to be |
| 184 | * supplied as putfile data; |
| 185 | * - this list is added to when controlvm messages come in that supply |
| 186 | * file data |
| 187 | * - this list is removed from via the hotplug program that is actually |
| 188 | * consuming these buffers to write as file data */ |
| 189 | struct list_head input_buffer_list; |
| 190 | spinlock_t req_list_lock; /* lock for input_buffer_list */ |
| 191 | |
| 192 | /* waiters for input_buffer_list to go non-empty */ |
| 193 | wait_queue_head_t input_buffer_wq; |
| 194 | |
| 195 | /* data not yet read within current putfile_buffer_entry */ |
| 196 | struct putfile_active_buffer active_buf; |
| 197 | |
| 198 | /* <0 = failed, 0 = in-progress, >0 = successful; */ |
| 199 | /* note that this must be set with req_list_lock, and if you set <0, */ |
| 200 | /* it is your responsibility to also free up all of the other objects */ |
| 201 | /* in this struct (like input_buffer_list, active_buf.parser_ctx) */ |
| 202 | /* before releasing the lock */ |
| 203 | int completion_status; |
| 204 | }; |
| 205 | |
Benjamin Romer | 712f42c | 2015-03-16 13:58:40 -0400 | [diff] [blame] | 206 | static atomic_t visorchipset_cache_buffers_in_use = ATOMIC_INIT(0); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 207 | |
| 208 | struct parahotplug_request { |
| 209 | struct list_head list; |
| 210 | int id; |
| 211 | unsigned long expiration; |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 212 | struct controlvm_message msg; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 213 | }; |
| 214 | |
Benjamin Romer | ddf5de5 | 2015-03-16 13:58:41 -0400 | [diff] [blame] | 215 | static LIST_HEAD(parahotplug_request_list); |
| 216 | static DEFINE_SPINLOCK(parahotplug_request_list_lock); /* lock for above */ |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 217 | static void parahotplug_process_list(void); |
| 218 | |
| 219 | /* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE / |
| 220 | * CONTROLVM_REPORTEVENT. |
| 221 | */ |
Benjamin Romer | 6fe345a | 2015-03-16 13:58:42 -0400 | [diff] [blame] | 222 | static struct visorchipset_busdev_notifiers busdev_server_notifiers; |
| 223 | static struct visorchipset_busdev_notifiers busdev_client_notifiers; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 224 | |
Benjamin Romer | 8e3fedd | 2015-03-16 13:58:43 -0400 | [diff] [blame] | 225 | static void bus_create_response(ulong bus_no, int response); |
| 226 | static void bus_destroy_response(ulong bus_no, int response); |
| 227 | static void device_create_response(ulong bus_no, ulong dev_no, int response); |
| 228 | static void device_destroy_response(ulong bus_no, ulong dev_no, int response); |
| 229 | static void device_resume_response(ulong bus_no, ulong dev_no, int response); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 230 | |
Benjamin Romer | 8e3fedd | 2015-03-16 13:58:43 -0400 | [diff] [blame] | 231 | static struct visorchipset_busdev_responders busdev_responders = { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 232 | .bus_create = bus_create_response, |
| 233 | .bus_destroy = bus_destroy_response, |
| 234 | .device_create = device_create_response, |
| 235 | .device_destroy = device_destroy_response, |
Ken Cox | 927c792 | 2014-03-05 14:52:25 -0600 | [diff] [blame] | 236 | .device_pause = visorchipset_device_pause_response, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 237 | .device_resume = device_resume_response, |
| 238 | }; |
| 239 | |
| 240 | /* info for /dev/visorchipset */ |
Benjamin Romer | 5aa8ae5 | 2015-03-16 13:58:44 -0400 | [diff] [blame] | 241 | static dev_t major_dev = -1; /**< indicates major num for device */ |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 242 | |
Benjamin Romer | 19f6634 | 2014-07-22 09:56:25 -0400 | [diff] [blame] | 243 | /* prototypes for attributes */ |
| 244 | static ssize_t toolaction_show(struct device *dev, |
| 245 | struct device_attribute *attr, char *buf); |
| 246 | static ssize_t toolaction_store(struct device *dev, |
| 247 | struct device_attribute *attr, const char *buf, size_t count); |
| 248 | static DEVICE_ATTR_RW(toolaction); |
| 249 | |
Benjamin Romer | 54b3122 | 2014-07-22 09:56:26 -0400 | [diff] [blame] | 250 | static ssize_t boottotool_show(struct device *dev, |
| 251 | struct device_attribute *attr, char *buf); |
| 252 | static ssize_t boottotool_store(struct device *dev, |
| 253 | struct device_attribute *attr, const char *buf, size_t count); |
| 254 | static DEVICE_ATTR_RW(boottotool); |
| 255 | |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 256 | static ssize_t error_show(struct device *dev, struct device_attribute *attr, |
| 257 | char *buf); |
| 258 | static ssize_t error_store(struct device *dev, struct device_attribute *attr, |
| 259 | const char *buf, size_t count); |
| 260 | static DEVICE_ATTR_RW(error); |
| 261 | |
| 262 | static ssize_t textid_show(struct device *dev, struct device_attribute *attr, |
| 263 | char *buf); |
| 264 | static ssize_t textid_store(struct device *dev, struct device_attribute *attr, |
| 265 | const char *buf, size_t count); |
| 266 | static DEVICE_ATTR_RW(textid); |
| 267 | |
| 268 | static ssize_t remaining_steps_show(struct device *dev, |
| 269 | struct device_attribute *attr, char *buf); |
| 270 | static ssize_t remaining_steps_store(struct device *dev, |
| 271 | struct device_attribute *attr, const char *buf, size_t count); |
| 272 | static DEVICE_ATTR_RW(remaining_steps); |
| 273 | |
Benjamin Romer | 18b87ed | 2014-07-24 14:08:43 -0400 | [diff] [blame] | 274 | static ssize_t chipsetready_store(struct device *dev, |
| 275 | struct device_attribute *attr, const char *buf, size_t count); |
| 276 | static DEVICE_ATTR_WO(chipsetready); |
| 277 | |
Benjamin Romer | e56fa7c | 2014-07-29 11:11:21 -0400 | [diff] [blame] | 278 | static ssize_t devicedisabled_store(struct device *dev, |
| 279 | struct device_attribute *attr, const char *buf, size_t count); |
| 280 | static DEVICE_ATTR_WO(devicedisabled); |
| 281 | |
| 282 | static ssize_t deviceenabled_store(struct device *dev, |
| 283 | struct device_attribute *attr, const char *buf, size_t count); |
| 284 | static DEVICE_ATTR_WO(deviceenabled); |
| 285 | |
Benjamin Romer | 19f6634 | 2014-07-22 09:56:25 -0400 | [diff] [blame] | 286 | static struct attribute *visorchipset_install_attrs[] = { |
| 287 | &dev_attr_toolaction.attr, |
Benjamin Romer | 54b3122 | 2014-07-22 09:56:26 -0400 | [diff] [blame] | 288 | &dev_attr_boottotool.attr, |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 289 | &dev_attr_error.attr, |
| 290 | &dev_attr_textid.attr, |
| 291 | &dev_attr_remaining_steps.attr, |
Benjamin Romer | 19f6634 | 2014-07-22 09:56:25 -0400 | [diff] [blame] | 292 | NULL |
| 293 | }; |
| 294 | |
| 295 | static struct attribute_group visorchipset_install_group = { |
| 296 | .name = "install", |
| 297 | .attrs = visorchipset_install_attrs |
| 298 | }; |
| 299 | |
Benjamin Romer | 18b87ed | 2014-07-24 14:08:43 -0400 | [diff] [blame] | 300 | static struct attribute *visorchipset_guest_attrs[] = { |
| 301 | &dev_attr_chipsetready.attr, |
| 302 | NULL |
| 303 | }; |
| 304 | |
| 305 | static struct attribute_group visorchipset_guest_group = { |
| 306 | .name = "guest", |
| 307 | .attrs = visorchipset_guest_attrs |
| 308 | }; |
| 309 | |
Benjamin Romer | e56fa7c | 2014-07-29 11:11:21 -0400 | [diff] [blame] | 310 | static struct attribute *visorchipset_parahotplug_attrs[] = { |
| 311 | &dev_attr_devicedisabled.attr, |
| 312 | &dev_attr_deviceenabled.attr, |
| 313 | NULL |
| 314 | }; |
| 315 | |
| 316 | static struct attribute_group visorchipset_parahotplug_group = { |
| 317 | .name = "parahotplug", |
| 318 | .attrs = visorchipset_parahotplug_attrs |
| 319 | }; |
| 320 | |
Benjamin Romer | 19f6634 | 2014-07-22 09:56:25 -0400 | [diff] [blame] | 321 | static const struct attribute_group *visorchipset_dev_groups[] = { |
| 322 | &visorchipset_install_group, |
Benjamin Romer | 18b87ed | 2014-07-24 14:08:43 -0400 | [diff] [blame] | 323 | &visorchipset_guest_group, |
Benjamin Romer | e56fa7c | 2014-07-29 11:11:21 -0400 | [diff] [blame] | 324 | &visorchipset_parahotplug_group, |
Benjamin Romer | 19f6634 | 2014-07-22 09:56:25 -0400 | [diff] [blame] | 325 | NULL |
| 326 | }; |
| 327 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 328 | /* /sys/devices/platform/visorchipset */ |
Benjamin Romer | eb34e87 | 2015-03-16 13:58:45 -0400 | [diff] [blame] | 329 | static struct platform_device visorchipset_platform_device = { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 330 | .name = "visorchipset", |
| 331 | .id = -1, |
Benjamin Romer | 19f6634 | 2014-07-22 09:56:25 -0400 | [diff] [blame] | 332 | .dev.groups = visorchipset_dev_groups, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 333 | }; |
| 334 | |
| 335 | /* Function prototypes */ |
Benjamin Romer | b3168c7 | 2015-03-16 13:58:46 -0400 | [diff] [blame] | 336 | static void controlvm_respond(struct controlvm_message_header *msg_hdr, |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 337 | int response); |
| 338 | static void controlvm_respond_chipset_init( |
Benjamin Romer | b3168c7 | 2015-03-16 13:58:46 -0400 | [diff] [blame] | 339 | struct controlvm_message_header *msg_hdr, int response, |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 340 | enum ultra_chipset_feature features); |
| 341 | static void controlvm_respond_physdev_changestate( |
Benjamin Romer | b3168c7 | 2015-03-16 13:58:46 -0400 | [diff] [blame] | 342 | struct controlvm_message_header *msg_hdr, int response, |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 343 | struct spar_segment_state state); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 344 | |
Vincent Bernat | d746cb5 | 2014-08-01 10:29:30 +0200 | [diff] [blame] | 345 | static ssize_t toolaction_show(struct device *dev, |
| 346 | struct device_attribute *attr, |
| 347 | char *buf) |
Benjamin Romer | 19f6634 | 2014-07-22 09:56:25 -0400 | [diff] [blame] | 348 | { |
Benjamin Romer | 01f4d85 | 2015-03-16 13:58:48 -0400 | [diff] [blame] | 349 | u8 tool_action; |
Benjamin Romer | 19f6634 | 2014-07-22 09:56:25 -0400 | [diff] [blame] | 350 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 351 | visorchannel_read(controlvm_channel, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 352 | offsetof(struct spar_controlvm_channel_protocol, |
Benjamin Romer | 01f4d85 | 2015-03-16 13:58:48 -0400 | [diff] [blame] | 353 | tool_action), &tool_action, sizeof(u8)); |
| 354 | return scnprintf(buf, PAGE_SIZE, "%u\n", tool_action); |
Benjamin Romer | 19f6634 | 2014-07-22 09:56:25 -0400 | [diff] [blame] | 355 | } |
| 356 | |
Vincent Bernat | d746cb5 | 2014-08-01 10:29:30 +0200 | [diff] [blame] | 357 | static ssize_t toolaction_store(struct device *dev, |
| 358 | struct device_attribute *attr, |
| 359 | const char *buf, size_t count) |
Benjamin Romer | 19f6634 | 2014-07-22 09:56:25 -0400 | [diff] [blame] | 360 | { |
Benjamin Romer | 01f4d85 | 2015-03-16 13:58:48 -0400 | [diff] [blame] | 361 | u8 tool_action; |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 362 | int ret; |
Benjamin Romer | 19f6634 | 2014-07-22 09:56:25 -0400 | [diff] [blame] | 363 | |
Benjamin Romer | 01f4d85 | 2015-03-16 13:58:48 -0400 | [diff] [blame] | 364 | if (kstrtou8(buf, 10, &tool_action) != 0) |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 365 | return -EINVAL; |
| 366 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 367 | ret = visorchannel_write(controlvm_channel, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 368 | offsetof(struct spar_controlvm_channel_protocol, tool_action), |
Benjamin Romer | 01f4d85 | 2015-03-16 13:58:48 -0400 | [diff] [blame] | 369 | &tool_action, sizeof(u8)); |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 370 | |
| 371 | if (ret) |
| 372 | return ret; |
Benjamin Romer | e22a4a0 | 2014-08-18 09:34:54 -0400 | [diff] [blame] | 373 | return count; |
Benjamin Romer | 19f6634 | 2014-07-22 09:56:25 -0400 | [diff] [blame] | 374 | } |
| 375 | |
Vincent Bernat | d746cb5 | 2014-08-01 10:29:30 +0200 | [diff] [blame] | 376 | static ssize_t boottotool_show(struct device *dev, |
| 377 | struct device_attribute *attr, |
| 378 | char *buf) |
Benjamin Romer | 54b3122 | 2014-07-22 09:56:26 -0400 | [diff] [blame] | 379 | { |
Benjamin Romer | 365522d | 2015-03-16 13:58:49 -0400 | [diff] [blame] | 380 | struct efi_spar_indication efi_spar_indication; |
Benjamin Romer | 54b3122 | 2014-07-22 09:56:26 -0400 | [diff] [blame] | 381 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 382 | visorchannel_read(controlvm_channel, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 383 | offsetof(struct spar_controlvm_channel_protocol, |
Benjamin Romer | 365522d | 2015-03-16 13:58:49 -0400 | [diff] [blame] | 384 | efi_spar_ind), &efi_spar_indication, |
Benjamin Romer | 755e2ec | 2014-10-23 14:30:21 -0400 | [diff] [blame] | 385 | sizeof(struct efi_spar_indication)); |
Benjamin Romer | 54b3122 | 2014-07-22 09:56:26 -0400 | [diff] [blame] | 386 | return scnprintf(buf, PAGE_SIZE, "%u\n", |
Benjamin Romer | 365522d | 2015-03-16 13:58:49 -0400 | [diff] [blame] | 387 | efi_spar_indication.boot_to_tool); |
Benjamin Romer | 54b3122 | 2014-07-22 09:56:26 -0400 | [diff] [blame] | 388 | } |
| 389 | |
Vincent Bernat | d746cb5 | 2014-08-01 10:29:30 +0200 | [diff] [blame] | 390 | static ssize_t boottotool_store(struct device *dev, |
| 391 | struct device_attribute *attr, |
| 392 | const char *buf, size_t count) |
Benjamin Romer | 54b3122 | 2014-07-22 09:56:26 -0400 | [diff] [blame] | 393 | { |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 394 | int val, ret; |
Benjamin Romer | 365522d | 2015-03-16 13:58:49 -0400 | [diff] [blame] | 395 | struct efi_spar_indication efi_spar_indication; |
Benjamin Romer | 54b3122 | 2014-07-22 09:56:26 -0400 | [diff] [blame] | 396 | |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 397 | if (kstrtoint(buf, 10, &val) != 0) |
| 398 | return -EINVAL; |
| 399 | |
Benjamin Romer | 365522d | 2015-03-16 13:58:49 -0400 | [diff] [blame] | 400 | efi_spar_indication.boot_to_tool = val; |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 401 | ret = visorchannel_write(controlvm_channel, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 402 | offsetof(struct spar_controlvm_channel_protocol, |
| 403 | efi_spar_ind), |
Benjamin Romer | 365522d | 2015-03-16 13:58:49 -0400 | [diff] [blame] | 404 | &(efi_spar_indication), |
Benjamin Romer | 755e2ec | 2014-10-23 14:30:21 -0400 | [diff] [blame] | 405 | sizeof(struct efi_spar_indication)); |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 406 | |
| 407 | if (ret) |
| 408 | return ret; |
Benjamin Romer | e22a4a0 | 2014-08-18 09:34:54 -0400 | [diff] [blame] | 409 | return count; |
Benjamin Romer | 54b3122 | 2014-07-22 09:56:26 -0400 | [diff] [blame] | 410 | } |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 411 | |
| 412 | static ssize_t error_show(struct device *dev, struct device_attribute *attr, |
| 413 | char *buf) |
| 414 | { |
| 415 | u32 error; |
| 416 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 417 | visorchannel_read(controlvm_channel, offsetof( |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 418 | struct spar_controlvm_channel_protocol, installation_error), |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 419 | &error, sizeof(u32)); |
| 420 | return scnprintf(buf, PAGE_SIZE, "%i\n", error); |
| 421 | } |
| 422 | |
| 423 | static ssize_t error_store(struct device *dev, struct device_attribute *attr, |
| 424 | const char *buf, size_t count) |
| 425 | { |
| 426 | u32 error; |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 427 | int ret; |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 428 | |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 429 | if (kstrtou32(buf, 10, &error) != 0) |
| 430 | return -EINVAL; |
| 431 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 432 | ret = visorchannel_write(controlvm_channel, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 433 | offsetof(struct spar_controlvm_channel_protocol, |
| 434 | installation_error), |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 435 | &error, sizeof(u32)); |
| 436 | if (ret) |
| 437 | return ret; |
Benjamin Romer | e22a4a0 | 2014-08-18 09:34:54 -0400 | [diff] [blame] | 438 | return count; |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | static ssize_t textid_show(struct device *dev, struct device_attribute *attr, |
| 442 | char *buf) |
| 443 | { |
Benjamin Romer | 10dbf0e | 2015-03-16 13:58:50 -0400 | [diff] [blame] | 444 | u32 text_id; |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 445 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 446 | visorchannel_read(controlvm_channel, offsetof( |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 447 | struct spar_controlvm_channel_protocol, installation_text_id), |
Benjamin Romer | 10dbf0e | 2015-03-16 13:58:50 -0400 | [diff] [blame] | 448 | &text_id, sizeof(u32)); |
| 449 | return scnprintf(buf, PAGE_SIZE, "%i\n", text_id); |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static ssize_t textid_store(struct device *dev, struct device_attribute *attr, |
| 453 | const char *buf, size_t count) |
| 454 | { |
Benjamin Romer | 10dbf0e | 2015-03-16 13:58:50 -0400 | [diff] [blame] | 455 | u32 text_id; |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 456 | int ret; |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 457 | |
Benjamin Romer | 10dbf0e | 2015-03-16 13:58:50 -0400 | [diff] [blame] | 458 | if (kstrtou32(buf, 10, &text_id) != 0) |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 459 | return -EINVAL; |
| 460 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 461 | ret = visorchannel_write(controlvm_channel, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 462 | offsetof(struct spar_controlvm_channel_protocol, |
| 463 | installation_text_id), |
Benjamin Romer | 10dbf0e | 2015-03-16 13:58:50 -0400 | [diff] [blame] | 464 | &text_id, sizeof(u32)); |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 465 | if (ret) |
| 466 | return ret; |
Benjamin Romer | e22a4a0 | 2014-08-18 09:34:54 -0400 | [diff] [blame] | 467 | return count; |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 468 | } |
| 469 | |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 470 | static ssize_t remaining_steps_show(struct device *dev, |
| 471 | struct device_attribute *attr, char *buf) |
| 472 | { |
Benjamin Romer | ee8da29 | 2015-03-16 13:58:51 -0400 | [diff] [blame^] | 473 | u16 remaining_steps; |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 474 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 475 | visorchannel_read(controlvm_channel, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 476 | offsetof(struct spar_controlvm_channel_protocol, |
| 477 | installation_remaining_steps), |
Benjamin Romer | ee8da29 | 2015-03-16 13:58:51 -0400 | [diff] [blame^] | 478 | &remaining_steps, |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 479 | sizeof(u16)); |
Benjamin Romer | ee8da29 | 2015-03-16 13:58:51 -0400 | [diff] [blame^] | 480 | return scnprintf(buf, PAGE_SIZE, "%hu\n", remaining_steps); |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | static ssize_t remaining_steps_store(struct device *dev, |
| 484 | struct device_attribute *attr, const char *buf, size_t count) |
| 485 | { |
Benjamin Romer | ee8da29 | 2015-03-16 13:58:51 -0400 | [diff] [blame^] | 486 | u16 remaining_steps; |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 487 | int ret; |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 488 | |
Benjamin Romer | ee8da29 | 2015-03-16 13:58:51 -0400 | [diff] [blame^] | 489 | if (kstrtou16(buf, 10, &remaining_steps) != 0) |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 490 | return -EINVAL; |
| 491 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 492 | ret = visorchannel_write(controlvm_channel, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 493 | offsetof(struct spar_controlvm_channel_protocol, |
| 494 | installation_remaining_steps), |
Benjamin Romer | ee8da29 | 2015-03-16 13:58:51 -0400 | [diff] [blame^] | 495 | &remaining_steps, sizeof(u16)); |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 496 | if (ret) |
| 497 | return ret; |
Benjamin Romer | e22a4a0 | 2014-08-18 09:34:54 -0400 | [diff] [blame] | 498 | return count; |
Benjamin Romer | 422af17 | 2014-07-24 14:08:42 -0400 | [diff] [blame] | 499 | } |
| 500 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 501 | static void |
Benjamin Romer | 9b989a98 | 2015-03-16 13:58:11 -0400 | [diff] [blame] | 502 | bus_info_clear(void *v) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 503 | { |
Benjamin Romer | 33192fa | 2014-10-31 09:57:27 -0400 | [diff] [blame] | 504 | struct visorchipset_bus_info *p = (struct visorchipset_bus_info *) (v); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 505 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 506 | kfree(p->name); |
| 507 | p->name = NULL; |
| 508 | |
| 509 | kfree(p->description); |
| 510 | p->description = NULL; |
| 511 | |
| 512 | p->state.created = 0; |
Benjamin Romer | 33192fa | 2014-10-31 09:57:27 -0400 | [diff] [blame] | 513 | memset(p, 0, sizeof(struct visorchipset_bus_info)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | static void |
Benjamin Romer | 9b989a98 | 2015-03-16 13:58:11 -0400 | [diff] [blame] | 517 | dev_info_clear(void *v) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 518 | { |
Benjamin Romer | 246e0cd | 2014-10-31 09:57:24 -0400 | [diff] [blame] | 519 | struct visorchipset_device_info *p = |
| 520 | (struct visorchipset_device_info *)(v); |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 521 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 522 | p->state.created = 0; |
Benjamin Romer | 246e0cd | 2014-10-31 09:57:24 -0400 | [diff] [blame] | 523 | memset(p, 0, sizeof(struct visorchipset_device_info)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 524 | } |
| 525 | |
Benjamin Romer | c242233 | 2014-07-29 15:09:40 -0400 | [diff] [blame] | 526 | static u8 |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 527 | check_chipset_events(void) |
| 528 | { |
| 529 | int i; |
Benjamin Romer | c242233 | 2014-07-29 15:09:40 -0400 | [diff] [blame] | 530 | u8 send_msg = 1; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 531 | /* Check events to determine if response should be sent */ |
| 532 | for (i = 0; i < MAX_CHIPSET_EVENTS; i++) |
| 533 | send_msg &= chipset_events[i]; |
| 534 | return send_msg; |
| 535 | } |
| 536 | |
| 537 | static void |
| 538 | clear_chipset_events(void) |
| 539 | { |
| 540 | int i; |
| 541 | /* Clear chipset_events */ |
| 542 | for (i = 0; i < MAX_CHIPSET_EVENTS; i++) |
| 543 | chipset_events[i] = 0; |
| 544 | } |
| 545 | |
| 546 | void |
Benjamin Romer | fe90d89 | 2014-10-31 09:57:32 -0400 | [diff] [blame] | 547 | visorchipset_register_busdev_server( |
| 548 | struct visorchipset_busdev_notifiers *notifiers, |
Benjamin Romer | 929aa8a | 2014-10-31 09:57:33 -0400 | [diff] [blame] | 549 | struct visorchipset_busdev_responders *responders, |
Benjamin Romer | 1e7a59c | 2014-10-31 09:57:35 -0400 | [diff] [blame] | 550 | struct ultra_vbus_deviceinfo *driver_info) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 551 | { |
Benjamin Romer | 8f1947a | 2015-03-16 13:57:59 -0400 | [diff] [blame] | 552 | down(¬ifier_lock); |
Benjamin Romer | 38f736e | 2015-03-16 13:58:13 -0400 | [diff] [blame] | 553 | if (!notifiers) { |
Benjamin Romer | 6fe345a | 2015-03-16 13:58:42 -0400 | [diff] [blame] | 554 | memset(&busdev_server_notifiers, 0, |
| 555 | sizeof(busdev_server_notifiers)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 556 | serverregistered = 0; /* clear flag */ |
| 557 | } else { |
Benjamin Romer | 6fe345a | 2015-03-16 13:58:42 -0400 | [diff] [blame] | 558 | busdev_server_notifiers = *notifiers; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 559 | serverregistered = 1; /* set flag */ |
| 560 | } |
| 561 | if (responders) |
Benjamin Romer | 8e3fedd | 2015-03-16 13:58:43 -0400 | [diff] [blame] | 562 | *responders = busdev_responders; |
Benjamin Romer | 1e7a59c | 2014-10-31 09:57:35 -0400 | [diff] [blame] | 563 | if (driver_info) |
| 564 | bus_device_info_init(driver_info, "chipset", "visorchipset", |
Ken Cox | 836bee9 | 2014-06-26 09:55:55 -0500 | [diff] [blame] | 565 | VERSION, NULL); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 566 | |
Benjamin Romer | 8f1947a | 2015-03-16 13:57:59 -0400 | [diff] [blame] | 567 | up(¬ifier_lock); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 568 | } |
| 569 | EXPORT_SYMBOL_GPL(visorchipset_register_busdev_server); |
| 570 | |
| 571 | void |
Benjamin Romer | fe90d89 | 2014-10-31 09:57:32 -0400 | [diff] [blame] | 572 | visorchipset_register_busdev_client( |
| 573 | struct visorchipset_busdev_notifiers *notifiers, |
Benjamin Romer | 929aa8a | 2014-10-31 09:57:33 -0400 | [diff] [blame] | 574 | struct visorchipset_busdev_responders *responders, |
Benjamin Romer | 43fce01 | 2014-10-31 09:57:34 -0400 | [diff] [blame] | 575 | struct ultra_vbus_deviceinfo *driver_info) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 576 | { |
Benjamin Romer | 8f1947a | 2015-03-16 13:57:59 -0400 | [diff] [blame] | 577 | down(¬ifier_lock); |
Benjamin Romer | 38f736e | 2015-03-16 13:58:13 -0400 | [diff] [blame] | 578 | if (!notifiers) { |
Benjamin Romer | 6fe345a | 2015-03-16 13:58:42 -0400 | [diff] [blame] | 579 | memset(&busdev_client_notifiers, 0, |
| 580 | sizeof(busdev_client_notifiers)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 581 | clientregistered = 0; /* clear flag */ |
| 582 | } else { |
Benjamin Romer | 6fe345a | 2015-03-16 13:58:42 -0400 | [diff] [blame] | 583 | busdev_client_notifiers = *notifiers; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 584 | clientregistered = 1; /* set flag */ |
| 585 | } |
| 586 | if (responders) |
Benjamin Romer | 8e3fedd | 2015-03-16 13:58:43 -0400 | [diff] [blame] | 587 | *responders = busdev_responders; |
Benjamin Romer | 43fce01 | 2014-10-31 09:57:34 -0400 | [diff] [blame] | 588 | if (driver_info) |
| 589 | bus_device_info_init(driver_info, "chipset(bolts)", |
| 590 | "visorchipset", VERSION, NULL); |
Benjamin Romer | 8f1947a | 2015-03-16 13:57:59 -0400 | [diff] [blame] | 591 | up(¬ifier_lock); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 592 | } |
| 593 | EXPORT_SYMBOL_GPL(visorchipset_register_busdev_client); |
| 594 | |
| 595 | static void |
| 596 | cleanup_controlvm_structures(void) |
| 597 | { |
Benjamin Romer | 33192fa | 2014-10-31 09:57:27 -0400 | [diff] [blame] | 598 | struct visorchipset_bus_info *bi, *tmp_bi; |
Benjamin Romer | 246e0cd | 2014-10-31 09:57:24 -0400 | [diff] [blame] | 599 | struct visorchipset_device_info *di, *tmp_di; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 600 | |
Benjamin Romer | 1390b88 | 2015-03-16 13:58:03 -0400 | [diff] [blame] | 601 | list_for_each_entry_safe(bi, tmp_bi, &bus_info_list, entry) { |
Benjamin Romer | 9b989a98 | 2015-03-16 13:58:11 -0400 | [diff] [blame] | 602 | bus_info_clear(bi); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 603 | list_del(&bi->entry); |
| 604 | kfree(bi); |
| 605 | } |
| 606 | |
Benjamin Romer | 1390b88 | 2015-03-16 13:58:03 -0400 | [diff] [blame] | 607 | list_for_each_entry_safe(di, tmp_di, &dev_info_list, entry) { |
Benjamin Romer | 9b989a98 | 2015-03-16 13:58:11 -0400 | [diff] [blame] | 608 | dev_info_clear(di); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 609 | list_del(&di->entry); |
| 610 | kfree(di); |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | static void |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 615 | chipset_init(struct controlvm_message *inmsg) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 616 | { |
| 617 | static int chipset_inited; |
Benjamin Romer | b9b141e | 2014-10-23 14:30:24 -0400 | [diff] [blame] | 618 | enum ultra_chipset_feature features = 0; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 619 | int rc = CONTROLVM_RESP_SUCCESS; |
| 620 | |
| 621 | POSTCODE_LINUX_2(CHIPSET_INIT_ENTRY_PC, POSTCODE_SEVERITY_INFO); |
| 622 | if (chipset_inited) { |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 623 | rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE; |
Benjamin Romer | e3199b2 | 2015-03-16 13:58:14 -0400 | [diff] [blame] | 624 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 625 | } |
| 626 | chipset_inited = 1; |
| 627 | POSTCODE_LINUX_2(CHIPSET_INIT_EXIT_PC, POSTCODE_SEVERITY_INFO); |
| 628 | |
| 629 | /* Set features to indicate we support parahotplug (if Command |
| 630 | * also supports it). */ |
| 631 | features = |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 632 | inmsg->cmd.init_chipset. |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 633 | features & ULTRA_CHIPSET_FEATURE_PARA_HOTPLUG; |
| 634 | |
| 635 | /* Set the "reply" bit so Command knows this is a |
| 636 | * features-aware driver. */ |
| 637 | features |= ULTRA_CHIPSET_FEATURE_REPLY; |
| 638 | |
Benjamin Romer | e3199b2 | 2015-03-16 13:58:14 -0400 | [diff] [blame] | 639 | cleanup: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 640 | if (rc < 0) |
| 641 | cleanup_controlvm_structures(); |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 642 | if (inmsg->hdr.flags.response_expected) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 643 | controlvm_respond_chipset_init(&inmsg->hdr, rc, features); |
| 644 | } |
| 645 | |
| 646 | static void |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 647 | controlvm_init_response(struct controlvm_message *msg, |
Benjamin Romer | b3168c7 | 2015-03-16 13:58:46 -0400 | [diff] [blame] | 648 | struct controlvm_message_header *msg_hdr, int response) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 649 | { |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 650 | memset(msg, 0, sizeof(struct controlvm_message)); |
Benjamin Romer | b3168c7 | 2015-03-16 13:58:46 -0400 | [diff] [blame] | 651 | memcpy(&msg->hdr, msg_hdr, sizeof(struct controlvm_message_header)); |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 652 | msg->hdr.payload_bytes = 0; |
| 653 | msg->hdr.payload_vm_offset = 0; |
| 654 | msg->hdr.payload_max_bytes = 0; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 655 | if (response < 0) { |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 656 | msg->hdr.flags.failed = 1; |
| 657 | msg->hdr.completion_status = (u32) (-response); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
| 661 | static void |
Benjamin Romer | b3168c7 | 2015-03-16 13:58:46 -0400 | [diff] [blame] | 662 | controlvm_respond(struct controlvm_message_header *msg_hdr, int response) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 663 | { |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 664 | struct controlvm_message outmsg; |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 665 | |
Benjamin Romer | b3168c7 | 2015-03-16 13:58:46 -0400 | [diff] [blame] | 666 | controlvm_init_response(&outmsg, msg_hdr, response); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 667 | /* For DiagPool channel DEVICE_CHANGESTATE, we need to send |
| 668 | * back the deviceChangeState structure in the packet. */ |
Benjamin Romer | b3168c7 | 2015-03-16 13:58:46 -0400 | [diff] [blame] | 669 | if (msg_hdr->id == CONTROLVM_DEVICE_CHANGESTATE && |
Benjamin Romer | 0639ba6 | 2015-03-16 13:58:04 -0400 | [diff] [blame] | 670 | g_devicechangestate_packet.device_change_state.bus_no == |
| 671 | g_diagpool_bus_no && |
| 672 | g_devicechangestate_packet.device_change_state.dev_no == |
Benjamin Romer | 83d4890 | 2015-03-16 13:58:01 -0400 | [diff] [blame] | 673 | g_diagpool_dev_no) |
Benjamin Romer | 4f44b72 | 2015-03-16 13:58:02 -0400 | [diff] [blame] | 674 | outmsg.cmd = g_devicechangestate_packet; |
Benjamin Romer | 2098dbd | 2015-03-04 12:14:22 -0500 | [diff] [blame] | 675 | if (outmsg.hdr.flags.test_message == 1) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 676 | return; |
Benjamin Romer | 2098dbd | 2015-03-04 12:14:22 -0500 | [diff] [blame] | 677 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 678 | if (!visorchannel_signalinsert(controlvm_channel, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 679 | CONTROLVM_QUEUE_REQUEST, &outmsg)) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 680 | return; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | static void |
Benjamin Romer | b3168c7 | 2015-03-16 13:58:46 -0400 | [diff] [blame] | 685 | controlvm_respond_chipset_init(struct controlvm_message_header *msg_hdr, |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 686 | int response, |
Benjamin Romer | b9b141e | 2014-10-23 14:30:24 -0400 | [diff] [blame] | 687 | enum ultra_chipset_feature features) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 688 | { |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 689 | struct controlvm_message outmsg; |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 690 | |
Benjamin Romer | b3168c7 | 2015-03-16 13:58:46 -0400 | [diff] [blame] | 691 | controlvm_init_response(&outmsg, msg_hdr, response); |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 692 | outmsg.cmd.init_chipset.features = features; |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 693 | if (!visorchannel_signalinsert(controlvm_channel, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 694 | CONTROLVM_QUEUE_REQUEST, &outmsg)) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 695 | return; |
| 696 | } |
| 697 | } |
| 698 | |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 699 | static void controlvm_respond_physdev_changestate( |
Benjamin Romer | b3168c7 | 2015-03-16 13:58:46 -0400 | [diff] [blame] | 700 | struct controlvm_message_header *msg_hdr, int response, |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 701 | struct spar_segment_state state) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 702 | { |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 703 | struct controlvm_message outmsg; |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 704 | |
Benjamin Romer | b3168c7 | 2015-03-16 13:58:46 -0400 | [diff] [blame] | 705 | controlvm_init_response(&outmsg, msg_hdr, response); |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 706 | outmsg.cmd.device_change_state.state = state; |
| 707 | outmsg.cmd.device_change_state.flags.phys_device = 1; |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 708 | if (!visorchannel_signalinsert(controlvm_channel, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 709 | CONTROLVM_QUEUE_REQUEST, &outmsg)) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 710 | return; |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | void |
Benjamin Romer | 2c683cd | 2014-10-31 09:57:22 -0400 | [diff] [blame] | 715 | visorchipset_save_message(struct controlvm_message *msg, |
| 716 | enum crash_obj_type type) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 717 | { |
Benjamin Romer | 4577225 | 2015-03-16 13:58:15 -0400 | [diff] [blame] | 718 | u32 crash_msg_offset; |
| 719 | u16 crash_msg_count; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 720 | |
| 721 | /* get saved message count */ |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 722 | if (visorchannel_read(controlvm_channel, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 723 | offsetof(struct spar_controlvm_channel_protocol, |
| 724 | saved_crash_message_count), |
Benjamin Romer | 4577225 | 2015-03-16 13:58:15 -0400 | [diff] [blame] | 725 | &crash_msg_count, sizeof(u16)) < 0) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 726 | POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC, |
| 727 | POSTCODE_SEVERITY_ERR); |
| 728 | return; |
| 729 | } |
| 730 | |
Benjamin Romer | 4577225 | 2015-03-16 13:58:15 -0400 | [diff] [blame] | 731 | if (crash_msg_count != CONTROLVM_CRASHMSG_MAX) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 732 | POSTCODE_LINUX_3(CRASH_DEV_COUNT_FAILURE_PC, |
Benjamin Romer | 4577225 | 2015-03-16 13:58:15 -0400 | [diff] [blame] | 733 | crash_msg_count, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 734 | POSTCODE_SEVERITY_ERR); |
| 735 | return; |
| 736 | } |
| 737 | |
| 738 | /* get saved crash message offset */ |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 739 | if (visorchannel_read(controlvm_channel, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 740 | offsetof(struct spar_controlvm_channel_protocol, |
| 741 | saved_crash_message_offset), |
Benjamin Romer | 4577225 | 2015-03-16 13:58:15 -0400 | [diff] [blame] | 742 | &crash_msg_offset, sizeof(u32)) < 0) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 743 | POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC, |
| 744 | POSTCODE_SEVERITY_ERR); |
| 745 | return; |
| 746 | } |
| 747 | |
Benjamin Romer | 2c683cd | 2014-10-31 09:57:22 -0400 | [diff] [blame] | 748 | if (type == CRASH_BUS) { |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 749 | if (visorchannel_write(controlvm_channel, |
Benjamin Romer | 4577225 | 2015-03-16 13:58:15 -0400 | [diff] [blame] | 750 | crash_msg_offset, |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 751 | msg, |
| 752 | sizeof(struct controlvm_message)) < 0) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 753 | POSTCODE_LINUX_2(SAVE_MSG_BUS_FAILURE_PC, |
| 754 | POSTCODE_SEVERITY_ERR); |
| 755 | return; |
| 756 | } |
| 757 | } else { |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 758 | if (visorchannel_write(controlvm_channel, |
Benjamin Romer | 4577225 | 2015-03-16 13:58:15 -0400 | [diff] [blame] | 759 | crash_msg_offset + |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 760 | sizeof(struct controlvm_message), msg, |
| 761 | sizeof(struct controlvm_message)) < 0) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 762 | POSTCODE_LINUX_2(SAVE_MSG_DEV_FAILURE_PC, |
| 763 | POSTCODE_SEVERITY_ERR); |
| 764 | return; |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | EXPORT_SYMBOL_GPL(visorchipset_save_message); |
| 769 | |
| 770 | static void |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 771 | bus_responder(enum controlvm_id cmd_id, ulong bus_no, int response) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 772 | { |
Benjamin Romer | 33192fa | 2014-10-31 09:57:27 -0400 | [diff] [blame] | 773 | struct visorchipset_bus_info *p = NULL; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 774 | BOOL need_clear = FALSE; |
| 775 | |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 776 | p = findbus(&bus_info_list, bus_no); |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 777 | if (!p) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 778 | return; |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 779 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 780 | if (response < 0) { |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 781 | if ((cmd_id == CONTROLVM_BUS_CREATE) && |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 782 | (response != (-CONTROLVM_RESP_ERROR_ALREADY_DONE))) |
| 783 | /* undo the row we just created... */ |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 784 | delbusdevices(&dev_info_list, bus_no); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 785 | } else { |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 786 | if (cmd_id == CONTROLVM_BUS_CREATE) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 787 | p->state.created = 1; |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 788 | if (cmd_id == CONTROLVM_BUS_DESTROY) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 789 | need_clear = TRUE; |
| 790 | } |
| 791 | |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 792 | if (p->pending_msg_hdr.id == CONTROLVM_INVALID) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 793 | return; /* no controlvm response needed */ |
Benjamin Romer | 6b59b31 | 2015-03-16 13:58:18 -0400 | [diff] [blame] | 794 | if (p->pending_msg_hdr.id != (u32)cmd_id) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 795 | return; |
Benjamin Romer | 33192fa | 2014-10-31 09:57:27 -0400 | [diff] [blame] | 796 | controlvm_respond(&p->pending_msg_hdr, response); |
| 797 | p->pending_msg_hdr.id = CONTROLVM_INVALID; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 798 | if (need_clear) { |
Benjamin Romer | 9b989a98 | 2015-03-16 13:58:11 -0400 | [diff] [blame] | 799 | bus_info_clear(p); |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 800 | delbusdevices(&dev_info_list, bus_no); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
| 804 | static void |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 805 | device_changestate_responder(enum controlvm_id cmd_id, |
| 806 | ulong bus_no, ulong dev_no, int response, |
| 807 | struct spar_segment_state response_state) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 808 | { |
Benjamin Romer | 246e0cd | 2014-10-31 09:57:24 -0400 | [diff] [blame] | 809 | struct visorchipset_device_info *p = NULL; |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 810 | struct controlvm_message outmsg; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 811 | |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 812 | p = finddevice(&dev_info_list, bus_no, dev_no); |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 813 | if (!p) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 814 | return; |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 815 | if (p->pending_msg_hdr.id == CONTROLVM_INVALID) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 816 | return; /* no controlvm response needed */ |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 817 | if (p->pending_msg_hdr.id != cmd_id) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 818 | return; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 819 | |
Benjamin Romer | 246e0cd | 2014-10-31 09:57:24 -0400 | [diff] [blame] | 820 | controlvm_init_response(&outmsg, &p->pending_msg_hdr, response); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 821 | |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 822 | outmsg.cmd.device_change_state.bus_no = bus_no; |
| 823 | outmsg.cmd.device_change_state.dev_no = dev_no; |
| 824 | outmsg.cmd.device_change_state.state = response_state; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 825 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 826 | if (!visorchannel_signalinsert(controlvm_channel, |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 827 | CONTROLVM_QUEUE_REQUEST, &outmsg)) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 828 | return; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 829 | |
Benjamin Romer | 246e0cd | 2014-10-31 09:57:24 -0400 | [diff] [blame] | 830 | p->pending_msg_hdr.id = CONTROLVM_INVALID; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | static void |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 834 | device_responder(enum controlvm_id cmd_id, ulong bus_no, ulong dev_no, |
Benjamin Romer | 53bebb1 | 2014-10-23 14:30:17 -0400 | [diff] [blame] | 835 | int response) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 836 | { |
Benjamin Romer | 246e0cd | 2014-10-31 09:57:24 -0400 | [diff] [blame] | 837 | struct visorchipset_device_info *p = NULL; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 838 | BOOL need_clear = FALSE; |
| 839 | |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 840 | p = finddevice(&dev_info_list, bus_no, dev_no); |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 841 | if (!p) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 842 | return; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 843 | if (response >= 0) { |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 844 | if (cmd_id == CONTROLVM_DEVICE_CREATE) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 845 | p->state.created = 1; |
Benjamin Romer | fbb31f4 | 2015-03-16 13:58:16 -0400 | [diff] [blame] | 846 | if (cmd_id == CONTROLVM_DEVICE_DESTROY) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 847 | need_clear = TRUE; |
| 848 | } |
| 849 | |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 850 | if (p->pending_msg_hdr.id == CONTROLVM_INVALID) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 851 | return; /* no controlvm response needed */ |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 852 | |
Benjamin Romer | 6b59b31 | 2015-03-16 13:58:18 -0400 | [diff] [blame] | 853 | if (p->pending_msg_hdr.id != (u32)cmd_id) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 854 | return; |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 855 | |
Benjamin Romer | 246e0cd | 2014-10-31 09:57:24 -0400 | [diff] [blame] | 856 | controlvm_respond(&p->pending_msg_hdr, response); |
| 857 | p->pending_msg_hdr.id = CONTROLVM_INVALID; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 858 | if (need_clear) |
Benjamin Romer | 9b989a98 | 2015-03-16 13:58:11 -0400 | [diff] [blame] | 859 | dev_info_clear(p); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | static void |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 863 | bus_epilog(u32 bus_no, |
| 864 | u32 cmd, struct controlvm_message_header *msg_hdr, |
| 865 | int response, BOOL need_response) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 866 | { |
| 867 | BOOL notified = FALSE; |
| 868 | |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 869 | struct visorchipset_bus_info *bus_info = findbus(&bus_info_list, |
| 870 | bus_no); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 871 | |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 872 | if (!bus_info) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 873 | return; |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 874 | |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 875 | if (need_response) { |
| 876 | memcpy(&bus_info->pending_msg_hdr, msg_hdr, |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 877 | sizeof(struct controlvm_message_header)); |
Benjamin Romer | 75c1f8b | 2015-03-16 13:58:19 -0400 | [diff] [blame] | 878 | } else { |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 879 | bus_info->pending_msg_hdr.id = CONTROLVM_INVALID; |
Benjamin Romer | 75c1f8b | 2015-03-16 13:58:19 -0400 | [diff] [blame] | 880 | } |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 881 | |
Benjamin Romer | 8f1947a | 2015-03-16 13:57:59 -0400 | [diff] [blame] | 882 | down(¬ifier_lock); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 883 | if (response == CONTROLVM_RESP_SUCCESS) { |
| 884 | switch (cmd) { |
| 885 | case CONTROLVM_BUS_CREATE: |
| 886 | /* We can't tell from the bus_create |
| 887 | * information which of our 2 bus flavors the |
| 888 | * devices on this bus will ultimately end up. |
| 889 | * FORTUNATELY, it turns out it is harmless to |
| 890 | * send the bus_create to both of them. We can |
| 891 | * narrow things down a little bit, though, |
| 892 | * because we know: - BusDev_Server can handle |
| 893 | * either server or client devices |
| 894 | * - BusDev_Client can handle ONLY client |
| 895 | * devices */ |
Benjamin Romer | 6fe345a | 2015-03-16 13:58:42 -0400 | [diff] [blame] | 896 | if (busdev_server_notifiers.bus_create) { |
| 897 | (*busdev_server_notifiers.bus_create) (bus_no); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 898 | notified = TRUE; |
| 899 | } |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 900 | if ((!bus_info->flags.server) /*client */ && |
Benjamin Romer | 6fe345a | 2015-03-16 13:58:42 -0400 | [diff] [blame] | 901 | busdev_client_notifiers.bus_create) { |
| 902 | (*busdev_client_notifiers.bus_create) (bus_no); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 903 | notified = TRUE; |
| 904 | } |
| 905 | break; |
| 906 | case CONTROLVM_BUS_DESTROY: |
Benjamin Romer | 6fe345a | 2015-03-16 13:58:42 -0400 | [diff] [blame] | 907 | if (busdev_server_notifiers.bus_destroy) { |
| 908 | (*busdev_server_notifiers.bus_destroy) (bus_no); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 909 | notified = TRUE; |
| 910 | } |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 911 | if ((!bus_info->flags.server) /*client */ && |
Benjamin Romer | 6fe345a | 2015-03-16 13:58:42 -0400 | [diff] [blame] | 912 | busdev_client_notifiers.bus_destroy) { |
| 913 | (*busdev_client_notifiers.bus_destroy) (bus_no); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 914 | notified = TRUE; |
| 915 | } |
| 916 | break; |
| 917 | } |
| 918 | } |
| 919 | if (notified) |
| 920 | /* The callback function just called above is responsible |
Benjamin Romer | 929aa8a | 2014-10-31 09:57:33 -0400 | [diff] [blame] | 921 | * for calling the appropriate visorchipset_busdev_responders |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 922 | * function, which will call bus_responder() |
| 923 | */ |
| 924 | ; |
| 925 | else |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 926 | bus_responder(cmd, bus_no, response); |
Benjamin Romer | 8f1947a | 2015-03-16 13:57:59 -0400 | [diff] [blame] | 927 | up(¬ifier_lock); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | static void |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 931 | device_epilog(u32 bus_no, u32 dev_no, struct spar_segment_state state, u32 cmd, |
| 932 | struct controlvm_message_header *msg_hdr, int response, |
| 933 | BOOL need_response, BOOL for_visorbus) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 934 | { |
Benjamin Romer | fe90d89 | 2014-10-31 09:57:32 -0400 | [diff] [blame] | 935 | struct visorchipset_busdev_notifiers *notifiers = NULL; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 936 | BOOL notified = FALSE; |
| 937 | |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 938 | struct visorchipset_device_info *dev_info = |
| 939 | finddevice(&dev_info_list, bus_no, dev_no); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 940 | char *envp[] = { |
| 941 | "SPARSP_DIAGPOOL_PAUSED_STATE = 1", |
| 942 | NULL |
| 943 | }; |
| 944 | |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 945 | if (!dev_info) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 946 | return; |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 947 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 948 | if (for_visorbus) |
Benjamin Romer | 6fe345a | 2015-03-16 13:58:42 -0400 | [diff] [blame] | 949 | notifiers = &busdev_server_notifiers; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 950 | else |
Benjamin Romer | 6fe345a | 2015-03-16 13:58:42 -0400 | [diff] [blame] | 951 | notifiers = &busdev_client_notifiers; |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 952 | if (need_response) { |
| 953 | memcpy(&dev_info->pending_msg_hdr, msg_hdr, |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 954 | sizeof(struct controlvm_message_header)); |
Benjamin Romer | 75c1f8b | 2015-03-16 13:58:19 -0400 | [diff] [blame] | 955 | } else { |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 956 | dev_info->pending_msg_hdr.id = CONTROLVM_INVALID; |
Benjamin Romer | 75c1f8b | 2015-03-16 13:58:19 -0400 | [diff] [blame] | 957 | } |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 958 | |
Benjamin Romer | 8f1947a | 2015-03-16 13:57:59 -0400 | [diff] [blame] | 959 | down(¬ifier_lock); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 960 | if (response >= 0) { |
| 961 | switch (cmd) { |
| 962 | case CONTROLVM_DEVICE_CREATE: |
| 963 | if (notifiers->device_create) { |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 964 | (*notifiers->device_create) (bus_no, dev_no); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 965 | notified = TRUE; |
| 966 | } |
| 967 | break; |
| 968 | case CONTROLVM_DEVICE_CHANGESTATE: |
| 969 | /* ServerReady / ServerRunning / SegmentStateRunning */ |
Benjamin Romer | bd0d2dc | 2014-10-23 14:30:13 -0400 | [diff] [blame] | 970 | if (state.alive == segment_state_running.alive && |
| 971 | state.operating == |
| 972 | segment_state_running.operating) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 973 | if (notifiers->device_resume) { |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 974 | (*notifiers->device_resume) (bus_no, |
| 975 | dev_no); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 976 | notified = TRUE; |
| 977 | } |
| 978 | } |
| 979 | /* ServerNotReady / ServerLost / SegmentStateStandby */ |
Benjamin Romer | bd0d2dc | 2014-10-23 14:30:13 -0400 | [diff] [blame] | 980 | else if (state.alive == segment_state_standby.alive && |
Benjamin Romer | 3f833b5 | 2014-10-23 14:30:12 -0400 | [diff] [blame] | 981 | state.operating == |
Benjamin Romer | bd0d2dc | 2014-10-23 14:30:13 -0400 | [diff] [blame] | 982 | segment_state_standby.operating) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 983 | /* technically this is standby case |
| 984 | * where server is lost |
| 985 | */ |
| 986 | if (notifiers->device_pause) { |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 987 | (*notifiers->device_pause) (bus_no, |
| 988 | dev_no); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 989 | notified = TRUE; |
| 990 | } |
Benjamin Romer | bd0d2dc | 2014-10-23 14:30:13 -0400 | [diff] [blame] | 991 | } else if (state.alive == segment_state_paused.alive && |
Benjamin Romer | 3f833b5 | 2014-10-23 14:30:12 -0400 | [diff] [blame] | 992 | state.operating == |
Benjamin Romer | bd0d2dc | 2014-10-23 14:30:13 -0400 | [diff] [blame] | 993 | segment_state_paused.operating) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 994 | /* this is lite pause where channel is |
| 995 | * still valid just 'pause' of it |
| 996 | */ |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 997 | if (bus_no == g_diagpool_bus_no && |
| 998 | dev_no == g_diagpool_dev_no) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 999 | /* this will trigger the |
| 1000 | * diag_shutdown.sh script in |
| 1001 | * the visorchipset hotplug */ |
| 1002 | kobject_uevent_env |
Benjamin Romer | eb34e87 | 2015-03-16 13:58:45 -0400 | [diff] [blame] | 1003 | (&visorchipset_platform_device.dev. |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1004 | kobj, KOBJ_ONLINE, envp); |
| 1005 | } |
| 1006 | } |
| 1007 | break; |
| 1008 | case CONTROLVM_DEVICE_DESTROY: |
| 1009 | if (notifiers->device_destroy) { |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 1010 | (*notifiers->device_destroy) (bus_no, dev_no); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1011 | notified = TRUE; |
| 1012 | } |
| 1013 | break; |
| 1014 | } |
| 1015 | } |
| 1016 | if (notified) |
| 1017 | /* The callback function just called above is responsible |
Benjamin Romer | 929aa8a | 2014-10-31 09:57:33 -0400 | [diff] [blame] | 1018 | * for calling the appropriate visorchipset_busdev_responders |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1019 | * function, which will call device_responder() |
| 1020 | */ |
| 1021 | ; |
| 1022 | else |
Benjamin Romer | 2836c6a | 2015-03-16 13:58:17 -0400 | [diff] [blame] | 1023 | device_responder(cmd, bus_no, dev_no, response); |
Benjamin Romer | 8f1947a | 2015-03-16 13:57:59 -0400 | [diff] [blame] | 1024 | up(¬ifier_lock); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | static void |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1028 | bus_create(struct controlvm_message *inmsg) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1029 | { |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1030 | struct controlvm_message_packet *cmd = &inmsg->cmd; |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1031 | ulong bus_no = cmd->create_bus.bus_no; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1032 | int rc = CONTROLVM_RESP_SUCCESS; |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1033 | struct visorchipset_bus_info *bus_info = NULL; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1034 | |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1035 | bus_info = findbus(&bus_info_list, bus_no); |
| 1036 | if (bus_info && (bus_info->state.created == 1)) { |
| 1037 | POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus_no, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1038 | POSTCODE_SEVERITY_ERR); |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1039 | rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE; |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1040 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1041 | } |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1042 | bus_info = kzalloc(sizeof(*bus_info), GFP_KERNEL); |
| 1043 | if (!bus_info) { |
| 1044 | POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus_no, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1045 | POSTCODE_SEVERITY_ERR); |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1046 | rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED; |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1047 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1048 | } |
| 1049 | |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1050 | INIT_LIST_HEAD(&bus_info->entry); |
| 1051 | bus_info->bus_no = bus_no; |
| 1052 | bus_info->dev_no = cmd->create_bus.dev_count; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1053 | |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1054 | POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC, bus_no, POSTCODE_SEVERITY_INFO); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1055 | |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 1056 | if (inmsg->hdr.flags.test_message == 1) |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1057 | bus_info->chan_info.addr_type = ADDRTYPE_LOCALTEST; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1058 | else |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1059 | bus_info->chan_info.addr_type = ADDRTYPE_LOCALPHYSICAL; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1060 | |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1061 | bus_info->flags.server = inmsg->hdr.flags.server; |
| 1062 | bus_info->chan_info.channel_addr = cmd->create_bus.channel_addr; |
| 1063 | bus_info->chan_info.n_channel_bytes = cmd->create_bus.channel_bytes; |
| 1064 | bus_info->chan_info.channel_type_uuid = |
Benjamin Romer | 9b1caee | 2014-10-31 09:57:23 -0400 | [diff] [blame] | 1065 | cmd->create_bus.bus_data_type_uuid; |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1066 | bus_info->chan_info.channel_inst_uuid = cmd->create_bus.bus_inst_uuid; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1067 | |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1068 | list_add(&bus_info->entry, &bus_info_list); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1069 | |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1070 | POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, bus_no, POSTCODE_SEVERITY_INFO); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1071 | |
Benjamin Romer | 6c5fed3 | 2015-03-16 13:58:20 -0400 | [diff] [blame] | 1072 | cleanup: |
| 1073 | bus_epilog(bus_no, CONTROLVM_BUS_CREATE, &inmsg->hdr, |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 1074 | rc, inmsg->hdr.flags.response_expected == 1); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | static void |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1078 | bus_destroy(struct controlvm_message *inmsg) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1079 | { |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1080 | struct controlvm_message_packet *cmd = &inmsg->cmd; |
Benjamin Romer | dff54cd | 2015-03-16 13:58:21 -0400 | [diff] [blame] | 1081 | ulong bus_no = cmd->destroy_bus.bus_no; |
| 1082 | struct visorchipset_bus_info *bus_info; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1083 | int rc = CONTROLVM_RESP_SUCCESS; |
| 1084 | |
Benjamin Romer | dff54cd | 2015-03-16 13:58:21 -0400 | [diff] [blame] | 1085 | bus_info = findbus(&bus_info_list, bus_no); |
| 1086 | if (!bus_info) |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1087 | rc = -CONTROLVM_RESP_ERROR_BUS_INVALID; |
Benjamin Romer | dff54cd | 2015-03-16 13:58:21 -0400 | [diff] [blame] | 1088 | else if (bus_info->state.created == 0) |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1089 | rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1090 | |
Benjamin Romer | dff54cd | 2015-03-16 13:58:21 -0400 | [diff] [blame] | 1091 | bus_epilog(bus_no, CONTROLVM_BUS_DESTROY, &inmsg->hdr, |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 1092 | rc, inmsg->hdr.flags.response_expected == 1); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | static void |
Benjamin Romer | 317d961 | 2015-03-16 13:57:51 -0400 | [diff] [blame] | 1096 | bus_configure(struct controlvm_message *inmsg, |
| 1097 | struct parser_context *parser_ctx) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1098 | { |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1099 | struct controlvm_message_packet *cmd = &inmsg->cmd; |
Benjamin Romer | 654bada | 2015-03-16 13:58:22 -0400 | [diff] [blame] | 1100 | ulong bus_no = cmd->configure_bus.bus_no; |
| 1101 | struct visorchipset_bus_info *bus_info = NULL; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1102 | int rc = CONTROLVM_RESP_SUCCESS; |
| 1103 | char s[99]; |
| 1104 | |
Benjamin Romer | 654bada | 2015-03-16 13:58:22 -0400 | [diff] [blame] | 1105 | bus_no = cmd->configure_bus.bus_no; |
| 1106 | POSTCODE_LINUX_3(BUS_CONFIGURE_ENTRY_PC, bus_no, |
| 1107 | POSTCODE_SEVERITY_INFO); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1108 | |
Benjamin Romer | 654bada | 2015-03-16 13:58:22 -0400 | [diff] [blame] | 1109 | bus_info = findbus(&bus_info_list, bus_no); |
| 1110 | if (!bus_info) { |
| 1111 | POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, bus_no, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1112 | POSTCODE_SEVERITY_ERR); |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1113 | rc = -CONTROLVM_RESP_ERROR_BUS_INVALID; |
Benjamin Romer | 654bada | 2015-03-16 13:58:22 -0400 | [diff] [blame] | 1114 | } else if (bus_info->state.created == 0) { |
| 1115 | POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, bus_no, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1116 | POSTCODE_SEVERITY_ERR); |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1117 | rc = -CONTROLVM_RESP_ERROR_BUS_INVALID; |
Benjamin Romer | 654bada | 2015-03-16 13:58:22 -0400 | [diff] [blame] | 1118 | } else if (bus_info->pending_msg_hdr.id != CONTROLVM_INVALID) { |
| 1119 | POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, bus_no, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1120 | POSTCODE_SEVERITY_ERR); |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1121 | rc = -CONTROLVM_RESP_ERROR_MESSAGE_ID_INVALID_FOR_CLIENT; |
Benjamin Romer | 654bada | 2015-03-16 13:58:22 -0400 | [diff] [blame] | 1122 | } else { |
| 1123 | bus_info->partition_handle = cmd->configure_bus.guest_handle; |
| 1124 | bus_info->partition_uuid = parser_id_get(parser_ctx); |
| 1125 | parser_param_start(parser_ctx, PARSERSTRING_NAME); |
| 1126 | bus_info->name = parser_string_get(parser_ctx); |
| 1127 | |
| 1128 | visorchannel_uuid_id(&bus_info->partition_uuid, s); |
| 1129 | POSTCODE_LINUX_3(BUS_CONFIGURE_EXIT_PC, bus_no, |
| 1130 | POSTCODE_SEVERITY_INFO); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1131 | } |
Benjamin Romer | 654bada | 2015-03-16 13:58:22 -0400 | [diff] [blame] | 1132 | bus_epilog(bus_no, CONTROLVM_BUS_CONFIGURE, &inmsg->hdr, |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 1133 | rc, inmsg->hdr.flags.response_expected == 1); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | static void |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1137 | my_device_create(struct controlvm_message *inmsg) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1138 | { |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1139 | struct controlvm_message_packet *cmd = &inmsg->cmd; |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1140 | ulong bus_no = cmd->create_device.bus_no; |
| 1141 | ulong dev_no = cmd->create_device.dev_no; |
| 1142 | struct visorchipset_device_info *dev_info = NULL; |
| 1143 | struct visorchipset_bus_info *bus_info = NULL; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1144 | int rc = CONTROLVM_RESP_SUCCESS; |
| 1145 | |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1146 | dev_info = finddevice(&dev_info_list, bus_no, dev_no); |
| 1147 | if (dev_info && (dev_info->state.created == 1)) { |
| 1148 | POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1149 | POSTCODE_SEVERITY_ERR); |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1150 | rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE; |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1151 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1152 | } |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1153 | bus_info = findbus(&bus_info_list, bus_no); |
| 1154 | if (!bus_info) { |
| 1155 | POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1156 | POSTCODE_SEVERITY_ERR); |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1157 | rc = -CONTROLVM_RESP_ERROR_BUS_INVALID; |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1158 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1159 | } |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1160 | if (bus_info->state.created == 0) { |
| 1161 | POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1162 | POSTCODE_SEVERITY_ERR); |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1163 | rc = -CONTROLVM_RESP_ERROR_BUS_INVALID; |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1164 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1165 | } |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1166 | dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL); |
| 1167 | if (!dev_info) { |
| 1168 | POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1169 | POSTCODE_SEVERITY_ERR); |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1170 | rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED; |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1171 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1172 | } |
Andreea-Cristina Bernat | 97a84f1 | 2014-03-14 04:20:06 +0200 | [diff] [blame] | 1173 | |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1174 | INIT_LIST_HEAD(&dev_info->entry); |
| 1175 | dev_info->bus_no = bus_no; |
| 1176 | dev_info->dev_no = dev_no; |
| 1177 | dev_info->dev_inst_uuid = cmd->create_device.dev_inst_uuid; |
| 1178 | POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, dev_no, bus_no, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1179 | POSTCODE_SEVERITY_INFO); |
| 1180 | |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 1181 | if (inmsg->hdr.flags.test_message == 1) |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1182 | dev_info->chan_info.addr_type = ADDRTYPE_LOCALTEST; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1183 | else |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1184 | dev_info->chan_info.addr_type = ADDRTYPE_LOCALPHYSICAL; |
| 1185 | dev_info->chan_info.channel_addr = cmd->create_device.channel_addr; |
| 1186 | dev_info->chan_info.n_channel_bytes = cmd->create_device.channel_bytes; |
| 1187 | dev_info->chan_info.channel_type_uuid = |
Benjamin Romer | 9b1caee | 2014-10-31 09:57:23 -0400 | [diff] [blame] | 1188 | cmd->create_device.data_type_uuid; |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1189 | dev_info->chan_info.intr = cmd->create_device.intr; |
| 1190 | list_add(&dev_info->entry, &dev_info_list); |
| 1191 | POSTCODE_LINUX_4(DEVICE_CREATE_EXIT_PC, dev_no, bus_no, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1192 | POSTCODE_SEVERITY_INFO); |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1193 | cleanup: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1194 | /* get the bus and devNo for DiagPool channel */ |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1195 | if (dev_info && |
| 1196 | is_diagpool_channel(dev_info->chan_info.channel_type_uuid)) { |
| 1197 | g_diagpool_bus_no = bus_no; |
| 1198 | g_diagpool_dev_no = dev_no; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1199 | } |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1200 | device_epilog(bus_no, dev_no, segment_state_running, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1201 | CONTROLVM_DEVICE_CREATE, &inmsg->hdr, rc, |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 1202 | inmsg->hdr.flags.response_expected == 1, |
Benjamin Romer | c60c8e2 | 2015-03-16 13:58:23 -0400 | [diff] [blame] | 1203 | FOR_VISORBUS(dev_info->chan_info.channel_type_uuid)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | static void |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1207 | my_device_changestate(struct controlvm_message *inmsg) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1208 | { |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1209 | struct controlvm_message_packet *cmd = &inmsg->cmd; |
Benjamin Romer | 0278a90 | 2015-03-16 13:58:24 -0400 | [diff] [blame] | 1210 | ulong bus_no = cmd->device_change_state.bus_no; |
| 1211 | ulong dev_no = cmd->device_change_state.dev_no; |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1212 | struct spar_segment_state state = cmd->device_change_state.state; |
Benjamin Romer | 0278a90 | 2015-03-16 13:58:24 -0400 | [diff] [blame] | 1213 | struct visorchipset_device_info *dev_info = NULL; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1214 | int rc = CONTROLVM_RESP_SUCCESS; |
| 1215 | |
Benjamin Romer | 0278a90 | 2015-03-16 13:58:24 -0400 | [diff] [blame] | 1216 | dev_info = finddevice(&dev_info_list, bus_no, dev_no); |
| 1217 | if (!dev_info) { |
| 1218 | POSTCODE_LINUX_4(DEVICE_CHANGESTATE_FAILURE_PC, dev_no, bus_no, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1219 | POSTCODE_SEVERITY_ERR); |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1220 | rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID; |
Benjamin Romer | 0278a90 | 2015-03-16 13:58:24 -0400 | [diff] [blame] | 1221 | } else if (dev_info->state.created == 0) { |
| 1222 | POSTCODE_LINUX_4(DEVICE_CHANGESTATE_FAILURE_PC, dev_no, bus_no, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1223 | POSTCODE_SEVERITY_ERR); |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1224 | rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1225 | } |
Benjamin Romer | 0278a90 | 2015-03-16 13:58:24 -0400 | [diff] [blame] | 1226 | if ((rc >= CONTROLVM_RESP_SUCCESS) && dev_info) |
| 1227 | device_epilog(bus_no, dev_no, state, |
| 1228 | CONTROLVM_DEVICE_CHANGESTATE, &inmsg->hdr, rc, |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 1229 | inmsg->hdr.flags.response_expected == 1, |
Benjamin Romer | 9b1caee | 2014-10-31 09:57:23 -0400 | [diff] [blame] | 1230 | FOR_VISORBUS( |
Benjamin Romer | 0278a90 | 2015-03-16 13:58:24 -0400 | [diff] [blame] | 1231 | dev_info->chan_info.channel_type_uuid)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | static void |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1235 | my_device_destroy(struct controlvm_message *inmsg) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1236 | { |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1237 | struct controlvm_message_packet *cmd = &inmsg->cmd; |
Benjamin Romer | 61715c8 | 2015-03-16 13:58:25 -0400 | [diff] [blame] | 1238 | ulong bus_no = cmd->destroy_device.bus_no; |
| 1239 | ulong dev_no = cmd->destroy_device.dev_no; |
| 1240 | struct visorchipset_device_info *dev_info = NULL; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1241 | int rc = CONTROLVM_RESP_SUCCESS; |
| 1242 | |
Benjamin Romer | 61715c8 | 2015-03-16 13:58:25 -0400 | [diff] [blame] | 1243 | dev_info = finddevice(&dev_info_list, bus_no, dev_no); |
| 1244 | if (!dev_info) |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1245 | rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID; |
Benjamin Romer | 61715c8 | 2015-03-16 13:58:25 -0400 | [diff] [blame] | 1246 | else if (dev_info->state.created == 0) |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1247 | rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1248 | |
Benjamin Romer | 61715c8 | 2015-03-16 13:58:25 -0400 | [diff] [blame] | 1249 | if ((rc >= CONTROLVM_RESP_SUCCESS) && dev_info) |
| 1250 | device_epilog(bus_no, dev_no, segment_state_running, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1251 | CONTROLVM_DEVICE_DESTROY, &inmsg->hdr, rc, |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 1252 | inmsg->hdr.flags.response_expected == 1, |
Benjamin Romer | 9b1caee | 2014-10-31 09:57:23 -0400 | [diff] [blame] | 1253 | FOR_VISORBUS( |
Benjamin Romer | 61715c8 | 2015-03-16 13:58:25 -0400 | [diff] [blame] | 1254 | dev_info->chan_info.channel_type_uuid)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | /* When provided with the physical address of the controlvm channel |
| 1258 | * (phys_addr), the offset to the payload area we need to manage |
| 1259 | * (offset), and the size of this payload area (bytes), fills in the |
Frederico Cadete | 84b11df | 2015-02-18 19:53:40 +0100 | [diff] [blame] | 1260 | * controlvm_payload_info struct. Returns TRUE for success or FALSE |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1261 | * for failure. |
| 1262 | */ |
| 1263 | static int |
Benjamin Romer | 5fc0229 | 2014-07-31 12:00:51 -0400 | [diff] [blame] | 1264 | initialize_controlvm_payload_info(HOSTADDRESS phys_addr, u64 offset, u32 bytes, |
Frederico Cadete | 84b11df | 2015-02-18 19:53:40 +0100 | [diff] [blame] | 1265 | struct controlvm_payload_info *info) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1266 | { |
Benjamin Romer | c242233 | 2014-07-29 15:09:40 -0400 | [diff] [blame] | 1267 | u8 __iomem *payload = NULL; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1268 | int rc = CONTROLVM_RESP_SUCCESS; |
| 1269 | |
Benjamin Romer | 38f736e | 2015-03-16 13:58:13 -0400 | [diff] [blame] | 1270 | if (!info) { |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1271 | rc = -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID; |
Benjamin Romer | f118a39 | 2015-03-16 13:58:26 -0400 | [diff] [blame] | 1272 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1273 | } |
Frederico Cadete | 84b11df | 2015-02-18 19:53:40 +0100 | [diff] [blame] | 1274 | memset(info, 0, sizeof(struct controlvm_payload_info)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1275 | if ((offset == 0) || (bytes == 0)) { |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1276 | rc = -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID; |
Benjamin Romer | f118a39 | 2015-03-16 13:58:26 -0400 | [diff] [blame] | 1277 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1278 | } |
| 1279 | payload = ioremap_cache(phys_addr + offset, bytes); |
Benjamin Romer | 38f736e | 2015-03-16 13:58:13 -0400 | [diff] [blame] | 1280 | if (!payload) { |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 1281 | rc = -CONTROLVM_RESP_ERROR_IOREMAP_FAILED; |
Benjamin Romer | f118a39 | 2015-03-16 13:58:26 -0400 | [diff] [blame] | 1282 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | info->offset = offset; |
| 1286 | info->bytes = bytes; |
| 1287 | info->ptr = payload; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1288 | |
Benjamin Romer | f118a39 | 2015-03-16 13:58:26 -0400 | [diff] [blame] | 1289 | cleanup: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1290 | if (rc < 0) { |
Benjamin Romer | f118a39 | 2015-03-16 13:58:26 -0400 | [diff] [blame] | 1291 | if (payload) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1292 | iounmap(payload); |
| 1293 | payload = NULL; |
| 1294 | } |
| 1295 | } |
| 1296 | return rc; |
| 1297 | } |
| 1298 | |
| 1299 | static void |
Frederico Cadete | 84b11df | 2015-02-18 19:53:40 +0100 | [diff] [blame] | 1300 | destroy_controlvm_payload_info(struct controlvm_payload_info *info) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1301 | { |
Benjamin Romer | 597c338 | 2015-03-16 13:58:27 -0400 | [diff] [blame] | 1302 | if (info->ptr) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1303 | iounmap(info->ptr); |
| 1304 | info->ptr = NULL; |
| 1305 | } |
Frederico Cadete | 84b11df | 2015-02-18 19:53:40 +0100 | [diff] [blame] | 1306 | memset(info, 0, sizeof(struct controlvm_payload_info)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | static void |
| 1310 | initialize_controlvm_payload(void) |
| 1311 | { |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 1312 | HOSTADDRESS phys_addr = visorchannel_get_physaddr(controlvm_channel); |
Benjamin Romer | cafefc0 | 2015-03-16 13:58:28 -0400 | [diff] [blame] | 1313 | u64 payload_offset = 0; |
| 1314 | u32 payload_bytes = 0; |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 1315 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 1316 | if (visorchannel_read(controlvm_channel, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 1317 | offsetof(struct spar_controlvm_channel_protocol, |
| 1318 | request_payload_offset), |
Benjamin Romer | cafefc0 | 2015-03-16 13:58:28 -0400 | [diff] [blame] | 1319 | &payload_offset, sizeof(payload_offset)) < 0) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1320 | POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC, |
| 1321 | POSTCODE_SEVERITY_ERR); |
| 1322 | return; |
| 1323 | } |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 1324 | if (visorchannel_read(controlvm_channel, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 1325 | offsetof(struct spar_controlvm_channel_protocol, |
| 1326 | request_payload_bytes), |
Benjamin Romer | cafefc0 | 2015-03-16 13:58:28 -0400 | [diff] [blame] | 1327 | &payload_bytes, sizeof(payload_bytes)) < 0) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1328 | POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC, |
| 1329 | POSTCODE_SEVERITY_ERR); |
| 1330 | return; |
| 1331 | } |
| 1332 | initialize_controlvm_payload_info(phys_addr, |
Benjamin Romer | cafefc0 | 2015-03-16 13:58:28 -0400 | [diff] [blame] | 1333 | payload_offset, payload_bytes, |
Benjamin Romer | 84982fb | 2015-03-16 13:58:07 -0400 | [diff] [blame] | 1334 | &controlvm_payload_info); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | /* Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset. |
| 1338 | * Returns CONTROLVM_RESP_xxx code. |
| 1339 | */ |
| 1340 | int |
| 1341 | visorchipset_chipset_ready(void) |
| 1342 | { |
Benjamin Romer | eb34e87 | 2015-03-16 13:58:45 -0400 | [diff] [blame] | 1343 | kobject_uevent(&visorchipset_platform_device.dev.kobj, KOBJ_ONLINE); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1344 | return CONTROLVM_RESP_SUCCESS; |
| 1345 | } |
| 1346 | EXPORT_SYMBOL_GPL(visorchipset_chipset_ready); |
| 1347 | |
| 1348 | int |
| 1349 | visorchipset_chipset_selftest(void) |
| 1350 | { |
| 1351 | char env_selftest[20]; |
| 1352 | char *envp[] = { env_selftest, NULL }; |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 1353 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1354 | sprintf(env_selftest, "SPARSP_SELFTEST=%d", 1); |
Benjamin Romer | eb34e87 | 2015-03-16 13:58:45 -0400 | [diff] [blame] | 1355 | kobject_uevent_env(&visorchipset_platform_device.dev.kobj, KOBJ_CHANGE, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1356 | envp); |
| 1357 | return CONTROLVM_RESP_SUCCESS; |
| 1358 | } |
| 1359 | EXPORT_SYMBOL_GPL(visorchipset_chipset_selftest); |
| 1360 | |
| 1361 | /* Send ACTION=offline for DEVPATH=/sys/devices/platform/visorchipset. |
| 1362 | * Returns CONTROLVM_RESP_xxx code. |
| 1363 | */ |
| 1364 | int |
| 1365 | visorchipset_chipset_notready(void) |
| 1366 | { |
Benjamin Romer | eb34e87 | 2015-03-16 13:58:45 -0400 | [diff] [blame] | 1367 | kobject_uevent(&visorchipset_platform_device.dev.kobj, KOBJ_OFFLINE); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1368 | return CONTROLVM_RESP_SUCCESS; |
| 1369 | } |
| 1370 | EXPORT_SYMBOL_GPL(visorchipset_chipset_notready); |
| 1371 | |
| 1372 | static void |
Benjamin Romer | 77a0449 | 2015-03-16 13:58:47 -0400 | [diff] [blame] | 1373 | chipset_ready(struct controlvm_message_header *msg_hdr) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1374 | { |
| 1375 | int rc = visorchipset_chipset_ready(); |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 1376 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1377 | if (rc != CONTROLVM_RESP_SUCCESS) |
| 1378 | rc = -rc; |
Benjamin Romer | 77a0449 | 2015-03-16 13:58:47 -0400 | [diff] [blame] | 1379 | if (msg_hdr->flags.response_expected && !visorchipset_holdchipsetready) |
| 1380 | controlvm_respond(msg_hdr, rc); |
| 1381 | if (msg_hdr->flags.response_expected && visorchipset_holdchipsetready) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1382 | /* Send CHIPSET_READY response when all modules have been loaded |
| 1383 | * and disks mounted for the partition |
| 1384 | */ |
Benjamin Romer | 77a0449 | 2015-03-16 13:58:47 -0400 | [diff] [blame] | 1385 | g_chipset_msg_hdr = *msg_hdr; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | static void |
Benjamin Romer | 77a0449 | 2015-03-16 13:58:47 -0400 | [diff] [blame] | 1390 | chipset_selftest(struct controlvm_message_header *msg_hdr) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1391 | { |
| 1392 | int rc = visorchipset_chipset_selftest(); |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 1393 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1394 | if (rc != CONTROLVM_RESP_SUCCESS) |
| 1395 | rc = -rc; |
Benjamin Romer | 77a0449 | 2015-03-16 13:58:47 -0400 | [diff] [blame] | 1396 | if (msg_hdr->flags.response_expected) |
| 1397 | controlvm_respond(msg_hdr, rc); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | static void |
Benjamin Romer | 77a0449 | 2015-03-16 13:58:47 -0400 | [diff] [blame] | 1401 | chipset_notready(struct controlvm_message_header *msg_hdr) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1402 | { |
| 1403 | int rc = visorchipset_chipset_notready(); |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 1404 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1405 | if (rc != CONTROLVM_RESP_SUCCESS) |
| 1406 | rc = -rc; |
Benjamin Romer | 77a0449 | 2015-03-16 13:58:47 -0400 | [diff] [blame] | 1407 | if (msg_hdr->flags.response_expected) |
| 1408 | controlvm_respond(msg_hdr, rc); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | /* This is your "one-stop" shop for grabbing the next message from the |
| 1412 | * CONTROLVM_QUEUE_EVENT queue in the controlvm channel. |
| 1413 | */ |
| 1414 | static BOOL |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1415 | read_controlvm_event(struct controlvm_message *msg) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1416 | { |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 1417 | if (visorchannel_signalremove(controlvm_channel, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1418 | CONTROLVM_QUEUE_EVENT, msg)) { |
| 1419 | /* got a message */ |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 1420 | if (msg->hdr.flags.test_message == 1) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1421 | return FALSE; |
Benjamin Romer | e22a4a0 | 2014-08-18 09:34:54 -0400 | [diff] [blame] | 1422 | return TRUE; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1423 | } |
| 1424 | return FALSE; |
| 1425 | } |
| 1426 | |
| 1427 | /* |
| 1428 | * The general parahotplug flow works as follows. The visorchipset |
| 1429 | * driver receives a DEVICE_CHANGESTATE message from Command |
| 1430 | * specifying a physical device to enable or disable. The CONTROLVM |
| 1431 | * message handler calls parahotplug_process_message, which then adds |
| 1432 | * the message to a global list and kicks off a udev event which |
| 1433 | * causes a user level script to enable or disable the specified |
| 1434 | * device. The udev script then writes to |
| 1435 | * /proc/visorchipset/parahotplug, which causes parahotplug_proc_write |
| 1436 | * to get called, at which point the appropriate CONTROLVM message is |
| 1437 | * retrieved from the list and responded to. |
| 1438 | */ |
| 1439 | |
| 1440 | #define PARAHOTPLUG_TIMEOUT_MS 2000 |
| 1441 | |
| 1442 | /* |
| 1443 | * Generate unique int to match an outstanding CONTROLVM message with a |
| 1444 | * udev script /proc response |
| 1445 | */ |
| 1446 | static int |
| 1447 | parahotplug_next_id(void) |
| 1448 | { |
| 1449 | static atomic_t id = ATOMIC_INIT(0); |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 1450 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1451 | return atomic_inc_return(&id); |
| 1452 | } |
| 1453 | |
| 1454 | /* |
| 1455 | * Returns the time (in jiffies) when a CONTROLVM message on the list |
| 1456 | * should expire -- PARAHOTPLUG_TIMEOUT_MS in the future |
| 1457 | */ |
| 1458 | static unsigned long |
| 1459 | parahotplug_next_expiration(void) |
| 1460 | { |
Nicholas Mc Guire | 2cc1a1b | 2015-01-31 12:02:08 +0100 | [diff] [blame] | 1461 | return jiffies + msecs_to_jiffies(PARAHOTPLUG_TIMEOUT_MS); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | /* |
| 1465 | * Create a parahotplug_request, which is basically a wrapper for a |
| 1466 | * CONTROLVM_MESSAGE that we can stick on a list |
| 1467 | */ |
| 1468 | static struct parahotplug_request * |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1469 | parahotplug_request_create(struct controlvm_message *msg) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1470 | { |
Quentin Lambert | ea0dcfc | 2015-02-10 15:12:07 +0100 | [diff] [blame] | 1471 | struct parahotplug_request *req; |
| 1472 | |
Benjamin Romer | 6a55e3c | 2015-03-16 13:58:30 -0400 | [diff] [blame] | 1473 | req = kmalloc(sizeof(*req), GFP_KERNEL | __GFP_NORETRY); |
Benjamin Romer | 38f736e | 2015-03-16 13:58:13 -0400 | [diff] [blame] | 1474 | if (!req) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1475 | return NULL; |
| 1476 | |
| 1477 | req->id = parahotplug_next_id(); |
| 1478 | req->expiration = parahotplug_next_expiration(); |
| 1479 | req->msg = *msg; |
| 1480 | |
| 1481 | return req; |
| 1482 | } |
| 1483 | |
| 1484 | /* |
| 1485 | * Free a parahotplug_request. |
| 1486 | */ |
| 1487 | static void |
| 1488 | parahotplug_request_destroy(struct parahotplug_request *req) |
| 1489 | { |
| 1490 | kfree(req); |
| 1491 | } |
| 1492 | |
| 1493 | /* |
| 1494 | * Cause uevent to run the user level script to do the disable/enable |
| 1495 | * specified in (the CONTROLVM message in) the specified |
| 1496 | * parahotplug_request |
| 1497 | */ |
| 1498 | static void |
| 1499 | parahotplug_request_kickoff(struct parahotplug_request *req) |
| 1500 | { |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1501 | struct controlvm_message_packet *cmd = &req->msg.cmd; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1502 | char env_cmd[40], env_id[40], env_state[40], env_bus[40], env_dev[40], |
| 1503 | env_func[40]; |
| 1504 | char *envp[] = { |
| 1505 | env_cmd, env_id, env_state, env_bus, env_dev, env_func, NULL |
| 1506 | }; |
| 1507 | |
| 1508 | sprintf(env_cmd, "SPAR_PARAHOTPLUG=1"); |
| 1509 | sprintf(env_id, "SPAR_PARAHOTPLUG_ID=%d", req->id); |
| 1510 | sprintf(env_state, "SPAR_PARAHOTPLUG_STATE=%d", |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1511 | cmd->device_change_state.state.active); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1512 | sprintf(env_bus, "SPAR_PARAHOTPLUG_BUS=%d", |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1513 | cmd->device_change_state.bus_no); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1514 | sprintf(env_dev, "SPAR_PARAHOTPLUG_DEVICE=%d", |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1515 | cmd->device_change_state.dev_no >> 3); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1516 | sprintf(env_func, "SPAR_PARAHOTPLUG_FUNCTION=%d", |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1517 | cmd->device_change_state.dev_no & 0x7); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1518 | |
Benjamin Romer | eb34e87 | 2015-03-16 13:58:45 -0400 | [diff] [blame] | 1519 | kobject_uevent_env(&visorchipset_platform_device.dev.kobj, KOBJ_CHANGE, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1520 | envp); |
| 1521 | } |
| 1522 | |
| 1523 | /* |
| 1524 | * Remove any request from the list that's been on there too long and |
| 1525 | * respond with an error. |
| 1526 | */ |
| 1527 | static void |
| 1528 | parahotplug_process_list(void) |
| 1529 | { |
| 1530 | struct list_head *pos = NULL; |
| 1531 | struct list_head *tmp = NULL; |
| 1532 | |
Benjamin Romer | ddf5de5 | 2015-03-16 13:58:41 -0400 | [diff] [blame] | 1533 | spin_lock(¶hotplug_request_list_lock); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1534 | |
Benjamin Romer | ddf5de5 | 2015-03-16 13:58:41 -0400 | [diff] [blame] | 1535 | list_for_each_safe(pos, tmp, ¶hotplug_request_list) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1536 | struct parahotplug_request *req = |
| 1537 | list_entry(pos, struct parahotplug_request, list); |
Benjamin Romer | 55b3341 | 2015-03-16 13:58:29 -0400 | [diff] [blame] | 1538 | |
| 1539 | if (!time_after_eq(jiffies, req->expiration)) |
| 1540 | continue; |
| 1541 | |
| 1542 | list_del(pos); |
| 1543 | if (req->msg.hdr.flags.response_expected) |
| 1544 | controlvm_respond_physdev_changestate( |
| 1545 | &req->msg.hdr, |
| 1546 | CONTROLVM_RESP_ERROR_DEVICE_UDEV_TIMEOUT, |
| 1547 | req->msg.cmd.device_change_state.state); |
| 1548 | parahotplug_request_destroy(req); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1549 | } |
| 1550 | |
Benjamin Romer | ddf5de5 | 2015-03-16 13:58:41 -0400 | [diff] [blame] | 1551 | spin_unlock(¶hotplug_request_list_lock); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | /* |
| 1555 | * Called from the /proc handler, which means the user script has |
| 1556 | * finished the enable/disable. Find the matching identifier, and |
| 1557 | * respond to the CONTROLVM message with success. |
| 1558 | */ |
| 1559 | static int |
Benjamin Romer | b06bdf7 | 2014-07-31 12:00:49 -0400 | [diff] [blame] | 1560 | parahotplug_request_complete(int id, u16 active) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1561 | { |
| 1562 | struct list_head *pos = NULL; |
| 1563 | struct list_head *tmp = NULL; |
| 1564 | |
Benjamin Romer | ddf5de5 | 2015-03-16 13:58:41 -0400 | [diff] [blame] | 1565 | spin_lock(¶hotplug_request_list_lock); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1566 | |
| 1567 | /* Look for a request matching "id". */ |
Benjamin Romer | ddf5de5 | 2015-03-16 13:58:41 -0400 | [diff] [blame] | 1568 | list_for_each_safe(pos, tmp, ¶hotplug_request_list) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1569 | struct parahotplug_request *req = |
| 1570 | list_entry(pos, struct parahotplug_request, list); |
| 1571 | if (req->id == id) { |
| 1572 | /* Found a match. Remove it from the list and |
| 1573 | * respond. |
| 1574 | */ |
| 1575 | list_del(pos); |
Benjamin Romer | ddf5de5 | 2015-03-16 13:58:41 -0400 | [diff] [blame] | 1576 | spin_unlock(¶hotplug_request_list_lock); |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1577 | req->msg.cmd.device_change_state.state.active = active; |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 1578 | if (req->msg.hdr.flags.response_expected) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1579 | controlvm_respond_physdev_changestate( |
| 1580 | &req->msg.hdr, CONTROLVM_RESP_SUCCESS, |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1581 | req->msg.cmd.device_change_state.state); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1582 | parahotplug_request_destroy(req); |
| 1583 | return 0; |
| 1584 | } |
| 1585 | } |
| 1586 | |
Benjamin Romer | ddf5de5 | 2015-03-16 13:58:41 -0400 | [diff] [blame] | 1587 | spin_unlock(¶hotplug_request_list_lock); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1588 | return -1; |
| 1589 | } |
| 1590 | |
| 1591 | /* |
| 1592 | * Enables or disables a PCI device by kicking off a udev script |
| 1593 | */ |
Ken Cox | bd5b9b3 | 2014-03-13 15:39:22 -0500 | [diff] [blame] | 1594 | static void |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1595 | parahotplug_process_message(struct controlvm_message *inmsg) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1596 | { |
| 1597 | struct parahotplug_request *req; |
| 1598 | |
| 1599 | req = parahotplug_request_create(inmsg); |
| 1600 | |
Benjamin Romer | 38f736e | 2015-03-16 13:58:13 -0400 | [diff] [blame] | 1601 | if (!req) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1602 | return; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1603 | |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1604 | if (inmsg->cmd.device_change_state.state.active) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1605 | /* For enable messages, just respond with success |
| 1606 | * right away. This is a bit of a hack, but there are |
| 1607 | * issues with the early enable messages we get (with |
| 1608 | * either the udev script not detecting that the device |
| 1609 | * is up, or not getting called at all). Fortunately |
| 1610 | * the messages that get lost don't matter anyway, as |
| 1611 | * devices are automatically enabled at |
| 1612 | * initialization. |
| 1613 | */ |
| 1614 | parahotplug_request_kickoff(req); |
| 1615 | controlvm_respond_physdev_changestate(&inmsg->hdr, |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1616 | CONTROLVM_RESP_SUCCESS, inmsg->cmd. |
| 1617 | device_change_state.state); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1618 | parahotplug_request_destroy(req); |
| 1619 | } else { |
| 1620 | /* For disable messages, add the request to the |
| 1621 | * request list before kicking off the udev script. It |
| 1622 | * won't get responded to until the script has |
| 1623 | * indicated it's done. |
| 1624 | */ |
Benjamin Romer | ddf5de5 | 2015-03-16 13:58:41 -0400 | [diff] [blame] | 1625 | spin_lock(¶hotplug_request_list_lock); |
| 1626 | list_add_tail(&req->list, ¶hotplug_request_list); |
| 1627 | spin_unlock(¶hotplug_request_list_lock); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1628 | |
| 1629 | parahotplug_request_kickoff(req); |
| 1630 | } |
| 1631 | } |
| 1632 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1633 | /* Process a controlvm message. |
| 1634 | * Return result: |
| 1635 | * FALSE - this function will return FALSE only in the case where the |
| 1636 | * controlvm message was NOT processed, but processing must be |
| 1637 | * retried before reading the next controlvm message; a |
| 1638 | * scenario where this can occur is when we need to throttle |
| 1639 | * the allocation of memory in which to copy out controlvm |
| 1640 | * payload data |
| 1641 | * TRUE - processing of the controlvm message completed, |
| 1642 | * either successfully or with an error. |
| 1643 | */ |
| 1644 | static BOOL |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1645 | handle_command(struct controlvm_message inmsg, HOSTADDRESS channel_addr) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1646 | { |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1647 | struct controlvm_message_packet *cmd = &inmsg.cmd; |
Benjamin Romer | 818352a | 2015-03-16 13:58:31 -0400 | [diff] [blame] | 1648 | u64 parm_addr = 0; |
| 1649 | u32 parm_bytes = 0; |
Benjamin Romer | 317d961 | 2015-03-16 13:57:51 -0400 | [diff] [blame] | 1650 | struct parser_context *parser_ctx = NULL; |
Benjamin Romer | 818352a | 2015-03-16 13:58:31 -0400 | [diff] [blame] | 1651 | bool local_addr = false; |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1652 | struct controlvm_message ackmsg; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1653 | |
| 1654 | /* create parsing context if necessary */ |
Benjamin Romer | 818352a | 2015-03-16 13:58:31 -0400 | [diff] [blame] | 1655 | local_addr = (inmsg.hdr.flags.test_message == 1); |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 1656 | if (channel_addr == 0) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1657 | return TRUE; |
Benjamin Romer | 818352a | 2015-03-16 13:58:31 -0400 | [diff] [blame] | 1658 | parm_addr = channel_addr + inmsg.hdr.payload_vm_offset; |
| 1659 | parm_bytes = inmsg.hdr.payload_bytes; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1660 | |
| 1661 | /* Parameter and channel addresses within test messages actually lie |
| 1662 | * within our OS-controlled memory. We need to know that, because it |
| 1663 | * makes a difference in how we compute the virtual address. |
| 1664 | */ |
Benjamin Romer | 818352a | 2015-03-16 13:58:31 -0400 | [diff] [blame] | 1665 | if (parm_addr != 0 && parm_bytes != 0) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1666 | BOOL retry = FALSE; |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 1667 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1668 | parser_ctx = |
Benjamin Romer | 818352a | 2015-03-16 13:58:31 -0400 | [diff] [blame] | 1669 | parser_init_byte_stream(parm_addr, parm_bytes, |
| 1670 | local_addr, &retry); |
Benjamin Romer | 1b08872 | 2015-03-04 12:14:26 -0500 | [diff] [blame] | 1671 | if (!parser_ctx && retry) |
| 1672 | return FALSE; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1673 | } |
| 1674 | |
Benjamin Romer | 818352a | 2015-03-16 13:58:31 -0400 | [diff] [blame] | 1675 | if (!local_addr) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1676 | controlvm_init_response(&ackmsg, &inmsg.hdr, |
| 1677 | CONTROLVM_RESP_SUCCESS); |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 1678 | if (controlvm_channel) |
| 1679 | visorchannel_signalinsert(controlvm_channel, |
Benjamin Romer | 1b08872 | 2015-03-04 12:14:26 -0500 | [diff] [blame] | 1680 | CONTROLVM_QUEUE_ACK, |
| 1681 | &ackmsg); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1682 | } |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 1683 | switch (inmsg.hdr.id) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1684 | case CONTROLVM_CHIPSET_INIT: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1685 | chipset_init(&inmsg); |
| 1686 | break; |
| 1687 | case CONTROLVM_BUS_CREATE: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1688 | bus_create(&inmsg); |
| 1689 | break; |
| 1690 | case CONTROLVM_BUS_DESTROY: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1691 | bus_destroy(&inmsg); |
| 1692 | break; |
| 1693 | case CONTROLVM_BUS_CONFIGURE: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1694 | bus_configure(&inmsg, parser_ctx); |
| 1695 | break; |
| 1696 | case CONTROLVM_DEVICE_CREATE: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1697 | my_device_create(&inmsg); |
| 1698 | break; |
| 1699 | case CONTROLVM_DEVICE_CHANGESTATE: |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1700 | if (cmd->device_change_state.flags.phys_device) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1701 | parahotplug_process_message(&inmsg); |
| 1702 | } else { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1703 | /* save the hdr and cmd structures for later use */ |
| 1704 | /* when sending back the response to Command */ |
| 1705 | my_device_changestate(&inmsg); |
Benjamin Romer | da021f0 | 2015-03-16 13:57:58 -0400 | [diff] [blame] | 1706 | g_diag_msg_hdr = inmsg.hdr; |
Benjamin Romer | 4f44b72 | 2015-03-16 13:58:02 -0400 | [diff] [blame] | 1707 | g_devicechangestate_packet = inmsg.cmd; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1708 | break; |
| 1709 | } |
| 1710 | break; |
| 1711 | case CONTROLVM_DEVICE_DESTROY: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1712 | my_device_destroy(&inmsg); |
| 1713 | break; |
| 1714 | case CONTROLVM_DEVICE_CONFIGURE: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1715 | /* no op for now, just send a respond that we passed */ |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 1716 | if (inmsg.hdr.flags.response_expected) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1717 | controlvm_respond(&inmsg.hdr, CONTROLVM_RESP_SUCCESS); |
| 1718 | break; |
| 1719 | case CONTROLVM_CHIPSET_READY: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1720 | chipset_ready(&inmsg.hdr); |
| 1721 | break; |
| 1722 | case CONTROLVM_CHIPSET_SELFTEST: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1723 | chipset_selftest(&inmsg.hdr); |
| 1724 | break; |
| 1725 | case CONTROLVM_CHIPSET_STOP: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1726 | chipset_notready(&inmsg.hdr); |
| 1727 | break; |
| 1728 | default: |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 1729 | if (inmsg.hdr.flags.response_expected) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1730 | controlvm_respond(&inmsg.hdr, |
Benjamin Romer | 818352a | 2015-03-16 13:58:31 -0400 | [diff] [blame] | 1731 | -CONTROLVM_RESP_ERROR_MESSAGE_ID_UNKNOWN); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1732 | break; |
| 1733 | } |
| 1734 | |
Benjamin Romer | 38f736e | 2015-03-16 13:58:13 -0400 | [diff] [blame] | 1735 | if (parser_ctx) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1736 | parser_done(parser_ctx); |
| 1737 | parser_ctx = NULL; |
| 1738 | } |
| 1739 | return TRUE; |
| 1740 | } |
| 1741 | |
Vincent Bernat | d746cb5 | 2014-08-01 10:29:30 +0200 | [diff] [blame] | 1742 | static HOSTADDRESS controlvm_get_channel_address(void) |
Benjamin Romer | 524b0b6 | 2014-07-17 12:39:57 -0400 | [diff] [blame] | 1743 | { |
Benjamin Romer | 5fc0229 | 2014-07-31 12:00:51 -0400 | [diff] [blame] | 1744 | u64 addr = 0; |
Benjamin Romer | b3c55b1 | 2014-07-31 12:00:50 -0400 | [diff] [blame] | 1745 | u32 size = 0; |
Benjamin Romer | 524b0b6 | 2014-07-17 12:39:57 -0400 | [diff] [blame] | 1746 | |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 1747 | if (!VMCALL_SUCCESSFUL(issue_vmcall_io_controlvm_addr(&addr, &size))) |
Benjamin Romer | 524b0b6 | 2014-07-17 12:39:57 -0400 | [diff] [blame] | 1748 | return 0; |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 1749 | |
Benjamin Romer | 524b0b6 | 2014-07-17 12:39:57 -0400 | [diff] [blame] | 1750 | return addr; |
| 1751 | } |
| 1752 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1753 | static void |
| 1754 | controlvm_periodic_work(struct work_struct *work) |
| 1755 | { |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1756 | struct controlvm_message inmsg; |
Benjamin Romer | 1c1ed29 | 2015-03-16 13:58:32 -0400 | [diff] [blame] | 1757 | BOOL got_command = FALSE; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1758 | BOOL handle_command_failed = FALSE; |
Benjamin Romer | 1c1ed29 | 2015-03-16 13:58:32 -0400 | [diff] [blame] | 1759 | static u64 poll_count; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1760 | |
| 1761 | /* make sure visorbus server is registered for controlvm callbacks */ |
| 1762 | if (visorchipset_serverregwait && !serverregistered) |
Benjamin Romer | 1c1ed29 | 2015-03-16 13:58:32 -0400 | [diff] [blame] | 1763 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1764 | /* make sure visorclientbus server is regsitered for controlvm |
| 1765 | * callbacks |
| 1766 | */ |
| 1767 | if (visorchipset_clientregwait && !clientregistered) |
Benjamin Romer | 1c1ed29 | 2015-03-16 13:58:32 -0400 | [diff] [blame] | 1768 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1769 | |
Benjamin Romer | 1c1ed29 | 2015-03-16 13:58:32 -0400 | [diff] [blame] | 1770 | poll_count++; |
| 1771 | if (poll_count >= 250) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1772 | ; /* keep going */ |
| 1773 | else |
Benjamin Romer | 1c1ed29 | 2015-03-16 13:58:32 -0400 | [diff] [blame] | 1774 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1775 | |
| 1776 | /* Check events to determine if response to CHIPSET_READY |
| 1777 | * should be sent |
| 1778 | */ |
Benjamin Romer | 0639ba6 | 2015-03-16 13:58:04 -0400 | [diff] [blame] | 1779 | if (visorchipset_holdchipsetready && |
| 1780 | (g_chipset_msg_hdr.id != CONTROLVM_INVALID)) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1781 | if (check_chipset_events() == 1) { |
Benjamin Romer | da021f0 | 2015-03-16 13:57:58 -0400 | [diff] [blame] | 1782 | controlvm_respond(&g_chipset_msg_hdr, 0); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1783 | clear_chipset_events(); |
Benjamin Romer | da021f0 | 2015-03-16 13:57:58 -0400 | [diff] [blame] | 1784 | memset(&g_chipset_msg_hdr, 0, |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 1785 | sizeof(struct controlvm_message_header)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1786 | } |
| 1787 | } |
| 1788 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 1789 | while (visorchannel_signalremove(controlvm_channel, |
Benjamin Romer | 8a1182e | 2014-07-17 12:39:58 -0400 | [diff] [blame] | 1790 | CONTROLVM_QUEUE_RESPONSE, |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 1791 | &inmsg)) |
| 1792 | ; |
Benjamin Romer | 1c1ed29 | 2015-03-16 13:58:32 -0400 | [diff] [blame] | 1793 | if (!got_command) { |
Benjamin Romer | 7166ed1 | 2015-03-16 13:58:38 -0400 | [diff] [blame] | 1794 | if (controlvm_pending_msg_valid) { |
Benjamin Romer | 8a1182e | 2014-07-17 12:39:58 -0400 | [diff] [blame] | 1795 | /* we throttled processing of a prior |
| 1796 | * msg, so try to process it again |
| 1797 | * rather than reading a new one |
| 1798 | */ |
Benjamin Romer | 7166ed1 | 2015-03-16 13:58:38 -0400 | [diff] [blame] | 1799 | inmsg = controlvm_pending_msg; |
| 1800 | controlvm_pending_msg_valid = FALSE; |
Benjamin Romer | 1c1ed29 | 2015-03-16 13:58:32 -0400 | [diff] [blame] | 1801 | got_command = true; |
Benjamin Romer | 75c1f8b | 2015-03-16 13:58:19 -0400 | [diff] [blame] | 1802 | } else { |
Benjamin Romer | 1c1ed29 | 2015-03-16 13:58:32 -0400 | [diff] [blame] | 1803 | got_command = read_controlvm_event(&inmsg); |
Benjamin Romer | 75c1f8b | 2015-03-16 13:58:19 -0400 | [diff] [blame] | 1804 | } |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | handle_command_failed = FALSE; |
Benjamin Romer | 1c1ed29 | 2015-03-16 13:58:32 -0400 | [diff] [blame] | 1808 | while (got_command && (!handle_command_failed)) { |
Benjamin Romer | b53e0e9 | 2015-03-16 13:57:56 -0400 | [diff] [blame] | 1809 | most_recent_message_jiffies = jiffies; |
Benjamin Romer | 8a1182e | 2014-07-17 12:39:58 -0400 | [diff] [blame] | 1810 | if (handle_command(inmsg, |
| 1811 | visorchannel_get_physaddr |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 1812 | (controlvm_channel))) |
Benjamin Romer | 1c1ed29 | 2015-03-16 13:58:32 -0400 | [diff] [blame] | 1813 | got_command = read_controlvm_event(&inmsg); |
Benjamin Romer | 8a1182e | 2014-07-17 12:39:58 -0400 | [diff] [blame] | 1814 | else { |
| 1815 | /* this is a scenario where throttling |
| 1816 | * is required, but probably NOT an |
| 1817 | * error...; we stash the current |
| 1818 | * controlvm msg so we will attempt to |
| 1819 | * reprocess it on our next loop |
| 1820 | */ |
| 1821 | handle_command_failed = TRUE; |
Benjamin Romer | 7166ed1 | 2015-03-16 13:58:38 -0400 | [diff] [blame] | 1822 | controlvm_pending_msg = inmsg; |
| 1823 | controlvm_pending_msg_valid = TRUE; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1824 | } |
| 1825 | } |
| 1826 | |
| 1827 | /* parahotplug_worker */ |
| 1828 | parahotplug_process_list(); |
| 1829 | |
Benjamin Romer | 1c1ed29 | 2015-03-16 13:58:32 -0400 | [diff] [blame] | 1830 | cleanup: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1831 | |
| 1832 | if (time_after(jiffies, |
Benjamin Romer | b53e0e9 | 2015-03-16 13:57:56 -0400 | [diff] [blame] | 1833 | most_recent_message_jiffies + (HZ * MIN_IDLE_SECONDS))) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1834 | /* it's been longer than MIN_IDLE_SECONDS since we |
| 1835 | * processed our last controlvm message; slow down the |
| 1836 | * polling |
| 1837 | */ |
Benjamin Romer | 911e213 | 2015-03-16 13:57:47 -0400 | [diff] [blame] | 1838 | if (poll_jiffies != POLLJIFFIES_CONTROLVMCHANNEL_SLOW) |
| 1839 | poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_SLOW; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1840 | } else { |
Benjamin Romer | 911e213 | 2015-03-16 13:57:47 -0400 | [diff] [blame] | 1841 | if (poll_jiffies != POLLJIFFIES_CONTROLVMCHANNEL_FAST) |
| 1842 | poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1843 | } |
| 1844 | |
Benjamin Romer | 9232d2d | 2015-03-16 13:57:57 -0400 | [diff] [blame] | 1845 | queue_delayed_work(periodic_controlvm_workqueue, |
| 1846 | &periodic_controlvm_work, poll_jiffies); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | static void |
| 1850 | setup_crash_devices_work_queue(struct work_struct *work) |
| 1851 | { |
Benjamin Romer | e6bdb90 | 2015-03-16 13:58:33 -0400 | [diff] [blame] | 1852 | struct controlvm_message local_crash_bus_msg; |
| 1853 | struct controlvm_message local_crash_dev_msg; |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1854 | struct controlvm_message msg; |
Benjamin Romer | e6bdb90 | 2015-03-16 13:58:33 -0400 | [diff] [blame] | 1855 | u32 local_crash_msg_offset; |
| 1856 | u16 local_crash_msg_count; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1857 | |
| 1858 | /* make sure visorbus server is registered for controlvm callbacks */ |
| 1859 | if (visorchipset_serverregwait && !serverregistered) |
Benjamin Romer | e6bdb90 | 2015-03-16 13:58:33 -0400 | [diff] [blame] | 1860 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1861 | |
| 1862 | /* make sure visorclientbus server is regsitered for controlvm |
| 1863 | * callbacks |
| 1864 | */ |
| 1865 | if (visorchipset_clientregwait && !clientregistered) |
Benjamin Romer | e6bdb90 | 2015-03-16 13:58:33 -0400 | [diff] [blame] | 1866 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1867 | |
| 1868 | POSTCODE_LINUX_2(CRASH_DEV_ENTRY_PC, POSTCODE_SEVERITY_INFO); |
| 1869 | |
| 1870 | /* send init chipset msg */ |
Benjamin Romer | 98d7b59 | 2014-10-23 14:30:26 -0400 | [diff] [blame] | 1871 | msg.hdr.id = CONTROLVM_CHIPSET_INIT; |
Benjamin Romer | 2ea5117 | 2014-10-23 14:30:25 -0400 | [diff] [blame] | 1872 | msg.cmd.init_chipset.bus_count = 23; |
| 1873 | msg.cmd.init_chipset.switch_count = 0; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1874 | |
| 1875 | chipset_init(&msg); |
| 1876 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1877 | /* get saved message count */ |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 1878 | if (visorchannel_read(controlvm_channel, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 1879 | offsetof(struct spar_controlvm_channel_protocol, |
| 1880 | saved_crash_message_count), |
Benjamin Romer | e6bdb90 | 2015-03-16 13:58:33 -0400 | [diff] [blame] | 1881 | &local_crash_msg_count, sizeof(u16)) < 0) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1882 | POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC, |
| 1883 | POSTCODE_SEVERITY_ERR); |
| 1884 | return; |
| 1885 | } |
| 1886 | |
Benjamin Romer | e6bdb90 | 2015-03-16 13:58:33 -0400 | [diff] [blame] | 1887 | if (local_crash_msg_count != CONTROLVM_CRASHMSG_MAX) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1888 | POSTCODE_LINUX_3(CRASH_DEV_COUNT_FAILURE_PC, |
Benjamin Romer | e6bdb90 | 2015-03-16 13:58:33 -0400 | [diff] [blame] | 1889 | local_crash_msg_count, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1890 | POSTCODE_SEVERITY_ERR); |
| 1891 | return; |
| 1892 | } |
| 1893 | |
| 1894 | /* get saved crash message offset */ |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 1895 | if (visorchannel_read(controlvm_channel, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 1896 | offsetof(struct spar_controlvm_channel_protocol, |
| 1897 | saved_crash_message_offset), |
Benjamin Romer | e6bdb90 | 2015-03-16 13:58:33 -0400 | [diff] [blame] | 1898 | &local_crash_msg_offset, sizeof(u32)) < 0) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1899 | POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC, |
| 1900 | POSTCODE_SEVERITY_ERR); |
| 1901 | return; |
| 1902 | } |
| 1903 | |
| 1904 | /* read create device message for storage bus offset */ |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 1905 | if (visorchannel_read(controlvm_channel, |
Benjamin Romer | e6bdb90 | 2015-03-16 13:58:33 -0400 | [diff] [blame] | 1906 | local_crash_msg_offset, |
| 1907 | &local_crash_bus_msg, |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1908 | sizeof(struct controlvm_message)) < 0) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1909 | POSTCODE_LINUX_2(CRASH_DEV_RD_BUS_FAIULRE_PC, |
| 1910 | POSTCODE_SEVERITY_ERR); |
| 1911 | return; |
| 1912 | } |
| 1913 | |
| 1914 | /* read create device message for storage device */ |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 1915 | if (visorchannel_read(controlvm_channel, |
Benjamin Romer | e6bdb90 | 2015-03-16 13:58:33 -0400 | [diff] [blame] | 1916 | local_crash_msg_offset + |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1917 | sizeof(struct controlvm_message), |
Benjamin Romer | e6bdb90 | 2015-03-16 13:58:33 -0400 | [diff] [blame] | 1918 | &local_crash_dev_msg, |
Benjamin Romer | 3ab4770 | 2014-10-23 14:30:31 -0400 | [diff] [blame] | 1919 | sizeof(struct controlvm_message)) < 0) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1920 | POSTCODE_LINUX_2(CRASH_DEV_RD_DEV_FAIULRE_PC, |
| 1921 | POSTCODE_SEVERITY_ERR); |
| 1922 | return; |
| 1923 | } |
| 1924 | |
| 1925 | /* reuse IOVM create bus message */ |
Benjamin Romer | e6bdb90 | 2015-03-16 13:58:33 -0400 | [diff] [blame] | 1926 | if (local_crash_bus_msg.cmd.create_bus.channel_addr != 0) { |
| 1927 | bus_create(&local_crash_bus_msg); |
Benjamin Romer | 75c1f8b | 2015-03-16 13:58:19 -0400 | [diff] [blame] | 1928 | } else { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1929 | POSTCODE_LINUX_2(CRASH_DEV_BUS_NULL_FAILURE_PC, |
| 1930 | POSTCODE_SEVERITY_ERR); |
| 1931 | return; |
| 1932 | } |
| 1933 | |
| 1934 | /* reuse create device message for storage device */ |
Benjamin Romer | e6bdb90 | 2015-03-16 13:58:33 -0400 | [diff] [blame] | 1935 | if (local_crash_dev_msg.cmd.create_device.channel_addr != 0) { |
| 1936 | my_device_create(&local_crash_dev_msg); |
Benjamin Romer | 75c1f8b | 2015-03-16 13:58:19 -0400 | [diff] [blame] | 1937 | } else { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1938 | POSTCODE_LINUX_2(CRASH_DEV_DEV_NULL_FAILURE_PC, |
| 1939 | POSTCODE_SEVERITY_ERR); |
| 1940 | return; |
| 1941 | } |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1942 | POSTCODE_LINUX_2(CRASH_DEV_EXIT_PC, POSTCODE_SEVERITY_INFO); |
| 1943 | return; |
| 1944 | |
Benjamin Romer | e6bdb90 | 2015-03-16 13:58:33 -0400 | [diff] [blame] | 1945 | cleanup: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1946 | |
Benjamin Romer | 911e213 | 2015-03-16 13:57:47 -0400 | [diff] [blame] | 1947 | poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_SLOW; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1948 | |
Benjamin Romer | 9232d2d | 2015-03-16 13:57:57 -0400 | [diff] [blame] | 1949 | queue_delayed_work(periodic_controlvm_workqueue, |
| 1950 | &periodic_controlvm_work, poll_jiffies); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | static void |
Benjamin Romer | 8e3fedd | 2015-03-16 13:58:43 -0400 | [diff] [blame] | 1954 | bus_create_response(ulong bus_no, int response) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1955 | { |
Benjamin Romer | 8e3fedd | 2015-03-16 13:58:43 -0400 | [diff] [blame] | 1956 | bus_responder(CONTROLVM_BUS_CREATE, bus_no, response); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | static void |
Benjamin Romer | 8e3fedd | 2015-03-16 13:58:43 -0400 | [diff] [blame] | 1960 | bus_destroy_response(ulong bus_no, int response) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1961 | { |
Benjamin Romer | 8e3fedd | 2015-03-16 13:58:43 -0400 | [diff] [blame] | 1962 | bus_responder(CONTROLVM_BUS_DESTROY, bus_no, response); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | static void |
Benjamin Romer | 8e3fedd | 2015-03-16 13:58:43 -0400 | [diff] [blame] | 1966 | device_create_response(ulong bus_no, ulong dev_no, int response) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1967 | { |
Benjamin Romer | 8e3fedd | 2015-03-16 13:58:43 -0400 | [diff] [blame] | 1968 | device_responder(CONTROLVM_DEVICE_CREATE, bus_no, dev_no, response); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | static void |
Benjamin Romer | 8e3fedd | 2015-03-16 13:58:43 -0400 | [diff] [blame] | 1972 | device_destroy_response(ulong bus_no, ulong dev_no, int response) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1973 | { |
Benjamin Romer | 8e3fedd | 2015-03-16 13:58:43 -0400 | [diff] [blame] | 1974 | device_responder(CONTROLVM_DEVICE_DESTROY, bus_no, dev_no, response); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | void |
Benjamin Romer | 8420f41 | 2014-10-31 09:57:36 -0400 | [diff] [blame] | 1978 | visorchipset_device_pause_response(ulong bus_no, ulong dev_no, int response) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1979 | { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1980 | device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE, |
Benjamin Romer | 8420f41 | 2014-10-31 09:57:36 -0400 | [diff] [blame] | 1981 | bus_no, dev_no, response, |
Benjamin Romer | bd0d2dc | 2014-10-23 14:30:13 -0400 | [diff] [blame] | 1982 | segment_state_standby); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1983 | } |
Ken Cox | 927c792 | 2014-03-05 14:52:25 -0600 | [diff] [blame] | 1984 | EXPORT_SYMBOL_GPL(visorchipset_device_pause_response); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1985 | |
| 1986 | static void |
Benjamin Romer | 8e3fedd | 2015-03-16 13:58:43 -0400 | [diff] [blame] | 1987 | device_resume_response(ulong bus_no, ulong dev_no, int response) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1988 | { |
| 1989 | device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE, |
Benjamin Romer | 8e3fedd | 2015-03-16 13:58:43 -0400 | [diff] [blame] | 1990 | bus_no, dev_no, response, |
Benjamin Romer | bd0d2dc | 2014-10-23 14:30:13 -0400 | [diff] [blame] | 1991 | segment_state_running); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | BOOL |
Benjamin Romer | 77db712 | 2014-10-31 09:57:37 -0400 | [diff] [blame] | 1995 | visorchipset_get_bus_info(ulong bus_no, struct visorchipset_bus_info *bus_info) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 1996 | { |
Benjamin Romer | 1390b88 | 2015-03-16 13:58:03 -0400 | [diff] [blame] | 1997 | void *p = findbus(&bus_info_list, bus_no); |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 1998 | |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 1999 | if (!p) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2000 | return FALSE; |
Benjamin Romer | 77db712 | 2014-10-31 09:57:37 -0400 | [diff] [blame] | 2001 | memcpy(bus_info, p, sizeof(struct visorchipset_bus_info)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2002 | return TRUE; |
| 2003 | } |
| 2004 | EXPORT_SYMBOL_GPL(visorchipset_get_bus_info); |
| 2005 | |
| 2006 | BOOL |
Benjamin Romer | 58dd8f2d | 2014-10-31 09:57:40 -0400 | [diff] [blame] | 2007 | visorchipset_set_bus_context(ulong bus_no, void *context) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2008 | { |
Benjamin Romer | 1390b88 | 2015-03-16 13:58:03 -0400 | [diff] [blame] | 2009 | struct visorchipset_bus_info *p = findbus(&bus_info_list, bus_no); |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 2010 | |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 2011 | if (!p) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2012 | return FALSE; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2013 | p->bus_driver_context = context; |
| 2014 | return TRUE; |
| 2015 | } |
| 2016 | EXPORT_SYMBOL_GPL(visorchipset_set_bus_context); |
| 2017 | |
| 2018 | BOOL |
Benjamin Romer | b486df1 | 2014-10-31 09:57:38 -0400 | [diff] [blame] | 2019 | visorchipset_get_device_info(ulong bus_no, ulong dev_no, |
| 2020 | struct visorchipset_device_info *dev_info) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2021 | { |
Benjamin Romer | 1390b88 | 2015-03-16 13:58:03 -0400 | [diff] [blame] | 2022 | void *p = finddevice(&dev_info_list, bus_no, dev_no); |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 2023 | |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 2024 | if (!p) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2025 | return FALSE; |
Benjamin Romer | b486df1 | 2014-10-31 09:57:38 -0400 | [diff] [blame] | 2026 | memcpy(dev_info, p, sizeof(struct visorchipset_device_info)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2027 | return TRUE; |
| 2028 | } |
| 2029 | EXPORT_SYMBOL_GPL(visorchipset_get_device_info); |
| 2030 | |
| 2031 | BOOL |
Benjamin Romer | cf0bd0b | 2014-10-31 09:57:41 -0400 | [diff] [blame] | 2032 | visorchipset_set_device_context(ulong bus_no, ulong dev_no, void *context) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2033 | { |
Benjamin Romer | 246e0cd | 2014-10-31 09:57:24 -0400 | [diff] [blame] | 2034 | struct visorchipset_device_info *p = |
Benjamin Romer | 1390b88 | 2015-03-16 13:58:03 -0400 | [diff] [blame] | 2035 | finddevice(&dev_info_list, bus_no, dev_no); |
Benjamin Romer | 26eb2c0 | 2014-08-18 09:34:53 -0400 | [diff] [blame] | 2036 | |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 2037 | if (!p) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2038 | return FALSE; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2039 | p->bus_driver_context = context; |
| 2040 | return TRUE; |
| 2041 | } |
| 2042 | EXPORT_SYMBOL_GPL(visorchipset_set_device_context); |
| 2043 | |
| 2044 | /* Generic wrapper function for allocating memory from a kmem_cache pool. |
| 2045 | */ |
| 2046 | void * |
| 2047 | visorchipset_cache_alloc(struct kmem_cache *pool, BOOL ok_to_block, |
| 2048 | char *fn, int ln) |
| 2049 | { |
| 2050 | gfp_t gfp; |
| 2051 | void *p; |
| 2052 | |
| 2053 | if (ok_to_block) |
| 2054 | gfp = GFP_KERNEL; |
| 2055 | else |
| 2056 | gfp = GFP_ATOMIC; |
| 2057 | /* __GFP_NORETRY means "ok to fail", meaning |
| 2058 | * kmem_cache_alloc() can return NULL, implying the caller CAN |
| 2059 | * cope with failure. If you do NOT specify __GFP_NORETRY, |
| 2060 | * Linux will go to extreme measures to get memory for you |
| 2061 | * (like, invoke oom killer), which will probably cripple the |
| 2062 | * system. |
| 2063 | */ |
| 2064 | gfp |= __GFP_NORETRY; |
| 2065 | p = kmem_cache_alloc(pool, gfp); |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 2066 | if (!p) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2067 | return NULL; |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 2068 | |
Benjamin Romer | 712f42c | 2015-03-16 13:58:40 -0400 | [diff] [blame] | 2069 | atomic_inc(&visorchipset_cache_buffers_in_use); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2070 | return p; |
| 2071 | } |
| 2072 | |
| 2073 | /* Generic wrapper function for freeing memory from a kmem_cache pool. |
| 2074 | */ |
| 2075 | void |
| 2076 | visorchipset_cache_free(struct kmem_cache *pool, void *p, char *fn, int ln) |
| 2077 | { |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 2078 | if (!p) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2079 | return; |
Benjamin Romer | 0aca7844 | 2015-03-04 12:14:25 -0500 | [diff] [blame] | 2080 | |
Benjamin Romer | 712f42c | 2015-03-16 13:58:40 -0400 | [diff] [blame] | 2081 | atomic_dec(&visorchipset_cache_buffers_in_use); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2082 | kmem_cache_free(pool, p); |
| 2083 | } |
| 2084 | |
Benjamin Romer | 18b87ed | 2014-07-24 14:08:43 -0400 | [diff] [blame] | 2085 | static ssize_t chipsetready_store(struct device *dev, |
| 2086 | struct device_attribute *attr, const char *buf, size_t count) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2087 | { |
Benjamin Romer | 18b87ed | 2014-07-24 14:08:43 -0400 | [diff] [blame] | 2088 | char msgtype[64]; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2089 | |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 2090 | if (sscanf(buf, "%63s", msgtype) != 1) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2091 | return -EINVAL; |
Benjamin Romer | 66e24b7 | 2014-07-25 13:55:10 -0400 | [diff] [blame] | 2092 | |
| 2093 | if (strcmp(msgtype, "CALLHOMEDISK_MOUNTED") == 0) { |
| 2094 | chipset_events[0] = 1; |
| 2095 | return count; |
| 2096 | } else if (strcmp(msgtype, "MODULES_LOADED") == 0) { |
| 2097 | chipset_events[1] = 1; |
| 2098 | return count; |
Benjamin Romer | e22a4a0 | 2014-08-18 09:34:54 -0400 | [diff] [blame] | 2099 | } |
| 2100 | return -EINVAL; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2101 | } |
| 2102 | |
Benjamin Romer | e56fa7c | 2014-07-29 11:11:21 -0400 | [diff] [blame] | 2103 | /* The parahotplug/devicedisabled interface gets called by our support script |
| 2104 | * when an SR-IOV device has been shut down. The ID is passed to the script |
| 2105 | * and then passed back when the device has been removed. |
| 2106 | */ |
| 2107 | static ssize_t devicedisabled_store(struct device *dev, |
| 2108 | struct device_attribute *attr, const char *buf, size_t count) |
| 2109 | { |
| 2110 | uint id; |
| 2111 | |
| 2112 | if (kstrtouint(buf, 10, &id) != 0) |
| 2113 | return -EINVAL; |
| 2114 | |
| 2115 | parahotplug_request_complete(id, 0); |
| 2116 | return count; |
| 2117 | } |
| 2118 | |
| 2119 | /* The parahotplug/deviceenabled interface gets called by our support script |
| 2120 | * when an SR-IOV device has been recovered. The ID is passed to the script |
| 2121 | * and then passed back when the device has been brought back up. |
| 2122 | */ |
| 2123 | static ssize_t deviceenabled_store(struct device *dev, |
| 2124 | struct device_attribute *attr, const char *buf, size_t count) |
| 2125 | { |
| 2126 | uint id; |
| 2127 | |
| 2128 | if (kstrtouint(buf, 10, &id) != 0) |
| 2129 | return -EINVAL; |
| 2130 | |
| 2131 | parahotplug_request_complete(id, 1); |
| 2132 | return count; |
| 2133 | } |
| 2134 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2135 | static int __init |
| 2136 | visorchipset_init(void) |
| 2137 | { |
| 2138 | int rc = 0, x = 0; |
Benjamin Romer | 8a1182e | 2014-07-17 12:39:58 -0400 | [diff] [blame] | 2139 | HOSTADDRESS addr; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2140 | |
Ken Cox | fcd0157e | 2014-04-28 12:23:13 -0500 | [diff] [blame] | 2141 | if (!unisys_spar_platform) |
| 2142 | return -ENODEV; |
| 2143 | |
Benjamin Romer | 6fe345a | 2015-03-16 13:58:42 -0400 | [diff] [blame] | 2144 | memset(&busdev_server_notifiers, 0, sizeof(busdev_server_notifiers)); |
| 2145 | memset(&busdev_client_notifiers, 0, sizeof(busdev_client_notifiers)); |
Benjamin Romer | 84982fb | 2015-03-16 13:58:07 -0400 | [diff] [blame] | 2146 | memset(&controlvm_payload_info, 0, sizeof(controlvm_payload_info)); |
Benjamin Romer | ea33b4ee5 | 2015-03-16 13:58:08 -0400 | [diff] [blame] | 2147 | memset(&livedump_info, 0, sizeof(livedump_info)); |
| 2148 | atomic_set(&livedump_info.buffers_in_use, 0); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2149 | |
Ken Cox | 9f8d0e8 | 2014-03-19 13:06:19 -0500 | [diff] [blame] | 2150 | if (visorchipset_testvnic) { |
Ken Cox | 9f8d0e8 | 2014-03-19 13:06:19 -0500 | [diff] [blame] | 2151 | POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, x, DIAG_SEVERITY_ERR); |
| 2152 | rc = x; |
Benjamin Romer | a6a3989 | 2015-03-16 13:58:34 -0400 | [diff] [blame] | 2153 | goto cleanup; |
Ken Cox | 9f8d0e8 | 2014-03-19 13:06:19 -0500 | [diff] [blame] | 2154 | } |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2155 | |
Benjamin Romer | 8a1182e | 2014-07-17 12:39:58 -0400 | [diff] [blame] | 2156 | addr = controlvm_get_channel_address(); |
| 2157 | if (addr != 0) { |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 2158 | controlvm_channel = |
Benjamin Romer | 8a1182e | 2014-07-17 12:39:58 -0400 | [diff] [blame] | 2159 | visorchannel_create_with_lock |
| 2160 | (addr, |
Benjamin Romer | d19642f | 2014-10-23 14:30:34 -0400 | [diff] [blame] | 2161 | sizeof(struct spar_controlvm_channel_protocol), |
Benjamin Romer | 5fbaa4b | 2014-10-23 14:30:14 -0400 | [diff] [blame] | 2162 | spar_controlvm_channel_protocol_uuid); |
Benjamin Romer | 93a8456 | 2014-10-23 14:30:05 -0400 | [diff] [blame] | 2163 | if (SPAR_CONTROLVM_CHANNEL_OK_CLIENT( |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 2164 | visorchannel_get_header(controlvm_channel))) { |
Benjamin Romer | 8a1182e | 2014-07-17 12:39:58 -0400 | [diff] [blame] | 2165 | initialize_controlvm_payload(); |
| 2166 | } else { |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 2167 | visorchannel_destroy(controlvm_channel); |
| 2168 | controlvm_channel = NULL; |
Benjamin Romer | 8a1182e | 2014-07-17 12:39:58 -0400 | [diff] [blame] | 2169 | return -ENODEV; |
| 2170 | } |
| 2171 | } else { |
Benjamin Romer | 8a1182e | 2014-07-17 12:39:58 -0400 | [diff] [blame] | 2172 | return -ENODEV; |
| 2173 | } |
| 2174 | |
Benjamin Romer | 5aa8ae5 | 2015-03-16 13:58:44 -0400 | [diff] [blame] | 2175 | major_dev = MKDEV(visorchipset_major, 0); |
| 2176 | rc = visorchipset_file_init(major_dev, &controlvm_channel); |
Ken Cox | 4cb005a | 2014-03-19 13:06:20 -0500 | [diff] [blame] | 2177 | if (rc < 0) { |
Ken Cox | 4cb005a | 2014-03-19 13:06:20 -0500 | [diff] [blame] | 2178 | POSTCODE_LINUX_2(CHIPSET_INIT_FAILURE_PC, DIAG_SEVERITY_ERR); |
Benjamin Romer | a6a3989 | 2015-03-16 13:58:34 -0400 | [diff] [blame] | 2179 | goto cleanup; |
Ken Cox | 4cb005a | 2014-03-19 13:06:20 -0500 | [diff] [blame] | 2180 | } |
Ken Cox | 9f8d0e8 | 2014-03-19 13:06:19 -0500 | [diff] [blame] | 2181 | |
Benjamin Romer | da021f0 | 2015-03-16 13:57:58 -0400 | [diff] [blame] | 2182 | memset(&g_diag_msg_hdr, 0, sizeof(struct controlvm_message_header)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2183 | |
Benjamin Romer | da021f0 | 2015-03-16 13:57:58 -0400 | [diff] [blame] | 2184 | memset(&g_chipset_msg_hdr, 0, sizeof(struct controlvm_message_header)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2185 | |
Benjamin Romer | da021f0 | 2015-03-16 13:57:58 -0400 | [diff] [blame] | 2186 | memset(&g_del_dump_msg_hdr, 0, sizeof(struct controlvm_message_header)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2187 | |
Benjamin Romer | 1eee001 | 2015-03-16 13:58:39 -0400 | [diff] [blame] | 2188 | putfile_buffer_list_pool = |
| 2189 | kmem_cache_create(putfile_buffer_list_pool_name, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2190 | sizeof(struct putfile_buffer_entry), |
| 2191 | 0, SLAB_HWCACHE_ALIGN, NULL); |
Benjamin Romer | 1eee001 | 2015-03-16 13:58:39 -0400 | [diff] [blame] | 2192 | if (!putfile_buffer_list_pool) { |
Ken Cox | 4cb005a | 2014-03-19 13:06:20 -0500 | [diff] [blame] | 2193 | POSTCODE_LINUX_2(CHIPSET_INIT_FAILURE_PC, DIAG_SEVERITY_ERR); |
| 2194 | rc = -1; |
Benjamin Romer | a6a3989 | 2015-03-16 13:58:34 -0400 | [diff] [blame] | 2195 | goto cleanup; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2196 | } |
Benjamin Romer | 2098dbd | 2015-03-04 12:14:22 -0500 | [diff] [blame] | 2197 | if (!visorchipset_disable_controlvm) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2198 | /* if booting in a crash kernel */ |
| 2199 | if (visorchipset_crash_kernel) |
Benjamin Romer | 9232d2d | 2015-03-16 13:57:57 -0400 | [diff] [blame] | 2200 | INIT_DELAYED_WORK(&periodic_controlvm_work, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2201 | setup_crash_devices_work_queue); |
| 2202 | else |
Benjamin Romer | 9232d2d | 2015-03-16 13:57:57 -0400 | [diff] [blame] | 2203 | INIT_DELAYED_WORK(&periodic_controlvm_work, |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2204 | controlvm_periodic_work); |
Benjamin Romer | 9232d2d | 2015-03-16 13:57:57 -0400 | [diff] [blame] | 2205 | periodic_controlvm_workqueue = |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2206 | create_singlethread_workqueue("visorchipset_controlvm"); |
| 2207 | |
Benjamin Romer | 38f736e | 2015-03-16 13:58:13 -0400 | [diff] [blame] | 2208 | if (!periodic_controlvm_workqueue) { |
Ken Cox | 4cb005a | 2014-03-19 13:06:20 -0500 | [diff] [blame] | 2209 | POSTCODE_LINUX_2(CREATE_WORKQUEUE_FAILED_PC, |
| 2210 | DIAG_SEVERITY_ERR); |
| 2211 | rc = -ENOMEM; |
Benjamin Romer | a6a3989 | 2015-03-16 13:58:34 -0400 | [diff] [blame] | 2212 | goto cleanup; |
Ken Cox | 4cb005a | 2014-03-19 13:06:20 -0500 | [diff] [blame] | 2213 | } |
Benjamin Romer | b53e0e9 | 2015-03-16 13:57:56 -0400 | [diff] [blame] | 2214 | most_recent_message_jiffies = jiffies; |
Benjamin Romer | 911e213 | 2015-03-16 13:57:47 -0400 | [diff] [blame] | 2215 | poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST; |
Benjamin Romer | 9232d2d | 2015-03-16 13:57:57 -0400 | [diff] [blame] | 2216 | rc = queue_delayed_work(periodic_controlvm_workqueue, |
| 2217 | &periodic_controlvm_work, poll_jiffies); |
Ken Cox | 4cb005a | 2014-03-19 13:06:20 -0500 | [diff] [blame] | 2218 | if (rc < 0) { |
Ken Cox | 4cb005a | 2014-03-19 13:06:20 -0500 | [diff] [blame] | 2219 | POSTCODE_LINUX_2(QUEUE_DELAYED_WORK_PC, |
| 2220 | DIAG_SEVERITY_ERR); |
Benjamin Romer | a6a3989 | 2015-03-16 13:58:34 -0400 | [diff] [blame] | 2221 | goto cleanup; |
Ken Cox | 4cb005a | 2014-03-19 13:06:20 -0500 | [diff] [blame] | 2222 | } |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2223 | } |
| 2224 | |
Benjamin Romer | eb34e87 | 2015-03-16 13:58:45 -0400 | [diff] [blame] | 2225 | visorchipset_platform_device.dev.devt = major_dev; |
| 2226 | if (platform_device_register(&visorchipset_platform_device) < 0) { |
Ken Cox | 4cb005a | 2014-03-19 13:06:20 -0500 | [diff] [blame] | 2227 | POSTCODE_LINUX_2(DEVICE_REGISTER_FAILURE_PC, DIAG_SEVERITY_ERR); |
| 2228 | rc = -1; |
Benjamin Romer | a6a3989 | 2015-03-16 13:58:34 -0400 | [diff] [blame] | 2229 | goto cleanup; |
Ken Cox | 4cb005a | 2014-03-19 13:06:20 -0500 | [diff] [blame] | 2230 | } |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2231 | POSTCODE_LINUX_2(CHIPSET_INIT_SUCCESS_PC, POSTCODE_SEVERITY_INFO); |
Ken Cox | 22ad57b | 2014-03-19 13:06:25 -0500 | [diff] [blame] | 2232 | rc = 0; |
Benjamin Romer | a6a3989 | 2015-03-16 13:58:34 -0400 | [diff] [blame] | 2233 | cleanup: |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2234 | if (rc) { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2235 | POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, rc, |
| 2236 | POSTCODE_SEVERITY_ERR); |
| 2237 | } |
| 2238 | return rc; |
| 2239 | } |
| 2240 | |
| 2241 | static void |
| 2242 | visorchipset_exit(void) |
| 2243 | { |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2244 | POSTCODE_LINUX_2(DRIVER_EXIT_PC, POSTCODE_SEVERITY_INFO); |
| 2245 | |
| 2246 | if (visorchipset_disable_controlvm) { |
| 2247 | ; |
| 2248 | } else { |
Benjamin Romer | 9232d2d | 2015-03-16 13:57:57 -0400 | [diff] [blame] | 2249 | cancel_delayed_work(&periodic_controlvm_work); |
| 2250 | flush_workqueue(periodic_controlvm_workqueue); |
| 2251 | destroy_workqueue(periodic_controlvm_workqueue); |
| 2252 | periodic_controlvm_workqueue = NULL; |
Benjamin Romer | 84982fb | 2015-03-16 13:58:07 -0400 | [diff] [blame] | 2253 | destroy_controlvm_payload_info(&controlvm_payload_info); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2254 | } |
Benjamin Romer | 1eee001 | 2015-03-16 13:58:39 -0400 | [diff] [blame] | 2255 | if (putfile_buffer_list_pool) { |
| 2256 | kmem_cache_destroy(putfile_buffer_list_pool); |
| 2257 | putfile_buffer_list_pool = NULL; |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2258 | } |
Benjamin Romer | 1783319 | 2014-07-15 13:30:41 -0400 | [diff] [blame] | 2259 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2260 | cleanup_controlvm_structures(); |
| 2261 | |
Benjamin Romer | da021f0 | 2015-03-16 13:57:58 -0400 | [diff] [blame] | 2262 | memset(&g_diag_msg_hdr, 0, sizeof(struct controlvm_message_header)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2263 | |
Benjamin Romer | da021f0 | 2015-03-16 13:57:58 -0400 | [diff] [blame] | 2264 | memset(&g_chipset_msg_hdr, 0, sizeof(struct controlvm_message_header)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2265 | |
Benjamin Romer | da021f0 | 2015-03-16 13:57:58 -0400 | [diff] [blame] | 2266 | memset(&g_del_dump_msg_hdr, 0, sizeof(struct controlvm_message_header)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2267 | |
Benjamin Romer | c3d9a22 | 2015-03-16 13:58:05 -0400 | [diff] [blame] | 2268 | visorchannel_destroy(controlvm_channel); |
Benjamin Romer | 8a1182e | 2014-07-17 12:39:58 -0400 | [diff] [blame] | 2269 | |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2270 | visorchipset_file_cleanup(); |
| 2271 | POSTCODE_LINUX_2(DRIVER_EXIT_PC, POSTCODE_SEVERITY_INFO); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | module_param_named(testvnic, visorchipset_testvnic, int, S_IRUGO); |
| 2275 | MODULE_PARM_DESC(visorchipset_testvnic, "1 to test vnic, using dummy VNIC connected via a loopback to a physical ethernet"); |
| 2276 | int visorchipset_testvnic = 0; |
| 2277 | |
| 2278 | module_param_named(testvnicclient, visorchipset_testvnicclient, int, S_IRUGO); |
| 2279 | MODULE_PARM_DESC(visorchipset_testvnicclient, "1 to test vnic, using real VNIC channel attached to a separate IOVM guest"); |
| 2280 | int visorchipset_testvnicclient = 0; |
| 2281 | |
| 2282 | module_param_named(testmsg, visorchipset_testmsg, int, S_IRUGO); |
| 2283 | MODULE_PARM_DESC(visorchipset_testmsg, |
| 2284 | "1 to manufacture the chipset, bus, and switch messages"); |
| 2285 | int visorchipset_testmsg = 0; |
| 2286 | |
| 2287 | module_param_named(major, visorchipset_major, int, S_IRUGO); |
| 2288 | MODULE_PARM_DESC(visorchipset_major, "major device number to use for the device node"); |
| 2289 | int visorchipset_major = 0; |
| 2290 | |
| 2291 | module_param_named(serverregwait, visorchipset_serverregwait, int, S_IRUGO); |
| 2292 | MODULE_PARM_DESC(visorchipset_serverreqwait, |
| 2293 | "1 to have the module wait for the visor bus to register"); |
| 2294 | int visorchipset_serverregwait = 0; /* default is off */ |
| 2295 | module_param_named(clientregwait, visorchipset_clientregwait, int, S_IRUGO); |
| 2296 | MODULE_PARM_DESC(visorchipset_clientregwait, "1 to have the module wait for the visorclientbus to register"); |
| 2297 | int visorchipset_clientregwait = 1; /* default is on */ |
| 2298 | module_param_named(testteardown, visorchipset_testteardown, int, S_IRUGO); |
| 2299 | MODULE_PARM_DESC(visorchipset_testteardown, |
| 2300 | "1 to test teardown of the chipset, bus, and switch"); |
| 2301 | int visorchipset_testteardown = 0; /* default is off */ |
| 2302 | module_param_named(disable_controlvm, visorchipset_disable_controlvm, int, |
| 2303 | S_IRUGO); |
| 2304 | MODULE_PARM_DESC(visorchipset_disable_controlvm, |
| 2305 | "1 to disable polling of controlVm channel"); |
| 2306 | int visorchipset_disable_controlvm = 0; /* default is off */ |
| 2307 | module_param_named(crash_kernel, visorchipset_crash_kernel, int, S_IRUGO); |
| 2308 | MODULE_PARM_DESC(visorchipset_crash_kernel, |
| 2309 | "1 means we are running in crash kernel"); |
| 2310 | int visorchipset_crash_kernel = 0; /* default is running in non-crash kernel */ |
| 2311 | module_param_named(holdchipsetready, visorchipset_holdchipsetready, |
| 2312 | int, S_IRUGO); |
| 2313 | MODULE_PARM_DESC(visorchipset_holdchipsetready, |
| 2314 | "1 to hold response to CHIPSET_READY"); |
| 2315 | int visorchipset_holdchipsetready = 0; /* default is to send CHIPSET_READY |
| 2316 | * response immediately */ |
| 2317 | module_init(visorchipset_init); |
| 2318 | module_exit(visorchipset_exit); |
| 2319 | |
| 2320 | MODULE_AUTHOR("Unisys"); |
| 2321 | MODULE_LICENSE("GPL"); |
| 2322 | MODULE_DESCRIPTION("Supervisor chipset driver for service partition: ver " |
| 2323 | VERSION); |
| 2324 | MODULE_VERSION(VERSION); |