setup.c 37 KB

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