setup.c 36 KB

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