setup.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460
  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. #ifdef CONFIG_BF60x
  793. static inline u_long bfin_get_clk(char *name)
  794. {
  795. struct clk *clk;
  796. u_long clk_rate;
  797. clk = clk_get(NULL, name);
  798. if (IS_ERR(clk))
  799. return 0;
  800. clk_rate = clk_get_rate(clk);
  801. clk_put(clk);
  802. return clk_rate;
  803. }
  804. #endif
  805. void __init setup_arch(char **cmdline_p)
  806. {
  807. u32 mmr;
  808. unsigned long sclk, cclk;
  809. native_machine_early_platform_add_devices();
  810. enable_shadow_console();
  811. /* Check to make sure we are running on the right processor */
  812. mmr = bfin_cpuid();
  813. if (unlikely(CPUID != bfin_cpuid()))
  814. printk(KERN_ERR "ERROR: Not running on ADSP-%s: unknown CPUID 0x%04x Rev 0.%d\n",
  815. CPU, bfin_cpuid(), bfin_revid());
  816. #ifdef CONFIG_DUMMY_CONSOLE
  817. conswitchp = &dummy_con;
  818. #endif
  819. #if defined(CONFIG_CMDLINE_BOOL)
  820. strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
  821. command_line[sizeof(command_line) - 1] = 0;
  822. #endif
  823. /* Keep a copy of command line */
  824. *cmdline_p = &command_line[0];
  825. memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  826. boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
  827. memset(&bfin_memmap, 0, sizeof(bfin_memmap));
  828. #ifdef CONFIG_BF60x
  829. /* Should init clock device before parse command early */
  830. clk_init();
  831. #endif
  832. /* If the user does not specify things on the command line, use
  833. * what the bootloader set things up as
  834. */
  835. physical_mem_end = 0;
  836. parse_cmdline_early(&command_line[0]);
  837. if (_ramend == 0)
  838. _ramend = get_mem_size() * 1024 * 1024;
  839. if (physical_mem_end == 0)
  840. physical_mem_end = _ramend;
  841. memory_setup();
  842. #ifndef CONFIG_BF60x
  843. /* Initialize Async memory banks */
  844. bfin_write_EBIU_AMBCTL0(AMBCTL0VAL);
  845. bfin_write_EBIU_AMBCTL1(AMBCTL1VAL);
  846. bfin_write_EBIU_AMGCTL(AMGCTLVAL);
  847. #ifdef CONFIG_EBIU_MBSCTLVAL
  848. bfin_write_EBIU_MBSCTL(CONFIG_EBIU_MBSCTLVAL);
  849. bfin_write_EBIU_MODE(CONFIG_EBIU_MODEVAL);
  850. bfin_write_EBIU_FCTL(CONFIG_EBIU_FCTLVAL);
  851. #endif
  852. #endif
  853. #ifdef CONFIG_BFIN_HYSTERESIS_CONTROL
  854. bfin_write_PORTF_HYSTERESIS(HYST_PORTF_0_15);
  855. bfin_write_PORTG_HYSTERESIS(HYST_PORTG_0_15);
  856. bfin_write_PORTH_HYSTERESIS(HYST_PORTH_0_15);
  857. bfin_write_MISCPORT_HYSTERESIS((bfin_read_MISCPORT_HYSTERESIS() &
  858. ~HYST_NONEGPIO_MASK) | HYST_NONEGPIO);
  859. #endif
  860. cclk = get_cclk();
  861. sclk = get_sclk();
  862. if ((ANOMALY_05000273 || ANOMALY_05000274) && (cclk >> 1) < sclk)
  863. panic("ANOMALY 05000273 or 05000274: CCLK must be >= 2*SCLK");
  864. #ifdef BF561_FAMILY
  865. if (ANOMALY_05000266) {
  866. bfin_read_IMDMA_D0_IRQ_STATUS();
  867. bfin_read_IMDMA_D1_IRQ_STATUS();
  868. }
  869. #endif
  870. mmr = bfin_read_TBUFCTL();
  871. printk(KERN_INFO "Hardware Trace %s and %sabled\n",
  872. (mmr & 0x1) ? "active" : "off",
  873. (mmr & 0x2) ? "en" : "dis");
  874. #ifndef CONFIG_BF60x
  875. mmr = bfin_read_SYSCR();
  876. printk(KERN_INFO "Boot Mode: %i\n", mmr & 0xF);
  877. /* Newer parts mirror SWRST bits in SYSCR */
  878. #if defined(CONFIG_BF53x) || defined(CONFIG_BF561) || \
  879. defined(CONFIG_BF538) || defined(CONFIG_BF539)
  880. _bfin_swrst = bfin_read_SWRST();
  881. #else
  882. /* Clear boot mode field */
  883. _bfin_swrst = mmr & ~0xf;
  884. #endif
  885. #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
  886. bfin_write_SWRST(_bfin_swrst & ~DOUBLE_FAULT);
  887. #endif
  888. #ifdef CONFIG_DEBUG_DOUBLEFAULT_RESET
  889. bfin_write_SWRST(_bfin_swrst | DOUBLE_FAULT);
  890. #endif
  891. #ifdef CONFIG_SMP
  892. if (_bfin_swrst & SWRST_DBL_FAULT_A) {
  893. #else
  894. if (_bfin_swrst & RESET_DOUBLE) {
  895. #endif
  896. printk(KERN_EMERG "Recovering from DOUBLE FAULT event\n");
  897. #ifdef CONFIG_DEBUG_DOUBLEFAULT
  898. /* We assume the crashing kernel, and the current symbol table match */
  899. printk(KERN_EMERG " While handling exception (EXCAUSE = %#x) at %pF\n",
  900. initial_pda.seqstat_doublefault & SEQSTAT_EXCAUSE,
  901. initial_pda.retx_doublefault);
  902. printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %pF\n",
  903. initial_pda.dcplb_doublefault_addr);
  904. printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %pF\n",
  905. initial_pda.icplb_doublefault_addr);
  906. #endif
  907. printk(KERN_NOTICE " The instruction at %pF caused a double exception\n",
  908. initial_pda.retx);
  909. } else if (_bfin_swrst & RESET_WDOG)
  910. printk(KERN_INFO "Recovering from Watchdog event\n");
  911. else if (_bfin_swrst & RESET_SOFTWARE)
  912. printk(KERN_NOTICE "Reset caused by Software reset\n");
  913. #endif
  914. printk(KERN_INFO "Blackfin support (C) 2004-2010 Analog Devices, Inc.\n");
  915. if (bfin_compiled_revid() == 0xffff)
  916. printk(KERN_INFO "Compiled for ADSP-%s Rev any, running on 0.%d\n", CPU, bfin_revid());
  917. else if (bfin_compiled_revid() == -1)
  918. printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
  919. else
  920. printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
  921. if (likely(CPUID == bfin_cpuid())) {
  922. if (bfin_revid() != bfin_compiled_revid()) {
  923. if (bfin_compiled_revid() == -1)
  924. printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
  925. bfin_revid());
  926. else if (bfin_compiled_revid() != 0xffff) {
  927. printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
  928. bfin_compiled_revid(), bfin_revid());
  929. if (bfin_compiled_revid() > bfin_revid())
  930. panic("Error: you are missing anomaly workarounds for this rev");
  931. }
  932. }
  933. if (bfin_revid() < CONFIG_BF_REV_MIN || bfin_revid() > CONFIG_BF_REV_MAX)
  934. printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
  935. CPU, bfin_revid());
  936. }
  937. printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
  938. #ifdef CONFIG_BF60x
  939. printk(KERN_INFO "Processor Speed: %lu MHz core clock, %lu MHz SCLk, %lu MHz SCLK0, %lu MHz SCLK1 and %lu MHz DCLK\n",
  940. cclk / 1000000, bfin_get_clk("SYSCLK") / 1000000, get_sclk0() / 1000000, get_sclk1() / 1000000, get_dclk() / 1000000);
  941. #else
  942. printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
  943. cclk / 1000000, sclk / 1000000);
  944. #endif
  945. setup_bootmem_allocator();
  946. paging_init();
  947. /* Copy atomic sequences to their fixed location, and sanity check that
  948. these locations are the ones that we advertise to userspace. */
  949. memcpy((void *)FIXED_CODE_START, &fixed_code_start,
  950. FIXED_CODE_END - FIXED_CODE_START);
  951. BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
  952. != SIGRETURN_STUB - FIXED_CODE_START);
  953. BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
  954. != ATOMIC_XCHG32 - FIXED_CODE_START);
  955. BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
  956. != ATOMIC_CAS32 - FIXED_CODE_START);
  957. BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
  958. != ATOMIC_ADD32 - FIXED_CODE_START);
  959. BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
  960. != ATOMIC_SUB32 - FIXED_CODE_START);
  961. BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
  962. != ATOMIC_IOR32 - FIXED_CODE_START);
  963. BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
  964. != ATOMIC_AND32 - FIXED_CODE_START);
  965. BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
  966. != ATOMIC_XOR32 - FIXED_CODE_START);
  967. BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
  968. != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
  969. #ifdef CONFIG_SMP
  970. platform_init_cpus();
  971. #endif
  972. init_exception_vectors();
  973. bfin_cache_init(); /* Initialize caches for the boot CPU */
  974. }
  975. static int __init topology_init(void)
  976. {
  977. unsigned int cpu;
  978. for_each_possible_cpu(cpu) {
  979. register_cpu(&per_cpu(cpu_data, cpu).cpu, cpu);
  980. }
  981. return 0;
  982. }
  983. subsys_initcall(topology_init);
  984. /* Get the input clock frequency */
  985. static u_long cached_clkin_hz = CONFIG_CLKIN_HZ;
  986. #ifndef CONFIG_BF60x
  987. static u_long get_clkin_hz(void)
  988. {
  989. return cached_clkin_hz;
  990. }
  991. #endif
  992. static int __init early_init_clkin_hz(char *buf)
  993. {
  994. cached_clkin_hz = simple_strtoul(buf, NULL, 0);
  995. #ifdef BFIN_KERNEL_CLOCK
  996. if (cached_clkin_hz != CONFIG_CLKIN_HZ)
  997. panic("cannot change clkin_hz when reprogramming clocks");
  998. #endif
  999. return 1;
  1000. }
  1001. early_param("clkin_hz=", early_init_clkin_hz);
  1002. #ifndef CONFIG_BF60x
  1003. /* Get the voltage input multiplier */
  1004. static u_long get_vco(void)
  1005. {
  1006. static u_long cached_vco;
  1007. u_long msel, pll_ctl;
  1008. /* The assumption here is that VCO never changes at runtime.
  1009. * If, someday, we support that, then we'll have to change this.
  1010. */
  1011. if (cached_vco)
  1012. return cached_vco;
  1013. pll_ctl = bfin_read_PLL_CTL();
  1014. msel = (pll_ctl >> 9) & 0x3F;
  1015. if (0 == msel)
  1016. msel = 64;
  1017. cached_vco = get_clkin_hz();
  1018. cached_vco >>= (1 & pll_ctl); /* DF bit */
  1019. cached_vco *= msel;
  1020. return cached_vco;
  1021. }
  1022. #endif
  1023. /* Get the Core clock */
  1024. u_long get_cclk(void)
  1025. {
  1026. #ifdef CONFIG_BF60x
  1027. return bfin_get_clk("CCLK");
  1028. #else
  1029. static u_long cached_cclk_pll_div, cached_cclk;
  1030. u_long csel, ssel;
  1031. if (bfin_read_PLL_STAT() & 0x1)
  1032. return get_clkin_hz();
  1033. ssel = bfin_read_PLL_DIV();
  1034. if (ssel == cached_cclk_pll_div)
  1035. return cached_cclk;
  1036. else
  1037. cached_cclk_pll_div = ssel;
  1038. csel = ((ssel >> 4) & 0x03);
  1039. ssel &= 0xf;
  1040. if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
  1041. cached_cclk = get_vco() / ssel;
  1042. else
  1043. cached_cclk = get_vco() >> csel;
  1044. return cached_cclk;
  1045. #endif
  1046. }
  1047. EXPORT_SYMBOL(get_cclk);
  1048. #ifdef CONFIG_BF60x
  1049. /* Get the bf60x clock of SCLK0 domain */
  1050. u_long get_sclk0(void)
  1051. {
  1052. return bfin_get_clk("SCLK0");
  1053. }
  1054. EXPORT_SYMBOL(get_sclk0);
  1055. /* Get the bf60x clock of SCLK1 domain */
  1056. u_long get_sclk1(void)
  1057. {
  1058. return bfin_get_clk("SCLK1");
  1059. }
  1060. EXPORT_SYMBOL(get_sclk1);
  1061. /* Get the bf60x DRAM clock */
  1062. u_long get_dclk(void)
  1063. {
  1064. return bfin_get_clk("DCLK");
  1065. }
  1066. EXPORT_SYMBOL(get_dclk);
  1067. #endif
  1068. /* Get the default system clock */
  1069. u_long get_sclk(void)
  1070. {
  1071. #ifdef CONFIG_BF60x
  1072. return get_sclk0();
  1073. #else
  1074. static u_long cached_sclk;
  1075. u_long ssel;
  1076. /* The assumption here is that SCLK never changes at runtime.
  1077. * If, someday, we support that, then we'll have to change this.
  1078. */
  1079. if (cached_sclk)
  1080. return cached_sclk;
  1081. if (bfin_read_PLL_STAT() & 0x1)
  1082. return get_clkin_hz();
  1083. ssel = bfin_read_PLL_DIV() & 0xf;
  1084. if (0 == ssel) {
  1085. printk(KERN_WARNING "Invalid System Clock\n");
  1086. ssel = 1;
  1087. }
  1088. cached_sclk = get_vco() / ssel;
  1089. return cached_sclk;
  1090. #endif
  1091. }
  1092. EXPORT_SYMBOL(get_sclk);
  1093. unsigned long sclk_to_usecs(unsigned long sclk)
  1094. {
  1095. u64 tmp = USEC_PER_SEC * (u64)sclk;
  1096. do_div(tmp, get_sclk());
  1097. return tmp;
  1098. }
  1099. EXPORT_SYMBOL(sclk_to_usecs);
  1100. unsigned long usecs_to_sclk(unsigned long usecs)
  1101. {
  1102. u64 tmp = get_sclk() * (u64)usecs;
  1103. do_div(tmp, USEC_PER_SEC);
  1104. return tmp;
  1105. }
  1106. EXPORT_SYMBOL(usecs_to_sclk);
  1107. /*
  1108. * Get CPU information for use by the procfs.
  1109. */
  1110. static int show_cpuinfo(struct seq_file *m, void *v)
  1111. {
  1112. char *cpu, *mmu, *fpu, *vendor, *cache;
  1113. uint32_t revid;
  1114. int cpu_num = *(unsigned int *)v;
  1115. u_long sclk, cclk;
  1116. u_int icache_size = BFIN_ICACHESIZE / 1024, dcache_size = 0, dsup_banks = 0;
  1117. struct blackfin_cpudata *cpudata = &per_cpu(cpu_data, cpu_num);
  1118. cpu = CPU;
  1119. mmu = "none";
  1120. fpu = "none";
  1121. revid = bfin_revid();
  1122. sclk = get_sclk();
  1123. cclk = get_cclk();
  1124. switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
  1125. case 0xca:
  1126. vendor = "Analog Devices";
  1127. break;
  1128. default:
  1129. vendor = "unknown";
  1130. break;
  1131. }
  1132. seq_printf(m, "processor\t: %d\n" "vendor_id\t: %s\n", cpu_num, vendor);
  1133. if (CPUID == bfin_cpuid())
  1134. seq_printf(m, "cpu family\t: 0x%04x\n", CPUID);
  1135. else
  1136. seq_printf(m, "cpu family\t: Compiled for:0x%04x, running on:0x%04x\n",
  1137. CPUID, bfin_cpuid());
  1138. seq_printf(m, "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
  1139. "stepping\t: %d ",
  1140. cpu, cclk/1000000, sclk/1000000,
  1141. #ifdef CONFIG_MPU
  1142. "mpu on",
  1143. #else
  1144. "mpu off",
  1145. #endif
  1146. revid);
  1147. if (bfin_revid() != bfin_compiled_revid()) {
  1148. if (bfin_compiled_revid() == -1)
  1149. seq_printf(m, "(Compiled for Rev none)");
  1150. else if (bfin_compiled_revid() == 0xffff)
  1151. seq_printf(m, "(Compiled for Rev any)");
  1152. else
  1153. seq_printf(m, "(Compiled for Rev %d)", bfin_compiled_revid());
  1154. }
  1155. seq_printf(m, "\ncpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
  1156. cclk/1000000, cclk%1000000,
  1157. sclk/1000000, sclk%1000000);
  1158. seq_printf(m, "bogomips\t: %lu.%02lu\n"
  1159. "Calibration\t: %lu loops\n",
  1160. (loops_per_jiffy * HZ) / 500000,
  1161. ((loops_per_jiffy * HZ) / 5000) % 100,
  1162. (loops_per_jiffy * HZ));
  1163. /* Check Cache configutation */
  1164. switch (cpudata->dmemctl & (1 << DMC0_P | 1 << DMC1_P)) {
  1165. case ACACHE_BSRAM:
  1166. cache = "dbank-A/B\t: cache/sram";
  1167. dcache_size = 16;
  1168. dsup_banks = 1;
  1169. break;
  1170. case ACACHE_BCACHE:
  1171. cache = "dbank-A/B\t: cache/cache";
  1172. dcache_size = 32;
  1173. dsup_banks = 2;
  1174. break;
  1175. case ASRAM_BSRAM:
  1176. cache = "dbank-A/B\t: sram/sram";
  1177. dcache_size = 0;
  1178. dsup_banks = 0;
  1179. break;
  1180. default:
  1181. cache = "unknown";
  1182. dcache_size = 0;
  1183. dsup_banks = 0;
  1184. break;
  1185. }
  1186. /* Is it turned on? */
  1187. if ((cpudata->dmemctl & (ENDCPLB | DMC_ENABLE)) != (ENDCPLB | DMC_ENABLE))
  1188. dcache_size = 0;
  1189. if ((cpudata->imemctl & (IMC | ENICPLB)) != (IMC | ENICPLB))
  1190. icache_size = 0;
  1191. seq_printf(m, "cache size\t: %d KB(L1 icache) "
  1192. "%d KB(L1 dcache) %d KB(L2 cache)\n",
  1193. icache_size, dcache_size, 0);
  1194. seq_printf(m, "%s\n", cache);
  1195. seq_printf(m, "external memory\t: "
  1196. #if defined(CONFIG_BFIN_EXTMEM_ICACHEABLE)
  1197. "cacheable"
  1198. #else
  1199. "uncacheable"
  1200. #endif
  1201. " in instruction cache\n");
  1202. seq_printf(m, "external memory\t: "
  1203. #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK)
  1204. "cacheable (write-back)"
  1205. #elif defined(CONFIG_BFIN_EXTMEM_WRITETHROUGH)
  1206. "cacheable (write-through)"
  1207. #else
  1208. "uncacheable"
  1209. #endif
  1210. " in data cache\n");
  1211. if (icache_size)
  1212. seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
  1213. BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
  1214. else
  1215. seq_printf(m, "icache setup\t: off\n");
  1216. seq_printf(m,
  1217. "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
  1218. dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
  1219. BFIN_DLINES);
  1220. #ifdef __ARCH_SYNC_CORE_DCACHE
  1221. seq_printf(m, "dcache flushes\t: %lu\n", dcache_invld_count[cpu_num]);
  1222. #endif
  1223. #ifdef __ARCH_SYNC_CORE_ICACHE
  1224. seq_printf(m, "icache flushes\t: %lu\n", icache_invld_count[cpu_num]);
  1225. #endif
  1226. seq_printf(m, "\n");
  1227. if (cpu_num != num_possible_cpus() - 1)
  1228. return 0;
  1229. if (L2_LENGTH) {
  1230. seq_printf(m, "L2 SRAM\t\t: %dKB\n", L2_LENGTH/0x400);
  1231. seq_printf(m, "L2 SRAM\t\t: "
  1232. #if defined(CONFIG_BFIN_L2_ICACHEABLE)
  1233. "cacheable"
  1234. #else
  1235. "uncacheable"
  1236. #endif
  1237. " in instruction cache\n");
  1238. seq_printf(m, "L2 SRAM\t\t: "
  1239. #if defined(CONFIG_BFIN_L2_WRITEBACK)
  1240. "cacheable (write-back)"
  1241. #elif defined(CONFIG_BFIN_L2_WRITETHROUGH)
  1242. "cacheable (write-through)"
  1243. #else
  1244. "uncacheable"
  1245. #endif
  1246. " in data cache\n");
  1247. }
  1248. seq_printf(m, "board name\t: %s\n", bfin_board_name);
  1249. seq_printf(m, "board memory\t: %ld kB (0x%08lx -> 0x%08lx)\n",
  1250. physical_mem_end >> 10, 0ul, physical_mem_end);
  1251. seq_printf(m, "kernel memory\t: %d kB (0x%08lx -> 0x%08lx)\n",
  1252. ((int)memory_end - (int)_rambase) >> 10,
  1253. _rambase, memory_end);
  1254. return 0;
  1255. }
  1256. static void *c_start(struct seq_file *m, loff_t *pos)
  1257. {
  1258. if (*pos == 0)
  1259. *pos = cpumask_first(cpu_online_mask);
  1260. if (*pos >= num_online_cpus())
  1261. return NULL;
  1262. return pos;
  1263. }
  1264. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  1265. {
  1266. *pos = cpumask_next(*pos, cpu_online_mask);
  1267. return c_start(m, pos);
  1268. }
  1269. static void c_stop(struct seq_file *m, void *v)
  1270. {
  1271. }
  1272. const struct seq_operations cpuinfo_op = {
  1273. .start = c_start,
  1274. .next = c_next,
  1275. .stop = c_stop,
  1276. .show = show_cpuinfo,
  1277. };
  1278. void __init cmdline_init(const char *r0)
  1279. {
  1280. early_shadow_stamp();
  1281. if (r0)
  1282. strncpy(command_line, r0, COMMAND_LINE_SIZE);
  1283. }