setup.c 31 KB

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