setup.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  1. /*
  2. * Copyright 2004-2010 Analog Devices Inc.
  3. *
  4. * Licensed under the GPL-2 or later.
  5. */
  6. #include <linux/delay.h>
  7. #include <linux/console.h>
  8. #include <linux/bootmem.h>
  9. #include <linux/seq_file.h>
  10. #include <linux/cpu.h>
  11. #include <linux/mm.h>
  12. #include <linux/module.h>
  13. #include <linux/tty.h>
  14. #include <linux/pfn.h>
  15. #ifdef CONFIG_MTD_UCLINUX
  16. #include <linux/mtd/map.h>
  17. #include <linux/ext2_fs.h>
  18. #include <linux/cramfs_fs.h>
  19. #include <linux/romfs_fs.h>
  20. #endif
  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/cpu.h>
  27. #include <asm/fixed_code.h>
  28. #include <asm/early_printk.h>
  29. #include <asm/irq_handler.h>
  30. u16 _bfin_swrst;
  31. EXPORT_SYMBOL(_bfin_swrst);
  32. unsigned long memory_start, memory_end, physical_mem_end;
  33. unsigned long _rambase, _ramstart, _ramend;
  34. unsigned long reserved_mem_dcache_on;
  35. unsigned long reserved_mem_icache_on;
  36. EXPORT_SYMBOL(memory_start);
  37. EXPORT_SYMBOL(memory_end);
  38. EXPORT_SYMBOL(physical_mem_end);
  39. EXPORT_SYMBOL(_ramend);
  40. EXPORT_SYMBOL(reserved_mem_dcache_on);
  41. #ifdef CONFIG_MTD_UCLINUX
  42. extern struct map_info uclinux_ram_map;
  43. unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
  44. unsigned long _ebss;
  45. EXPORT_SYMBOL(memory_mtd_end);
  46. EXPORT_SYMBOL(memory_mtd_start);
  47. EXPORT_SYMBOL(mtd_size);
  48. #endif
  49. char __initdata command_line[COMMAND_LINE_SIZE];
  50. void __initdata *init_retx, *init_saved_retx, *init_saved_seqstat,
  51. *init_saved_icplb_fault_addr, *init_saved_dcplb_fault_addr;
  52. /* boot memmap, for parsing "memmap=" */
  53. #define BFIN_MEMMAP_MAX 128 /* number of entries in bfin_memmap */
  54. #define BFIN_MEMMAP_RAM 1
  55. #define BFIN_MEMMAP_RESERVED 2
  56. static struct bfin_memmap {
  57. int nr_map;
  58. struct bfin_memmap_entry {
  59. unsigned long long addr; /* start of memory segment */
  60. unsigned long long size;
  61. unsigned long type;
  62. } map[BFIN_MEMMAP_MAX];
  63. } bfin_memmap __initdata;
  64. /* for memmap sanitization */
  65. struct change_member {
  66. struct bfin_memmap_entry *pentry; /* pointer to original entry */
  67. unsigned long long addr; /* address for this change point */
  68. };
  69. static struct change_member change_point_list[2*BFIN_MEMMAP_MAX] __initdata;
  70. static struct change_member *change_point[2*BFIN_MEMMAP_MAX] __initdata;
  71. static struct bfin_memmap_entry *overlap_list[BFIN_MEMMAP_MAX] __initdata;
  72. static struct bfin_memmap_entry new_map[BFIN_MEMMAP_MAX] __initdata;
  73. DEFINE_PER_CPU(struct blackfin_cpudata, cpu_data);
  74. static int early_init_clkin_hz(char *buf);
  75. #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
  76. void __init generate_cplb_tables(void)
  77. {
  78. unsigned int cpu;
  79. generate_cplb_tables_all();
  80. /* Generate per-CPU I&D CPLB tables */
  81. for (cpu = 0; cpu < num_possible_cpus(); ++cpu)
  82. generate_cplb_tables_cpu(cpu);
  83. }
  84. #endif
  85. void __cpuinit bfin_setup_caches(unsigned int cpu)
  86. {
  87. #ifdef CONFIG_BFIN_ICACHE
  88. bfin_icache_init(icplb_tbl[cpu]);
  89. #endif
  90. #ifdef CONFIG_BFIN_DCACHE
  91. bfin_dcache_init(dcplb_tbl[cpu]);
  92. #endif
  93. bfin_setup_cpudata(cpu);
  94. /*
  95. * In cache coherence emulation mode, we need to have the
  96. * D-cache enabled before running any atomic operation which
  97. * might involve cache invalidation (i.e. spinlock, rwlock).
  98. * So printk's are deferred until then.
  99. */
  100. #ifdef CONFIG_BFIN_ICACHE
  101. printk(KERN_INFO "Instruction Cache Enabled for CPU%u\n", cpu);
  102. printk(KERN_INFO " External memory:"
  103. # ifdef CONFIG_BFIN_EXTMEM_ICACHEABLE
  104. " cacheable"
  105. # else
  106. " uncacheable"
  107. # endif
  108. " in instruction cache\n");
  109. if (L2_LENGTH)
  110. printk(KERN_INFO " L2 SRAM :"
  111. # ifdef CONFIG_BFIN_L2_ICACHEABLE
  112. " cacheable"
  113. # else
  114. " uncacheable"
  115. # endif
  116. " in instruction cache\n");
  117. #else
  118. printk(KERN_INFO "Instruction Cache Disabled for CPU%u\n", cpu);
  119. #endif
  120. #ifdef CONFIG_BFIN_DCACHE
  121. printk(KERN_INFO "Data Cache Enabled for CPU%u\n", cpu);
  122. printk(KERN_INFO " External memory:"
  123. # if defined CONFIG_BFIN_EXTMEM_WRITEBACK
  124. " cacheable (write-back)"
  125. # elif defined CONFIG_BFIN_EXTMEM_WRITETHROUGH
  126. " cacheable (write-through)"
  127. # else
  128. " uncacheable"
  129. # endif
  130. " in data cache\n");
  131. if (L2_LENGTH)
  132. printk(KERN_INFO " L2 SRAM :"
  133. # if defined CONFIG_BFIN_L2_WRITEBACK
  134. " cacheable (write-back)"
  135. # elif defined CONFIG_BFIN_L2_WRITETHROUGH
  136. " cacheable (write-through)"
  137. # else
  138. " uncacheable"
  139. # endif
  140. " in data cache\n");
  141. #else
  142. printk(KERN_INFO "Data Cache Disabled for CPU%u\n", cpu);
  143. #endif
  144. }
  145. void __cpuinit bfin_setup_cpudata(unsigned int cpu)
  146. {
  147. struct blackfin_cpudata *cpudata = &per_cpu(cpu_data, cpu);
  148. cpudata->imemctl = bfin_read_IMEM_CONTROL();
  149. cpudata->dmemctl = bfin_read_DMEM_CONTROL();
  150. }
  151. void __init bfin_cache_init(void)
  152. {
  153. #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
  154. generate_cplb_tables();
  155. #endif
  156. bfin_setup_caches(0);
  157. }
  158. void __init bfin_relocate_l1_mem(void)
  159. {
  160. unsigned long text_l1_len = (unsigned long)_text_l1_len;
  161. unsigned long data_l1_len = (unsigned long)_data_l1_len;
  162. unsigned long data_b_l1_len = (unsigned long)_data_b_l1_len;
  163. unsigned long l2_len = (unsigned long)_l2_len;
  164. early_shadow_stamp();
  165. /*
  166. * due to the ALIGN(4) in the arch/blackfin/kernel/vmlinux.lds.S
  167. * we know that everything about l1 text/data is nice and aligned,
  168. * so copy by 4 byte chunks, and don't worry about overlapping
  169. * src/dest.
  170. *
  171. * We can't use the dma_memcpy functions, since they can call
  172. * scheduler functions which might be in L1 :( and core writes
  173. * into L1 instruction cause bad access errors, so we are stuck,
  174. * we are required to use DMA, but can't use the common dma
  175. * functions. We can't use memcpy either - since that might be
  176. * going to be in the relocated L1
  177. */
  178. blackfin_dma_early_init();
  179. /* if necessary, copy L1 text to L1 instruction SRAM */
  180. if (L1_CODE_LENGTH && text_l1_len)
  181. early_dma_memcpy(_stext_l1, _text_l1_lma, text_l1_len);
  182. /* if necessary, copy L1 data to L1 data bank A SRAM */
  183. if (L1_DATA_A_LENGTH && data_l1_len)
  184. early_dma_memcpy(_sdata_l1, _data_l1_lma, data_l1_len);
  185. /* if necessary, copy L1 data B to L1 data bank B SRAM */
  186. if (L1_DATA_B_LENGTH && data_b_l1_len)
  187. early_dma_memcpy(_sdata_b_l1, _data_b_l1_lma, data_b_l1_len);
  188. early_dma_memcpy_done();
  189. #if defined(CONFIG_SMP) && defined(CONFIG_ICACHE_FLUSH_L1)
  190. blackfin_iflush_l1_entry[0] = (unsigned long)blackfin_icache_flush_range_l1;
  191. #endif
  192. /* if necessary, copy L2 text/data to L2 SRAM */
  193. if (L2_LENGTH && l2_len)
  194. memcpy(_stext_l2, _l2_lma, l2_len);
  195. }
  196. #ifdef CONFIG_SMP
  197. void __init bfin_relocate_coreb_l1_mem(void)
  198. {
  199. unsigned long text_l1_len = (unsigned long)_text_l1_len;
  200. unsigned long data_l1_len = (unsigned long)_data_l1_len;
  201. unsigned long data_b_l1_len = (unsigned long)_data_b_l1_len;
  202. blackfin_dma_early_init();
  203. /* if necessary, copy L1 text to L1 instruction SRAM */
  204. if (L1_CODE_LENGTH && text_l1_len)
  205. early_dma_memcpy((void *)COREB_L1_CODE_START, _text_l1_lma,
  206. text_l1_len);
  207. /* if necessary, copy L1 data to L1 data bank A SRAM */
  208. if (L1_DATA_A_LENGTH && data_l1_len)
  209. early_dma_memcpy((void *)COREB_L1_DATA_A_START, _data_l1_lma,
  210. data_l1_len);
  211. /* if necessary, copy L1 data B to L1 data bank B SRAM */
  212. if (L1_DATA_B_LENGTH && data_b_l1_len)
  213. early_dma_memcpy((void *)COREB_L1_DATA_B_START, _data_b_l1_lma,
  214. data_b_l1_len);
  215. early_dma_memcpy_done();
  216. #ifdef CONFIG_ICACHE_FLUSH_L1
  217. blackfin_iflush_l1_entry[1] = (unsigned long)blackfin_icache_flush_range_l1 -
  218. (unsigned long)_stext_l1 + COREB_L1_CODE_START;
  219. #endif
  220. }
  221. #endif
  222. #ifdef CONFIG_ROMKERNEL
  223. void __init bfin_relocate_xip_data(void)
  224. {
  225. early_shadow_stamp();
  226. memcpy(_sdata, _data_lma, (unsigned long)_data_len - THREAD_SIZE + sizeof(struct thread_info));
  227. memcpy(_sinitdata, _init_data_lma, (unsigned long)_init_data_len);
  228. }
  229. #endif
  230. /* add_memory_region to memmap */
  231. static void __init add_memory_region(unsigned long long start,
  232. unsigned long long size, int type)
  233. {
  234. int i;
  235. i = bfin_memmap.nr_map;
  236. if (i == BFIN_MEMMAP_MAX) {
  237. printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
  238. return;
  239. }
  240. bfin_memmap.map[i].addr = start;
  241. bfin_memmap.map[i].size = size;
  242. bfin_memmap.map[i].type = type;
  243. bfin_memmap.nr_map++;
  244. }
  245. /*
  246. * Sanitize the boot memmap, removing overlaps.
  247. */
  248. static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map)
  249. {
  250. struct change_member *change_tmp;
  251. unsigned long current_type, last_type;
  252. unsigned long long last_addr;
  253. int chgidx, still_changing;
  254. int overlap_entries;
  255. int new_entry;
  256. int old_nr, new_nr, chg_nr;
  257. int i;
  258. /*
  259. Visually we're performing the following (1,2,3,4 = memory types)
  260. Sample memory map (w/overlaps):
  261. ____22__________________
  262. ______________________4_
  263. ____1111________________
  264. _44_____________________
  265. 11111111________________
  266. ____________________33__
  267. ___________44___________
  268. __________33333_________
  269. ______________22________
  270. ___________________2222_
  271. _________111111111______
  272. _____________________11_
  273. _________________4______
  274. Sanitized equivalent (no overlap):
  275. 1_______________________
  276. _44_____________________
  277. ___1____________________
  278. ____22__________________
  279. ______11________________
  280. _________1______________
  281. __________3_____________
  282. ___________44___________
  283. _____________33_________
  284. _______________2________
  285. ________________1_______
  286. _________________4______
  287. ___________________2____
  288. ____________________33__
  289. ______________________4_
  290. */
  291. /* if there's only one memory region, don't bother */
  292. if (*pnr_map < 2)
  293. return -1;
  294. old_nr = *pnr_map;
  295. /* bail out if we find any unreasonable addresses in memmap */
  296. for (i = 0; i < old_nr; i++)
  297. if (map[i].addr + map[i].size < map[i].addr)
  298. return -1;
  299. /* create pointers for initial change-point information (for sorting) */
  300. for (i = 0; i < 2*old_nr; i++)
  301. change_point[i] = &change_point_list[i];
  302. /* record all known change-points (starting and ending addresses),
  303. omitting those that are for empty memory regions */
  304. chgidx = 0;
  305. for (i = 0; i < old_nr; i++) {
  306. if (map[i].size != 0) {
  307. change_point[chgidx]->addr = map[i].addr;
  308. change_point[chgidx++]->pentry = &map[i];
  309. change_point[chgidx]->addr = map[i].addr + map[i].size;
  310. change_point[chgidx++]->pentry = &map[i];
  311. }
  312. }
  313. chg_nr = chgidx; /* true number of change-points */
  314. /* sort change-point list by memory addresses (low -> high) */
  315. still_changing = 1;
  316. while (still_changing) {
  317. still_changing = 0;
  318. for (i = 1; i < chg_nr; i++) {
  319. /* if <current_addr> > <last_addr>, swap */
  320. /* or, if current=<start_addr> & last=<end_addr>, swap */
  321. if ((change_point[i]->addr < change_point[i-1]->addr) ||
  322. ((change_point[i]->addr == change_point[i-1]->addr) &&
  323. (change_point[i]->addr == change_point[i]->pentry->addr) &&
  324. (change_point[i-1]->addr != change_point[i-1]->pentry->addr))
  325. ) {
  326. change_tmp = change_point[i];
  327. change_point[i] = change_point[i-1];
  328. change_point[i-1] = change_tmp;
  329. still_changing = 1;
  330. }
  331. }
  332. }
  333. /* create a new memmap, removing overlaps */
  334. overlap_entries = 0; /* number of entries in the overlap table */
  335. new_entry = 0; /* index for creating new memmap entries */
  336. last_type = 0; /* start with undefined memory type */
  337. last_addr = 0; /* start with 0 as last starting address */
  338. /* loop through change-points, determining affect on the new memmap */
  339. for (chgidx = 0; chgidx < chg_nr; chgidx++) {
  340. /* keep track of all overlapping memmap entries */
  341. if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) {
  342. /* add map entry to overlap list (> 1 entry implies an overlap) */
  343. overlap_list[overlap_entries++] = change_point[chgidx]->pentry;
  344. } else {
  345. /* remove entry from list (order independent, so swap with last) */
  346. for (i = 0; i < overlap_entries; i++) {
  347. if (overlap_list[i] == change_point[chgidx]->pentry)
  348. overlap_list[i] = overlap_list[overlap_entries-1];
  349. }
  350. overlap_entries--;
  351. }
  352. /* if there are overlapping entries, decide which "type" to use */
  353. /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
  354. current_type = 0;
  355. for (i = 0; i < overlap_entries; i++)
  356. if (overlap_list[i]->type > current_type)
  357. current_type = overlap_list[i]->type;
  358. /* continue building up new memmap based on this information */
  359. if (current_type != last_type) {
  360. if (last_type != 0) {
  361. new_map[new_entry].size =
  362. change_point[chgidx]->addr - last_addr;
  363. /* move forward only if the new size was non-zero */
  364. if (new_map[new_entry].size != 0)
  365. if (++new_entry >= BFIN_MEMMAP_MAX)
  366. break; /* no more space left for new entries */
  367. }
  368. if (current_type != 0) {
  369. new_map[new_entry].addr = change_point[chgidx]->addr;
  370. new_map[new_entry].type = current_type;
  371. last_addr = change_point[chgidx]->addr;
  372. }
  373. last_type = current_type;
  374. }
  375. }
  376. new_nr = new_entry; /* retain count for new entries */
  377. /* copy new mapping into original location */
  378. memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry));
  379. *pnr_map = new_nr;
  380. return 0;
  381. }
  382. static void __init print_memory_map(char *who)
  383. {
  384. int i;
  385. for (i = 0; i < bfin_memmap.nr_map; i++) {
  386. printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who,
  387. bfin_memmap.map[i].addr,
  388. bfin_memmap.map[i].addr + bfin_memmap.map[i].size);
  389. switch (bfin_memmap.map[i].type) {
  390. case BFIN_MEMMAP_RAM:
  391. printk(KERN_CONT "(usable)\n");
  392. break;
  393. case BFIN_MEMMAP_RESERVED:
  394. printk(KERN_CONT "(reserved)\n");
  395. break;
  396. default:
  397. printk(KERN_CONT "type %lu\n", bfin_memmap.map[i].type);
  398. break;
  399. }
  400. }
  401. }
  402. static __init int parse_memmap(char *arg)
  403. {
  404. unsigned long long start_at, mem_size;
  405. if (!arg)
  406. return -EINVAL;
  407. mem_size = memparse(arg, &arg);
  408. if (*arg == '@') {
  409. start_at = memparse(arg+1, &arg);
  410. add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM);
  411. } else if (*arg == '$') {
  412. start_at = memparse(arg+1, &arg);
  413. add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED);
  414. }
  415. return 0;
  416. }
  417. /*
  418. * Initial parsing of the command line. Currently, we support:
  419. * - Controlling the linux memory size: mem=xxx[KMG]
  420. * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
  421. * $ -> reserved memory is dcacheable
  422. * # -> reserved memory is icacheable
  423. * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
  424. * @ from <start> to <start>+<mem>, type RAM
  425. * $ from <start> to <start>+<mem>, type RESERVED
  426. */
  427. static __init void parse_cmdline_early(char *cmdline_p)
  428. {
  429. char c = ' ', *to = cmdline_p;
  430. unsigned int memsize;
  431. for (;;) {
  432. if (c == ' ') {
  433. if (!memcmp(to, "mem=", 4)) {
  434. to += 4;
  435. memsize = memparse(to, &to);
  436. if (memsize)
  437. _ramend = memsize;
  438. } else if (!memcmp(to, "max_mem=", 8)) {
  439. to += 8;
  440. memsize = memparse(to, &to);
  441. if (memsize) {
  442. physical_mem_end = memsize;
  443. if (*to != ' ') {
  444. if (*to == '$'
  445. || *(to + 1) == '$')
  446. reserved_mem_dcache_on = 1;
  447. if (*to == '#'
  448. || *(to + 1) == '#')
  449. reserved_mem_icache_on = 1;
  450. }
  451. }
  452. } else if (!memcmp(to, "clkin_hz=", 9)) {
  453. to += 9;
  454. early_init_clkin_hz(to);
  455. #ifdef CONFIG_EARLY_PRINTK
  456. } else if (!memcmp(to, "earlyprintk=", 12)) {
  457. to += 12;
  458. setup_early_printk(to);
  459. #endif
  460. } else if (!memcmp(to, "memmap=", 7)) {
  461. to += 7;
  462. parse_memmap(to);
  463. }
  464. }
  465. c = *(to++);
  466. if (!c)
  467. break;
  468. }
  469. }
  470. /*
  471. * Setup memory defaults from user config.
  472. * The physical memory layout looks like:
  473. *
  474. * [_rambase, _ramstart]: kernel image
  475. * [memory_start, memory_end]: dynamic memory managed by kernel
  476. * [memory_end, _ramend]: reserved memory
  477. * [memory_mtd_start(memory_end),
  478. * memory_mtd_start + mtd_size]: rootfs (if any)
  479. * [_ramend - DMA_UNCACHED_REGION,
  480. * _ramend]: uncached DMA region
  481. * [_ramend, physical_mem_end]: memory not managed by kernel
  482. */
  483. static __init void memory_setup(void)
  484. {
  485. #ifdef CONFIG_MTD_UCLINUX
  486. unsigned long mtd_phys = 0;
  487. #endif
  488. unsigned long max_mem;
  489. _rambase = CONFIG_BOOT_LOAD;
  490. _ramstart = (unsigned long)_end;
  491. if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
  492. console_init();
  493. panic("DMA region exceeds memory limit: %lu.",
  494. _ramend - _ramstart);
  495. }
  496. max_mem = memory_end = _ramend - DMA_UNCACHED_REGION;
  497. #if (defined(CONFIG_BFIN_EXTMEM_ICACHEABLE) && ANOMALY_05000263)
  498. /* Due to a Hardware Anomaly we need to limit the size of usable
  499. * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
  500. * 05000263 - Hardware loop corrupted when taking an ICPLB exception
  501. */
  502. # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
  503. if (max_mem >= 56 * 1024 * 1024)
  504. max_mem = 56 * 1024 * 1024;
  505. # else
  506. if (max_mem >= 60 * 1024 * 1024)
  507. max_mem = 60 * 1024 * 1024;
  508. # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
  509. #endif /* ANOMALY_05000263 */
  510. #ifdef CONFIG_MPU
  511. /* Round up to multiple of 4MB */
  512. memory_start = (_ramstart + 0x3fffff) & ~0x3fffff;
  513. #else
  514. memory_start = PAGE_ALIGN(_ramstart);
  515. #endif
  516. #if defined(CONFIG_MTD_UCLINUX)
  517. /* generic memory mapped MTD driver */
  518. memory_mtd_end = memory_end;
  519. mtd_phys = _ramstart;
  520. mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
  521. # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
  522. if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
  523. mtd_size =
  524. PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
  525. # endif
  526. # if defined(CONFIG_CRAMFS)
  527. if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
  528. mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
  529. # endif
  530. # if defined(CONFIG_ROMFS_FS)
  531. if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
  532. && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1) {
  533. mtd_size =
  534. PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
  535. /* ROM_FS is XIP, so if we found it, we need to limit memory */
  536. if (memory_end > max_mem) {
  537. pr_info("Limiting kernel memory to %liMB due to anomaly 05000263\n", max_mem >> 20);
  538. memory_end = max_mem;
  539. }
  540. }
  541. # endif /* CONFIG_ROMFS_FS */
  542. /* Since the default MTD_UCLINUX has no magic number, we just blindly
  543. * read 8 past the end of the kernel's image, and look at it.
  544. * When no image is attached, mtd_size is set to a random number
  545. * Do some basic sanity checks before operating on things
  546. */
  547. if (mtd_size == 0 || memory_end <= mtd_size) {
  548. pr_emerg("Could not find valid ram mtd attached.\n");
  549. } else {
  550. memory_end -= mtd_size;
  551. /* Relocate MTD image to the top of memory after the uncached memory area */
  552. uclinux_ram_map.phys = memory_mtd_start = memory_end;
  553. uclinux_ram_map.size = mtd_size;
  554. pr_info("Found mtd parition at 0x%p, (len=0x%lx), moving to 0x%p\n",
  555. _end, mtd_size, (void *)memory_mtd_start);
  556. dma_memcpy((void *)uclinux_ram_map.phys, _end, uclinux_ram_map.size);
  557. }
  558. #endif /* CONFIG_MTD_UCLINUX */
  559. /* We need lo limit memory, since everything could have a text section
  560. * of userspace in it, and expose anomaly 05000263. If the anomaly
  561. * doesn't exist, or we don't need to - then dont.
  562. */
  563. if (memory_end > max_mem) {
  564. pr_info("Limiting kernel memory to %liMB due to anomaly 05000263\n", max_mem >> 20);
  565. memory_end = max_mem;
  566. }
  567. #ifdef CONFIG_MPU
  568. #if defined(CONFIG_ROMFS_ON_MTD) && defined(CONFIG_MTD_ROM)
  569. page_mask_nelts = (((_ramend + ASYNC_BANK3_BASE + ASYNC_BANK3_SIZE -
  570. ASYNC_BANK0_BASE) >> PAGE_SHIFT) + 31) / 32;
  571. #else
  572. page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32;
  573. #endif
  574. page_mask_order = get_order(3 * page_mask_nelts * sizeof(long));
  575. #endif
  576. init_mm.start_code = (unsigned long)_stext;
  577. init_mm.end_code = (unsigned long)_etext;
  578. init_mm.end_data = (unsigned long)_edata;
  579. init_mm.brk = (unsigned long)0;
  580. printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
  581. printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
  582. printk(KERN_INFO "Memory map:\n"
  583. " fixedcode = 0x%p-0x%p\n"
  584. " text = 0x%p-0x%p\n"
  585. " rodata = 0x%p-0x%p\n"
  586. " bss = 0x%p-0x%p\n"
  587. " data = 0x%p-0x%p\n"
  588. " stack = 0x%p-0x%p\n"
  589. " init = 0x%p-0x%p\n"
  590. " available = 0x%p-0x%p\n"
  591. #ifdef CONFIG_MTD_UCLINUX
  592. " rootfs = 0x%p-0x%p\n"
  593. #endif
  594. #if DMA_UNCACHED_REGION > 0
  595. " DMA Zone = 0x%p-0x%p\n"
  596. #endif
  597. , (void *)FIXED_CODE_START, (void *)FIXED_CODE_END,
  598. _stext, _etext,
  599. __start_rodata, __end_rodata,
  600. __bss_start, __bss_stop,
  601. _sdata, _edata,
  602. (void *)&init_thread_union,
  603. (void *)((int)(&init_thread_union) + THREAD_SIZE),
  604. __init_begin, __init_end,
  605. (void *)_ramstart, (void *)memory_end
  606. #ifdef CONFIG_MTD_UCLINUX
  607. , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
  608. #endif
  609. #if DMA_UNCACHED_REGION > 0
  610. , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
  611. #endif
  612. );
  613. }
  614. /*
  615. * Find the lowest, highest page frame number we have available
  616. */
  617. void __init find_min_max_pfn(void)
  618. {
  619. int i;
  620. max_pfn = 0;
  621. min_low_pfn = memory_end;
  622. for (i = 0; i < bfin_memmap.nr_map; i++) {
  623. unsigned long start, end;
  624. /* RAM? */
  625. if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
  626. continue;
  627. start = PFN_UP(bfin_memmap.map[i].addr);
  628. end = PFN_DOWN(bfin_memmap.map[i].addr +
  629. bfin_memmap.map[i].size);
  630. if (start >= end)
  631. continue;
  632. if (end > max_pfn)
  633. max_pfn = end;
  634. if (start < min_low_pfn)
  635. min_low_pfn = start;
  636. }
  637. }
  638. static __init void setup_bootmem_allocator(void)
  639. {
  640. int bootmap_size;
  641. int i;
  642. unsigned long start_pfn, end_pfn;
  643. unsigned long curr_pfn, last_pfn, size;
  644. /* mark memory between memory_start and memory_end usable */
  645. add_memory_region(memory_start,
  646. memory_end - memory_start, BFIN_MEMMAP_RAM);
  647. /* sanity check for overlap */
  648. sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
  649. print_memory_map("boot memmap");
  650. /* initialize globals in linux/bootmem.h */
  651. find_min_max_pfn();
  652. /* pfn of the last usable page frame */
  653. if (max_pfn > memory_end >> PAGE_SHIFT)
  654. max_pfn = memory_end >> PAGE_SHIFT;
  655. /* pfn of last page frame directly mapped by kernel */
  656. max_low_pfn = max_pfn;
  657. /* pfn of the first usable page frame after kernel image*/
  658. if (min_low_pfn < memory_start >> PAGE_SHIFT)
  659. min_low_pfn = memory_start >> PAGE_SHIFT;
  660. start_pfn = PAGE_OFFSET >> PAGE_SHIFT;
  661. end_pfn = memory_end >> PAGE_SHIFT;
  662. /*
  663. * give all the memory to the bootmap allocator, tell it to put the
  664. * boot mem_map at the start of memory.
  665. */
  666. bootmap_size = init_bootmem_node(NODE_DATA(0),
  667. memory_start >> PAGE_SHIFT, /* map goes here */
  668. start_pfn, end_pfn);
  669. /* register the memmap regions with the bootmem allocator */
  670. for (i = 0; i < bfin_memmap.nr_map; i++) {
  671. /*
  672. * Reserve usable memory
  673. */
  674. if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
  675. continue;
  676. /*
  677. * We are rounding up the start address of usable memory:
  678. */
  679. curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
  680. if (curr_pfn >= end_pfn)
  681. continue;
  682. /*
  683. * ... and at the end of the usable range downwards:
  684. */
  685. last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
  686. bfin_memmap.map[i].size);
  687. if (last_pfn > end_pfn)
  688. last_pfn = end_pfn;
  689. /*
  690. * .. finally, did all the rounding and playing
  691. * around just make the area go away?
  692. */
  693. if (last_pfn <= curr_pfn)
  694. continue;
  695. size = last_pfn - curr_pfn;
  696. free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
  697. }
  698. /* reserve memory before memory_start, including bootmap */
  699. reserve_bootmem(PAGE_OFFSET,
  700. memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET,
  701. BOOTMEM_DEFAULT);
  702. }
  703. #define EBSZ_TO_MEG(ebsz) \
  704. ({ \
  705. int meg = 0; \
  706. switch (ebsz & 0xf) { \
  707. case 0x1: meg = 16; break; \
  708. case 0x3: meg = 32; break; \
  709. case 0x5: meg = 64; break; \
  710. case 0x7: meg = 128; break; \
  711. case 0x9: meg = 256; break; \
  712. case 0xb: meg = 512; break; \
  713. } \
  714. meg; \
  715. })
  716. static inline int __init get_mem_size(void)
  717. {
  718. #if defined(EBIU_SDBCTL)
  719. # if defined(BF561_FAMILY)
  720. int ret = 0;
  721. u32 sdbctl = bfin_read_EBIU_SDBCTL();
  722. ret += EBSZ_TO_MEG(sdbctl >> 0);
  723. ret += EBSZ_TO_MEG(sdbctl >> 8);
  724. ret += EBSZ_TO_MEG(sdbctl >> 16);
  725. ret += EBSZ_TO_MEG(sdbctl >> 24);
  726. return ret;
  727. # else
  728. return EBSZ_TO_MEG(bfin_read_EBIU_SDBCTL());
  729. # endif
  730. #elif defined(EBIU_DDRCTL1)
  731. u32 ddrctl = bfin_read_EBIU_DDRCTL1();
  732. int ret = 0;
  733. switch (ddrctl & 0xc0000) {
  734. case DEVSZ_64: ret = 64 / 8;
  735. case DEVSZ_128: ret = 128 / 8;
  736. case DEVSZ_256: ret = 256 / 8;
  737. case DEVSZ_512: ret = 512 / 8;
  738. }
  739. switch (ddrctl & 0x30000) {
  740. case DEVWD_4: ret *= 2;
  741. case DEVWD_8: ret *= 2;
  742. case DEVWD_16: break;
  743. }
  744. if ((ddrctl & 0xc000) == 0x4000)
  745. ret *= 2;
  746. return ret;
  747. #endif
  748. BUG();
  749. }
  750. __attribute__((weak))
  751. void __init native_machine_early_platform_add_devices(void)
  752. {
  753. }
  754. void __init setup_arch(char **cmdline_p)
  755. {
  756. unsigned long sclk, cclk;
  757. native_machine_early_platform_add_devices();
  758. enable_shadow_console();
  759. /* Check to make sure we are running on the right processor */
  760. if (unlikely(CPUID != bfin_cpuid()))
  761. printk(KERN_ERR "ERROR: Not running on ADSP-%s: unknown CPUID 0x%04x Rev 0.%d\n",
  762. CPU, bfin_cpuid(), bfin_revid());
  763. #ifdef CONFIG_DUMMY_CONSOLE
  764. conswitchp = &dummy_con;
  765. #endif
  766. #if defined(CONFIG_CMDLINE_BOOL)
  767. strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
  768. command_line[sizeof(command_line) - 1] = 0;
  769. #endif
  770. /* Keep a copy of command line */
  771. *cmdline_p = &command_line[0];
  772. memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  773. boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
  774. memset(&bfin_memmap, 0, sizeof(bfin_memmap));
  775. /* If the user does not specify things on the command line, use
  776. * what the bootloader set things up as
  777. */
  778. physical_mem_end = 0;
  779. parse_cmdline_early(&command_line[0]);
  780. if (_ramend == 0)
  781. _ramend = get_mem_size() * 1024 * 1024;
  782. if (physical_mem_end == 0)
  783. physical_mem_end = _ramend;
  784. memory_setup();
  785. /* Initialize Async memory banks */
  786. bfin_write_EBIU_AMBCTL0(AMBCTL0VAL);
  787. bfin_write_EBIU_AMBCTL1(AMBCTL1VAL);
  788. bfin_write_EBIU_AMGCTL(AMGCTLVAL);
  789. #ifdef CONFIG_EBIU_MBSCTLVAL
  790. bfin_write_EBIU_MBSCTL(CONFIG_EBIU_MBSCTLVAL);
  791. bfin_write_EBIU_MODE(CONFIG_EBIU_MODEVAL);
  792. bfin_write_EBIU_FCTL(CONFIG_EBIU_FCTLVAL);
  793. #endif
  794. #ifdef CONFIG_BFIN_HYSTERESIS_CONTROL
  795. bfin_write_PORTF_HYSTERESIS(HYST_PORTF_0_15);
  796. bfin_write_PORTG_HYSTERESIS(HYST_PORTG_0_15);
  797. bfin_write_PORTH_HYSTERESIS(HYST_PORTH_0_15);
  798. bfin_write_MISCPORT_HYSTERESIS((bfin_read_MISCPORT_HYSTERESIS() &
  799. ~HYST_NONEGPIO_MASK) | HYST_NONEGPIO);
  800. #endif
  801. cclk = get_cclk();
  802. sclk = get_sclk();
  803. if ((ANOMALY_05000273 || ANOMALY_05000274) && (cclk >> 1) < sclk)
  804. panic("ANOMALY 05000273 or 05000274: CCLK must be >= 2*SCLK");
  805. #ifdef BF561_FAMILY
  806. if (ANOMALY_05000266) {
  807. bfin_read_IMDMA_D0_IRQ_STATUS();
  808. bfin_read_IMDMA_D1_IRQ_STATUS();
  809. }
  810. #endif
  811. printk(KERN_INFO "Hardware Trace ");
  812. if (bfin_read_TBUFCTL() & 0x1)
  813. printk(KERN_CONT "Active ");
  814. else
  815. printk(KERN_CONT "Off ");
  816. if (bfin_read_TBUFCTL() & 0x2)
  817. printk(KERN_CONT "and Enabled\n");
  818. else
  819. printk(KERN_CONT "and Disabled\n");
  820. printk(KERN_INFO "Boot Mode: %i\n", bfin_read_SYSCR() & 0xF);
  821. /* Newer parts mirror SWRST bits in SYSCR */
  822. #if defined(CONFIG_BF53x) || defined(CONFIG_BF561) || \
  823. defined(CONFIG_BF538) || defined(CONFIG_BF539)
  824. _bfin_swrst = bfin_read_SWRST();
  825. #else
  826. /* Clear boot mode field */
  827. _bfin_swrst = bfin_read_SYSCR() & ~0xf;
  828. #endif
  829. #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
  830. bfin_write_SWRST(_bfin_swrst & ~DOUBLE_FAULT);
  831. #endif
  832. #ifdef CONFIG_DEBUG_DOUBLEFAULT_RESET
  833. bfin_write_SWRST(_bfin_swrst | DOUBLE_FAULT);
  834. #endif
  835. #ifdef CONFIG_SMP
  836. if (_bfin_swrst & SWRST_DBL_FAULT_A) {
  837. #else
  838. if (_bfin_swrst & RESET_DOUBLE) {
  839. #endif
  840. printk(KERN_EMERG "Recovering from DOUBLE FAULT event\n");
  841. #ifdef CONFIG_DEBUG_DOUBLEFAULT
  842. /* We assume the crashing kernel, and the current symbol table match */
  843. printk(KERN_EMERG " While handling exception (EXCAUSE = 0x%x) at %pF\n",
  844. (int)init_saved_seqstat & SEQSTAT_EXCAUSE, init_saved_retx);
  845. printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %pF\n", init_saved_dcplb_fault_addr);
  846. printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %pF\n", init_saved_icplb_fault_addr);
  847. #endif
  848. printk(KERN_NOTICE " The instruction at %pF caused a double exception\n",
  849. init_retx);
  850. } else if (_bfin_swrst & RESET_WDOG)
  851. printk(KERN_INFO "Recovering from Watchdog event\n");
  852. else if (_bfin_swrst & RESET_SOFTWARE)
  853. printk(KERN_NOTICE "Reset caused by Software reset\n");
  854. printk(KERN_INFO "Blackfin support (C) 2004-2010 Analog Devices, Inc.\n");
  855. if (bfin_compiled_revid() == 0xffff)
  856. printk(KERN_INFO "Compiled for ADSP-%s Rev any, running on 0.%d\n", CPU, bfin_revid());
  857. else if (bfin_compiled_revid() == -1)
  858. printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
  859. else
  860. printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
  861. if (likely(CPUID == bfin_cpuid())) {
  862. if (bfin_revid() != bfin_compiled_revid()) {
  863. if (bfin_compiled_revid() == -1)
  864. printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
  865. bfin_revid());
  866. else if (bfin_compiled_revid() != 0xffff) {
  867. printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
  868. bfin_compiled_revid(), bfin_revid());
  869. if (bfin_compiled_revid() > bfin_revid())
  870. panic("Error: you are missing anomaly workarounds for this rev");
  871. }
  872. }
  873. if (bfin_revid() < CONFIG_BF_REV_MIN || bfin_revid() > CONFIG_BF_REV_MAX)
  874. printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
  875. CPU, bfin_revid());
  876. }
  877. printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
  878. printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
  879. cclk / 1000000, sclk / 1000000);
  880. setup_bootmem_allocator();
  881. paging_init();
  882. /* Copy atomic sequences to their fixed location, and sanity check that
  883. these locations are the ones that we advertise to userspace. */
  884. memcpy((void *)FIXED_CODE_START, &fixed_code_start,
  885. FIXED_CODE_END - FIXED_CODE_START);
  886. BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
  887. != SIGRETURN_STUB - FIXED_CODE_START);
  888. BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
  889. != ATOMIC_XCHG32 - FIXED_CODE_START);
  890. BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
  891. != ATOMIC_CAS32 - FIXED_CODE_START);
  892. BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
  893. != ATOMIC_ADD32 - FIXED_CODE_START);
  894. BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
  895. != ATOMIC_SUB32 - FIXED_CODE_START);
  896. BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
  897. != ATOMIC_IOR32 - FIXED_CODE_START);
  898. BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
  899. != ATOMIC_AND32 - FIXED_CODE_START);
  900. BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
  901. != ATOMIC_XOR32 - FIXED_CODE_START);
  902. BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
  903. != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
  904. #ifdef CONFIG_SMP
  905. platform_init_cpus();
  906. #endif
  907. init_exception_vectors();
  908. bfin_cache_init(); /* Initialize caches for the boot CPU */
  909. }
  910. static int __init topology_init(void)
  911. {
  912. unsigned int cpu;
  913. for_each_possible_cpu(cpu) {
  914. register_cpu(&per_cpu(cpu_data, cpu).cpu, cpu);
  915. }
  916. return 0;
  917. }
  918. subsys_initcall(topology_init);
  919. /* Get the input clock frequency */
  920. static u_long cached_clkin_hz = CONFIG_CLKIN_HZ;
  921. static u_long get_clkin_hz(void)
  922. {
  923. return cached_clkin_hz;
  924. }
  925. static int __init early_init_clkin_hz(char *buf)
  926. {
  927. cached_clkin_hz = simple_strtoul(buf, NULL, 0);
  928. #ifdef BFIN_KERNEL_CLOCK
  929. if (cached_clkin_hz != CONFIG_CLKIN_HZ)
  930. panic("cannot change clkin_hz when reprogramming clocks");
  931. #endif
  932. return 1;
  933. }
  934. early_param("clkin_hz=", early_init_clkin_hz);
  935. /* Get the voltage input multiplier */
  936. static u_long get_vco(void)
  937. {
  938. static u_long cached_vco;
  939. u_long msel, pll_ctl;
  940. /* The assumption here is that VCO never changes at runtime.
  941. * If, someday, we support that, then we'll have to change this.
  942. */
  943. if (cached_vco)
  944. return cached_vco;
  945. pll_ctl = bfin_read_PLL_CTL();
  946. msel = (pll_ctl >> 9) & 0x3F;
  947. if (0 == msel)
  948. msel = 64;
  949. cached_vco = get_clkin_hz();
  950. cached_vco >>= (1 & pll_ctl); /* DF bit */
  951. cached_vco *= msel;
  952. return cached_vco;
  953. }
  954. /* Get the Core clock */
  955. u_long get_cclk(void)
  956. {
  957. static u_long cached_cclk_pll_div, cached_cclk;
  958. u_long csel, ssel;
  959. if (bfin_read_PLL_STAT() & 0x1)
  960. return get_clkin_hz();
  961. ssel = bfin_read_PLL_DIV();
  962. if (ssel == cached_cclk_pll_div)
  963. return cached_cclk;
  964. else
  965. cached_cclk_pll_div = ssel;
  966. csel = ((ssel >> 4) & 0x03);
  967. ssel &= 0xf;
  968. if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
  969. cached_cclk = get_vco() / ssel;
  970. else
  971. cached_cclk = get_vco() >> csel;
  972. return cached_cclk;
  973. }
  974. EXPORT_SYMBOL(get_cclk);
  975. /* Get the System clock */
  976. u_long get_sclk(void)
  977. {
  978. static u_long cached_sclk;
  979. u_long ssel;
  980. /* The assumption here is that SCLK never changes at runtime.
  981. * If, someday, we support that, then we'll have to change this.
  982. */
  983. if (cached_sclk)
  984. return cached_sclk;
  985. if (bfin_read_PLL_STAT() & 0x1)
  986. return get_clkin_hz();
  987. ssel = bfin_read_PLL_DIV() & 0xf;
  988. if (0 == ssel) {
  989. printk(KERN_WARNING "Invalid System Clock\n");
  990. ssel = 1;
  991. }
  992. cached_sclk = get_vco() / ssel;
  993. return cached_sclk;
  994. }
  995. EXPORT_SYMBOL(get_sclk);
  996. unsigned long sclk_to_usecs(unsigned long sclk)
  997. {
  998. u64 tmp = USEC_PER_SEC * (u64)sclk;
  999. do_div(tmp, get_sclk());
  1000. return tmp;
  1001. }
  1002. EXPORT_SYMBOL(sclk_to_usecs);
  1003. unsigned long usecs_to_sclk(unsigned long usecs)
  1004. {
  1005. u64 tmp = get_sclk() * (u64)usecs;
  1006. do_div(tmp, USEC_PER_SEC);
  1007. return tmp;
  1008. }
  1009. EXPORT_SYMBOL(usecs_to_sclk);
  1010. /*
  1011. * Get CPU information for use by the procfs.
  1012. */
  1013. static int show_cpuinfo(struct seq_file *m, void *v)
  1014. {
  1015. char *cpu, *mmu, *fpu, *vendor, *cache;
  1016. uint32_t revid;
  1017. int cpu_num = *(unsigned int *)v;
  1018. u_long sclk, cclk;
  1019. u_int icache_size = BFIN_ICACHESIZE / 1024, dcache_size = 0, dsup_banks = 0;
  1020. struct blackfin_cpudata *cpudata = &per_cpu(cpu_data, cpu_num);
  1021. cpu = CPU;
  1022. mmu = "none";
  1023. fpu = "none";
  1024. revid = bfin_revid();
  1025. sclk = get_sclk();
  1026. cclk = get_cclk();
  1027. switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
  1028. case 0xca:
  1029. vendor = "Analog Devices";
  1030. break;
  1031. default:
  1032. vendor = "unknown";
  1033. break;
  1034. }
  1035. seq_printf(m, "processor\t: %d\n" "vendor_id\t: %s\n", cpu_num, vendor);
  1036. if (CPUID == bfin_cpuid())
  1037. seq_printf(m, "cpu family\t: 0x%04x\n", CPUID);
  1038. else
  1039. seq_printf(m, "cpu family\t: Compiled for:0x%04x, running on:0x%04x\n",
  1040. CPUID, bfin_cpuid());
  1041. seq_printf(m, "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
  1042. "stepping\t: %d ",
  1043. cpu, cclk/1000000, sclk/1000000,
  1044. #ifdef CONFIG_MPU
  1045. "mpu on",
  1046. #else
  1047. "mpu off",
  1048. #endif
  1049. revid);
  1050. if (bfin_revid() != bfin_compiled_revid()) {
  1051. if (bfin_compiled_revid() == -1)
  1052. seq_printf(m, "(Compiled for Rev none)");
  1053. else if (bfin_compiled_revid() == 0xffff)
  1054. seq_printf(m, "(Compiled for Rev any)");
  1055. else
  1056. seq_printf(m, "(Compiled for Rev %d)", bfin_compiled_revid());
  1057. }
  1058. seq_printf(m, "\ncpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
  1059. cclk/1000000, cclk%1000000,
  1060. sclk/1000000, sclk%1000000);
  1061. seq_printf(m, "bogomips\t: %lu.%02lu\n"
  1062. "Calibration\t: %lu loops\n",
  1063. (loops_per_jiffy * HZ) / 500000,
  1064. ((loops_per_jiffy * HZ) / 5000) % 100,
  1065. (loops_per_jiffy * HZ));
  1066. /* Check Cache configutation */
  1067. switch (cpudata->dmemctl & (1 << DMC0_P | 1 << DMC1_P)) {
  1068. case ACACHE_BSRAM:
  1069. cache = "dbank-A/B\t: cache/sram";
  1070. dcache_size = 16;
  1071. dsup_banks = 1;
  1072. break;
  1073. case ACACHE_BCACHE:
  1074. cache = "dbank-A/B\t: cache/cache";
  1075. dcache_size = 32;
  1076. dsup_banks = 2;
  1077. break;
  1078. case ASRAM_BSRAM:
  1079. cache = "dbank-A/B\t: sram/sram";
  1080. dcache_size = 0;
  1081. dsup_banks = 0;
  1082. break;
  1083. default:
  1084. cache = "unknown";
  1085. dcache_size = 0;
  1086. dsup_banks = 0;
  1087. break;
  1088. }
  1089. /* Is it turned on? */
  1090. if ((cpudata->dmemctl & (ENDCPLB | DMC_ENABLE)) != (ENDCPLB | DMC_ENABLE))
  1091. dcache_size = 0;
  1092. if ((cpudata->imemctl & (IMC | ENICPLB)) != (IMC | ENICPLB))
  1093. icache_size = 0;
  1094. seq_printf(m, "cache size\t: %d KB(L1 icache) "
  1095. "%d KB(L1 dcache) %d KB(L2 cache)\n",
  1096. icache_size, dcache_size, 0);
  1097. seq_printf(m, "%s\n", cache);
  1098. seq_printf(m, "external memory\t: "
  1099. #if defined(CONFIG_BFIN_EXTMEM_ICACHEABLE)
  1100. "cacheable"
  1101. #else
  1102. "uncacheable"
  1103. #endif
  1104. " in instruction cache\n");
  1105. seq_printf(m, "external memory\t: "
  1106. #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK)
  1107. "cacheable (write-back)"
  1108. #elif defined(CONFIG_BFIN_EXTMEM_WRITETHROUGH)
  1109. "cacheable (write-through)"
  1110. #else
  1111. "uncacheable"
  1112. #endif
  1113. " in data cache\n");
  1114. if (icache_size)
  1115. seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
  1116. BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
  1117. else
  1118. seq_printf(m, "icache setup\t: off\n");
  1119. seq_printf(m,
  1120. "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
  1121. dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
  1122. BFIN_DLINES);
  1123. #ifdef __ARCH_SYNC_CORE_DCACHE
  1124. seq_printf(m, "dcache flushes\t: %lu\n", dcache_invld_count[cpu_num]);
  1125. #endif
  1126. #ifdef __ARCH_SYNC_CORE_ICACHE
  1127. seq_printf(m, "icache flushes\t: %lu\n", icache_invld_count[cpu_num]);
  1128. #endif
  1129. seq_printf(m, "\n");
  1130. if (cpu_num != num_possible_cpus() - 1)
  1131. return 0;
  1132. if (L2_LENGTH) {
  1133. seq_printf(m, "L2 SRAM\t\t: %dKB\n", L2_LENGTH/0x400);
  1134. seq_printf(m, "L2 SRAM\t\t: "
  1135. #if defined(CONFIG_BFIN_L2_ICACHEABLE)
  1136. "cacheable"
  1137. #else
  1138. "uncacheable"
  1139. #endif
  1140. " in instruction cache\n");
  1141. seq_printf(m, "L2 SRAM\t\t: "
  1142. #if defined(CONFIG_BFIN_L2_WRITEBACK)
  1143. "cacheable (write-back)"
  1144. #elif defined(CONFIG_BFIN_L2_WRITETHROUGH)
  1145. "cacheable (write-through)"
  1146. #else
  1147. "uncacheable"
  1148. #endif
  1149. " in data cache\n");
  1150. }
  1151. seq_printf(m, "board name\t: %s\n", bfin_board_name);
  1152. seq_printf(m, "board memory\t: %ld kB (0x%08lx -> 0x%08lx)\n",
  1153. physical_mem_end >> 10, 0ul, physical_mem_end);
  1154. seq_printf(m, "kernel memory\t: %d kB (0x%08lx -> 0x%08lx)\n",
  1155. ((int)memory_end - (int)_rambase) >> 10,
  1156. _rambase, memory_end);
  1157. return 0;
  1158. }
  1159. static void *c_start(struct seq_file *m, loff_t *pos)
  1160. {
  1161. if (*pos == 0)
  1162. *pos = first_cpu(cpu_online_map);
  1163. if (*pos >= num_online_cpus())
  1164. return NULL;
  1165. return pos;
  1166. }
  1167. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  1168. {
  1169. *pos = next_cpu(*pos, cpu_online_map);
  1170. return c_start(m, pos);
  1171. }
  1172. static void c_stop(struct seq_file *m, void *v)
  1173. {
  1174. }
  1175. const struct seq_operations cpuinfo_op = {
  1176. .start = c_start,
  1177. .next = c_next,
  1178. .stop = c_stop,
  1179. .show = show_cpuinfo,
  1180. };
  1181. void __init cmdline_init(const char *r0)
  1182. {
  1183. early_shadow_stamp();
  1184. if (r0)
  1185. strncpy(command_line, r0, COMMAND_LINE_SIZE);
  1186. }