]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/i386/i386/nexus.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / i386 / i386 / nexus.c
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 __FBSDID("$FreeBSD$");
32
33 /*
34  * This code implements a `root nexus' for Intel Architecture
35  * machines.  The function of the root nexus is to serve as an
36  * attachment point for both processors and buses, and to manage
37  * resources which are common to all of them.  In particular,
38  * this code implements the core resource managers for interrupt
39  * requests, DMA requests (which rightfully should be a part of the
40  * ISA code but it's easier to do it here for now), I/O port addresses,
41  * and I/O memory address space.
42  */
43
44 #include "opt_apic.h"
45 #include "opt_isa.h"
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/bus.h>
50 #include <sys/kernel.h>
51 #include <sys/malloc.h>
52 #include <sys/module.h>
53 #include <machine/bus.h>
54 #include <machine/intr_machdep.h>
55 #include <sys/rman.h>
56 #include <sys/interrupt.h>
57
58 #include <machine/vmparam.h>
59 #include <vm/vm.h>
60 #include <vm/pmap.h>
61 #include <machine/pmap.h>
62
63 #include <machine/nexusvar.h>
64 #include <machine/resource.h>
65
66 #ifdef DEV_APIC
67 #include "pcib_if.h"
68 #endif
69
70 #ifdef DEV_ISA
71 #include <isa/isavar.h>
72 #ifdef PC98
73 #include <pc98/cbus/cbus.h>
74 #else
75 #include <i386/isa/isa.h>
76 #endif
77 #endif
78 #include <sys/rtprio.h>
79
80 static MALLOC_DEFINE(M_NEXUSDEV, "nexusdev", "Nexus device");
81
82 #define DEVTONX(dev)    ((struct nexus_device *)device_get_ivars(dev))
83
84 struct rman irq_rman, drq_rman, port_rman, mem_rman;
85
86 static  int nexus_probe(device_t);
87 static  int nexus_attach(device_t);
88 static  int nexus_print_all_resources(device_t dev);
89 static  int nexus_print_child(device_t, device_t);
90 static device_t nexus_add_child(device_t bus, int order, const char *name,
91                                 int unit);
92 static  struct resource *nexus_alloc_resource(device_t, device_t, int, int *,
93                                               u_long, u_long, u_long, u_int);
94 #ifdef SMP
95 static  int nexus_bind_intr(device_t, device_t, struct resource *, int);
96 #endif
97 static  int nexus_config_intr(device_t, int, enum intr_trigger,
98                               enum intr_polarity);
99 static  int nexus_describe_intr(device_t dev, device_t child,
100                                 struct resource *irq, void *cookie,
101                                 const char *descr);
102 static  int nexus_activate_resource(device_t, device_t, int, int,
103                                     struct resource *);
104 static  int nexus_deactivate_resource(device_t, device_t, int, int,
105                                       struct resource *);
106 static  int nexus_release_resource(device_t, device_t, int, int,
107                                    struct resource *);
108 static  int nexus_setup_intr(device_t, device_t, struct resource *, int flags,
109                              driver_filter_t filter, void (*)(void *), void *,
110                               void **);
111 static  int nexus_teardown_intr(device_t, device_t, struct resource *,
112                                 void *);
113 static struct resource_list *nexus_get_reslist(device_t dev, device_t child);
114 static  int nexus_set_resource(device_t, device_t, int, int, u_long, u_long);
115 static  int nexus_get_resource(device_t, device_t, int, int, u_long *, u_long *);
116 static void nexus_delete_resource(device_t, device_t, int, int);
117 #ifdef DEV_APIC
118 static  int nexus_alloc_msi(device_t pcib, device_t dev, int count, int maxcount, int *irqs);
119 static  int nexus_release_msi(device_t pcib, device_t dev, int count, int *irqs);
120 static  int nexus_alloc_msix(device_t pcib, device_t dev, int *irq);
121 static  int nexus_release_msix(device_t pcib, device_t dev, int irq);
122 static  int nexus_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr, uint32_t *data);
123 #endif
124
125 static device_method_t nexus_methods[] = {
126         /* Device interface */
127         DEVMETHOD(device_probe,         nexus_probe),
128         DEVMETHOD(device_attach,        nexus_attach),
129         DEVMETHOD(device_detach,        bus_generic_detach),
130         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
131         DEVMETHOD(device_suspend,       bus_generic_suspend),
132         DEVMETHOD(device_resume,        bus_generic_resume),
133
134         /* Bus interface */
135         DEVMETHOD(bus_print_child,      nexus_print_child),
136         DEVMETHOD(bus_add_child,        nexus_add_child),
137         DEVMETHOD(bus_alloc_resource,   nexus_alloc_resource),
138         DEVMETHOD(bus_release_resource, nexus_release_resource),
139         DEVMETHOD(bus_activate_resource, nexus_activate_resource),
140         DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource),
141         DEVMETHOD(bus_setup_intr,       nexus_setup_intr),
142         DEVMETHOD(bus_teardown_intr,    nexus_teardown_intr),
143 #ifdef SMP
144         DEVMETHOD(bus_bind_intr,        nexus_bind_intr),
145 #endif
146         DEVMETHOD(bus_config_intr,      nexus_config_intr),
147         DEVMETHOD(bus_describe_intr,    nexus_describe_intr),
148         DEVMETHOD(bus_get_resource_list, nexus_get_reslist),
149         DEVMETHOD(bus_set_resource,     nexus_set_resource),
150         DEVMETHOD(bus_get_resource,     nexus_get_resource),
151         DEVMETHOD(bus_delete_resource,  nexus_delete_resource),
152
153         /* pcib interface */
154 #ifdef DEV_APIC
155         DEVMETHOD(pcib_alloc_msi,       nexus_alloc_msi),
156         DEVMETHOD(pcib_release_msi,     nexus_release_msi),
157         DEVMETHOD(pcib_alloc_msix,      nexus_alloc_msix),
158         DEVMETHOD(pcib_release_msix,    nexus_release_msix),
159         DEVMETHOD(pcib_map_msi,         nexus_map_msi),
160 #endif
161
162         { 0, 0 }
163 };
164
165 DEFINE_CLASS_0(nexus, nexus_driver, nexus_methods, 1);
166 static devclass_t nexus_devclass;
167
168 DRIVER_MODULE(nexus, root, nexus_driver, nexus_devclass, 0, 0);
169
170 static int
171 nexus_probe(device_t dev)
172 {
173
174         device_quiet(dev);      /* suppress attach message for neatness */
175         return (BUS_PROBE_GENERIC);
176 }
177
178 void
179 nexus_init_resources(void)
180 {
181         int irq;
182
183         /*
184          * XXX working notes:
185          *
186          * - IRQ resource creation should be moved to the PIC/APIC driver.
187          * - DRQ resource creation should be moved to the DMAC driver.
188          * - The above should be sorted to probe earlier than any child busses.
189          *
190          * - Leave I/O and memory creation here, as child probes may need them.
191          *   (especially eg. ACPI)
192          */
193
194         /*
195          * IRQ's are on the mainboard on old systems, but on the ISA part
196          * of PCI->ISA bridges.  There would be multiple sets of IRQs on
197          * multi-ISA-bus systems.  PCI interrupts are routed to the ISA
198          * component, so in a way, PCI can be a partial child of an ISA bus(!).
199          * APIC interrupts are global though.
200          */
201         irq_rman.rm_start = 0;
202         irq_rman.rm_type = RMAN_ARRAY;
203         irq_rman.rm_descr = "Interrupt request lines";
204         irq_rman.rm_end = NUM_IO_INTS - 1;
205         if (rman_init(&irq_rman))
206                 panic("nexus_init_resources irq_rman");
207
208         /*
209          * We search for regions of existing IRQs and add those to the IRQ
210          * resource manager.
211          */
212         for (irq = 0; irq < NUM_IO_INTS; irq++)
213                 if (intr_lookup_source(irq) != NULL)
214                         if (rman_manage_region(&irq_rman, irq, irq) != 0)
215                                 panic("nexus_init_resources irq_rman add");
216
217         /*
218          * ISA DMA on PCI systems is implemented in the ISA part of each
219          * PCI->ISA bridge and the channels can be duplicated if there are
220          * multiple bridges.  (eg: laptops with docking stations)
221          */
222         drq_rman.rm_start = 0;
223 #ifdef PC98
224         drq_rman.rm_end = 3;
225 #else
226         drq_rman.rm_end = 7;
227 #endif
228         drq_rman.rm_type = RMAN_ARRAY;
229         drq_rman.rm_descr = "DMA request lines";
230         /* XXX drq 0 not available on some machines */
231         if (rman_init(&drq_rman)
232             || rman_manage_region(&drq_rman,
233                                   drq_rman.rm_start, drq_rman.rm_end))
234                 panic("nexus_init_resources drq_rman");
235
236         /*
237          * However, IO ports and Memory truely are global at this level,
238          * as are APIC interrupts (however many IO APICS there turn out
239          * to be on large systems..)
240          */
241         port_rman.rm_start = 0;
242         port_rman.rm_end = 0xffff;
243         port_rman.rm_type = RMAN_ARRAY;
244         port_rman.rm_descr = "I/O ports";
245         if (rman_init(&port_rman)
246             || rman_manage_region(&port_rman, 0, 0xffff))
247                 panic("nexus_init_resources port_rman");
248
249         mem_rman.rm_start = 0;
250         mem_rman.rm_end = ~0u;
251         mem_rman.rm_type = RMAN_ARRAY;
252         mem_rman.rm_descr = "I/O memory addresses";
253         if (rman_init(&mem_rman)
254             || rman_manage_region(&mem_rman, 0, ~0))
255                 panic("nexus_init_resources mem_rman");
256 }
257
258 static int
259 nexus_attach(device_t dev)
260 {
261
262         nexus_init_resources();
263         bus_generic_probe(dev);
264
265         /*
266          * Explicitly add the legacy0 device here.  Other platform
267          * types (such as ACPI), use their own nexus(4) subclass
268          * driver to override this routine and add their own root bus.
269          */
270         if (BUS_ADD_CHILD(dev, 10, "legacy", 0) == NULL)
271                 panic("legacy: could not attach");
272         bus_generic_attach(dev);
273         return 0;
274 }
275
276 static int
277 nexus_print_all_resources(device_t dev)
278 {
279         struct  nexus_device *ndev = DEVTONX(dev);
280         struct resource_list *rl = &ndev->nx_resources;
281         int retval = 0;
282
283         if (STAILQ_FIRST(rl))
284                 retval += printf(" at");
285
286         retval += resource_list_print_type(rl, "port", SYS_RES_IOPORT, "%#lx");
287         retval += resource_list_print_type(rl, "iomem", SYS_RES_MEMORY, "%#lx");
288         retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
289
290         return retval;
291 }
292
293 static int
294 nexus_print_child(device_t bus, device_t child)
295 {
296         int retval = 0;
297
298         retval += bus_print_child_header(bus, child);
299         retval += nexus_print_all_resources(child);
300         if (device_get_flags(child))
301                 retval += printf(" flags %#x", device_get_flags(child));
302         retval += printf(" on motherboard\n");  /* XXX "motherboard", ick */
303
304         return (retval);
305 }
306
307 static device_t
308 nexus_add_child(device_t bus, int order, const char *name, int unit)
309 {
310         device_t                child;
311         struct nexus_device     *ndev;
312
313         ndev = malloc(sizeof(struct nexus_device), M_NEXUSDEV, M_NOWAIT|M_ZERO);
314         if (!ndev)
315                 return(0);
316         resource_list_init(&ndev->nx_resources);
317
318         child = device_add_child_ordered(bus, order, name, unit);
319
320         /* should we free this in nexus_child_detached? */
321         device_set_ivars(child, ndev);
322
323         return(child);
324 }
325
326 /*
327  * Allocate a resource on behalf of child.  NB: child is usually going to be a
328  * child of one of our descendants, not a direct child of nexus0.
329  * (Exceptions include npx.)
330  */
331 static struct resource *
332 nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
333                      u_long start, u_long end, u_long count, u_int flags)
334 {
335         struct nexus_device *ndev = DEVTONX(child);
336         struct  resource *rv;
337         struct resource_list_entry *rle;
338         struct  rman *rm;
339         int needactivate = flags & RF_ACTIVE;
340
341         /*
342          * If this is an allocation of the "default" range for a given RID, and
343          * we know what the resources for this device are (ie. they aren't maintained
344          * by a child bus), then work out the start/end values.
345          */
346         if ((start == 0UL) && (end == ~0UL) && (count == 1)) {
347                 if (ndev == NULL)
348                         return(NULL);
349                 rle = resource_list_find(&ndev->nx_resources, type, *rid);
350                 if (rle == NULL)
351                         return(NULL);
352                 start = rle->start;
353                 end = rle->end;
354                 count = rle->count;
355         }
356
357         flags &= ~RF_ACTIVE;
358
359         switch (type) {
360         case SYS_RES_IRQ:
361                 rm = &irq_rman;
362                 break;
363
364         case SYS_RES_DRQ:
365                 rm = &drq_rman;
366                 break;
367
368         case SYS_RES_IOPORT:
369                 rm = &port_rman;
370                 break;
371
372         case SYS_RES_MEMORY:
373                 rm = &mem_rman;
374                 break;
375
376         default:
377                 return 0;
378         }
379
380         rv = rman_reserve_resource(rm, start, end, count, flags, child);
381         if (rv == 0)
382                 return 0;
383         rman_set_rid(rv, *rid);
384
385         if (needactivate) {
386                 if (bus_activate_resource(child, type, *rid, rv)) {
387                         rman_release_resource(rv);
388                         return 0;
389                 }
390         }
391
392         return rv;
393 }
394
395 static int
396 nexus_activate_resource(device_t bus, device_t child, int type, int rid,
397                         struct resource *r)
398 {
399 #ifdef PC98
400         bus_space_handle_t bh;
401         int error;
402 #endif
403         void *vaddr;
404
405         /*
406          * If this is a memory resource, map it into the kernel.
407          */
408         switch (type) {
409         case SYS_RES_IOPORT:
410 #ifdef PC98
411                 error = i386_bus_space_handle_alloc(I386_BUS_SPACE_IO,
412                     rman_get_start(r), rman_get_size(r), &bh);
413                 if (error)
414                         return (error);
415                 rman_set_bushandle(r, bh);
416 #else
417                 rman_set_bushandle(r, rman_get_start(r));
418 #endif
419                 rman_set_bustag(r, I386_BUS_SPACE_IO);
420                 break;
421         case SYS_RES_MEMORY:
422 #ifdef PC98
423                 error = i386_bus_space_handle_alloc(I386_BUS_SPACE_MEM,
424                     rman_get_start(r), rman_get_size(r), &bh);
425                 if (error)
426                         return (error);
427 #endif
428                 vaddr = pmap_mapdev(rman_get_start(r), rman_get_size(r));
429                 rman_set_virtual(r, vaddr);
430                 rman_set_bustag(r, I386_BUS_SPACE_MEM);
431 #ifdef PC98
432                 /* PC-98: the type of bus_space_handle_t is the structure. */
433                 bh->bsh_base = (bus_addr_t) vaddr;
434                 rman_set_bushandle(r, bh);
435 #else
436                 /* IBM-PC: the type of bus_space_handle_t is u_int */
437                 rman_set_bushandle(r, (bus_space_handle_t) vaddr);
438 #endif
439         }
440         return (rman_activate_resource(r));
441 }
442
443 static int
444 nexus_deactivate_resource(device_t bus, device_t child, int type, int rid,
445                           struct resource *r)
446 {
447
448         /*
449          * If this is a memory resource, unmap it.
450          */
451         if (type == SYS_RES_MEMORY) {
452                 pmap_unmapdev((vm_offset_t)rman_get_virtual(r),
453                     rman_get_size(r));
454         }
455 #ifdef PC98
456         if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
457                 bus_space_handle_t bh;
458
459                 bh = rman_get_bushandle(r);
460                 i386_bus_space_handle_free(rman_get_bustag(r), bh, bh->bsh_sz);
461         }
462 #endif
463         return (rman_deactivate_resource(r));
464 }
465
466 static int
467 nexus_release_resource(device_t bus, device_t child, int type, int rid,
468                        struct resource *r)
469 {
470         if (rman_get_flags(r) & RF_ACTIVE) {
471                 int error = bus_deactivate_resource(child, type, rid, r);
472                 if (error)
473                         return error;
474         }
475         return (rman_release_resource(r));
476 }
477
478 /*
479  * Currently this uses the really grody interface from kern/kern_intr.c
480  * (which really doesn't belong in kern/anything.c).  Eventually, all of
481  * the code in kern_intr.c and machdep_intr.c should get moved here, since
482  * this is going to be the official interface.
483  */
484 static int
485 nexus_setup_intr(device_t bus, device_t child, struct resource *irq,
486                  int flags, driver_filter_t filter, void (*ihand)(void *),
487                  void *arg, void **cookiep)
488 {
489         int             error;
490
491         /* somebody tried to setup an irq that failed to allocate! */
492         if (irq == NULL)
493                 panic("nexus_setup_intr: NULL irq resource!");
494
495         *cookiep = 0;
496         if ((rman_get_flags(irq) & RF_SHAREABLE) == 0)
497                 flags |= INTR_EXCL;
498
499         /*
500          * We depend here on rman_activate_resource() being idempotent.
501          */
502         error = rman_activate_resource(irq);
503         if (error)
504                 return (error);
505
506         error = intr_add_handler(device_get_nameunit(child),
507             rman_get_start(irq), filter, ihand, arg, flags, cookiep);
508
509         return (error);
510 }
511
512 static int
513 nexus_teardown_intr(device_t dev, device_t child, struct resource *r, void *ih)
514 {
515         return (intr_remove_handler(ih));
516 }
517
518 #ifdef SMP
519 static int
520 nexus_bind_intr(device_t dev, device_t child, struct resource *irq, int cpu)
521 {
522         return (intr_bind(rman_get_start(irq), cpu));
523 }
524 #endif
525
526 static int
527 nexus_config_intr(device_t dev, int irq, enum intr_trigger trig,
528     enum intr_polarity pol)
529 {
530         return (intr_config_intr(irq, trig, pol));
531 }
532
533 static int
534 nexus_describe_intr(device_t dev, device_t child, struct resource *irq,
535     void *cookie, const char *descr)
536 {
537
538         return (intr_describe(rman_get_start(irq), cookie, descr));
539 }
540
541 static struct resource_list *
542 nexus_get_reslist(device_t dev, device_t child)
543 {
544         struct nexus_device *ndev = DEVTONX(child);
545
546         return (&ndev->nx_resources);
547 }
548
549 static int
550 nexus_set_resource(device_t dev, device_t child, int type, int rid, u_long start, u_long count)
551 {
552         struct nexus_device     *ndev = DEVTONX(child);
553         struct resource_list    *rl = &ndev->nx_resources;
554
555         /* XXX this should return a success/failure indicator */
556         resource_list_add(rl, type, rid, start, start + count - 1, count);
557         return(0);
558 }
559
560 static int
561 nexus_get_resource(device_t dev, device_t child, int type, int rid, u_long *startp, u_long *countp)
562 {
563         struct nexus_device     *ndev = DEVTONX(child);
564         struct resource_list    *rl = &ndev->nx_resources;
565         struct resource_list_entry *rle;
566
567         rle = resource_list_find(rl, type, rid);
568         if (!rle)
569                 return(ENOENT);
570         if (startp)
571                 *startp = rle->start;
572         if (countp)
573                 *countp = rle->count;
574         return(0);
575 }
576
577 static void
578 nexus_delete_resource(device_t dev, device_t child, int type, int rid)
579 {
580         struct nexus_device     *ndev = DEVTONX(child);
581         struct resource_list    *rl = &ndev->nx_resources;
582
583         resource_list_delete(rl, type, rid);
584 }
585
586 /* Called from the MSI code to add new IRQs to the IRQ rman. */
587 void
588 nexus_add_irq(u_long irq)
589 {
590
591         if (rman_manage_region(&irq_rman, irq, irq) != 0)
592                 panic("%s: failed", __func__);
593 }
594
595 #ifdef DEV_APIC
596 static int
597 nexus_alloc_msix(device_t pcib, device_t dev, int *irq)
598 {
599
600         return (msix_alloc(dev, irq));
601 }
602
603 static int
604 nexus_release_msix(device_t pcib, device_t dev, int irq)
605 {
606
607         return (msix_release(irq));
608 }
609
610 static int
611 nexus_alloc_msi(device_t pcib, device_t dev, int count, int maxcount, int *irqs)
612 {
613
614         return (msi_alloc(dev, count, maxcount, irqs));
615 }
616
617 static int
618 nexus_release_msi(device_t pcib, device_t dev, int count, int *irqs)
619 {
620
621         return (msi_release(irqs, count));
622 }
623
624 static int
625 nexus_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr, uint32_t *data)
626 {
627
628         return (msi_map(irq, addr, data));
629 }
630 #endif
631
632 /* Placeholder for system RAM. */
633 static void
634 ram_identify(driver_t *driver, device_t parent)
635 {
636
637         if (resource_disabled("ram", 0))
638                 return; 
639         if (BUS_ADD_CHILD(parent, 0, "ram", 0) == NULL)
640                 panic("ram_identify");
641 }
642
643 static int
644 ram_probe(device_t dev)
645 {
646
647         device_quiet(dev);
648         device_set_desc(dev, "System RAM");
649         return (0);
650 }
651
652 static int
653 ram_attach(device_t dev)
654 {
655         struct resource *res;
656         vm_paddr_t *p;
657         int error, i, rid;
658
659         /*
660          * We use the dump_avail[] array rather than phys_avail[] for
661          * the memory map as phys_avail[] contains holes for kernel
662          * memory, page 0, the message buffer, and the dcons buffer.
663          * We test the end address in the loop instead of the start
664          * since the start address for the first segment is 0.
665          *
666          * XXX: It would be preferable to use the SMAP if it exists
667          * instead since if the SMAP is very fragmented we may not
668          * include some memory regions in dump_avail[] and phys_avail[].
669          */
670         for (i = 0, p = dump_avail; p[1] != 0; i++, p += 2) {
671                 rid = i;
672 #ifdef PAE
673                 /*
674                  * Resources use long's to track resources, so we can't
675                  * include memory regions above 4GB.
676                  */
677                 if (p[0] >= ~0ul)
678                         break;
679 #endif
680                 error = bus_set_resource(dev, SYS_RES_MEMORY, rid, p[0],
681                     p[1] - p[0]);
682                 if (error)
683                         panic("ram_attach: resource %d failed set with %d", i,
684                             error);
685                 res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 0);
686                 if (res == NULL)
687                         panic("ram_attach: resource %d failed to attach", i);
688         }
689         return (0);
690 }
691
692 static device_method_t ram_methods[] = {
693         /* Device interface */
694         DEVMETHOD(device_identify,      ram_identify),
695         DEVMETHOD(device_probe,         ram_probe),
696         DEVMETHOD(device_attach,        ram_attach),
697         { 0, 0 }
698 };
699
700 static driver_t ram_driver = {
701         "ram",
702         ram_methods,
703         1,              /* no softc */
704 };
705
706 static devclass_t ram_devclass;
707
708 DRIVER_MODULE(ram, nexus, ram_driver, ram_devclass, 0, 0);
709
710 #ifdef DEV_ISA
711 /*
712  * Placeholder which claims PnP 'devices' which describe system
713  * resources.
714  */
715 static struct isa_pnp_id sysresource_ids[] = {
716         { 0x010cd041 /* PNP0c01 */, "System Memory" },
717         { 0x020cd041 /* PNP0c02 */, "System Resource" },
718         { 0 }
719 };
720
721 static int
722 sysresource_probe(device_t dev)
723 {
724         int     result;
725
726         if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, sysresource_ids)) <= 0) {
727                 device_quiet(dev);
728         }
729         return(result);
730 }
731
732 static int
733 sysresource_attach(device_t dev)
734 {
735         return(0);
736 }
737
738 static device_method_t sysresource_methods[] = {
739         /* Device interface */
740         DEVMETHOD(device_probe,         sysresource_probe),
741         DEVMETHOD(device_attach,        sysresource_attach),
742         DEVMETHOD(device_detach,        bus_generic_detach),
743         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
744         DEVMETHOD(device_suspend,       bus_generic_suspend),
745         DEVMETHOD(device_resume,        bus_generic_resume),
746         { 0, 0 }
747 };
748
749 static driver_t sysresource_driver = {
750         "sysresource",
751         sysresource_methods,
752         1,              /* no softc */
753 };
754
755 static devclass_t sysresource_devclass;
756
757 DRIVER_MODULE(sysresource, isa, sysresource_driver, sysresource_devclass, 0, 0);
758 #endif /* DEV_ISA */