1
2
3
4
5
6
7
8
9
10#include <linux/mm.h>
11#include <linux/hugetlb.h>
12#include <asm/pgtable.h>
13#include <asm/pgalloc.h>
14#include <asm/cacheflush.h>
15#include <asm/machdep.h>
16
17extern long hpte_insert_repeating(unsigned long hash, unsigned long vpn,
18 unsigned long pa, unsigned long rlags,
19 unsigned long vflags, int psize, int ssize);
20
21int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid,
22 pte_t *ptep, unsigned long trap, unsigned long flags,
23 int ssize, unsigned int shift, unsigned int mmu_psize)
24{
25 unsigned long vpn;
26 unsigned long old_pte, new_pte;
27 unsigned long rflags, pa, sz;
28 long slot;
29
30 BUG_ON(shift != mmu_psize_defs[mmu_psize].shift);
31
32
33 vpn = hpt_vpn(ea, vsid, ssize);
34
35
36
37
38
39
40
41
42
43
44
45
46
47 do {
48 old_pte = pte_val(*ptep);
49
50 if (unlikely(old_pte & H_PAGE_BUSY))
51 return 0;
52
53 if (unlikely(!check_pte_access(access, old_pte)))
54 return 1;
55
56
57
58 new_pte = old_pte | H_PAGE_BUSY | _PAGE_ACCESSED;
59 if (access & _PAGE_WRITE)
60 new_pte |= _PAGE_DIRTY;
61 } while(!pte_xchg(ptep, __pte(old_pte), __pte(new_pte)));
62
63 rflags = htab_convert_pte_flags(new_pte);
64
65 sz = ((1UL) << shift);
66 if (!cpu_has_feature(CPU_FTR_COHERENT_ICACHE))
67
68
69 rflags = hash_page_do_lazy_icache(rflags, __pte(old_pte), trap);
70
71
72 if (unlikely(old_pte & H_PAGE_HASHPTE)) {
73
74 unsigned long hash, slot;
75
76 hash = hpt_hash(vpn, shift, ssize);
77 if (old_pte & H_PAGE_F_SECOND)
78 hash = ~hash;
79 slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
80 slot += (old_pte & H_PAGE_F_GIX) >> H_PAGE_F_GIX_SHIFT;
81
82 if (mmu_hash_ops.hpte_updatepp(slot, rflags, vpn, mmu_psize,
83 mmu_psize, ssize, flags) == -1)
84 old_pte &= ~_PAGE_HPTEFLAGS;
85 }
86
87 if (likely(!(old_pte & H_PAGE_HASHPTE))) {
88 unsigned long hash = hpt_hash(vpn, shift, ssize);
89
90 pa = pte_pfn(__pte(old_pte)) << PAGE_SHIFT;
91
92
93 new_pte = (new_pte & ~_PAGE_HPTEFLAGS) | H_PAGE_HASHPTE;
94
95 slot = hpte_insert_repeating(hash, vpn, pa, rflags, 0,
96 mmu_psize, ssize);
97
98
99
100
101
102 if (unlikely(slot == -2)) {
103 *ptep = __pte(old_pte);
104 hash_failure_debug(ea, access, vsid, trap, ssize,
105 mmu_psize, mmu_psize, old_pte);
106 return -1;
107 }
108
109 new_pte |= (slot << H_PAGE_F_GIX_SHIFT) &
110 (H_PAGE_F_SECOND | H_PAGE_F_GIX);
111 }
112
113
114
115
116 *ptep = __pte(new_pte & ~H_PAGE_BUSY);
117 return 0;
118}
119
120#if defined(CONFIG_PPC_64K_PAGES) && defined(CONFIG_DEBUG_VM)
121
122
123
124
125int hugepd_ok(hugepd_t hpd)
126{
127 bool is_hugepd;
128
129
130
131
132 is_hugepd = (((hpd.pd & 0x3) == 0x0) && ((hpd.pd & HUGEPD_SHIFT_MASK) != 0));
133 WARN(is_hugepd, "Found wrong page directory format\n");
134 return 0;
135}
136#endif
137