summaryrefslogtreecommitdiffstats
path: root/src/kernel/vmmmgr.C
blob: 553fa3d34067551002343f0012e12e7450ca0aa0 (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/kernel/vmmmgr.C $                                         */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2010,2017                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#include <limits.h>
#include <util/singleton.H>
#include <kernel/vmmmgr.H>
#include <kernel/console.H>
#include <arch/ppc.H>
#include <kernel/ptmgr.H>
#include <kernel/segmentmgr.H>
#include <kernel/basesegment.H>
#include <kernel/stacksegment.H>
#include <kernel/devicesegment.H>
#include <config.h>
#include <kernel/bltohbdatamgr.H>
#include <util/align.H>


extern void* data_load_address;
uint64_t VmmManager::g_patb[2];

VmmManager::VmmManager() : lock()
{
    printk("HRMOR = %lX\n", getHRMOR());
}

void VmmManager::init()
{

    VmmManager& v = Singleton<VmmManager>::instance();

    BaseSegment::init();
    StackSegment::init();
    for (size_t i = SegmentManager::MMIO_FIRST_SEGMENT_ID;
                i < SegmentManager::MMIO_LAST_SEGMENT_ID; ++i)
    {
        new DeviceSegment(i); // Self-registers with SegmentManager.
    }
    SegmentManager::initSLB();

    v.initPTEs();

#ifdef CONFIG_P9_PAGE_TABLE
    v.initPartitionTable();
#else
    v.initSDR1();
#endif
};

void VmmManager::init_slb()
{
    VmmManager& v = Singleton<VmmManager>::instance();
    SegmentManager::initSLB();

#ifdef CONFIG_P9_PAGE_TABLE
    v.initPartitionTable();
#else
    v.initSDR1();
#endif
}

bool VmmManager::pteMiss(task_t* t, uint64_t effAddr, bool store)
{
    return Singleton<VmmManager>::instance()._pteMiss(t, effAddr, store);
}

uint64_t VmmManager::findPhysicalAddress(uint64_t i_vaddr)
{
    return Singleton<VmmManager>::instance()._findPhysicalAddress(i_vaddr);
}

void VmmManager::castOutPages(VmmManager::castout_t i_ct)
{
    Singleton<VmmManager>::instance()._castOutPages(i_ct);
}

void VmmManager::flushPageTable( void )
{
    Singleton<VmmManager>::instance()._flushPageTable();
}

void* VmmManager::devMap(void* ra, uint64_t i_devDataSize, bool i_nonCI,
    bool i_guarded)
{
    return Singleton<VmmManager>::instance()._devMap(ra, i_devDataSize,
                                                     i_nonCI, i_guarded);
}

int VmmManager::devUnmap(void* ea)
{
    return Singleton<VmmManager>::instance()._devUnmap(ea);
}

void VmmManager::initPTEs()
{
    // Initialize and invalidate the page table
    PageTableManager::init();

    // There is no need to add PTE entries because the PTE-miss page fault
    // handler will add as-needed.
}

void VmmManager::initPartitionTable()
{
    // Use SLB, not In-Memory Segment Tables (Process Table)
    // Set LPCR[41] (UPRT) = 0
    setLPCR(getLPCR() & (~0x0000000000400000));

    // Set the first partition table entry (PATE)
    // HTABORG, HTABSIZE = 0 (11 bits, 256k table)
    g_patb[0] = HTABORG();
    g_patb[1] = 0x0;

    // Init the PTCR reg
    // PATB, PATS = 0 (4k table)
    // PATB, PATS = 4 (64k table)
    setPTCR( reinterpret_cast<uint64_t>(g_patb) + getHRMOR() + 4 );
}

void VmmManager::initSDR1()
{
    // HTABORG, HTABSIZE = 0 (11 bits, 256k table)
    register uint64_t sdr1 = HTABORG();
    asm volatile("mtsdr1 %0" :: "r"(sdr1) : "memory");
}

bool VmmManager::_pteMiss(task_t* t, uint64_t effAddr, bool store)
{
    lock.lock();

    bool rc = SegmentManager::handlePageFault(t, effAddr, store);

    lock.unlock();

    return rc;
}

int VmmManager::mmAllocBlock(MessageQueue* i_mq,void* i_va,uint64_t i_size)
{
    return Singleton<VmmManager>::instance()._mmAllocBlock(i_mq,i_va,i_size);
}

int VmmManager::_mmAllocBlock(MessageQueue* i_mq,void* i_va,uint64_t i_size)
{
    lock.lock();
    int rc = BaseSegment::mmAllocBlock(i_mq,i_va,i_size);
    lock.unlock();
    return rc;
}

Spinlock* VmmManager::getLock()
{
    return &Singleton<VmmManager>::instance().lock;
}

uint64_t VmmManager::_findPhysicalAddress(uint64_t i_vaddr)
{
    uint64_t paddr = 0;

    lock.lock();

    paddr = SegmentManager::findPhysicalAddress(i_vaddr);

    lock.unlock();

    return paddr;
}

int VmmManager::mmRemovePages(VmmManager::PAGE_REMOVAL_OPS i_op, void* i_vaddr,
                              uint64_t i_size, task_t* i_task)
{
    return Singleton<VmmManager>::instance()._mmRemovePages(i_op,i_vaddr,
                                                            i_size,i_task);
}

int VmmManager::_mmRemovePages(VmmManager::PAGE_REMOVAL_OPS i_op,void* i_vaddr,
                               uint64_t i_size,task_t* i_task)
{
    lock.lock();
    int rc = BaseSegment::mmRemovePages(i_op,i_vaddr,i_size,i_task);
    lock.unlock();
    return rc;
}

int VmmManager::mmSetPermission(void* i_va, uint64_t i_size, uint64_t i_access_type)
{
    return Singleton<VmmManager>::instance()._mmSetPermission(i_va, i_size, i_access_type);
}


int VmmManager::_mmSetPermission(void* i_va, uint64_t i_size, uint64_t i_access_type)
{
    int rc = 1;

    lock.lock();

    rc = BaseSegment::mmSetPermission(i_va, i_size, i_access_type);

    lock.unlock();

    return rc;
}

void VmmManager::_castOutPages(VmmManager::castout_t i_ct)
{
    lock.lock();

    SegmentManager::castOutPages((uint64_t)i_ct);

    lock.unlock();
}

void VmmManager::_flushPageTable( void )
{
    lock.lock();

    PageTableManager::flush();

    lock.unlock();
}


int VmmManager::mmExtend(void)
{
    return Singleton<VmmManager>::instance()._mmExtend();
}

int VmmManager::_mmExtend(void)
{
    lock.lock();
    int rc = BaseSegment::mmExtend();
    lock.unlock();
    return rc;
}

void* VmmManager::_devMap(void* ra, uint64_t i_devDataSize, bool i_nonCI,
    bool i_guarded)
{
    void* ea = NULL;

    lock.lock();
    ea = SegmentManager::devMap(ra, i_devDataSize, i_nonCI, i_guarded);
    lock.unlock();

    return ea;
}

int VmmManager::_devUnmap(void* ea)
{
    int rc = 0;

    lock.lock();
    rc = SegmentManager::devUnmap(ea);
    lock.unlock();

    return rc;
}

uint64_t VmmManager::HTABORG()
{
    return static_cast<uint32_t>(pageTableOffset()) + getHRMOR();
}

uint64_t VmmManager::findKernelAddress(uint64_t i_vaddr)
{
    //in hypervisor mode the HRMOR is automatically ORed onto
    // the address so we need to tell the hardware to ignore it
    uint64_t phys = VmmManager::findPhysicalAddress(i_vaddr);
    if( static_cast<uint64_t>(-EFAULT) != phys )
    {
        phys |= FORCE_PHYS_ADDR;
    }
    return phys;
}

int VmmManager::mmLinearMap(void *i_paddr, uint64_t i_size)
{
    return Singleton<VmmManager>::instance()._mmLinearMap(i_paddr, i_size);
}

int VmmManager::_mmLinearMap(void *i_paddr, uint64_t i_size)
{
    lock.lock();
    int rc = BaseSegment::mmLinearMap(i_paddr, i_size);
    lock.unlock();
    return rc;
}

uint64_t VmmManager::pageTableOffset()
{
    return Singleton<VmmManager>::instance()._pageTableOffset();
}

uint64_t VmmManager::_pageTableOffset() const
{
    return ALIGN_X(_endPreservedOffset(), PT_ALIGNMENT);
}

uint64_t VmmManager::BlToHbPreserveDataOffset()
{
    return Singleton<VmmManager>::instance()._BlToHbPreserveDataOffset();
}

uint64_t VmmManager::_BlToHbPreserveDataOffset() const
{
    return  ALIGN_8(MAX_HBB_SIZE + g_BlToHbDataManager.getBlToHbDataSize());
}

uint64_t VmmManager::endPreservedOffset()
{
    return Singleton<VmmManager>::instance()._endPreservedOffset();
}

uint64_t VmmManager::_endPreservedOffset() const
{
    return ALIGN_PAGE(_BlToHbPreserveDataOffset() +
                      g_BlToHbDataManager.getPreservedSize());
}
OpenPOWER on IntegriCloud