memblock.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 rmo_size;
  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. u64 (*nid_range)(u64, u64, int *));
  42. extern u64 __init memblock_alloc(u64 size, u64 align);
  43. extern u64 __init memblock_alloc_base(u64 size,
  44. u64, u64 max_addr);
  45. extern u64 __init __memblock_alloc_base(u64 size,
  46. u64 align, u64 max_addr);
  47. extern u64 __init memblock_phys_mem_size(void);
  48. extern u64 memblock_end_of_DRAM(void);
  49. extern void __init memblock_enforce_memory_limit(u64 memory_limit);
  50. extern int memblock_is_memory(u64 addr);
  51. extern int memblock_is_region_memory(u64 base, u64 size);
  52. extern int __init memblock_is_reserved(u64 addr);
  53. extern int memblock_is_region_reserved(u64 base, u64 size);
  54. extern void memblock_dump_all(void);
  55. /*
  56. * pfn conversion functions
  57. *
  58. * While the memory MEMBLOCKs should always be page aligned, the reserved
  59. * MEMBLOCKs may not be. This accessor attempt to provide a very clear
  60. * idea of what they return for such non aligned MEMBLOCKs.
  61. */
  62. /**
  63. * memblock_region_base_pfn - Return the lowest pfn intersecting with the region
  64. * @reg: memblock_region structure
  65. */
  66. static inline unsigned long memblock_region_base_pfn(const struct memblock_region *reg)
  67. {
  68. return reg->base >> PAGE_SHIFT;
  69. }
  70. /**
  71. * memblock_region_last_pfn - Return the highest pfn intersecting with the region
  72. * @reg: memblock_region structure
  73. */
  74. static inline unsigned long memblock_region_last_pfn(const struct memblock_region *reg)
  75. {
  76. return (reg->base + reg->size - 1) >> PAGE_SHIFT;
  77. }
  78. /**
  79. * memblock_region_end_pfn - Return the pfn of the first page following the region
  80. * but not intersecting it
  81. * @reg: memblock_region structure
  82. */
  83. static inline unsigned long memblock_region_end_pfn(const struct memblock_region *reg)
  84. {
  85. return memblock_region_last_pfn(reg) + 1;
  86. }
  87. /**
  88. * memblock_region_pages - Return the number of pages covering a region
  89. * @reg: memblock_region structure
  90. */
  91. static inline unsigned long memblock_region_pages(const struct memblock_region *reg)
  92. {
  93. return memblock_region_end_pfn(reg) - memblock_region_end_pfn(reg);
  94. }
  95. #define for_each_memblock(memblock_type, region) \
  96. for (region = memblock.memblock_type.regions; \
  97. region < (memblock.memblock_type.regions + memblock.memblock_type.cnt); \
  98. region++)
  99. #endif /* __KERNEL__ */
  100. #endif /* _LINUX_MEMBLOCK_H */