memblock.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef _LINUX_MEMBLOCK_H
  2. #define _LINUX_MEMBLOCK_H
  3. #ifdef __KERNEL__
  4. /*
  5. * Logical memory blocks.
  6. *
  7. * Copyright (C) 2001 Peter Bergner, IBM Corp.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/mm.h>
  16. #include <asm/memblock.h>
  17. #define MAX_MEMBLOCK_REGIONS 128
  18. struct memblock_region {
  19. u64 base;
  20. u64 size;
  21. };
  22. struct memblock_type {
  23. unsigned long cnt;
  24. u64 size;
  25. struct memblock_region regions[MAX_MEMBLOCK_REGIONS+1];
  26. };
  27. struct memblock {
  28. unsigned long debug;
  29. u64 current_limit;
  30. struct memblock_type memory;
  31. struct memblock_type reserved;
  32. };
  33. extern struct memblock memblock;
  34. extern void __init memblock_init(void);
  35. extern void __init memblock_analyze(void);
  36. extern long memblock_add(u64 base, u64 size);
  37. extern long memblock_remove(u64 base, u64 size);
  38. extern long __init memblock_free(u64 base, u64 size);
  39. extern long __init memblock_reserve(u64 base, u64 size);
  40. extern u64 __init memblock_alloc_nid(u64 size, u64 align, int nid);
  41. extern u64 __init memblock_alloc(u64 size, u64 align);
  42. /* Flags for memblock_alloc_base() amd __memblock_alloc_base() */
  43. #define MEMBLOCK_ALLOC_ANYWHERE (~(u64)0)
  44. #define MEMBLOCK_ALLOC_ACCESSIBLE 0
  45. extern u64 __init memblock_alloc_base(u64 size,
  46. u64, u64 max_addr);
  47. extern u64 __init __memblock_alloc_base(u64 size,
  48. u64 align, u64 max_addr);
  49. extern u64 __init memblock_phys_mem_size(void);
  50. extern u64 memblock_end_of_DRAM(void);
  51. extern void __init memblock_enforce_memory_limit(u64 memory_limit);
  52. extern int memblock_is_memory(u64 addr);
  53. extern int memblock_is_region_memory(u64 base, u64 size);
  54. extern int __init memblock_is_reserved(u64 addr);
  55. extern int memblock_is_region_reserved(u64 base, u64 size);
  56. extern void memblock_dump_all(void);
  57. /* Provided by the architecture */
  58. extern u64 memblock_nid_range(u64 start, u64 end, int *nid);
  59. /**
  60. * memblock_set_current_limit - Set the current allocation limit to allow
  61. * limiting allocations to what is currently
  62. * accessible during boot
  63. * @limit: New limit value (physical address)
  64. */
  65. extern void memblock_set_current_limit(u64 limit);
  66. /*
  67. * pfn conversion functions
  68. *
  69. * While the memory MEMBLOCKs should always be page aligned, the reserved
  70. * MEMBLOCKs may not be. This accessor attempt to provide a very clear
  71. * idea of what they return for such non aligned MEMBLOCKs.
  72. */
  73. /**
  74. * memblock_region_base_pfn - Return the lowest pfn intersecting with the region
  75. * @reg: memblock_region structure
  76. */
  77. static inline unsigned long memblock_region_base_pfn(const struct memblock_region *reg)
  78. {
  79. return reg->base >> PAGE_SHIFT;
  80. }
  81. /**
  82. * memblock_region_last_pfn - Return the highest pfn intersecting with the region
  83. * @reg: memblock_region structure
  84. */
  85. static inline unsigned long memblock_region_last_pfn(const struct memblock_region *reg)
  86. {
  87. return (reg->base + reg->size - 1) >> PAGE_SHIFT;
  88. }
  89. /**
  90. * memblock_region_end_pfn - Return the pfn of the first page following the region
  91. * but not intersecting it
  92. * @reg: memblock_region structure
  93. */
  94. static inline unsigned long memblock_region_end_pfn(const struct memblock_region *reg)
  95. {
  96. return memblock_region_last_pfn(reg) + 1;
  97. }
  98. /**
  99. * memblock_region_pages - Return the number of pages covering a region
  100. * @reg: memblock_region structure
  101. */
  102. static inline unsigned long memblock_region_pages(const struct memblock_region *reg)
  103. {
  104. return memblock_region_end_pfn(reg) - memblock_region_end_pfn(reg);
  105. }
  106. #define for_each_memblock(memblock_type, region) \
  107. for (region = memblock.memblock_type.regions; \
  108. region < (memblock.memblock_type.regions + memblock.memblock_type.cnt); \
  109. region++)
  110. #endif /* __KERNEL__ */
  111. #endif /* _LINUX_MEMBLOCK_H */