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 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
132 PcdToken(PcdWinNtGop
), &gEfiWinNtGopGuid
,
134 PcdToken(PcdWinNtSerialPort
), &gEfiWinNtSerialPortGuid
,
135 PcdToken(PcdWinNtFileSystem
), &gEfiWinNtFileSystemGuid
,
136 PcdToken(PcdWinNtVirtualDisk
), &gEfiWinNtVirtualDisksGuid
,
137 PcdToken(PcdWinNtPhysicalDisk
), &gEfiWinNtPhysicalDisksGuid
,
138 PcdToken(PcdWinNtCpuModel
), &gEfiWinNtCPUModelGuid
,
139 PcdToken(PcdWinNtCpuSpeed
), &gEfiWinNtCPUSpeedGuid
,
140 PcdToken(PcdWinNtMemorySize
), &gEfiWinNtMemoryGuid
151 Status
= gBS
->AllocatePool (
156 if (EFI_ERROR (Status
)) {
166 WinNtBusDriverBindingSupported (
167 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
168 IN EFI_HANDLE ControllerHandle
,
169 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
182 // TODO: This - add argument and description to function comment
183 // TODO: ControllerHandle - add argument and description to function comment
184 // TODO: RemainingDevicePath - add argument and description to function comment
185 // TODO: EFI_UNSUPPORTED - add return value to function comment
186 // TODO: EFI_UNSUPPORTED - add return value to function comment
187 // TODO: EFI_SUCCESS - add return value to function comment
188 // TODO: EFI_SUCCESS - add return value to function comment
191 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
192 EFI_WIN_NT_THUNK_PROTOCOL
*WinNtThunk
;
196 // Check the contents of the first Device Path Node of RemainingDevicePath to make sure
197 // it is a legal Device Path Node for this bus driver's children.
199 if (RemainingDevicePath
!= NULL
) {
200 if (RemainingDevicePath
->Type
!= HARDWARE_DEVICE_PATH
||
201 RemainingDevicePath
->SubType
!= HW_VENDOR_DP
||
202 DevicePathNodeLength(RemainingDevicePath
) != sizeof(WIN_NT_VENDOR_DEVICE_PATH_NODE
)) {
203 return EFI_UNSUPPORTED
;
206 for (Index
= 0; Index
< NT_PCD_ARRAY_SIZE
; Index
++) {
207 if (CompareGuid (&((VENDOR_DEVICE_PATH
*) RemainingDevicePath
)->Guid
, mPcdEnvironment
[Index
].DevicePathGuid
)) {
212 if (Index
>= NT_PCD_ARRAY_SIZE
) {
213 return EFI_UNSUPPORTED
;
218 // Open the IO Abstraction(s) needed to perform the supported test
220 Status
= gBS
->OpenProtocol (
222 &gEfiDevicePathProtocolGuid
,
224 This
->DriverBindingHandle
,
226 EFI_OPEN_PROTOCOL_BY_DRIVER
228 if (Status
== EFI_ALREADY_STARTED
) {
232 if (EFI_ERROR (Status
)) {
238 &gEfiDevicePathProtocolGuid
,
239 This
->DriverBindingHandle
,
243 Status
= gBS
->OpenProtocol (
245 &gEfiWinNtThunkProtocolGuid
,
247 This
->DriverBindingHandle
,
249 EFI_OPEN_PROTOCOL_BY_DRIVER
251 if (Status
== EFI_ALREADY_STARTED
) {
255 if (EFI_ERROR (Status
)) {
260 // Since we call through WinNtThunk we need to make sure it's valid
262 Status
= EFI_SUCCESS
;
263 if (WinNtThunk
->Signature
!= EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE
) {
264 Status
= EFI_UNSUPPORTED
;
268 // Close the I/O Abstraction(s) used to perform the supported test
272 &gEfiWinNtThunkProtocolGuid
,
273 This
->DriverBindingHandle
,
282 WinNtBusDriverBindingStart (
283 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
284 IN EFI_HANDLE ControllerHandle
,
285 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
298 // TODO: This - add argument and description to function comment
299 // TODO: ControllerHandle - add argument and description to function comment
300 // TODO: RemainingDevicePath - add argument and description to function comment
301 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
302 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
303 // TODO: EFI_SUCCESS - add return value to function comment
306 EFI_STATUS InstallStatus
;
307 EFI_WIN_NT_THUNK_PROTOCOL
*WinNtThunk
;
308 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
309 WIN_NT_BUS_DEVICE
*WinNtBusDevice
;
310 WIN_NT_IO_DEVICE
*WinNtDevice
;
316 UINT16 ComponentName
[MAX_NT_ENVIRNMENT_VARIABLE_LENGTH
];
317 WIN_NT_VENDOR_DEVICE_PATH_NODE
*Node
;
318 BOOLEAN CreateDevice
;
323 Status
= EFI_UNSUPPORTED
;
326 // Grab the protocols we need
328 Status
= gBS
->OpenProtocol (
330 &gEfiDevicePathProtocolGuid
,
332 This
->DriverBindingHandle
,
334 EFI_OPEN_PROTOCOL_BY_DRIVER
336 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
340 Status
= gBS
->OpenProtocol (
342 &gEfiWinNtThunkProtocolGuid
,
344 This
->DriverBindingHandle
,
346 EFI_OPEN_PROTOCOL_BY_DRIVER
348 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
352 if (Status
!= EFI_ALREADY_STARTED
) {
353 Status
= gBS
->AllocatePool (
355 sizeof (WIN_NT_BUS_DEVICE
),
356 (VOID
*) &WinNtBusDevice
358 if (EFI_ERROR (Status
)) {
362 WinNtBusDevice
->Signature
= WIN_NT_BUS_DEVICE_SIGNATURE
;
363 WinNtBusDevice
->ControllerNameTable
= NULL
;
367 gWinNtBusDriverComponentName
.SupportedLanguages
,
368 &WinNtBusDevice
->ControllerNameTable
,
369 L
"Windows Bus Controller"
372 Status
= gBS
->InstallMultipleProtocolInterfaces (
374 &gWinNtBusDriverGuid
,
378 if (EFI_ERROR (Status
)) {
379 FreeUnicodeStringTable (WinNtBusDevice
->ControllerNameTable
);
380 gBS
->FreePool (WinNtBusDevice
);
386 // Loop on the Variable list. Parse each variable to produce a set of handles that
387 // represent virtual hardware devices.
389 InstallStatus
= EFI_NOT_FOUND
;
390 for (Index
= 0; Index
< NT_PCD_ARRAY_SIZE
; Index
++) {
391 PcdTempStr
= (VOID
*)LibPcdGetPtr (mPcdEnvironment
[Index
].Token
);
392 ASSERT (PcdTempStr
!= NULL
);
394 TempStrSize
= StrLen (PcdTempStr
);
395 TempStr
= AllocateMemory ((TempStrSize
* sizeof (CHAR16
)) + 1);
396 StrCpy (TempStr
, PcdTempStr
);
398 StartString
= TempStr
;
401 // Parse the envirnment variable into sub strings using '!' as a delimator.
402 // Each substring needs it's own handle to be added to the system. This code
403 // does not understand the sub string. Thats the device drivers job.
406 while (*StartString
!= '\0') {
409 // Find the end of the sub string
411 SubString
= StartString
;
412 while (*SubString
!= '\0' && *SubString
!= '!') {
416 if (*SubString
== '!') {
418 // Replace token with '\0' to make sub strings. If this is the end
419 // of the string SubString will already point to NULL.
426 if (RemainingDevicePath
!= NULL
) {
427 CreateDevice
= FALSE
;
428 Node
= (WIN_NT_VENDOR_DEVICE_PATH_NODE
*) RemainingDevicePath
;
429 if (Node
->VendorDevicePath
.Header
.Type
== HARDWARE_DEVICE_PATH
&&
430 Node
->VendorDevicePath
.Header
.SubType
== HW_VENDOR_DP
&&
431 DevicePathNodeLength (&Node
->VendorDevicePath
.Header
) == sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE
)
433 if (CompareGuid (&Node
->VendorDevicePath
.Guid
, mPcdEnvironment
[Index
].DevicePathGuid
) &&
434 Node
->Instance
== Count
444 // Allocate instance structure, and fill in parent information.
446 WinNtDevice
= AllocateMemory (sizeof (WIN_NT_IO_DEVICE
));
447 if (WinNtDevice
== NULL
) {
448 return EFI_OUT_OF_RESOURCES
;
451 WinNtDevice
->Handle
= NULL
;
452 WinNtDevice
->ControllerHandle
= ControllerHandle
;
453 WinNtDevice
->ParentDevicePath
= ParentDevicePath
;
455 WinNtDevice
->WinNtIo
.WinNtThunk
= WinNtThunk
;
458 // Plus 2 to account for the NULL at the end of the Unicode string
460 StringSize
= (UINTN
) ((UINT8
*) SubString
- (UINT8
*) StartString
) + sizeof (CHAR16
);
461 WinNtDevice
->WinNtIo
.EnvString
= AllocateMemory (StringSize
);
462 if (WinNtDevice
->WinNtIo
.EnvString
!= NULL
) {
463 CopyMem (WinNtDevice
->WinNtIo
.EnvString
, StartString
, StringSize
);
466 WinNtDevice
->ControllerNameTable
= NULL
;
468 WinNtThunk
->SPrintf (ComponentName
, sizeof (ComponentName
), L
"%s", WinNtDevice
->WinNtIo
.EnvString
);
470 WinNtDevice
->DevicePath
= WinNtBusCreateDevicePath (
472 mPcdEnvironment
[Index
].DevicePathGuid
,
475 if (WinNtDevice
->DevicePath
== NULL
) {
476 gBS
->FreePool (WinNtDevice
);
477 return EFI_OUT_OF_RESOURCES
;
482 gWinNtBusDriverComponentName
.SupportedLanguages
,
483 &WinNtDevice
->ControllerNameTable
,
487 WinNtDevice
->WinNtIo
.TypeGuid
= mPcdEnvironment
[Index
].DevicePathGuid
;
488 WinNtDevice
->WinNtIo
.InstanceNumber
= Count
;
490 WinNtDevice
->Signature
= WIN_NT_IO_DEVICE_SIGNATURE
;
492 Status
= gBS
->InstallMultipleProtocolInterfaces (
493 &WinNtDevice
->Handle
,
494 &gEfiDevicePathProtocolGuid
,
495 WinNtDevice
->DevicePath
,
496 &gEfiWinNtIoProtocolGuid
,
497 &WinNtDevice
->WinNtIo
,
500 if (EFI_ERROR (Status
)) {
501 FreeUnicodeStringTable (WinNtDevice
->ControllerNameTable
);
502 gBS
->FreePool (WinNtDevice
);
505 // Open For Child Device
507 Status
= gBS
->OpenProtocol (
509 &gEfiWinNtThunkProtocolGuid
,
511 This
->DriverBindingHandle
,
513 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
515 if (!EFI_ERROR (Status
)) {
516 InstallStatus
= EFI_SUCCESS
;
522 // Parse Next sub string. This will point to '\0' if we are at the end.
525 StartString
= SubString
;
528 gBS
->FreePool (TempStr
);
537 WinNtBusDriverBindingStop (
538 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
539 IN EFI_HANDLE ControllerHandle
,
540 IN UINTN NumberOfChildren
,
541 IN EFI_HANDLE
*ChildHandleBuffer
554 // TODO: This - add argument and description to function comment
555 // TODO: ControllerHandle - add argument and description to function comment
556 // TODO: NumberOfChildren - add argument and description to function comment
557 // TODO: ChildHandleBuffer - add argument and description to function comment
558 // TODO: EFI_SUCCESS - add return value to function comment
559 // TODO: EFI_DEVICE_ERROR - add return value to function comment
560 // TODO: EFI_SUCCESS - add return value to function comment
564 BOOLEAN AllChildrenStopped
;
565 EFI_WIN_NT_IO_PROTOCOL
*WinNtIo
;
566 WIN_NT_BUS_DEVICE
*WinNtBusDevice
;
567 WIN_NT_IO_DEVICE
*WinNtDevice
;
568 EFI_WIN_NT_THUNK_PROTOCOL
*WinNtThunk
;
571 // Complete all outstanding transactions to Controller.
572 // Don't allow any new transaction to Controller to be started.
575 if (NumberOfChildren
== 0) {
577 // Close the bus driver
579 Status
= gBS
->OpenProtocol (
581 &gWinNtBusDriverGuid
,
583 This
->DriverBindingHandle
,
585 EFI_OPEN_PROTOCOL_GET_PROTOCOL
587 if (EFI_ERROR (Status
)) {
591 gBS
->UninstallMultipleProtocolInterfaces (
593 &gWinNtBusDriverGuid
,
598 FreeUnicodeStringTable (WinNtBusDevice
->ControllerNameTable
);
600 gBS
->FreePool (WinNtBusDevice
);
604 &gEfiWinNtThunkProtocolGuid
,
605 This
->DriverBindingHandle
,
611 &gEfiDevicePathProtocolGuid
,
612 This
->DriverBindingHandle
,
618 AllChildrenStopped
= TRUE
;
620 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
622 Status
= gBS
->OpenProtocol (
623 ChildHandleBuffer
[Index
],
624 &gEfiWinNtIoProtocolGuid
,
626 This
->DriverBindingHandle
,
628 EFI_OPEN_PROTOCOL_GET_PROTOCOL
630 if (!EFI_ERROR (Status
)) {
632 WinNtDevice
= WIN_NT_IO_DEVICE_FROM_THIS (WinNtIo
);
634 Status
= gBS
->CloseProtocol (
636 &gEfiWinNtThunkProtocolGuid
,
637 This
->DriverBindingHandle
,
641 Status
= gBS
->UninstallMultipleProtocolInterfaces (
643 &gEfiDevicePathProtocolGuid
,
644 WinNtDevice
->DevicePath
,
645 &gEfiWinNtIoProtocolGuid
,
646 &WinNtDevice
->WinNtIo
,
650 if (EFI_ERROR (Status
)) {
653 &gEfiWinNtThunkProtocolGuid
,
654 (VOID
**) &WinNtThunk
,
655 This
->DriverBindingHandle
,
657 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
661 // Close the child handle
663 FreeUnicodeStringTable (WinNtDevice
->ControllerNameTable
);
664 gBS
->FreePool (WinNtDevice
);
668 if (EFI_ERROR (Status
)) {
669 AllChildrenStopped
= FALSE
;
673 if (!AllChildrenStopped
) {
674 return EFI_DEVICE_ERROR
;
680 EFI_DEVICE_PATH_PROTOCOL
*
681 WinNtBusCreateDevicePath (
682 IN EFI_DEVICE_PATH_PROTOCOL
*RootDevicePath
,
684 IN UINT16 InstanceNumber
689 Create a device path node using Guid and InstanceNumber and append it to
690 the passed in RootDevicePath
693 RootDevicePath - Root of the device path to return.
695 Guid - GUID to use in vendor device path node.
697 InstanceNumber - Instance number to use in the vendor device path. This
698 argument is needed to make sure each device path is unique.
702 EFI_DEVICE_PATH_PROTOCOL
706 WIN_NT_VENDOR_DEVICE_PATH_NODE DevicePath
;
708 DevicePath
.VendorDevicePath
.Header
.Type
= HARDWARE_DEVICE_PATH
;
709 DevicePath
.VendorDevicePath
.Header
.SubType
= HW_VENDOR_DP
;
710 SetDevicePathNodeLength (&DevicePath
.VendorDevicePath
.Header
, sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE
));
713 // The GUID defines the Class
715 CopyMem (&DevicePath
.VendorDevicePath
.Guid
, Guid
, sizeof (EFI_GUID
));
718 // Add an instance number so we can make sure there are no Device Path
721 DevicePath
.Instance
= InstanceNumber
;
723 return AppendDevicePathNode (
725 (EFI_DEVICE_PATH_PROTOCOL
*) &DevicePath