]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/LibC/Uefi/Devices/Utility/DevGenisis.c
2 Device Abstraction: device creation utility functions.
4 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #include <Library/BaseLib.h>
15 #include <Library/MemoryAllocationLib.h>
17 #include <LibConfig.h>
22 #include <Device/Device.h>
25 LIST_ENTRY daDeviceList
= INITIALIZE_LIST_HEAD_VARIABLE(daDeviceList
);
26 DeviceNode
*daDefaultDevice
= NULL
; ///< Device to use if nothing else found
27 DeviceNode
*daRootDevice
= NULL
; ///< Device containing the root file system
28 DeviceNode
*daCurrentDevice
= NULL
; ///< Device currently being accessed
30 /* Commonly used fileops
31 fnullop_* Does nothing and returns success.
32 fbadop_* Does nothing and returns EPERM
34 int EFIAPI
fnullop_fcntl (struct __filedes
*filp
, UINT32 Cmd
, void *p3
, void *p4
)
37 short EFIAPI
fnullop_poll (struct __filedes
*filp
, short Events
)
39 return ((POLLIN
| POLLRDNORM
| POLLOUT
) & Events
);
42 int EFIAPI
fnullop_flush (struct __filedes
*filp
)
45 int EFIAPI
fbadop_stat (struct __filedes
*filp
, struct stat
*StatBuf
, void *Buf
)
48 int EFIAPI
fbadop_ioctl (struct __filedes
*filp
, ULONGN Cmd
, void *argp
)
51 int EFIAPI
fbadop_delete (struct __filedes
*filp
)
54 int EFIAPI
fbadop_mkdir (const char *path
, __mode_t perms
)
57 int EFIAPI
fbadop_rename (const char *from
, const char *to
)
60 int EFIAPI
fbadop_rmdir (struct __filedes
*filp
)
63 /** Add a new device to the device list.
64 If both DevName and DevProto are NULL, register this as the Default device.
66 @param DevName Name of the device to add.
67 @param DevProto Pointer to the GUID identifying the protocol associated with this device.
68 If DevProto is NULL, startup code will not try to find instances
70 @param OpenFunc Pointer to the device's Open function.
71 @param InstanceList Optional pointer to the device's initialized instance list.
72 If InstanceList is NULL, the application startup code will
73 scan for instances of the protocol identified by DevProto and
74 populate the InstanceList in the order those protocols are found.
75 @param NumInstance Number of instances in InstanceList.
76 @param Modes Bit-mapped flags indicating operations (R, W, RW, ...) permitted to this device.
82 IN
const CHAR16
*DevName
,
85 IN
void *InstanceList
,
87 IN UINT32 InstanceSize
,
96 /* Validate parameters */
97 if(((DevName
== NULL
) && (DevProto
!= NULL
)) ||
99 EFIerrno
= RETURN_INVALID_PARAMETER
;
102 Node
= (DeviceNode
*)AllocateZeroPool(sizeof(DeviceNode
));
104 EFIerrno
= RETURN_OUT_OF_RESOURCES
;
108 Node
->DevName
= DevName
;
109 Node
->DevProto
= DevProto
;
110 Node
->InstanceList
= InstanceList
;
111 Node
->OpenFunc
= OpenFunc
;
112 Node
->InstanceSize
= InstanceSize
;
113 Node
->NumInstances
= NumInstance
;
114 Node
->OpModes
= Modes
;
116 /* Update the Parent member of each element of the InstanceList */
117 if(InstanceList
!= NULL
) {
118 GenPtr
= InstanceList
;
120 for(i
= 0; i
< NumInstance
; ++i
) { // Iterate through each element of InstanceList
121 GIp
= (GenericInstance
*)GenPtr
;
122 GIp
->Parent
= Node
; // Initializing the Parent member & InstanceNum
123 //GIp->InstanceNum = i;
124 GenPtr
+= InstanceSize
;
127 if(DevName
== NULL
) {
128 if(daDefaultDevice
!= NULL
) {
129 EFIerrno
= RETURN_INVALID_PARAMETER
;
132 daDefaultDevice
= Node
;
135 (void) InsertTailList(&daDeviceList
, &Node
->DevList
);
137 EFIerrno
= RETURN_SUCCESS
;