Author: attilio
Date: Fri Nov 19 17:49:16 2010
New Revision: 215539
URL: http://svn.freebsd.org/changeset/base/215539

Log:
  MFC r214457,214515,214584,214676,214681,214686 by jhb, nyan and me:
  Move nexus in x86 and cleaning it up.
  
  Sponsored by: Sandvine Incorporated

Added:
  stable/8/sys/x86/x86/nexus.c
     - copied, changed from r214457, head/sys/x86/x86/nexus.c
Deleted:
  stable/8/sys/amd64/amd64/nexus.c
  stable/8/sys/i386/i386/nexus.c
Modified:
  stable/8/sys/conf/files.amd64
  stable/8/sys/conf/files.i386
  stable/8/sys/conf/files.pc98
  stable/8/sys/i386/i386/machdep.c
  stable/8/sys/pc98/include/bus.h
  stable/8/sys/pc98/pc98/busiosubr.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)
  stable/8/sys/dev/xen/xenpci/   (props changed)

Modified: stable/8/sys/conf/files.amd64
==============================================================================
--- stable/8/sys/conf/files.amd64       Fri Nov 19 17:49:08 2010        
(r215538)
+++ stable/8/sys/conf/files.amd64       Fri Nov 19 17:49:16 2010        
(r215539)
@@ -123,7 +123,6 @@ amd64/amd64/minidump_machdep.c      standard
 amd64/amd64/mp_machdep.c       optional        smp
 amd64/amd64/mp_watchdog.c      optional        mp_watchdog smp
 amd64/amd64/mpboot.S           optional        smp
-amd64/amd64/nexus.c            standard
 amd64/amd64/pmap.c             standard
 amd64/amd64/prof_machdep.c     optional        profiling-routine
 amd64/amd64/sigtramp.S         standard
@@ -319,3 +318,4 @@ x86/x86/mca.c                       standard
 x86/x86/mptable.c              optional        mptable
 x86/x86/mptable_pci.c          optional        mptable pci
 x86/x86/msi.c                  optional        pci
+x86/x86/nexus.c                        standard

Modified: stable/8/sys/conf/files.i386
==============================================================================
--- stable/8/sys/conf/files.i386        Fri Nov 19 17:49:08 2010        
(r215538)
+++ stable/8/sys/conf/files.i386        Fri Nov 19 17:49:16 2010        
(r215539)
@@ -289,7 +289,6 @@ i386/xen/mp_machdep.c               optional xen smp
 i386/i386/mp_watchdog.c                optional mp_watchdog smp
 i386/i386/mpboot.s             optional smp native
 i386/xen/mptable.c             optional apic xen
-i386/i386/nexus.c              standard
 i386/i386/perfmon.c            optional perfmon
 i386/i386/pmap.c               optional native
 i386/xen/pmap.c                        optional xen
@@ -394,3 +393,4 @@ x86/x86/mca.c                       standard
 x86/x86/mptable.c              optional apic native
 x86/x86/mptable_pci.c          optional apic pci
 x86/x86/msi.c                  optional apic pci
+x86/x86/nexus.c                        standard

Modified: stable/8/sys/conf/files.pc98
==============================================================================
--- stable/8/sys/conf/files.pc98        Fri Nov 19 17:49:08 2010        
(r215538)
+++ stable/8/sys/conf/files.pc98        Fri Nov 19 17:49:16 2010        
(r215539)
@@ -158,7 +158,6 @@ i386/i386/mp_clock.c                optional smp
 i386/i386/mp_machdep.c         optional smp
 i386/i386/mp_watchdog.c                optional mp_watchdog smp
 i386/i386/mpboot.s             optional smp
-i386/i386/nexus.c              standard
 i386/i386/perfmon.c            optional perfmon
 i386/i386/pmap.c               standard
 i386/i386/ptrace_machdep.c     standard
@@ -258,3 +257,4 @@ x86/x86/mca.c                       standard
 x86/x86/mptable.c              optional apic
 x86/x86/mptable_pci.c          optional apic pci
 x86/x86/msi.c                  optional apic pci
+x86/x86/nexus.c                        standard

