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