u-boot mmu: Style cleanup, no functional change
This commit is contained in:
@@ -24,7 +24,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
//#define TRACE_MMU
|
#define TRACE_MMU
|
||||||
#ifdef TRACE_MMU
|
#ifdef TRACE_MMU
|
||||||
# define TRACE(x) dprintf x
|
# define TRACE(x) dprintf x
|
||||||
#else
|
#else
|
||||||
@@ -233,8 +233,8 @@ mmu_write_DACR(uint32 value)
|
|||||||
static uint32 *
|
static uint32 *
|
||||||
get_next_page_table(uint32 type)
|
get_next_page_table(uint32 type)
|
||||||
{
|
{
|
||||||
TRACE(("get_next_page_table, sNextPageTableAddress %p, kPageTableRegionEnd "
|
TRACE(("get_next_page_table, sNextPageTableAddress %p, kPageTableRegionEnd "
|
||||||
"%p, type 0x%lx\n", sNextPageTableAddress, kPageTableRegionEnd, type));
|
"%p, type 0x%lx\n", sNextPageTableAddress, kPageTableRegionEnd, type));
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
switch(type){
|
switch(type){
|
||||||
case MMU_L1_TYPE_COARSEPAGETABLE:
|
case MMU_L1_TYPE_COARSEPAGETABLE:
|
||||||
@@ -245,21 +245,21 @@ get_next_page_table(uint32 type)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr_t address = sNextPageTableAddress;
|
addr_t address = sNextPageTableAddress;
|
||||||
if (address >= kPageTableRegionEnd) {
|
if (address >= kPageTableRegionEnd) {
|
||||||
TRACE(("outside of pagetableregion!\n"));
|
TRACE(("outside of pagetableregion!\n"));
|
||||||
return (uint32 *)get_next_physical_address_alligned(size, 0xffffffc0);
|
return (uint32 *)get_next_physical_address_alligned(size, 0xffffffc0);
|
||||||
}
|
}
|
||||||
|
|
||||||
sNextPageTableAddress += size;
|
sNextPageTableAddress += size;
|
||||||
return (uint32 *)address;
|
return (uint32 *)address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
init_page_directory()
|
init_page_directory()
|
||||||
{
|
{
|
||||||
TRACE(("init_page_directory\n"));
|
TRACE(("init_page_directory\n"));
|
||||||
uint32 smalltype;
|
uint32 smalltype;
|
||||||
|
|
||||||
// see if subpages disabled
|
// see if subpages disabled
|
||||||
@@ -268,71 +268,77 @@ init_page_directory()
|
|||||||
else
|
else
|
||||||
smalltype = MMU_L2_TYPE_SMALLEXT;
|
smalltype = MMU_L2_TYPE_SMALLEXT;
|
||||||
|
|
||||||
gKernelArgs.arch_args.phys_pgdir = (uint32)sPageDirectory;
|
gKernelArgs.arch_args.phys_pgdir = (uint32)sPageDirectory;
|
||||||
|
|
||||||
// clear out the pgdir
|
// clear out the pgdir
|
||||||
for (uint32 i = 0; i < 4096; i++)
|
for (uint32 i = 0; i < 4096; i++)
|
||||||
sPageDirectory[i] = 0;
|
sPageDirectory[i] = 0;
|
||||||
|
|
||||||
uint32 *pageTable = NULL;
|
uint32 *pageTable = NULL;
|
||||||
for (uint32 i=0; i < ARRAY_SIZE(LOADER_MEMORYMAP);i++){
|
for (uint32 i = 0; i < ARRAY_SIZE(LOADER_MEMORYMAP);i++) {
|
||||||
|
|
||||||
pageTable = get_next_page_table(MMU_L1_TYPE_COARSEPAGETABLE);
|
pageTable = get_next_page_table(MMU_L1_TYPE_COARSEPAGETABLE);
|
||||||
TRACE(("BLOCK: %s START: %lx END %lx\n",LOADER_MEMORYMAP[i].name,LOADER_MEMORYMAP[i].start,LOADER_MEMORYMAP[i].end));
|
TRACE(("BLOCK: %s START: %lx END %lx\n", LOADER_MEMORYMAP[i].name,
|
||||||
|
LOADER_MEMORYMAP[i].start, LOADER_MEMORYMAP[i].end));
|
||||||
addr_t pos = LOADER_MEMORYMAP[i].start;
|
addr_t pos = LOADER_MEMORYMAP[i].start;
|
||||||
|
|
||||||
int c = 0;
|
int c = 0;
|
||||||
while(pos < LOADER_MEMORYMAP[i].end) {
|
while (pos < LOADER_MEMORYMAP[i].end) {
|
||||||
pageTable[c] = pos | LOADER_MEMORYMAP[i].flags | smalltype;
|
pageTable[c] = pos | LOADER_MEMORYMAP[i].flags | smalltype;
|
||||||
|
|
||||||
c++;
|
c++;
|
||||||
if (c > 255) { //we filled a pagetable => we need a new one
|
if (c > 255) { // we filled a pagetable => we need a new one
|
||||||
//there is 1MB per pagetable so:
|
// there is 1MB per pagetable so:
|
||||||
sPageDirectory[VADDR_TO_PDENT(pos)] = (uint32)pageTable | MMU_L1_TYPE_COARSEPAGETABLE;
|
sPageDirectory[VADDR_TO_PDENT(pos)]
|
||||||
|
= (uint32)pageTable | MMU_L1_TYPE_COARSEPAGETABLE;
|
||||||
pageTable = get_next_page_table(MMU_L1_TYPE_COARSEPAGETABLE);
|
pageTable = get_next_page_table(MMU_L1_TYPE_COARSEPAGETABLE);
|
||||||
c=0;
|
c = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos += B_PAGE_SIZE;
|
pos += B_PAGE_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c > 0)
|
if (c > 0) {
|
||||||
sPageDirectory[VADDR_TO_PDENT(pos)] = (uint32)pageTable | MMU_L1_TYPE_COARSEPAGETABLE;
|
sPageDirectory[VADDR_TO_PDENT(pos)]
|
||||||
|
= (uint32)pageTable | MMU_L1_TYPE_COARSEPAGETABLE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mmu_flush_TLB();
|
mmu_flush_TLB();
|
||||||
|
|
||||||
/* set up the translation table base */
|
/* set up the translation table base */
|
||||||
mmu_set_TTBR((uint32)sPageDirectory);
|
mmu_set_TTBR((uint32)sPageDirectory);
|
||||||
|
|
||||||
mmu_flush_TLB();
|
mmu_flush_TLB();
|
||||||
|
|
||||||
/* set up the domain access register */
|
/* set up the domain access register */
|
||||||
mmu_write_DACR(0xFFFFFFFF);
|
mmu_write_DACR(0xFFFFFFFF);
|
||||||
|
|
||||||
/* turn on the mmu */
|
/* turn on the mmu */
|
||||||
mmu_write_C1(mmu_read_C1() | 0x1);
|
mmu_write_C1(mmu_read_C1() | 0x1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! Adds a new page table for the specified base address */
|
/*! Adds a new page table for the specified base address */
|
||||||
static void
|
static void
|
||||||
add_page_table(addr_t base)
|
add_page_table(addr_t base)
|
||||||
{
|
{
|
||||||
TRACE(("add_page_table(base = %p)\n", (void *)base));
|
TRACE(("add_page_table(base = %p)\n", (void *)base));
|
||||||
|
|
||||||
// Get new page table and clear it out
|
// Get new page table and clear it out
|
||||||
uint32 *pageTable = get_next_page_table(MMU_L1_TYPE_COARSEPAGETABLE);
|
uint32 *pageTable = get_next_page_table(MMU_L1_TYPE_COARSEPAGETABLE);
|
||||||
/* if (pageTable > (uint32 *)(8 * 1024 * 1024)) {
|
/*
|
||||||
panic("tried to add page table beyond the indentity mapped 8 MB "
|
if (pageTable > (uint32 *)(8 * 1024 * 1024)) {
|
||||||
"region\n");
|
panic("tried to add page table beyond the indentity mapped 8 MB "
|
||||||
}
|
"region\n");
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
for (int32 i = 0; i < 256; i++)
|
for (int32 i = 0; i < 256; i++)
|
||||||
pageTable[i] = 0;
|
pageTable[i] = 0;
|
||||||
|
|
||||||
// put the new page table into the page directory
|
// put the new page table into the page directory
|
||||||
sPageDirectory[VADDR_TO_PDENT(base)]
|
sPageDirectory[VADDR_TO_PDENT(base)]
|
||||||
= (uint32)pageTable | MMU_L1_TYPE_COARSEPAGETABLE;
|
= (uint32)pageTable | MMU_L1_TYPE_COARSEPAGETABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -344,7 +350,8 @@ add_page_table(addr_t base)
|
|||||||
static void
|
static void
|
||||||
map_page(addr_t virtualAddress, addr_t physicalAddress, uint32 flags)
|
map_page(addr_t virtualAddress, addr_t physicalAddress, uint32 flags)
|
||||||
{
|
{
|
||||||
TRACE(("map_page: vaddr 0x%lx, paddr 0x%lx\n", virtualAddress, physicalAddress));
|
TRACE(("map_page: vaddr 0x%lx, paddr 0x%lx\n", virtualAddress,
|
||||||
|
physicalAddress));
|
||||||
|
|
||||||
if (virtualAddress < KERNEL_BASE) {
|
if (virtualAddress < KERNEL_BASE) {
|
||||||
panic("map_page: asked to map invalid page %p!\n",
|
panic("map_page: asked to map invalid page %p!\n",
|
||||||
@@ -365,11 +372,14 @@ map_page(addr_t virtualAddress, addr_t physicalAddress, uint32 flags)
|
|||||||
physicalAddress &= ~(B_PAGE_SIZE - 1);
|
physicalAddress &= ~(B_PAGE_SIZE - 1);
|
||||||
|
|
||||||
// map the page to the correct page table
|
// map the page to the correct page table
|
||||||
uint32 *pageTable = (uint32 *)(sPageDirectory[VADDR_TO_PDENT(virtualAddress)]
|
uint32 *pageTable
|
||||||
& ARM_PDE_ADDRESS_MASK);
|
= (uint32 *)(sPageDirectory[VADDR_TO_PDENT(virtualAddress)]
|
||||||
TRACE(("map_page: pageTable 0x%lx\n", (sPageDirectory[VADDR_TO_PDENT(virtualAddress)]
|
& ARM_PDE_ADDRESS_MASK);
|
||||||
& ARM_PDE_ADDRESS_MASK) ));
|
|
||||||
if(pageTable == NULL) {
|
TRACE(("map_page: pageTable 0x%lx\n",
|
||||||
|
sPageDirectory[VADDR_TO_PDENT(virtualAddress)] & ARM_PDE_ADDRESS_MASK));
|
||||||
|
|
||||||
|
if (pageTable == NULL) {
|
||||||
add_page_table(virtualAddress);
|
add_page_table(virtualAddress);
|
||||||
pageTable = (uint32 *)(sPageDirectory[VADDR_TO_PDENT(virtualAddress)]
|
pageTable = (uint32 *)(sPageDirectory[VADDR_TO_PDENT(virtualAddress)]
|
||||||
& ARM_PDE_ADDRESS_MASK);
|
& ARM_PDE_ADDRESS_MASK);
|
||||||
@@ -400,7 +410,8 @@ mmu_map_physical_memory(addr_t physicalAddress, size_t size, uint32 flags)
|
|||||||
physicalAddress -= pageOffset;
|
physicalAddress -= pageOffset;
|
||||||
|
|
||||||
for (addr_t offset = 0; offset < size; offset += B_PAGE_SIZE) {
|
for (addr_t offset = 0; offset < size; offset += B_PAGE_SIZE) {
|
||||||
map_page(get_next_virtual_page(B_PAGE_SIZE), physicalAddress + offset, flags);
|
map_page(get_next_virtual_page(B_PAGE_SIZE), physicalAddress + offset,
|
||||||
|
flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
return address + pageOffset;
|
return address + pageOffset;
|
||||||
@@ -410,17 +421,19 @@ mmu_map_physical_memory(addr_t physicalAddress, size_t size, uint32 flags)
|
|||||||
static void
|
static void
|
||||||
unmap_page(addr_t virtualAddress)
|
unmap_page(addr_t virtualAddress)
|
||||||
{
|
{
|
||||||
TRACE(("unmap_page(virtualAddress = %p)\n", (void *)virtualAddress));
|
TRACE(("unmap_page(virtualAddress = %p)\n", (void *)virtualAddress));
|
||||||
|
|
||||||
if (virtualAddress < KERNEL_BASE) {
|
if (virtualAddress < KERNEL_BASE) {
|
||||||
panic("unmap_page: asked to unmap invalid page %p!\n",
|
panic("unmap_page: asked to unmap invalid page %p!\n",
|
||||||
(void *)virtualAddress);
|
(void *)virtualAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmap the page from the correct page table
|
// unmap the page from the correct page table
|
||||||
uint32 *pageTable = (uint32 *)(sPageDirectory[VADDR_TO_PDENT(virtualAddress)]
|
uint32 *pageTable
|
||||||
& ARM_PDE_ADDRESS_MASK);
|
= (uint32 *)(sPageDirectory[VADDR_TO_PDENT(virtualAddress)]
|
||||||
pageTable[VADDR_TO_PTENT(virtualAddress)] = 0;
|
& ARM_PDE_ADDRESS_MASK);
|
||||||
|
|
||||||
|
pageTable[VADDR_TO_PTENT(virtualAddress)] = 0;
|
||||||
|
|
||||||
mmu_flush_TLB();
|
mmu_flush_TLB();
|
||||||
}
|
}
|
||||||
@@ -445,14 +458,16 @@ mmu_allocate(void *virtualAddress, size_t size)
|
|||||||
|
|
||||||
// is the address within the valid range?
|
// is the address within the valid range?
|
||||||
if (address < KERNEL_BASE
|
if (address < KERNEL_BASE
|
||||||
|| address + size >= KERNEL_BASE + kMaxKernelSize){
|
|| address + size >= KERNEL_BASE + kMaxKernelSize) {
|
||||||
TRACE(("mmu_allocate in illegal range\n address: %lx"
|
TRACE(("mmu_allocate in illegal range\n address: %lx"
|
||||||
" KERNELBASE: %lx KERNEL_BASE + kMaxKernelSize: %lx address + size : %lx \n",
|
" KERNELBASE: %lx KERNEL_BASE + kMaxKernelSize: %lx"
|
||||||
(uint32)address , KERNEL_BASE, KERNEL_BASE + kMaxKernelSize,(uint32)(address + size)));
|
" address + size : %lx \n", (uint32)address, KERNEL_BASE,
|
||||||
|
KERNEL_BASE + kMaxKernelSize, (uint32)(address + size)));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (uint32 i = 0; i < size; i++) {
|
for (uint32 i = 0; i < size; i++) {
|
||||||
map_page(address, get_next_physical_page(B_PAGE_SIZE), kDefaultPageFlags);
|
map_page(address, get_next_physical_page(B_PAGE_SIZE),
|
||||||
|
kDefaultPageFlags);
|
||||||
address += B_PAGE_SIZE;
|
address += B_PAGE_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,8 +477,8 @@ mmu_allocate(void *virtualAddress, size_t size)
|
|||||||
void *address = (void *)sNextVirtualAddress;
|
void *address = (void *)sNextVirtualAddress;
|
||||||
|
|
||||||
for (uint32 i = 0; i < size; i++) {
|
for (uint32 i = 0; i < size; i++) {
|
||||||
map_page(get_next_virtual_page(B_PAGE_SIZE), get_next_physical_page(B_PAGE_SIZE),
|
map_page(get_next_virtual_page(B_PAGE_SIZE),
|
||||||
kDefaultPageFlags);
|
get_next_physical_page(B_PAGE_SIZE), kDefaultPageFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
return address;
|
return address;
|
||||||
@@ -529,17 +544,23 @@ mmu_init_for_kernel(void)
|
|||||||
|
|
||||||
dprintf("phys memory ranges:\n");
|
dprintf("phys memory ranges:\n");
|
||||||
for (i = 0; i < gKernelArgs.num_physical_memory_ranges; i++) {
|
for (i = 0; i < gKernelArgs.num_physical_memory_ranges; i++) {
|
||||||
dprintf(" base 0x%08lx, length 0x%08lx\n", gKernelArgs.physical_memory_range[i].start, gKernelArgs.physical_memory_range[i].size);
|
dprintf(" base 0x%08lx, length 0x%08lx\n",
|
||||||
|
gKernelArgs.physical_memory_range[i].start,
|
||||||
|
gKernelArgs.physical_memory_range[i].size);
|
||||||
}
|
}
|
||||||
|
|
||||||
dprintf("allocated phys memory ranges:\n");
|
dprintf("allocated phys memory ranges:\n");
|
||||||
for (i = 0; i < gKernelArgs.num_physical_allocated_ranges; i++) {
|
for (i = 0; i < gKernelArgs.num_physical_allocated_ranges; i++) {
|
||||||
dprintf(" base 0x%08lx, length 0x%08lx\n", gKernelArgs.physical_allocated_range[i].start, gKernelArgs.physical_allocated_range[i].size);
|
dprintf(" base 0x%08lx, length 0x%08lx\n",
|
||||||
|
gKernelArgs.physical_allocated_range[i].start,
|
||||||
|
gKernelArgs.physical_allocated_range[i].size);
|
||||||
}
|
}
|
||||||
|
|
||||||
dprintf("allocated virt memory ranges:\n");
|
dprintf("allocated virt memory ranges:\n");
|
||||||
for (i = 0; i < gKernelArgs.num_virtual_allocated_ranges; i++) {
|
for (i = 0; i < gKernelArgs.num_virtual_allocated_ranges; i++) {
|
||||||
dprintf(" base 0x%08lx, length 0x%08lx\n", gKernelArgs.virtual_allocated_range[i].start, gKernelArgs.virtual_allocated_range[i].size);
|
dprintf(" base 0x%08lx, length 0x%08lx\n",
|
||||||
|
gKernelArgs.virtual_allocated_range[i].start,
|
||||||
|
gKernelArgs.virtual_allocated_range[i].size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -551,17 +572,19 @@ mmu_init(void)
|
|||||||
{
|
{
|
||||||
TRACE(("mmu_init\n"));
|
TRACE(("mmu_init\n"));
|
||||||
|
|
||||||
mmu_write_C1(mmu_read_C1() & ~((1<<29)|(1<<28)|(1<<0)));// access flag disabled, TEX remap disabled, mmu disabled
|
mmu_write_C1(mmu_read_C1() & ~((1<<29)|(1<<28)|(1<<0)));
|
||||||
|
// access flag disabled, TEX remap disabled, mmu disabled
|
||||||
|
|
||||||
uint32 highestRAMAddress = SDRAM_BASE;
|
uint32 highestRAMAddress = SDRAM_BASE;
|
||||||
|
|
||||||
//calculate lowest RAM adress from MEMORYMAP
|
// calculate lowest RAM adress from MEMORYMAP
|
||||||
for(uint32 i = 0; i < ARRAY_SIZE(LOADER_MEMORYMAP); i++) {
|
for (uint32 i = 0; i < ARRAY_SIZE(LOADER_MEMORYMAP); i++) {
|
||||||
if (strcmp("RAM_free", LOADER_MEMORYMAP[i].name) == 0)
|
if (strcmp("RAM_free", LOADER_MEMORYMAP[i].name) == 0)
|
||||||
sNextPhysicalAddress = LOADER_MEMORYMAP[i].start;
|
sNextPhysicalAddress = LOADER_MEMORYMAP[i].start;
|
||||||
|
|
||||||
if (strcmp("RAM_pt", LOADER_MEMORYMAP[i].name) == 0) {
|
if (strcmp("RAM_pt", LOADER_MEMORYMAP[i].name) == 0) {
|
||||||
sNextPageTableAddress = LOADER_MEMORYMAP[i].start + MMU_L1_TABLE_SIZE;
|
sNextPageTableAddress = LOADER_MEMORYMAP[i].start
|
||||||
|
+ MMU_L1_TABLE_SIZE;
|
||||||
kPageTableRegionEnd = LOADER_MEMORYMAP[i].end;
|
kPageTableRegionEnd = LOADER_MEMORYMAP[i].end;
|
||||||
sPageDirectory = (uint32 *) LOADER_MEMORYMAP[i].start;
|
sPageDirectory = (uint32 *) LOADER_MEMORYMAP[i].start;
|
||||||
}
|
}
|
||||||
@@ -642,5 +665,3 @@ platform_init_heap(struct stage2_args *args, void **_base, void **_top)
|
|||||||
*_top = (void *)((int8 *)heap + args->heap_size);
|
*_top = (void *)((int8 *)heap + args->heap_size);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2005, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2004-2005, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef MMU_H
|
#ifndef MMU_H
|
||||||
#define MMU_H
|
#define MMU_H
|
||||||
@@ -10,7 +10,9 @@
|
|||||||
|
|
||||||
|
|
||||||
// For use with mmu_map_physical_memory()
|
// For use with mmu_map_physical_memory()
|
||||||
static const uint32 kDefaultPageFlags = 0x3; // present, R/W
|
static const uint32 kDefaultPageFlags = 0x3;
|
||||||
|
// present, R/W
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -18,7 +20,8 @@ extern "C" {
|
|||||||
|
|
||||||
extern void mmu_init(void);
|
extern void mmu_init(void);
|
||||||
extern void mmu_init_for_kernel(void);
|
extern void mmu_init_for_kernel(void);
|
||||||
extern addr_t mmu_map_physical_memory(addr_t physicalAddress, size_t size, uint32 flags);
|
extern addr_t mmu_map_physical_memory(addr_t physicalAddress,
|
||||||
|
size_t size, uint32 flags);
|
||||||
extern void *mmu_allocate(void *virtualAddress, size_t size);
|
extern void *mmu_allocate(void *virtualAddress, size_t size);
|
||||||
extern void mmu_free(void *virtualAddress, size_t size);
|
extern void mmu_free(void *virtualAddress, size_t size);
|
||||||
|
|
||||||
@@ -26,4 +29,5 @@ extern void mmu_free(void *virtualAddress, size_t size);
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* MMU_H */
|
#endif /* MMU_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user