Modified: stable/8/sys/i386/i386/machdep.c
==============================================================================
--- stable/8/sys/i386/i386/machdep.c    Fri Nov 19 17:49:08 2010        
(r215538)
+++ stable/8/sys/i386/i386/machdep.c    Fri Nov 19 17:49:16 2010        
(r215539)
@@ -1957,7 +1957,7 @@ add_smap_entry(struct bios_smap *smap, v
                return (1);
 
 #ifndef PAE
-       if (smap->base >= 0xffffffff) {
+       if (smap->base > 0xffffffff) {
                printf("%uK of memory above 4GB ignored\n",
                    (u_int)(smap->length / 1024));
                return (1);

Modified: stable/8/sys/pc98/include/bus.h
==============================================================================
--- stable/8/sys/pc98/include/bus.h     Fri Nov 19 17:49:08 2010        
(r215538)
+++ stable/8/sys/pc98/include/bus.h     Fri Nov 19 17:49:16 2010        
(r215539)
@@ -158,8 +158,8 @@ struct bus_space_access_methods {
  * Access methods for bus resources and address space.
  */
 struct bus_space_tag {
-#define        BUS_SPACE_IO    0
-#define        BUS_SPACE_MEM   1
+#define        BUS_SPACE_TAG_IO        0
+#define        BUS_SPACE_TAG_MEM       1
        u_int   bs_tag;                 /* bus space flags */
 
        struct bus_space_access_methods bs_da;  /* direct access */

Modified: stable/8/sys/pc98/pc98/busiosubr.c
==============================================================================
--- stable/8/sys/pc98/pc98/busiosubr.c  Fri Nov 19 17:49:08 2010        
(r215538)
+++ stable/8/sys/pc98/pc98/busiosubr.c  Fri Nov 19 17:49:16 2010        
(r215539)
@@ -63,7 +63,7 @@ _BUS_SPACE_CALL_FUNCS_PROTO(SBUS_RA_mem,
 _BUS_SPACE_CALL_FUNCS_PROTO(SBUS_RA_mem,u_int32_t,4)
 
 struct bus_space_tag SBUS_io_space_tag = {
-       BUS_SPACE_IO,
+       BUS_SPACE_TAG_IO,
 
        /* direct bus access methods */
        {
@@ -81,7 +81,7 @@ struct bus_space_tag SBUS_io_space_tag =
 };
 
 struct bus_space_tag SBUS_mem_space_tag = {
-       BUS_SPACE_MEM,
+       BUS_SPACE_TAG_MEM,
 
        /* direct bus access methods */
        {
@@ -109,7 +109,7 @@ _BUS_SPACE_CALL_FUNCS_PROTO(NEPC_RA_io,u
 _BUS_SPACE_CALL_FUNCS_PROTO(NEPC_RA_io,u_int32_t,4)
 
 struct bus_space_tag NEPC_io_space_tag = {
-       BUS_SPACE_IO,
+       BUS_SPACE_TAG_IO,
 
        /* direct bus access methods */
        {
@@ -127,7 +127,7 @@ struct bus_space_tag NEPC_io_space_tag =
 };
 
 struct bus_space_tag NEPC_mem_space_tag = {
-       BUS_SPACE_MEM,
+       BUS_SPACE_TAG_MEM,
 
        /* direct bus access methods */
        {
@@ -256,7 +256,7 @@ i386_memio_subregion(bus_space_tag_t t, 
 
        pbase = pbsh->bsh_base + offset;
        switch (t->bs_tag) {
-       case BUS_SPACE_IO:
+       case BUS_SPACE_TAG_IO:
                if (pbsh->bsh_iatsz > 0) {
                        if (offset >= pbsh->bsh_iatsz || 
                            offset + size > pbsh->bsh_iatsz)
@@ -265,7 +265,7 @@ i386_memio_subregion(bus_space_tag_t t, 
                }
                break;
 
-       case BUS_SPACE_MEM:
+       case BUS_SPACE_TAG_MEM:
                if (pbsh->bsh_iatsz > 0)
                        return EINVAL;
                if (offset > pbsh->bsh_sz || offset + size > pbsh->bsh_sz)
@@ -282,7 +282,7 @@ i386_memio_subregion(bus_space_tag_t t, 
                return error;
 
        switch (t->bs_tag) {
-       case BUS_SPACE_IO:
+       case BUS_SPACE_TAG_IO:
                if (pbsh->bsh_iatsz > 0) {
                        for (i = 0; i < size; i ++)
                                bsh->bsh_iat[i] = pbsh->bsh_iat[i + offset];
@@ -295,7 +295,7 @@ i386_memio_subregion(bus_space_tag_t t, 
                }
                break;
 
-       case BUS_SPACE_MEM:
+       case BUS_SPACE_TAG_MEM:
                break;
        }
 

Copied and modified: stable/8/sys/x86/x86/nexus.c (from r214457, 
head/sys/x86/x86/nexus.c)
==============================================================================
--- head/sys/x86/x86/nexus.c    Thu Oct 28 16:31:39 2010        (r214457, copy 
source)
+++ stable/8/sys/x86/x86/nexus.c        Fri Nov 19 17:49:16 2010        
(r215539)
@@ -52,9 +52,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/systm.h>
 #include <sys/bus.h>
 #include <sys/kernel.h>
-#ifdef __amd64__
 #include <sys/linker.h>
-#endif
 #include <sys/malloc.h>
 #include <sys/module.h>
 #include <machine/bus.h>
@@ -67,12 +65,10 @@ __FBSDID("$FreeBSD$");
 #include <vm/pmap.h>
 #include <machine/pmap.h>
 
-#ifdef __amd64__
 #include <machine/metadata.h>
-#include <machine/pc/bios.h>
-#endif
 #include <machine/nexusvar.h>
 #include <machine/resource.h>
+#include <machine/pc/bios.h>
 
 #ifdef DEV_APIC
 #include "pcib_if.h"
@@ -89,13 +85,15 @@ __FBSDID("$FreeBSD$");
 #include <sys/rtprio.h>
 
 #ifdef __amd64__
-#define        RMAN_BUS_SPACE_IO       AMD64_BUS_SPACE_IO
-#define        RMAN_BUS_SPACE_MEM      AMD64_BUS_SPACE_MEM
+#define        BUS_SPACE_IO    AMD64_BUS_SPACE_IO
+#define        BUS_SPACE_MEM   AMD64_BUS_SPACE_MEM
 #else
-#define        RMAN_BUS_SPACE_IO       I386_BUS_SPACE_IO
-#define        RMAN_BUS_SPACE_MEM      I386_BUS_SPACE_MEM
+#define        BUS_SPACE_IO    I386_BUS_SPACE_IO
+#define        BUS_SPACE_MEM   I386_BUS_SPACE_MEM
 #endif
 
+#define        ELF_KERN_STR    ("elf"__XSTRING(__ELF_WORD_SIZE)" kernel")
+
 static MALLOC_DEFINE(M_NEXUSDEV, "nexusdev", "Nexus device");
 
 #define DEVTONX(dev)   ((struct nexus_device *)device_get_ivars(dev))
@@ -435,7 +433,7 @@ nexus_activate_resource(device_t bus, de
 #else
                rman_set_bushandle(r, rman_get_start(r));
 #endif
-               rman_set_bustag(r, RMAN_BUS_SPACE_IO);
+               rman_set_bustag(r, BUS_SPACE_IO);
                break;
        case SYS_RES_MEMORY:
 #ifdef PC98
@@ -446,7 +444,7 @@ nexus_activate_resource(device_t bus, de
 #endif
                vaddr = pmap_mapdev(rman_get_start(r), rman_get_size(r));
                rman_set_virtual(r, vaddr);
-               rman_set_bustag(r, RMAN_BUS_SPACE_MEM);
+               rman_set_bustag(r, BUS_SPACE_MEM);
 #ifdef PC98
                /* PC-98: the type of bus_space_handle_t is the structure. */
                bh->bsh_base = (bus_addr_t) vaddr;
@@ -668,12 +666,12 @@ ram_probe(device_t dev)
        return (0);
 }
 
-#ifdef __amd64__
 static int
 ram_attach(device_t dev)
 {
        struct bios_smap *smapbase, *smap, *smapend;
        struct resource *res;
+       vm_paddr_t *p;
        caddr_t kmdp;
        uint32_t smapsize;
        int error, rid;
@@ -681,69 +679,74 @@ ram_attach(device_t dev)
        /* 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 != SMAP_TYPE_MEMORY || 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++;
+               kmdp = preload_search_by_type(ELF_KERN_STR);  
+       if (kmdp != NULL)
+               smapbase = (struct bios_smap *)preload_search_info(kmdp,
+                   MODINFO_METADATA | MODINFOMD_SMAP);
+       else
+               smapbase = NULL;
+       if (smapbase != NULL) {
+               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 != SMAP_TYPE_MEMORY ||
+                           smap->length == 0)
+                               continue;
+#ifdef __i386__
+                       /*
+                        * Resources use long's to track resources, so
+                        * we can't include memory regions above 4GB.
+                        */
+                       if (smap->base > ~0ul)
+                               continue;
+#endif
+                       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);
        }
-       return (0);
-}
-#else
-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[].
+        * If the system map is not available, fall back to using
+        * dump_avail[].  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.
         */
-       for (i = 0, p = dump_avail; p[1] != 0; i++, p += 2) {
-               rid = i;
+       for (rid = 0, p = dump_avail; p[1] != 0; rid++, p += 2) {
 #ifdef PAE
                /*
                 * Resources use long's to track resources, so we can't
                 * include memory regions above 4GB.
                 */
-               if (p[0] >= ~0ul)
+               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,
+                       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", i);
+                       panic("ram_attach: resource %d failed to attach", rid);
        }
        return (0);
 }
-#endif
 
 static device_method_t ram_methods[] = {
        /* Device interface */
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to