]>
Commit | Line | Data |
---|---|---|
9060e3ec | 1 | /** @file\r |
2 | Functions implementation for Bus Specific Driver Override protoocl.\r | |
3 | \r | |
cd5ebaa0 HT |
4 | Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r |
5 | This program and the accompanying materials\r | |
9060e3ec | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "PciBus.h"\r | |
16 | \r | |
17 | /**\r | |
18 | Initializes a PCI Driver Override Instance.\r | |
19 | \r | |
20 | @param PciIoDevice PCI Device instance.\r | |
21 | \r | |
22 | **/\r | |
23 | VOID\r | |
24 | InitializePciDriverOverrideInstance (\r | |
25 | IN OUT PCI_IO_DEVICE *PciIoDevice\r | |
26 | )\r | |
27 | {\r | |
28 | PciIoDevice->PciDriverOverride.GetDriver = GetDriver;\r | |
29 | }\r | |
30 | \r | |
31 | \r | |
32 | /**\r | |
33 | Uses a bus specific algorithm to retrieve a driver image handle for a controller.\r | |
34 | \r | |
35 | @param This A pointer to the EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL instance.\r | |
36 | @param DriverImageHandle On input, a pointer to the previous driver image handle returned\r | |
37 | by GetDriver(). On output, a pointer to the next driver\r | |
38 | image handle. Passing in a NULL, will return the first driver\r | |
39 | image handle.\r | |
40 | \r | |
41 | @retval EFI_SUCCESS A bus specific override driver is returned in DriverImageHandle.\r | |
42 | @retval EFI_NOT_FOUND The end of the list of override drivers was reached.\r | |
43 | A bus specific override driver is not returned in DriverImageHandle.\r | |
44 | @retval EFI_INVALID_PARAMETER DriverImageHandle is not a handle that was returned on a\r | |
45 | previous call to GetDriver().\r | |
46 | \r | |
47 | **/\r | |
48 | EFI_STATUS\r | |
49 | EFIAPI\r | |
50 | GetDriver (\r | |
51 | IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *This,\r | |
52 | IN OUT EFI_HANDLE *DriverImageHandle\r | |
53 | )\r | |
54 | {\r | |
55 | PCI_IO_DEVICE *PciIoDevice;\r | |
56 | LIST_ENTRY *CurrentLink;\r | |
57 | PCI_DRIVER_OVERRIDE_LIST *Node;\r | |
58 | \r | |
59 | PciIoDevice = PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This);\r | |
60 | \r | |
61 | CurrentLink = PciIoDevice->OptionRomDriverList.ForwardLink;\r | |
62 | \r | |
63 | while (CurrentLink != NULL && CurrentLink != &PciIoDevice->OptionRomDriverList) {\r | |
64 | \r | |
65 | Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink);\r | |
66 | \r | |
67 | if (*DriverImageHandle == NULL) {\r | |
68 | \r | |
69 | *DriverImageHandle = Node->DriverImageHandle;\r | |
70 | return EFI_SUCCESS;\r | |
71 | }\r | |
72 | \r | |
73 | if (*DriverImageHandle == Node->DriverImageHandle) {\r | |
74 | \r | |
75 | if (CurrentLink->ForwardLink == &PciIoDevice->OptionRomDriverList ||\r | |
76 | CurrentLink->ForwardLink == NULL) {\r | |
77 | return EFI_NOT_FOUND;\r | |
78 | }\r | |
79 | \r | |
80 | //\r | |
81 | // Get next node\r | |
82 | //\r | |
83 | Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink->ForwardLink);\r | |
84 | *DriverImageHandle = Node->DriverImageHandle;\r | |
85 | return EFI_SUCCESS;\r | |
86 | }\r | |
87 | \r | |
88 | CurrentLink = CurrentLink->ForwardLink;\r | |
89 | }\r | |
90 | \r | |
91 | return EFI_INVALID_PARAMETER;\r | |
92 | }\r | |
93 | \r | |
94 | /**\r | |
95 | Add an overriding driver image.\r | |
96 | \r | |
97 | @param PciIoDevice Instance of PciIo device.\r | |
98 | @param DriverImageHandle new added driver image.\r | |
99 | \r | |
100 | @retval EFI_SUCCESS Successfully added driver.\r | |
101 | @retval EFI_OUT_OF_RESOURCES No memory resource for new driver instance.\r | |
102 | @retval other Some error occurred when locating gEfiLoadedImageProtocolGuid.\r | |
103 | \r | |
104 | **/\r | |
105 | EFI_STATUS\r | |
106 | AddDriver (\r | |
107 | IN PCI_IO_DEVICE *PciIoDevice,\r | |
108 | IN EFI_HANDLE DriverImageHandle\r | |
109 | )\r | |
110 | {\r | |
111 | EFI_STATUS Status;\r | |
112 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r | |
113 | PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;\r | |
114 | PCI_DRIVER_OVERRIDE_LIST *Node;\r | |
115 | \r | |
116 | Status = gBS->HandleProtocol (DriverImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);\r | |
117 | if (EFI_ERROR (Status)) {\r | |
118 | return Status;\r | |
119 | }\r | |
120 | \r | |
121 | Node = AllocatePool (sizeof (PCI_DRIVER_OVERRIDE_LIST));\r | |
122 | if (Node == NULL) {\r | |
123 | return EFI_OUT_OF_RESOURCES;\r | |
124 | }\r | |
125 | \r | |
126 | Node->Signature = DRIVER_OVERRIDE_SIGNATURE;\r | |
127 | Node->DriverImageHandle = DriverImageHandle;\r | |
128 | \r | |
129 | InsertTailList (&PciIoDevice->OptionRomDriverList, &(Node->Link));\r | |
130 | \r | |
131 | PciIoDevice->BusOverride = TRUE;\r | |
132 | \r | |
133 | ImageContext.Handle = LoadedImage->ImageBase;\r | |
134 | ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;\r | |
135 | \r | |
136 | //\r | |
137 | // Get information about the image\r | |
138 | //\r | |
139 | PeCoffLoaderGetImageInfo (&ImageContext);\r | |
140 | \r | |
141 | return EFI_SUCCESS;\r | |
142 | }\r | |
143 | \r |