setup.c 37 KB

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