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