From owner-svn-src-head@FreeBSD.ORG Fri Oct 29 14:33:07 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0BF1D106566C; Fri, 29 Oct 2010 14:33:07 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from mail-qy0-f175.google.com (mail-qy0-f175.google.com [209.85.216.175]) by mx1.freebsd.org (Postfix) with ESMTP id 6E5E28FC1C; Fri, 29 Oct 2010 14:33:06 +0000 (UTC) Received: by qyk7 with SMTP id 7so6047932qyk.13 for ; Fri, 29 Oct 2010 07:33:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=NysACTbN7FO+M4EyS0O/TPolq4ii6KadP0mgCfD+ChE=; b=buvDcUQeeJC7D+t1h1bet/H/vF8E2PEk3OtbHAEZ3KCRO0C22OBwKjxflQ2/Ni8/2N rxd36ag9A0t19oYPHIzKHhPJwMU5IIfXGDmEUR6GxdrgTY84a2e+sKwl/ABfjBXgE2Qi cWRGA0OTdRTK7veQnsBejm1uhasXP3x7kXjTA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=lX9V+DcxIT8s19Cdbs7DZCRgV9+qxKr7+nJhjxqonudkVEyCPgDxfx/SyhJMWlqk3o LsWeRTPVSrLwMQqkrA5npw434YCYyEwv02/Kg5lUXfCEDG9Q296Trtmmpfaa4tZzMsoi eQXJJulY3x/V26czAxYvzV8sNXF0JNk6UQ5TU= MIME-Version: 1.0 Received: by 10.229.97.68 with SMTP id k4mr11898523qcn.261.1288362785353; Fri, 29 Oct 2010 07:33:05 -0700 (PDT) Sender: asmrookie@gmail.com Received: by 10.229.237.9 with HTTP; Fri, 29 Oct 2010 07:33:05 -0700 (PDT) In-Reply-To: <201010291026.20252.jhb@freebsd.org> References: <201010281631.o9SGVdtZ014923@svn.freebsd.org> <201010290944.53628.jhb@freebsd.org> <201010291026.20252.jhb@freebsd.org> Date: Fri, 29 Oct 2010 16:33:05 +0200 X-Google-Sender-Auth: VR4uMcgmy1x2_28q_oeCQktzVdg Message-ID: From: Attilio Rao To: John Baldwin Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r214457 - in head/sys: amd64/amd64 conf i386/i386 x86/x86 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Oct 2010 14:33:07 -0000 2010/10/29 John Baldwin : > On Friday, October 29, 2010 10:17:23 am Attilio Rao wrote: >> 2010/10/29 John Baldwin : >> > On Thursday, October 28, 2010 8:25:38 pm Attilio Rao wrote: >> >> 2010/10/28 John Baldwin : >> >> > On Thursday, October 28, 2010 4:28:12 pm Attilio Rao wrote: >> >> >> 2010/10/28 John Baldwin : >> >> >> > On Thursday, October 28, 2010 1:21:34 pm Attilio Rao wrote: >> >> >> >> 2010/10/28 John Baldwin : >> >> >> >> > On Thursday, October 28, 2010 12:31:39 pm Attilio Rao wrote: >> >> >> >> >> Author: attilio >> >> >> >> >> Date: Thu Oct 28 16:31:39 2010 >> >> >> >> >> New Revision: 214457 >> >> >> >> >> URL: http://svn.freebsd.org/changeset/base/214457 >> >> >> >> >> >> >> >> >> >> Log: >> >> >> >> >> =C2=A0 Merge nexus.c from amd64 and i386 to x86 subtree. >> >> >> >> >> >> >> >> >> >> =C2=A0 Sponsored by: =C2=A0 =C2=A0 =C2=A0 Sandvine Incorpora= ted >> >> >> >> >> =C2=A0 Tested by: =C2=A0gianni >> >> >> >> >> >> >> >> >> > >> >> >> >> > It would be better to merge these two routines. =C2=A0The loa= der now passes >> >> > the >> >> >> >> > smap to i386 kernels as well, so ram_attach() should probably= be >> >> > changed to >> >> >> >> > try the amd64 approach first and if that fails fall back to u= sing the >> >> >> >> > phys_avail[] array instead. >> >> >> >> >> >> >> >> What do you think about this patch?: >> >> >> >> Index: nexus.c >> >> >> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> >> >> >> --- nexus.c =C2=A0 =C2=A0 (revision 214457) >> >> >> >> +++ nexus.c =C2=A0 =C2=A0 (working copy) >> >> >> >> @@ -52,9 +52,7 @@ >> >> >> >> =C2=A0#include >> >> >> >> =C2=A0#include >> >> >> >> =C2=A0#include >> >> >> >> -#ifdef __amd64__ >> >> >> >> =C2=A0#include >> >> >> >> -#endif >> >> >> >> =C2=A0#include >> >> >> >> =C2=A0#include >> >> >> >> =C2=A0#include >> >> >> >> @@ -67,12 +65,10 @@ >> >> >> >> =C2=A0#include >> >> >> >> =C2=A0#include >> >> >> >> >> >> >> >> -#ifdef __amd64__ >> >> >> >> =C2=A0#include >> >> >> >> -#include >> >> >> >> -#endif >> >> >> >> =C2=A0#include >> >> >> >> =C2=A0#include >> >> >> >> +#include >> >> >> >> >> >> >> >> =C2=A0#ifdef DEV_APIC >> >> >> >> =C2=A0#include "pcib_if.h" >> >> >> >> @@ -89,11 +85,13 @@ >> >> >> >> =C2=A0#include >> >> >> >> >> >> >> >> =C2=A0#ifdef __amd64__ >> >> >> >> -#define =C2=A0 =C2=A0 =C2=A0 =C2=A0RMAN_BUS_SPACE_IO =C2=A0 = =C2=A0 =C2=A0 AMD64_BUS_SPACE_IO >> >> >> >> -#define =C2=A0 =C2=A0 =C2=A0 =C2=A0RMAN_BUS_SPACE_MEM =C2=A0 = =C2=A0 =C2=A0AMD64_BUS_SPACE_MEM >> >> >> >> +#define =C2=A0 =C2=A0 =C2=A0 =C2=A0X86_BUS_SPACE_IO =C2=A0 =C2= =A0 =C2=A0 =C2=A0AMD64_BUS_SPACE_IO >> >> >> >> +#define =C2=A0 =C2=A0 =C2=A0 =C2=A0X86_BUS_SPACE_MEM =C2=A0 = =C2=A0 =C2=A0 AMD64_BUS_SPACE_MEM >> >> >> >> +#define =C2=A0 =C2=A0 =C2=A0 =C2=A0ELF_KERN_STR =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0"elf64 kernel" >> >> >> >> =C2=A0#else >> >> >> >> -#define =C2=A0 =C2=A0 =C2=A0 =C2=A0RMAN_BUS_SPACE_IO =C2=A0 = =C2=A0 =C2=A0 I386_BUS_SPACE_IO >> >> >> >> -#define =C2=A0 =C2=A0 =C2=A0 =C2=A0RMAN_BUS_SPACE_MEM =C2=A0 = =C2=A0 =C2=A0I386_BUS_SPACE_MEM >> >> >> >> +#define =C2=A0 =C2=A0 =C2=A0 =C2=A0X86_BUS_SPACE_IO =C2=A0 =C2= =A0 =C2=A0 =C2=A0I386_BUS_SPACE_IO >> >> >> >> +#define =C2=A0 =C2=A0 =C2=A0 =C2=A0X86_BUS_SPACE_MEM =C2=A0 = =C2=A0 =C2=A0 I386_BUS_SPACE_MEM >> >> >> >> +#define =C2=A0 =C2=A0 =C2=A0 =C2=A0ELF_KERN_STR =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0"elf32 kernel" >> >> >> >> =C2=A0#endif >> >> >> >> @@ -701,16 +699,11 @@ >> >> >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 panic("ram_attach: resource %d failed to attach", >> >> > rid); >> >> >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rid++; >> >> >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 } >> >> >> >> - =C2=A0 =C2=A0 =C2=A0 return (0); >> >> >> >> -} >> >> >> >> -#else >> >> >> >> -static int >> >> >> >> -ram_attach(device_t dev) >> >> >> >> -{ >> >> >> >> - =C2=A0 =C2=A0 =C2=A0 struct resource *res; >> >> >> >> - =C2=A0 =C2=A0 =C2=A0 vm_paddr_t *p; >> >> >> >> - =C2=A0 =C2=A0 =C2=A0 int error, i, rid; >> >> >> >> >> >> >> >> + =C2=A0 =C2=A0 =C2=A0 /* If at least one smap attached, return= . */ >> >> >> >> + =C2=A0 =C2=A0 =C2=A0 if (rid !=3D 0) >> >> >> >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return (0); >> >> >> >> + >> >> >> > >> >> >> > Perhaps this instead: >> >> >> > >> >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0/* If we found an SMAP, return. */ >> >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0if (smapbase !=3D NULL) >> >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (0= ); >> >> >> >> >> >> No, I don't think this check is right, smapbase will always be != =3D NULL >> >> >> (otherwise the code panics). >> >> > >> >> > Oh, that needs to be fixed then. =C2=A0It can be NULL on i386 with = an old loader >> >> > (or on a really old machine without an SMAP). =C2=A0The amd64 nexus= code could >> >> > assume it would never be NULL, but i386 cannot. >> >> > >> >> > It should probably more closely match what i386 does during the mem= ory probe >> >> > which is: >> >> > >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0kmdp =3D search("elf kernel"); >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0if (kmdp =3D=3D NULL) >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0kmdp =3D sea= rch("elfXX kernel"); >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0if (kmdp !=3D NULL) >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0smapbase =3D= preload_search(...); >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0else >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0smapbase =3D= NULL; >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0if (smapbase !=3D NULL) { >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for (smap = =3D ...) { >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> >> > >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (0); >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> >> > >> >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0/* fall through to old i386 code using p= hys_avail[] */ >> >> >> >> This further patch should address your concerns about nexus.c: >> >> Index: nexus.c >> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> >> --- nexus.c =C2=A0 =C2=A0 (revision 214457) >> >> +++ nexus.c =C2=A0 =C2=A0 (working copy) >> >> @@ -52,9 +52,7 @@ >> >> =C2=A0#include >> >> =C2=A0#include >> >> =C2=A0#include >> >> -#ifdef __amd64__ >> >> =C2=A0#include >> >> -#endif >> >> =C2=A0#include >> >> =C2=A0#include >> >> =C2=A0#include >> >> @@ -67,12 +65,10 @@ >> >> =C2=A0#include >> >> =C2=A0#include >> >> >> >> -#ifdef __amd64__ >> >> =C2=A0#include >> >> -#include >> >> -#endif >> >> =C2=A0#include >> >> =C2=A0#include >> >> +#include >> >> >> >> =C2=A0#ifdef DEV_APIC >> >> =C2=A0#include "pcib_if.h" >> >> @@ -89,13 +85,15 @@ >> >> =C2=A0#include >> >> >> >> =C2=A0#ifdef __amd64__ >> >> -#define =C2=A0 =C2=A0 =C2=A0 =C2=A0RMAN_BUS_SPACE_IO =C2=A0 =C2=A0 = =C2=A0 AMD64_BUS_SPACE_IO >> >> -#define =C2=A0 =C2=A0 =C2=A0 =C2=A0RMAN_BUS_SPACE_MEM =C2=A0 =C2=A0 = =C2=A0AMD64_BUS_SPACE_MEM >> >> +#define =C2=A0 =C2=A0 =C2=A0 =C2=A0BUS_SPACE_IO =C2=A0 =C2=A0AMD64_B= US_SPACE_IO >> >> +#define =C2=A0 =C2=A0 =C2=A0 =C2=A0BUS_SPACE_MEM =C2=A0 AMD64_BUS_SP= ACE_MEM >> >> =C2=A0#else >> >> -#define =C2=A0 =C2=A0 =C2=A0 =C2=A0RMAN_BUS_SPACE_IO =C2=A0 =C2=A0 = =C2=A0 I386_BUS_SPACE_IO >> >> -#define =C2=A0 =C2=A0 =C2=A0 =C2=A0RMAN_BUS_SPACE_MEM =C2=A0 =C2=A0 = =C2=A0I386_BUS_SPACE_MEM >> >> +#define =C2=A0 =C2=A0 =C2=A0 =C2=A0BUS_SPACE_IO =C2=A0 =C2=A0I386_BU= S_SPACE_IO >> >> +#define =C2=A0 =C2=A0 =C2=A0 =C2=A0BUS_SPACE_MEM =C2=A0 I386_BUS_SPA= CE_MEM >> >> =C2=A0#endif >> >> >> >> +#define =C2=A0 =C2=A0 =C2=A0 =C2=A0ELF_KERN_STR =C2=A0 =C2=A0("elf"_= _XSTRING(__ELF_WORD_SIZE)" kernel") >> >> + >> >> =C2=A0static MALLOC_DEFINE(M_NEXUSDEV, "nexusdev", "Nexus device"); >> >> >> >> =C2=A0#define DEVTONX(dev) =C2=A0 ((struct nexus_device *)device_get_= ivars(dev)) >> >> @@ -435,7 +433,7 @@ >> >> =C2=A0#else >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rman_set_bush= andle(r, rman_get_start(r)); >> >> =C2=A0#endif >> >> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rman_set_bustag(r,= RMAN_BUS_SPACE_IO); >> >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rman_set_bustag(r,= BUS_SPACE_IO); >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break; >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 case SYS_RES_MEMORY: >> >> =C2=A0#ifdef PC98 >> >> @@ -446,7 +444,7 @@ >> >> =C2=A0#endif >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vaddr =3D pma= p_mapdev(rman_get_start(r), rman_get_size(r)); >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rman_set_virt= ual(r, vaddr); >> >> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rman_set_bustag(r,= RMAN_BUS_SPACE_MEM); >> >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rman_set_bustag(r,= BUS_SPACE_MEM); >> >> =C2=A0#ifdef PC98 >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* PC-98: the= type of bus_space_handle_t is the structure. */ >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bh->bsh_base = =3D (bus_addr_t) vaddr; >> >> @@ -668,48 +666,45 @@ >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 return (0); >> >> =C2=A0} >> >> >> >> -#ifdef __amd64__ >> >> =C2=A0static int >> >> =C2=A0ram_attach(device_t dev) >> >> =C2=A0{ >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 struct bios_smap *smapbase, *smap, *smape= nd; >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 struct resource *res; >> >> + =C2=A0 =C2=A0 =C2=A0 vm_paddr_t *p; >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 caddr_t kmdp; >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 uint32_t smapsize; >> >> - =C2=A0 =C2=A0 =C2=A0 int error, rid; >> >> + =C2=A0 =C2=A0 =C2=A0 int error, i, rid; >> >> >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Retrieve the system memory map from th= e loader. */ >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 kmdp =3D preload_search_by_type("elf kern= el"); >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (kmdp =3D=3D NULL) >> >> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 kmdp =3D preload_s= earch_by_type("elf64 kernel"); >> >> - =C2=A0 =C2=A0 =C2=A0 smapbase =3D (struct bios_smap *)preload_searc= h_info(kmdp, >> >> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 MODINFO_METADATA | MODINFOMD_SMA= P); >> >> - =C2=A0 =C2=A0 =C2=A0 smapsize =3D *((u_int32_t *)smapbase - 1); >> >> - =C2=A0 =C2=A0 =C2=A0 smapend =3D (struct bios_smap *)((uintptr_t)sm= apbase + smapsize); >> >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 kmdp =3D preload_s= earch_by_type(ELF_KERN_STR); >> >> + =C2=A0 =C2=A0 =C2=A0 if (kmdp !=3D NULL) { >> >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 smapbase =3D (stru= ct bios_smap *)preload_search_info(kmdp, >> >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 MODI= NFO_METADATA | MODINFOMD_SMAP); >> >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 smapsize =3D *((u_= int32_t *)smapbase - 1); >> >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 smapend =3D (struc= t bios_smap *)((uintptr_t)smapbase + smapsize); >> > >> > I think this doesn't check for the case that smapbase is NULL. =C2=A0I= would >> > expect kmdp to always be non-NULL in practice (it just means we have a >> > kernel). =C2=A0However, the preload_search_info() can fail when bootin= g on an old >> > machine without an SMAP or an old loader that doesn't pass the SMAP to= i386. >> >> I don't understand where is the problem. >> smap is only used when it is consistent in that patch, otherwise it is >> not used and fallsthrough the physavail[] approach. >> It doesn't need to be set to NULL or checked. >> >> I guess that you want to patch the file and see how it looks like, >> will be easier to review than inline .diff, in this case. > > The preload_search_info() can fail and return NULL (old machine with no S= MAP > or an older /boot/loader on i386). =C2=A0Then when you do this: > > =C2=A0 =C2=A0 =C2=A0 =C2=A0smapsize =3D *((u_int32_t *)smapbase - 1); > > the kernel will panic. Ah, I thought that it could be failing only with a NULL kmdp. That patch should fix it then: Index: nexus.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- nexus.c (revision 214457) +++ nexus.c (working copy) @@ -52,9 +52,7 @@ #include #include #include -#ifdef __amd64__ #include -#endif #include #include #include @@ -67,12 +65,10 @@ #include #include -#ifdef __amd64__ #include -#include -#endif #include #include +#include #ifdef DEV_APIC #include "pcib_if.h" @@ -89,13 +85,15 @@ #include #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 @@ #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 @@ #endif vaddr =3D 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 =3D (bus_addr_t) vaddr; @@ -668,48 +666,48 @@ 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; + int error, i, rid; /* Retrieve the system memory map from the loader. */ kmdp =3D preload_search_by_type("elf kernel"); if (kmdp =3D=3D NULL) - kmdp =3D preload_search_by_type("elf64 kernel"); - smapbase =3D (struct bios_smap *)preload_search_info(kmdp, - MODINFO_METADATA | MODINFOMD_SMAP); - smapsize =3D *((u_int32_t *)smapbase - 1); - smapend =3D (struct bios_smap *)((uintptr_t)smapbase + smapsize); + kmdp =3D preload_search_by_type(ELF_KERN_STR); + if (kmdp !=3D NULL) + smapbase =3D (struct bios_smap *)preload_search_info(kmdp, + MODINFO_METADATA | MODINFOMD_SMAP); + else + smapbase =3D NULL; + if (smapbase !=3D NULL) { + smapsize =3D *((u_int32_t *)smapbase - 1); + smapend =3D (struct bios_smap *)((uintptr_t)smapbase + smap= size); - rid =3D 0; - for (smap =3D smapbase; smap < smapend; smap++) { - if (smap->type !=3D SMAP_TYPE_MEMORY || smap->length =3D=3D= 0) - continue; - error =3D 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 =3D bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 0= ); - if (res =3D=3D NULL) - panic("ram_attach: resource %d failed to attach", r= id); - rid++; + rid =3D 0; + for (smap =3D smapbase; smap < smapend; smap++) { + if (smap->type !=3D SMAP_TYPE_MEMORY || + smap->length =3D=3D 0) + continue; + error =3D 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 =3D bus_alloc_resource_any(dev, SYS_RES_MEMORY,= &rid, + 0); + if (res =3D=3D 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 @@ -743,7 +741,6 @@ } return (0); } -#endif static device_method_t ram_methods[] =3D { /* Device interface */