summaryrefslogtreecommitdiff
path: root/Core/EM/UsbRecovery/PeiUsbLib.c
blob: 2348910f66417c40ce1dfd8583f535c972de508a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2007, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**         5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************
//**********************************************************************
//
// $Header: /Alaska/SOURCE/Modules/USBRecovery/PeiUsbLib.c 10    11/24/12 5:43a Ryanchou $
//
// $Revision: 10 $
//
// $Date: 11/24/12 5:43a $
//
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/USBRecovery/PeiUsbLib.c $
// 
// 10    11/24/12 5:43a Ryanchou
// [TAG]  		EIP103990
// [Category]  	Improvement
// [Description]  	Synchronized with USB PEI module 4.6.3_USB_08.10.24.
// [Files]  		EhciPei.c, EhciPei.h, OhciPei.c, OhciPei.h, UhcPeim.c,
// BotPeim.c, BotPeim.h, PeiAtapi.c, UsbBotPeim.c, UsbBotPeim.h,
// HubPeim.c, UsbPeim.c, XhciPei.c, XhciPei.h, HubPeim.h, PeiUsbLib.c,
// PeiUsbLib.h, UsbPeim.h
// 
// 9     4/12/11 12:00a Rameshr
// [TAG]- EIP 57444
// [Category]-IMPROVEMENT
// [Description]- PI1.1 Support.
// [Files]- OhciPeiboard.c,Xhcipei.c, Peiusblib.c
// 
// 8     10/11/10 4:51p Olegi
// XHCI support added.
// 
// 7     4/06/10 3:37p Fasihm
// EIP#31987 - Added the generic USBRecovery Fix in the module.
// 
// 6     3/17/09 5:10p Olegi
// Added IsPortHighSpeedDeviceAttached function.
// 
// 5     7/18/08 5:03p Michaela
// 1  File-level debugging is now available
// 2  AMI_USB_DEBUG_INTERFACE.WaitConsoleKey() now returns
//    the keypress so that conditional debugging can
//    be dynamic (alphanumeric keys only)
// 3  Added more function headers.
// 4  Removed code that will never be used (I.e., Bala?).
// 5  Moved typedef, contants and extern declarations
//    into header files.
// 6  Now all controller blocks are enabled for SB700
//    (EHCI controllers route to companion controller
//    by default)
// 7  Removed unused constants and typedefs n OhciPei.h
//    (also reorganized the file to make it more 
//    readable.)
// 8  Renamed many functions/variables according to
//    coding standard.
// 9  Removed code initializing data structures for
//    periodic lists, as this is not needed.
// 10 Removed the CONTROLLER_TYPE SDL token to
//    allow UHCI and OHCI controllers to supported
//    simultaneously. (modified MAKE files 
//    accordingly)
// 
// 4     7/10/08 6:33p Michaela
// Updated to support OHCI controllers
//
// 3     4/16/07 1:02p Sivagarn
// - Updated as per coding standard review
// - In previous check-in, TIANO.H file is removed and AMIMAPPING.H file
// is included
//
// 2     3/28/07 3:07a Meenakshim
// Removed dependency on core source files..Added amimapping file.
//
// 1     9/22/06 4:07p Sivagarn
// - Initial Check-in
// - Included Recovery code in Source
// - Included appropriate headers for flies and functions
// - Updated copyright messages
//
//*****************************************************************************

//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:        PeiUsbLib.C
//
// Description: 
//      This file belongs to "Framework" and included here for
//      compatibility purposes. This file is modified by AMI to include
//      copyright message, appropriate header and integration code.
//      This file contains generic routines needed for USB recover
//      PEIM
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>

/*++
   This file contains 'Framework Code' and is licensed as such
   under the terms of your license agreement with Intel or your
   vendor.  This file may not be modified, except as allowed by
   additional terms of your license agreement.
   --*/

/*++

   Copyright (c)  1999 - 2002 Intel Corporation. All rights reserved
   This software and associated documentation (if any) is furnished
   under a license and may only be used or copied in accordance
   with the terms of the license. Except as permitted by such
   license, no part of this software or documentation may be
   reproduced, stored in a retrieval system, or transmitted in any
   form or by any means without the express written consent of
   Intel Corporation.


   Module Name:

    PeiUsbLib.c

   Abstract:

   Common Libarary  for PEI USB

   Revision History

   --*/

#include "Efi.h"
#include "Pei.h"
#include "usb.h"
#include "UsbPeim.h"
#include "PeiUsbLib.h"


