setup.c 31 KB

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