memblock.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #define MAX_MEMBLOCK_REGIONS 128
  17. struct memblock_region {
  18. u64 base;
  19. u64 size;
  20. };
  21. struct memblock_type {
  22. unsigned long cnt;
  23. u64 size;
  24. struct memblock_region regions[MAX_MEMBLOCK_REGIONS+1];
  25. };
  26. struct memblock {
  27. unsigned long debug;
  28. u64 rmo_size;
  29. struct memblock_type memory;
  30. struct memblock_type reserved;
  31. };
  32. extern struct memblock memblock;
  33. extern void __init memblock_init(void);
  34. extern void __init memblock_analyze(void);
  35. extern long memblock_add(u64 base, u64 size);
  36. extern long memblock_remove(u64 base, u64 size);
  37. extern long __init memblock_free(u64 base, u64 size);
  38. extern long __init memblock_reserve(u64 base, u64 size);
  39. extern u64 __init memblock_alloc_nid(u64 size, u64 align, int nid,
  40. u64 (*nid_range)(u64, u64, int *));
  41. extern u64 __init memblock_alloc(u64 size, u64 align);
  42. extern u64 __init memblock_alloc_base(u64 size,
  43. u64, u64 max_addr);
  44. extern u64 __init __memblock_alloc_base(u64 size,
  45. u64 align, u64 max_addr);
  46. extern u64 __init memblock_phys_mem_size(void);
  47. extern u64 memblock_end_of_DRAM(void);
  48. extern void __init memblock_enforce_memory_limit(u64 memory_limit);
  49. extern int __init memblock_is_reserved(u64 addr);
  50. extern int memblock_is_region_reserved(u64 base, u64 size);
  51. extern int memblock_find(struct memblock_region *res);
  52. extern void memblock_dump_all(void);
  53. static inline u64
  54. memblock_size_bytes(struct memblock_type *type, unsigned long region_nr)
  55. {
  56. return type->regions[region_nr].size;
  57. }
  58. static inline u64
  59. memblock_size_pages(struct memblock_type *type, unsigned long region_nr)
  60. {
  61. return memblock_size_bytes(type, region_nr) >> PAGE_SHIFT;
  62. }
  63. static inline u64
  64. memblock_start_pfn(struct memblock_type *type, unsigned long region_nr)
  65. {
  66. return type->regions[region_nr].base >> PAGE_SHIFT;
  67. }
  68. static inline u64
  69. memblock_end_pfn(struct memblock_type *type, unsigned long region_nr)
  70. {
  71. return memblock_start_pfn(type, region_nr) +
  72. memblock_size_pages(type, region_nr);
  73. }
  74. #include <asm/memblock.h>
  75. #endif /* __KERNEL__ */
  76. #endif /* _LINUX_MEMBLOCK_H */