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