Rename the functions for suspend to reflect that Xen does not hijack the ACPI "sleepstate" sysctl(7) node anymore. Add a boolean value to mark that the save/suspend operation has been notified by dom0, so as to avoid possible errors where admin would like to schedule the domain for sleep without dom0 being prepared for that. Fail with EAGAIN in this case. Sprinkle some KNF.diff -r1.3 -r1.3.34.1 src/sys/arch/xen/include/shutdown_xenbus.h
(jym)
--- src/sys/arch/xen/include/shutdown_xenbus.h 2007/10/17 19:58:29 1.3
+++ src/sys/arch/xen/include/shutdown_xenbus.h 2011/08/27 15:56:48 1.3.34.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: shutdown_xenbus.h,v 1.3 2007/10/17 19:58:29 garbled Exp $ */ | 1 | /* $NetBSD: shutdown_xenbus.h,v 1.3.34.1 2011/08/27 15:56:48 jym Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c)2006 YAMAMOTO Takashi, | 4 | * Copyright (c)2006 YAMAMOTO Takashi, | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -19,16 +19,19 @@ | @@ -19,16 +19,19 @@ | |||
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 | * SUCH DAMAGE. | 26 | * SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #ifndef _XEN_SHUTDOWN_XENBUS_H_ | 29 | #ifndef _XEN_SHUTDOWN_XENBUS_H_ | |
30 | #define _XEN_SHUTDOWN_XENBUS_H_ | 30 | #define _XEN_SHUTDOWN_XENBUS_H_ | |
31 | 31 | |||
32 | /* Whether dom0 ordered a suspend (true) or not (false) */ | |||
33 | bool xen_suspend_allow; | |||
34 | ||||
32 | void shutdown_xenbus_setup(void); | 35 | void shutdown_xenbus_setup(void); | |
33 | 36 | |||
34 | #endif /* _XEN_SHUTDOWN_XENBUS_H_ */ | 37 | #endif /* _XEN_SHUTDOWN_XENBUS_H_ */ |
--- src/sys/arch/xen/include/xen.h 2011/08/27 15:48:35 1.30.8.7
+++ src/sys/arch/xen/include/xen.h 2011/08/27 15:56:48 1.30.8.8
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: xen.h,v 1.30.8.7 2011/08/27 15:48:35 jym Exp $ */ | 1 | /* $NetBSD: xen.h,v 1.30.8.8 2011/08/27 15:56:48 jym Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * | 4 | * | |
5 | * Copyright (c) 2003, 2004 Keir Fraser (on behalf of the Xen team) | 5 | * Copyright (c) 2003, 2004 Keir Fraser (on behalf of the Xen team) | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
9 | * of this software and associated documentation files (the "Software"), to | 9 | * of this software and associated documentation files (the "Software"), to | |
10 | * deal in the Software without restriction, including without limitation the | 10 | * deal in the Software without restriction, including without limitation the | |
11 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | 11 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
12 | * sell copies of the Software, and to permit persons to whom the Software is | 12 | * sell copies of the Software, and to permit persons to whom the Software is | |
13 | * furnished to do so, subject to the following conditions: | 13 | * furnished to do so, subject to the following conditions: | |
14 | * | 14 | * | |
@@ -63,27 +63,27 @@ void xenconscn_attach(void); | @@ -63,27 +63,27 @@ void xenconscn_attach(void); | |||
63 | void xenprivcmd_init(void); | 63 | void xenprivcmd_init(void); | |
64 | 64 | |||
65 | void xbdback_init(void); | 65 | void xbdback_init(void); | |
66 | void xennetback_init(void); | 66 | void xennetback_init(void); | |
67 | void xen_shm_init(void); | 67 | void xen_shm_init(void); | |
68 | 68 | |||
69 | void xenevt_event(int); | 69 | void xenevt_event(int); | |
70 | void xenevt_setipending(int, int); | 70 | void xenevt_setipending(int, int); | |
71 | void xenevt_notify(void); | 71 | void xenevt_notify(void); | |
72 | 72 | |||
73 | void idle_block(void); | 73 | void idle_block(void); | |
74 | 74 | |||
75 | /* xen_machdep.c */ | 75 | /* xen_machdep.c */ | |
76 | void sysctl_xen_sleepstate_setup(void); | 76 | void sysctl_xen_suspend_setup(void); | |
77 | 77 | |||
78 | #if defined(XENDEBUG) || 1 /* XXX */ | 78 | #if defined(XENDEBUG) || 1 /* XXX */ | |
79 | #include <sys/stdarg.h> | 79 | #include <sys/stdarg.h> | |
80 | 80 | |||
81 | void printk(const char *, ...); | 81 | void printk(const char *, ...); | |
82 | void vprintk(const char *, va_list); | 82 | void vprintk(const char *, va_list); | |
83 | #endif | 83 | #endif | |
84 | 84 | |||
85 | #endif | 85 | #endif | |
86 | 86 | |||
87 | #endif /* _XEN_H */ | 87 | #endif /* _XEN_H */ | |
88 | 88 | |||
89 | /****************************************************************************** | 89 | /****************************************************************************** |
--- src/sys/arch/xen/x86/hypervisor_machdep.c 2011/08/27 15:44:09 1.11.8.9
+++ src/sys/arch/xen/x86/hypervisor_machdep.c 2011/08/27 15:56:48 1.11.8.10
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: hypervisor_machdep.c,v 1.11.8.9 2011/08/27 15:44:09 jym Exp $ */ | 1 | /* $NetBSD: hypervisor_machdep.c,v 1.11.8.10 2011/08/27 15:56:48 jym Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * | 4 | * | |
5 | * Copyright (c) 2004 Christian Limpach. | 5 | * Copyright (c) 2004 Christian Limpach. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -44,27 +44,27 @@ | @@ -44,27 +44,27 @@ | |||
44 | * all copies or substantial portions of the Software. | 44 | * all copies or substantial portions of the Software. | |
45 | * | 45 | * | |
46 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 46 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
47 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 47 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
48 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 48 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
49 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 49 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
50 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | 50 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
51 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 51 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
52 | * DEALINGS IN THE SOFTWARE. | 52 | * DEALINGS IN THE SOFTWARE. | |
53 | */ | 53 | */ | |
54 | 54 | |||
55 | 55 | |||
56 | #include <sys/cdefs.h> | 56 | #include <sys/cdefs.h> | |
57 | __KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.11.8.9 2011/08/27 15:44:09 jym Exp $"); | 57 | __KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.11.8.10 2011/08/27 15:56:48 jym Exp $"); | |
58 | 58 | |||
59 | #include <sys/param.h> | 59 | #include <sys/param.h> | |
60 | #include <sys/systm.h> | 60 | #include <sys/systm.h> | |
61 | #include <sys/kmem.h> | 61 | #include <sys/kmem.h> | |
62 | 62 | |||
63 | #include <uvm/uvm_extern.h> | 63 | #include <uvm/uvm_extern.h> | |
64 | 64 | |||
65 | #include <machine/vmparam.h> | 65 | #include <machine/vmparam.h> | |
66 | #include <machine/pmap.h> | 66 | #include <machine/pmap.h> | |
67 | 67 | |||
68 | #include <xen/xen.h> | 68 | #include <xen/xen.h> | |
69 | #include <xen/hypervisor.h> | 69 | #include <xen/hypervisor.h> | |
70 | #include <xen/evtchn.h> | 70 | #include <xen/evtchn.h> | |
@@ -373,27 +373,27 @@ hypervisor_set_ipending(struct cpu_info | @@ -373,27 +373,27 @@ hypervisor_set_ipending(struct cpu_info | |||
373 | ipl--; | 373 | ipl--; | |
374 | KASSERT(ipl < NIPL); | 374 | KASSERT(ipl < NIPL); | |
375 | KASSERT(ci->ci_isources[ipl] != NULL); | 375 | KASSERT(ci->ci_isources[ipl] != NULL); | |
376 | ci->ci_isources[ipl]->ipl_evt_mask1 |= 1UL << l1; | 376 | ci->ci_isources[ipl]->ipl_evt_mask1 |= 1UL << l1; | |
377 | ci->ci_isources[ipl]->ipl_evt_mask2[l1] |= 1UL << l2; | 377 | ci->ci_isources[ipl]->ipl_evt_mask2[l1] |= 1UL << l2; | |
378 | } | 378 | } | |
379 | 379 | |||
380 | void | 380 | void | |
381 | hypervisor_machdep_attach(void) | 381 | hypervisor_machdep_attach(void) | |
382 | { | 382 | { | |
383 | /* dom0 does not require the arch-dependent P2M translation table */ | 383 | /* dom0 does not require the arch-dependent P2M translation table */ | |
384 | if (!xendomain_is_dom0()) { | 384 | if (!xendomain_is_dom0()) { | |
385 | build_p2m_frame_list_list(); | 385 | build_p2m_frame_list_list(); | |
386 | sysctl_xen_sleepstate_setup(); | 386 | sysctl_xen_suspend_setup(); | |
387 | } | 387 | } | |
388 | } | 388 | } | |
389 | 389 | |||
390 | void | 390 | void | |
391 | hypervisor_machdep_resume(void) | 391 | hypervisor_machdep_resume(void) | |
392 | { | 392 | { | |
393 | /* dom0 does not require the arch-dependent P2M translation table */ | 393 | /* dom0 does not require the arch-dependent P2M translation table */ | |
394 | if (!xendomain_is_dom0()) | 394 | if (!xendomain_is_dom0()) | |
395 | update_p2m_frame_list_list(); | 395 | update_p2m_frame_list_list(); | |
396 | } | 396 | } | |
397 | 397 | |||
398 | /* | 398 | /* | |
399 | * Generate the p2m_frame_list_list table, | 399 | * Generate the p2m_frame_list_list table, |
--- src/sys/arch/xen/xen/shutdown_xenbus.c 2009/11/01 21:43:28 1.5.8.3
+++ src/sys/arch/xen/xen/shutdown_xenbus.c 2011/08/27 15:56:48 1.5.8.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $Id: shutdown_xenbus.c,v 1.5.8.3 2009/11/01 21:43:28 jym Exp $ */ | 1 | /* $Id: shutdown_xenbus.c,v 1.5.8.4 2011/08/27 15:56:48 jym Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c)2006 YAMAMOTO Takashi, | 4 | * Copyright (c)2006 YAMAMOTO Takashi, | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -46,27 +46,27 @@ | @@ -46,27 +46,27 @@ | |||
46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
47 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 47 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
48 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 48 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
50 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 50 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
51 | * | 51 | * | |
52 | */ | 52 | */ | |
53 | 53 | |||
54 | /* | 54 | /* | |
55 | * watch "control/shutdown" and generate sysmon events. | 55 | * watch "control/shutdown" and generate sysmon events. | |
56 | */ | 56 | */ | |
57 | 57 | |||
58 | #include <sys/cdefs.h> | 58 | #include <sys/cdefs.h> | |
59 | __KERNEL_RCSID(0, "$NetBSD: shutdown_xenbus.c,v 1.5.8.3 2009/11/01 21:43:28 jym Exp $"); | 59 | __KERNEL_RCSID(0, "$NetBSD: shutdown_xenbus.c,v 1.5.8.4 2011/08/27 15:56:48 jym Exp $"); | |
60 | 60 | |||
61 | #include <sys/param.h> | 61 | #include <sys/param.h> | |
62 | #include <sys/malloc.h> | 62 | #include <sys/malloc.h> | |
63 | 63 | |||
64 | #include <dev/sysmon/sysmonvar.h> | 64 | #include <dev/sysmon/sysmonvar.h> | |
65 | 65 | |||
66 | #include <xen/xenbus.h> | 66 | #include <xen/xenbus.h> | |
67 | #include <xen/shutdown_xenbus.h> | 67 | #include <xen/shutdown_xenbus.h> | |
68 | 68 | |||
69 | #define SHUTDOWN_PATH "control" | 69 | #define SHUTDOWN_PATH "control" | |
70 | #define SHUTDOWN_NAME "shutdown" | 70 | #define SHUTDOWN_NAME "shutdown" | |
71 | 71 | |||
72 | static struct sysmon_pswitch xenbus_power = { | 72 | static struct sysmon_pswitch xenbus_power = { | |
@@ -120,39 +120,41 @@ again: | @@ -120,39 +120,41 @@ again: | |||
120 | free(reqstr, M_DEVBUF); | 120 | free(reqstr, M_DEVBUF); | |
121 | goto again; | 121 | goto again; | |
122 | } | 122 | } | |
123 | if (error != 0) { | 123 | if (error != 0) { | |
124 | printf("%s: xenbus_transaction_end 2 %d\n", __func__, error); | 124 | printf("%s: xenbus_transaction_end 2 %d\n", __func__, error); | |
125 | } | 125 | } | |
126 | if (strcmp(reqstr, "poweroff") == 0) { | 126 | if (strcmp(reqstr, "poweroff") == 0) { | |
127 | sysmon_pswitch_event(&xenbus_power, PSWITCH_EVENT_PRESSED); | 127 | sysmon_pswitch_event(&xenbus_power, PSWITCH_EVENT_PRESSED); | |
128 | } else if (strcmp(reqstr, "halt") == 0) { /* XXX eventually halt without -p */ | 128 | } else if (strcmp(reqstr, "halt") == 0) { /* XXX eventually halt without -p */ | |
129 | sysmon_pswitch_event(&xenbus_power, PSWITCH_EVENT_PRESSED); | 129 | sysmon_pswitch_event(&xenbus_power, PSWITCH_EVENT_PRESSED); | |
130 | } else if (strcmp(reqstr, "reboot") == 0) { | 130 | } else if (strcmp(reqstr, "reboot") == 0) { | |
131 | sysmon_pswitch_event(&xenbus_reset, PSWITCH_EVENT_PRESSED); | 131 | sysmon_pswitch_event(&xenbus_reset, PSWITCH_EVENT_PRESSED); | |
132 | } else if (strcmp(reqstr, "suspend") == 0) { | 132 | } else if (strcmp(reqstr, "suspend") == 0) { | |
133 | xen_suspend_allow = true; | |||
133 | sysmon_pswitch_event(&xenbus_sleep, PSWITCH_EVENT_PRESSED); | 134 | sysmon_pswitch_event(&xenbus_sleep, PSWITCH_EVENT_PRESSED); | |
134 | } else { | 135 | } else { | |
135 | printf("ignore shutdown request: %s\n", reqstr); | 136 | printf("ignore shutdown request: %s\n", reqstr); | |
136 | } | 137 | } | |
137 | free(reqstr, M_DEVBUF); | 138 | free(reqstr, M_DEVBUF); | |
138 | } | 139 | } | |
139 | 140 | |||
140 | static struct xenbus_watch xenbus_shutdown_watch = { | 141 | static struct xenbus_watch xenbus_shutdown_watch = { | |
141 | .node = __UNCONST(SHUTDOWN_PATH "/" SHUTDOWN_NAME), /* XXX */ | 142 | .node = __UNCONST(SHUTDOWN_PATH "/" SHUTDOWN_NAME), /* XXX */ | |
142 | .xbw_callback = xenbus_shutdown_handler, | 143 | .xbw_callback = xenbus_shutdown_handler, | |
143 | }; | 144 | }; | |
144 | 145 | |||
145 | void | 146 | void | |
146 | shutdown_xenbus_setup(void) | 147 | shutdown_xenbus_setup(void) | |
147 | { | 148 | { | |
149 | xen_suspend_allow = false; | |||
148 | 150 | |||
149 | if (sysmon_pswitch_register(&xenbus_power) != 0 || | 151 | if (sysmon_pswitch_register(&xenbus_power) != 0 || | |
150 | sysmon_pswitch_register(&xenbus_reset) != 0 || | 152 | sysmon_pswitch_register(&xenbus_reset) != 0 || | |
151 | sysmon_pswitch_register(&xenbus_sleep) != 0) { | 153 | sysmon_pswitch_register(&xenbus_sleep) != 0) { | |
152 | aprint_error("%s: unable to register with sysmon\n", __func__); | 154 | aprint_error("%s: unable to register with sysmon\n", __func__); | |
153 | return; | 155 | return; | |
154 | } | 156 | } | |
155 | if (register_xenbus_watch(&xenbus_shutdown_watch)) { | 157 | if (register_xenbus_watch(&xenbus_shutdown_watch)) { | |
156 | aprint_error("%s: unable to watch control/shutdown\n", __func__); | 158 | aprint_error("%s: unable to watch control/shutdown\n", __func__); | |
157 | } | 159 | } | |
158 | } | 160 | } |
--- src/sys/arch/xen/xen/xen_machdep.c 2011/08/24 21:37:05 1.4.12.9
+++ src/sys/arch/xen/xen/xen_machdep.c 2011/08/27 15:56:48 1.4.12.10
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: xen_machdep.c,v 1.4.12.9 2011/08/24 21:37:05 jym Exp $ */ | 1 | /* $NetBSD: xen_machdep.c,v 1.4.12.10 2011/08/27 15:56:48 jym Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2006 Manuel Bouyer. | 4 | * Copyright (c) 2006 Manuel Bouyer. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * | 14 | * | |
@@ -43,51 +43,52 @@ | @@ -43,51 +43,52 @@ | |||
43 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 43 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
44 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 44 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
45 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 45 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
46 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 46 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
47 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 47 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
48 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 48 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
49 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 49 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
50 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 50 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
51 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 51 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
52 | */ | 52 | */ | |
53 | 53 | |||
54 | 54 | |||
55 | #include <sys/cdefs.h> | 55 | #include <sys/cdefs.h> | |
56 | __KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.4.12.9 2011/08/24 21:37:05 jym Exp $"); | 56 | __KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.4.12.10 2011/08/27 15:56:48 jym Exp $"); | |
57 | 57 | |||
58 | #include "opt_xen.h" | 58 | #include "opt_xen.h" | |
59 | 59 | |||
60 | #include <sys/param.h> | 60 | #include <sys/param.h> | |
61 | #include <sys/systm.h> | 61 | #include <sys/systm.h> | |
62 | #include <sys/boot_flag.h> | 62 | #include <sys/boot_flag.h> | |
63 | #include <sys/mount.h> | 63 | #include <sys/mount.h> | |
64 | #include <sys/reboot.h> | 64 | #include <sys/reboot.h> | |
65 | #include <sys/timetc.h> | 65 | #include <sys/timetc.h> | |
66 | #include <sys/sysctl.h> | 66 | #include <sys/sysctl.h> | |
67 | #include <sys/pmf.h> | 67 | #include <sys/pmf.h> | |
68 | 68 | |||
69 | #include <xen/hypervisor.h> | 69 | #include <xen/hypervisor.h> | |
70 | #include <xen/shutdown_xenbus.h> | |||
70 | 71 | |||
71 | #define DPRINTK(x) printk x | 72 | #define DPRINTK(x) printk x | |
72 | #if 0 | 73 | #if 0 | |
73 | #define DPRINTK(x) | 74 | #define DPRINTK(x) | |
74 | #endif | 75 | #endif | |
75 | 76 | |||
76 | u_int tsc_get_timecount(struct timecounter *); | 77 | u_int tsc_get_timecount(struct timecounter *); | |
77 | 78 | |||
78 | uint64_t tsc_freq; /* XXX */ | 79 | uint64_t tsc_freq; /* XXX */ | |
79 | 80 | |||
80 | static int sysctl_xen_sleepstate(SYSCTLFN_ARGS); | 81 | static int sysctl_xen_suspend(SYSCTLFN_ARGS); | |
81 | static void xen_suspend_domain(void); | 82 | static void xen_suspend_domain(void); | |
82 | static void xen_prepare_suspend(void); | 83 | static void xen_prepare_suspend(void); | |
83 | static void xen_prepare_resume(void); | 84 | static void xen_prepare_resume(void); | |
84 | 85 | |||
85 | void | 86 | void | |
86 | xen_parse_cmdline(int what, union xen_cmdline_parseinfo *xcp) | 87 | xen_parse_cmdline(int what, union xen_cmdline_parseinfo *xcp) | |
87 | { | 88 | { | |
88 | char _cmd_line[256], *cmd_line, *opt, *s; | 89 | char _cmd_line[256], *cmd_line, *opt, *s; | |
89 | int b, i, ipidx = 0; | 90 | int b, i, ipidx = 0; | |
90 | uint32_t xi_ip[5]; | 91 | uint32_t xi_ip[5]; | |
91 | size_t len; | 92 | size_t len; | |
92 | 93 | |||
93 | len = strlcpy(_cmd_line, xen_start_info.cmd_line, sizeof(_cmd_line)); | 94 | len = strlcpy(_cmd_line, xen_start_info.cmd_line, sizeof(_cmd_line)); | |
@@ -212,82 +213,86 @@ xen_parse_cmdline(int what, union xen_cm | @@ -212,82 +213,86 @@ xen_parse_cmdline(int what, union xen_cm | |||
212 | 213 | |||
213 | u_int | 214 | u_int | |
214 | tsc_get_timecount(struct timecounter *tc) | 215 | tsc_get_timecount(struct timecounter *tc) | |
215 | { | 216 | { | |
216 | 217 | |||
217 | panic("xen: tsc_get_timecount"); | 218 | panic("xen: tsc_get_timecount"); | |
218 | } | 219 | } | |
219 | 220 | |||
220 | /* | 221 | /* | |
221 | * this function sets up the machdep.xen.suspend sysctl(7) that | 222 | * this function sets up the machdep.xen.suspend sysctl(7) that | |
222 | * controls domain suspend/save. | 223 | * controls domain suspend/save. | |
223 | */ | 224 | */ | |
224 | void | 225 | void | |
225 | sysctl_xen_sleepstate_setup(void) | 226 | sysctl_xen_suspend_setup(void) | |
226 | { | 227 | { | |
227 | const struct sysctlnode *node = NULL; | 228 | const struct sysctlnode *node = NULL; | |
228 | 229 | |||
229 | /* | 230 | /* | |
230 | * dom0 implements sleep support through ACPI. It should not call this | 231 | * dom0 implements sleep support through ACPI. It should not call this | |
231 | * this function to register a suspend interface. | 232 | * this function to register a suspend interface. | |
232 | */ | 233 | */ | |
233 | KASSERT(!(xendomain_is_dom0())); | 234 | KASSERT(!(xendomain_is_dom0())); | |
234 | 235 | |||
235 | sysctl_createv(clog, 0, NULL, &node, | 236 | sysctl_createv(NULL, 0, NULL, &node, | |
236 | CTLFLAG_PERMANENT, | 237 | CTLFLAG_PERMANENT, | |
237 | CTLTYPE_NODE, "machdep", NULL, | 238 | CTLTYPE_NODE, "machdep", NULL, | |
238 | NULL, 0, NULL, 0, | 239 | NULL, 0, NULL, 0, | |
239 | CTL_MACHDEP, CTL_EOL); | 240 | CTL_MACHDEP, CTL_EOL); | |
240 | 241 | |||
241 | sysctl_createv(clog, 0, &node, &node, | 242 | sysctl_createv(NULL, 0, &node, &node, | |
242 | CTLFLAG_PERMANENT, | 243 | CTLFLAG_PERMANENT, | |
243 | CTLTYPE_NODE, "xen", | 244 | CTLTYPE_NODE, "xen", | |
244 | SYSCTL_DESCR("Xen top level node"), | 245 | SYSCTL_DESCR("Xen top level node"), | |
245 | NULL, 0, NULL, 0, | 246 | NULL, 0, NULL, 0, | |
246 | CTL_CREATE, CTL_EOL); | 247 | CTL_CREATE, CTL_EOL); | |
247 | 248 | |||
248 | sysctl_createv(clog, 0, &node, &node, | 249 | sysctl_createv(NULL, 0, &node, &node, | |
249 | CTLFLAG_PERMANENT | CTLFLAG_READWRITE, | 250 | CTLFLAG_PERMANENT | CTLFLAG_READWRITE, | |
250 | CTLTYPE_INT, "suspend", | 251 | CTLTYPE_INT, "suspend", | |
251 | SYSCTL_DESCR("Suspend/save control of current Xen domain"), | 252 | SYSCTL_DESCR("Suspend/save current Xen domain"), | |
252 | NULL, sysctl_xen_sleepstate, 0, NULL, 0, | 253 | sysctl_xen_suspend, 0, NULL, 0, | |
253 | CTL_CREATE, CTL_EOL); | 254 | CTL_CREATE, CTL_EOL); | |
254 | } | 255 | } | |
255 | 256 | |||
256 | static int | 257 | static int | |
257 | sysctl_xen_sleepstate(SYSCTLFN_ARGS) { | 258 | sysctl_xen_suspend(SYSCTLFN_ARGS) | |
258 | 259 | { | ||
259 | int error, t; | 260 | int error, t; | |
260 | struct sysctlnode node; | 261 | struct sysctlnode node; | |
261 | 262 | |||
262 | node = *rnode; | 263 | node = *rnode; | |
263 | node.sysctl_data = &t; | 264 | node.sysctl_data = &t; | |
264 | error = sysctl_lookup(SYSCTLFN_CALL(&node)); | 265 | error = sysctl_lookup(SYSCTLFN_CALL(&node)); | |
265 | 266 | |||
266 | if (error || newp == NULL) | 267 | if (error || newp == NULL) | |
267 | return error; | 268 | return error; | |
268 | 269 | |||
270 | /* only allow domain to suspend when dom0 instructed to do so */ | |||
271 | if (xen_suspend_allow == false) | |||
272 | return EAGAIN; | |||
273 | ||||
269 | xen_suspend_domain(); | 274 | xen_suspend_domain(); | |
270 | 275 | |||
271 | return 0; | 276 | return 0; | |
272 | 277 | |||
273 | } | 278 | } | |
274 | 279 | |||
275 | /* | 280 | /* | |
276 | * Last operations before suspending domain | 281 | * Last operations before suspending domain | |
277 | */ | 282 | */ | |
278 | static void | 283 | static void | |
279 | xen_prepare_suspend(void) { | 284 | xen_prepare_suspend(void) | |
280 | 285 | { | ||
281 | kpreempt_disable(); | 286 | kpreempt_disable(); | |
282 | 287 | |||
283 | /* | 288 | /* | |
284 | * Xen lazy evaluation of recursive mappings requires | 289 | * Xen lazy evaluation of recursive mappings requires | |
285 | * to flush the APDP entries | 290 | * to flush the APDP entries | |
286 | */ | 291 | */ | |
287 | pmap_unmap_all_apdp_pdes(); | 292 | pmap_unmap_all_apdp_pdes(); | |
288 | 293 | |||
289 | #ifdef PAE | 294 | #ifdef PAE | |
290 | pmap_unmap_recursive_entries(); | 295 | pmap_unmap_recursive_entries(); | |
291 | #endif | 296 | #endif | |
292 | 297 | |||
293 | xen_suspendclocks(); | 298 | xen_suspendclocks(); | |
@@ -305,61 +310,63 @@ xen_prepare_suspend(void) { | @@ -305,61 +310,63 @@ xen_prepare_suspend(void) { | |||
305 | /* invalidate the shared_info page */ | 310 | /* invalidate the shared_info page */ | |
306 | if (HYPERVISOR_update_va_mapping((vaddr_t)HYPERVISOR_shared_info, | 311 | if (HYPERVISOR_update_va_mapping((vaddr_t)HYPERVISOR_shared_info, | |
307 | 0, UVMF_INVLPG)) { | 312 | 0, UVMF_INVLPG)) { | |
308 | DPRINTK(("HYPERVISOR_shared_info page invalidation failed")); | 313 | DPRINTK(("HYPERVISOR_shared_info page invalidation failed")); | |
309 | HYPERVISOR_crash(); | 314 | HYPERVISOR_crash(); | |
310 | } | 315 | } | |
311 | 316 | |||
312 | } | 317 | } | |
313 | 318 | |||
314 | /* | 319 | /* | |
315 | * First operations before restoring domain context | 320 | * First operations before restoring domain context | |
316 | */ | 321 | */ | |
317 | static void | 322 | static void | |
318 | xen_prepare_resume(void) { | 323 | xen_prepare_resume(void) | |
319 | 324 | { | ||
320 | /* map the new shared_info page */ | 325 | /* map the new shared_info page */ | |
321 | if (HYPERVISOR_update_va_mapping((vaddr_t)HYPERVISOR_shared_info, | 326 | if (HYPERVISOR_update_va_mapping((vaddr_t)HYPERVISOR_shared_info, | |
322 | xen_start_info.shared_info | PG_RW | PG_V, | 327 | xen_start_info.shared_info | PG_RW | PG_V, | |
323 | UVMF_INVLPG)) { | 328 | UVMF_INVLPG)) { | |
324 | DPRINTK(("could not map new shared info page")); | 329 | DPRINTK(("could not map new shared info page")); | |
325 | HYPERVISOR_crash(); | 330 | HYPERVISOR_crash(); | |
326 | } | 331 | } | |
327 | 332 | |||
328 | #ifdef PAE | 333 | #ifdef PAE | |
329 | pmap_map_recursive_entries(); | 334 | pmap_map_recursive_entries(); | |
330 | #endif | 335 | #endif | |
331 | 336 | |||
332 | if (xen_start_info.nr_pages != physmem) { | 337 | if (xen_start_info.nr_pages != physmem) { | |
333 | /* | 338 | /* | |
334 | * XXX JYM for now, we crash - fix it with memory | 339 | * XXX JYM for now, we crash - fix it with memory | |
335 | * hotplug when supported | 340 | * hotplug when supported | |
336 | */ | 341 | */ | |
337 | DPRINTK(("xen_start_info.nr_pages != physmem")); | 342 | DPRINTK(("xen_start_info.nr_pages != physmem")); | |
338 | HYPERVISOR_crash(); | 343 | HYPERVISOR_crash(); | |
339 | } | 344 | } | |
340 | 345 | |||
341 | DPRINTK(("preparing domain resume\n")); | 346 | DPRINTK(("preparing domain resume\n")); | |
342 | aprint_verbose("preparing domain resume\n"); | 347 | aprint_verbose("preparing domain resume\n"); | |
343 | 348 | |||
349 | xen_suspend_allow = false; | |||
350 | ||||
344 | xen_resumeclocks(); | 351 | xen_resumeclocks(); | |
345 | 352 | |||
346 | kpreempt_enable(); | 353 | kpreempt_enable(); | |
347 | 354 | |||
348 | } | 355 | } | |
349 | 356 | |||
350 | static void | 357 | static void | |
351 | xen_suspend_domain(void) { | 358 | xen_suspend_domain(void) | |
352 | 359 | { | ||
353 | paddr_t mfn; | 360 | paddr_t mfn; | |
354 | int s = splvm(); | 361 | int s = splvm(); | |
355 | 362 | |||
356 | /* | 363 | /* | |
357 | * console becomes unavailable when suspended, so | 364 | * console becomes unavailable when suspended, so | |
358 | * direct communications to domain are hampered from there on. | 365 | * direct communications to domain are hampered from there on. | |
359 | * We can only rely on low level primitives like printk(), until | 366 | * We can only rely on low level primitives like printk(), until | |
360 | * console is fully restored | 367 | * console is fully restored | |
361 | */ | 368 | */ | |
362 | if (!pmf_system_suspend(PMF_Q_NONE)) { | 369 | if (!pmf_system_suspend(PMF_Q_NONE)) { | |
363 | DPRINTK(("devices suspend failed")); | 370 | DPRINTK(("devices suspend failed")); | |
364 | HYPERVISOR_crash(); | 371 | HYPERVISOR_crash(); | |
365 | } | 372 | } |