summaryrefslogtreecommitdiff
path: root/Platform/ARM/Drivers/CcixDxe/CcixTopology.c
blob: 6b26127f8f6cb655226735fd6affcab2aca15a2a (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
/** @file

  Copyright (c) 2019, ARM Limited. All rights reserved.

  SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include "Ccix.h"
EFI_STATUS
GetPortIdForConnection (
  CCIX_DEVICE   *SourceDevice,
  CCIX_DEVICE   *DestinationDevice,
  UINT32        *PortId
  )
{
    *PortId = 0x0;
    return EFI_SUCCESS;
}

EFI_STATUS
GetLinkIdForConnection (
  CCIX_DEVICE   *SourceDevice,
  CCIX_DEVICE   *DestinationDevice,
  UINT32        *LinkId
  )
{
    *LinkId = 0x0;
    return EFI_SUCCESS;
}

EFI_STATUS
getSourceTransportIDForPort (
  CCIX_PORT   *Port,
  UINT32      *TransportId
  )
{
    *TransportId = Port->CcixIo->SrcTransportID;
    return EFI_SUCCESS;
}

EFI_STATUS
ConfigureIDMTables (
  EFI_CCIX_CONFIGURATION_PROTOCOL *Ccix
  )
{
  CCIX_PORT     *PrimaryPort;
  CCIX_DEVICE   *Device;
  CCIX_AGENT    *Agent;
  LIST_ENTRY    *DeviceEntry, *AgentEntry;
  EFI_STATUS    Status;
  UINT32        IdmTableOffset, PortId, LinkId, IdmEntry;

  ForEachEntry(Ccix, GlobalDeviceList, DeviceEntry) {
    Device = CCIX_DEVICE_FROM_GLOBAL_DEVICE_LIST(DeviceEntry);

    if (Device->isHost)
      continue;

    Status = GetPrimaryPortForDevice(Device, &PrimaryPort);
    if (EFI_ERROR(Status))
      goto ErrorExit;

    Status = GetTableOffset(PrimaryPort, CM_CAP_IDM_TABLE_OFF, &IdmTableOffset);
    if (EFI_ERROR(Status))
      goto ErrorExit;

    /* Add Local Entry */
    ForEachEntry(Device, DeviceAgentList, AgentEntry) {
      Agent = CCIX_AGENT_FROM_DEVICE_LIST(AgentEntry);

      Status = CcixWrite32(PrimaryPort->CcixIo, IdmTableOffset + (4*Agent->AgentId), 0x0);
      if (EFI_ERROR(Status))
        goto ErrorExit;
    }

    if (Device->NumRA || Device->NumSA) {
      /* Add HA's in IDM entry */
      ForEachEntry(Ccix, GlobalAgentList, AgentEntry) {
        Agent = CCIX_AGENT_FROM_GLOBAL_AGENT_LIST(AgentEntry);

        if (Agent->AgentType != AGENT_HA)
          continue;

        if (Device->DeviceId == Agent->Port->Device->DeviceId)
          continue;

        Status = GetPortIdForConnection(Device, Agent->Port->Device, &PortId);
        if (EFI_ERROR(Status))
          goto ErrorExit;

        Status = GetLinkIdForConnection(Device, Agent->Port->Device, &LinkId);
        if (EFI_ERROR(Status))
          goto ErrorExit;

        IdmEntry = (LinkId << IDM_LINKID_OFF) | (PortId << IDM_PORTID_OFF) | IDM_DESTTYPE_PORT;
        Status = CcixWrite32(PrimaryPort->CcixIo, IdmTableOffset + (4*Agent->AgentId), IdmEntry);
        if (EFI_ERROR(Status))
          goto ErrorExit;
      }
    }
    if (Device->NumHA) {
      /* Add RA's & SA's in IDM entry */
      ForEachEntry(Ccix, GlobalAgentList, AgentEntry) {
        Agent = CCIX_AGENT_FROM_GLOBAL_AGENT_LIST(AgentEntry);

        if (Agent->AgentType == AGENT_HA)
          continue;

        if (Device->DeviceId == Agent->Port->Device->DeviceId)
          continue;

        Status = GetPortIdForConnection(Device, Agent->Port->Device, &PortId);
        if (EFI_ERROR(Status))
          goto ErrorExit;

        Status = GetLinkIdForConnection(Device, Agent->Port->Device, &LinkId);
        if (EFI_ERROR(Status))
          goto ErrorExit;

        IdmEntry = (LinkId << IDM_LINKID_OFF) | (PortId << IDM_PORTID_OFF) | IDM_DESTTYPE_PORT;
        Status = CcixWrite32(PrimaryPort->CcixIo, IdmTableOffset + (4*Agent->AgentId), IdmEntry);
        if (EFI_ERROR(Status))
          goto ErrorExit;
      }
    }
  }

  return EFI_SUCCESS;
