setup.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. /*
  2. * arch/blackfin/kernel/setup.c
  3. *
  4. * Copyright 2004-2006 Analog Devices Inc.
  5. *
  6. * Enter bugs at http://blackfin.uclinux.org/
  7. *
  8. * Licensed under the GPL-2 or later.
  9. */
  10. #include <linux/delay.h>
  11. #include <linux/console.h>
  12. #include <linux/bootmem.h>
  13. #include <linux/seq_file.h>
  14. #include <linux/cpu.h>
  15. #include <linux/module.h>
  16. #include <linux/tty.h>
  17. #include <linux/pfn.h>
  18. #include <linux/ext2_fs.h>
  19. #include <linux/cramfs_fs.h>
  20. #include <linux/romfs_fs.h>
  21. #include <asm/cplb.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/blackfin.h>
  24. #include <asm/cplbinit.h>
  25. #include <asm/div64.h>
  26. #include <asm/fixed_code.h>
  27. #include <asm/early_printk.h>
  28. static DEFINE_PER_CPU(struct cpu, cpu_devices);
  29. u16 _bfin_swrst;
  30. unsigned long memory_start, memory_end, physical_mem_end;
  31. unsigned long reserved_mem_dcache_on;
  32. unsigned long reserved_mem_icache_on;
  33. EXPORT_SYMBOL(memory_start);
  34. EXPORT_SYMBOL(memory_end);
  35. EXPORT_SYMBOL(physical_mem_end);
  36. EXPORT_SYMBOL(_ramend);
  37. #ifdef CONFIG_MTD_UCLINUX
  38. unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
  39. unsigned long _ebss;
  40. EXPORT_SYMBOL(memory_mtd_end);
  41. EXPORT_SYMBOL(memory_mtd_start);
  42. EXPORT_SYMBOL(mtd_size);
  43. #endif
  44. char __initdata command_line[COMMAND_LINE_SIZE];
  45. /* boot memmap, for parsing "memmap=" */
  46. #define BFIN_MEMMAP_MAX 128 /* number of entries in bfin_memmap */
  47. #define BFIN_MEMMAP_RAM 1
  48. #define BFIN_MEMMAP_RESERVED 2
  49. struct bfin_memmap {
  50. int nr_map;
  51. struct bfin_memmap_entry {
  52. unsigned long long addr; /* start of memory segment */
  53. unsigned long long size;
  54. unsigned long type;
  55. } map[BFIN_MEMMAP_MAX];
  56. } bfin_memmap __initdata;
  57. /* for memmap sanitization */
  58. struct change_member {
  59. struct bfin_memmap_entry *pentry; /* pointer to original entry */
  60. unsigned long long addr; /* address for this change point */
  61. };
  62. static struct change_member change_point_list[2*BFIN_MEMMAP_MAX] __initdata;
  63. static struct change_member *change_point[2*BFIN_MEMMAP_MAX] __initdata;
  64. static struct bfin_memmap_entry *overlap_list[BFIN_MEMMAP_MAX] __initdata;
  65. static struct bfin_memmap_entry new_map[BFIN_MEMMAP_MAX] __initdata;
  66. void __init bf53x_cache_init(void)
  67. {
  68. #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
  69. generate_cpl_tables();
  70. #endif
  71. #ifdef CONFIG_BFIN_ICACHE
  72. bfin_icache_init();
  73. printk(KERN_INFO "Instruction Cache Enabled\n");
  74. #endif
  75. #ifdef CONFIG_BFIN_DCACHE
  76. bfin_dcache_init();
  77. printk(KERN_INFO "Data Cache Enabled"
  78. # if defined CONFIG_BFIN_WB
  79. " (write-back)"
  80. # elif defined CONFIG_BFIN_WT
  81. " (write-through)"
  82. # endif
  83. "\n");
  84. #endif
  85. }
  86. void __init bf53x_relocate_l1_mem(void)
  87. {
  88. unsigned long l1_code_length;
  89. unsigned long l1_data_a_length;
  90. unsigned long l1_data_b_length;
  91. l1_code_length = _etext_l1 - _stext_l1;
  92. if (l1_code_length > L1_CODE_LENGTH)
  93. l1_code_length = L1_CODE_LENGTH;
  94. /* cannot complain as printk is not available as yet.
  95. * But we can continue booting and complain later!
  96. */
  97. /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
  98. dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
  99. l1_data_a_length = _ebss_l1 - _sdata_l1;
  100. if (l1_data_a_length > L1_DATA_A_LENGTH)
  101. l1_data_a_length = L1_DATA_A_LENGTH;
  102. /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
  103. dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
  104. l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
  105. if (l1_data_b_length > L1_DATA_B_LENGTH)
  106. l1_data_b_length = L1_DATA_B_LENGTH;
  107. /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
  108. dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
  109. l1_data_a_length, l1_data_b_length);
  110. }
  111. /* add_memory_region to memmap */
  112. static void __init add_memory_region(unsigned long long start,
  113. unsigned long long size, int type)
  114. {
  115. int i;
  116. i = bfin_memmap.nr_map;
  117. if (i == BFIN_MEMMAP_MAX) {
  118. printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
  119. return;
  120. }
  121. bfin_memmap.map[i].addr = start;
  122. bfin_memmap.map[i].size = size;
  123. bfin_memmap.map[i].type = type;
  124. bfin_memmap.nr_map++;
  125. }
  126. /*
  127. * Sanitize the boot memmap, removing overlaps.
  128. */
  129. static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map)
  130. {
  131. struct change_member *change_tmp;
  132. unsigned long current_type, last_type;
  133. unsigned long long last_addr;
  134. int chgidx, still_changing;
  135. int overlap_entries;
  136. int new_entry;
  137. int old_nr, new_nr, chg_nr;
  138. int i;
  139. /*
  140. Visually we're performing the following (1,2,3,4 = memory types)
  141. Sample memory map (w/overlaps):
  142. ____22__________________
  143. ______________________4_
  144. ____1111________________
  145. _44_____________________
  146. 11111111________________
  147. ____________________33__
  148. ___________44___________
  149. __________33333_________
  150. ______________22________
  151. ___________________2222_
  152. _________111111111______
  153. _____________________11_
  154. _________________4______
  155. Sanitized equivalent (no overlap):
  156. 1_______________________
  157. _44_____________________
  158. ___1____________________
  159. ____22__________________
  160. ______11________________
  161. _________1______________
  162. __________3_____________
  163. ___________44___________
  164. _____________33_________
  165. _______________2________
  166. ________________1_______
  167. _________________4______
  168. ___________________2____
  169. ____________________33__
  170. ______________________4_
  171. */
  172. /* if there's only one memory region, don't bother */
  173. if (*pnr_map < 2)
  174. return -1;
  175. old_nr = *pnr_map;
  176. /* bail out if we find any unreasonable addresses in memmap */
  177. for (i = 0; i < old_nr; i++)
  178. if (map[i].addr + map[i].size < map[i].addr)
  179. return -1;
  180. /* create pointers for initial change-point information (for sorting) */
  181. for (i = 0; i < 2*old_nr; i++)
  182. change_point[i] = &change_point_list[i];
  183. /* record all known change-points (starting and ending addresses),
  184. omitting those that are for empty memory regions */
  185. chgidx = 0;
  186. for (i = 0; i < old_nr; i++) {
  187. if (map[i].size != 0) {
  188. change_point[chgidx]->addr = map[i].addr;
  189. change_point[chgidx++]->pentry = &map[i];
  190. change_point[chgidx]->addr = map[i].addr + map[i].size;
  191. change_point[chgidx++]->pentry = &map[i];
  192. }
  193. }
  194. chg_nr = chgidx; /* true number of change-points */
  195. /* sort change-point list by memory addresses (low -> high) */
  196. still_changing = 1;
  197. while (still_changing) {
  198. still_changing = 0;
  199. for (i = 1; i < chg_nr; i++) {
  200. /* if <current_addr> > <last_addr>, swap */
  201. /* or, if current=<start_addr> & last=<end_addr>, swap */
  202. if ((change_point[i]->addr < change_point[i-1]->addr) ||
  203. ((change_point[i]->addr == change_point[i-1]->addr) &&
  204. (change_point[i]->addr == change_point[i]->pentry->addr) &&
  205. (change_point[i-1]->addr != change_point[i-1]->pentry->addr))
  206. ) {
  207. change_tmp = change_point[i];
  208. change_point[i] = change_point[i-1];
  209. change_point[i-1] = change_tmp;
  210. still_changing = 1;
  211. }
  212. }
  213. }
  214. /* create a new memmap, removing overlaps */
  215. overlap_entries = 0; /* number of entries in the overlap table */
  216. new_entry = 0; /* index for creating new memmap entries */
  217. last_type = 0; /* start with undefined memory type */
  218. last_addr = 0; /* start with 0 as last starting address */
  219. /* loop through change-points, determining affect on the new memmap */
  220. for (chgidx = 0; chgidx < chg_nr; chgidx++) {
  221. /* keep track of all overlapping memmap entries */
  222. if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) {
  223. /* add map entry to overlap list (> 1 entry implies an overlap) */
  224. overlap_list[overlap_entries++] = change_point[chgidx]->pentry;
  225. } else {
  226. /* remove entry from list (order independent, so swap with last) */
  227. for (i = 0; i < overlap_entries; i++) {
  228. if (overlap_list[i] == change_point[chgidx]->pentry)
  229. overlap_list[i] = overlap_list[overlap_entries-1];
  230. }
  231. overlap_entries--;
  232. }
  233. /* if there are overlapping entries, decide which "type" to use */
  234. /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
  235. current_type = 0;
  236. for (i = 0; i < overlap_entries; i++)
  237. if (overlap_list[i]->type > current_type)
  238. current_type = overlap_list[i]->type;
  239. /* continue building up new memmap based on this information */
  240. if (current_type != last_type) {
  241. if (last_type != 0) {
  242. new_map[new_entry].size =
  243. change_point[chgidx]->addr - last_addr;
  244. /* move forward only if the new size was non-zero */
  245. if (new_map[new_entry].size != 0)
  246. if (++new_entry >= BFIN_MEMMAP_MAX)
  247. break; /* no more space left for new entries */
  248. }
  249. if (current_type != 0) {
  250. new_map[new_entry].addr = change_point[chgidx]->addr;
  251. new_map[new_entry].type = current_type;
  252. last_addr = change_point[chgidx]->addr;
  253. }
  254. last_type = current_type;
  255. }
  256. }
  257. new_nr = new_entry; /* retain count for new entries */
  258. /* copy new mapping into original location */
  259. memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry));
  260. *pnr_map = new_nr;
  261. return 0;
  262. }
  263. static void __init print_memory_map(char *who)
  264. {
  265. int i;
  266. for (i = 0; i < bfin_memmap.nr_map; i++) {
  267. printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who,
  268. bfin_memmap.map[i].addr,
  269. bfin_memmap.map[i].addr + bfin_memmap.map[i].size);
  270. switch (bfin_memmap.map[i].type) {
  271. case BFIN_MEMMAP_RAM:
  272. printk("(usable)\n");
  273. break;
  274. case BFIN_MEMMAP_RESERVED:
  275. printk("(reserved)\n");
  276. break;
  277. default: printk("type %lu\n", bfin_memmap.map[i].type);
  278. break;
  279. }
  280. }
  281. }
  282. static __init int parse_memmap(char *arg)
  283. {
  284. unsigned long long start_at, mem_size;
  285. if (!arg)
  286. return -EINVAL;
  287. mem_size = memparse(arg, &arg);
  288. if (*arg == '@') {
  289. start_at = memparse(arg+1, &arg);
  290. add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM);
  291. } else if (*arg == '$') {
  292. start_at = memparse(arg+1, &arg);
  293. add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED);
  294. }
  295. return 0;
  296. }
  297. /*
  298. * Initial parsing of the command line. Currently, we support:
  299. * - Controlling the linux memory size: mem=xxx[KMG]
  300. * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
  301. * $ -> reserved memory is dcacheable
  302. * # -> reserved memory is icacheable
  303. * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
  304. * @ from <start> to <start>+<mem>, type RAM
  305. * $ from <start> to <start>+<mem>, type RESERVED
  306. *
  307. */
  308. static __init void parse_cmdline_early(char *cmdline_p)
  309. {
  310. char c = ' ', *to = cmdline_p;
  311. unsigned int memsize;
  312. for (;;) {
  313. if (c == ' ') {
  314. if (!memcmp(to, "mem=", 4)) {
  315. to += 4;
  316. memsize = memparse(to, &to);
  317. if (memsize)
  318. _ramend = memsize;
  319. } else if (!memcmp(to, "max_mem=", 8)) {
  320. to += 8;
  321. memsize = memparse(to, &to);
  322. if (memsize) {
  323. physical_mem_end = memsize;
  324. if (*to != ' ') {
  325. if (*to == '$'
  326. || *(to + 1) == '$')
  327. reserved_mem_dcache_on =
  328. 1;
  329. if (*to == '#'
  330. || *(to + 1) == '#')
  331. reserved_mem_icache_on =
  332. 1;
  333. }
  334. }
  335. } else if (!memcmp(to, "earlyprintk=", 12)) {
  336. to += 12;
  337. setup_early_printk(to);
  338. } else if (!memcmp(to, "memmap=", 7)) {
  339. to += 7;
  340. parse_memmap(to);
  341. }
  342. }
  343. c = *(to++);
  344. if (!c)
  345. break;
  346. }
  347. }
  348. /*
  349. * Setup memory defaults from user config.
  350. * The physical memory layout looks like:
  351. *
  352. * [_rambase, _ramstart]: kernel image
  353. * [memory_start, memory_end]: dynamic memory managed by kernel
  354. * [memory_end, _ramend]: reserved memory
  355. * [meory_mtd_start(memory_end),
  356. * memory_mtd_start + mtd_size]: rootfs (if any)
  357. * [_ramend - DMA_UNCACHED_REGION,
  358. * _ramend]: uncached DMA region
  359. * [_ramend, physical_mem_end]: memory not managed by kernel
  360. *
  361. */
  362. static __init void memory_setup(void)
  363. {
  364. _rambase = (unsigned long)_stext;
  365. _ramstart = (unsigned long)_end;
  366. if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
  367. console_init();
  368. panic("DMA region exceeds memory limit: %lu.\n",
  369. _ramend - _ramstart);
  370. }
  371. memory_end = _ramend - DMA_UNCACHED_REGION;
  372. #ifdef CONFIG_MPU
  373. /* Round up to multiple of 4MB. */
  374. memory_start = (_ramstart + 0x3fffff) & ~0x3fffff;
  375. #else
  376. memory_start = PAGE_ALIGN(_ramstart);
  377. #endif
  378. #if defined(CONFIG_MTD_UCLINUX)
  379. /* generic memory mapped MTD driver */
  380. memory_mtd_end = memory_end;
  381. mtd_phys = _ramstart;
  382. mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
  383. # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
  384. if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
  385. mtd_size =
  386. PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
  387. # endif
  388. # if defined(CONFIG_CRAMFS)
  389. if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
  390. mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
  391. # endif
  392. # if defined(CONFIG_ROMFS_FS)
  393. if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
  394. && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
  395. mtd_size =
  396. PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
  397. # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
  398. /* Due to a Hardware Anomaly we need to limit the size of usable
  399. * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
  400. * 05000263 - Hardware loop corrupted when taking an ICPLB exception
  401. */
  402. # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
  403. if (memory_end >= 56 * 1024 * 1024)
  404. memory_end = 56 * 1024 * 1024;
  405. # else
  406. if (memory_end >= 60 * 1024 * 1024)
  407. memory_end = 60 * 1024 * 1024;
  408. # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
  409. # endif /* ANOMALY_05000263 */
  410. # endif /* CONFIG_ROMFS_FS */
  411. memory_end -= mtd_size;
  412. if (mtd_size == 0) {
  413. console_init();
  414. panic("Don't boot kernel without rootfs attached.\n");
  415. }
  416. /* Relocate MTD image to the top of memory after the uncached memory area */
  417. dma_memcpy((char *)memory_end, _end, mtd_size);
  418. memory_mtd_start = memory_end;
  419. _ebss = memory_mtd_start; /* define _ebss for compatible */
  420. #endif /* CONFIG_MTD_UCLINUX */
  421. #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
  422. /* Due to a Hardware Anomaly we need to limit the size of usable
  423. * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
  424. * 05000263 - Hardware loop corrupted when taking an ICPLB exception
  425. */
  426. #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
  427. if (memory_end >= 56 * 1024 * 1024)
  428. memory_end = 56 * 1024 * 1024;
  429. #else
  430. if (memory_end >= 60 * 1024 * 1024)
  431. memory_end = 60 * 1024 * 1024;
  432. #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
  433. printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
  434. #endif /* ANOMALY_05000263 */
  435. #ifdef CONFIG_MPU
  436. page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32;
  437. page_mask_order = get_order(3 * page_mask_nelts * sizeof(long));
  438. #endif
  439. #if !defined(CONFIG_MTD_UCLINUX)
  440. /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
  441. memory_end -= SIZE_4K;
  442. #endif
  443. init_mm.start_code = (unsigned long)_stext;
  444. init_mm.end_code = (unsigned long)_etext;
  445. init_mm.end_data = (unsigned long)_edata;
  446. init_mm.brk = (unsigned long)0;
  447. printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
  448. printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
  449. printk(KERN_INFO "Memory map:\n"
  450. KERN_INFO " text = 0x%p-0x%p\n"
  451. KERN_INFO " rodata = 0x%p-0x%p\n"
  452. KERN_INFO " bss = 0x%p-0x%p\n"
  453. KERN_INFO " data = 0x%p-0x%p\n"
  454. KERN_INFO " stack = 0x%p-0x%p\n"
  455. KERN_INFO " init = 0x%p-0x%p\n"
  456. KERN_INFO " available = 0x%p-0x%p\n"
  457. #ifdef CONFIG_MTD_UCLINUX
  458. KERN_INFO " rootfs = 0x%p-0x%p\n"
  459. #endif
  460. #if DMA_UNCACHED_REGION > 0
  461. KERN_INFO " DMA Zone = 0x%p-0x%p\n"
  462. #endif
  463. , _stext, _etext,
  464. __start_rodata, __end_rodata,
  465. __bss_start, __bss_stop,
  466. _sdata, _edata,
  467. (void *)&init_thread_union,
  468. (void *)((int)(&init_thread_union) + 0x2000),
  469. __init_begin, __init_end,
  470. (void *)_ramstart, (void *)memory_end
  471. #ifdef CONFIG_MTD_UCLINUX
  472. , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
  473. #endif
  474. #if DMA_UNCACHED_REGION > 0
  475. , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
  476. #endif
  477. );
  478. }
  479. static __init void setup_bootmem_allocator(void)
  480. {
  481. int bootmap_size;
  482. int i;
  483. unsigned long min_pfn, max_pfn;
  484. unsigned long curr_pfn, last_pfn, size;
  485. /* mark memory between memory_start and memory_end usable */
  486. add_memory_region(memory_start,
  487. memory_end - memory_start, BFIN_MEMMAP_RAM);
  488. /* sanity check for overlap */
  489. sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
  490. print_memory_map("boot memmap");
  491. min_pfn = PAGE_OFFSET >> PAGE_SHIFT;
  492. max_pfn = memory_end >> PAGE_SHIFT;
  493. /*
  494. * give all the memory to the bootmap allocator, tell it to put the
  495. * boot mem_map at the start of memory.
  496. */
  497. bootmap_size = init_bootmem_node(NODE_DATA(0),
  498. memory_start >> PAGE_SHIFT, /* map goes here */
  499. min_pfn, max_pfn);
  500. /* register the memmap regions with the bootmem allocator */
  501. for (i = 0; i < bfin_memmap.nr_map; i++) {
  502. /*
  503. * Reserve usable memory
  504. */
  505. if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
  506. continue;
  507. /*
  508. * We are rounding up the start address of usable memory:
  509. */
  510. curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
  511. if (curr_pfn >= max_pfn)
  512. continue;
  513. /*
  514. * ... and at the end of the usable range downwards:
  515. */
  516. last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
  517. bfin_memmap.map[i].size);
  518. if (last_pfn > max_pfn)
  519. last_pfn = max_pfn;
  520. /*
  521. * .. finally, did all the rounding and playing
  522. * around just make the area go away?
  523. */
  524. if (last_pfn <= curr_pfn)
  525. continue;
  526. size = last_pfn - curr_pfn;
  527. free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
  528. }
  529. /* reserve memory before memory_start, including bootmap */
  530. reserve_bootmem(PAGE_OFFSET,
  531. memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET,
  532. BOOTMEM_DEFAULT);
  533. }
  534. void __init setup_arch(char **cmdline_p)
  535. {
  536. unsigned long l1_length, sclk, cclk;
  537. #ifdef CONFIG_MTD_UCLINUX
  538. unsigned long mtd_phys = 0;
  539. #endif
  540. #ifdef CONFIG_DUMMY_CONSOLE
  541. conswitchp = &dummy_con;
  542. #endif
  543. #if defined(CONFIG_CMDLINE_BOOL)
  544. strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
  545. command_line[sizeof(command_line) - 1] = 0;
  546. #endif
  547. /* Keep a copy of command line */
  548. *cmdline_p = &command_line[0];
  549. memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  550. boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
  551. /* setup memory defaults from the user config */
  552. physical_mem_end = 0;
  553. _ramend = CONFIG_MEM_SIZE * 1024 * 1024;
  554. memset(&bfin_memmap, 0, sizeof(bfin_memmap));
  555. parse_cmdline_early(&command_line[0]);
  556. if (physical_mem_end == 0)
  557. physical_mem_end = _ramend;
  558. memory_setup();
  559. cclk = get_cclk();
  560. sclk = get_sclk();
  561. #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
  562. if (ANOMALY_05000273 && cclk == sclk)
  563. panic("ANOMALY 05000273, SCLK can not be same as CCLK");
  564. #endif
  565. #ifdef BF561_FAMILY
  566. if (ANOMALY_05000266) {
  567. bfin_read_IMDMA_D0_IRQ_STATUS();
  568. bfin_read_IMDMA_D1_IRQ_STATUS();
  569. }
  570. #endif
  571. printk(KERN_INFO "Hardware Trace ");
  572. if (bfin_read_TBUFCTL() & 0x1)
  573. printk("Active ");
  574. else
  575. printk("Off ");
  576. if (bfin_read_TBUFCTL() & 0x2)
  577. printk("and Enabled\n");
  578. else
  579. printk("and Disabled\n");
  580. #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
  581. /* we need to initialize the Flashrom device here since we might
  582. * do things with flash early on in the boot
  583. */
  584. flash_probe();
  585. #endif
  586. _bfin_swrst = bfin_read_SWRST();
  587. if (_bfin_swrst & RESET_DOUBLE)
  588. printk(KERN_INFO "Recovering from Double Fault event\n");
  589. else if (_bfin_swrst & RESET_WDOG)
  590. printk(KERN_INFO "Recovering from Watchdog event\n");
  591. else if (_bfin_swrst & RESET_SOFTWARE)
  592. printk(KERN_NOTICE "Reset caused by Software reset\n");
  593. printk(KERN_INFO "Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
  594. if (bfin_compiled_revid() == 0xffff)
  595. printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
  596. else if (bfin_compiled_revid() == -1)
  597. printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
  598. else
  599. printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
  600. if (bfin_revid() != bfin_compiled_revid()) {
  601. if (bfin_compiled_revid() == -1)
  602. printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
  603. bfin_revid());
  604. else if (bfin_compiled_revid() != 0xffff)
  605. printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
  606. bfin_compiled_revid(), bfin_revid());
  607. }
  608. if (bfin_revid() < SUPPORTED_REVID)
  609. printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
  610. CPU, bfin_revid());
  611. printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
  612. printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
  613. cclk / 1000000, sclk / 1000000);
  614. if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
  615. printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
  616. setup_bootmem_allocator();
  617. paging_init();
  618. /* check the size of the l1 area */
  619. l1_length = _etext_l1 - _stext_l1;
  620. if (l1_length > L1_CODE_LENGTH)
  621. panic("L1 code memory overflow\n");
  622. l1_length = _ebss_l1 - _sdata_l1;
  623. if (l1_length > L1_DATA_A_LENGTH)
  624. panic("L1 data memory overflow\n");
  625. /* Copy atomic sequences to their fixed location, and sanity check that
  626. these locations are the ones that we advertise to userspace. */
  627. memcpy((void *)FIXED_CODE_START, &fixed_code_start,
  628. FIXED_CODE_END - FIXED_CODE_START);
  629. BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
  630. != SIGRETURN_STUB - FIXED_CODE_START);
  631. BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
  632. != ATOMIC_XCHG32 - FIXED_CODE_START);
  633. BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
  634. != ATOMIC_CAS32 - FIXED_CODE_START);
  635. BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
  636. != ATOMIC_ADD32 - FIXED_CODE_START);
  637. BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
  638. != ATOMIC_SUB32 - FIXED_CODE_START);
  639. BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
  640. != ATOMIC_IOR32 - FIXED_CODE_START);
  641. BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
  642. != ATOMIC_AND32 - FIXED_CODE_START);
  643. BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
  644. != ATOMIC_XOR32 - FIXED_CODE_START);
  645. BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
  646. != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
  647. init_exception_vectors();
  648. bf53x_cache_init();
  649. }
  650. static int __init topology_init(void)
  651. {
  652. int cpu;
  653. for_each_possible_cpu(cpu) {
  654. struct cpu *c = &per_cpu(cpu_devices, cpu);
  655. register_cpu(c, cpu);
  656. }
  657. return 0;
  658. }
  659. subsys_initcall(topology_init);
  660. static u_long get_vco(void)
  661. {
  662. u_long msel;
  663. u_long vco;
  664. msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
  665. if (0 == msel)
  666. msel = 64;
  667. vco = CONFIG_CLKIN_HZ;
  668. vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
  669. vco = msel * vco;
  670. return vco;
  671. }
  672. /* Get the Core clock */
  673. u_long get_cclk(void)
  674. {
  675. u_long csel, ssel;
  676. if (bfin_read_PLL_STAT() & 0x1)
  677. return CONFIG_CLKIN_HZ;
  678. ssel = bfin_read_PLL_DIV();
  679. csel = ((ssel >> 4) & 0x03);
  680. ssel &= 0xf;
  681. if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
  682. return get_vco() / ssel;
  683. return get_vco() >> csel;
  684. }
  685. EXPORT_SYMBOL(get_cclk);
  686. /* Get the System clock */
  687. u_long get_sclk(void)
  688. {
  689. u_long ssel;
  690. if (bfin_read_PLL_STAT() & 0x1)
  691. return CONFIG_CLKIN_HZ;
  692. ssel = (bfin_read_PLL_DIV() & 0xf);
  693. if (0 == ssel) {
  694. printk(KERN_WARNING "Invalid System Clock\n");
  695. ssel = 1;
  696. }
  697. return get_vco() / ssel;
  698. }
  699. EXPORT_SYMBOL(get_sclk);
  700. unsigned long sclk_to_usecs(unsigned long sclk)
  701. {
  702. u64 tmp = USEC_PER_SEC * (u64)sclk;
  703. do_div(tmp, get_sclk());
  704. return tmp;
  705. }
  706. EXPORT_SYMBOL(sclk_to_usecs);
  707. unsigned long usecs_to_sclk(unsigned long usecs)
  708. {
  709. u64 tmp = get_sclk() * (u64)usecs;
  710. do_div(tmp, USEC_PER_SEC);
  711. return tmp;
  712. }
  713. EXPORT_SYMBOL(usecs_to_sclk);
  714. /*
  715. * Get CPU information for use by the procfs.
  716. */
  717. static int show_cpuinfo(struct seq_file *m, void *v)
  718. {
  719. char *cpu, *mmu, *fpu, *vendor, *cache;
  720. uint32_t revid;
  721. u_long cclk = 0, sclk = 0;
  722. u_int dcache_size = 0, dsup_banks = 0;
  723. cpu = CPU;
  724. mmu = "none";
  725. fpu = "none";
  726. revid = bfin_revid();
  727. cclk = get_cclk();
  728. sclk = get_sclk();
  729. switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
  730. case 0xca:
  731. vendor = "Analog Devices";
  732. break;
  733. default:
  734. vendor = "unknown";
  735. break;
  736. }
  737. seq_printf(m, "processor\t: %d\n"
  738. "vendor_id\t: %s\n"
  739. "cpu family\t: 0x%x\n"
  740. "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK)\n"
  741. "stepping\t: %d\n",
  742. 0,
  743. vendor,
  744. (bfin_read_CHIPID() & CHIPID_FAMILY),
  745. cpu, cclk/1000000, sclk/1000000,
  746. revid);
  747. seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
  748. cclk/1000000, cclk%1000000,
  749. sclk/1000000, sclk%1000000);
  750. seq_printf(m, "bogomips\t: %lu.%02lu\n"
  751. "Calibration\t: %lu loops\n",
  752. (loops_per_jiffy * HZ) / 500000,
  753. ((loops_per_jiffy * HZ) / 5000) % 100,
  754. (loops_per_jiffy * HZ));
  755. /* Check Cache configutation */
  756. switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
  757. case ACACHE_BSRAM:
  758. cache = "dbank-A/B\t: cache/sram";
  759. dcache_size = 16;
  760. dsup_banks = 1;
  761. break;
  762. case ACACHE_BCACHE:
  763. cache = "dbank-A/B\t: cache/cache";
  764. dcache_size = 32;
  765. dsup_banks = 2;
  766. break;
  767. case ASRAM_BSRAM:
  768. cache = "dbank-A/B\t: sram/sram";
  769. dcache_size = 0;
  770. dsup_banks = 0;
  771. break;
  772. default:
  773. cache = "unknown";
  774. dcache_size = 0;
  775. dsup_banks = 0;
  776. break;
  777. }
  778. /* Is it turned on? */
  779. if (!((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE)))
  780. dcache_size = 0;
  781. seq_printf(m, "cache size\t: %d KB(L1 icache) "
  782. "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
  783. BFIN_ICACHESIZE / 1024, dcache_size,
  784. #if defined CONFIG_BFIN_WB
  785. "wb"
  786. #elif defined CONFIG_BFIN_WT
  787. "wt"
  788. #endif
  789. "", 0);
  790. seq_printf(m, "%s\n", cache);
  791. seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
  792. BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
  793. seq_printf(m,
  794. "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
  795. dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
  796. BFIN_DLINES);
  797. #ifdef CONFIG_BFIN_ICACHE_LOCK
  798. switch (read_iloc()) {
  799. case WAY0_L:
  800. seq_printf(m, "Way0 Locked-Down\n");
  801. break;
  802. case WAY1_L:
  803. seq_printf(m, "Way1 Locked-Down\n");
  804. break;
  805. case WAY01_L:
  806. seq_printf(m, "Way0,Way1 Locked-Down\n");
  807. break;
  808. case WAY2_L:
  809. seq_printf(m, "Way2 Locked-Down\n");
  810. break;
  811. case WAY02_L:
  812. seq_printf(m, "Way0,Way2 Locked-Down\n");
  813. break;
  814. case WAY12_L:
  815. seq_printf(m, "Way1,Way2 Locked-Down\n");
  816. break;
  817. case WAY012_L:
  818. seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
  819. break;
  820. case WAY3_L:
  821. seq_printf(m, "Way3 Locked-Down\n");
  822. break;
  823. case WAY03_L:
  824. seq_printf(m, "Way0,Way3 Locked-Down\n");
  825. break;
  826. case WAY13_L:
  827. seq_printf(m, "Way1,Way3 Locked-Down\n");
  828. break;
  829. case WAY013_L:
  830. seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
  831. break;
  832. case WAY32_L:
  833. seq_printf(m, "Way3,Way2 Locked-Down\n");
  834. break;
  835. case WAY320_L:
  836. seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
  837. break;
  838. case WAY321_L:
  839. seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
  840. break;
  841. case WAYALL_L:
  842. seq_printf(m, "All Ways are locked\n");
  843. break;
  844. default:
  845. seq_printf(m, "No Ways are locked\n");
  846. }
  847. #endif
  848. seq_printf(m, "board name\t: %s\n", bfin_board_name);
  849. seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
  850. physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
  851. seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
  852. ((int)memory_end - (int)_stext) >> 10,
  853. _stext,
  854. (void *)memory_end);
  855. return 0;
  856. }
  857. static void *c_start(struct seq_file *m, loff_t *pos)
  858. {
  859. return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
  860. }
  861. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  862. {
  863. ++*pos;
  864. return c_start(m, pos);
  865. }
  866. static void c_stop(struct seq_file *m, void *v)
  867. {
  868. }
  869. const struct seq_operations cpuinfo_op = {
  870. .start = c_start,
  871. .next = c_next,
  872. .stop = c_stop,
  873. .show = show_cpuinfo,
  874. };
  875. void __init cmdline_init(const char *r0)
  876. {
  877. if (r0)
  878. strncpy(command_line, r0, COMMAND_LINE_SIZE);
  879. }