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"
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 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
125 PcdToken(PcdWinNtGop
), &gEfiWinNtGopGuid
,
127 PcdToken(PcdWinNtSerialPort
), &gEfiWinNtSerialPortGuid
,
128 PcdToken(PcdWinNtFileSystem
), &gEfiWinNtFileSystemGuid
,
129 PcdToken(PcdWinNtVirtualDisk
), &gEfiWinNtVirtualDisksGuid
,
130 PcdToken(PcdWinNtPhysicalDisk
), &gEfiWinNtPhysicalDisksGuid
,
131 PcdToken(PcdWinNtCpuModel
), &gEfiWinNtCPUModelGuid
,
132 PcdToken(PcdWinNtCpuSpeed
), &gEfiWinNtCPUSpeedGuid
,
133 PcdToken(PcdWinNtMemorySize
), &gEfiWinNtMemoryGuid
144 Status
= gBS
->AllocatePool (
149 if (EFI_ERROR (Status
)) {
159 WinNtBusDriverBindingSupported (
160 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
161 IN EFI_HANDLE ControllerHandle
,
162 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
175 // TODO: This - add argument and description to function comment
176 // TODO: ControllerHandle - add argument and description to function comment
177 // TODO: RemainingDevicePath - add argument and description to function comment
178 // TODO: EFI_UNSUPPORTED - add return value to function comment
179 // TODO: EFI_UNSUPPORTED - add return value to function comment
180 // TODO: EFI_SUCCESS - add return value to function comment
181 // TODO: EFI_SUCCESS - add return value to function comment
184 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
185 EFI_WIN_NT_THUNK_PROTOCOL
*WinNtThunk
;
189 // Check the contents of the first Device Path Node of RemainingDevicePath to make sure
190 // it is a legal Device Path Node for this bus driver's children.
192 if (RemainingDevicePath
!= NULL
) {
193 if (RemainingDevicePath
->Type
!= HARDWARE_DEVICE_PATH
||
194 RemainingDevicePath
->SubType
!= HW_VENDOR_DP
||
195 DevicePathNodeLength(RemainingDevicePath
) != sizeof(WIN_NT_VENDOR_DEVICE_PATH_NODE
)) {
196 return EFI_UNSUPPORTED
;
199 for (Index
= 0; Index
< NT_PCD_ARRAY_SIZE
; Index
++) {
200 if (CompareGuid (&((VENDOR_DEVICE_PATH
*) RemainingDevicePath
)->Guid
, mPcdEnvironment
[Index
].DevicePathGuid
)) {
205 if (Index
>= NT_PCD_ARRAY_SIZE
) {
206 return EFI_UNSUPPORTED
;
211 // Open the IO Abstraction(s) needed to perform the supported test
213 Status
= gBS
->OpenProtocol (
215 &gEfiDevicePathProtocolGuid
,
217 This
->DriverBindingHandle
,
219 EFI_OPEN_PROTOCOL_BY_DRIVER
221 if (Status
== EFI_ALREADY_STARTED
) {
225 if (EFI_ERROR (Status
)) {
231 &gEfiDevicePathProtocolGuid
,
232 This
->DriverBindingHandle
,
236 Status
= gBS
->OpenProtocol (
238 &gEfiWinNtThunkProtocolGuid
,
240 This
->DriverBindingHandle
,
242 EFI_OPEN_PROTOCOL_BY_DRIVER
244 if (Status
== EFI_ALREADY_STARTED
) {
248 if (EFI_ERROR (Status
)) {
253 // Since we call through WinNtThunk we need to make sure it's valid
255 Status
= EFI_SUCCESS
;
256 if (WinNtThunk
->Signature
!= EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE
) {
257 Status
= EFI_UNSUPPORTED
;
261 // Close the I/O Abstraction(s) used to perform the supported test
265 &gEfiWinNtThunkProtocolGuid
,
266 This
->DriverBindingHandle
,
275 WinNtBusDriverBindingStart (
276 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
277 IN EFI_HANDLE ControllerHandle
,
278 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
291 // TODO: This - add argument and description to function comment
292 // TODO: ControllerHandle - add argument and description to function comment
293 // TODO: RemainingDevicePath - add argument and description to function comment
294 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
295 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
296 // TODO: EFI_SUCCESS - add return value to function comment
299 EFI_STATUS InstallStatus
;
300 EFI_WIN_NT_THUNK_PROTOCOL
*WinNtThunk
;
301 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
302 WIN_NT_BUS_DEVICE
*WinNtBusDevice
;
303 WIN_NT_IO_DEVICE
*WinNtDevice
;
309 UINT16 ComponentName
[MAX_NT_ENVIRNMENT_VARIABLE_LENGTH
];
310 WIN_NT_VENDOR_DEVICE_PATH_NODE
*Node
;
311 BOOLEAN CreateDevice
;
316 Status
= EFI_UNSUPPORTED
;
319 // Grab the protocols we need
321 Status
= gBS
->OpenProtocol (
323 &gEfiDevicePathProtocolGuid
,
325 This
->DriverBindingHandle
,
327 EFI_OPEN_PROTOCOL_BY_DRIVER
329 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
333 Status
= gBS
->OpenProtocol (
335 &gEfiWinNtThunkProtocolGuid
,
337 This
->DriverBindingHandle
,
339 EFI_OPEN_PROTOCOL_BY_DRIVER
341 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
345 if (Status
!= EFI_ALREADY_STARTED
) {
346 Status
= gBS
->AllocatePool (
348 sizeof (WIN_NT_BUS_DEVICE
),
349 (VOID
*) &WinNtBusDevice
351 if (EFI_ERROR (Status
)) {
355 WinNtBusDevice
->Signature
= WIN_NT_BUS_DEVICE_SIGNATURE
;
356 WinNtBusDevice
->ControllerNameTable
= NULL
;
360 gWinNtBusDriverComponentName
.SupportedLanguages
,
361 &WinNtBusDevice
->ControllerNameTable
,
362 L
"Windows Bus Controller"
365 Status
= gBS
->InstallMultipleProtocolInterfaces (
367 &gWinNtBusDriverGuid
,
371 if (EFI_ERROR (Status
)) {
372 FreeUnicodeStringTable (WinNtBusDevice
->ControllerNameTable
);
373 gBS
->FreePool (WinNtBusDevice
);
379 // Loop on the Variable list. Parse each variable to produce a set of handles that
380 // represent virtual hardware devices.
382 InstallStatus
= EFI_NOT_FOUND
;
383 for (Index
= 0; Index
< NT_PCD_ARRAY_SIZE
; Index
++) {
384 PcdTempStr
= (VOID
*)LibPcdGetPtr (mPcdEnvironment
[Index
].Token
);
385 ASSERT (PcdTempStr
!= NULL
);
387 TempStrSize
= StrLen (PcdTempStr
);
388 TempStr
= AllocateMemory ((TempStrSize
* sizeof (CHAR16
)) + 1);
389 StrCpy (TempStr
, PcdTempStr
);
391 StartString
= TempStr
;
394 // Parse the envirnment variable into sub strings using '!' as a delimator.
395 // Each substring needs it's own handle to be added to the system. This code
396 // does not understand the sub string. Thats the device drivers job.
399 while (*StartString
!= '\0') {
402 // Find the end of the sub string
404 SubString
= StartString
;
405 while (*SubString
!= '\0' && *SubString
!= '!') {
409 if (*SubString
== '!') {
411 // Replace token with '\0' to make sub strings. If this is the end
412 // of the string SubString will already point to NULL.
419 if (RemainingDevicePath
!= NULL
) {
420 CreateDevice
= FALSE
;
421 Node
= (WIN_NT_VENDOR_DEVICE_PATH_NODE
*) RemainingDevicePath
;
422 if (Node
->VendorDevicePath
.Header
.Type
== HARDWARE_DEVICE_PATH
&&
423 Node
->VendorDevicePath
.Header
.SubType
== HW_VENDOR_DP
&&
424 DevicePathNodeLength (&Node
->VendorDevicePath
.Header
) == sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE
)
426 if (CompareGuid (&Node
->VendorDevicePath
.Guid
, mPcdEnvironment
[Index
].DevicePathGuid
) &&
427 Node
->Instance
== Count
437 // Allocate instance structure, and fill in parent information.
439 WinNtDevice
= AllocateMemory (sizeof (WIN_NT_IO_DEVICE
));
440 if (WinNtDevice
== NULL
) {
441 return EFI_OUT_OF_RESOURCES
;
444 WinNtDevice
->Handle
= NULL
;
445 WinNtDevice
->ControllerHandle
= ControllerHandle
;
446 WinNtDevice
->ParentDevicePath
= ParentDevicePath
;
448 WinNtDevice
->WinNtIo
.WinNtThunk
= WinNtThunk
;
451 // Plus 2 to account for the NULL at the end of the Unicode string
453 StringSize
= (UINTN
) ((UINT8
*) SubString
- (UINT8
*) StartString
) + sizeof (CHAR16
);
454 WinNtDevice
->WinNtIo
.EnvString
= AllocateMemory (StringSize
);
455 if (WinNtDevice
->WinNtIo
.EnvString
!= NULL
) {
456 CopyMem (WinNtDevice
->WinNtIo
.EnvString
, StartString
, StringSize
);
459 WinNtDevice
->ControllerNameTable
= NULL
;
461 WinNtThunk
->SPrintf (ComponentName
, sizeof (ComponentName
), L
"%s", WinNtDevice
->WinNtIo
.EnvString
);
463 WinNtDevice
->DevicePath
= WinNtBusCreateDevicePath (
465 mPcdEnvironment
[Index
].DevicePathGuid
,
468 if (WinNtDevice
->DevicePath
== NULL
) {
469 gBS
->FreePool (WinNtDevice
);
470 return EFI_OUT_OF_RESOURCES
;
475 gWinNtBusDriverComponentName
.SupportedLanguages
,
476 &WinNtDevice
->ControllerNameTable
,
480 WinNtDevice
->WinNtIo
.TypeGuid
= mPcdEnvironment
[Index
].DevicePathGuid
;
481 WinNtDevice
->WinNtIo
.InstanceNumber
= Count
;
483 WinNtDevice
->Signature
= WIN_NT_IO_DEVICE_SIGNATURE
;
485 Status
= gBS
->InstallMultipleProtocolInterfaces (
486 &WinNtDevice
->Handle
,
487 &gEfiDevicePathProtocolGuid
,
488 WinNtDevice
->DevicePath
,
489 &gEfiWinNtIoProtocolGuid
,
490 &WinNtDevice
->WinNtIo
,
493 if (EFI_ERROR (Status
)) {
494 FreeUnicodeStringTable (WinNtDevice
->ControllerNameTable
);
495 gBS
->FreePool (WinNtDevice
);
498 // Open For Child Device
500 Status
= gBS
->OpenProtocol (
502 &gEfiWinNtThunkProtocolGuid
,
504 This
->DriverBindingHandle
,
506 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
508 if (!EFI_ERROR (Status
)) {
509 InstallStatus
= EFI_SUCCESS
;
515 // Parse Next sub string. This will point to '\0' if we are at the end.
518 StartString
= SubString
;
521 gBS
->FreePool (TempStr
);
530 WinNtBusDriverBindingStop (
531 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
532 IN EFI_HANDLE ControllerHandle
,
533 IN UINTN NumberOfChildren
,
534 IN EFI_HANDLE
*ChildHandleBuffer
547 // TODO: This - add argument and description to function comment
548 // TODO: ControllerHandle - add argument and description to function comment
549 // TODO: NumberOfChildren - add argument and description to function comment
550 // TODO: ChildHandleBuffer - add argument and description to function comment
551 // TODO: EFI_SUCCESS - add return value to function comment
552 // TODO: EFI_DEVICE_ERROR - add return value to function comment
553 // TODO: EFI_SUCCESS - add return value to function comment
557 BOOLEAN AllChildrenStopped
;
558 EFI_WIN_NT_IO_PROTOCOL
*WinNtIo
;
559 WIN_NT_BUS_DEVICE
*WinNtBusDevice
;
560 WIN_NT_IO_DEVICE
*WinNtDevice
;
561 EFI_WIN_NT_THUNK_PROTOCOL
*WinNtThunk
;
564 // Complete all outstanding transactions to Controller.
565 // Don't allow any new transaction to Controller to be started.
568 if (NumberOfChildren
== 0) {
570 // Close the bus driver
572 Status
= gBS
->OpenProtocol (
574 &gWinNtBusDriverGuid
,
576 This
->DriverBindingHandle
,
578 EFI_OPEN_PROTOCOL_GET_PROTOCOL
580 if (EFI_ERROR (Status
)) {
584 gBS
->UninstallMultipleProtocolInterfaces (
586 &gWinNtBusDriverGuid
,
591 FreeUnicodeStringTable (WinNtBusDevice
->ControllerNameTable
);
593 gBS
->FreePool (WinNtBusDevice
);
597 &gEfiWinNtThunkProtocolGuid
,
598 This
->DriverBindingHandle
,
604 &gEfiDevicePathProtocolGuid
,
605 This
->DriverBindingHandle
,
611 AllChildrenStopped
= TRUE
;
613 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
615 Status
= gBS
->OpenProtocol (
616 ChildHandleBuffer
[Index
],
617 &gEfiWinNtIoProtocolGuid
,
619 This
->DriverBindingHandle
,
621 EFI_OPEN_PROTOCOL_GET_PROTOCOL
623 if (!EFI_ERROR (Status
)) {
625 WinNtDevice
= WIN_NT_IO_DEVICE_FROM_THIS (WinNtIo
);
627 Status
= gBS
->CloseProtocol (
629 &gEfiWinNtThunkProtocolGuid
,
630 This
->DriverBindingHandle
,
634 Status
= gBS
->UninstallMultipleProtocolInterfaces (
636 &gEfiDevicePathProtocolGuid
,
637 WinNtDevice
->DevicePath
,
638 &gEfiWinNtIoProtocolGuid
,
639 &WinNtDevice
->WinNtIo
,
643 if (EFI_ERROR (Status
)) {
646 &gEfiWinNtThunkProtocolGuid
,
647 (VOID
**) &WinNtThunk
,
648 This
->DriverBindingHandle
,
650 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
654 // Close the child handle
656 FreeUnicodeStringTable (WinNtDevice
->ControllerNameTable
);
657 gBS
->FreePool (WinNtDevice
);
661 if (EFI_ERROR (Status
)) {
662 AllChildrenStopped
= FALSE
;
666 if (!AllChildrenStopped
) {
667 return EFI_DEVICE_ERROR
;
673 EFI_DEVICE_PATH_PROTOCOL
*
674 WinNtBusCreateDevicePath (
675 IN EFI_DEVICE_PATH_PROTOCOL
*RootDevicePath
,
677 IN UINT16 InstanceNumber
682 Create a device path node using Guid and InstanceNumber and append it to
683 the passed in RootDevicePath
686 RootDevicePath - Root of the device path to return.
688 Guid - GUID to use in vendor device path node.
690 InstanceNumber - Instance number to use in the vendor device path. This
691 argument is needed to make sure each device path is unique.
695 EFI_DEVICE_PATH_PROTOCOL
699 WIN_NT_VENDOR_DEVICE_PATH_NODE DevicePath
;
701 DevicePath
.VendorDevicePath
.Header
.Type
= HARDWARE_DEVICE_PATH
;
702 DevicePath
.VendorDevicePath
.Header
.SubType
= HW_VENDOR_DP
;
703 SetDevicePathNodeLength (&DevicePath
.VendorDevicePath
.Header
, sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE
));
706 // The GUID defines the Class
708 CopyMem (&DevicePath
.VendorDevicePath
.Guid
, Guid
, sizeof (EFI_GUID
));
711 // Add an instance number so we can make sure there are no Device Path
714 DevicePath
.Instance
= InstanceNumber
;
716 return AppendDevicePathNode (
718 (EFI_DEVICE_PATH_PROTOCOL
*) &DevicePath