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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * linux/arch/m68k/motorola.c
  3.  *
  4.  * Routines specific to the Motorola MMU, originally from:
  5.  * linux/arch/m68k/init.c 
  6.  * which are Copyright (C) 1995 Hamish Macdonald
  7.  * 
  8.  * Moved 8/20/1999 Sam Creasey
  9.  */
  10. #include <linux/config.h>
  11. #include <linux/signal.h>
  12. #include <linux/sched.h>
  13. #include <linux/mm.h>
  14. #include <linux/swap.h>
  15. #include <linux/kernel.h>
  16. #include <linux/string.h>
  17. #include <linux/types.h>
  18. #include <linux/init.h>
  19. #include <linux/bootmem.h>
  20. #ifdef CONFIG_BLK_DEV_RAM
  21. #include <linux/blk.h>
  22. #endif
  23. #include <asm/setup.h>
  24. #include <asm/uaccess.h>
  25. #include <asm/page.h>
  26. #include <asm/pgalloc.h>
  27. #include <asm/system.h>
  28. #include <asm/machdep.h>
  29. #include <asm/io.h>
  30. #include <asm/dma.h>
  31. #ifdef CONFIG_ATARI
  32. #include <asm/atari_stram.h>
  33. #endif
  34. #undef DEBUG
  35. #ifndef mm_cachebits
  36. /*
  37.  * Bits to add to page descriptors for "normal" caching mode.
  38.  * For 68020/030 this is 0.
  39.  * For 68040, this is _PAGE_CACHE040 (cachable, copyback)
  40.  */
  41. unsigned long mm_cachebits = 0;
  42. #endif
  43. static pte_t * __init kernel_page_table(void)
  44. {
  45. pte_t *ptablep;
  46. ptablep = (pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);
  47. clear_page(ptablep);
  48. __flush_page_to_ram((unsigned long) ptablep);
  49. flush_tlb_kernel_page((unsigned long) ptablep);
  50. nocache_page ((unsigned long)ptablep);
  51. return ptablep;
  52. }
  53. static pmd_t *last_pgtable __initdata = NULL;
  54. pmd_t *zero_pgtable __initdata = NULL;
  55. static pmd_t * __init kernel_ptr_table(void)
  56. {
  57. if (!last_pgtable) {
  58. unsigned long pmd, last;
  59. int i;
  60. /* Find the last ptr table that was used in head.S and
  61.  * reuse the remaining space in that page for further
  62.  * ptr tables.
  63.  */
  64. last = (unsigned long)kernel_pg_dir;
  65. for (i = 0; i < PTRS_PER_PGD; i++) {
  66. if (!pgd_present(kernel_pg_dir[i]))
  67. continue;
  68. pmd = __pgd_page(kernel_pg_dir[i]);
  69. if (pmd > last)
  70. last = pmd;
  71. }
  72. last_pgtable = (pmd_t *)last;
  73. #ifdef DEBUG
  74. printk("kernel_ptr_init: %pn", last_pgtable);
  75. #endif
  76. }
  77. if (((unsigned long)(last_pgtable + PTRS_PER_PMD) & ~PAGE_MASK) == 0) {
  78. last_pgtable = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
  79. clear_page(last_pgtable);
  80. __flush_page_to_ram((unsigned long)last_pgtable);
  81. flush_tlb_kernel_page((unsigned long)last_pgtable);
  82. nocache_page((unsigned long)last_pgtable);
  83. } else
  84. last_pgtable += PTRS_PER_PMD;
  85. return last_pgtable;
  86. }
  87. static unsigned long __init 
  88. map_chunk (unsigned long addr, long size)
  89. {
  90. #define PTRTREESIZE (256*1024)
  91. #define ROOTTREESIZE (32*1024*1024)
  92. static unsigned long virtaddr = PAGE_OFFSET;
  93. unsigned long physaddr;
  94. pgd_t *pgd_dir;
  95. pmd_t *pmd_dir;
  96. pte_t *pte_dir;
  97. physaddr = (addr | m68k_supervisor_cachemode |
  98.     _PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_DIRTY);
  99. if (CPU_IS_040_OR_060)
  100. physaddr |= _PAGE_GLOBAL040;
  101. while (size > 0) {
  102. #ifdef DEBUG
  103. if (!(virtaddr & (PTRTREESIZE-1)))
  104. printk ("npa=%#lx va=%#lx ", physaddr & PAGE_MASK,
  105. virtaddr);
  106. #endif
  107. pgd_dir = pgd_offset_k(virtaddr);
  108. if (virtaddr && CPU_IS_020_OR_030) {
  109. if (!(virtaddr & (ROOTTREESIZE-1)) &&
  110.     size >= ROOTTREESIZE) {
  111. #ifdef DEBUG
  112. printk ("[very early term]");
  113. #endif
  114. pgd_val(*pgd_dir) = physaddr;
  115. size -= ROOTTREESIZE;
  116. virtaddr += ROOTTREESIZE;
  117. physaddr += ROOTTREESIZE;
  118. continue;
  119. }
  120. }
  121. if (!pgd_present(*pgd_dir)) {
  122. pmd_dir = kernel_ptr_table();
  123. #ifdef DEBUG
  124. printk ("[new pointer %p]", pmd_dir);
  125. #endif
  126. pgd_set(pgd_dir, pmd_dir);
  127. } else
  128. pmd_dir = pmd_offset(pgd_dir, virtaddr);
  129. if (CPU_IS_020_OR_030) {
  130. if (virtaddr) {
  131. #ifdef DEBUG
  132. printk ("[early term]");
  133. #endif
  134. pmd_dir->pmd[(virtaddr/PTRTREESIZE) & 15] = physaddr;
  135. physaddr += PTRTREESIZE;
  136. } else {
  137. int i;
  138. #ifdef DEBUG
  139. printk ("[zero map]");
  140. #endif
  141. zero_pgtable = kernel_ptr_table();
  142. pte_dir = (pte_t *)zero_pgtable;
  143. pmd_dir->pmd[0] = virt_to_phys(pte_dir) |
  144. _PAGE_TABLE | _PAGE_ACCESSED;
  145. pte_val(*pte_dir++) = 0;
  146. physaddr += PAGE_SIZE;
  147. for (i = 1; i < 64; physaddr += PAGE_SIZE, i++)
  148. pte_val(*pte_dir++) = physaddr;
  149. }
  150. size -= PTRTREESIZE;
  151. virtaddr += PTRTREESIZE;
  152. } else {
  153. if (!pmd_present(*pmd_dir)) {
  154. #ifdef DEBUG
  155. printk ("[new table]");
  156. #endif
  157. pte_dir = kernel_page_table();
  158. pmd_set(pmd_dir, pte_dir);
  159. }
  160. pte_dir = pte_offset(pmd_dir, virtaddr);
  161. if (virtaddr) {
  162. if (!pte_present(*pte_dir))
  163. pte_val(*pte_dir) = physaddr;
  164. } else
  165. pte_val(*pte_dir) = 0;
  166. size -= PAGE_SIZE;
  167. virtaddr += PAGE_SIZE;
  168. physaddr += PAGE_SIZE;
  169. }
  170. }
  171. #ifdef DEBUG
  172. printk("n");
  173. #endif
  174. return virtaddr;
  175. }
  176. extern unsigned long empty_bad_page_table;
  177. extern unsigned long empty_bad_page;
  178. /*
  179.  * paging_init() continues the virtual memory environment setup which
  180.  * was begun by the code in arch/head.S.
  181.  */
  182. void __init paging_init(void)
  183. {
  184. int chunk;
  185. unsigned long mem_avail = 0;
  186. unsigned long zones_size[3] = { 0, };
  187. #ifdef DEBUG
  188. {
  189. extern unsigned long availmem;
  190. printk ("start of paging_init (%p, %lx, %lx, %lx)n",
  191. kernel_pg_dir, availmem, start_mem, end_mem);
  192. }
  193. #endif
  194. /* Fix the cache mode in the page descriptors for the 680[46]0.  */
  195. if (CPU_IS_040_OR_060) {
  196. int i;
  197. #ifndef mm_cachebits
  198. mm_cachebits = _PAGE_CACHE040;
  199. #endif
  200. for (i = 0; i < 16; i++)
  201. pgprot_val(protection_map[i]) |= _PAGE_CACHE040;
  202. }
  203. /* Fix the PAGE_NONE value. */
  204. if (CPU_IS_040_OR_060) {
  205. /* On the 680[46]0 we can use the _PAGE_SUPER bit.  */
  206. pgprot_val(protection_map[0]) |= _PAGE_SUPER;
  207. pgprot_val(protection_map[VM_SHARED]) |= _PAGE_SUPER;
  208. } else {
  209. /* Otherwise we must fake it. */
  210. pgprot_val(protection_map[0]) &= ~_PAGE_PRESENT;
  211. pgprot_val(protection_map[0]) |= _PAGE_FAKE_SUPER;
  212. pgprot_val(protection_map[VM_SHARED]) &= ~_PAGE_PRESENT;
  213. pgprot_val(protection_map[VM_SHARED]) |= _PAGE_FAKE_SUPER;
  214. }
  215. /*
  216.  * Map the physical memory available into the kernel virtual
  217.  * address space.  It may allocate some memory for page
  218.  * tables and thus modify availmem.
  219.  */
  220. for (chunk = 0; chunk < m68k_num_memory; chunk++) {
  221. mem_avail = map_chunk (m68k_memory[chunk].addr,
  222.        m68k_memory[chunk].size);
  223. }
  224. flush_tlb_all();
  225. #ifdef DEBUG
  226. printk ("memory available is %ldKBn", mem_avail >> 10);
  227. printk ("start_mem is %#lxnvirtual_end is %#lxn",
  228. start_mem, end_mem);
  229. #endif
  230. /*
  231.  * initialize the bad page table and bad page to point
  232.  * to a couple of allocated pages
  233.  */
  234. empty_bad_page_table = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
  235. empty_bad_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
  236. empty_zero_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
  237. memset((void *)empty_zero_page, 0, PAGE_SIZE);
  238. /*
  239.  * Set up SFC/DFC registers (user data space)
  240.  */
  241. set_fs (USER_DS);
  242. #ifdef DEBUG
  243. printk ("before free_area_initn");
  244. #endif
  245. zones_size[0] = (mach_max_dma_address < (unsigned long)high_memory ?
  246.  mach_max_dma_address : (unsigned long)high_memory);
  247. zones_size[1] = (unsigned long)high_memory - zones_size[0];
  248. zones_size[0] = (zones_size[0] - PAGE_OFFSET) >> PAGE_SHIFT;
  249. zones_size[1] >>= PAGE_SHIFT;
  250. free_area_init(zones_size);
  251. }
  252. extern char __init_begin, __init_end;
  253. extern unsigned long totalram_pages;
  254. void free_initmem(void)
  255. {
  256. unsigned long addr;
  257. addr = (unsigned long)&__init_begin;
  258. for (; addr < (unsigned long)&__init_end; addr += PAGE_SIZE) {
  259. virt_to_page(addr)->flags &= ~(1 << PG_reserved);
  260. set_page_count(virt_to_page(addr), 1);
  261. free_page(addr);
  262. totalram_pages++;
  263. }
  264. }