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