summaryrefslogtreecommitdiff
path: root/include/asm-ppc/pgalloc.h
blob: 015b8ab4b99f0c57a8574ac77b2a2c9c59b06956 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * BK Id: %F% %I% %G% %U% %#%
 */
#ifdef __KERNEL__
#ifndef _PPC_PGALLOC_H
#define _PPC_PGALLOC_H

#include <linux/config.h>
#include <linux/threads.h>
#include <linux/highmem.h>
#include <asm/processor.h>

extern void __bad_pte(pmd_t *pmd);

static inline pgd_t *pgd_alloc(struct mm_struct *mm)
{
	pgd_t *ret;

	if ((ret = (pgd_t *)__get_free_page(GFP_KERNEL)) != NULL)
		clear_page(ret);
	return ret;
}

extern __inline__ void pgd_free(pgd_t *pgd)
{
	free_page((unsigned long)pgd);
}

/*
 * We don't have any real pmd's, and this code never triggers because
 * the pgd will always be present..
 */
#define pmd_alloc_one(mm,address)       ({ BUG(); ((pmd_t *)2); })
#define pmd_free(x)                     do { } while (0)
#define pgd_populate(mm, pmd, pte)      BUG()

static inline pte_t *
pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
{
	pte_t *pte;
	extern int mem_init_done;
	extern void *early_get_page(void);
	int timeout = 0;

	if (mem_init_done) {
		while ((pte = (pte_t *) __get_free_page(GFP_KERNEL)) == NULL
		       && ++timeout < 10) {
			set_current_state(TASK_UNINTERRUPTIBLE);
			schedule_timeout(HZ);
		}
	} else
		pte = (pte_t *) early_get_page();
	if (pte != NULL)
		clear_page(pte);
	return pte;
}

static inline struct page *
pte_alloc_one(struct mm_struct *mm, unsigned long address)
{
	struct page *pte;
	int timeout = 0;
#ifdef CONFIG_HIGHPTE
	int flags = GFP_KERNEL | __GFP_HIGHMEM;
#else
	int flags = GFP_KERNEL;
#endif

	while ((pte = alloc_pages(flags, 0)) == NULL) {
		if (++timeout >= 10)
			return NULL;
		set_current_state(TASK_UNINTERRUPTIBLE);
		schedule_timeout(HZ);
	}
	clear_highpage(pte);
	return pte;
}

static inline void pte_free_kernel(pte_t *pte)
{
	free_page((unsigned long)pte);
}

static inline void pte_free(struct page *pte)
{
	__free_page(pte);
}

#define pmd_populate_kernel(mm, pmd, pte)	\
		(pmd_val(*(pmd)) = __pa(pte))
#define pmd_populate(mm, pmd, pte)	\
		(pmd_val(*(pmd)) = ((pte) - mem_map) << PAGE_SHIFT)

extern int do_check_pgt_cache(int, int);

#endif /* _PPC_PGALLOC_H */
#endif /* __KERNEL__ */