vfpmodule.c 18 KB

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