//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   ZeroMem
//
// Description: This library function initializes provided buffer with Zero
//
// Input:       *Buffer     Pointer to the buffer whose content to be inited
//              Size        Number of bytes to be filled in
//
// Output:      Returns None
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>

VOID ZeroMem (
    OUT VOID    *Buffer,
    IN  UINTN   Size )
{
    UINT8 *Ptr;

    Ptr = Buffer;
    while (Size--) {
        *(Ptr++) = 0;
    }
}


//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   PeiCopyMem
//
// Description: 
//      This library function copies bytes specified by Length from the memory
//      location specified by Source to the memory location specified by 
//      Destination.
//
// Input:
//      OUT VOID *Destination
//                  --  Target memory location of copy
//      IN  VOID *Source
//                  --  Source memory location
//      IN  UINTN Length
//                  --  Number of bytes to copy
//
// Output:     
//      VOID (No Return Value)
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>

VOID PeiCopyMem (
    OUT VOID *Destination,
    IN VOID  *Source,
    IN UINTN Length )
{
    CHAR8 *Destination8;
    CHAR8 *Source8;

    Destination8 = Destination;
    Source8 = Source;
    while (Length--) {
        *(Destination8++) = *(Source8++);
    }
}


//<AMI_PHDR_START>
//---------------------------------------------------------------------------
//
// Procedure:   PeiUsbGetDescriptor
//
// Description:  
//      This function uses a device's PEI_USB_IO_PPI interface to execute a 
//      control transfer on the default control pipe to obtain a device 
//      descriptor.
//
// Input: 
//      IN EFI_PEI_SERVICES **PeiServices
//                  --  PEI Sevices table pointer
//      IN PEI_USB_IO_PPI *UsbIoPpi
//                  --  PEI_USB_IO_PPI interface pointer for the device
//                      that is being accessed
//      IN UINT16 Value
//                  --  The upper byte of Value specifies the type of 
//                      descriptor and the lower byte of Value specifies
//                      the index (for configuration and string descriptors)
//      IN UINT16 Index
//                  --  Specifies the Language ID for string descriptors
//                      or zero for all other descriptors
//      IN UINT16 DescriptorLength
//                  --  Specifies the length of the descriptor to be
//                      retrieved
//      IN VOID *Descriptor
//                  --  Allocated buffer in which the descriptor will be 
//                      returned
//
// Output:  
//      EFI_STATUS (Return Value)
//                  = EFI_SUCCESS on successful completion
//                      or valid EFI error code
//
// Notes:
//      The lower byte of Value is typically zero and the upper byte of 
//      Value specifies the type of descriptor:
//
//                  READ_BITS(Value,15,8)   Descriptor
//                  -------------------------------------------------
//                          1               DEVICE
//                          2               CONFIGURATION
//                          3               STRING
//                          4               INTERFACE
//                          5               ENDPOINT
//                          6               DEVICE_QUALIFIER
//                          7               OTHER_SPEED_CONFIGURATION
//                          8               INTERFACE_POWER
//
//      For additional reference, read the USB Device Framework chapter in 
//      the USB Specification (Revision 2.0)
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS PeiUsbGetDescriptor (
    IN EFI_PEI_SERVICES **PeiServices,
    IN PEI_USB_IO_PPI   *UsbIoPpi,
    IN UINT16           Value,
    IN UINT16           Index,
    IN UINT16           DescriptorLength,
    IN VOID             *Descriptor )
{
    EFI_USB_DEVICE_REQUEST DevReq;
    UINT32 Timeout;

    if (UsbIoPpi == NULL) {
        return EFI_INVALID_PARAMETER;
    }

    DevReq.RequestType = USB_DEV_GET_DESCRIPTOR_REQ_TYPE;
    DevReq.Request = USB_DEV_GET_DESCRIPTOR;
    DevReq.Value = Value;
    DevReq.Index = Index;
    DevReq.Length = DescriptorLength;

    Timeout = 3000;

    return UsbIoPpi->UsbControlTransfer(
        PeiServices,
        UsbIoPpi,
        &DevReq,
		EfiUsbDataIn,
        Timeout,
        Descriptor,
        DescriptorLength
    );

}


