Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 2 | #ifndef _ASM_X86_I8259_H |
| 3 | #define _ASM_X86_I8259_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | |
David P. Reed | bc0a733 | 2008-02-18 13:58:34 -0500 | [diff] [blame] | 5 | #include <linux/delay.h> |
Guenter Roeck | 0a957467 | 2018-08-15 13:22:27 -0700 | [diff] [blame] | 6 | #include <asm/io.h> |
David P. Reed | bc0a733 | 2008-02-18 13:58:34 -0500 | [diff] [blame] | 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | extern unsigned int cached_irq_mask; |
| 9 | |
Joe Perches | ace4fdb | 2008-03-23 01:02:19 -0700 | [diff] [blame] | 10 | #define __byte(x, y) (((unsigned char *)&(y))[x]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #define cached_master_mask (__byte(0, cached_irq_mask)) |
| 12 | #define cached_slave_mask (__byte(1, cached_irq_mask)) |
| 13 | |
Thomas Gleixner | f20ebee | 2008-01-30 13:30:29 +0100 | [diff] [blame] | 14 | /* i8259A PIC registers */ |
| 15 | #define PIC_MASTER_CMD 0x20 |
| 16 | #define PIC_MASTER_IMR 0x21 |
| 17 | #define PIC_MASTER_ISR PIC_MASTER_CMD |
| 18 | #define PIC_MASTER_POLL PIC_MASTER_ISR |
| 19 | #define PIC_MASTER_OCW3 PIC_MASTER_ISR |
| 20 | #define PIC_SLAVE_CMD 0xa0 |
| 21 | #define PIC_SLAVE_IMR 0xa1 |
Maciej W. Rozycki | d253166 | 2021-07-20 05:28:09 +0200 | [diff] [blame] | 22 | #define PIC_ELCR1 0x4d0 |
| 23 | #define PIC_ELCR2 0x4d1 |
Thomas Gleixner | f20ebee | 2008-01-30 13:30:29 +0100 | [diff] [blame] | 24 | |
| 25 | /* i8259A PIC related value */ |
| 26 | #define PIC_CASCADE_IR 2 |
| 27 | #define MASTER_ICW4_DEFAULT 0x01 |
| 28 | #define SLAVE_ICW4_DEFAULT 0x01 |
| 29 | #define PIC_ICW4_AEOI 2 |
| 30 | |
Thomas Gleixner | 5619c28 | 2009-07-25 18:35:11 +0200 | [diff] [blame] | 31 | extern raw_spinlock_t i8259A_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
David P. Reed | bc0a733 | 2008-02-18 13:58:34 -0500 | [diff] [blame] | 33 | /* the PIC may need a careful delay on some platforms, hence specific calls */ |
| 34 | static inline unsigned char inb_pic(unsigned int port) |
| 35 | { |
| 36 | unsigned char value = inb(port); |
| 37 | |
| 38 | /* |
| 39 | * delay for some accesses to PIC on motherboard or in chipset |
| 40 | * must be at least one microsecond, so be safe here: |
| 41 | */ |
| 42 | udelay(2); |
| 43 | |
| 44 | return value; |
| 45 | } |
| 46 | |
| 47 | static inline void outb_pic(unsigned char value, unsigned int port) |
| 48 | { |
| 49 | outb(value, port); |
| 50 | /* |
| 51 | * delay for some accesses to PIC on motherboard or in chipset |
| 52 | * must be at least one microsecond, so be safe here: |
| 53 | */ |
| 54 | udelay(2); |
| 55 | } |
Alan Cox | 466eed2 | 2008-01-30 13:33:14 +0100 | [diff] [blame] | 56 | |
Pavel Machek | 40bd217 | 2008-05-21 11:44:02 +0200 | [diff] [blame] | 57 | extern struct irq_chip i8259A_chip; |
| 58 | |
Jacob Pan | ef35486 | 2009-11-09 11:24:14 -0800 | [diff] [blame] | 59 | struct legacy_pic { |
| 60 | int nr_legacy_irqs; |
| 61 | struct irq_chip *chip; |
Thomas Gleixner | 4305df9 | 2010-09-28 15:01:33 +0200 | [diff] [blame] | 62 | void (*mask)(unsigned int irq); |
| 63 | void (*unmask)(unsigned int irq); |
Jacob Pan | ef35486 | 2009-11-09 11:24:14 -0800 | [diff] [blame] | 64 | void (*mask_all)(void); |
| 65 | void (*restore_mask)(void); |
| 66 | void (*init)(int auto_eoi); |
Vitaly Kuznetsov | 8c058b0 | 2015-11-03 10:40:14 +0100 | [diff] [blame] | 67 | int (*probe)(void); |
Jacob Pan | ef35486 | 2009-11-09 11:24:14 -0800 | [diff] [blame] | 68 | int (*irq_pending)(unsigned int irq); |
| 69 | void (*make_irq)(unsigned int irq); |
| 70 | }; |
| 71 | |
| 72 | extern struct legacy_pic *legacy_pic; |
| 73 | extern struct legacy_pic null_legacy_pic; |
| 74 | |
Peter Zijlstra | 30c7e5b | 2017-12-22 10:20:11 +0100 | [diff] [blame] | 75 | static inline bool has_legacy_pic(void) |
| 76 | { |
| 77 | return legacy_pic != &null_legacy_pic; |
| 78 | } |
| 79 | |
Jiang Liu | 95d76ac | 2014-06-09 16:19:48 +0800 | [diff] [blame] | 80 | static inline int nr_legacy_irqs(void) |
| 81 | { |
| 82 | return legacy_pic->nr_legacy_irqs; |
| 83 | } |
| 84 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 85 | #endif /* _ASM_X86_I8259_H */ |