setup.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  1. /*
  2. * arch/blackfin/kernel/setup.c
  3. *
  4. * Copyright 2004-2006 Analog Devices Inc.
  5. *
  6. * Enter bugs at http://blackfin.uclinux.org/
  7. *
  8. * Licensed under the GPL-2 or later.
  9. */
  10. #include <linux/delay.h>
  11. #include <linux/console.h>
  12. #include <linux/bootmem.h>
  13. #include <linux/seq_file.h>
  14. #include <linux/cpu.h>
  15. #include <linux/module.h>
  16. #include <linux/tty.h>
  17. #include <linux/pfn.h>
  18. #include <linux/ext2_fs.h>
  19. #include <linux/cramfs_fs.h>
  20. #include <linux/romfs_fs.h>
  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/fixed_code.h>
  27. #include <asm/early_printk.h>
  28. static DEFINE_PER_CPU(struct cpu, cpu_devices);
  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. #ifdef CONFIG_MTD_UCLINUX
  40. unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
  41. unsigned long _ebss;
  42. EXPORT_SYMBOL(memory_mtd_end);
  43. EXPORT_SYMBOL(memory_mtd_start);
  44. EXPORT_SYMBOL(mtd_size);
  45. #endif
  46. char __initdata command_line[COMMAND_LINE_SIZE];
  47. /* boot memmap, for parsing "memmap=" */
  48. #define BFIN_MEMMAP_MAX 128 /* number of entries in bfin_memmap */
  49. #define BFIN_MEMMAP_RAM 1
  50. #define BFIN_MEMMAP_RESERVED 2
  51. struct bfin_memmap {
  52. int nr_map;
  53. struct bfin_memmap_entry {
  54. unsigned long long addr; /* start of memory segment */
  55. unsigned long long size;
  56. unsigned long type;
  57. } map[BFIN_MEMMAP_MAX];
  58. } bfin_memmap __initdata;
  59. /* for memmap sanitization */
  60. struct change_member {
  61. struct bfin_memmap_entry *pentry; /* pointer to original entry */
  62. unsigned long long addr; /* address for this change point */
  63. };
  64. static struct change_member change_point_list[2*BFIN_MEMMAP_MAX] __initdata;
  65. static struct change_member *change_point[2*BFIN_MEMMAP_MAX] __initdata;
  66. static struct bfin_memmap_entry *overlap_list[BFIN_MEMMAP_MAX] __initdata;
  67. static struct bfin_memmap_entry new_map[BFIN_MEMMAP_MAX] __initdata;
  68. void __init bf53x_cache_init(void)
  69. {
  70. #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
  71. generate_cpl_tables();
  72. #endif
  73. #ifdef CONFIG_BFIN_ICACHE
  74. bfin_icache_init();
  75. printk(KERN_INFO "Instruction Cache Enabled\n");
  76. #endif
  77. #ifdef CONFIG_BFIN_DCACHE
  78. bfin_dcache_init();
  79. printk(KERN_INFO "Data Cache Enabled"
  80. # if defined CONFIG_BFIN_WB
  81. " (write-back)"
  82. # elif defined CONFIG_BFIN_WT
  83. " (write-through)"
  84. # endif
  85. "\n");
  86. #endif
  87. }
  88. void __init bf53x_relocate_l1_mem(void)
  89. {
  90. unsigned long l1_code_length;
  91. unsigned long l1_data_a_length;
  92. unsigned long l1_data_b_length;
  93. unsigned long l2_length;
  94. l1_code_length = _etext_l1 - _stext_l1;
  95. if (l1_code_length > L1_CODE_LENGTH)
  96. panic("L1 Instruction SRAM Overflow\n");
  97. /* cannot complain as printk is not available as yet.
  98. * But we can continue booting and complain later!
  99. */
  100. /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
  101. dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
  102. l1_data_a_length = _ebss_l1 - _sdata_l1;
  103. if (l1_data_a_length > L1_DATA_A_LENGTH)
  104. panic("L1 Data SRAM Bank A Overflow\n");
  105. /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
  106. dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
  107. l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
  108. if (l1_data_b_length > L1_DATA_B_LENGTH)
  109. panic("L1 Data SRAM Bank B Overflow\n");
  110. /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
  111. dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
  112. l1_data_a_length, l1_data_b_length);
  113. #ifdef L2_LENGTH
  114. l2_length = _ebss_l2 - _stext_l2;
  115. if (l2_length > L2_LENGTH)
  116. panic("L2 SRAM Overflow\n");
  117. /* Copy _stext_l2 to _edata_l2 to L2 SRAM */
  118. dma_memcpy(_stext_l2, _l2_lma_start, l2_length);
  119. #endif
  120. }
  121. /* add_memory_region to memmap */
  122. static void __init add_memory_region(unsigned long long start,
  123. unsigned long long size, int type)
  124. {
  125. int i;
  126. i = bfin_memmap.nr_map;
  127. if (i == BFIN_MEMMAP_MAX) {
  128. printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
  129. return;
  130. }
  131. bfin_memmap.map[i].addr = start;
  132. bfin_memmap.map[i].size = size;
  133. bfin_memmap.map[i].type = type;
  134. bfin_memmap.nr_map++;
  135. }
  136. /*
  137. * Sanitize the boot memmap, removing overlaps.
  138. */
  139. static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map)
  140. {
  141. struct change_member *change_tmp;
  142. unsigned long current_type, last_type;
  143. unsigned long long last_addr;
  144. int chgidx, still_changing;
  145. int overlap_entries;
  146. int new_entry;
  147. int old_nr, new_nr, chg_nr;
  148. int i;
  149. /*
  150. Visually we're performing the following (1,2,3,4 = memory types)
  151. Sample memory map (w/overlaps):
  152. ____22__________________
  153. ______________________4_
  154. ____1111________________
  155. _44_____________________
  156. 11111111________________
  157. ____________________33__
  158. ___________44___________
  159. __________33333_________
  160. ______________22________
  161. ___________________2222_
  162. _________111111111______
  163. _____________________11_
  164. _________________4______
  165. Sanitized equivalent (no overlap):
  166. 1_______________________
  167. _44_____________________
  168. ___1____________________
  169. ____22__________________
  170. ______11________________
  171. _________1______________
  172. __________3_____________
  173. ___________44___________
  174. _____________33_________
  175. _______________2________
  176. ________________1_______
  177. _________________4______
  178. ___________________2____
  179. ____________________33__
  180. ______________________4_
  181. */
  182. /* if there's only one memory region, don't bother */
  183. if (*pnr_map < 2)
  184. return -1;
  185. old_nr = *pnr_map;
  186. /* bail out if we find any unreasonable addresses in memmap */
  187. for (i = 0; i < old_nr; i++)
  188. if (map[i].addr + map[i].size < map[i].addr)
  189. return -1;
  190. /* create pointers for initial change-point information (for sorting) */
  191. for (i = 0; i < 2*old_nr; i++)
  192. change_point[i] = &change_point_list[i];
  193. /* record all known change-points (starting and ending addresses),
  194. omitting those that are for empty memory regions */
  195. chgidx = 0;
  196. for (i = 0; i < old_nr; i++) {
  197. if (map[i].size != 0) {
  198. change_point[chgidx]->addr = map[i].addr;
  199. change_point[chgidx++]->pentry = &map[i];
  200. change_point[chgidx]->addr = map[i].addr + map[i].size;
  201. change_point[chgidx++]->pentry = &map[i];
  202. }
  203. }
  204. chg_nr = chgidx; /* true number of change-points */
  205. /* sort change-point list by memory addresses (low -> high) */
  206. still_changing = 1;
  207. while (still_changing) {
  208. still_changing = 0;
  209. for (i = 1; i < chg_nr; i++) {
  210. /* if <current_addr> > <last_addr>, swap */
  211. /* or, if current=<start_addr> & last=<end_addr>, swap */
  212. if ((change_point[i]->addr < change_point[i-1]->addr) ||
  213. ((change_point[i]->addr == change_point[i-1]->addr) &&
  214. (change_point[i]->addr == change_point[i]->pentry->addr) &&
  215. (change_point[i-1]->addr != change_point[i-1]->pentry->addr))
  216. ) {
  217. change_tmp = change_point[i];
  218. change_point[i] = change_point[i-1];
  219. change_point[i-1] = change_tmp;
  220. still_changing = 1;
  221. }
  222. }
  223. }
  224. /* create a new memmap, removing overlaps */
  225. overlap_entries = 0; /* number of entries in the overlap table */
  226. new_entry = 0; /* index for creating new memmap entries */
  227. last_type = 0; /* start with undefined memory type */
  228. last_addr = 0; /* start with 0 as last starting address */
  229. /* loop through change-points, determining affect on the new memmap */
  230. for (chgidx = 0; chgidx < chg_nr; chgidx++) {
  231. /* keep track of all overlapping memmap entries */
  232. if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) {
  233. /* add map entry to overlap list (> 1 entry implies an overlap) */
  234. overlap_list[overlap_entries++] = change_point[chgidx]->pentry;
  235. } else {
  236. /* remove entry from list (order independent, so swap with last) */
  237. for (i = 0; i < overlap_entries; i++) {
  238. if (overlap_list[i] == change_point[chgidx]->pentry)
  239. overlap_list[i] = overlap_list[overlap_entries-1];
  240. }
  241. overlap_entries--;
  242. }
  243. /* if there are overlapping entries, decide which "type" to use */
  244. /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
  245. current_type = 0;
  246. for (i = 0; i < overlap_entries; i++)
  247. if (overlap_list[i]->type > current_type)
  248. current_type = overlap_list[i]->type;
  249. /* continue building up new memmap based on this information */
  250. if (current_type != last_type) {
  251. if (last_type != 0) {
  252. new_map[new_entry].size =
  253. change_point[chgidx]->addr - last_addr;
  254. /* move forward only if the new size was non-zero */
  255. if (new_map[new_entry].size != 0)
  256. if (++new_entry >= BFIN_MEMMAP_MAX)
  257. break; /* no more space left for new entries */
  258. }
  259. if (current_type != 0) {
  260. new_map[new_entry].addr = change_point[chgidx]->addr;
  261. new_map[new_entry].type = current_type;
  262. last_addr = change_point[chgidx]->addr;
  263. }
  264. last_type = current_type;
  265. }
  266. }
  267. new_nr = new_entry; /* retain count for new entries */
  268. /* copy new mapping into original location */
  269. memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry));
  270. *pnr_map = new_nr;
  271. return 0;
  272. }
  273. static void __init print_memory_map(char *who)
  274. {
  275. int i;
  276. for (i = 0; i < bfin_memmap.nr_map; i++) {
  277. printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who,
  278. bfin_memmap.map[i].addr,
  279. bfin_memmap.map[i].addr + bfin_memmap.map[i].size);
  280. switch (bfin_memmap.map[i].type) {
  281. case BFIN_MEMMAP_RAM:
  282. printk("(usable)\n");
  283. break;
  284. case BFIN_MEMMAP_RESERVED:
  285. printk("(reserved)\n");
  286. break;
  287. default: printk("type %lu\n", bfin_memmap.map[i].type);
  288. break;
  289. }
  290. }
  291. }
  292. static __init int parse_memmap(char *arg)
  293. {
  294. unsigned long long start_at, mem_size;
  295. if (!arg)
  296. return -EINVAL;
  297. mem_size = memparse(arg, &arg);
  298. if (*arg == '@') {
  299. start_at = memparse(arg+1, &arg);
  300. add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM);
  301. } else if (*arg == '$') {
  302. start_at = memparse(arg+1, &arg);
  303. add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED);
  304. }
  305. return 0;
  306. }
  307. /*
  308. * Initial parsing of the command line. Currently, we support:
  309. * - Controlling the linux memory size: mem=xxx[KMG]
  310. * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
  311. * $ -> reserved memory is dcacheable
  312. * # -> reserved memory is icacheable
  313. * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
  314. * @ from <start> to <start>+<mem>, type RAM
  315. * $ from <start> to <start>+<mem>, type RESERVED
  316. *
  317. */
  318. static __init void parse_cmdline_early(char *cmdline_p)
  319. {
  320. char c = ' ', *to = cmdline_p;
  321. unsigned int memsize;
  322. for (;;) {
  323. if (c == ' ') {
  324. if (!memcmp(to, "mem=", 4)) {
  325. to += 4;
  326. memsize = memparse(to, &to);
  327. if (memsize)
  328. _ramend = memsize;
  329. } else if (!memcmp(to, "max_mem=", 8)) {
  330. to += 8;
  331. memsize = memparse(to, &to);
  332. if (memsize) {
  333. physical_mem_end = memsize;
  334. if (*to != ' ') {
  335. if (*to == '$'
  336. || *(to + 1) == '$')
  337. reserved_mem_dcache_on =
  338. 1;
  339. if (*to == '#'
  340. || *(to + 1) == '#')
  341. reserved_mem_icache_on =
  342. 1;
  343. }
  344. }
  345. } else if (!memcmp(to, "earlyprintk=", 12)) {
  346. to += 12;
  347. setup_early_printk(to);
  348. } else if (!memcmp(to, "memmap=", 7)) {
  349. to += 7;
  350. parse_memmap(to);
  351. }
  352. }
  353. c = *(to++);
  354. if (!c)
  355. break;
  356. }
  357. }
  358. /*
  359. * Setup memory defaults from user config.
  360. * The physical memory layout looks like:
  361. *
  362. * [_rambase, _ramstart]: kernel image
  363. * [memory_start, memory_end]: dynamic memory managed by kernel
  364. * [memory_end, _ramend]: reserved memory
  365. * [meory_mtd_start(memory_end),
  366. * memory_mtd_start + mtd_size]: rootfs (if any)
  367. * [_ramend - DMA_UNCACHED_REGION,
  368. * _ramend]: uncached DMA region
  369. * [_ramend, physical_mem_end]: memory not managed by kernel
  370. *
  371. */
  372. static __init void memory_setup(void)
  373. {
  374. #ifdef CONFIG_MTD_UCLINUX
  375. unsigned long mtd_phys = 0;
  376. #endif
  377. _rambase = (unsigned long)_stext;
  378. _ramstart = (unsigned long)_end;
  379. if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
  380. console_init();
  381. panic("DMA region exceeds memory limit: %lu.\n",
  382. _ramend - _ramstart);
  383. }
  384. memory_end = _ramend - DMA_UNCACHED_REGION;
  385. #ifdef CONFIG_MPU
  386. /* Round up to multiple of 4MB. */
  387. memory_start = (_ramstart + 0x3fffff) & ~0x3fffff;
  388. #else
  389. memory_start = PAGE_ALIGN(_ramstart);
  390. #endif
  391. #if defined(CONFIG_MTD_UCLINUX)
  392. /* generic memory mapped MTD driver */
  393. memory_mtd_end = memory_end;
  394. mtd_phys = _ramstart;
  395. mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
  396. # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
  397. if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
  398. mtd_size =
  399. PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
  400. # endif
  401. # if defined(CONFIG_CRAMFS)
  402. if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
  403. mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
  404. # endif
  405. # if defined(CONFIG_ROMFS_FS)
  406. if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
  407. && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
  408. mtd_size =
  409. PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
  410. # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
  411. /* Due to a Hardware Anomaly we need to limit the size of usable
  412. * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
  413. * 05000263 - Hardware loop corrupted when taking an ICPLB exception
  414. */
  415. # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
  416. if (memory_end >= 56 * 1024 * 1024)
  417. memory_end = 56 * 1024 * 1024;
  418. # else
  419. if (memory_end >= 60 * 1024 * 1024)
  420. memory_end = 60 * 1024 * 1024;
  421. # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
  422. # endif /* ANOMALY_05000263 */
  423. # endif /* CONFIG_ROMFS_FS */
  424. memory_end -= mtd_size;
  425. if (mtd_size == 0) {
  426. console_init();
  427. panic("Don't boot kernel without rootfs attached.\n");
  428. }
  429. /* Relocate MTD image to the top of memory after the uncached memory area */
  430. dma_memcpy((char *)memory_end, _end, mtd_size);
  431. memory_mtd_start = memory_end;
  432. _ebss = memory_mtd_start; /* define _ebss for compatible */
  433. #endif /* CONFIG_MTD_UCLINUX */
  434. #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
  435. /* Due to a Hardware Anomaly we need to limit the size of usable
  436. * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
  437. * 05000263 - Hardware loop corrupted when taking an ICPLB exception
  438. */
  439. #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
  440. if (memory_end >= 56 * 1024 * 1024)
  441. memory_end = 56 * 1024 * 1024;
  442. #else
  443. if (memory_end >= 60 * 1024 * 1024)
  444. memory_end = 60 * 1024 * 1024;
  445. #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
  446. printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
  447. #endif /* ANOMALY_05000263 */
  448. #ifdef CONFIG_MPU
  449. page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32;
  450. page_mask_order = get_order(3 * page_mask_nelts * sizeof(long));
  451. #endif
  452. #if !defined(CONFIG_MTD_UCLINUX)
  453. /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
  454. memory_end -= SIZE_4K;
  455. #endif
  456. init_mm.start_code = (unsigned long)_stext;
  457. init_mm.end_code = (unsigned long)_etext;
  458. init_mm.end_data = (unsigned long)_edata;
  459. init_mm.brk = (unsigned long)0;
  460. printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
  461. printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
  462. printk(KERN_INFO "Memory map:\n"
  463. KERN_INFO " fixedcode = 0x%p-0x%p\n"
  464. KERN_INFO " text = 0x%p-0x%p\n"
  465. KERN_INFO " rodata = 0x%p-0x%p\n"
  466. KERN_INFO " bss = 0x%p-0x%p\n"
  467. KERN_INFO " data = 0x%p-0x%p\n"
  468. KERN_INFO " stack = 0x%p-0x%p\n"
  469. KERN_INFO " init = 0x%p-0x%p\n"
  470. KERN_INFO " available = 0x%p-0x%p\n"
  471. #ifdef CONFIG_MTD_UCLINUX
  472. KERN_INFO " rootfs = 0x%p-0x%p\n"
  473. #endif
  474. #if DMA_UNCACHED_REGION > 0
  475. KERN_INFO " DMA Zone = 0x%p-0x%p\n"
  476. #endif
  477. , (void *)FIXED_CODE_START, (void *)FIXED_CODE_END,
  478. _stext, _etext,
  479. __start_rodata, __end_rodata,
  480. __bss_start, __bss_stop,
  481. _sdata, _edata,
  482. (void *)&init_thread_union,
  483. (void *)((int)(&init_thread_union) + 0x2000),
  484. __init_begin, __init_end,
  485. (void *)_ramstart, (void *)memory_end
  486. #ifdef CONFIG_MTD_UCLINUX
  487. , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
  488. #endif
  489. #if DMA_UNCACHED_REGION > 0
  490. , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
  491. #endif
  492. );
  493. }
  494. /*
  495. * Find the lowest, highest page frame number we have available
  496. */
  497. void __init find_min_max_pfn(void)
  498. {
  499. int i;
  500. max_pfn = 0;
  501. min_low_pfn = memory_end;
  502. for (i = 0; i < bfin_memmap.nr_map; i++) {
  503. unsigned long start, end;
  504. /* RAM? */
  505. if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
  506. continue;
  507. start = PFN_UP(bfin_memmap.map[i].addr);
  508. end = PFN_DOWN(bfin_memmap.map[i].addr +
  509. bfin_memmap.map[i].size);
  510. if (start >= end)
  511. continue;
  512. if (end > max_pfn)
  513. max_pfn = end;
  514. if (start < min_low_pfn)
  515. min_low_pfn = start;
  516. }
  517. }
  518. static __init void setup_bootmem_allocator(void)
  519. {
  520. int bootmap_size;
  521. int i;
  522. unsigned long start_pfn, end_pfn;
  523. unsigned long curr_pfn, last_pfn, size;
  524. /* mark memory between memory_start and memory_end usable */
  525. add_memory_region(memory_start,
  526. memory_end - memory_start, BFIN_MEMMAP_RAM);
  527. /* sanity check for overlap */
  528. sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
  529. print_memory_map("boot memmap");
  530. /* intialize globals in linux/bootmem.h */
  531. find_min_max_pfn();
  532. /* pfn of the last usable page frame */
  533. if (max_pfn > memory_end >> PAGE_SHIFT)
  534. max_pfn = memory_end >> PAGE_SHIFT;
  535. /* pfn of last page frame directly mapped by kernel */
  536. max_low_pfn = max_pfn;
  537. /* pfn of the first usable page frame after kernel image*/
  538. if (min_low_pfn < memory_start >> PAGE_SHIFT)
  539. min_low_pfn = memory_start >> PAGE_SHIFT;
  540. start_pfn = PAGE_OFFSET >> PAGE_SHIFT;
  541. end_pfn = memory_end >> PAGE_SHIFT;
  542. /*
  543. * give all the memory to the bootmap allocator, tell it to put the
  544. * boot mem_map at the start of memory.
  545. */
  546. bootmap_size = init_bootmem_node(NODE_DATA(0),
  547. memory_start >> PAGE_SHIFT, /* map goes here */
  548. start_pfn, end_pfn);
  549. /* register the memmap regions with the bootmem allocator */
  550. for (i = 0; i < bfin_memmap.nr_map; i++) {
  551. /*
  552. * Reserve usable memory
  553. */
  554. if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
  555. continue;
  556. /*
  557. * We are rounding up the start address of usable memory:
  558. */
  559. curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
  560. if (curr_pfn >= end_pfn)
  561. continue;
  562. /*
  563. * ... and at the end of the usable range downwards:
  564. */
  565. last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
  566. bfin_memmap.map[i].size);
  567. if (last_pfn > end_pfn)
  568. last_pfn = end_pfn;
  569. /*
  570. * .. finally, did all the rounding and playing
  571. * around just make the area go away?
  572. */
  573. if (last_pfn <= curr_pfn)
  574. continue;
  575. size = last_pfn - curr_pfn;
  576. free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
  577. }
  578. /* reserve memory before memory_start, including bootmap */
  579. reserve_bootmem(PAGE_OFFSET,
  580. memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET,
  581. BOOTMEM_DEFAULT);
  582. }
  583. #define EBSZ_TO_MEG(ebsz) \
  584. ({ \
  585. int meg = 0; \
  586. switch (ebsz & 0xf) { \
  587. case 0x1: meg = 16; break; \
  588. case 0x3: meg = 32; break; \
  589. case 0x5: meg = 64; break; \
  590. case 0x7: meg = 128; break; \
  591. case 0x9: meg = 256; break; \
  592. case 0xb: meg = 512; break; \
  593. } \
  594. meg; \
  595. })
  596. static inline int __init get_mem_size(void)
  597. {
  598. #if defined(EBIU_SDBCTL)
  599. # if defined(BF561_FAMILY)
  600. int ret = 0;
  601. u32 sdbctl = bfin_read_EBIU_SDBCTL();
  602. ret += EBSZ_TO_MEG(sdbctl >> 0);
  603. ret += EBSZ_TO_MEG(sdbctl >> 8);
  604. ret += EBSZ_TO_MEG(sdbctl >> 16);
  605. ret += EBSZ_TO_MEG(sdbctl >> 24);
  606. return ret;
  607. # else
  608. return EBSZ_TO_MEG(bfin_read_EBIU_SDBCTL());
  609. # endif
  610. #elif defined(EBIU_DDRCTL1)
  611. u32 ddrctl = bfin_read_EBIU_DDRCTL1();
  612. int ret = 0;
  613. switch (ddrctl & 0xc0000) {
  614. case DEVSZ_64: ret = 64 / 8;
  615. case DEVSZ_128: ret = 128 / 8;
  616. case DEVSZ_256: ret = 256 / 8;
  617. case DEVSZ_512: ret = 512 / 8;
  618. }
  619. switch (ddrctl & 0x30000) {
  620. case DEVWD_4: ret *= 2;
  621. case DEVWD_8: ret *= 2;
  622. case DEVWD_16: break;
  623. }
  624. if ((ddrctl & 0xc000) == 0x4000)
  625. ret *= 2;
  626. return ret;
  627. #endif
  628. BUG();
  629. }
  630. void __init setup_arch(char **cmdline_p)
  631. {
  632. unsigned long sclk, cclk;
  633. #ifdef CONFIG_DUMMY_CONSOLE
  634. conswitchp = &dummy_con;
  635. #endif
  636. #if defined(CONFIG_CMDLINE_BOOL)
  637. strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
  638. command_line[sizeof(command_line) - 1] = 0;
  639. #endif
  640. /* Keep a copy of command line */
  641. *cmdline_p = &command_line[0];
  642. memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  643. boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
  644. /* setup memory defaults from the user config */
  645. physical_mem_end = 0;
  646. _ramend = get_mem_size() * 1024 * 1024;
  647. memset(&bfin_memmap, 0, sizeof(bfin_memmap));
  648. parse_cmdline_early(&command_line[0]);
  649. if (physical_mem_end == 0)
  650. physical_mem_end = _ramend;
  651. memory_setup();
  652. cclk = get_cclk();
  653. sclk = get_sclk();
  654. #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
  655. if (ANOMALY_05000273 && cclk == sclk)
  656. panic("ANOMALY 05000273, SCLK can not be same as CCLK");
  657. #endif
  658. #ifdef BF561_FAMILY
  659. if (ANOMALY_05000266) {
  660. bfin_read_IMDMA_D0_IRQ_STATUS();
  661. bfin_read_IMDMA_D1_IRQ_STATUS();
  662. }
  663. #endif
  664. printk(KERN_INFO "Hardware Trace ");
  665. if (bfin_read_TBUFCTL() & 0x1)
  666. printk("Active ");
  667. else
  668. printk("Off ");
  669. if (bfin_read_TBUFCTL() & 0x2)
  670. printk("and Enabled\n");
  671. else
  672. printk("and Disabled\n");
  673. #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
  674. /* we need to initialize the Flashrom device here since we might
  675. * do things with flash early on in the boot
  676. */
  677. flash_probe();
  678. #endif
  679. _bfin_swrst = bfin_read_SWRST();
  680. /* If we double fault, reset the system - otherwise we hang forever */
  681. bfin_write_SWRST(DOUBLE_FAULT);
  682. if (_bfin_swrst & RESET_DOUBLE)
  683. printk(KERN_INFO "Recovering from Double Fault event\n");
  684. else if (_bfin_swrst & RESET_WDOG)
  685. printk(KERN_INFO "Recovering from Watchdog event\n");
  686. else if (_bfin_swrst & RESET_SOFTWARE)
  687. printk(KERN_NOTICE "Reset caused by Software reset\n");
  688. printk(KERN_INFO "Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
  689. if (bfin_compiled_revid() == 0xffff)
  690. printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
  691. else if (bfin_compiled_revid() == -1)
  692. printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
  693. else
  694. printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
  695. if (bfin_revid() != bfin_compiled_revid()) {
  696. if (bfin_compiled_revid() == -1)
  697. printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
  698. bfin_revid());
  699. else if (bfin_compiled_revid() != 0xffff)
  700. printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
  701. bfin_compiled_revid(), bfin_revid());
  702. }
  703. if (bfin_revid() < SUPPORTED_REVID)
  704. printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
  705. CPU, bfin_revid());
  706. printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
  707. printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
  708. cclk / 1000000, sclk / 1000000);
  709. if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
  710. printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
  711. setup_bootmem_allocator();
  712. paging_init();
  713. /* Copy atomic sequences to their fixed location, and sanity check that
  714. these locations are the ones that we advertise to userspace. */
  715. memcpy((void *)FIXED_CODE_START, &fixed_code_start,
  716. FIXED_CODE_END - FIXED_CODE_START);
  717. BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
  718. != SIGRETURN_STUB - FIXED_CODE_START);
  719. BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
  720. != ATOMIC_XCHG32 - FIXED_CODE_START);
  721. BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
  722. != ATOMIC_CAS32 - FIXED_CODE_START);
  723. BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
  724. != ATOMIC_ADD32 - FIXED_CODE_START);
  725. BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
  726. != ATOMIC_SUB32 - FIXED_CODE_START);
  727. BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
  728. != ATOMIC_IOR32 - FIXED_CODE_START);
  729. BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
  730. != ATOMIC_AND32 - FIXED_CODE_START);
  731. BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
  732. != ATOMIC_XOR32 - FIXED_CODE_START);
  733. BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
  734. != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
  735. init_exception_vectors();
  736. bf53x_cache_init();
  737. }
  738. static int __init topology_init(void)
  739. {
  740. int cpu;
  741. for_each_possible_cpu(cpu) {
  742. struct cpu *c = &per_cpu(cpu_devices, cpu);
  743. register_cpu(c, cpu);
  744. }
  745. return 0;
  746. }
  747. subsys_initcall(topology_init);
  748. /* Get the voltage input multiplier */
  749. static u_long cached_vco_pll_ctl, cached_vco;
  750. static u_long get_vco(void)
  751. {
  752. u_long msel;
  753. u_long pll_ctl = bfin_read_PLL_CTL();
  754. if (pll_ctl == cached_vco_pll_ctl)
  755. return cached_vco;
  756. else
  757. cached_vco_pll_ctl = pll_ctl;
  758. msel = (pll_ctl >> 9) & 0x3F;
  759. if (0 == msel)
  760. msel = 64;
  761. cached_vco = CONFIG_CLKIN_HZ;
  762. cached_vco >>= (1 & pll_ctl); /* DF bit */
  763. cached_vco *= msel;
  764. return cached_vco;
  765. }
  766. /* Get the Core clock */
  767. static u_long cached_cclk_pll_div, cached_cclk;
  768. u_long get_cclk(void)
  769. {
  770. u_long csel, ssel;
  771. if (bfin_read_PLL_STAT() & 0x1)
  772. return CONFIG_CLKIN_HZ;
  773. ssel = bfin_read_PLL_DIV();
  774. if (ssel == cached_cclk_pll_div)
  775. return cached_cclk;
  776. else
  777. cached_cclk_pll_div = ssel;
  778. csel = ((ssel >> 4) & 0x03);
  779. ssel &= 0xf;
  780. if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
  781. cached_cclk = get_vco() / ssel;
  782. else
  783. cached_cclk = get_vco() >> csel;
  784. return cached_cclk;
  785. }
  786. EXPORT_SYMBOL(get_cclk);
  787. /* Get the System clock */
  788. static u_long cached_sclk_pll_div, cached_sclk;
  789. u_long get_sclk(void)
  790. {
  791. u_long ssel;
  792. if (bfin_read_PLL_STAT() & 0x1)
  793. return CONFIG_CLKIN_HZ;
  794. ssel = bfin_read_PLL_DIV();
  795. if (ssel == cached_sclk_pll_div)
  796. return cached_sclk;
  797. else
  798. cached_sclk_pll_div = ssel;
  799. ssel &= 0xf;
  800. if (0 == ssel) {
  801. printk(KERN_WARNING "Invalid System Clock\n");
  802. ssel = 1;
  803. }
  804. cached_sclk = get_vco() / ssel;
  805. return cached_sclk;
  806. }
  807. EXPORT_SYMBOL(get_sclk);
  808. unsigned long sclk_to_usecs(unsigned long sclk)
  809. {
  810. u64 tmp = USEC_PER_SEC * (u64)sclk;
  811. do_div(tmp, get_sclk());
  812. return tmp;
  813. }
  814. EXPORT_SYMBOL(sclk_to_usecs);
  815. unsigned long usecs_to_sclk(unsigned long usecs)
  816. {
  817. u64 tmp = get_sclk() * (u64)usecs;
  818. do_div(tmp, USEC_PER_SEC);
  819. return tmp;
  820. }
  821. EXPORT_SYMBOL(usecs_to_sclk);
  822. /*
  823. * Get CPU information for use by the procfs.
  824. */
  825. static int show_cpuinfo(struct seq_file *m, void *v)
  826. {
  827. char *cpu, *mmu, *fpu, *vendor, *cache;
  828. uint32_t revid;
  829. u_long cclk = 0, sclk = 0;
  830. u_int icache_size = BFIN_ICACHESIZE / 1024, dcache_size = 0, dsup_banks = 0;
  831. cpu = CPU;
  832. mmu = "none";
  833. fpu = "none";
  834. revid = bfin_revid();
  835. cclk = get_cclk();
  836. sclk = get_sclk();
  837. switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
  838. case 0xca:
  839. vendor = "Analog Devices";
  840. break;
  841. default:
  842. vendor = "unknown";
  843. break;
  844. }
  845. seq_printf(m, "processor\t: %d\n"
  846. "vendor_id\t: %s\n"
  847. "cpu family\t: 0x%x\n"
  848. "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
  849. "stepping\t: %d\n",
  850. 0,
  851. vendor,
  852. (bfin_read_CHIPID() & CHIPID_FAMILY),
  853. cpu, cclk/1000000, sclk/1000000,
  854. #ifdef CONFIG_MPU
  855. "mpu on",
  856. #else
  857. "mpu off",
  858. #endif
  859. revid);
  860. seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
  861. cclk/1000000, cclk%1000000,
  862. sclk/1000000, sclk%1000000);
  863. seq_printf(m, "bogomips\t: %lu.%02lu\n"
  864. "Calibration\t: %lu loops\n",
  865. (loops_per_jiffy * HZ) / 500000,
  866. ((loops_per_jiffy * HZ) / 5000) % 100,
  867. (loops_per_jiffy * HZ));
  868. /* Check Cache configutation */
  869. switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
  870. case ACACHE_BSRAM:
  871. cache = "dbank-A/B\t: cache/sram";
  872. dcache_size = 16;
  873. dsup_banks = 1;
  874. break;
  875. case ACACHE_BCACHE:
  876. cache = "dbank-A/B\t: cache/cache";
  877. dcache_size = 32;
  878. dsup_banks = 2;
  879. break;
  880. case ASRAM_BSRAM:
  881. cache = "dbank-A/B\t: sram/sram";
  882. dcache_size = 0;
  883. dsup_banks = 0;
  884. break;
  885. default:
  886. cache = "unknown";
  887. dcache_size = 0;
  888. dsup_banks = 0;
  889. break;
  890. }
  891. /* Is it turned on? */
  892. if ((bfin_read_DMEM_CONTROL() & (ENDCPLB | DMC_ENABLE)) != (ENDCPLB | DMC_ENABLE))
  893. dcache_size = 0;
  894. if ((bfin_read_IMEM_CONTROL() & (IMC | ENICPLB)) == (IMC | ENICPLB))
  895. icache_size = 0;
  896. seq_printf(m, "cache size\t: %d KB(L1 icache) "
  897. "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
  898. icache_size, dcache_size,
  899. #if defined CONFIG_BFIN_WB
  900. "wb"
  901. #elif defined CONFIG_BFIN_WT
  902. "wt"
  903. #endif
  904. "", 0);
  905. seq_printf(m, "%s\n", cache);
  906. if (icache_size)
  907. seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
  908. BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
  909. else
  910. seq_printf(m, "icache setup\t: off\n");
  911. seq_printf(m,
  912. "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
  913. dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
  914. BFIN_DLINES);
  915. #ifdef CONFIG_BFIN_ICACHE_LOCK
  916. switch (read_iloc()) {
  917. case WAY0_L:
  918. seq_printf(m, "Way0 Locked-Down\n");
  919. break;
  920. case WAY1_L:
  921. seq_printf(m, "Way1 Locked-Down\n");
  922. break;
  923. case WAY01_L:
  924. seq_printf(m, "Way0,Way1 Locked-Down\n");
  925. break;
  926. case WAY2_L:
  927. seq_printf(m, "Way2 Locked-Down\n");
  928. break;
  929. case WAY02_L:
  930. seq_printf(m, "Way0,Way2 Locked-Down\n");
  931. break;
  932. case WAY12_L:
  933. seq_printf(m, "Way1,Way2 Locked-Down\n");
  934. break;
  935. case WAY012_L:
  936. seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
  937. break;
  938. case WAY3_L:
  939. seq_printf(m, "Way3 Locked-Down\n");
  940. break;
  941. case WAY03_L:
  942. seq_printf(m, "Way0,Way3 Locked-Down\n");
  943. break;
  944. case WAY13_L:
  945. seq_printf(m, "Way1,Way3 Locked-Down\n");
  946. break;
  947. case WAY013_L:
  948. seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
  949. break;
  950. case WAY32_L:
  951. seq_printf(m, "Way3,Way2 Locked-Down\n");
  952. break;
  953. case WAY320_L:
  954. seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
  955. break;
  956. case WAY321_L:
  957. seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
  958. break;
  959. case WAYALL_L:
  960. seq_printf(m, "All Ways are locked\n");
  961. break;
  962. default:
  963. seq_printf(m, "No Ways are locked\n");
  964. }
  965. #endif
  966. seq_printf(m, "board name\t: %s\n", bfin_board_name);
  967. seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
  968. physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
  969. seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
  970. ((int)memory_end - (int)_stext) >> 10,
  971. _stext,
  972. (void *)memory_end);
  973. return 0;
  974. }
  975. static void *c_start(struct seq_file *m, loff_t *pos)
  976. {
  977. return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
  978. }
  979. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  980. {
  981. ++*pos;
  982. return c_start(m, pos);
  983. }
  984. static void c_stop(struct seq_file *m, void *v)
  985. {
  986. }
  987. const struct seq_operations cpuinfo_op = {
  988. .start = c_start,
  989. .next = c_next,
  990. .stop = c_stop,
  991. .show = show_cpuinfo,
  992. };
  993. void __init cmdline_init(const char *r0)
  994. {
  995. if (r0)
  996. strncpy(command_line, r0, COMMAND_LINE_SIZE);
  997. }