setup.c 29 KB

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