setup.c 36 KB

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