io_uring: ensure finish_wait() is always called in __io_uring_task_cancel()
[linux/fpc-iii.git] / arch / powerpc / platforms / pseries / suspend.c
blob1b902cbf85c537a95d8115b5bd14b94431f2268a
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2010 Brian King IBM Corporation
4 */
6 #include <linux/cpu.h>
7 #include <linux/delay.h>
8 #include <linux/suspend.h>
9 #include <linux/stat.h>
10 #include <asm/firmware.h>
11 #include <asm/hvcall.h>
12 #include <asm/machdep.h>
13 #include <asm/mmu.h>
14 #include <asm/rtas.h>
15 #include <asm/topology.h>
17 static struct device suspend_dev;
19 /**
20 * pseries_suspend_begin - First phase of hibernation
22 * Check to ensure we are in a valid state to hibernate
24 * Return value:
25 * 0 on success / other on failure
26 **/
27 static int pseries_suspend_begin(u64 stream_id)
29 long vasi_state, rc;
30 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
32 /* Make sure the state is valid */
33 rc = plpar_hcall(H_VASI_STATE, retbuf, stream_id);
35 vasi_state = retbuf[0];
37 if (rc) {
38 pr_err("pseries_suspend_begin: vasi_state returned %ld\n",rc);
39 return rc;
40 } else if (vasi_state == H_VASI_ENABLED) {
41 return -EAGAIN;
42 } else if (vasi_state != H_VASI_SUSPENDING) {
43 pr_err("pseries_suspend_begin: vasi_state returned state %ld\n",
44 vasi_state);
45 return -EIO;
47 return 0;
50 /**
51 * pseries_suspend_enter - Final phase of hibernation
53 * Return value:
54 * 0 on success / other on failure
55 **/
56 static int pseries_suspend_enter(suspend_state_t state)
58 return rtas_ibm_suspend_me(NULL);
61 /**
62 * store_hibernate - Initiate partition hibernation
63 * @dev: subsys root device
64 * @attr: device attribute struct
65 * @buf: buffer
66 * @count: buffer size
68 * Write the stream ID received from the HMC to this file
69 * to trigger hibernating the partition
71 * Return value:
72 * number of bytes printed to buffer / other on failure
73 **/
74 static ssize_t store_hibernate(struct device *dev,
75 struct device_attribute *attr,
76 const char *buf, size_t count)
78 u64 stream_id;
79 int rc;
81 if (!capable(CAP_SYS_ADMIN))
82 return -EPERM;
84 stream_id = simple_strtoul(buf, NULL, 16);
86 do {
87 rc = pseries_suspend_begin(stream_id);
88 if (rc == -EAGAIN)
89 ssleep(1);
90 } while (rc == -EAGAIN);
92 if (!rc)
93 rc = pm_suspend(PM_SUSPEND_MEM);
95 if (!rc) {
96 rc = count;
97 post_mobility_fixup();
101 return rc;
104 #define USER_DT_UPDATE 0
105 #define KERN_DT_UPDATE 1
108 * show_hibernate - Report device tree update responsibilty
109 * @dev: subsys root device
110 * @attr: device attribute struct
111 * @buf: buffer
113 * Report whether a device tree update is performed by the kernel after a
114 * resume, or if drmgr must coordinate the update from user space.
116 * Return value:
117 * 0 if drmgr is to initiate update, and 1 otherwise
119 static ssize_t show_hibernate(struct device *dev,
120 struct device_attribute *attr,
121 char *buf)
123 return sprintf(buf, "%d\n", KERN_DT_UPDATE);
126 static DEVICE_ATTR(hibernate, 0644, show_hibernate, store_hibernate);
128 static struct bus_type suspend_subsys = {
129 .name = "power",
130 .dev_name = "power",
133 static const struct platform_suspend_ops pseries_suspend_ops = {
134 .valid = suspend_valid_only_mem,
135 .enter = pseries_suspend_enter,
139 * pseries_suspend_sysfs_register - Register with sysfs
141 * Return value:
142 * 0 on success / other on failure
144 static int pseries_suspend_sysfs_register(struct device *dev)
146 int rc;
148 if ((rc = subsys_system_register(&suspend_subsys, NULL)))
149 return rc;
151 dev->id = 0;
152 dev->bus = &suspend_subsys;
154 if ((rc = device_create_file(suspend_subsys.dev_root, &dev_attr_hibernate)))
155 goto subsys_unregister;
157 return 0;
159 subsys_unregister:
160 bus_unregister(&suspend_subsys);
161 return rc;
165 * pseries_suspend_init - initcall for pSeries suspend
167 * Return value:
168 * 0 on success / other on failure
170 static int __init pseries_suspend_init(void)
172 int rc;
174 if (!firmware_has_feature(FW_FEATURE_LPAR))
175 return 0;
177 if ((rc = pseries_suspend_sysfs_register(&suspend_dev)))
178 return rc;
180 suspend_set_ops(&pseries_suspend_ops);
181 return 0;
183 machine_device_initcall(pseries, pseries_suspend_init);