ErrorExit:
  DEBUG((DEBUG_ERROR, "%a failed: %r\n", __func__, Status));
  return Status;
}

EFI_STATUS
ConfigureHSAMTables (
  EFI_CCIX_CONFIGURATION_PROTOCOL *Ccix
  )
{
  return EFI_SUCCESS;
}

EFI_STATUS
ConfigureRSAMTables (
  EFI_CCIX_CONFIGURATION_PROTOCOL *Ccix
  )
{
  CCIX_PORT     *PrimaryPort;
  CCIX_DEVICE   *Device;
  LIST_ENTRY    *DeviceEntry, *AgentEntry, *MemoryEntry;
  EFI_STATUS    Status;
  UINT32        RsamTableOffset, PortId, SamEntry;
  BOOLEAN       isRaPresent = FALSE;
  CCIX_AGENT    *Agent;
  CCIX_MEMORY   *MemPool;

  ForEachEntry(Ccix, GlobalDeviceList, DeviceEntry) {
    Device = CCIX_DEVICE_FROM_GLOBAL_DEVICE_LIST(DeviceEntry);

    if (Device->isHost)
      continue;

    /*If No RA Then Skip device No RSAM */
    ForEachEntry(Device, DeviceAgentList, AgentEntry) {
      Agent = CCIX_AGENT_FROM_DEVICE_LIST(AgentEntry);
      if (Agent->AgentType == AGENT_RA) {
        isRaPresent = TRUE;
        break;
      }
    }
    if (!isRaPresent)
      continue;

    Status = GetPrimaryPortForDevice(Device, &PrimaryPort);
    if (EFI_ERROR(Status))
      goto ErrorExit;

    Status = GetTableOffset(PrimaryPort, CM_CAP_RSAM_TABLE_OFF, &RsamTableOffset);
    if (EFI_ERROR(Status))
      goto ErrorExit;

    ForEachEntry(Ccix, GlobalAgentList, AgentEntry) {
      Agent = CCIX_AGENT_FROM_GLOBAL_AGENT_LIST(AgentEntry);

      if (Agent->AgentType == AGENT_HA) {
        Status = GetPortIdForConnection(Device, Agent->Port->Device, &PortId);
        if (EFI_ERROR(Status))
          goto ErrorExit;

        ForEachEntry(Agent, AgentMemoryList, MemoryEntry) {
          MemPool = CCIX_MEMORY_FROM_AGENT_LIST(MemoryEntry);

          SamEntry = (PortId << SAM_PORTID_OFF) | ((Device->DeviceId != Agent->Port->Device->DeviceId)? SAM_DESTTYPE_PORT : 0x0);

          Status = CcixWrite32(PrimaryPort->CcixIo, RsamTableOffset + (12*Device->NumRsamEntry), SamEntry);
          if (EFI_ERROR(Status))
            goto ErrorExit;

          Status = CcixWrite32(PrimaryPort->CcixIo, RsamTableOffset + 0x4 + (12*Device->NumRsamEntry), MemPool->BaseAddr);
          if (EFI_ERROR(Status))
            goto ErrorExit;
          Status = CcixWrite32(PrimaryPort->CcixIo, RsamTableOffset + 0x8 + (12*Device->NumRsamEntry), MemPool->BaseAddr+MemPool->PoolSize);
          if (EFI_ERROR(Status))
            goto ErrorExit;

          Device->NumRsamEntry++;
        }
      }
    }
  }
  return EFI_SUCCESS;
ErrorExit:
  DEBUG((DEBUG_ERROR, "%a failed: %r\n", __func__, Status));
  return Status;
}

