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