]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseIoLibIntrinsic/IoLibIpf.c
Removed MdePkg usage of ModuleName: in file headers
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLibIpf.c
CommitLineData
e1f414b6 1/** @file\r
2 Common I/O Library routines.\r
3\r
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
e1f414b6 13**/\r
14\r
15//\r
16// Include common header file for this module.\r
17//\r
f734a10a 18#include "BaseIoLibIntrinsicInternal.h"\r
e1f414b6 19\r
20#define MAP_PORT_BASE_TO_MEM(_Port) \\r
21 ((((_Port) & 0xfffc) << 10) | ((_Port) & 0x0fff))\r
22\r
23/**\r
24 Reads a 8-bit I/O port.\r
25\r
26 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r
27 This function must guarantee that all I/O read and write operations are\r
28 serialized.\r
29\r
30 @param Port The I/O port to read.\r
31\r
32 @return The value read.\r
33\r
34**/\r
35UINT8\r
36EFIAPI\r
37IoRead8 (\r
38 IN UINT64 Port\r
39 )\r
40{\r
41 UINT64 Address;\r
42\r
43 //\r
44 // Add the 64MB aligned IO Port space to the IO address\r
45 //\r
46 Address = MAP_PORT_BASE_TO_MEM (Port);\r
47 Address += PcdGet64(PcdIoBlockBaseAddressForIpf);\r
48\r
49 return MmioRead8 (Address);\r
50}\r
51\r
52/**\r
53 Reads a 16-bit I/O port.\r
54\r
55 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r
56 This function must guarantee that all I/O read and write operations are\r
57 serialized.\r
58\r
59 @param Port The I/O port to read.\r
60\r
61 @return The value read.\r
62\r
63**/\r
64UINT16\r
65EFIAPI\r
66IoRead16 (\r
67 IN UINT64 Port\r
68 )\r
69{\r
70 UINT64 Address;\r
71\r
72 //\r
73 // Add the 64MB aligned IO Port space to the IO address\r
74 //\r
75 Address = MAP_PORT_BASE_TO_MEM (Port);\r
76 Address += PcdGet64(PcdIoBlockBaseAddressForIpf);\r
77\r
78 return MmioRead16 (Address);\r
79}\r
80\r
81/**\r
82 Reads a 32-bit I/O port.\r
83\r
84 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r
85 This function must guarantee that all I/O read and write operations are\r
86 serialized.\r
87\r
88 @param Port The I/O port to read.\r
89\r
90 @return The value read.\r
91\r
92**/\r
93UINT32\r
94EFIAPI\r
95IoRead32 (\r
96 IN UINT64 Port\r
97 )\r
98{\r
99 UINT64 Address;\r
100\r
101 //\r
102 // Add the 64MB aligned IO Port space to the IO address\r
103 //\r
104 Address = MAP_PORT_BASE_TO_MEM (Port);\r
105 Address += PcdGet64(PcdIoBlockBaseAddressForIpf);\r
106\r
107 return MmioRead32 (Address);\r
108}\r
109\r
110/**\r
111 Reads a 64-bit I/O port.\r
112\r
113 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.\r
114 This function must guarantee that all I/O read and write operations are\r
115 serialized.\r
116\r
117 If 64-bit I/O port operations are not supported, then ASSERT().\r
118\r
119 @param Port The I/O port to read.\r
120\r
121 @return The value read.\r
122\r
123**/\r
124UINT64\r
125EFIAPI\r
126IoRead64 (\r
127 IN UINTN Port\r
128 )\r
129{\r
130 ASSERT (FALSE);\r
131 return 0;\r
132}\r
133\r
134/**\r
135 Writes a 8-bit I/O port.\r
136\r
137 Writes the 8-bit I/O port specified by Port with the value specified by Value\r
138 and returns Value. This function must guarantee that all I/O read and write\r
139 operations are serialized.\r
140\r
141 @param Port The I/O port to write.\r
142 @param Value The value to write to the I/O port.\r
143\r
144 @return The value written the I/O port.\r
145\r
146**/\r
147UINT8\r
148EFIAPI\r
149IoWrite8 (\r
150 IN UINT64 Port,\r
151 IN UINT8 Data\r
152 )\r
153{\r
154 UINT64 Address;\r
155\r
156 //\r
157 // Add the 64MB aligned IO Port space to the IO address\r
158 //\r
159 Address = MAP_PORT_BASE_TO_MEM (Port);\r
160 Address += PcdGet64(PcdIoBlockBaseAddressForIpf);\r
161\r
162 return MmioWrite8 (Address, Data);\r
163}\r
164\r
165/**\r
166 Writes a 16-bit I/O port.\r
167\r
168 Writes the 16-bit I/O port specified by Port with the value specified by Value\r
169 and returns Value. This function must guarantee that all I/O read and write\r
170 operations are serialized.\r
171\r
172 @param Port The I/O port to write.\r
173 @param Value The value to write to the I/O port.\r
174\r
175 @return The value written the I/O port.\r
176\r
177**/\r
178UINT16\r
179EFIAPI\r
180IoWrite16 (\r
181 IN UINT64 Port,\r
182 IN UINT16 Data\r
183 )\r
184{\r
185 UINT64 Address;\r
186\r
187 //\r
188 // Add the 64MB aligned IO Port space to the IO address\r
189 //\r
190 Address = MAP_PORT_BASE_TO_MEM (Port);\r
191 Address += PcdGet64(PcdIoBlockBaseAddressForIpf);\r
192\r
193 return MmioWrite16 (Address, Data);\r
194}\r
195\r
196/**\r
197 Writes a 32-bit I/O port.\r
198\r
199 Writes the 32-bit I/O port specified by Port with the value specified by Value\r
200 and returns Value. This function must guarantee that all I/O read and write\r
201 operations are serialized.\r
202\r
203 @param Port The I/O port to write.\r
204 @param Value The value to write to the I/O port.\r
205\r
206 @return The value written the I/O port.\r
207\r
208**/\r
209UINT32\r
210EFIAPI\r
211IoWrite32 (\r
212 IN UINT64 Port,\r
213 IN UINT32 Data\r
214 )\r
215{\r
216 UINT64 Address;\r
217\r
218 //\r
219 // Add the 64MB aligned IO Port space to the IO address\r
220 //\r
221 Address = MAP_PORT_BASE_TO_MEM (Port);\r
222 Address += PcdGet64(PcdIoBlockBaseAddressForIpf);\r
223\r
224 return MmioWrite32 (Address, Data);\r
225}\r
226\r
227/**\r
228 Writes a 64-bit I/O port.\r
229\r
230 Writes the 64-bit I/O port specified by Port with the value specified by Value\r
231 and returns Value. This function must guarantee that all I/O read and write\r
232 operations are serialized.\r
233\r
234 If 64-bit I/O port operations are not supported, then ASSERT().\r
235\r
236 @param Port The I/O port to write.\r
237 @param Value The value to write to the I/O port.\r
238\r
239 @return The value written the I/O port.\r
240\r
241**/\r
242UINT64\r
243EFIAPI\r
244IoWrite64 (\r
245 IN UINTN Port,\r
246 IN UINT64 Value\r
247 )\r
248{\r
249 ASSERT (FALSE);\r
250 return 0;\r
251}\r
252\r
253/**\r
254 Reads a 8-bit MMIO register.\r
255\r
256 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is\r
257 returned. This function must guarantee that all MMIO read and write\r
258 operations are serialized.\r
259\r
260 @param Address The MMIO register to read.\r
261\r
262 @return The value read.\r
263\r
264**/\r
265UINT8\r
266EFIAPI\r
267MmioRead8 (\r
268 IN UINT64 Address\r
269 )\r
270{\r
271 UINT8 Data;\r
272\r
273 Address |= BIT63;\r
274\r
275 MemoryFence ();\r
276 Data = *((volatile UINT8 *) Address);\r
277 MemoryFence ();\r
278\r
279 return Data;\r
280}\r
281\r
282/**\r
283 Reads a 16-bit MMIO register.\r
284\r
285 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is\r
286 returned. This function must guarantee that all MMIO read and write\r
287 operations are serialized.\r
288\r
289 @param Address The MMIO register to read.\r
290\r
291 @return The value read.\r
292\r
293**/\r
294UINT16\r
295EFIAPI\r
296MmioRead16 (\r
297 IN UINT64 Address\r
298 )\r
299{\r
300 UINT16 Data;\r
301\r
302 Address |= BIT63;\r
303\r
304 MemoryFence ();\r
305 Data = *((volatile UINT16 *) Address);\r
306 MemoryFence ();\r
307\r
308 return Data;\r
309}\r
310\r
311/**\r
312 Reads a 32-bit MMIO register.\r
313\r
314 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is\r
315 returned. This function must guarantee that all MMIO read and write\r
316 operations are serialized.\r
317\r
318 @param Address The MMIO register to read.\r
319\r
320 @return The value read.\r
321\r
322**/\r
323UINT32\r
324EFIAPI\r
325MmioRead32 (\r
326 IN UINT64 Address\r
327 )\r
328{\r
329 UINT32 Data;\r
330\r
331 Address |= BIT63;\r
332\r
333 MemoryFence ();\r
334 Data = *((volatile UINT32 *) Address);\r
335 MemoryFence ();\r
336\r
337 return Data;\r
338}\r
339\r
340/**\r
341 Reads a 64-bit MMIO register.\r
342\r
343 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is\r
344 returned. This function must guarantee that all MMIO read and write\r
345 operations are serialized.\r
346\r
347 @param Address The MMIO register to read.\r
348\r
349 @return The value read.\r
350\r
351**/\r
352UINT64\r
353EFIAPI\r
354MmioRead64 (\r
355 IN UINT64 Address\r
356 )\r
357{\r
358 UINT64 Data;\r
359\r
360 Address |= BIT63;\r
361\r
362 MemoryFence ();\r
363 Data = *((volatile UINT64 *) Address);\r
364 MemoryFence ();\r
365\r
366 return Data;\r
367\r
368}\r
369\r
370/**\r
371 Writes a 8-bit MMIO register.\r
372\r
373 Writes the 8-bit MMIO register specified by Address with the value specified\r
374 by Value and returns Value. This function must guarantee that all MMIO read\r
375 and write operations are serialized.\r
376\r
377 @param Address The MMIO register to write.\r
378 @param Data The value to write to the MMIO register.\r
379\r
380 @return The value written the memory address.\r
381\r
382**/\r
383UINT8\r
384EFIAPI\r
385MmioWrite8 (\r
386 IN UINT64 Address,\r
387 IN UINT8 Data\r
388 )\r
389{\r
390 Address |= BIT63;\r
391\r
392 MemoryFence ();\r
393 *((volatile UINT8 *) Address) = Data;\r
394 MemoryFence ();\r
395\r
396 return Data;\r
397}\r
398\r
399/**\r
400 Writes a 16-bit MMIO register.\r
401\r
402 Writes the 16-bit MMIO register specified by Address with the value specified\r
403 by Value and returns Value. This function must guarantee that all MMIO read\r
404 and write operations are serialized.\r
405\r
406 @param Address The MMIO register to write.\r
407 @param Data The value to write to the MMIO register.\r
408\r
409 @return The value written the memory address.\r
410\r
411**/\r
412UINT16\r
413EFIAPI\r
414MmioWrite16 (\r
415 IN UINT64 Address,\r
416 IN UINT16 Data\r
417 )\r
418{\r
419 Address |= BIT63;\r
420\r
421 MemoryFence ();\r
422 *((volatile UINT16 *) Address) = Data;\r
423 MemoryFence ();\r
424\r
425 return Data;\r
426}\r
427\r
428/**\r
429 Writes a 32-bit MMIO register.\r
430\r
431 Writes the 32-bit MMIO register specified by Address with the value specified\r
432 by Value and returns Value. This function must guarantee that all MMIO read\r
433 and write operations are serialized.\r
434\r
435 @param Address The MMIO register to write.\r
436 @param Data The value to write to the MMIO register.\r
437\r
438 @return The value written the memory address.\r
439\r
440**/\r
441UINT32\r
442EFIAPI\r
443MmioWrite32 (\r
444 IN UINT64 Address,\r
445 IN UINT32 Data\r
446 )\r
447{\r
448 Address |= BIT63;\r
449\r
450 MemoryFence ();\r
451 *((volatile UINT32 *) Address) = Data;\r
452 MemoryFence ();\r
453\r
454 return Data;\r
455}\r
456\r
457/**\r
458 Writes a 64-bit MMIO register.\r
459\r
460 Writes the 64-bit MMIO register specified by Address with the value specified\r
461 by Value and returns Value. This function must guarantee that all MMIO read\r
462 and write operations are serialized.\r
463\r
464 @param Address The MMIO register to write.\r
465 @param Data The value to write to the MMIO register.\r
466\r
467 @return The value written the memory address.\r
468\r
469**/\r
470UINT64\r
471EFIAPI\r
472MmioWrite64 (\r
473 IN UINT64 Address,\r
474 IN UINT64 Data\r
475 )\r
476{\r
477 Address |= BIT63;\r
478\r
479 MemoryFence ();\r
480 *((volatile UINT64 *) Address) = Data;\r
481 MemoryFence ();\r
482\r
483 return Data;\r
484}\r