setup.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2004-2007 Cavium Networks
  7. * Copyright (C) 2008, 2009 Wind River Systems
  8. * written by Ralf Baechle <[email protected]>
  9. */
  10. #include <linux/compiler.h>
  11. #include <linux/vmalloc.h>
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/console.h>
  15. #include <linux/delay.h>
  16. #include <linux/export.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/io.h>
  19. #include <linux/memblock.h>
  20. #include <linux/serial.h>
  21. #include <linux/smp.h>
  22. #include <linux/types.h>
  23. #include <linux/string.h> /* for memset */
  24. #include <linux/tty.h>
  25. #include <linux/time.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/serial_core.h>
  28. #include <linux/serial_8250.h>
  29. #include <linux/of_fdt.h>
  30. #include <linux/libfdt.h>
  31. #include <linux/kexec.h>
  32. #include <asm/processor.h>
  33. #include <asm/reboot.h>
  34. #include <asm/smp-ops.h>
  35. #include <asm/irq_cpu.h>
  36. #include <asm/mipsregs.h>
  37. #include <asm/bootinfo.h>
  38. #include <asm/sections.h>
  39. #include <asm/fw/fw.h>
  40. #include <asm/setup.h>
  41. #include <asm/prom.h>
  42. #include <asm/time.h>
  43. #include <asm/octeon/octeon.h>
  44. #include <asm/octeon/pci-octeon.h>
  45. #include <asm/octeon/cvmx-rst-defs.h>
  46. /*
  47. * TRUE for devices having registers with little-endian byte
  48. * order, FALSE for registers with native-endian byte order.
  49. * PCI mandates little-endian, USB and SATA are configuraable,
  50. * but we chose little-endian for these.
  51. */
  52. const bool octeon_should_swizzle_table[256] = {
  53. [0x00] = true, /* bootbus/CF */
  54. [0x1b] = true, /* PCI mmio window */
  55. [0x1c] = true, /* PCI mmio window */
  56. [0x1d] = true, /* PCI mmio window */
  57. [0x1e] = true, /* PCI mmio window */
  58. [0x68] = true, /* OCTEON III USB */
  59. [0x69] = true, /* OCTEON III USB */
  60. [0x6c] = true, /* OCTEON III SATA */
  61. [0x6f] = true, /* OCTEON II USB */
  62. };
  63. EXPORT_SYMBOL(octeon_should_swizzle_table);
  64. #ifdef CONFIG_PCI
  65. extern void pci_console_init(const char *arg);
  66. #endif
  67. static unsigned long long max_memory = ULLONG_MAX;
  68. static unsigned long long reserve_low_mem;
  69. DEFINE_SEMAPHORE(octeon_bootbus_sem);
  70. EXPORT_SYMBOL(octeon_bootbus_sem);
  71. static struct octeon_boot_descriptor *octeon_boot_desc_ptr;
  72. struct cvmx_bootinfo *octeon_bootinfo;
  73. EXPORT_SYMBOL(octeon_bootinfo);
  74. #ifdef CONFIG_KEXEC
  75. #ifdef CONFIG_SMP
  76. /*
  77. * Wait for relocation code is prepared and send
  78. * secondary CPUs to spin until kernel is relocated.
  79. */
  80. static void octeon_kexec_smp_down(void *ignored)
  81. {
  82. int cpu = smp_processor_id();
  83. local_irq_disable();
  84. set_cpu_online(cpu, false);
  85. while (!atomic_read(&kexec_ready_to_reboot))
  86. cpu_relax();
  87. asm volatile (
  88. " sync \n"
  89. " synci ($0) \n");
  90. kexec_reboot();
  91. }
  92. #endif
  93. #define OCTEON_DDR0_BASE (0x0ULL)
  94. #define OCTEON_DDR0_SIZE (0x010000000ULL)
  95. #define OCTEON_DDR1_BASE (0x410000000ULL)
  96. #define OCTEON_DDR1_SIZE (0x010000000ULL)
  97. #define OCTEON_DDR2_BASE (0x020000000ULL)
  98. #define OCTEON_DDR2_SIZE (0x3e0000000ULL)
  99. #define OCTEON_MAX_PHY_MEM_SIZE (16*1024*1024*1024ULL)
  100. static struct kimage *kimage_ptr;
  101. static void kexec_bootmem_init(uint64_t mem_size, uint32_t low_reserved_bytes)
  102. {
  103. int64_t addr;
  104. struct cvmx_bootmem_desc *bootmem_desc;
  105. bootmem_desc = cvmx_bootmem_get_desc();
  106. if (mem_size > OCTEON_MAX_PHY_MEM_SIZE) {
  107. mem_size = OCTEON_MAX_PHY_MEM_SIZE;
  108. pr_err("Error: requested memory too large,"
  109. "truncating to maximum size\n");
  110. }
  111. bootmem_desc->major_version = CVMX_BOOTMEM_DESC_MAJ_VER;
  112. bootmem_desc->minor_version = CVMX_BOOTMEM_DESC_MIN_VER;
  113. addr = (OCTEON_DDR0_BASE + reserve_low_mem + low_reserved_bytes);
  114. bootmem_desc->head_addr = 0;
  115. if (mem_size <= OCTEON_DDR0_SIZE) {
  116. __cvmx_bootmem_phy_free(addr,
  117. mem_size - reserve_low_mem -
  118. low_reserved_bytes, 0);
  119. return;
  120. }
  121. __cvmx_bootmem_phy_free(addr,
  122. OCTEON_DDR0_SIZE - reserve_low_mem -
  123. low_reserved_bytes, 0);
  124. mem_size -= OCTEON_DDR0_SIZE;
  125. if (mem_size > OCTEON_DDR1_SIZE) {
  126. __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, OCTEON_DDR1_SIZE, 0);
  127. __cvmx_bootmem_phy_free(OCTEON_DDR2_BASE,
  128. mem_size - OCTEON_DDR1_SIZE, 0);
  129. } else
  130. __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, mem_size, 0);
  131. }
  132. static int octeon_kexec_prepare(struct kimage *image)
  133. {
  134. int i;
  135. char *bootloader = "kexec";
  136. octeon_boot_desc_ptr->argc = 0;
  137. for (i = 0; i < image->nr_segments; i++) {
  138. if (!strncmp(bootloader, (char *)image->segment[i].buf,
  139. strlen(bootloader))) {
  140. /*
  141. * convert command line string to array
  142. * of parameters (as bootloader does).
  143. */
  144. int argc = 0, offt;
  145. char *str = (char *)image->segment[i].buf;
  146. char *ptr = strchr(str, ' ');
  147. while (ptr && (OCTEON_ARGV_MAX_ARGS > argc)) {
  148. *ptr = '\0';
  149. if (ptr[1] != ' ') {
  150. offt = (int)(ptr - str + 1);
  151. octeon_boot_desc_ptr->argv[argc] =
  152. image->segment[i].mem + offt;
  153. argc++;
  154. }
  155. ptr = strchr(ptr + 1, ' ');
  156. }
  157. octeon_boot_desc_ptr->argc = argc;
  158. break;
  159. }
  160. }
  161. /*
  162. * Information about segments will be needed during pre-boot memory
  163. * initialization.
  164. */
  165. kimage_ptr = image;
  166. return 0;
  167. }
  168. static void octeon_generic_shutdown(void)
  169. {
  170. int i;
  171. #ifdef CONFIG_SMP
  172. int cpu;
  173. #endif
  174. struct cvmx_bootmem_desc *bootmem_desc;
  175. void *named_block_array_ptr;
  176. bootmem_desc = cvmx_bootmem_get_desc();
  177. named_block_array_ptr =
  178. cvmx_phys_to_ptr(bootmem_desc->named_block_array_addr);
  179. #ifdef CONFIG_SMP
  180. /* disable watchdogs */
  181. for_each_online_cpu(cpu)
  182. cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
  183. #else
  184. cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
  185. #endif
  186. if (kimage_ptr != kexec_crash_image) {
  187. memset(named_block_array_ptr,
  188. 0x0,
  189. CVMX_BOOTMEM_NUM_NAMED_BLOCKS *
  190. sizeof(struct cvmx_bootmem_named_block_desc));
  191. /*
  192. * Mark all memory (except low 0x100000 bytes) as free.
  193. * It is the same thing that bootloader does.
  194. */
  195. kexec_bootmem_init(octeon_bootinfo->dram_size*1024ULL*1024ULL,
  196. 0x100000);
  197. /*
  198. * Allocate all segments to avoid their corruption during boot.
  199. */
  200. for (i = 0; i < kimage_ptr->nr_segments; i++)
  201. cvmx_bootmem_alloc_address(
  202. kimage_ptr->segment[i].memsz + 2*PAGE_SIZE,
  203. kimage_ptr->segment[i].mem - PAGE_SIZE,
  204. PAGE_SIZE);
  205. } else {
  206. /*
  207. * Do not mark all memory as free. Free only named sections
  208. * leaving the rest of memory unchanged.
  209. */
  210. struct cvmx_bootmem_named_block_desc *ptr =
  211. (struct cvmx_bootmem_named_block_desc *)
  212. named_block_array_ptr;
  213. for (i = 0; i < bootmem_desc->named_block_num_blocks; i++)
  214. if (ptr[i].size)
  215. cvmx_bootmem_free_named(ptr[i].name);
  216. }
  217. kexec_args[2] = 1UL; /* running on octeon_main_processor */
  218. kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
  219. #ifdef CONFIG_SMP
  220. secondary_kexec_args[2] = 0UL; /* running on secondary cpu */
  221. secondary_kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
  222. #endif
  223. }
  224. static void octeon_shutdown(void)
  225. {
  226. octeon_generic_shutdown();
  227. #ifdef CONFIG_SMP
  228. smp_call_function(octeon_kexec_smp_down, NULL, 0);
  229. smp_wmb();
  230. while (num_online_cpus() > 1) {
  231. cpu_relax();
  232. mdelay(1);
  233. }
  234. #endif
  235. }
  236. static void octeon_crash_shutdown(struct pt_regs *regs)
  237. {
  238. octeon_generic_shutdown();
  239. default_machine_crash_shutdown(regs);
  240. }
  241. #ifdef CONFIG_SMP
  242. void octeon_crash_smp_send_stop(void)
  243. {
  244. int cpu;
  245. /* disable watchdogs */
  246. for_each_online_cpu(cpu)
  247. cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
  248. }
  249. #endif
  250. #endif /* CONFIG_KEXEC */
  251. uint64_t octeon_reserve32_memory;
  252. EXPORT_SYMBOL(octeon_reserve32_memory);
  253. #ifdef CONFIG_KEXEC
  254. /* crashkernel cmdline parameter is parsed _after_ memory setup
  255. * we also parse it here (workaround for EHB5200) */
  256. static uint64_t crashk_size, crashk_base;
  257. #endif
  258. static int octeon_uart;
  259. extern asmlinkage void handle_int(void);
  260. /**
  261. * octeon_is_simulation - Return non-zero if we are currently running
  262. * in the Octeon simulator
  263. *
  264. * Return: non-0 if running in the Octeon simulator, 0 otherwise
  265. */
  266. int octeon_is_simulation(void)
  267. {
  268. return octeon_bootinfo->board_type == CVMX_BOARD_TYPE_SIM;
  269. }
  270. EXPORT_SYMBOL(octeon_is_simulation);
  271. /**
  272. * octeon_is_pci_host - Return true if Octeon is in PCI Host mode. This means
  273. * Linux can control the PCI bus.
  274. *
  275. * Return: Non-zero if Octeon is in host mode.
  276. */
  277. int octeon_is_pci_host(void)
  278. {
  279. #ifdef CONFIG_PCI
  280. return octeon_bootinfo->config_flags & CVMX_BOOTINFO_CFG_FLAG_PCI_HOST;
  281. #else
  282. return 0;
  283. #endif
  284. }
  285. /**
  286. * octeon_get_clock_rate - Get the clock rate of Octeon
  287. *
  288. * Return: Clock rate in HZ
  289. */
  290. uint64_t octeon_get_clock_rate(void)
  291. {
  292. struct cvmx_sysinfo *sysinfo = cvmx_sysinfo_get();
  293. return sysinfo->cpu_clock_hz;
  294. }
  295. EXPORT_SYMBOL(octeon_get_clock_rate);
  296. static u64 octeon_io_clock_rate;
  297. u64 octeon_get_io_clock_rate(void)
  298. {
  299. return octeon_io_clock_rate;
  300. }
  301. EXPORT_SYMBOL(octeon_get_io_clock_rate);
  302. /**
  303. * octeon_write_lcd - Write to the LCD display connected to the bootbus.
  304. * @s: String to write
  305. *
  306. * This display exists on most Cavium evaluation boards. If it doesn't exist,
  307. * then this function doesn't do anything.
  308. */
  309. static void octeon_write_lcd(const char *s)
  310. {
  311. if (octeon_bootinfo->led_display_base_addr) {
  312. void __iomem *lcd_address =
  313. ioremap(octeon_bootinfo->led_display_base_addr,
  314. 8);
  315. int i;
  316. for (i = 0; i < 8; i++, s++) {
  317. if (*s)
  318. iowrite8(*s, lcd_address + i);
  319. else
  320. iowrite8(' ', lcd_address + i);
  321. }
  322. iounmap(lcd_address);
  323. }
  324. }
  325. /**
  326. * octeon_get_boot_uart - Return the console uart passed by the bootloader
  327. *
  328. * Return: uart number (0 or 1)
  329. */
  330. static int octeon_get_boot_uart(void)
  331. {
  332. return (octeon_boot_desc_ptr->flags & OCTEON_BL_FLAG_CONSOLE_UART1) ?
  333. 1 : 0;
  334. }
  335. /**
  336. * octeon_get_boot_coremask - Get the coremask Linux was booted on.
  337. *
  338. * Return: Core mask
  339. */
  340. int octeon_get_boot_coremask(void)
  341. {
  342. return octeon_boot_desc_ptr->core_mask;
  343. }
  344. /**
  345. * octeon_check_cpu_bist - Check the hardware BIST results for a CPU
  346. */
  347. void octeon_check_cpu_bist(void)
  348. {
  349. const int coreid = cvmx_get_core_num();
  350. unsigned long long mask;
  351. unsigned long long bist_val;
  352. /* Check BIST results for COP0 registers */
  353. mask = 0x1f00000000ull;
  354. bist_val = read_octeon_c0_icacheerr();
  355. if (bist_val & mask)
  356. pr_err("Core%d BIST Failure: CacheErr(icache) = 0x%llx\n",
  357. coreid, bist_val);
  358. bist_val = read_octeon_c0_dcacheerr();
  359. if (bist_val & 1)
  360. pr_err("Core%d L1 Dcache parity error: "
  361. "CacheErr(dcache) = 0x%llx\n",
  362. coreid, bist_val);
  363. mask = 0xfc00000000000000ull;
  364. bist_val = read_c0_cvmmemctl();
  365. if (bist_val & mask)
  366. pr_err("Core%d BIST Failure: COP0_CVM_MEM_CTL = 0x%llx\n",
  367. coreid, bist_val);
  368. write_octeon_c0_dcacheerr(0);
  369. }
  370. /**
  371. * octeon_restart - Reboot Octeon
  372. *
  373. * @command: Command to pass to the bootloader. Currently ignored.
  374. */
  375. static void octeon_restart(char *command)
  376. {
  377. /* Disable all watchdogs before soft reset. They don't get cleared */
  378. #ifdef CONFIG_SMP
  379. int cpu;
  380. for_each_online_cpu(cpu)
  381. cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
  382. #else
  383. cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
  384. #endif
  385. mb();
  386. while (1)
  387. if (OCTEON_IS_OCTEON3())
  388. cvmx_write_csr(CVMX_RST_SOFT_RST, 1);
  389. else
  390. cvmx_write_csr(CVMX_CIU_SOFT_RST, 1);
  391. }
  392. /**
  393. * octeon_kill_core - Permanently stop a core.
  394. *
  395. * @arg: Ignored.
  396. */
  397. static void octeon_kill_core(void *arg)
  398. {
  399. if (octeon_is_simulation())
  400. /* A break instruction causes the simulator stop a core */
  401. asm volatile ("break" ::: "memory");
  402. local_irq_disable();
  403. /* Disable watchdog on this core. */
  404. cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
  405. /* Spin in a low power mode. */
  406. while (true)
  407. asm volatile ("wait" ::: "memory");
  408. }
  409. /**
  410. * octeon_halt - Halt the system
  411. */
  412. static void octeon_halt(void)
  413. {
  414. smp_call_function(octeon_kill_core, NULL, 0);
  415. switch (octeon_bootinfo->board_type) {
  416. case CVMX_BOARD_TYPE_NAO38:
  417. /* Driving a 1 to GPIO 12 shuts off this board */
  418. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
  419. cvmx_write_csr(CVMX_GPIO_TX_SET, 0x1000);
  420. break;
  421. default:
  422. octeon_write_lcd("PowerOff");
  423. break;
  424. }
  425. octeon_kill_core(NULL);
  426. }
  427. static char __read_mostly octeon_system_type[80];
  428. static void __init init_octeon_system_type(void)
  429. {
  430. char const *board_type;
  431. board_type = cvmx_board_type_to_string(octeon_bootinfo->board_type);
  432. if (board_type == NULL) {
  433. struct device_node *root;
  434. int ret;
  435. root = of_find_node_by_path("/");
  436. ret = of_property_read_string(root, "model", &board_type);
  437. of_node_put(root);
  438. if (ret)
  439. board_type = "Unsupported Board";
  440. }
  441. snprintf(octeon_system_type, sizeof(octeon_system_type), "%s (%s)",
  442. board_type, octeon_model_get_string(read_c0_prid()));
  443. }
  444. /**
  445. * octeon_board_type_string - Return a string representing the system type
  446. *
  447. * Return: system type string
  448. */
  449. const char *octeon_board_type_string(void)
  450. {
  451. return octeon_system_type;
  452. }
  453. const char *get_system_type(void)
  454. __attribute__ ((alias("octeon_board_type_string")));
  455. void octeon_user_io_init(void)
  456. {
  457. union octeon_cvmemctl cvmmemctl;
  458. /* Get the current settings for CP0_CVMMEMCTL_REG */
  459. cvmmemctl.u64 = read_c0_cvmmemctl();
  460. /* R/W If set, marked write-buffer entries time out the same
  461. * as other entries; if clear, marked write-buffer entries
  462. * use the maximum timeout. */
  463. cvmmemctl.s.dismarkwblongto = 1;
  464. /* R/W If set, a merged store does not clear the write-buffer
  465. * entry timeout state. */
  466. cvmmemctl.s.dismrgclrwbto = 0;
  467. /* R/W Two bits that are the MSBs of the resultant CVMSEG LM
  468. * word location for an IOBDMA. The other 8 bits come from the
  469. * SCRADDR field of the IOBDMA. */
  470. cvmmemctl.s.iobdmascrmsb = 0;
  471. /* R/W If set, SYNCWS and SYNCS only order marked stores; if
  472. * clear, SYNCWS and SYNCS only order unmarked
  473. * stores. SYNCWSMARKED has no effect when DISSYNCWS is
  474. * set. */
  475. cvmmemctl.s.syncwsmarked = 0;
  476. /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
  477. cvmmemctl.s.dissyncws = 0;
  478. /* R/W If set, no stall happens on write buffer full. */
  479. if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2))
  480. cvmmemctl.s.diswbfst = 1;
  481. else
  482. cvmmemctl.s.diswbfst = 0;
  483. /* R/W If set (and SX set), supervisor-level loads/stores can
  484. * use XKPHYS addresses with <48>==0 */
  485. cvmmemctl.s.xkmemenas = 0;
  486. /* R/W If set (and UX set), user-level loads/stores can use
  487. * XKPHYS addresses with VA<48>==0 */
  488. cvmmemctl.s.xkmemenau = 0;
  489. /* R/W If set (and SX set), supervisor-level loads/stores can
  490. * use XKPHYS addresses with VA<48>==1 */
  491. cvmmemctl.s.xkioenas = 0;
  492. /* R/W If set (and UX set), user-level loads/stores can use
  493. * XKPHYS addresses with VA<48>==1 */
  494. cvmmemctl.s.xkioenau = 0;
  495. /* R/W If set, all stores act as SYNCW (NOMERGE must be set
  496. * when this is set) RW, reset to 0. */
  497. cvmmemctl.s.allsyncw = 0;
  498. /* R/W If set, no stores merge, and all stores reach the
  499. * coherent bus in order. */
  500. cvmmemctl.s.nomerge = 0;
  501. /* R/W Selects the bit in the counter used for DID time-outs 0
  502. * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is
  503. * between 1x and 2x this interval. For example, with
  504. * DIDTTO=3, expiration interval is between 16K and 32K. */
  505. cvmmemctl.s.didtto = 0;
  506. /* R/W If set, the (mem) CSR clock never turns off. */
  507. cvmmemctl.s.csrckalwys = 0;
  508. /* R/W If set, mclk never turns off. */
  509. cvmmemctl.s.mclkalwys = 0;
  510. /* R/W Selects the bit in the counter used for write buffer
  511. * flush time-outs (WBFLT+11) is the bit position in an
  512. * internal counter used to determine expiration. The write
  513. * buffer expires between 1x and 2x this interval. For
  514. * example, with WBFLT = 0, a write buffer expires between 2K
  515. * and 4K cycles after the write buffer entry is allocated. */
  516. cvmmemctl.s.wbfltime = 0;
  517. /* R/W If set, do not put Istream in the L2 cache. */
  518. cvmmemctl.s.istrnol2 = 0;
  519. /*
  520. * R/W The write buffer threshold. As per erratum Core-14752
  521. * for CN63XX, a sc/scd might fail if the write buffer is
  522. * full. Lowering WBTHRESH greatly lowers the chances of the
  523. * write buffer ever being full and triggering the erratum.
  524. */
  525. if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X))
  526. cvmmemctl.s.wbthresh = 4;
  527. else
  528. cvmmemctl.s.wbthresh = 10;
  529. /* R/W If set, CVMSEG is available for loads/stores in
  530. * kernel/debug mode. */
  531. #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
  532. cvmmemctl.s.cvmsegenak = 1;
  533. #else
  534. cvmmemctl.s.cvmsegenak = 0;
  535. #endif
  536. /* R/W If set, CVMSEG is available for loads/stores in
  537. * supervisor mode. */
  538. cvmmemctl.s.cvmsegenas = 0;
  539. /* R/W If set, CVMSEG is available for loads/stores in user
  540. * mode. */
  541. cvmmemctl.s.cvmsegenau = 0;
  542. write_c0_cvmmemctl(cvmmemctl.u64);
  543. /* Setup of CVMSEG is done in kernel-entry-init.h */
  544. if (smp_processor_id() == 0)
  545. pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
  546. CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE,
  547. CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128);
  548. if (octeon_has_feature(OCTEON_FEATURE_FAU)) {
  549. union cvmx_iob_fau_timeout fau_timeout;
  550. /* Set a default for the hardware timeouts */
  551. fau_timeout.u64 = 0;
  552. fau_timeout.s.tout_val = 0xfff;
  553. /* Disable tagwait FAU timeout */
  554. fau_timeout.s.tout_enb = 0;
  555. cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT, fau_timeout.u64);
  556. }
  557. if ((!OCTEON_IS_MODEL(OCTEON_CN68XX) &&
  558. !OCTEON_IS_MODEL(OCTEON_CN7XXX)) ||
  559. OCTEON_IS_MODEL(OCTEON_CN70XX)) {
  560. union cvmx_pow_nw_tim nm_tim;
  561. nm_tim.u64 = 0;
  562. /* 4096 cycles */
  563. nm_tim.s.nw_tim = 3;
  564. cvmx_write_csr(CVMX_POW_NW_TIM, nm_tim.u64);
  565. }
  566. write_octeon_c0_icacheerr(0);
  567. write_c0_derraddr1(0);
  568. }
  569. /**
  570. * prom_init - Early entry point for arch setup
  571. */
  572. void __init prom_init(void)
  573. {
  574. struct cvmx_sysinfo *sysinfo;
  575. const char *arg;
  576. char *p;
  577. int i;
  578. u64 t;
  579. int argc;
  580. /*
  581. * The bootloader passes a pointer to the boot descriptor in
  582. * $a3, this is available as fw_arg3.
  583. */
  584. octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
  585. octeon_bootinfo =
  586. cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
  587. cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr));
  588. sysinfo = cvmx_sysinfo_get();
  589. memset(sysinfo, 0, sizeof(*sysinfo));
  590. sysinfo->system_dram_size = octeon_bootinfo->dram_size << 20;
  591. sysinfo->phy_mem_desc_addr = (u64)phys_to_virt(octeon_bootinfo->phy_mem_desc_addr);
  592. if ((octeon_bootinfo->major_version > 1) ||
  593. (octeon_bootinfo->major_version == 1 &&
  594. octeon_bootinfo->minor_version >= 4))
  595. cvmx_coremask_copy(&sysinfo->core_mask,
  596. &octeon_bootinfo->ext_core_mask);
  597. else
  598. cvmx_coremask_set64(&sysinfo->core_mask,
  599. octeon_bootinfo->core_mask);
  600. /* Some broken u-boot pass garbage in upper bits, clear them out */
  601. if (!OCTEON_IS_MODEL(OCTEON_CN78XX))
  602. for (i = 512; i < 1024; i++)
  603. cvmx_coremask_clear_core(&sysinfo->core_mask, i);
  604. sysinfo->exception_base_addr = octeon_bootinfo->exception_base_addr;
  605. sysinfo->cpu_clock_hz = octeon_bootinfo->eclock_hz;
  606. sysinfo->dram_data_rate_hz = octeon_bootinfo->dclock_hz * 2;
  607. sysinfo->board_type = octeon_bootinfo->board_type;
  608. sysinfo->board_rev_major = octeon_bootinfo->board_rev_major;
  609. sysinfo->board_rev_minor = octeon_bootinfo->board_rev_minor;
  610. memcpy(sysinfo->mac_addr_base, octeon_bootinfo->mac_addr_base,
  611. sizeof(sysinfo->mac_addr_base));
  612. sysinfo->mac_addr_count = octeon_bootinfo->mac_addr_count;
  613. memcpy(sysinfo->board_serial_number,
  614. octeon_bootinfo->board_serial_number,
  615. sizeof(sysinfo->board_serial_number));
  616. sysinfo->compact_flash_common_base_addr =
  617. octeon_bootinfo->compact_flash_common_base_addr;
  618. sysinfo->compact_flash_attribute_base_addr =
  619. octeon_bootinfo->compact_flash_attribute_base_addr;
  620. sysinfo->led_display_base_addr = octeon_bootinfo->led_display_base_addr;
  621. sysinfo->dfa_ref_clock_hz = octeon_bootinfo->dfa_ref_clock_hz;
  622. sysinfo->bootloader_config_flags = octeon_bootinfo->config_flags;
  623. if (OCTEON_IS_OCTEON2()) {
  624. /* I/O clock runs at a different rate than the CPU. */
  625. union cvmx_mio_rst_boot rst_boot;
  626. rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);
  627. octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
  628. } else if (OCTEON_IS_OCTEON3()) {
  629. /* I/O clock runs at a different rate than the CPU. */
  630. union cvmx_rst_boot rst_boot;
  631. rst_boot.u64 = cvmx_read_csr(CVMX_RST_BOOT);
  632. octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
  633. } else {
  634. octeon_io_clock_rate = sysinfo->cpu_clock_hz;
  635. }
  636. t = read_c0_cvmctl();
  637. if ((t & (1ull << 27)) == 0) {
  638. /*
  639. * Setup the multiplier save/restore code if
  640. * CvmCtl[NOMUL] clear.
  641. */
  642. void *save;
  643. void *save_end;
  644. void *restore;
  645. void *restore_end;
  646. int save_len;
  647. int restore_len;
  648. int save_max = (char *)octeon_mult_save_end -
  649. (char *)octeon_mult_save;
  650. int restore_max = (char *)octeon_mult_restore_end -
  651. (char *)octeon_mult_restore;
  652. if (current_cpu_data.cputype == CPU_CAVIUM_OCTEON3) {
  653. save = octeon_mult_save3;
  654. save_end = octeon_mult_save3_end;
  655. restore = octeon_mult_restore3;
  656. restore_end = octeon_mult_restore3_end;
  657. } else {
  658. save = octeon_mult_save2;
  659. save_end = octeon_mult_save2_end;
  660. restore = octeon_mult_restore2;
  661. restore_end = octeon_mult_restore2_end;
  662. }
  663. save_len = (char *)save_end - (char *)save;
  664. restore_len = (char *)restore_end - (char *)restore;
  665. if (!WARN_ON(save_len > save_max ||
  666. restore_len > restore_max)) {
  667. memcpy(octeon_mult_save, save, save_len);
  668. memcpy(octeon_mult_restore, restore, restore_len);
  669. }
  670. }
  671. /*
  672. * Only enable the LED controller if we're running on a CN38XX, CN58XX,
  673. * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
  674. */
  675. if (!octeon_is_simulation() &&
  676. octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER)) {
  677. cvmx_write_csr(CVMX_LED_EN, 0);
  678. cvmx_write_csr(CVMX_LED_PRT, 0);
  679. cvmx_write_csr(CVMX_LED_DBG, 0);
  680. cvmx_write_csr(CVMX_LED_PRT_FMT, 0);
  681. cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
  682. cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
  683. cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
  684. cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
  685. cvmx_write_csr(CVMX_LED_EN, 1);
  686. }
  687. /*
  688. * We need to temporarily allocate all memory in the reserve32
  689. * region. This makes sure the kernel doesn't allocate this
  690. * memory when it is getting memory from the
  691. * bootloader. Later, after the memory allocations are
  692. * complete, the reserve32 will be freed.
  693. *
  694. * Allocate memory for RESERVED32 aligned on 2MB boundary. This
  695. * is in case we later use hugetlb entries with it.
  696. */
  697. if (CONFIG_CAVIUM_RESERVE32) {
  698. int64_t addr =
  699. cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
  700. 0, 0, 2 << 20,
  701. "CAVIUM_RESERVE32", 0);
  702. if (addr < 0)
  703. pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
  704. else
  705. octeon_reserve32_memory = addr;
  706. }
  707. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
  708. if (cvmx_read_csr(CVMX_L2D_FUS3) & (3ull << 34)) {
  709. pr_info("Skipping L2 locking due to reduced L2 cache size\n");
  710. } else {
  711. uint32_t __maybe_unused ebase = read_c0_ebase() & 0x3ffff000;
  712. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB
  713. /* TLB refill */
  714. cvmx_l2c_lock_mem_region(ebase, 0x100);
  715. #endif
  716. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION
  717. /* General exception */
  718. cvmx_l2c_lock_mem_region(ebase + 0x180, 0x80);
  719. #endif
  720. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT
  721. /* Interrupt handler */
  722. cvmx_l2c_lock_mem_region(ebase + 0x200, 0x80);
  723. #endif
  724. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT
  725. cvmx_l2c_lock_mem_region(__pa_symbol(handle_int), 0x100);
  726. cvmx_l2c_lock_mem_region(__pa_symbol(plat_irq_dispatch), 0x80);
  727. #endif
  728. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY
  729. cvmx_l2c_lock_mem_region(__pa_symbol(memcpy), 0x480);
  730. #endif
  731. }
  732. #endif
  733. octeon_check_cpu_bist();
  734. octeon_uart = octeon_get_boot_uart();
  735. #ifdef CONFIG_SMP
  736. octeon_write_lcd("LinuxSMP");
  737. #else
  738. octeon_write_lcd("Linux");
  739. #endif
  740. octeon_setup_delays();
  741. /*
  742. * BIST should always be enabled when doing a soft reset. L2
  743. * Cache locking for instance is not cleared unless BIST is
  744. * enabled. Unfortunately due to a chip errata G-200 for
  745. * Cn38XX and CN31XX, BIST must be disabled on these parts.
  746. */
  747. if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
  748. OCTEON_IS_MODEL(OCTEON_CN31XX))
  749. cvmx_write_csr(CVMX_CIU_SOFT_BIST, 0);
  750. else
  751. cvmx_write_csr(CVMX_CIU_SOFT_BIST, 1);
  752. /* Default to 64MB in the simulator to speed things up */
  753. if (octeon_is_simulation())
  754. max_memory = 64ull << 20;
  755. arg = strstr(arcs_cmdline, "mem=");
  756. if (arg) {
  757. max_memory = memparse(arg + 4, &p);
  758. if (max_memory == 0)
  759. max_memory = 32ull << 30;
  760. if (*p == '@')
  761. reserve_low_mem = memparse(p + 1, &p);
  762. }
  763. arcs_cmdline[0] = 0;
  764. argc = octeon_boot_desc_ptr->argc;
  765. for (i = 0; i < argc; i++) {
  766. const char *arg =
  767. cvmx_phys_to_ptr(octeon_boot_desc_ptr->argv[i]);
  768. if ((strncmp(arg, "MEM=", 4) == 0) ||
  769. (strncmp(arg, "mem=", 4) == 0)) {
  770. max_memory = memparse(arg + 4, &p);
  771. if (max_memory == 0)
  772. max_memory = 32ull << 30;
  773. if (*p == '@')
  774. reserve_low_mem = memparse(p + 1, &p);
  775. #ifdef CONFIG_KEXEC
  776. } else if (strncmp(arg, "crashkernel=", 12) == 0) {
  777. crashk_size = memparse(arg+12, &p);
  778. if (*p == '@')
  779. crashk_base = memparse(p+1, &p);
  780. strcat(arcs_cmdline, " ");
  781. strcat(arcs_cmdline, arg);
  782. /*
  783. * To do: switch parsing to new style, something like:
  784. * parse_crashkernel(arg, sysinfo->system_dram_size,
  785. * &crashk_size, &crashk_base);
  786. */
  787. #endif
  788. } else if (strlen(arcs_cmdline) + strlen(arg) + 1 <
  789. sizeof(arcs_cmdline) - 1) {
  790. strcat(arcs_cmdline, " ");
  791. strcat(arcs_cmdline, arg);
  792. }
  793. }
  794. if (strstr(arcs_cmdline, "console=") == NULL) {
  795. if (octeon_uart == 1)
  796. strcat(arcs_cmdline, " console=ttyS1,115200");
  797. else
  798. strcat(arcs_cmdline, " console=ttyS0,115200");
  799. }
  800. mips_hpt_frequency = octeon_get_clock_rate();
  801. octeon_init_cvmcount();
  802. _machine_restart = octeon_restart;
  803. _machine_halt = octeon_halt;
  804. #ifdef CONFIG_KEXEC
  805. _machine_kexec_shutdown = octeon_shutdown;
  806. _machine_crash_shutdown = octeon_crash_shutdown;
  807. _machine_kexec_prepare = octeon_kexec_prepare;
  808. #ifdef CONFIG_SMP
  809. _crash_smp_send_stop = octeon_crash_smp_send_stop;
  810. #endif
  811. #endif
  812. octeon_user_io_init();
  813. octeon_setup_smp();
  814. }
  815. /* Exclude a single page from the regions obtained in plat_mem_setup. */
  816. #ifndef CONFIG_CRASH_DUMP
  817. static __init void memory_exclude_page(u64 addr, u64 *mem, u64 *size)
  818. {
  819. if (addr > *mem && addr < *mem + *size) {
  820. u64 inc = addr - *mem;
  821. memblock_add(*mem, inc);
  822. *mem += inc;
  823. *size -= inc;
  824. }
  825. if (addr == *mem && *size > PAGE_SIZE) {
  826. *mem += PAGE_SIZE;
  827. *size -= PAGE_SIZE;
  828. }
  829. }
  830. #endif /* CONFIG_CRASH_DUMP */
  831. void __init fw_init_cmdline(void)
  832. {
  833. int i;
  834. octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
  835. for (i = 0; i < octeon_boot_desc_ptr->argc; i++) {
  836. const char *arg =
  837. cvmx_phys_to_ptr(octeon_boot_desc_ptr->argv[i]);
  838. if (strlen(arcs_cmdline) + strlen(arg) + 1 <
  839. sizeof(arcs_cmdline) - 1) {
  840. strcat(arcs_cmdline, " ");
  841. strcat(arcs_cmdline, arg);
  842. }
  843. }
  844. }
  845. void __init *plat_get_fdt(void)
  846. {
  847. octeon_bootinfo =
  848. cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
  849. return phys_to_virt(octeon_bootinfo->fdt_addr);
  850. }
  851. void __init plat_mem_setup(void)
  852. {
  853. uint64_t mem_alloc_size;
  854. uint64_t total;
  855. uint64_t crashk_end;
  856. #ifndef CONFIG_CRASH_DUMP
  857. int64_t memory;
  858. #endif
  859. total = 0;
  860. crashk_end = 0;
  861. /*
  862. * The Mips memory init uses the first memory location for
  863. * some memory vectors. When SPARSEMEM is in use, it doesn't
  864. * verify that the size is big enough for the final
  865. * vectors. Making the smallest chuck 4MB seems to be enough
  866. * to consistently work.
  867. */
  868. mem_alloc_size = 4 << 20;
  869. if (mem_alloc_size > max_memory)
  870. mem_alloc_size = max_memory;
  871. /* Crashkernel ignores bootmem list. It relies on mem=X@Y option */
  872. #ifdef CONFIG_CRASH_DUMP
  873. memblock_add(reserve_low_mem, max_memory);
  874. total += max_memory;
  875. #else
  876. #ifdef CONFIG_KEXEC
  877. if (crashk_size > 0) {
  878. memblock_add(crashk_base, crashk_size);
  879. crashk_end = crashk_base + crashk_size;
  880. }
  881. #endif
  882. /*
  883. * When allocating memory, we want incrementing addresses,
  884. * which is handled by memblock
  885. */
  886. cvmx_bootmem_lock();
  887. while (total < max_memory) {
  888. memory = cvmx_bootmem_phy_alloc(mem_alloc_size,
  889. __pa_symbol(&_end), -1,
  890. 0x100000,
  891. CVMX_BOOTMEM_FLAG_NO_LOCKING);
  892. if (memory >= 0) {
  893. u64 size = mem_alloc_size;
  894. #ifdef CONFIG_KEXEC
  895. uint64_t end;
  896. #endif
  897. /*
  898. * exclude a page at the beginning and end of
  899. * the 256MB PCIe 'hole' so the kernel will not
  900. * try to allocate multi-page buffers that
  901. * span the discontinuity.
  902. */
  903. memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE,
  904. &memory, &size);
  905. memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE +
  906. CVMX_PCIE_BAR1_PHYS_SIZE,
  907. &memory, &size);
  908. #ifdef CONFIG_KEXEC
  909. end = memory + mem_alloc_size;
  910. /*
  911. * This function automatically merges address regions
  912. * next to each other if they are received in
  913. * incrementing order
  914. */
  915. if (memory < crashk_base && end > crashk_end) {
  916. /* region is fully in */
  917. memblock_add(memory, crashk_base - memory);
  918. total += crashk_base - memory;
  919. memblock_add(crashk_end, end - crashk_end);
  920. total += end - crashk_end;
  921. continue;
  922. }
  923. if (memory >= crashk_base && end <= crashk_end)
  924. /*
  925. * Entire memory region is within the new
  926. * kernel's memory, ignore it.
  927. */
  928. continue;
  929. if (memory > crashk_base && memory < crashk_end &&
  930. end > crashk_end) {
  931. /*
  932. * Overlap with the beginning of the region,
  933. * reserve the beginning.
  934. */
  935. mem_alloc_size -= crashk_end - memory;
  936. memory = crashk_end;
  937. } else if (memory < crashk_base && end > crashk_base &&
  938. end < crashk_end)
  939. /*
  940. * Overlap with the beginning of the region,
  941. * chop of end.
  942. */
  943. mem_alloc_size -= end - crashk_base;
  944. #endif
  945. memblock_add(memory, mem_alloc_size);
  946. total += mem_alloc_size;
  947. /* Recovering mem_alloc_size */
  948. mem_alloc_size = 4 << 20;
  949. } else {
  950. break;
  951. }
  952. }
  953. cvmx_bootmem_unlock();
  954. #endif /* CONFIG_CRASH_DUMP */
  955. /*
  956. * Now that we've allocated the kernel memory it is safe to
  957. * free the reserved region. We free it here so that builtin
  958. * drivers can use the memory.
  959. */
  960. if (octeon_reserve32_memory)
  961. cvmx_bootmem_free_named("CAVIUM_RESERVE32");
  962. if (total == 0)
  963. panic("Unable to allocate memory from "
  964. "cvmx_bootmem_phy_alloc");
  965. }
  966. /*
  967. * Emit one character to the boot UART. Exported for use by the
  968. * watchdog timer.
  969. */
  970. void prom_putchar(char c)
  971. {
  972. uint64_t lsrval;
  973. /* Spin until there is room */
  974. do {
  975. lsrval = cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart));
  976. } while ((lsrval & 0x20) == 0);
  977. /* Write the byte */
  978. cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart), c & 0xffull);
  979. }
  980. EXPORT_SYMBOL(prom_putchar);
  981. void __init prom_free_prom_memory(void)
  982. {
  983. if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
  984. /* Check for presence of Core-14449 fix. */
  985. u32 insn;
  986. u32 *foo;
  987. foo = &insn;
  988. asm volatile("# before" : : : "memory");
  989. prefetch(foo);
  990. asm volatile(
  991. ".set push\n\t"
  992. ".set noreorder\n\t"
  993. "bal 1f\n\t"
  994. "nop\n"
  995. "1:\tlw %0,-12($31)\n\t"
  996. ".set pop\n\t"
  997. : "=r" (insn) : : "$31", "memory");
  998. if ((insn >> 26) != 0x33)
  999. panic("No PREF instruction at Core-14449 probe point.");
  1000. if (((insn >> 16) & 0x1f) != 28)
  1001. panic("OCTEON II DCache prefetch workaround not in place (%04x).\n"
  1002. "Please build kernel with proper options (CONFIG_CAVIUM_CN63XXP1).",
  1003. insn);
  1004. }
  1005. }
  1006. void __init octeon_fill_mac_addresses(void);
  1007. void __init device_tree_init(void)
  1008. {
  1009. const void *fdt;
  1010. bool do_prune;
  1011. bool fill_mac;
  1012. #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
  1013. if (!fdt_check_header(&__appended_dtb)) {
  1014. fdt = &__appended_dtb;
  1015. do_prune = false;
  1016. fill_mac = true;
  1017. pr_info("Using appended Device Tree.\n");
  1018. } else
  1019. #endif
  1020. if (octeon_bootinfo->minor_version >= 3 && octeon_bootinfo->fdt_addr) {
  1021. fdt = phys_to_virt(octeon_bootinfo->fdt_addr);
  1022. if (fdt_check_header(fdt))
  1023. panic("Corrupt Device Tree passed to kernel.");
  1024. do_prune = false;
  1025. fill_mac = false;
  1026. pr_info("Using passed Device Tree.\n");
  1027. } else if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
  1028. fdt = &__dtb_octeon_68xx_begin;
  1029. do_prune = true;
  1030. fill_mac = true;
  1031. } else {
  1032. fdt = &__dtb_octeon_3xxx_begin;
  1033. do_prune = true;
  1034. fill_mac = true;
  1035. }
  1036. initial_boot_params = (void *)fdt;
  1037. if (do_prune) {
  1038. octeon_prune_device_tree();
  1039. pr_info("Using internal Device Tree.\n");
  1040. }
  1041. if (fill_mac)
  1042. octeon_fill_mac_addresses();
  1043. unflatten_and_copy_device_tree();
  1044. init_octeon_system_type();
  1045. }
  1046. static int __initdata disable_octeon_edac_p;
  1047. static int __init disable_octeon_edac(char *str)
  1048. {
  1049. disable_octeon_edac_p = 1;
  1050. return 0;
  1051. }
  1052. early_param("disable_octeon_edac", disable_octeon_edac);
  1053. static char *edac_device_names[] = {
  1054. "octeon_l2c_edac",
  1055. "octeon_pc_edac",
  1056. };
  1057. static int __init edac_devinit(void)
  1058. {
  1059. struct platform_device *dev;
  1060. int i, err = 0;
  1061. int num_lmc;
  1062. char *name;
  1063. if (disable_octeon_edac_p)
  1064. return 0;
  1065. for (i = 0; i < ARRAY_SIZE(edac_device_names); i++) {
  1066. name = edac_device_names[i];
  1067. dev = platform_device_register_simple(name, -1, NULL, 0);
  1068. if (IS_ERR(dev)) {
  1069. pr_err("Registration of %s failed!\n", name);
  1070. err = PTR_ERR(dev);
  1071. }
  1072. }
  1073. num_lmc = OCTEON_IS_MODEL(OCTEON_CN68XX) ? 4 :
  1074. (OCTEON_IS_MODEL(OCTEON_CN56XX) ? 2 : 1);
  1075. for (i = 0; i < num_lmc; i++) {
  1076. dev = platform_device_register_simple("octeon_lmc_edac",
  1077. i, NULL, 0);
  1078. if (IS_ERR(dev)) {
  1079. pr_err("Registration of octeon_lmc_edac %d failed!\n", i);
  1080. err = PTR_ERR(dev);
  1081. }
  1082. }
  1083. return err;
  1084. }
  1085. device_initcall(edac_devinit);
  1086. static void __initdata *octeon_dummy_iospace;
  1087. static int __init octeon_no_pci_init(void)
  1088. {
  1089. /*
  1090. * Initially assume there is no PCI. The PCI/PCIe platform code will
  1091. * later re-initialize these to correct values if they are present.
  1092. */
  1093. octeon_dummy_iospace = vzalloc(IO_SPACE_LIMIT);
  1094. set_io_port_base((unsigned long)octeon_dummy_iospace);
  1095. ioport_resource.start = MAX_RESOURCE;
  1096. ioport_resource.end = 0;
  1097. return 0;
  1098. }
  1099. core_initcall(octeon_no_pci_init);
  1100. static int __init octeon_no_pci_release(void)
  1101. {
  1102. /*
  1103. * Release the allocated memory if a real IO space is there.
  1104. */
  1105. if ((unsigned long)octeon_dummy_iospace != mips_io_port_base)
  1106. vfree(octeon_dummy_iospace);
  1107. return 0;
  1108. }
  1109. late_initcall(octeon_no_pci_release);