Changeset View
Changeset View
Standalone View
Standalone View
stand/kboot/main.c
Show First 20 Lines • Show All 316 Lines • ▼ Show 20 Lines | |||||
#define SEGALIGN (1ul<<20) | #define SEGALIGN (1ul<<20) | ||||
static ssize_t | static ssize_t | ||||
get_phys_buffer(vm_offset_t dest, const size_t len, void **buf) | get_phys_buffer(vm_offset_t dest, const size_t len, void **buf) | ||||
{ | { | ||||
int i = 0; | int i = 0; | ||||
const size_t segsize = 64*1024*1024; | const size_t segsize = 64*1024*1024; | ||||
size_t sz; | |||||
if (nkexec_segments == HOST_KEXEC_SEGMENT_MAX) | if (nkexec_segments == HOST_KEXEC_SEGMENT_MAX) | ||||
panic("Tried to load too many kexec segments"); | panic("Tried to load too many kexec segments"); | ||||
for (i = 0; i < nkexec_segments; i++) { | for (i = 0; i < nkexec_segments; i++) { | ||||
if (dest >= (vm_offset_t)loaded_segments[i].mem && | if (dest >= (vm_offset_t)loaded_segments[i].mem && | ||||
dest < (vm_offset_t)loaded_segments[i].mem + | dest < (vm_offset_t)loaded_segments[i].mem + | ||||
loaded_segments[i].memsz) | loaded_segments[i].memsz) | ||||
goto out; | goto out; | ||||
} | } | ||||
loaded_segments[nkexec_segments].buf = host_getmem(segsize); | sz = segsize; | ||||
loaded_segments[nkexec_segments].bufsz = segsize; | if (nkexec_segments == 0) { | ||||
/* how much space does this segment have */ | |||||
sz = space_avail(dest); | |||||
/* Clip to 45% of available memory (need 2 copies) */ | |||||
sz = min(sz, rounddown2(mem_avail * 45 / 100, SEGALIGN)); | |||||
/* And only use 95% of what we can allocate */ | |||||
sz = min(sz, rounddown2( | |||||
(commit_limit - committed_as) * 95 / 100, SEGALIGN)); | |||||
printf("Allocating %zd MB for first segment\n", sz >> 20); | |||||
} | |||||
loaded_segments[nkexec_segments].buf = host_getmem(sz); | |||||
loaded_segments[nkexec_segments].bufsz = sz; | |||||
loaded_segments[nkexec_segments].mem = (void *)rounddown2(dest,SEGALIGN); | loaded_segments[nkexec_segments].mem = (void *)rounddown2(dest,SEGALIGN); | ||||
loaded_segments[nkexec_segments].memsz = segsize; | loaded_segments[nkexec_segments].memsz = sz; | ||||
i = nkexec_segments; | i = nkexec_segments; | ||||
nkexec_segments++; | nkexec_segments++; | ||||
out: | out: | ||||
*buf = loaded_segments[i].buf + (dest - | *buf = loaded_segments[i].buf + (dest - | ||||
(vm_offset_t)loaded_segments[i].mem); | (vm_offset_t)loaded_segments[i].mem); | ||||
return (min(len,loaded_segments[i].bufsz - (dest - | return (min(len,loaded_segments[i].bufsz - (dest - | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |