setup.c 30 KB

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