cpu.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright (c) 2009
  3. * The President and Fellows of Harvard College.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. #ifndef _CPU_H_
  30. #define _CPU_H_
  31. #include <spinlock.h>
  32. #include <threadlist.h>
  33. #include <machine/vm.h> /* for TLBSHOOTDOWN_MAX */
  34. /*
  35. * Per-cpu structure
  36. *
  37. * Note: curcpu is defined by <current.h>.
  38. *
  39. * cpu->c_self should always be used when *using* the address of curcpu
  40. * (as opposed to merely dereferencing it) in case curcpu is defined as
  41. * a pointer with a fixed address and a per-cpu mapping in the MMU.
  42. */
  43. struct cpu {
  44. /*
  45. * Fixed after allocation.
  46. */
  47. struct cpu *c_self; /* Canonical address of this struct */
  48. unsigned c_number; /* This cpu's cpu number */
  49. unsigned c_hardware_number; /* Hardware-defined cpu number */
  50. /*
  51. * Accessed only by this cpu.
  52. */
  53. struct thread *c_curthread; /* Current thread on cpu */
  54. struct threadlist c_zombies; /* List of exited threads */
  55. unsigned c_hardclocks; /* Counter of hardclock() calls */
  56. /*
  57. * Accessed by other cpus.
  58. * Protected by the runqueue lock.
  59. */
  60. bool c_isidle; /* True if this cpu is idle */
  61. struct threadlist c_runqueue; /* Run queue for this cpu */
  62. struct spinlock c_runqueue_lock;
  63. /*
  64. * Accessed by other cpus.
  65. * Protected by the IPI lock.
  66. *
  67. * If c_numshootdown is -1 (TLBSHOOTDOWN_ALL), all mappings
  68. * should be invalidated. This is used if more than
  69. * TLBSHOOTDOWN_MAX mappings are going to be invalidated at
  70. * once. TLBSHOOTDOWN_MAX is MD and chosen based on when it
  71. * becomes more efficient just to flush the whole TLB.
  72. *
  73. * struct tlbshootdown is machine-dependent and might
  74. * reasonably be either an address space and vaddr pair, or a
  75. * paddr, or something else.
  76. */
  77. uint32_t c_ipi_pending; /* One bit for each IPI number */
  78. struct tlbshootdown c_shootdown[TLBSHOOTDOWN_MAX];
  79. int c_numshootdown;
  80. struct spinlock c_ipi_lock;
  81. };
  82. #define TLBSHOOTDOWN_ALL (-1)
  83. /*
  84. * Initialization functions.
  85. *
  86. * cpu_create creates a cpu; it is suitable for calling from driver-
  87. * or bus-specific code that looks for secondary CPUs.
  88. *
  89. * cpu_create calls cpu_machdep_init.
  90. *
  91. * cpu_start_secondary is the platform-dependent assembly language
  92. * entry point for new CPUs; it can be found in start.S. It calls
  93. * cpu_hatch after having claimed the startup stack and thread created
  94. * for the cpu.
  95. */
  96. struct cpu *cpu_create(unsigned hardware_number);
  97. void cpu_machdep_init(struct cpu *);
  98. /*ASMLINKAGE*/ void cpu_start_secondary(void);
  99. void cpu_hatch(unsigned software_number);
  100. /*
  101. * Return a string describing the CPU type.
  102. */
  103. const char *cpu_identify(void);
  104. /*
  105. * Hardware-level interrupt on/off, for the current CPU.
  106. *
  107. * These should only be used by the spl code.
  108. */
  109. void cpu_irqoff(void);
  110. void cpu_irqon(void);
  111. /*
  112. * Idle or shut down (respectively) the processor.
  113. *
  114. * cpu_idle() sits around (in a low-power state if possible) until it
  115. * thinks something interesting may have happened, such as an
  116. * interrupt. Then it returns. (It may be wrong, so it should always
  117. * be called in a loop checking some other condition.) It must be
  118. * called with interrupts off to avoid race conditions, although
  119. * interrupts may be delivered before it returns.
  120. *
  121. * cpu_halt sits around (in a low-power state if possible) until the
  122. * external reset is pushed. Interrupts should be disabled. It does
  123. * not return. It should not allow interrupts to be delivered.
  124. */
  125. void cpu_idle(void);
  126. void cpu_halt(void);
  127. /*
  128. * Interprocessor interrupts.
  129. *
  130. * From time to time it is necessary to poke another CPU. System
  131. * boards of multiprocessor machines provide a way to do this.
  132. *
  133. * TLB shootdown is done by the VM system when more than one processor
  134. * has (or may have) a page mapped in the MMU and it is being changed
  135. * or otherwise needs to be invalidated across all CPUs.
  136. *
  137. * ipi_send sends an IPI to one CPU.
  138. * ipi_broadcast sends an IPI to all CPUs except the current one.
  139. * ipi_tlbshootdown is like ipi_send but carries TLB shootdown data.
  140. *
  141. * interprocessor_interrupt is called on the target CPU when an IPI is
  142. * received.
  143. */
  144. /* IPI types */
  145. #define IPI_PANIC 0 /* System has called panic() */
  146. #define IPI_OFFLINE 1 /* CPU is requested to go offline */
  147. #define IPI_UNIDLE 2 /* Runnable threads are available */
  148. #define IPI_TLBSHOOTDOWN 3 /* MMU mapping(s) need invalidation */
  149. void ipi_send(struct cpu *target, int code);
  150. void ipi_broadcast(int code);
  151. void ipi_tlbshootdown(struct cpu *target, const struct tlbshootdown *mapping);
  152. void interprocessor_interrupt(void);
  153. #endif /* _CPU_H_ */