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
|
||||||
@@ -275,29 +275,33 @@ init_page_directory()
|
|||||||
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();
|
||||||
@@ -314,6 +318,7 @@ init_page_directory()
|
|||||||
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)
|
||||||
@@ -322,7 +327,8 @@ add_page_table(addr_t 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)) {
|
/*
|
||||||
|
if (pageTable > (uint32 *)(8 * 1024 * 1024)) {
|
||||||
panic("tried to add page table beyond the indentity mapped 8 MB "
|
panic("tried to add page table beyond the indentity mapped 8 MB "
|
||||||
"region\n");
|
"region\n");
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
= (uint32 *)(sPageDirectory[VADDR_TO_PDENT(virtualAddress)]
|
||||||
& ARM_PDE_ADDRESS_MASK);
|
& ARM_PDE_ADDRESS_MASK);
|
||||||
TRACE(("map_page: pageTable 0x%lx\n", (sPageDirectory[VADDR_TO_PDENT(virtualAddress)]
|
|
||||||
& ARM_PDE_ADDRESS_MASK) ));
|
TRACE(("map_page: pageTable 0x%lx\n",
|
||||||
if(pageTable == NULL) {
|
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;
|
||||||
@@ -418,8 +429,10 @@ unmap_page(addr_t 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
|
||||||
|
= (uint32 *)(sPageDirectory[VADDR_TO_PDENT(virtualAddress)]
|
||||||
& ARM_PDE_ADDRESS_MASK);
|
& ARM_PDE_ADDRESS_MASK);
|
||||||
|
|
||||||
pageTable[VADDR_TO_PTENT(virtualAddress)] = 0;
|
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