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