]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/platform/drvAppleIntelClassicPIC/AppleIntelClassicPIC.h
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
32 #ifndef _IOKIT_APPLEINTELCLASSICPIC_H
33 #define _IOKIT_APPLEINTELCLASSICPIC_H
35 #include <IOKit/IOInterrupts.h>
36 #include <IOKit/IOInterruptController.h>
38 #define kClockIRQ 0 // FIXME for SMP systems.
40 #define kPIC1BasePort 0x20
41 #define kPIC2BasePort 0xa0
43 #define kPIC1TriggerTypePort 0x4d0
44 #define kPIC2TriggerTypePort 0x4d1
46 #define kPICCmdPortOffset 0
47 #define kPICDataPortOffset 1
49 #define kEOICommand 0x20
51 #define kPICSlaveID 2 // Slave ID for second PIC
53 #define kNumVectors 16
55 #define IS_SLAVE_VECTOR(x) ((x) & 8)
59 #define kPIC_ICW1(x) ((x) + kPICCmdPortOffset)
60 #define kPIC_ICW1_MBO 0x10 // must be one
61 #define kPIC_ICW1_LTIM 0x08 // level/edge triggered mode
62 #define kPIC_ICW1_ADI 0x04 // 4/8 byte call address interval
63 #define kPIC_ICW1_SNGL 0x02 // single/cascade mode
64 #define kPIC_ICW1_IC4 0x01 // ICW4 needed/not needed
66 // ICW2 - Interrupt vector address (bits 7 - 3).
68 #define kPIC_ICW2(x) ((x) + kPICDataPortOffset)
70 // ICW3 - Slave device.
72 #define kPIC_ICW3(x) ((x) + kPICDataPortOffset)
76 #define kPIC_ICW4(x) ((x) + kPICDataPortOffset)
77 #define kPIC_ICW4_SFNM 0x10 // special fully nested mode
78 #define kPIC_ICW4_BUF 0x08 // buffered mode
79 #define kPIC_ICW4_MS 0x04 // master/slave
80 #define kPIC_ICW4_AEOI 0x02 // automatic end of interrupt mode
81 #define kPIC_ICW4_uPM 0x01 // 8088 (vs. 8085) operation
83 // OCW1 - Interrupt mask.
85 #define kPIC_OCW1(x) ((x) + kPICDataPortOffset)
87 // OCW2 - Bit 4 must be zero.
89 #define kPIC_OCW2(x) ((x) + kPICCmdPortOffset)
90 #define kPIC_OCW2_R 0x80 // rotation
91 #define kPIC_OCW2_SL 0x40 // specific
92 #define kPIC_OCW2_EOI 0x20
93 #define kPIC_OCW2_LEVEL(x) ((x) & 0x07)
95 // OCW3 - Bit 4 must be zero.
97 #define kPIC_OCW3(x) ((x) + kPICCmdPortOffset)
98 #define kPIC_OCW3_ESMM 0x40 // special mask mode
99 #define kPIC_OCW3_SMM 0x20
100 #define kPIC_OCW3_MBO 0x08 // must be one
101 #define kPIC_OCW3_P 0x04 // poll
102 #define kPIC_OCW3_RR 0x02
103 #define kPIC_OCW3_RIS 0x01
106 class AppleIntelClassicPIC
: public IOInterruptController
108 OSDeclareDefaultStructors( AppleIntelClassicPIC
);
111 volatile UInt16 maskInterrupts
; /* Which interrupts are masked out */
112 UInt16 triggerTypes
; /* Interrupt trigger type mask */
114 inline int getTriggerType(long irq
)
116 return ( triggerTypes
& (1 << irq
) ) ?
117 kIOInterruptTypeLevel
: kIOInterruptTypeEdge
;
120 inline void updateMask(long irq
)
122 if ( IS_SLAVE_VECTOR(irq
) )
123 outb( kPIC_OCW1(kPIC2BasePort
), maskInterrupts
>> 8 );
125 outb( kPIC_OCW1(kPIC1BasePort
), maskInterrupts
& 0xff );
128 inline void disableInterrupt(long irq
)
130 maskInterrupts
|= (1 << irq
);
134 inline void enableInterrupt(long irq
)
136 maskInterrupts
&= ~(1 << irq
);
140 inline void ackInterrupt(long irq
)
142 if ( IS_SLAVE_VECTOR(irq
) )
143 outb( kPIC_OCW2(kPIC2BasePort
), kEOICommand
);
144 outb( kPIC_OCW2(kPIC1BasePort
), kEOICommand
);
147 virtual void initializePIC(UInt16 port
,
148 UInt8 icw1
, UInt8 icw2
,
149 UInt8 icw3
, UInt8 icw4
);
152 virtual bool start(IOService
* provider
);
153 virtual void free(void);
155 // Methods that must be implemented by simplifed interrupt controllers.
157 virtual int getVectorType(long vectorNumber
, IOInterruptVector
* vector
);
158 virtual IOInterruptAction
getInterruptHandlerAddress(void);
159 virtual IOReturn
handleInterrupt(void * refCon
, IOService
* nub
, int source
);
160 virtual bool vectorCanBeShared(long vectorNumber
, IOInterruptVector
* vector
);
161 virtual void initVector(long vectorNumber
, IOInterruptVector
* vector
);
162 virtual void disableVectorHard(long vectorNumber
, IOInterruptVector
* vector
);
163 virtual void enableVector(long vectorNumber
, IOInterruptVector
* vector
);
166 #endif /* ! _IOKIT_APPLEINTELCLASSICPIC_H */