Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Mar 2004 10:15:27 -0500
From:      John Baldwin <jhb@FreeBSD.org>
To:        freebsd-hackers@FreeBSD.org
Cc:        thefly <thefly@acaro.org>
Subject:   Re: bus_alloc_resource() returns NULL, but why?
Message-ID:  <200403171015.27710.jhb@FreeBSD.org>
In-Reply-To: <20040316150321.GA4900@tyler>
References:  <20040316150321.GA4900@tyler>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <jhb@FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200403171015.27710.jhb>