pgalloc.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * linux/include/asm-xtensa/pgalloc.h
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * Copyright (C) 2001-2005 Tensilica Inc.
  9. */
  10. #ifndef _XTENSA_PGALLOC_H
  11. #define _XTENSA_PGALLOC_H
  12. #ifdef __KERNEL__
  13. #include <linux/threads.h>
  14. #include <linux/highmem.h>
  15. #include <asm/processor.h>
  16. #include <asm/cacheflush.h>
  17. /* Cache aliasing:
  18. *
  19. * If the cache size for one way is greater than the page size, we have to
  20. * deal with cache aliasing. The cache index is wider than the page size:
  21. *
  22. * |cache |
  23. * |pgnum |page| virtual address
  24. * |xxxxxX|zzzz|
  25. * | | |
  26. * \ / | |
  27. * trans.| |
  28. * / \ | |
  29. * |yyyyyY|zzzz| physical address
  30. *
  31. * When the page number is translated to the physical page address, the lowest
  32. * bit(s) (X) that are also part of the cache index are also translated (Y).
  33. * If this translation changes this bit (X), the cache index is also afected,
  34. * thus resulting in a different cache line than before.
  35. * The kernel does not provide a mechanism to ensure that the page color
  36. * (represented by this bit) remains the same when allocated or when pages
  37. * are remapped. When user pages are mapped into kernel space, the color of
  38. * the page might also change.
  39. *
  40. * We use the address space VMALLOC_END ... VMALLOC_END + DCACHE_WAY_SIZE * 2
  41. * to temporarily map a patch so we can match the color.
  42. */
  43. #if (DCACHE_WAY_SIZE > PAGE_SIZE)
  44. # define PAGE_COLOR_MASK (PAGE_MASK & (DCACHE_WAY_SIZE-1))
  45. # define PAGE_COLOR(a) \
  46. (((unsigned long)(a)&PAGE_COLOR_MASK) >> PAGE_SHIFT)
  47. # define PAGE_COLOR_EQ(a,b) \
  48. ((((unsigned long)(a) ^ (unsigned long)(b)) & PAGE_COLOR_MASK) == 0)
  49. # define PAGE_COLOR_MAP0(v) \
  50. (VMALLOC_END + ((unsigned long)(v) & PAGE_COLOR_MASK))
  51. # define PAGE_COLOR_MAP1(v) \
  52. (VMALLOC_END + ((unsigned long)(v) & PAGE_COLOR_MASK) + DCACHE_WAY_SIZE)
  53. #endif
  54. /*
  55. * Allocating and freeing a pmd is trivial: the 1-entry pmd is
  56. * inside the pgd, so has no extra memory associated with it.
  57. */
  58. #define pgd_free(pgd) free_page((unsigned long)(pgd))
  59. #if (DCACHE_WAY_SIZE > PAGE_SIZE) && XCHAL_DCACHE_IS_WRITEBACK
  60. static inline void
  61. pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *pte)
  62. {
  63. pmd_val(*(pmdp)) = (unsigned long)(pte);
  64. __asm__ __volatile__ ("memw; dhwb %0, 0; dsync" :: "a" (pmdp));
  65. }
  66. static inline void
  67. pmd_populate(struct mm_struct *mm, pmd_t *pmdp, struct page *page)
  68. {
  69. pmd_val(*(pmdp)) = (unsigned long)page_to_virt(page);
  70. __asm__ __volatile__ ("memw; dhwb %0, 0; dsync" :: "a" (pmdp));
  71. }
  72. #else
  73. # define pmd_populate_kernel(mm, pmdp, pte) \
  74. (pmd_val(*(pmdp)) = (unsigned long)(pte))
  75. # define pmd_populate(mm, pmdp, page) \
  76. (pmd_val(*(pmdp)) = (unsigned long)page_to_virt(page))
  77. #endif
  78. static inline pgd_t*
  79. pgd_alloc(struct mm_struct *mm)
  80. {
  81. pgd_t *pgd;
  82. pgd = (pgd_t *)__get_free_pages(GFP_KERNEL|__GFP_ZERO, PGD_ORDER);
  83. if (likely(pgd != NULL))
  84. __flush_dcache_page((unsigned long)pgd);
  85. return pgd;
  86. }
  87. extern pte_t* pte_alloc_one_kernel(struct mm_struct* mm, unsigned long addr);
  88. extern struct page* pte_alloc_one(struct mm_struct* mm, unsigned long addr);
  89. #define pte_free_kernel(pte) free_page((unsigned long)pte)
  90. #define pte_free(pte) __free_page(pte)
  91. #endif /* __KERNEL__ */
  92. #endif /* _XTENSA_PGALLOC_H */