MCPcopy Create free account
hub / github.com/F-Stack/f-stack / add_physmap_entry

Function add_physmap_entry

freebsd/amd64/amd64/machdep.c:986–1050  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

984u_int basemem;
985
986static int
987add_physmap_entry(uint64_t base, uint64_t length, vm_paddr_t *physmap,
988 int *physmap_idxp)
989{
990 int i, insert_idx, physmap_idx;
991
992 physmap_idx = *physmap_idxp;
993
994 if (length == 0)
995 return (1);
996
997 /*
998 * Find insertion point while checking for overlap. Start off by
999 * assuming the new entry will be added to the end.
1000 *
1001 * NB: physmap_idx points to the next free slot.
1002 */
1003 insert_idx = physmap_idx;
1004 for (i = 0; i <= physmap_idx; i += 2) {
1005 if (base < physmap[i + 1]) {
1006 if (base + length <= physmap[i]) {
1007 insert_idx = i;
1008 break;
1009 }
1010 if (boothowto & RB_VERBOSE)
1011 printf(
1012 "Overlapping memory regions, ignoring second region\n");
1013 return (1);
1014 }
1015 }
1016
1017 /* See if we can prepend to the next entry. */
1018 if (insert_idx <= physmap_idx && base + length == physmap[insert_idx]) {
1019 physmap[insert_idx] = base;
1020 return (1);
1021 }
1022
1023 /* See if we can append to the previous entry. */
1024 if (insert_idx > 0 && base == physmap[insert_idx - 1]) {
1025 physmap[insert_idx - 1] += length;
1026 return (1);
1027 }
1028
1029 physmap_idx += 2;
1030 *physmap_idxp = physmap_idx;
1031 if (physmap_idx == PHYS_AVAIL_ENTRIES) {
1032 printf(
1033 "Too many segments in the physical address map, giving up\n");
1034 return (0);
1035 }
1036
1037 /*
1038 * Move the last 'N' entries down to make room for the new
1039 * entry if needed.
1040 */
1041 for (i = (physmap_idx - 2); i > insert_idx; i -= 2) {
1042 physmap[i] = physmap[i - 2];
1043 physmap[i + 1] = physmap[i - 1];

Callers 2

bios_add_smap_entriesFunction · 0.70
add_efi_map_entriesFunction · 0.70

Calls 1

printfFunction · 0.50

Tested by

no test coverage detected