cmos.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2011 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/datetime.h>
  19. #include <grub/cmos.h>
  20. #include <grub/dl.h>
  21. #include <grub/ieee1275/ieee1275.h>
  22. #include <grub/misc.h>
  23. volatile grub_uint8_t *grub_cmos_port = 0;
  24. /* Helper for grub_cmos_find_port. */
  25. static int
  26. grub_cmos_find_port_iter (struct grub_ieee1275_devalias *alias)
  27. {
  28. grub_ieee1275_phandle_t dev;
  29. grub_uint32_t addr[2];
  30. grub_ssize_t actual;
  31. /* Enough to check if it's "m5819" */
  32. char compat[100];
  33. if (grub_ieee1275_finddevice (alias->path, &dev))
  34. return 0;
  35. if (grub_ieee1275_get_property (dev, "compatible", compat, sizeof (compat),
  36. 0))
  37. return 0;
  38. if (grub_strcmp (compat, "m5819") != 0)
  39. return 0;
  40. if (grub_ieee1275_get_integer_property (dev, "address",
  41. addr, sizeof (addr), &actual))
  42. return 0;
  43. if (actual == 4)
  44. {
  45. grub_cmos_port = (volatile grub_uint8_t *) (grub_addr_t) addr[0];
  46. return 1;
  47. }
  48. #if GRUB_CPU_SIZEOF_VOID_P == 8
  49. if (actual == 8)
  50. {
  51. grub_cmos_port = (volatile grub_uint8_t *)
  52. ((((grub_addr_t) addr[0]) << 32) | addr[1]);
  53. return 1;
  54. }
  55. #else
  56. if (actual == 8 && addr[0] == 0)
  57. {
  58. grub_cmos_port = (volatile grub_uint8_t *) addr[1];
  59. return 1;
  60. }
  61. #endif
  62. return 0;
  63. }
  64. grub_err_t
  65. grub_cmos_find_port (void)
  66. {
  67. grub_ieee1275_devices_iterate (grub_cmos_find_port_iter);
  68. if (!grub_cmos_port)
  69. return grub_error (GRUB_ERR_IO, "no cmos found");
  70. return GRUB_ERR_NONE;
  71. }