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