standalloc.c revision ae115bc77f6fcde83175c75b4206dc2e50747966
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/bootconf.h>
#include "multiboot.h"
#include "util.h"
#include "standalloc.h"
#include "debug.h"
/* memory lists */
extern multiboot_info_t *mbi;
extern multiboot_header_t *mbh;
extern int verbosemode;
/* scratch memory */
static void
{
while (listp) {
dprintf("(0x%x%x, 0x%x%x)",
}
dprintf("\n");
}
static struct memlist *
{
}
static void
{
}
/* insert in the order of addresses */
static void
{
/* find the location in list */
}
if (prev == 0) {
entry = memlist_alloc();
return;
}
/* coalesce entries if possible */
} else {
entry = memlist_alloc();
}
}
/* delet memory chunks, assuming list sorted by address */
static int
{
/* find the location in list */
}
dprintf("memlist_remove: addr 0x%x%x, size 0x%x%x"
" not contained in list\n",
return (-1);
}
entry = memlist_alloc();
}
/* addr == next->address */
} else {
/* the entire chunk is deleted */
if (prev == 0) {
} else {
}
}
return (0);
}
/*
* find and claim a memory chunk of given size, bypassing
* scratch memory + room below 8MB
*/
static uint64_t
{
/* find the chunk with sufficient size */
while (next &&
}
return (0);
if (delta)
return (paddr);
}
static void
{
printf("Installed physical memory:\n");
printf("BIOS reserved physical memory:\n");
printf("Booter occupied memory (including modules):\n");
printf("Ramdisk memory:\n");
printf("Available physical memory:\n");
printf("Available virtual memory:\n");
}
void
setup_memlists(void)
{
int i;
/*
* initialize scratch memory so we can call bkmem_alloc
* to get memory for keeping track of memory lists
*/
reset_alloc();
/*
* initialize RAM list (pinstalledp) and available pci memory
* PCI memory excludes memory below 1M (realmode)
*/
case 1: /* RAM */
/*FALLTHROUGH*/
default: /* Take out of available pci memory space */
break;
}
}
/*
* initialize memory occupied by the booter
* make the boundary page aligned to simplify
* MMU stuff
*/
/* where the modules are in memory */
/* round up to page boundaries */
/* assume first one is ramdisk */
if (ramdisk_end == 0) {
if (verbosemode) {
printf("ramdisk is at 0x%llx-0x%llx\n",
}
} else {
}
}
/* delete booter memory from pfreelistp */
while (entry) {
}
/* delete ramdisk memory */
while (entry) {
}
/*
* initialize free virtual memory list
* start withe the entire range
* delete booter memory
*/
while (entry) {
}
}
/* resource allocate routines */
void
reset_alloc(void)
{
if (verbosemode)
printf("initialize scratch memory \n");
/* reclaim existing scratch memory */
if (scratchmem_end > scratchmem_start) {
}
/* start allocating at 1MB */
}
/*
* allocate memory with an identical physical and virtual address
*/
{
/* sanity checks */
if (bytes == 0)
return ((caddr_t)0);
if (virthint == 0) {
} else if (memlist_remove(
}
if (addr == 0) {
printf("idmap_mem: failed to find phys 0x%lx bytes at 0x%x\n",
return (0);
}
/*
* For any piece of low (< kernelbase) physical memory, we
* either map it 1:1 or map it above kernelbase. Hence, the
* corresponding virtual memory is always available by design.
*/
if (memlist_remove(&vfreelistp,
printf("idmap_mem: failed to find virtual "
return (0);
}
printf("idmap_mem: failed to 1:1 map 0x%lx bytes at 0x%p\n",
return (0);
}
return (addr);
}
/*
* allocate memory with a physical mapping
*/
/*ARGSUSED*/
{
/* sanity checks */
if (bytes == 0)
return ((caddr_t)0);
}
/*ARGSUSED*/
{
/* sanity checks */
if (bytes == 0)
return ((caddr_t)0);
if (scratchmem_end == 0)
prom_panic("scratch memory uninitialized\n");
switch (type) {
case RES_BOOTSCRATCH:
/* scratch memory */
scratchmem_end += bytes;
if (scratchmem_end > magic_phys)
prom_panic("scratch memory overflow!");
return (vaddr);
/*NOTREACHED*/
case RES_CHILDVIRT:
/* program memory */
if (delta)
goto fail; /* not page aligned */
if (memlist_remove(&vfreelistp,
goto fail; /* virtual memory not available */
if (align == 0)
align = 1;
if (paddr == -1)
goto fail; /* out of physical memory */
goto fail;
return (vaddr);
/*NOTREACHED*/
}
fail:
dprintf("resalloc of 0x%lx bytes at 0x%p failed",
return (0);
}
void
{
/* scratch memory is freed one one shot */
return;
dprintf("resfree: 0x%p 0x%lx not implemented\n",
}
int
{
if (n) {
vaddr -= n;
size += n;
}
return (-1);
return (0);
}