--- //depot/vendor/freebsd/src/sys/amd64/amd64/nexus.c 2007/02/23 12:24:01 +++ //depot/user/jhb/acpipci/amd64/amd64/nexus.c 2007/03/05 17:04:36 @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -59,7 +60,9 @@ #include #include +#include #include +#include #include "pcib_if.h" @@ -550,6 +551,79 @@ return (msi_release(irqs, count)); } +/* Placeholder for system RAM. */ +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 (0); +} + +static int +ram_attach(device_t dev) +{ + struct bios_smap *smapbase, *smap, *smapend; + struct resource *res; + caddr_t kmdp; + uint32_t smapsize; + int error, rid; + + /* Retrieve the system memory map from the loader. */ + kmdp = preload_search_by_type("elf kernel"); + if (kmdp == NULL) + kmdp = preload_search_by_type("elf64 kernel"); + smapbase = (struct bios_smap *)preload_search_info(kmdp, + MODINFO_METADATA | MODINFOMD_SMAP); + smapsize = *((u_int32_t *)smapbase - 1); + smapend = (struct bios_smap *)((uintptr_t)smapbase + smapsize); + + rid = 0; + for (smap = smapbase; smap < smapend; smap++) { + if (smap->type != 0x01 || smap->length == 0) + continue; + error = bus_set_resource(dev, SYS_RES_MEMORY, rid, smap->base, + smap->length); + if (error) + panic("ram_attach: resource %d failed set with %d", rid, + error); + res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 0); + if (res == NULL) + panic("ram_attach: resource %d failed to attach", rid); + 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), + { 0, 0 } +}; + +static driver_t ram_driver = { + "ram", + ram_methods, + 1, /* no softc */ +}; + +static devclass_t ram_devclass; + +DRIVER_MODULE(ram, nexus, ram_driver, ram_devclass, 0, 0); + #ifdef DEV_ISA /* * Placeholder which claims PnP 'devices' which describe system --- //depot/vendor/freebsd/src/sys/i386/i386/nexus.c 2007/03/05 22:31:43 +++ //depot/user/jhb/acpipci/i386/i386/nexus.c 2007/03/06 15:28:38 @@ -607,6 +600,84 @@ } #endif +/* Placeholder for system RAM. */ +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 (0); +} + +static int +ram_attach(device_t dev) +{ + struct resource *res; + vm_paddr_t *p; + int error, i, rid; + + /* + * We use the dump_avail[] array rather than phys_avail[] for + * the memory map as phys_avail[] contains holes for kernel + * memory, page 0, the message buffer, and the dcons buffer. + * We test the end address in the loop instead of the start + * since the start address for the first segment is 0. + * + * XXX: It would be preferable to use the SMAP if it exists + * instead since if the SMAP is very fragmented we may not + * include some memory regions in dump_avail[] and phys_avail[]. + */ + for (i = 0, p = dump_avail; p[1] != 0; i++, p += 2) { + rid = i; +#ifdef PAE + /* + * Resources use long's to track resources, so we can't + * include memory regions above 4GB. + */ + if (p[0] >= ~0ul) + break; +#endif + error = bus_set_resource(dev, SYS_RES_MEMORY, rid, p[0], + p[1] - p[0]); + if (error) + panic("ram_attach: resource %d failed set with %d", i, + error); + res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 0); + if (res == NULL) + panic("ram_attach: resource %d failed to attach", i); + } + 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), + { 0, 0 } +}; + +static driver_t ram_driver = { + "ram", + ram_methods, + 1, /* no softc */ +}; + +static devclass_t ram_devclass; + +DRIVER_MODULE(ram, nexus, ram_driver, ram_devclass, 0, 0); + #ifdef DEV_ISA /* * Placeholder which claims PnP 'devices' which describe system