Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Sep 2008 11:05:58 -0700
From:      Nate Lawson <nate@root.org>
To:        Gavin Atkinson <gavin@FreeBSD.org>
Cc:        freebsd-acpi@FreeBSD.org
Subject:   Re: Writing a driver: how do I get resources?
Message-ID:  <48D93006.7050400@root.org>
In-Reply-To: <1222173505.80882.15.camel@buffy.york.ac.uk>
References:  <1222173505.80882.15.camel@buffy.york.ac.uk>

next in thread | previous in thread | raw e-mail | index | archive | help
Gavin Atkinson wrote:
> Please forgive me if this email makes very little sense: I've never
> really looked at how ACPI works from a driver's perspective, so don't
> really know if what I'm trying to do is even correct.
> 
> I'm expanding the acpi_sony driver to cover the PNP ID SNY6001.  When I
> simply claim it by returning 0 from the probe, I get the following I/O range:
> 
> acpi_sony0: <Sony programmable I/O> port 0-0x1f on acpi0
>
> However, if I'm reading the AML[1] and Linux drivers[2] correctly, this
> is not the correct range.  It appears that the _PRS method offers a
> choice of four I/O ranges and four IRQs, one of which is then selected
> by evaluating _SRS.  None of them are 0-0x1f.
> 
> Firstly, does that make sense?  Secondly, how do I do this from a
> driver?  I can't see any other drivers that seem to get this involved in
> ACPI, indeed the only mention of evaluating _PRS is within the ACPI code
> itself.

Generally resources are the responsibility of the parent bus.  So for
various devices (ethernet, usb, etc.) attached to a pci bus, the
acpi_pci driver sets up the resources correctly for them.

The Sony driver is somewhat special in that it's not on a standard bus,
it's proprietary.  Same goes for the IBM, Panasonic, etc. power
management drivers.  For Windows, the OEM even writes this driver, not
Microsoft.

Since there's no parent bus, the driver itself has to set up its
resources.  You're seeing that this is just not being done.  Normally
the BIOS initializes such devices with reasonable values, but in your
case it hasn't.

FreeBSD does not yet have support routines for _SRS (set resources).
For non-standard devices, we just use _CRS (current resources) and trust
that the BIOS set things up well.  Obviously, it would be good to have
some conversion routine that read _CRS and _PRS and provided a bus
method to wrap _SRS.  Then all these proprietary drivers could ask for
resources in a common way.  This would be the FreeBSD Approach.

The Linux approach is to cut/paste the low-level routines into each
driver (this time from the PCI driver) and have them grok ACPI resources
directly.  This is not a good approach but is the one the Linux
sony-laptop driver takes.

If you talk to John Baldwin, he may have some ideas how to implement
_SRS support in a general way.  I'm sure he'd love the help.  If you
don't want to do that, you'll have to implement methods similar to the
Linux sony_pic_add(), sony_pic_enable(), etc. in the FreeBSD acpi_sony.c
driver.  This might still be a useful first step to understand how to
generalize these routines.

-- 
Nate



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