pgalloc.h 3.3 KB

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