• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 Defined the platform specific device path which will be filled to
3 ConIn/ConOut variables.
4 
5 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution.  The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10 
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 
14 **/
15 
16 #include "PlatformBootManager.h"
17 
18 ///
19 /// the short form device path for Usb keyboard
20 ///
21 #define CLASS_HID           3
22 #define SUBCLASS_BOOT       1
23 #define PROTOCOL_KEYBOARD   1
24 
25 ///
26 /// PcdDefaultTerminalType values
27 ///
28 #define PCANSITYPE                0
29 #define VT100TYPE                 1
30 #define VT100PLUSTYPE             2
31 #define VTUTF8TYPE                3
32 #define TTYTERMTYPE               4
33 
34 //
35 // Below is the platform console device path
36 //
37 typedef struct {
38   ACPI_HID_DEVICE_PATH            PciRootBridge;
39   PCI_DEVICE_PATH                 PciUart;
40   UART_DEVICE_PATH                Uart;
41   VENDOR_DEVICE_PATH              TerminalType;
42   EFI_DEVICE_PATH_PROTOCOL        End;
43 } PCI_UART_DEVICE_PATH;
44 
45 typedef struct {
46   VENDOR_DEVICE_PATH        VendorHardware;
47   UART_DEVICE_PATH          Uart;
48   VENDOR_DEVICE_PATH        TerminalType;
49   EFI_DEVICE_PATH_PROTOCOL  End;
50 } VENDOR_UART_DEVICE_PATH;
51 
52 typedef struct {
53   USB_CLASS_DEVICE_PATH           UsbClass;
54   EFI_DEVICE_PATH_PROTOCOL        End;
55 } USB_CLASS_FORMAT_DEVICE_PATH;
56 
57 #define PNPID_DEVICE_PATH_NODE(PnpId) \
58   { \
59     { \
60       ACPI_DEVICE_PATH, \
61       ACPI_DP, \
62       { \
63         (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), \
64         (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) \
65       } \
66     }, \
67     EISA_PNP_ID((PnpId)), \
68     0 \
69   }
70 
71 #define PCI_DEVICE_PATH_NODE(Func, Dev) \
72   { \
73     { \
74       HARDWARE_DEVICE_PATH, \
75       HW_PCI_DP, \
76       { \
77         (UINT8) (sizeof (PCI_DEVICE_PATH)), \
78         (UINT8) ((sizeof (PCI_DEVICE_PATH)) >> 8) \
79       }, \
80     }, \
81     (Func), \
82     (Dev) \
83   }
84 
85 #define gEndEntire \
86   { \
87     END_DEVICE_PATH_TYPE, \
88     END_ENTIRE_DEVICE_PATH_SUBTYPE, \
89     { \
90       END_DEVICE_PATH_LENGTH, \
91       0 \
92     } \
93   }
94 
95 //
96 // Platform specific serial device path
97 //
98 PCI_UART_DEVICE_PATH   gPciUartDevicePath0 = {
99   PNPID_DEVICE_PATH_NODE(0x0A03),
100   PCI_DEVICE_PATH_NODE(1, 20),
101   {
102     {
103       MESSAGING_DEVICE_PATH,
104       MSG_UART_DP,
105       {
106         (UINT8)(sizeof (UART_DEVICE_PATH)),
107         (UINT8)((sizeof (UART_DEVICE_PATH)) >> 8)
108       }
109     },
110     0,         // Reserved
111     921600,    // BaudRate
112     8,         // DataBits
113     1,         // Parity
114     1          // StopBits
115   },
116   {
117     {
118       MESSAGING_DEVICE_PATH,
119       MSG_VENDOR_DP,
120       {
121         (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
122         (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
123       },
124     },
125     DEVICE_PATH_MESSAGING_PC_ANSI
126   },
127   gEndEntire
128 };
129 
130 PCI_UART_DEVICE_PATH   gPciUartDevicePath1 = {
131   PNPID_DEVICE_PATH_NODE(0x0A03),
132   PCI_DEVICE_PATH_NODE(5, 20),
133   {
134     {
135       MESSAGING_DEVICE_PATH,
136       MSG_UART_DP,
137       {
138         (UINT8)(sizeof (UART_DEVICE_PATH)),
139         (UINT8)((sizeof (UART_DEVICE_PATH)) >> 8)
140       }
141     },
142     0,         // Reserved
143     921600,    // BaudRate
144     8,         // DataBits
145     1,         // Parity
146     1          // StopBits
147   },
148   {
149     {
150       MESSAGING_DEVICE_PATH,
151       MSG_VENDOR_DP,
152       {
153         (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
154         (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
155       }
156     },
157     DEVICE_PATH_MESSAGING_PC_ANSI
158   },
159   gEndEntire
160 };
161 
162 VENDOR_UART_DEVICE_PATH gDebugAgentUartDevicePath = {
163   {
164     {
165       HARDWARE_DEVICE_PATH,
166       HW_VENDOR_DP,
167       {
168         (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
169         (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
170       }
171     },
172     EFI_DEBUG_AGENT_GUID,
173   },
174   {
175     {
176       MESSAGING_DEVICE_PATH,
177       MSG_UART_DP,
178       {
179         (UINT8) (sizeof (UART_DEVICE_PATH)),
180         (UINT8) ((sizeof (UART_DEVICE_PATH)) >> 8)
181       }
182     },
183     0,  // Reserved
184     0,  // BaudRate - Default
185     0,  // DataBits - Default
186     0,  // Parity   - Default
187     0,  // StopBits - Default
188   },
189   {
190     {
191       MESSAGING_DEVICE_PATH,
192       MSG_VENDOR_DP,
193       {
194         (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
195         (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
196       }
197     },
198     DEVICE_PATH_MESSAGING_PC_ANSI
199   },
200   gEndEntire
201 };
202 
203 USB_CLASS_FORMAT_DEVICE_PATH gUsbClassKeyboardDevicePath = {
204   {
205     {
206       MESSAGING_DEVICE_PATH,
207       MSG_USB_CLASS_DP,
208       {
209         (UINT8)(sizeof (USB_CLASS_DEVICE_PATH)),
210         (UINT8)((sizeof (USB_CLASS_DEVICE_PATH)) >> 8)
211       }
212     },
213     0xffff,              // VendorId  - Match any vendor
214     0xffff,              // ProductId - Match any product
215     CLASS_HID,           // DeviceClass
216     SUBCLASS_BOOT,       // DeviceSubClass
217     PROTOCOL_KEYBOARD    // DeviceProtocol
218   },
219   gEndEntire
220 };
221 
222 //
223 // Predefined platform default console device path
224 //
225 PLATFORM_CONSOLE_CONNECT_ENTRY   gPlatformConsole[] = {
226   { (EFI_DEVICE_PATH_PROTOCOL *) &gPciUartDevicePath0,         (CONSOLE_OUT | CONSOLE_IN) },
227   { (EFI_DEVICE_PATH_PROTOCOL *) &gPciUartDevicePath1,         (CONSOLE_OUT | CONSOLE_IN) },
228   { (EFI_DEVICE_PATH_PROTOCOL *) &gDebugAgentUartDevicePath,   (CONSOLE_OUT | CONSOLE_IN) },
229   { (EFI_DEVICE_PATH_PROTOCOL *) &gUsbClassKeyboardDevicePath, (CONSOLE_IN)               },
230   { NULL, 0 }
231 };
232 
233 EFI_STATUS
234 EFIAPI
InitializePlatformBootManagerLib(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)235 InitializePlatformBootManagerLib (
236   IN EFI_HANDLE        ImageHandle,
237   IN EFI_SYSTEM_TABLE  *SystemTable
238   )
239 {
240   EFI_GUID  *TerminalTypeGuid;
241 
242   //
243   // Update UART device path nodes based on UART PCD settings
244   //
245   gPciUartDevicePath0.Uart.BaudRate = PcdGet64 (PcdUartDefaultBaudRate);
246   gPciUartDevicePath0.Uart.DataBits = PcdGet8 (PcdUartDefaultDataBits);
247   gPciUartDevicePath0.Uart.Parity   = PcdGet8 (PcdUartDefaultParity);
248   gPciUartDevicePath0.Uart.StopBits = PcdGet8 (PcdUartDefaultStopBits);
249   gPciUartDevicePath1.Uart.BaudRate = PcdGet64 (PcdUartDefaultBaudRate);
250   gPciUartDevicePath1.Uart.DataBits = PcdGet8 (PcdUartDefaultDataBits);
251   gPciUartDevicePath1.Uart.Parity   = PcdGet8 (PcdUartDefaultParity);
252   gPciUartDevicePath1.Uart.StopBits = PcdGet8 (PcdUartDefaultStopBits);
253 
254   //
255   // Update Vendor device path nodes based on terminal type PCD settings
256   //
257   switch (PcdGet8 (PcdDefaultTerminalType)) {
258   case PCANSITYPE:
259     TerminalTypeGuid = &gEfiPcAnsiGuid;
260     break;
261   case VT100TYPE:
262     TerminalTypeGuid = &gEfiVT100Guid;
263     break;
264   case VT100PLUSTYPE:
265     TerminalTypeGuid = &gEfiVT100PlusGuid;
266     break;
267   case VTUTF8TYPE:
268     TerminalTypeGuid = &gEfiVTUTF8Guid;
269     break;
270   case TTYTERMTYPE:
271     TerminalTypeGuid = &gEfiTtyTermGuid;
272     break;
273   default:
274     TerminalTypeGuid = &gEfiPcAnsiGuid;
275     break;
276   }
277   CopyGuid (&gPciUartDevicePath0.TerminalType.Guid, TerminalTypeGuid);
278   CopyGuid (&gPciUartDevicePath1.TerminalType.Guid, TerminalTypeGuid);
279 
280   return EFI_SUCCESS;
281 }
282