rtuTemperatureHumidityDataOperation.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * linux/arch/arm/mm/init.c
  3. *
  4. * Copyright (C) 1995-2005 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/errno.h>
  12. #include <linux/swap.h>
  13. #include <linux/init.h>
  14. #include <linux/bootmem.h>
  15. #include <linux/mman.h>
  16. #include <linux/export.h>
  17. #include <linux/nodemask.h>
  18. #include <linux/initrd.h>
  19. #include <linux/of_fdt.h>
  20. #include <linux/highmem.h>
  21. #include <linux/gfp.h>
  22. #include <linux/memblock.h>
  23. #include <linux/dma-contiguous.h>
  24. #include <linux/sizes.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/memblock.h>
  27. #include <asm/prom.h>
  28. #include <asm/sections.h>
  29. #include <asm/setup.h>
  30. #include <asm/tlb.h>
  31. #include <asm/fixmap.h>
  32. #include <asm/mach/arch.h>
  33. #include <asm/mach/map.h>
  34. #include "mm.h"
  35. static unsigned long phys_initrd_start __initdata = 0;
  36. static unsigned long phys_initrd_size __initdata = 0;
  37. static int __init early_initrd(char *p)
  38. {
  39. unsigned long start, size;
  40. char *endp;
  41. start = memparse(p, &endp);
  42. if (*endp == ',') {
  43. size = memparse(endp + 1, NULL);
  44. phys_initrd_start = start;
  45. phys_initrd_size = size;
  46. }
  47. return 0;
  48. }
  49. early_param("initrd", early_initrd);
  50. static int __init parse_tag_initrd(const struct tag *tag)
  51. {
  52. printk(KERN_WARNING "ATAG_INITRD is deprecated; "
  53. "please update your bootloader.\n");
  54. phys_initrd_start = __virt_to_phys(tag->u.initrd.start);
  55. phys_initrd_size = tag->u.initrd.size;
  56. return 0;
  57. }
  58. __tagtable(ATAG_INITRD, parse_tag_initrd);
  59. static int __init parse_tag_initrd2(const struct tag *tag)
  60. {
  61. phys_initrd_start = tag->u.initrd.start;
  62. phys_initrd_size = tag->u.initrd.size;
  63. return 0;
  64. }
  65. __tagtable(ATAG_INITRD2, parse_tag_initrd2);
  66. #ifdef CONFIG_OF_FLATTREE
  67. void __init early_init_dt_setup_initrd_arch(unsigned long start, unsigned long end)
  68. {
  69. phys_initrd_start = start;
  70. phys_initrd_size = end - start;
  71. }
  72. #endif /* CONFIG_OF_FLATTREE */
  73. /*
  74. * This keeps memory configuration data used by a couple memory
  75. * initialization functions, as well as show_mem() for the skipping
  76. * of holes in the memory map. It is populated by arm_add_memory().
  77. */
  78. struct meminfo meminfo;
  79. void show_mem(unsigned int filter)
  80. {
  81. int free = 0, total = 0, reserved = 0;
  82. int shared = 0, cached = 0, slab = 0, i;
  83. struct meminfo * mi = &meminfo;
  84. printk("Mem-info:\n");
  85. show_free_areas(filter);
  86. for_each_bank (i, mi) {
  87. struct membank *bank = &mi->bank[i];
  88. unsigned int pfn1, pfn2;
  89. struct page *page, *end;
  90. pfn1 = bank_pfn_start(bank);
  91. pfn2 = bank_pfn_end(bank);
  92. page = pfn_to_page(pfn1);
  93. end = pfn_to_page(pfn2 - 1) + 1;
  94. do {
  95. total++;
  96. if (PageReserved(page))
  97. reserved++;
  98. else if (PageSwapCache(page))
  99. cached++;
  100. else if (PageSlab(page))
  101. slab++;
  102. else if (!page_count(page))
  103. free++;
  104. else
  105. shared += page_count(page) - 1;
  106. page++;
  107. } while (page < end);
  108. }
  109. printk("%d pages of RAM\n", total);
  110. printk("%d free pages\n", free);
  111. printk("%d reserved pages\n", reserved);
  112. printk("%d slab pages\n", slab);
  113. printk("%d pages shared\n", shared);
  114. printk("%d pages swap cached\n", cached);
  115. }
  116. static void __init find_limits(unsigned long *min, unsigned long *max_low,
  117. unsigned long *max_high)
  118. {
  119. struct meminfo *mi = &meminfo;
  120. int i;
  121. /* This assumes the meminfo array is properly sorted */
  122. *min = bank_pfn_start(&mi->bank[0]);
  123. for_each_bank (i, mi)
  124. if (mi->bank[i].highmem)
  125. break;
  126. *max_low = bank_pfn_end(&mi->bank[i - 1]);
  127. *max_high = bank_pfn_end(&mi->bank[mi->nr_banks - 1]);
  128. }
  129. static void __init arm_bootmem_init(unsigned long start_pfn,
  130. unsigned long end_pfn)
  131. {
  132. struct memblock_region *reg;
  133. unsigned int boot_pages;
  134. phys_addr_t bitmap;
  135. pg_data_t *pgdat;
  136. /*
  137. * Allocate the bootmem bitmap page. This must be in a region
  138. * of memory which has already been mapped.
  139. */
  140. boot_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
  141. bitmap = memblock_alloc_base(boot_pages << PAGE_SHIFT, L1_CACHE_BYTES,
  142. __pfn_to_phys(end_pfn));
  143. /*
  144. * Initialise the bootmem allocator, handing the
  145. * memory banks over to bootmem.
  146. */
  147. node_set_online(0);
  148. pgdat = NODE_DATA(0);
  149. init_bootmem_node(pgdat, __phys_to_pfn(bitmap), start_pfn, end_pfn);
  150. /* Free the lowmem regions from memblock into bootmem. */
  151. for_each_memblock(memory, reg) {
  152. unsigned long start = memblock_region_memory_base_pfn(reg);
  153. unsigned long end = memblock_region_memory_end_pfn(reg);
  154. if (end >= end_pfn)
  155. end = end_pfn;
  156. if (start >= end)
  157. break;
  158. free_bootmem(__pfn_to_phys(start), (end - start) << PAGE_SHIFT);
  159. }
  160. /* Reserve the lowmem memblock reserved regions in bootmem. */
  161. for_each_memblock(reserved, reg) {
  162. unsigned long start = memblock_region_reserved_base_pfn(reg);
  163. unsigned long end = memblock_region_reserved_end_pfn(reg);
  164. if (end >= end_pfn)
  165. end = end_pfn;
  166. if (start >= end)
  167. break;
  168. reserve_bootmem(__pfn_to_phys(start),
  169. (end - start) << PAGE_SHIFT, BOOTMEM_DEFAULT);
  170. }
  171. }
  172. #ifdef CONFIG_ZONE_DMA
  173. unsigned long arm_dma_zone_size __read_mostly;
  174. EXPORT_SYMBOL(arm_dma_zone_size);
  175. /*
  176. * The DMA mask corresponding to the maximum bus address allocatable
  177. * using GFP_DMA. The default here places no restriction on DMA
  178. * allocations. This must be the smallest DMA mask in the system,
  179. * so a successful GFP_DMA allocation will always satisfy this.
  180. */
  181. phys_addr_t arm_dma_limit;
  182. static void __init arm_adjust_dma_zone(unsigned long *size, unsigned long *hole,
  183. unsigned long dma_size)
  184. {
  185. if (size[0] <= dma_size)
  186. return;
  187. size[ZONE_NORMAL] = size[0] - dma_size;
  188. size[ZONE_DMA] = dma_size;
  189. hole[ZONE_NORMAL] = hole[0];
  190. hole[ZONE_DMA] = 0;
  191. }
  192. #endif
  193. void __init setup_dma_zone(struct machine_desc *mdesc)
  194. {
  195. #ifdef CONFIG_ZONE_DMA
  196. if (mdesc->dma_zone_size) {
  197. arm_dma_zone_size = mdesc->dma_zone_size;
  198. arm_dma_limit = PHYS_OFFSET + arm_dma_zone_size - 1;
  199. } else
  200. arm_dma_limit = 0xffffffff;
  201. #endif
  202. }
  203. static void __init arm_bootmem_free(unsigned long min, unsigned long max_low,
  204. unsigned long max_high)
  205. {
  206. unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
  207. struct memblock_region *reg;
  208. /*
  209. * initialise the zones.
  210. */
  211. memset(zone_size, 0, sizeof(zone_size));
  212. /*
  213. * The memory size has already been determined. If we need
  214. * to do anything fancy with the allocation of this memory
  215. * to the zones, now is the time to do it.
  216. */
  217. zone_size[0] = max_low - min;
  218. #ifdef CONFIG_HIGHMEM
  219. zone_size[ZONE_HIGHMEM] = max_high - max_low;
  220. #endif
  221. /*
  222. * Calculate the size of the holes.
  223. * holes = node_size - sum(bank_sizes)
  224. */
  225. memcpy(zhole_size, zone_size, sizeof(zhole_size));
  226. for_each_memblock(memory, reg) {
  227. unsigned long start = memblock_region_memory_base_pfn(reg);
  228. unsigned long end = memblock_region_memory_end_pfn(reg);
  229. if (start < max_low) {
  230. unsigned long low_end = min(end, max_low);
  231. zhole_size[0] -= low_end - start;
  232. }
  233. #ifdef CONFIG_HIGHMEM
  234. if (end > max_low) {
  235. unsigned long high_start = max(start, max_low);
  236. zhole_size[ZONE_HIGHMEM] -= end - high_start;
  237. }
  238. #endif
  239. }
  240. #ifdef CONFIG_ZONE_DMA
  241. /*
  242. * Adjust the sizes according to any special requirements for
  243. * this machine type.
  244. */
  245. if (arm_dma_zone_size)
  246. arm_adjust_dma_zone(zone_size, zhole_size,
  247. arm_dma_zone_size >> PAGE_SHIFT);
  248. #endif