summaryrefslogtreecommitdiff
path: root/Core/EM/PlatformToDriver/PlatformToDriver.c
blob: 4077656d96c57540b2dbc7a01d08ec229f6e2ccb (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
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************

//**********************************************************************
// $Header: /Alaska/BIN/Core/Modules/PlatformToDriverConfiguration/PlatformToDriver.c 1     5/02/11 5:30p Artems $
//
// $Revision: 1 $
//
// $Date: 5/02/11 5:30p $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/BIN/Core/Modules/PlatformToDriverConfiguration/PlatformToDriver.c $
// 
// 1     5/02/11 5:30p Artems
// Platform-to-Driver confuguration protocol supporting infrastructure
// 
//**********************************************************************
//<AMI_FHDR_START>
//
// Name: PlatformToDriver.c
//
// Description: 
//
//<AMI_FHDR_END>
//**********************************************************************
#include <Token.h>
#include <AmiDxeLib.h>
#include <Protocol\PlatformToDriverConfiguration.h>

typedef EFI_STATUS (PLATFORM_TO_DRIVER_AGENT_SUPPORTED) (
   IN EFI_HANDLE ControllerHandle,
   IN EFI_HANDLE ChildHandle OPTIONAL
);

typedef EFI_STATUS (PLATFORM_TO_DRIVER_AGENT_QUERY) (
    IN  EFI_HANDLE ControllerHandle,
    IN  EFI_HANDLE ChildHandle OPTIONAL,
    IN  UINTN      *Instance,
    OUT EFI_GUID   **ParameterTypeGuid,
    OUT VOID       **ParameterBlock,
    OUT UINTN      *ParameterBlockSize
);

typedef EFI_STATUS (PLATFORM_TO_DRIVER_AGENT_RESPONSE) (
    IN EFI_HANDLE                        ControllerHandle,
    IN EFI_HANDLE                        ChildHandle OPTIONAL,
    IN UINTN                             *Instance,
    IN EFI_GUID                          *ParameterTypeGuid,
    IN VOID                              *ParameterBlock,
    IN UINTN                             ParameterBlockSize,
    IN EFI_PLATFORM_CONFIGURATION_ACTION ConfigurationAction
);

typedef struct{
	PLATFORM_TO_DRIVER_AGENT_SUPPORTED  *Supported;
    PLATFORM_TO_DRIVER_AGENT_QUERY      *Query;
	PLATFORM_TO_DRIVER_AGENT_RESPONSE   *Response;
} PLATFORM_TO_DRIVER_AGENT;


#define OEM_PLATFORM_TO_DRIVER_AGENT(Supported, Query, Response) Supported
extern PLATFORM_TO_DRIVER_AGENT_SUPPORTED PlatformToDriverAgentList EndOfList1;
#undef OEM_PLATFORM_TO_DRIVER_AGENT

#define OEM_PLATFORM_TO_DRIVER_AGENT(Supported, Query, Response) Query
extern PLATFORM_TO_DRIVER_AGENT_QUERY PlatformToDriverAgentList EndOfList2;
#undef OEM_PLATFORM_TO_DRIVER_AGENT

#define OEM_PLATFORM_TO_DRIVER_AGENT(Supported, Query, Response) Response
extern PLATFORM_TO_DRIVER_AGENT_RESPONSE PlatformToDriverAgentList EndOfList3;
#undef OEM_PLATFORM_TO_DRIVER_AGENT

#define OEM_PLATFORM_TO_DRIVER_AGENT(Supported, Query, Response) { Supported, Query, Response }
PLATFORM_TO_DRIVER_AGENT AgentList[] = {
    PlatformToDriverAgentList
    { NULL, NULL, NULL }
};

EFI_HANDLE CurrentControllerHandle = NULL;
UINT32 CurrentAgentIndex;

EFI_STATUS PlatformToDriverConfigurationQuery (
    IN  EFI_PLATFORM_TO_DRIVER_CONFIGURATION_PROTOCOL *This,
    IN  EFI_HANDLE                                    ControllerHandle,
    IN  EFI_HANDLE                                    ChildHandle OPTIONAL,
    IN  UINTN                                         *Instance,
    OUT EFI_GUID                                      **ParameterTypeGuid,
    OUT VOID                                          **ParameterBlock,
    OUT UINTN                                         *ParameterBlockSize
)
{
    EFI_STATUS Status;

    if(ControllerHandle == NULL || Instance == NULL)
        return EFI_INVALID_PARAMETER;

    if(ControllerHandle != CurrentControllerHandle) {
        CurrentAgentIndex = 0;
        Status = EFI_UNSUPPORTED;
        while(AgentList[CurrentAgentIndex].Supported != NULL) {
            Status = AgentList[CurrentAgentIndex].Supported(ControllerHandle, ChildHandle);
            if(!EFI_ERROR(Status))
                break;
            CurrentAgentIndex++;
        }
        if(EFI_ERROR(Status)) {
            CurrentControllerHandle = NULL;
            return EFI_NOT_FOUND;
        }

        CurrentControllerHandle = ControllerHandle;
    }

    return AgentList[CurrentAgentIndex].Query(ControllerHandle,
                                              ChildHandle,
                                              Instance,
                                              ParameterTypeGuid,
                                              ParameterBlock,
                                              ParameterBlockSize);
}

EFI_STATUS PlatformToDriverConfigurationResponse (
    IN EFI_PLATFORM_TO_DRIVER_CONFIGURATION_PROTOCOL *This,
    IN EFI_HANDLE                                    ControllerHandle,
    IN EFI_HANDLE                                    ChildHandle OPTIONAL,
    IN UINTN                                         *Instance,
    IN EFI_GUID                                      *ParameterTypeGuid,
    IN VOID                                          *ParameterBlock,
    IN UINTN                                         ParameterBlockSize,
    IN EFI_PLATFORM_CONFIGURATION_ACTION             ConfigurationAction
)
{
    if(ControllerHandle == NULL || Instance == NULL)
        return EFI_INVALID_PARAMETER;

    if(ControllerHandle != CurrentControllerHandle)
        return EFI_NOT_FOUND;

    return AgentList[CurrentAgentIndex].Response(ControllerHandle,
                                                 ChildHandle,
                                                 Instance,
                                                 ParameterTypeGuid,
                                                 ParameterBlock,
                                                 ParameterBlockSize,
                                                 ConfigurationAction);
}

EFI_PLATFORM_TO_DRIVER_CONFIGURATION_PROTOCOL EfiPlatformToDriverConfigurationProtocol = {
    PlatformToDriverConfigurationQuery,
    PlatformToDriverConfigurationResponse
};

EFI_STATUS PlatformToDriverEntryPoint(
    IN EFI_HANDLE ImageHandle,
    IN EFI_SYSTEM_TABLE *SystemTable
)
{
    EFI_STATUS  Status;
    EFI_HANDLE  Handle = NULL;

    InitAmiLib(ImageHandle,SystemTable);

    Status = pBS->InstallMultipleProtocolInterfaces(
                                &Handle,
                                &gEfiPlatformToDriverConfigurationProtocolGuid, 
                                &EfiPlatformToDriverConfigurationProtocol,
                                NULL);


    return Status;
}



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