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