//<AMI_PHDR_START>
//---------------------------------------------------------------------------
//
// Procedure:   PeiUsbSetDeviceAddress
//
// Description: 
//      This function uses a device's PEI_USB_IO_PPI interface to execute a 
//      control transfer on the default control pipe to set the device's 
//      address on the USB bus for all future accesses.
//
// Input:
//      IN EFI_PEI_SERVICES **PeiServices
//                  --  PEI Sevices table pointer
//      IN PEI_USB_IO_PPI *UsbIoPpi
//                  --  PEI_USB_IO_PPI interface pointer for the device
//                      that is being accessed
//      IN UINT16 AddressValue
//                  --  The device address to be set
//
// Output: 
//      EFI_STATUS (Return Value)
//                  = EFI_SUCCESS on successful completion
//                      or valid EFI error code
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS PeiUsbSetDeviceAddress (
    IN EFI_PEI_SERVICES **PeiServices,
    IN PEI_USB_IO_PPI   *UsbIoPpi,
    IN UINT16           AddressValue )
{
    EFI_USB_DEVICE_REQUEST DevReq;
    UINT32 Timeout;

    if (UsbIoPpi == NULL) {
        return EFI_INVALID_PARAMETER;
    }

    DevReq.RequestType = USB_DEV_SET_ADDRESS_REQ_TYPE;
    DevReq.Request = USB_DEV_SET_ADDRESS;
    DevReq.Value = AddressValue;
    DevReq.Index = 0;
    DevReq.Length = 0;

    Timeout = 3000;

    return UsbIoPpi->UsbControlTransfer(
        PeiServices,
        UsbIoPpi,
        &DevReq,
        EfiUsbNoData,
        Timeout,
        NULL,
        0
    );

}


//<AMI_PHDR_START>
//---------------------------------------------------------------------------
//
// Procedure:   PeiUsbClearDeviceFeature
//
// Description:  
//      This function uses a device's PEI_USB_IO_PPI interface to execute a 
//      control transfer on the default control pipe to clear or disable a
//      specific feature.
//
// Input: 
//      IN EFI_PEI_SERVICES **PeiServices
//                  --  PEI Sevices table pointer
//      IN PEI_USB_IO_PPI *UsbIoPpi
//                  --  PEI_USB_IO_PPI interface pointer for the device
//                      that is being accessed
//      IN EFI_USB_RECIPIENT Recipient
//                  --  The recipient of the request can be a device,
//                      an interface or an endpoint respectively specified 
//                      by EfiUsbDevice, EfiUsbInterface or EfiUsbEndpoint.
//      IN UINT16 Value
//                  --  The feature selector to be cleared or disabled
//      IN UINT16 Target
//                  --  This value specifies an index for a specific 
//                      interface/endpoint or zero for device recipients.
//
// Output:  
//      EFI_STATUS (Return Value)
//                  = EFI_SUCCESS on successful completion
//                      or valid EFI error code
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS PeiUsbClearDeviceFeature (
    IN EFI_PEI_SERVICES  **PeiServices,
    IN PEI_USB_IO_PPI    *UsbIoPpi,
    IN EFI_USB_RECIPIENT Recipient,
    IN UINT16            Value,
    IN UINT16            Target )
{
    EFI_USB_DEVICE_REQUEST DevReq;
    UINT32 Timeout;

    if (UsbIoPpi == NULL) {
        return EFI_INVALID_PARAMETER;
    }

    switch (Recipient)
    {
    case EfiUsbDevice:
        DevReq.RequestType = 0x00;
        break;

    case EfiUsbInterface:
        DevReq.RequestType = 0x01;
        break;

    case EfiUsbEndpoint:
        DevReq.RequestType = 0x02;
        break;
    }

    DevReq.Request = USB_DEV_CLEAR_FEATURE;
    DevReq.Value = Value;
    DevReq.Index = Target;
    DevReq.Length = 0;

    Timeout = 3000;

    return UsbIoPpi->UsbControlTransfer(
        PeiServices,
        UsbIoPpi,
        &DevReq,
        EfiUsbNoData,
        Timeout,
        NULL,
        0
    );

}


//<AMI_PHDR_START>
//---------------------------------------------------------------------------
//
// Procedure:   PeiUsbSetConfiguration
//
// Description: 
//      This function uses a device's PEI_USB_IO_PPI interface to execute a 
//      control transfer on the default control pipe to set the device's 
//      default configuration index of 1.
//
// Input:
//      IN EFI_PEI_SERVICES **PeiServices
//                  --  PEI Sevices table pointer
//      IN PEI_USB_IO_PPI *UsbIoPpi
//                  --  PEI_USB_IO_PPI interface pointer for the device
//                      that is being accessed
//
// Output: 
//      EFI_STATUS (Return Value)
//                  = EFI_SUCCESS on successful completion
//                      or valid EFI error code
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS PeiUsbSetConfiguration (
    IN EFI_PEI_SERVICES **PeiServices,
    IN PEI_USB_IO_PPI   *UsbIoPpi )
{
    EFI_USB_DEVICE_REQUEST DevReq;
    UINT32 Timeout;

    ZeroMem( &DevReq, sizeof(EFI_USB_DEVICE_REQUEST) );

    DevReq.RequestType = USB_DEV_SET_CONFIGURATION_REQ_TYPE;
    DevReq.Request = USB_DEV_SET_CONFIGURATION;
    DevReq.Value = 1;  // default
    DevReq.Index = 0;
    DevReq.Length = 0;

    Timeout = 3000;

    return UsbIoPpi->UsbControlTransfer(
        PeiServices,
        UsbIoPpi,
        &DevReq,
        EfiUsbNoData,
        Timeout,
        NULL,
        0
    );
}


