1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
/** @file
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions
of the BSD License which accompanies this distribution. The
full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "LegacyBiosInterface.h"
#include <IndustryStandard/Pci.h>
// Give floppy 3 states
// FLOPPY_PRESENT_WITH_MEDIA = Floppy controller present and media is inserted
// FLOPPY_NOT_PRESENT = No floppy controller present
// FLOPPY_PRESENT_NO_MEDIA = Floppy controller present but no media inserted
//
#define FLOPPY_NOT_PRESENT 0
#define FLOPPY_PRESENT_WITH_MEDIA 1
#define FLOPPY_PRESENT_NO_MEDIA 2
BBS_TABLE *mBbsTable;
BOOLEAN mBbsTableDoneFlag = FALSE;
BOOLEAN IsHaveMediaInFloppy = TRUE;
/**
Checks the state of the floppy and if media is inserted.
This routine checks the state of the floppy and if media is inserted.
There are 3 cases:
No floppy present - Set BBS entry to ignore
Floppy present & no media - Set BBS entry to lowest priority. We cannot
set it to ignore since 16-bit CSM will
indicate no floppy and thus drive A: is
unusable. CSM-16 will not try floppy since
lowest priority and thus not incur boot
time penality.
Floppy present & media - Set BBS entry to some priority.
@return State of floppy media
**/
UINT8
HasMediaInFloppy (
VOID
)
{
EFI_STATUS Status;
UINTN HandleCount;
EFI_HANDLE *HandleBuffer;
UINTN Index;
EFI_ISA_IO_PROTOCOL *IsaIo;
EFI_BLOCK_IO_PROTOCOL *BlkIo;
HandleBuffer = NULL;
HandleCount = 0;
gBS->LocateHandleBuffer (
ByProtocol,
&gEfiIsaIoProtocolGuid,
NULL,
&HandleCount,
&HandleBuffer
);
//
// If don't find any ISA/IO protocol assume no floppy. Need for floppy
// free system
//
if (HandleCount == 0) {
return FLOPPY_NOT_PRESENT;
}
ASSERT (HandleBuffer != NULL);
for (Index = 0; Index < HandleCount; Index++) {
Status = gBS->HandleProtocol (
HandleBuffer[Index],
&gEfiIsaIoProtocolGuid,
(VOID **) &IsaIo
);
if (EFI_ERROR (Status)) {
continue;
}
if (IsaIo->ResourceList->Device.HID != EISA_PNP_ID (0x604)) {
continue;
}
//
// Update blockio in case the floppy is inserted in during BdsTimeout
//
Status = gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
if (EFI_ERROR (Status)) {
continue;
}
Status = gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
if (EFI_ERROR (Status)) {
continue;
}
Status = gBS->HandleProtocol (
HandleBuffer[Index],
&gEfiBlockIoProtocolGuid,
(VOID **) &BlkIo
);
if (EFI_ERROR (Status)) {
continue;
}
if (BlkIo->Media->MediaPresent) {
FreePool (HandleBuffer);
return FLOPPY_PRESENT_WITH_MEDIA;
} else {
FreePool (HandleBuffer);
return FLOPPY_PRESENT_NO_MEDIA;
}
}
FreePool (HandleBuffer);
return FLOPPY_NOT_PRESENT;
}
/**
Complete build of BBS TABLE.
@param Private Legacy BIOS Instance data
@param BbsTable BBS Table passed to 16-bit code
@retval EFI_SUCCESS Removable media not present
**/
EFI_STATUS
LegacyBiosBuildBbs (
IN LEGACY_BIOS_INSTANCE *Private,
IN BBS_TABLE *BbsTable
)
{
UINTN BbsIndex;
HDD_INFO *HddInfo;
UINTN HddIndex;
UINTN Index;
//
// First entry is floppy.
// Next 2*MAX_IDE_CONTROLLER entries are for onboard IDE.
// Next n entries are filled in after each ROM is dispatched.
// Entry filled in if follow BBS spec. See LegacyPci.c
// Next entries are for non-BBS compliant ROMS. They are filled in by
// 16-bit code during Legacy16UpdateBbs invocation. Final BootPriority
// occurs after that invocation.
//
// Floppy
// Set default state.
//
IsHaveMediaInFloppy = HasMediaInFloppy ();
if (IsHaveMediaInFloppy == FLOPPY_PRESENT_WITH_MEDIA) {
BbsTable[0].BootPriority = BBS_UNPRIORITIZED_ENTRY;
} else {
if (IsHaveMediaInFloppy == FLOPPY_PRESENT_NO_MEDIA) {
BbsTable[0].BootPriority = BBS_LOWEST_PRIORITY;
} else {
BbsTable[0].BootPriority = BBS_IGNORE_ENTRY;
}
}
BbsTable[0].Bus = 0xff;
BbsTable[0].Device = 0xff;
BbsTable[0].Function = 0xff;
BbsTable[0].DeviceType = BBS_FLOPPY;
BbsTable[0].Class = 01;
BbsTable[0].SubClass = 02;
BbsTable[0].StatusFlags.OldPosition = 0;
BbsTable[0].StatusFlags.Reserved1 = 0;
BbsTable[0].StatusFlags.Enabled = 0;
BbsTable[0].StatusFlags.Failed = 0;
BbsTable[0].StatusFlags.MediaPresent = 0;
BbsTable[0].StatusFlags.Reserved2 = 0;
//
// Onboard HDD - Note Each HDD controller controls 2 drives
// Master & Slave
//
HddInfo = &Private->IntThunk->EfiToLegacy16BootTable.HddInfo[0];
//
// Get IDE Drive Info
//
LegacyBiosBuildIdeData (Private, &HddInfo, 0);
for (HddIndex = 0; HddIndex < MAX_IDE_CONTROLLER; HddIndex++) {
BbsIndex = HddIndex * 2 + 1;
for (Index = 0; Index < 2; ++Index) {
BbsTable[BbsIndex + Index].Bus = HddInfo[HddIndex].Bus;
BbsTable[BbsIndex + Index].Device = HddInfo[HddIndex].Device;
BbsTable[BbsIndex + Index].Function = HddInfo[HddIndex].Function;
BbsTable[BbsIndex + Index].Class = 01;
BbsTable[BbsIndex + Index].SubClass = 01;
BbsTable[BbsIndex + Index].StatusFlags.OldPosition = 0;
BbsTable[BbsIndex + Index].StatusFlags.Reserved1 = 0;
BbsTable[BbsIndex + Index].StatusFlags.Enabled = 0;
BbsTable[BbsIndex + Index].StatusFlags.Failed = 0;
BbsTable[BbsIndex + Index].StatusFlags.MediaPresent = 0;
BbsTable[BbsIndex + Index].StatusFlags.Reserved2 = 0;
//
// If no controller found or no device found set to ignore
// else set to unprioritized and set device type
//
if (HddInfo[HddIndex].CommandBaseAddress == 0) {
BbsTable[BbsIndex + Index].BootPriority = BBS_IGNORE_ENTRY;
} else {
if (Index == 0) {
if ((HddInfo[HddIndex].Status & (HDD_MASTER_IDE | HDD_MASTER_ATAPI_CDROM | HDD_MASTER_ATAPI_ZIPDISK)) != 0) {
BbsTable[BbsIndex + Index].BootPriority = BBS_UNPRIORITIZED_ENTRY;
if ((HddInfo[HddIndex].Status & HDD_MASTER_IDE) != 0) {
BbsTable[BbsIndex + Index].DeviceType = BBS_HARDDISK;
} else if ((HddInfo[HddIndex].Status & HDD_MASTER_ATAPI_CDROM) != 0) {
BbsTable[BbsIndex + Index].DeviceType = BBS_CDROM;
} else {
//
// for ZIPDISK
//
BbsTable[BbsIndex + Index].DeviceType = BBS_HARDDISK;
}
} else {
BbsTable[BbsIndex + Index].BootPriority = BBS_IGNORE_ENTRY;
}
} else {
if ((HddInfo[HddIndex].Status & (HDD_SLAVE_IDE | HDD_SLAVE_ATAPI_CDROM | HDD_SLAVE_ATAPI_ZIPDISK)) != 0) {
BbsTable[BbsIndex + Index].BootPriority = BBS_UNPRIORITIZED_ENTRY;
if ((HddInfo[HddIndex].Status & HDD_SLAVE_IDE) != 0) {
BbsTable[BbsIndex + Index].DeviceType = BBS_HARDDISK;
} else if ((HddInfo[HddIndex].Status & HDD_SLAVE_ATAPI_CDROM) != 0) {
BbsTable[BbsIndex + Index].DeviceType = BBS_CDROM;
} else {
//
// for ZIPDISK
//
BbsTable[BbsIndex + Index].DeviceType = BBS_HARDDISK;
}
} else {
BbsTable[BbsIndex + Index].BootPriority = BBS_IGNORE_ENTRY;
}
}
}
}
}
return EFI_SUCCESS;
}
/**
Get all BBS info
@param This Protocol instance pointer.
@param HddCount Number of HDD_INFO structures
@param HddInfo Onboard IDE controller information
@param BbsCount Number of BBS_TABLE structures
@param BbsTable List BBS entries
@retval EFI_SUCCESS Tables returned
@retval EFI_NOT_FOUND resource not found
@retval EFI_DEVICE_ERROR can not get BBS table
**/
EFI_STATUS
EFIAPI
LegacyBiosGetBbsInfo (
IN EFI_LEGACY_BIOS_PROTOCOL *This,
OUT UINT16 *HddCount,
OUT HDD_INFO **HddInfo,
OUT UINT16 *BbsCount,
OUT BBS_TABLE **BbsTable
)
{
LEGACY_BIOS_INSTANCE *Private;
EFI_IA32_REGISTER_SET Regs;
EFI_TO_COMPATIBILITY16_BOOT_TABLE *EfiToLegacy16BootTable;
// HDD_INFO *LocalHddInfo;
// IN BBS_TABLE *LocalBbsTable;
UINTN NumHandles;
EFI_HANDLE *HandleBuffer;
UINTN Index;
UINTN TempData;
UINT32 Granularity;
HandleBuffer = NULL;
Private = LEGACY_BIOS_INSTANCE_FROM_THIS (This);
EfiToLegacy16BootTable = &Private->IntThunk->EfiToLegacy16BootTable;
// LocalHddInfo = EfiToLegacy16BootTable->HddInfo;
// LocalBbsTable = (BBS_TABLE*)(UINTN)EfiToLegacy16BootTable->BbsTable;
if (!mBbsTableDoneFlag) {
mBbsTable = Private->BbsTablePtr;
//
// Always enable disk controllers so 16-bit CSM code has valid information for all
// drives.
//
//
// Get PciRootBridgeIO protocol
//
gBS->LocateHandleBuffer (
ByProtocol,
&gEfiPciRootBridgeIoProtocolGuid,
NULL,
&NumHandles,
&HandleBuffer
);
if (NumHandles == 0) {
return EFI_NOT_FOUND;
}
mBbsTableDoneFlag = TRUE;
for (Index = 0; Index < NumHandles; Index++) {
//
// Connect PciRootBridgeIO protocol handle with FALSE parameter to let
// PCI bus driver enumerate all subsequent handles
//
gBS->ConnectController (HandleBuffer[Index], NULL, NULL, FALSE);
}
LegacyBiosBuildBbs (Private, mBbsTable);
Private->LegacyRegion->UnLock (Private->LegacyRegion, 0xe0000, 0x20000, &Granularity);
//
// Call into Legacy16 code to add to BBS table for non BBS compliant OPROMs.
//
ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET));
Regs.X.AX = Legacy16UpdateBbs;
//
// Pass in handoff data
//
TempData = (UINTN) EfiToLegacy16BootTable;
Regs.X.ES = NORMALIZE_EFI_SEGMENT ((UINT32) TempData);
Regs.X.BX = NORMALIZE_EFI_OFFSET ((UINT32) TempData);
Private->LegacyBios.FarCall86 (
This,
Private->Legacy16CallSegment,
Private->Legacy16CallOffset,
&Regs,
NULL,
0
);
Private->Cpu->FlushDataCache (Private->Cpu, 0xE0000, 0x20000, EfiCpuFlushTypeWriteBackInvalidate);
Private->LegacyRegion->Lock (Private->LegacyRegion, 0xe0000, 0x20000, &Granularity);
if (Regs.X.AX != 0) {
return EFI_DEVICE_ERROR;
}
}
if (HandleBuffer != NULL) {
FreePool (HandleBuffer);
}
*HddCount = MAX_IDE_CONTROLLER;
*HddInfo = EfiToLegacy16BootTable->HddInfo;
*BbsTable = (BBS_TABLE*)(UINTN)EfiToLegacy16BootTable->BbsTable;
*BbsCount = (UINT16) (sizeof (Private->IntThunk->BbsTable) / sizeof (BBS_TABLE));
return EFI_SUCCESS;
}
|