Writing a driver: how do I get resources?

View: New views
7 Messages — Rating Filter:   Alert me  

Writing a driver: how do I get resources?

by Gavin Atkinson-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

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.

Lastly, I only have intermittent access to this laptop, so I apologise
if I can't test things quickly.

Thanks,

Gavin


[1] http://www-users.york.ac.uk/~ga9/sony-vgn-tz31wn.asl
[2] http://lxr.linux.no/linux+v2.6.26.5/drivers/misc/sony-laptop.c
_______________________________________________
freebsd-acpi@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-acpi
To unsubscribe, send any mail to "freebsd-acpi-unsubscribe@..."

Re: Writing a driver: how do I get resources?

by John Baldwin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday 23 September 2008 08:38:25 am Gavin Atkinson wrote:
> Hi all,
>
> 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.
>
> Lastly, I only have intermittent access to this laptop, so I apologise
> if I can't test things quickly.

Our ACPI driver isn't smart enough yet (AFAIK) to allocate new resources for a
device that doesn't have any.  That logic should be in acpi_alloc_resource()
and once that is present then your driver just needs to do the usual
bus_alloc_resource() stuff to work.

--
John Baldwin
_______________________________________________
freebsd-acpi@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-acpi
To unsubscribe, send any mail to "freebsd-acpi-unsubscribe@..."

Re: Writing a driver: how do I get resources?

by Gavin Atkinson-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 2008-09-23 at 10:36 -0400, John Baldwin wrote:

> On Tuesday 23 September 2008 08:38:25 am Gavin Atkinson wrote:
> > Hi all,
> >
> > 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.
> >
> > Lastly, I only have intermittent access to this laptop, so I apologise
> > if I can't test things quickly.
>
> Our ACPI driver isn't smart enough yet (AFAIK) to allocate new resources for a
> device that doesn't have any.  That logic should be in acpi_alloc_resource()
> and once that is present then your driver just needs to do the usual
> bus_alloc_resource() stuff to work.

Thanks.  So I guess there's no easy way to do it at the moment?

Gavin
_______________________________________________
freebsd-acpi@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-acpi
To unsubscribe, send any mail to "freebsd-acpi-unsubscribe@..."

Re: Writing a driver: how do I get resources?

by Nate Lawson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
_______________________________________________
freebsd-acpi@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-acpi
To unsubscribe, send any mail to "freebsd-acpi-unsubscribe@..."

Re: Writing a driver: how do I get resources?

by John Baldwin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday 23 September 2008 01:21:22 pm Gavin Atkinson wrote:

> On Tue, 2008-09-23 at 10:36 -0400, John Baldwin wrote:
> > On Tuesday 23 September 2008 08:38:25 am Gavin Atkinson wrote:
> > > Hi all,
> > >
> > > 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.
> > >
> > > Lastly, I only have intermittent access to this laptop, so I apologise
> > > if I can't test things quickly.
> >
> > Our ACPI driver isn't smart enough yet (AFAIK) to allocate new resources
for a
> > device that doesn't have any.  That logic should be in
acpi_alloc_resource()
> > and once that is present then your driver just needs to do the usual
> > bus_alloc_resource() stuff to work.
>
> Thanks.  So I guess there's no easy way to do it at the moment?

No. :(  What you would need to do is to change acpi_alloc_resource() such that
if it is working on a direct child (so device_get_parent(child) == dev) and
the child has no resources assigned yet, but there are possible resources, it
needs to allocate a set of resources and do _SRS.

--
John Baldwin
_______________________________________________
freebsd-acpi@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-acpi
To unsubscribe, send any mail to "freebsd-acpi-unsubscribe@..."

Re: Writing a driver: how do I get resources?

by Wilkinson, Alex :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

    0n Tue, Sep 23, 2008 at 11:05:58AM -0700, Nate Lawson wrote:

    >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.

What are the best laptops to use with freebsd then ? i.e the ones that dont have
a proprietary bus ?

 -aW



IMPORTANT: This email remains the property of the Australian Defence Organisation and is subject to the jurisdiction of section 70 of the CRIMES ACT 1914.  If you have received this email in error, you are requested to contact the sender and delete the email.


_______________________________________________
freebsd-acpi@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-acpi
To unsubscribe, send any mail to "freebsd-acpi-unsubscribe@..."

Re: Writing a driver: how do I get resources?

by Nate Lawson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Wilkinson, Alex wrote:
>     0n Tue, Sep 23, 2008 at 11:05:58AM -0700, Nate Lawson wrote:
>
>     >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.
>
> What are the best laptops to use with freebsd then ? i.e the ones that dont have
> a proprietary bus ?

You misunderstood.  What I'm saying is that all laptops have proprietary
 OEM drivers for features like hotkeys, backlight, etc.  That includes
Acer, IBM/Lenovo, Toshiba, Panasonic, Sony, etc.  The "hardware" you're
accessing via those ACPI methods is actually the BIOS itself, which then
talks to the chipset and GPIO pins to perform the requests.  So there's
no PCI bus or other open interface to configure these.

Your best bet is to implement the _SRS stuff the way John was suggesting.

--
Nate
_______________________________________________
freebsd-acpi@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-acpi
To unsubscribe, send any mail to "freebsd-acpi-unsubscribe@..."
LightInTheBox - Buy quality products at wholesale price!