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