setup.c 39 KB

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