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