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