2 Private include file for IsaFloppyPei PEIM.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef _RECOVERY_FLOPPY_H_
11 #define _RECOVERY_FLOPPY_H_
13 #include <Ppi/BlockIo.h>
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>
29 // Some PC AT Compatible Device definitions
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
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
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
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
65 #define R_8237_DMA_STA_CH0_3 0x09
66 #define R_8237_DMA_STA_CH4_7 0xd2
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
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
85 #define R_8237_DMA_CBPR_CH0_3 0x0c
86 #define R_8237_DMA_CBPR_CH4_7 0xd8
88 #define R_8237_DMA_MCR_CH0_3 0x0d
89 #define R_8237_DMA_MCR_CH4_7 0xda
91 #define R_8237_DMA_CLMSK_CH0_3 0x0e
92 #define R_8237_DMA_CLMSK_CH4_7 0xdc
94 #define R_8237_DMA_WRMSK_CH0_3 0x0f
95 #define R_8237_DMA_WRMSK_CH4_7 0xde
100 #define ISA_MAX_MEMORY_ADDRESS 0x1000000
103 // Macro for time delay & interval
105 #define STALL_1_SECOND 1000000
106 #define STALL_1_MSECOND 1000
107 #define FDC_CHECK_INTERVAL 50
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
136 BOOLEAN NeedRecalibrate
;
137 FDC_DISKET_TYPE Type
;
138 EFI_PEI_BLOCK_IO_MEDIA MediaInfo
;
139 } PEI_FLOPPY_DEVICE_INFO
;
141 #define FDC_BLK_IO_DEV_SIGNATURE SIGNATURE_32 ('F', 'b', 'i', 'o')
145 EFI_PEI_RECOVERY_BLOCK_IO_PPI FdcBlkIo
;
146 EFI_PEI_PPI_DESCRIPTOR PpiDescriptor
;
148 PEI_FLOPPY_DEVICE_INFO DeviceInfo
[2];
151 #define PEI_RECOVERY_FDC_FROM_BLKIO_THIS(a) CR (a, FDC_BLK_IO_DEV, FdcBlkIo, FDC_BLK_IO_DEV_SIGNATURE)
154 // PEI Recovery Block I/O PPI
158 Get the number of FDC devices.
160 This function implements EFI_PEI_RECOVERY_BLOCK_IO_PPI.GetNumberOfBlockDevices.
161 It get the number of FDC devices in the system.
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.
167 @retval EFI_SUCCESS Number of FDC devices is retrieved successfully.
168 @retval EFI_INVALID_PARAMETER Parameter This is NULL.
173 FdcGetNumberOfBlockDevices (
174 IN EFI_PEI_SERVICES
**PeiServices
,
175 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
176 OUT UINTN
*NumberBlockDevices
180 Get the specified media information.
182 This function implements EFI_PEI_RECOVERY_BLOCK_IO_PPI.GetBlockDeviceMediaInfo.
183 It gets the specified media information.
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.
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.
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
207 Get the requested number of blocks from the specified FDC device.
209 This function implements EFI_PEI_RECOVERY_BLOCK_IO_PPI.ReadBlocks.
210 It reads the requested number of blocks from the specified FDC device.
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.
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.
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
,