setup.c 31 KB

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