setup.c 27 KB

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