Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Apr 2008 09:15:03 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-acpi@freebsd.org
Cc:        Alexey Tarasov <glorgster@gmail.com>
Subject:   Re: Question about resource allocation
Message-ID:  <200804160915.04328.jhb@freebsd.org>
In-Reply-To: <db2194de0804102211m5cb69480rc9d2a12684184bf@mail.gmail.com>
References:  <db2194de0804102211m5cb69480rc9d2a12684184bf@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Friday 11 April 2008 01:11:51 am Alexey Tarasov wrote:
> Hi,
>
> I'm trying to update spic and acpi_sony drivers, looking to Linux
> sony_laptop driver.
>
> Now I'm at allocating IO ports resource stage.
> spic driver on FreeBSD uses bus_alloc_resources() with default for bus
> values (0, ~0) for this purpose
> ----
>
> 	if (!(sc->port_res = bus_alloc_resource(sc->dev, SYS_RES_IOPORT,
> 		&sc->port_rid, 0, ~0, 5, RF_ACTIVE))) {
> 		device_printf(sc->dev,"Couldn't map I/O\n");
> 		return (ENXIO);
> 	}
>
> ----
>
> sony_laptop  enumerates resources of device using acpi_walk_resources()
> function and then calls request_region() for all found IO regions. First
> non fail result will be used later in working with SPIC.
>
> So question: is it better to use approach from sony_laptop. If yes, then
> how to walk resources (I've not found analog of acpi_walk_resource function
> in FreeBSD)

The IO resources will be present at rids 0 ... N so to do what the Sony device 
does you can do something like this:

	int rid;

	for (rid = 0; rid++;) {
		if (bus_get_resource(sc->dev, SYS_RES_IOPORT, rid, NULL, NULL) != 0)
			break;
	}

	/* 'rid' is now the resource ID of the first invalid resource. */
	if (rid == 0)
		/* no valid IO port resources, so error out */
	sc->port_rid = rid - 1;

	sc->port_res = bus_alloc_resource_any(sc->dev, SYS_RES_IOPORT, &sc->port_rid,
	    RF_ACTIVE);
	if (sc->port_res == NULL) {
		device_printf(sc->dev, "Couldn't map I/O\n");
		return (ENXIO);
	}

etc.

-- 
John Baldwin



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