]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciCommand.c
1. Sync Tcp4 protocol definitions to match UEFI 2.1
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / PciBusDxe / PciCommand.c
CommitLineData
3db51098 1/**@file\r
ead42efc 2\r
3db51098 3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT 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
17EFI_STATUS\r
18PciOperateRegister (\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
25/*++\r
26\r
27Routine Description:\r
28\r
29Arguments:\r
30\r
31Returns:\r
32\r
33 None\r
34\r
35--*/\r
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
81BOOLEAN\r
82PciCapabilitySupport (\r
83 IN PCI_IO_DEVICE *PciIoDevice\r
84 )\r
85/*++\r
86\r
87Routine Description:\r
88\r
89Arguments:\r
90\r
91Returns:\r
92\r
93 None\r
94\r
95--*/\r
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
106EFI_STATUS\r
107LocateCapabilityRegBlock (\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
113/*++\r
114\r
115Routine Description:\r
116 Locate cap reg.\r
117\r
118Arguments:\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
124Returns:\r
125\r
126 None\r
127\r
128--*/\r
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