2 This file contains the callback routines for undi3.1.
3 the callback routines for Undi3.1 have an extra parameter UniqueId which
4 stores the interface context for the NIC that snp is trying to talk.
6 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
14 Acquire or release a lock of the exclusive access to a critical section of the
17 This is a callback routine supplied to UNDI3.1 at undi_start time.
18 New callbacks for 3.1: there won't be a virtual2physical callback for UNDI 3.1
19 because undi3.1 uses the MemMap call to map the required address by itself!
21 @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to
22 store Undi interface context (Undi does not read or write
24 @param Enable Non-zero indicates acquire; Zero indicates release.
29 SnpUndi32CallbackBlock (
36 Snp
= (SNP_DRIVER
*) (UINTN
) UniqueId
;
38 // tcpip was calling snp at tpl_notify and when we acquire a lock that was
39 // created at a lower level (TPL_CALLBACK) it gives an assert!
42 EfiAcquireLock (&Snp
->Lock
);
44 EfiReleaseLock (&Snp
->Lock
);
49 Delay MicroSeconds of micro seconds.
51 This is a callback routine supplied to UNDI at undi_start time.
53 @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to
54 store Undi interface context (Undi does not read or write
56 @param MicroSeconds Number of micro seconds to pause, usually multiple of 10.
61 SnpUndi32CallbackDelay (
63 IN UINT64 MicroSeconds
66 if (MicroSeconds
!= 0) {
67 gBS
->Stall ((UINTN
) MicroSeconds
);
72 IO routine for UNDI3.1.
74 This is a callback routine supplied to UNDI at undi_start time.
76 @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this
77 to store Undi interface context (Undi does not read or
79 @param ReadOrWrite Indicates read or write, IO or Memory.
80 @param NumBytes Number of bytes to read or write.
81 @param MemOrPortAddr IO or memory address to read from or write to.
82 @param BufferPtr Memory location to read into or that contains the bytes
88 SnpUndi32CallbackMemio (
92 IN UINT64 MemOrPortAddr
,
93 IN OUT UINT64 BufferPtr
97 EFI_PCI_IO_PROTOCOL_WIDTH Width
;
99 Snp
= (SNP_DRIVER
*) (UINTN
) UniqueId
;
101 Width
= (EFI_PCI_IO_PROTOCOL_WIDTH
) 0;
104 Width
= (EFI_PCI_IO_PROTOCOL_WIDTH
) 1;
108 Width
= (EFI_PCI_IO_PROTOCOL_WIDTH
) 2;
112 Width
= (EFI_PCI_IO_PROTOCOL_WIDTH
) 3;
116 switch (ReadOrWrite
) {
118 Snp
->PciIo
->Io
.Read (
121 Snp
->IoBarIndex
, // BAR 1 (for 32bit regs), IO base address
124 (VOID
*) (UINTN
) BufferPtr
129 Snp
->PciIo
->Io
.Write (
132 Snp
->IoBarIndex
, // BAR 1 (for 32bit regs), IO base address
135 (VOID
*) (UINTN
) BufferPtr
140 Snp
->PciIo
->Mem
.Read (
143 Snp
->MemoryBarIndex
, // BAR 0, Memory base address
146 (VOID
*) (UINTN
) BufferPtr
151 Snp
->PciIo
->Mem
.Write (
154 Snp
->MemoryBarIndex
, // BAR 0, Memory base address
157 (VOID
*) (UINTN
) BufferPtr
166 Map a CPU address to a device address.
168 This is a callback routine supplied to UNDI at undi_start time.
170 @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to
171 store Undi interface context (Undi does not read or write
173 @param CpuAddr Virtual address to be mapped.
174 @param NumBytes Size of memory to be mapped.
175 @param Direction Direction of data flow for this memory's usage:
176 cpu->device, device->cpu or both ways.
177 @param DeviceAddrPtr Pointer to return the mapped device address.
182 SnpUndi32CallbackMap (
187 IN OUT UINT64 DeviceAddrPtr
190 EFI_PHYSICAL_ADDRESS
*DevAddrPtr
;
191 EFI_PCI_IO_PROTOCOL_OPERATION DirectionFlag
;
197 BuffSize
= (UINTN
) NumBytes
;
198 Snp
= (SNP_DRIVER
*) (UINTN
) UniqueId
;
199 DevAddrPtr
= (EFI_PHYSICAL_ADDRESS
*) (UINTN
) DeviceAddrPtr
;
207 case TO_AND_FROM_DEVICE
:
208 DirectionFlag
= EfiPciIoOperationBusMasterCommonBuffer
;
212 DirectionFlag
= EfiPciIoOperationBusMasterWrite
;
216 DirectionFlag
= EfiPciIoOperationBusMasterRead
;
222 // any non zero indicates error!
227 // find an unused map_list entry
229 for (Index
= 0; Index
< MAX_MAP_LENGTH
; Index
++) {
230 if (Snp
->MapList
[Index
].VirtualAddress
== 0) {
235 if (Index
>= MAX_MAP_LENGTH
) {
236 DEBUG ((EFI_D_INFO
, "SNP maplist is FULL\n"));
241 Snp
->MapList
[Index
].VirtualAddress
= (EFI_PHYSICAL_ADDRESS
) CpuAddr
;
243 Status
= Snp
->PciIo
->Map (
246 (VOID
*) (UINTN
) CpuAddr
,
249 &(Snp
->MapList
[Index
].MapCookie
)
251 if (Status
!= EFI_SUCCESS
) {
253 Snp
->MapList
[Index
].VirtualAddress
= 0;
260 Unmap an address that was previously mapped using map callback.
262 This is a callback routine supplied to UNDI at undi_start time.
264 @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to
265 store. Undi interface context (Undi does not read or write
267 @param CpuAddr Virtual address that was mapped.
268 @param NumBytes Size of memory mapped.
269 @param Direction Direction of data flow for this memory's usage:
270 cpu->device, device->cpu or both ways.
271 @param DeviceAddr The mapped device address.
276 SnpUndi32CallbackUnmap (
287 Snp
= (SNP_DRIVER
*) (UINTN
) UniqueId
;
289 for (Index
= 0; Index
< MAX_MAP_LENGTH
; Index
++) {
290 if (Snp
->MapList
[Index
].VirtualAddress
== CpuAddr
) {
295 if (Index
>= MAX_MAP_LENGTH
) {
296 DEBUG ((EFI_D_ERROR
, "SNP could not find a mapping, failed to unmap.\n"));
300 Snp
->PciIo
->Unmap (Snp
->PciIo
, Snp
->MapList
[Index
].MapCookie
);
301 Snp
->MapList
[Index
].VirtualAddress
= 0;
302 Snp
->MapList
[Index
].MapCookie
= NULL
;
307 Synchronize the virtual buffer contents with the mapped buffer contents.
309 This is a callback routine supplied to UNDI at undi_start time. The virtual
310 and mapped buffers need not correspond to the same physical memory (especially
311 if the virtual address is > 4GB). Depending on the direction for which the
312 buffer is mapped, undi will need to synchronize their contents whenever it
313 writes to/reads from the buffer using either the cpu address or the device
315 EFI does not provide a sync call since virt=physical, we should just do the
316 synchronization ourselves here.
318 @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to
319 store Undi interface context (Undi does not read or write
321 @param CpuAddr Virtual address that was mapped.
322 @param NumBytes Size of memory mapped.
323 @param Direction Direction of data flow for this memory's usage:
324 cpu->device, device->cpu or both ways.
325 @param DeviceAddr The mapped device address.
330 SnpUndi32CallbackSync (
338 if ((CpuAddr
== 0) || (DeviceAddr
== 0) || (NumBytes
== 0)) {
345 CopyMem ((UINT8
*) (UINTN
) CpuAddr
, (UINT8
*) (UINTN
) DeviceAddr
, NumBytes
);
349 CopyMem ((UINT8
*) (UINTN
) DeviceAddr
, (UINT8
*) (UINTN
) CpuAddr
, NumBytes
);