[363] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
| 2 | ; Description : Functions for initializing QDI Vision
|
---|
| 3 | ; QD6500 and QD6580 VLB IDE Controllers.
|
---|
| 4 |
|
---|
| 5 | ; Section containing code
|
---|
| 6 | SECTION .text
|
---|
| 7 |
|
---|
| 8 | ;--------------------------------------------------------------------
|
---|
[364] | 9 | ; Vision_DetectAndReturnIDinAXandPortInDXifControllerPresent
|
---|
[363] | 10 | ; Parameters:
|
---|
| 11 | ; Nothing
|
---|
| 12 | ; Returns:
|
---|
| 13 | ; AX: ID WORD specific for QDI Vision Controllers
|
---|
| 14 | ; (AL = QD65xx Config Register contents)
|
---|
| 15 | ; (AH = QDI Vision Controller ID (bits 4...7))
|
---|
[364] | 16 | ; DX: Controller port (not IDE port)
|
---|
[363] | 17 | ; ZF: Set if controller found
|
---|
| 18 | ; Cleared if supported controller not found (AX,DX = undefined)
|
---|
| 19 | ; Corrupts registers:
|
---|
| 20 | ; Nothing
|
---|
| 21 | ;--------------------------------------------------------------------
|
---|
[364] | 22 | Vision_DetectAndReturnIDinAXandPortInDXifControllerPresent:
|
---|
[363] | 23 | ; Check QD65xx base port
|
---|
[364] | 24 | mov dx, QD65XX_BASE_PORT
|
---|
[363] | 25 | in al, QD65XX_BASE_PORT + QD65XX_CONFIG_REGISTER_in
|
---|
| 26 | call IsConfigRegisterWithIDinAL
|
---|
| 27 | je SHORT VisionControllerDetected
|
---|
| 28 |
|
---|
| 29 | ; Check QD65xx alternative base port
|
---|
[364] | 30 | or dl, QD65XX_ALTERNATIVE_BASE_PORT
|
---|
[363] | 31 | in al, QD65XX_ALTERNATIVE_BASE_PORT + QD65XX_CONFIG_REGISTER_in
|
---|
| 32 | ; Fall to IsConfigRegisterWithIDinAL
|
---|
| 33 |
|
---|
| 34 | ;--------------------------------------------------------------------
|
---|
| 35 | ; IsConfigRegisterWithIDinAL
|
---|
| 36 | ; Parameters:
|
---|
| 37 | ; AL: Possible QD65xx Config Register contents
|
---|
| 38 | ; Returns:
|
---|
| 39 | ; AH QDI Vision Controller ID or undefined
|
---|
| 40 | ; ZF: Set if controller found
|
---|
| 41 | ; Cleared if supported controller not found (AH = undefined)
|
---|
| 42 | ; Corrupts registers:
|
---|
| 43 | ; Nothing
|
---|
| 44 | ;--------------------------------------------------------------------
|
---|
| 45 | IsConfigRegisterWithIDinAL:
|
---|
| 46 | mov ah, al
|
---|
[370] | 47 | and al, MASK_QDCONFIG_CONTROLLER_ID
|
---|
| 48 | cmp al, ID_QD6500 << 4
|
---|
[363] | 49 | je SHORT VisionControllerDetected
|
---|
[370] | 50 | cmp al, ID_QD6580 << 4
|
---|
[363] | 51 | je SHORT VisionControllerDetected
|
---|
[370] | 52 | cmp al, ID_QD6580_ALTERNATE << 4
|
---|
[363] | 53 | VisionControllerDetected:
|
---|
[370] | 54 | xchg ah, al
|
---|
[363] | 55 | ret
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | ;--------------------------------------------------------------------
|
---|
[364] | 59 | ; Vision_DoesIdePortInBXbelongToControllerWithIDinAX
|
---|
[363] | 60 | ; Parameters:
|
---|
[364] | 61 | ; AL: QD65xx Config Register contents
|
---|
| 62 | ; AH: QDI Vision Controller ID (bits 4...7)
|
---|
| 63 | ; BX: IDE Base port to check
|
---|
| 64 | ; DX: Vision Controller port
|
---|
[363] | 65 | ; Returns:
|
---|
| 66 | ; ZF: Set if port belongs to controller
|
---|
| 67 | ; Cleared if port belongs to another controller
|
---|
| 68 | ; Corrupts registers:
|
---|
[364] | 69 | ; Nothing
|
---|
[363] | 70 | ;--------------------------------------------------------------------
|
---|
[364] | 71 | Vision_DoesIdePortInBXbelongToControllerWithIDinAX:
|
---|
[363] | 72 | cmp ah, ID_QD6500 << 4
|
---|
| 73 | je SHORT .DoesIdePortInDXbelongToQD6500
|
---|
| 74 |
|
---|
| 75 | ; QD6580 always have Primary IDE at 1F0h
|
---|
| 76 | ; Secondary IDE at 170h can be enabled or disabled
|
---|
[364] | 77 | cmp bx, DEVICE_ATA_DEFAULT_PORT
|
---|
[363] | 78 | je SHORT .ReturnResultInZF
|
---|
| 79 |
|
---|
| 80 | ; Check if Secondary IDE channel is enabled
|
---|
[364] | 81 | push ax
|
---|
[363] | 82 | add dx, BYTE QD6580_CONTROL_REGISTER
|
---|
| 83 | in al, dx
|
---|
| 84 | sub dx, BYTE QD6580_CONTROL_REGISTER
|
---|
[364] | 85 | test al, FLG_QDCONTROL_SECONDARY_DISABLED_in
|
---|
| 86 | pop ax
|
---|
| 87 | jz SHORT .CompareBXtoSecondaryIDE
|
---|
[363] | 88 | ret
|
---|
| 89 |
|
---|
| 90 | ; QD6500 has only one IDE channel that can be at 1F0h or 170h
|
---|
| 91 | .DoesIdePortInDXbelongToQD6500:
|
---|
| 92 | test al, FLG_QDCONFIG_PRIMARY_IDE
|
---|
[364] | 93 | jz SHORT .CompareBXtoSecondaryIDE
|
---|
| 94 | cmp bx, DEVICE_ATA_DEFAULT_PORT
|
---|
[363] | 95 | ret
|
---|
| 96 |
|
---|
[364] | 97 | .CompareBXtoSecondaryIDE:
|
---|
| 98 | cmp bx, DEVICE_ATA_DEFAULT_SECONDARY_PORT
|
---|
[363] | 99 | .ReturnResultInZF:
|
---|
| 100 | ret
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | ;--------------------------------------------------------------------
|
---|
| 104 | ; Vision_GetMaxPioModeToAL
|
---|
| 105 | ; Parameters:
|
---|
[364] | 106 | ; AL: QD65xx Config Register contents
|
---|
| 107 | ; AH: QDI Vision Controller ID (bits 4...7)
|
---|
[363] | 108 | ; Returns:
|
---|
[364] | 109 | ; AL: Max supported PIO mode
|
---|
| 110 | ; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise
|
---|
[363] | 111 | ; CF: Set if PIO limit necessary
|
---|
| 112 | ; Cleared if no need to limit timings
|
---|
| 113 | ; Corrupts registers:
|
---|
[364] | 114 | ; (AX if CF cleared)
|
---|
| 115 | ; Corrupts registers:
|
---|
[363] | 116 | ; Nothing
|
---|
| 117 | ;--------------------------------------------------------------------
|
---|
| 118 | Vision_GetMaxPioModeToAL:
|
---|
| 119 | cmp ah, ID_QD6500 << 4
|
---|
| 120 | clc
|
---|
| 121 | jne SHORT .NoNeedToLimitForQD6580
|
---|
| 122 |
|
---|
[364] | 123 | mov ax, 2 ; Limit to PIO 2 because QD6500 does not support IORDY
|
---|
[363] | 124 | stc
|
---|
| 125 | .NoNeedToLimitForQD6580:
|
---|
| 126 | ret
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | ;--------------------------------------------------------------------
|
---|
| 130 | ; Vision_InitializeWithIDinAHandConfigInAL
|
---|
| 131 | ; Parameters:
|
---|
[364] | 132 | ; AL: QD65xx Config Register contents
|
---|
| 133 | ; AH: QDI Vision Controller ID (bits 4...7)
|
---|
| 134 | ; DS:DI: Ptr to DPT for Single or Slave Drive
|
---|
| 135 | ; SI: Offset to Master DPT if Slave Drive present
|
---|
| 136 | ; Zero if Slave Drive not present
|
---|
[363] | 137 | ; Returns:
|
---|
| 138 | ; CF: Cleared if success
|
---|
| 139 | ; Set if error
|
---|
| 140 | ; Corrupts registers:
|
---|
[364] | 141 | ; AX, BX, CX, DX, BP
|
---|
[363] | 142 | ;--------------------------------------------------------------------
|
---|
| 143 | Vision_InitializeWithIDinAHandConfigInAL:
|
---|
| 144 | ; QD6580 has a Control Register that needs to be programmed
|
---|
[364] | 145 | mov dx, [di+DPT_ADVANCED_ATA.wControllerBasePort]
|
---|
[363] | 146 | cmp ah, ID_QD6500 << 4
|
---|
[364] | 147 | je SHORT .CalculateTimingForQD6500
|
---|
[363] | 148 |
|
---|
| 149 | ; Program QD6580 Control Register (not available on QD6500) to
|
---|
| 150 | ; Enable or Disable Read-Ahead and Post-Write Buffer to match
|
---|
| 151 | ; jumper setting on the multi I/O card.
|
---|
[364] | 152 | xor ax, ax
|
---|
[363] | 153 | add dx, BYTE QD6580_CONTROL_REGISTER
|
---|
| 154 | in al, dx ; Read to get ATAPI jumper status
|
---|
| 155 | test al, FLG_QDCONTROL_HDONLY_in
|
---|
[364] | 156 | eCMOVNZ ah, FLG_QDCONTROL_NONATAPI ; Enable Read-Ahead and Post-Write Buffers
|
---|
| 157 | or ah, MASK_QDCONTROL_FLAGS_TO_SET
|
---|
| 158 | mov al, ah
|
---|
[363] | 159 | out dx, al
|
---|
[364] | 160 | sub dx, BYTE QD6580_CONTROL_REGISTER
|
---|
[363] | 161 |
|
---|
| 162 | ; Now we need to determine is the drive connected to the Primary or Secondary channel.
|
---|
| 163 | ; QD6500 has only one channel that can be Primary at 1F0h or Secondary at 170h.
|
---|
| 164 | ; QD6580 always has Primary channel at 1F0h. Secondary channel at 170h can be Enabled or Disabled.
|
---|
[364] | 165 | call AccessDPT_GetIdeBasePortToBX
|
---|
| 166 | cmp bx, DEVICE_ATA_DEFAULT_PORT
|
---|
| 167 | je SHORT .CalculateTimingTicksForQD6580 ; Primary Channel so no need to modify DX
|
---|
[363] | 168 | times 2 inc dx ; Secondary Channel IDE Timing Register
|
---|
| 169 |
|
---|
[364] | 170 | ; QD6500 and QD6580 require slightly different calculations.
|
---|
[363] | 171 | .CalculateTimingTicksForQD6580:
|
---|
[364] | 172 | mov bp, QD6580_MAX_ACTIVE_TIME_CLOCKS | (QD6580_MIN_ACTIVE_TIME_CLOCKS << 8)
|
---|
| 173 | jmp SHORT .CalculateTimingsForQD65xx
|
---|
[363] | 174 |
|
---|
[364] | 175 | .CalculateTimingForQD6500:
|
---|
| 176 | mov bp, QD6500_MAX_ACTIVE_TIME_CLOCKS | (QD6500_MIN_ACTIVE_TIME_CLOCKS << 8)
|
---|
[363] | 177 |
|
---|
[370] | 178 | ; We need the PIO Cycle Time in CX to calculate Active and Recovery Times.
|
---|
[364] | 179 | .CalculateTimingsForQD65xx:
|
---|
| 180 | call AdvAtaInit_SelectSlowestCommonPioTimingsToBXandCXfromDSSIandDSDI
|
---|
[363] | 181 |
|
---|
[364] | 182 | ; Calculate Active Time value for QD65xx IDE Timing Register
|
---|
| 183 | call AtaID_GetActiveTimeToAXfromPioModeInBX
|
---|
| 184 | call ConvertNanosecsFromAXwithLimitsInBPtoRegisterValue
|
---|
| 185 | xchg bp, ax
|
---|
[363] | 186 |
|
---|
[364] | 187 | ; Calculate Recovery Time value for QD65xx IDE Timing Register
|
---|
| 188 | call AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX
|
---|
| 189 | mov bx, bp ; Active Time value now in BL
|
---|
| 190 | mov bp, QD65xx_MAX_RECOVERY_TIME_CLOCKS | (QD65xx_MIN_RECOVERY_TIME_CLOCKS << 8)
|
---|
| 191 | call ConvertNanosecsFromAXwithLimitsInBPtoRegisterValue
|
---|
| 192 |
|
---|
| 193 | ; Merge the values to a single byte to output
|
---|
| 194 | eSHIFT_IM al, POSITON_QD65XXIDE_RECOVERY_TIME, shl
|
---|
| 195 | or al, bl
|
---|
| 196 | out dx, al
|
---|
| 197 | ret ; Return with CF cleared
|
---|
| 198 |
|
---|
| 199 |
|
---|
| 200 | ;--------------------------------------------------------------------
|
---|
| 201 | ; ConvertNanosecsFromAXwithLimitsInBPtoRegisterValue
|
---|
| 202 | ; Parameters:
|
---|
| 203 | ; AX: Nanosecs to convert
|
---|
| 204 | ; BP: Low Byte: Maximum allowed ticks
|
---|
| 205 | ; High Byte: Minimum allowed ticks
|
---|
| 206 | ; DS:DI: Ptr to DPT for Single or Slave Drive
|
---|
| 207 | ; Returns:
|
---|
| 208 | ; AL: Timing value for QD65xx register
|
---|
| 209 | ; Corrupts registers:
|
---|
| 210 | ; Nothing
|
---|
| 211 | ;--------------------------------------------------------------------
|
---|
| 212 | ConvertNanosecsFromAXwithLimitsInBPtoRegisterValue:
|
---|
| 213 | push cx
|
---|
| 214 |
|
---|
| 215 | ; Get VLB Cycle Time in nanosecs
|
---|
| 216 | mov cl, VLB_33MHZ_CYCLE_TIME ; Assume 33 MHz or slower VLB bus
|
---|
| 217 | test BYTE [di+DPT_ADVANCED_ATA.wControllerID], FLG_QDCONFIG_ID3
|
---|
| 218 | eCMOVZ cl, VLB_40MHZ_CYCLE_TIME
|
---|
| 219 |
|
---|
| 220 | ; Convert value in AX to VLB ticks
|
---|
| 221 | div cl ; AL = VLB ticks
|
---|
[363] | 222 | inc ax ; Round up
|
---|
| 223 |
|
---|
[364] | 224 | ; Limit value to QD65xx limits
|
---|
| 225 | mov cx, bp
|
---|
| 226 | MAX_U al, ch ; Make sure not below minimum
|
---|
| 227 | MIN_U al, cl ; Make sure not above maximum
|
---|
| 228 |
|
---|
[363] | 229 | ; Not done yet, we need to invert the ticks since 0 is the slowest
|
---|
| 230 | ; value on the timing register
|
---|
[364] | 231 | sub cl, al
|
---|
| 232 | xchg ax, cx ; Return in AL
|
---|
[363] | 233 |
|
---|
[364] | 234 | pop cx
|
---|
| 235 | ret
|
---|