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