setup.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  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. switch (bfin_read_EBIU_DDRCTL1() & 0xc0000) {
  607. case DEVSZ_64: return 64;
  608. case DEVSZ_128: return 128;
  609. case DEVSZ_256: return 256;
  610. case DEVSZ_512: return 512;
  611. default: return 0;
  612. }
  613. # endif
  614. #endif
  615. BUG();
  616. }
  617. void __init setup_arch(char **cmdline_p)
  618. {
  619. unsigned long sclk, cclk;
  620. #ifdef CONFIG_DUMMY_CONSOLE
  621. conswitchp = &dummy_con;
  622. #endif
  623. #if defined(CONFIG_CMDLINE_BOOL)
  624. strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
  625. command_line[sizeof(command_line) - 1] = 0;
  626. #endif
  627. /* Keep a copy of command line */
  628. *cmdline_p = &command_line[0];
  629. memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  630. boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
  631. /* setup memory defaults from the user config */
  632. physical_mem_end = 0;
  633. _ramend = get_mem_size() * 1024 * 1024;
  634. memset(&bfin_memmap, 0, sizeof(bfin_memmap));
  635. parse_cmdline_early(&command_line[0]);
  636. if (physical_mem_end == 0)
  637. physical_mem_end = _ramend;
  638. memory_setup();
  639. cclk = get_cclk();
  640. sclk = get_sclk();
  641. #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
  642. if (ANOMALY_05000273 && cclk == sclk)
  643. panic("ANOMALY 05000273, SCLK can not be same as CCLK");
  644. #endif
  645. #ifdef BF561_FAMILY
  646. if (ANOMALY_05000266) {
  647. bfin_read_IMDMA_D0_IRQ_STATUS();
  648. bfin_read_IMDMA_D1_IRQ_STATUS();
  649. }
  650. #endif
  651. printk(KERN_INFO "Hardware Trace ");
  652. if (bfin_read_TBUFCTL() & 0x1)
  653. printk("Active ");
  654. else
  655. printk("Off ");
  656. if (bfin_read_TBUFCTL() & 0x2)
  657. printk("and Enabled\n");
  658. else
  659. printk("and Disabled\n");
  660. #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
  661. /* we need to initialize the Flashrom device here since we might
  662. * do things with flash early on in the boot
  663. */
  664. flash_probe();
  665. #endif
  666. _bfin_swrst = bfin_read_SWRST();
  667. if (_bfin_swrst & RESET_DOUBLE)
  668. printk(KERN_INFO "Recovering from Double Fault event\n");
  669. else if (_bfin_swrst & RESET_WDOG)
  670. printk(KERN_INFO "Recovering from Watchdog event\n");
  671. else if (_bfin_swrst & RESET_SOFTWARE)
  672. printk(KERN_NOTICE "Reset caused by Software reset\n");
  673. printk(KERN_INFO "Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
  674. if (bfin_compiled_revid() == 0xffff)
  675. printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
  676. else if (bfin_compiled_revid() == -1)
  677. printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
  678. else
  679. printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
  680. if (bfin_revid() != bfin_compiled_revid()) {
  681. if (bfin_compiled_revid() == -1)
  682. printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
  683. bfin_revid());
  684. else if (bfin_compiled_revid() != 0xffff)
  685. printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
  686. bfin_compiled_revid(), bfin_revid());
  687. }
  688. if (bfin_revid() < SUPPORTED_REVID)
  689. printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
  690. CPU, bfin_revid());
  691. printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
  692. printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
  693. cclk / 1000000, sclk / 1000000);
  694. if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
  695. printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
  696. setup_bootmem_allocator();
  697. paging_init();
  698. /* Copy atomic sequences to their fixed location, and sanity check that
  699. these locations are the ones that we advertise to userspace. */
  700. memcpy((void *)FIXED_CODE_START, &fixed_code_start,
  701. FIXED_CODE_END - FIXED_CODE_START);
  702. BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
  703. != SIGRETURN_STUB - FIXED_CODE_START);
  704. BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
  705. != ATOMIC_XCHG32 - FIXED_CODE_START);
  706. BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
  707. != ATOMIC_CAS32 - FIXED_CODE_START);
  708. BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
  709. != ATOMIC_ADD32 - FIXED_CODE_START);
  710. BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
  711. != ATOMIC_SUB32 - FIXED_CODE_START);
  712. BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
  713. != ATOMIC_IOR32 - FIXED_CODE_START);
  714. BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
  715. != ATOMIC_AND32 - FIXED_CODE_START);
  716. BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
  717. != ATOMIC_XOR32 - FIXED_CODE_START);
  718. BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
  719. != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
  720. init_exception_vectors();
  721. bf53x_cache_init();
  722. }
  723. static int __init topology_init(void)
  724. {
  725. int cpu;
  726. for_each_possible_cpu(cpu) {
  727. struct cpu *c = &per_cpu(cpu_devices, cpu);
  728. register_cpu(c, cpu);
  729. }
  730. return 0;
  731. }
  732. subsys_initcall(topology_init);
  733. static u_long get_vco(void)
  734. {
  735. u_long msel;
  736. u_long vco;
  737. msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
  738. if (0 == msel)
  739. msel = 64;
  740. vco = CONFIG_CLKIN_HZ;
  741. vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
  742. vco = msel * vco;
  743. return vco;
  744. }
  745. /* Get the Core clock */
  746. u_long get_cclk(void)
  747. {
  748. u_long csel, ssel;
  749. if (bfin_read_PLL_STAT() & 0x1)
  750. return CONFIG_CLKIN_HZ;
  751. ssel = bfin_read_PLL_DIV();
  752. csel = ((ssel >> 4) & 0x03);
  753. ssel &= 0xf;
  754. if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
  755. return get_vco() / ssel;
  756. return get_vco() >> csel;
  757. }
  758. EXPORT_SYMBOL(get_cclk);
  759. /* Get the System clock */
  760. u_long get_sclk(void)
  761. {
  762. u_long ssel;
  763. if (bfin_read_PLL_STAT() & 0x1)
  764. return CONFIG_CLKIN_HZ;
  765. ssel = (bfin_read_PLL_DIV() & 0xf);
  766. if (0 == ssel) {
  767. printk(KERN_WARNING "Invalid System Clock\n");
  768. ssel = 1;
  769. }
  770. return get_vco() / ssel;
  771. }
  772. EXPORT_SYMBOL(get_sclk);
  773. unsigned long sclk_to_usecs(unsigned long sclk)
  774. {
  775. u64 tmp = USEC_PER_SEC * (u64)sclk;
  776. do_div(tmp, get_sclk());
  777. return tmp;
  778. }
  779. EXPORT_SYMBOL(sclk_to_usecs);
  780. unsigned long usecs_to_sclk(unsigned long usecs)
  781. {
  782. u64 tmp = get_sclk() * (u64)usecs;
  783. do_div(tmp, USEC_PER_SEC);
  784. return tmp;
  785. }
  786. EXPORT_SYMBOL(usecs_to_sclk);
  787. /*
  788. * Get CPU information for use by the procfs.
  789. */
  790. static int show_cpuinfo(struct seq_file *m, void *v)
  791. {
  792. char *cpu, *mmu, *fpu, *vendor, *cache;
  793. uint32_t revid;
  794. u_long cclk = 0, sclk = 0;
  795. u_int dcache_size = 0, dsup_banks = 0;
  796. cpu = CPU;
  797. mmu = "none";
  798. fpu = "none";
  799. revid = bfin_revid();
  800. cclk = get_cclk();
  801. sclk = get_sclk();
  802. switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
  803. case 0xca:
  804. vendor = "Analog Devices";
  805. break;
  806. default:
  807. vendor = "unknown";
  808. break;
  809. }
  810. seq_printf(m, "processor\t: %d\n"
  811. "vendor_id\t: %s\n"
  812. "cpu family\t: 0x%x\n"
  813. "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
  814. "stepping\t: %d\n",
  815. 0,
  816. vendor,
  817. (bfin_read_CHIPID() & CHIPID_FAMILY),
  818. cpu, cclk/1000000, sclk/1000000,
  819. #ifdef CONFIG_MPU
  820. "mpu on",
  821. #else
  822. "mpu off",
  823. #endif
  824. revid);
  825. seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
  826. cclk/1000000, cclk%1000000,
  827. sclk/1000000, sclk%1000000);
  828. seq_printf(m, "bogomips\t: %lu.%02lu\n"
  829. "Calibration\t: %lu loops\n",
  830. (loops_per_jiffy * HZ) / 500000,
  831. ((loops_per_jiffy * HZ) / 5000) % 100,
  832. (loops_per_jiffy * HZ));
  833. /* Check Cache configutation */
  834. switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
  835. case ACACHE_BSRAM:
  836. cache = "dbank-A/B\t: cache/sram";
  837. dcache_size = 16;
  838. dsup_banks = 1;
  839. break;
  840. case ACACHE_BCACHE:
  841. cache = "dbank-A/B\t: cache/cache";
  842. dcache_size = 32;
  843. dsup_banks = 2;
  844. break;
  845. case ASRAM_BSRAM:
  846. cache = "dbank-A/B\t: sram/sram";
  847. dcache_size = 0;
  848. dsup_banks = 0;
  849. break;
  850. default:
  851. cache = "unknown";
  852. dcache_size = 0;
  853. dsup_banks = 0;
  854. break;
  855. }
  856. /* Is it turned on? */
  857. if (!((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE)))
  858. dcache_size = 0;
  859. seq_printf(m, "cache size\t: %d KB(L1 icache) "
  860. "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
  861. BFIN_ICACHESIZE / 1024, dcache_size,
  862. #if defined CONFIG_BFIN_WB
  863. "wb"
  864. #elif defined CONFIG_BFIN_WT
  865. "wt"
  866. #endif
  867. "", 0);
  868. seq_printf(m, "%s\n", cache);
  869. seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
  870. BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
  871. seq_printf(m,
  872. "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
  873. dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
  874. BFIN_DLINES);
  875. #ifdef CONFIG_BFIN_ICACHE_LOCK
  876. switch (read_iloc()) {
  877. case WAY0_L:
  878. seq_printf(m, "Way0 Locked-Down\n");
  879. break;
  880. case WAY1_L:
  881. seq_printf(m, "Way1 Locked-Down\n");
  882. break;
  883. case WAY01_L:
  884. seq_printf(m, "Way0,Way1 Locked-Down\n");
  885. break;
  886. case WAY2_L:
  887. seq_printf(m, "Way2 Locked-Down\n");
  888. break;
  889. case WAY02_L:
  890. seq_printf(m, "Way0,Way2 Locked-Down\n");
  891. break;
  892. case WAY12_L:
  893. seq_printf(m, "Way1,Way2 Locked-Down\n");
  894. break;
  895. case WAY012_L:
  896. seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
  897. break;
  898. case WAY3_L:
  899. seq_printf(m, "Way3 Locked-Down\n");
  900. break;
  901. case WAY03_L:
  902. seq_printf(m, "Way0,Way3 Locked-Down\n");
  903. break;
  904. case WAY13_L:
  905. seq_printf(m, "Way1,Way3 Locked-Down\n");
  906. break;
  907. case WAY013_L:
  908. seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
  909. break;
  910. case WAY32_L:
  911. seq_printf(m, "Way3,Way2 Locked-Down\n");
  912. break;
  913. case WAY320_L:
  914. seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
  915. break;
  916. case WAY321_L:
  917. seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
  918. break;
  919. case WAYALL_L:
  920. seq_printf(m, "All Ways are locked\n");
  921. break;
  922. default:
  923. seq_printf(m, "No Ways are locked\n");
  924. }
  925. #endif
  926. seq_printf(m, "board name\t: %s\n", bfin_board_name);
  927. seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
  928. physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
  929. seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
  930. ((int)memory_end - (int)_stext) >> 10,
  931. _stext,
  932. (void *)memory_end);
  933. return 0;
  934. }
  935. static void *c_start(struct seq_file *m, loff_t *pos)
  936. {
  937. return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
  938. }
  939. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  940. {
  941. ++*pos;
  942. return c_start(m, pos);
  943. }
  944. static void c_stop(struct seq_file *m, void *v)
  945. {
  946. }
  947. const struct seq_operations cpuinfo_op = {
  948. .start = c_start,
  949. .next = c_next,
  950. .stop = c_stop,
  951. .show = show_cpuinfo,
  952. };
  953. void __init cmdline_init(const char *r0)
  954. {
  955. if (r0)
  956. strncpy(command_line, r0, COMMAND_LINE_SIZE);
  957. }