1 /*
2  *  acpi.c - Architecture-Specific Low-Level ACPI Support
3  *
4  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5  *  Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.com>
6  *  Copyright (C) 2001 Patrick Mochel <mochel@osdl.org>
7  *
8  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23  *
24  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25  */
26 
27 #include <linux/config.h>
28 #include <linux/kernel.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/stddef.h>
32 #include <linux/slab.h>
33 #include <linux/pci.h>
34 #include <linux/bootmem.h>
35 #include <linux/irq.h>
36 #include <linux/acpi.h>
37 #include <asm/mpspec.h>
38 #include <asm/io.h>
39 #include <asm/apic.h>
40 #include <asm/apicdef.h>
41 #include <asm/page.h>
42 #include <asm/pgtable.h>
43 #include <asm/pgalloc.h>
44 #include <asm/io_apic.h>
45 #include <asm/acpi.h>
46 #include <asm/save_state.h>
47 #include <asm/smpboot.h>
48 
49 
50 #define PREFIX			"ACPI: "
51 
52 int acpi_lapic;
53 int acpi_ioapic;
54 int acpi_strict;
55 
56 acpi_interrupt_flags acpi_sci_flags __initdata;
57 int acpi_sci_override_gsi __initdata;
58 int acpi_skip_timer_override __initdata;
59 /* --------------------------------------------------------------------------
60                               Boot-time Configuration
61    -------------------------------------------------------------------------- */
62 
63 #ifdef CONFIG_ACPI_PCI
64 int acpi_noirq __initdata;	/* skip ACPI IRQ initialization */
65 int acpi_pci_disabled __initdata; /* skip ACPI PCI scan and IRQ initialization */
66 #endif
67 int acpi_ht __initdata = 1;     /* enable HT */
68 
69 enum acpi_irq_model_id		acpi_irq_model;
70 
71 
72 /*
73  * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
74  * to map the target physical address. The problem is that set_fixmap()
75  * provides a single page, and it is possible that the page is not
76  * sufficient.
77  * By using this area, we can map up to MAX_IO_APICS pages temporarily,
78  * i.e. until the next __va_range() call.
79  *
80  * Important Safety Note:  The fixed I/O APIC page numbers are *subtracted*
81  * from the fixed base.  That's why we start at FIX_IO_APIC_BASE_END and
82  * count idx down while incrementing the phys address.
83  */
__acpi_map_table(unsigned long phys,unsigned long size)84 char *__acpi_map_table(unsigned long phys, unsigned long size)
85 {
86 	unsigned long base, offset, mapped_size;
87 	int idx;
88 
89 	if (phys + size < 8*1024*1024)
90 		return __va(phys);
91 
92 	offset = phys & (PAGE_SIZE - 1);
93 	mapped_size = PAGE_SIZE - offset;
94 	set_fixmap(FIX_ACPI_END, phys);
95 	base = fix_to_virt(FIX_ACPI_END);
96 
97 	/*
98 	 * Most cases can be covered by the below.
99 	 */
100 	idx = FIX_ACPI_END;
101 	while (mapped_size < size) {
102 		if (--idx < FIX_ACPI_BEGIN)
103 			return 0;	/* cannot handle this */
104 		phys += PAGE_SIZE;
105 		set_fixmap(idx, phys);
106 		mapped_size += PAGE_SIZE;
107 	}
108 
109 	return ((unsigned char *) base + offset);
110 }
111 
112 #ifdef CONFIG_ACPI_MMCONFIG
113 
114 u32 pci_mmcfg_base_addr;
115 
116 static int __init
acpi_parse_mcfg(unsigned long phys_addr,unsigned long size)117 acpi_parse_mcfg(unsigned long phys_addr,
118 		unsigned long size)
119 {
120 	struct acpi_table_mcfg *mcfg = NULL;
121 
122 	if (!phys_addr || !size)
123 		return -EINVAL;
124 
125 	mcfg = (struct acpi_table_mcfg *) __acpi_map_table(phys_addr, size);
126 	if (!mcfg) {
127 		printk(KERN_WARNING PREFIX "Unable to map MCFG\n");
128 		return -ENODEV;
129 	}
130 
131 	if (mcfg->base_reserved) {
132 		printk(KERN_ERR PREFIX "MMCONFIG not in low 4GB of memory\n");
133 		return -ENODEV;
134 	}
135 
136 	pci_mmcfg_base_addr = mcfg->base_address;
137 
138 	return 0;
139 }
140 #endif /* CONFIG_ACPI_MMCONFIG */
141 
142 #ifdef CONFIG_X86_LOCAL_APIC
143 
144 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
145 
146 
147 static int __init
acpi_parse_madt(unsigned long phys_addr,unsigned long size)148 acpi_parse_madt (
149 	unsigned long		phys_addr,
150 	unsigned long		size)
151 {
152 	struct acpi_table_madt	*madt = NULL;
153 
154 	if (!phys_addr || !size)
155 		return -EINVAL;
156 
157 	madt = (struct acpi_table_madt *) __acpi_map_table(phys_addr, size);
158 	if (!madt) {
159 		printk(KERN_WARNING PREFIX "Unable to map MADT\n");
160 		return -ENODEV;
161 	}
162 
163 	if (madt->lapic_address)
164 		acpi_lapic_addr = (u64) madt->lapic_address;
165 
166 	printk(KERN_INFO PREFIX "Local APIC address 0x%08x\n",
167 		madt->lapic_address);
168 
169 	detect_clustered_apic(madt->header.oem_id, madt->header.oem_table_id);
170 
171 	return 0;
172 }
173 
174 
175 static int __init
acpi_parse_lapic(acpi_table_entry_header * header)176 acpi_parse_lapic (
177 	acpi_table_entry_header *header)
178 {
179 	struct acpi_table_lapic	*processor = NULL;
180 
181 	processor = (struct acpi_table_lapic*) header;
182 	if (!processor)
183 		return -EINVAL;
184 
185 	acpi_table_print_madt_entry(header);
186 
187 	mp_register_lapic (
188 		processor->id,					   /* APIC ID */
189 		processor->flags.enabled);			  /* Enabled? */
190 
191 	return 0;
192 }
193 
194 
195 static int __init
acpi_parse_lapic_addr_ovr(acpi_table_entry_header * header)196 acpi_parse_lapic_addr_ovr (
197 	acpi_table_entry_header *header)
198 {
199 	struct acpi_table_lapic_addr_ovr *lapic_addr_ovr = NULL;
200 
201 	lapic_addr_ovr = (struct acpi_table_lapic_addr_ovr*) header;
202 	if (!lapic_addr_ovr)
203 		return -EINVAL;
204 
205 	acpi_lapic_addr = lapic_addr_ovr->address;
206 
207 	return 0;
208 }
209 
210 static int __init
acpi_parse_lapic_nmi(acpi_table_entry_header * header)211 acpi_parse_lapic_nmi (
212 	acpi_table_entry_header *header)
213 {
214 	struct acpi_table_lapic_nmi *lapic_nmi = NULL;
215 
216 	lapic_nmi = (struct acpi_table_lapic_nmi*) header;
217 	if (!lapic_nmi)
218 		return -EINVAL;
219 
220 	acpi_table_print_madt_entry(header);
221 
222 	if (lapic_nmi->lint != 1)
223 		printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
224 
225 	return 0;
226 }
227 
228 #endif /*CONFIG_X86_LOCAL_APIC*/
229 
230 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_ACPI_INTERPRETER)
231 
232 static int __init
acpi_parse_ioapic(acpi_table_entry_header * header)233 acpi_parse_ioapic (
234 	acpi_table_entry_header *header)
235 {
236 	struct acpi_table_ioapic *ioapic = NULL;
237 
238 	ioapic = (struct acpi_table_ioapic*) header;
239 	if (!ioapic)
240 		return -EINVAL;
241 
242 	acpi_table_print_madt_entry(header);
243 
244 	mp_register_ioapic (
245 		ioapic->id,
246 		ioapic->address,
247 		ioapic->global_irq_base);
248 
249 	return 0;
250 }
251 
252 /*
253  * Parse Interrupt Source Override for the ACPI SCI
254  */
255 static void
acpi_sci_ioapic_setup(u32 gsi,u16 polarity,u16 trigger)256 acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
257 {
258 	if (trigger == 0)	/* compatible SCI trigger is level */
259 		trigger = 3;
260 
261 	if (polarity == 0)	/* compatible SCI polarity is low */
262 		polarity = 3;
263 
264 	/* Command-line over-ride via acpi_sci= */
265 	if (acpi_sci_flags.trigger)
266 		trigger = acpi_sci_flags.trigger;
267 
268 	if (acpi_sci_flags.polarity)
269 		polarity = acpi_sci_flags.polarity;
270 
271 	/*
272  	 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
273 	 * If GSI is < 16, this will update its flags,
274 	 * else it will create a new mp_irqs[] entry.
275 	 */
276 	mp_override_legacy_irq(gsi, polarity, trigger, gsi);
277 
278 	/*
279 	 * stash over-ride to indicate we've been here
280 	 * and for later update of acpi_fadt
281 	 */
282 	acpi_sci_override_gsi = gsi;
283 	return;
284 }
285 
286 static int __init
acpi_parse_fadt(unsigned long phys,unsigned long size)287 acpi_parse_fadt(unsigned long phys, unsigned long size)
288 {
289         struct fadt_descriptor_rev2 *fadt =0;
290 
291         fadt = (struct fadt_descriptor_rev2*) __acpi_map_table(phys,size);
292         if (!fadt) {
293                 printk(KERN_WARNING PREFIX "Unable to map FADT\n");
294                 return 0;
295         }
296 
297 #ifdef  CONFIG_ACPI_INTERPRETER
298         /* initialize sci_int early for INT_SRC_OVR MADT parsing */
299         acpi_fadt.sci_int = fadt->sci_int;
300 #endif
301 
302         return 0;
303 }
304 
305 
306 static int __init
acpi_parse_int_src_ovr(acpi_table_entry_header * header)307 acpi_parse_int_src_ovr (
308 	acpi_table_entry_header *header)
309 {
310 	struct acpi_table_int_src_ovr *intsrc = NULL;
311 
312 	intsrc = (struct acpi_table_int_src_ovr*) header;
313 	if (!intsrc)
314 		return -EINVAL;
315 
316 	acpi_table_print_madt_entry(header);
317 
318 	if (intsrc->bus_irq == acpi_fadt.sci_int) {
319 		acpi_sci_ioapic_setup(intsrc->global_irq,
320 			intsrc->flags.polarity, intsrc->flags.trigger);
321 		return 0;
322 	}
323 
324 	if (acpi_skip_timer_override &&
325 		intsrc->bus_irq == 0 && intsrc->global_irq == 2) {
326 		printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
327 		return 0;
328 	}
329 
330 	mp_override_legacy_irq (
331 		intsrc->bus_irq,
332 		intsrc->flags.polarity,
333 		intsrc->flags.trigger,
334 		intsrc->global_irq);
335 
336 	return 0;
337 }
338 
339 
340 static int __init
acpi_parse_nmi_src(acpi_table_entry_header * header)341 acpi_parse_nmi_src (
342 	acpi_table_entry_header *header)
343 {
344 	struct acpi_table_nmi_src *nmi_src = NULL;
345 
346 	nmi_src = (struct acpi_table_nmi_src*) header;
347 	if (!nmi_src)
348 		return -EINVAL;
349 
350 	acpi_table_print_madt_entry(header);
351 
352 	/* TBD: Support nimsrc entries? */
353 
354 	return 0;
355 }
356 
357 #endif /*CONFIG_X86_IO_APIC && CONFIG_ACPI_INTERPRETER*/
358 
359 
360 static unsigned long __init
acpi_scan_rsdp(unsigned long start,unsigned long length)361 acpi_scan_rsdp (
362 	unsigned long		start,
363 	unsigned long		length)
364 {
365 	unsigned long		offset = 0;
366 	unsigned long		sig_len = sizeof("RSD PTR ") - 1;
367 
368 	/*
369 	 * Scan all 16-byte boundaries of the physical memory region for the
370 	 * RSDP signature.
371 	 */
372 	for (offset = 0; offset < length; offset += 16) {
373 		if (strncmp((char *) (start + offset), "RSD PTR ", sig_len))
374 			continue;
375 		return (start + offset);
376 	}
377 
378 	return 0;
379 }
380 
381 
382 unsigned long __init
acpi_find_rsdp(void)383 acpi_find_rsdp (void)
384 {
385 	unsigned long		rsdp_phys = 0;
386 
387 	/*
388 	 * Scan memory looking for the RSDP signature. First search EBDA (low
389 	 * memory) paragraphs and then search upper memory (E0000-FFFFF).
390 	 */
391 	rsdp_phys = acpi_scan_rsdp (0, 0x400);
392 	if (!rsdp_phys)
393 		rsdp_phys = acpi_scan_rsdp (0xE0000, 0xFFFFF);
394 
395 	return rsdp_phys;
396 }
397 
398 
399 extern int mp_irqs_alloc(void);
400 
401 /*
402  * acpi_boot_init()
403  *  called from setup_arch(), always.
404  *	1. maps ACPI tables for later use
405  *	2. enumerates lapics
406  *	3. enumerates io-apics
407  *
408  * side effects:
409  * 	acpi_lapic = 1 if LAPIC found
410  *	acpi_ioapic = 1 if IOAPIC found
411  *	if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
412  *	if acpi_blacklisted() disable_acpi()
413  *	acpi_irq_model=...
414  *	...
415  *
416  * return value: (currently ignored)
417  *	0: success
418  *	!0: failure
419  */
420 int __init
acpi_boot_init(void)421 acpi_boot_init (void)
422 {
423 	int			result = 0;
424 
425 	if (acpi_disabled && !acpi_ht)
426 		return(1);
427 
428 	/*
429 	 * The default interrupt routing model is PIC (8259).  This gets
430 	 * overriden if IOAPICs are enumerated (below).
431 	 */
432 	acpi_irq_model = ACPI_IRQ_MODEL_PIC;
433 
434 	/*
435 	 * Initialize the ACPI boot-time table parser.
436 	 */
437 	result = acpi_table_init();
438 	if (result) {
439 		disable_acpi();
440 		return result;
441 	}
442 
443 #ifdef CONFIG_X86_IO_APIC
444 	check_acpi_pci();
445 #endif
446 
447 	result = acpi_blacklisted();
448 	if (result) {
449 		printk(KERN_NOTICE PREFIX "BIOS listed in blacklist, disabling ACPI support\n");
450 		disable_acpi();
451 		return result;
452 	}
453 
454 #ifdef CONFIG_ACPI_MMCONFIG
455 	result = acpi_table_parse(ACPI_MCFG, acpi_parse_mcfg);
456 	if (result < 0) {
457 		printk(KERN_ERR PREFIX "Error %d parsing MCFG\n", result);
458 	} else if (result > 1) {
459 		printk(KERN_WARNING PREFIX "Multiple MCFG tables exist\n");
460 	}
461 #endif
462 
463 #ifdef CONFIG_X86_LOCAL_APIC
464 
465 	/*
466 	 * MADT
467 	 * ----
468 	 * Parse the Multiple APIC Description Table (MADT), if exists.
469 	 * Note that this table provides platform SMP configuration
470 	 * information -- the successor to MPS tables.
471 	 */
472 
473 	result = acpi_table_parse(ACPI_APIC, acpi_parse_madt);
474 	if (!result) {
475 		return 0;
476 	}
477 	else if (result < 0) {
478 		printk(KERN_ERR PREFIX "Error parsing MADT\n");
479 		return result;
480 	}
481 	else if (result > 1)
482 		printk(KERN_WARNING PREFIX "Multiple MADT tables exist\n");
483 
484 	/*
485 	 * Local APIC
486 	 * ----------
487 	 * Note that the LAPIC address is obtained from the MADT (32-bit value)
488 	 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
489 	 */
490 
491 	result = acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr);
492 	if (result < 0) {
493 		printk(KERN_ERR PREFIX "Error parsing LAPIC address override entry\n");
494 		return result;
495 	}
496 
497 	mp_register_lapic_address(acpi_lapic_addr);
498 
499 	result = acpi_table_parse_madt(ACPI_MADT_LAPIC, acpi_parse_lapic);
500 	if (!result) {
501 		printk(KERN_ERR PREFIX "No LAPIC entries present\n");
502 		/* TBD: Cleanup to allow fallback to MPS */
503 		return -ENODEV;
504 	}
505 	else if (result < 0) {
506 		printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
507 		/* TBD: Cleanup to allow fallback to MPS */
508 		return result;
509 	}
510 
511 	result = acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi);
512 	if (result < 0) {
513 		printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
514 		/* TBD: Cleanup to allow fallback to MPS */
515 		return result;
516 	}
517 
518 	acpi_lapic = 1;
519 
520 #endif /*CONFIG_X86_LOCAL_APIC*/
521 
522 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_ACPI_INTERPRETER)
523 
524 	/*
525 	 * I/O APIC
526 	 * --------
527 	 */
528 
529 	/*
530 	 * ACPI interpreter is required to complete interrupt setup,
531 	 * so if it is off, don't enumerate the io-apics with ACPI.
532 	 * If MPS is present, it will handle them,
533 	 * otherwise the system will stay in PIC mode
534 	 */
535 	if (acpi_disabled || acpi_noirq) {
536 		return 1;
537 	}
538 
539 	/*
540 	 * if "noapic" boot option, don't look for IO-APICs
541 	 */
542 	if (ioapic_setup_disabled()) {
543 		printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
544 			"due to 'noapic' option.\n");
545 		return 1;
546         }
547 
548 	result = mp_irqs_alloc();	/* Dynamically allocate mp_irqs[] */
549 	if (result < 0)  {
550 		acpi_noirq = 1;
551 		return result;
552 	}
553 
554 	result = acpi_table_parse_madt(ACPI_MADT_IOAPIC, acpi_parse_ioapic);
555 	if (!result) {
556 		printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
557 		return -ENODEV;
558 	}
559 	else if (result < 0) {
560 		printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
561 		return result;
562 	}
563 
564 	/* Record sci_int for use when looking for MADT sci_int override */
565 	acpi_table_parse(ACPI_FADT, acpi_parse_fadt);
566 
567 	result = acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr);
568 	if (result < 0) {
569 		printk(KERN_ERR PREFIX "Error parsing interrupt source overrides entry\n");
570 		/* TBD: Cleanup to allow fallback to MPS */
571 		return result;
572 	}
573 
574 	/*
575 	 * If BIOS did not supply an INT_SRC_OVR for the SCI
576 	 * pretend we got one so we can set the SCI flags.
577 	 */
578 	if (!acpi_sci_override_gsi)
579 		acpi_sci_ioapic_setup(acpi_fadt.sci_int, 0, 0);
580 
581 	/* Fill in identity legacy mapings where no override */
582 	mp_config_acpi_legacy_irqs();
583 
584 	result = acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src);
585 	if (result < 0) {
586 		printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
587 		/* TBD: Cleanup to allow fallback to MPS */
588 		return result;
589 	}
590 
591 	acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
592 
593 	acpi_irq_balance_set(NULL);
594 
595 	acpi_ioapic = 1;
596 
597 	if (acpi_lapic && acpi_ioapic)
598 		smp_found_config = 1;
599 
600 #endif /*CONFIG_X86_IO_APIC && CONFIG_ACPI_INTERPRETER*/
601 
602 	return 0;
603 }
604 
605 
606 #ifdef	CONFIG_ACPI_BUS
607 /*
608  * acpi_pic_sci_set_trigger()
609  *
610  * use ELCR to set PIC-mode trigger type for SCI
611  *
612  * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
613  * it may require Edge Trigger -- use "acpi_sci=edge"
614  *
615  * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
616  * for the 8259 PIC.  bit[n] = 1 means irq[n] is Level, otherwise Edge.
617  * ECLR1 is IRQ's 0-7 (IRQ 0, 1, 2 must be 0)
618  * ECLR2 is IRQ's 8-15 (IRQ 8, 13 must be 0)
619  */
620 
621 void __init
acpi_pic_sci_set_trigger(unsigned int irq,u16 trigger)622 acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
623 {
624 	unsigned char mask = 1 << (irq & 7);
625 	unsigned int port = 0x4d0 + (irq >> 3);
626 	unsigned char val = inb(port);
627 
628 
629 	printk(PREFIX "IRQ%d SCI:", irq);
630 	if (!(val & mask)) {
631 		printk(" Edge");
632 
633 		if (trigger == 3) {
634 			printk(" set to Level");
635 			outb(val | mask, port);
636 		}
637 	} else {
638 		printk(" Level");
639 
640 		if (trigger == 1) {
641 			printk(" set to Edge");
642 			outb(val & ~mask, port);
643 		}
644 	}
645 	printk(" Trigger.\n");
646 }
647 
648 #endif /* CONFIG_ACPI_BUS */
649 
650 
651 
652 #ifndef __HAVE_ARCH_CMPXCHG
653 #warning ACPI uses CMPXCHG, i486 and later hardware
654 #endif
655 
656 /* --------------------------------------------------------------------------
657                               Low-Level Sleep Support
658    -------------------------------------------------------------------------- */
659 
660 #ifdef CONFIG_ACPI_SLEEP
661 
662 #define DEBUG
663 
664 #ifdef DEBUG
665 #include <linux/serial.h>
666 #endif
667 
668 /* address in low memory of the wakeup routine. */
669 unsigned long acpi_wakeup_address = 0;
670 
671 /* new page directory that we will be using */
672 static pmd_t *pmd;
673 
674 /* saved page directory */
675 static pmd_t saved_pmd;
676 
677 /* page which we'll use for the new page directory */
678 static pte_t *ptep;
679 
680 extern unsigned long FASTCALL(acpi_copy_wakeup_routine(unsigned long));
681 
682 /*
683  * acpi_create_identity_pmd
684  *
685  * Create a new, identity mapped pmd.
686  *
687  * Do this by creating new page directory, and marking all the pages as R/W
688  * Then set it as the new Page Middle Directory.
689  * And, of course, flush the TLB so it takes effect.
690  *
691  * We save the address of the old one, for later restoration.
692  */
acpi_create_identity_pmd(void)693 static void acpi_create_identity_pmd (void)
694 {
695 	pgd_t *pgd;
696 	int i;
697 
698 	ptep = (pte_t*)__get_free_page(GFP_KERNEL);
699 
700 	/* fill page with low mapping */
701 	for (i = 0; i < PTRS_PER_PTE; i++)
702 		set_pte(ptep + i, mk_pte_phys(i << PAGE_SHIFT, PAGE_SHARED));
703 
704 	pgd = pgd_offset(current->active_mm, 0);
705 	pmd = pmd_alloc(current->mm,pgd, 0);
706 
707 	/* save the old pmd */
708 	saved_pmd = *pmd;
709 
710 	/* set the new one */
711 	set_pmd(pmd, __pmd(_PAGE_TABLE + __pa(ptep)));
712 
713 	/* flush the TLB */
714 	local_flush_tlb();
715 }
716 
717 /*
718  * acpi_restore_pmd
719  *
720  * Restore the old pmd saved by acpi_create_identity_pmd and
721  * free the page that said function alloc'd
722  */
acpi_restore_pmd(void)723 static void acpi_restore_pmd (void)
724 {
725 	set_pmd(pmd, saved_pmd);
726 	local_flush_tlb();
727 	free_page((unsigned long)ptep);
728 }
729 
730 /**
731  * acpi_save_state_mem - save kernel state
732  *
733  * Create an identity mapped page table and copy the wakeup routine to
734  * low memory.
735  */
acpi_save_state_mem(void)736 int acpi_save_state_mem (void)
737 {
738 	acpi_create_identity_pmd();
739 	acpi_copy_wakeup_routine(acpi_wakeup_address);
740 
741 	return 0;
742 }
743 
744 /**
745  * acpi_save_state_disk - save kernel state to disk
746  *
747  */
acpi_save_state_disk(void)748 int acpi_save_state_disk (void)
749 {
750 	return 1;
751 }
752 
753 /*
754  * acpi_restore_state
755  */
acpi_restore_state_mem(void)756 void acpi_restore_state_mem (void)
757 {
758 	acpi_restore_pmd();
759 }
760 
761 /**
762  * acpi_reserve_bootmem - do _very_ early ACPI initialisation
763  *
764  * We allocate a page in low memory for the wakeup
765  * routine for when we come back from a sleep state. The
766  * runtime allocator allows specification of <16M pages, but not
767  * <1M pages.
768  */
acpi_reserve_bootmem(void)769 void __init acpi_reserve_bootmem(void)
770 {
771 	acpi_wakeup_address = (unsigned long)alloc_bootmem_low(PAGE_SIZE);
772 	if (!acpi_wakeup_address)
773 		printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
774 }
775 
do_suspend_lowlevel_s4bios(int resume)776 void do_suspend_lowlevel_s4bios(int resume)
777 {
778 	if (!resume) {
779 		save_processor_context();
780 		acpi_save_register_state((unsigned long)&&acpi_sleep_done);
781 		acpi_enter_sleep_state_s4bios();
782 		return;
783 	}
784 acpi_sleep_done:
785 	restore_processor_context();
786 }
787 
788 
789 #endif /*CONFIG_ACPI_SLEEP*/
790 
791