]>
Commit | Line | Data |
---|---|---|
e1f414b6 | 1 | /** @file\r |
2 | I/O Library. This file has compiler specifics for GCC as there is no\r | |
3 | ANSI C standard for doing IO.\r | |
4 | \r | |
5 | GCC - uses EFIAPI assembler. __asm__ calls GAS. __volatile__ makes sure the\r | |
6 | compiler puts the assembler in this exact location. The complex GNUC\r | |
7 | operations are not optimzed. It would be possible to also write these\r | |
8 | with EFIAPI assembler.\r | |
9 | \r | |
10 | We don't advocate putting compiler specifics in libraries or drivers but there\r | |
11 | is no other way to make this work.\r | |
12 | \r | |
13 | Copyright (c) 2006 - 2007, Intel Corporation<BR>\r | |
14 | All rights reserved. This program and the accompanying materials\r | |
15 | are licensed and made available under the terms and conditions of the BSD License\r | |
16 | which accompanies this distribution. The full text of the license may be found at\r | |
17 | http://opensource.org/licenses/bsd-license.php\r | |
18 | \r | |
19 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
20 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
21 | \r | |
e1f414b6 | 22 | **/\r |
23 | \r | |
1efcc4ae | 24 | \r |
f734a10a | 25 | #include "BaseIoLibIntrinsicInternal.h"\r |
e1f414b6 | 26 | \r |
27 | /**\r | |
28 | Reads an 8-bit MMIO register.\r | |
29 | \r | |
30 | Reads the 8-bit MMIO register specified by Address. The 8-bit read value is\r | |
31 | returned. This function must guarantee that all MMIO read and write\r | |
32 | operations are serialized.\r | |
33 | \r | |
34 | If 8-bit MMIO register operations are not supported, then ASSERT().\r | |
35 | \r | |
36 | @param Address The MMIO register to read.\r | |
37 | \r | |
38bbd3d9 | 38 | @return The value read from Address.\r |
e1f414b6 | 39 | \r |
40 | **/\r | |
41 | UINT8\r | |
42 | EFIAPI\r | |
43 | MmioRead8 (\r | |
44 | IN UINTN Address\r | |
45 | )\r | |
46 | {\r | |
47 | return *(volatile UINT8*)Address;\r | |
48 | }\r | |
49 | \r | |
50 | /**\r | |
51 | Writes an 8-bit MMIO register.\r | |
52 | \r | |
53 | Writes the 8-bit MMIO register specified by Address with the value specified\r | |
54 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
55 | and write operations are serialized.\r | |
56 | \r | |
57 | If 8-bit MMIO register operations are not supported, then ASSERT().\r | |
58 | \r | |
59 | @param Address The MMIO register to write.\r | |
60 | @param Value The value to write to the MMIO register.\r | |
61 | \r | |
38bbd3d9 | 62 | @return The value written to the Mmio. It equals to the input\r |
63 | Value instead of the actual value read back from the\r | |
64 | Mmio.\r | |
e1f414b6 | 65 | **/\r |
66 | UINT8\r | |
67 | EFIAPI\r | |
68 | MmioWrite8 (\r | |
69 | IN UINTN Address,\r | |
70 | IN UINT8 Value\r | |
71 | )\r | |
72 | {\r | |
73 | return *(volatile UINT8*)Address = Value;\r | |
74 | }\r | |
75 | \r | |
76 | /**\r | |
77 | Reads a 16-bit MMIO register.\r | |
78 | \r | |
79 | Reads the 16-bit MMIO register specified by Address. The 16-bit read value is\r | |
80 | returned. This function must guarantee that all MMIO read and write\r | |
81 | operations are serialized.\r | |
82 | \r | |
83 | If 16-bit MMIO register operations are not supported, then ASSERT().\r | |
84 | \r | |
85 | @param Address The MMIO register to read.\r | |
86 | \r | |
38bbd3d9 | 87 | @return The value read from Address.\r |
e1f414b6 | 88 | \r |
89 | **/\r | |
90 | UINT16\r | |
91 | EFIAPI\r | |
92 | MmioRead16 (\r | |
93 | IN UINTN Address\r | |
94 | )\r | |
95 | {\r | |
96 | ASSERT ((Address & 1) == 0);\r | |
97 | return *(volatile UINT16*)Address;\r | |
98 | }\r | |
99 | \r | |
100 | /**\r | |
101 | Writes a 16-bit MMIO register.\r | |
102 | \r | |
103 | Writes the 16-bit MMIO register specified by Address with the value specified\r | |
104 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
105 | and write operations are serialized.\r | |
106 | \r | |
107 | If 16-bit MMIO register operations are not supported, then ASSERT().\r | |
108 | \r | |
109 | @param Address The MMIO register to write.\r | |
110 | @param Value The value to write to the MMIO register.\r | |
111 | \r | |
38bbd3d9 | 112 | @return The value written to the Mmio. It equals to the input\r |
113 | Value instead of the actual value read back from the\r | |
114 | Mmio.\r | |
e1f414b6 | 115 | **/\r |
116 | UINT16\r | |
117 | EFIAPI\r | |
118 | MmioWrite16 (\r | |
119 | IN UINTN Address,\r | |
120 | IN UINT16 Value\r | |
121 | )\r | |
122 | {\r | |
123 | ASSERT ((Address & 1) == 0);\r | |
124 | return *(volatile UINT16*)Address = Value;\r | |
125 | }\r | |
126 | \r | |
127 | /**\r | |
128 | Reads a 32-bit MMIO register.\r | |
129 | \r | |
130 | Reads the 32-bit MMIO register specified by Address. The 32-bit read value is\r | |
131 | returned. This function must guarantee that all MMIO read and write\r | |
132 | operations are serialized.\r | |
133 | \r | |
134 | If 32-bit MMIO register operations are not supported, then ASSERT().\r | |
135 | \r | |
136 | @param Address The MMIO register to read.\r | |
137 | \r | |
38bbd3d9 | 138 | @return The value read from Address.\r |
e1f414b6 | 139 | \r |
140 | **/\r | |
141 | UINT32\r | |
142 | EFIAPI\r | |
143 | MmioRead32 (\r | |
144 | IN UINTN Address\r | |
145 | )\r | |
146 | {\r | |
147 | ASSERT ((Address & 3) == 0);\r | |
148 | return *(volatile UINT32*)Address;\r | |
149 | }\r | |
150 | \r | |
151 | /**\r | |
152 | Writes a 32-bit MMIO register.\r | |
153 | \r | |
154 | Writes the 32-bit MMIO register specified by Address with the value specified\r | |
155 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
156 | and write operations are serialized.\r | |
157 | \r | |
158 | If 32-bit MMIO register operations are not supported, then ASSERT().\r | |
159 | \r | |
160 | @param Address The MMIO register to write.\r | |
161 | @param Value The value to write to the MMIO register.\r | |
162 | \r | |
38bbd3d9 | 163 | @return The value written to the Mmio. It equals to the input\r |
164 | Value instead of the actual value read back from the\r | |
165 | Mmio.\r | |
e1f414b6 | 166 | **/\r |
167 | UINT32\r | |
168 | EFIAPI\r | |
169 | MmioWrite32 (\r | |
170 | IN UINTN Address,\r | |
171 | IN UINT32 Value\r | |
172 | )\r | |
173 | {\r | |
174 | ASSERT ((Address & 3) == 0);\r | |
175 | return *(volatile UINT32*)Address = Value;\r | |
176 | }\r | |
177 | \r | |
178 | /**\r | |
179 | Reads a 64-bit MMIO register.\r | |
180 | \r | |
181 | Reads the 64-bit MMIO register specified by Address. The 64-bit read value is\r | |
182 | returned. This function must guarantee that all MMIO read and write\r | |
183 | operations are serialized.\r | |
184 | \r | |
185 | If 64-bit MMIO register operations are not supported, then ASSERT().\r | |
186 | \r | |
187 | @param Address The MMIO register to read.\r | |
188 | \r | |
38bbd3d9 | 189 | @return The value read from Address.\r |
e1f414b6 | 190 | \r |
191 | **/\r | |
192 | UINT64\r | |
193 | EFIAPI\r | |
194 | MmioRead64 (\r | |
195 | IN UINTN Address\r | |
196 | )\r | |
197 | {\r | |
198 | ASSERT ((Address & 7) == 0);\r | |
199 | return *(volatile UINT64*)Address;\r | |
200 | }\r | |
201 | \r | |
202 | /**\r | |
203 | Writes a 64-bit MMIO register.\r | |
204 | \r | |
205 | Writes the 64-bit MMIO register specified by Address with the value specified\r | |
206 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
207 | and write operations are serialized.\r | |
208 | \r | |
209 | If 64-bit MMIO register operations are not supported, then ASSERT().\r | |
210 | \r | |
211 | @param Address The MMIO register to write.\r | |
212 | @param Value The value to write to the MMIO register.\r | |
213 | \r | |
38bbd3d9 | 214 | @return The value written to the Mmio. It equals to the input\r |
215 | Value instead of the actual value read back from the\r | |
216 | Mmio.\r | |
e1f414b6 | 217 | **/\r |
218 | UINT64\r | |
219 | EFIAPI\r | |
220 | MmioWrite64 (\r | |
221 | IN UINTN Address,\r | |
222 | IN UINT64 Value\r | |
223 | )\r | |
224 | {\r | |
225 | ASSERT ((Address & 7) == 0);\r | |
226 | return *(volatile UINT64*)Address = Value;\r | |
227 | }\r | |
228 | \r | |
229 | \r | |
230 | \r | |
231 | /**\r | |
232 | Reads an 8-bit I/O port.\r | |
233 | \r | |
234 | Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r | |
235 | This function must guarantee that all I/O read and write operations are\r | |
236 | serialized.\r | |
237 | \r | |
238 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
239 | \r | |
240 | @param Port The I/O port to read.\r | |
241 | \r | |
38bbd3d9 | 242 | @return The value read from Port.\r |
e1f414b6 | 243 | \r |
244 | **/\r | |
245 | __inline__\r | |
246 | UINT8\r | |
247 | EFIAPI\r | |
248 | IoRead8 (\r | |
249 | IN UINTN Port\r | |
250 | )\r | |
251 | {\r | |
252 | UINT8 Data;\r | |
253 | \r | |
254 | __asm__ __volatile__ ("inb %w1,%b0" : "=a" (Data) : "d" ((UINT16)Port));\r | |
255 | return Data;\r | |
256 | }\r | |
257 | \r | |
258 | /**\r | |
259 | Writes an 8-bit I/O port.\r | |
260 | \r | |
261 | Writes the 8-bit I/O port specified by Port with the value specified by Value\r | |
262 | and returns Value. This function must guarantee that all I/O read and write\r | |
263 | operations are serialized.\r | |
264 | \r | |
265 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
266 | \r | |
267 | @param Port The I/O port to write.\r | |
268 | @param Value The value to write to the I/O port.\r | |
269 | \r | |
38bbd3d9 | 270 | @return The value written to the I/O port. It equals to the\r |
271 | input Value instead of the actual value read back from\r | |
272 | the I/O port.\r | |
e1f414b6 | 273 | \r |
274 | **/\r | |
275 | __inline__\r | |
276 | UINT8\r | |
277 | EFIAPI\r | |
278 | IoWrite8 (\r | |
279 | IN UINTN Port,\r | |
280 | IN UINT8 Value\r | |
281 | )\r | |
282 | {\r | |
283 | __asm__ __volatile__ ("outb %b0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r | |
284 | return Value;;\r | |
285 | }\r | |
286 | \r | |
287 | /**\r | |
288 | Reads a 16-bit I/O port.\r | |
289 | \r | |
290 | Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r | |
291 | This function must guarantee that all I/O read and write operations are\r | |
292 | serialized.\r | |
293 | \r | |
294 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
295 | \r | |
296 | @param Port The I/O port to read.\r | |
297 | \r | |
38bbd3d9 | 298 | @return The value read from Port.\r |
e1f414b6 | 299 | \r |
300 | **/\r | |
301 | __inline__\r | |
302 | UINT16\r | |
303 | EFIAPI\r | |
304 | IoRead16 (\r | |
305 | IN UINTN Port\r | |
306 | )\r | |
307 | {\r | |
308 | UINT16 Data;\r | |
309 | \r | |
310 | ASSERT ((Port & 1) == 0);\r | |
311 | __asm__ __volatile__ ("inw %w1,%w0" : "=a" (Data) : "d" ((UINT16)Port));\r | |
312 | return Data;\r | |
313 | }\r | |
314 | \r | |
315 | /**\r | |
316 | Writes a 16-bit I/O port.\r | |
317 | \r | |
318 | Writes the 16-bit I/O port specified by Port with the value specified by Value\r | |
319 | and returns Value. This function must guarantee that all I/O read and write\r | |
320 | operations are serialized.\r | |
321 | \r | |
322 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
323 | \r | |
324 | @param Port The I/O port to write.\r | |
325 | @param Value The value to write to the I/O port.\r | |
326 | \r | |
38bbd3d9 | 327 | @return The value written to the I/O port. It equals to the\r |
328 | input Value instead of the actual value read back from\r | |
329 | the I/O port.\r | |
e1f414b6 | 330 | \r |
331 | **/\r | |
332 | __inline__\r | |
333 | UINT16\r | |
334 | EFIAPI\r | |
335 | IoWrite16 (\r | |
336 | IN UINTN Port,\r | |
337 | IN UINT16 Value\r | |
338 | )\r | |
339 | {\r | |
340 | ASSERT ((Port & 1) == 0);\r | |
341 | __asm__ __volatile__ ("outw %w0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r | |
342 | return Value;;\r | |
343 | }\r | |
344 | \r | |
345 | /**\r | |
346 | Reads a 32-bit I/O port.\r | |
347 | \r | |
348 | Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r | |
349 | This function must guarantee that all I/O read and write operations are\r | |
350 | serialized.\r | |
351 | \r | |
352 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
353 | \r | |
354 | @param Port The I/O port to read.\r | |
355 | \r | |
38bbd3d9 | 356 | @return The value read from Port.\r |
e1f414b6 | 357 | \r |
358 | **/\r | |
359 | __inline__\r | |
360 | UINT32\r | |
361 | EFIAPI\r | |
362 | IoRead32 (\r | |
363 | IN UINTN Port\r | |
364 | )\r | |
365 | {\r | |
366 | UINT32 Data;\r | |
367 | \r | |
368 | ASSERT ((Port & 3) == 0);\r | |
369 | __asm__ __volatile__ ("inl %w1,%0" : "=a" (Data) : "d" ((UINT16)Port));\r | |
370 | return Data;\r | |
371 | }\r | |
372 | \r | |
373 | /**\r | |
374 | Writes a 32-bit I/O port.\r | |
375 | \r | |
376 | Writes the 32-bit I/O port specified by Port with the value specified by Value\r | |
377 | and returns Value. This function must guarantee that all I/O read and write\r | |
378 | operations are serialized.\r | |
379 | \r | |
380 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
381 | \r | |
382 | @param Port The I/O port to write.\r | |
383 | @param Value The value to write to the I/O port.\r | |
384 | \r | |
38bbd3d9 | 385 | @return The value written to the I/O port. It equals to the\r |
386 | input Value instead of the actual value read back from\r | |
387 | the I/O port.\r | |
e1f414b6 | 388 | \r |
389 | **/\r | |
390 | __inline__\r | |
391 | UINT32\r | |
392 | EFIAPI\r | |
393 | IoWrite32 (\r | |
394 | IN UINTN Port,\r | |
395 | IN UINT32 Value\r | |
396 | )\r | |
397 | {\r | |
398 | ASSERT ((Port & 3) == 0);\r | |
399 | __asm__ __volatile__ ("outl %0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r | |
400 | return Value;\r | |
401 | }\r | |
402 | \r |