Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F169666097
D32343.id96368.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D32343.id96368.diff
View Options
Index: sys/kern/subr_physmem.c
===================================================================
--- sys/kern/subr_physmem.c
+++ sys/kern/subr_physmem.c
@@ -38,14 +38,19 @@
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/bus.h>
#include <sys/kernel.h>
+#include <sys/module.h>
#include <sys/physmem.h>
+
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/vm_page.h>
#include <vm/vm_phys.h>
#include <vm/vm_dumpset.h>
+
#include <machine/md_var.h>
+#include <machine/resource.h>
/*
* These structures are used internally to keep track of regions of physical
@@ -425,3 +430,98 @@
}
#endif /* DDB */
+
+/*
+ * ram pseudo driver - this reserves memory resources corresponding to physical
+ * memory regions.
+ */
+
+static void
+ram_identify(driver_t *driver, device_t parent)
+{
+
+ if (resource_disabled("ram", 0))
+ return;
+ if (BUS_ADD_CHILD(parent, 0, "ram", 0) == NULL)
+ panic("ram_identify");
+}
+
+static int
+ram_probe(device_t dev)
+{
+
+ device_quiet(dev);
+ device_set_desc(dev, "System RAM");
+ return (BUS_PROBE_SPECIFIC);
+}
+
+static int
+ram_attach(device_t dev)
+{
+ vm_paddr_t avail_list[PHYS_AVAIL_COUNT];
+ rman_res_t start, end;
+ struct region *hwp;
+ int rid, i;
+
+ rid = 0;
+
+ /* Get the avail list. */
+ bzero(avail_list, sizeof(avail_list));
+ regions_to_avail(avail_list, EXFLAG_NOALLOC | EXFLAG_NODUMP,
+ PHYS_AVAIL_COUNT, 0, NULL, NULL);
+
+ /* Reserve all memory regions. */
+ for (i = 0; avail_list[i + 1] != 0; i += 2) {
+ start = avail_list[i];
+ end = avail_list[i + 1];
+
+ if (bootverbose)
+ device_printf(dev,
+ "reserving memory region: %jx-%jx\n",
+ (uintmax_t)start, (uintmax_t)end);
+
+ if (bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, start, end,
+ end - start, 0) == NULL)
+ panic("ram_attach: resource %d failed to attach", rid);
+ rid++;
+ }
+
+ /* Now, reserve the excluded memory regions. */
+ for (i = 0, hwp = exregions; i < excnt; i++, hwp++) {
+ start = hwp->addr;
+ end = hwp->addr + hwp->size;
+
+ if (bootverbose)
+ device_printf(dev,
+ "reserving excluded region: %jx-%jx\n",
+ (uintmax_t)start, (uintmax_t)(end - 1));
+
+ /*
+ * Best-effort attempt to reserve the range. This may fail, as
+ * sometimes the excluded ranges provided by the device tree
+ * will cover or overlap some I/O range.
+ */
+ if (bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, start, end,
+ end - start, 0) == NULL) {
+ if (bootverbose)
+ device_printf(dev, "failed to reserve region\n");
+ continue;
+ }
+ rid++;
+ }
+
+ return (0);
+}
+
+static device_method_t ram_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_identify, ram_identify),
+ DEVMETHOD(device_probe, ram_probe),
+ DEVMETHOD(device_attach, ram_attach),
+
+ DEVMETHOD_END
+};
+
+static devclass_t ram_devclass;
+DEFINE_CLASS_0(ram, ram_driver, ram_methods, /* no softc */ 1);
+DRIVER_MODULE(ram, nexus, ram_driver, ram_devclass, 0, 0);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Sep 3, 5:43 AM (16 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38071115
Default Alt Text
D32343.id96368.diff (2 KB)
Attached To
Mode
D32343: physmem: add ram0 pseudo-driver
Attached
Detach File
Event Timeline
Log In to Comment