setup.c 34 KB

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