]> git.proxmox.com Git - mirror_edk2.git/blame - UnixPkg/CpuRuntimeDxe/CpuIo.c
Remove extra #includes where possible to make build more efficient
[mirror_edk2.git] / UnixPkg / CpuRuntimeDxe / CpuIo.c
CommitLineData
804405e7 1/*++\r
2\r
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
11\r
12Module Name:\r
13\r
14 CpuIo.c\r
15\r
16Abstract:\r
17\r
18 This is the code that publishes the CPU I/O Protocol.\r
19 The intent herein is to have a single I/O service that can load\r
20 as early as possible, extend into runtime, and be layered upon by \r
21 the implementations of architectural protocols and the PCI Root\r
22 Bridge I/O Protocol.\r
23\r
24--*/\r
25#include "PiDxe.h"\r
26#include <Protocol/Cpu.h>\r
27#include <Protocol/DataHub.h>\r
28#include <Guid/DataHubRecords.h>\r
29#include <Protocol/CpuIo.h>\r
30#include <Protocol/FrameworkHii.h>\r
804405e7 31\r
32#include <Library/BaseLib.h>\r
33#include <Library/DebugLib.h>\r
34#include <Library/HiiLib.h>\r
35#include <Library/UefiLib.h>\r
36#include <Library/UefiDriverEntryPoint.h>\r
37#include <Library/BaseMemoryLib.h>\r
38#include <Library/MemoryAllocationLib.h>\r
39#include <Library/UefiBootServicesTableLib.h>\r
40#include <CpuDriver.h>\r
41\r
42#define IA32_MAX_IO_ADDRESS 0xFFFF\r
43#define IA32_MAX_MEM_ADDRESS 0xFFFFFFFF\r
44\r
45EFI_CPU_IO_PROTOCOL mCpuIoProtocol;\r
46\r
47EFI_STATUS\r
48CpuIoCheckAddressRange (\r
49 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
50 IN UINT64 Address,\r
51 IN UINTN Count,\r
52 IN VOID *Buffer,\r
53 IN UINT64 Limit\r
54 );\r
55\r
56EFI_STATUS\r
57EFIAPI\r
58CpuMemoryServiceRead (\r
59 IN EFI_CPU_IO_PROTOCOL *This,\r
60 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
61 IN UINT64 Address,\r
62 IN UINTN Count,\r
63 IN OUT VOID *Buffer\r
64 )\r
65/*++\r
66\r
67Routine Description:\r
68\r
69 Perform the Memory Access Read service for the CPU I/O Protocol\r
70\r
71Arguments:\r
72\r
73 Pointer to an instance of the CPU I/O Protocol\r
74 Width of the Memory Access\r
75 Address of the Memory access\r
76 Count of the number of accesses to perform\r
77 Pointer to the buffer to read or write from memory\r
78\r
79Returns:\r
80\r
81 Status\r
82\r
83 EFI_SUCCESS - The data was read from or written to the EFI \r
84 System.\r
85 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.\r
86 EFI_INVALID_PARAMETER - Buffer is NULL.\r
87 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
88 EFI_UNSUPPORTED - The address range specified by Address, Width, \r
89 and Count is not valid for this EFI System.\r
90\r
91--*/\r
92// TODO: This - add argument and description to function comment\r
93{\r
94 EFI_STATUS Status;\r
95\r
96 if (!Buffer) {\r
97 return EFI_INVALID_PARAMETER;\r
98 }\r
99\r
100 Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);\r
101 if (EFI_ERROR (Status)) {\r
102 return Status;\r
103 }\r
104\r
105 //\r
106 // Do nothing for Nt32 version\r
107 //\r
108 return EFI_SUCCESS;\r
109}\r
110\r
111EFI_STATUS\r
112EFIAPI\r
113CpuMemoryServiceWrite (\r
114 IN EFI_CPU_IO_PROTOCOL *This,\r
115 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
116 IN UINT64 Address,\r
117 IN UINTN Count,\r
118 IN OUT VOID *Buffer\r
119 )\r
120/*++\r
121\r
122Routine Description:\r
123\r
124 Perform the Memory Access Read service for the CPU I/O Protocol\r
125\r
126Arguments:\r
127\r
128 Pointer to an instance of the CPU I/O Protocol\r
129 Width of the Memory Access\r
130 Address of the Memory access\r
131 Count of the number of accesses to perform\r
132 Pointer to the buffer to read or write from memory\r
133\r
134Returns:\r
135\r
136 Status\r
137\r
138 EFI_SUCCESS - The data was read from or written to the EFI System.\r
139 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.\r
140 EFI_INVALID_PARAMETER - Buffer is NULL.\r
141 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
142 EFI_UNSUPPORTED - The address range specified by Address, Width, and \r
143 Count is not valid for this EFI System.\r
144\r
145--*/\r
146// TODO: This - add argument and description to function comment\r
147{\r
148 EFI_STATUS Status;\r
149\r
150 if (!Buffer) {\r
151 return EFI_INVALID_PARAMETER;\r
152 }\r
153\r
154 Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);\r
155 if (EFI_ERROR (Status)) {\r
156 return Status;\r
157 }\r
158\r
159 //\r
160 // Do nothing for Nt32 version\r
161 //\r
162 return EFI_SUCCESS;\r
163}\r
164\r
165EFI_STATUS\r
166EFIAPI\r
167CpuIoServiceRead (\r
168 IN EFI_CPU_IO_PROTOCOL *This,\r
169 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
170 IN UINT64 UserAddress,\r
171 IN UINTN Count,\r
172 IN OUT VOID *UserBuffer\r
173 )\r
174/*++\r
175\r
176Routine Description:\r
177 \r
178 This is the service that implements the I/O read\r
179\r
180Arguments:\r
181\r
182 Pointer to an instance of the CPU I/O Protocol\r
183 Width of the Memory Access\r
184 Address of the I/O access\r
185 Count of the number of accesses to perform\r
186 Pointer to the buffer to read or write from I/O space\r
187\r
188Returns:\r
189\r
190 Status\r
191 EFI_SUCCESS - The data was read from or written to the EFI System.\r
192 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.\r
193 EFI_INVALID_PARAMETER - Buffer is NULL.\r
194 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
195 EFI_UNSUPPORTED - The address range specified by Address, Width, and \r
196 Count is not valid for this EFI System.\r
197--*/\r
198// TODO: This - add argument and description to function comment\r
199// TODO: UserAddress - add argument and description to function comment\r
200// TODO: UserBuffer - add argument and description to function comment\r
201{\r
202 UINTN Address;\r
203 EFI_STATUS Status;\r
204\r
205 if (!UserBuffer) {\r
206 return EFI_INVALID_PARAMETER;\r
207 }\r
208\r
209 Address = (UINTN) UserAddress;\r
210\r
211 if (Width >= EfiCpuIoWidthMaximum) {\r
212 return EFI_INVALID_PARAMETER;\r
213 }\r
214\r
215 Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);\r
216 if (EFI_ERROR (Status)) {\r
217 return Status;\r
218 }\r
219\r
220 //\r
221 // Do nothing for Nt32 version\r
222 //\r
223 return EFI_SUCCESS;\r
224}\r
225\r
226EFI_STATUS\r
227EFIAPI\r
228CpuIoServiceWrite (\r
229 IN EFI_CPU_IO_PROTOCOL *This,\r
230 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
231 IN UINT64 UserAddress,\r
232 IN UINTN Count,\r
233 IN OUT VOID *UserBuffer\r
234 )\r
235/*++\r
236\r
237Routine Description:\r
238\r
239 \r
240 This is the service that implements the I/O Write\r
241\r
242Arguments:\r
243\r
244 Pointer to an instance of the CPU I/O Protocol\r
245 Width of the Memory Access\r
246 Address of the I/O access\r
247 Count of the number of accesses to perform\r
248 Pointer to the buffer to read or write from I/O space\r
249\r
250Returns:\r
251\r
252 Status\r
253\r
254 Status\r
255 EFI_SUCCESS - The data was read from or written to the EFI System.\r
256 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.\r
257 EFI_INVALID_PARAMETER - Buffer is NULL.\r
258 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
259 EFI_UNSUPPORTED - The address range specified by Address, Width, and \r
260 Count is not valid for this EFI System.\r
261\r
262--*/\r
263// TODO: This - add argument and description to function comment\r
264// TODO: UserAddress - add argument and description to function comment\r
265// TODO: UserBuffer - add argument and description to function comment\r
266{\r
267 UINTN Address;\r
268 EFI_STATUS Status;\r
269\r
270 if (!UserBuffer) {\r
271 return EFI_INVALID_PARAMETER;\r
272 }\r
273\r
274 Address = (UINTN) UserAddress;\r
275\r
276 if (Width >= EfiCpuIoWidthMaximum) {\r
277 return EFI_INVALID_PARAMETER;\r
278 }\r
279\r
280 Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);\r
281 if (EFI_ERROR (Status)) {\r
282 return Status;\r
283 }\r
284\r
285 //\r
286 // Do nothing for Nt32 version\r
287 //\r
288 return EFI_SUCCESS;\r
289}\r
290\r
291\r
292EFI_STATUS\r
293CpuIoCheckAddressRange (\r
294 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
295 IN UINT64 Address,\r
296 IN UINTN Count,\r
297 IN VOID *Buffer,\r
298 IN UINT64 Limit\r
299 )\r
300/*++\r
301\r
302Routine Description:\r
303\r
304 TODO: Add function description\r
305\r
306Arguments:\r
307\r
308 Width - TODO: add argument description\r
309 Address - TODO: add argument description\r
310 Count - TODO: add argument description\r
311 Buffer - TODO: add argument description\r
312 Limit - TODO: add argument description\r
313\r
314Returns:\r
315\r
316 EFI_UNSUPPORTED - TODO: Add description for return value\r
317 EFI_UNSUPPORTED - TODO: Add description for return value\r
318 EFI_UNSUPPORTED - TODO: Add description for return value\r
319 EFI_SUCCESS - TODO: Add description for return value\r
320\r
321--*/\r
322{\r
323 UINTN AlignMask;\r
324\r
325 if (Address > Limit) {\r
326 return EFI_UNSUPPORTED;\r
327 }\r
328\r
329 //\r
330 // For FiFo type, the target address won't increase during the access, so treat count as 1\r
331 //\r
332 if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
333 Count = 1;\r
334 }\r
335\r
336 Width = Width & 0x03;\r
337 if (Address - 1 + (1 << Width) * Count > Limit) {\r
338 return EFI_UNSUPPORTED;\r
339 }\r
340\r
341 AlignMask = (1 << Width) - 1;\r
342 if ((UINTN) Buffer & AlignMask) {\r
343 return EFI_UNSUPPORTED;\r
344 }\r
345\r
346 return EFI_SUCCESS;\r
347}\r
348\r
349\r