vfpmodule.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. /*
  2. * linux/arch/arm/vfp/vfpmodule.c
  3. *
  4. * Copyright (C) 2004 ARM Limited.
  5. * Written by Deep Blue Solutions Limited.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/types.h>
  12. #include <linux/cpu.h>
  13. #include <linux/cpu_pm.h>
  14. #include <linux/hardirq.h>
  15. #include <linux/kernel.h>
  16. #include <linux/notifier.h>
  17. #include <linux/signal.h>
  18. #include <linux/sched.h>
  19. #include <linux/smp.h>
  20. #include <linux/init.h>
  21. #include <linux/uaccess.h>
  22. #include <linux/user.h>
  23. #include <asm/cp15.h>
  24. #include <asm/cputype.h>
  25. #include <asm/system_info.h>
  26. #include <asm/thread_notify.h>
  27. #include <asm/vfp.h>
  28. #include "vfpinstr.h"
  29. #include "vfp.h"
  30. /*
  31. * Our undef handlers (in entry.S)
  32. */
  33. void vfp_testing_entry(void);
  34. void vfp_support_entry(void);
  35. void vfp_null_entry(void);
  36. void (*vfp_vector)(void) = vfp_null_entry;
  37. /*
  38. * Dual-use variable.
  39. * Used in startup: set to non-zero if VFP checks fail
  40. * After startup, holds VFP architecture
  41. */
  42. unsigned int VFP_arch;
  43. /*
  44. * The pointer to the vfpstate structure of the thread which currently
  45. * owns the context held in the VFP hardware, or NULL if the hardware
  46. * context is invalid.
  47. *
  48. * For UP, this is sufficient to tell which thread owns the VFP context.
  49. * However, for SMP, we also need to check the CPU number stored in the
  50. * saved state too to catch migrations.
  51. */
  52. union vfp_state *vfp_current_hw_state[NR_CPUS];
  53. /*
  54. * Is 'thread's most up to date state stored in this CPUs hardware?
  55. * Must be called from non-preemptible context.
  56. */
  57. static bool vfp_state_in_hw(unsigned int cpu, struct thread_info *thread)
  58. {
  59. #ifdef CONFIG_SMP
  60. if (thread->vfpstate.hard.cpu != cpu)
  61. return false;
  62. #endif
  63. return vfp_current_hw_state[cpu] == &thread->vfpstate;
  64. }
  65. /*
  66. * Force a reload of the VFP context from the thread structure. We do
  67. * this by ensuring that access to the VFP hardware is disabled, and
  68. * clear vfp_current_hw_state. Must be called from non-preemptible context.
  69. */
  70. static void vfp_force_reload(unsigned int cpu, struct thread_info *thread)
  71. {
  72. if (vfp_state_in_hw(cpu, thread)) {
  73. fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN);
  74. vfp_current_hw_state[cpu] = NULL;
  75. }
  76. #ifdef CONFIG_SMP
  77. thread->vfpstate.hard.cpu = NR_CPUS;
  78. #endif
  79. }
  80. /*
  81. * Per-thread VFP initialization.
  82. */
  83. static void vfp_thread_flush(struct thread_info *thread)
  84. {
  85. union vfp_state *vfp = &thread->vfpstate;
  86. unsigned int cpu;
  87. /*
  88. * Disable VFP to ensure we initialize it first. We must ensure
  89. * that the modification of vfp_current_hw_state[] and hardware
  90. * disable are done for the same CPU and without preemption.
  91. *
  92. * Do this first to ensure that preemption won't overwrite our
  93. * state saving should access to the VFP be enabled at this point.
  94. */
  95. cpu = get_cpu();
  96. if (vfp_current_hw_state[cpu] == vfp)
  97. vfp_current_hw_state[cpu] = NULL;
  98. fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN);
  99. put_cpu();
  100. memset(vfp, 0, sizeof(union vfp_state));
  101. vfp->hard.fpexc = FPEXC_EN;
  102. vfp->hard.fpscr = FPSCR_ROUND_NEAREST;
  103. #ifdef CONFIG_SMP
  104. vfp->hard.cpu = NR_CPUS;
  105. #endif
  106. }
  107. static void vfp_thread_exit(struct thread_info *thread)
  108. {
  109. /* release case: Per-thread VFP cleanup. */
  110. union vfp_state *vfp = &thread->vfpstate;
  111. unsigned int cpu = get_cpu();
  112. if (vfp_current_hw_state[cpu] == vfp)
  113. vfp_current_hw_state[cpu] = NULL;
  114. put_cpu();
  115. }
  116. static void vfp_thread_copy(struct thread_info *thread)
  117. {
  118. struct thread_info *parent = current_thread_info();
  119. vfp_sync_hwstate(parent);
  120. thread->vfpstate = parent->vfpstate;
  121. #ifdef CONFIG_SMP
  122. thread->vfpstate.hard.cpu = NR_CPUS;
  123. #endif
  124. }
  125. /*
  126. * When this function is called with the following 'cmd's, the following
  127. * is true while this function is being run:
  128. * THREAD_NOFTIFY_SWTICH:
  129. * - the previously running thread will not be scheduled onto another CPU.
  130. * - the next thread to be run (v) will not be running on another CPU.
  131. * - thread->cpu is the local CPU number
  132. * - not preemptible as we're called in the middle of a thread switch
  133. * THREAD_NOTIFY_FLUSH:
  134. * - the thread (v) will be running on the local CPU, so
  135. * v === current_thread_info()
  136. * - thread->cpu is the local CPU number at the time it is accessed,
  137. * but may change at any time.
  138. * - we could be preempted if tree preempt rcu is enabled, so
  139. * it is unsafe to use thread->cpu.
  140. * THREAD_NOTIFY_EXIT
  141. * - the thread (v) will be running on the local CPU, so
  142. * v === current_thread_info()
  143. * - thread->cpu is the local CPU number at the time it is accessed,
  144. * but may change at any time.
  145. * - we could be preempted if tree preempt rcu is enabled, so
  146. * it is unsafe to use thread->cpu.
  147. */
  148. static int vfp_notifier(struct notifier_block *self, unsigned long cmd, void *v)
  149. {
  150. struct thread_info *thread = v;
  151. u32 fpexc;
  152. #ifdef CONFIG_SMP
  153. unsigned int cpu;
  154. #endif
  155. switch (cmd) {
  156. case THREAD_NOTIFY_SWITCH:
  157. fpexc = fmrx(FPEXC);
  158. #ifdef CONFIG_SMP
  159. cpu = thread->cpu;
  160. /*
  161. * On SMP, if VFP is enabled, save the old state in
  162. * case the thread migrates to a different CPU. The
  163. * restoring is done lazily.
  164. */
  165. if ((fpexc & FPEXC_EN) && vfp_current_hw_state[cpu])
  166. vfp_save_state(vfp_current_hw_state[cpu], fpexc);
  167. #endif
  168. /*
  169. * Always disable VFP so we can lazily save/restore the
  170. * old state.
  171. */
  172. fmxr(FPEXC, fpexc & ~FPEXC_EN);
  173. break;
  174. case THREAD_NOTIFY_FLUSH:
  175. vfp_thread_flush(thread);
  176. break;
  177. case THREAD_NOTIFY_EXIT:
  178. vfp_thread_exit(thread);
  179. break;
  180. case THREAD_NOTIFY_COPY:
  181. vfp_thread_copy(thread);
  182. break;
  183. }
  184. return NOTIFY_DONE;
  185. }
  186. static struct notifier_block vfp_notifier_block = {
  187. .notifier_call = vfp_notifier,
  188. };
  189. /*
  190. * Raise a SIGFPE for the current process.
  191. * sicode describes the signal being raised.
  192. */
  193. static void vfp_raise_sigfpe(unsigned int sicode, struct pt_regs *regs)
  194. {
  195. siginfo_t info;
  196. memset(&info, 0, sizeof(info));
  197. info.si_signo = SIGFPE;
  198. info.si_code = sicode;
  199. info.si_addr = (void __user *)(instruction_pointer(regs) - 4);
  200. /*
  201. * This is the same as NWFPE, because it's not clear what
  202. * this is used for
  203. */
  204. current->thread.error_code = 0;
  205. current->thread.trap_no = 6;
  206. send_sig_info(SIGFPE, &info, current);
  207. }
  208. static void vfp_panic(char *reason, u32 inst)
  209. {
  210. int i;
  211. pr_err("VFP: Error: %s\n", reason);
  212. pr_err("VFP: EXC 0x%08x SCR 0x%08x INST 0x%08x\n",
  213. fmrx(FPEXC), fmrx(FPSCR), inst);
  214. for (i = 0; i < 32; i += 2)
  215. pr_err("VFP: s%2u: 0x%08x s%2u: 0x%08x\n",
  216. i, vfp_get_float(i), i+1, vfp_get_float(i+1));
  217. }
  218. /*
  219. * Process bitmask of exception conditions.
  220. */
  221. static void vfp_raise_exceptions(u32 exceptions, u32 inst, u32 fpscr, struct pt_regs *regs)
  222. {
  223. int si_code = 0;
  224. pr_debug("VFP: raising exceptions %08x\n", exceptions);
  225. if (exceptions == VFP_EXCEPTION_ERROR) {
  226. vfp_panic("unhandled bounce", inst);
  227. vfp_raise_sigfpe(0, regs);
  228. return;
  229. }
  230. /*
  231. * If any of the status flags are set, update the FPSCR.
  232. * Comparison instructions always return at least one of
  233. * these flags set.
  234. */
  235. if (exceptions & (FPSCR_N|FPSCR_Z|FPSCR_C|FPSCR_V))
  236. fpscr &= ~(FPSCR_N|FPSCR_Z|FPSCR_C|FPSCR_V);
  237. fpscr |= exceptions;
  238. fmxr(FPSCR, fpscr);
  239. #define RAISE(stat,en,sig) \
  240. if (exceptions & stat && fpscr & en) \
  241. si_code = sig;
  242. /*
  243. * These are arranged in priority order, least to highest.
  244. */
  245. RAISE(FPSCR_DZC, FPSCR_DZE, FPE_FLTDIV);
  246. RAISE(FPSCR_IXC, FPSCR_IXE, FPE_FLTRES);
  247. RAISE(FPSCR_UFC, FPSCR_UFE, FPE_FLTUND);
  248. RAISE(FPSCR_OFC, FPSCR_OFE, FPE_FLTOVF);
  249. RAISE(FPSCR_IOC, FPSCR_IOE, FPE_FLTINV);
  250. if (si_code)
  251. vfp_raise_sigfpe(si_code, regs);
  252. }
  253. /*
  254. * Emulate a VFP instruction.
  255. */
  256. static u32 vfp_emulate_instruction(u32 inst, u32 fpscr, struct pt_regs *regs)
  257. {
  258. u32 exceptions = VFP_EXCEPTION_ERROR;
  259. pr_debug("VFP: emulate: INST=0x%08x SCR=0x%08x\n", inst, fpscr);
  260. if (INST_CPRTDO(inst)) {
  261. if (!INST_CPRT(inst)) {
  262. /*
  263. * CPDO
  264. */
  265. if (vfp_single(inst)) {
  266. exceptions = vfp_single_cpdo(inst, fpscr);
  267. } else {
  268. exceptions = vfp_double_cpdo(inst, fpscr);
  269. }
  270. } else {
  271. /*
  272. * A CPRT instruction can not appear in FPINST2, nor
  273. * can it cause an exception. Therefore, we do not
  274. * have to emulate it.
  275. */
  276. }
  277. } else {
  278. /*
  279. * A CPDT instruction can not appear in FPINST2, nor can
  280. * it cause an exception. Therefore, we do not have to
  281. * emulate it.
  282. */
  283. }
  284. return exceptions & ~VFP_NAN_FLAG;
  285. }
  286. /*
  287. * Package up a bounce condition.
  288. */
  289. void VFP_bounce(u32 trigger, u32 fpexc, struct pt_regs *regs)
  290. {
  291. u32 fpscr, orig_fpscr, fpsid, exceptions;
  292. pr_debug("VFP: bounce: trigger %08x fpexc %08x\n", trigger, fpexc);
  293. /*
  294. * At this point, FPEXC can have the following configuration:
  295. *
  296. * EX DEX IXE
  297. * 0 1 x - synchronous exception
  298. * 1 x 0 - asynchronous exception
  299. * 1 x 1 - sychronous on VFP subarch 1 and asynchronous on later
  300. * 0 0 1 - synchronous on VFP9 (non-standard subarch 1
  301. * implementation), undefined otherwise
  302. *
  303. * Clear various bits and enable access to the VFP so we can
  304. * handle the bounce.
  305. */
  306. fmxr(FPEXC, fpexc & ~(FPEXC_EX|FPEXC_DEX|FPEXC_FP2V|FPEXC_VV|FPEXC_TRAP_MASK));
  307. fpsid = fmrx(FPSID);
  308. orig_fpscr = fpscr = fmrx(FPSCR);
  309. /*
  310. * Check for the special VFP subarch 1 and FPSCR.IXE bit case
  311. */
  312. if ((fpsid & FPSID_ARCH_MASK) == (1 << FPSID_ARCH_BIT)
  313. && (fpscr & FPSCR_IXE)) {
  314. /*
  315. * Synchronous exception, emulate the trigger instruction
  316. */
  317. goto emulate;
  318. }
  319. if (fpexc & FPEXC_EX) {
  320. #ifndef CONFIG_CPU_FEROCEON
  321. /*
  322. * Asynchronous exception. The instruction is read from FPINST
  323. * and the interrupted instruction has to be restarted.
  324. */
  325. trigger = fmrx(FPINST);
  326. regs->ARM_pc -= 4;
  327. #endif
  328. } else if (!(fpexc & FPEXC_DEX)) {
  329. /*
  330. * Illegal combination of bits. It can be caused by an
  331. * unallocated VFP instruction but with FPSCR.IXE set and not
  332. * on VFP subarch 1.
  333. */
  334. vfp_raise_exceptions(VFP_EXCEPTION_ERROR, trigger, fpscr, regs);
  335. goto exit;
  336. }
  337. /*
  338. * Modify fpscr to indicate the number of iterations remaining.
  339. * If FPEXC.EX is 0, FPEXC.DEX is 1 and the FPEXC.VV bit indicates
  340. * whether FPEXC.VECITR or FPSCR.LEN is used.
  341. */
  342. if (fpexc & (FPEXC_EX | FPEXC_VV)) {
  343. u32 len;
  344. len = fpexc + (1 << FPEXC_LENGTH_BIT);
  345. fpscr &= ~FPSCR_LENGTH_MASK;
  346. fpscr |= (len & FPEXC_LENGTH_MASK) << (FPSCR_LENGTH_BIT - FPEXC_LENGTH_BIT);
  347. }
  348. /*
  349. * Handle the first FP instruction. We used to take note of the
  350. * FPEXC bounce reason, but this appears to be unreliable.
  351. * Emulate the bounced instruction instead.
  352. */
  353. exceptions = vfp_emulate_instruction(trigger, fpscr, regs);
  354. if (exceptions)
  355. vfp_raise_exceptions(exceptions, trigger, orig_fpscr, regs);
  356. /*
  357. * If there isn't a second FP instruction, exit now. Note that
  358. * the FPEXC.FP2V bit is valid only if FPEXC.EX is 1.
  359. */
  360. if (fpexc ^ (FPEXC_EX | FPEXC_FP2V))
  361. goto exit;
  362. /*
  363. * The barrier() here prevents fpinst2 being read
  364. * before the condition above.
  365. */
  366. barrier();
  367. trigger = fmrx(FPINST2);
  368. emulate:
  369. exceptions = vfp_emulate_instruction(trigger, orig_fpscr, regs);
  370. if (exceptions)
  371. vfp_raise_exceptions(exceptions, trigger, orig_fpscr, regs);
  372. exit:
  373. preempt_enable();
  374. }
  375. static void vfp_enable(void *unused)
  376. {
  377. u32 access;
  378. BUG_ON(preemptible());
  379. access = get_copro_access();
  380. /*
  381. * Enable full access to VFP (cp10 and cp11)
  382. */
  383. set_copro_access(access | CPACC_FULL(10) | CPACC_FULL(11));
  384. }
  385. #ifdef CONFIG_CPU_PM
  386. static int vfp_pm_suspend(void)
  387. {
  388. struct thread_info *ti = current_thread_info();
  389. u32 fpexc = fmrx(FPEXC);
  390. /* if vfp is on, then save state for resumption */
  391. if (fpexc & FPEXC_EN) {
  392. pr_debug("%s: saving vfp state\n", __func__);
  393. vfp_save_state(&ti->vfpstate, fpexc);
  394. /* disable, just in case */
  395. fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN);
  396. } else if (vfp_current_hw_state[ti->cpu]) {
  397. #ifndef CONFIG_SMP
  398. fmxr(FPEXC, fpexc | FPEXC_EN);
  399. vfp_save_state(vfp_current_hw_state[ti->cpu], fpexc);
  400. fmxr(FPEXC, fpexc);
  401. #endif
  402. }
  403. /* clear any information we had about last context state */
  404. vfp_current_hw_state[ti->cpu] = NULL;
  405. return 0;
  406. }
  407. static void vfp_pm_resume(void)
  408. {
  409. /* ensure we have access to the vfp */
  410. vfp_enable(NULL);
  411. /* and disable it to ensure the next usage restores the state */
  412. fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN);
  413. }
  414. static int vfp_cpu_pm_notifier(struct notifier_block *self, unsigned long cmd,
  415. void *v)
  416. {
  417. switch (cmd) {
  418. case CPU_PM_ENTER:
  419. vfp_pm_suspend();
  420. break;
  421. case CPU_PM_ENTER_FAILED:
  422. case CPU_PM_EXIT:
  423. vfp_pm_resume();
  424. break;
  425. }
  426. return NOTIFY_OK;
  427. }
  428. static struct notifier_block vfp_cpu_pm_notifier_block = {
  429. .notifier_call = vfp_cpu_pm_notifier,
  430. };
  431. static void vfp_pm_init(void)
  432. {
  433. cpu_pm_register_notifier(&vfp_cpu_pm_notifier_block);
  434. }
  435. #else
  436. static inline void vfp_pm_init(void) { }
  437. #endif /* CONFIG_CPU_PM */
  438. /*
  439. * Ensure that the VFP state stored in 'thread->vfpstate' is up to date
  440. * with the hardware state.
  441. */
  442. void vfp_sync_hwstate(struct thread_info *thread)
  443. {
  444. unsigned int cpu = get_cpu();
  445. if (vfp_state_in_hw(cpu, thread)) {
  446. u32 fpexc = fmrx(FPEXC);
  447. /*
  448. * Save the last VFP state on this CPU.
  449. */
  450. fmxr(FPEXC, fpexc | FPEXC_EN);
  451. vfp_save_state(&thread->vfpstate, fpexc | FPEXC_EN);
  452. fmxr(FPEXC, fpexc);
  453. }
  454. put_cpu();
  455. }
  456. /* Ensure that the thread reloads the hardware VFP state on the next use. */
  457. void vfp_flush_hwstate(struct thread_info *thread)
  458. {
  459. unsigned int cpu = get_cpu();
  460. vfp_force_reload(cpu, thread);
  461. put_cpu();
  462. }
  463. /*
  464. * Save the current VFP state into the provided structures and prepare
  465. * for entry into a new function (signal handler).
  466. */
  467. int vfp_preserve_user_clear_hwstate(struct user_vfp __user *ufp,
  468. struct user_vfp_exc __user *ufp_exc)
  469. {
  470. struct thread_info *thread = current_thread_info();
  471. struct vfp_hard_struct *hwstate = &thread->vfpstate.hard;
  472. int err = 0;
  473. /* Ensure that the saved hwstate is up-to-date. */
  474. vfp_sync_hwstate(thread);
  475. /*
  476. * Copy the floating point registers. There can be unused
  477. * registers see asm/hwcap.h for details.
  478. */
  479. err |= __copy_to_user(&ufp->fpregs, &hwstate->fpregs,
  480. sizeof(hwstate->fpregs));
  481. /*
  482. * Copy the status and control register.
  483. */
  484. __put_user_error(hwstate->fpscr, &ufp->fpscr, err);
  485. /*
  486. * Copy the exception registers.
  487. */
  488. __put_user_error(hwstate->fpexc, &ufp_exc->fpexc, err);
  489. __put_user_error(hwstate->fpinst, &ufp_exc->fpinst, err);
  490. __put_user_error(hwstate->fpinst2, &ufp_exc->fpinst2, err);
  491. if (err)
  492. return -EFAULT;
  493. /* Ensure that VFP is disabled. */
  494. vfp_flush_hwstate(thread);
  495. /*
  496. * As per the PCS, clear the length and stride bits for function
  497. * entry.
  498. */
  499. hwstate->fpscr &= ~(FPSCR_LENGTH_MASK | FPSCR_STRIDE_MASK);
  500. return 0;
  501. }
  502. /* Sanitise and restore the current VFP state from the provided structures. */
  503. int vfp_restore_user_hwstate(struct user_vfp __user *ufp,
  504. struct user_vfp_exc __user *ufp_exc)
  505. {
  506. struct thread_info *thread = current_thread_info();
  507. struct vfp_hard_struct *hwstate = &thread->vfpstate.hard;
  508. unsigned long fpexc;
  509. int err = 0;
  510. /* Disable VFP to avoid corrupting the new thread state. */
  511. vfp_flush_hwstate(thread);
  512. /*
  513. * Copy the floating point registers. There can be unused
  514. * registers see asm/hwcap.h for details.
  515. */
  516. err |= __copy_from_user(&hwstate->fpregs, &ufp->fpregs,
  517. sizeof(hwstate->fpregs));
  518. /*
  519. * Copy the status and control register.
  520. */
  521. __get_user_error(hwstate->fpscr, &ufp->fpscr, err);
  522. /*
  523. * Sanitise and restore the exception registers.
  524. */
  525. __get_user_error(fpexc, &ufp_exc->fpexc, err);
  526. /* Ensure the VFP is enabled. */
  527. fpexc |= FPEXC_EN;
  528. /* Ensure FPINST2 is invalid and the exception flag is cleared. */
  529. fpexc &= ~(FPEXC_EX | FPEXC_FP2V);
  530. hwstate->fpexc = fpexc;
  531. __get_user_error(hwstate->fpinst, &ufp_exc->fpinst, err);
  532. __get_user_error(hwstate->fpinst2, &ufp_exc->fpinst2, err);
  533. return err ? -EFAULT : 0;
  534. }
  535. /*
  536. * VFP hardware can lose all context when a CPU goes offline.
  537. * As we will be running in SMP mode with CPU hotplug, we will save the
  538. * hardware state at every thread switch. We clear our held state when
  539. * a CPU has been killed, indicating that the VFP hardware doesn't contain
  540. * a threads VFP state. When a CPU starts up, we re-enable access to the
  541. * VFP hardware.
  542. *
  543. * Both CPU_DYING and CPU_STARTING are called on the CPU which
  544. * is being offlined/onlined.
  545. */
  546. static int vfp_hotplug(struct notifier_block *b, unsigned long action,
  547. void *hcpu)
  548. {
  549. if (action == CPU_DYING || action == CPU_DYING_FROZEN) {
  550. vfp_force_reload((long)hcpu, current_thread_info());
  551. } else if (action == CPU_STARTING || action == CPU_STARTING_FROZEN)
  552. vfp_enable(NULL);
  553. return NOTIFY_OK;
  554. }
  555. /*
  556. * VFP support code initialisation.
  557. */
  558. static int __init vfp_init(void)
  559. {
  560. unsigned int vfpsid;
  561. unsigned int cpu_arch = cpu_architecture();
  562. if (cpu_arch >= CPU_ARCH_ARMv6)
  563. on_each_cpu(vfp_enable, NULL, 1);
  564. /*
  565. * First check that there is a VFP that we can use.
  566. * The handler is already setup to just log calls, so
  567. * we just need to read the VFPSID register.
  568. */
  569. vfp_vector = vfp_testing_entry;
  570. barrier();
  571. vfpsid = fmrx(FPSID);
  572. barrier();
  573. vfp_vector = vfp_null_entry;
  574. pr_info("VFP support v0.3: ");
  575. if (VFP_arch)
  576. pr_cont("not present\n");
  577. else if (vfpsid & FPSID_NODOUBLE) {
  578. pr_cont("no double precision support\n");
  579. } else {
  580. hotcpu_notifier(vfp_hotplug, 0);
  581. VFP_arch = (vfpsid & FPSID_ARCH_MASK) >> FPSID_ARCH_BIT; /* Extract the architecture version */
  582. pr_cont("implementor %02x architecture %d part %02x variant %x rev %x\n",
  583. (vfpsid & FPSID_IMPLEMENTER_MASK) >> FPSID_IMPLEMENTER_BIT,
  584. (vfpsid & FPSID_ARCH_MASK) >> FPSID_ARCH_BIT,
  585. (vfpsid & FPSID_PART_MASK) >> FPSID_PART_BIT,
  586. (vfpsid & FPSID_VARIANT_MASK) >> FPSID_VARIANT_BIT,
  587. (vfpsid & FPSID_REV_MASK) >> FPSID_REV_BIT);
  588. vfp_vector = vfp_support_entry;
  589. thread_register_notifier(&vfp_notifier_block);
  590. vfp_pm_init();
  591. /*
  592. * We detected VFP, and the support code is
  593. * in place; report VFP support to userspace.
  594. */
  595. elf_hwcap |= HWCAP_VFP;
  596. #ifdef CONFIG_VFPv3
  597. if (VFP_arch >= 2) {
  598. elf_hwcap |= HWCAP_VFPv3;
  599. /*
  600. * Check for VFPv3 D16. CPUs in this configuration
  601. * only have 16 x 64bit registers.
  602. */
  603. if (((fmrx(MVFR0) & MVFR0_A_SIMD_MASK)) == 1)
  604. elf_hwcap |= HWCAP_VFPv3D16;
  605. }
  606. #endif
  607. /*
  608. * Check for the presence of the Advanced SIMD
  609. * load/store instructions, integer and single
  610. * precision floating point operations. Only check
  611. * for NEON if the hardware has the MVFR registers.
  612. */
  613. if ((read_cpuid_id() & 0x000f0000) == 0x000f0000) {
  614. #ifdef CONFIG_NEON
  615. if ((fmrx(MVFR1) & 0x000fff00) == 0x00011100)
  616. elf_hwcap |= HWCAP_NEON;
  617. #endif
  618. if ((fmrx(MVFR1) & 0xf0000000) == 0x10000000)
  619. elf_hwcap |= HWCAP_VFPv4;
  620. }
  621. }
  622. return 0;
  623. }
  624. late_initcall(vfp_init);