| 1 |
|
| 2 |
|
| 3 |
#include <bootstate.h> |
| 4 |
#include <cbmem.h> |
| 5 |
#include <cpu/amd/mtrr.h> |
| 6 |
#include <string.h> |
| 7 |
#include <vendorcode/amd/opensil/opensil.h> |
| 8 |
|
| 9 |
#include "opensil.h" |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
typedef struct { |
| 16 |
uint64_t base; |
| 17 |
uint64_t size; |
| 18 |
uint32_t type; |
| 19 |
uint32_t reserved; |
| 20 |
} HOLE_INFO; |
| 21 |
|
| 22 |
|
| 23 |
void amd_opensil_add_memmap(struct device *dev, unsigned long *idx) |
| 24 |
{ |
| 25 |
uint64_t top_of_mem = 0; |
| 26 |
uint32_t n_holes = 0; |
| 27 |
void *hole_info = NULL; |
| 28 |
|
| 29 |
|
| 30 |
const uint32_t mem_usable = cbmem_top(); |
| 31 |
const uint32_t top_mem = ALIGN_DOWN(get_top_of_mem_below_4gb(), 1 * MiB); |
| 32 |
if (mem_usable != top_mem) |
| 33 |
reserved_ram_from_to(dev, (*idx)++, mem_usable, top_mem); |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
opensil_get_hole_info(&n_holes, &top_of_mem, &hole_info); |
| 38 |
if (hole_info == NULL) |
| 39 |
return; |
| 40 |
|
| 41 |
|
| 42 |
if (top_of_mem <= 4ULL * GiB) |
| 43 |
return; |
| 44 |
|
| 45 |
HOLE_INFO *holes = (HOLE_INFO *)hole_info; |
| 46 |
|
| 47 |
uint64_t lowest_upper_hole_base = top_of_mem; |
| 48 |
uint64_t highest_upper_hole_end = 4ULL * GiB; |
| 49 |
for (size_t hole = 0; hole < n_holes; hole++) { |
| 50 |
if (!strcmp(opensil_get_hole_info_type(holes[hole].type), "MMIO")) |
| 51 |
continue; |
| 52 |
if (holes[hole].base < 4ULL * GiB) |
| 53 |
continue; |
| 54 |
lowest_upper_hole_base = MIN(lowest_upper_hole_base, holes[hole].base); |
| 55 |
highest_upper_hole_end = MAX(highest_upper_hole_end, holes[hole].base + holes[hole].size); |
| 56 |
if (!strcmp(opensil_get_hole_info_type(holes[hole].type), "UMA")) |
| 57 |
mmio_range(dev, (*idx)++, holes[hole].base, holes[hole].size); |
| 58 |
else |
| 59 |
reserved_ram_range(dev, (*idx)++, holes[hole].base, holes[hole].size); |
| 60 |
} |
| 61 |
|
| 62 |
ram_from_to(dev, (*idx)++, 4ULL * GiB, lowest_upper_hole_base); |
| 63 |
|
| 64 |
if (top_of_mem > highest_upper_hole_end) |
| 65 |
ram_from_to(dev, (*idx)++, highest_upper_hole_end, top_of_mem); |
| 66 |
} |
| 67 |
|
| 68 |
static void print_memory_holes(void *unused) |
| 69 |
{ |
| 70 |
uint64_t top_of_mem = 0; |
| 71 |
uint32_t n_holes = 0; |
| 72 |
void *hole_info = NULL; |
| 73 |
|
| 74 |
opensil_get_hole_info(&n_holes, &top_of_mem, &hole_info); |
| 75 |
if (hole_info == NULL) |
| 76 |
return; |
| 77 |
|
| 78 |
HOLE_INFO *holes = (HOLE_INFO *)hole_info; |
| 79 |
|
| 80 |
printk(BIOS_DEBUG, "APOB: top of memory 0x%016llx\n", top_of_mem); |
| 81 |
printk(BIOS_DEBUG, "The following holes are reported in APOB\n"); |
| 82 |
for (size_t hole = 0; hole < n_holes; hole++) { |
| 83 |
printk(BIOS_DEBUG, " Base: 0x%016llx, Size: 0x%016llx, Type: %02d:%s\n", |
| 84 |
holes[hole].base, holes[hole].size, holes[hole].type, |
| 85 |
opensil_get_hole_info_type(holes[hole].type)); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
BOOT_STATE_INIT_ENTRY(BS_DEV_RESOURCES, BS_ON_ENTRY, print_memory_holes, NULL); |