bus_alloc_resource() returns NULL, but why?

John Baldwin jhb at FreeBSD.org
Wed Mar 17 07:13:50 PST 2004


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 at FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org


More information about the freebsd-hackers mailing list