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