acpi_wakeup.c (236938) | acpi_wakeup.c (237037) |
---|---|
1/*- 2 * Copyright (c) 2001 Takanori Watanabe <takawata@jp.freebsd.org> 3 * Copyright (c) 2001-2012 Mitsuru IWASAKI <iwasaki@jp.freebsd.org> 4 * Copyright (c) 2003 Peter Wemm 5 * Copyright (c) 2008-2012 Jung-uk Kim <jkim@FreeBSD.org> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2001 Takanori Watanabe <takawata@jp.freebsd.org> 3 * Copyright (c) 2001-2012 Mitsuru IWASAKI <iwasaki@jp.freebsd.org> 4 * Copyright (c) 2003 Peter Wemm 5 * Copyright (c) 2008-2012 Jung-uk Kim <jkim@FreeBSD.org> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sys/x86/acpica/acpi_wakeup.c 236938 2012-06-12 00:14:54Z iwasaki $"); | 31__FBSDID("$FreeBSD: head/sys/x86/acpica/acpi_wakeup.c 237037 2012-06-13 22:53:56Z jkim $"); |
32 33#include <sys/param.h> 34#include <sys/bus.h> 35#include <sys/eventhandler.h> 36#include <sys/kernel.h> 37#include <sys/malloc.h> 38#include <sys/memrange.h> 39#include <sys/smp.h> --- 44 unchanged lines hidden (view full) --- 84#endif 85 86#ifdef __amd64__ 87#define ACPI_PAGETABLES 3 88#else 89#define ACPI_PAGETABLES 0 90#endif 91 | 32 33#include <sys/param.h> 34#include <sys/bus.h> 35#include <sys/eventhandler.h> 36#include <sys/kernel.h> 37#include <sys/malloc.h> 38#include <sys/memrange.h> 39#include <sys/smp.h> --- 44 unchanged lines hidden (view full) --- 84#endif 85 86#ifdef __amd64__ 87#define ACPI_PAGETABLES 3 88#else 89#define ACPI_PAGETABLES 0 90#endif 91 |
92#define WAKECODE_VADDR(sc) ((sc)->acpi_wakeaddr + (ACPI_PAGETABLES * PAGE_SIZE)) 93#define WAKECODE_PADDR(sc) ((sc)->acpi_wakephys + (ACPI_PAGETABLES * PAGE_SIZE)) 94#define WAKECODE_FIXUP(offset, type, val) do { \ | 92#define WAKECODE_VADDR(sc) \ 93 ((sc)->acpi_wakeaddr + (ACPI_PAGETABLES * PAGE_SIZE)) 94#define WAKECODE_PADDR(sc) \ 95 ((sc)->acpi_wakephys + (ACPI_PAGETABLES * PAGE_SIZE)) 96#define WAKECODE_FIXUP(offset, type, val) do { \ |
95 type *addr; \ 96 addr = (type *)(WAKECODE_VADDR(sc) + offset); \ 97 *addr = val; \ 98} while (0) 99 100static void 101acpi_stop_beep(void *arg) 102{ --- 102 unchanged lines hidden (view full) --- 205 device_printf(sc->acpi_dev, "Failed to suspend APs\n"); 206 return (0); /* couldn't sleep */ 207 } 208#endif 209 210 WAKECODE_FIXUP(resume_beep, uint8_t, (acpi_resume_beep != 0)); 211 WAKECODE_FIXUP(reset_video, uint8_t, (acpi_reset_video != 0)); 212 | 97 type *addr; \ 98 addr = (type *)(WAKECODE_VADDR(sc) + offset); \ 99 *addr = val; \ 100} while (0) 101 102static void 103acpi_stop_beep(void *arg) 104{ --- 102 unchanged lines hidden (view full) --- 207 device_printf(sc->acpi_dev, "Failed to suspend APs\n"); 208 return (0); /* couldn't sleep */ 209 } 210#endif 211 212 WAKECODE_FIXUP(resume_beep, uint8_t, (acpi_resume_beep != 0)); 213 WAKECODE_FIXUP(reset_video, uint8_t, (acpi_reset_video != 0)); 214 |
215#ifndef __amd64__ |
|
213 WAKECODE_FIXUP(wakeup_cr4, register_t, susppcbs[0]->pcb_cr4); | 216 WAKECODE_FIXUP(wakeup_cr4, register_t, susppcbs[0]->pcb_cr4); |
217#endif |
|
214 WAKECODE_FIXUP(wakeup_pcb, struct pcb *, susppcbs[0]); 215 WAKECODE_FIXUP(wakeup_gdt, uint16_t, 216 susppcbs[0]->pcb_gdt.rd_limit); 217 WAKECODE_FIXUP(wakeup_gdt + 2, uint64_t, 218 susppcbs[0]->pcb_gdt.rd_base); 219 220 /* Call ACPICA to enter the desired sleep state */ 221 if (state == ACPI_STATE_S4 && sc->acpi_s4bios) --- 21 unchanged lines hidden (view full) --- 243 244 if (sleep_result == -1) 245 return (sleep_result); 246 247 if (!intr_enabled) { 248 /* Wakeup MD procedures in interrupt disabled context */ 249 if (sleep_result == 1) { 250 pmap_init_pat(); | 218 WAKECODE_FIXUP(wakeup_pcb, struct pcb *, susppcbs[0]); 219 WAKECODE_FIXUP(wakeup_gdt, uint16_t, 220 susppcbs[0]->pcb_gdt.rd_limit); 221 WAKECODE_FIXUP(wakeup_gdt + 2, uint64_t, 222 susppcbs[0]->pcb_gdt.rd_base); 223 224 /* Call ACPICA to enter the desired sleep state */ 225 if (state == ACPI_STATE_S4 && sc->acpi_s4bios) --- 21 unchanged lines hidden (view full) --- 247 248 if (sleep_result == -1) 249 return (sleep_result); 250 251 if (!intr_enabled) { 252 /* Wakeup MD procedures in interrupt disabled context */ 253 if (sleep_result == 1) { 254 pmap_init_pat(); |
251#if 0 252 load_cr3(susppcbs[0]->pcb_cr3); 253#endif | |
254 initializecpu(); 255 PCPU_SET(switchtime, 0); 256 PCPU_SET(switchticks, ticks); 257#ifdef SMP 258 if (!CPU_EMPTY(&suspcpus)) 259 acpi_wakeup_cpus(sc); 260#endif 261 } --- 33 unchanged lines hidden (view full) --- 295 M_WAITOK, 0x500, 0xa0000, PAGE_SIZE, 0ul); 296 if (wakeaddr == NULL) { 297 printf("%s: can't alloc wake memory\n", __func__); 298 return (NULL); 299 } 300 if (EVENTHANDLER_REGISTER(power_resume, acpi_stop_beep, NULL, 301 EVENTHANDLER_PRI_LAST) == NULL) { 302 printf("%s: can't register event handler\n", __func__); | 255 initializecpu(); 256 PCPU_SET(switchtime, 0); 257 PCPU_SET(switchticks, ticks); 258#ifdef SMP 259 if (!CPU_EMPTY(&suspcpus)) 260 acpi_wakeup_cpus(sc); 261#endif 262 } --- 33 unchanged lines hidden (view full) --- 296 M_WAITOK, 0x500, 0xa0000, PAGE_SIZE, 0ul); 297 if (wakeaddr == NULL) { 298 printf("%s: can't alloc wake memory\n", __func__); 299 return (NULL); 300 } 301 if (EVENTHANDLER_REGISTER(power_resume, acpi_stop_beep, NULL, 302 EVENTHANDLER_PRI_LAST) == NULL) { 303 printf("%s: can't register event handler\n", __func__); |
303 contigfree(wakeaddr, (ACPI_PAGETABLES + 1) * PAGE_SIZE, M_DEVBUF); | 304 contigfree(wakeaddr, (ACPI_PAGETABLES + 1) * PAGE_SIZE, 305 M_DEVBUF); |
304 return (NULL); 305 } 306 susppcbs = malloc(mp_ncpus * sizeof(*susppcbs), M_DEVBUF, M_WAITOK); 307 for (i = 0; i < mp_ncpus; i++) { 308 susppcbs[i] = malloc(sizeof(**susppcbs), M_DEVBUF, M_WAITOK); 309#ifdef __amd64__ 310 susppcbs[i]->pcb_fpususpend = alloc_fpusave(M_WAITOK); 311#endif --- 31 unchanged lines hidden (view full) --- 343#ifdef __amd64__ 344 WAKECODE_FIXUP((wakeup_sw64 + 1), uint32_t, 345 WAKECODE_PADDR(sc) + wakeup_64); 346 WAKECODE_FIXUP(wakeup_pagetables, uint32_t, sc->acpi_wakephys); 347#endif 348 349 /* Save pointers to some global data. */ 350 WAKECODE_FIXUP(wakeup_ret, void *, resumectx); | 306 return (NULL); 307 } 308 susppcbs = malloc(mp_ncpus * sizeof(*susppcbs), M_DEVBUF, M_WAITOK); 309 for (i = 0; i < mp_ncpus; i++) { 310 susppcbs[i] = malloc(sizeof(**susppcbs), M_DEVBUF, M_WAITOK); 311#ifdef __amd64__ 312 susppcbs[i]->pcb_fpususpend = alloc_fpusave(M_WAITOK); 313#endif --- 31 unchanged lines hidden (view full) --- 345#ifdef __amd64__ 346 WAKECODE_FIXUP((wakeup_sw64 + 1), uint32_t, 347 WAKECODE_PADDR(sc) + wakeup_64); 348 WAKECODE_FIXUP(wakeup_pagetables, uint32_t, sc->acpi_wakephys); 349#endif 350 351 /* Save pointers to some global data. */ 352 WAKECODE_FIXUP(wakeup_ret, void *, resumectx); |
351#ifdef __amd64__ 352 WAKECODE_FIXUP(wakeup_cr3, uint64_t, KPML4phys); 353#else | 353#ifndef __amd64__ |
354#ifdef PAE 355 WAKECODE_FIXUP(wakeup_cr3, register_t, vtophys(kernel_pmap->pm_pdpt)); 356#else 357 WAKECODE_FIXUP(wakeup_cr3, register_t, vtophys(kernel_pmap->pm_pdir)); 358#endif | 354#ifdef PAE 355 WAKECODE_FIXUP(wakeup_cr3, register_t, vtophys(kernel_pmap->pm_pdpt)); 356#else 357 WAKECODE_FIXUP(wakeup_cr3, register_t, vtophys(kernel_pmap->pm_pdir)); 358#endif |
359#endif | |
360 | 359 |
361#ifdef __amd64__ | 360#else |
362 /* Build temporary page tables below realmode code. */ 363 pt4 = wakeaddr; 364 pt3 = pt4 + (PAGE_SIZE) / sizeof(uint64_t); 365 pt2 = pt3 + (PAGE_SIZE) / sizeof(uint64_t); 366 367 /* Create the initial 1GB replicated page tables */ 368 for (i = 0; i < 512; i++) { 369 /* --- 23 unchanged lines hidden --- | 361 /* Build temporary page tables below realmode code. */ 362 pt4 = wakeaddr; 363 pt3 = pt4 + (PAGE_SIZE) / sizeof(uint64_t); 364 pt2 = pt3 + (PAGE_SIZE) / sizeof(uint64_t); 365 366 /* Create the initial 1GB replicated page tables */ 367 for (i = 0; i < 512; i++) { 368 /* --- 23 unchanged lines hidden --- |