1 /*- 2 * Copyright 1998 Massachusetts Institute of Technology 3 * 4 * Permission to use, copy, modify, and distribute this software and 5 * its documentation for any purpose and without fee is hereby 6 * granted, provided that both the above copyright notice and this 7 * permission notice appear in all copies, that both the above 8 * copyright notice and this permission notice appear in all 9 * supporting documentation, and that the name of M.I.T. not be used 10 * in advertising or publicity pertaining to distribution of the 11 * software without specific, written prior permission. M.I.T. makes 12 * no representations about the suitability of this software for any 13 * purpose. It is provided "as is" without express or implied 14 * warranty. 15 * 16 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 17 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 20 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #include <sys/cdefs.h> 31 /* 32 * This code implements a `root nexus' for Intel Architecture 33 * machines. The function of the root nexus is to serve as an 34 * attachment point for both processors and buses, and to manage 35 * resources which are common to all of them. In particular, 36 * this code implements the core resource managers for interrupt 37 * requests, DMA requests (which rightfully should be a part of the 38 * ISA code but it's easier to do it here for now), I/O port addresses, 39 * and I/O memory address space. 40 */ 41 42 #ifdef __amd64__ 43 #define DEV_APIC 44 #else 45 #include "opt_apic.h" 46 #endif 47 #include "opt_isa.h" 48 #include "opt_pci.h" 49 50 #include <sys/param.h> 51 #include <sys/systm.h> 52 #include <sys/bus.h> 53 #include <sys/interrupt.h> 54 #include <sys/kernel.h> 55 #include <sys/linker.h> 56 #include <sys/malloc.h> 57 #include <sys/module.h> 58 #include <sys/rman.h> 59 60 #include <vm/vm.h> 61 #include <vm/vm_param.h> 62 #include <vm/vm_page.h> 63 #include <vm/vm_phys.h> 64 #include <vm/vm_dumpset.h> 65 #include <vm/pmap.h> 66 67 #include <machine/bus.h> 68 #include <machine/intr_machdep.h> 69 #include <machine/md_var.h> 70 #include <machine/metadata.h> 71 #include <machine/nexusvar.h> 72 #include <machine/pc/bios.h> 73 #include <machine/resource.h> 74 75 #ifdef DEV_APIC 76 #include "pcib_if.h" 77 #endif 78 79 #ifdef DEV_ISA 80 #include <isa/isavar.h> 81 #include <isa/isareg.h> 82 #endif 83 84 #define ELF_KERN_STR ("elf"__XSTRING(__ELF_WORD_SIZE)" kernel") 85 86 static MALLOC_DEFINE(M_NEXUSDEV, "nexusdev", "Nexus device"); 87 88 #define DEVTONX(dev) ((struct nexus_device *)device_get_ivars(dev)) 89 90 struct rman irq_rman, drq_rman, port_rman, mem_rman; 91 92 static int nexus_print_all_resources(device_t dev); 93 94 static device_probe_t nexus_probe; 95 static device_attach_t nexus_attach; 96 97 static bus_add_child_t nexus_add_child; 98 static bus_print_child_t nexus_print_child; 99 100 static bus_alloc_resource_t nexus_alloc_resource; 101 static bus_get_resource_list_t nexus_get_reslist; 102 static bus_get_rman_t nexus_get_rman; 103 static bus_map_resource_t nexus_map_resource; 104 static bus_unmap_resource_t nexus_unmap_resource; 105 106 #ifdef SMP 107 static bus_bind_intr_t nexus_bind_intr; 108 #endif 109 static bus_config_intr_t nexus_config_intr; 110 static bus_describe_intr_t nexus_describe_intr; 111 static bus_resume_intr_t nexus_resume_intr; 112 static bus_setup_intr_t nexus_setup_intr; 113 static bus_suspend_intr_t nexus_suspend_intr; 114 static bus_teardown_intr_t nexus_teardown_intr; 115 116 static bus_get_cpus_t nexus_get_cpus; 117 118 #if defined(DEV_APIC) && defined(DEV_PCI) 119 static pcib_alloc_msi_t nexus_alloc_msi; 120 static pcib_release_msi_t nexus_release_msi; 121 static pcib_alloc_msix_t nexus_alloc_msix; 122 static pcib_release_msix_t nexus_release_msix; 123 static pcib_map_msi_t nexus_map_msi; 124 #endif 125 126 static device_method_t nexus_methods[] = { 127 /* Device interface */ 128 DEVMETHOD(device_probe, nexus_probe), 129 DEVMETHOD(device_attach, nexus_attach), 130 DEVMETHOD(device_detach, bus_generic_detach), 131 DEVMETHOD(device_shutdown, bus_generic_shutdown), 132 DEVMETHOD(device_suspend, bus_generic_suspend), 133 DEVMETHOD(device_resume, bus_generic_resume), 134 135 /* Bus interface */ 136 DEVMETHOD(bus_print_child, nexus_print_child), 137 DEVMETHOD(bus_add_child, nexus_add_child), 138 DEVMETHOD(bus_activate_resource, bus_generic_rman_activate_resource), 139 DEVMETHOD(bus_adjust_resource, bus_generic_rman_adjust_resource), 140 DEVMETHOD(bus_alloc_resource, nexus_alloc_resource), 141 DEVMETHOD(bus_deactivate_resource, bus_generic_rman_deactivate_resource), 142 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), 143 DEVMETHOD(bus_get_resource_list, nexus_get_reslist), 144 DEVMETHOD(bus_get_rman, nexus_get_rman), 145 DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource), 146 DEVMETHOD(bus_map_resource, nexus_map_resource), 147 DEVMETHOD(bus_release_resource, bus_generic_rman_release_resource), 148 DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource), 149 DEVMETHOD(bus_unmap_resource, nexus_unmap_resource), 150 #ifdef SMP 151 DEVMETHOD(bus_bind_intr, nexus_bind_intr), 152 #endif 153 DEVMETHOD(bus_config_intr, nexus_config_intr), 154 DEVMETHOD(bus_describe_intr, nexus_describe_intr), 155 DEVMETHOD(bus_resume_intr, nexus_resume_intr), 156 DEVMETHOD(bus_setup_intr, nexus_setup_intr), 157 DEVMETHOD(bus_suspend_intr, nexus_suspend_intr), 158 DEVMETHOD(bus_teardown_intr, nexus_teardown_intr), 159 DEVMETHOD(bus_get_cpus, nexus_get_cpus), 160 161 /* pcib interface */ 162 #if defined(DEV_APIC) && defined(DEV_PCI) 163 DEVMETHOD(pcib_alloc_msi, nexus_alloc_msi), 164 DEVMETHOD(pcib_release_msi, nexus_release_msi), 165 DEVMETHOD(pcib_alloc_msix, nexus_alloc_msix), 166 DEVMETHOD(pcib_release_msix, nexus_release_msix), 167 DEVMETHOD(pcib_map_msi, nexus_map_msi), 168 #endif 169 DEVMETHOD_END 170 }; 171 172 DEFINE_CLASS_0(nexus, nexus_driver, nexus_methods, 1); 173 174 DRIVER_MODULE(nexus, root, nexus_driver, 0, 0); 175 176 static int 177 nexus_probe(device_t dev) 178 { 179 180 device_quiet(dev); /* suppress attach message for neatness */ 181 return (BUS_PROBE_GENERIC); 182 } 183 184 void 185 nexus_init_resources(void) 186 { 187 int irq; 188 189 /* 190 * XXX working notes: 191 * 192 * - IRQ resource creation should be moved to the PIC/APIC driver. 193 * - DRQ resource creation should be moved to the DMAC driver. 194 * - The above should be sorted to probe earlier than any child buses. 195 * 196 * - Leave I/O and memory creation here, as child probes may need them. 197 * (especially eg. ACPI) 198 */ 199 200 /* 201 * IRQ's are on the mainboard on old systems, but on the ISA part 202 * of PCI->ISA bridges. There would be multiple sets of IRQs on 203 * multi-ISA-bus systems. PCI interrupts are routed to the ISA 204 * component, so in a way, PCI can be a partial child of an ISA bus(!). 205 * APIC interrupts are global though. 206 */ 207 irq_rman.rm_start = 0; 208 irq_rman.rm_type = RMAN_ARRAY; 209 irq_rman.rm_descr = "Interrupt request lines"; 210 irq_rman.rm_end = num_io_irqs - 1; 211 if (rman_init(&irq_rman)) 212 panic("nexus_init_resources irq_rman"); 213 214 /* 215 * We search for regions of existing IRQs and add those to the IRQ 216 * resource manager. 217 */ 218 for (irq = 0; irq < num_io_irqs; irq++) 219 if (intr_lookup_source(irq) != NULL) 220 if (rman_manage_region(&irq_rman, irq, irq) != 0) 221 panic("nexus_init_resources irq_rman add"); 222 223 /* 224 * ISA DMA on PCI systems is implemented in the ISA part of each 225 * PCI->ISA bridge and the channels can be duplicated if there are 226 * multiple bridges. (eg: laptops with docking stations) 227 */ 228 drq_rman.rm_start = 0; 229 drq_rman.rm_end = 7; 230 drq_rman.rm_type = RMAN_ARRAY; 231 drq_rman.rm_descr = "DMA request lines"; 232 /* XXX drq 0 not available on some machines */ 233 if (rman_init(&drq_rman) 234 || rman_manage_region(&drq_rman, 235 drq_rman.rm_start, drq_rman.rm_end)) 236 panic("nexus_init_resources drq_rman"); 237 238 /* 239 * However, IO ports and Memory truely are global at this level, 240 * as are APIC interrupts (however many IO APICS there turn out 241 * to be on large systems..) 242 */ 243 port_rman.rm_start = 0; 244 port_rman.rm_end = 0xffff; 245 port_rman.rm_type = RMAN_ARRAY; 246 port_rman.rm_descr = "I/O ports"; 247 if (rman_init(&port_rman) 248 || rman_manage_region(&port_rman, 0, 0xffff)) 249 panic("nexus_init_resources port_rman"); 250 251 mem_rman.rm_start = 0; 252 mem_rman.rm_end = cpu_getmaxphyaddr(); 253 mem_rman.rm_type = RMAN_ARRAY; 254 mem_rman.rm_descr = "I/O memory addresses"; 255 if (rman_init(&mem_rman) 256 || rman_manage_region(&mem_rman, 0, mem_rman.rm_end)) 257 panic("nexus_init_resources mem_rman"); 258 } 259 260 static int 261 nexus_attach(device_t dev) 262 { 263 264 nexus_init_resources(); 265 bus_generic_probe(dev); 266 267 /* 268 * Explicitly add the legacy0 device here. Other platform 269 * types (such as ACPI), use their own nexus(4) subclass 270 * driver to override this routine and add their own root bus. 271 */ 272 if (BUS_ADD_CHILD(dev, 10, "legacy", 0) == NULL) 273 panic("legacy: could not attach"); 274 bus_generic_attach(dev); 275 return (0); 276 } 277 278 static int 279 nexus_print_all_resources(device_t dev) 280 { 281 struct nexus_device *ndev = DEVTONX(dev); 282 struct resource_list *rl = &ndev->nx_resources; 283 int retval = 0; 284 285 if (STAILQ_FIRST(rl)) 286 retval += printf(" at"); 287 288 retval += resource_list_print_type(rl, "port", SYS_RES_IOPORT, "%#jx"); 289 retval += resource_list_print_type(rl, "iomem", SYS_RES_MEMORY, "%#jx"); 290 retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%jd"); 291 292 return (retval); 293 } 294 295 static int 296 nexus_print_child(device_t bus, device_t child) 297 { 298 int retval = 0; 299 300 retval += bus_print_child_header(bus, child); 301 retval += nexus_print_all_resources(child); 302 if (device_get_flags(child)) 303 retval += printf(" flags %#x", device_get_flags(child)); 304 retval += printf("\n"); 305 306 return (retval); 307 } 308 309 static device_t 310 nexus_add_child(device_t bus, u_int order, const char *name, int unit) 311 { 312 device_t child; 313 struct nexus_device *ndev; 314 315 ndev = malloc(sizeof(struct nexus_device), M_NEXUSDEV, M_NOWAIT|M_ZERO); 316 if (!ndev) 317 return (0); 318 resource_list_init(&ndev->nx_resources); 319 320 child = device_add_child_ordered(bus, order, name, unit); 321 322 /* should we free this in nexus_child_detached? */ 323 device_set_ivars(child, ndev); 324 325 return (child); 326 } 327 328 static struct rman * 329 nexus_get_rman(device_t bus, int type, u_int flags) 330 { 331 switch (type) { 332 case SYS_RES_IRQ: 333 return (&irq_rman); 334 case SYS_RES_DRQ: 335 return (&drq_rman); 336 case SYS_RES_IOPORT: 337 return (&port_rman); 338 case SYS_RES_MEMORY: 339 return (&mem_rman); 340 default: 341 return (NULL); 342 } 343 } 344 345 /* 346 * Allocate a resource on behalf of child. NB: child is usually going to be a 347 * child of one of our descendants, not a direct child of nexus0. 348 */ 349 static struct resource * 350 nexus_alloc_resource(device_t bus, device_t child, int type, int *rid, 351 rman_res_t start, rman_res_t end, rman_res_t count, 352 u_int flags) 353 { 354 struct nexus_device *ndev = DEVTONX(child); 355 struct resource_list_entry *rle; 356 357 /* 358 * If this is an allocation of the "default" range for a given 359 * RID, and we know what the resources for this device are 360 * (ie. they aren't maintained by a child bus), then work out 361 * the start/end values. 362 */ 363 if (RMAN_IS_DEFAULT_RANGE(start, end) && (count == 1)) { 364 if (device_get_parent(child) != bus || ndev == NULL) 365 return (NULL); 366 rle = resource_list_find(&ndev->nx_resources, type, *rid); 367 if (rle == NULL) 368 return (NULL); 369 start = rle->start; 370 end = rle->end; 371 count = rle->count; 372 } 373 374 return (bus_generic_rman_alloc_resource(bus, child, type, rid, 375 start, end, count, flags)); 376 } 377 378 static int 379 nexus_map_resource(device_t bus, device_t child, int type, struct resource *r, 380 struct resource_map_request *argsp, struct resource_map *map) 381 { 382 struct resource_map_request args; 383 rman_res_t length, start; 384 int error; 385 386 /* Resources must be active to be mapped. */ 387 if (!(rman_get_flags(r) & RF_ACTIVE)) 388 return (ENXIO); 389 390 /* Mappings are only supported on I/O and memory resources. */ 391 switch (type) { 392 case SYS_RES_IOPORT: 393 case SYS_RES_MEMORY: 394 break; 395 default: 396 return (EINVAL); 397 } 398 399 resource_init_map_request(&args); 400 error = resource_validate_map_request(r, argsp, &args, &start, &length); 401 if (error) 402 return (error); 403 404 /* 405 * If this is a memory resource, map it into the kernel. 406 */ 407 switch (type) { 408 case SYS_RES_IOPORT: 409 map->r_bushandle = start; 410 map->r_bustag = X86_BUS_SPACE_IO; 411 map->r_size = length; 412 map->r_vaddr = NULL; 413 break; 414 case SYS_RES_MEMORY: 415 map->r_vaddr = pmap_mapdev_attr(start, length, args.memattr); 416 map->r_bustag = X86_BUS_SPACE_MEM; 417 map->r_size = length; 418 419 /* 420 * The handle is the virtual address. 421 */ 422 map->r_bushandle = (bus_space_handle_t)map->r_vaddr; 423 break; 424 } 425 return (0); 426 } 427 428 static int 429 nexus_unmap_resource(device_t bus, device_t child, int type, struct resource *r, 430 struct resource_map *map) 431 { 432 433 /* 434 * If this is a memory resource, unmap it. 435 */ 436 switch (type) { 437 case SYS_RES_MEMORY: 438 pmap_unmapdev(map->r_vaddr, map->r_size); 439 /* FALLTHROUGH */ 440 case SYS_RES_IOPORT: 441 break; 442 default: 443 return (EINVAL); 444 } 445 return (0); 446 } 447 448 /* 449 * Currently this uses the really grody interface from kern/kern_intr.c 450 * (which really doesn't belong in kern/anything.c). Eventually, all of 451 * the code in kern_intr.c and machdep_intr.c should get moved here, since 452 * this is going to be the official interface. 453 */ 454 static int 455 nexus_setup_intr(device_t bus, device_t child, struct resource *irq, 456 int flags, driver_filter_t filter, void (*ihand)(void *), 457 void *arg, void **cookiep) 458 { 459 int error, domain; 460 461 /* somebody tried to setup an irq that failed to allocate! */ 462 if (irq == NULL) 463 panic("nexus_setup_intr: NULL irq resource!"); 464 465 *cookiep = NULL; 466 if ((rman_get_flags(irq) & RF_SHAREABLE) == 0) 467 flags |= INTR_EXCL; 468 469 /* 470 * We depend here on rman_activate_resource() being idempotent. 471 */ 472 error = rman_activate_resource(irq); 473 if (error != 0) 474 return (error); 475 if (bus_get_domain(child, &domain) != 0) 476 domain = 0; 477 478 error = intr_add_handler(device_get_nameunit(child), 479 rman_get_start(irq), filter, ihand, arg, flags, cookiep, domain); 480 if (error == 0) 481 rman_set_irq_cookie(irq, *cookiep); 482 483 return (error); 484 } 485 486 static int 487 nexus_teardown_intr(device_t dev, device_t child, struct resource *r, void *ih) 488 { 489 int error; 490 491 error = intr_remove_handler(ih); 492 if (error == 0) 493 rman_set_irq_cookie(r, NULL); 494 return (error); 495 } 496 497 static int 498 nexus_suspend_intr(device_t dev, device_t child, struct resource *irq) 499 { 500 return (intr_event_suspend_handler(rman_get_irq_cookie(irq))); 501 } 502 503 static int 504 nexus_resume_intr(device_t dev, device_t child, struct resource *irq) 505 { 506 return (intr_event_resume_handler(rman_get_irq_cookie(irq))); 507 } 508 509 #ifdef SMP 510 static int 511 nexus_bind_intr(device_t dev, device_t child, struct resource *irq, int cpu) 512 { 513 struct intsrc *isrc; 514 515 isrc = intr_lookup_source(rman_get_start(irq)); 516 if (isrc == NULL) 517 return (EINVAL); 518 return (intr_event_bind(isrc->is_event, cpu)); 519 } 520 #endif 521 522 static int 523 nexus_config_intr(device_t dev, int irq, enum intr_trigger trig, 524 enum intr_polarity pol) 525 { 526 return (intr_config_intr(irq, trig, pol)); 527 } 528 529 static int 530 nexus_describe_intr(device_t dev, device_t child, struct resource *irq, 531 void *cookie, const char *descr) 532 { 533 534 return (intr_describe(rman_get_start(irq), cookie, descr)); 535 } 536 537 static struct resource_list * 538 nexus_get_reslist(device_t dev, device_t child) 539 { 540 struct nexus_device *ndev = DEVTONX(child); 541 542 return (&ndev->nx_resources); 543 } 544 545 static int 546 nexus_get_cpus(device_t dev, device_t child, enum cpu_sets op, size_t setsize, 547 cpuset_t *cpuset) 548 { 549 550 switch (op) { 551 #ifdef SMP 552 case INTR_CPUS: 553 if (setsize != sizeof(cpuset_t)) 554 return (EINVAL); 555 *cpuset = intr_cpus; 556 return (0); 557 #endif 558 default: 559 return (bus_generic_get_cpus(dev, child, op, setsize, cpuset)); 560 } 561 } 562 563 /* Called from the MSI code to add new IRQs to the IRQ rman. */ 564 void 565 nexus_add_irq(u_long irq) 566 { 567 568 if (rman_manage_region(&irq_rman, irq, irq) != 0) 569 panic("%s: failed", __func__); 570 } 571 572 #if defined(DEV_APIC) && defined(DEV_PCI) 573 static int 574 nexus_alloc_msix(device_t pcib, device_t dev, int *irq) 575 { 576 577 return (msix_alloc(dev, irq)); 578 } 579 580 static int 581 nexus_release_msix(device_t pcib, device_t dev, int irq) 582 { 583 584 return (msix_release(irq)); 585 } 586 587 static int 588 nexus_alloc_msi(device_t pcib, device_t dev, int count, int maxcount, int *irqs) 589 { 590 591 return (msi_alloc(dev, count, maxcount, irqs)); 592 } 593 594 static int 595 nexus_release_msi(device_t pcib, device_t dev, int count, int *irqs) 596 { 597 598 return (msi_release(irqs, count)); 599 } 600 601 static int 602 nexus_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr, uint32_t *data) 603 { 604 605 return (msi_map(irq, addr, data)); 606 } 607 #endif /* DEV_APIC && DEV_PCI */ 608 609 /* Placeholder for system RAM. */ 610 static void 611 ram_identify(driver_t *driver, device_t parent) 612 { 613 614 if (resource_disabled("ram", 0)) 615 return; 616 if (BUS_ADD_CHILD(parent, 0, "ram", 0) == NULL) 617 panic("ram_identify"); 618 } 619 620 static int 621 ram_probe(device_t dev) 622 { 623 624 device_quiet(dev); 625 device_set_desc(dev, "System RAM"); 626 return (0); 627 } 628 629 static int 630 ram_attach(device_t dev) 631 { 632 struct bios_smap *smapbase, *smap, *smapend; 633 struct resource *res; 634 rman_res_t length; 635 vm_paddr_t *p; 636 caddr_t kmdp; 637 uint32_t smapsize; 638 int error, rid; 639 640 /* Retrieve the system memory map from the loader. */ 641 kmdp = preload_search_by_type("elf kernel"); 642 if (kmdp == NULL) 643 kmdp = preload_search_by_type(ELF_KERN_STR); 644 smapbase = (struct bios_smap *)preload_search_info(kmdp, 645 MODINFO_METADATA | MODINFOMD_SMAP); 646 if (smapbase != NULL) { 647 smapsize = *((u_int32_t *)smapbase - 1); 648 smapend = (struct bios_smap *)((uintptr_t)smapbase + smapsize); 649 650 rid = 0; 651 for (smap = smapbase; smap < smapend; smap++) { 652 if (smap->type != SMAP_TYPE_MEMORY || 653 smap->length == 0) 654 continue; 655 if (smap->base > mem_rman.rm_end) 656 continue; 657 length = smap->base + smap->length > mem_rman.rm_end ? 658 mem_rman.rm_end - smap->base : smap->length; 659 error = bus_set_resource(dev, SYS_RES_MEMORY, rid, 660 smap->base, length); 661 if (error) 662 panic( 663 "ram_attach: resource %d failed set with %d", 664 rid, error); 665 res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 666 0); 667 if (res == NULL) 668 panic("ram_attach: resource %d failed to attach", 669 rid); 670 rid++; 671 } 672 return (0); 673 } 674 675 /* 676 * If the system map is not available, fall back to using 677 * dump_avail[]. We use the dump_avail[] array rather than 678 * phys_avail[] for the memory map as phys_avail[] contains 679 * holes for kernel memory, page 0, the message buffer, and 680 * the dcons buffer. We test the end address in the loop 681 * instead of the start since the start address for the first 682 * segment is 0. 683 */ 684 for (rid = 0, p = dump_avail; p[1] != 0; rid++, p += 2) { 685 if (p[0] > mem_rman.rm_end) 686 break; 687 length = (p[1] > mem_rman.rm_end ? mem_rman.rm_end : p[1]) - 688 p[0]; 689 error = bus_set_resource(dev, SYS_RES_MEMORY, rid, p[0], 690 length); 691 if (error) 692 panic("ram_attach: resource %d failed set with %d", rid, 693 error); 694 res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 0); 695 if (res == NULL) 696 panic("ram_attach: resource %d failed to attach", rid); 697 } 698 return (0); 699 } 700 701 static device_method_t ram_methods[] = { 702 /* Device interface */ 703 DEVMETHOD(device_identify, ram_identify), 704 DEVMETHOD(device_probe, ram_probe), 705 DEVMETHOD(device_attach, ram_attach), 706 707 DEVMETHOD_END 708 }; 709 710 static driver_t ram_driver = { 711 "ram", 712 ram_methods, 713 1, /* no softc */ 714 }; 715 716 DRIVER_MODULE(ram, nexus, ram_driver, 0, 0); 717 718 #ifdef DEV_ISA 719 /* 720 * Placeholder which claims PnP 'devices' which describe system 721 * resources. 722 */ 723 static struct isa_pnp_id sysresource_ids[] = { 724 { 0x010cd041 /* PNP0c01 */, "System Memory" }, 725 { 0x020cd041 /* PNP0c02 */, "System Resource" }, 726 { 0 } 727 }; 728 729 static int 730 sysresource_probe(device_t dev) 731 { 732 int result; 733 734 if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, sysresource_ids)) <= 0) { 735 device_quiet(dev); 736 } 737 return (result); 738 } 739 740 static int 741 sysresource_attach(device_t dev) 742 { 743 return (0); 744 } 745 746 static device_method_t sysresource_methods[] = { 747 /* Device interface */ 748 DEVMETHOD(device_probe, sysresource_probe), 749 DEVMETHOD(device_attach, sysresource_attach), 750 DEVMETHOD(device_detach, bus_generic_detach), 751 DEVMETHOD(device_shutdown, bus_generic_shutdown), 752 DEVMETHOD(device_suspend, bus_generic_suspend), 753 DEVMETHOD(device_resume, bus_generic_resume), 754 755 DEVMETHOD_END 756 }; 757 758 static driver_t sysresource_driver = { 759 "sysresource", 760 sysresource_methods, 761 1, /* no softc */ 762 }; 763 764 DRIVER_MODULE(sysresource, isa, sysresource_driver, 0, 0); 765 ISA_PNP_INFO(sysresource_ids); 766 #endif /* DEV_ISA */ 767