H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_IO_APIC_H |
| 2 | #define _ASM_X86_IO_APIC_H |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 3 | |
Akinobu Mita | a1a33fa | 2008-04-19 23:55:13 +0900 | [diff] [blame] | 4 | #include <linux/types.h> |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 5 | #include <asm/mpspec.h> |
| 6 | #include <asm/apicdef.h> |
Yinghai Lu | 9d6a4d0 | 2008-08-19 20:50:52 -0700 | [diff] [blame] | 7 | #include <asm/irq_vectors.h> |
Konrad Rzeszutek Wilk | 4a8e2a3 | 2012-03-28 12:37:36 -0400 | [diff] [blame] | 8 | #include <asm/x86_init.h> |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 9 | /* |
| 10 | * Intel IO-APIC support for SMP and UP systems. |
| 11 | * |
| 12 | * Copyright (C) 1997, 1998, 1999, 2000 Ingo Molnar |
| 13 | */ |
| 14 | |
Cyrill Gorcunov | d3f020d | 2008-06-07 19:53:56 +0400 | [diff] [blame] | 15 | /* I/O Unit Redirection Table */ |
| 16 | #define IO_APIC_REDIR_VECTOR_MASK 0x000FF |
| 17 | #define IO_APIC_REDIR_DEST_LOGICAL 0x00800 |
| 18 | #define IO_APIC_REDIR_DEST_PHYSICAL 0x00000 |
| 19 | #define IO_APIC_REDIR_SEND_PENDING (1 << 12) |
| 20 | #define IO_APIC_REDIR_REMOTE_IRR (1 << 14) |
| 21 | #define IO_APIC_REDIR_LEVEL_TRIGGER (1 << 15) |
| 22 | #define IO_APIC_REDIR_MASKED (1 << 16) |
| 23 | |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 24 | /* |
| 25 | * The structure of the IO-APIC: |
| 26 | */ |
| 27 | union IO_APIC_reg_00 { |
| 28 | u32 raw; |
| 29 | struct { |
| 30 | u32 __reserved_2 : 14, |
| 31 | LTS : 1, |
| 32 | delivery_type : 1, |
| 33 | __reserved_1 : 8, |
| 34 | ID : 8; |
| 35 | } __attribute__ ((packed)) bits; |
| 36 | }; |
| 37 | |
| 38 | union IO_APIC_reg_01 { |
| 39 | u32 raw; |
| 40 | struct { |
| 41 | u32 version : 8, |
| 42 | __reserved_2 : 7, |
| 43 | PRQ : 1, |
| 44 | entries : 8, |
| 45 | __reserved_1 : 8; |
| 46 | } __attribute__ ((packed)) bits; |
| 47 | }; |
| 48 | |
| 49 | union IO_APIC_reg_02 { |
| 50 | u32 raw; |
| 51 | struct { |
| 52 | u32 __reserved_2 : 24, |
| 53 | arbitration : 4, |
| 54 | __reserved_1 : 4; |
| 55 | } __attribute__ ((packed)) bits; |
| 56 | }; |
| 57 | |
| 58 | union IO_APIC_reg_03 { |
| 59 | u32 raw; |
| 60 | struct { |
| 61 | u32 boot_DT : 1, |
| 62 | __reserved_1 : 31; |
| 63 | } __attribute__ ((packed)) bits; |
| 64 | }; |
| 65 | |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 66 | struct IO_APIC_route_entry { |
| 67 | __u32 vector : 8, |
| 68 | delivery_mode : 3, /* 000: FIXED |
| 69 | * 001: lowest prio |
| 70 | * 111: ExtINT |
| 71 | */ |
| 72 | dest_mode : 1, /* 0: physical, 1: logical */ |
| 73 | delivery_status : 1, |
| 74 | polarity : 1, |
| 75 | irr : 1, |
| 76 | trigger : 1, /* 0: edge, 1: level */ |
| 77 | mask : 1, /* 0: enabled, 1: disabled */ |
| 78 | __reserved_2 : 15; |
| 79 | |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 80 | __u32 __reserved_3 : 24, |
| 81 | dest : 8; |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 82 | } __attribute__ ((packed)); |
| 83 | |
Suresh Siddha | 89027d3 | 2008-07-10 11:16:56 -0700 | [diff] [blame] | 84 | struct IR_IO_APIC_route_entry { |
| 85 | __u64 vector : 8, |
| 86 | zero : 3, |
| 87 | index2 : 1, |
| 88 | delivery_status : 1, |
| 89 | polarity : 1, |
| 90 | irr : 1, |
| 91 | trigger : 1, |
| 92 | mask : 1, |
| 93 | reserved : 31, |
| 94 | format : 1, |
| 95 | index : 15; |
| 96 | } __attribute__ ((packed)); |
| 97 | |
Jiang Liu | c4d05a2 | 2015-04-13 14:11:54 +0800 | [diff] [blame] | 98 | struct irq_alloc_info; |
Thomas Gleixner | f7a0c78 | 2015-04-14 10:30:08 +0800 | [diff] [blame^] | 99 | struct ioapic_domain_cfg; |
Jiang Liu | c4d05a2 | 2015-04-13 14:11:54 +0800 | [diff] [blame] | 100 | |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 101 | #define IOAPIC_AUTO -1 |
| 102 | #define IOAPIC_EDGE 0 |
| 103 | #define IOAPIC_LEVEL 1 |
| 104 | |
| 105 | #define IOAPIC_MASKED 1 |
| 106 | #define IOAPIC_UNMASKED 0 |
| 107 | |
| 108 | #define IOAPIC_POL_HIGH 0 |
| 109 | #define IOAPIC_POL_LOW 1 |
| 110 | |
| 111 | #define IOAPIC_DEST_MODE_PHYSICAL 0 |
| 112 | #define IOAPIC_DEST_MODE_LOGICAL 1 |
| 113 | |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 114 | #define IOAPIC_MAP_ALLOC 0x1 |
| 115 | #define IOAPIC_MAP_CHECK 0x2 |
Thomas Gleixner | abb0052 | 2011-02-23 19:54:53 +0100 | [diff] [blame] | 116 | |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 117 | #ifdef CONFIG_X86_IO_APIC |
| 118 | |
| 119 | /* |
| 120 | * # of IO-APICs and # of IRQ routing registers |
| 121 | */ |
| 122 | extern int nr_ioapics; |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 123 | |
Suresh Siddha | d537143 | 2011-05-18 16:31:37 -0700 | [diff] [blame] | 124 | extern int mpc_ioapic_id(int ioapic); |
| 125 | extern unsigned int mpc_ioapic_addr(int ioapic); |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 126 | |
| 127 | /* # of MP IRQ source entries */ |
| 128 | extern int mp_irq_entries; |
| 129 | |
| 130 | /* MP IRQ source entries */ |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 131 | extern struct mpc_intsrc mp_irqs[MAX_IRQ_SOURCES]; |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 132 | |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 133 | /* 1 if "noapic" boot option passed */ |
| 134 | extern int skip_ioapic_setup; |
| 135 | |
Ingo Molnar | 7a9787e | 2008-10-28 16:26:12 +0100 | [diff] [blame] | 136 | /* 1 if "noapic" boot option passed */ |
| 137 | extern int noioapicquirk; |
| 138 | |
| 139 | /* -1 if "noapic" boot option passed */ |
| 140 | extern int noioapicreroute; |
| 141 | |
Jiang Liu | 154d9e5 | 2015-04-14 10:29:56 +0800 | [diff] [blame] | 142 | extern u32 gsi_top; |
| 143 | |
Jiang Liu | 8643e28 | 2014-10-27 16:12:04 +0800 | [diff] [blame] | 144 | extern unsigned long io_apic_irqs; |
| 145 | |
| 146 | #define IO_APIC_IRQ(x) (((x) >= NR_IRQS_LEGACY) || ((1 << (x)) & io_apic_irqs)) |
| 147 | |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 148 | /* |
| 149 | * If we use the IO-APIC for IRQ routing, disable automatic |
| 150 | * assignment of PCI IRQ's. |
| 151 | */ |
| 152 | #define io_apic_assign_pci_irqs \ |
| 153 | (mp_irq_entries && !skip_ioapic_setup && io_apic_irqs) |
| 154 | |
Joerg Roedel | 9b1b0e4 | 2012-09-26 12:44:45 +0200 | [diff] [blame] | 155 | struct irq_cfg; |
Yinghai Lu | 857fdc5 | 2009-07-10 09:36:20 -0700 | [diff] [blame] | 156 | extern void ioapic_insert_resources(void); |
Jiang Liu | 11d686e | 2014-10-27 16:12:05 +0800 | [diff] [blame] | 157 | extern int arch_early_ioapic_init(void); |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 158 | |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 159 | extern int save_ioapic_entries(void); |
| 160 | extern void mask_ioapic_entries(void); |
| 161 | extern int restore_ioapic_entries(void); |
Suresh Siddha | 4dc2f96 | 2008-07-10 11:16:47 -0700 | [diff] [blame] | 162 | |
Thomas Gleixner | de93410 | 2009-08-20 09:27:29 +0200 | [diff] [blame] | 163 | extern void setup_ioapic_ids_from_mpc(void); |
Sebastian Andrzej Siewior | a38c538 | 2010-11-26 17:50:20 +0100 | [diff] [blame] | 164 | extern void setup_ioapic_ids_from_mpc_nocheck(void); |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 165 | |
Jiang Liu | 3eb2be5 | 2014-06-09 16:19:39 +0800 | [diff] [blame] | 166 | extern int mp_find_ioapic(u32 gsi); |
| 167 | extern int mp_find_ioapic_pin(int ioapic, u32 gsi); |
Jiang Liu | c4d05a2 | 2015-04-13 14:11:54 +0800 | [diff] [blame] | 168 | extern int mp_map_gsi_to_irq(u32 gsi, unsigned int flags, |
| 169 | struct irq_alloc_info *info); |
Jiang Liu | df334be | 2014-06-09 16:20:06 +0800 | [diff] [blame] | 170 | extern void mp_unmap_irq(int irq); |
Jiang Liu | 35ef9c9 | 2014-10-27 13:21:43 +0800 | [diff] [blame] | 171 | extern int mp_register_ioapic(int id, u32 address, u32 gsi_base, |
| 172 | struct ioapic_domain_cfg *cfg); |
Jiang Liu | 15516a3 | 2014-10-27 13:21:46 +0800 | [diff] [blame] | 173 | extern int mp_unregister_ioapic(u32 gsi_base); |
Jiang Liu | e89900c | 2014-10-27 13:21:47 +0800 | [diff] [blame] | 174 | extern int mp_ioapic_registered(u32 gsi_base); |
Thomas Gleixner | f7a0c78 | 2015-04-14 10:30:08 +0800 | [diff] [blame^] | 175 | |
Jiang Liu | c4d05a2 | 2015-04-13 14:11:54 +0800 | [diff] [blame] | 176 | extern void ioapic_set_alloc_attr(struct irq_alloc_info *info, |
| 177 | int node, int trigger, int polarity); |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 178 | |
Feng Tang | 2d8009b | 2010-11-19 11:33:35 +0800 | [diff] [blame] | 179 | extern void mp_save_irq(struct mpc_intsrc *m); |
| 180 | |
Henrik Kretzschmar | 7167d08 | 2011-02-22 15:38:05 +0100 | [diff] [blame] | 181 | extern void disable_ioapic_support(void); |
| 182 | |
Thomas Gleixner | ca1b886 | 2015-04-24 13:57:48 +0200 | [diff] [blame] | 183 | extern void __init io_apic_init_mappings(void); |
Konrad Rzeszutek Wilk | 4a8e2a3 | 2012-03-28 12:37:36 -0400 | [diff] [blame] | 184 | extern unsigned int native_io_apic_read(unsigned int apic, unsigned int reg); |
Joerg Roedel | 1c4248c | 2012-09-26 12:44:35 +0200 | [diff] [blame] | 185 | extern void native_disable_io_apic(void); |
Konrad Rzeszutek Wilk | 4a8e2a3 | 2012-03-28 12:37:36 -0400 | [diff] [blame] | 186 | |
| 187 | static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg) |
| 188 | { |
| 189 | return x86_io_apic_ops.read(apic, reg); |
| 190 | } |
| 191 | |
Jiang Liu | 8643e28 | 2014-10-27 16:12:04 +0800 | [diff] [blame] | 192 | extern void setup_IO_APIC(void); |
| 193 | extern void enable_IO_APIC(void); |
| 194 | extern void disable_IO_APIC(void); |
| 195 | extern void setup_ioapic_dest(void); |
| 196 | extern int IO_APIC_get_PCI_irq_vector(int bus, int devfn, int pin); |
| 197 | extern void print_IO_APICs(void); |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 198 | #else /* !CONFIG_X86_IO_APIC */ |
Linus Torvalds | 78f28b7 | 2009-09-18 14:05:47 -0700 | [diff] [blame] | 199 | |
Jiang Liu | 8643e28 | 2014-10-27 16:12:04 +0800 | [diff] [blame] | 200 | #define IO_APIC_IRQ(x) 0 |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 201 | #define io_apic_assign_pci_irqs 0 |
Thomas Gleixner | de93410 | 2009-08-20 09:27:29 +0200 | [diff] [blame] | 202 | #define setup_ioapic_ids_from_mpc x86_init_noop |
Yinghai Lu | 857fdc5 | 2009-07-10 09:36:20 -0700 | [diff] [blame] | 203 | static inline void ioapic_insert_resources(void) { } |
Jiang Liu | 11d686e | 2014-10-27 16:12:05 +0800 | [diff] [blame] | 204 | static inline int arch_early_ioapic_init(void) { return 0; } |
Jiang Liu | 8643e28 | 2014-10-27 16:12:04 +0800 | [diff] [blame] | 205 | static inline void print_IO_APICs(void) {} |
Eric W. Biederman | a4384df | 2010-06-08 11:44:32 -0700 | [diff] [blame] | 206 | #define gsi_top (NR_IRQS_LEGACY) |
Eric W. Biederman | eddb0c5 | 2010-03-30 01:07:09 -0700 | [diff] [blame] | 207 | static inline int mp_find_ioapic(u32 gsi) { return 0; } |
Jiang Liu | c4d05a2 | 2015-04-13 14:11:54 +0800 | [diff] [blame] | 208 | static inline int mp_map_gsi_to_irq(u32 gsi, unsigned int flags, |
| 209 | struct irq_alloc_info *info) |
| 210 | { |
| 211 | return gsi; |
| 212 | } |
| 213 | |
Jiang Liu | df334be | 2014-06-09 16:20:06 +0800 | [diff] [blame] | 214 | static inline void mp_unmap_irq(int irq) { } |
Linus Torvalds | 78f28b7 | 2009-09-18 14:05:47 -0700 | [diff] [blame] | 215 | |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 216 | static inline int save_ioapic_entries(void) |
Henrik Kretzschmar | 7d0f192 | 2011-02-22 15:38:06 +0100 | [diff] [blame] | 217 | { |
| 218 | return -ENOMEM; |
| 219 | } |
| 220 | |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 221 | static inline void mask_ioapic_entries(void) { } |
| 222 | static inline int restore_ioapic_entries(void) |
Henrik Kretzschmar | 7d0f192 | 2011-02-22 15:38:06 +0100 | [diff] [blame] | 223 | { |
| 224 | return -ENOMEM; |
| 225 | } |
| 226 | |
Thomas Gleixner | ca1b886 | 2015-04-24 13:57:48 +0200 | [diff] [blame] | 227 | static inline void mp_save_irq(struct mpc_intsrc *m) { } |
Henrik Kretzschmar | 7167d08 | 2011-02-22 15:38:05 +0100 | [diff] [blame] | 228 | static inline void disable_ioapic_support(void) { } |
Thomas Gleixner | ca1b886 | 2015-04-24 13:57:48 +0200 | [diff] [blame] | 229 | static inline void io_apic_init_mappings(void) { } |
Konrad Rzeszutek Wilk | 4a8e2a3 | 2012-03-28 12:37:36 -0400 | [diff] [blame] | 230 | #define native_io_apic_read NULL |
Joerg Roedel | 1c4248c | 2012-09-26 12:44:35 +0200 | [diff] [blame] | 231 | #define native_disable_io_apic NULL |
Thomas Gleixner | 8686608 | 2015-01-15 21:22:30 +0000 | [diff] [blame] | 232 | |
| 233 | static inline void setup_IO_APIC(void) { } |
| 234 | static inline void enable_IO_APIC(void) { } |
| 235 | static inline void setup_ioapic_dest(void) { } |
| 236 | |
Thomas Gleixner | e1d9197 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 237 | #endif |
| 238 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 239 | #endif /* _ASM_X86_IO_APIC_H */ |