setup.c 36 KB

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