mm-armo.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:4k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *  linux/arch/arm/mm/mm-armo.c
  3.  *
  4.  *  Copyright (C) 1998-2000 Russell King
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License version 2 as
  8.  * published by the Free Software Foundation.
  9.  *
  10.  *  Page table sludge for older ARM processor architectures.
  11.  */
  12. #include <linux/sched.h>
  13. #include <linux/mm.h>
  14. #include <linux/init.h>
  15. #include <linux/bootmem.h>
  16. #include <asm/pgtable.h>
  17. #include <asm/pgalloc.h>
  18. #include <asm/page.h>
  19. #include <asm/arch/memory.h>
  20. #include <asm/mach/map.h>
  21. #define MEMC_TABLE_SIZE (256*sizeof(unsigned long))
  22. kmem_cache_t *pte_cache, *pgd_cache;
  23. int page_nr;
  24. /*
  25.  * Allocate a page table.  Note that we place the MEMC
  26.  * table before the page directory.  This means we can
  27.  * easily get to both tightly-associated data structures
  28.  * with a single pointer.
  29.  */
  30. static inline pgd_t *alloc_pgd_table(int priority)
  31. {
  32. void *pg2k = kmem_cache_alloc(pgd_cache, GFP_KERNEL);
  33. if (pg2k)
  34. pg2k += MEMC_TABLE_SIZE;
  35. return (pgd_t *)pg2k;
  36. }
  37. void free_pgd_slow(pgd_t *pgd)
  38. {
  39. unsigned long tbl = (unsigned long)pgd;
  40. /*
  41.  * CHECKME: are we leaking pte tables here???
  42.  */
  43. tbl -= MEMC_TABLE_SIZE;
  44. kmem_cache_free(pgd_cache, (void *)tbl);
  45. }
  46. pgd_t *get_pgd_slow(struct mm_struct *mm)
  47. {
  48. pgd_t *new_pgd, *init_pgd;
  49. pmd_t *new_pmd, *init_pmd;
  50. pte_t *new_pte, *init_pte;
  51. new_pgd = alloc_pgd_table(GFP_KERNEL);
  52. if (!new_pgd)
  53. goto no_pgd;
  54. /*
  55.  * This lock is here just to satisfy pmd_alloc and pte_lock
  56.  */
  57. spin_lock(&mm->page_table_lock);
  58. /*
  59.  * On ARM, first page must always be allocated since it contains
  60.  * the machine vectors.
  61.  */
  62. new_pmd = pmd_alloc(mm, new_pgd, 0);
  63. if (!new_pmd)
  64. goto no_pmd;
  65. new_pte = pte_alloc(mm, new_pmd, 0);
  66. if (!new_pte)
  67. goto no_pte;
  68. init_pgd = pgd_offset_k(0);
  69. init_pmd = pmd_offset(init_pgd, 0);
  70. init_pte = pte_offset(init_pmd, 0);
  71. set_pte(new_pte, *init_pte);
  72. /*
  73.  * most of the page table entries are zeroed
  74.  * wne the table is created.
  75.  */
  76. memcpy(new_pgd + USER_PTRS_PER_PGD, init_pgd + USER_PTRS_PER_PGD,
  77. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  78. spin_unlock(&mm->page_table_lock);
  79. /* update MEMC tables */
  80. cpu_memc_update_all(new_pgd);
  81. return new_pgd;
  82. no_pte:
  83. spin_unlock(&mm->page_table_lock);
  84. pmd_free(new_pmd);
  85. free_pgd_slow(new_pgd);
  86. return NULL;
  87. no_pmd:
  88. spin_unlock(&mm->page_table_lock);
  89. free_pgd_slow(new_pgd);
  90. return NULL;
  91. no_pgd:
  92. return NULL;
  93. }
  94. /*
  95.  * No special code is required here.
  96.  */
  97. void setup_mm_for_reboot(char mode)
  98. {
  99. }
  100. /*
  101.  * This contains the code to setup the memory map on an ARM2/ARM250/ARM3
  102.  * machine. This is both processor & architecture specific, and requires
  103.  * some more work to get it to fit into our separate processor and
  104.  * architecture structure.
  105.  */
  106. void __init memtable_init(struct meminfo *mi)
  107. {
  108. pte_t *pte;
  109. int i;
  110. page_nr = max_low_pfn;
  111. pte = alloc_bootmem_low_pages(PTRS_PER_PTE * sizeof(pte_t));
  112. pte[0] = mk_pte_phys(PAGE_OFFSET + 491520, PAGE_READONLY);
  113. pmd_populate(&init_mm, pmd_offset(swapper_pg_dir, 0), pte);
  114. for (i = 1; i < PTRS_PER_PGD; i++)
  115. pgd_val(swapper_pg_dir[i]) = 0;
  116. }
  117. void __init iotable_init(struct map_desc *io_desc)
  118. {
  119. /* nothing to do */
  120. }
  121. /*
  122.  * We never have holes in the memmap
  123.  */
  124. void __init create_memmap_holes(struct meminfo *mi)
  125. {
  126. }
  127. static void pte_cache_ctor(void *pte, kmem_cache_t *cache, unsigned long flags)
  128. {
  129. memzero(pte, sizeof(pte_t) * PTRS_PER_PTE);
  130. }
  131. static void pgd_cache_ctor(void *pte, kmem_cache_t *cache, unsigned long flags)
  132. {
  133. pgd_t *pgd = (pte + MEMC_TABLE_SIZE);
  134. memzero(pgd, USER_PTRS_PER_PGD * sizeof(pgd_t));
  135. }
  136. void __init pgtable_cache_init(void)
  137. {
  138. pte_cache = kmem_cache_create("pte-cache",
  139. sizeof(pte_t) * PTRS_PER_PTE,
  140. 0, 0, pte_cache_ctor, NULL);
  141. if (!pte_cache)
  142. BUG();
  143. pgd_cache = kmem_cache_create("pgd-cache", MEMC_TABLE_SIZE +
  144. sizeof(pgd_t) * PTRS_PER_PGD,
  145. 0, 0, pgd_cache_ctor, NULL);
  146. if (!pgd_cache)
  147. BUG();
  148. }