setup.c 40 KB

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