2 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more
16 #include <linux/acpi.h>
17 #include <linux/crash_dump.h>
20 #include "visorbus_private.h"
22 /* {72120008-4AAB-11DC-8530-444553544200} */
23 #define VISOR_SIOVM_GUID \
24 GUID_INIT(0x72120008, 0x4AAB, 0x11DC, \
25 0x85, 0x30, 0x44, 0x45, 0x53, 0x54, 0x42, 0x00)
27 static const guid_t visor_vhba_channel_guid = VISOR_VHBA_CHANNEL_GUID;
28 static const guid_t visor_siovm_guid = VISOR_SIOVM_GUID;
29 static const guid_t visor_controlvm_channel_guid = VISOR_CONTROLVM_CHANNEL_GUID;
31 #define POLLJIFFIES_CONTROLVMCHANNEL_FAST 1
32 #define POLLJIFFIES_CONTROLVMCHANNEL_SLOW 100
34 #define MAX_CONTROLVM_PAYLOAD_BYTES (1024 * 128)
36 #define UNISYS_VISOR_LEAF_ID 0x40000000
38 /* The s-Par leaf ID returns "UnisysSpar64" encoded across ebx, ecx, edx */
39 #define UNISYS_VISOR_ID_EBX 0x73696e55
40 #define UNISYS_VISOR_ID_ECX 0x70537379
41 #define UNISYS_VISOR_ID_EDX 0x34367261
44 * When the controlvm channel is idle for at least MIN_IDLE_SECONDS,
45 * we switch to slow polling mode. As soon as we get a controlvm
46 * message, we switch back to fast polling mode.
48 #define MIN_IDLE_SECONDS 10
50 struct parser_context {
51 unsigned long allocbytes;
52 unsigned long param_bytes;
54 unsigned long bytes_remaining;
59 /* VMCALL_CONTROLVM_ADDR: Used by all guests, not just IO. */
60 #define VMCALL_CONTROLVM_ADDR 0x0501
63 VMCALL_RESULT_SUCCESS = 0,
64 VMCALL_RESULT_INVALID_PARAM = 1,
65 VMCALL_RESULT_DATA_UNAVAILABLE = 2,
66 VMCALL_RESULT_FAILURE_UNAVAILABLE = 3,
67 VMCALL_RESULT_DEVICE_ERROR = 4,
68 VMCALL_RESULT_DEVICE_NOT_READY = 5
72 * struct vmcall_io_controlvm_addr_params - Structure for IO VMCALLS. Has
73 * parameters to VMCALL_CONTROLVM_ADDR
75 * @address: The Guest-relative physical address of the ControlVm channel.
76 * This VMCall fills this in with the appropriate address.
77 * Contents provided by this VMCALL (OUT).
78 * @channel_bytes: The size of the ControlVm channel in bytes This VMCall fills
79 * this in with the appropriate address. Contents provided by
81 * @unused: Unused Bytes in the 64-Bit Aligned Struct.
83 struct vmcall_io_controlvm_addr_params {
89 struct visorchipset_device {
90 struct acpi_device *acpi_device;
91 unsigned long poll_jiffies;
92 /* when we got our last controlvm message */
93 unsigned long most_recent_message_jiffies;
94 struct delayed_work periodic_controlvm_work;
95 struct visorchannel *controlvm_channel;
96 unsigned long controlvm_payload_bytes_buffered;
98 * The following variables are used to handle the scenario where we are
99 * unable to offload the payload from a controlvm message due to memory
100 * requirements. In this scenario, we simply stash the controlvm
101 * message, then attempt to process it again the next time
102 * controlvm_periodic_work() runs.
104 struct controlvm_message controlvm_pending_msg;
105 bool controlvm_pending_msg_valid;
106 struct vmcall_io_controlvm_addr_params controlvm_params;
109 static struct visorchipset_device *chipset_dev;
111 struct parahotplug_request {
112 struct list_head list;
114 unsigned long expiration;
115 struct controlvm_message msg;
118 /* prototypes for attributes */
119 static ssize_t toolaction_show(struct device *dev,
120 struct device_attribute *attr,
126 err = visorchannel_read(chipset_dev->controlvm_channel,
127 offsetof(struct visor_controlvm_channel,
129 &tool_action, sizeof(u8));
133 return sprintf(buf, "%u\n", tool_action);
136 static ssize_t toolaction_store(struct device *dev,
137 struct device_attribute *attr,
138 const char *buf, size_t count)
143 if (kstrtou8(buf, 10, &tool_action))
146 err = visorchannel_write(chipset_dev->controlvm_channel,
147 offsetof(struct visor_controlvm_channel,
149 &tool_action, sizeof(u8));
154 static DEVICE_ATTR_RW(toolaction);
156 static ssize_t boottotool_show(struct device *dev,
157 struct device_attribute *attr,
160 struct efi_visor_indication efi_visor_indication;
163 err = visorchannel_read(chipset_dev->controlvm_channel,
164 offsetof(struct visor_controlvm_channel,
166 &efi_visor_indication,
167 sizeof(struct efi_visor_indication));
170 return sprintf(buf, "%u\n", efi_visor_indication.boot_to_tool);
173 static ssize_t boottotool_store(struct device *dev,
174 struct device_attribute *attr,
175 const char *buf, size_t count)
178 struct efi_visor_indication efi_visor_indication;
180 if (kstrtoint(buf, 10, &val))
183 efi_visor_indication.boot_to_tool = val;
184 err = visorchannel_write(chipset_dev->controlvm_channel,
185 offsetof(struct visor_controlvm_channel,
187 &(efi_visor_indication),
188 sizeof(struct efi_visor_indication));
193 static DEVICE_ATTR_RW(boottotool);
195 static ssize_t error_show(struct device *dev, struct device_attribute *attr,
201 err = visorchannel_read(chipset_dev->controlvm_channel,
202 offsetof(struct visor_controlvm_channel,
204 &error, sizeof(u32));
207 return sprintf(buf, "%u\n", error);
210 static ssize_t error_store(struct device *dev, struct device_attribute *attr,
211 const char *buf, size_t count)
216 if (kstrtou32(buf, 10, &error))
219 err = visorchannel_write(chipset_dev->controlvm_channel,
220 offsetof(struct visor_controlvm_channel,
222 &error, sizeof(u32));
227 static DEVICE_ATTR_RW(error);
229 static ssize_t textid_show(struct device *dev, struct device_attribute *attr,
235 err = visorchannel_read(chipset_dev->controlvm_channel,
236 offsetof(struct visor_controlvm_channel,
237 installation_text_id),
238 &text_id, sizeof(u32));
242 return sprintf(buf, "%u\n", text_id);
245 static ssize_t textid_store(struct device *dev, struct device_attribute *attr,
246 const char *buf, size_t count)
251 if (kstrtou32(buf, 10, &text_id))
254 err = visorchannel_write(chipset_dev->controlvm_channel,
255 offsetof(struct visor_controlvm_channel,
256 installation_text_id),
257 &text_id, sizeof(u32));
262 static DEVICE_ATTR_RW(textid);
264 static ssize_t remaining_steps_show(struct device *dev,
265 struct device_attribute *attr, char *buf)
267 u16 remaining_steps = 0;
270 err = visorchannel_read(chipset_dev->controlvm_channel,
271 offsetof(struct visor_controlvm_channel,
272 installation_remaining_steps),
273 &remaining_steps, sizeof(u16));
277 return sprintf(buf, "%hu\n", remaining_steps);
280 static ssize_t remaining_steps_store(struct device *dev,
281 struct device_attribute *attr,
282 const char *buf, size_t count)
287 if (kstrtou16(buf, 10, &remaining_steps))
290 err = visorchannel_write(chipset_dev->controlvm_channel,
291 offsetof(struct visor_controlvm_channel,
292 installation_remaining_steps),
293 &remaining_steps, sizeof(u16));
298 static DEVICE_ATTR_RW(remaining_steps);
300 static const guid_t *parser_id_get(struct parser_context *ctx)
302 struct visor_controlvm_parameters_header *phdr = NULL;
304 phdr = (struct visor_controlvm_parameters_header *)(ctx->data);
308 static void parser_done(struct parser_context *ctx)
310 chipset_dev->controlvm_payload_bytes_buffered -= ctx->param_bytes;
314 static void *parser_string_get(struct parser_context *ctx)
318 int value_length = -1;
325 nscan = ctx->bytes_remaining;
329 for (i = 0, value_length = -1; i < nscan; i++)
330 if (pscan[i] == '\0') {
334 /* '\0' was not included in the length */
335 if (value_length < 0)
336 value_length = nscan;
338 value = kmalloc(value_length + 1, GFP_KERNEL);
341 if (value_length > 0)
342 memcpy(value, pscan, value_length);
343 ((u8 *)(value))[value_length] = '\0';
347 static void *parser_name_get(struct parser_context *ctx)
349 struct visor_controlvm_parameters_header *phdr = NULL;
351 phdr = (struct visor_controlvm_parameters_header *)(ctx->data);
353 if (phdr->name_offset + phdr->name_length > ctx->param_bytes)
356 ctx->curr = ctx->data + phdr->name_offset;
357 ctx->bytes_remaining = phdr->name_length;
358 return parser_string_get(ctx);
361 struct visor_busdev {
366 static int match_visorbus_dev_by_id(struct device *dev, void *data)
368 struct visor_device *vdev = to_visor_device(dev);
369 struct visor_busdev *id = data;
371 if ((vdev->chipset_bus_no == id->bus_no) &&
372 (vdev->chipset_dev_no == id->dev_no))
378 struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no,
379 struct visor_device *from)
382 struct device *dev_start = NULL;
383 struct visor_device *vdev = NULL;
384 struct visor_busdev id = {
390 dev_start = &from->device;
391 dev = bus_find_device(&visorbus_type, dev_start, (void *)&id,
392 match_visorbus_dev_by_id);
394 vdev = to_visor_device(dev);
398 static void controlvm_init_response(struct controlvm_message *msg,
399 struct controlvm_message_header *msg_hdr,
402 memset(msg, 0, sizeof(struct controlvm_message));
403 memcpy(&msg->hdr, msg_hdr, sizeof(struct controlvm_message_header));
404 msg->hdr.payload_bytes = 0;
405 msg->hdr.payload_vm_offset = 0;
406 msg->hdr.payload_max_bytes = 0;
408 msg->hdr.flags.failed = 1;
409 msg->hdr.completion_status = (u32)(-response);
413 static int controlvm_respond_chipset_init(
414 struct controlvm_message_header *msg_hdr,
416 enum visor_chipset_feature features)
418 struct controlvm_message outmsg;
420 controlvm_init_response(&outmsg, msg_hdr, response);
421 outmsg.cmd.init_chipset.features = features;
422 return visorchannel_signalinsert(chipset_dev->controlvm_channel,
423 CONTROLVM_QUEUE_REQUEST, &outmsg);
426 static int chipset_init(struct controlvm_message *inmsg)
428 static int chipset_inited;
429 enum visor_chipset_feature features = 0;
430 int rc = CONTROLVM_RESP_SUCCESS;
433 if (chipset_inited) {
434 rc = -CONTROLVM_RESP_ALREADY_DONE;
441 * Set features to indicate we support parahotplug (if Command
444 features = inmsg->cmd.init_chipset.features &
445 VISOR_CHIPSET_FEATURE_PARA_HOTPLUG;
448 * Set the "reply" bit so Command knows this is a
449 * features-aware driver.
451 features |= VISOR_CHIPSET_FEATURE_REPLY;
454 if (inmsg->hdr.flags.response_expected)
455 res = controlvm_respond_chipset_init(&inmsg->hdr, rc, features);
460 static int controlvm_respond(struct controlvm_message_header *msg_hdr,
462 struct visor_segment_state *state)
464 struct controlvm_message outmsg;
466 controlvm_init_response(&outmsg, msg_hdr, response);
467 if (outmsg.hdr.flags.test_message == 1)
471 outmsg.cmd.device_change_state.state = *state;
472 outmsg.cmd.device_change_state.flags.phys_device = 1;
475 return visorchannel_signalinsert(chipset_dev->controlvm_channel,
476 CONTROLVM_QUEUE_REQUEST, &outmsg);
479 enum crash_obj_type {
484 static int save_crash_message(struct controlvm_message *msg,
485 enum crash_obj_type cr_type)
487 u32 local_crash_msg_offset;
488 u16 local_crash_msg_count;
491 err = visorchannel_read(chipset_dev->controlvm_channel,
492 offsetof(struct visor_controlvm_channel,
493 saved_crash_message_count),
494 &local_crash_msg_count, sizeof(u16));
496 dev_err(&chipset_dev->acpi_device->dev,
497 "failed to read message count\n");
501 if (local_crash_msg_count != CONTROLVM_CRASHMSG_MAX) {
502 dev_err(&chipset_dev->acpi_device->dev,
503 "invalid number of messages\n");
507 err = visorchannel_read(chipset_dev->controlvm_channel,
508 offsetof(struct visor_controlvm_channel,
509 saved_crash_message_offset),
510 &local_crash_msg_offset, sizeof(u32));
512 dev_err(&chipset_dev->acpi_device->dev,
513 "failed to read offset\n");
519 local_crash_msg_offset += sizeof(struct controlvm_message);
520 err = visorchannel_write(chipset_dev->controlvm_channel,
521 local_crash_msg_offset,
523 sizeof(struct controlvm_message));
525 dev_err(&chipset_dev->acpi_device->dev,
526 "failed to write dev msg\n");
531 err = visorchannel_write(chipset_dev->controlvm_channel,
532 local_crash_msg_offset,
534 sizeof(struct controlvm_message));
536 dev_err(&chipset_dev->acpi_device->dev,
537 "failed to write bus msg\n");
542 dev_err(&chipset_dev->acpi_device->dev,
543 "Invalid crash_obj_type\n");
549 static int controlvm_responder(enum controlvm_id cmd_id,
550 struct controlvm_message_header *pending_msg_hdr,
553 if (!pending_msg_hdr)
556 if (pending_msg_hdr->id != (u32)cmd_id)
559 return controlvm_respond(pending_msg_hdr, response, NULL);
562 static int device_changestate_responder(
563 enum controlvm_id cmd_id,
564 struct visor_device *p, int response,
565 struct visor_segment_state response_state)
567 struct controlvm_message outmsg;
569 if (!p->pending_msg_hdr)
571 if (p->pending_msg_hdr->id != cmd_id)
574 controlvm_init_response(&outmsg, p->pending_msg_hdr, response);
576 outmsg.cmd.device_change_state.bus_no = p->chipset_bus_no;
577 outmsg.cmd.device_change_state.dev_no = p->chipset_dev_no;
578 outmsg.cmd.device_change_state.state = response_state;
580 return visorchannel_signalinsert(chipset_dev->controlvm_channel,
581 CONTROLVM_QUEUE_REQUEST, &outmsg);
584 static int visorbus_create(struct controlvm_message *inmsg)
586 struct controlvm_message_packet *cmd = &inmsg->cmd;
587 struct controlvm_message_header *pmsg_hdr = NULL;
588 u32 bus_no = cmd->create_bus.bus_no;
589 struct visor_device *bus_info;
590 struct visorchannel *visorchannel;
593 bus_info = visorbus_get_device_by_id(bus_no, BUS_ROOT_DEVICE, NULL);
594 if (bus_info && (bus_info->state.created == 1)) {
595 dev_err(&chipset_dev->acpi_device->dev,
596 "failed %s: already exists\n", __func__);
601 bus_info = kzalloc(sizeof(*bus_info), GFP_KERNEL);
607 INIT_LIST_HEAD(&bus_info->list_all);
608 bus_info->chipset_bus_no = bus_no;
609 bus_info->chipset_dev_no = BUS_ROOT_DEVICE;
611 if (guid_equal(&cmd->create_bus.bus_inst_guid, &visor_siovm_guid)) {
612 err = save_crash_message(inmsg, CRASH_BUS);
614 goto err_free_bus_info;
617 if (inmsg->hdr.flags.response_expected == 1) {
618 pmsg_hdr = kzalloc(sizeof(*pmsg_hdr),
622 goto err_free_bus_info;
625 memcpy(pmsg_hdr, &inmsg->hdr,
626 sizeof(struct controlvm_message_header));
627 bus_info->pending_msg_hdr = pmsg_hdr;
630 visorchannel = visorchannel_create(cmd->create_bus.channel_addr,
631 cmd->create_bus.channel_bytes,
633 &cmd->create_bus.bus_data_type_guid);
636 goto err_free_pending_msg;
639 bus_info->visorchannel = visorchannel;
641 /* Response will be handled by visorbus_create_instance on success */
642 err = visorbus_create_instance(bus_info);
644 goto err_destroy_channel;
649 visorchannel_destroy(visorchannel);
651 err_free_pending_msg:
652 kfree(bus_info->pending_msg_hdr);
658 if (inmsg->hdr.flags.response_expected == 1)
659 controlvm_responder(inmsg->hdr.id, &inmsg->hdr, err);
663 static int visorbus_destroy(struct controlvm_message *inmsg)
665 struct controlvm_message_packet *cmd = &inmsg->cmd;
666 struct controlvm_message_header *pmsg_hdr = NULL;
667 u32 bus_no = cmd->destroy_bus.bus_no;
668 struct visor_device *bus_info;
671 bus_info = visorbus_get_device_by_id(bus_no, BUS_ROOT_DEVICE, NULL);
676 if (bus_info->state.created == 0) {
680 if (bus_info->pending_msg_hdr) {
681 /* only non-NULL if dev is still waiting on a response */
685 if (inmsg->hdr.flags.response_expected == 1) {
686 pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), GFP_KERNEL);
692 memcpy(pmsg_hdr, &inmsg->hdr,
693 sizeof(struct controlvm_message_header));
694 bus_info->pending_msg_hdr = pmsg_hdr;
697 /* Response will be handled by visorbus_remove_instance */
698 visorbus_remove_instance(bus_info);
702 if (inmsg->hdr.flags.response_expected == 1)
703 controlvm_responder(inmsg->hdr.id, &inmsg->hdr, err);
707 static int visorbus_configure(struct controlvm_message *inmsg,
708 struct parser_context *parser_ctx)
710 struct controlvm_message_packet *cmd = &inmsg->cmd;
712 struct visor_device *bus_info;
715 bus_no = cmd->configure_bus.bus_no;
716 bus_info = visorbus_get_device_by_id(bus_no, BUS_ROOT_DEVICE, NULL);
720 } else if (bus_info->state.created == 0) {
723 } else if (bus_info->pending_msg_hdr) {
728 err = visorchannel_set_clientpartition
729 (bus_info->visorchannel,
730 cmd->configure_bus.guest_handle);
735 const guid_t *partition_guid = parser_id_get(parser_ctx);
737 guid_copy(&bus_info->partition_guid, partition_guid);
738 bus_info->name = parser_name_get(parser_ctx);
741 if (inmsg->hdr.flags.response_expected == 1)
742 controlvm_responder(inmsg->hdr.id, &inmsg->hdr, err);
746 dev_err(&chipset_dev->acpi_device->dev,
747 "%s exited with err: %d\n", __func__, err);
748 if (inmsg->hdr.flags.response_expected == 1)
749 controlvm_responder(inmsg->hdr.id, &inmsg->hdr, err);
753 static int visorbus_device_create(struct controlvm_message *inmsg)
755 struct controlvm_message_packet *cmd = &inmsg->cmd;
756 struct controlvm_message_header *pmsg_hdr = NULL;
757 u32 bus_no = cmd->create_device.bus_no;
758 u32 dev_no = cmd->create_device.dev_no;
759 struct visor_device *dev_info = NULL;
760 struct visor_device *bus_info;
761 struct visorchannel *visorchannel;
764 bus_info = visorbus_get_device_by_id(bus_no, BUS_ROOT_DEVICE, NULL);
766 dev_err(&chipset_dev->acpi_device->dev,
767 "failed to get bus by id: %d\n", bus_no);
771 if (bus_info->state.created == 0) {
772 dev_err(&chipset_dev->acpi_device->dev,
773 "bus not created, id: %d\n", bus_no);
778 dev_info = visorbus_get_device_by_id(bus_no, dev_no, NULL);
779 if (dev_info && (dev_info->state.created == 1)) {
780 dev_err(&chipset_dev->acpi_device->dev,
781 "failed to get bus by id: %d/%d\n", bus_no, dev_no);
786 dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
792 dev_info->chipset_bus_no = bus_no;
793 dev_info->chipset_dev_no = dev_no;
794 guid_copy(&dev_info->inst, &cmd->create_device.dev_inst_guid);
796 /* not sure where the best place to set the 'parent' */
797 dev_info->device.parent = &bus_info->device;
800 visorchannel_create_with_lock(cmd->create_device.channel_addr,
801 cmd->create_device.channel_bytes,
803 &cmd->create_device.data_type_guid);
805 dev_err(&chipset_dev->acpi_device->dev,
806 "failed to create visorchannel: %d/%d\n",
809 goto err_free_dev_info;
811 dev_info->visorchannel = visorchannel;
812 guid_copy(&dev_info->channel_type_guid, &cmd->create_device.data_type_guid);
813 if (guid_equal(&cmd->create_device.data_type_guid, &visor_vhba_channel_guid)) {
814 err = save_crash_message(inmsg, CRASH_DEV);
816 goto err_destroy_visorchannel;
819 if (inmsg->hdr.flags.response_expected == 1) {
820 pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), GFP_KERNEL);
823 goto err_destroy_visorchannel;
826 memcpy(pmsg_hdr, &inmsg->hdr,
827 sizeof(struct controlvm_message_header));
828 dev_info->pending_msg_hdr = pmsg_hdr;
830 /* create_visor_device will send response */
831 err = create_visor_device(dev_info);
833 goto err_destroy_visorchannel;
837 err_destroy_visorchannel:
838 visorchannel_destroy(visorchannel);
844 if (inmsg->hdr.flags.response_expected == 1)
845 controlvm_responder(inmsg->hdr.id, &inmsg->hdr, err);
849 static int visorbus_device_changestate(struct controlvm_message *inmsg)
851 struct controlvm_message_packet *cmd = &inmsg->cmd;
852 struct controlvm_message_header *pmsg_hdr = NULL;
853 u32 bus_no = cmd->device_change_state.bus_no;
854 u32 dev_no = cmd->device_change_state.dev_no;
855 struct visor_segment_state state = cmd->device_change_state.state;
856 struct visor_device *dev_info;
859 dev_info = visorbus_get_device_by_id(bus_no, dev_no, NULL);
864 if (dev_info->state.created == 0) {
868 if (dev_info->pending_msg_hdr) {
869 /* only non-NULL if dev is still waiting on a response */
873 if (inmsg->hdr.flags.response_expected == 1) {
874 pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), GFP_KERNEL);
880 memcpy(pmsg_hdr, &inmsg->hdr,
881 sizeof(struct controlvm_message_header));
882 dev_info->pending_msg_hdr = pmsg_hdr;
885 if (state.alive == segment_state_running.alive &&
886 state.operating == segment_state_running.operating)
887 /* Response will be sent from visorchipset_device_resume */
888 err = visorchipset_device_resume(dev_info);
889 /* ServerNotReady / ServerLost / SegmentStateStandby */
890 else if (state.alive == segment_state_standby.alive &&
891 state.operating == segment_state_standby.operating)
893 * technically this is standby case where server is lost.
894 * Response will be sent from visorchipset_device_pause.
896 err = visorchipset_device_pause(dev_info);
903 dev_err(&chipset_dev->acpi_device->dev, "failed: %d\n", err);
904 if (inmsg->hdr.flags.response_expected == 1)
905 controlvm_responder(inmsg->hdr.id, &inmsg->hdr, err);
909 static int visorbus_device_destroy(struct controlvm_message *inmsg)
911 struct controlvm_message_packet *cmd = &inmsg->cmd;
912 struct controlvm_message_header *pmsg_hdr = NULL;
913 u32 bus_no = cmd->destroy_device.bus_no;
914 u32 dev_no = cmd->destroy_device.dev_no;
915 struct visor_device *dev_info;
918 dev_info = visorbus_get_device_by_id(bus_no, dev_no, NULL);
923 if (dev_info->state.created == 0) {
927 if (dev_info->pending_msg_hdr) {
928 /* only non-NULL if dev is still waiting on a response */
932 if (inmsg->hdr.flags.response_expected == 1) {
933 pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), GFP_KERNEL);
939 memcpy(pmsg_hdr, &inmsg->hdr,
940 sizeof(struct controlvm_message_header));
941 dev_info->pending_msg_hdr = pmsg_hdr;
944 kfree(dev_info->name);
945 remove_visor_device(dev_info);
949 if (inmsg->hdr.flags.response_expected == 1)
950 controlvm_responder(inmsg->hdr.id, &inmsg->hdr, err);
955 * The general parahotplug flow works as follows. The visorchipset receives
956 * a DEVICE_CHANGESTATE message from Command specifying a physical device
957 * to enable or disable. The CONTROLVM message handler calls
958 * parahotplug_process_message, which then adds the message to a global list
959 * and kicks off a udev event which causes a user level script to enable or
960 * disable the specified device. The udev script then writes to
961 * /sys/devices/platform/visorchipset/parahotplug, which causes the
962 * parahotplug store functions to get called, at which point the
963 * appropriate CONTROLVM message is retrieved from the list and responded to.
966 #define PARAHOTPLUG_TIMEOUT_MS 2000
969 * parahotplug_next_id() - generate unique int to match an outstanding
970 * CONTROLVM message with a udev script /sys
973 * Return: a unique integer value
975 static int parahotplug_next_id(void)
977 static atomic_t id = ATOMIC_INIT(0);
979 return atomic_inc_return(&id);
983 * parahotplug_next_expiration() - returns the time (in jiffies) when a
984 * CONTROLVM message on the list should expire
985 * -- PARAHOTPLUG_TIMEOUT_MS in the future
987 * Return: expected expiration time (in jiffies)
989 static unsigned long parahotplug_next_expiration(void)
991 return jiffies + msecs_to_jiffies(PARAHOTPLUG_TIMEOUT_MS);
995 * parahotplug_request_create() - create a parahotplug_request, which is
996 * basically a wrapper for a CONTROLVM_MESSAGE
997 * that we can stick on a list
998 * @msg: the message to insert in the request
1000 * Return: the request containing the provided message
1002 static struct parahotplug_request *parahotplug_request_create(
1003 struct controlvm_message *msg)
1005 struct parahotplug_request *req;
1007 req = kmalloc(sizeof(*req), GFP_KERNEL);
1011 req->id = parahotplug_next_id();
1012 req->expiration = parahotplug_next_expiration();
1019 * parahotplug_request_destroy() - free a parahotplug_request
1020 * @req: the request to deallocate
1022 static void parahotplug_request_destroy(struct parahotplug_request *req)
1027 static LIST_HEAD(parahotplug_request_list);
1028 /* lock for above */
1029 static DEFINE_SPINLOCK(parahotplug_request_list_lock);
1032 * parahotplug_request_complete() - mark request as complete
1033 * @id: the id of the request
1034 * @active: indicates whether the request is assigned to active partition
1036 * Called from the /sys handler, which means the user script has
1037 * finished the enable/disable. Find the matching identifier, and
1038 * respond to the CONTROLVM message with success.
1040 * Return: 0 on success or -EINVAL on failure
1042 static int parahotplug_request_complete(int id, u16 active)
1044 struct list_head *pos;
1045 struct list_head *tmp;
1047 spin_lock(¶hotplug_request_list_lock);
1049 /* Look for a request matching "id". */
1050 list_for_each_safe(pos, tmp, ¶hotplug_request_list) {
1051 struct parahotplug_request *req =
1052 list_entry(pos, struct parahotplug_request, list);
1053 if (req->id == id) {
1055 * Found a match. Remove it from the list and
1059 spin_unlock(¶hotplug_request_list_lock);
1060 req->msg.cmd.device_change_state.state.active = active;
1061 if (req->msg.hdr.flags.response_expected)
1063 &req->msg.hdr, CONTROLVM_RESP_SUCCESS,
1064 &req->msg.cmd.device_change_state.state);
1065 parahotplug_request_destroy(req);
1070 spin_unlock(¶hotplug_request_list_lock);
1075 * devicedisabled_store() - disables the hotplug device
1076 * @dev: sysfs interface variable not utilized in this function
1077 * @attr: sysfs interface variable not utilized in this function
1078 * @buf: buffer containing the device id
1079 * @count: the size of the buffer
1081 * The parahotplug/devicedisabled interface gets called by our support script
1082 * when an SR-IOV device has been shut down. The ID is passed to the script
1083 * and then passed back when the device has been removed.
1085 * Return: the size of the buffer for success or negative for error
1087 static ssize_t devicedisabled_store(struct device *dev,
1088 struct device_attribute *attr,
1089 const char *buf, size_t count)
1094 if (kstrtouint(buf, 10, &id))
1097 err = parahotplug_request_complete(id, 0);
1102 static DEVICE_ATTR_WO(devicedisabled);
1105 * deviceenabled_store() - enables the hotplug device
1106 * @dev: sysfs interface variable not utilized in this function
1107 * @attr: sysfs interface variable not utilized in this function
1108 * @buf: buffer containing the device id
1109 * @count: the size of the buffer
1111 * The parahotplug/deviceenabled interface gets called by our support script
1112 * when an SR-IOV device has been recovered. The ID is passed to the script
1113 * and then passed back when the device has been brought back up.
1115 * Return: the size of the buffer for success or negative for error
1117 static ssize_t deviceenabled_store(struct device *dev,
1118 struct device_attribute *attr,
1119 const char *buf, size_t count)
1123 if (kstrtouint(buf, 10, &id))
1126 parahotplug_request_complete(id, 1);
1129 static DEVICE_ATTR_WO(deviceenabled);
1131 static struct attribute *visorchipset_install_attrs[] = {
1132 &dev_attr_toolaction.attr,
1133 &dev_attr_boottotool.attr,
1134 &dev_attr_error.attr,
1135 &dev_attr_textid.attr,
1136 &dev_attr_remaining_steps.attr,
1140 static const struct attribute_group visorchipset_install_group = {
1142 .attrs = visorchipset_install_attrs
1145 static struct attribute *visorchipset_parahotplug_attrs[] = {
1146 &dev_attr_devicedisabled.attr,
1147 &dev_attr_deviceenabled.attr,
1151 static const struct attribute_group visorchipset_parahotplug_group = {
1152 .name = "parahotplug",
1153 .attrs = visorchipset_parahotplug_attrs
1156 static const struct attribute_group *visorchipset_dev_groups[] = {
1157 &visorchipset_install_group,
1158 &visorchipset_parahotplug_group,
1163 * parahotplug_request_kickoff() - initiate parahotplug request
1164 * @req: the request to initiate
1166 * Cause uevent to run the user level script to do the disable/enable specified
1167 * in the parahotplug_request.
1169 static int parahotplug_request_kickoff(struct parahotplug_request *req)
1171 struct controlvm_message_packet *cmd = &req->msg.cmd;
1172 char env_cmd[40], env_id[40], env_state[40], env_bus[40], env_dev[40],
1175 env_cmd, env_id, env_state, env_bus, env_dev, env_func, NULL
1178 sprintf(env_cmd, "VISOR_PARAHOTPLUG=1");
1179 sprintf(env_id, "VISOR_PARAHOTPLUG_ID=%d", req->id);
1180 sprintf(env_state, "VISOR_PARAHOTPLUG_STATE=%d",
1181 cmd->device_change_state.state.active);
1182 sprintf(env_bus, "VISOR_PARAHOTPLUG_BUS=%d",
1183 cmd->device_change_state.bus_no);
1184 sprintf(env_dev, "VISOR_PARAHOTPLUG_DEVICE=%d",
1185 cmd->device_change_state.dev_no >> 3);
1186 sprintf(env_func, "VISOR_PARAHOTPLUG_FUNCTION=%d",
1187 cmd->device_change_state.dev_no & 0x7);
1189 return kobject_uevent_env(&chipset_dev->acpi_device->dev.kobj,
1194 * parahotplug_process_message() - enables or disables a PCI device by kicking
1196 * @inmsg: the message indicating whether to enable or disable
1198 static int parahotplug_process_message(struct controlvm_message *inmsg)
1200 struct parahotplug_request *req;
1203 req = parahotplug_request_create(inmsg);
1208 * For enable messages, just respond with success right away, we don't
1209 * need to wait to see if the enable was successful.
1211 if (inmsg->cmd.device_change_state.state.active) {
1212 err = parahotplug_request_kickoff(req);
1215 controlvm_respond(&inmsg->hdr, CONTROLVM_RESP_SUCCESS,
1216 &inmsg->cmd.device_change_state.state);
1217 parahotplug_request_destroy(req);
1222 * For disable messages, add the request to the
1223 * request list before kicking off the udev script. It
1224 * won't get responded to until the script has
1225 * indicated it's done.
1227 spin_lock(¶hotplug_request_list_lock);
1228 list_add_tail(&req->list, ¶hotplug_request_list);
1229 spin_unlock(¶hotplug_request_list_lock);
1231 err = parahotplug_request_kickoff(req);
1237 controlvm_respond(&inmsg->hdr, err,
1238 &inmsg->cmd.device_change_state.state);
1243 * chipset_ready_uevent() - sends chipset_ready action
1245 * Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset.
1247 * Return: 0 on success, negative on failure
1249 static int chipset_ready_uevent(struct controlvm_message_header *msg_hdr)
1253 res = kobject_uevent(&chipset_dev->acpi_device->dev.kobj,
1256 if (msg_hdr->flags.response_expected)
1257 controlvm_respond(msg_hdr, res, NULL);
1263 * chipset_selftest_uevent() - sends chipset_selftest action
1265 * Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset.
1267 * Return: 0 on success, negative on failure
1269 static int chipset_selftest_uevent(struct controlvm_message_header *msg_hdr)
1271 char env_selftest[20];
1272 char *envp[] = { env_selftest, NULL };
1275 sprintf(env_selftest, "SPARSP_SELFTEST=%d", 1);
1276 res = kobject_uevent_env(&chipset_dev->acpi_device->dev.kobj,
1279 if (msg_hdr->flags.response_expected)
1280 controlvm_respond(msg_hdr, res, NULL);
1286 * chipset_notready_uevent() - sends chipset_notready action
1288 * Send ACTION=offline for DEVPATH=/sys/devices/platform/visorchipset.
1290 * Return: 0 on success, negative on failure
1292 static int chipset_notready_uevent(struct controlvm_message_header *msg_hdr)
1294 int res = kobject_uevent(&chipset_dev->acpi_device->dev.kobj,
1297 if (msg_hdr->flags.response_expected)
1298 controlvm_respond(msg_hdr, res, NULL);
1303 static int unisys_vmcall(unsigned long tuple, unsigned long param)
1306 unsigned int cpuid_eax, cpuid_ebx, cpuid_ecx, cpuid_edx;
1307 unsigned long reg_ebx;
1308 unsigned long reg_ecx;
1310 reg_ebx = param & 0xFFFFFFFF;
1311 reg_ecx = param >> 32;
1313 cpuid(0x00000001, &cpuid_eax, &cpuid_ebx, &cpuid_ecx, &cpuid_edx);
1314 if (!(cpuid_ecx & 0x80000000))
1317 __asm__ __volatile__(".byte 0x00f, 0x001, 0x0c1" : "=a"(result) :
1318 "a"(tuple), "b"(reg_ebx), "c"(reg_ecx));
1323 /* Need to convert from VMCALL error codes to Linux */
1326 case VMCALL_RESULT_INVALID_PARAM:
1328 case VMCALL_RESULT_DATA_UNAVAILABLE:
1335 static unsigned int issue_vmcall_io_controlvm_addr(u64 *control_addr,
1341 physaddr = virt_to_phys(&chipset_dev->controlvm_params);
1342 err = unisys_vmcall(VMCALL_CONTROLVM_ADDR, physaddr);
1346 *control_addr = chipset_dev->controlvm_params.address;
1347 *control_bytes = chipset_dev->controlvm_params.channel_bytes;
1352 static u64 controlvm_get_channel_address(void)
1357 if (issue_vmcall_io_controlvm_addr(&addr, &size))
1363 static void setup_crash_devices_work_queue(struct work_struct *work)
1365 struct controlvm_message local_crash_bus_msg;
1366 struct controlvm_message local_crash_dev_msg;
1367 struct controlvm_message msg;
1368 u32 local_crash_msg_offset;
1369 u16 local_crash_msg_count;
1371 /* send init chipset msg */
1372 msg.hdr.id = CONTROLVM_CHIPSET_INIT;
1373 msg.cmd.init_chipset.bus_count = 23;
1374 msg.cmd.init_chipset.switch_count = 0;
1378 /* get saved message count */
1379 if (visorchannel_read(chipset_dev->controlvm_channel,
1380 offsetof(struct visor_controlvm_channel,
1381 saved_crash_message_count),
1382 &local_crash_msg_count, sizeof(u16)) < 0) {
1383 dev_err(&chipset_dev->acpi_device->dev,
1384 "failed to read channel\n");
1388 if (local_crash_msg_count != CONTROLVM_CRASHMSG_MAX) {
1389 dev_err(&chipset_dev->acpi_device->dev,
1394 /* get saved crash message offset */
1395 if (visorchannel_read(chipset_dev->controlvm_channel,
1396 offsetof(struct visor_controlvm_channel,
1397 saved_crash_message_offset),
1398 &local_crash_msg_offset, sizeof(u32)) < 0) {
1399 dev_err(&chipset_dev->acpi_device->dev,
1400 "failed to read channel\n");
1404 /* read create device message for storage bus offset */
1405 if (visorchannel_read(chipset_dev->controlvm_channel,
1406 local_crash_msg_offset,
1407 &local_crash_bus_msg,
1408 sizeof(struct controlvm_message)) < 0) {
1409 dev_err(&chipset_dev->acpi_device->dev,
1410 "failed to read channel\n");
1414 /* read create device message for storage device */
1415 if (visorchannel_read(chipset_dev->controlvm_channel,
1416 local_crash_msg_offset +
1417 sizeof(struct controlvm_message),
1418 &local_crash_dev_msg,
1419 sizeof(struct controlvm_message)) < 0) {
1420 dev_err(&chipset_dev->acpi_device->dev,
1421 "failed to read channel\n");
1425 /* reuse IOVM create bus message */
1426 if (!local_crash_bus_msg.cmd.create_bus.channel_addr) {
1427 dev_err(&chipset_dev->acpi_device->dev,
1428 "no valid create_bus message\n");
1431 visorbus_create(&local_crash_bus_msg);
1433 /* reuse create device message for storage device */
1434 if (!local_crash_dev_msg.cmd.create_device.channel_addr) {
1435 dev_err(&chipset_dev->acpi_device->dev,
1436 "no valid create_device message\n");
1439 visorbus_device_create(&local_crash_dev_msg);
1442 void visorbus_response(struct visor_device *bus_info, int response,
1445 controlvm_responder(controlvm_id, bus_info->pending_msg_hdr, response);
1447 kfree(bus_info->pending_msg_hdr);
1448 bus_info->pending_msg_hdr = NULL;
1451 void visorbus_device_changestate_response(struct visor_device *dev_info,
1453 struct visor_segment_state state)
1455 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE,
1456 dev_info, response, state);
1458 kfree(dev_info->pending_msg_hdr);
1459 dev_info->pending_msg_hdr = NULL;
1462 static struct parser_context *parser_init_byte_stream(u64 addr, u32 bytes,
1465 int allocbytes = sizeof(struct parser_context) + bytes;
1466 struct parser_context *ctx;
1472 * alloc an 0 extra byte to ensure payload is
1476 if ((chipset_dev->controlvm_payload_bytes_buffered + bytes)
1477 > MAX_CONTROLVM_PAYLOAD_BYTES) {
1481 ctx = kzalloc(allocbytes, GFP_KERNEL);
1487 ctx->allocbytes = allocbytes;
1488 ctx->param_bytes = bytes;
1490 ctx->bytes_remaining = 0;
1491 ctx->byte_stream = false;
1492 mapping = memremap(addr, bytes, MEMREMAP_WB);
1494 goto err_finish_ctx;
1495 memcpy(ctx->data, mapping, bytes);
1497 ctx->byte_stream = true;
1498 chipset_dev->controlvm_payload_bytes_buffered += ctx->param_bytes;
1508 * handle_command() - process a controlvm message
1509 * @inmsg: the message to process
1510 * @channel_addr: address of the controlvm channel
1513 * 0 - Successfully processed the message
1514 * -EAGAIN - ControlVM message was not processed and should be retried
1515 * reading the next controlvm message; a scenario where this can
1516 * occur is when we need to throttle the allocation of memory in
1517 * which to copy out controlvm payload data.
1518 * < 0 - error: ControlVM message was processed but an error occurred.
1520 static int handle_command(struct controlvm_message inmsg, u64 channel_addr)
1522 struct controlvm_message_packet *cmd = &inmsg.cmd;
1525 struct parser_context *parser_ctx = NULL;
1526 struct controlvm_message ackmsg;
1529 /* create parsing context if necessary */
1530 parm_addr = channel_addr + inmsg.hdr.payload_vm_offset;
1531 parm_bytes = inmsg.hdr.payload_bytes;
1534 * Parameter and channel addresses within test messages actually lie
1535 * within our OS-controlled memory. We need to know that, because it
1536 * makes a difference in how we compute the virtual address.
1538 if (parm_addr && parm_bytes) {
1542 parser_init_byte_stream(parm_addr, parm_bytes, &retry);
1543 if (!parser_ctx && retry)
1546 controlvm_init_response(&ackmsg, &inmsg.hdr, CONTROLVM_RESP_SUCCESS);
1547 err = visorchannel_signalinsert(chipset_dev->controlvm_channel,
1548 CONTROLVM_QUEUE_ACK, &ackmsg);
1552 switch (inmsg.hdr.id) {
1553 case CONTROLVM_CHIPSET_INIT:
1554 err = chipset_init(&inmsg);
1556 case CONTROLVM_BUS_CREATE:
1557 err = visorbus_create(&inmsg);
1559 case CONTROLVM_BUS_DESTROY:
1560 err = visorbus_destroy(&inmsg);
1562 case CONTROLVM_BUS_CONFIGURE:
1563 err = visorbus_configure(&inmsg, parser_ctx);
1565 case CONTROLVM_DEVICE_CREATE:
1566 err = visorbus_device_create(&inmsg);
1568 case CONTROLVM_DEVICE_CHANGESTATE:
1569 if (cmd->device_change_state.flags.phys_device) {
1570 err = parahotplug_process_message(&inmsg);
1573 * save the hdr and cmd structures for later use
1574 * when sending back the response to Command
1576 err = visorbus_device_changestate(&inmsg);
1580 case CONTROLVM_DEVICE_DESTROY:
1581 err = visorbus_device_destroy(&inmsg);
1583 case CONTROLVM_DEVICE_CONFIGURE:
1584 /* no op just send a respond that we passed */
1585 if (inmsg.hdr.flags.response_expected)
1586 controlvm_respond(&inmsg.hdr, CONTROLVM_RESP_SUCCESS,
1589 case CONTROLVM_CHIPSET_READY:
1590 err = chipset_ready_uevent(&inmsg.hdr);
1592 case CONTROLVM_CHIPSET_SELFTEST:
1593 err = chipset_selftest_uevent(&inmsg.hdr);
1595 case CONTROLVM_CHIPSET_STOP:
1596 err = chipset_notready_uevent(&inmsg.hdr);
1600 if (inmsg.hdr.flags.response_expected)
1601 controlvm_respond(&inmsg.hdr,
1602 -CONTROLVM_RESP_ID_UNKNOWN, NULL);
1607 parser_done(parser_ctx);
1614 * read_controlvm_event() - retreives the next message from the
1615 * CONTROLVM_QUEUE_EVENT queue in the controlvm
1617 * @msg: pointer to the retrieved message
1619 * Return: 0 if valid message was retrieved or -error
1621 static int read_controlvm_event(struct controlvm_message *msg)
1623 int err = visorchannel_signalremove(chipset_dev->controlvm_channel,
1624 CONTROLVM_QUEUE_EVENT, msg);
1629 if (msg->hdr.flags.test_message == 1)
1636 * parahotplug_process_list() - remove any request from the list that's been on
1637 * there too long and respond with an error
1639 static void parahotplug_process_list(void)
1641 struct list_head *pos;
1642 struct list_head *tmp;
1644 spin_lock(¶hotplug_request_list_lock);
1646 list_for_each_safe(pos, tmp, ¶hotplug_request_list) {
1647 struct parahotplug_request *req =
1648 list_entry(pos, struct parahotplug_request, list);
1650 if (!time_after_eq(jiffies, req->expiration))
1654 if (req->msg.hdr.flags.response_expected)
1657 CONTROLVM_RESP_DEVICE_UDEV_TIMEOUT,
1658 &req->msg.cmd.device_change_state.state);
1659 parahotplug_request_destroy(req);
1662 spin_unlock(¶hotplug_request_list_lock);
1665 static void controlvm_periodic_work(struct work_struct *work)
1667 struct controlvm_message inmsg;
1671 /* Drain the RESPONSE queue make it empty */
1673 err = visorchannel_signalremove(chipset_dev->controlvm_channel,
1674 CONTROLVM_QUEUE_RESPONSE,
1676 } while ((!err) && (++count < CONTROLVM_MESSAGE_MAX));
1681 if (chipset_dev->controlvm_pending_msg_valid) {
1683 * we throttled processing of a prior
1684 * msg, so try to process it again
1685 * rather than reading a new one
1687 inmsg = chipset_dev->controlvm_pending_msg;
1688 chipset_dev->controlvm_pending_msg_valid = false;
1691 err = read_controlvm_event(&inmsg);
1695 chipset_dev->most_recent_message_jiffies = jiffies;
1696 err = handle_command(inmsg,
1697 visorchannel_get_physaddr
1698 (chipset_dev->controlvm_channel));
1699 if (err == -EAGAIN) {
1700 chipset_dev->controlvm_pending_msg = inmsg;
1701 chipset_dev->controlvm_pending_msg_valid = true;
1705 err = read_controlvm_event(&inmsg);
1708 /* parahotplug_worker */
1709 parahotplug_process_list();
1712 * The controlvm messages are sent in a bulk. If we start receiving messages, we
1713 * want the polling to be fast. If we do not receive any message for
1714 * MIN_IDLE_SECONDS, we can slow down the polling.
1717 if (time_after(jiffies, chipset_dev->most_recent_message_jiffies +
1718 (HZ * MIN_IDLE_SECONDS))) {
1720 * it's been longer than MIN_IDLE_SECONDS since we
1721 * processed our last controlvm message; slow down the
1724 if (chipset_dev->poll_jiffies !=
1725 POLLJIFFIES_CONTROLVMCHANNEL_SLOW)
1726 chipset_dev->poll_jiffies =
1727 POLLJIFFIES_CONTROLVMCHANNEL_SLOW;
1729 if (chipset_dev->poll_jiffies !=
1730 POLLJIFFIES_CONTROLVMCHANNEL_FAST)
1731 chipset_dev->poll_jiffies =
1732 POLLJIFFIES_CONTROLVMCHANNEL_FAST;
1735 schedule_delayed_work(&chipset_dev->periodic_controlvm_work,
1736 chipset_dev->poll_jiffies);
1739 static int visorchipset_init(struct acpi_device *acpi_device)
1743 struct visorchannel *controlvm_channel;
1745 chipset_dev = kzalloc(sizeof(*chipset_dev), GFP_KERNEL);
1749 addr = controlvm_get_channel_address();
1753 acpi_device->driver_data = chipset_dev;
1754 chipset_dev->acpi_device = acpi_device;
1755 chipset_dev->poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST;
1756 controlvm_channel = visorchannel_create_with_lock(addr, 0, GFP_KERNEL,
1757 &visor_controlvm_channel_guid);
1758 if (!controlvm_channel)
1759 goto error_free_chipset_dev;
1761 chipset_dev->controlvm_channel = controlvm_channel;
1763 err = sysfs_create_groups(&chipset_dev->acpi_device->dev.kobj,
1764 visorchipset_dev_groups);
1766 goto error_destroy_channel;
1768 if (!visor_check_channel(visorchannel_get_header(controlvm_channel),
1769 &visor_controlvm_channel_guid,
1771 sizeof(struct visor_controlvm_channel),
1772 VISOR_CONTROLVM_CHANNEL_VERSIONID,
1773 VISOR_CHANNEL_SIGNATURE))
1774 goto error_delete_groups;
1776 /* if booting in a crash kernel */
1777 if (is_kdump_kernel())
1778 INIT_DELAYED_WORK(&chipset_dev->periodic_controlvm_work,
1779 setup_crash_devices_work_queue);
1781 INIT_DELAYED_WORK(&chipset_dev->periodic_controlvm_work,
1782 controlvm_periodic_work);
1784 chipset_dev->most_recent_message_jiffies = jiffies;
1785 chipset_dev->poll_jiffies = POLLJIFFIES_CONTROLVMCHANNEL_FAST;
1786 schedule_delayed_work(&chipset_dev->periodic_controlvm_work,
1787 chipset_dev->poll_jiffies);
1789 err = visorbus_init();
1791 goto error_cancel_work;
1796 cancel_delayed_work_sync(&chipset_dev->periodic_controlvm_work);
1798 error_delete_groups:
1799 sysfs_remove_groups(&chipset_dev->acpi_device->dev.kobj,
1800 visorchipset_dev_groups);
1802 error_destroy_channel:
1803 visorchannel_destroy(chipset_dev->controlvm_channel);
1805 error_free_chipset_dev:
1809 dev_err(&acpi_device->dev, "failed with error %d\n", err);
1813 static int visorchipset_exit(struct acpi_device *acpi_device)
1816 cancel_delayed_work_sync(&chipset_dev->periodic_controlvm_work);
1817 sysfs_remove_groups(&chipset_dev->acpi_device->dev.kobj,
1818 visorchipset_dev_groups);
1820 visorchannel_destroy(chipset_dev->controlvm_channel);
1826 static const struct acpi_device_id unisys_device_ids[] = {
1831 static struct acpi_driver unisys_acpi_driver = {
1832 .name = "unisys_acpi",
1833 .class = "unisys_acpi_class",
1834 .owner = THIS_MODULE,
1835 .ids = unisys_device_ids,
1837 .add = visorchipset_init,
1838 .remove = visorchipset_exit,
1842 MODULE_DEVICE_TABLE(acpi, unisys_device_ids);
1844 static __init int visorutil_spar_detect(void)
1846 unsigned int eax, ebx, ecx, edx;
1848 if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) {
1850 cpuid(UNISYS_VISOR_LEAF_ID, &eax, &ebx, &ecx, &edx);
1851 return (ebx == UNISYS_VISOR_ID_EBX) &&
1852 (ecx == UNISYS_VISOR_ID_ECX) &&
1853 (edx == UNISYS_VISOR_ID_EDX);
1859 static int init_unisys(void)
1863 if (!visorutil_spar_detect())
1866 result = acpi_bus_register_driver(&unisys_acpi_driver);
1870 pr_info("Unisys Visorchipset Driver Loaded.\n");
1874 static void exit_unisys(void)
1876 acpi_bus_unregister_driver(&unisys_acpi_driver);
1879 module_init(init_unisys);
1880 module_exit(exit_unisys);
1882 MODULE_AUTHOR("Unisys");
1883 MODULE_LICENSE("GPL");
1884 MODULE_DESCRIPTION("s-Par visorbus driver for virtual device buses");