3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 This following section documents the envirnoment variables for the Win NT
19 build. These variables are used to define the (virtual) hardware
20 configuration of the NT environment
22 A ! can be used to seperate multiple instances in a variable. Each
23 instance represents a seperate hardware device.
25 EFI_WIN_NT_PHYSICAL_DISKS - maps to drives on your system
26 EFI_WIN_NT_VIRTUAL_DISKS - maps to a device emulated by a file
27 EFI_WIN_NT_FILE_SYSTEM - mouts a directory as a file system
28 EFI_WIN_NT_CONSOLE - make a logical comand line window (only one!)
29 EFI_WIN_NT_UGA - Builds UGA Windows of Width and Height
30 EFI_WIN_NT_SERIAL_PORT - maps physical serial ports
32 <F>ixed - Fixed disk like a hard drive.
33 <R>emovable - Removable media like a floppy or CD-ROM.
34 Read <O>nly - Write protected device.
35 Read <W>rite - Read write device.
36 <block count> - Decimal number of blocks a device supports.
37 <block size> - Decimal number of bytes per block.
39 NT envirnonment variable contents. '<' and '>' are not part of the variable,
40 they are just used to make this help more readable. There should be no
41 spaces between the ';'. Extra spaces will break the variable. A '!' is
42 used to seperate multiple devices in a variable.
44 EFI_WIN_NT_VIRTUAL_DISKS =
45 <F | R><O | W>;<block count>;<block size>[!...]
47 EFI_WIN_NT_PHYSICAL_DISKS =
48 <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]
50 Virtual Disks: These devices use a file to emulate a hard disk or removable
53 Thus a 20 MB emulated hard drive would look like:
54 EFI_WIN_NT_VIRTUAL_DISKS=FW;40960;512
56 A 1.44MB emulated floppy with a block size of 1024 would look like:
57 EFI_WIN_NT_VIRTUAL_DISKS=RW;1440;1024
59 Physical Disks: These devices use NT to open a real device in your system
61 Thus a 120 MB floppy would look like:
62 EFI_WIN_NT_PHYSICAL_DISKS=B:RW;245760;512
64 Thus a standard CD-ROM floppy would look like:
65 EFI_WIN_NT_PHYSICAL_DISKS=Z:RO;307200;2048
67 EFI_WIN_NT_FILE_SYSTEM =
68 <directory path>[!...]
70 Mounting the two directories C:\FOO and C:\BAR would look like:
71 EFI_WIN_NT_FILE_SYSTEM=c:\foo!c:\bar
76 Declaring a text console window with the title "My EFI Console" woild look like:
77 EFI_WIN_NT_CONSOLE=My EFI Console
80 <width> <height>[!...]
82 Declaring a two UGA windows with resolutions of 800x600 and 1024x768 would look like:
83 Example : EFI_WIN_NT_UGA=800 600!1024 768
85 EFI_WIN_NT_SERIAL_PORT =
88 Declaring two serial ports on COM1 and COM2 would look like:
89 Example : EFI_WIN_NT_SERIAL_PORT=COM1!COM2
91 EFI_WIN_NT_PASS_THROUGH =
92 <BaseAddress>;<Bus#>;<Device#>;<Function#>
94 Declaring a base address of 0xE0000000 (used for PCI Express devices)
95 and having NT32 talk to a device located at bus 0, device 1, function 0:
96 Example : EFI_WIN_NT_PASS_THROUGH=E000000;0;1;0
100 #include "WinNtBusDriver.h"
101 //#include "PciHostBridge.h"
104 // Define GUID for the WinNt Bus Driver
106 static EFI_GUID gWinNtBusDriverGuid
= {
107 0x419f582, 0x625, 0x4531, 0x8a, 0x33, 0x85, 0xa9, 0x96, 0x5c, 0x95, 0xbc
111 // DriverBinding protocol global
113 EFI_DRIVER_BINDING_PROTOCOL gWinNtBusDriverBinding
= {
114 WinNtBusDriverBindingSupported
,
115 WinNtBusDriverBindingStart
,
116 WinNtBusDriverBindingStop
,
122 #define NT_PCD_ARRAY_SIZE (sizeof(mPcdEnvironment)/sizeof(NT_PCD_ENTRY))
125 // Table to map NT Environment variable to the GUID that should be in
128 static NT_PCD_ENTRY mPcdEnvironment
[] = {
129 PcdToken(PcdWinNtConsole
), &gEfiWinNtConsoleGuid
,
130 PcdToken(PcdWinNtUga
), &gEfiWinNtUgaGuid
,
131 PcdToken(PcdWinNtSerialPort
), &gEfiWinNtSerialPortGuid
,
132 PcdToken(PcdWinNtFileSystem
), &gEfiWinNtFileSystemGuid
,
133 PcdToken(PcdWinNtVirtualDisk
), &gEfiWinNtVirtualDisksGuid
,
134 PcdToken(PcdWinNtPhysicalDisk
), &gEfiWinNtPhysicalDisksGuid
,
135 PcdToken(PcdWinNtCpuModel
), &gEfiWinNtCPUModelGuid
,
136 PcdToken(PcdWinNtCpuSpeed
), &gEfiWinNtCPUSpeedGuid
,
137 PcdToken(PcdWinNtMemorySize
), &gEfiWinNtMemoryGuid
148 Status
= gBS
->AllocatePool (
153 if (EFI_ERROR (Status
)) {
163 WinNtBusDriverBindingSupported (
164 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
165 IN EFI_HANDLE ControllerHandle
,
166 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
179 // TODO: This - add argument and description to function comment
180 // TODO: ControllerHandle - add argument and description to function comment
181 // TODO: RemainingDevicePath - add argument and description to function comment
182 // TODO: EFI_UNSUPPORTED - add return value to function comment
183 // TODO: EFI_UNSUPPORTED - add return value to function comment
184 // TODO: EFI_SUCCESS - add return value to function comment
185 // TODO: EFI_SUCCESS - add return value to function comment
188 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
189 EFI_WIN_NT_THUNK_PROTOCOL
*WinNtThunk
;
193 // Check the contents of the first Device Path Node of RemainingDevicePath to make sure
194 // it is a legal Device Path Node for this bus driver's children.
196 if (RemainingDevicePath
!= NULL
) {
197 if (RemainingDevicePath
->Type
!= HARDWARE_DEVICE_PATH
||
198 RemainingDevicePath
->SubType
!= HW_VENDOR_DP
||
199 DevicePathNodeLength(RemainingDevicePath
) != sizeof(WIN_NT_VENDOR_DEVICE_PATH_NODE
)) {
200 return EFI_UNSUPPORTED
;
203 for (Index
= 0; Index
< NT_PCD_ARRAY_SIZE
; Index
++) {
204 if (CompareGuid (&((VENDOR_DEVICE_PATH
*) RemainingDevicePath
)->Guid
, mPcdEnvironment
[Index
].DevicePathGuid
)) {
209 if (Index
>= NT_PCD_ARRAY_SIZE
) {
210 return EFI_UNSUPPORTED
;
215 // Open the IO Abstraction(s) needed to perform the supported test
217 Status
= gBS
->OpenProtocol (
219 &gEfiDevicePathProtocolGuid
,
221 This
->DriverBindingHandle
,
223 EFI_OPEN_PROTOCOL_BY_DRIVER
225 if (Status
== EFI_ALREADY_STARTED
) {
229 if (EFI_ERROR (Status
)) {
235 &gEfiDevicePathProtocolGuid
,
236 This
->DriverBindingHandle
,
240 Status
= gBS
->OpenProtocol (
242 &gEfiWinNtThunkProtocolGuid
,
244 This
->DriverBindingHandle
,
246 EFI_OPEN_PROTOCOL_BY_DRIVER
248 if (Status
== EFI_ALREADY_STARTED
) {
252 if (EFI_ERROR (Status
)) {
257 // Since we call through WinNtThunk we need to make sure it's valid
259 Status
= EFI_SUCCESS
;
260 if (WinNtThunk
->Signature
!= EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE
) {
261 Status
= EFI_UNSUPPORTED
;
265 // Close the I/O Abstraction(s) used to perform the supported test
269 &gEfiWinNtThunkProtocolGuid
,
270 This
->DriverBindingHandle
,
279 WinNtBusDriverBindingStart (
280 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
281 IN EFI_HANDLE ControllerHandle
,
282 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
295 // TODO: This - add argument and description to function comment
296 // TODO: ControllerHandle - add argument and description to function comment
297 // TODO: RemainingDevicePath - add argument and description to function comment
298 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
299 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
300 // TODO: EFI_SUCCESS - add return value to function comment
303 EFI_STATUS InstallStatus
;
304 EFI_WIN_NT_THUNK_PROTOCOL
*WinNtThunk
;
305 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
306 WIN_NT_BUS_DEVICE
*WinNtBusDevice
;
307 WIN_NT_IO_DEVICE
*WinNtDevice
;
313 UINT16 ComponentName
[MAX_NT_ENVIRNMENT_VARIABLE_LENGTH
];
314 WIN_NT_VENDOR_DEVICE_PATH_NODE
*Node
;
315 BOOLEAN CreateDevice
;
320 Status
= EFI_UNSUPPORTED
;
323 // Grab the protocols we need
325 Status
= gBS
->OpenProtocol (
327 &gEfiDevicePathProtocolGuid
,
329 This
->DriverBindingHandle
,
331 EFI_OPEN_PROTOCOL_BY_DRIVER
333 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
337 Status
= gBS
->OpenProtocol (
339 &gEfiWinNtThunkProtocolGuid
,
341 This
->DriverBindingHandle
,
343 EFI_OPEN_PROTOCOL_BY_DRIVER
345 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
349 if (Status
!= EFI_ALREADY_STARTED
) {
350 Status
= gBS
->AllocatePool (
352 sizeof (WIN_NT_BUS_DEVICE
),
353 (VOID
*) &WinNtBusDevice
355 if (EFI_ERROR (Status
)) {
359 WinNtBusDevice
->Signature
= WIN_NT_BUS_DEVICE_SIGNATURE
;
360 WinNtBusDevice
->ControllerNameTable
= NULL
;
364 gWinNtBusDriverComponentName
.SupportedLanguages
,
365 &WinNtBusDevice
->ControllerNameTable
,
366 L
"Windows Bus Controller"
369 Status
= gBS
->InstallMultipleProtocolInterfaces (
371 &gWinNtBusDriverGuid
,
375 if (EFI_ERROR (Status
)) {
376 FreeUnicodeStringTable (WinNtBusDevice
->ControllerNameTable
);
377 gBS
->FreePool (WinNtBusDevice
);
383 // Loop on the Variable list. Parse each variable to produce a set of handles that
384 // represent virtual hardware devices.
386 InstallStatus
= EFI_NOT_FOUND
;
387 for (Index
= 0; Index
< NT_PCD_ARRAY_SIZE
; Index
++) {
388 PcdTempStr
= (VOID
*)LibPcdGetPtr (mPcdEnvironment
[Index
].Token
);
389 ASSERT (PcdTempStr
!= NULL
);
391 TempStrSize
= StrLen (PcdTempStr
);
392 TempStr
= AllocateMemory ((TempStrSize
* sizeof (CHAR16
)) + 1);
393 StrCpy (TempStr
, PcdTempStr
);
395 StartString
= TempStr
;
398 // Parse the envirnment variable into sub strings using '!' as a delimator.
399 // Each substring needs it's own handle to be added to the system. This code
400 // does not understand the sub string. Thats the device drivers job.
403 while (*StartString
!= '\0') {
406 // Find the end of the sub string
408 SubString
= StartString
;
409 while (*SubString
!= '\0' && *SubString
!= '!') {
413 if (*SubString
== '!') {
415 // Replace token with '\0' to make sub strings. If this is the end
416 // of the string SubString will already point to NULL.
423 if (RemainingDevicePath
!= NULL
) {
424 CreateDevice
= FALSE
;
425 Node
= (WIN_NT_VENDOR_DEVICE_PATH_NODE
*) RemainingDevicePath
;
426 if (Node
->VendorDevicePath
.Header
.Type
== HARDWARE_DEVICE_PATH
&&
427 Node
->VendorDevicePath
.Header
.SubType
== HW_VENDOR_DP
&&
428 DevicePathNodeLength (&Node
->VendorDevicePath
.Header
) == sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE
)
430 if (CompareGuid (&Node
->VendorDevicePath
.Guid
, mPcdEnvironment
[Index
].DevicePathGuid
) &&
431 Node
->Instance
== Count
441 // Allocate instance structure, and fill in parent information.
443 WinNtDevice
= AllocateMemory (sizeof (WIN_NT_IO_DEVICE
));
444 if (WinNtDevice
== NULL
) {
445 return EFI_OUT_OF_RESOURCES
;
448 WinNtDevice
->Handle
= NULL
;
449 WinNtDevice
->ControllerHandle
= ControllerHandle
;
450 WinNtDevice
->ParentDevicePath
= ParentDevicePath
;
452 WinNtDevice
->WinNtIo
.WinNtThunk
= WinNtThunk
;
455 // Plus 2 to account for the NULL at the end of the Unicode string
457 StringSize
= (UINTN
) ((UINT8
*) SubString
- (UINT8
*) StartString
) + sizeof (CHAR16
);
458 WinNtDevice
->WinNtIo
.EnvString
= AllocateMemory (StringSize
);
459 if (WinNtDevice
->WinNtIo
.EnvString
!= NULL
) {
460 CopyMem (WinNtDevice
->WinNtIo
.EnvString
, StartString
, StringSize
);
463 WinNtDevice
->ControllerNameTable
= NULL
;
465 WinNtThunk
->SPrintf (ComponentName
, L
"%s", WinNtDevice
->WinNtIo
.EnvString
);
467 WinNtDevice
->DevicePath
= WinNtBusCreateDevicePath (
469 mPcdEnvironment
[Index
].DevicePathGuid
,
472 if (WinNtDevice
->DevicePath
== NULL
) {
473 gBS
->FreePool (WinNtDevice
);
474 return EFI_OUT_OF_RESOURCES
;
479 gWinNtBusDriverComponentName
.SupportedLanguages
,
480 &WinNtDevice
->ControllerNameTable
,
484 WinNtDevice
->WinNtIo
.TypeGuid
= mPcdEnvironment
[Index
].DevicePathGuid
;
485 WinNtDevice
->WinNtIo
.InstanceNumber
= Count
;
487 WinNtDevice
->Signature
= WIN_NT_IO_DEVICE_SIGNATURE
;
489 Status
= gBS
->InstallMultipleProtocolInterfaces (
490 &WinNtDevice
->Handle
,
491 &gEfiDevicePathProtocolGuid
,
492 WinNtDevice
->DevicePath
,
493 &gEfiWinNtIoProtocolGuid
,
494 &WinNtDevice
->WinNtIo
,
497 if (EFI_ERROR (Status
)) {
498 FreeUnicodeStringTable (WinNtDevice
->ControllerNameTable
);
499 gBS
->FreePool (WinNtDevice
);
502 // Open For Child Device
504 Status
= gBS
->OpenProtocol (
506 &gEfiWinNtThunkProtocolGuid
,
508 This
->DriverBindingHandle
,
510 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
512 if (!EFI_ERROR (Status
)) {
513 InstallStatus
= EFI_SUCCESS
;
519 // Parse Next sub string. This will point to '\0' if we are at the end.
522 StartString
= SubString
;
525 gBS
->FreePool (TempStr
);
534 WinNtBusDriverBindingStop (
535 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
536 IN EFI_HANDLE ControllerHandle
,
537 IN UINTN NumberOfChildren
,
538 IN EFI_HANDLE
*ChildHandleBuffer
551 // TODO: This - add argument and description to function comment
552 // TODO: ControllerHandle - add argument and description to function comment
553 // TODO: NumberOfChildren - add argument and description to function comment
554 // TODO: ChildHandleBuffer - add argument and description to function comment
555 // TODO: EFI_SUCCESS - add return value to function comment
556 // TODO: EFI_DEVICE_ERROR - add return value to function comment
557 // TODO: EFI_SUCCESS - add return value to function comment
561 BOOLEAN AllChildrenStopped
;
562 EFI_WIN_NT_IO_PROTOCOL
*WinNtIo
;
563 WIN_NT_BUS_DEVICE
*WinNtBusDevice
;
564 WIN_NT_IO_DEVICE
*WinNtDevice
;
565 EFI_WIN_NT_THUNK_PROTOCOL
*WinNtThunk
;
568 // Complete all outstanding transactions to Controller.
569 // Don't allow any new transaction to Controller to be started.
572 if (NumberOfChildren
== 0) {
574 // Close the bus driver
576 Status
= gBS
->OpenProtocol (
578 &gWinNtBusDriverGuid
,
580 This
->DriverBindingHandle
,
582 EFI_OPEN_PROTOCOL_GET_PROTOCOL
584 if (EFI_ERROR (Status
)) {
588 gBS
->UninstallMultipleProtocolInterfaces (
590 &gWinNtBusDriverGuid
,
595 FreeUnicodeStringTable (WinNtBusDevice
->ControllerNameTable
);
597 gBS
->FreePool (WinNtBusDevice
);
601 &gEfiWinNtThunkProtocolGuid
,
602 This
->DriverBindingHandle
,
608 &gEfiDevicePathProtocolGuid
,
609 This
->DriverBindingHandle
,
615 AllChildrenStopped
= TRUE
;
617 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
619 Status
= gBS
->OpenProtocol (
620 ChildHandleBuffer
[Index
],
621 &gEfiWinNtIoProtocolGuid
,
623 This
->DriverBindingHandle
,
625 EFI_OPEN_PROTOCOL_GET_PROTOCOL
627 if (!EFI_ERROR (Status
)) {
629 WinNtDevice
= WIN_NT_IO_DEVICE_FROM_THIS (WinNtIo
);
631 Status
= gBS
->CloseProtocol (
633 &gEfiWinNtThunkProtocolGuid
,
634 This
->DriverBindingHandle
,
638 Status
= gBS
->UninstallMultipleProtocolInterfaces (
640 &gEfiDevicePathProtocolGuid
,
641 WinNtDevice
->DevicePath
,
642 &gEfiWinNtIoProtocolGuid
,
643 &WinNtDevice
->WinNtIo
,
647 if (EFI_ERROR (Status
)) {
650 &gEfiWinNtThunkProtocolGuid
,
651 (VOID
**) &WinNtThunk
,
652 This
->DriverBindingHandle
,
654 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
658 // Close the child handle
660 FreeUnicodeStringTable (WinNtDevice
->ControllerNameTable
);
661 gBS
->FreePool (WinNtDevice
);
665 if (EFI_ERROR (Status
)) {
666 AllChildrenStopped
= FALSE
;
670 if (!AllChildrenStopped
) {
671 return EFI_DEVICE_ERROR
;
677 EFI_DEVICE_PATH_PROTOCOL
*
678 WinNtBusCreateDevicePath (
679 IN EFI_DEVICE_PATH_PROTOCOL
*RootDevicePath
,
681 IN UINT16 InstanceNumber
686 Create a device path node using Guid and InstanceNumber and append it to
687 the passed in RootDevicePath
690 RootDevicePath - Root of the device path to return.
692 Guid - GUID to use in vendor device path node.
694 InstanceNumber - Instance number to use in the vendor device path. This
695 argument is needed to make sure each device path is unique.
699 EFI_DEVICE_PATH_PROTOCOL
703 WIN_NT_VENDOR_DEVICE_PATH_NODE DevicePath
;
705 DevicePath
.VendorDevicePath
.Header
.Type
= HARDWARE_DEVICE_PATH
;
706 DevicePath
.VendorDevicePath
.Header
.SubType
= HW_VENDOR_DP
;
707 SetDevicePathNodeLength (&DevicePath
.VendorDevicePath
.Header
, sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE
));
710 // The GUID defines the Class
712 CopyMem (&DevicePath
.VendorDevicePath
.Guid
, Guid
, sizeof (EFI_GUID
));
715 // Add an instance number so we can make sure there are no Device Path
718 DevicePath
.Instance
= InstanceNumber
;
720 return AppendDevicePathNode (
722 (EFI_DEVICE_PATH_PROTOCOL
*) &DevicePath