18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_I8259_H 38c2ecf20Sopenharmony_ci#define _ASM_X86_I8259_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/delay.h> 68c2ecf20Sopenharmony_ci#include <asm/io.h> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ciextern unsigned int cached_irq_mask; 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#define __byte(x, y) (((unsigned char *)&(y))[x]) 118c2ecf20Sopenharmony_ci#define cached_master_mask (__byte(0, cached_irq_mask)) 128c2ecf20Sopenharmony_ci#define cached_slave_mask (__byte(1, cached_irq_mask)) 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* i8259A PIC registers */ 158c2ecf20Sopenharmony_ci#define PIC_MASTER_CMD 0x20 168c2ecf20Sopenharmony_ci#define PIC_MASTER_IMR 0x21 178c2ecf20Sopenharmony_ci#define PIC_MASTER_ISR PIC_MASTER_CMD 188c2ecf20Sopenharmony_ci#define PIC_MASTER_POLL PIC_MASTER_ISR 198c2ecf20Sopenharmony_ci#define PIC_MASTER_OCW3 PIC_MASTER_ISR 208c2ecf20Sopenharmony_ci#define PIC_SLAVE_CMD 0xa0 218c2ecf20Sopenharmony_ci#define PIC_SLAVE_IMR 0xa1 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci/* i8259A PIC related value */ 248c2ecf20Sopenharmony_ci#define PIC_CASCADE_IR 2 258c2ecf20Sopenharmony_ci#define MASTER_ICW4_DEFAULT 0x01 268c2ecf20Sopenharmony_ci#define SLAVE_ICW4_DEFAULT 0x01 278c2ecf20Sopenharmony_ci#define PIC_ICW4_AEOI 2 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ciextern raw_spinlock_t i8259A_lock; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/* the PIC may need a careful delay on some platforms, hence specific calls */ 328c2ecf20Sopenharmony_cistatic inline unsigned char inb_pic(unsigned int port) 338c2ecf20Sopenharmony_ci{ 348c2ecf20Sopenharmony_ci unsigned char value = inb(port); 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci /* 378c2ecf20Sopenharmony_ci * delay for some accesses to PIC on motherboard or in chipset 388c2ecf20Sopenharmony_ci * must be at least one microsecond, so be safe here: 398c2ecf20Sopenharmony_ci */ 408c2ecf20Sopenharmony_ci udelay(2); 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci return value; 438c2ecf20Sopenharmony_ci} 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistatic inline void outb_pic(unsigned char value, unsigned int port) 468c2ecf20Sopenharmony_ci{ 478c2ecf20Sopenharmony_ci outb(value, port); 488c2ecf20Sopenharmony_ci /* 498c2ecf20Sopenharmony_ci * delay for some accesses to PIC on motherboard or in chipset 508c2ecf20Sopenharmony_ci * must be at least one microsecond, so be safe here: 518c2ecf20Sopenharmony_ci */ 528c2ecf20Sopenharmony_ci udelay(2); 538c2ecf20Sopenharmony_ci} 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ciextern struct irq_chip i8259A_chip; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cistruct legacy_pic { 588c2ecf20Sopenharmony_ci int nr_legacy_irqs; 598c2ecf20Sopenharmony_ci struct irq_chip *chip; 608c2ecf20Sopenharmony_ci void (*mask)(unsigned int irq); 618c2ecf20Sopenharmony_ci void (*unmask)(unsigned int irq); 628c2ecf20Sopenharmony_ci void (*mask_all)(void); 638c2ecf20Sopenharmony_ci void (*restore_mask)(void); 648c2ecf20Sopenharmony_ci void (*init)(int auto_eoi); 658c2ecf20Sopenharmony_ci int (*probe)(void); 668c2ecf20Sopenharmony_ci int (*irq_pending)(unsigned int irq); 678c2ecf20Sopenharmony_ci void (*make_irq)(unsigned int irq); 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_civoid legacy_pic_pcat_compat(void); 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ciextern struct legacy_pic *legacy_pic; 738c2ecf20Sopenharmony_ciextern struct legacy_pic null_legacy_pic; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistatic inline bool has_legacy_pic(void) 768c2ecf20Sopenharmony_ci{ 778c2ecf20Sopenharmony_ci return legacy_pic != &null_legacy_pic; 788c2ecf20Sopenharmony_ci} 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistatic inline int nr_legacy_irqs(void) 818c2ecf20Sopenharmony_ci{ 828c2ecf20Sopenharmony_ci return legacy_pic->nr_legacy_irqs; 838c2ecf20Sopenharmony_ci} 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#endif /* _ASM_X86_I8259_H */ 86