Blame view

arch/arm/kernel/suspend.c 1.85 KB
e8ce0eb5e   Russell King   ARM: pm: prealloc...
1
2
3
4
5
6
7
8
9
  #include <linux/init.h>
  
  #include <asm/pgalloc.h>
  #include <asm/pgtable.h>
  #include <asm/memory.h>
  #include <asm/suspend.h>
  #include <asm/tlbflush.h>
  
  static pgd_t *suspend_pgd;
abda1bd5f   Russell King   ARM: pm: convert ...
10
  extern int __cpu_suspend(unsigned long, int (*)(unsigned long));
62b2d07c0   Russell King   ARM: pm: get rid ...
11
  extern void cpu_resume_mmu(void);
e8ce0eb5e   Russell King   ARM: pm: prealloc...
12
13
  
  /*
abda1bd5f   Russell King   ARM: pm: convert ...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
   * This is called by __cpu_suspend() to save the state, and do whatever
   * flushing is required to ensure that when the CPU goes to sleep we have
   * the necessary data available when the caches are not searched.
   */
  void __cpu_suspend_save(u32 *ptr, u32 ptrsz, u32 sp, u32 *save_ptr)
  {
  	*save_ptr = virt_to_phys(ptr);
  
  	/* This must correspond to the LDM in cpu_resume() assembly */
  	*ptr++ = virt_to_phys(suspend_pgd);
  	*ptr++ = sp;
  	*ptr++ = virt_to_phys(cpu_do_resume);
  
  	cpu_do_suspend(ptr);
  
  	flush_cache_all();
8e6f83bbd   Russell King   ARM: pm: add L2 c...
30
31
32
  	outer_clean_range(*save_ptr, *save_ptr + ptrsz);
  	outer_clean_range(virt_to_phys(save_ptr),
  			  virt_to_phys(save_ptr) + sizeof(*save_ptr));
abda1bd5f   Russell King   ARM: pm: convert ...
33
34
35
  }
  
  /*
e8ce0eb5e   Russell King   ARM: pm: prealloc...
36
37
38
39
40
41
42
43
44
45
46
47
   * Hide the first two arguments to __cpu_suspend - these are an implementation
   * detail which platform code shouldn't have to know about.
   */
  int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
  {
  	struct mm_struct *mm = current->active_mm;
  	int ret;
  
  	if (!suspend_pgd)
  		return -EINVAL;
  
  	/*
de8e71ca4   Russell King   ARM: pm: only use...
48
49
50
51
  	 * Provide a temporary page table with an identity mapping for
  	 * the MMU-enable code, required for resuming.  On successful
  	 * resume (indicated by a zero return code), we need to switch
  	 * back to the correct page tables.
e8ce0eb5e   Russell King   ARM: pm: prealloc...
52
  	 */
abda1bd5f   Russell King   ARM: pm: convert ...
53
  	ret = __cpu_suspend(arg, fn);
de8e71ca4   Russell King   ARM: pm: only use...
54
55
56
57
  	if (ret == 0) {
  		cpu_switch_mm(mm->pgd, mm);
  		local_flush_tlb_all();
  	}
e8ce0eb5e   Russell King   ARM: pm: prealloc...
58
59
60
61
62
63
64
65
  
  	return ret;
  }
  
  static int __init cpu_suspend_init(void)
  {
  	suspend_pgd = pgd_alloc(&init_mm);
  	if (suspend_pgd) {
62b2d07c0   Russell King   ARM: pm: get rid ...
66
  		unsigned long addr = virt_to_phys(cpu_resume_mmu);
e8ce0eb5e   Russell King   ARM: pm: prealloc...
67
68
69
70
71
  		identity_mapping_add(suspend_pgd, addr, addr + SECTION_SIZE);
  	}
  	return suspend_pgd ? 0 : -ENOMEM;
  }
  core_initcall(cpu_suspend_init);