setup.c 39 KB

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