Question about resource allocation
John Baldwin
jhb at freebsd.org
Wed Apr 16 14:47:10 UTC 2008
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
More information about the freebsd-acpi
mailing list