11#include <linux/kernel.h>
22
33#include <asm/cputype.h>
4+ #include <asm/idmap.h>
45#include <asm/pgalloc.h>
56#include <asm/pgtable.h>
7+ #include <asm/sections.h>
8+
9+ pgd_t * idmap_pgd ;
610
711static void idmap_add_pmd (pud_t * pud , unsigned long addr , unsigned long end ,
812 unsigned long prot )
@@ -28,7 +32,7 @@ static void idmap_add_pud(pgd_t *pgd, unsigned long addr, unsigned long end,
2832 } while (pud ++ , addr = next , addr != end );
2933}
3034
31- void identity_mapping_add (pgd_t * pgd , unsigned long addr , unsigned long end )
35+ static void identity_mapping_add (pgd_t * pgd , unsigned long addr , unsigned long end )
3236{
3337 unsigned long prot , next ;
3438
@@ -43,48 +47,41 @@ void identity_mapping_add(pgd_t *pgd, unsigned long addr, unsigned long end)
4347 } while (pgd ++ , addr = next , addr != end );
4448}
4549
46- #ifdef CONFIG_SMP
47- static void idmap_del_pmd (pud_t * pud , unsigned long addr , unsigned long end )
48- {
49- pmd_t * pmd = pmd_offset (pud , addr );
50- pmd_clear (pmd );
51- }
50+ extern char __idmap_text_start [], __idmap_text_end [];
5251
53- static void idmap_del_pud ( pgd_t * pgd , unsigned long addr , unsigned long end )
52+ static int __init init_static_idmap ( void )
5453{
55- pud_t * pud = pud_offset (pgd , addr );
56- unsigned long next ;
54+ phys_addr_t idmap_start , idmap_end ;
5755
58- do {
59- next = pud_addr_end (addr , end );
60- idmap_del_pmd (pud , addr , next );
61- } while (pud ++ , addr = next , addr != end );
62- }
56+ idmap_pgd = pgd_alloc (& init_mm );
57+ if (!idmap_pgd )
58+ return - ENOMEM ;
6359
64- void identity_mapping_del ( pgd_t * pgd , unsigned long addr , unsigned long end )
65- {
66- unsigned long next ;
60+ /* Add an identity mapping for the physical address of the section. */
61+ idmap_start = virt_to_phys (( void * ) __idmap_text_start );
62+ idmap_end = virt_to_phys (( void * ) __idmap_text_end ) ;
6763
68- pgd += pgd_index ( addr );
69- do {
70- next = pgd_addr_end ( addr , end );
71- idmap_del_pud ( pgd , addr , next );
72- } while ( pgd ++ , addr = next , addr != end ) ;
64+ pr_info ( "Setting up static identity map for 0x%llx - 0x%llx\n" ,
65+ ( long long ) idmap_start , ( long long ) idmap_end );
66+ identity_mapping_add ( idmap_pgd , idmap_start , idmap_end );
67+
68+ return 0 ;
7369}
74- #endif
70+ early_initcall ( init_static_idmap );
7571
7672/*
77- * In order to soft-boot, we need to insert a 1:1 mapping in place of
78- * the user-mode pages. This will then ensure that we have predictable
79- * results when turning the mmu off
73+ * In order to soft-boot, we need to switch to a 1:1 mapping for the
74+ * cpu_reset functions. This will then ensure that we have predictable
75+ * results when turning off the mmu.
8076 */
8177void setup_mm_for_reboot (void )
8278{
83- /*
84- * We need to access to user-mode page tables here. For kernel threads
85- * we don't have any user-mode mappings so we use the context that we
86- * "borrowed".
87- */
88- identity_mapping_add (current -> active_mm -> pgd , 0 , TASK_SIZE );
79+ /* Clean and invalidate L1. */
80+ flush_cache_all ();
81+
82+ /* Switch to the identity mapping. */
83+ cpu_switch_mm (idmap_pgd , & init_mm );
84+
85+ /* Flush the TLB. */
8986 local_flush_tlb_all ();
9087}
0 commit comments