Linux should not set the "PnP OS" boot flag
Quoted 3 lines · [email protected] wrote:
Hmm. Linux isn't quite a "PnP OS". I agree that in the short term we should not set the boot flag. But we should also investigate what needs to added so that setpnp does not need to be called.
This change has to be permanent. Linux should never automatically set the boot flag, no matter how PnP-competent we make it. The reason is that setting the flag affects what the BIOS will do on the _subsequent_ boot. But Linux can't possibly know which operating system will be booted _next time_. This is something that has to be left up to the user to control.
Assuming I've made that point, I'll go on to say that I do not know of any reason why the PnP-OS flag should _ever_ be set. SFAIK all that setting the flag does is stop the PnP BIOS from configuring devices in the way that it has been told to do (if we used "setpnp -b" to set the nonvolative configuration). I don't see why we would ever want to do this. If the BIOS does configure the devices, nothing stops us from reconfiguring them (using "setpnp") once Linux has booted. The PnP-OS flag is called a "quick boot" flag, but the time savings involved must be on the order of milliseconds. All that we seem to achieve by booting Linux with disabled devices is to induce certain device drivers to segfault.
Please let me know if I'm overlooking something.
If I'm right, then bootflag.c should be modified (see my patch) to remove the bit that sets the flag. It would be nice, however, if the flag could be controlled via a /proc entry.
--
Thomas
Quoted 6 lines
This change has to be permanent. Linux should never automatically set the boot flag, no matter how PnP-competent we make it. The reason is that setting the flag affects what the BIOS will do on the _subsequent_ boot. But Linux can't possibly know which operating system will be booted
_nexttime_. This is something that has to be left up to the user to control.
When it cuts your reboot time right down then its a very useful thing to set. Also remember that this is entirely configurable. In fact the last stage of a pnp aware bootup requires that user space sets the "booted ok" flag.
Quoted 2 lines
a "quick boot" flag, but the time savings involved must be on the order of milliseconds. All that we seem to achieve by booting
On some boxes they are much higher
Quoted 3 lines
If I'm right, then
bootflag.cshould be modified (see my patch) to remove the bit that sets the flag. It would be nice, however, if the flag could be controlled via a /proc entry.
No need. It's all already handled
Alan
Quoted 9 lines · Alan Cox
Quoted 6 lines
This change has to be permanent. Linux should never automatically set the boot flag, no matter how PnP-competent we make it. The reason is that setting the flag affects what the BIOS will do on the _subsequent_ boot. But Linux can't possibly know which operating system will be booted
_nexttime_. This is something that has to be left up to the user to control.When it cuts your reboot time right down then its a very useful thing to set.
Okay, clearly we do need the ability to set the PnP-OS flag. But this has to be under the user's control. Microsoft itself says (from their Simple Boot Flag FAQ
http://www.microsoft.com/hwdev/desinit/simp_bios.htm):
---------------------------------------------------------------------
How does this specification solve the multi-boot scenarios? This specification does not attempt to solve multi-boot scenarios in which a user has several different operating systems, some Plug and Play, some not, installed on the machine. This specification only provides a more reliable technique for detecting the presence of these operating systems than previously published designs.
The multi-boot problem is fundamentally intractable: the information needed by the system BIOS in order to boot is not available until after boot. A system BIOS would like to know whether or not a Plug and Play operating system will be booted. If so, it will only configure devices that are required for boot. If not, it will configure all devices it controls. The information about which OS will be booted is not known until the user chooses the operating system in a boot menu. To present the boot menu, however, the system BIOS must start booting the operating system, which means it must have already configured devices. Thus, the situation is a catch 22. The best any design can do is provide some hint to the system BIOS that a Plug and Play operating system is installed. This specification does no more than that.
---------------------------------------------------------------------
For these reasons it must be left up to the user to provide this "hint".
Quoted 1 line
Also remember that this is entirely configurable.
I'm not sure what you mean by 'configurable' here. All I see is that the code that sets the PnP-OS flag gets compiled in if one chooses to build the PnP BIOS driver by defining CONFIG_PNPBIOS. But having a PnP BIOS driver (merely an interface to the PnP BIOS) is not the same thing as "being a PnP OS". There ought to be some way of overriding this---of building in the PnP BIOS driver without setting the PnP-OS flag. One solution is to put #ifdef CONFIG_PNPOS ... #endif around the flag-setting code and add a new choice to the configuration.
Quoted 2 lines
In fact the last stage of a pnp aware bootup requires that user space sets the "booted ok" flag.
Yes (if you mean: clears the "Booting" flag). This is a different flag from the PnP-OS flag. The PnP-OS flag is bit 0; the "Booting" flag is bit 1. So this is a separate issue.
But look at the code (following). The code DOES NOT clear the "Booting" flag. It ONLY sets the PnP-OS flag. Not only that: when it does so it fails to change bit 7 in order to preserve odd parity, as the spec requires.
------------------------------------------------------------------
static void __init sbf_bootup(void)
{
u8 v = sbf_read();
if(!sbf_value_valid(v))
v = 0;
#if defined(CONFIG_PNPBIOS)
/* Tell the BIOS to fast init as we are a PnP OS */
v |= (1<<0); /* Set PNPOS flag */
#endif
sbf_write(v);
}#ifdef NOT_USED
void linux_booted_ok(void)
{
u8 v = sbf_read();
if(!sbf_value_valid(v))
return;
v &= ~(1<<1); /* Clear BOOTING flag */
sbf_write(v);
}#endif /* NOT_USED */
----------------------------------------------------------------
Quoted 5 lines
Quoted 3 lines
If I'm right, then
bootflag.cshould be modified (see my patch) to remove the bit that sets the flag. It would be nice, however, if the flag could be controlled via a /proc entry.No need. It's all already handled
I think you'll understand why I say that it is not handled _correctly_ and that the handling must be brought under the user's control ... if not via a /proc entry then by a build option or boot option. I invite advice about this.
Please let me know if you still disagree.
--
Thomas
Quoted 4 lines · Thomas Hood
I think you'll understand why I say that it is not handled _correctly_ and that the handling must be brought under the user's control ... if not via a /proc entry then by a build option or boot option. I invite advice about this.
The final part doesn't need to be in kernel space at all. (And from my reading of the spec, shouldn't be, as it signifies the OS completed the final stages of booting successfully)
http://www.codemonkey.org.uk/sbf.c
is some quick code I hacked up when bootflag.c first appeared. Its not perfect, and I have some outstanding patches that Randy Dunlap sent to clean up some bits, but I've not got around to merging them.
regards,
Dave.
Signature · 2 lines
| Dave Jones. http://www.suse.de/~davej | SuSE Labs
Quoted 3 lines
Yes (if you mean: clears the "Booting" flag). This is a different flag from the PnP-OS flag. The PnP-OS flag is bit 0; the "Booting" flag is bit 1. So this is a separate issue.
Its very much the same issue. Only a marked successful PnP boot counts for anything
Quoted 4 lines
But look at the code (following). The code DOES NOT clear the "Booting" flag. It ONLY sets the PnP-OS flag. Not only that: when it does so it fails to change bit 7 in order to preserve odd parity, as the spec requires.
sbf_write computes parity
Quoted 6 lines · Alan Cox
Quoted 3 lines
Yes (if you mean: clears the "Booting" flag). This is a different flag from the PnP-OS flag. The PnP-OS flag is bit 0; the "Booting" flag is bit 1. So this is a separate issue.
Its very much the same issue. Only a marked successful PnP boot counts for anything
Well, the SBF spec treats the two bits as totally separate. The PnP-OS bit controls PnP BIOS device configuration. The Booting and Diag bits control whether or not POSTs are run:
------------------------------------------------------------------
BOOT register structure
-----------------------
0 PNPOS -- Indicates that a Plug-and-Play capable OS is installed on the system. The system BIOS must check the state of this bit during its initialization. If this bit is not set, the system BIOS must assume a legacy operating system and configure the resources of all devices it controls. If the bit is set, the system BIOS must assume a Plug and Play operating system and only configure devices required for boot as per the PC98 specification.
1 BOOTING -- Indicates whether or not the previous boot was not completed. The system BIOS must check the state of this flag at the beginning of POST. If this bit is set, the system BIOS will set DIAG to 1 to inform itself and other components to run a full diagnostic suite. If this bit is not set, DIAG will be cleared to inform components to skip all tests and to begin loading the boot sector as soon as possible. This bit is set by the system BIOS at the earliest possible moment of POST. This bit is cleared by the OS after it has completed its boot procedure.
2 DIAG -- Indicates whether or not to run diagnostics. This bit is set based on the state of BOOTING at the beginning of POST, or by the operating system during the previous boot. If set at the beginning of POST, this bit must remain set to allow the operating system to request diagnostic boots. If set during POST, the system BIOS, option ROMs, and operating systems should run diagnostic tests. If not set, these components must not run diagnostic tests and should boot the machine as quickly as possible.
3-6 Reserved -- Reserved. Must be 0.
7 PARITY -- A parity bit used to check used to verify the integrity of this register. This bit should be set with ODD parity based on the contents of the rest of the register. If the system BIOS detects that the PARITY bit is not set correctly, it must assume the register is corrupted.
------------------------------------------------------------------
Quoted 6 lines
Quoted 4 lines
But look at the code (following). The code DOES NOT clear the "Booting" flag. It ONLY sets the PnP-OS flag. Not only that: when it does so it fails to change bit 7 in order to preserve odd parity, as the spec requires.
sbf_writecomputes parity
oh. ;)
I append the patch that shows the sort of thing that I think needs to be done. (This patch includes the change from spin_lock to spin_lock_irqsave.) The patch would need to be accompanied by the addition of stuff to allow the user to define CONFIG_PNPOS.
Cheers,
Thomas
The patch:
arch/i386/kernel/bootflag.c +19 -19
@@ -59,7 +59,7 @@return 0 ;if (sb.sbf_len ==39 ) -printk (KERN_WARNING "ACPI BOOT descriptor is wrong length (%d)\n" , +printk (KERN_WARNING "SBF: ACPI BOOT descriptor is wrong length (%d)\n" , sb.sbf_len); sbf_port = sb.sbf_cmos;/* Save CMOS port */
@@ -81,32 +81,38 @@static void __init sbf_write (u8 v) { +unsigned long flags; +if (sbf_port !=-1 ) { v &= ~(1 <<7 );if (!parity (v)) v|=1 <<7 ; -spin_lock (&rtc_lock); +printk (KERN_INFO "SBF: Setting boot flags 0x%x\n" ,v); + +spin_lock_irqsave (&rtc_lock, flags);CMOS_WRITE (v, sbf_port); -spin_unlock (&rtc_lock); +spin_unlock_irqrestore (&rtc_lock, flags); } }static u8 __init sbf_read (void ) {u8 v; +unsigned long flags; +if (sbf_port ==-1 )return 0 ; -spin_lock (&rtc_lock); +spin_lock_irqsave (&rtc_lock, flags); v =CMOS_READ (sbf_port); -spin_unlock (&rtc_lock); +spin_unlock_irqrestore (&rtc_lock, flags);return v; }static int __init sbf_value_valid (u8 v) { -if (v&0x78 )/* Reserved bits */ +if (v&0x78 )/* Reserved bits should be 0 */ return 0 ;if (!parity (v))return 0 ;
@@ -118,24 +124,18 @@ {u8 v =sbf_read ();if (!sbf_value_valid (v)) - v =0 ; -#if defined(CONFIG_PNPBIOS ) +printk (KERN_WARNING "SBF: Simple boot flag value read from CMOS RAM 0x%x is invalid\n" ,v); + + v &= ~0x78 ;/* Clear reserved bits 3-6 */ + v &= ~(1 <<1 );/* Clear BOOTING flag */ + v &= ~(1 <<2 );/* Clear DIAG flag */ +#if defined(CONFIG_PNPOS )/* Tell the BIOS to fast init as we are a PnP OS */ v |= (1 <<0 );/* Set PNPOS flag */ #endif -sbf_write (v); -} -#ifdef NOT_USED -void linux_booted_ok (void ) -{ -u8 v =sbf_read (); -if (!sbf_value_valid (v)) -return ; - v &= ~(1 <<1 );/* Clear BOOTING flag */ sbf_write (v); } -#endif /* NOT_USED */ static int __init sbf_init (void ) {
@@ -235,7 +235,7 @@if (sbf_struct_valid (rp)) {/* Found the BOOT table and processed it */ -printk (KERN_INFO "Simple Boot Flag extension found and enabled.\n" ); +printk (KERN_INFO "SBF: Simple Boot Flag extension found and enabled.\n" ); }iounmap ((void *)rp); }
Quoted 4 lines
I append the patch that shows the sort of thing that I think needs to be done. (This patch includes the change from
spin_locktospin_lock_irqsave.) The patch would need to be accompanied by the addition of stuff to allow the user to defineCONFIG_PNPOS.
Would it not be better to tackle the job head on ? If the pnpbios scan as it walks the devices configured them would that do the job ?
Here's a slightly neater version of the patch which gives control over the DIAG bit also. We'd need config options for "CONFIG_SBF_DIAG" and "CONFIG_SBF_PNPOS".
I'd like to say in defense of this patch that the more conservative thing to do _by default_ is to let the PnP BIOS configure devices before Linux boots. The cost SFAIK is only time. The cost of leaving devices unconfigured is, for some people, oopses.
--
Thomas
The patch:
arch/i386/kernel/bootflag.c +35 -24
@@ -15,6 +15,13 @@#include <linux/mc146818rtc.h> + +#define SBF_RESERVED (0x78) +#define SBF_PNPOS (1<<0) +#define SBF_BOOTING (1<<1) +#define SBF_DIAG (1<<2) +#define SBF_PARITY (1<<7) +struct sbf_boot {u8 sbf_signature[4 ];
@@ -59,7 +66,7 @@return 0 ;if (sb.sbf_len ==39 ) -printk (KERN_WARNING "ACPI BOOT descriptor is wrong length (%d)\n" , +printk (KERN_WARNING "SBF: ACPI BOOT descriptor is wrong length (%d)\n" , sb.sbf_len); sbf_port = sb.sbf_cmos;/* Save CMOS port */
@@ -81,61 +88,65 @@static void __init sbf_write (u8 v) { +unsigned long flags; +if (sbf_port !=-1 ) { - v &= ~(1 <<7 ); + v &= ~SBF_PARITY ;if (!parity (v)) - v|=1 <<7 ; + v|=SBF_PARITY ;/* Make parity odd */ -spin_lock (&rtc_lock); +printk (KERN_INFO "SBF: Setting boot flags 0x%x\n" ,v); + +spin_lock_irqsave (&rtc_lock, flags);CMOS_WRITE (v, sbf_port); -spin_unlock (&rtc_lock); +spin_unlock_irqrestore (&rtc_lock, flags); } }static u8 __init sbf_read (void ) {u8 v; +unsigned long flags; +if (sbf_port ==-1 )return 0 ; -spin_lock (&rtc_lock); +spin_lock_irqsave (&rtc_lock, flags); v =CMOS_READ (sbf_port); -spin_unlock (&rtc_lock); +spin_unlock_irqrestore (&rtc_lock, flags);return v; }static int __init sbf_value_valid (u8 v) { -if (v&0x78 )/* Reserved bits */ +if (v&SBF_RESERVED )/* Reserved bits should be 0 */ return 0 ;if (!parity (v))return 0 ;return 1 ; } -static void __init sbf_bootup (void ) {u8 v =sbf_read ();if (!sbf_value_valid (v)) - v =0 ; -#if defined(CONFIG_PNPBIOS ) -/* Tell the BIOS to fast init as we are a PnP OS */ - v |= (1 <<0 );/* Set PNPOS flag */ +printk (KERN_WARNING "SBF: Simple boot flag value 0x%x read from CMOS RAM was invalid\n" ,v); + + v &= ~SBF_RESERVED ; + v &= ~SBF_BOOTING ; +#if defined(CONFIG_SBF_DIAG ) + v |=SBF_DIAG ; +#else + v &= ~SBF_DIAG ; +#endif +#if defined(CONFIG_SBF_PNPOS ) + v |=SBF_PNPOS ; +#else + v &= ~SBF_PNPOS ;#endif -sbf_write (v); -} -#ifdef NOT_USED -void linux_booted_ok (void ) -{ -u8 v =sbf_read (); -if (!sbf_value_valid (v)) -return ; - v &= ~(1 <<1 );/* Clear BOOTING flag */ sbf_write (v); } -#endif /* NOT_USED */ static int __init sbf_init (void ) {
@@ -235,7 +246,7 @@if (sbf_struct_valid (rp)) {/* Found the BOOT table and processed it */ -printk (KERN_INFO "Simple Boot Flag extension found and enabled.\n" ); +printk (KERN_INFO "SBF: Simple Boot Flag extension found and enabled.\n" ); }iounmap ((void *)rp); }