]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/SmmIoLibSmmCpuIo2/IoLib.c
MdePkg: Fix typos in comments
[mirror_edk2.git] / MdePkg / Library / SmmIoLibSmmCpuIo2 / IoLib.c
CommitLineData
b7c5912a 1/** @file\r
2 I/O Library.\r
3 The implementation of I/O operation for this library instance \r
4 are based on EFI_CPU_IO_PROTOCOL.\r
5 \r
19388d29
HT
6 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
7 This program and the accompanying materials\r
b7c5912a 8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
2fc59a00 10 http://opensource.org/licenses/bsd-license.php.\r
b7c5912a 11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
b7c5912a 15**/\r
16\r
b7c5912a 17#include "SmmCpuIoLibInternal.h"\r
18\r
b7c5912a 19/**\r
20 Reads registers in the EFI CPU I/O space.\r
21\r
22 Reads the I/O port specified by Port with registers width specified by Width.\r
23 The read value is returned. If such operations are not supported, then ASSERT().\r
24 This function must guarantee that all I/O read and write operations are serialized.\r
25\r
26 @param Port The base address of the I/O operation.\r
27 The caller is responsible for aligning the Address if required.\r
28 @param Width The width of the I/O operation.\r
29\r
30 @return Data read from registers in the EFI CPU I/O space.\r
31\r
32**/\r
33UINT64\r
34EFIAPI\r
35IoReadWorker (\r
36 IN UINTN Port,\r
37 IN EFI_SMM_IO_WIDTH Width\r
38 )\r
39{\r
40 EFI_STATUS Status;\r
41 UINT64 Data;\r
42\r
112af426 43 Status = gSmst->SmmIo.Io.Read (&gSmst->SmmIo, Width, Port, 1, &Data);\r
b7c5912a 44 ASSERT_EFI_ERROR (Status);\r
45\r
46 return Data;\r
47}\r
48\r
49/**\r
50 Writes registers in the EFI CPU I/O space.\r
51\r
52 Writes the I/O port specified by Port with registers width and value specified by Width\r
53 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().\r
54 This function must guarantee that all I/O read and write operations are serialized.\r
55\r
56 @param Port The base address of the I/O operation.\r
57 The caller is responsible for aligning the Address if required.\r
58 @param Width The width of the I/O operation.\r
59 @param Data The value to write to the I/O port.\r
60\r
a750b4ae 61 @return The parameter of Data.\r
b7c5912a 62\r
63**/\r
64UINT64\r
65EFIAPI\r
66IoWriteWorker (\r
67 IN UINTN Port,\r
68 IN EFI_SMM_IO_WIDTH Width,\r
69 IN UINT64 Data\r
70 )\r
71{\r
72 EFI_STATUS Status;\r
73\r
112af426 74 Status = gSmst->SmmIo.Io.Write (&gSmst->SmmIo, Width, Port, 1, &Data);\r
b7c5912a 75 ASSERT_EFI_ERROR (Status);\r
76\r
77 return Data;\r
78}\r
79\r
80/**\r
81 Reads memory-mapped registers in the EFI system memory space.\r
82\r
83 Reads the MMIO registers specified by Address with registers width specified by Width.\r
84 The read value is returned. If such operations are not supported, then ASSERT().\r
85 This function must guarantee that all MMIO read and write operations are serialized.\r
86\r
87 @param Address The MMIO register to read.\r
88 The caller is responsible for aligning the Address if required.\r
89 @param Width The width of the I/O operation.\r
90\r
91 @return Data read from registers in the EFI system memory space.\r
92\r
93**/\r
94UINT64\r
95EFIAPI\r
96MmioReadWorker (\r
97 IN UINTN Address,\r
98 IN EFI_SMM_IO_WIDTH Width\r
99 )\r
100{\r
101 EFI_STATUS Status;\r
102 UINT64 Data;\r
103\r
112af426 104 Status = gSmst->SmmIo.Mem.Read (&gSmst->SmmIo, Width, Address, 1, &Data);\r
b7c5912a 105 ASSERT_EFI_ERROR (Status);\r
106\r
107 return Data;\r
108}\r
109\r
110/**\r
111 Writes memory-mapped registers in the EFI system memory space.\r
112\r
113 Writes the MMIO registers specified by Address with registers width and value specified by Width\r
114 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().\r
115 This function must guarantee that all MMIO read and write operations are serialized.\r
116\r
117 @param Address The MMIO register to read.\r
118 The caller is responsible for aligning the Address if required.\r
119 @param Width The width of the I/O operation.\r
120 @param Data The value to write to the I/O port.\r
121 \r
122 @return Data read from registers in the EFI system memory space.\r
123\r
124**/\r
125UINT64\r
126EFIAPI\r
127MmioWriteWorker (\r
128 IN UINTN Address,\r
129 IN EFI_SMM_IO_WIDTH Width,\r
130 IN UINT64 Data\r
131 )\r
132{\r
133 EFI_STATUS Status;\r
134\r
112af426 135 Status = gSmst->SmmIo.Mem.Write (&gSmst->SmmIo, Width, Address, 1, &Data);\r
b7c5912a 136 ASSERT_EFI_ERROR (Status);\r
137\r
138 return Data;\r
139}\r
140\r
141/**\r
142 Reads an 8-bit I/O port.\r
143\r
144 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r
145 This function must guarantee that all I/O read and write operations are\r
146 serialized.\r
147\r
148 If 8-bit I/O port operations are not supported, then ASSERT().\r
149\r
150 @param Port The I/O port to read.\r
151\r
152 @return The value read.\r
153\r
154**/\r
155UINT8\r
156EFIAPI\r
157IoRead8 (\r
158 IN UINTN Port\r
159 )\r
160{\r
161 return (UINT8)IoReadWorker (Port, SMM_IO_UINT8);\r
162}\r
163\r
164/**\r
165 Writes an 8-bit I/O port.\r
166\r
167 Writes the 8-bit I/O port specified by Port with the value specified by Value\r
168 and returns Value. This function must guarantee that all I/O read and write\r
169 operations are serialized.\r
170\r
171 If 8-bit I/O port operations are not supported, then ASSERT().\r
172\r
173 @param Port The I/O port to write.\r
174 @param Value The value to write to the I/O port.\r
175\r
176 @return The value written the I/O port.\r
177\r
178**/\r
179UINT8\r
180EFIAPI\r
181IoWrite8 (\r
182 IN UINTN Port,\r
183 IN UINT8 Value\r
184 )\r
185{\r
186 return (UINT8)IoWriteWorker (Port, SMM_IO_UINT8, Value);\r
187}\r
188\r
189/**\r
190 Reads a 16-bit I/O port.\r
191\r
192 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r
193 This function must guarantee that all I/O read and write operations are\r
194 serialized.\r
195\r
196 If Port is not aligned on a 16-bit boundary, then ASSERT().\r
197 \r
198 If 16-bit I/O port operations are not supported, then ASSERT().\r
199\r
200 @param Port The I/O port to read.\r
201\r
202 @return The value read.\r
203\r
204**/\r
205UINT16\r
206EFIAPI\r
207IoRead16 (\r
208 IN UINTN Port\r
209 )\r
210{\r
211 //\r
212 // Make sure Port is aligned on a 16-bit boundary.\r
213 //\r
214 ASSERT ((Port & 1) == 0);\r
215 return (UINT16)IoReadWorker (Port, SMM_IO_UINT16);\r
216}\r
217\r
218/**\r
219 Writes a 16-bit I/O port.\r
220\r
221 Writes the 16-bit I/O port specified by Port with the value specified by Value\r
222 and returns Value. This function must guarantee that all I/O read and write\r
223 operations are serialized.\r
224\r
225 If Port is not aligned on a 16-bit boundary, then ASSERT().\r
226\r
227 If 16-bit I/O port operations are not supported, then ASSERT().\r
228\r
229 @param Port The I/O port to write.\r
230 @param Value The value to write to the I/O port.\r
231\r
232 @return The value written the I/O port.\r
233\r
234**/\r
235UINT16\r
236EFIAPI\r
237IoWrite16 (\r
238 IN UINTN Port,\r
239 IN UINT16 Value\r
240 )\r
241{\r
242 //\r
243 // Make sure Port is aligned on a 16-bit boundary.\r
244 //\r
245 ASSERT ((Port & 1) == 0);\r
246 return (UINT16)IoWriteWorker (Port, SMM_IO_UINT16, Value);\r
247}\r
248\r
249/**\r
250 Reads a 32-bit I/O port.\r
251\r
252 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r
253 This function must guarantee that all I/O read and write operations are\r
254 serialized.\r
255 \r
256 If Port is not aligned on a 32-bit boundary, then ASSERT().\r
257\r
258 If 32-bit I/O port operations are not supported, then ASSERT().\r
259\r
260 @param Port The I/O port to read.\r
261\r
262 @return The value read.\r
263\r
264**/\r
265UINT32\r
266EFIAPI\r
267IoRead32 (\r
268 IN UINTN Port\r
269 )\r
270{\r
271 //\r
272 // Make sure Port is aligned on a 32-bit boundary.\r
273 //\r
274 ASSERT ((Port & 3) == 0);\r
275 return (UINT32)IoReadWorker (Port, SMM_IO_UINT32);\r
276}\r
277\r
278/**\r
279 Writes a 32-bit I/O port.\r
280\r
281 Writes the 32-bit I/O port specified by Port with the value specified by Value\r
282 and returns Value. This function must guarantee that all I/O read and write\r
283 operations are serialized.\r
284\r
285 If Port is not aligned on a 32-bit boundary, then ASSERT().\r
286\r
287 If 32-bit I/O port operations are not supported, then ASSERT().\r
288\r
289 @param Port The I/O port to write.\r
290 @param Value The value to write to the I/O port.\r
291\r
292 @return The value written the I/O port.\r
293\r
294**/\r
295UINT32\r
296EFIAPI\r
297IoWrite32 (\r
298 IN UINTN Port,\r
299 IN UINT32 Value\r
300 )\r
301{\r
302 //\r
303 // Make sure Port is aligned on a 32-bit boundary.\r
304 //\r
305 ASSERT ((Port & 3) == 0);\r
306 return (UINT32)IoWriteWorker (Port, SMM_IO_UINT32, Value);\r
307}\r
308\r
309/**\r
310 Reads a 64-bit I/O port.\r
311\r
312 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.\r
313 This function must guarantee that all I/O read and write operations are\r
314 serialized.\r
315\r
316 If Port is not aligned on a 64-bit boundary, then ASSERT().\r
317\r
318 If 64-bit I/O port operations are not supported, then ASSERT().\r
319\r
320 @param Port The I/O port to read.\r
321\r
322 @return The value read.\r
323\r
324**/\r
325UINT64\r
326EFIAPI\r
327IoRead64 (\r
328 IN UINTN Port\r
329 )\r
330{\r
331 //\r
332 // Make sure Port is aligned on a 64-bit boundary.\r
333 //\r
334 ASSERT ((Port & 7) == 0);\r
335 return IoReadWorker (Port, SMM_IO_UINT64);\r
336}\r
337\r
338/**\r
339 Writes a 64-bit I/O port.\r
340\r
341 Writes the 64-bit I/O port specified by Port with the value specified by Value\r
342 and returns Value. This function must guarantee that all I/O read and write\r
343 operations are serialized.\r
344\r
345 If Port is not aligned on a 64-bit boundary, then ASSERT().\r
346 \r
347 If 64-bit I/O port operations are not supported, then ASSERT().\r
348\r
349 @param Port The I/O port to write.\r
350 @param Value The value to write to the I/O port.\r
351\r
352 @return The value written the I/O port.\r
353\r
354**/\r
355UINT64\r
356EFIAPI\r
357IoWrite64 (\r
358 IN UINTN Port,\r
359 IN UINT64 Value\r
360 )\r
361{\r
362 //\r
363 // Make sure Port is aligned on a 64-bit boundary.\r
364 //\r
365 ASSERT ((Port & 7) == 0);\r
366 return IoWriteWorker (Port, SMM_IO_UINT64, Value);\r
367}\r
368\r
369/**\r
370 Reads an 8-bit MMIO register.\r
371\r
372 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is\r
373 returned. This function must guarantee that all MMIO read and write\r
374 operations are serialized.\r
375\r
376 If 8-bit MMIO register operations are not supported, then ASSERT().\r
377\r
378 @param Address The MMIO register to read.\r
379\r
380 @return The value read.\r
381\r
382**/\r
383UINT8\r
384EFIAPI\r
385MmioRead8 (\r
386 IN UINTN Address\r
387 )\r
388{\r
389 return (UINT8)MmioReadWorker (Address, SMM_IO_UINT8);\r
390}\r
391\r
392/**\r
393 Writes an 8-bit MMIO register.\r
394\r
395 Writes the 8-bit MMIO register specified by Address with the value specified\r
396 by Value and returns Value. This function must guarantee that all MMIO read\r
397 and write operations are serialized.\r
398\r
399 If 8-bit MMIO register operations are not supported, then ASSERT().\r
400\r
401 @param Address The MMIO register to write.\r
402 @param Value The value to write to the MMIO register.\r
403\r
404**/\r
405UINT8\r
406EFIAPI\r
407MmioWrite8 (\r
408 IN UINTN Address,\r
409 IN UINT8 Value\r
410 )\r
411{\r
412 return (UINT8)MmioWriteWorker (Address, SMM_IO_UINT8, Value);\r
413}\r
414\r
415/**\r
416 Reads a 16-bit MMIO register.\r
417\r
418 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is\r
419 returned. This function must guarantee that all MMIO read and write\r
420 operations are serialized.\r
421\r
422 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
423 \r
424 If 16-bit MMIO register operations are not supported, then ASSERT().\r
425\r
426 @param Address The MMIO register to read.\r
427\r
428 @return The value read.\r
429\r
430**/\r
431UINT16\r
432EFIAPI\r
433MmioRead16 (\r
434 IN UINTN Address\r
435 )\r
436{\r
437 //\r
438 // Make sure Address is aligned on a 16-bit boundary.\r
439 //\r
440 ASSERT ((Address & 1) == 0);\r
441 return (UINT16)MmioReadWorker (Address, SMM_IO_UINT16);\r
442}\r
443\r
444/**\r
445 Writes a 16-bit MMIO register.\r
446\r
447 Writes the 16-bit MMIO register specified by Address with the value specified\r
448 by Value and returns Value. This function must guarantee that all MMIO read\r
449 and write operations are serialized.\r
450\r
451 If Address is not aligned on a 16-bit boundary, then ASSERT().\r
452 \r
453 If 16-bit MMIO register operations are not supported, then ASSERT().\r
454\r
455 @param Address The MMIO register to write.\r
456 @param Value The value to write to the MMIO register.\r
457\r
458**/\r
459UINT16\r
460EFIAPI\r
461MmioWrite16 (\r
462 IN UINTN Address,\r
463 IN UINT16 Value\r
464 )\r
465{\r
466 //\r
467 // Make sure Address is aligned on a 16-bit boundary.\r
468 //\r
469 ASSERT ((Address & 1) == 0);\r
470 return (UINT16)MmioWriteWorker (Address, SMM_IO_UINT16, Value);\r
471}\r
472\r
473/**\r
474 Reads a 32-bit MMIO register.\r
475\r
476 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is\r
477 returned. This function must guarantee that all MMIO read and write\r
478 operations are serialized.\r
479\r
480 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
481 \r
482 If 32-bit MMIO register operations are not supported, then ASSERT().\r
483\r
484 @param Address The MMIO register to read.\r
485\r
486 @return The value read.\r
487\r
488**/\r
489UINT32\r
490EFIAPI\r
491MmioRead32 (\r
492 IN UINTN Address\r
493 )\r
494{\r
495 //\r
496 // Make sure Address is aligned on a 32-bit boundary.\r
497 //\r
498 ASSERT ((Address & 3) == 0);\r
499 return (UINT32)MmioReadWorker (Address, SMM_IO_UINT32);\r
500}\r
501\r
502/**\r
503 Writes a 32-bit MMIO register.\r
504\r
505 Writes the 32-bit MMIO register specified by Address with the value specified\r
506 by Value and returns Value. This function must guarantee that all MMIO read\r
507 and write operations are serialized.\r
508\r
509 If Address is not aligned on a 32-bit boundary, then ASSERT().\r
510 \r
511 If 32-bit MMIO register operations are not supported, then ASSERT().\r
512\r
513 @param Address The MMIO register to write.\r
514 @param Value The value to write to the MMIO register.\r
515\r
516**/\r
517UINT32\r
518EFIAPI\r
519MmioWrite32 (\r
520 IN UINTN Address,\r
521 IN UINT32 Value\r
522 )\r
523{\r
524 //\r
525 // Make sure Address is aligned on a 32-bit boundary.\r
526 //\r
527 ASSERT ((Address & 3) == 0);\r
528 return (UINT32)MmioWriteWorker (Address, SMM_IO_UINT32, Value);\r
529}\r
530\r
531/**\r
532 Reads a 64-bit MMIO register.\r
533\r
534 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is\r
535 returned. This function must guarantee that all MMIO read and write\r
536 operations are serialized.\r
537\r
538 If Address is not aligned on a 64-bit boundary, then ASSERT().\r
539 \r
540 If 64-bit MMIO register operations are not supported, then ASSERT().\r
541\r
542 @param Address The MMIO register to read.\r
543\r
544 @return The value read.\r
545\r
546**/\r
547UINT64\r
548EFIAPI\r
549MmioRead64 (\r
550 IN UINTN Address\r
551 )\r
552{\r
553 //\r
554 // Make sure Address is aligned on a 64-bit boundary.\r
555 //\r
556 ASSERT ((Address & 7) == 0);\r
557 return (UINT64)MmioReadWorker (Address, SMM_IO_UINT64);\r
558}\r
559\r
560/**\r
561 Writes a 64-bit MMIO register.\r
562\r
563 Writes the 64-bit MMIO register specified by Address with the value specified\r
564 by Value and returns Value. This function must guarantee that all MMIO read\r
565 and write operations are serialized.\r
566\r
567 If Address is not aligned on a 64-bit boundary, then ASSERT().\r
568 \r
569 If 64-bit MMIO register operations are not supported, then ASSERT().\r
570\r
571 @param Address The MMIO register to write.\r
572 @param Value The value to write to the MMIO register.\r
573\r
574**/\r
575UINT64\r
576EFIAPI\r
577MmioWrite64 (\r
578 IN UINTN Address,\r
579 IN UINT64 Value\r
580 )\r
581{\r
582 //\r
583 // Make sure Address is aligned on a 64-bit boundary.\r
584 //\r
585 ASSERT ((Address & 7) == 0);\r
586 return (UINT64)MmioWriteWorker (Address, SMM_IO_UINT64, Value);\r
587}\r