//<AMI_PHDR_START>
//---------------------------------------------------------------------------
//
// Procedure:   PeiUsbClearEndpointHalt
//
// Description: 
//      This function uses a device's PEI_USB_IO_PPI interface to execute a 
//      control transfer on the default control pipe to clear a bulk Endpoint
//      halt condition (and resetting the Halt status bit) for a specified 
//      Endpoint.
//
// Input:
//      IN EFI_PEI_SERVICES **PeiServices
//                  --  PEI Sevices table pointer
//      IN PEI_USB_IO_PPI *UsbIoPpi
//                  --  PEI_USB_IO_PPI interface pointer for the device
//                      that is being accessed
//      IN UINT8 EndpointAddress
//                  --  The endpoint for which the Halt condition is to be 
//                      cleared
//
// Output: 
//      EFI_STATUS (Return Value)
//                  = EFI_SUCCESS on successful completion
//                      or valid EFI error code
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS PeiUsbClearEndpointHalt (
    IN EFI_PEI_SERVICES **PeiServices,
    IN PEI_USB_IO_PPI   *UsbIoPpi,
    IN UINT8            EndpointAddress )
{
    EFI_STATUS     Status;
    PEI_USB_DEVICE *PeiUsbDev;
    EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDescriptor;
    UINT8 EndpointIndex = 0;

    PeiUsbDev = PEI_USB_DEVICE_FROM_THIS( UsbIoPpi );

    while (EndpointIndex < MAX_ENDPOINT) {
        Status = UsbIoPpi->UsbGetEndpointDescriptor( PeiServices, UsbIoPpi,
            EndpointIndex, &EndpointDescriptor );
        if ( EFI_ERROR( Status ) ) {
            return EFI_INVALID_PARAMETER;
        }

        if (EndpointDescriptor->EndpointAddress == EndpointAddress) {
            break;
        }

        EndpointIndex++;
    }

    if (EndpointIndex == MAX_ENDPOINT) {
        return EFI_INVALID_PARAMETER;
    }

    Status = PeiUsbClearDeviceFeature(
        PeiServices,
        UsbIoPpi,
        EfiUsbEndpoint,
        EfiUsbEndpointHalt,
        EndpointAddress
             );

    //
    // set data toggle to zero.
    //
    if ( ( PeiUsbDev->DataToggle & (1 << EndpointIndex) ) != 0 ) {
        PeiUsbDev->DataToggle =
            (UINT8) ( PeiUsbDev->DataToggle ^ (1 << EndpointIndex) );
    }

    return Status;
}


//<AMI_PHDR_START>
//---------------------------------------------------------------------------
//
// Procedure:   IsPortConnect
//
// Description: 
//      This function returns true if the Hub Class device's Current Connect 
//      Status bit is set in the port status value specified by PortStatus.
//
// Input:
//      IN UINT16 PortStatus
//                  --  This value is the USB Specification (Revision 2.0) 
//                      Hub Port Status Field value as returned by the Get 
//                      Port Status Hub Class device standard request.
//
// Output: 
//      BOOLEAN (Return Value)
//                  = TRUE if a device is present or FALSE if a device is not
//                      present
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>

BOOLEAN IsPortConnect (
    IN UINT16 PortStatus )
{
    //
    // return the bit 0 value of PortStatus
    //
    if ( (PortStatus & USB_PORT_STAT_CONNECTION) != 0 ) {
        return TRUE;
    }
    else {
        return FALSE;
    }
}

//<AMI_PHDR_START>
//---------------------------------------------------------------------------
//
// Procedure:   IsPortEnable
//
// Description: 
//
// Input:
//
// Output: 
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>

BOOLEAN IsPortEnable (
    IN UINT16 PortStatus )
{
    //
    // return the bit 0 value of PortStatus
    //
    if ( (PortStatus & USB_PORT_STAT_ENABLE) != 0 ) {
        return TRUE;
    }
    else {
        return FALSE;
    }
}

