From owner-freebsd-acpi@FreeBSD.ORG Wed Apr 16 14:47:10 2008 Return-Path: Delivered-To: freebsd-acpi@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8D120106564A for ; Wed, 16 Apr 2008 14:47:10 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 8270B8FC13 for ; Wed, 16 Apr 2008 14:47:10 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from zion.baldwin.cx (unknown [208.65.88.170]) by elvis.mu.org (Postfix) with ESMTP id 3E0CA1A4D7C; Wed, 16 Apr 2008 07:47:10 -0700 (PDT) From: John Baldwin To: freebsd-acpi@freebsd.org Date: Wed, 16 Apr 2008 09:15:03 -0400 User-Agent: KMail/1.9.7 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200804160915.04328.jhb@freebsd.org> Cc: Alexey Tarasov Subject: Re: Question about resource allocation X-BeenThere: freebsd-acpi@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: ACPI and power management development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Apr 2008 14:47:10 -0000 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