]>
Commit | Line | Data |
---|---|---|
3db51098 | 1 | /**@file\r |
ead42efc | 2 | \r |
3db51098 | 3 | Copyright (c) 2006, Intel Corporation \r |
4 | All rights reserved. This program and the accompanying materials \r | |
5 | are licensed and made available under the terms and conditions of the BSD License \r | |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
ead42efc | 11 | \r |
3db51098 | 12 | **/\r |
ead42efc | 13 | \r |
ead42efc | 14 | \r |
15 | #include "pcibus.h"\r | |
16 | \r | |
17 | EFI_STATUS\r | |
18 | PciOperateRegister (\r | |
19 | IN PCI_IO_DEVICE *PciIoDevice,\r | |
20 | IN UINT16 Command,\r | |
21 | IN UINT8 Offset,\r | |
22 | IN UINT8 Operation,\r | |
23 | OUT UINT16 *PtrCommand\r | |
24 | )\r | |
bcd70414 | 25 | /**\r |
ead42efc | 26 | \r |
27 | Routine Description:\r | |
28 | \r | |
29 | Arguments:\r | |
30 | \r | |
31 | Returns:\r | |
32 | \r | |
33 | None\r | |
34 | \r | |
bcd70414 | 35 | **/\r |
ead42efc | 36 | // TODO: PciIoDevice - add argument and description to function comment\r |
37 | // TODO: Command - add argument and description to function comment\r | |
38 | // TODO: Offset - add argument and description to function comment\r | |
39 | // TODO: Operation - add argument and description to function comment\r | |
40 | // TODO: PtrCommand - add argument and description to function comment\r | |
41 | {\r | |
42 | UINT16 OldCommand;\r | |
43 | EFI_STATUS Status;\r | |
44 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
45 | \r | |
46 | OldCommand = 0;\r | |
47 | PciIo = &PciIoDevice->PciIo;\r | |
48 | \r | |
49 | if (Operation != EFI_SET_REGISTER) {\r | |
50 | Status = PciIoRead (\r | |
51 | PciIo,\r | |
52 | EfiPciIoWidthUint16,\r | |
53 | Offset,\r | |
54 | 1,\r | |
55 | &OldCommand\r | |
56 | );\r | |
57 | \r | |
58 | if (Operation == EFI_GET_REGISTER) {\r | |
59 | *PtrCommand = OldCommand;\r | |
60 | return Status;\r | |
61 | }\r | |
62 | }\r | |
63 | \r | |
64 | if (Operation == EFI_ENABLE_REGISTER) {\r | |
65 | OldCommand = (UINT16) (OldCommand | Command);\r | |
66 | } else if (Operation == EFI_DISABLE_REGISTER) {\r | |
67 | OldCommand = (UINT16) (OldCommand & ~(Command));\r | |
68 | } else {\r | |
69 | OldCommand = Command;\r | |
70 | }\r | |
71 | \r | |
72 | return PciIoWrite (\r | |
73 | PciIo,\r | |
74 | EfiPciIoWidthUint16,\r | |
75 | Offset,\r | |
76 | 1,\r | |
77 | &OldCommand\r | |
78 | );\r | |
79 | }\r | |
80 | \r | |
81 | BOOLEAN\r | |
82 | PciCapabilitySupport (\r | |
83 | IN PCI_IO_DEVICE *PciIoDevice\r | |
84 | )\r | |
bcd70414 | 85 | /**\r |
ead42efc | 86 | \r |
87 | Routine Description:\r | |
88 | \r | |
89 | Arguments:\r | |
90 | \r | |
91 | Returns:\r | |
92 | \r | |
93 | None\r | |
94 | \r | |
bcd70414 | 95 | **/\r |
ead42efc | 96 | // TODO: PciIoDevice - add argument and description to function comment\r |
97 | {\r | |
98 | \r | |
99 | if (PciIoDevice->Pci.Hdr.Status & EFI_PCI_STATUS_CAPABILITY) {\r | |
100 | return TRUE;\r | |
101 | }\r | |
102 | \r | |
103 | return FALSE;\r | |
104 | }\r | |
105 | \r | |
106 | EFI_STATUS\r | |
107 | LocateCapabilityRegBlock (\r | |
108 | IN PCI_IO_DEVICE *PciIoDevice,\r | |
109 | IN UINT8 CapId,\r | |
110 | IN OUT UINT8 *Offset,\r | |
111 | OUT UINT8 *NextRegBlock OPTIONAL\r | |
112 | )\r | |
bcd70414 | 113 | /**\r |
ead42efc | 114 | \r |
115 | Routine Description:\r | |
116 | Locate cap reg.\r | |
117 | \r | |
118 | Arguments:\r | |
119 | PciIoDevice - A pointer to the PCI_IO_DEVICE.\r | |
120 | CapId - The cap ID.\r | |
121 | Offset - A pointer to the offset.\r | |
122 | NextRegBlock - A pointer to the next block.\r | |
123 | \r | |
124 | Returns:\r | |
125 | \r | |
126 | None\r | |
127 | \r | |
bcd70414 | 128 | **/\r |
ead42efc | 129 | // TODO: EFI_UNSUPPORTED - add return value to function comment\r |
130 | // TODO: EFI_SUCCESS - add return value to function comment\r | |
131 | // TODO: EFI_NOT_FOUND - add return value to function comment\r | |
132 | {\r | |
133 | UINT8 CapabilityPtr;\r | |
134 | UINT16 CapabilityEntry;\r | |
135 | UINT8 CapabilityID;\r | |
136 | \r | |
137 | //\r | |
138 | // To check the cpability of this device supports\r | |
139 | //\r | |
140 | if (!PciCapabilitySupport (PciIoDevice)) {\r | |
141 | return EFI_UNSUPPORTED;\r | |
142 | }\r | |
143 | \r | |
144 | if (*Offset != 0) {\r | |
145 | CapabilityPtr = *Offset;\r | |
146 | } else {\r | |
147 | \r | |
148 | CapabilityPtr = 0;\r | |
149 | if (IS_CARDBUS_BRIDGE (&PciIoDevice->Pci)) {\r | |
150 | \r | |
151 | PciIoRead (\r | |
152 | &PciIoDevice->PciIo,\r | |
153 | EfiPciIoWidthUint8,\r | |
154 | EFI_PCI_CARDBUS_BRIDGE_CAPABILITY_PTR,\r | |
155 | 1,\r | |
156 | &CapabilityPtr\r | |
157 | );\r | |
158 | } else {\r | |
159 | \r | |
160 | PciIoRead (\r | |
161 | &PciIoDevice->PciIo,\r | |
162 | EfiPciIoWidthUint8,\r | |
163 | EFI_PCI_CAPABILITY_PTR,\r | |
164 | 1,\r | |
165 | &CapabilityPtr\r | |
166 | );\r | |
167 | }\r | |
168 | }\r | |
169 | \r | |
170 | while (CapabilityPtr > 0x3F) {\r | |
171 | //\r | |
172 | // Mask it to DWORD alignment per PCI spec\r | |
173 | //\r | |
174 | CapabilityPtr &= 0xFC;\r | |
175 | PciIoRead (\r | |
176 | &PciIoDevice->PciIo,\r | |
177 | EfiPciIoWidthUint16,\r | |
178 | CapabilityPtr,\r | |
179 | 1,\r | |
180 | &CapabilityEntry\r | |
181 | );\r | |
182 | \r | |
183 | CapabilityID = (UINT8) CapabilityEntry;\r | |
184 | \r | |
185 | if (CapabilityID == CapId) {\r | |
186 | *Offset = CapabilityPtr;\r | |
187 | if (NextRegBlock != NULL) {\r | |
188 | *NextRegBlock = (UINT8) (CapabilityEntry >> 8);\r | |
189 | }\r | |
190 | \r | |
191 | return EFI_SUCCESS;\r | |
192 | }\r | |
193 | \r | |
194 | CapabilityPtr = (UINT8) (CapabilityEntry >> 8);\r | |
195 | }\r | |
196 | \r | |
197 | return EFI_NOT_FOUND;\r | |
198 | }\r |