//<AMI_PHDR_START>
//---------------------------------------------------------------------------
//
// Procedure:   IsPortLowSpeedDeviceAttached
//
// Description: 
//      This function returns true if the Hub Class device's Low-Speed 
//      Device Attached bit is set in the port status value specified by 
//      PortStatus.
//
// Input:
//      IN UINT16 PortStatus
//                  --  This value is the USB Specification (Revision 2.0) 
//                      Hub Port Status Field value as returned by the Get 
//                      Port Status Hub Class device standard request.
//
// Output: 
//      BOOLEAN (Return Value)
//                  = TRUE if a low-speed device is present or FALSE otherwise
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>

BOOLEAN IsPortLowSpeedDeviceAttached (
    UINT16 PortStatus )
{
    //
    // return the bit 9 value of PortStatus
    //
    if ( (PortStatus & USB_PORT_STAT_LOW_SPEED) != 0 ) {
        return TRUE;
    }
    else {
        return FALSE;
    }
}


//<AMI_PHDR_START>
//---------------------------------------------------------------------------
//
// Procedure:   IsPortHighSpeedDeviceAttached
//
// Description: 
//      This function returns true if the Hub Class device's High-Speed 
//      Device Attached bit is set in the port status value specified by 
//      PortStatus.
//
// Input:
//      IN UINT16 PortStatus
//                  --  This value is the USB Specification (Revision 2.0) 
//                      Hub Port Status Field value as returned by the Get 
//                      Port Status Hub Class device standard request.
//
// Output: 
//      BOOLEAN (Return Value)
//                  = TRUE if a high-speed device is present or FALSE otherwise
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>

BOOLEAN IsPortHighSpeedDeviceAttached (
    UINT16 PortStatus )
{
    //
    // return the bit 10 value of PortStatus
    //
    if ( (PortStatus & USB_PORT_STAT_HIGH_SPEED) != 0 ) {
        return TRUE;
    }
    else {
        return FALSE;
    }
}


//<AMI_PHDR_START>
//---------------------------------------------------------------------------
//
// Procedure:   IsPortSuperSpeedDeviceAttached
//
// Description: 
//      This function returns true if connect status indicates the SuperSpeed
//      device.
//
// Output: 
//      BOOLEAN (Return Value)
//                  = TRUE if a super-speed device is present or FALSE otherwise
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>

BOOLEAN IsPortSuperSpeedDeviceAttached (
    UINT16 PortStatus )
{
    //
    // return the bit 10 value of PortStatus
    //
    if ( (PortStatus & USB_PORT_STAT_SUPER_SPEED) != 0 ) {
        return TRUE;
    }
    else {
        return FALSE;
    }
}


//<AMI_PHDR_START>
//---------------------------------------------------------------------------
//
// Procedure:   IsPortConnectChange
//
// Description: 
//      This function returns true if the Hub Class device's Connect Status 
//      Change bit is set in the port change status value specified 
//      by PortChangeStatus.
//
// Input:
//      IN UINT16 PortStatus
//                  --  This value is the USB Specification (Revision 2.0) 
//                      Hub Port Change Field value as returned by the Get 
//                      Port Status Hub Class device standard request.
//
// Output: 
//      BOOLEAN (Return Value)
//                  = TRUE if Current Connect status has changed or FALSE
//                      if no change has occurred to Current Connect status
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>

BOOLEAN IsPortConnectChange (
    UINT16 PortChangeStatus )
{
    //
    // return the bit 0 value of PortChangeStatus
    //
    if ( (PortChangeStatus & USB_PORT_STAT_C_CONNECTION) != 0 ) {
        return TRUE;
    }
    else {
        return FALSE;
    }
}


#ifndef PI_SPECIFICATION_VERSION //old Core

EFI_STATUS PciCfgModify(
    IN CONST EFI_PEI_SERVICES 	**PeiServices,
    IN EFI_PEI_PCI_CFG_PPI_WIDTH	Width,
    IN UINT64					Address,
    IN UINTN					SetBits,
    IN UINTN					ClearBits)
{
    if((*PeiServices)->PciCfg==NULL)
        return EFI_NOT_AVAILABLE_YET;

    return (*PeiServices)->PciCfg->Modify(
                    (EFI_PEI_SERVICES**)PeiServices,
                    (*PeiServices)->PciCfg,
                    Width, Address,
                    SetBits, ClearBits);
}
#endif

//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2007, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**         5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************
//**********************************************************************