aboutsummaryrefslogtreecommitdiffstats
path: root/old/xenolinux-2.4.16-sparse/arch/xeno/mm/hypervisor.c
blob: b051684aa2b756ce82cdd923086f628b089adbdf (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/******************************************************************************
 * xeno/mm/hypervisor.c
 * 
 * Update page tables via the hypervisor.
 * 
 * Copyright (c) 2002, K A Fraser
 */

#include <linux/config.h>
#include <linux/sched.h>
#include <asm/hypervisor.h>
#include <asm/page.h>
#include <asm/pgtable.h>

#define QUEUE_SIZE 2048
static page_update_request_t update_queue[QUEUE_SIZE];
unsigned int pt_update_queue_idx = 0;
#define idx pt_update_queue_idx

#if PT_UPDATE_DEBUG > 0
page_update_debug_t update_debug_queue[QUEUE_SIZE] = {{0}};
#undef queue_l1_entry_update
#undef queue_l2_entry_update
static void DEBUG_allow_pt_reads(void)
{
    pte_t *pte;
    page_update_request_t update;
    int i;
    for ( i = idx-1; i >= 0; i-- )
    {
        pte = update_debug_queue[i].ptep;
        if ( pte == NULL ) continue;
        update_debug_queue[i].ptep = NULL;
        update.ptr = phys_to_machine(__pa(pte));
        update.val = update_debug_queue[i].pteval;
        HYPERVISOR_pt_update(&update, 1);
    }
}
static void DEBUG_disallow_pt_read(unsigned long pa)
{
    pte_t *pte;
    pmd_t *pmd;
    pgd_t *pgd;
    unsigned long pteval;
    /*
     * We may fault because of an already outstanding update.
     * That's okay -- it'll get fixed up in the fault handler.
     */
    page_update_request_t update;
    unsigned long va = (unsigned long)__va(pa);
    pgd = pgd_offset_k(va);
    pmd = pmd_offset(pgd, va);
    pte = pte_offset(pmd, va);
    update.ptr = phys_to_machine(__pa(pte));
    pteval = *(unsigned long *)pte;
    update.val = pteval & ~_PAGE_PRESENT;
    HYPERVISOR_pt_update(&update, 1);
    update_debug_queue[idx].ptep = pte;
    update_debug_queue[idx].pteval = pteval;
}
#endif

#if PT_UPDATE_DEBUG > 1
#undef queue_pt_switch
#undef queue_tlb_flush
#undef queue_invlpg
#undef queue_pgd_pin
#undef queue_pgd_unpin
#undef queue_pte_pin
#undef queue_pte_unpin
#endif


/*
 * This is the current pagetable base pointer, which is updated
 * on context switch.
 */
unsigned long pt_baseptr;

void _flush_page_update_queue(void)
{
    if ( idx == 0 ) return;
#if PT_UPDATE_DEBUG > 1
    printk("Flushing %d entries from pt update queue\n", idx);
#endif
#if PT_UPDATE_DEBUG > 0
    DEBUG_allow_pt_reads();
#endif
    HYPERVISOR_pt_update(update_queue, idx);
    idx = 0;
}

static void increment_index(void)
{
    if ( ++idx == QUEUE_SIZE ) _flush_page_update_queue();
}

void queue_l1_entry_update(unsigned long ptr, unsigned long val)
{
#if PT_UPDATE_DEBUG > 0
    DEBUG_disallow_pt_read(ptr);
#endif
    update_queue[idx].ptr = phys_to_machine(ptr);
    update_queue[idx].val = val;
    increment_index();
}

void queue_l2_entry_update(unsigned long ptr, unsigned long val)
{
    update_queue[idx].ptr = phys_to_machine(ptr);
    update_queue[idx].val = val;
    increment_index();
}

void queue_pt_switch(unsigned long ptr)
{
    update_queue[idx].ptr  = phys_to_machine(ptr);
    update_queue[idx].ptr |= PGREQ_EXTENDED_COMMAND;
    update_queue[idx].val  = PGEXT_NEW_BASEPTR;
    increment_index();
}

void queue_tlb_flush(void)
{
    update_queue[idx].ptr  = PGREQ_EXTENDED_COMMAND;
    update_queue[idx].val  = PGEXT_TLB_FLUSH;
    increment_index();
}

void queue_invlpg(unsigned long ptr)
{
    update_queue[idx].ptr  = PGREQ_EXTENDED_COMMAND;
    update_queue[idx].val  = ptr & PAGE_MASK;
    update_queue[idx].val |= PGEXT_INVLPG;
    increment_index();
}

void queue_pgd_pin(unsigned long ptr)
{
    update_queue[idx].ptr  = phys_to_machine(ptr);
    update_queue[idx].ptr |= PGREQ_EXTENDED_COMMAND;
    update_queue[idx].val  = PGEXT_PIN_L2_TABLE;
    increment_index();
}

void queue_pgd_unpin(unsigned long ptr)
{
    update_queue[idx].ptr  = phys_to_machine(ptr);
    update_queue[idx].ptr |= PGREQ_EXTENDED_COMMAND;
    update_queue[idx].val  = PGEXT_UNPIN_TABLE;
    increment_index();
}

void queue_pte_pin(unsigned long ptr)
{
    update_queue[idx].ptr  = phys_to_machine(ptr);
    update_queue[idx].ptr |= PGREQ_EXTENDED_COMMAND;
    update_queue[idx].val  = PGEXT_PIN_L1_TABLE;
    increment_index();
}

void queue_pte_unpin(unsigned long ptr)
{
    update_queue[idx].ptr  = phys_to_machine(ptr);
    update_queue[idx].ptr |= PGREQ_EXTENDED_COMMAND;
    update_queue[idx].val  = PGEXT_UNPIN_TABLE;
    increment_index();
}