| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#include <assert.h> |
| 30 |
#include <stdlib.h> |
| 31 |
#include <stdint.h> |
| 32 |
#include <string.h> |
| 33 |
|
| 34 |
#include <arch/mmu.h> |
| 35 |
#include <arch/lib_helpers.h> |
| 36 |
#include <arch/cache.h> |
| 37 |
|
| 38 |
|
| 39 |
static unsigned int max_tables; |
| 40 |
|
| 41 |
static uint64_t *xlat_addr; |
| 42 |
|
| 43 |
static int free_idx; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
static uint8_t ttb_buffer[TTB_DEFAULT_SIZE] __aligned(GRANULE_SIZE) |
| 51 |
__section(".bss.ttb_buffer"); |
| 52 |
|
| 53 |
static const char * const tag_to_string[] = { |
| 54 |
[TYPE_NORMAL_MEM] = "normal", |
| 55 |
[TYPE_DEV_MEM] = "device", |
| 56 |
[TYPE_DMA_MEM] = "uncached", |
| 57 |
}; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
static struct mmu_ranges usedmem_ranges; |
| 70 |
|
| 71 |
static void __attribute__((noreturn)) mmu_error(void) |
| 72 |
{ |
| 73 |
halt(); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
static uint64_t get_block_attr(unsigned long tag) |
| 81 |
{ |
| 82 |
uint64_t attr; |
| 83 |
|
| 84 |
|
| 85 |
attr = BLOCK_NS; |
| 86 |
|
| 87 |
|
| 88 |
attr |= BLOCK_AP_RW; |
| 89 |
|
| 90 |
attr |= BLOCK_ACCESS; |
| 91 |
|
| 92 |
switch (tag) { |
| 93 |
|
| 94 |
case TYPE_NORMAL_MEM: |
| 95 |
attr |= BLOCK_SH_INNER_SHAREABLE; |
| 96 |
attr |= (BLOCK_INDEX_MEM_NORMAL << BLOCK_INDEX_SHIFT); |
| 97 |
break; |
| 98 |
case TYPE_DEV_MEM: |
| 99 |
attr |= BLOCK_INDEX_MEM_DEV_NGNRNE << BLOCK_INDEX_SHIFT; |
| 100 |
attr |= BLOCK_XN; |
| 101 |
break; |
| 102 |
case TYPE_DMA_MEM: |
| 103 |
attr |= BLOCK_INDEX_MEM_NORMAL_NC << BLOCK_INDEX_SHIFT; |
| 104 |
break; |
| 105 |
} |
| 106 |
|
| 107 |
return attr; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
static uint64_t table_desc_valid(uint64_t desc) |
| 114 |
{ |
| 115 |
return((desc & TABLE_DESC) == TABLE_DESC); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
static uint64_t *setup_new_table(uint64_t desc, size_t xlat_size) |
| 122 |
{ |
| 123 |
uint64_t *new, *entry; |
| 124 |
|
| 125 |
assert(free_idx < max_tables); |
| 126 |
|
| 127 |
new = (uint64_t*)((unsigned char *)xlat_addr + free_idx * GRANULE_SIZE); |
| 128 |
free_idx++; |
| 129 |
|
| 130 |
if (!desc) { |
| 131 |
memset(new, 0, GRANULE_SIZE); |
| 132 |
} else { |
| 133 |
|
| 134 |
if (xlat_size == L3_XLAT_SIZE) |
| 135 |
desc |= PAGE_DESC; |
| 136 |
|
| 137 |
for (entry = new; (u8 *)entry < (u8 *)new + GRANULE_SIZE; |
| 138 |
entry++, desc += xlat_size) |
| 139 |
*entry = desc; |
| 140 |
} |
| 141 |
|
| 142 |
return new; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
static uint64_t *get_table_from_desc(uint64_t desc) |
| 149 |
{ |
| 150 |
uint64_t *ptr = (uint64_t*)(desc & XLAT_TABLE_MASK); |
| 151 |
return ptr; |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
static uint64_t *get_next_level_table(uint64_t *ptr, size_t xlat_size) |
| 159 |
{ |
| 160 |
uint64_t desc = *ptr; |
| 161 |
|
| 162 |
if (!table_desc_valid(desc)) { |
| 163 |
uint64_t *new_table = setup_new_table(desc, xlat_size); |
| 164 |
desc = ((uint64_t)new_table) | TABLE_DESC; |
| 165 |
*ptr = desc; |
| 166 |
} |
| 167 |
return get_table_from_desc(desc); |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
static uint64_t init_xlat_table(uint64_t base_addr, |
| 178 |
uint64_t size, |
| 179 |
uint64_t tag) |
| 180 |
{ |
| 181 |
uint64_t l0_index = (base_addr & L0_ADDR_MASK) >> L0_ADDR_SHIFT; |
| 182 |
uint64_t l1_index = (base_addr & L1_ADDR_MASK) >> L1_ADDR_SHIFT; |
| 183 |
uint64_t l2_index = (base_addr & L2_ADDR_MASK) >> L2_ADDR_SHIFT; |
| 184 |
uint64_t l3_index = (base_addr & L3_ADDR_MASK) >> L3_ADDR_SHIFT; |
| 185 |
uint64_t *table = xlat_addr; |
| 186 |
uint64_t desc; |
| 187 |
uint64_t attr = get_block_attr(tag); |
| 188 |
|
| 189 |
|
| 190 |
table = get_next_level_table(&table[l0_index], L1_XLAT_SIZE); |
| 191 |
|
| 192 |
|
| 193 |
if ((size >= L1_XLAT_SIZE) && |
| 194 |
IS_ALIGNED(base_addr, (1UL << L1_ADDR_SHIFT))) { |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
desc = base_addr | BLOCK_DESC | attr; |
| 199 |
table[l1_index] = desc; |
| 200 |
|
| 201 |
return L1_XLAT_SIZE; |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
table = get_next_level_table(&table[l1_index], L2_XLAT_SIZE); |
| 206 |
|
| 207 |
|
| 208 |
if ((size >= L2_XLAT_SIZE) && |
| 209 |
IS_ALIGNED(base_addr, (1UL << L2_ADDR_SHIFT))) { |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
desc = base_addr | BLOCK_DESC | attr; |
| 214 |
table[l2_index] = desc; |
| 215 |
|
| 216 |
return L2_XLAT_SIZE; |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
table = get_next_level_table(&table[l2_index], L3_XLAT_SIZE); |
| 221 |
|
| 222 |
|
| 223 |
desc = base_addr | PAGE_DESC | attr; |
| 224 |
table[l3_index] = desc; |
| 225 |
return L3_XLAT_SIZE; |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
static void sanity_check(uint64_t addr, uint64_t size) |
| 232 |
{ |
| 233 |
assert(!(addr & GRANULE_SIZE_MASK) && |
| 234 |
!(size & GRANULE_SIZE_MASK) && |
| 235 |
(addr + size < (1UL << BITS_PER_VA)) && |
| 236 |
size >= GRANULE_SIZE); |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
void mmu_config_range(void *start, size_t size, uint64_t tag) |
| 246 |
{ |
| 247 |
uint64_t base_addr = (uintptr_t)start; |
| 248 |
uint64_t temp_size = size; |
| 249 |
|
| 250 |
assert(tag < ARRAY_SIZE(tag_to_string)); |
| 251 |
printf("Libpayload: ARM64 MMU: Mapping address range [%p:%p) as %s\n", |
| 252 |
start, start + size, tag_to_string[tag]); |
| 253 |
sanity_check(base_addr, temp_size); |
| 254 |
|
| 255 |
while (temp_size) |
| 256 |
temp_size -= init_xlat_table(base_addr + (size - temp_size), |
| 257 |
temp_size, tag); |
| 258 |
|
| 259 |
|
| 260 |
dsb(); |
| 261 |
tlbiall_el2(); |
| 262 |
dsb(); |
| 263 |
isb(); |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
uint64_t mmu_init(struct mmu_ranges *mmu_ranges) |
| 273 |
{ |
| 274 |
int i = 0; |
| 275 |
|
| 276 |
xlat_addr = (uint64_t *)&ttb_buffer; |
| 277 |
|
| 278 |
memset((void*)xlat_addr, 0, GRANULE_SIZE); |
| 279 |
max_tables = (TTB_DEFAULT_SIZE >> GRANULE_SIZE_SHIFT); |
| 280 |
free_idx = 1; |
| 281 |
|
| 282 |
printf("Libpayload ARM64: TTB_BUFFER: %p Max Tables: %d\n", |
| 283 |
(void*)xlat_addr, max_tables); |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
mmu_config_range(NULL, 0x100000000, TYPE_DEV_MEM); |
| 293 |
|
| 294 |
for (; i < mmu_ranges->used; i++) |
| 295 |
mmu_config_range((void *)mmu_ranges->entries[i].base, |
| 296 |
mmu_ranges->entries[i].size, |
| 297 |
mmu_ranges->entries[i].type); |
| 298 |
|
| 299 |
printf("Libpayload ARM64: MMU init done\n"); |
| 300 |
return 0; |
| 301 |
} |
| 302 |
|
| 303 |
static uint32_t is_mmu_enabled(void) |
| 304 |
{ |
| 305 |
uint32_t sctlr; |
| 306 |
|
| 307 |
sctlr = raw_read_sctlr_el2(); |
| 308 |
|
| 309 |
return (sctlr & SCTLR_M); |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
void mmu_enable(void) |
| 318 |
{ |
| 319 |
uint32_t sctlr; |
| 320 |
|
| 321 |
|
| 322 |
raw_write_mair_el2(MAIR_ATTRIBUTES); |
| 323 |
|
| 324 |
|
| 325 |
tlbiall_el2(); |
| 326 |
|
| 327 |
|
| 328 |
raw_write_tcr_el2(TCR_TOSZ | TCR_IRGN0_NM_WBWAC | TCR_ORGN0_NM_WBWAC | |
| 329 |
TCR_SH0_IS | TCR_TG0_4KB | TCR_PS_256TB | |
| 330 |
TCR_TBI_USED); |
| 331 |
|
| 332 |
|
| 333 |
raw_write_ttbr0_el2((uintptr_t)xlat_addr); |
| 334 |
|
| 335 |
|
| 336 |
isb(); |
| 337 |
|
| 338 |
|
| 339 |
sctlr = raw_read_sctlr_el2(); |
| 340 |
sctlr |= SCTLR_C | SCTLR_M | SCTLR_I; |
| 341 |
raw_write_sctlr_el2(sctlr); |
| 342 |
|
| 343 |
isb(); |
| 344 |
|
| 345 |
if(is_mmu_enabled()) |
| 346 |
printf("ARM64: MMU enable done\n"); |
| 347 |
else |
| 348 |
printf("ARM64: MMU enable failed\n"); |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
static struct mmu_memrange *mmu_add_memrange(struct mmu_ranges *r, |
| 356 |
uint64_t base, uint64_t size, |
| 357 |
uint64_t type) |
| 358 |
{ |
| 359 |
struct mmu_memrange *curr = NULL; |
| 360 |
int i = r->used; |
| 361 |
|
| 362 |
if (i < ARRAY_SIZE(r->entries)) { |
| 363 |
curr = &r->entries[i]; |
| 364 |
curr->base = base; |
| 365 |
curr->size = size; |
| 366 |
curr->type = type; |
| 367 |
|
| 368 |
r->used = i + 1; |
| 369 |
} |
| 370 |
|
| 371 |
return curr; |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
struct mmu_new_range_prop { |
| 376 |
|
| 377 |
uint64_t type; |
| 378 |
|
| 379 |
uint64_t size; |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
uint64_t lim_excl; |
| 385 |
|
| 386 |
uint64_t align; |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
int (*is_valid_range)(uint64_t, uint64_t); |
| 393 |
|
| 394 |
uint64_t src_type; |
| 395 |
}; |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
static int mmu_is_range_free(uint64_t r_base, |
| 412 |
uint64_t r_end) |
| 413 |
{ |
| 414 |
uint64_t payload_end = (uint64_t)&_end; |
| 415 |
uint64_t i; |
| 416 |
struct mmu_memrange *r = &usedmem_ranges.entries[0]; |
| 417 |
|
| 418 |
|
| 419 |
if ((r_base <= payload_end) || (r_end <= payload_end)) |
| 420 |
return 0; |
| 421 |
|
| 422 |
for (i = 0; i < usedmem_ranges.used; i++) { |
| 423 |
uint64_t start = r[i].base; |
| 424 |
uint64_t end = start + r[i].size; |
| 425 |
|
| 426 |
if ((start < r_end) && (end > r_base)) |
| 427 |
return 0; |
| 428 |
} |
| 429 |
|
| 430 |
return 1; |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
static struct mmu_memrange *mmu_get_new_range(struct mmu_ranges *mmu_ranges, |
| 441 |
struct mmu_new_range_prop *new) |
| 442 |
{ |
| 443 |
int i = 0; |
| 444 |
struct mmu_memrange *r = &mmu_ranges->entries[0]; |
| 445 |
|
| 446 |
if (new->size == 0) { |
| 447 |
printf("MMU Error: Invalid range size\n"); |
| 448 |
return NULL; |
| 449 |
} |
| 450 |
|
| 451 |
for (; i < mmu_ranges->used; i++) { |
| 452 |
|
| 453 |
if ((r[i].type != new->src_type) || |
| 454 |
(r[i].size < new->size) || |
| 455 |
(new->lim_excl && (r[i].base >= new->lim_excl))) |
| 456 |
continue; |
| 457 |
|
| 458 |
uint64_t base_addr; |
| 459 |
uint64_t range_end_addr = r[i].base + r[i].size; |
| 460 |
uint64_t end_addr = range_end_addr; |
| 461 |
|
| 462 |
|
| 463 |
if (new->lim_excl && (end_addr >= new->lim_excl)) |
| 464 |
end_addr = new->lim_excl; |
| 465 |
|
| 466 |
while (1) { |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
if (new->align) |
| 472 |
end_addr = ALIGN_DOWN(end_addr, new->align); |
| 473 |
|
| 474 |
base_addr = end_addr - new->size; |
| 475 |
|
| 476 |
if (base_addr < r[i].base) |
| 477 |
break; |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
if (mmu_is_range_free(base_addr, end_addr) && |
| 484 |
((new->is_valid_range == NULL) || |
| 485 |
new->is_valid_range(base_addr, end_addr))) |
| 486 |
break; |
| 487 |
|
| 488 |
|
| 489 |
end_addr -= 1; |
| 490 |
} |
| 491 |
|
| 492 |
if (base_addr < r[i].base) |
| 493 |
continue; |
| 494 |
|
| 495 |
if (end_addr != range_end_addr) { |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
r[i].size -= (range_end_addr - end_addr); |
| 501 |
if (mmu_add_memrange(mmu_ranges, end_addr, |
| 502 |
range_end_addr - end_addr, |
| 503 |
r[i].type) == NULL) |
| 504 |
mmu_error(); |
| 505 |
} |
| 506 |
|
| 507 |
if (r[i].size == new->size) { |
| 508 |
r[i].type = new->type; |
| 509 |
return &r[i]; |
| 510 |
} |
| 511 |
|
| 512 |
r[i].size -= new->size; |
| 513 |
|
| 514 |
r = mmu_add_memrange(mmu_ranges, base_addr, new->size, |
| 515 |
new->type); |
| 516 |
|
| 517 |
if (r == NULL) |
| 518 |
mmu_error(); |
| 519 |
|
| 520 |
return r; |
| 521 |
} |
| 522 |
|
| 523 |
|
| 524 |
printf("ARM64 ERROR: No region allocated\n"); |
| 525 |
return NULL; |
| 526 |
} |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
static struct mmu_memrange *mmu_alloc_range(struct mmu_ranges *mmu_ranges, |
| 534 |
struct mmu_new_range_prop *p) |
| 535 |
{ |
| 536 |
struct mmu_memrange *r = mmu_get_new_range(mmu_ranges, p); |
| 537 |
|
| 538 |
if (r == NULL) |
| 539 |
return NULL; |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
if (mmu_add_memrange(&usedmem_ranges, r->base, r->size, r->type) |
| 547 |
== NULL) |
| 548 |
mmu_error(); |
| 549 |
|
| 550 |
return r; |
| 551 |
} |
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
static struct mmu_memrange *mmu_add_dma_range(struct mmu_ranges *mmu_ranges) |
| 561 |
{ |
| 562 |
struct mmu_new_range_prop prop; |
| 563 |
|
| 564 |
prop.type = TYPE_DMA_MEM; |
| 565 |
|
| 566 |
assert((DMA_DEFAULT_SIZE % GRANULE_SIZE) == 0); |
| 567 |
prop.size = DMA_DEFAULT_SIZE; |
| 568 |
prop.lim_excl = (uint64_t)CONFIG_LP_DMA_LIM_EXCL * MiB; |
| 569 |
prop.align = GRANULE_SIZE; |
| 570 |
prop.is_valid_range = NULL; |
| 571 |
prop.src_type = TYPE_NORMAL_MEM; |
| 572 |
|
| 573 |
return mmu_alloc_range(mmu_ranges, &prop); |
| 574 |
} |
| 575 |
|
| 576 |
static struct mmu_memrange *_mmu_add_fb_range( |
| 577 |
uint32_t size, |
| 578 |
struct mmu_ranges *mmu_ranges) |
| 579 |
{ |
| 580 |
struct mmu_new_range_prop prop; |
| 581 |
|
| 582 |
prop.type = TYPE_DMA_MEM; |
| 583 |
|
| 584 |
prop.size = size; |
| 585 |
prop.lim_excl = MIN_64_BIT_ADDR; |
| 586 |
prop.align = MB_SIZE; |
| 587 |
prop.is_valid_range = NULL; |
| 588 |
prop.src_type = TYPE_NORMAL_MEM; |
| 589 |
|
| 590 |
return mmu_alloc_range(mmu_ranges, &prop); |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
static void mmu_extract_ranges(struct memrange *cb_ranges, |
| 601 |
uint64_t ncb, |
| 602 |
struct mmu_ranges *mmu_ranges) |
| 603 |
{ |
| 604 |
int i = 0; |
| 605 |
struct mmu_memrange *prev_range = NULL; |
| 606 |
|
| 607 |
|
| 608 |
for (; i < ncb; i++) { |
| 609 |
uint64_t base = cb_ranges[i].base; |
| 610 |
uint64_t size = cb_ranges[i].size; |
| 611 |
|
| 612 |
switch (cb_ranges[i].type) { |
| 613 |
case CB_MEM_TABLE: |
| 614 |
|
| 615 |
if (mmu_add_memrange(&usedmem_ranges, base, size, |
| 616 |
TYPE_NORMAL_MEM) == NULL) |
| 617 |
mmu_error(); |
| 618 |
__fallthrough; |
| 619 |
case CB_MEM_RAM: |
| 620 |
if (prev_range && |
| 621 |
prev_range->base + prev_range->size == base) { |
| 622 |
prev_range->size += size; |
| 623 |
} else { |
| 624 |
prev_range = mmu_add_memrange(mmu_ranges, |
| 625 |
base, size, |
| 626 |
TYPE_NORMAL_MEM); |
| 627 |
if (prev_range == NULL) |
| 628 |
mmu_error(); |
| 629 |
} |
| 630 |
break; |
| 631 |
default: |
| 632 |
break; |
| 633 |
} |
| 634 |
} |
| 635 |
} |
| 636 |
|
| 637 |
static void mmu_add_fb_range(struct mmu_ranges *mmu_ranges) |
| 638 |
{ |
| 639 |
struct mmu_memrange *fb_range; |
| 640 |
struct cb_framebuffer *framebuffer = &lib_sysinfo.framebuffer; |
| 641 |
uint32_t fb_size; |
| 642 |
|
| 643 |
|
| 644 |
fb_size = framebuffer->bytes_per_line * framebuffer->y_resolution; |
| 645 |
if (!fb_size) |
| 646 |
return; |
| 647 |
|
| 648 |
|
| 649 |
fb_size = ALIGN_UP(fb_size, GRANULE_SIZE); |
| 650 |
|
| 651 |
|
| 652 |
if (framebuffer->physical_address) { |
| 653 |
if (mmu_add_memrange(mmu_ranges, |
| 654 |
framebuffer->physical_address, |
| 655 |
fb_size, |
| 656 |
TYPE_DMA_MEM) == NULL) |
| 657 |
mmu_error(); |
| 658 |
return; |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
fb_range = _mmu_add_fb_range(fb_size, mmu_ranges); |
| 663 |
if (fb_range == NULL) |
| 664 |
mmu_error(); |
| 665 |
|
| 666 |
framebuffer->physical_address = fb_range->base; |
| 667 |
} |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
struct mmu_memrange *mmu_init_ranges_from_sysinfo(struct memrange *cb_ranges, |
| 675 |
uint64_t ncb, |
| 676 |
struct mmu_ranges *mmu_ranges) |
| 677 |
{ |
| 678 |
struct mmu_memrange *dma_range; |
| 679 |
|
| 680 |
|
| 681 |
mmu_ranges->used = 0; |
| 682 |
|
| 683 |
|
| 684 |
mmu_extract_ranges(cb_ranges, ncb, mmu_ranges); |
| 685 |
|
| 686 |
|
| 687 |
dma_range = mmu_add_dma_range(mmu_ranges); |
| 688 |
|
| 689 |
|
| 690 |
mmu_add_fb_range(mmu_ranges); |
| 691 |
|
| 692 |
if (dma_range == NULL) |
| 693 |
mmu_error(); |
| 694 |
|
| 695 |
return dma_range; |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
void mmu_presysinfo_memory_used(uint64_t base, uint64_t size) |
| 707 |
{ |
| 708 |
uint64_t range_base; |
| 709 |
|
| 710 |
range_base = ALIGN_DOWN(base, GRANULE_SIZE); |
| 711 |
|
| 712 |
size += (base - range_base); |
| 713 |
size = ALIGN_UP(size, GRANULE_SIZE); |
| 714 |
|
| 715 |
mmu_add_memrange(&usedmem_ranges, range_base, size, TYPE_NORMAL_MEM); |
| 716 |
} |
| 717 |
|
| 718 |
void mmu_presysinfo_enable(void) |
| 719 |
{ |
| 720 |
mmu_init(&usedmem_ranges); |
| 721 |
mmu_enable(); |
| 722 |
} |
| 723 |
|
| 724 |
const struct mmu_ranges *mmu_get_used_ranges(void) |
| 725 |
{ |
| 726 |
return &usedmem_ranges; |
| 727 |
} |