EFI_STATUS
ConfigureLinkControl (
  EFI_CCIX_CONFIGURATION_PROTOCOL *Ccix
  )
{
  EFI_STATUS    Status;
  LIST_ENTRY    *DeviceEntry, *PortEntry;
  CCIX_PORT     *Port;
  CCIX_DEVICE   *Device;
  CCIX_LINK     *Link;
  /* Program Destination Transport ID for every Link */

  ForEachEntry(Ccix, GlobalDeviceList, DeviceEntry) {
    Device = CCIX_DEVICE_FROM_GLOBAL_DEVICE_LIST(DeviceEntry);

    if (Device->isHost)
      continue;

    ForEachEntry(Device, DevicePortList, PortEntry) {
      Port = CCIX_PORT_FROM_DEVICE_LIST(PortEntry);

      Link = Port->LinkInfo;
      /* Destination BDF in Link */
      Status = CcixWrite32(Port->CcixIo, Link->LinkControlOffset + DW1_OFF + Link->LinkControlSize + DW1_OFF, 0x00000000);
      if (EFI_ERROR(Status))
        goto ErrorExit;
    }
  }
  return EFI_SUCCESS;
ErrorExit:
  DEBUG((DEBUG_ERROR, "%a failed: %r\n", __func__, Status));
  return Status;
}

EFI_STATUS
ConfigurePortControl (
  EFI_CCIX_CONFIGURATION_PROTOCOL *Ccix
  )
{
  EFI_STATUS    Status;
  LIST_ENTRY    *Entry;
  CCIX_PORT     *Port;

  ForEachEntry(Ccix, GlobalPortList, Entry) {
    Port = CCIX_PORT_FROM_GLOBAL_PORT_LIST(Entry);

    if (Port->Device->isHost)
      continue;

    Status = CcixWrite32(Port->CcixIo, Port->PortControlOffset + DW4_OFF, Port->CcixIo->SrcTransportID);
    if (EFI_ERROR(Status))
      goto ErrorExit;
  }

  return EFI_SUCCESS;
ErrorExit:
  DEBUG((DEBUG_ERROR, "%a failed: %r\n", __func__, Status));
  return Status;
}

EFI_STATUS
CcixConfigureLinksPorts (
  EFI_CCIX_CONFIGURATION_PROTOCOL *Ccix
  )
{
  EFI_STATUS Status;

  Status = ConfigureLinkControl(Ccix);
  if (EFI_ERROR(Status))
    goto ErrorExit;

  Status = ConfigurePortControl(Ccix);
  if (EFI_ERROR(Status))
    goto ErrorExit;

  return EFI_SUCCESS;
ErrorExit:
  DEBUG((DEBUG_ERROR, "%a failed: %r\n", __func__, Status));
  return Status;
}

EFI_STATUS
CcixConfigureRoutingTables (
  EFI_CCIX_CONFIGURATION_PROTOCOL *Ccix
  )
{
  EFI_STATUS Status;

  Status = ConfigureIDMTables(Ccix);
  if (EFI_ERROR(Status)) {
    DEBUG((DEBUG_ERROR, "ConfigureIDMTables failed\n"));
    goto ErrorExit;
  }

  Status = ConfigureHSAMTables(Ccix);
  if (EFI_ERROR(Status)) {
    DEBUG((DEBUG_ERROR, "ConfigureHSAMTables failed\n"));
    goto ErrorExit;
  }

  Status = ConfigureRSAMTables(Ccix);
  if (EFI_ERROR(Status)) {
    DEBUG((DEBUG_ERROR, "ConfigureRSAMTables failed\n"));
    goto ErrorExit;
  }

  return EFI_SUCCESS;
ErrorExit:
  DEBUG((DEBUG_ERROR, "%a failed: %r\n", __func__, Status));
  return Status;
}

EFI_STATUS
CcixTopologyConfigure (
  EFI_CCIX_CONFIGURATION_PROTOCOL *Ccix
  )
{
  EFI_STATUS Status;

  Status = CcixConfigureLinksPorts(Ccix);
  if (EFI_ERROR(Status))
    goto ErrorExit;

  Status = CcixConfigureRoutingTables(Ccix);
  if (EFI_ERROR(Status))
    goto ErrorExit;

  return EFI_SUCCESS;
ErrorExit:
  DEBUG((DEBUG_ERROR, "%a failed: %r\n", __func__, Status));
  return Status;
}

EFI_STATUS
CcixTopologyDiscover (
  EFI_CCIX_CONFIGURATION_PROTOCOL *Ccix
  )
{
  return EFI_SUCCESS;
}