/*++\r
-Copyright (c) 2006, Intel Corporation \r
-All rights reserved. This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
- \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
\r
Module name:\r
snp.c\r
\r
#include "Snp.h"\r
\r
-EFI_STATUS\r
-pxe_start (\r
- SNP_DRIVER *snp\r
- );\r
-EFI_STATUS\r
-pxe_stop (\r
- SNP_DRIVER *snp\r
- );\r
-EFI_STATUS\r
-pxe_init (\r
- SNP_DRIVER *snp,\r
- UINT16 OpFlags\r
- );\r
-EFI_STATUS\r
-pxe_shutdown (\r
- SNP_DRIVER *snp\r
- );\r
-EFI_STATUS\r
-pxe_get_stn_addr (\r
- SNP_DRIVER *snp\r
- );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-InitializeSnpNiiDriver (\r
- IN EFI_HANDLE image_handle,\r
- IN EFI_SYSTEM_TABLE *system_table\r
- );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-SimpleNetworkDriverSupported (\r
- IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
- IN EFI_HANDLE Controller,\r
- IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
- );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-SimpleNetworkDriverStart (\r
- IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
- IN EFI_HANDLE Controller,\r
- IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
- );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-SimpleNetworkDriverStop (\r
- IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
- IN EFI_HANDLE Controller,\r
- IN UINTN NumberOfChildren,\r
- IN EFI_HANDLE *ChildHandleBuffer\r
- );\r
-\r
-//\r
-// Simple Network Protocol Driver Global Variables\r
-//\r
-EFI_DRIVER_BINDING_PROTOCOL mSimpleNetworkDriverBinding = {\r
- SimpleNetworkDriverSupported,\r
- SimpleNetworkDriverStart,\r
- SimpleNetworkDriverStop,\r
- 0x10,\r
- NULL,\r
- NULL\r
-};\r
-\r
//\r
// Module global variables needed to support undi 3.0 interface\r
//\r
struct s_v2p *_v2p = NULL; // undi3.0 map_list head\r
// End Global variables\r
//\r
-EFI_STATUS\r
-add_v2p (\r
- IN OUT struct s_v2p **v2p,\r
- EFI_PCI_IO_PROTOCOL_OPERATION type,\r
- VOID *vaddr,\r
- UINTN bsize\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine maps the given CPU address to a Device address. It creates a\r
- an entry in the map list with the virtual and physical addresses and the \r
- un map cookie.\r
-\r
-Arguments:\r
- v2p - pointer to return a map list node pointer.\r
- type - the direction in which the data flows from the given virtual address\r
- device->cpu or cpu->device or both ways.\r
- vaddr - virtual address (or CPU address) to be mapped\r
- bsize - size of the buffer to be mapped.\r
-\r
-Returns:\r
-\r
- EFI_SUCEESS - routine has completed the mapping\r
- other - error as indicated.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
-\r
- if ((v2p == NULL) || (vaddr == NULL) || (bsize == 0)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = gBS->AllocatePool (\r
- EfiBootServicesData,\r
- sizeof (struct s_v2p),\r
- (VOID **) v2p\r
- );\r
-\r
- if (Status != EFI_SUCCESS) {\r
- return Status;\r
- }\r
-\r
- Status = mPciIoFncs->Map (\r
- mPciIoFncs,\r
- type,\r
- vaddr,\r
- &bsize,\r
- &(*v2p)->paddr,\r
- &(*v2p)->unmap\r
- );\r
- if (Status != EFI_SUCCESS) {\r
- gBS->FreePool (*v2p);\r
- return Status;\r
- }\r
- (*v2p)->vaddr = vaddr;\r
- (*v2p)->bsize = bsize;\r
- (*v2p)->next = _v2p;\r
- _v2p = *v2p;\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-find_v2p (\r
- struct s_v2p **v2p,\r
- VOID *vaddr\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine searches the linked list of mapped address nodes (for undi3.0 \r
- interface) to find the node that corresponds to the given virtual address and\r
- returns a pointer to that node.\r
-\r
-Arguments:\r
- v2p - pointer to return a map list node pointer.\r
- vaddr - virtual address (or CPU address) to be searched in the map list\r
-\r
-Returns:\r
-\r
- EFI_SUCEESS - if a match found!\r
- Other - match not found\r
-\r
---*/\r
-{\r
- struct s_v2p *v;\r
-\r
- if (v2p == NULL || vaddr == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- for (v = _v2p; v != NULL; v = v->next) {\r
- if (v->vaddr == vaddr) {\r
- *v2p = v;\r
- return EFI_SUCCESS;\r
- }\r
- }\r
-\r
- return EFI_NOT_FOUND;\r
-}\r
-\r
-EFI_STATUS\r
-del_v2p (\r
- VOID *vaddr\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine unmaps the given virtual address and frees the memory allocated \r
- for the map list node corresponding to that address.\r
- \r
-Arguments:\r
- vaddr - virtual address (or CPU address) to be unmapped\r
-\r
-Returns:\r
- EFI_SUCEESS - if successfully unmapped\r
- Other - as indicated by the error\r
-\r
-\r
---*/\r
-{\r
- struct s_v2p *v;\r
- struct s_v2p *t;\r
- EFI_STATUS Status;\r
-\r
- if (vaddr == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (_v2p == NULL) {\r
- return EFI_NOT_FOUND;\r
- }\r
- //\r
- // Is our node at the head of the list??\r
- //\r
- if ((v = _v2p)->vaddr == vaddr) {\r
- _v2p = _v2p->next;\r
-\r
- Status = mPciIoFncs->Unmap (mPciIoFncs, v->unmap);\r
-\r
- gBS->FreePool (v);\r
-\r
-#if SNP_DEBUG\r
- if (Status) {\r
- Print (L"Unmap failed with status = %x\n", Status);\r
- }\r
-#endif\r
- return Status;\r
- }\r
-\r
- for (; v->next != NULL; v = t) {\r
- if ((t = v->next)->vaddr == vaddr) {\r
- v->next = t->next;\r
- Status = mPciIoFncs->Unmap (mPciIoFncs, t->unmap);\r
- gBS->FreePool (t);\r
-#if SNP_DEBUG\r
- if (Status) {\r
- Print (L"Unmap failed with status = %x\n", Status);\r
- }\r
-#endif\r
- return Status;\r
- }\r
- }\r
-\r
- return EFI_NOT_FOUND;\r
-}\r
-\r
-#if SNP_DEBUG\r
-VOID\r
-snp_wait_for_key (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Wait for a key stroke, used for debugging purposes\r
-\r
-Arguments:\r
- none\r
-\r
-Returns:\r
- none\r
-\r
---*/\r
-{\r
- EFI_INPUT_KEY key;\r
-\r
- Aprint ("\nPress any key to continue\n");\r
-\r
- while (gST->ConIn->ReadKeyStroke (gST->ConIn, &key) == EFI_NOT_READY) {\r
- ;\r
- }\r
-}\r
-#endif\r
\r
STATIC\r
EFI_STATUS\r
\r
--*/\r
{\r
-#if SNP_DEBUG\r
- Aprint ("\nissue_hwundi_command() - This should not be called!");\r
- snp_wait_for_key ();\r
-#endif\r
+ DEBUG ((EFI_D_ERROR, "\nissue_hwundi_command() - This should not be called!"));\r
+\r
if (cdb == 0) {\r
return EFI_INVALID_PARAMETER;\r
\r
\r
Routine Description:\r
Compute 8-bit checksum of a buffer.\r
- \r
+\r
Arguments:\r
ptr - Pointer to buffer.\r
len - Length of buffer in bytes.\r
return cksum;\r
}\r
\r
+STATIC\r
EFI_STATUS\r
EFIAPI\r
SimpleNetworkDriverSupported (\r
);\r
if (Status == EFI_ALREADY_STARTED)\r
{\r
-#if SNP_DEBUG\r
- Aprint ("Support(): Already Started. on handle %x\n", Controller);\r
-#endif\r
+ DEBUG ((EFI_D_INFO, "Support(): Already Started. on handle %x\n", Controller));\r
return EFI_ALREADY_STARTED;\r
}\r
\r
if (!EFI_ERROR (Status))\r
{\r
-\r
-#if SNP_DEBUG\r
- Aprint ("Support(): UNDI3.1 found on handle %x\n", Controller);\r
- snp_wait_for_key ();\r
-#endif\r
+ DEBUG ((EFI_D_INFO, "Support(): UNDI3.1 found on handle %x\n", Controller));\r
IsUndi31 = TRUE;\r
} else {\r
//\r
return Status;\r
}\r
\r
-#if SNP_DEBUG\r
- Aprint ("Support(): UNDI3.0 found on handle %x\n", Controller);\r
- snp_wait_for_key ();\r
-#endif\r
+ DEBUG ((EFI_D_INFO, "Support(): UNDI3.0 found on handle %x\n", Controller));\r
}\r
//\r
// check the version, we don't want to connect to the undi16\r
}\r
\r
Status = EFI_SUCCESS;\r
-#if SNP_DEBUG\r
- Aprint ("Support(): supported on %x\n", Controller);\r
- snp_wait_for_key ();\r
-#endif\r
+ DEBUG ((EFI_D_INFO, "Support(): supported on %x\n", Controller));\r
\r
Done:\r
if (IsUndi31) {\r
return Status;\r
}\r
\r
+STATIC\r
EFI_STATUS\r
EFIAPI\r
SimpleNetworkDriverStart (\r
// probably not a 3.1 UNDI\r
//\r
UndiNew = TRUE;\r
-#if SNP_DEBUG\r
- Aprint ("Start(): UNDI3.1 found\n");\r
- snp_wait_for_key ();\r
-#endif\r
+ DEBUG ((EFI_D_INFO, "Start(): UNDI3.1 found\n"));\r
+\r
} else {\r
UndiNew = FALSE;\r
Status = gBS->OpenProtocol (\r
return Status;\r
}\r
\r
-#if SNP_DEBUG\r
- Aprint ("Start(): UNDI3.0 found\n");\r
- snp_wait_for_key ();\r
-#endif\r
+ DEBUG ((EFI_D_INFO, "Start(): UNDI3.0 found\n"));\r
}\r
\r
pxe = (PXE_UNDI *) (UINTN) (Nii->ID);\r
return Status;\r
}\r
\r
+STATIC\r
EFI_STATUS\r
EFIAPI\r
SimpleNetworkDriverStop (\r
Controller\r
);\r
}\r
- \r
+\r
Status = gBS->CloseProtocol (\r
Controller,\r
&gEfiDevicePathProtocolGuid,\r
return Status;\r
}\r
\r
+//\r
+// Simple Network Protocol Driver Global Variables\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL mSimpleNetworkDriverBinding = {\r
+ SimpleNetworkDriverSupported,\r
+ SimpleNetworkDriverStart,\r
+ SimpleNetworkDriverStop,\r
+ 0xa,\r
+ NULL,\r
+ NULL\r
+};\r
+\r
+EFI_STATUS\r
+add_v2p (\r
+ IN OUT struct s_v2p **v2p,\r
+ EFI_PCI_IO_PROTOCOL_OPERATION type,\r
+ VOID *vaddr,\r
+ UINTN bsize\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ This routine maps the given CPU address to a Device address. It creates a\r
+ an entry in the map list with the virtual and physical addresses and the\r
+ un map cookie.\r
+\r
+Arguments:\r
+ v2p - pointer to return a map list node pointer.\r
+ type - the direction in which the data flows from the given virtual address\r
+ device->cpu or cpu->device or both ways.\r
+ vaddr - virtual address (or CPU address) to be mapped\r
+ bsize - size of the buffer to be mapped.\r
+\r
+Returns:\r
+\r
+ EFI_SUCEESS - routine has completed the mapping\r
+ other - error as indicated.\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ if ((v2p == NULL) || (vaddr == NULL) || (bsize == 0)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Status = gBS->AllocatePool (\r
+ EfiBootServicesData,\r
+ sizeof (struct s_v2p),\r
+ (VOID **) v2p\r
+ );\r
+\r
+ if (Status != EFI_SUCCESS) {\r
+ return Status;\r
+ }\r
+\r
+ Status = mPciIoFncs->Map (\r
+ mPciIoFncs,\r
+ type,\r
+ vaddr,\r
+ &bsize,\r
+ &(*v2p)->paddr,\r
+ &(*v2p)->unmap\r
+ );\r
+ if (Status != EFI_SUCCESS) {\r
+ gBS->FreePool (*v2p);\r
+ return Status;\r
+ }\r
+ (*v2p)->vaddr = vaddr;\r
+ (*v2p)->bsize = bsize;\r
+ (*v2p)->next = _v2p;\r
+ _v2p = *v2p;\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+find_v2p (\r
+ struct s_v2p **v2p,\r
+ VOID *vaddr\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ This routine searches the linked list of mapped address nodes (for undi3.0\r
+ interface) to find the node that corresponds to the given virtual address and\r
+ returns a pointer to that node.\r
+\r
+Arguments:\r
+ v2p - pointer to return a map list node pointer.\r
+ vaddr - virtual address (or CPU address) to be searched in the map list\r
+\r
+Returns:\r
+\r
+ EFI_SUCEESS - if a match found!\r
+ Other - match not found\r
+\r
+--*/\r
+{\r
+ struct s_v2p *v;\r
+\r
+ if (v2p == NULL || vaddr == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ for (v = _v2p; v != NULL; v = v->next) {\r
+ if (v->vaddr == vaddr) {\r
+ *v2p = v;\r
+ return EFI_SUCCESS;\r
+ }\r
+ }\r
+\r
+ return EFI_NOT_FOUND;\r
+}\r
+\r
+EFI_STATUS\r
+del_v2p (\r
+ VOID *vaddr\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ This routine unmaps the given virtual address and frees the memory allocated\r
+ for the map list node corresponding to that address.\r
+\r
+Arguments:\r
+ vaddr - virtual address (or CPU address) to be unmapped\r
+\r
+Returns:\r
+ EFI_SUCEESS - if successfully unmapped\r
+ Other - as indicated by the error\r
+\r
+\r
+--*/\r
+{\r
+ struct s_v2p *v;\r
+ struct s_v2p *t;\r
+ EFI_STATUS Status;\r
+\r
+ if (vaddr == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ if (_v2p == NULL) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ //\r
+ // Is our node at the head of the list??\r
+ //\r
+ if ((v = _v2p)->vaddr == vaddr) {\r
+ _v2p = _v2p->next;\r
+\r
+ Status = mPciIoFncs->Unmap (mPciIoFncs, v->unmap);\r
+\r
+ gBS->FreePool (v);\r
+\r
+ if (Status) {\r
+ DEBUG ((EFI_D_ERROR, "Unmap failed with status = %x\n", Status));\r
+ }\r
+ return Status;\r
+ }\r
+\r
+ for (; v->next != NULL; v = t) {\r
+ if ((t = v->next)->vaddr == vaddr) {\r
+ v->next = t->next;\r
+ Status = mPciIoFncs->Unmap (mPciIoFncs, t->unmap);\r
+ gBS->FreePool (t);\r
+\r
+ if (Status) {\r
+ DEBUG ((EFI_D_ERROR, "Unmap failed with status = %x\n", Status));\r
+ }\r
+ return Status;\r
+ }\r
+ }\r
+\r
+ return EFI_NOT_FOUND;\r
+}\r