setup.c 37 KB

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