From owner-freebsd-hackers@FreeBSD.ORG Wed Mar 17 07:13:50 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A699116A4CE for ; Wed, 17 Mar 2004 07:13:50 -0800 (PST) Received: from mail3.speakeasy.net (mail3.speakeasy.net [216.254.0.203]) by mx1.FreeBSD.org (Postfix) with ESMTP id 84DE443D2F for ; Wed, 17 Mar 2004 07:13:50 -0800 (PST) (envelope-from jhb@FreeBSD.org) Received: (qmail 1261 invoked from network); 17 Mar 2004 15:13:49 -0000 Received: from dsl027-160-063.atl1.dsl.speakeasy.net (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender ) encrypted SMTP for ; 17 Mar 2004 15:13:49 -0000 Received: from 10.50.40.205 (gw1.twc.weather.com [216.133.140.1]) by server.baldwin.cx (8.12.10/8.12.10) with ESMTP id i2HFDj28070823; Wed, 17 Mar 2004 10:13:45 -0500 (EST) (envelope-from jhb@FreeBSD.org) From: John Baldwin To: freebsd-hackers@FreeBSD.org Date: Wed, 17 Mar 2004 10:15:27 -0500 User-Agent: KMail/1.6 References: <20040316150321.GA4900@tyler> In-Reply-To: <20040316150321.GA4900@tyler> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200403171015.27710.jhb@FreeBSD.org> X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on server.baldwin.cx cc: thefly Subject: Re: bus_alloc_resource() returns NULL, but why? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Mar 2004 15:13:50 -0000 On Tuesday 16 March 2004 10:03 am, thefly wrote: > Hi, i'm currently porting QuanCom PWDOG1 Watchdog card to FreeBSD, (you > can find the current code at http://chiakotay.nexlab.it/acaro/pwdog.c). > I defined my softc struct: > > struct pwdog1_softc { > bus_space_tag_t bst; > bus_space_handle_t bsh; > struct resource *res; > int rid; > }; > > In my attach() function i do NewBus initialization: > > sc = (struct pwdog1_softc *) device_get_softc(dev); > > sc->rid = 0; > sc->res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->rid, 0, ~0, 1, > RF_ACTIVE); sc->bst = rman_get_bustag(sc->res); > sc->bsh = rman_get_bushandle(sc->res); > > but the problem is that bus_alloc_resource() returns NULL. I don't have > a clue about WHY it should. It's running on: FreeBSD 5.2.1-RELEASE with > GENERIC kernel in a dual pentium 200MMX. > > Thanks in advance The rid needs to tell the bus driver which BAR you are using for this resource, thus, if the IO ports are in BAR 0, you should do: sc->rid = PCIR_BAR(0); Before the call to bus_alloc_resource(). If it's BAR 1, use PCIR_BAR(1), etc. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org