bootflag.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/spinlock.h>
  9. #include <linux/acpi.h>
  10. #include <asm/io.h>
  11. #include <linux/mc146818rtc.h>
  12. #define SBF_RESERVED (0x78)
  13. #define SBF_PNPOS (1<<0)
  14. #define SBF_BOOTING (1<<1)
  15. #define SBF_DIAG (1<<2)
  16. #define SBF_PARITY (1<<7)
  17. int sbf_port __initdata = -1; /* set via acpi_boot_init() */
  18. static int __init parity(u8 v)
  19. {
  20. int x = 0;
  21. int i;
  22. for (i = 0; i < 8; i++) {
  23. x ^= (v & 1);
  24. v >>= 1;
  25. }
  26. return x;
  27. }
  28. static void __init sbf_write(u8 v)
  29. {
  30. unsigned long flags;
  31. if (sbf_port != -1) {
  32. v &= ~SBF_PARITY;
  33. if (!parity(v))
  34. v |= SBF_PARITY;
  35. printk(KERN_INFO "Simple Boot Flag at 0x%x set to 0x%x\n",
  36. sbf_port, v);
  37. spin_lock_irqsave(&rtc_lock, flags);
  38. CMOS_WRITE(v, sbf_port);
  39. spin_unlock_irqrestore(&rtc_lock, flags);
  40. }
  41. }
  42. static u8 __init sbf_read(void)
  43. {
  44. unsigned long flags;
  45. u8 v;
  46. if (sbf_port == -1)
  47. return 0;
  48. spin_lock_irqsave(&rtc_lock, flags);
  49. v = CMOS_READ(sbf_port);
  50. spin_unlock_irqrestore(&rtc_lock, flags);
  51. return v;
  52. }
  53. static int __init sbf_value_valid(u8 v)
  54. {
  55. if (v & SBF_RESERVED) /* Reserved bits */
  56. return 0;
  57. if (!parity(v))
  58. return 0;
  59. return 1;
  60. }
  61. static int __init sbf_init(void)
  62. {
  63. u8 v;
  64. if (sbf_port == -1)
  65. return 0;
  66. v = sbf_read();
  67. if (!sbf_value_valid(v)) {
  68. printk(KERN_WARNING "Simple Boot Flag value 0x%x read from "
  69. "CMOS RAM was invalid\n", v);
  70. }
  71. v &= ~SBF_RESERVED;
  72. v &= ~SBF_BOOTING;
  73. v &= ~SBF_DIAG;
  74. #if defined(CONFIG_ISAPNP)
  75. v |= SBF_PNPOS;
  76. #endif
  77. sbf_write(v);
  78. return 0;
  79. }
  80. arch_initcall(sbf_init);