]> git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/ata/drvApplePIIXATA/AppleATAPIIXTiming.h
xnu-201.42.3.tar.gz
[apple/xnu.git] / iokit / Drivers / ata / drvApplePIIXATA / AppleATAPIIXTiming.h
1 /*
2 * Copyright (c) 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) 2000 Apple Computer, Inc. All rights reserved.
24 *
25 * AppleATAPIIXTiming.h - Timing tables.
26 *
27 * HISTORY
28 *
29 */
30
31 #ifndef _APPLEATAPIIXTIMING_H
32 #define _APPLEATAPIIXTIMING_H
33
34 /*
35 * Supported transfer protocols. Entries in this table must map to the
36 * entries in ATATimingProtocol table.
37 */
38 typedef enum {
39 kPIIXProtocolPIO = 0,
40 kPIIXProtocolDMA,
41 kPIIXProtocolUDMA33,
42 kPIIXProtocolUDMA66,
43 kPIIXProtocolLast
44 } PIIXProtocol;
45
46 /*
47 * PIIX PIO/DMA timing table.
48 */
49 typedef struct {
50 UInt8 pioMode; // PIO mode
51 UInt8 swDMAMode; // single-word DMA mode (obsolete)
52 UInt8 mwDMAMode; // multiword DMA mode
53 UInt8 isp; // IORDY sample point in PCI clocks
54 UInt8 rtc; // Recovery time in PCI clocks
55 UInt16 cycle; // cycle time in ns
56 } PIIXTiming;
57
58 #define _NVM_ 0xff // not a valid mode
59
60 static const
61 PIIXTiming PIIXPIOTimingTable[] = {
62 /* PIO SW MW ISP RTC CYCLE (ns) */
63 {0, 0, 0, 5, 4, 600},
64 {1, 1, _NVM_, 5, 4, 600},
65 {2, 2, _NVM_, 4, 4, 240},
66 {3, _NVM_, 1, 3, 3, 180},
67 {4, _NVM_, 2, 3, 1, 120},
68 {5, _NVM_, 2, 3, 1, 120},
69 };
70
71 static const UInt8 PIIXPIOTimingTableSize = sizeof(PIIXPIOTimingTable) /
72 sizeof(PIIXPIOTimingTable[0]);
73
74 /*
75 * PIIX Ultra-DMA/33 timing table.
76 */
77 typedef struct {
78 UInt8 mode; // mode number
79 UInt8 ct; // cycle time in PCI clocks
80 UInt8 rp; // Ready to Pause time in PCI clocks
81 UInt8 bits; // register bit setting
82 UInt16 strobe; // strobe period (cycle) in ns
83 } PIIXUDMATiming;
84
85 static const
86 PIIXUDMATiming PIIXUDMATimingTable[] = {
87 /* MODE CT RP BITS STROBE/CYCLE (ns) */
88 {0, 4, 6, 0, 120},
89 {1, 3, 5, 1, 90},
90 {2, 2, 4, 2, 60},
91 };
92
93 static const UInt8
94 PIIXUDMATimingTableSize = sizeof(PIIXUDMATimingTable) /
95 sizeof(PIIXUDMATimingTable[0]);
96
97 /*
98 * For each drive, the following table will store the chosen timings
99 * for each supported protocol.
100 */
101 typedef struct {
102 UInt8 activeTimings[kPIIXProtocolLast]; // selected timings
103 UInt8 validTimings[kPIIXProtocolLast]; // calculated timings
104 UInt32 validFlag;
105 UInt32 activeFlag;
106 } PIIXSelectedTimings;
107
108 /*
109 * Convert from ATATimingProtocol to PIIXProtocol.
110 */
111 inline PIIXProtocol ataToPIIXProtocol(ATATimingProtocol timingProtocol)
112 {
113 int piixProtocol = kPIIXProtocolPIO;
114 int ataProtocol = timingProtocol;
115
116 while (ataProtocol != 1) {
117 ataProtocol >>= 1; piixProtocol++;
118 }
119 return ((PIIXProtocol) piixProtocol);
120 }
121
122 /*
123 * Misc macros to get information from the PIIXSelectedTimings table.
124 */
125 #define PIIX_ACTIVATE_PROTOCOL(p) { \
126 timings[unit].activeTimings[p] = timings[unit].validTimings[p]; \
127 timings[unit].activeFlag |= (1 << (p)); \
128 }
129
130 #define PIIX_DEACTIVATE_PROTOCOL(p) { \
131 timings[unit].activeFlag &= ~(1 << (p)); \
132 }
133
134 #define PIIX_GET_ACTIVE_TIMING(p) (timings[unit].activeTimings[p])
135
136 #define PIIX_PROTOCOL_IS_ACTIVE(p) ((bool) \
137 (timings[unit].activeFlag & (1 << (p))))
138
139 #define PIIX_PROTOCOL_IS_VALID(p) ((bool) \
140 (timings[unit].validFlag & (1 << (p))))
141
142 #endif /* !_APPLEATAPIIXTIMING_H */