io_apic.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_IO_APIC_H
  3. #define _ASM_X86_IO_APIC_H
  4. #include <linux/types.h>
  5. #include <asm/mpspec.h>
  6. #include <asm/apicdef.h>
  7. #include <asm/irq_vectors.h>
  8. #include <asm/x86_init.h>
  9. /*
  10. * Intel IO-APIC support for SMP and UP systems.
  11. *
  12. * Copyright (C) 1997, 1998, 1999, 2000 Ingo Molnar
  13. */
  14. /* I/O Unit Redirection Table */
  15. #define IO_APIC_REDIR_VECTOR_MASK 0x000FF
  16. #define IO_APIC_REDIR_DEST_LOGICAL 0x00800
  17. #define IO_APIC_REDIR_DEST_PHYSICAL 0x00000
  18. #define IO_APIC_REDIR_SEND_PENDING (1 << 12)
  19. #define IO_APIC_REDIR_REMOTE_IRR (1 << 14)
  20. #define IO_APIC_REDIR_LEVEL_TRIGGER (1 << 15)
  21. #define IO_APIC_REDIR_MASKED (1 << 16)
  22. /*
  23. * The structure of the IO-APIC:
  24. */
  25. union IO_APIC_reg_00 {
  26. u32 raw;
  27. struct {
  28. u32 __reserved_2 : 14,
  29. LTS : 1,
  30. delivery_type : 1,
  31. __reserved_1 : 8,
  32. ID : 8;
  33. } __attribute__ ((packed)) bits;
  34. };
  35. union IO_APIC_reg_01 {
  36. u32 raw;
  37. struct {
  38. u32 version : 8,
  39. __reserved_2 : 7,
  40. PRQ : 1,
  41. entries : 8,
  42. __reserved_1 : 8;
  43. } __attribute__ ((packed)) bits;
  44. };
  45. union IO_APIC_reg_02 {
  46. u32 raw;
  47. struct {
  48. u32 __reserved_2 : 24,
  49. arbitration : 4,
  50. __reserved_1 : 4;
  51. } __attribute__ ((packed)) bits;
  52. };
  53. union IO_APIC_reg_03 {
  54. u32 raw;
  55. struct {
  56. u32 boot_DT : 1,
  57. __reserved_1 : 31;
  58. } __attribute__ ((packed)) bits;
  59. };
  60. struct IO_APIC_route_entry {
  61. __u32 vector : 8,
  62. delivery_mode : 3, /* 000: FIXED
  63. * 001: lowest prio
  64. * 111: ExtINT
  65. */
  66. dest_mode : 1, /* 0: physical, 1: logical */
  67. delivery_status : 1,
  68. polarity : 1,
  69. irr : 1,
  70. trigger : 1, /* 0: edge, 1: level */
  71. mask : 1, /* 0: enabled, 1: disabled */
  72. __reserved_2 : 15;
  73. __u32 __reserved_3 : 24,
  74. dest : 8;
  75. } __attribute__ ((packed));
  76. struct IR_IO_APIC_route_entry {
  77. __u64 vector : 8,
  78. zero : 3,
  79. index2 : 1,
  80. delivery_status : 1,
  81. polarity : 1,
  82. irr : 1,
  83. trigger : 1,
  84. mask : 1,
  85. reserved : 31,
  86. format : 1,
  87. index : 15;
  88. } __attribute__ ((packed));
  89. struct irq_alloc_info;
  90. struct ioapic_domain_cfg;
  91. #define IOAPIC_AUTO -1
  92. #define IOAPIC_EDGE 0
  93. #define IOAPIC_LEVEL 1
  94. #define IOAPIC_MASKED 1
  95. #define IOAPIC_UNMASKED 0
  96. #define IOAPIC_POL_HIGH 0
  97. #define IOAPIC_POL_LOW 1
  98. #define IOAPIC_DEST_MODE_PHYSICAL 0
  99. #define IOAPIC_DEST_MODE_LOGICAL 1
  100. #define IOAPIC_MAP_ALLOC 0x1
  101. #define IOAPIC_MAP_CHECK 0x2
  102. #ifdef CONFIG_X86_IO_APIC
  103. /*
  104. * # of IO-APICs and # of IRQ routing registers
  105. */
  106. extern int nr_ioapics;
  107. extern int mpc_ioapic_id(int ioapic);
  108. extern unsigned int mpc_ioapic_addr(int ioapic);
  109. /* # of MP IRQ source entries */
  110. extern int mp_irq_entries;
  111. /* MP IRQ source entries */
  112. extern struct mpc_intsrc mp_irqs[MAX_IRQ_SOURCES];
  113. /* 1 if "noapic" boot option passed */
  114. extern int skip_ioapic_setup;
  115. /* 1 if "noapic" boot option passed */
  116. extern int noioapicquirk;
  117. /* -1 if "noapic" boot option passed */
  118. extern int noioapicreroute;
  119. extern u32 gsi_top;
  120. extern unsigned long io_apic_irqs;
  121. #define IO_APIC_IRQ(x) (((x) >= NR_IRQS_LEGACY) || ((1 << (x)) & io_apic_irqs))
  122. /*
  123. * If we use the IO-APIC for IRQ routing, disable automatic
  124. * assignment of PCI IRQ's.
  125. */
  126. #define io_apic_assign_pci_irqs \
  127. (mp_irq_entries && !skip_ioapic_setup && io_apic_irqs)
  128. struct irq_cfg;
  129. extern void ioapic_insert_resources(void);
  130. extern int arch_early_ioapic_init(void);
  131. extern int save_ioapic_entries(void);
  132. extern void mask_ioapic_entries(void);
  133. extern int restore_ioapic_entries(void);
  134. extern void setup_ioapic_ids_from_mpc(void);
  135. extern void setup_ioapic_ids_from_mpc_nocheck(void);
  136. extern int mp_find_ioapic(u32 gsi);
  137. extern int mp_find_ioapic_pin(int ioapic, u32 gsi);
  138. extern int mp_map_gsi_to_irq(u32 gsi, unsigned int flags,
  139. struct irq_alloc_info *info);
  140. extern void mp_unmap_irq(int irq);
  141. extern int mp_register_ioapic(int id, u32 address, u32 gsi_base,
  142. struct ioapic_domain_cfg *cfg);
  143. extern int mp_unregister_ioapic(u32 gsi_base);
  144. extern int mp_ioapic_registered(u32 gsi_base);
  145. extern void ioapic_set_alloc_attr(struct irq_alloc_info *info,
  146. int node, int trigger, int polarity);
  147. extern void mp_save_irq(struct mpc_intsrc *m);
  148. extern void disable_ioapic_support(void);
  149. extern void __init io_apic_init_mappings(void);
  150. extern unsigned int native_io_apic_read(unsigned int apic, unsigned int reg);
  151. extern void native_disable_io_apic(void);
  152. static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg)
  153. {
  154. return x86_io_apic_ops.read(apic, reg);
  155. }
  156. extern void setup_IO_APIC(void);
  157. extern void enable_IO_APIC(void);
  158. extern void clear_IO_APIC(void);
  159. extern void restore_boot_irq_mode(void);
  160. extern int IO_APIC_get_PCI_irq_vector(int bus, int devfn, int pin);
  161. extern void print_IO_APICs(void);
  162. #else /* !CONFIG_X86_IO_APIC */
  163. #define IO_APIC_IRQ(x) 0
  164. #define io_apic_assign_pci_irqs 0
  165. #define setup_ioapic_ids_from_mpc x86_init_noop
  166. static inline void ioapic_insert_resources(void) { }
  167. static inline int arch_early_ioapic_init(void) { return 0; }
  168. static inline void print_IO_APICs(void) {}
  169. #define gsi_top (NR_IRQS_LEGACY)
  170. static inline int mp_find_ioapic(u32 gsi) { return 0; }
  171. static inline int mp_map_gsi_to_irq(u32 gsi, unsigned int flags,
  172. struct irq_alloc_info *info)
  173. {
  174. return gsi;
  175. }
  176. static inline void mp_unmap_irq(int irq) { }
  177. static inline int save_ioapic_entries(void)
  178. {
  179. return -ENOMEM;
  180. }
  181. static inline void mask_ioapic_entries(void) { }
  182. static inline int restore_ioapic_entries(void)
  183. {
  184. return -ENOMEM;
  185. }
  186. static inline void mp_save_irq(struct mpc_intsrc *m) { }
  187. static inline void disable_ioapic_support(void) { }
  188. static inline void io_apic_init_mappings(void) { }
  189. #define native_io_apic_read NULL
  190. #define native_disable_io_apic NULL
  191. static inline void setup_IO_APIC(void) { }
  192. static inline void enable_IO_APIC(void) { }
  193. static inline void restore_boot_irq_mode(void) { }
  194. #endif
  195. #endif /* _ASM_X86_IO_APIC_H */