PNP: request ioport and iomem resources used by active devices
Subsystems (3)
RFC PATCH 1/1 PNP: request ioport and iomem resources used by active devices
Reserve resources used by active PNP devices to prevent those resources from being assigned to other devices.
This can be turned off with the "pnp=no_reservations" flag. If you need to use it, please report it, because it indicates a potential problem, like a driver that requests more resources than it needs.
This is similar to request_standard_resources(). That function requests resources for a compiled-in list of standard PC devices such as DMA controllers, PICs, timers, and keyboard, and marks them "busy." This patch requests resources for devices that are actually present but does not mark them "busy."
Sometimes the built-in standard resources are larger than what PNP reports, or they combine things that PNP reports separately, which makes things look a little strange, e.g.,
0000-001f : dma1 <-- built-in resource includes 2 controllers
0000-000f : 00:02 <-- PNP reports only one DMA controller
0020-0021 : pic1
002e-002f : 00:06
0040-0043 : timer0
0050-0053 : timer1
0060-006f : keyboard <-- built-in resource groups several things
0060-0060 : 00:04 <-- PNP reports 8042 controller data register
0061-0061 : 00:03 <-- PNP reports AT-style speaker
0064-0064 : 00:04 <-- PNP reports 8042 controller status register
0070-0073 : 00:06
0070-0071 : rtcDocumentation/kernel-parameters.txt +8 -0
@@ -1410,6 +1410,14 @@ Format: { parport<nr> | timid | 0 } See also Documentation/parport.txt. + pnp= [PNP] PNP subsystem options: + no_reservations Don't reserve resources used by PNP devices + This is for working around problems where a + driver uses a PNP device without using the PNP + core. Typical symptom is that the driver can't + reserve the resources it needs. Please report + these issues. + pnpacpi= [ACPI] { off }
drivers/pnp/base.h +2 -0
@@ -5,6 +5,8 @@void pnp_free_option (struct pnp_option *option);int __pnp_add_device (struct pnp_dev *dev);void __pnp_remove_device (struct pnp_dev *dev); +int pnp_request_resources (struct pnp_dev *dev); +int pnp_release_resources (struct pnp_dev *dev);int pnp_check_port (struct pnp_dev * dev,int idx);int pnp_check_mem (struct pnp_dev * dev,int idx);
drivers/pnp/core.c +3 -0
@@ -124,6 +124,9 @@list_add_tail (&dev->protocol_list, &dev->protocol->devices);spin_unlock (&pnp_lock); +if (dev->active) +pnp_request_resources (dev); + ret =device_register (&dev->dev);if (ret)return ret;
drivers/pnp/manager.c +9 -3
@@ -391,9 +391,11 @@if (!pnp_can_configure (dev))return -ENODEV ; + bak =pnp_alloc (sizeof (struct pnp_resource_table ));if (!bak)return -ENOMEM ; + *bak = dev->res;down (&pnp_res_mutex);
@@ -463,7 +465,7 @@* pnp_start_dev - low-level start of the PnP device * @dev: pointer to the desired device * -* assumes that resources have already been allocated +* assumes that resources have already been assigned to the device */ int pnp_start_dev (struct pnp_dev *dev) {
@@ -472,6 +474,9 @@return -EINVAL ; } +if (pnp_request_resources (dev)) +dev_err (&dev->dev,"could not allocate resources\n" ); +if (dev->protocol->set (dev, &dev->res) <0 ) {dev_err (&dev->dev,"activation failed\n" );return -EIO ;
@@ -484,8 +489,6 @@/** * pnp_stop_dev - low-level disable of the PnP device * @dev: pointer to the desired device -* -* does not free resources */ int pnp_stop_dev (struct pnp_dev *dev) {
@@ -493,11 +496,14 @@dev_dbg (&dev->dev,"disabling not supported\n" );return -EINVAL ; } +if (dev->protocol->disable (dev) <0 ) {dev_err (&dev->dev,"disable failed\n" );return -EIO ; } +pnp_release_resources (dev); +dev_info (&dev->dev,"disabled\n" );return 0 ; }
drivers/pnp/resource.c +103 -0
118 lines not on this page · raw message
Quoted 2 lines · Bjorn Helgaas
Reserve resources used by active PNP devices to prevent those resources from being assigned to other devices.
Yes, I think this is probably a safe approach to take.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 2 lines · Bjorn Helgaas
0000-001f : dma1 <-- built-in resource includes 2 controllers
0000-000f : 00:02 <-- PNP reports only one DMA controller[...]
Quoted 4 lines
0060-006f : keyboard <-- built-in resource groups several things
0060-0060 : 00:04 <-- PNP reports 8042 controller data register
0061-0061 : 00:03 <-- PNP reports AT-style speaker
0064-0064 : 00:04 <-- PNP reports 8042 controller status register Note that the built-in resources are requested according to how the PC/AT
architecture defined address decoding for the relevant subsystems. In particular, there was always a single DMA controller at 0x0000 and the 8042 controller was decoded at 0x0060. No full decoding was done and unused locations aliased to the corresponding ones with the don't-care bits set to the other value. I do not recall all the details of the port B (named after the original from the 8255 as used in the PC/XT) at 0x0061 as implemented in the PC/AT and I do not have a reference handy, but it is a bunch of GPIO bits, some being r/o and some r/w, possibly with side-effects. I believe it was a set of additional latches sub-decoded from the 8042 controller range for compatibility with how the 8255 was wired and programmed.
Anyway, PNP may provide a more accurate picture of the address ranges in
a particular system... if it gets it right! Which is a lost hope, I suppose, as even the above is questionable -- "AT-style speaker" is a misnomer as most of the GPIO bits involved deal with the handling of system error interrupts normally routed to NMI.
The patch itself is useful and makes sense though. Have you passed it
through `scripts/checkpatch.pl'?
Maciej
Quoted 23 lines · Maciej W. Rozycki
Quoted 2 lines · Bjorn Helgaas
0000-001f : dma1 <-- built-in resource includes 2 controllers 0000-000f : 00:02 <-- PNP reports only one DMA controller[...]
Quoted 4 lines
0060-006f : keyboard <-- built-in resource groups several things 0060-0060 : 00:04 <-- PNP reports 8042 controller data register 0061-0061 : 00:03 <-- PNP reports AT-style speaker 0064-0064 : 00:04 <-- PNP reports 8042 controller status registerNote that the built-in resources are requested according to how the PC/AT
architecture defined address decoding for the relevant subsystems. In particular, there was always a single DMA controller at0x0000and the 8042 controller was decoded at0x0060. No full decoding was done and unused locations aliased to the corresponding ones with the don't-care bits set to the other value. I do not recall all the details of the port B (named after the original from the 8255 as used in the PC/XT) at0x0061as implemented in the PC/AT and I do not have a reference handy, but it is a bunch of GPIO bits, some being r/o and some r/w, possibly with side-effects. I believe it was a set of additional latches sub-decoded from the 8042 controller range for compatibility with how the 8255 was wired and programmed.
Quoted 5 lines
Anyway, PNP may provide a more accurate picture of the address ranges in
a particular system... if it gets it right! Which is a lost hope, I suppose, as even the above is questionable -- "AT-style speaker" is a misnomer as most of the GPIO bits involved deal with the handling of system error interrupts normally routed to NMI.
Thanks for the background and the comments.
There will undoubtedly be errors in what the firmware reports. But if firmware tells us about some non PC/AT device, we should believe it at least enough to avoid placing some other device on top of it.
If we have PNPBIOS or ACPI, the built-in stuff reserved in request_standard_resources() should be superfluous. In theory. But I doubt there's any benefit in skipping request_standard_resources(). Possibly it could be done *after* the PNP reservations, so the hierarchy would make more sense, but I don't know if even that is worth the trouble.
Quoted 2 lines
The patch itself is useful and makes sense though. Have you passed it
through `scripts/checkpatch.pl'?
Yes. The patch was added to -mm on Nov 1 as pnp-request-ioport-and-iomem-resources-used-by-active-devices.patch.
Bjorn
Quoted 10 lines · Bjorn Helgaas
There will undoubtedly be errors in what the firmware reports. But if firmware tells us about some non PC/AT device, we should believe it at least enough to avoid placing some other device on top of it.
If we have PNPBIOS or ACPI, the built-in stuff reserved in
request_standard_resources()should be superfluous. In theory. But I doubt there's any benefit in skippingrequest_standard_resources(). Possibly it could be done *after* the PNP reservations, so the hierarchy would make more sense, but I don't know if even that is worth the trouble.
In practice it is resources above 0x00ff that really matter here as using
the motherboard range for device allocation is unsafe anyway (the whole range may be actively decoded by the south bridge). So whatever is reported between 0x0000 and 0x00ff is mostly informational; with some protection against driver bugs perhaps (that assuming they have got error handling right for reservations). I second it is not worth the hassle.
Maciej