correlationCalculationWaterTankSpray.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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;