wakeup code translated to .c
Subsystems (4)
Hi!
This version works on 32-bit, and builds on 64-bit (but I'm pretty sure it does not work. 32-bit code probably needs to go into rm/....)
Pavel
arch/x86/boot/Makefile +2 -1
@@ -30,7 +30,8 @@ subdir- := compressed setup-y += a20.o apm.o cmdline.o copy.o cpu.o cpucheck.o edd.o setup-y += header.o main.o mca.o memory.o pm.o pmjump.o -setup-y += printf.o string.o tty.o video.o version.o voyager.o +setup-y += printf.o string.o tty.o video.o video-mode.o +setup-y += version.o voyager.o # The link order of the video-*.o modules can matter. In particular, # video-vga.o *must* be listed first, followed by video-vesa.o.
arch/x86/boot/boot.h +5 -0
@@ -285,6 +285,11 @@ int getchar_timeout(void);/* video.c */ void set_video (void ); +/* video-mode.c */ +int set_mode (u16 mode); +int mode_defined (u16 mode); +void probe_cards (int unsafe); +/* video-vesa.c */ void vesa_store_edid (void );
arch/x86/boot/video-bios.c +6 -0
@@ -50,6 +50,7 @@ static int set_bios_mode(u8 mode)if (new_mode == mode)return 0 ;/* Mode change OK */ +#ifndef _WAKEUPif (new_mode != boot_params.screen_info.orig_video_mode) {/* Mode setting failed, but we didn't end up where we started. That's bad. Try to revert to the original
@@ -59,13 +60,18 @@ static int set_bios_mode(u8 mode) : "+a" (ax) : : "ebx", "ecx", "edx", "esi", "edi"); } +#endif return -1 ; }static int bios_probe (void ) {u8 mode; +#ifdef _WAKEUP +u8 saved_mode =0x03 ; +#else u8 saved_mode = boot_params.screen_info.orig_video_mode; +#endif u16 crtc;struct mode_info *mi;int nmodes =0 ;
arch/x86/boot/video-mode.c new file +173 -0
173 lines not on this page · raw message
arch/x86/boot/video-vesa.c +8 -0
@@ -152,7 +152,9 @@ static int vesa_set_mode(struct mode_inf do_restore =1 ; }else {/* Graphics mode */ +#ifndef _WAKEUPvesa_store_mode_params_graphics (); +#endif }return 0 ;
@@ -179,6 +181,7 @@ static void vesa_dac_set_8bits(void) }/* Set the color sizes to the DAC size, and offsets to 0 */ +#ifndef _WAKEUP boot_params.screen_info.red_size = dac_size; boot_params.screen_info.green_size = dac_size; boot_params.screen_info.blue_size = dac_size;
@@ -188,8 +191,11 @@ static void vesa_dac_set_8bits(void) boot_params.screen_info.green_pos =0 ; boot_params.screen_info.blue_pos =0 ; boot_params.screen_info.rsvd_pos =0 ; +#endif } +#ifndef _WAKEUP +/* Save the VESA protected mode info */ static void vesa_store_pm_info (void ) {
@@ -282,6 +288,8 @@ #ifdef CONFIG_FIRMWARE_EDID#endif /* CONFIG_FIRMWARE_EDID */ } +#endif /* not _WAKEUP */ +__videocard video_vesa = { .card_name ="VESA" ,
arch/x86/boot/video-vga.c +10 -2
@@ -210,6 +210,8 @@ static int vga_set_mode(struct mode_info*/ static int vga_probe (void ) { +u16 ega_bx; +static const char *card_name[] = {"CGA/MDA/HGC" ,"EGA" ,"VGA" };
@@ -226,12 +228,16 @@ static int vga_probe(void)u8 vga_flag; asm(INT10 - : "=b" (boot_params.screen_info.orig_video_ega_bx) + : "=b" (ega_bx) : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */ : "ecx", "edx", "esi", "edi"); +#ifndef _WAKEUP + boot_params.screen_info.orig_video_ega_bx = ega_bx; +#endif +/* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */ -if ((u8 )boot_params.screen_info.orig_video_ega_bx !=0x10 ) { +if ((u8 )ega_bx !=0x10 ) {/* EGA/VGA */ asm(INT10 : "=a" (vga_flag)
@@ -240,7 +246,9 @@ static int vga_probe(void)if (vga_flag ==0x1a ) { adapter =ADAPTER_VGA ; +#ifndef _WAKEUP boot_params.screen_info.orig_video_isVGA =1 ; +#endif }else { adapter =ADAPTER_EGA ; }
arch/x86/boot/video.c +1 -156
175 lines not on this page · raw message
arch/x86/kernel/acpi/Makefile +8 -1
@@ -1,7 +1,14 @@ +subdir- := rm + obj-$(CONFIG_ACPI) += boot.o -obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_$(BITS).o +obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_rm.o wakeup_$(BITS).o ifneq ($(CONFIG_ACPI_PROCESSOR),) obj-y += cstate.o processor.o endif +$(obj)/wakeup_rm.o: $(obj)/rm/wakeup.bin + +$(obj)/rm/wakeup.bin: FORCE + $(Q)$(MAKE) $(build)=$(obj)/rm $@ +
arch/x86/kernel/acpi/rm/Makefile new file +55 -0
55 lines not on this page · raw message
arch/x86/kernel/acpi/rm/copy.S new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/copy.S"
arch/x86/kernel/acpi/rm/video-bios.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-bios.c"
arch/x86/kernel/acpi/rm/video-mode.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-mode.c"
arch/x86/kernel/acpi/rm/video-vesa.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-vesa.c"
arch/x86/kernel/acpi/rm/video-vga.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-vga.c"
arch/x86/kernel/acpi/rm/wakemain.c new file +35 -0
@@ -0,0 +1,35 @@ +#include "wakeup.h" +#include "boot.h" + +extern struct wakeup_header wakeup_header; + +void main (void ) +{ + asmvolatile ("movb $0x00, %al; outb %al, $0x80" ); + +if (wakeup_header.real_magic !=0x12345678 ) { + asmvolatile ("inb $97, %al; outb %al, $0x80; movb $3, %al; outb %al, $97; outb %al, $0x80; movb $-74, %al; outb %al, $67; outb %al, $0x80; movb $-119, %al; outb %al, $66; outb %al, $0x80; movb $15, %al; outb %al, $66" ); +while (1 ); + } +#if 0 +if (wakeup_header.realmode_flags &4 ) { + asmvolatile ("inb $97, %al; outb %al, $0x80; movb $3, %al; outb %al, $97; outb %al, $0x80; movb $-74, %al; outb %al, $67; outb %al, $0x80; movb $-119, %al; outb %al, $66; outb %al, $0x80; movb $15, %al; outb %al, $66" ); + } +#endif + +if (wakeup_header.realmode_flags &1 ) { + asmvolatile ("lcallw $0xc000,$3" ); +// ("movw %cs, %ax; movw %ax, %ds; movw %ax, %es; movw %ax, %ss"); + } + +if (wakeup_header.realmode_flags &2 ) { +/* Need to call BIOS */ +probe_cards (0 ); +set_mode (wakeup_header.video_mode); +// set_mode(6); + } + + asmvolatile ("movb $0x01, %al; outb %al, $0x80" ); + +/* Set up GDT and IDT here, possibly CR4 and EFER */ +}
arch/x86/kernel/acpi/rm/wakeup.S new file +166 -0
166 lines not on this page · raw message
arch/x86/kernel/acpi/rm/wakeup.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* Definitions for the wakeup data structure at the head of the +* wakeup code. +*/ + +#ifndef ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H +#define ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H + +#include <linux/types.h> + +/* This must match data at wakeup.S */ +struct wakeup_header { +u16 entry;/* unused */ +u16 total;/* unused */ +u16 video_mode;/* Video mode number */ +u16 _jmp1; +u32 pmode_entry;/* Protected mode resume point */ +u16 _jmp2; +u32 pmode_cr0;/* Protected mode cr0 */ +u32 pmode_cr3;/* Protected mode cr3 */ +u32 pmode_cr4;/* Protected mode cr4 */ +u32 pmode_efer_low;/* Protected mode EFER */ +u32 pmode_efer_high; +u64 pmode_gdt; +u32 realmode_flags; +u32 signature;/* To check we have correct structure */ +u32 real_magic; +} __attribute__((__packed__ )); + +#endif /* ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H */
arch/x86/kernel/acpi/rm/wakeup.ld new file +50 -0
50 lines not on this page · raw message
arch/x86/kernel/acpi/sleep.c +61 -9
103 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup.S +0 -93
97 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup_32.S +5 -98
124 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup_64.S +13 -78
131 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup_rm.S new file +10 -0
@@ -0,0 +1,10 @@ +/* + * Wrapper script for the realmode binary as a transport object + * before copying to low memory. + */ + .section ".rodata","a" + .globl wakeup_code_start, wakeup_code_end +wakeup_code_start: + .incbin "arch/x86/kernel/acpi/rm/wakeup.bin" +wakeup_code_end: + .size wakeup_code_start, .-wakeup_code_start
arch/x86/kernel/setup_32.c +2 -2
@@ -114,7 +114,7 @@ #endifextern void early_cpu_init (void );extern int root_mountflags; -unsigned long saved_videomode; +unsigned long saved_video_mode;#define RAMDISK_IMAGE_START_MASK 0x07FF#define RAMDISK_PROMPT_FLAG 0x8000
@@ -564,7 +564,7 @@ #endif edid_info = boot_params.edid_info; apm_info.bios = boot_params.apm_bios_info; ist_info = boot_params.ist_info; - saved_videomode = boot_params.hdr.vid_mode; + saved_video_mode = boot_params.hdr.vid_mode;if ( boot_params.sys_desc_table.length !=0 ) {set_mca_bus (boot_params.sys_desc_table.table[3 ] &0x2 ); machine_id = boot_params.sys_desc_table.table[0 ];
drivers/acpi/sleep/main.c +1 -1
@@ -139,7 +139,7 @@ static int acpi_pm_enter(suspend_state_tbreak ; } -/* ACPI 3.0 specs (P62) says that it's the responsabilty +/* ACPI 3.0 specs (P62) says that it's the responsibilty * of the OSPM to clear the status bit [ implying that the * POWER_BUTTON event should not reach userspace ] */
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 1 line · Pavel Machek
Hi!
Hi,
Quoted 3 lines
This version works on 32-bit, and builds on 64-bit (but I'm pretty sure it does not work. 32-bit code probably needs to go into rm/....)
Do you have an updated version or is this the latest one?
Rafael
Hi!
Quoted 5 lines
Quoted 3 lines
This version works on 32-bit, and builds on 64-bit (but I'm pretty sure it does not work. 32-bit code probably needs to go into rm/....)
Do you have an updated version or is this the latest one?
I'm glad you ask ;-). Here's reasonably-recent version (I have slightly cleaner one, but it got obscured by 2.6.24-git merge), I eventually got it to work on 64-bit, by reusing trampoline.S code.
Pavel
arch/x86/boot/Makefile +2 -1
@@ -30,7 +30,8 @@ subdir- := compressed setup-y += a20.o apm.o cmdline.o copy.o cpu.o cpucheck.o edd.o setup-y += header.o main.o mca.o memory.o pm.o pmjump.o -setup-y += printf.o string.o tty.o video.o version.o voyager.o +setup-y += printf.o string.o tty.o video.o video-mode.o +setup-y += version.o voyager.o # The link order of the video-*.o modules can matter. In particular, # video-vga.o *must* be listed first, followed by video-vesa.o.
arch/x86/boot/boot.h +5 -0
@@ -285,6 +285,11 @@ int getchar_timeout(void);/* video.c */ void set_video (void ); +/* video-mode.c */ +int set_mode (u16 mode); +int mode_defined (u16 mode); +void probe_cards (int unsafe); +/* video-vesa.c */ void vesa_store_edid (void );
arch/x86/boot/video-bios.c +6 -0
@@ -50,6 +50,7 @@ static int set_bios_mode(u8 mode)if (new_mode == mode)return 0 ;/* Mode change OK */ +#ifndef _WAKEUPif (new_mode != boot_params.screen_info.orig_video_mode) {/* Mode setting failed, but we didn't end up where we started. That's bad. Try to revert to the original
@@ -59,13 +60,18 @@ static int set_bios_mode(u8 mode) : "+a" (ax) : : "ebx", "ecx", "edx", "esi", "edi"); } +#endif return -1 ; }static int bios_probe (void ) {u8 mode; +#ifdef _WAKEUP +u8 saved_mode =0x03 ; +#else u8 saved_mode = boot_params.screen_info.orig_video_mode; +#endif u16 crtc;struct mode_info *mi;int nmodes =0 ;
arch/x86/boot/video-mode.c new file +173 -0
173 lines not on this page · raw message
arch/x86/boot/video-vesa.c +8 -0
@@ -152,7 +152,9 @@ static int vesa_set_mode(struct mode_inf do_restore =1 ; }else {/* Graphics mode */ +#ifndef _WAKEUPvesa_store_mode_params_graphics (); +#endif }return 0 ;
@@ -179,6 +181,7 @@ static void vesa_dac_set_8bits(void) }/* Set the color sizes to the DAC size, and offsets to 0 */ +#ifndef _WAKEUP boot_params.screen_info.red_size = dac_size; boot_params.screen_info.green_size = dac_size; boot_params.screen_info.blue_size = dac_size;
@@ -188,8 +191,11 @@ static void vesa_dac_set_8bits(void) boot_params.screen_info.green_pos =0 ; boot_params.screen_info.blue_pos =0 ; boot_params.screen_info.rsvd_pos =0 ; +#endif } +#ifndef _WAKEUP +/* Save the VESA protected mode info */ static void vesa_store_pm_info (void ) {
@@ -282,6 +288,8 @@ #ifdef CONFIG_FIRMWARE_EDID#endif /* CONFIG_FIRMWARE_EDID */ } +#endif /* not _WAKEUP */ +__videocard video_vesa = { .card_name ="VESA" ,
arch/x86/boot/video-vga.c +10 -2
@@ -210,6 +210,8 @@ static int vga_set_mode(struct mode_info*/ static int vga_probe (void ) { +u16 ega_bx; +static const char *card_name[] = {"CGA/MDA/HGC" ,"EGA" ,"VGA" };
@@ -226,12 +228,16 @@ static int vga_probe(void)u8 vga_flag; asm(INT10 - : "=b" (boot_params.screen_info.orig_video_ega_bx) + : "=b" (ega_bx) : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */ : "ecx", "edx", "esi", "edi"); +#ifndef _WAKEUP + boot_params.screen_info.orig_video_ega_bx = ega_bx; +#endif +/* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */ -if ((u8 )boot_params.screen_info.orig_video_ega_bx !=0x10 ) { +if ((u8 )ega_bx !=0x10 ) {/* EGA/VGA */ asm(INT10 : "=a" (vga_flag)
@@ -240,7 +246,9 @@ static int vga_probe(void)if (vga_flag ==0x1a ) { adapter =ADAPTER_VGA ; +#ifndef _WAKEUP boot_params.screen_info.orig_video_isVGA =1 ; +#endif }else { adapter =ADAPTER_EGA ; }
arch/x86/boot/video.c +1 -156
175 lines not on this page · raw message
arch/x86/kernel/acpi/Makefile +8 -1
@@ -1,7 +1,14 @@ +subdir- := rm + obj-$(CONFIG_ACPI) += boot.o -obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_$(BITS).o +obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_rm.o wakeup_$(BITS).o ifneq ($(CONFIG_ACPI_PROCESSOR),) obj-y += cstate.o processor.o endif +$(obj)/wakeup_rm.o: $(obj)/rm/wakeup.bin + +$(obj)/rm/wakeup.bin: FORCE + $(Q)$(MAKE) $(build)=$(obj)/rm $@ +
arch/x86/kernel/acpi/rm/Makefile new file +55 -0
55 lines not on this page · raw message
arch/x86/kernel/acpi/rm/copy.S new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/copy.S"
arch/x86/kernel/acpi/rm/video-bios.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-bios.c"
arch/x86/kernel/acpi/rm/video-mode.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-mode.c"
arch/x86/kernel/acpi/rm/video-vesa.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-vesa.c"
arch/x86/kernel/acpi/rm/video-vga.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-vga.c"
arch/x86/kernel/acpi/rm/wakemain.c new file +30 -0
@@ -0,0 +1,30 @@ +#include "wakeup.h" +#include "boot.h" + +extern volatile struct wakeup_header wakeup_header; + +void main (void ) +{ +if (wakeup_header.real_magic !=0x12345678 ) { + asmvolatile ("movb $0xba, %al; outb %al, $0x80" ); + asmvolatile ("inb $97, %al; outb %al, $0x80; movb $3, %al; outb %al, $97; outb %al, $0x80; movb $-74, %al; outb %al, $67; outb %al, $0x80; movb $-119, %al; outb %al, $66; outb %al, $0x80; movb $15, %al; outb %al, $66" ); +while (1 ); + } + +if (wakeup_header.realmode_flags &4 ) { + asmvolatile ("inb $97, %al; outb %al, $0x80; movb $3, %al; outb %al, $97; outb %al, $0x80; movb $-74, %al; outb %al, $67; outb %al, $0x80; movb $-119, %al; outb %al, $66; outb %al, $0x80; movb $15, %al; outb %al, $66" ); + } + +if (wakeup_header.realmode_flags &1 ) { + asmvolatile ("lcallw $0xc000,$3" ); +// ("movw %cs, %ax; movw %ax, %ds; movw %ax, %es; movw %ax, %ss"); + } + +if (wakeup_header.realmode_flags &2 ) { +/* Need to call BIOS */ +probe_cards (0 ); +set_mode (wakeup_header.video_mode); + } + +/* Set up GDT and IDT here, possibly CR4 and EFER */ +}
arch/x86/kernel/acpi/rm/wakeup.S new file +126 -0
126 lines not on this page · raw message
arch/x86/kernel/acpi/rm/wakeup.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Definitions for the wakeup data structure at the head of the +* wakeup code. +*/ + +#ifndef ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H +#define ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H + +#include <linux/types.h> + +/* This must match data at wakeup.S */ +struct wakeup_header { +u16 entry;/* unused */ +u16 total;/* unused */ +u16 video_mode;/* Video mode number */ +u16 _jmp1; +u32 pmode_entry;/* Protected mode resume point */ +u16 _jmp2; +u32 pmode_cr0;/* Protected mode cr0 */ +u32 pmode_cr3;/* Protected mode cr3 */ +u32 pmode_cr4;/* Protected mode cr4 */ +u32 pmode_efer_low;/* Protected mode EFER */ +u32 pmode_efer_high; +u64 pmode_gdt; +u32 realmode_flags; +u32 signature;/* To check we have correct structure */ +u32 real_magic; +u64 level3_ident_pgt; +u64 level3_kernel_pgt; +u16 trampoline_segment; +} __attribute__((__packed__ )); + +#endif /* ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H */
arch/x86/kernel/acpi/rm/wakeup.ld new file +51 -0
51 lines not on this page · raw message
arch/x86/kernel/acpi/sleep.c +76 -9
118 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup.S +0 -110
111 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup_32.S +3 -98
121 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup_64.S +1 -170
199 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup_rm.S new file +10 -0
@@ -0,0 +1,10 @@ +/* + * Wrapper script for the realmode binary as a transport object + * before copying to low memory. + */ + .section ".rodata","a" + .globl wakeup_code_start, wakeup_code_end +wakeup_code_start: + .incbin "arch/x86/kernel/acpi/rm/wakeup.bin" +wakeup_code_end: + .size wakeup_code_start, .-wakeup_code_start
arch/x86/kernel/head_64.S +0 -4
@@ -120,10 +120,6 @@ #ifdef CONFIG_SMP addq %rbp, trampoline_level4_pgt + 0(%rip) addq %rbp, trampoline_level4_pgt + (511*8)(%rip) #endif -#ifdef CONFIG_ACPI_SLEEP - addq %rbp, wakeup_level4_pgt + 0(%rip) - addq %rbp, wakeup_level4_pgt + (511*8)(%rip) -#endif /* Due to ENTRY(), sometimes the empty space gets filled with * zeros. Better take a jmp than relying on empty space being
arch/x86/kernel/setup_32.c +2 -2
@@ -114,7 +114,7 @@ #endifextern void early_cpu_init (void );extern int root_mountflags; -unsigned long saved_videomode; +unsigned long saved_video_mode;#define RAMDISK_IMAGE_START_MASK 0x07FF#define RAMDISK_PROMPT_FLAG 0x8000
@@ -564,7 +564,7 @@ #endif edid_info = boot_params.edid_info; apm_info.bios = boot_params.apm_bios_info; ist_info = boot_params.ist_info; - saved_videomode = boot_params.hdr.vid_mode; + saved_video_mode = boot_params.hdr.vid_mode;if ( boot_params.sys_desc_table.length !=0 ) {set_mca_bus (boot_params.sys_desc_table.table[3 ] &0x2 ); machine_id = boot_params.sys_desc_table.table[0 ];
arch/x86/kernel/smpboot_64.c +6 -8
@@ -124,7 +124,7 @@ #define set_idle_for_cpu(x,p) (idle_th* has made sure it's suitably aligned. */ -static unsigned long __cpuinit setup_trampoline (void ) +unsigned long __cpuinit setup_trampoline (void ) {void *tramp =__va (SMP_TRAMPOLINE_BASE );memcpy (tramp, trampoline_data, trampoline_end - trampoline_data);
@@ -188,7 +188,7 @@ void __cpuinit smp_callin(void)/* * Waiting 2s total for startup (udelay is not yet working) */ - timeout = jiffies +2 *HZ ; + timeout = jiffies +200 *HZ ;while (time_before (jiffies, timeout)) {/* * Has the boot CPU finished it's STARTUP sequence?
@@ -639,6 +639,9 @@ do_rest: *((volatile unsigned short *)phys_to_virt (0x467 )) = start_rip &0xf ;Dprintk ("3.\n" ); +/* Trampoline assumes it is at beggining of segment */ +BUG_ON (start_rip &0xf ); +/* * Be paranoid about clearing APIC errors. */
@@ -646,11 +649,6 @@ do_rest:apic_read (APIC_ESR );/* -* Status is now clean -*/ - boot_error =0 ; - -/* * Starting actual IPI sequence... */ boot_error =wakeup_secondary_via_INIT (apicid, start_rip);
@@ -666,7 +664,7 @@ do_rest:/* * Wait 5s total for a response */ -for (timeout =0 ; timeout <50000 ; timeout++) { +for (timeout =0 ; timeout <5000000 ; timeout++) {if (cpu_isset (cpu, cpu_callin_map))break ;/* It has booted */ udelay (100 );
arch/x86/kernel/trampoline_32.S +1 -6
@@ -11,12 +11,7 @@ * trampoline page to make our stack and everything else * is a mystery. * - * In fact we don't actually need a stack so we don't - * set one up. - * - * We jump into the boot/compressed/head.S code. So you'd - * better be running a compressed kernel image or you - * won't get very far. + * We jump into arch/x86/kernel/head_32.S. * * On entry to trampoline_data, the processor is in real mode * with 16-bit addressing and 16-bit data. CS has some value
drivers/acpi/sleep/main.c +1 -1
@@ -139,7 +139,7 @@ static int acpi_pm_enter(suspend_state_tbreak ; } -/* ACPI 3.0 specs (P62) says that it's the responsabilty +/* ACPI 3.0 specs (P62) says that it's the responsibilty * of the OSPM to clear the status bit [ implying that the * POWER_BUTTON event should not reach userspace ] */
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 11 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 3 lines
This version works on 32-bit, and builds on 64-bit (but I'm pretty sure it does not work. 32-bit code probably needs to go into rm/....)
Do you have an updated version or is this the latest one?
I'm glad you ask ;-). Here's reasonably-recent version (I have slightly cleaner one, but it got obscured by 2.6.24-git merge), I eventually got it to work on 64-bit, by reusing
trampoline.Scode.
Thanks, I'll have a look and test it a bit.
Rafael
Quoted 6 lines · Pavel Machek
Hi!
Quoted 4 lines
Quoted 3 lines
This version works on 32-bit, and builds on 64-bit (but I'm pretty sure it does not work. 32-bit code probably needs to go into rm/....)
Quoted 8 lines
Quoted 1 line
Do you have an updated version or is this the latest one?
I'm glad you ask ;-). Here's reasonably-recent version (I have slightly cleaner one, but it got obscured by 2.6.24-git merge), I eventually got it to work on 64-bit, by reusing
trampoline.Scode.Pavel
Signed-off-by Pavel Machek <[email protected]>
Hi PAvel.
Before you submit this for real we need me to take a deper look into your Makefiles.
We do not want this duplication between boot and acpi. And the way you deal with code sharing from boot/ is not OK either.
But I do have a few other things pending before I have time so please ping me in a week or two.
Sam
H. Peter Anvin
reviewerQuoted 16 lines · Sam Ravnborg
Quoted 5 lines · Pavel Machek
Hi!
Quoted 3 lines
Quoted 3 lines
This version works on 32-bit, and builds on 64-bit (but I'm pretty sure it does not work. 32-bit code probably needs to go into rm/....)
Quoted 7 lines
Quoted 1 line
Do you have an updated version or is this the latest one?
I'm glad you ask ;-). Here's reasonably-recent version (I have slightly cleaner one, but it got obscured by 2.6.24-git merge), I eventually got it to work on 64-bit, by reusing
trampoline.Scode.Pavel
Signed-off-by Pavel Machek <[email protected]>Hi PAvel.
Quoted 9 lines
Before you submit this for real we need me to take a deper look into your Makefiles.
We do not want this duplication between boot and acpi. And the way you deal with code sharing from boot/ is not OK either.But I do have a few other things pending before I have time so please ping me in a week or two.
Don't blame Pavel for that. That has a quick hack I threw together to give him something at all to work with.
-hpa
Quoted 13 lines · Sam Ravnborg
Quoted 12 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 3 lines
This version works on 32-bit, and builds on 64-bit (but I'm pretty sure it does not work. 32-bit code probably needs to go into rm/....)
Do you have an updated version or is this the latest one?
I'm glad you ask ;-). Here's reasonably-recent version (I have slightly cleaner one, but it got obscured by 2.6.24-git merge), I eventually got it to work on 64-bit, by reusing
trampoline.Scode.
Quoted 7 lines
Quoted 2 lines
Pavel
Signed-off-by Pavel Machek <[email protected]>Hi PAvel.
Before you submit this for real we need me to take a deper look into your Makefiles.
Ok, lets get this right.
Quoted 3 lines
We do not want this duplication between boot and acpi. And the way you deal with code sharing from boot/ is not OK either.
Well, current version has one copy in .c, then two duplicate .S version, based on older code.... so few duplicate Makefiles do not seem like huge deal.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 24 lines · Pavel Machek
Quoted 13 lines · Sam Ravnborg
Quoted 12 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 3 lines
This version works on 32-bit, and builds on 64-bit (but I'm pretty sure it does not work. 32-bit code probably needs to go into rm/....)
Do you have an updated version or is this the latest one?
I'm glad you ask ;-). Here's reasonably-recent version (I have slightly cleaner one, but it got obscured by 2.6.24-git merge), I eventually got it to work on 64-bit, by reusing
trampoline.Scode.Quoted 7 lines
Quoted 2 lines
Pavel
Signed-off-by Pavel Machek <[email protected]>Hi PAvel.
Before you submit this for real we need me to take a deper look into your Makefiles.
Ok, lets get this right.
Quoted 7 lines
Quoted 3 lines
We do not want this duplication between boot and acpi. And the way you deal with code sharing from boot/ is not OK either.
Well, current version has one copy in .c, then two duplicate .S version, based on older code.... so few duplicate Makefiles do not seem like huge deal.
It is more the single files that just include another .c file.
Can you drop me an updated patch sometime Monday - I already lost the inital mail and I guess you continue your updates.
Sam
Quoted 11 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 3 lines
This version works on 32-bit, and builds on 64-bit (but I'm pretty sure it does not work. 32-bit code probably needs to go into rm/....)
Do you have an updated version or is this the latest one?
I'm glad you ask ;-). Here's reasonably-recent version (I have slightly cleaner one, but it got obscured by 2.6.24-git merge), I eventually got it to work on 64-bit, by reusing
trampoline.Scode.
I needed to rebase it against the current mainline (Makefile conflict).
Some remarks:
- It looks like arch/x86/kernel/acpi/wakeup.S is not necessary any more.
- These warnings:
/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c: In function ‘acpi_save_state_mem’:/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:41: warning: initialization makes pointer from integer without a cast /home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:50: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long unsigned int’ /home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:50: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long unsigned int’ /home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:70: warning: ISO C90 forbids mixed declarations and code /home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:82: warning: assignment makes integer from pointer without a cast /home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:83: warning: assignment makes integer from pointer without a cast /home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:84: warning: ISO C90 forbids mixed declarations and code /home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:87: warning: ISO C90 forbids mixed declarations and code /home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:90: warning: assignment makes integer from pointer without a cast /home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:91: warning: ISO C90 forbids mixed declarations and code
look pretty scary.
- Could the real mode directory be called just "real-mode" or something like this ("rm" is not very meaningful :-))?
Apart from the above and the _WAKEUP hacks mentioned elsewhere, it looks okay (from a very high orbit).
Greetings,
Rafael
Quoted 33 lines · Rafael J. Wysocki
Quoted 11 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 3 lines
This version works on 32-bit, and builds on 64-bit (but I'm pretty sure it does not work. 32-bit code probably needs to go into rm/....)
Do you have an updated version or is this the latest one?
I'm glad you ask ;-). Here's reasonably-recent version (I have slightly cleaner one, but it got obscured by 2.6.24-git merge), I eventually got it to work on 64-bit, by reusing
trampoline.Scode.I needed to rebase it against the current mainline (
Makefileconflict).Some remarks:
- It looks like
arch/x86/kernel/acpi/wakeup.Sis not necessary any more.- These warnings:
/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c: In function ‘acpi_save_state_mem’:/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:41: warning: initialization makes pointer from integer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:50: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long unsigned int’/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:50: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long unsigned int’/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:70: warning: ISO C90 forbids mixed declarations and code/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:82: warning: assignment makes integer from pointer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:83: warning: assignment makes integer from pointer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:84: warning: ISO C90 forbids mixed declarations and code/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:87: warning: ISO C90 forbids mixed declarations and code/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:90: warning: assignment makes integer from pointer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:91: warning: ISO C90 forbids mixed declarations and code
Quoted 1 line
look pretty scary.
Below is the arch/x86/kernel/acpi/sleep.c part without the warnings (untested).
It still contains some hardcoded magic numbers and extern declarations, so I guess the #include list is not complete or another header is necessary.
BTW:
1) why exactly is acpi_wakeup_address not (void *)?
2) header->level3_ident_pgt and header->level3_ident_pgt could be (char *) IMO
arch/x86/kernel/acpi/sleep.c +78 -10
@@ -11,29 +11,92 @@#include <linux/cpumask.h> #include <asm/smp.h> +#include "rm/wakeup.h" /* address in low memory of the wakeup routine. */ -unsigned long acpi_wakeup_address =0 ; +static unsigned long acpi_realmode; +unsigned long acpi_wakeup_address;unsigned long acpi_realmode_flags; -extern char wakeup_start, wakeup_end; +extern char wakeup_code_start, wakeup_code_end;extern unsigned long acpi_copy_wakeup_routine (unsigned long ); +extern unsigned long setup_trampoline (void ); +extern void wakeup_long64 (void ); + +extern unsigned long saved_video_mode; +extern long saved_magic; +extern char level3_ident_pgt[PAGE_SIZE ]; +extern char level3_kernel_pgt[PAGE_SIZE ]; +extern volatile unsigned long init_rsp; +extern void (*initial_code)(void ); +#ifndef CONFIG_64BIT +extern int wakeup_pmode_return; +extern char swsusp_pg_dir[PAGE_SIZE ]; +#endif + +static char temp_stack[10240 ];/** * acpi_save_state_mem - save kernel state * * Create an identity mapped page table and copy the wakeup routine to * low memory. +* +* Note that this is too late to change acpi_wakeup_address. */ int acpi_save_state_mem (void ) { -if (!acpi_wakeup_address) { -printk (KERN_ERR "Could not allocate memory during boot, S3 disabled\n" ); +struct wakeup_header *header; + +printk ("acpi_save_state_mem\n" ); + +if (!acpi_realmode) { +printk (KERN_ERR "Could not allocate memory during boot, " +"S3 disabled\n" );return -ENOMEM ; } -memcpy ((void *)acpi_wakeup_address, &wakeup_start, - &wakeup_end - &wakeup_start); -acpi_copy_wakeup_routine (acpi_wakeup_address); + +memcpy ((void *)acpi_realmode, &wakeup_code_start,4 *PAGE_SIZE ); + + header = (struct wakeup_header *)(acpi_realmode +0x3f00 ); +if (header->signature !=0x51ee1111 ) { +printk (KERN_ERR "wakeup header does not match\n" ); +return -EINVAL ; + } + + header->video_mode = saved_video_mode; +printk ("Video mode = %lu, realmode flags = %lu\n" , + saved_video_mode, acpi_realmode_flags); +mdelay (1000 ); + +#ifndef CONFIG_64BIT +store_gdt (&header->pmode_gdt); + + header->pmode_efer_low = nx_enabled; +if (header->pmode_efer_low &1 ) { +/* This is strange, why not save efer, always? */ +rdmsr (MSR_EFER , header->pmode_efer_low, + header->pmode_efer_high); + } +#endif /* !CONFIG_64BIT */ + + header->pmode_cr0 =read_cr0 (); + header->pmode_cr4 =read_cr4 (); + header->realmode_flags = acpi_realmode_flags; + header->real_magic =0x12345678 ; + +#ifndef CONFIG_64BIT + header->pmode_entry = &wakeup_pmode_return; + header->pmode_cr3 = swsusp_pg_dir - __PAGE_OFFSET; + saved_magic =0x12345678 ; +#else /* CONFIG_64BIT */ + header->level3_ident_pgt = (u64 )level3_ident_pgt; + header->level3_kernel_pgt = (u64 )level3_kernel_pgt; + header->trampoline_segment =setup_trampoline () >>4 ; + init_rsp = (unsigned long )temp_stack +4096 ; + initial_code = wakeup_long64; + saved_magic =0x123456789abcdef0 ; +#endif /* CONFIG_64BIT */ return 0 ; }
@@ -56,15 +119,20 @@ void acpi_restore_state_mem(void)*/ void __init acpi_reserve_bootmem (void ) { -if ((&wakeup_end - &wakeup_start) >PAGE_SIZE *2 ) { +if ((&wakeup_code_end - &wakeup_code_start) >PAGE_SIZE *4 ) {printk (KERN_ERR "ACPI: Wakeup code way too big, S3 disabled.\n" );return ; } - acpi_wakeup_address = (unsigned long )alloc_bootmem_low (PAGE_SIZE *2 ); -if (!acpi_wakeup_address) + acpi_realmode = (unsigned long )alloc_bootmem_low (PAGE_SIZE *4 ); + +if (!acpi_realmode) {printk (KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n" ); +return ; + } + + acpi_wakeup_address = acpi_realmode; }
Quoted 34 lines · Rafael J. Wysocki
Quoted 33 lines · Rafael J. Wysocki
Quoted 11 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 3 lines
This version works on 32-bit, and builds on 64-bit (but I'm pretty sure it does not work. 32-bit code probably needs to go into rm/....)
Do you have an updated version or is this the latest one?
I'm glad you ask ;-). Here's reasonably-recent version (I have slightly cleaner one, but it got obscured by 2.6.24-git merge), I eventually got it to work on 64-bit, by reusing
trampoline.Scode.I needed to rebase it against the current mainline (
Makefileconflict).Some remarks:
- It looks like
arch/x86/kernel/acpi/wakeup.Sis not necessary any more.- These warnings:
/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c: In function ‘acpi_save_state_mem’:/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:41: warning: initialization makes pointer from integer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:50: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long unsigned int’/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:50: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long unsigned int’/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:70: warning: ISO C90 forbids mixed declarations and code/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:82: warning: assignment makes integer from pointer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:83: warning: assignment makes integer from pointer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:84: warning: ISO C90 forbids mixed declarations and code/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:87: warning: ISO C90 forbids mixed declarations and code/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:90: warning: assignment makes integer from pointer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:91: warning: ISO C90 forbids mixed declarations and code
Quoted 3 lines
Quoted 1 line
look pretty scary.
Below is the
arch/x86/kernel/acpi/sleep.cpart without the warnings (untested).
Now also tested on x86-64 (works just fine :-)).
Quoted 124 lines
It still contains some hardcoded magic numbers and extern declarations, so I guess the #include list is not complete or another header is necessary.
BTW:
1) why exactly isacpi_wakeup_addressnot (void *)?
2)header->level3_ident_pgtandheader->level3_ident_pgtcould be (char *) IMOarch/x86/kernel/acpi/sleep.c +72
-10@@ -11,29 +11,92 @@#include <linux/cpumask.h> #include <asm/smp.h> +#include "rm/wakeup.h" /* address in low memory of the wakeup routine. */ -unsigned long acpi_wakeup_address =0 ; +static unsigned long acpi_realmode; +unsigned long acpi_wakeup_address;unsigned long acpi_realmode_flags; -extern char wakeup_start, wakeup_end; +extern char wakeup_code_start, wakeup_code_end;extern unsigned long acpi_copy_wakeup_routine (unsigned long ); +extern unsigned long setup_trampoline (void ); +extern void wakeup_long64 (void ); + +extern unsigned long saved_video_mode; +extern long saved_magic; +extern char level3_ident_pgt[PAGE_SIZE ]; +extern char level3_kernel_pgt[PAGE_SIZE ]; +extern volatile unsigned long init_rsp; +extern void (*initial_code)(void ); +#ifndef CONFIG_64BIT +extern int wakeup_pmode_return; +extern char swsusp_pg_dir[PAGE_SIZE ]; +#endif + +static char temp_stack[10240 ];/** * acpi_save_state_mem - save kernel state * * Create an identity mapped page table and copy the wakeup routine to * low memory. +* +* Note that this is too late to change acpi_wakeup_address. */ int acpi_save_state_mem (void ) { -if (!acpi_wakeup_address) { -printk (KERN_ERR "Could not allocate memory during boot, S3 disabled\n" ); +struct wakeup_header *header; + +printk ("acpi_save_state_mem\n" ); + +if (!acpi_realmode) { +printk (KERN_ERR "Could not allocate memory during boot, " +"S3 disabled\n" );return -ENOMEM ; } -memcpy ((void *)acpi_wakeup_address, &wakeup_start, - &wakeup_end - &wakeup_start); -acpi_copy_wakeup_routine (acpi_wakeup_address); + +memcpy ((void *)acpi_realmode, &wakeup_code_start,4 *PAGE_SIZE ); + + header = (struct wakeup_header *)(acpi_realmode +0x3f00 ); +if (header->signature !=0x51ee1111 ) { +printk (KERN_ERR "wakeup header does not match\n" ); +return -EINVAL ; + } + + header->video_mode = saved_video_mode; +printk ("Video mode = %lu, realmode flags = %lu\n" , + saved_video_mode, acpi_realmode_flags); +mdelay (1000 ); + +#ifndef CONFIG_64BIT +store_gdt (&header->pmode_gdt); + + header->pmode_efer_low = nx_enabled; +if (header->pmode_efer_low &1 ) { +/* This is strange, why not save efer, always? */ +rdmsr (MSR_EFER , header->pmode_efer_low, + header->pmode_efer_high); + } +#endif /* !CONFIG_64BIT */ + + header->pmode_cr0 =read_cr0 (); + header->pmode_cr4 =read_cr4 (); + header->realmode_flags = acpi_realmode_flags; + header->real_magic =0x12345678 ; + +#ifndef CONFIG_64BIT + header->pmode_entry = &wakeup_pmode_return; + header->pmode_cr3 = swsusp_pg_dir - __PAGE_OFFSET; + saved_magic =0x12345678 ; +#else /* CONFIG_64BIT */ + header->level3_ident_pgt = (u64 )level3_ident_pgt; + header->level3_kernel_pgt = (u64 )level3_kernel_pgt; + header->trampoline_segment =setup_trampoline () >>4 ; + init_rsp = (unsigned long )temp_stack +4096 ; + initial_code = wakeup_long64; + saved_magic =0x123456789abcdef0 ; +#endif /* CONFIG_64BIT */ return 0 ; }@@ -56,15 +119,20 @@ void acpi_restore_state_mem(void)*/ void __init acpi_reserve_bootmem (void ) { -if ((&wakeup_end - &wakeup_start) >PAGE_SIZE *2 ) { +if ((&wakeup_code_end - &wakeup_code_start) >PAGE_SIZE *4 ) {printk (KERN_ERR "ACPI: Wakeup code way too big, S3 disabled.\n" );return ; } - acpi_wakeup_address = (unsigned long )alloc_bootmem_low (PAGE_SIZE *2 ); -if (!acpi_wakeup_address) + acpi_realmode = (unsigned long )alloc_bootmem_low (PAGE_SIZE *4 );
arch/x86/kernel/acpi/sleep.c void acpi_restore_state_mem(void) · line 138
Quoted 10 lines
arch/x86/kernel/acpi/sleep.c +6
-0+ +if (!acpi_realmode) {printk (KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n" ); +return ; + } + + acpi_wakeup_address = acpi_realmode; }
Greetings,
Rafael
Quoted 36 lines · Rafael J. Wysocki
Quoted 33 lines · Rafael J. Wysocki
Quoted 11 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 3 lines
This version works on 32-bit, and builds on 64-bit (but I'm pretty sure it does not work. 32-bit code probably needs to go into rm/....)
Do you have an updated version or is this the latest one?
I'm glad you ask ;-). Here's reasonably-recent version (I have slightly cleaner one, but it got obscured by 2.6.24-git merge), I eventually got it to work on 64-bit, by reusing
trampoline.Scode.I needed to rebase it against the current mainline (
Makefileconflict).Some remarks:
- It looks like
arch/x86/kernel/acpi/wakeup.Sis not necessary any more.- These warnings:
/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c: In function ???acpi_save_state_mem???:/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:41: warning: initialization makes pointer from integer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:50: warning: format ???%d??? expects type ???int???, but argument 2 has type ???long unsigned int???/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:50: warning: format ???%d??? expects type ???int???, but argument 3 has type ???long unsigned int???/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:70: warning: ISO C90 forbids mixed declarations and code/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:82: warning: assignment makes integer from pointer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:83: warning: assignment makes integer from pointer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:84: warning: ISO C90 forbids mixed declarations and code/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:87: warning: ISO C90 forbids mixed declarations and code/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:90: warning: assignment makes integer from pointer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:91: warning: ISO C90 forbids mixed declarations and codeQuoted 1 line
look pretty scary.
Quoted 7 lines
Below is the
arch/x86/kernel/acpi/sleep.cpart without the warnings (untested).It still contains some hardcoded magic numbers and extern declarations, so I guess the #include list is not complete or another header is necessary.
BTW:
1) why exactly isacpi_wakeup_addressnot (void *)?
Well, it is physical address, not really a pointer.
Quoted 1 line
2)
header->level3_ident_pgtandheader->level3_ident_pgtcould be
(char *) IMO
Those are unused, they can be deleted ;-).
Pavel
Quoted 126 lines
arch/x86/kernel/acpi/sleep.c +78
-10@@ -11,29 +11,92 @@#include <linux/cpumask.h> #include <asm/smp.h> +#include "rm/wakeup.h" /* address in low memory of the wakeup routine. */ -unsigned long acpi_wakeup_address =0 ; +static unsigned long acpi_realmode; +unsigned long acpi_wakeup_address;unsigned long acpi_realmode_flags; -extern char wakeup_start, wakeup_end; +extern char wakeup_code_start, wakeup_code_end;extern unsigned long acpi_copy_wakeup_routine (unsigned long ); +extern unsigned long setup_trampoline (void ); +extern void wakeup_long64 (void ); + +extern unsigned long saved_video_mode; +extern long saved_magic; +extern char level3_ident_pgt[PAGE_SIZE ]; +extern char level3_kernel_pgt[PAGE_SIZE ]; +extern volatile unsigned long init_rsp; +extern void (*initial_code)(void ); +#ifndef CONFIG_64BIT +extern int wakeup_pmode_return; +extern char swsusp_pg_dir[PAGE_SIZE ]; +#endif + +static char temp_stack[10240 ];/** * acpi_save_state_mem - save kernel state * * Create an identity mapped page table and copy the wakeup routine to * low memory. +* +* Note that this is too late to change acpi_wakeup_address. */ int acpi_save_state_mem (void ) { -if (!acpi_wakeup_address) { -printk (KERN_ERR "Could not allocate memory during boot, S3 disabled\n" ); +struct wakeup_header *header; + +printk ("acpi_save_state_mem\n" ); + +if (!acpi_realmode) { +printk (KERN_ERR "Could not allocate memory during boot, " +"S3 disabled\n" );return -ENOMEM ; } -memcpy ((void *)acpi_wakeup_address, &wakeup_start, - &wakeup_end - &wakeup_start); -acpi_copy_wakeup_routine (acpi_wakeup_address); + +memcpy ((void *)acpi_realmode, &wakeup_code_start,4 *PAGE_SIZE ); + + header = (struct wakeup_header *)(acpi_realmode +0x3f00 ); +if (header->signature !=0x51ee1111 ) { +printk (KERN_ERR "wakeup header does not match\n" ); +return -EINVAL ; + } + + header->video_mode = saved_video_mode; +printk ("Video mode = %lu, realmode flags = %lu\n" , + saved_video_mode, acpi_realmode_flags); +mdelay (1000 ); + +#ifndef CONFIG_64BIT +store_gdt (&header->pmode_gdt); + + header->pmode_efer_low = nx_enabled; +if (header->pmode_efer_low &1 ) { +/* This is strange, why not save efer, always? */ +rdmsr (MSR_EFER , header->pmode_efer_low, + header->pmode_efer_high); + } +#endif /* !CONFIG_64BIT */ + + header->pmode_cr0 =read_cr0 (); + header->pmode_cr4 =read_cr4 (); + header->realmode_flags = acpi_realmode_flags; + header->real_magic =0x12345678 ; + +#ifndef CONFIG_64BIT + header->pmode_entry = &wakeup_pmode_return; + header->pmode_cr3 = swsusp_pg_dir - __PAGE_OFFSET; + saved_magic =0x12345678 ; +#else /* CONFIG_64BIT */ + header->level3_ident_pgt = (u64 )level3_ident_pgt; + header->level3_kernel_pgt = (u64 )level3_kernel_pgt; + header->trampoline_segment =setup_trampoline () >>4 ; + init_rsp = (unsigned long )temp_stack +4096 ; + initial_code = wakeup_long64; + saved_magic =0x123456789abcdef0 ; +#endif /* CONFIG_64BIT */ return 0 ; }@@ -56,15 +119,20 @@ void acpi_restore_state_mem(void)*/ void __init acpi_reserve_bootmem (void ) { -if ((&wakeup_end - &wakeup_start) >PAGE_SIZE *2 ) { +if ((&wakeup_code_end - &wakeup_code_start) >PAGE_SIZE *4 ) {printk (KERN_ERR "ACPI: Wakeup code way too big, S3 disabled.\n" );return ; } - acpi_wakeup_address = (unsigned long )alloc_bootmem_low (PAGE_SIZE *2 ); -if (!acpi_wakeup_address) + acpi_realmode = (unsigned long )alloc_bootmem_low (PAGE_SIZE *4 ); + +if (!acpi_realmode) {printk (KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n" ); +return ; + } + + acpi_wakeup_address = acpi_realmode; }
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 39 lines · Pavel Machek
Quoted 38 lines · Rafael J. Wysocki
Quoted 33 lines · Rafael J. Wysocki
Quoted 11 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 3 lines
This version works on 32-bit, and builds on 64-bit (but I'm pretty sure it does not work. 32-bit code probably needs to go into rm/....)
Do you have an updated version or is this the latest one?
I'm glad you ask ;-). Here's reasonably-recent version (I have slightly cleaner one, but it got obscured by 2.6.24-git merge), I eventually got it to work on 64-bit, by reusing
trampoline.Scode.I needed to rebase it against the current mainline (
Makefileconflict).Some remarks:
- It looks like
arch/x86/kernel/acpi/wakeup.Sis not necessary any more.- These warnings:
/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c: In function ???acpi_save_state_mem???:/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:41: warning: initialization makes pointer from integer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:50: warning: format ???%d??? expects type ???int???, but argument 2 has type ???long unsigned int???/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:50: warning: format ???%d??? expects type ???int???, but argument 3 has type ???long unsigned int???/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:70: warning: ISO C90 forbids mixed declarations and code/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:82: warning: assignment makes integer from pointer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:83: warning: assignment makes integer from pointer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:84: warning: ISO C90 forbids mixed declarations and code/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:87: warning: ISO C90 forbids mixed declarations and code/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:90: warning: assignment makes integer from pointer without a cast/home/rafael/src/linux-2.6/arch/x86/kernel/acpi/sleep.c:91: warning: ISO C90 forbids mixed declarations and codeQuoted 1 line
look pretty scary.
Below is the
arch/x86/kernel/acpi/sleep.cpart without the warnings (untested).
Quoted 7 lines
Quoted 5 lines
It still contains some hardcoded magic numbers and extern declarations, so I guess the #include list is not complete or another header is necessary.
BTW:
1) why exactly isacpi_wakeup_addressnot (void *)?Well, it is physical address, not really a pointer.
But then it's converted to a pointer all over the place (same for acpi_realmode).
Using (void *) will cause it to have the appropriate size and to be type checked by the compiler in the C code.
Quoted 2 lines
Quoted 1 line
2)
header->level3_ident_pgtandheader->level3_ident_pgtcould be(char *) IMO
OK
BTW, I don't like the way in which the 'struct wakeup_header' fields are reproduced in rm/wakeup.S very much, because it makes the code fragile. It might be better to define the offsets in asm-offsets*.c and refer to them relative to wakeup_header (if possible).
Rafael
Hi!
Quoted 8 lines
Below is the
arch/x86/kernel/acpi/sleep.cpart without the warnings (untested).It still contains some hardcoded magic numbers and extern declarations, so I guess the #include list is not complete or another header is necessary.
BTW:
1) why exactly isacpi_wakeup_addressnot (void *)?
2)header->level3_ident_pgtandheader->level3_ident_pgtcould be (char *) IMO
I applied it, and renamed acpi/rm to acpi/realmode... yep, rm was a bad name.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 5 lines
- Could the real mode directory be called just "real-mode" or something like this ("rm" is not very meaningful :-))?
Apart from the above and the
_WAKEUPhacks mentioned elsewhere, it looks okay (from a very high orbit).
Wakeup hacks? You mean those #ifdef WAKEUP in video code?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 9 lines · Pavel Machek
Hi!
Quoted 5 lines
- Could the real mode directory be called just "real-mode" or something like this ("rm" is not very meaningful :-))?
Apart from the above and the
_WAKEUPhacks mentioned elsewhere, it looks okay (from a very high orbit).Wakeup hacks? You mean those #ifdef WAKEUP in video code?
Yes.
[I'm not sure if that could be done differently, though. Surely hpa knows ;-)]
Rafael
Quoted 2 lines
it looks okay
(from a very high orbit).
It should look better from closer look. Reusing trampoline_64.S instead of cut©&paste gets us rid of some really nasty assembly ;-).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 4 lines
BTW, I don't like the way in which the 'struct
wakeup_header' fields are reproduced inrm/wakeup.Svery much, because it makes the code fragile. It might be better to define the offsets in asm-offsets*.c and refer to them relative towakeup_header(if possible).
If you can do that.. yes, that would be nice. I triple-checked it, but indeed is fragile.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 9 lines · Pavel Machek
Hi!
Quoted 4 lines
BTW, I don't like the way in which the 'struct
wakeup_header' fields are reproduced inrm/wakeup.Svery much, because it makes the code fragile. It might be better to define the offsets in asm-offsets*.c and refer to them relative towakeup_header(if possible).If you can do that.. yes, that would be nice. I triple-checked it, but indeed is fragile.
Do you want me to remove the unused fields from 'struct wakeup_header' too?
Rafael
Quoted 8 lines · Rafael J. Wysocki
Quoted 7 lines · Pavel Machek
Hi!
Quoted 4 lines
BTW, I don't like the way in which the 'struct
wakeup_header' fields are reproduced inrm/wakeup.Svery much, because it makes the code fragile. It might be better to define the offsets in asm-offsets*.c and refer to them relative towakeup_header(if possible).
Quoted 4 lines
Quoted 2 lines
If you can do that.. yes, that would be nice. I triple-checked it, but indeed is fragile.
Do you want me to remove the unused fields from 'struct
wakeup_header' too?
I think I did that already. My wakeup.S/wakeup.h is attached. If you can find more unused fields, kill them for sure.
(I'm not sure about fields needed on 32-bit only. I'm leaving them in because it does not really matter).
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
/*
* Definitions for the wakeup data structure at the head of the
* wakeup code.
*/
#ifndef ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H
#define ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H
#include <linux/types.h>
/* This must match data at wakeup.S */
struct wakeup_header {
u16 entry; /* unused */
u16 total; /* unused */
u16 video_mode; /* Video mode number */
u16 _jmp1;
u32 pmode_entry; /* Protected mode resume point */
u16 _jmp2;
u32 pmode_cr0; /* Protected mode cr0 */
u32 pmode_cr3; /* Protected mode cr3 */
u32 pmode_cr4; /* Protected mode cr4 */
u32 pmode_efer_low; /* Protected mode EFER */
u32 pmode_efer_high;
u64 pmode_gdt;
u32 realmode_flags;
u32 real_magic;
u16 trampoline_segment;
u32 signature; /* To check we have correct structure */
} __attribute__((__packed__));#endif /* ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H */
/*
* ACPI wakeup real mode startup stub
*/
#include <asm/segment.h>
#include <asm/msr-index.h>
#include <asm/page_64.h>
#include <asm/pgtable_64.h>
.code16 .section ".header", "a"
/* This should match the structure in wakeup.h */
.globl wakeup_headerwakeup_header:
entry: .short _start /* unused */
total: .short _end /* unused */video_mode: .short 0 /* Video mode number */pmode_return: .byte 0x66, 0xea /* ljmpl */
.long 0 /* offset goes here */ .short __KERNEL_CS
pmode_cr0: .long 0 /* Saved %cr0 */pmode_cr3: .long 0 /* Saved %cr3 */pmode_cr4: .long 0 /* Saved %cr4 */pmode_efer: .quad 0 /* Saved EFER */pmode_gdt: .quad 0realmode_flags: .long 0real_magic: .long 0trampoline_segment: .word 0
signature: .long 0x51ee1111
.text .globl _start .code16 wakeup_code: _start: cli cld /* Set up segments */ movw %cs,%ax movw %ax,%ds movw %ax,%es movw %ax,%ss movl $wakeup_stack_end, %esp /* Clear the EFLAGS */ pushl $0 popfl /* Check header signature... */ movl signature, %eax cmpl $0x51ee1111, %eax jne bogus_real_magic /* Check we really have everything... */ movl end_signature, %eax cmpl $0x65a22c82, %eax jne bogus_real_magic /* Zero the bss */ xorl %eax, %eax movw $__bss_start, %di movw $__bss_end+3, %cx subw %di, %cx shrw $2, %cx rep; stosl /* Call the C code */ calll main /* Do any other stuff... */
#ifndef CONFIG_64BIT /* This could also be done in C code... */ movl pmode_cr3, %eax movl %eax, %cr3 movl pmode_cr4, %ecx jecxz 1f movl %ecx, %cr4 1: movl pmode_efer, %eax movl pmode_efer+4, %edx movl %eax, %ecx orl %edx, %ecx jz 1f movl $0xc0000080, %ecx wrmsr
1:
lgdtl pmode_gdt /* This really couldn't... */ movl pmode_cr0, %eax movl %eax, %cr0 jmp pmode_return #else pushw $0 pushw trampoline_segment pushw $0 lret
#endif
bogus_real_magic:
1:
hlt jmp 1b .data .balign 4 .globl HEAP, heap_end
HEAP:
.long wakeup_heapheap_end:
.long wakeup_stack
.bsswakeup_heap:
.space 2048 wakeup_stack: .space 2048
wakeup_stack_end:
Hi!
Here's updated diff. Video & Makefiles by hpa, rest by me ;-).
Pavel
arch/x86/Makefile +1 -1
@@ -192,8 +192,8 @@ drivers-$(CONFIG_PCI) += arch # must be linked after kernel/ drivers-$(CONFIG_OPROFILE) += arch/x86/oprofile/ -ifeq ($(CONFIG_X86_32),y) drivers-$(CONFIG_PM) += arch/x86/power/ +ifeq ($(CONFIG_X86_32),y) drivers-$(CONFIG_FB) += arch/x86/video/ endif
arch/x86/boot/Makefile +1 -1
@@ -30,7 +30,7 @@ subdir- := compressed setup-y += a20.o cmdline.o copy.o cpu.o cpucheck.o edd.o setup-y += header.o main.o mca.o memory.o pm.o pmjump.o -setup-y += printf.o string.o tty.o video.o version.o +setup-y += printf.o string.o tty.o video.o video-mode.o version.o setup-$(CONFIG_X86_APM_BOOT) += apm.o setup-$(CONFIG_X86_VOYAGER) += voyager.o
arch/x86/boot/boot.h +5 -0
@@ -286,6 +286,11 @@ int getchar_timeout(void);/* video.c */ void set_video (void ); +/* video-mode.c */ +int set_mode (u16 mode); +int mode_defined (u16 mode); +void probe_cards (int unsafe); +/* video-vesa.c */ void vesa_store_edid (void );
arch/x86/boot/video-bios.c +6 -0
@@ -50,6 +50,7 @@ static int set_bios_mode(u8 mode)if (new_mode == mode)return 0 ;/* Mode change OK */ +#ifndef _WAKEUPif (new_mode != boot_params.screen_info.orig_video_mode) {/* Mode setting failed, but we didn't end up where we started. That's bad. Try to revert to the original
@@ -59,13 +60,18 @@ static int set_bios_mode(u8 mode) : "+a" (ax) : : "ebx", "ecx", "edx", "esi", "edi"); } +#endif return -1 ; }static int bios_probe (void ) {u8 mode; +#ifdef _WAKEUP +u8 saved_mode =0x03 ; +#else u8 saved_mode = boot_params.screen_info.orig_video_mode; +#endif u16 crtc;struct mode_info *mi;int nmodes =0 ;
arch/x86/boot/video-mode.c new file +173 -0
173 lines not on this page · raw message
arch/x86/boot/video-vesa.c +8 -0
@@ -160,7 +160,9 @@ static int vesa_set_mode(struct mode_inf do_restore =1 ; }else {/* Graphics mode */ +#ifndef _WAKEUPvesa_store_mode_params_graphics (); +#endif }return 0 ;
@@ -187,6 +189,7 @@ static void vesa_dac_set_8bits(void) }/* Set the color sizes to the DAC size, and offsets to 0 */ +#ifndef _WAKEUP boot_params.screen_info.red_size = dac_size; boot_params.screen_info.green_size = dac_size; boot_params.screen_info.blue_size = dac_size;
@@ -196,8 +199,11 @@ static void vesa_dac_set_8bits(void) boot_params.screen_info.green_pos =0 ; boot_params.screen_info.blue_pos =0 ; boot_params.screen_info.rsvd_pos =0 ; +#endif } +#ifndef _WAKEUP +/* Save the VESA protected mode info */ static void vesa_store_pm_info (void ) {
@@ -290,6 +296,8 @@ #ifdef CONFIG_FIRMWARE_EDID#endif /* CONFIG_FIRMWARE_EDID */ } +#endif /* not _WAKEUP */ +__videocard video_vesa = { .card_name ="VESA" ,
arch/x86/boot/video-vga.c +10 -2
@@ -210,6 +210,8 @@ static int vga_set_mode(struct mode_info*/ static int vga_probe (void ) { +u16 ega_bx; +static const char *card_name[] = {"CGA/MDA/HGC" ,"EGA" ,"VGA" };
@@ -226,12 +228,16 @@ static int vga_probe(void)u8 vga_flag; asm(INT10 - : "=b" (boot_params.screen_info.orig_video_ega_bx) + : "=b" (ega_bx) : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */ : "ecx", "edx", "esi", "edi"); +#ifndef _WAKEUP + boot_params.screen_info.orig_video_ega_bx = ega_bx; +#endif +/* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */ -if ((u8 )boot_params.screen_info.orig_video_ega_bx !=0x10 ) { +if ((u8 )ega_bx !=0x10 ) {/* EGA/VGA */ asm(INT10 : "=a" (vga_flag)
@@ -240,7 +246,9 @@ static int vga_probe(void)if (vga_flag ==0x1a ) { adapter =ADAPTER_VGA ; +#ifndef _WAKEUP boot_params.screen_info.orig_video_isVGA =1 ; +#endif }else { adapter =ADAPTER_EGA ; }
arch/x86/boot/video.c +1 -156
175 lines not on this page · raw message
arch/x86/kernel/acpi/Makefile +8 -1
@@ -1,7 +1,14 @@ +subdir- := realmode + obj-$(CONFIG_ACPI) += boot.o -obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_$(BITS).o +obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_rm.o wakeup_$(BITS).o ifneq ($(CONFIG_ACPI_PROCESSOR),) obj-y += cstate.o processor.o endif +$(obj)/wakeup_rm.o: $(obj)/realmode/wakeup.bin + +$(obj)/realmode/wakeup.bin: FORCE + $(Q)$(MAKE) $(build)=$(obj)/realmode $@ +
arch/x86/kernel/acpi/realmode/Makefile new file +55 -0
55 lines not on this page · raw message
arch/x86/kernel/acpi/realmode/copy.S new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/copy.S"
arch/x86/kernel/acpi/realmode/video-bios.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-bios.c"
arch/x86/kernel/acpi/realmode/video-mode.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-mode.c"
arch/x86/kernel/acpi/realmode/video-vesa.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-vesa.c"
arch/x86/kernel/acpi/realmode/video-vga.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-vga.c"
arch/x86/kernel/acpi/realmode/wakemain.c new file +26 -0
@@ -0,0 +1,26 @@ +#include "wakeup.h" +#include "boot.h" + +extern volatile struct wakeup_header wakeup_header; + +void main (void ) +{ +/* Kill machine if structures are wrong */ +if (wakeup_header.real_magic !=0x12345678 ) +while (1 ); + +if (wakeup_header.realmode_flags &4 ) { + asmvolatile ("inb $97, %al; outb %al, $0x80; movb $3, %al; outb %al, $97; outb %al, $0x80; movb $-74, %al; outb %al, $67; outb %al, $0x80; movb $-119, %al; outb %al, $66; outb %al, $0x80; movb $15, %al; outb %al, $66" ); + } + +if (wakeup_header.realmode_flags &1 ) { + asmvolatile ("lcallw $0xc000,$3" ); +// ("movw %cs, %ax; movw %ax, %ds; movw %ax, %es; movw %ax, %ss"); + } + +if (wakeup_header.realmode_flags &2 ) { +/* Need to call BIOS */ +probe_cards (0 ); +set_mode (wakeup_header.video_mode); + } +}
arch/x86/kernel/acpi/realmode/wakeup.S new file +124 -0
124 lines not on this page · raw message
arch/x86/kernel/acpi/realmode/wakeup.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Definitions for the wakeup data structure at the head of the +* wakeup code. +*/ + +#ifndef ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H +#define ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H + +#include <linux/types.h> + +/* This must match data at wakeup.S */ +struct wakeup_header { +u16 entry;/* unused */ +u16 total;/* unused */ +u16 video_mode;/* Video mode number */ +u16 _jmp1; +u32 pmode_entry;/* Protected mode resume point */ +u16 _jmp2; +u32 pmode_cr0;/* Protected mode cr0 */ +u32 pmode_cr3;/* Protected mode cr3 */ +u32 pmode_cr4;/* Protected mode cr4 */ +u32 pmode_efer_low;/* Protected mode EFER */ +u32 pmode_efer_high; +u64 pmode_gdt; +u32 realmode_flags; +u32 real_magic; +u16 trampoline_segment; +u32 signature;/* To check we have correct structure */ +} __attribute__((__packed__ )); + +#endif /* ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H */
arch/x86/kernel/acpi/realmode/wakeup.ld new file +51 -0
51 lines not on this page · raw message
arch/x86/kernel/acpi/sleep.c +70 -10
114 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup.S new file +1 -0
@@ -0,0 +1 @@ +# Copyright 2003, 2008 Pavel Machek <[email protected]>, distribute under GPLv2
arch/x86/kernel/acpi/wakeup_32.S +5 -212
239 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup_64.S +2 -292
324 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup_rm.S new file +10 -0
@@ -0,0 +1,10 @@ +/* + * Wrapper script for the realmode binary as a transport object + * before copying to low memory. + */ + .section ".rodata","a" + .globl wakeup_code_start, wakeup_code_end +wakeup_code_start: + .incbin "arch/x86/kernel/acpi/rm/wakeup.bin" +wakeup_code_end: + .size wakeup_code_start, .-wakeup_code_start
arch/x86/kernel/head_64.S +0 -4
@@ -127,10 +127,6 @@ #ifdef CONFIG_SMP addq %rbp, trampoline_level4_pgt + 0(%rip) addq %rbp, trampoline_level4_pgt + (511*8)(%rip) #endif -#ifdef CONFIG_ACPI_SLEEP - addq %rbp, wakeup_level4_pgt + 0(%rip) - addq %rbp, wakeup_level4_pgt + (511*8)(%rip) -#endif /* Due to ENTRY(), sometimes the empty space gets filled with * zeros. Better take a jmp than relying on empty space being
arch/x86/kernel/setup_32.c +2 -2
@@ -186,7 +186,7 @@ #endifextern void early_cpu_init (void );extern int root_mountflags; -unsigned long saved_videomode; +unsigned long saved_video_mode;#define RAMDISK_IMAGE_START_MASK 0x07FF#define RAMDISK_PROMPT_FLAG 0x8000
@@ -711,7 +711,7 @@ #endif edid_info = boot_params.edid_info; apm_info.bios = boot_params.apm_bios_info; ist_info = boot_params.ist_info; - saved_videomode = boot_params.hdr.vid_mode; + saved_video_mode = boot_params.hdr.vid_mode;if ( boot_params.sys_desc_table.length !=0 ) {set_mca_bus (boot_params.sys_desc_table.table[3 ] &0x2 ); machine_id = boot_params.sys_desc_table.table[0 ];
arch/x86/kernel/smpboot_64.c +4 -6
@@ -132,7 +132,7 @@ #endif* has made sure it's suitably aligned. */ -static unsigned long __cpuinit setup_trampoline (void ) +unsigned long __cpuinit setup_trampoline (void ) {void *tramp =__va (SMP_TRAMPOLINE_BASE );memcpy (tramp, trampoline_data, trampoline_end - trampoline_data);
@@ -649,6 +649,9 @@ do_rest: *((volatile unsigned short *)phys_to_virt (0x467 )) = start_rip &0xf ;Dprintk ("3.\n" ); +/* Trampoline assumes it is at beggining of segment */ +BUG_ON (start_rip &0xf ); +/* * Be paranoid about clearing APIC errors. */
@@ -656,11 +659,6 @@ do_rest:apic_read (APIC_ESR );/* -* Status is now clean -*/ - boot_error =0 ; - -/* * Starting actual IPI sequence... */ boot_error =wakeup_secondary_via_INIT (apicid, start_rip);
arch/x86_64/kernel/acpi/wakeup.S new file +425 -0
425 lines not on this page · raw message
drivers/acpi/sleep/main.c +1 -1
@@ -170,7 +170,7 @@ static int acpi_pm_enter(suspend_state_t/* Reprogram control registers and execute _BFS */ acpi_leave_sleep_state_prep (acpi_state); -/* ACPI 3.0 specs (P62) says that it's the responsabilty +/* ACPI 3.0 specs (P62) says that it's the responsibilty * of the OSPM to clear the status bit [ implying that the * POWER_BUTTON event should not reach userspace ] */
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 29 lines · Sam Ravnborg
Quoted 28 lines · Pavel Machek
Quoted 13 lines · Sam Ravnborg
Quoted 12 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 3 lines
This version works on 32-bit, and builds on 64-bit (but I'm pretty sure it does not work. 32-bit code probably needs to go into rm/....)
Do you have an updated version or is this the latest one?
I'm glad you ask ;-). Here's reasonably-recent version (I have slightly cleaner one, but it got obscured by 2.6.24-git merge), I eventually got it to work on 64-bit, by reusing
trampoline.Scode.Quoted 7 lines
Quoted 2 lines
Pavel
Signed-off-by Pavel Machek <[email protected]>Hi PAvel.
Before you submit this for real we need me to take a deper look into your Makefiles.
Ok, lets get this right.
Quoted 3 lines
We do not want this duplication between boot and acpi. And the way you deal with code sharing from boot/ is not OK either.
Quoted 7 lines
Quoted 3 lines
Well, current version has one copy in .c, then two duplicate .S version, based on older code.... so few duplicate Makefiles do not seem like huge deal.
It is more the single files that just include another .c file.
Can you drop me an updated patch sometime Monday - I already lost the inital mail and I guess you continue your updates.
Here's current version...
Pavel
arch/x86/Makefile +1 -1
@@ -192,8 +192,8 @@ drivers-$(CONFIG_PCI) += arch # must be linked after kernel/ drivers-$(CONFIG_OPROFILE) += arch/x86/oprofile/ -ifeq ($(CONFIG_X86_32),y) drivers-$(CONFIG_PM) += arch/x86/power/ +ifeq ($(CONFIG_X86_32),y) drivers-$(CONFIG_FB) += arch/x86/video/ endif
arch/x86/boot/Makefile +1 -1
@@ -30,7 +30,7 @@ subdir- := compressed setup-y += a20.o cmdline.o copy.o cpu.o cpucheck.o edd.o setup-y += header.o main.o mca.o memory.o pm.o pmjump.o -setup-y += printf.o string.o tty.o video.o version.o +setup-y += printf.o string.o tty.o video.o video-mode.o version.o setup-$(CONFIG_X86_APM_BOOT) += apm.o setup-$(CONFIG_X86_VOYAGER) += voyager.o
arch/x86/boot/boot.h +5 -0
@@ -286,6 +286,11 @@ int getchar_timeout(void);/* video.c */ void set_video (void ); +/* video-mode.c */ +int set_mode (u16 mode); +int mode_defined (u16 mode); +void probe_cards (int unsafe); +/* video-vesa.c */ void vesa_store_edid (void );
arch/x86/boot/video-bios.c +6 -0
@@ -50,6 +50,7 @@ static int set_bios_mode(u8 mode)if (new_mode == mode)return 0 ;/* Mode change OK */ +#ifndef _WAKEUPif (new_mode != boot_params.screen_info.orig_video_mode) {/* Mode setting failed, but we didn't end up where we started. That's bad. Try to revert to the original
@@ -59,13 +60,18 @@ static int set_bios_mode(u8 mode) : "+a" (ax) : : "ebx", "ecx", "edx", "esi", "edi"); } +#endif return -1 ; }static int bios_probe (void ) {u8 mode; +#ifdef _WAKEUP +u8 saved_mode =0x03 ; +#else u8 saved_mode = boot_params.screen_info.orig_video_mode; +#endif u16 crtc;struct mode_info *mi;int nmodes =0 ;
arch/x86/boot/video-mode.c new file +173 -0
173 lines not on this page · raw message
arch/x86/boot/video-vesa.c +8 -0
@@ -160,7 +160,9 @@ static int vesa_set_mode(struct mode_inf do_restore =1 ; }else {/* Graphics mode */ +#ifndef _WAKEUPvesa_store_mode_params_graphics (); +#endif }return 0 ;
@@ -187,6 +189,7 @@ static void vesa_dac_set_8bits(void) }/* Set the color sizes to the DAC size, and offsets to 0 */ +#ifndef _WAKEUP boot_params.screen_info.red_size = dac_size; boot_params.screen_info.green_size = dac_size; boot_params.screen_info.blue_size = dac_size;
@@ -196,8 +199,11 @@ static void vesa_dac_set_8bits(void) boot_params.screen_info.green_pos =0 ; boot_params.screen_info.blue_pos =0 ; boot_params.screen_info.rsvd_pos =0 ; +#endif } +#ifndef _WAKEUP +/* Save the VESA protected mode info */ static void vesa_store_pm_info (void ) {
@@ -290,6 +296,8 @@ #ifdef CONFIG_FIRMWARE_EDID#endif /* CONFIG_FIRMWARE_EDID */ } +#endif /* not _WAKEUP */ +__videocard video_vesa = { .card_name ="VESA" ,
arch/x86/boot/video-vga.c +10 -2
@@ -210,6 +210,8 @@ static int vga_set_mode(struct mode_info*/ static int vga_probe (void ) { +u16 ega_bx; +static const char *card_name[] = {"CGA/MDA/HGC" ,"EGA" ,"VGA" };
@@ -226,12 +228,16 @@ static int vga_probe(void)u8 vga_flag; asm(INT10 - : "=b" (boot_params.screen_info.orig_video_ega_bx) + : "=b" (ega_bx) : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */ : "ecx", "edx", "esi", "edi"); +#ifndef _WAKEUP + boot_params.screen_info.orig_video_ega_bx = ega_bx; +#endif +/* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */ -if ((u8 )boot_params.screen_info.orig_video_ega_bx !=0x10 ) { +if ((u8 )ega_bx !=0x10 ) {/* EGA/VGA */ asm(INT10 : "=a" (vga_flag)
@@ -240,7 +246,9 @@ static int vga_probe(void)if (vga_flag ==0x1a ) { adapter =ADAPTER_VGA ; +#ifndef _WAKEUP boot_params.screen_info.orig_video_isVGA =1 ; +#endif }else { adapter =ADAPTER_EGA ; }
arch/x86/boot/video.c +1 -156
175 lines not on this page · raw message
arch/x86/kernel/acpi/Makefile +8 -1
@@ -1,7 +1,14 @@ +subdir- := realmode + obj-$(CONFIG_ACPI) += boot.o -obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_$(BITS).o +obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_rm.o wakeup_$(BITS).o ifneq ($(CONFIG_ACPI_PROCESSOR),) obj-y += cstate.o processor.o endif +$(obj)/wakeup_rm.o: $(obj)/realmode/wakeup.bin + +$(obj)/realmode/wakeup.bin: FORCE + $(Q)$(MAKE) $(build)=$(obj)/realmode $@ +
arch/x86/kernel/acpi/realmode/Makefile new file +55 -0
55 lines not on this page · raw message
arch/x86/kernel/acpi/realmode/copy.S new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/copy.S"
arch/x86/kernel/acpi/realmode/video-bios.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-bios.c"
arch/x86/kernel/acpi/realmode/video-mode.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-mode.c"
arch/x86/kernel/acpi/realmode/video-vesa.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-vesa.c"
arch/x86/kernel/acpi/realmode/video-vga.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-vga.c"
arch/x86/kernel/acpi/realmode/wakemain.c new file +26 -0
@@ -0,0 +1,26 @@ +#include "wakeup.h" +#include "boot.h" + +extern volatile struct wakeup_header wakeup_header; + +void main (void ) +{ +/* Kill machine if structures are wrong */ +if (wakeup_header.real_magic !=0x12345678 ) +while (1 ); + +if (wakeup_header.realmode_flags &4 ) { + asmvolatile ("inb $97, %al; outb %al, $0x80; movb $3, %al; outb %al, $97; outb %al, $0x80; movb $-74, %al; outb %al, $67; outb %al, $0x80; movb $-119, %al; outb %al, $66; outb %al, $0x80; movb $15, %al; outb %al, $66" ); + } + +if (wakeup_header.realmode_flags &1 ) { + asmvolatile ("lcallw $0xc000,$3" ); +// ("movw %cs, %ax; movw %ax, %ds; movw %ax, %es; movw %ax, %ss"); + } + +if (wakeup_header.realmode_flags &2 ) { +/* Need to call BIOS */ +probe_cards (0 ); +set_mode (wakeup_header.video_mode); + } +}
arch/x86/kernel/acpi/realmode/wakeup.S new file +124 -0
124 lines not on this page · raw message
arch/x86/kernel/acpi/realmode/wakeup.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Definitions for the wakeup data structure at the head of the +* wakeup code. +*/ + +#ifndef ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H +#define ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H + +#include <linux/types.h> + +/* This must match data at wakeup.S */ +struct wakeup_header { +u16 entry;/* unused */ +u16 total;/* unused */ +u16 video_mode;/* Video mode number */ +u16 _jmp1; +u32 pmode_entry;/* Protected mode resume point */ +u16 _jmp2; +u32 pmode_cr0;/* Protected mode cr0 */ +u32 pmode_cr3;/* Protected mode cr3 */ +u32 pmode_cr4;/* Protected mode cr4 */ +u32 pmode_efer_low;/* Protected mode EFER */ +u32 pmode_efer_high; +u64 pmode_gdt; +u32 realmode_flags; +u32 real_magic; +u16 trampoline_segment; +u32 signature;/* To check we have correct structure */ +} __attribute__((__packed__ )); + +#endif /* ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H */
arch/x86/kernel/acpi/realmode/wakeup.ld new file +51 -0
51 lines not on this page · raw message
arch/x86/kernel/acpi/sleep.c +70 -10
114 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup.S new file +1 -0
@@ -0,0 +1 @@ +# Copyright 2003, 2008 Pavel Machek <[email protected]>, distribute under GPLv2
arch/x86/kernel/acpi/wakeup_32.S +5 -212
239 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup_64.S +2 -292
324 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup_rm.S new file +10 -0
@@ -0,0 +1,10 @@ +/* + * Wrapper script for the realmode binary as a transport object + * before copying to low memory. + */ + .section ".rodata","a" + .globl wakeup_code_start, wakeup_code_end +wakeup_code_start: + .incbin "arch/x86/kernel/acpi/rm/wakeup.bin" +wakeup_code_end: + .size wakeup_code_start, .-wakeup_code_start
arch/x86/kernel/head_64.S +0 -4
@@ -127,10 +127,6 @@ #ifdef CONFIG_SMP addq %rbp, trampoline_level4_pgt + 0(%rip) addq %rbp, trampoline_level4_pgt + (511*8)(%rip) #endif -#ifdef CONFIG_ACPI_SLEEP - addq %rbp, wakeup_level4_pgt + 0(%rip) - addq %rbp, wakeup_level4_pgt + (511*8)(%rip) -#endif /* Due to ENTRY(), sometimes the empty space gets filled with * zeros. Better take a jmp than relying on empty space being
arch/x86/kernel/setup_32.c +2 -2
@@ -186,7 +186,7 @@ #endifextern void early_cpu_init (void );extern int root_mountflags; -unsigned long saved_videomode; +unsigned long saved_video_mode;#define RAMDISK_IMAGE_START_MASK 0x07FF#define RAMDISK_PROMPT_FLAG 0x8000
@@ -711,7 +711,7 @@ #endif edid_info = boot_params.edid_info; apm_info.bios = boot_params.apm_bios_info; ist_info = boot_params.ist_info; - saved_videomode = boot_params.hdr.vid_mode; + saved_video_mode = boot_params.hdr.vid_mode;if ( boot_params.sys_desc_table.length !=0 ) {set_mca_bus (boot_params.sys_desc_table.table[3 ] &0x2 ); machine_id = boot_params.sys_desc_table.table[0 ];
arch/x86/kernel/smpboot_64.c +4 -6
@@ -132,7 +132,7 @@ #endif* has made sure it's suitably aligned. */ -static unsigned long __cpuinit setup_trampoline (void ) +unsigned long __cpuinit setup_trampoline (void ) {void *tramp =__va (SMP_TRAMPOLINE_BASE );memcpy (tramp, trampoline_data, trampoline_end - trampoline_data);
@@ -649,6 +649,9 @@ do_rest: *((volatile unsigned short *)phys_to_virt (0x467 )) = start_rip &0xf ;Dprintk ("3.\n" ); +/* Trampoline assumes it is at beggining of segment */ +BUG_ON (start_rip &0xf ); +/* * Be paranoid about clearing APIC errors. */
@@ -656,11 +659,6 @@ do_rest:apic_read (APIC_ESR );/* -* Status is now clean -*/ - boot_error =0 ; - -/* * Starting actual IPI sequence... */ boot_error =wakeup_secondary_via_INIT (apicid, start_rip);
arch/x86_64/kernel/acpi/wakeup.S new file +425 -0
425 lines not on this page · raw message
drivers/acpi/sleep/main.c +1 -1
@@ -170,7 +170,7 @@ static int acpi_pm_enter(suspend_state_t/* Reprogram control registers and execute _BFS */ acpi_leave_sleep_state_prep (acpi_state); -/* ACPI 3.0 specs (P62) says that it's the responsabilty +/* ACPI 3.0 specs (P62) says that it's the responsibilty * of the OSPM to clear the status bit [ implying that the * POWER_BUTTON event should not reach userspace ] */
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html