repo init
[linux-rt-nao.git] / arch / x86 / kernel / bootflag.c
blob30f25a75fe2876ef93605181f81c386c02953bfb
1 /*
2 * Implement 'Simple Boot Flag Specification 2.0'
3 */
4 #include <linux/types.h>
5 #include <linux/kernel.h>
6 #include <linux/init.h>
7 #include <linux/string.h>
8 #include <linux/slab.h>
9 #include <linux/spinlock.h>
10 #include <linux/acpi.h>
11 #include <asm/io.h>
13 #include <linux/mc146818rtc.h>
15 #define SBF_RESERVED (0x78)
16 #define SBF_PNPOS (1<<0)
17 #define SBF_BOOTING (1<<1)
18 #define SBF_DIAG (1<<2)
19 #define SBF_PARITY (1<<7)
21 int sbf_port __initdata = -1; /* set via acpi_boot_init() */
23 static int __init parity(u8 v)
25 int x = 0;
26 int i;
28 for (i = 0; i < 8; i++) {
29 x ^= (v & 1);
30 v >>= 1;
33 return x;
36 static void __init sbf_write(u8 v)
38 unsigned long flags;
40 if (sbf_port != -1) {
41 v &= ~SBF_PARITY;
42 if (!parity(v))
43 v |= SBF_PARITY;
45 printk(KERN_INFO "Simple Boot Flag at 0x%x set to 0x%x\n",
46 sbf_port, v);
48 spin_lock_irqsave(&rtc_lock, flags);
49 CMOS_WRITE(v, sbf_port);
50 spin_unlock_irqrestore(&rtc_lock, flags);
54 static u8 __init sbf_read(void)
56 unsigned long flags;
57 u8 v;
59 if (sbf_port == -1)
60 return 0;
62 spin_lock_irqsave(&rtc_lock, flags);
63 v = CMOS_READ(sbf_port);
64 spin_unlock_irqrestore(&rtc_lock, flags);
66 return v;
69 static int __init sbf_value_valid(u8 v)
71 if (v & SBF_RESERVED) /* Reserved bits */
72 return 0;
73 if (!parity(v))
74 return 0;
76 return 1;
79 static int __init sbf_init(void)
81 u8 v;
83 if (sbf_port == -1)
84 return 0;
86 v = sbf_read();
87 if (!sbf_value_valid(v)) {
88 printk(KERN_WARNING "Simple Boot Flag value 0x%x read from "
89 "CMOS RAM was invalid\n", v);
92 v &= ~SBF_RESERVED;
93 v &= ~SBF_BOOTING;
94 v &= ~SBF_DIAG;
95 #if defined(CONFIG_ISAPNP)
96 v |= SBF_PNPOS;
97 #endif
98 sbf_write(v);
100 return 0;
102 module_init(sbf_init);