1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
7 #include <linux/acpi.h>
8 #include <linux/crash_dump.h>
9 #include <linux/visorbus.h>
11 #include "visorbus_private.h"
13 /* {72120008-4AAB-11DC-8530-444553544200} */
14 #define VISOR_SIOVM_GUID GUID_INIT(0x72120008, 0x4AAB, 0x11DC, 0x85, 0x30, \
15 0x44, 0x45, 0x53, 0x54, 0x42, 0x00)
17 static const guid_t visor_vhba_channel_guid
= VISOR_VHBA_CHANNEL_GUID
;
18 static const guid_t visor_siovm_guid
= VISOR_SIOVM_GUID
;
19 static const guid_t visor_controlvm_channel_guid
= VISOR_CONTROLVM_CHANNEL_GUID
;
21 #define POLLJIFFIES_CONTROLVM_FAST 1
22 #define POLLJIFFIES_CONTROLVM_SLOW 100
24 #define MAX_CONTROLVM_PAYLOAD_BYTES (1024 * 128)
26 #define UNISYS_VISOR_LEAF_ID 0x40000000
28 /* The s-Par leaf ID returns "UnisysSpar64" encoded across ebx, ecx, edx */
29 #define UNISYS_VISOR_ID_EBX 0x73696e55
30 #define UNISYS_VISOR_ID_ECX 0x70537379
31 #define UNISYS_VISOR_ID_EDX 0x34367261
34 * When the controlvm channel is idle for at least MIN_IDLE_SECONDS, we switch
35 * to slow polling mode. As soon as we get a controlvm message, we switch back
36 * to fast polling mode.
38 #define MIN_IDLE_SECONDS 10
40 struct parser_context
{
41 unsigned long allocbytes
;
42 unsigned long param_bytes
;
44 unsigned long bytes_remaining
;
46 struct visor_controlvm_parameters_header data
;
49 /* VMCALL_CONTROLVM_ADDR: Used by all guests, not just IO. */
50 #define VMCALL_CONTROLVM_ADDR 0x0501
53 VMCALL_RESULT_SUCCESS
= 0,
54 VMCALL_RESULT_INVALID_PARAM
= 1,
55 VMCALL_RESULT_DATA_UNAVAILABLE
= 2,
56 VMCALL_RESULT_FAILURE_UNAVAILABLE
= 3,
57 VMCALL_RESULT_DEVICE_ERROR
= 4,
58 VMCALL_RESULT_DEVICE_NOT_READY
= 5
62 * struct vmcall_io_controlvm_addr_params - Structure for IO VMCALLS. Has
63 * parameters to VMCALL_CONTROLVM_ADDR
65 * @address: The Guest-relative physical address of the ControlVm channel.
66 * This VMCall fills this in with the appropriate address.
67 * Contents provided by this VMCALL (OUT).
68 * @channel_bytes: The size of the ControlVm channel in bytes This VMCall fills
69 * this in with the appropriate address. Contents provided by
71 * @unused: Unused Bytes in the 64-Bit Aligned Struct.
73 struct vmcall_io_controlvm_addr_params
{
79 struct visorchipset_device
{
80 struct acpi_device
*acpi_device
;
81 unsigned long poll_jiffies
;
82 /* when we got our last controlvm message */
83 unsigned long most_recent_message_jiffies
;
84 struct delayed_work periodic_controlvm_work
;
85 struct visorchannel
*controlvm_channel
;
86 unsigned long controlvm_payload_bytes_buffered
;
88 * The following variables are used to handle the scenario where we are
89 * unable to offload the payload from a controlvm message due to memory
90 * requirements. In this scenario, we simply stash the controlvm
91 * message, then attempt to process it again the next time
92 * controlvm_periodic_work() runs.
94 struct controlvm_message controlvm_pending_msg
;
95 bool controlvm_pending_msg_valid
;
96 struct vmcall_io_controlvm_addr_params controlvm_params
;
99 static struct visorchipset_device
*chipset_dev
;
101 struct parahotplug_request
{
102 struct list_head list
;
104 unsigned long expiration
;
105 struct controlvm_message msg
;
108 /* prototypes for attributes */
109 static ssize_t
toolaction_show(struct device
*dev
,
110 struct device_attribute
*attr
,
116 err
= visorchannel_read(chipset_dev
->controlvm_channel
,
117 offsetof(struct visor_controlvm_channel
,
119 &tool_action
, sizeof(u8
));
122 return sprintf(buf
, "%u\n", tool_action
);
125 static ssize_t
toolaction_store(struct device
*dev
,
126 struct device_attribute
*attr
,
127 const char *buf
, size_t count
)
132 if (kstrtou8(buf
, 10, &tool_action
))
134 err
= visorchannel_write(chipset_dev
->controlvm_channel
,
135 offsetof(struct visor_controlvm_channel
,
137 &tool_action
, sizeof(u8
));
142 static DEVICE_ATTR_RW(toolaction
);
144 static ssize_t
boottotool_show(struct device
*dev
,
145 struct device_attribute
*attr
,
148 struct efi_visor_indication efi_visor_indication
;
151 err
= visorchannel_read(chipset_dev
->controlvm_channel
,
152 offsetof(struct visor_controlvm_channel
,
154 &efi_visor_indication
,
155 sizeof(struct efi_visor_indication
));
158 return sprintf(buf
, "%u\n", efi_visor_indication
.boot_to_tool
);
161 static ssize_t
boottotool_store(struct device
*dev
,
162 struct device_attribute
*attr
,
163 const char *buf
, size_t count
)
166 struct efi_visor_indication efi_visor_indication
;
168 if (kstrtoint(buf
, 10, &val
))
170 efi_visor_indication
.boot_to_tool
= val
;
171 err
= visorchannel_write(chipset_dev
->controlvm_channel
,
172 offsetof(struct visor_controlvm_channel
,
174 &(efi_visor_indication
),
175 sizeof(struct efi_visor_indication
));
180 static DEVICE_ATTR_RW(boottotool
);
182 static ssize_t
error_show(struct device
*dev
, struct device_attribute
*attr
,
188 err
= visorchannel_read(chipset_dev
->controlvm_channel
,
189 offsetof(struct visor_controlvm_channel
,
191 &error
, sizeof(u32
));
194 return sprintf(buf
, "%u\n", error
);
197 static ssize_t
error_store(struct device
*dev
, struct device_attribute
*attr
,
198 const char *buf
, size_t count
)
203 if (kstrtou32(buf
, 10, &error
))
205 err
= visorchannel_write(chipset_dev
->controlvm_channel
,
206 offsetof(struct visor_controlvm_channel
,
208 &error
, sizeof(u32
));
213 static DEVICE_ATTR_RW(error
);
215 static ssize_t
textid_show(struct device
*dev
, struct device_attribute
*attr
,
221 err
= visorchannel_read(chipset_dev
->controlvm_channel
,
222 offsetof(struct visor_controlvm_channel
,
223 installation_text_id
),
224 &text_id
, sizeof(u32
));
227 return sprintf(buf
, "%u\n", text_id
);
230 static ssize_t
textid_store(struct device
*dev
, struct device_attribute
*attr
,
231 const char *buf
, size_t count
)
236 if (kstrtou32(buf
, 10, &text_id
))
238 err
= visorchannel_write(chipset_dev
->controlvm_channel
,
239 offsetof(struct visor_controlvm_channel
,
240 installation_text_id
),
241 &text_id
, sizeof(u32
));
246 static DEVICE_ATTR_RW(textid
);
248 static ssize_t
remaining_steps_show(struct device
*dev
,
249 struct device_attribute
*attr
, char *buf
)
251 u16 remaining_steps
= 0;
254 err
= visorchannel_read(chipset_dev
->controlvm_channel
,
255 offsetof(struct visor_controlvm_channel
,
256 installation_remaining_steps
),
257 &remaining_steps
, sizeof(u16
));
260 return sprintf(buf
, "%hu\n", remaining_steps
);
263 static ssize_t
remaining_steps_store(struct device
*dev
,
264 struct device_attribute
*attr
,
265 const char *buf
, size_t count
)
270 if (kstrtou16(buf
, 10, &remaining_steps
))
272 err
= visorchannel_write(chipset_dev
->controlvm_channel
,
273 offsetof(struct visor_controlvm_channel
,
274 installation_remaining_steps
),
275 &remaining_steps
, sizeof(u16
));
280 static DEVICE_ATTR_RW(remaining_steps
);
282 static void controlvm_init_response(struct controlvm_message
*msg
,
283 struct controlvm_message_header
*msg_hdr
,
286 memset(msg
, 0, sizeof(struct controlvm_message
));
287 memcpy(&msg
->hdr
, msg_hdr
, sizeof(struct controlvm_message_header
));
288 msg
->hdr
.payload_bytes
= 0;
289 msg
->hdr
.payload_vm_offset
= 0;
290 msg
->hdr
.payload_max_bytes
= 0;
292 msg
->hdr
.flags
.failed
= 1;
293 msg
->hdr
.completion_status
= (u32
)(-response
);
297 static int controlvm_respond_chipset_init(
298 struct controlvm_message_header
*msg_hdr
,
300 enum visor_chipset_feature features
)
302 struct controlvm_message outmsg
;
304 controlvm_init_response(&outmsg
, msg_hdr
, response
);
305 outmsg
.cmd
.init_chipset
.features
= features
;
306 return visorchannel_signalinsert(chipset_dev
->controlvm_channel
,
307 CONTROLVM_QUEUE_REQUEST
, &outmsg
);
310 static int chipset_init(struct controlvm_message
*inmsg
)
312 static int chipset_inited
;
313 enum visor_chipset_feature features
= 0;
314 int rc
= CONTROLVM_RESP_SUCCESS
;
317 if (chipset_inited
) {
318 rc
= -CONTROLVM_RESP_ALREADY_DONE
;
324 * Set features to indicate we support parahotplug (if Command also
325 * supports it). Set the "reply" bit so Command knows this is a
326 * features-aware driver.
328 features
= inmsg
->cmd
.init_chipset
.features
&
329 VISOR_CHIPSET_FEATURE_PARA_HOTPLUG
;
330 features
|= VISOR_CHIPSET_FEATURE_REPLY
;
333 if (inmsg
->hdr
.flags
.response_expected
)
334 res
= controlvm_respond_chipset_init(&inmsg
->hdr
, rc
, features
);
339 static int controlvm_respond(struct controlvm_message_header
*msg_hdr
,
340 int response
, struct visor_segment_state
*state
)
342 struct controlvm_message outmsg
;
344 controlvm_init_response(&outmsg
, msg_hdr
, response
);
345 if (outmsg
.hdr
.flags
.test_message
== 1)
348 outmsg
.cmd
.device_change_state
.state
= *state
;
349 outmsg
.cmd
.device_change_state
.flags
.phys_device
= 1;
351 return visorchannel_signalinsert(chipset_dev
->controlvm_channel
,
352 CONTROLVM_QUEUE_REQUEST
, &outmsg
);
355 enum crash_obj_type
{
360 static int save_crash_message(struct controlvm_message
*msg
,
361 enum crash_obj_type cr_type
)
363 u32 local_crash_msg_offset
;
364 u16 local_crash_msg_count
;
367 err
= visorchannel_read(chipset_dev
->controlvm_channel
,
368 offsetof(struct visor_controlvm_channel
,
369 saved_crash_message_count
),
370 &local_crash_msg_count
, sizeof(u16
));
372 dev_err(&chipset_dev
->acpi_device
->dev
,
373 "failed to read message count\n");
376 if (local_crash_msg_count
!= CONTROLVM_CRASHMSG_MAX
) {
377 dev_err(&chipset_dev
->acpi_device
->dev
,
378 "invalid number of messages\n");
381 err
= visorchannel_read(chipset_dev
->controlvm_channel
,
382 offsetof(struct visor_controlvm_channel
,
383 saved_crash_message_offset
),
384 &local_crash_msg_offset
, sizeof(u32
));
386 dev_err(&chipset_dev
->acpi_device
->dev
,
387 "failed to read offset\n");
392 local_crash_msg_offset
+= sizeof(struct controlvm_message
);
393 err
= visorchannel_write(chipset_dev
->controlvm_channel
,
394 local_crash_msg_offset
, msg
,
395 sizeof(struct controlvm_message
));
397 dev_err(&chipset_dev
->acpi_device
->dev
,
398 "failed to write dev msg\n");
403 err
= visorchannel_write(chipset_dev
->controlvm_channel
,
404 local_crash_msg_offset
, msg
,
405 sizeof(struct controlvm_message
));
407 dev_err(&chipset_dev
->acpi_device
->dev
,
408 "failed to write bus msg\n");
413 dev_err(&chipset_dev
->acpi_device
->dev
,
414 "Invalid crash_obj_type\n");
420 static int controlvm_responder(enum controlvm_id cmd_id
,
421 struct controlvm_message_header
*pending_msg_hdr
,
424 if (pending_msg_hdr
->id
!= (u32
)cmd_id
)
427 return controlvm_respond(pending_msg_hdr
, response
, NULL
);
430 static int device_changestate_responder(enum controlvm_id cmd_id
,
431 struct visor_device
*p
, int response
,
432 struct visor_segment_state state
)
434 struct controlvm_message outmsg
;
436 if (p
->pending_msg_hdr
->id
!= cmd_id
)
439 controlvm_init_response(&outmsg
, p
->pending_msg_hdr
, response
);
440 outmsg
.cmd
.device_change_state
.bus_no
= p
->chipset_bus_no
;
441 outmsg
.cmd
.device_change_state
.dev_no
= p
->chipset_dev_no
;
442 outmsg
.cmd
.device_change_state
.state
= state
;
443 return visorchannel_signalinsert(chipset_dev
->controlvm_channel
,
444 CONTROLVM_QUEUE_REQUEST
, &outmsg
);
447 static int visorbus_create(struct controlvm_message
*inmsg
)
449 struct controlvm_message_packet
*cmd
= &inmsg
->cmd
;
450 struct controlvm_message_header
*pmsg_hdr
;
451 u32 bus_no
= cmd
->create_bus
.bus_no
;
452 struct visor_device
*bus_info
;
453 struct visorchannel
*visorchannel
;
456 bus_info
= visorbus_get_device_by_id(bus_no
, BUS_ROOT_DEVICE
, NULL
);
457 if (bus_info
&& bus_info
->state
.created
== 1) {
458 dev_err(&chipset_dev
->acpi_device
->dev
,
459 "failed %s: already exists\n", __func__
);
463 bus_info
= kzalloc(sizeof(*bus_info
), GFP_KERNEL
);
468 INIT_LIST_HEAD(&bus_info
->list_all
);
469 bus_info
->chipset_bus_no
= bus_no
;
470 bus_info
->chipset_dev_no
= BUS_ROOT_DEVICE
;
471 if (guid_equal(&cmd
->create_bus
.bus_inst_guid
, &visor_siovm_guid
)) {
472 err
= save_crash_message(inmsg
, CRASH_BUS
);
474 goto err_free_bus_info
;
476 if (inmsg
->hdr
.flags
.response_expected
== 1) {
477 pmsg_hdr
= kzalloc(sizeof(*pmsg_hdr
), GFP_KERNEL
);
480 goto err_free_bus_info
;
482 memcpy(pmsg_hdr
, &inmsg
->hdr
,
483 sizeof(struct controlvm_message_header
));
484 bus_info
->pending_msg_hdr
= pmsg_hdr
;
486 visorchannel
= visorchannel_create(cmd
->create_bus
.channel_addr
,
488 &cmd
->create_bus
.bus_data_type_guid
,
492 goto err_free_pending_msg
;
494 bus_info
->visorchannel
= visorchannel
;
495 /* Response will be handled by visorbus_create_instance on success */
496 err
= visorbus_create_instance(bus_info
);
498 goto err_destroy_channel
;
502 visorchannel_destroy(visorchannel
);
504 err_free_pending_msg
:
505 kfree(bus_info
->pending_msg_hdr
);
511 if (inmsg
->hdr
.flags
.response_expected
== 1)
512 controlvm_responder(inmsg
->hdr
.id
, &inmsg
->hdr
, err
);
516 static int visorbus_destroy(struct controlvm_message
*inmsg
)
518 struct controlvm_message_header
*pmsg_hdr
;
519 u32 bus_no
= inmsg
->cmd
.destroy_bus
.bus_no
;
520 struct visor_device
*bus_info
;
523 bus_info
= visorbus_get_device_by_id(bus_no
, BUS_ROOT_DEVICE
, NULL
);
528 if (bus_info
->state
.created
== 0) {
532 if (bus_info
->pending_msg_hdr
) {
533 /* only non-NULL if dev is still waiting on a response */
537 if (inmsg
->hdr
.flags
.response_expected
== 1) {
538 pmsg_hdr
= kzalloc(sizeof(*pmsg_hdr
), GFP_KERNEL
);
543 memcpy(pmsg_hdr
, &inmsg
->hdr
,
544 sizeof(struct controlvm_message_header
));
545 bus_info
->pending_msg_hdr
= pmsg_hdr
;
547 /* Response will be handled by visorbus_remove_instance */
548 visorbus_remove_instance(bus_info
);
552 if (inmsg
->hdr
.flags
.response_expected
== 1)
553 controlvm_responder(inmsg
->hdr
.id
, &inmsg
->hdr
, err
);
557 static const guid_t
*parser_id_get(struct parser_context
*ctx
)
559 return &ctx
->data
.id
;
562 static void *parser_string_get(u8
*pscan
, int nscan
)
570 value_length
= strnlen(pscan
, nscan
);
571 value
= kzalloc(value_length
+ 1, GFP_KERNEL
);
574 if (value_length
> 0)
575 memcpy(value
, pscan
, value_length
);
579 static void *parser_name_get(struct parser_context
*ctx
)
581 struct visor_controlvm_parameters_header
*phdr
;
584 if ((unsigned long)phdr
->name_offset
+
585 (unsigned long)phdr
->name_length
> ctx
->param_bytes
)
587 ctx
->curr
= (char *)&phdr
+ phdr
->name_offset
;
588 ctx
->bytes_remaining
= phdr
->name_length
;
589 return parser_string_get(ctx
->curr
, phdr
->name_length
);
592 static int visorbus_configure(struct controlvm_message
*inmsg
,
593 struct parser_context
*parser_ctx
)
595 struct controlvm_message_packet
*cmd
= &inmsg
->cmd
;
597 struct visor_device
*bus_info
;
600 bus_no
= cmd
->configure_bus
.bus_no
;
601 bus_info
= visorbus_get_device_by_id(bus_no
, BUS_ROOT_DEVICE
, NULL
);
606 if (bus_info
->state
.created
== 0) {
610 if (bus_info
->pending_msg_hdr
) {
614 err
= visorchannel_set_clientpartition(bus_info
->visorchannel
,
615 cmd
->configure_bus
.guest_handle
);
619 const guid_t
*partition_guid
= parser_id_get(parser_ctx
);
621 guid_copy(&bus_info
->partition_guid
, partition_guid
);
622 bus_info
->name
= parser_name_get(parser_ctx
);
624 if (inmsg
->hdr
.flags
.response_expected
== 1)
625 controlvm_responder(inmsg
->hdr
.id
, &inmsg
->hdr
, err
);
629 dev_err(&chipset_dev
->acpi_device
->dev
,
630 "%s exited with err: %d\n", __func__
, err
);
631 if (inmsg
->hdr
.flags
.response_expected
== 1)
632 controlvm_responder(inmsg
->hdr
.id
, &inmsg
->hdr
, err
);
636 static int visorbus_device_create(struct controlvm_message
*inmsg
)
638 struct controlvm_message_packet
*cmd
= &inmsg
->cmd
;
639 struct controlvm_message_header
*pmsg_hdr
;
640 u32 bus_no
= cmd
->create_device
.bus_no
;
641 u32 dev_no
= cmd
->create_device
.dev_no
;
642 struct visor_device
*dev_info
;
643 struct visor_device
*bus_info
;
644 struct visorchannel
*visorchannel
;
647 bus_info
= visorbus_get_device_by_id(bus_no
, BUS_ROOT_DEVICE
, NULL
);
649 dev_err(&chipset_dev
->acpi_device
->dev
,
650 "failed to get bus by id: %d\n", bus_no
);
654 if (bus_info
->state
.created
== 0) {
655 dev_err(&chipset_dev
->acpi_device
->dev
,
656 "bus not created, id: %d\n", bus_no
);
660 dev_info
= visorbus_get_device_by_id(bus_no
, dev_no
, NULL
);
661 if (dev_info
&& dev_info
->state
.created
== 1) {
662 dev_err(&chipset_dev
->acpi_device
->dev
,
663 "failed to get bus by id: %d/%d\n", bus_no
, dev_no
);
668 dev_info
= kzalloc(sizeof(*dev_info
), GFP_KERNEL
);
673 dev_info
->chipset_bus_no
= bus_no
;
674 dev_info
->chipset_dev_no
= dev_no
;
675 guid_copy(&dev_info
->inst
, &cmd
->create_device
.dev_inst_guid
);
676 dev_info
->device
.parent
= &bus_info
->device
;
677 visorchannel
= visorchannel_create(cmd
->create_device
.channel_addr
,
679 &cmd
->create_device
.data_type_guid
,
682 dev_err(&chipset_dev
->acpi_device
->dev
,
683 "failed to create visorchannel: %d/%d\n",
686 goto err_free_dev_info
;
688 dev_info
->visorchannel
= visorchannel
;
689 guid_copy(&dev_info
->channel_type_guid
,
690 &cmd
->create_device
.data_type_guid
);
691 if (guid_equal(&cmd
->create_device
.data_type_guid
,
692 &visor_vhba_channel_guid
)) {
693 err
= save_crash_message(inmsg
, CRASH_DEV
);
695 goto err_destroy_visorchannel
;
697 if (inmsg
->hdr
.flags
.response_expected
== 1) {
698 pmsg_hdr
= kzalloc(sizeof(*pmsg_hdr
), GFP_KERNEL
);
701 goto err_destroy_visorchannel
;
703 memcpy(pmsg_hdr
, &inmsg
->hdr
,
704 sizeof(struct controlvm_message_header
));
705 dev_info
->pending_msg_hdr
= pmsg_hdr
;
707 /* create_visor_device will send response */
708 err
= create_visor_device(dev_info
);
710 goto err_destroy_visorchannel
;
714 err_destroy_visorchannel
:
715 visorchannel_destroy(visorchannel
);
721 if (inmsg
->hdr
.flags
.response_expected
== 1)
722 controlvm_responder(inmsg
->hdr
.id
, &inmsg
->hdr
, err
);
726 static int visorbus_device_changestate(struct controlvm_message
*inmsg
)
728 struct controlvm_message_packet
*cmd
= &inmsg
->cmd
;
729 struct controlvm_message_header
*pmsg_hdr
;
730 u32 bus_no
= cmd
->device_change_state
.bus_no
;
731 u32 dev_no
= cmd
->device_change_state
.dev_no
;
732 struct visor_segment_state state
= cmd
->device_change_state
.state
;
733 struct visor_device
*dev_info
;
736 dev_info
= visorbus_get_device_by_id(bus_no
, dev_no
, NULL
);
741 if (dev_info
->state
.created
== 0) {
745 if (dev_info
->pending_msg_hdr
) {
746 /* only non-NULL if dev is still waiting on a response */
751 if (inmsg
->hdr
.flags
.response_expected
== 1) {
752 pmsg_hdr
= kzalloc(sizeof(*pmsg_hdr
), GFP_KERNEL
);
757 memcpy(pmsg_hdr
, &inmsg
->hdr
,
758 sizeof(struct controlvm_message_header
));
759 dev_info
->pending_msg_hdr
= pmsg_hdr
;
761 if (state
.alive
== segment_state_running
.alive
&&
762 state
.operating
== segment_state_running
.operating
)
763 /* Response will be sent from visorchipset_device_resume */
764 err
= visorchipset_device_resume(dev_info
);
765 /* ServerNotReady / ServerLost / SegmentStateStandby */
766 else if (state
.alive
== segment_state_standby
.alive
&&
767 state
.operating
== segment_state_standby
.operating
)
769 * technically this is standby case where server is lost.
770 * Response will be sent from visorchipset_device_pause.
772 err
= visorchipset_device_pause(dev_info
);
778 dev_err(&chipset_dev
->acpi_device
->dev
, "failed: %d\n", err
);
779 if (inmsg
->hdr
.flags
.response_expected
== 1)
780 controlvm_responder(inmsg
->hdr
.id
, &inmsg
->hdr
, err
);
784 static int visorbus_device_destroy(struct controlvm_message
*inmsg
)
786 struct controlvm_message_packet
*cmd
= &inmsg
->cmd
;
787 struct controlvm_message_header
*pmsg_hdr
;
788 u32 bus_no
= cmd
->destroy_device
.bus_no
;
789 u32 dev_no
= cmd
->destroy_device
.dev_no
;
790 struct visor_device
*dev_info
;
793 dev_info
= visorbus_get_device_by_id(bus_no
, dev_no
, NULL
);
798 if (dev_info
->state
.created
== 0) {
802 if (dev_info
->pending_msg_hdr
) {
803 /* only non-NULL if dev is still waiting on a response */
807 if (inmsg
->hdr
.flags
.response_expected
== 1) {
808 pmsg_hdr
= kzalloc(sizeof(*pmsg_hdr
), GFP_KERNEL
);
814 memcpy(pmsg_hdr
, &inmsg
->hdr
,
815 sizeof(struct controlvm_message_header
));
816 dev_info
->pending_msg_hdr
= pmsg_hdr
;
818 kfree(dev_info
->name
);
819 remove_visor_device(dev_info
);
823 if (inmsg
->hdr
.flags
.response_expected
== 1)
824 controlvm_responder(inmsg
->hdr
.id
, &inmsg
->hdr
, err
);
829 * The general parahotplug flow works as follows. The visorchipset receives
830 * a DEVICE_CHANGESTATE message from Command specifying a physical device
831 * to enable or disable. The CONTROLVM message handler calls
832 * parahotplug_process_message, which then adds the message to a global list
833 * and kicks off a udev event which causes a user level script to enable or
834 * disable the specified device. The udev script then writes to
835 * /sys/devices/platform/visorchipset/parahotplug, which causes the
836 * parahotplug store functions to get called, at which point the
837 * appropriate CONTROLVM message is retrieved from the list and responded to.
840 #define PARAHOTPLUG_TIMEOUT_MS 2000
843 * parahotplug_next_id() - generate unique int to match an outstanding
844 * CONTROLVM message with a udev script /sys
847 * Return: a unique integer value
849 static int parahotplug_next_id(void)
851 static atomic_t id
= ATOMIC_INIT(0);
853 return atomic_inc_return(&id
);
857 * parahotplug_next_expiration() - returns the time (in jiffies) when a
858 * CONTROLVM message on the list should expire
859 * -- PARAHOTPLUG_TIMEOUT_MS in the future
861 * Return: expected expiration time (in jiffies)
863 static unsigned long parahotplug_next_expiration(void)
865 return jiffies
+ msecs_to_jiffies(PARAHOTPLUG_TIMEOUT_MS
);
869 * parahotplug_request_create() - create a parahotplug_request, which is
870 * basically a wrapper for a CONTROLVM_MESSAGE
871 * that we can stick on a list
872 * @msg: the message to insert in the request
874 * Return: the request containing the provided message
876 static struct parahotplug_request
*parahotplug_request_create(
877 struct controlvm_message
*msg
)
879 struct parahotplug_request
*req
;
881 req
= kmalloc(sizeof(*req
), GFP_KERNEL
);
884 req
->id
= parahotplug_next_id();
885 req
->expiration
= parahotplug_next_expiration();
891 * parahotplug_request_destroy() - free a parahotplug_request
892 * @req: the request to deallocate
894 static void parahotplug_request_destroy(struct parahotplug_request
*req
)
899 static LIST_HEAD(parahotplug_request_list
);
901 static DEFINE_SPINLOCK(parahotplug_request_list_lock
);
904 * parahotplug_request_complete() - mark request as complete
905 * @id: the id of the request
906 * @active: indicates whether the request is assigned to active partition
908 * Called from the /sys handler, which means the user script has
909 * finished the enable/disable. Find the matching identifier, and
910 * respond to the CONTROLVM message with success.
912 * Return: 0 on success or -EINVAL on failure
914 static int parahotplug_request_complete(int id
, u16 active
)
916 struct list_head
*pos
;
917 struct list_head
*tmp
;
918 struct parahotplug_request
*req
;
920 spin_lock(¶hotplug_request_list_lock
);
921 /* Look for a request matching "id". */
922 list_for_each_safe(pos
, tmp
, ¶hotplug_request_list
) {
923 req
= list_entry(pos
, struct parahotplug_request
, list
);
926 * Found a match. Remove it from the list and
930 spin_unlock(¶hotplug_request_list_lock
);
931 req
->msg
.cmd
.device_change_state
.state
.active
= active
;
932 if (req
->msg
.hdr
.flags
.response_expected
)
934 &req
->msg
.hdr
, CONTROLVM_RESP_SUCCESS
,
935 &req
->msg
.cmd
.device_change_state
.state
);
936 parahotplug_request_destroy(req
);
940 spin_unlock(¶hotplug_request_list_lock
);
945 * devicedisabled_store() - disables the hotplug device
946 * @dev: sysfs interface variable not utilized in this function
947 * @attr: sysfs interface variable not utilized in this function
948 * @buf: buffer containing the device id
949 * @count: the size of the buffer
951 * The parahotplug/devicedisabled interface gets called by our support script
952 * when an SR-IOV device has been shut down. The ID is passed to the script
953 * and then passed back when the device has been removed.
955 * Return: the size of the buffer for success or negative for error
957 static ssize_t
devicedisabled_store(struct device
*dev
,
958 struct device_attribute
*attr
,
959 const char *buf
, size_t count
)
964 if (kstrtouint(buf
, 10, &id
))
966 err
= parahotplug_request_complete(id
, 0);
971 static DEVICE_ATTR_WO(devicedisabled
);
974 * deviceenabled_store() - enables the hotplug device
975 * @dev: sysfs interface variable not utilized in this function
976 * @attr: sysfs interface variable not utilized in this function
977 * @buf: buffer containing the device id
978 * @count: the size of the buffer
980 * The parahotplug/deviceenabled interface gets called by our support script
981 * when an SR-IOV device has been recovered. The ID is passed to the script
982 * and then passed back when the device has been brought back up.
984 * Return: the size of the buffer for success or negative for error
986 static ssize_t
deviceenabled_store(struct device
*dev
,
987 struct device_attribute
*attr
,
988 const char *buf
, size_t count
)
992 if (kstrtouint(buf
, 10, &id
))
994 parahotplug_request_complete(id
, 1);
997 static DEVICE_ATTR_WO(deviceenabled
);
999 static struct attribute
*visorchipset_install_attrs
[] = {
1000 &dev_attr_toolaction
.attr
,
1001 &dev_attr_boottotool
.attr
,
1002 &dev_attr_error
.attr
,
1003 &dev_attr_textid
.attr
,
1004 &dev_attr_remaining_steps
.attr
,
1008 static const struct attribute_group visorchipset_install_group
= {
1010 .attrs
= visorchipset_install_attrs
1013 static struct attribute
*visorchipset_parahotplug_attrs
[] = {
1014 &dev_attr_devicedisabled
.attr
,
1015 &dev_attr_deviceenabled
.attr
,
1019 static const struct attribute_group visorchipset_parahotplug_group
= {
1020 .name
= "parahotplug",
1021 .attrs
= visorchipset_parahotplug_attrs
1024 static const struct attribute_group
*visorchipset_dev_groups
[] = {
1025 &visorchipset_install_group
,
1026 &visorchipset_parahotplug_group
,
1031 * parahotplug_request_kickoff() - initiate parahotplug request
1032 * @req: the request to initiate
1034 * Cause uevent to run the user level script to do the disable/enable specified
1035 * in the parahotplug_request.
1037 static int parahotplug_request_kickoff(struct parahotplug_request
*req
)
1039 struct controlvm_message_packet
*cmd
= &req
->msg
.cmd
;
1040 char env_cmd
[40], env_id
[40], env_state
[40], env_bus
[40], env_dev
[40],
1042 char *envp
[] = { env_cmd
, env_id
, env_state
, env_bus
, env_dev
,
1046 sprintf(env_cmd
, "VISOR_PARAHOTPLUG=1");
1047 sprintf(env_id
, "VISOR_PARAHOTPLUG_ID=%d", req
->id
);
1048 sprintf(env_state
, "VISOR_PARAHOTPLUG_STATE=%d",
1049 cmd
->device_change_state
.state
.active
);
1050 sprintf(env_bus
, "VISOR_PARAHOTPLUG_BUS=%d",
1051 cmd
->device_change_state
.bus_no
);
1052 sprintf(env_dev
, "VISOR_PARAHOTPLUG_DEVICE=%d",
1053 cmd
->device_change_state
.dev_no
>> 3);
1054 sprintf(env_func
, "VISOR_PARAHOTPLUG_FUNCTION=%d",
1055 cmd
->device_change_state
.dev_no
& 0x7);
1056 return kobject_uevent_env(&chipset_dev
->acpi_device
->dev
.kobj
,
1061 * parahotplug_process_message() - enables or disables a PCI device by kicking
1063 * @inmsg: the message indicating whether to enable or disable
1065 static int parahotplug_process_message(struct controlvm_message
*inmsg
)
1067 struct parahotplug_request
*req
;
1070 req
= parahotplug_request_create(inmsg
);
1074 * For enable messages, just respond with success right away, we don't
1075 * need to wait to see if the enable was successful.
1077 if (inmsg
->cmd
.device_change_state
.state
.active
) {
1078 err
= parahotplug_request_kickoff(req
);
1081 controlvm_respond(&inmsg
->hdr
, CONTROLVM_RESP_SUCCESS
,
1082 &inmsg
->cmd
.device_change_state
.state
);
1083 parahotplug_request_destroy(req
);
1087 * For disable messages, add the request to the request list before
1088 * kicking off the udev script. It won't get responded to until the
1089 * script has indicated it's done.
1091 spin_lock(¶hotplug_request_list_lock
);
1092 list_add_tail(&req
->list
, ¶hotplug_request_list
);
1093 spin_unlock(¶hotplug_request_list_lock
);
1094 err
= parahotplug_request_kickoff(req
);
1100 controlvm_respond(&inmsg
->hdr
, err
,
1101 &inmsg
->cmd
.device_change_state
.state
);
1106 * chipset_ready_uevent() - sends chipset_ready action
1108 * Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset.
1110 * Return: 0 on success, negative on failure
1112 static int chipset_ready_uevent(struct controlvm_message_header
*msg_hdr
)
1116 res
= kobject_uevent(&chipset_dev
->acpi_device
->dev
.kobj
, KOBJ_ONLINE
);
1117 if (msg_hdr
->flags
.response_expected
)
1118 controlvm_respond(msg_hdr
, res
, NULL
);
1123 * chipset_selftest_uevent() - sends chipset_selftest action
1125 * Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset.
1127 * Return: 0 on success, negative on failure
1129 static int chipset_selftest_uevent(struct controlvm_message_header
*msg_hdr
)
1131 char env_selftest
[20];
1132 char *envp
[] = { env_selftest
, NULL
};
1135 sprintf(env_selftest
, "SPARSP_SELFTEST=%d", 1);
1136 res
= kobject_uevent_env(&chipset_dev
->acpi_device
->dev
.kobj
,
1138 if (msg_hdr
->flags
.response_expected
)
1139 controlvm_respond(msg_hdr
, res
, NULL
);
1144 * chipset_notready_uevent() - sends chipset_notready action
1146 * Send ACTION=offline for DEVPATH=/sys/devices/platform/visorchipset.
1148 * Return: 0 on success, negative on failure
1150 static int chipset_notready_uevent(struct controlvm_message_header
*msg_hdr
)
1152 int res
= kobject_uevent(&chipset_dev
->acpi_device
->dev
.kobj
,
1155 if (msg_hdr
->flags
.response_expected
)
1156 controlvm_respond(msg_hdr
, res
, NULL
);
1160 static int unisys_vmcall(unsigned long tuple
, unsigned long param
)
1163 unsigned int cpuid_eax
, cpuid_ebx
, cpuid_ecx
, cpuid_edx
;
1164 unsigned long reg_ebx
;
1165 unsigned long reg_ecx
;
1167 reg_ebx
= param
& 0xFFFFFFFF;
1168 reg_ecx
= param
>> 32;
1169 cpuid(0x00000001, &cpuid_eax
, &cpuid_ebx
, &cpuid_ecx
, &cpuid_edx
);
1170 if (!(cpuid_ecx
& 0x80000000))
1172 __asm__
__volatile__(".byte 0x00f, 0x001, 0x0c1" : "=a"(result
) :
1173 "a"(tuple
), "b"(reg_ebx
), "c"(reg_ecx
));
1178 /* Need to convert from VMCALL error codes to Linux */
1181 case VMCALL_RESULT_INVALID_PARAM
:
1183 case VMCALL_RESULT_DATA_UNAVAILABLE
:
1190 static int controlvm_channel_create(struct visorchipset_device
*dev
)
1192 struct visorchannel
*chan
;
1196 err
= unisys_vmcall(VMCALL_CONTROLVM_ADDR
,
1197 virt_to_phys(&dev
->controlvm_params
));
1200 addr
= dev
->controlvm_params
.address
;
1201 chan
= visorchannel_create(addr
, GFP_KERNEL
,
1202 &visor_controlvm_channel_guid
, true);
1205 dev
->controlvm_channel
= chan
;
1209 static void setup_crash_devices_work_queue(struct work_struct
*work
)
1211 struct controlvm_message local_crash_bus_msg
;
1212 struct controlvm_message local_crash_dev_msg
;
1213 struct controlvm_message msg
= {
1214 .hdr
.id
= CONTROLVM_CHIPSET_INIT
,
1215 .cmd
.init_chipset
= {
1220 u32 local_crash_msg_offset
;
1221 u16 local_crash_msg_count
;
1223 /* send init chipset msg */
1225 /* get saved message count */
1226 if (visorchannel_read(chipset_dev
->controlvm_channel
,
1227 offsetof(struct visor_controlvm_channel
,
1228 saved_crash_message_count
),
1229 &local_crash_msg_count
, sizeof(u16
)) < 0) {
1230 dev_err(&chipset_dev
->acpi_device
->dev
,
1231 "failed to read channel\n");
1234 if (local_crash_msg_count
!= CONTROLVM_CRASHMSG_MAX
) {
1235 dev_err(&chipset_dev
->acpi_device
->dev
, "invalid count\n");
1238 /* get saved crash message offset */
1239 if (visorchannel_read(chipset_dev
->controlvm_channel
,
1240 offsetof(struct visor_controlvm_channel
,
1241 saved_crash_message_offset
),
1242 &local_crash_msg_offset
, sizeof(u32
)) < 0) {
1243 dev_err(&chipset_dev
->acpi_device
->dev
,
1244 "failed to read channel\n");
1247 /* read create device message for storage bus offset */
1248 if (visorchannel_read(chipset_dev
->controlvm_channel
,
1249 local_crash_msg_offset
,
1250 &local_crash_bus_msg
,
1251 sizeof(struct controlvm_message
)) < 0) {
1252 dev_err(&chipset_dev
->acpi_device
->dev
,
1253 "failed to read channel\n");
1256 /* read create device message for storage device */
1257 if (visorchannel_read(chipset_dev
->controlvm_channel
,
1258 local_crash_msg_offset
+
1259 sizeof(struct controlvm_message
),
1260 &local_crash_dev_msg
,
1261 sizeof(struct controlvm_message
)) < 0) {
1262 dev_err(&chipset_dev
->acpi_device
->dev
,
1263 "failed to read channel\n");
1266 /* reuse IOVM create bus message */
1267 if (!local_crash_bus_msg
.cmd
.create_bus
.channel_addr
) {
1268 dev_err(&chipset_dev
->acpi_device
->dev
,
1269 "no valid create_bus message\n");
1272 visorbus_create(&local_crash_bus_msg
);
1273 /* reuse create device message for storage device */
1274 if (!local_crash_dev_msg
.cmd
.create_device
.channel_addr
) {
1275 dev_err(&chipset_dev
->acpi_device
->dev
,
1276 "no valid create_device message\n");
1279 visorbus_device_create(&local_crash_dev_msg
);
1282 void visorbus_response(struct visor_device
*bus_info
, int response
,
1285 if (!bus_info
->pending_msg_hdr
)
1288 controlvm_responder(controlvm_id
, bus_info
->pending_msg_hdr
, response
);
1289 kfree(bus_info
->pending_msg_hdr
);
1290 bus_info
->pending_msg_hdr
= NULL
;
1293 void visorbus_device_changestate_response(struct visor_device
*dev_info
,
1295 struct visor_segment_state state
)
1297 if (!dev_info
->pending_msg_hdr
)
1300 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE
, dev_info
,
1302 kfree(dev_info
->pending_msg_hdr
);
1303 dev_info
->pending_msg_hdr
= NULL
;
1306 static void parser_done(struct parser_context
*ctx
)
1308 chipset_dev
->controlvm_payload_bytes_buffered
-= ctx
->param_bytes
;
1312 static struct parser_context
*parser_init_stream(u64 addr
, u32 bytes
,
1315 unsigned long allocbytes
;
1316 struct parser_context
*ctx
;
1320 /* alloc an extra byte to ensure payload is \0 terminated */
1321 allocbytes
= (unsigned long)bytes
+ 1 + (sizeof(struct parser_context
) -
1322 sizeof(struct visor_controlvm_parameters_header
));
1323 if ((chipset_dev
->controlvm_payload_bytes_buffered
+ bytes
) >
1324 MAX_CONTROLVM_PAYLOAD_BYTES
) {
1328 ctx
= kzalloc(allocbytes
, GFP_KERNEL
);
1333 ctx
->allocbytes
= allocbytes
;
1334 ctx
->param_bytes
= bytes
;
1335 mapping
= memremap(addr
, bytes
, MEMREMAP_WB
);
1337 goto err_finish_ctx
;
1338 memcpy(&ctx
->data
, mapping
, bytes
);
1340 ctx
->byte_stream
= true;
1341 chipset_dev
->controlvm_payload_bytes_buffered
+= ctx
->param_bytes
;
1350 * handle_command() - process a controlvm message
1351 * @inmsg: the message to process
1352 * @channel_addr: address of the controlvm channel
1355 * 0 - Successfully processed the message
1356 * -EAGAIN - ControlVM message was not processed and should be retried
1357 * reading the next controlvm message; a scenario where this can
1358 * occur is when we need to throttle the allocation of memory in
1359 * which to copy out controlvm payload data.
1360 * < 0 - error: ControlVM message was processed but an error occurred.
1362 static int handle_command(struct controlvm_message inmsg
, u64 channel_addr
)
1364 struct controlvm_message_packet
*cmd
= &inmsg
.cmd
;
1367 struct parser_context
*parser_ctx
= NULL
;
1368 struct controlvm_message ackmsg
;
1371 /* create parsing context if necessary */
1372 parm_addr
= channel_addr
+ inmsg
.hdr
.payload_vm_offset
;
1373 parm_bytes
= inmsg
.hdr
.payload_bytes
;
1375 * Parameter and channel addresses within test messages actually lie
1376 * within our OS-controlled memory. We need to know that, because it
1377 * makes a difference in how we compute the virtual address.
1382 parser_ctx
= parser_init_stream(parm_addr
, parm_bytes
, &retry
);
1383 if (!parser_ctx
&& retry
)
1386 controlvm_init_response(&ackmsg
, &inmsg
.hdr
, CONTROLVM_RESP_SUCCESS
);
1387 err
= visorchannel_signalinsert(chipset_dev
->controlvm_channel
,
1388 CONTROLVM_QUEUE_ACK
, &ackmsg
);
1391 switch (inmsg
.hdr
.id
) {
1392 case CONTROLVM_CHIPSET_INIT
:
1393 err
= chipset_init(&inmsg
);
1395 case CONTROLVM_BUS_CREATE
:
1396 err
= visorbus_create(&inmsg
);
1398 case CONTROLVM_BUS_DESTROY
:
1399 err
= visorbus_destroy(&inmsg
);
1401 case CONTROLVM_BUS_CONFIGURE
:
1402 err
= visorbus_configure(&inmsg
, parser_ctx
);
1404 case CONTROLVM_DEVICE_CREATE
:
1405 err
= visorbus_device_create(&inmsg
);
1407 case CONTROLVM_DEVICE_CHANGESTATE
:
1408 if (cmd
->device_change_state
.flags
.phys_device
) {
1409 err
= parahotplug_process_message(&inmsg
);
1412 * save the hdr and cmd structures for later use when
1413 * sending back the response to Command
1415 err
= visorbus_device_changestate(&inmsg
);
1419 case CONTROLVM_DEVICE_DESTROY
:
1420 err
= visorbus_device_destroy(&inmsg
);
1422 case CONTROLVM_DEVICE_CONFIGURE
:
1423 /* no op just send a respond that we passed */
1424 if (inmsg
.hdr
.flags
.response_expected
)
1425 controlvm_respond(&inmsg
.hdr
, CONTROLVM_RESP_SUCCESS
,
1428 case CONTROLVM_CHIPSET_READY
:
1429 err
= chipset_ready_uevent(&inmsg
.hdr
);
1431 case CONTROLVM_CHIPSET_SELFTEST
:
1432 err
= chipset_selftest_uevent(&inmsg
.hdr
);
1434 case CONTROLVM_CHIPSET_STOP
:
1435 err
= chipset_notready_uevent(&inmsg
.hdr
);
1439 if (inmsg
.hdr
.flags
.response_expected
)
1440 controlvm_respond(&inmsg
.hdr
,
1441 -CONTROLVM_RESP_ID_UNKNOWN
, NULL
);
1445 parser_done(parser_ctx
);
1452 * read_controlvm_event() - retreives the next message from the
1453 * CONTROLVM_QUEUE_EVENT queue in the controlvm
1455 * @msg: pointer to the retrieved message
1457 * Return: 0 if valid message was retrieved or -error
1459 static int read_controlvm_event(struct controlvm_message
*msg
)
1461 int err
= visorchannel_signalremove(chipset_dev
->controlvm_channel
,
1462 CONTROLVM_QUEUE_EVENT
, msg
);
1467 if (msg
->hdr
.flags
.test_message
== 1)
1473 * parahotplug_process_list() - remove any request from the list that's been on
1474 * there too long and respond with an error
1476 static void parahotplug_process_list(void)
1478 struct list_head
*pos
;
1479 struct list_head
*tmp
;
1481 spin_lock(¶hotplug_request_list_lock
);
1482 list_for_each_safe(pos
, tmp
, ¶hotplug_request_list
) {
1483 struct parahotplug_request
*req
=
1484 list_entry(pos
, struct parahotplug_request
, list
);
1486 if (!time_after_eq(jiffies
, req
->expiration
))
1489 if (req
->msg
.hdr
.flags
.response_expected
)
1492 CONTROLVM_RESP_DEVICE_UDEV_TIMEOUT
,
1493 &req
->msg
.cmd
.device_change_state
.state
);
1494 parahotplug_request_destroy(req
);
1496 spin_unlock(¶hotplug_request_list_lock
);
1499 static void controlvm_periodic_work(struct work_struct
*work
)
1501 struct controlvm_message inmsg
;
1505 /* Drain the RESPONSE queue make it empty */
1507 err
= visorchannel_signalremove(chipset_dev
->controlvm_channel
,
1508 CONTROLVM_QUEUE_RESPONSE
,
1510 } while ((!err
) && (++count
< CONTROLVM_MESSAGE_MAX
));
1513 if (chipset_dev
->controlvm_pending_msg_valid
) {
1515 * we throttled processing of a prior msg, so try to process
1516 * it again rather than reading a new one
1518 inmsg
= chipset_dev
->controlvm_pending_msg
;
1519 chipset_dev
->controlvm_pending_msg_valid
= false;
1522 err
= read_controlvm_event(&inmsg
);
1525 chipset_dev
->most_recent_message_jiffies
= jiffies
;
1526 err
= handle_command(inmsg
,
1527 visorchannel_get_physaddr
1528 (chipset_dev
->controlvm_channel
));
1529 if (err
== -EAGAIN
) {
1530 chipset_dev
->controlvm_pending_msg
= inmsg
;
1531 chipset_dev
->controlvm_pending_msg_valid
= true;
1535 err
= read_controlvm_event(&inmsg
);
1537 /* parahotplug_worker */
1538 parahotplug_process_list();
1541 * The controlvm messages are sent in a bulk. If we start receiving messages, we
1542 * want the polling to be fast. If we do not receive any message for
1543 * MIN_IDLE_SECONDS, we can slow down the polling.
1546 if (time_after(jiffies
, chipset_dev
->most_recent_message_jiffies
+
1547 (HZ
* MIN_IDLE_SECONDS
))) {
1549 * it's been longer than MIN_IDLE_SECONDS since we processed
1550 * our last controlvm message; slow down the polling
1552 if (chipset_dev
->poll_jiffies
!= POLLJIFFIES_CONTROLVM_SLOW
)
1553 chipset_dev
->poll_jiffies
= POLLJIFFIES_CONTROLVM_SLOW
;
1555 if (chipset_dev
->poll_jiffies
!= POLLJIFFIES_CONTROLVM_FAST
)
1556 chipset_dev
->poll_jiffies
= POLLJIFFIES_CONTROLVM_FAST
;
1558 schedule_delayed_work(&chipset_dev
->periodic_controlvm_work
,
1559 chipset_dev
->poll_jiffies
);
1562 static int visorchipset_init(struct acpi_device
*acpi_device
)
1565 struct visorchannel
*controlvm_channel
;
1567 chipset_dev
= kzalloc(sizeof(*chipset_dev
), GFP_KERNEL
);
1570 err
= controlvm_channel_create(chipset_dev
);
1572 goto error_free_chipset_dev
;
1573 acpi_device
->driver_data
= chipset_dev
;
1574 chipset_dev
->acpi_device
= acpi_device
;
1575 chipset_dev
->poll_jiffies
= POLLJIFFIES_CONTROLVM_FAST
;
1576 err
= sysfs_create_groups(&chipset_dev
->acpi_device
->dev
.kobj
,
1577 visorchipset_dev_groups
);
1579 goto error_destroy_channel
;
1580 controlvm_channel
= chipset_dev
->controlvm_channel
;
1581 if (!visor_check_channel(visorchannel_get_header(controlvm_channel
),
1582 &chipset_dev
->acpi_device
->dev
,
1583 &visor_controlvm_channel_guid
,
1585 sizeof(struct visor_controlvm_channel
),
1586 VISOR_CONTROLVM_CHANNEL_VERSIONID
,
1587 VISOR_CHANNEL_SIGNATURE
))
1588 goto error_delete_groups
;
1589 /* if booting in a crash kernel */
1590 if (is_kdump_kernel())
1591 INIT_DELAYED_WORK(&chipset_dev
->periodic_controlvm_work
,
1592 setup_crash_devices_work_queue
);
1594 INIT_DELAYED_WORK(&chipset_dev
->periodic_controlvm_work
,
1595 controlvm_periodic_work
);
1596 chipset_dev
->most_recent_message_jiffies
= jiffies
;
1597 chipset_dev
->poll_jiffies
= POLLJIFFIES_CONTROLVM_FAST
;
1598 schedule_delayed_work(&chipset_dev
->periodic_controlvm_work
,
1599 chipset_dev
->poll_jiffies
);
1600 err
= visorbus_init();
1602 goto error_cancel_work
;
1606 cancel_delayed_work_sync(&chipset_dev
->periodic_controlvm_work
);
1608 error_delete_groups
:
1609 sysfs_remove_groups(&chipset_dev
->acpi_device
->dev
.kobj
,
1610 visorchipset_dev_groups
);
1612 error_destroy_channel
:
1613 visorchannel_destroy(chipset_dev
->controlvm_channel
);
1615 error_free_chipset_dev
:
1619 dev_err(&acpi_device
->dev
, "failed with error %d\n", err
);
1623 static int visorchipset_exit(struct acpi_device
*acpi_device
)
1626 cancel_delayed_work_sync(&chipset_dev
->periodic_controlvm_work
);
1627 sysfs_remove_groups(&chipset_dev
->acpi_device
->dev
.kobj
,
1628 visorchipset_dev_groups
);
1629 visorchannel_destroy(chipset_dev
->controlvm_channel
);
1634 static const struct acpi_device_id unisys_device_ids
[] = {
1639 static struct acpi_driver unisys_acpi_driver
= {
1640 .name
= "unisys_acpi",
1641 .class = "unisys_acpi_class",
1642 .owner
= THIS_MODULE
,
1643 .ids
= unisys_device_ids
,
1645 .add
= visorchipset_init
,
1646 .remove
= visorchipset_exit
,
1650 MODULE_DEVICE_TABLE(acpi
, unisys_device_ids
);
1652 static __init
int visorutil_spar_detect(void)
1654 unsigned int eax
, ebx
, ecx
, edx
;
1656 if (boot_cpu_has(X86_FEATURE_HYPERVISOR
)) {
1658 cpuid(UNISYS_VISOR_LEAF_ID
, &eax
, &ebx
, &ecx
, &edx
);
1659 return (ebx
== UNISYS_VISOR_ID_EBX
) &&
1660 (ecx
== UNISYS_VISOR_ID_ECX
) &&
1661 (edx
== UNISYS_VISOR_ID_EDX
);
1666 static int __init
init_unisys(void)
1670 if (!visorutil_spar_detect())
1672 result
= acpi_bus_register_driver(&unisys_acpi_driver
);
1675 pr_info("Unisys Visorchipset Driver Loaded.\n");
1679 static void __exit
exit_unisys(void)
1681 acpi_bus_unregister_driver(&unisys_acpi_driver
);
1684 module_init(init_unisys
);
1685 module_exit(exit_unisys
);
1687 MODULE_AUTHOR("Unisys");
1688 MODULE_LICENSE("GPL");
1689 MODULE_DESCRIPTION("s-Par visorbus driver for virtual device buses");