]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/CpuMpPei/PeiMpServices.c
UefiCpuPkg/CpuMpPei: Implementation of PeiWhoAmI ()
[mirror_edk2.git] / UefiCpuPkg / CpuMpPei / PeiMpServices.c
1 /** @file
2 Implementation of Multiple Processor PPI services.
3
4 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "PeiMpServices.h"
16
17
18
19 /**
20 Find the current Processor number by APIC ID.
21
22 @param PeiCpuMpData Pointer to PEI CPU MP Data
23 @param ProcessorNumber Return the pocessor number found
24
25 @retval EFI_SUCCESS ProcessorNumber is found and returned.
26 @retval EFI_NOT_FOUND ProcessorNumber is not found.
27 **/
28 EFI_STATUS
29 GetProcessorNumber (
30 IN PEI_CPU_MP_DATA *PeiCpuMpData,
31 OUT UINTN *ProcessorNumber
32 )
33 {
34 UINTN TotalProcessorNumber;
35 UINTN Index;
36
37 TotalProcessorNumber = PeiCpuMpData->CpuCount;
38 for (Index = 0; Index < TotalProcessorNumber; Index ++) {
39 if (PeiCpuMpData->CpuData[Index].ApicId == GetInitialApicId ()) {
40 *ProcessorNumber = Index;
41 return EFI_SUCCESS;
42 }
43 }
44 return EFI_NOT_FOUND;
45 }
46
47
48 /**
49 This return the handle number for the calling processor. This service may be
50 called from the BSP and APs.
51
52 This service returns the processor handle number for the calling processor.
53 The returned value is in the range from 0 to the total number of logical
54 processors minus 1. The total number of logical processors can be retrieved
55 with EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors(). This service may be
56 called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER
57 is returned. Otherwise, the current processors handle number is returned in
58 ProcessorNumber, and EFI_SUCCESS is returned.
59
60 @param[in] PeiServices An indirect pointer to the PEI Services Table
61 published by the PEI Foundation.
62 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
63 @param[out] ProcessorNumber The handle number of the AP. The range is from 0 to the
64 total number of logical processors minus 1. The total
65 number of logical processors can be retrieved by
66 EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
67
68 @retval EFI_SUCCESS The current processor handle number was returned in
69 ProcessorNumber.
70 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
71 **/
72 EFI_STATUS
73 EFIAPI
74 PeiWhoAmI (
75 IN CONST EFI_PEI_SERVICES **PeiServices,
76 IN EFI_PEI_MP_SERVICES_PPI *This,
77 OUT UINTN *ProcessorNumber
78 )
79 {
80 PEI_CPU_MP_DATA *PeiCpuMpData;
81
82 PeiCpuMpData = GetMpHobData ();
83 if (PeiCpuMpData == NULL) {
84 return EFI_NOT_FOUND;
85 }
86
87 if (ProcessorNumber == NULL) {
88 return EFI_INVALID_PARAMETER;
89 }
90
91 return GetProcessorNumber (PeiCpuMpData, ProcessorNumber);
92 }
93