change DxeSmmDriverEntryPoint library class name to UefiEntryPoint
[edk2.git] / DuetPkg / PciBusNoEnumerationDxe / PciCommand.c
blob61393edeb4e7129d7eff445c06aaa51700443813
1 /*++
3 Copyright (c) 2005 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 Module Name:
14 PciCommand.c
16 Abstract:
18 PCI Bus Driver
20 Revision History
22 --*/
24 #include "PciBus.h"
27 EFI_STATUS
28 PciReadCommandRegister (
29 IN PCI_IO_DEVICE *PciIoDevice,
30 OUT UINT16 *Command
32 /*++
34 Routine Description:
36 Arguments:
38 Returns:
40 None
42 --*/
45 EFI_PCI_IO_PROTOCOL *PciIo;
47 *Command = 0;
48 PciIo = &PciIoDevice->PciIo;
50 return PciIo->Pci.Read (
51 PciIo,
52 EfiPciIoWidthUint16,
53 PCI_COMMAND_OFFSET,
54 1,
55 Command
59 EFI_STATUS
60 PciSetCommandRegister (
61 IN PCI_IO_DEVICE *PciIoDevice,
62 IN UINT16 Command
64 /*++
66 Routine Description:
68 Arguments:
70 Returns:
72 None
74 --*/
76 UINT16 Temp;
77 EFI_PCI_IO_PROTOCOL *PciIo;
79 Temp = Command;
80 PciIo = &PciIoDevice->PciIo;
82 return PciIo->Pci.Write (
83 PciIo,
84 EfiPciIoWidthUint16,
85 PCI_COMMAND_OFFSET,
86 1,
87 &Temp
93 EFI_STATUS
94 PciEnableCommandRegister (
95 IN PCI_IO_DEVICE *PciIoDevice,
96 IN UINT16 Command
98 /*++
100 Routine Description:
102 Arguments:
104 Returns:
106 None
108 --*/
110 UINT16 OldCommand;
111 EFI_PCI_IO_PROTOCOL *PciIo;
113 OldCommand = 0;
114 PciIo = &PciIoDevice->PciIo;
116 PciIo->Pci.Read (
117 PciIo,
118 EfiPciIoWidthUint16,
119 PCI_COMMAND_OFFSET,
121 &OldCommand
124 OldCommand |= Command;
126 return PciIo->Pci.Write (
127 PciIo,
128 EfiPciIoWidthUint16,
129 PCI_COMMAND_OFFSET,
131 &OldCommand
137 EFI_STATUS
138 PciDisableCommandRegister (
139 IN PCI_IO_DEVICE *PciIoDevice,
140 IN UINT16 Command
142 /*++
144 Routine Description:
146 Arguments:
148 Returns:
150 None
152 --*/
154 UINT16 OldCommand;
155 EFI_PCI_IO_PROTOCOL *PciIo;
157 OldCommand = 0;
158 PciIo = &PciIoDevice->PciIo;
160 PciIo->Pci.Read (
161 PciIo,
162 EfiPciIoWidthUint16,
163 PCI_COMMAND_OFFSET,
165 &OldCommand
168 OldCommand &= ~(Command);
170 return PciIo->Pci.Write (
171 PciIo,
172 EfiPciIoWidthUint16,
173 PCI_COMMAND_OFFSET,
175 &OldCommand
182 EFI_STATUS
183 PciSetBridgeControlRegister (
184 IN PCI_IO_DEVICE *PciIoDevice,
185 IN UINT16 Command
187 /*++
189 Routine Description:
191 Arguments:
193 Returns:
195 None
197 --*/
199 UINT16 Temp;
200 EFI_PCI_IO_PROTOCOL *PciIo;
202 Temp = Command;
203 PciIo = &PciIoDevice->PciIo;
205 return PciIo->Pci.Write (
206 PciIo,
207 EfiPciIoWidthUint16,
208 PCI_BRIDGE_CONTROL_REGISTER_OFFSET,
210 &Temp
216 EFI_STATUS
217 PciEnableBridgeControlRegister (
218 IN PCI_IO_DEVICE *PciIoDevice,
219 IN UINT16 Command
221 /*++
223 Routine Description:
225 Arguments:
227 Returns:
229 None
231 --*/
233 UINT16 OldCommand;
234 EFI_PCI_IO_PROTOCOL *PciIo;
236 OldCommand = 0;
237 PciIo = &PciIoDevice->PciIo;
239 PciIo->Pci.Read (
240 PciIo,
241 EfiPciIoWidthUint16,
242 PCI_BRIDGE_CONTROL_REGISTER_OFFSET,
244 &OldCommand
247 OldCommand |= Command;
249 return PciIo->Pci.Write (
250 PciIo,
251 EfiPciIoWidthUint16,
252 PCI_BRIDGE_CONTROL_REGISTER_OFFSET,
254 &OldCommand
259 EFI_STATUS
260 PciDisableBridgeControlRegister (
261 IN PCI_IO_DEVICE *PciIoDevice,
262 IN UINT16 Command
264 /*++
266 Routine Description:
268 Arguments:
270 Returns:
272 None
274 --*/
276 UINT16 OldCommand;
277 EFI_PCI_IO_PROTOCOL *PciIo;
279 OldCommand = 0;
280 PciIo = &PciIoDevice->PciIo;
282 PciIo->Pci.Read (
283 PciIo,
284 EfiPciIoWidthUint16,
285 PCI_BRIDGE_CONTROL_REGISTER_OFFSET,
287 &OldCommand
290 OldCommand &= ~(Command);
292 return PciIo->Pci.Write (
293 PciIo,
294 EfiPciIoWidthUint16,
295 PCI_BRIDGE_CONTROL_REGISTER_OFFSET,
297 &OldCommand
304 EFI_STATUS
305 PciReadBridgeControlRegister (
306 IN PCI_IO_DEVICE *PciIoDevice,
307 OUT UINT16 *Command
309 /*++
311 Routine Description:
313 Arguments:
315 Returns:
317 None
319 --*/
322 EFI_PCI_IO_PROTOCOL *PciIo;
324 *Command = 0;
325 PciIo = &PciIoDevice->PciIo;
327 return PciIo->Pci.Read (
328 PciIo,
329 EfiPciIoWidthUint16,
330 PCI_BRIDGE_CONTROL_REGISTER_OFFSET,
332 Command
337 BOOLEAN
338 PciCapabilitySupport (
339 IN PCI_IO_DEVICE *PciIoDevice
341 /*++
343 Routine Description:
345 Arguments:
347 Returns:
349 None
351 --*/
352 // TODO: PciIoDevice - add argument and description to function comment
355 if (PciIoDevice->Pci.Hdr.Status & EFI_PCI_STATUS_CAPABILITY) {
356 return TRUE;
359 return FALSE;
362 EFI_STATUS
363 LocateCapabilityRegBlock (
364 IN PCI_IO_DEVICE *PciIoDevice,
365 IN UINT8 CapId,
366 IN OUT UINT8 *Offset,
367 OUT UINT8 *NextRegBlock OPTIONAL
369 /*++
371 Routine Description:
373 Locate Capability register.
375 Arguments:
377 PciIoDevice - A pointer to the PCI_IO_DEVICE.
378 CapId - The capability ID.
379 Offset - A pointer to the offset.
380 As input: the default offset;
381 As output: the offset of the found block.
382 NextRegBlock - An optional pointer to return the value of next block.
384 Returns:
386 EFI_UNSUPPORTED - The Pci Io device is not supported.
387 EFI_NOT_FOUND - The Pci Io device cannot be found.
388 EFI_SUCCESS - The Pci Io device is successfully located.
390 --*/
392 UINT8 CapabilityPtr;
393 UINT16 CapabilityEntry;
394 UINT8 CapabilityID;
395 UINT32 Temp;
398 // To check the capability of this device supports
400 if (!PciCapabilitySupport (PciIoDevice)) {
401 return EFI_UNSUPPORTED;
404 if (*Offset != 0) {
405 CapabilityPtr = *Offset;
406 } else {
408 CapabilityPtr = 0;
409 if (IS_CARDBUS_BRIDGE (&PciIoDevice->Pci)) {
411 PciIoDevice->PciIo.Pci.Read (
412 &PciIoDevice->PciIo,
413 EfiPciIoWidthUint8,
414 EFI_PCI_CARDBUS_BRIDGE_CAPABILITY_PTR,
416 &CapabilityPtr
418 } else {
420 PciIoDevice->PciIo.Pci.Read (
421 &PciIoDevice->PciIo,
422 EfiPciIoWidthUint32,
423 PCI_CAPBILITY_POINTER_OFFSET,
425 &Temp
428 // Do not get byte read directly, because some PCI card will return 0xFF
429 // when perform PCI-Express byte read, while return correct 0x00
430 // when perform PCI-Express dword read, or PCI dword read.
432 CapabilityPtr = (UINT8)Temp;
436 while (CapabilityPtr > 0x3F) {
438 // Mask it to DWORD alignment per PCI spec
440 CapabilityPtr &= 0xFC;
441 PciIoDevice->PciIo.Pci.Read (
442 &PciIoDevice->PciIo,
443 EfiPciIoWidthUint16,
444 CapabilityPtr,
446 &CapabilityEntry
449 CapabilityID = (UINT8) CapabilityEntry;
451 if (CapabilityID == CapId) {
452 *Offset = CapabilityPtr;
453 if (NextRegBlock != NULL) {
454 *NextRegBlock = (UINT8) (CapabilityEntry >> 8);
457 return EFI_SUCCESS;
460 CapabilityPtr = (UINT8) (CapabilityEntry >> 8);
463 return EFI_NOT_FOUND;