]> git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/platform/drvAppleIntelClassicPIC/AppleIntelClassicPIC.h
xnu-344.49.tar.gz
[apple/xnu.git] / iokit / Drivers / platform / drvAppleIntelClassicPIC / AppleIntelClassicPIC.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
27 *
28 * DRI: Josh de Cesare
29 *
30 */
31
32 #ifndef _IOKIT_APPLEINTELCLASSICPIC_H
33 #define _IOKIT_APPLEINTELCLASSICPIC_H
34
35 #include <IOKit/IOInterrupts.h>
36 #include <IOKit/IOInterruptController.h>
37
38 #define kClockIRQ 0 // FIXME for SMP systems.
39
40 #define kPIC1BasePort 0x20
41 #define kPIC2BasePort 0xa0
42
43 #define kPIC1TriggerTypePort 0x4d0
44 #define kPIC2TriggerTypePort 0x4d1
45
46 #define kPICCmdPortOffset 0
47 #define kPICDataPortOffset 1
48
49 #define kEOICommand 0x20
50
51 #define kPICSlaveID 2 // Slave ID for second PIC
52
53 #define kNumVectors 16
54
55 #define IS_SLAVE_VECTOR(x) ((x) & 8)
56
57 // ICW1
58 //
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
65
66 // ICW2 - Interrupt vector address (bits 7 - 3).
67 //
68 #define kPIC_ICW2(x) ((x) + kPICDataPortOffset)
69
70 // ICW3 - Slave device.
71 //
72 #define kPIC_ICW3(x) ((x) + kPICDataPortOffset)
73
74 // ICW4
75 //
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
82
83 // OCW1 - Interrupt mask.
84 //
85 #define kPIC_OCW1(x) ((x) + kPICDataPortOffset)
86
87 // OCW2 - Bit 4 must be zero.
88 //
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)
94
95 // OCW3 - Bit 4 must be zero.
96 //
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
104
105
106 class AppleIntelClassicPIC : public IOInterruptController
107 {
108 OSDeclareDefaultStructors( AppleIntelClassicPIC );
109
110 protected:
111 volatile UInt16 maskInterrupts; /* Which interrupts are masked out */
112 UInt16 triggerTypes; /* Interrupt trigger type mask */
113
114 inline int getTriggerType(long irq)
115 {
116 return ( triggerTypes & (1 << irq) ) ?
117 kIOInterruptTypeLevel : kIOInterruptTypeEdge;
118 }
119
120 inline void updateMask(long irq)
121 {
122 if ( IS_SLAVE_VECTOR(irq) )
123 outb( kPIC_OCW1(kPIC2BasePort), maskInterrupts >> 8 );
124 else
125 outb( kPIC_OCW1(kPIC1BasePort), maskInterrupts & 0xff );
126 }
127
128 inline void disableInterrupt(long irq)
129 {
130 maskInterrupts |= (1 << irq);
131 updateMask(irq);
132 }
133
134 inline void enableInterrupt(long irq)
135 {
136 maskInterrupts &= ~(1 << irq);
137 updateMask(irq);
138 }
139
140 inline void ackInterrupt(long irq)
141 {
142 if ( IS_SLAVE_VECTOR(irq) )
143 outb( kPIC_OCW2(kPIC2BasePort), kEOICommand );
144 outb( kPIC_OCW2(kPIC1BasePort), kEOICommand );
145 }
146
147 virtual void initializePIC(UInt16 port,
148 UInt8 icw1, UInt8 icw2,
149 UInt8 icw3, UInt8 icw4);
150
151 public:
152 virtual bool start(IOService * provider);
153 virtual void free(void);
154
155 // Methods that must be implemented by simplifed interrupt controllers.
156
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);
164 };
165
166 #endif /* ! _IOKIT_APPLEINTELCLASSICPIC_H */