io_apic.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. #ifndef _ASM_X86_IO_APIC_H
  2. #define _ASM_X86_IO_APIC_H
  3. #include <linux/types.h>
  4. #include <asm/mpspec.h>
  5. #include <asm/apicdef.h>
  6. #include <asm/irq_vectors.h>
  7. #include <asm/x86_init.h>
  8. /*
  9. * Intel IO-APIC support for SMP and UP systems.
  10. *
  11. * Copyright (C) 1997, 1998, 1999, 2000 Ingo Molnar
  12. */
  13. /* I/O Unit Redirection Table */
  14. #define IO_APIC_REDIR_VECTOR_MASK 0x000FF
  15. #define IO_APIC_REDIR_DEST_LOGICAL 0x00800
  16. #define IO_APIC_REDIR_DEST_PHYSICAL 0x00000
  17. #define IO_APIC_REDIR_SEND_PENDING (1 << 12)
  18. #define IO_APIC_REDIR_REMOTE_IRR (1 << 14)
  19. #define IO_APIC_REDIR_LEVEL_TRIGGER (1 << 15)
  20. #define IO_APIC_REDIR_MASKED (1 << 16)
  21. /*
  22. * The structure of the IO-APIC:
  23. */
  24. union IO_APIC_reg_00 {
  25. u32 raw;
  26. struct {
  27. u32 __reserved_2 : 14,
  28. LTS : 1,
  29. delivery_type : 1,
  30. __reserved_1 : 8,
  31. ID : 8;
  32. } __attribute__ ((packed)) bits;
  33. };
  34. union IO_APIC_reg_01 {
  35. u32 raw;
  36. struct {
  37. u32 version : 8,
  38. __reserved_2 : 7,
  39. PRQ : 1,
  40. entries : 8,
  41. __reserved_1 : 8;
  42. } __attribute__ ((packed)) bits;
  43. };
  44. union IO_APIC_reg_02 {
  45. u32 raw;
  46. struct {
  47. u32 __reserved_2 : 24,
  48. arbitration : 4,
  49. __reserved_1 : 4;
  50. } __attribute__ ((packed)) bits;
  51. };
  52. union IO_APIC_reg_03 {
  53. u32 raw;
  54. struct {
  55. u32 boot_DT : 1,
  56. __reserved_1 : 31;
  57. } __attribute__ ((packed)) bits;
  58. };
  59. struct IO_APIC_route_entry {
  60. __u32 vector : 8,
  61. delivery_mode : 3, /* 000: FIXED
  62. * 001: lowest prio
  63. * 111: ExtINT
  64. */
  65. dest_mode : 1, /* 0: physical, 1: logical */
  66. delivery_status : 1,
  67. polarity : 1,
  68. irr : 1,
  69. trigger : 1, /* 0: edge, 1: level */
  70. mask : 1, /* 0: enabled, 1: disabled */
  71. __reserved_2 : 15;
  72. __u32 __reserved_3 : 24,
  73. dest : 8;
  74. } __attribute__ ((packed));
  75. struct IR_IO_APIC_route_entry {
  76. __u64 vector : 8,
  77. zero : 3,
  78. index2 : 1,
  79. delivery_status : 1,
  80. polarity : 1,
  81. irr : 1,
  82. trigger : 1,
  83. mask : 1,
  84. reserved : 31,
  85. format : 1,
  86. index : 15;
  87. } __attribute__ ((packed));
  88. struct irq_alloc_info;
  89. struct irq_data;
  90. #define IOAPIC_AUTO -1
  91. #define IOAPIC_EDGE 0
  92. #define IOAPIC_LEVEL 1
  93. #define IOAPIC_MAP_ALLOC 0x1
  94. #define IOAPIC_MAP_CHECK 0x2
  95. #ifdef CONFIG_X86_IO_APIC
  96. /*
  97. * # of IO-APICs and # of IRQ routing registers
  98. */
  99. extern int nr_ioapics;
  100. extern int mpc_ioapic_id(int ioapic);
  101. extern unsigned int mpc_ioapic_addr(int ioapic);
  102. extern struct mp_ioapic_gsi *mp_ioapic_gsi_routing(int ioapic);
  103. #define MP_MAX_IOAPIC_PIN 127
  104. /* # of MP IRQ source entries */
  105. extern int mp_irq_entries;
  106. /* MP IRQ source entries */
  107. extern struct mpc_intsrc mp_irqs[MAX_IRQ_SOURCES];
  108. /* Older SiS APIC requires we rewrite the index register */
  109. extern int sis_apic_bug;
  110. /* 1 if "noapic" boot option passed */
  111. extern int skip_ioapic_setup;
  112. /* 1 if "noapic" boot option passed */
  113. extern int noioapicquirk;
  114. /* -1 if "noapic" boot option passed */
  115. extern int noioapicreroute;
  116. extern unsigned long io_apic_irqs;
  117. #define IO_APIC_IRQ(x) (((x) >= NR_IRQS_LEGACY) || ((1 << (x)) & io_apic_irqs))
  118. /*
  119. * If we use the IO-APIC for IRQ routing, disable automatic
  120. * assignment of PCI IRQ's.
  121. */
  122. #define io_apic_assign_pci_irqs \
  123. (mp_irq_entries && !skip_ioapic_setup && io_apic_irqs)
  124. struct irq_cfg;
  125. extern void ioapic_insert_resources(void);
  126. extern int arch_early_ioapic_init(void);
  127. extern void eoi_ioapic_irq(unsigned int irq, struct irq_cfg *cfg);
  128. extern void native_eoi_ioapic_pin(int apic, int pin, int vector);
  129. extern int save_ioapic_entries(void);
  130. extern void mask_ioapic_entries(void);
  131. extern int restore_ioapic_entries(void);
  132. extern void setup_ioapic_ids_from_mpc(void);
  133. extern void setup_ioapic_ids_from_mpc_nocheck(void);
  134. struct io_apic_irq_attr {
  135. int ioapic;
  136. int ioapic_pin;
  137. int trigger;
  138. int polarity;
  139. };
  140. enum ioapic_domain_type {
  141. IOAPIC_DOMAIN_INVALID,
  142. IOAPIC_DOMAIN_LEGACY,
  143. IOAPIC_DOMAIN_STRICT,
  144. IOAPIC_DOMAIN_DYNAMIC,
  145. };
  146. struct device_node;
  147. struct irq_domain;
  148. struct irq_domain_ops;
  149. struct ioapic_domain_cfg {
  150. enum ioapic_domain_type type;
  151. const struct irq_domain_ops *ops;
  152. struct device_node *dev;
  153. };
  154. struct mp_ioapic_gsi{
  155. u32 gsi_base;
  156. u32 gsi_end;
  157. };
  158. extern u32 gsi_top;
  159. extern int mp_find_ioapic(u32 gsi);
  160. extern int mp_find_ioapic_pin(int ioapic, u32 gsi);
  161. extern u32 mp_pin_to_gsi(int ioapic, int pin);
  162. extern int mp_map_gsi_to_irq(u32 gsi, unsigned int flags,
  163. struct irq_alloc_info *info);
  164. extern void mp_unmap_irq(int irq);
  165. extern int mp_register_ioapic(int id, u32 address, u32 gsi_base,
  166. struct ioapic_domain_cfg *cfg);
  167. extern int mp_unregister_ioapic(u32 gsi_base);
  168. extern int mp_ioapic_registered(u32 gsi_base);
  169. extern int mp_irqdomain_alloc(struct irq_domain *domain, unsigned int virq,
  170. unsigned int nr_irqs, void *arg);
  171. extern void mp_irqdomain_free(struct irq_domain *domain, unsigned int virq,
  172. unsigned int nr_irqs);
  173. extern void mp_irqdomain_activate(struct irq_domain *domain,
  174. struct irq_data *irq_data);
  175. extern void mp_irqdomain_deactivate(struct irq_domain *domain,
  176. struct irq_data *irq_data);
  177. extern int mp_irqdomain_ioapic_idx(struct irq_domain *domain);
  178. extern void ioapic_set_alloc_attr(struct irq_alloc_info *info,
  179. int node, int trigger, int polarity);
  180. extern void mp_save_irq(struct mpc_intsrc *m);
  181. extern void disable_ioapic_support(void);
  182. extern void __init native_io_apic_init_mappings(void);
  183. extern unsigned int native_io_apic_read(unsigned int apic, unsigned int reg);
  184. extern void native_io_apic_write(unsigned int apic, unsigned int reg, unsigned int val);
  185. extern void native_io_apic_modify(unsigned int apic, unsigned int reg, unsigned int val);
  186. extern void native_disable_io_apic(void);
  187. extern int native_ioapic_set_affinity(struct irq_data *,
  188. const struct cpumask *,
  189. bool);
  190. static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg)
  191. {
  192. return x86_io_apic_ops.read(apic, reg);
  193. }
  194. static inline void io_apic_write(unsigned int apic, unsigned int reg, unsigned int value)
  195. {
  196. x86_io_apic_ops.write(apic, reg, value);
  197. }
  198. static inline void io_apic_modify(unsigned int apic, unsigned int reg, unsigned int value)
  199. {
  200. x86_io_apic_ops.modify(apic, reg, value);
  201. }
  202. extern void io_apic_eoi(unsigned int apic, unsigned int vector);
  203. extern void setup_IO_APIC(void);
  204. extern void enable_IO_APIC(void);
  205. extern void disable_IO_APIC(void);
  206. extern void setup_ioapic_dest(void);
  207. extern int IO_APIC_get_PCI_irq_vector(int bus, int devfn, int pin);
  208. extern void print_IO_APICs(void);
  209. #else /* !CONFIG_X86_IO_APIC */
  210. #define IO_APIC_IRQ(x) 0
  211. #define io_apic_assign_pci_irqs 0
  212. #define setup_ioapic_ids_from_mpc x86_init_noop
  213. static inline void ioapic_insert_resources(void) { }
  214. static inline int arch_early_ioapic_init(void) { return 0; }
  215. static inline void print_IO_APICs(void) {}
  216. #define gsi_top (NR_IRQS_LEGACY)
  217. static inline int mp_find_ioapic(u32 gsi) { return 0; }
  218. static inline u32 mp_pin_to_gsi(int ioapic, int pin) { return UINT_MAX; }
  219. static inline int mp_map_gsi_to_irq(u32 gsi, unsigned int flags,
  220. struct irq_alloc_info *info)
  221. {
  222. return gsi;
  223. }
  224. static inline void mp_unmap_irq(int irq) { }
  225. static inline int save_ioapic_entries(void)
  226. {
  227. return -ENOMEM;
  228. }
  229. static inline void mask_ioapic_entries(void) { }
  230. static inline int restore_ioapic_entries(void)
  231. {
  232. return -ENOMEM;
  233. }
  234. static inline void mp_save_irq(struct mpc_intsrc *m) { };
  235. static inline void disable_ioapic_support(void) { }
  236. #define native_io_apic_init_mappings NULL
  237. #define native_io_apic_read NULL
  238. #define native_io_apic_write NULL
  239. #define native_io_apic_modify NULL
  240. #define native_disable_io_apic NULL
  241. #define native_ioapic_set_affinity NULL
  242. #define native_eoi_ioapic_pin NULL
  243. static inline void setup_IO_APIC(void) { }
  244. static inline void enable_IO_APIC(void) { }
  245. static inline void setup_ioapic_dest(void) { }
  246. #endif
  247. #endif /* _ASM_X86_IO_APIC_H */