]> git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/platform/drvAppleIntelClassicPIC/AppleIntelClassicPIC.h
xnu-123.5.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 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
24 *
25 * DRI: Josh de Cesare
26 *
27 */
28
29 #ifndef _IOKIT_APPLEINTELCLASSICPIC_H
30 #define _IOKIT_APPLEINTELCLASSICPIC_H
31
32 #include <IOKit/IOInterrupts.h>
33 #include <IOKit/IOInterruptController.h>
34
35 #define kClockIRQ 0 // FIXME for SMP systems.
36
37 #define kPIC1BasePort 0x20
38 #define kPIC2BasePort 0xa0
39
40 #define kPIC1TriggerTypePort 0x4d0
41 #define kPIC2TriggerTypePort 0x4d1
42
43 #define kPICCmdPortOffset 0
44 #define kPICDataPortOffset 1
45
46 #define kEOICommand 0x20
47
48 #define kPICSlaveID 2 // Slave ID for second PIC
49
50 #define kNumVectors 16
51
52 #define IS_SLAVE_VECTOR(x) ((x) & 8)
53
54 // ICW1
55 //
56 #define kPIC_ICW1(x) ((x) + kPICCmdPortOffset)
57 #define kPIC_ICW1_MBO 0x10 // must be one
58 #define kPIC_ICW1_LTIM 0x08 // level/edge triggered mode
59 #define kPIC_ICW1_ADI 0x04 // 4/8 byte call address interval
60 #define kPIC_ICW1_SNGL 0x02 // single/cascade mode
61 #define kPIC_ICW1_IC4 0x01 // ICW4 needed/not needed
62
63 // ICW2 - Interrupt vector address (bits 7 - 3).
64 //
65 #define kPIC_ICW2(x) ((x) + kPICDataPortOffset)
66
67 // ICW3 - Slave device.
68 //
69 #define kPIC_ICW3(x) ((x) + kPICDataPortOffset)
70
71 // ICW4
72 //
73 #define kPIC_ICW4(x) ((x) + kPICDataPortOffset)
74 #define kPIC_ICW4_SFNM 0x10 // special fully nested mode
75 #define kPIC_ICW4_BUF 0x08 // buffered mode
76 #define kPIC_ICW4_MS 0x04 // master/slave
77 #define kPIC_ICW4_AEOI 0x02 // automatic end of interrupt mode
78 #define kPIC_ICW4_uPM 0x01 // 8088 (vs. 8085) operation
79
80 // OCW1 - Interrupt mask.
81 //
82 #define kPIC_OCW1(x) ((x) + kPICDataPortOffset)
83
84 // OCW2 - Bit 4 must be zero.
85 //
86 #define kPIC_OCW2(x) ((x) + kPICCmdPortOffset)
87 #define kPIC_OCW2_R 0x80 // rotation
88 #define kPIC_OCW2_SL 0x40 // specific
89 #define kPIC_OCW2_EOI 0x20
90 #define kPIC_OCW2_LEVEL(x) ((x) & 0x07)
91
92 // OCW3 - Bit 4 must be zero.
93 //
94 #define kPIC_OCW3(x) ((x) + kPICCmdPortOffset)
95 #define kPIC_OCW3_ESMM 0x40 // special mask mode
96 #define kPIC_OCW3_SMM 0x20
97 #define kPIC_OCW3_MBO 0x08 // must be one
98 #define kPIC_OCW3_P 0x04 // poll
99 #define kPIC_OCW3_RR 0x02
100 #define kPIC_OCW3_RIS 0x01
101
102
103 class AppleIntelClassicPIC : public IOInterruptController
104 {
105 OSDeclareDefaultStructors( AppleIntelClassicPIC );
106
107 protected:
108 volatile UInt16 maskInterrupts; /* Which interrupts are masked out */
109 UInt16 triggerTypes; /* Interrupt trigger type mask */
110
111 inline int getTriggerType(long irq)
112 {
113 return ( triggerTypes & (1 << irq) ) ?
114 kIOInterruptTypeLevel : kIOInterruptTypeEdge;
115 }
116
117 inline void updateMask(long irq)
118 {
119 if ( IS_SLAVE_VECTOR(irq) )
120 outb( kPIC_OCW1(kPIC2BasePort), maskInterrupts >> 8 );
121 else
122 outb( kPIC_OCW1(kPIC1BasePort), maskInterrupts & 0xff );
123 }
124
125 inline void disableInterrupt(long irq)
126 {
127 maskInterrupts |= (1 << irq);
128 updateMask(irq);
129 }
130
131 inline void enableInterrupt(long irq)
132 {
133 maskInterrupts &= ~(1 << irq);
134 updateMask(irq);
135 }
136
137 inline void ackInterrupt(long irq)
138 {
139 if ( IS_SLAVE_VECTOR(irq) )
140 outb( kPIC_OCW2(kPIC2BasePort), kEOICommand );
141 outb( kPIC_OCW2(kPIC1BasePort), kEOICommand );
142 }
143
144 virtual void initializePIC(UInt16 port,
145 UInt8 icw1, UInt8 icw2,
146 UInt8 icw3, UInt8 icw4);
147
148 public:
149 virtual bool start(IOService * provider);
150 virtual void free(void);
151
152 // Methods that must be implemented by simplifed interrupt controllers.
153
154 virtual int getVectorType(long vectorNumber, IOInterruptVector * vector);
155 virtual IOInterruptAction getInterruptHandlerAddress(void);
156 virtual IOReturn handleInterrupt(void * refCon, IOService * nub, int source);
157 virtual bool vectorCanBeShared(long vectorNumber, IOInterruptVector * vector);
158 virtual void initVector(long vectorNumber, IOInterruptVector * vector);
159 virtual void disableVectorHard(long vectorNumber, IOInterruptVector * vector);
160 virtual void enableVector(long vectorNumber, IOInterruptVector * vector);
161 };
162
163 #endif /* ! _IOKIT_APPLEINTELCLASSICPIC_H */