3 Copyright (c) 2006 - 2007, 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"
102 extern EFI_GUID gWinNtBusDriverGuid
;
104 // DriverBinding protocol global
106 EFI_DRIVER_BINDING_PROTOCOL gWinNtBusDriverBinding
= {
107 WinNtBusDriverBindingSupported
,
108 WinNtBusDriverBindingStart
,
109 WinNtBusDriverBindingStop
,
115 #define NT_PCD_ARRAY_SIZE (sizeof(mPcdEnvironment)/sizeof(NT_PCD_ENTRY))
118 // Table to map NT Environment variable to the GUID that should be in
121 static NT_PCD_ENTRY mPcdEnvironment
[] = {
122 PcdToken(PcdWinNtConsole
), &gEfiWinNtConsoleGuid
,
123 PcdToken(PcdWinNtUga
), &gEfiWinNtUgaGuid
,
124 PcdToken(PcdWinNtGop
), &gEfiWinNtGopGuid
,
125 PcdToken(PcdWinNtSerialPort
), &gEfiWinNtSerialPortGuid
,
126 PcdToken(PcdWinNtFileSystem
), &gEfiWinNtFileSystemGuid
,
127 PcdToken(PcdWinNtVirtualDisk
), &gEfiWinNtVirtualDisksGuid
,
128 PcdToken(PcdWinNtPhysicalDisk
), &gEfiWinNtPhysicalDisksGuid
,
129 PcdToken(PcdWinNtCpuModel
), &gEfiWinNtCPUModelGuid
,
130 PcdToken(PcdWinNtCpuSpeed
), &gEfiWinNtCPUSpeedGuid
,
131 PcdToken(PcdWinNtMemorySize
), &gEfiWinNtMemoryGuid
142 Status
= gBS
->AllocatePool (
147 if (EFI_ERROR (Status
)) {
157 WinNtBusDriverBindingSupported (
158 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
159 IN EFI_HANDLE ControllerHandle
,
160 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
173 // TODO: This - add argument and description to function comment
174 // TODO: ControllerHandle - add argument and description to function comment
175 // TODO: RemainingDevicePath - add argument and description to function comment
176 // TODO: EFI_UNSUPPORTED - add return value to function comment
177 // TODO: EFI_UNSUPPORTED - add return value to function comment
178 // TODO: EFI_SUCCESS - add return value to function comment
179 // TODO: EFI_SUCCESS - add return value to function comment
182 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
183 EFI_WIN_NT_THUNK_PROTOCOL
*WinNtThunk
;
187 // Check the contents of the first Device Path Node of RemainingDevicePath to make sure
188 // it is a legal Device Path Node for this bus driver's children.
190 if (RemainingDevicePath
!= NULL
) {
191 if (RemainingDevicePath
->Type
!= HARDWARE_DEVICE_PATH
||
192 RemainingDevicePath
->SubType
!= HW_VENDOR_DP
||
193 DevicePathNodeLength(RemainingDevicePath
) != sizeof(WIN_NT_VENDOR_DEVICE_PATH_NODE
)) {
194 return EFI_UNSUPPORTED
;
197 for (Index
= 0; Index
< NT_PCD_ARRAY_SIZE
; Index
++) {
198 if (CompareGuid (&((VENDOR_DEVICE_PATH
*) RemainingDevicePath
)->Guid
, mPcdEnvironment
[Index
].DevicePathGuid
)) {
203 if (Index
>= NT_PCD_ARRAY_SIZE
) {
204 return EFI_UNSUPPORTED
;
209 // Open the IO Abstraction(s) needed to perform the supported test
211 Status
= gBS
->OpenProtocol (
213 &gEfiDevicePathProtocolGuid
,
215 This
->DriverBindingHandle
,
217 EFI_OPEN_PROTOCOL_BY_DRIVER
219 if (Status
== EFI_ALREADY_STARTED
) {
223 if (EFI_ERROR (Status
)) {
229 &gEfiDevicePathProtocolGuid
,
230 This
->DriverBindingHandle
,
234 Status
= gBS
->OpenProtocol (
236 &gEfiWinNtThunkProtocolGuid
,
238 This
->DriverBindingHandle
,
240 EFI_OPEN_PROTOCOL_BY_DRIVER
242 if (Status
== EFI_ALREADY_STARTED
) {
246 if (EFI_ERROR (Status
)) {
251 // Since we call through WinNtThunk we need to make sure it's valid
253 Status
= EFI_SUCCESS
;
254 if (WinNtThunk
->Signature
!= EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE
) {
255 Status
= EFI_UNSUPPORTED
;
259 // Close the I/O Abstraction(s) used to perform the supported test
263 &gEfiWinNtThunkProtocolGuid
,
264 This
->DriverBindingHandle
,
273 WinNtBusDriverBindingStart (
274 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
275 IN EFI_HANDLE ControllerHandle
,
276 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
289 // TODO: This - add argument and description to function comment
290 // TODO: ControllerHandle - add argument and description to function comment
291 // TODO: RemainingDevicePath - add argument and description to function comment
292 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
293 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
294 // TODO: EFI_SUCCESS - add return value to function comment
297 EFI_STATUS InstallStatus
;
298 EFI_WIN_NT_THUNK_PROTOCOL
*WinNtThunk
;
299 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
300 WIN_NT_BUS_DEVICE
*WinNtBusDevice
;
301 WIN_NT_IO_DEVICE
*WinNtDevice
;
307 UINT16 ComponentName
[MAX_NT_ENVIRNMENT_VARIABLE_LENGTH
];
308 WIN_NT_VENDOR_DEVICE_PATH_NODE
*Node
;
309 BOOLEAN CreateDevice
;
314 Status
= EFI_UNSUPPORTED
;
317 // Grab the protocols we need
319 Status
= gBS
->OpenProtocol (
321 &gEfiDevicePathProtocolGuid
,
323 This
->DriverBindingHandle
,
325 EFI_OPEN_PROTOCOL_BY_DRIVER
327 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
331 Status
= gBS
->OpenProtocol (
333 &gEfiWinNtThunkProtocolGuid
,
335 This
->DriverBindingHandle
,
337 EFI_OPEN_PROTOCOL_BY_DRIVER
339 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
343 if (Status
!= EFI_ALREADY_STARTED
) {
344 Status
= gBS
->AllocatePool (
346 sizeof (WIN_NT_BUS_DEVICE
),
347 (VOID
*) &WinNtBusDevice
349 if (EFI_ERROR (Status
)) {
353 WinNtBusDevice
->Signature
= WIN_NT_BUS_DEVICE_SIGNATURE
;
354 WinNtBusDevice
->ControllerNameTable
= NULL
;
358 gWinNtBusDriverComponentName
.SupportedLanguages
,
359 &WinNtBusDevice
->ControllerNameTable
,
360 L
"Windows Bus Controller"
363 Status
= gBS
->InstallMultipleProtocolInterfaces (
365 &gWinNtBusDriverGuid
,
369 if (EFI_ERROR (Status
)) {
370 FreeUnicodeStringTable (WinNtBusDevice
->ControllerNameTable
);
371 gBS
->FreePool (WinNtBusDevice
);
377 // Loop on the Variable list. Parse each variable to produce a set of handles that
378 // represent virtual hardware devices.
380 InstallStatus
= EFI_NOT_FOUND
;
381 for (Index
= 0; Index
< NT_PCD_ARRAY_SIZE
; Index
++) {
382 PcdTempStr
= (VOID
*)LibPcdGetPtr (mPcdEnvironment
[Index
].Token
);
383 ASSERT (PcdTempStr
!= NULL
);
385 TempStrSize
= StrLen (PcdTempStr
);
386 TempStr
= AllocateMemory ((TempStrSize
* sizeof (CHAR16
)) + 1);
387 StrCpy (TempStr
, PcdTempStr
);
389 StartString
= TempStr
;
392 // Parse the envirnment variable into sub strings using '!' as a delimator.
393 // Each substring needs it's own handle to be added to the system. This code
394 // does not understand the sub string. Thats the device drivers job.
397 while (*StartString
!= '\0') {
400 // Find the end of the sub string
402 SubString
= StartString
;
403 while (*SubString
!= '\0' && *SubString
!= '!') {
407 if (*SubString
== '!') {
409 // Replace token with '\0' to make sub strings. If this is the end
410 // of the string SubString will already point to NULL.
417 if (RemainingDevicePath
!= NULL
) {
418 CreateDevice
= FALSE
;
419 Node
= (WIN_NT_VENDOR_DEVICE_PATH_NODE
*) RemainingDevicePath
;
420 if (Node
->VendorDevicePath
.Header
.Type
== HARDWARE_DEVICE_PATH
&&
421 Node
->VendorDevicePath
.Header
.SubType
== HW_VENDOR_DP
&&
422 DevicePathNodeLength (&Node
->VendorDevicePath
.Header
) == sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE
)
424 if (CompareGuid (&Node
->VendorDevicePath
.Guid
, mPcdEnvironment
[Index
].DevicePathGuid
) &&
425 Node
->Instance
== Count
435 // Allocate instance structure, and fill in parent information.
437 WinNtDevice
= AllocateMemory (sizeof (WIN_NT_IO_DEVICE
));
438 if (WinNtDevice
== NULL
) {
439 return EFI_OUT_OF_RESOURCES
;
442 WinNtDevice
->Handle
= NULL
;
443 WinNtDevice
->ControllerHandle
= ControllerHandle
;
444 WinNtDevice
->ParentDevicePath
= ParentDevicePath
;
446 WinNtDevice
->WinNtIo
.WinNtThunk
= WinNtThunk
;
449 // Plus 2 to account for the NULL at the end of the Unicode string
451 StringSize
= (UINTN
) ((UINT8
*) SubString
- (UINT8
*) StartString
) + sizeof (CHAR16
);
452 WinNtDevice
->WinNtIo
.EnvString
= AllocateMemory (StringSize
);
453 if (WinNtDevice
->WinNtIo
.EnvString
!= NULL
) {
454 CopyMem (WinNtDevice
->WinNtIo
.EnvString
, StartString
, StringSize
);
457 WinNtDevice
->ControllerNameTable
= NULL
;
459 WinNtThunk
->SPrintf (ComponentName
, sizeof (ComponentName
), L
"%s", WinNtDevice
->WinNtIo
.EnvString
);
461 WinNtDevice
->DevicePath
= WinNtBusCreateDevicePath (
463 mPcdEnvironment
[Index
].DevicePathGuid
,
466 if (WinNtDevice
->DevicePath
== NULL
) {
467 gBS
->FreePool (WinNtDevice
);
468 return EFI_OUT_OF_RESOURCES
;
473 gWinNtBusDriverComponentName
.SupportedLanguages
,
474 &WinNtDevice
->ControllerNameTable
,
478 WinNtDevice
->WinNtIo
.TypeGuid
= mPcdEnvironment
[Index
].DevicePathGuid
;
479 WinNtDevice
->WinNtIo
.InstanceNumber
= Count
;
481 WinNtDevice
->Signature
= WIN_NT_IO_DEVICE_SIGNATURE
;
483 Status
= gBS
->InstallMultipleProtocolInterfaces (
484 &WinNtDevice
->Handle
,
485 &gEfiDevicePathProtocolGuid
,
486 WinNtDevice
->DevicePath
,
487 &gEfiWinNtIoProtocolGuid
,
488 &WinNtDevice
->WinNtIo
,
491 if (EFI_ERROR (Status
)) {
492 FreeUnicodeStringTable (WinNtDevice
->ControllerNameTable
);
493 gBS
->FreePool (WinNtDevice
);
496 // Open For Child Device
498 Status
= gBS
->OpenProtocol (
500 &gEfiWinNtThunkProtocolGuid
,
502 This
->DriverBindingHandle
,
504 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
506 if (!EFI_ERROR (Status
)) {
507 InstallStatus
= EFI_SUCCESS
;
513 // Parse Next sub string. This will point to '\0' if we are at the end.
516 StartString
= SubString
;
519 gBS
->FreePool (TempStr
);
528 WinNtBusDriverBindingStop (
529 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
530 IN EFI_HANDLE ControllerHandle
,
531 IN UINTN NumberOfChildren
,
532 IN EFI_HANDLE
*ChildHandleBuffer
545 // TODO: This - add argument and description to function comment
546 // TODO: ControllerHandle - add argument and description to function comment
547 // TODO: NumberOfChildren - add argument and description to function comment
548 // TODO: ChildHandleBuffer - add argument and description to function comment
549 // TODO: EFI_SUCCESS - add return value to function comment
550 // TODO: EFI_DEVICE_ERROR - add return value to function comment
551 // TODO: EFI_SUCCESS - add return value to function comment
555 BOOLEAN AllChildrenStopped
;
556 EFI_WIN_NT_IO_PROTOCOL
*WinNtIo
;
557 WIN_NT_BUS_DEVICE
*WinNtBusDevice
;
558 WIN_NT_IO_DEVICE
*WinNtDevice
;
559 EFI_WIN_NT_THUNK_PROTOCOL
*WinNtThunk
;
562 // Complete all outstanding transactions to Controller.
563 // Don't allow any new transaction to Controller to be started.
566 if (NumberOfChildren
== 0) {
568 // Close the bus driver
570 Status
= gBS
->OpenProtocol (
572 &gWinNtBusDriverGuid
,
574 This
->DriverBindingHandle
,
576 EFI_OPEN_PROTOCOL_GET_PROTOCOL
578 if (EFI_ERROR (Status
)) {
582 gBS
->UninstallMultipleProtocolInterfaces (
584 &gWinNtBusDriverGuid
,
589 FreeUnicodeStringTable (WinNtBusDevice
->ControllerNameTable
);
591 gBS
->FreePool (WinNtBusDevice
);
595 &gEfiWinNtThunkProtocolGuid
,
596 This
->DriverBindingHandle
,
602 &gEfiDevicePathProtocolGuid
,
603 This
->DriverBindingHandle
,
609 AllChildrenStopped
= TRUE
;
611 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
613 Status
= gBS
->OpenProtocol (
614 ChildHandleBuffer
[Index
],
615 &gEfiWinNtIoProtocolGuid
,
617 This
->DriverBindingHandle
,
619 EFI_OPEN_PROTOCOL_GET_PROTOCOL
621 if (!EFI_ERROR (Status
)) {
623 WinNtDevice
= WIN_NT_IO_DEVICE_FROM_THIS (WinNtIo
);
625 Status
= gBS
->CloseProtocol (
627 &gEfiWinNtThunkProtocolGuid
,
628 This
->DriverBindingHandle
,
632 Status
= gBS
->UninstallMultipleProtocolInterfaces (
634 &gEfiDevicePathProtocolGuid
,
635 WinNtDevice
->DevicePath
,
636 &gEfiWinNtIoProtocolGuid
,
637 &WinNtDevice
->WinNtIo
,
641 if (EFI_ERROR (Status
)) {
644 &gEfiWinNtThunkProtocolGuid
,
645 (VOID
**) &WinNtThunk
,
646 This
->DriverBindingHandle
,
648 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
652 // Close the child handle
654 FreeUnicodeStringTable (WinNtDevice
->ControllerNameTable
);
655 gBS
->FreePool (WinNtDevice
);
659 if (EFI_ERROR (Status
)) {
660 AllChildrenStopped
= FALSE
;
664 if (!AllChildrenStopped
) {
665 return EFI_DEVICE_ERROR
;
671 EFI_DEVICE_PATH_PROTOCOL
*
672 WinNtBusCreateDevicePath (
673 IN EFI_DEVICE_PATH_PROTOCOL
*RootDevicePath
,
675 IN UINT16 InstanceNumber
680 Create a device path node using Guid and InstanceNumber and append it to
681 the passed in RootDevicePath
684 RootDevicePath - Root of the device path to return.
686 Guid - GUID to use in vendor device path node.
688 InstanceNumber - Instance number to use in the vendor device path. This
689 argument is needed to make sure each device path is unique.
693 EFI_DEVICE_PATH_PROTOCOL
697 WIN_NT_VENDOR_DEVICE_PATH_NODE DevicePath
;
699 DevicePath
.VendorDevicePath
.Header
.Type
= HARDWARE_DEVICE_PATH
;
700 DevicePath
.VendorDevicePath
.Header
.SubType
= HW_VENDOR_DP
;
701 SetDevicePathNodeLength (&DevicePath
.VendorDevicePath
.Header
, sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE
));
704 // The GUID defines the Class
706 CopyMem (&DevicePath
.VendorDevicePath
.Guid
, Guid
, sizeof (EFI_GUID
));
709 // Add an instance number so we can make sure there are no Device Path
712 DevicePath
.Instance
= InstanceNumber
;
714 return AppendDevicePathNode (
716 (EFI_DEVICE_PATH_PROTOCOL
*) &DevicePath