minicache.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * linux/arch/arm/mm/minicache.c
  3. *
  4. * Copyright (C) 2001 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. * This handles the mini data cache, as found on SA11x0 and XScale
  11. * processors. When we copy a user page page, we map it in such a way
  12. * that accesses to this page will not touch the main data cache, but
  13. * will be cached in the mini data cache. This prevents us thrashing
  14. * the main data cache on page faults.
  15. */
  16. #include <linux/init.h>
  17. #include <linux/mm.h>
  18. #include <asm/page.h>
  19. #include <asm/pgtable.h>
  20. #include <asm/tlbflush.h>
  21. /*
  22. * 0xffff8000 to 0xffffffff is reserved for any ARM architecture
  23. * specific hacks for copying pages efficiently.
  24. */
  25. #define minicache_address (0xffff8000)
  26. #define minicache_pgprot __pgprot(L_PTE_PRESENT | L_PTE_YOUNG | \
  27. L_PTE_CACHEABLE)
  28. static pte_t *minicache_pte;
  29. /*
  30. * Note that this is intended to be called only from the copy_user_page
  31. * asm code; anything else will require special locking to prevent the
  32. * mini-cache space being re-used. (Note: probably preempt unsafe).
  33. *
  34. * We rely on the fact that the minicache is 2K, and we'll be pushing
  35. * 4K of data through it, so we don't actually have to specifically
  36. * flush the minicache when we change the mapping.
  37. *
  38. * Note also: assert(PAGE_OFFSET <= virt < high_memory).
  39. * Unsafe: preempt, kmap.
  40. */
  41. unsigned long map_page_minicache(unsigned long virt)
  42. {
  43. set_pte(minicache_pte, pfn_pte(__pa(virt) >> PAGE_SHIFT, minicache_pgprot));
  44. flush_tlb_kernel_page(minicache_address);
  45. return minicache_address;
  46. }
  47. static int __init minicache_init(void)
  48. {
  49. pgd_t *pgd;
  50. pmd_t *pmd;
  51. spin_lock(&init_mm.page_table_lock);
  52. pgd = pgd_offset_k(minicache_address);
  53. pmd = pmd_alloc(&init_mm, pgd, minicache_address);
  54. if (!pmd)
  55. BUG();
  56. minicache_pte = pte_alloc_kernel(&init_mm, pmd, minicache_address);
  57. if (!minicache_pte)
  58. BUG();
  59. spin_unlock(&init_mm.page_table_lock);
  60. return 0;
  61. }
  62. core_initcall(minicache_init);