hw.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* hw.c - U-Boot hardware discovery */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2013 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/kernel.h>
  20. #include <grub/memory.h>
  21. #include <grub/misc.h>
  22. #include <grub/mm.h>
  23. #include <grub/offsets.h>
  24. #include <grub/machine/kernel.h>
  25. #include <grub/uboot/disk.h>
  26. #include <grub/uboot/uboot.h>
  27. #include <grub/uboot/api_public.h>
  28. grub_addr_t start_of_ram;
  29. /*
  30. * grub_uboot_probe_memory():
  31. * Queries U-Boot for available memory regions.
  32. *
  33. * Sets up heap near the image in memory and sets up "start_of_ram".
  34. */
  35. void
  36. grub_uboot_mm_init (void)
  37. {
  38. struct sys_info *si = grub_uboot_get_sys_info ();
  39. grub_mm_init_region ((void *) grub_modules_get_end (),
  40. GRUB_KERNEL_MACHINE_HEAP_SIZE);
  41. if (si && (si->mr_no != 0))
  42. {
  43. int i;
  44. start_of_ram = GRUB_UINT_MAX;
  45. for (i = 0; i < si->mr_no; i++)
  46. if ((si->mr[i].flags & MR_ATTR_MASK) == MR_ATTR_DRAM)
  47. if (si->mr[i].start < start_of_ram)
  48. start_of_ram = si->mr[i].start;
  49. }
  50. }
  51. /*
  52. * grub_uboot_probe_hardware():
  53. */
  54. grub_err_t
  55. grub_uboot_probe_hardware (void)
  56. {
  57. int devcount, i;
  58. devcount = grub_uboot_dev_enum ();
  59. grub_dprintf ("init", "%d devices found\n", devcount);
  60. for (i = 0; i < devcount; i++)
  61. {
  62. struct device_info *devinfo = grub_uboot_dev_get (i);
  63. grub_dprintf ("init", "device handle: %d\n", i);
  64. grub_dprintf ("init", " cookie\t= 0x%08x\n",
  65. (grub_uint32_t) devinfo->cookie);
  66. if (devinfo->type & DEV_TYP_STOR)
  67. {
  68. grub_dprintf ("init", " type\t\t= DISK\n");
  69. grub_ubootdisk_register (devinfo);
  70. }
  71. else if (devinfo->type & DEV_TYP_NET)
  72. {
  73. /* Dealt with in ubootnet module. */
  74. grub_dprintf ("init", " type\t\t= NET (not supported yet)\n");
  75. }
  76. else
  77. {
  78. grub_dprintf ("init", "%s: unknown device type", __FUNCTION__);
  79. }
  80. }
  81. return GRUB_ERR_NONE;
  82. }
  83. grub_err_t
  84. grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
  85. {
  86. int i;
  87. struct sys_info *si = grub_uboot_get_sys_info ();
  88. if (!si || (si->mr_no < 1))
  89. return GRUB_ERR_BUG;
  90. /* Iterate and call `hook'. */
  91. for (i = 0; i < si->mr_no; i++)
  92. if ((si->mr[i].flags & MR_ATTR_MASK) == MR_ATTR_DRAM)
  93. hook (si->mr[i].start, si->mr[i].size, GRUB_MEMORY_AVAILABLE,
  94. hook_data);
  95. return GRUB_ERR_NONE;
  96. }