Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. /** @file
  21. *
  22. * Largest memory block
  23. *
  24. */
  25. #include <stdint.h>
  26. #include <ipxe/uaccess.h>
  27. #include <ipxe/io.h>
  28. #include <ipxe/memblock.h>
  29. /**
  30. * Find largest usable memory region
  31. *
  32. * @ret start Start of region
  33. * @ret len Length of region
  34. */
  35. size_t largest_memblock ( userptr_t *start ) {
  36. struct memory_map memmap;
  37. struct memory_region *region;
  38. physaddr_t max = ~( ( physaddr_t ) 0 );
  39. physaddr_t region_start;
  40. physaddr_t region_end;
  41. size_t region_len;
  42. unsigned int i;
  43. size_t len = 0;
  44. /* Avoid returning uninitialised data on error */
  45. *start = UNULL;
  46. /* Scan through all memory regions */
  47. get_memmap ( &memmap );
  48. for ( i = 0 ; i < memmap.count ; i++ ) {
  49. region = &memmap.regions[i];
  50. DBG ( "Considering [%llx,%llx)\n", region->start, region->end );
  51. /* Truncate block to maximum physical address */
  52. if ( region->start > max ) {
  53. DBG ( "...starts after maximum address %lx\n", max );
  54. continue;
  55. }
  56. region_start = region->start;
  57. if ( region->end > max ) {
  58. DBG ( "...end truncated to maximum address %lx\n", max);
  59. region_end = 0; /* =max, given the wraparound */
  60. } else {
  61. region_end = region->end;
  62. }
  63. region_len = ( region_end - region_start );
  64. /* Use largest block */
  65. if ( region_len > len ) {
  66. DBG ( "...new best block found\n" );
  67. *start = phys_to_user ( region_start );
  68. len = region_len;
  69. }
  70. }
  71. return len;
  72. }