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

Function ram_attach

freebsd/x86/x86/nexus.c:784–854  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

782}
783
784static int
785ram_attach(device_t dev)
786{
787 struct bios_smap *smapbase, *smap, *smapend;
788 struct resource *res;
789 rman_res_t length;
790 vm_paddr_t *p;
791 caddr_t kmdp;
792 uint32_t smapsize;
793 int error, rid;
794
795 /* Retrieve the system memory map from the loader. */
796 kmdp = preload_search_by_type("elf kernel");
797 if (kmdp == NULL)
798 kmdp = preload_search_by_type(ELF_KERN_STR);
799 smapbase = (struct bios_smap *)preload_search_info(kmdp,
800 MODINFO_METADATA | MODINFOMD_SMAP);
801 if (smapbase != NULL) {
802 smapsize = *((u_int32_t *)smapbase - 1);
803 smapend = (struct bios_smap *)((uintptr_t)smapbase + smapsize);
804
805 rid = 0;
806 for (smap = smapbase; smap < smapend; smap++) {
807 if (smap->type != SMAP_TYPE_MEMORY ||
808 smap->length == 0)
809 continue;
810 if (smap->base > mem_rman.rm_end)
811 continue;
812 length = smap->base + smap->length > mem_rman.rm_end ?
813 mem_rman.rm_end - smap->base : smap->length;
814 error = bus_set_resource(dev, SYS_RES_MEMORY, rid,
815 smap->base, length);
816 if (error)
817 panic(
818 "ram_attach: resource %d failed set with %d",
819 rid, error);
820 res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
821 0);
822 if (res == NULL)
823 panic("ram_attach: resource %d failed to attach",
824 rid);
825 rid++;
826 }
827 return (0);
828 }
829
830 /*
831 * If the system map is not available, fall back to using
832 * dump_avail[]. We use the dump_avail[] array rather than
833 * phys_avail[] for the memory map as phys_avail[] contains
834 * holes for kernel memory, page 0, the message buffer, and
835 * the dcons buffer. We test the end address in the loop
836 * instead of the start since the start address for the first
837 * segment is 0.
838 */
839 for (rid = 0, p = dump_avail; p[1] != 0; rid++, p += 2) {
840 if (p[0] > mem_rman.rm_end)
841 break;

Callers

nothing calls this directly

Calls 5

preload_search_by_typeFunction · 0.85
preload_search_infoFunction · 0.85
bus_set_resourceFunction · 0.85
bus_alloc_resource_anyFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected