setup.c 39 KB

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