+++ /dev/null
-/** @file\r
- Device Abstraction: device creation utility functions.\r
-\r
- Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials are licensed and made available under\r
- the terms and conditions of the BSD License that accompanies this distribution.\r
- 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
-#include <Uefi.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-\r
-#include <LibConfig.h>\r
-\r
-#include <errno.h>\r
-#include <stdarg.h>\r
-#include <sys/poll.h>\r
-#include <kfile.h>\r
-#include <Device/Device.h>\r
-#include <MainData.h>\r
-\r
-LIST_ENTRY daDeviceList = INITIALIZE_LIST_HEAD_VARIABLE(daDeviceList);\r
-DeviceNode *daDefaultDevice = NULL; ///< Device to use if nothing else found\r
-DeviceNode *daRootDevice = NULL; ///< Device containing the root file system\r
-DeviceNode *daCurrentDevice = NULL; ///< Device currently being accessed\r
-\r
-/* Commonly used fileops\r
- fnullop_* Does nothing and returns success.\r
- fbadop_* Does nothing and returns EPERM\r
-*/\r
-int EFIAPI fnullop_fcntl (struct __filedes *filp, UINT32 Cmd, void *p3, void *p4)\r
-{ return 0; }\r
-\r
-short EFIAPI fnullop_poll (struct __filedes *filp, short Events)\r
-{\r
- return ((POLLIN | POLLRDNORM | POLLOUT) & Events);\r
-}\r
-\r
-int EFIAPI fnullop_flush (struct __filedes *filp)\r
-{ return 0; }\r
-\r
-int EFIAPI fbadop_stat (struct __filedes *filp, struct stat *StatBuf, void *Buf)\r
-{\r
- errno = EPERM;\r
- return -1;\r
-}\r
-\r
-int EFIAPI fbadop_ioctl (struct __filedes *filp, ULONGN Cmd, va_list argp)\r
-{\r
- errno = EPERM;\r
- return -1;\r
-}\r
-\r
-int EFIAPI fbadop_delete (struct __filedes *filp)\r
-{\r
- errno = EPERM;\r
- return -1;\r
-}\r
-\r
-int EFIAPI fbadop_mkdir (const char *path, __mode_t perms)\r
-{\r
- errno = EPERM;\r
- return -1;\r
-}\r
-\r
-int EFIAPI fbadop_rename (const char *from, const char *to)\r
-{\r
- errno = EPERM;\r
- return -1;\r
-}\r
-\r
-int EFIAPI fbadop_rmdir (struct __filedes *filp)\r
-{\r
- errno = EPERM;\r
- return -1;\r
-}\r
-\r
-/** Add a new device to the device list.\r
- If both DevName and DevProto are NULL, register this as the Default device.\r
-\r
- @param DevName Name of the device to add.\r
- @param DevProto Pointer to the GUID identifying the protocol associated with this device.\r
- If DevProto is NULL, startup code will not try to find instances\r
- of this device.\r
- @param OpenFunc Pointer to the device's Open function.\r
- @param InstanceList Optional pointer to the device's initialized instance list.\r
- If InstanceList is NULL, the application startup code will\r
- scan for instances of the protocol identified by DevProto and\r
- populate the InstanceList in the order those protocols are found.\r
- @param NumInstance Number of instances in InstanceList.\r
- @param Modes Bit-mapped flags indicating operations (R, W, RW, ...) permitted to this device.\r
-\r
-**/\r
-DeviceNode *\r
-EFIAPI\r
-__DevRegister(\r
- IN const CHAR16 *DevName,\r
- IN GUID *DevProto,\r
- IN FO_OPEN OpenFunc,\r
- IN void *InstanceList,\r
- IN int NumInstance,\r
- IN UINT32 InstanceSize,\r
- IN UINT32 Modes\r
- )\r
-{\r
- DeviceNode *Node;\r
- GenericInstance *GIp;\r
- char *GenPtr;\r
- int i;\r
-\r
- /* Validate parameters */\r
- if(((DevName == NULL) && (DevProto != NULL)) ||\r
- (OpenFunc == NULL)) {\r
- EFIerrno = RETURN_INVALID_PARAMETER;\r
- return NULL;\r
- }\r
- Node = (DeviceNode *)AllocateZeroPool(sizeof(DeviceNode));\r
- if(Node == NULL) {\r
- EFIerrno = RETURN_OUT_OF_RESOURCES;\r
- return NULL;\r
- }\r
-\r
- Node->DevName = DevName;\r
- Node->DevProto = DevProto;\r
- Node->InstanceList = InstanceList;\r
- Node->OpenFunc = OpenFunc;\r
- Node->InstanceSize = InstanceSize;\r
- Node->NumInstances = NumInstance;\r
- Node->OpModes = Modes;\r
-\r
- /* Update the Parent member of each element of the InstanceList */\r
- if(InstanceList != NULL) {\r
- GenPtr = InstanceList;\r
-\r
- for(i = 0; i < NumInstance; ++i) { // Iterate through each element of InstanceList\r
- GIp = (GenericInstance *)GenPtr;\r
- GIp->Parent = Node; // Initializing the Parent member & InstanceNum\r
- //GIp->InstanceNum = i;\r
- GenPtr += InstanceSize;\r
- }\r
- }\r
- if(DevName == NULL) {\r
- if(daDefaultDevice != NULL) {\r
- EFIerrno = RETURN_INVALID_PARAMETER;\r
- return NULL;\r
- }\r
- daDefaultDevice = Node;\r
- }\r
- else {\r
- (void) InsertTailList(&daDeviceList, &Node->DevList);\r
- }\r
- EFIerrno = RETURN_SUCCESS;\r
- return Node;\r
-}\r