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