Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/subr_physmem.c
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
#if defined(__arm__) | #if defined(__arm__) | ||||
#define MAX_PHYS_ADDR 0xFFFFFFFFull | #define MAX_PHYS_ADDR 0xFFFFFFFFull | ||||
#elif defined(__aarch64__) || defined(__riscv) | #elif defined(__aarch64__) || defined(__riscv) | ||||
#define MAX_PHYS_ADDR 0xFFFFFFFFFFFFFFFFull | #define MAX_PHYS_ADDR 0xFFFFFFFFFFFFFFFFull | ||||
#endif | #endif | ||||
#if defined(__aarch64__) | |||||
/* | |||||
* The arm64 DMAP code assumes L2 block aligned & sized memory. Becauese of | |||||
* this round memory regions so the start and end are aligned to an L2 block | |||||
* boundary. | |||||
*/ | |||||
#define round_mem(x) roundup2((x), L2_SIZE) | |||||
#define truncate_mem(x) rounddown2((x), L2_SIZE) | |||||
#else | |||||
#define round_mem(x) round_page(x) | |||||
#define truncate_mem(x) truncate_page(x) | |||||
#endif | |||||
struct region { | struct region { | ||||
vm_paddr_t addr; | vm_paddr_t addr; | ||||
vm_size_t size; | vm_size_t size; | ||||
uint32_t flags; | uint32_t flags; | ||||
}; | }; | ||||
static struct region hwregions[MAX_HWCNT]; | static struct region hwregions[MAX_HWCNT]; | ||||
static struct region exregions[MAX_EXCNT]; | static struct region exregions[MAX_EXCNT]; | ||||
▲ Show 20 Lines • Show All 267 Lines • ▼ Show 20 Lines | if (sz <= 1024 * 1024) | ||||
return; | return; | ||||
sz -= 1024 * 1024; | sz -= 1024 * 1024; | ||||
} | } | ||||
/* | /* | ||||
* Round the starting address up to a page boundary, and truncate the | * Round the starting address up to a page boundary, and truncate the | ||||
* ending page down to a page boundary. | * ending page down to a page boundary. | ||||
*/ | */ | ||||
adj = round_page(pa) - pa; | adj = round_mem(pa) - pa; | ||||
pa = round_page(pa); | pa = round_mem(pa); | ||||
sz = trunc_page(sz - adj); | sz = trunc_mem(sz - adj); | ||||
if (sz > 0 && hwcnt < nitems(hwregions)) | if (sz > 0 && hwcnt < nitems(hwregions)) | ||||
hwcnt = insert_region(hwregions, hwcnt, pa, sz, 0); | hwcnt = insert_region(hwregions, hwcnt, pa, sz, 0); | ||||
} | } | ||||
/* | /* | ||||
* Add an exclusion region. | * Add an exclusion region. | ||||
*/ | */ | ||||
void | void | ||||
physmem_exclude_region(vm_paddr_t pa, vm_size_t sz, uint32_t exflags) | physmem_exclude_region(vm_paddr_t pa, vm_size_t sz, uint32_t exflags) | ||||
{ | { | ||||
vm_offset_t adj; | vm_offset_t adj; | ||||
/* | /* | ||||
* Truncate the starting address down to a page boundary, and round the | * Truncate the starting address down to a page boundary, and round the | ||||
* ending page up to a page boundary. | * ending page up to a page boundary. | ||||
*/ | */ | ||||
adj = pa - trunc_page(pa); | adj = pa - trunc_mem(pa); | ||||
pa = trunc_page(pa); | pa = trunc_mem(pa); | ||||
sz = round_page(sz + adj); | sz = round_mem(sz + adj); | ||||
if (excnt >= nitems(exregions)) | if (excnt >= nitems(exregions)) | ||||
panic("failed to exclude region %#jx-%#jx", (uintmax_t)pa, | panic("failed to exclude region %#jx-%#jx", (uintmax_t)pa, | ||||
(uintmax_t)(pa + sz)); | (uintmax_t)(pa + sz)); | ||||
excnt = insert_region(exregions, excnt, pa, sz, exflags); | excnt = insert_region(exregions, excnt, pa, sz, exflags); | ||||
} | } | ||||
size_t | size_t | ||||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |