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