]> git.proxmox.com Git - mirror_edk2.git/blame - SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
SourceLevelDebugPkg DebugUsb3: Support IOMMU
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugCommunicationLibUsb3 / DebugCommunicationLibUsb3Internal.h
CommitLineData
2cb6eabe
EL
1/** @file\r
2 Debug Port Library implementation based on usb3 debug port.\r
3\r
de8373fa 4 Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r
2cb6eabe
EL
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php.\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef __USB3_DEBUG_PORT_LIB_INTERNAL__\r
16#define __USB3_DEBUG_PORT_LIB_INTERNAL__\r
17\r
18#include <Uefi.h>\r
19#include <Base.h>\r
20#include <IndustryStandard/Usb.h>\r
21#include <Library/IoLib.h>\r
22#include <IndustryStandard/Pci.h>\r
23#include <Library/PcdLib.h>\r
24#include <Library/UefiLib.h>\r
25#include <Library/UefiBootServicesTableLib.h>\r
26#include <Library/MemoryAllocationLib.h>\r
27#include <Library/DebugLib.h>\r
28#include <Library/BaseMemoryLib.h>\r
29#include <Library/BaseLib.h>\r
30#include <Library/TimerLib.h>\r
31#include <Library/DebugCommunicationLib.h>\r
32#include <Library/PciLib.h>\r
2cb6eabe
EL
33\r
34//\r
35// USB Debug GUID value\r
36//\r
37#define USB3_DBG_GUID \\r
38 { \\r
39 0xb2a56f4d, 0x9177, 0x4fc8, { 0xa6, 0x77, 0xdd, 0x96, 0x3e, 0xb4, 0xcb, 0x1b } \\r
40 }\r
41\r
42//\r
43// The state machine of usb debug port\r
44//\r
45#define USB3DBG_NO_DBG_CAB 0 // The XHCI host controller does not support debug capability\r
46#define USB3DBG_DBG_CAB 1 // The XHCI host controller supports debug capability\r
47#define USB3DBG_ENABLED 2 // The XHCI debug device is enabled\r
48#define USB3DBG_NOT_ENABLED 4 // The XHCI debug device is not enabled\r
de8373fa 49#define USB3DBG_UNINITIALIZED 255 // The XHCI debug device is uninitialized\r
2cb6eabe 50\r
5d6507a1
EL
51#define USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE 0x08\r
52\r
53//\r
54// MaxPacketSize for DbC Endpoint Descriptor IN and OUT\r
55//\r
56#define XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE 0x400\r
2cb6eabe
EL
57\r
58#define XHCI_DEBUG_DEVICE_VENDOR_ID 0x0525\r
59#define XHCI_DEBUG_DEVICE_PRODUCT_ID 0x127A\r
60#define XHCI_DEBUG_DEVICE_PROTOCOL 0xFF\r
61#define XHCI_DEBUG_DEVICE_REVISION 0x00\r
62\r
63#define XHCI_BASE_ADDRESS_64_BIT_MASK 0xFFFFFFFFFFFF0000ULL\r
64#define XHCI_BASE_ADDRESS_32_BIT_MASK 0xFFFF0000\r
65\r
66#define PCI_CAPABILITY_ID_DEBUG_PORT 0x0A\r
67#define XHC_HCCPARAMS_OFFSET 0x10\r
68#define XHC_CAPABILITY_ID_MASK 0xFF\r
69#define XHC_NEXT_CAPABILITY_MASK 0xFF00\r
70\r
71#define XHC_HCSPARAMS1_OFFSET 0x4 // Structural Parameters 1\r
72#define XHC_USBCMD_OFFSET 0x0 // USB Command Register Offset\r
73#define XHC_USBSTS_OFFSET 0x4 // USB Status Register Offset\r
74#define XHC_PORTSC_OFFSET 0x400 // Port Status and Control Register Offset\r
75\r
76#define XHC_USBCMD_RUN BIT0 // Run/Stop\r
77#define XHC_USBCMD_RESET BIT1 // Host Controller Reset\r
78\r
79#define XHC_USBSTS_HALT BIT0\r
80\r
2cb6eabe
EL
81//\r
82// Indicate the timeout when data is transferred in microsecond. 0 means infinite timeout.\r
83//\r
84#define DATA_TRANSFER_WRITE_TIMEOUT 0\r
85#define DATA_TRANSFER_READ_TIMEOUT 50000\r
86#define DATA_TRANSFER_POLL_TIMEOUT 1000\r
08021523 87#define XHC_DEBUG_PORT_1_MILLISECOND 1000\r
2cb6eabe
EL
88//\r
89// XHCI port power off/on delay\r
90//\r
91#define XHC_DEBUG_PORT_ON_OFF_DELAY 100000\r
92\r
93//\r
94// USB debug device string descritpor (header size + unicode string length)\r
95//\r
96#define STRING0_DESC_LEN 4\r
97#define MANU_DESC_LEN 12\r
98#define PRODUCT_DESC_LEN 40\r
99#define SERIAL_DESC_LEN 4\r
100\r
101//\r
102// Debug Capability Register Offset\r
103//\r
104#define XHC_DC_DCID 0x0\r
105#define XHC_DC_DCDB 0x4\r
106#define XHC_DC_DCERSTSZ 0x8\r
107#define XHC_DC_DCERSTBA 0x10\r
108#define XHC_DC_DCERDP 0x18\r
109#define XHC_DC_DCCTRL 0x20\r
110#define XHC_DC_DCST 0x24\r
111#define XHC_DC_DCPORTSC 0x28\r
112#define XHC_DC_DCCP 0x30\r
113#define XHC_DC_DCDDI1 0x38\r
114#define XHC_DC_DCDDI2 0x3C\r
115\r
116#define TRB_TYPE_LINK 6\r
117\r
118#define ERST_NUMBER 0x01\r
119#define TR_RING_TRB_NUMBER 0x100\r
120#define EVENT_RING_TRB_NUMBER 0x200\r
121\r
122#define ED_BULK_OUT 2\r
123#define ED_BULK_IN 6\r
124\r
125#define XHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0xFFFFFFFF))\r
126#define XHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINT64)(UINTN)(Addr64), 32) & 0xFFFFFFFF))\r
127#define XHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))\r
128\r
129//\r
130// Endpoint Type (EP Type).\r
131//\r
132#define ED_NOT_VALID 0\r
133#define ED_ISOCH_OUT 1\r
134#define ED_BULK_OUT 2\r
135#define ED_INTERRUPT_OUT 3\r
136#define ED_CONTROL_BIDIR 4\r
137#define ED_ISOCH_IN 5\r
138#define ED_BULK_IN 6\r
139#define ED_INTERRUPT_IN 7\r
140\r
141//\r
142// 6.4.5 TRB Completion Codes\r
143//\r
144#define TRB_COMPLETION_INVALID 0\r
145#define TRB_COMPLETION_SUCCESS 1\r
146#define TRB_COMPLETION_DATA_BUFFER_ERROR 2\r
147#define TRB_COMPLETION_BABBLE_ERROR 3\r
148#define TRB_COMPLETION_USB_TRANSACTION_ERROR 4\r
149#define TRB_COMPLETION_TRB_ERROR 5\r
150#define TRB_COMPLETION_STALL_ERROR 6\r
151#define TRB_COMPLETION_SHORT_PACKET 13\r
152\r
153//\r
154// 6.4.6 TRB Types\r
155//\r
156#define TRB_TYPE_NORMAL 1\r
157#define TRB_TYPE_SETUP_STAGE 2\r
158#define TRB_TYPE_DATA_STAGE 3\r
159#define TRB_TYPE_STATUS_STAGE 4\r
160#define TRB_TYPE_ISOCH 5\r
161#define TRB_TYPE_LINK 6\r
162#define TRB_TYPE_EVENT_DATA 7\r
163#define TRB_TYPE_NO_OP 8\r
164#define TRB_TYPE_EN_SLOT 9\r
165#define TRB_TYPE_DIS_SLOT 10\r
166#define TRB_TYPE_ADDRESS_DEV 11\r
167#define TRB_TYPE_CON_ENDPOINT 12\r
168#define TRB_TYPE_EVALU_CONTXT 13\r
169#define TRB_TYPE_RESET_ENDPOINT 14\r
170#define TRB_TYPE_STOP_ENDPOINT 15\r
171#define TRB_TYPE_SET_TR_DEQUE 16\r
172#define TRB_TYPE_RESET_DEV 17\r
173#define TRB_TYPE_GET_PORT_BANW 21\r
174#define TRB_TYPE_FORCE_HEADER 22\r
175#define TRB_TYPE_NO_OP_COMMAND 23\r
176#define TRB_TYPE_TRANS_EVENT 32\r
177#define TRB_TYPE_COMMAND_COMPLT_EVENT 33\r
178#define TRB_TYPE_PORT_STATUS_CHANGE_EVENT 34\r
179#define TRB_TYPE_HOST_CONTROLLER_EVENT 37\r
180#define TRB_TYPE_DEVICE_NOTIFI_EVENT 38\r
181#define TRB_TYPE_MFINDEX_WRAP_EVENT 39\r
182\r
183//\r
184// Convert millisecond to microsecond.\r
185//\r
186#define XHC_1_MILLISECOND (1000)\r
187#define XHC_POLL_DELAY (1000)\r
188#define XHC_GENERIC_TIMEOUT (10 * 1000)\r
189\r
190#define EFI_USB_SPEED_FULL 0x0000 ///< 12 Mb/s, USB 1.1 OHCI and UHCI HC.\r
191#define EFI_USB_SPEED_LOW 0x0001 ///< 1 Mb/s, USB 1.1 OHCI and UHCI HC.\r
192#define EFI_USB_SPEED_HIGH 0x0002 ///< 480 Mb/s, USB 2.0 EHCI HC.\r
193#define EFI_USB_SPEED_SUPER 0x0003 ///< 4.8 Gb/s, USB 3.0 XHCI HC.\r
194\r
195//\r
196// Transfer types, used in URB to identify the transfer type\r
197//\r
198#define XHC_CTRL_TRANSFER 0x01\r
199#define XHC_BULK_TRANSFER 0x02\r
200#define XHC_INT_TRANSFER_SYNC 0x04\r
201#define XHC_INT_TRANSFER_ASYNC 0x08\r
202#define XHC_INT_ONLY_TRANSFER_ASYNC 0x10\r
203\r
204//\r
205// USB Transfer Results\r
206//\r
207#define EFI_USB_NOERROR 0x00\r
208#define EFI_USB_ERR_NOTEXECUTE 0x01\r
209#define EFI_USB_ERR_STALL 0x02\r
210#define EFI_USB_ERR_BUFFER 0x04\r
211#define EFI_USB_ERR_BABBLE 0x08\r
212#define EFI_USB_ERR_NAK 0x10\r
213#define EFI_USB_ERR_CRC 0x20\r
214#define EFI_USB_ERR_TIMEOUT 0x40\r
215#define EFI_USB_ERR_BITSTUFF 0x80\r
216#define EFI_USB_ERR_SYSTEM 0x100\r
217\r
218#pragma pack(1)\r
219\r
220//\r
221// 7.6.9 OUT/IN EP Context: 64 bytes\r
222// 7.6.9.2 When used by the DbC it is always a 64 byte data structure\r
223//\r
224typedef struct _ENDPOINT_CONTEXT_64 {\r
225 UINT32 EPState:3;\r
226 UINT32 RsvdZ1:5;\r
227 UINT32 Mult:2; // set to 0\r
228 UINT32 MaxPStreams:5; // set to 0\r
229 UINT32 LSA:1; // set to 0\r
230 UINT32 Interval:8; // set to 0\r
231 UINT32 RsvdZ2:8;\r
232\r
233 UINT32 RsvdZ3:1;\r
234 UINT32 CErr:2;\r
235 UINT32 EPType:3;\r
236 UINT32 RsvdZ4:1;\r
237 UINT32 HID:1; // set to 0\r
238 UINT32 MaxBurstSize:8;\r
239 UINT32 MaxPacketSize:16;\r
240\r
241 UINT32 PtrLo;\r
242\r
243 UINT32 PtrHi;\r
244\r
245 UINT32 AverageTRBLength:16;\r
246 UINT32 MaxESITPayload:16; // set to 0\r
247\r
248 UINT32 RsvdZ5; // Reserved\r
249 UINT32 RsvdZ6;\r
250 UINT32 RsvdZ7;\r
251 \r
252 UINT32 RsvdZ8;\r
253 UINT32 RsvdZ9;\r
254 UINT32 RsvdZ10;\r
255 UINT32 RsvdZ11;\r
256 \r
257 UINT32 RsvdZ12;\r
258 UINT32 RsvdZ13;\r
259 UINT32 RsvdZ14;\r
260 UINT32 RsvdZ15;\r
261} ENDPOINT_CONTEXT_64;\r
262\r
263//\r
264// 6.4.1.1 Normal TRB: 16 bytes\r
265// A Normal TRB is used in several ways; exclusively on Bulk and Interrupt Transfer Rings for normal and\r
266// Scatter/Gather operations, to define additional data buffers for Scatter/Gather operations on Isoch Transfer\r
267// Rings, and to define the Data stage information for Control Transfer Rings.\r
268//\r
269typedef struct _TRANSFER_TRB_NORMAL {\r
270 UINT32 TRBPtrLo;\r
271\r
272 UINT32 TRBPtrHi;\r
273\r
274 UINT32 Length:17;\r
275 UINT32 TDSize:5;\r
276 UINT32 IntTarget:10;\r
277\r
278 UINT32 CycleBit:1;\r
279 UINT32 ENT:1;\r
280 UINT32 ISP:1;\r
281 UINT32 NS:1;\r
282 UINT32 CH:1;\r
283 UINT32 IOC:1;\r
284 UINT32 IDT:1;\r
285 UINT32 RsvdZ1:2;\r
286 UINT32 BEI:1;\r
287 UINT32 Type:6;\r
288 UINT32 RsvdZ2:16;\r
289} TRANSFER_TRB_NORMAL;\r
290\r
291//\r
292// 6.4.2.1 Transfer Event TRB: 16 bytes\r
293// A Transfer Event provides the completion status associated with a Transfer TRB. Refer to section 4.11.3.1\r
294// for more information on the use and operation of Transfer Events.\r
295//\r
296typedef struct _EVT_TRB_TRANSFER {\r
297 UINT32 TRBPtrLo;\r
298\r
299 UINT32 TRBPtrHi;\r
300\r
301 UINT32 Length:24;\r
302 UINT32 Completecode:8;\r
303\r
304 UINT32 CycleBit:1;\r
305 UINT32 RsvdZ1:1;\r
306 UINT32 ED:1;\r
307 UINT32 RsvdZ2:7;\r
308 UINT32 Type:6;\r
309 UINT32 EndpointId:5;\r
310 UINT32 RsvdZ3:3;\r
311 UINT32 SlotId:8;\r
312} EVT_TRB_TRANSFER;\r
313\r
314//\r
315// 6.4.4.1 Link TRB: 16 bytes\r
316// A Link TRB provides support for non-contiguous TRB Rings.\r
317//\r
318typedef struct _LINK_TRB {\r
319 UINT32 PtrLo;\r
320\r
321 UINT32 PtrHi;\r
322\r
323 UINT32 RsvdZ1:22;\r
324 UINT32 InterTarget:10;\r
325\r
326 UINT32 CycleBit:1;\r
327 UINT32 TC:1;\r
328 UINT32 RsvdZ2:2;\r
329 UINT32 CH:1;\r
330 UINT32 IOC:1;\r
331 UINT32 RsvdZ3:4;\r
332 UINT32 Type:6;\r
333 UINT32 RsvdZ4:16;\r
334} LINK_TRB;\r
335\r
336//\r
337// TRB Template: 16 bytes\r
338//\r
339typedef struct _TRB_TEMPLATE {\r
340 UINT32 Parameter1;\r
341\r
342 UINT32 Parameter2;\r
343\r
344 UINT32 Status;\r
345\r
346 UINT32 CycleBit:1;\r
347 UINT32 RsvdZ1:9;\r
348 UINT32 Type:6;\r
349 UINT32 Control:16;\r
350} TRB_TEMPLATE;\r
351\r
352//\r
353// Refer to XHCI 6.5 Event Ring Segment Table: 16 bytes\r
354//\r
355typedef struct _EVENT_RING_SEG_TABLE_ENTRY {\r
356 UINT32 PtrLo;\r
357 UINT32 PtrHi;\r
358 UINT32 RingTrbSize:16;\r
359 UINT32 RsvdZ1:16;\r
360 UINT32 RsvdZ2;\r
361} EVENT_RING_SEG_TABLE_ENTRY;\r
362\r
363//\r
364// Size: 40 bytes\r
365//\r
366typedef struct _EVENT_RING {\r
367 EFI_PHYSICAL_ADDRESS ERSTBase;\r
368 EFI_PHYSICAL_ADDRESS EventRingSeg0;\r
369 UINT32 TrbNumber;\r
370 EFI_PHYSICAL_ADDRESS EventRingEnqueue;\r
371 EFI_PHYSICAL_ADDRESS EventRingDequeue;\r
372 UINT32 EventRingCCS;\r
373} EVENT_RING;\r
374\r
375// Size: 32 bytes\r
376typedef struct _TRANSFER_RING {\r
377 EFI_PHYSICAL_ADDRESS RingSeg0;\r
378 UINT32 TrbNumber;\r
379 EFI_PHYSICAL_ADDRESS RingEnqueue;\r
380 EFI_PHYSICAL_ADDRESS RingDequeue;\r
381 UINT32 RingPCS;\r
382} TRANSFER_RING;\r
383\r
384//\r
385// Size: 64 bytes\r
386//\r
387typedef struct _DBC_INFO_CONTEXT {\r
388 UINT64 String0DescAddress;\r
389 UINT64 ManufacturerStrDescAddress;\r
390 UINT64 ProductStrDescAddress;\r
391 UINT64 SerialNumberStrDescAddress;\r
392 UINT64 String0Length:8;\r
393 UINT64 ManufacturerStrLength:8;\r
394 UINT64 ProductStrLength:8;\r
395 UINT64 SerialNumberStrLength:8;\r
396 UINT64 RsvdZ1:32;\r
397 UINT64 RsvdZ2;\r
398 UINT64 RsvdZ3;\r
399 UINT64 RsvdZ4; \r
400} DBC_INFO_CONTEXT;\r
401\r
402//\r
403// Debug Capability Context Data Structure: 192 bytes\r
404//\r
405typedef struct _XHC_DC_CONTEXT {\r
406 DBC_INFO_CONTEXT DbcInfoContext;\r
407 ENDPOINT_CONTEXT_64 EpOutContext;\r
408 ENDPOINT_CONTEXT_64 EpInContext;\r
409} XHC_DC_CONTEXT;\r
410\r
411//\r
412// Size: 16 bytes\r
413//\r
414typedef union _TRB {\r
415 TRB_TEMPLATE TrbTemplate;\r
416 TRANSFER_TRB_NORMAL TrbNormal;\r
417} TRB;\r
418\r
419///\r
420/// USB data transfer direction\r
421///\r
422typedef enum {\r
423 EfiUsbDataIn,\r
424 EfiUsbDataOut,\r
425 EfiUsbNoData\r
426} EFI_USB_DATA_DIRECTION;\r
427\r
428//\r
429// URB (Usb Request Block) contains information for all kinds of\r
430// usb requests.\r
431//\r
432typedef struct _URB {\r
433 //\r
434 // Transfer data buffer\r
435 //\r
436 EFI_PHYSICAL_ADDRESS Data;\r
437 UINT32 DataLen;\r
438\r
439 //\r
440 // Execute result\r
441 //\r
442 UINT32 Result;\r
443 //\r
444 // Completed data length\r
445 //\r
446 UINT32 Completed;\r
447 //\r
448 // Tranfer Ring info\r
449 //\r
450 EFI_PHYSICAL_ADDRESS Ring;\r
451 EFI_PHYSICAL_ADDRESS Trb;\r
452 BOOLEAN Finished;\r
453 EFI_USB_DATA_DIRECTION Direction;\r
454} URB;\r
455\r
456typedef struct _USB3_DEBUG_PORT_INSTANCE {\r
457 UINT8 Initialized;\r
458\r
459 //\r
de8373fa 460 // The flag indicates debug capability is supported\r
2cb6eabe
EL
461 //\r
462 BOOLEAN DebugSupport;\r
463 \r
464 //\r
465 // The flag indicates debug device is ready\r
466 //\r
467 BOOLEAN Ready;\r
468\r
de8373fa
SZ
469 //\r
470 // The flag indicates the instance is from HOB\r
471 //\r
472 BOOLEAN FromHob;\r
473\r
474 //\r
475 // IOMMU PPI Notify registered\r
476 //\r
477 BOOLEAN PpiNotifyRegistered;\r
478\r
479 //\r
480 // Prevent notification being interrupted by debug timer\r
481 //\r
482 BOOLEAN InNotify;\r
483\r
484 //\r
485 // PciIo protocol event\r
486 //\r
487 EFI_PHYSICAL_ADDRESS PciIoEvent;\r
488\r
2cb6eabe
EL
489 //\r
490 // The flag indicates if USB 3.0 ports has been turn off/on power\r
491 // \r
492 BOOLEAN ChangePortPower;\r
493\r
494 //\r
495 // XHCI MMIO Base address\r
496 //\r
497 EFI_PHYSICAL_ADDRESS XhciMmioBase;\r
498\r
499 //\r
500 // XHCI OP RegisterBase address\r
501 // \r
502 EFI_PHYSICAL_ADDRESS XhciOpRegister;\r
503 \r
504 //\r
505 // XHCI Debug Register Base Address\r
506 //\r
507 EFI_PHYSICAL_ADDRESS DebugCapabilityBase;\r
508 \r
509 //\r
510 // XHCI Debug Capability offset\r
511 //\r
512 UINT64 DebugCapabilityOffset; \r
513 \r
514 //\r
515 // XHCI Debug Context Address\r
516 //\r
517 EFI_PHYSICAL_ADDRESS DebugCapabilityContext;\r
518 \r
519 //\r
520 // Transfer Ring\r
521 //\r
522 TRANSFER_RING TransferRingOut;\r
523 TRANSFER_RING TransferRingIn;\r
524\r
525 //\r
526 // EventRing\r
527 //\r
528 EVENT_RING EventRing;\r
529 \r
530 //\r
531 // URB - Read\r
532 //\r
533 URB UrbOut;\r
534\r
535 //\r
536 // URB - Write\r
537 //\r
538 URB UrbIn;\r
539\r
540 //\r
541 // The available data length in the following data buffer.\r
542 //\r
543 UINT8 DataCount;\r
544 //\r
5d6507a1 545 // The data buffer address for data read and poll.\r
2cb6eabe 546 //\r
5d6507a1 547 EFI_PHYSICAL_ADDRESS Data;\r
2cb6eabe
EL
548} USB3_DEBUG_PORT_HANDLE;\r
549\r
550#pragma pack()\r
551\r
552/**\r
553 Read XHCI debug register.\r
554\r
555 @param Handle Debug port handle.\r
556 @param Offset The offset of the debug register.\r
557\r
558 @return The register content read\r
559\r
560**/\r
561UINT32\r
562XhcReadDebugReg (\r
563 IN USB3_DEBUG_PORT_HANDLE *Handle,\r
564 IN UINT32 Offset\r
565 );\r
566\r
567/**\r
568 Set one bit of the debug register while keeping other bits.\r
569\r
570 @param Handle Debug port handle.\r
571 @param Offset The offset of the debug register.\r
572 @param Bit The bit mask of the register to set.\r
573\r
574**/\r
575VOID\r
576XhcSetDebugRegBit (\r
577 IN USB3_DEBUG_PORT_HANDLE *Handle,\r
578 IN UINT32 Offset,\r
579 IN UINT32 Bit\r
580 );\r
581 \r
582/**\r
583 Write the data to the debug register.\r
584\r
585 @param Handle Debug port handle.\r
586 @param Offset The offset of the debug register.\r
587 @param Data The data to write.\r
588\r
589**/ \r
590VOID\r
591XhcWriteDebugReg (\r
592 IN USB3_DEBUG_PORT_HANDLE *Handle,\r
593 IN UINT32 Offset,\r
594 IN UINT32 Data\r
595 );\r
596\r
597/**\r
598 Discover the USB3 debug device.\r
599 \r
600 @param Handle Debug port handle.\r
601 \r
602 @retval RETURN_SUCCESS The serial device was initialized.\r
603 @retval RETURN_DEVICE_ERROR The serial device could not be initialized.\r
604\r
605**/\r
606RETURN_STATUS\r
607DiscoverUsb3DebugPort(\r
608 USB3_DEBUG_PORT_HANDLE *Handle\r
609 );\r
610 \r
611/**\r
612 Initialize the Serial Device hardware.\r
613 \r
614 @param Handle Debug port handle.\r
615\r
616 @retval RETURN_SUCCESS The serial device was initialized successfully.\r
617 @retval !RETURN_SUCCESS Error.\r
618\r
619**/\r
620RETURN_STATUS\r
621InitializeUsb3DebugPort (\r
622 USB3_DEBUG_PORT_HANDLE *Handle\r
623 );\r
624\r
625/**\r
626 Return XHCI MMIO base address.\r
627\r
628**/\r
629EFI_PHYSICAL_ADDRESS\r
630GetXhciBaseAddress (\r
631 VOID\r
632 );\r
633\r
634/**\r
635 Verifies if the bit positions specified by a mask are set in a register.\r
636\r
637 @param[in, out] Register UNITN register\r
638 @param[in] BitMask 32-bit mask\r
639\r
640 @return BOOLEAN - TRUE if all bits specified by the mask are enabled.\r
641 - FALSE even if one of the bits specified by the mask \r
642 is not enabled.\r
643**/\r
644BOOLEAN\r
645XhcIsBitSet(\r
646 UINTN Register, \r
647 UINT32 BitMask\r
648 );\r
649\r
650/**\r
651 Sets bits as per the enabled bit positions in the mask.\r
652\r
653 @param[in, out] Register UINTN register\r
654 @param[in] BitMask 32-bit mask\r
655**/\r
656VOID\r
657XhcSetR32Bit(\r
658 UINTN Register, \r
659 UINT32 BitMask\r
660 );\r
661\r
662/**\r
663 Clears bits as per the enabled bit positions in the mask.\r
664\r
665 @param[in, out] Register UINTN register\r
666 @param[in] BitMask 32-bit mask\r
667**/\r
668VOID\r
669XhcClearR32Bit(\r
670 IN OUT UINTN Register, \r
671 IN UINT32 BitMask\r
672 );\r
673\r
674/**\r
675 Initialize USB3 debug port.\r
676 \r
677 This method invokes various internal functions to facilitate\r
678 detection and initialization of USB3 debug port.\r
679\r
680 @retval RETURN_SUCCESS The serial device was initialized.\r
681**/\r
682RETURN_STATUS\r
683EFIAPI\r
684USB3Initialize (\r
685 VOID\r
686 );\r
687\r
688/**\r
689 Return command register value in XHCI controller.\r
690\r
691**/\r
692UINT16\r
693GetXhciPciCommand (\r
694 VOID\r
695 );\r
696\r
697/**\r
698 Allocate aligned memory for XHC's usage.\r
699\r
700 @param BufferSize The size, in bytes, of the Buffer.\r
701 \r
702 @return A pointer to the allocated buffer or NULL if allocation fails.\r
703\r
704**/\r
705VOID*\r
706AllocateAlignBuffer (\r
707 IN UINTN BufferSize\r
708 );\r
709\r
710/**\r
711 The real function to initialize USB3 debug port.\r
712 \r
713 This method invokes various internal functions to facilitate\r
714 detection and initialization of USB3 debug port.\r
715\r
716 @retval RETURN_SUCCESS The serial device was initialized.\r
717**/\r
718RETURN_STATUS\r
719EFIAPI\r
720USB3InitializeReal (\r
721 VOID\r
722 );\r
723\r
724/**\r
725 Submits bulk transfer to a bulk endpoint of a USB device.\r
726\r
727 @param Handle The instance of debug device.\r
728 @param Direction The direction of data transfer.\r
729 @param Data Array of pointers to the buffers of data to transmit\r
730 from or receive into.\r
731 @param DataLength The lenght of the data buffer.\r
732 @param Timeout Indicates the maximum time, in millisecond, which\r
733 the transfer is allowed to complete.\r
734\r
735 @retval EFI_SUCCESS The transfer was completed successfully.\r
736 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resource.\r
737 @retval EFI_INVALID_PARAMETER Some parameters are invalid.\r
738 @retval EFI_TIMEOUT The transfer failed due to timeout.\r
739 @retval EFI_DEVICE_ERROR The transfer failed due to host controller error.\r
740\r
741**/\r
742EFI_STATUS\r
743EFIAPI\r
744XhcDataTransfer (\r
745 IN USB3_DEBUG_PORT_HANDLE *Handle,\r
746 IN EFI_USB_DATA_DIRECTION Direction,\r
747 IN OUT VOID *Data,\r
748 IN OUT UINTN *DataLength,\r
749 IN UINTN Timeout\r
750 );\r
751\r
de8373fa
SZ
752/**\r
753 Initialize usb debug port hardware.\r
754\r
755 @param Handle Debug port handle.\r
756\r
757 @retval TRUE The usb debug port hardware configuration is changed.\r
758 @retval FALSE The usb debug port hardware configuration is not changed.\r
759\r
760**/\r
761RETURN_STATUS\r
762EFIAPI\r
763InitializeUsbDebugHardware (\r
764 IN USB3_DEBUG_PORT_HANDLE *Handle\r
765 );\r
766\r
767/**\r
768 Discover and initialize usb debug port.\r
769\r
770 @param Handle Debug port handle.\r
771\r
772**/\r
773VOID\r
774DiscoverInitializeUsbDebugPort (\r
775 IN USB3_DEBUG_PORT_HANDLE *Handle\r
776 );\r
777\r
778/**\r
779 Return USB3 debug instance address.\r
780\r
781**/ \r
782USB3_DEBUG_PORT_HANDLE *\r
783GetUsb3DebugPortInstance (\r
784 VOID\r
785 );\r
786\r
2cb6eabe 787#endif //__SERIAL_PORT_LIB_USB__\r