setup.c 27 KB

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