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