]>
Commit | Line | Data |
---|---|---|
fb0b259e | 1 | /** @file\r |
2 | This file contains two sets of callback routines for undi3.0 and undi3.1.\r | |
3 | the callback routines for Undi3.1 have an extra parameter UniqueId which\r | |
4 | stores the interface context for the NIC that snp is trying to talk.\r | |
5 | \r | |
9c9f5859 | 6 | Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 7 | This program and the accompanying materials\r |
5e7e4fad | 8 | are licensed and made available under the terms and conditions of the BSD License\r |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
fb0b259e | 15 | **/\r |
5e7e4fad | 16 | \r |
17 | #include "Snp.h"\r | |
18 | \r | |
19 | //\r | |
20 | // Global variables\r | |
21 | // these 2 global variables are used only for 3.0 undi. we could not place\r | |
22 | // them in the snp structure because we will not know which snp structure\r | |
23 | // in the callback context!\r | |
24 | //\r | |
fe1e36e5 | 25 | BOOLEAN mInitializeLock = TRUE;\r |
26 | EFI_LOCK mLock;\r | |
5e7e4fad | 27 | \r |
28 | //\r | |
29 | // End Global variables\r | |
30 | //\r | |
4cda7726 | 31 | extern EFI_PCI_IO_PROTOCOL *mPciIo;\r |
5e7e4fad | 32 | \r |
9c9f5859 | 33 | /**\r |
34 | Convert a virtual or CPU address provided by SNP to a physical or device\r | |
35 | address.\r | |
f3816027 | 36 | \r |
37 | This is a callback routine supplied to UNDI at undi_start time. Since EFI uses\r | |
9c9f5859 | 38 | the identical mapping, this routine returns the physical address same as the\r |
39 | virtual address for most of the addresses. an address above 4GB cannot\r | |
40 | generally be used as a device address, it needs to be mapped to a lower\r | |
41 | physical address. This routine does not call the map routine itself, but it\r | |
42 | assumes that the mapping was done at the time of providing the address to\r | |
43 | UNDI. This routine just looks up the address in a map table (which is the v2p\r | |
44 | structure chain).\r | |
45 | \r | |
f3816027 | 46 | @param CpuAddr Virtual address.\r |
9c9f5859 | 47 | @param DeviceAddrPtr Pointer to the physical address, or 0 in case of any\r |
f3816027 | 48 | error.\r |
4cda7726 | 49 | \r |
50 | **/\r | |
5e7e4fad | 51 | VOID\r |
9c9f5859 | 52 | EFIAPI\r |
4cda7726 | 53 | SnpUndi32CallbackV2p30 (\r |
5e7e4fad | 54 | IN UINT64 CpuAddr,\r |
55 | IN OUT UINT64 DeviceAddrPtr\r | |
56 | )\r | |
5e7e4fad | 57 | {\r |
4cda7726 | 58 | V2P *V2p;\r |
5e7e4fad | 59 | //\r |
60 | // Do nothing if virtual address is zero or physical pointer is NULL.\r | |
61 | // No need to map if the virtual address is within 4GB limit since\r | |
62 | // EFI uses identical mapping\r | |
63 | //\r | |
64 | if ((CpuAddr == 0) || (DeviceAddrPtr == 0)) {\r | |
9cff2f8d | 65 | DEBUG ((EFI_D_NET, "\nv2p: Null virtual address or physical pointer.\n"));\r |
5e7e4fad | 66 | return ;\r |
67 | }\r | |
68 | \r | |
69 | if (CpuAddr < FOUR_GIGABYTES) {\r | |
70 | *(UINT64 *) (UINTN) DeviceAddrPtr = CpuAddr;\r | |
71 | return ;\r | |
72 | }\r | |
73 | //\r | |
74 | // SNP creates a vaddr tp paddr mapping at the time of calling undi with any\r | |
75 | // big address, this callback routine just looks up in the v2p list and\r | |
76 | // returns the physical address for any given virtual address.\r | |
77 | //\r | |
4cda7726 | 78 | if (FindV2p (&V2p, (VOID *) (UINTN) CpuAddr) != EFI_SUCCESS) {\r |
5e7e4fad | 79 | *(UINT64 *) (UINTN) DeviceAddrPtr = CpuAddr;\r |
80 | } else {\r | |
4cda7726 | 81 | *(UINT64 *) (UINTN) DeviceAddrPtr = V2p->PhysicalAddress;\r |
5e7e4fad | 82 | }\r |
83 | }\r | |
84 | \r | |
4cda7726 | 85 | /**\r |
f3816027 | 86 | Acquire or release a lock of an exclusive access to a critical section of the\r |
9c9f5859 | 87 | code/data.\r |
f3816027 | 88 | \r |
4cda7726 | 89 | This is a callback routine supplied to UNDI at undi_start time.\r |
4cda7726 | 90 | \r |
f3816027 | 91 | @param Enable Non-zero indicates acquire; Zero indicates release.\r |
4cda7726 | 92 | \r |
93 | **/\r | |
5e7e4fad | 94 | VOID\r |
9c9f5859 | 95 | EFIAPI\r |
4cda7726 | 96 | SnpUndi32CallbackBlock30 (\r |
5e7e4fad | 97 | IN UINT32 Enable\r |
98 | )\r | |
5e7e4fad | 99 | {\r |
100 | //\r | |
101 | // tcpip was calling snp at tpl_notify and if we acquire a lock that was\r | |
102 | // created at a lower level (TPL_CALLBACK) it gives an assert!\r | |
103 | //\r | |
104 | if (mInitializeLock) {\r | |
105 | EfiInitializeLock (&mLock, TPL_NOTIFY);\r | |
106 | mInitializeLock = FALSE;\r | |
107 | }\r | |
108 | \r | |
109 | if (Enable != 0) {\r | |
110 | EfiAcquireLock (&mLock);\r | |
111 | } else {\r | |
112 | EfiReleaseLock (&mLock);\r | |
113 | }\r | |
114 | }\r | |
115 | \r | |
4cda7726 | 116 | /**\r |
f3816027 | 117 | Delay MicroSeconds of micro seconds.\r |
9c9f5859 | 118 | \r |
4cda7726 | 119 | This is a callback routine supplied to UNDI at undi_start time.\r |
4cda7726 | 120 | \r |
f3816027 | 121 | @param MicroSeconds Number of micro seconds to pause, ususlly multiple of 10.\r |
4cda7726 | 122 | \r |
123 | **/\r | |
5e7e4fad | 124 | VOID\r |
9c9f5859 | 125 | EFIAPI\r |
4cda7726 | 126 | SnpUndi32CallbackDelay30 (\r |
5e7e4fad | 127 | IN UINT64 MicroSeconds\r |
128 | )\r | |
5e7e4fad | 129 | {\r |
130 | if (MicroSeconds != 0) {\r | |
131 | gBS->Stall ((UINTN) MicroSeconds);\r | |
132 | }\r | |
133 | }\r | |
134 | \r | |
4cda7726 | 135 | /**\r |
9c9f5859 | 136 | IO routine for UNDI.\r |
f3816027 | 137 | \r |
9c9f5859 | 138 | This is a callback routine supplied to UNDI at undi_start time. This is not\r |
139 | currently being used by UNDI3.0 because Undi3.0 uses io/mem offsets relative\r | |
140 | to the beginning of the device io/mem address and so it needs to use the\r | |
141 | PCI_IO_FUNCTION that abstracts the start of the device's io/mem addresses.\r | |
142 | Since SNP cannot retrive the context of the undi3.0 interface it cannot use\r | |
143 | the PCI_IO_FUNCTION that specific for that NIC and uses one global IO\r | |
144 | functions structure, this does not work. This however works fine for EFI1.0\r | |
145 | Undis because they use absolute addresses for io/mem access.\r | |
f3816027 | 146 | \r |
147 | @param ReadOrWrite Indicates read or write, IO or Memory.\r | |
148 | @param NumBytes Number of bytes to read or write.\r | |
149 | @param Address IO or memory address to read from or write to.\r | |
150 | @param BufferAddr Memory location to read into or that contains the bytes to\r | |
151 | write.\r | |
4cda7726 | 152 | \r |
153 | **/\r | |
5e7e4fad | 154 | VOID\r |
9c9f5859 | 155 | EFIAPI\r |
4cda7726 | 156 | SnpUndi32CallbackMemio30 (\r |
5e7e4fad | 157 | IN UINT8 ReadOrWrite,\r |
158 | IN UINT8 NumBytes,\r | |
159 | IN UINT64 Address,\r | |
160 | IN OUT UINT64 BufferAddr\r | |
161 | )\r | |
5e7e4fad | 162 | {\r |
163 | EFI_PCI_IO_PROTOCOL_WIDTH Width;\r | |
164 | \r | |
165 | switch (NumBytes) {\r | |
166 | case 2:\r | |
167 | Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 1;\r | |
168 | break;\r | |
169 | \r | |
170 | case 4:\r | |
171 | Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 2;\r | |
172 | break;\r | |
173 | \r | |
174 | case 8:\r | |
175 | Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 3;\r | |
176 | break;\r | |
177 | \r | |
178 | default:\r | |
179 | Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 0;\r | |
180 | }\r | |
181 | \r | |
182 | switch (ReadOrWrite) {\r | |
183 | case PXE_IO_READ:\r | |
4cda7726 | 184 | mPciIo->Io.Read (\r |
185 | mPciIo,\r | |
186 | Width,\r | |
187 | 1, // BAR 1, IO base address\r | |
188 | Address,\r | |
189 | 1, // count\r | |
190 | (VOID *) (UINTN) BufferAddr\r | |
191 | );\r | |
5e7e4fad | 192 | break;\r |
193 | \r | |
194 | case PXE_IO_WRITE:\r | |
4cda7726 | 195 | mPciIo->Io.Write (\r |
196 | mPciIo,\r | |
197 | Width,\r | |
198 | 1, // BAR 1, IO base address\r | |
199 | Address,\r | |
200 | 1, // count\r | |
201 | (VOID *) (UINTN) BufferAddr\r | |
202 | );\r | |
5e7e4fad | 203 | break;\r |
204 | \r | |
205 | case PXE_MEM_READ:\r | |
4cda7726 | 206 | mPciIo->Mem.Read (\r |
207 | mPciIo,\r | |
208 | Width,\r | |
209 | 0, // BAR 0, Memory base address\r | |
210 | Address,\r | |
211 | 1, // count\r | |
212 | (VOID *) (UINTN) BufferAddr\r | |
213 | );\r | |
5e7e4fad | 214 | break;\r |
215 | \r | |
216 | case PXE_MEM_WRITE:\r | |
4cda7726 | 217 | mPciIo->Mem.Write (\r |
218 | mPciIo,\r | |
219 | Width,\r | |
220 | 0, // BAR 0, Memory base address\r | |
221 | Address,\r | |
222 | 1, // count\r | |
223 | (VOID *) (UINTN) BufferAddr\r | |
224 | );\r | |
5e7e4fad | 225 | break;\r |
226 | }\r | |
227 | \r | |
228 | return ;\r | |
229 | }\r | |
4cda7726 | 230 | \r |
231 | /**\r | |
9c9f5859 | 232 | Acquire or release a lock of the exclusive access to a critical section of the\r |
233 | code/data.\r | |
234 | \r | |
4cda7726 | 235 | This is a callback routine supplied to UNDI3.1 at undi_start time.\r |
f3816027 | 236 | New callbacks for 3.1: there won't be a virtual2physical callback for UNDI 3.1\r |
9c9f5859 | 237 | because undi3.1 uses the MemMap call to map the required address by itself!\r |
4cda7726 | 238 | \r |
9c9f5859 | 239 | @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to\r |
f3816027 | 240 | store Undi interface context (Undi does not read or write\r |
241 | this variable).\r | |
9c9f5859 | 242 | @param Enable Non-zero indicates acquire; Zero indicates release.\r |
f3816027 | 243 | \r |
4cda7726 | 244 | **/\r |
5e7e4fad | 245 | VOID\r |
9c9f5859 | 246 | EFIAPI\r |
4cda7726 | 247 | SnpUndi32CallbackBlock (\r |
5e7e4fad | 248 | IN UINT64 UniqueId,\r |
249 | IN UINT32 Enable\r | |
250 | )\r | |
5e7e4fad | 251 | {\r |
4cda7726 | 252 | SNP_DRIVER *Snp;\r |
5e7e4fad | 253 | \r |
4cda7726 | 254 | Snp = (SNP_DRIVER *) (UINTN) UniqueId;\r |
5e7e4fad | 255 | //\r |
256 | // tcpip was calling snp at tpl_notify and when we acquire a lock that was\r | |
257 | // created at a lower level (TPL_CALLBACK) it gives an assert!\r | |
258 | //\r | |
259 | if (Enable != 0) {\r | |
4cda7726 | 260 | EfiAcquireLock (&Snp->Lock);\r |
5e7e4fad | 261 | } else {\r |
4cda7726 | 262 | EfiReleaseLock (&Snp->Lock);\r |
5e7e4fad | 263 | }\r |
264 | }\r | |
265 | \r | |
4cda7726 | 266 | /**\r |
f3816027 | 267 | Delay MicroSeconds of micro seconds.\r |
9c9f5859 | 268 | \r |
4cda7726 | 269 | This is a callback routine supplied to UNDI at undi_start time.\r |
4cda7726 | 270 | \r |
271 | @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to\r | |
f3816027 | 272 | store Undi interface context (Undi does not read or write\r |
273 | this variable).\r | |
9c9f5859 | 274 | @param MicroSeconds Number of micro seconds to pause, ususlly multiple of 10.\r |
f3816027 | 275 | \r |
4cda7726 | 276 | **/\r |
5e7e4fad | 277 | VOID\r |
9c9f5859 | 278 | EFIAPI\r |
4cda7726 | 279 | SnpUndi32CallbackDelay (\r |
5e7e4fad | 280 | IN UINT64 UniqueId,\r |
281 | IN UINT64 MicroSeconds\r | |
282 | )\r | |
5e7e4fad | 283 | {\r |
284 | if (MicroSeconds != 0) {\r | |
285 | gBS->Stall ((UINTN) MicroSeconds);\r | |
286 | }\r | |
287 | }\r | |
288 | \r | |
4cda7726 | 289 | /**\r |
9c9f5859 | 290 | IO routine for UNDI3.1.\r |
291 | \r | |
4cda7726 | 292 | This is a callback routine supplied to UNDI at undi_start time.\r |
9c9f5859 | 293 | \r |
294 | @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this\r | |
295 | to store Undi interface context (Undi does not read or\r | |
296 | write this variable).\r | |
f3816027 | 297 | @param ReadOrWrite Indicates read or write, IO or Memory.\r |
298 | @param NumBytes Number of bytes to read or write.\r | |
4cda7726 | 299 | @param MemOrPortAddr IO or memory address to read from or write to.\r |
f3816027 | 300 | @param BufferPtr Memory location to read into or that contains the bytes\r |
9c9f5859 | 301 | to write.\r |
f3816027 | 302 | \r |
4cda7726 | 303 | **/\r |
5e7e4fad | 304 | VOID\r |
9c9f5859 | 305 | EFIAPI\r |
4cda7726 | 306 | SnpUndi32CallbackMemio (\r |
307 | IN UINT64 UniqueId,\r | |
308 | IN UINT8 ReadOrWrite,\r | |
309 | IN UINT8 NumBytes,\r | |
310 | IN UINT64 MemOrPortAddr,\r | |
311 | IN OUT UINT64 BufferPtr\r | |
5e7e4fad | 312 | )\r |
5e7e4fad | 313 | {\r |
4cda7726 | 314 | SNP_DRIVER *Snp;\r |
5e7e4fad | 315 | EFI_PCI_IO_PROTOCOL_WIDTH Width;\r |
316 | \r | |
4cda7726 | 317 | Snp = (SNP_DRIVER *) (UINTN) UniqueId;\r |
5e7e4fad | 318 | \r |
319 | Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 0;\r | |
320 | switch (NumBytes) {\r | |
321 | case 2:\r | |
322 | Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 1;\r | |
323 | break;\r | |
324 | \r | |
325 | case 4:\r | |
326 | Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 2;\r | |
327 | break;\r | |
328 | \r | |
329 | case 8:\r | |
330 | Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 3;\r | |
331 | break;\r | |
332 | }\r | |
333 | \r | |
334 | switch (ReadOrWrite) {\r | |
335 | case PXE_IO_READ:\r | |
4cda7726 | 336 | Snp->PciIo->Io.Read (\r |
337 | Snp->PciIo,\r | |
338 | Width,\r | |
339 | Snp->IoBarIndex, // BAR 1 (for 32bit regs), IO base address\r | |
340 | MemOrPortAddr,\r | |
341 | 1, // count\r | |
342 | (VOID *) (UINTN) BufferPtr\r | |
343 | );\r | |
5e7e4fad | 344 | break;\r |
345 | \r | |
346 | case PXE_IO_WRITE:\r | |
4cda7726 | 347 | Snp->PciIo->Io.Write (\r |
348 | Snp->PciIo,\r | |
349 | Width,\r | |
350 | Snp->IoBarIndex, // BAR 1 (for 32bit regs), IO base address\r | |
351 | MemOrPortAddr,\r | |
352 | 1, // count\r | |
353 | (VOID *) (UINTN) BufferPtr\r | |
354 | );\r | |
5e7e4fad | 355 | break;\r |
356 | \r | |
357 | case PXE_MEM_READ:\r | |
4cda7726 | 358 | Snp->PciIo->Mem.Read (\r |
359 | Snp->PciIo,\r | |
5e7e4fad | 360 | Width,\r |
4cda7726 | 361 | Snp->MemoryBarIndex, // BAR 0, Memory base address\r |
362 | MemOrPortAddr,\r | |
5e7e4fad | 363 | 1, // count\r |
4cda7726 | 364 | (VOID *) (UINTN) BufferPtr\r |
5e7e4fad | 365 | );\r |
366 | break;\r | |
367 | \r | |
368 | case PXE_MEM_WRITE:\r | |
4cda7726 | 369 | Snp->PciIo->Mem.Write (\r |
370 | Snp->PciIo,\r | |
5e7e4fad | 371 | Width,\r |
4cda7726 | 372 | Snp->MemoryBarIndex, // BAR 0, Memory base address\r |
373 | MemOrPortAddr,\r | |
5e7e4fad | 374 | 1, // count\r |
4cda7726 | 375 | (VOID *) (UINTN) BufferPtr\r |
5e7e4fad | 376 | );\r |
377 | break;\r | |
378 | }\r | |
379 | \r | |
380 | return ;\r | |
381 | }\r | |
382 | \r | |
4cda7726 | 383 | /**\r |
9c9f5859 | 384 | Map a CPU address to a device address.\r |
f3816027 | 385 | \r |
4cda7726 | 386 | This is a callback routine supplied to UNDI at undi_start time.\r |
4cda7726 | 387 | \r |
f3816027 | 388 | @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to\r |
389 | store Undi interface context (Undi does not read or write\r | |
390 | this variable).\r | |
391 | @param CpuAddr Virtual address to be mapped.\r | |
392 | @param NumBytes Size of memory to be mapped.\r | |
393 | @param Direction Direction of data flow for this memory's usage:\r | |
394 | cpu->device, device->cpu or both ways.\r | |
395 | @param DeviceAddrPtr Pointer to return the mapped device address.\r | |
4cda7726 | 396 | \r |
397 | **/\r | |
5e7e4fad | 398 | VOID\r |
9c9f5859 | 399 | EFIAPI\r |
4cda7726 | 400 | SnpUndi32CallbackMap (\r |
5e7e4fad | 401 | IN UINT64 UniqueId,\r |
402 | IN UINT64 CpuAddr,\r | |
403 | IN UINT32 NumBytes,\r | |
404 | IN UINT32 Direction,\r | |
405 | IN OUT UINT64 DeviceAddrPtr\r | |
406 | )\r | |
5e7e4fad | 407 | {\r |
408 | EFI_PHYSICAL_ADDRESS *DevAddrPtr;\r | |
409 | EFI_PCI_IO_PROTOCOL_OPERATION DirectionFlag;\r | |
410 | UINTN BuffSize;\r | |
4cda7726 | 411 | SNP_DRIVER *Snp;\r |
5e7e4fad | 412 | UINTN Index;\r |
413 | EFI_STATUS Status;\r | |
414 | \r | |
415 | BuffSize = (UINTN) NumBytes;\r | |
4cda7726 | 416 | Snp = (SNP_DRIVER *) (UINTN) UniqueId;\r |
5e7e4fad | 417 | DevAddrPtr = (EFI_PHYSICAL_ADDRESS *) (UINTN) DeviceAddrPtr;\r |
418 | \r | |
419 | if (CpuAddr == 0) {\r | |
420 | *DevAddrPtr = 0;\r | |
421 | return ;\r | |
422 | }\r | |
423 | \r | |
424 | switch (Direction) {\r | |
425 | case TO_AND_FROM_DEVICE:\r | |
426 | DirectionFlag = EfiPciIoOperationBusMasterCommonBuffer;\r | |
427 | break;\r | |
428 | \r | |
429 | case FROM_DEVICE:\r | |
430 | DirectionFlag = EfiPciIoOperationBusMasterWrite;\r | |
431 | break;\r | |
432 | \r | |
433 | case TO_DEVICE:\r | |
434 | DirectionFlag = EfiPciIoOperationBusMasterRead;\r | |
435 | break;\r | |
436 | \r | |
437 | default:\r | |
438 | *DevAddrPtr = 0;\r | |
439 | //\r | |
440 | // any non zero indicates error!\r | |
441 | //\r | |
442 | return ;\r | |
443 | }\r | |
444 | //\r | |
445 | // find an unused map_list entry\r | |
446 | //\r | |
447 | for (Index = 0; Index < MAX_MAP_LENGTH; Index++) {\r | |
4cda7726 | 448 | if (Snp->MapList[Index].VirtualAddress == 0) {\r |
5e7e4fad | 449 | break;\r |
450 | }\r | |
451 | }\r | |
452 | \r | |
453 | if (Index >= MAX_MAP_LENGTH) {\r | |
454 | DEBUG ((EFI_D_INFO, "SNP maplist is FULL\n"));\r | |
455 | *DevAddrPtr = 0;\r | |
456 | return ;\r | |
457 | }\r | |
458 | \r | |
4cda7726 | 459 | Snp->MapList[Index].VirtualAddress = (EFI_PHYSICAL_ADDRESS) CpuAddr;\r |
5e7e4fad | 460 | \r |
4cda7726 | 461 | Status = Snp->PciIo->Map (\r |
462 | Snp->PciIo,\r | |
463 | DirectionFlag,\r | |
464 | (VOID *) (UINTN) CpuAddr,\r | |
465 | &BuffSize,\r | |
466 | DevAddrPtr,\r | |
467 | &(Snp->MapList[Index].MapCookie)\r | |
468 | );\r | |
5e7e4fad | 469 | if (Status != EFI_SUCCESS) {\r |
4cda7726 | 470 | *DevAddrPtr = 0;\r |
471 | Snp->MapList[Index].VirtualAddress = 0;\r | |
5e7e4fad | 472 | }\r |
473 | \r | |
474 | return ;\r | |
475 | }\r | |
476 | \r | |
4cda7726 | 477 | /**\r |
9c9f5859 | 478 | Unmap an address that was previously mapped using map callback.\r |
479 | \r | |
4cda7726 | 480 | This is a callback routine supplied to UNDI at undi_start time.\r |
4cda7726 | 481 | \r |
9c9f5859 | 482 | @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to\r |
f3816027 | 483 | store. Undi interface context (Undi does not read or write\r |
484 | this variable).\r | |
485 | @param CpuAddr Virtual address that was mapped.\r | |
486 | @param NumBytes Size of memory mapped.\r | |
9c9f5859 | 487 | @param Direction Direction of data flow for this memory's usage:\r |
f3816027 | 488 | cpu->device, device->cpu or both ways.\r |
489 | @param DeviceAddr The mapped device address.\r | |
4cda7726 | 490 | \r |
491 | **/\r | |
5e7e4fad | 492 | VOID\r |
9c9f5859 | 493 | EFIAPI\r |
4cda7726 | 494 | SnpUndi32CallbackUnmap (\r |
5e7e4fad | 495 | IN UINT64 UniqueId,\r |
496 | IN UINT64 CpuAddr,\r | |
497 | IN UINT32 NumBytes,\r | |
498 | IN UINT32 Direction,\r | |
499 | IN UINT64 DeviceAddr\r | |
500 | )\r | |
5e7e4fad | 501 | {\r |
4cda7726 | 502 | SNP_DRIVER *Snp;\r |
5e7e4fad | 503 | UINT16 Index;\r |
504 | \r | |
4cda7726 | 505 | Snp = (SNP_DRIVER *) (UINTN) UniqueId;\r |
5e7e4fad | 506 | \r |
507 | for (Index = 0; Index < MAX_MAP_LENGTH; Index++) {\r | |
4cda7726 | 508 | if (Snp->MapList[Index].VirtualAddress == CpuAddr) {\r |
5e7e4fad | 509 | break;\r |
510 | }\r | |
511 | }\r | |
512 | \r | |
f3816027 | 513 | if (Index >= MAX_MAP_LENGTH) {\r |
5e7e4fad | 514 | DEBUG ((EFI_D_ERROR, "SNP could not find a mapping, failed to unmap.\n"));\r |
515 | return ;\r | |
516 | }\r | |
517 | \r | |
4cda7726 | 518 | Snp->PciIo->Unmap (Snp->PciIo, Snp->MapList[Index].MapCookie);\r |
519 | Snp->MapList[Index].VirtualAddress = 0;\r | |
520 | Snp->MapList[Index].MapCookie = NULL;\r | |
5e7e4fad | 521 | return ;\r |
522 | }\r | |
523 | \r | |
9c9f5859 | 524 | /**\r |
525 | Synchronize the virtual buffer contents with the mapped buffer contents.\r | |
526 | \r | |
f3816027 | 527 | This is a callback routine supplied to UNDI at undi_start time. The virtual\r |
9c9f5859 | 528 | and mapped buffers need not correspond to the same physical memory (especially\r |
529 | if the virtual address is > 4GB). Depending on the direction for which the\r | |
530 | buffer is mapped, undi will need to synchronize their contents whenever it\r | |
531 | writes to/reads from the buffer using either the cpu address or the device\r | |
532 | address.\r | |
533 | EFI does not provide a sync call since virt=physical, we should just do the\r | |
534 | synchronization ourselves here.\r | |
535 | \r | |
536 | @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to\r | |
f3816027 | 537 | store Undi interface context (Undi does not read or write\r |
538 | this variable).\r | |
539 | @param CpuAddr Virtual address that was mapped.\r | |
540 | @param NumBytes Size of memory mapped.\r | |
541 | @param Direction Direction of data flow for this memory's usage:\r | |
4cda7726 | 542 | cpu->device, device->cpu or both ways.\r |
f3816027 | 543 | @param DeviceAddr The mapped device address.\r |
4cda7726 | 544 | \r |
545 | **/\r | |
5e7e4fad | 546 | VOID\r |
9c9f5859 | 547 | EFIAPI\r |
4cda7726 | 548 | SnpUndi32CallbackSync (\r |
549 | IN UINT64 UniqueId,\r | |
550 | IN UINT64 CpuAddr,\r | |
551 | IN UINT32 NumBytes,\r | |
552 | IN UINT32 Direction,\r | |
553 | IN UINT64 DeviceAddr\r | |
5e7e4fad | 554 | )\r |
5e7e4fad | 555 | {\r |
556 | if ((CpuAddr == 0) || (DeviceAddr == 0) || (NumBytes == 0)) {\r | |
557 | return ;\r | |
558 | \r | |
559 | }\r | |
560 | \r | |
561 | switch (Direction) {\r | |
562 | case FROM_DEVICE:\r | |
563 | CopyMem ((UINT8 *) (UINTN) CpuAddr, (UINT8 *) (UINTN) DeviceAddr, NumBytes);\r | |
564 | break;\r | |
565 | \r | |
566 | case TO_DEVICE:\r | |
567 | CopyMem ((UINT8 *) (UINTN) DeviceAddr, (UINT8 *) (UINTN) CpuAddr, NumBytes);\r | |
568 | break;\r | |
569 | }\r | |
570 | \r | |
571 | return ;\r | |
572 | }\r |