setup.c 37 KB

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