init.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
  6. * and Cort Dougan (PReP) (cort@cs.nmt.edu)
  7. * Copyright (C) 1996 Paul Mackerras
  8. * Amiga/APUS changes by Jesper Skov (jskov@cygnus.co.uk).
  9. * PPC44x/36-bit changes by Matt Porter (mporter@mvista.com)
  10. *
  11. * Derived from "arch/i386/mm/init.c"
  12. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version
  17. * 2 of the License, or (at your option) any later version.
  18. *
  19. */
  20. #include <linux/config.h>
  21. #include <linux/module.h>
  22. #include <linux/sched.h>
  23. #include <linux/kernel.h>
  24. #include <linux/errno.h>
  25. #include <linux/string.h>
  26. #include <linux/types.h>
  27. #include <linux/mm.h>
  28. #include <linux/stddef.h>
  29. #include <linux/init.h>
  30. #include <linux/bootmem.h>
  31. #include <linux/highmem.h>
  32. #include <linux/initrd.h>
  33. #include <linux/pagemap.h>
  34. #include <asm/pgalloc.h>
  35. #include <asm/prom.h>
  36. #include <asm/io.h>
  37. #include <asm/mmu_context.h>
  38. #include <asm/pgtable.h>
  39. #include <asm/mmu.h>
  40. #include <asm/smp.h>
  41. #include <asm/machdep.h>
  42. #include <asm/btext.h>
  43. #include <asm/tlb.h>
  44. #include <asm/bootinfo.h>
  45. #include "mem_pieces.h"
  46. #include "mmu_decl.h"
  47. #if defined(CONFIG_KERNEL_START_BOOL) || defined(CONFIG_LOWMEM_SIZE_BOOL)
  48. /* The ammount of lowmem must be within 0xF0000000 - KERNELBASE. */
  49. #if (CONFIG_LOWMEM_SIZE > (0xF0000000 - KERNELBASE))
  50. #error "You must adjust CONFIG_LOWMEM_SIZE or CONFIG_START_KERNEL"
  51. #endif
  52. #endif
  53. #define MAX_LOW_MEM CONFIG_LOWMEM_SIZE
  54. DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
  55. unsigned long total_memory;
  56. unsigned long total_lowmem;
  57. unsigned long ppc_memstart;
  58. unsigned long ppc_memoffset = PAGE_OFFSET;
  59. int mem_init_done;
  60. int init_bootmem_done;
  61. int boot_mapsize;
  62. #ifdef CONFIG_PPC_PMAC
  63. unsigned long agp_special_page;
  64. EXPORT_SYMBOL(agp_special_page);
  65. #endif
  66. extern char _end[];
  67. extern char etext[], _stext[];
  68. extern char __init_begin, __init_end;
  69. #ifdef CONFIG_HIGHMEM
  70. pte_t *kmap_pte;
  71. pgprot_t kmap_prot;
  72. EXPORT_SYMBOL(kmap_prot);
  73. EXPORT_SYMBOL(kmap_pte);
  74. #endif
  75. void MMU_init(void);
  76. void set_phys_avail(unsigned long total_ram);
  77. /* XXX should be in current.h -- paulus */
  78. extern struct task_struct *current_set[NR_CPUS];
  79. char *klimit = _end;
  80. struct mem_pieces phys_avail;
  81. /*
  82. * this tells the system to map all of ram with the segregs
  83. * (i.e. page tables) instead of the bats.
  84. * -- Cort
  85. */
  86. int __map_without_bats;
  87. int __map_without_ltlbs;
  88. /* max amount of RAM to use */
  89. unsigned long __max_memory;
  90. /* max amount of low RAM to map in */
  91. unsigned long __max_low_memory = MAX_LOW_MEM;
  92. void show_mem(void)
  93. {
  94. int i,free = 0,total = 0,reserved = 0;
  95. int shared = 0, cached = 0;
  96. int highmem = 0;
  97. printk("Mem-info:\n");
  98. show_free_areas();
  99. printk("Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
  100. i = max_mapnr;
  101. while (i-- > 0) {
  102. total++;
  103. if (PageHighMem(mem_map+i))
  104. highmem++;
  105. if (PageReserved(mem_map+i))
  106. reserved++;
  107. else if (PageSwapCache(mem_map+i))
  108. cached++;
  109. else if (!page_count(mem_map+i))
  110. free++;
  111. else
  112. shared += page_count(mem_map+i) - 1;
  113. }
  114. printk("%d pages of RAM\n",total);
  115. printk("%d pages of HIGHMEM\n", highmem);
  116. printk("%d free pages\n",free);
  117. printk("%d reserved pages\n",reserved);
  118. printk("%d pages shared\n",shared);
  119. printk("%d pages swap cached\n",cached);
  120. }
  121. /* Free up now-unused memory */
  122. static void free_sec(unsigned long start, unsigned long end, const char *name)
  123. {
  124. unsigned long cnt = 0;
  125. while (start < end) {
  126. ClearPageReserved(virt_to_page(start));
  127. set_page_count(virt_to_page(start), 1);
  128. free_page(start);
  129. cnt++;
  130. start += PAGE_SIZE;
  131. }
  132. if (cnt) {
  133. printk(" %ldk %s", cnt << (PAGE_SHIFT - 10), name);
  134. totalram_pages += cnt;
  135. }
  136. }
  137. void free_initmem(void)
  138. {
  139. #define FREESEC(TYPE) \
  140. free_sec((unsigned long)(&__ ## TYPE ## _begin), \
  141. (unsigned long)(&__ ## TYPE ## _end), \
  142. #TYPE);
  143. printk ("Freeing unused kernel memory:");
  144. FREESEC(init);
  145. printk("\n");
  146. ppc_md.progress = NULL;
  147. #undef FREESEC
  148. }
  149. #ifdef CONFIG_BLK_DEV_INITRD
  150. void free_initrd_mem(unsigned long start, unsigned long end)
  151. {
  152. printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
  153. for (; start < end; start += PAGE_SIZE) {
  154. ClearPageReserved(virt_to_page(start));
  155. set_page_count(virt_to_page(start), 1);
  156. free_page(start);
  157. totalram_pages++;
  158. }
  159. }
  160. #endif
  161. /*
  162. * Check for command-line options that affect what MMU_init will do.
  163. */
  164. void MMU_setup(void)
  165. {
  166. /* Check for nobats option (used in mapin_ram). */
  167. if (strstr(cmd_line, "nobats")) {
  168. __map_without_bats = 1;
  169. }
  170. if (strstr(cmd_line, "noltlbs")) {
  171. __map_without_ltlbs = 1;
  172. }
  173. /* Look for mem= option on command line */
  174. if (strstr(cmd_line, "mem=")) {
  175. char *p, *q;
  176. unsigned long maxmem = 0;
  177. for (q = cmd_line; (p = strstr(q, "mem=")) != 0; ) {
  178. q = p + 4;
  179. if (p > cmd_line && p[-1] != ' ')
  180. continue;
  181. maxmem = simple_strtoul(q, &q, 0);
  182. if (*q == 'k' || *q == 'K') {
  183. maxmem <<= 10;
  184. ++q;
  185. } else if (*q == 'm' || *q == 'M') {
  186. maxmem <<= 20;
  187. ++q;
  188. }
  189. }
  190. __max_memory = maxmem;
  191. }
  192. }
  193. /*
  194. * MMU_init sets up the basic memory mappings for the kernel,
  195. * including both RAM and possibly some I/O regions,
  196. * and sets up the page tables and the MMU hardware ready to go.
  197. */
  198. void __init MMU_init(void)
  199. {
  200. if (ppc_md.progress)
  201. ppc_md.progress("MMU:enter", 0x111);
  202. /* parse args from command line */
  203. MMU_setup();
  204. /*
  205. * Figure out how much memory we have, how much
  206. * is lowmem, and how much is highmem. If we were
  207. * passed the total memory size from the bootloader,
  208. * just use it.
  209. */
  210. if (boot_mem_size)
  211. total_memory = boot_mem_size;
  212. else
  213. total_memory = ppc_md.find_end_of_memory();
  214. if (__max_memory && total_memory > __max_memory)
  215. total_memory = __max_memory;
  216. total_lowmem = total_memory;
  217. #ifdef CONFIG_FSL_BOOKE
  218. /* Freescale Book-E parts expect lowmem to be mapped by fixed TLB
  219. * entries, so we need to adjust lowmem to match the amount we can map
  220. * in the fixed entries */
  221. adjust_total_lowmem();
  222. #endif /* CONFIG_FSL_BOOKE */
  223. if (total_lowmem > __max_low_memory) {
  224. total_lowmem = __max_low_memory;
  225. #ifndef CONFIG_HIGHMEM
  226. total_memory = total_lowmem;
  227. #endif /* CONFIG_HIGHMEM */
  228. }
  229. set_phys_avail(total_lowmem);
  230. /* Initialize the MMU hardware */
  231. if (ppc_md.progress)
  232. ppc_md.progress("MMU:hw init", 0x300);
  233. MMU_init_hw();
  234. /* Map in all of RAM starting at KERNELBASE */
  235. if (ppc_md.progress)
  236. ppc_md.progress("MMU:mapin", 0x301);
  237. mapin_ram();
  238. #ifdef CONFIG_HIGHMEM
  239. ioremap_base = PKMAP_BASE;
  240. #else
  241. ioremap_base = 0xfe000000UL; /* for now, could be 0xfffff000 */
  242. #endif /* CONFIG_HIGHMEM */
  243. ioremap_bot = ioremap_base;
  244. /* Map in I/O resources */
  245. if (ppc_md.progress)
  246. ppc_md.progress("MMU:setio", 0x302);
  247. if (ppc_md.setup_io_mappings)
  248. ppc_md.setup_io_mappings();
  249. /* Initialize the context management stuff */
  250. mmu_context_init();
  251. if (ppc_md.progress)
  252. ppc_md.progress("MMU:exit", 0x211);
  253. #ifdef CONFIG_BOOTX_TEXT
  254. /* By default, we are no longer mapped */
  255. boot_text_mapped = 0;
  256. /* Must be done last, or ppc_md.progress will die. */
  257. map_boot_text();
  258. #endif
  259. }
  260. /* This is only called until mem_init is done. */
  261. void __init *early_get_page(void)
  262. {
  263. void *p;
  264. if (init_bootmem_done) {
  265. p = alloc_bootmem_pages(PAGE_SIZE);
  266. } else {
  267. p = mem_pieces_find(PAGE_SIZE, PAGE_SIZE);
  268. }
  269. return p;
  270. }
  271. /*
  272. * Initialize the bootmem system and give it all the memory we
  273. * have available.
  274. */
  275. void __init do_init_bootmem(void)
  276. {
  277. unsigned long start, size;
  278. int i;
  279. /*
  280. * Find an area to use for the bootmem bitmap.
  281. * We look for the first area which is at least
  282. * 128kB in length (128kB is enough for a bitmap
  283. * for 4GB of memory, using 4kB pages), plus 1 page
  284. * (in case the address isn't page-aligned).
  285. */
  286. start = 0;
  287. size = 0;
  288. for (i = 0; i < phys_avail.n_regions; ++i) {
  289. unsigned long a = phys_avail.regions[i].address;
  290. unsigned long s = phys_avail.regions[i].size;
  291. if (s <= size)
  292. continue;
  293. start = a;
  294. size = s;
  295. if (s >= 33 * PAGE_SIZE)
  296. break;
  297. }
  298. start = PAGE_ALIGN(start);
  299. min_low_pfn = start >> PAGE_SHIFT;
  300. max_low_pfn = (PPC_MEMSTART + total_lowmem) >> PAGE_SHIFT;
  301. max_pfn = (PPC_MEMSTART + total_memory) >> PAGE_SHIFT;
  302. boot_mapsize = init_bootmem_node(&contig_page_data, min_low_pfn,
  303. PPC_MEMSTART >> PAGE_SHIFT,
  304. max_low_pfn);
  305. /* remove the bootmem bitmap from the available memory */
  306. mem_pieces_remove(&phys_avail, start, boot_mapsize, 1);
  307. /* add everything in phys_avail into the bootmem map */
  308. for (i = 0; i < phys_avail.n_regions; ++i)
  309. free_bootmem(phys_avail.regions[i].address,
  310. phys_avail.regions[i].size);
  311. init_bootmem_done = 1;
  312. }
  313. /*
  314. * paging_init() sets up the page tables - in fact we've already done this.
  315. */
  316. void __init paging_init(void)
  317. {
  318. unsigned long zones_size[MAX_NR_ZONES], i;
  319. #ifdef CONFIG_HIGHMEM
  320. map_page(PKMAP_BASE, 0, 0); /* XXX gross */
  321. pkmap_page_table = pte_offset_kernel(pmd_offset(pgd_offset_k
  322. (PKMAP_BASE), PKMAP_BASE), PKMAP_BASE);
  323. map_page(KMAP_FIX_BEGIN, 0, 0); /* XXX gross */
  324. kmap_pte = pte_offset_kernel(pmd_offset(pgd_offset_k
  325. (KMAP_FIX_BEGIN), KMAP_FIX_BEGIN), KMAP_FIX_BEGIN);
  326. kmap_prot = PAGE_KERNEL;
  327. #endif /* CONFIG_HIGHMEM */
  328. /*
  329. * All pages are DMA-able so we put them all in the DMA zone.
  330. */
  331. zones_size[ZONE_DMA] = total_lowmem >> PAGE_SHIFT;
  332. for (i = 1; i < MAX_NR_ZONES; i++)
  333. zones_size[i] = 0;
  334. #ifdef CONFIG_HIGHMEM
  335. zones_size[ZONE_HIGHMEM] = (total_memory - total_lowmem) >> PAGE_SHIFT;
  336. #endif /* CONFIG_HIGHMEM */
  337. free_area_init(zones_size);
  338. }
  339. void __init mem_init(void)
  340. {
  341. unsigned long addr;
  342. int codepages = 0;
  343. int datapages = 0;
  344. int initpages = 0;
  345. #ifdef CONFIG_HIGHMEM
  346. unsigned long highmem_mapnr;
  347. highmem_mapnr = total_lowmem >> PAGE_SHIFT;
  348. #endif /* CONFIG_HIGHMEM */
  349. max_mapnr = total_memory >> PAGE_SHIFT;
  350. high_memory = (void *) __va(PPC_MEMSTART + total_lowmem);
  351. num_physpages = max_mapnr; /* RAM is assumed contiguous */
  352. totalram_pages += free_all_bootmem();
  353. #ifdef CONFIG_BLK_DEV_INITRD
  354. /* if we are booted from BootX with an initial ramdisk,
  355. make sure the ramdisk pages aren't reserved. */
  356. if (initrd_start) {
  357. for (addr = initrd_start; addr < initrd_end; addr += PAGE_SIZE)
  358. ClearPageReserved(virt_to_page(addr));
  359. }
  360. #endif /* CONFIG_BLK_DEV_INITRD */
  361. #ifdef CONFIG_PPC_OF
  362. /* mark the RTAS pages as reserved */
  363. if ( rtas_data )
  364. for (addr = (ulong)__va(rtas_data);
  365. addr < PAGE_ALIGN((ulong)__va(rtas_data)+rtas_size) ;
  366. addr += PAGE_SIZE)
  367. SetPageReserved(virt_to_page(addr));
  368. #endif
  369. #ifdef CONFIG_PPC_PMAC
  370. if (agp_special_page)
  371. SetPageReserved(virt_to_page(agp_special_page));
  372. #endif
  373. for (addr = PAGE_OFFSET; addr < (unsigned long)high_memory;
  374. addr += PAGE_SIZE) {
  375. if (!PageReserved(virt_to_page(addr)))
  376. continue;
  377. if (addr < (ulong) etext)
  378. codepages++;
  379. else if (addr >= (unsigned long)&__init_begin
  380. && addr < (unsigned long)&__init_end)
  381. initpages++;
  382. else if (addr < (ulong) klimit)
  383. datapages++;
  384. }
  385. #ifdef CONFIG_HIGHMEM
  386. {
  387. unsigned long pfn;
  388. for (pfn = highmem_mapnr; pfn < max_mapnr; ++pfn) {
  389. struct page *page = mem_map + pfn;
  390. ClearPageReserved(page);
  391. set_page_count(page, 1);
  392. __free_page(page);
  393. totalhigh_pages++;
  394. }
  395. totalram_pages += totalhigh_pages;
  396. }
  397. #endif /* CONFIG_HIGHMEM */
  398. printk("Memory: %luk available (%dk kernel code, %dk data, %dk init, %ldk highmem)\n",
  399. (unsigned long)nr_free_pages()<< (PAGE_SHIFT-10),
  400. codepages<< (PAGE_SHIFT-10), datapages<< (PAGE_SHIFT-10),
  401. initpages<< (PAGE_SHIFT-10),
  402. (unsigned long) (totalhigh_pages << (PAGE_SHIFT-10)));
  403. #ifdef CONFIG_PPC_PMAC
  404. if (agp_special_page)
  405. printk(KERN_INFO "AGP special page: 0x%08lx\n", agp_special_page);
  406. #endif
  407. mem_init_done = 1;
  408. }
  409. /*
  410. * Set phys_avail to the amount of physical memory,
  411. * less the kernel text/data/bss.
  412. */
  413. void __init
  414. set_phys_avail(unsigned long total_memory)
  415. {
  416. unsigned long kstart, ksize;
  417. /*
  418. * Initially, available physical memory is equivalent to all
  419. * physical memory.
  420. */
  421. phys_avail.regions[0].address = PPC_MEMSTART;
  422. phys_avail.regions[0].size = total_memory;
  423. phys_avail.n_regions = 1;
  424. /*
  425. * Map out the kernel text/data/bss from the available physical
  426. * memory.
  427. */
  428. kstart = __pa(_stext); /* should be 0 */
  429. ksize = PAGE_ALIGN(klimit - _stext);
  430. mem_pieces_remove(&phys_avail, kstart, ksize, 0);
  431. mem_pieces_remove(&phys_avail, 0, 0x4000, 0);
  432. #if defined(CONFIG_BLK_DEV_INITRD)
  433. /* Remove the init RAM disk from the available memory. */
  434. if (initrd_start) {
  435. mem_pieces_remove(&phys_avail, __pa(initrd_start),
  436. initrd_end - initrd_start, 1);
  437. }
  438. #endif /* CONFIG_BLK_DEV_INITRD */
  439. #ifdef CONFIG_PPC_OF
  440. /* remove the RTAS pages from the available memory */
  441. if (rtas_data)
  442. mem_pieces_remove(&phys_avail, rtas_data, rtas_size, 1);
  443. #endif
  444. #ifdef CONFIG_PPC_PMAC
  445. /* Because of some uninorth weirdness, we need a page of
  446. * memory as high as possible (it must be outside of the
  447. * bus address seen as the AGP aperture). It will be used
  448. * by the r128 DRM driver
  449. *
  450. * FIXME: We need to make sure that page doesn't overlap any of the\
  451. * above. This could be done by improving mem_pieces_find to be able
  452. * to do a backward search from the end of the list.
  453. */
  454. if (_machine == _MACH_Pmac && find_devices("uni-north-agp")) {
  455. agp_special_page = (total_memory - PAGE_SIZE);
  456. mem_pieces_remove(&phys_avail, agp_special_page, PAGE_SIZE, 0);
  457. agp_special_page = (unsigned long)__va(agp_special_page);
  458. }
  459. #endif /* CONFIG_PPC_PMAC */
  460. }
  461. /* Mark some memory as reserved by removing it from phys_avail. */
  462. void __init reserve_phys_mem(unsigned long start, unsigned long size)
  463. {
  464. mem_pieces_remove(&phys_avail, start, size, 1);
  465. }
  466. /*
  467. * This is called when a page has been modified by the kernel.
  468. * It just marks the page as not i-cache clean. We do the i-cache
  469. * flush later when the page is given to a user process, if necessary.
  470. */
  471. void flush_dcache_page(struct page *page)
  472. {
  473. clear_bit(PG_arch_1, &page->flags);
  474. }
  475. void flush_dcache_icache_page(struct page *page)
  476. {
  477. #ifdef CONFIG_BOOKE
  478. void *start = kmap_atomic(page, KM_PPC_SYNC_ICACHE);
  479. __flush_dcache_icache(start);
  480. kunmap_atomic(start, KM_PPC_SYNC_ICACHE);
  481. #elif defined(CONFIG_8xx)
  482. /* On 8xx there is no need to kmap since highmem is not supported */
  483. __flush_dcache_icache(page_address(page));
  484. #else
  485. __flush_dcache_icache_phys(page_to_pfn(page) << PAGE_SHIFT);
  486. #endif
  487. }
  488. void clear_user_page(void *page, unsigned long vaddr, struct page *pg)
  489. {
  490. clear_page(page);
  491. clear_bit(PG_arch_1, &pg->flags);
  492. }
  493. void copy_user_page(void *vto, void *vfrom, unsigned long vaddr,
  494. struct page *pg)
  495. {
  496. copy_page(vto, vfrom);
  497. clear_bit(PG_arch_1, &pg->flags);
  498. }
  499. void flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
  500. unsigned long addr, int len)
  501. {
  502. unsigned long maddr;
  503. maddr = (unsigned long) kmap(page) + (addr & ~PAGE_MASK);
  504. flush_icache_range(maddr, maddr + len);
  505. kunmap(page);
  506. }
  507. /*
  508. * This is called at the end of handling a user page fault, when the
  509. * fault has been handled by updating a PTE in the linux page tables.
  510. * We use it to preload an HPTE into the hash table corresponding to
  511. * the updated linux PTE.
  512. */
  513. void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
  514. pte_t pte)
  515. {
  516. /* handle i-cache coherency */
  517. unsigned long pfn = pte_pfn(pte);
  518. if (pfn_valid(pfn)) {
  519. struct page *page = pfn_to_page(pfn);
  520. if (!PageReserved(page)
  521. && !test_bit(PG_arch_1, &page->flags)) {
  522. if (vma->vm_mm == current->active_mm) {
  523. #ifdef CONFIG_8xx
  524. /* On 8xx, cache control instructions (particularly
  525. * "dcbst" from flush_dcache_icache) fault as write
  526. * operation if there is an unpopulated TLB entry
  527. * for the address in question. To workaround that,
  528. * we invalidate the TLB here, thus avoiding dcbst
  529. * misbehaviour.
  530. */
  531. _tlbie(address);
  532. #endif
  533. __flush_dcache_icache((void *) address);
  534. } else
  535. flush_dcache_icache_page(page);
  536. set_bit(PG_arch_1, &page->flags);
  537. }
  538. }
  539. #ifdef CONFIG_PPC_STD_MMU
  540. /* We only want HPTEs for linux PTEs that have _PAGE_ACCESSED set */
  541. if (Hash != 0 && pte_young(pte)) {
  542. struct mm_struct *mm;
  543. pmd_t *pmd;
  544. mm = (address < TASK_SIZE)? vma->vm_mm: &init_mm;
  545. pmd = pmd_offset(pgd_offset(mm, address), address);
  546. if (!pmd_none(*pmd))
  547. add_hash_page(mm->context, address, pmd_val(*pmd));
  548. }
  549. #endif
  550. }
  551. /*
  552. * This is called by /dev/mem to know if a given address has to
  553. * be mapped non-cacheable or not
  554. */
  555. int page_is_ram(unsigned long pfn)
  556. {
  557. return pfn < max_pfn;
  558. }
  559. pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
  560. unsigned long size, pgprot_t vma_prot)
  561. {
  562. if (ppc_md.phys_mem_access_prot)
  563. return ppc_md.phys_mem_access_prot(file, pfn, size, vma_prot);
  564. if (!page_is_ram(pfn))
  565. vma_prot = __pgprot(pgprot_val(vma_prot)
  566. | _PAGE_GUARDED | _PAGE_NO_CACHE);
  567. return vma_prot;
  568. }
  569. EXPORT_SYMBOL(phys_mem_access_prot);