1 /** @file 2 Private include file for IsaFloppyPei PEIM. 3 4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> 5 6 SPDX-License-Identifier: BSD-2-Clause-Patent 7 8 **/ 9 10 #ifndef _RECOVERY_FLOPPY_H_ 11 #define _RECOVERY_FLOPPY_H_ 12 13 #include <Ppi/BlockIo.h> 14 15 #include <Library/DebugLib.h> 16 #include <Library/PeimEntryPoint.h> 17 #include <Library/PeiServicesLib.h> 18 #include <Library/BaseMemoryLib.h> 19 #include <Library/ReportStatusCodeLib.h> 20 #include <Library/TimerLib.h> 21 #include <Library/IoLib.h> 22 #include <Library/MemoryAllocationLib.h> 23 #include <Library/PcdLib.h> 24 25 #include "Fdc.h" 26 27 28 // 29 // Some PC AT Compatible Device definitions 30 // 31 // 32 // 8237 DMA registers 33 // 34 #define R_8237_DMA_BASE_CA_CH0 0x00 35 #define R_8237_DMA_BASE_CA_CH1 0x02 36 #define R_8237_DMA_BASE_CA_CH2 0x04 37 #define R_8237_DMA_BASE_CA_CH3 0xd6 38 #define R_8237_DMA_BASE_CA_CH5 0xc4 39 #define R_8237_DMA_BASE_CA_CH6 0xc8 40 #define R_8237_DMA_BASE_CA_CH7 0xcc 41 42 #define R_8237_DMA_BASE_CC_CH0 0x01 43 #define R_8237_DMA_BASE_CC_CH1 0x03 44 #define R_8237_DMA_BASE_CC_CH2 0x05 45 #define R_8237_DMA_BASE_CC_CH3 0xd7 46 #define R_8237_DMA_BASE_CC_CH5 0xc6 47 #define R_8237_DMA_BASE_CC_CH6 0xca 48 #define R_8237_DMA_BASE_CC_CH7 0xce 49 50 #define R_8237_DMA_MEM_LP_CH0 0x87 51 #define R_8237_DMA_MEM_LP_CH1 0x83 52 #define R_8237_DMA_MEM_LP_CH2 0x81 53 #define R_8237_DMA_MEM_LP_CH3 0x82 54 #define R_8237_DMA_MEM_LP_CH5 0x8B 55 #define R_8237_DMA_MEM_LP_CH6 0x89 56 #define R_8237_DMA_MEM_LP_CH7 0x8A 57 58 59 #define R_8237_DMA_COMMAND_CH0_3 0x08 60 #define R_8237_DMA_COMMAND_CH4_7 0xd0 61 #define B_8237_DMA_COMMAND_GAP 0x10 62 #define B_8237_DMA_COMMAND_CGE 0x04 63 64 65 #define R_8237_DMA_STA_CH0_3 0x09 66 #define R_8237_DMA_STA_CH4_7 0xd2 67 68 #define R_8237_DMA_WRSMSK_CH0_3 0x0a 69 #define R_8237_DMA_WRSMSK_CH4_7 0xd4 70 #define B_8237_DMA_WRSMSK_CMS 0x04 71 72 73 #define R_8237_DMA_CHMODE_CH0_3 0x0b 74 #define R_8237_DMA_CHMODE_CH4_7 0xd6 75 #define V_8237_DMA_CHMODE_DEMAND 0x00 76 #define V_8237_DMA_CHMODE_SINGLE 0x40 77 #define V_8237_DMA_CHMODE_CASCADE 0xc0 78 #define B_8237_DMA_CHMODE_DECREMENT 0x20 79 #define B_8237_DMA_CHMODE_INCREMENT 0x00 80 #define B_8237_DMA_CHMODE_AE 0x10 81 #define V_8237_DMA_CHMODE_VERIFY 0 82 #define V_8237_DMA_CHMODE_IO2MEM 0x04 83 #define V_8237_DMA_CHMODE_MEM2IO 0x08 84 85 #define R_8237_DMA_CBPR_CH0_3 0x0c 86 #define R_8237_DMA_CBPR_CH4_7 0xd8 87 88 #define R_8237_DMA_MCR_CH0_3 0x0d 89 #define R_8237_DMA_MCR_CH4_7 0xda 90 91 #define R_8237_DMA_CLMSK_CH0_3 0x0e 92 #define R_8237_DMA_CLMSK_CH4_7 0xdc 93 94 #define R_8237_DMA_WRMSK_CH0_3 0x0f 95 #define R_8237_DMA_WRMSK_CH4_7 0xde 96 97 /// 98 /// ISA memory range 99 /// 100 #define ISA_MAX_MEMORY_ADDRESS 0x1000000 101 102 // 103 // Macro for time delay & interval 104 // 105 #define STALL_1_SECOND 1000000 106 #define STALL_1_MSECOND 1000 107 #define FDC_CHECK_INTERVAL 50 108 109 #define FDC_SHORT_DELAY 50 110 #define FDC_MEDIUM_DELAY 100 111 #define FDC_LONG_DELAY 4000 112 #define FDC_RESET_DELAY 2000 113 #define FDC_RECALIBRATE_DELAY 250000 114 115 typedef enum { 116 FdcType360K360K = 0, 117 FdcType360K1200K, 118 FdcType1200K1200K, 119 FdcType720K720K, 120 FdcType720K1440K, 121 FdcType1440K1440K, 122 FdcType720K2880K, 123 FdcType1440K2880K, 124 FdcType2880K2880K 125 } FDC_DISKET_TYPE; 126 127 typedef struct { 128 UINT8 Register; 129 UINT8 Value; 130 } PEI_DMA_TABLE; 131 132 typedef struct { 133 UINT8 DevPos; 134 UINT8 Pcn; 135 BOOLEAN MotorOn; 136 BOOLEAN NeedRecalibrate; 137 FDC_DISKET_TYPE Type; 138 EFI_PEI_BLOCK_IO_MEDIA MediaInfo; 139 } PEI_FLOPPY_DEVICE_INFO; 140 141 #define FDC_BLK_IO_DEV_SIGNATURE SIGNATURE_32 ('F', 'b', 'i', 'o') 142 143 typedef struct { 144 UINTN Signature; 145 EFI_PEI_RECOVERY_BLOCK_IO_PPI FdcBlkIo; 146 EFI_PEI_PPI_DESCRIPTOR PpiDescriptor; 147 UINTN DeviceCount; 148 PEI_FLOPPY_DEVICE_INFO DeviceInfo[2]; 149 } FDC_BLK_IO_DEV; 150 151 #define PEI_RECOVERY_FDC_FROM_BLKIO_THIS(a) CR (a, FDC_BLK_IO_DEV, FdcBlkIo, FDC_BLK_IO_DEV_SIGNATURE) 152 153 // 154 // PEI Recovery Block I/O PPI 155 // 156 157 /** 158 Get the number of FDC devices. 159 160 This function implements EFI_PEI_RECOVERY_BLOCK_IO_PPI.GetNumberOfBlockDevices. 161 It get the number of FDC devices in the system. 162 163 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation. 164 @param This Pointer to this PPI instance. 165 @param NumberBlockDevices Pointer to the the number of FDC devices for output. 166 167 @retval EFI_SUCCESS Number of FDC devices is retrieved successfully. 168 @retval EFI_INVALID_PARAMETER Parameter This is NULL. 169 170 **/ 171 EFI_STATUS 172 EFIAPI 173 FdcGetNumberOfBlockDevices ( 174 IN EFI_PEI_SERVICES **PeiServices, 175 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, 176 OUT UINTN *NumberBlockDevices 177 ); 178 179 /** 180 Get the specified media information. 181 182 This function implements EFI_PEI_RECOVERY_BLOCK_IO_PPI.GetBlockDeviceMediaInfo. 183 It gets the specified media information. 184 185 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation. 186 @param This Pointer to this PPI instance. 187 @param DeviceIndex Index of FDC device to get information. 188 @param MediaInfo Pointer to the media info buffer for output. 189 190 @retval EFI_SUCCESS Number of FDC devices is retrieved successfully. 191 @retval EFI_INVALID_PARAMETER Parameter This is NULL. 192 @retval EFI_INVALID_PARAMETER Parameter MediaInfo is NULL. 193 @retval EFI_INVALID_PARAMETER DeviceIndex is not valid. 194 @retval EFI_DEVICE_ERROR FDC device does not exist or has errors. 195 196 **/ 197 EFI_STATUS 198 EFIAPI 199 FdcGetBlockDeviceMediaInfo ( 200 IN EFI_PEI_SERVICES **PeiServices, 201 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, 202 IN UINTN DeviceIndex, 203 OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo 204 ); 205 206 /** 207 Get the requested number of blocks from the specified FDC device. 208 209 This function implements EFI_PEI_RECOVERY_BLOCK_IO_PPI.ReadBlocks. 210 It reads the requested number of blocks from the specified FDC device. 211 212 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation. 213 @param This Pointer to this PPI instance. 214 @param DeviceIndex Index of FDC device to get information. 215 @param StartLba The start LBA to read from. 216 @param BufferSize The size of range to read. 217 @param Buffer Buffer to hold the data read from FDC. 218 219 @retval EFI_SUCCESS Number of FDC devices is retrieved successfully. 220 @retval EFI_INVALID_PARAMETER Parameter This is NULL. 221 @retval EFI_INVALID_PARAMETER Parameter Buffer is NULL. 222 @retval EFI_INVALID_PARAMETER Parameter BufferSize cannot be divided by block size of FDC device. 223 @retval EFI_NO_MEDIA No media present. 224 @retval EFI_DEVICE_ERROR FDC device has error. 225 @retval Others Fail to read blocks. 226 227 **/ 228 EFI_STATUS 229 EFIAPI 230 FdcReadBlocks ( 231 IN EFI_PEI_SERVICES **PeiServices, 232 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, 233 IN UINTN DeviceIndex, 234 IN EFI_PEI_LBA StartLba, 235 IN UINTN BufferSize, 236 OUT VOID *Buffer 237 ); 238 239 #endif 240