]>
Commit | Line | Data |
---|---|---|
878ddf1f | 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, 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 | |
22 | Module Name: IoLibGcc.c\r | |
23 | \r | |
24 | **/\r | |
25 | \r | |
26 | #ifdef __GNUC__\r | |
27 | \r | |
2ce31132 | 28 | /**\r |
29 | Reads an 8-bit MMIO register.\r | |
30 | \r | |
31 | Reads the 8-bit MMIO register specified by Address. The 8-bit read value is\r | |
32 | returned. This function must guarantee that all MMIO read and write\r | |
33 | operations are serialized.\r | |
34 | \r | |
35 | If 8-bit MMIO register operations are not supported, then ASSERT().\r | |
36 | \r | |
37 | @param Address The MMIO register to read.\r | |
38 | \r | |
39 | @return The value read.\r | |
40 | \r | |
41 | **/\r | |
42 | UINT8\r | |
43 | EFIAPI\r | |
44 | MmioRead8 (\r | |
45 | IN UINTN Address\r | |
46 | )\r | |
47 | {\r | |
48 | return *(volatile UINT8*)Address;\r | |
49 | }\r | |
50 | \r | |
51 | /**\r | |
52 | Writes an 8-bit MMIO register.\r | |
53 | \r | |
54 | Writes the 8-bit MMIO register specified by Address with the value specified\r | |
55 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
56 | and write operations are serialized.\r | |
57 | \r | |
58 | If 8-bit MMIO register operations are not supported, then ASSERT().\r | |
59 | \r | |
60 | @param Address The MMIO register to write.\r | |
61 | @param Value The value to write to the MMIO register.\r | |
62 | \r | |
63 | **/\r | |
64 | UINT8\r | |
65 | EFIAPI\r | |
66 | MmioWrite8 (\r | |
67 | IN UINTN Address,\r | |
68 | IN UINT8 Value\r | |
69 | )\r | |
70 | {\r | |
71 | return *(volatile UINT8*)Address = Value;\r | |
72 | }\r | |
73 | \r | |
74 | /**\r | |
75 | Reads a 16-bit MMIO register.\r | |
76 | \r | |
77 | Reads the 16-bit MMIO register specified by Address. The 16-bit read value is\r | |
78 | returned. This function must guarantee that all MMIO read and write\r | |
79 | operations are serialized.\r | |
80 | \r | |
81 | If 16-bit MMIO register operations are not supported, then ASSERT().\r | |
82 | \r | |
83 | @param Address The MMIO register to read.\r | |
84 | \r | |
85 | @return The value read.\r | |
86 | \r | |
87 | **/\r | |
88 | UINT16\r | |
89 | EFIAPI\r | |
90 | MmioRead16 (\r | |
91 | IN UINTN Address\r | |
92 | )\r | |
93 | {\r | |
94 | ASSERT ((Address & 1) == 0);\r | |
95 | return *(volatile UINT16*)Address;\r | |
96 | }\r | |
97 | \r | |
98 | /**\r | |
99 | Writes a 16-bit MMIO register.\r | |
100 | \r | |
101 | Writes the 16-bit MMIO register specified by Address with the value specified\r | |
102 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
103 | and write operations are serialized.\r | |
104 | \r | |
105 | If 16-bit MMIO register operations are not supported, then ASSERT().\r | |
106 | \r | |
107 | @param Address The MMIO register to write.\r | |
108 | @param Value The value to write to the MMIO register.\r | |
109 | \r | |
110 | **/\r | |
111 | UINT16\r | |
112 | EFIAPI\r | |
113 | MmioWrite16 (\r | |
114 | IN UINTN Address,\r | |
115 | IN UINT16 Value\r | |
116 | )\r | |
117 | {\r | |
118 | ASSERT ((Address & 1) == 0);\r | |
119 | return *(volatile UINT16*)Address = Value;\r | |
120 | }\r | |
121 | \r | |
122 | /**\r | |
123 | Reads a 32-bit MMIO register.\r | |
124 | \r | |
125 | Reads the 32-bit MMIO register specified by Address. The 32-bit read value is\r | |
126 | returned. This function must guarantee that all MMIO read and write\r | |
127 | operations are serialized.\r | |
128 | \r | |
129 | If 32-bit MMIO register operations are not supported, then ASSERT().\r | |
130 | \r | |
131 | @param Address The MMIO register to read.\r | |
132 | \r | |
133 | @return The value read.\r | |
134 | \r | |
135 | **/\r | |
136 | UINT32\r | |
137 | EFIAPI\r | |
138 | MmioRead32 (\r | |
139 | IN UINTN Address\r | |
140 | )\r | |
141 | {\r | |
142 | ASSERT ((Address & 3) == 0);\r | |
143 | return *(volatile UINT32*)Address;\r | |
144 | }\r | |
145 | \r | |
146 | /**\r | |
147 | Writes a 32-bit MMIO register.\r | |
148 | \r | |
149 | Writes the 32-bit MMIO register specified by Address with the value specified\r | |
150 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
151 | and write operations are serialized.\r | |
152 | \r | |
153 | If 32-bit MMIO register operations are not supported, then ASSERT().\r | |
154 | \r | |
155 | @param Address The MMIO register to write.\r | |
156 | @param Value The value to write to the MMIO register.\r | |
157 | \r | |
158 | **/\r | |
159 | UINT32\r | |
160 | EFIAPI\r | |
161 | MmioWrite32 (\r | |
162 | IN UINTN Address,\r | |
163 | IN UINT32 Value\r | |
164 | )\r | |
165 | {\r | |
166 | ASSERT ((Address & 3) == 0);\r | |
167 | return *(volatile UINT32*)Address = Value;\r | |
168 | }\r | |
169 | \r | |
170 | /**\r | |
171 | Reads a 64-bit MMIO register.\r | |
172 | \r | |
173 | Reads the 64-bit MMIO register specified by Address. The 64-bit read value is\r | |
174 | returned. This function must guarantee that all MMIO read and write\r | |
175 | operations are serialized.\r | |
176 | \r | |
177 | If 64-bit MMIO register operations are not supported, then ASSERT().\r | |
178 | \r | |
179 | @param Address The MMIO register to read.\r | |
180 | \r | |
181 | @return The value read.\r | |
182 | \r | |
183 | **/\r | |
184 | UINT64\r | |
185 | EFIAPI\r | |
186 | MmioRead64 (\r | |
187 | IN UINTN Address\r | |
188 | )\r | |
189 | {\r | |
190 | ASSERT ((Address & 7) == 0);\r | |
191 | return *(volatile UINT64*)Address;\r | |
192 | }\r | |
193 | \r | |
194 | /**\r | |
195 | Writes a 64-bit MMIO register.\r | |
196 | \r | |
197 | Writes the 64-bit MMIO register specified by Address with the value specified\r | |
198 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
199 | and write operations are serialized.\r | |
200 | \r | |
201 | If 64-bit MMIO register operations are not supported, then ASSERT().\r | |
202 | \r | |
203 | @param Address The MMIO register to write.\r | |
204 | @param Value The value to write to the MMIO register.\r | |
205 | \r | |
206 | **/\r | |
207 | UINT64\r | |
208 | EFIAPI\r | |
209 | MmioWrite64 (\r | |
210 | IN UINTN Address,\r | |
211 | IN UINT64 Value\r | |
212 | )\r | |
213 | {\r | |
214 | ASSERT ((Address & 7) == 0);\r | |
215 | return *(volatile UINT64*)Address = Value;\r | |
216 | }\r | |
217 | \r | |
218 | \r | |
219 | \r | |
878ddf1f | 220 | /**\r |
221 | Reads an 8-bit I/O port.\r | |
222 | \r | |
223 | Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r | |
224 | This function must guarantee that all I/O read and write operations are\r | |
225 | serialized.\r | |
226 | \r | |
227 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
228 | \r | |
229 | @param Port The I/O port to read.\r | |
230 | \r | |
231 | @return The value read.\r | |
232 | \r | |
233 | **/\r | |
234 | __inline__\r | |
235 | UINT8\r | |
236 | EFIAPI\r | |
237 | IoRead8 (\r | |
238 | IN UINTN Port\r | |
239 | )\r | |
240 | {\r | |
241 | UINT8 Data;\r | |
242 | \r | |
243 | __asm__ __volatile__ ("inb %w1,%b0" : "=a" (Data) : "d" ((UINT16)Port));\r | |
244 | return Data;\r | |
245 | }\r | |
246 | \r | |
247 | /**\r | |
248 | Writes an 8-bit I/O port.\r | |
249 | \r | |
250 | Writes the 8-bit I/O port specified by Port with the value specified by Value\r | |
251 | and returns Value. This function must guarantee that all I/O read and write\r | |
252 | operations are serialized.\r | |
253 | \r | |
254 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
255 | \r | |
256 | @param Port The I/O port to write.\r | |
257 | @param Value The value to write to the I/O port.\r | |
258 | \r | |
259 | @return The value written the I/O port.\r | |
260 | \r | |
261 | **/\r | |
262 | __inline__\r | |
263 | UINT8\r | |
264 | EFIAPI\r | |
265 | IoWrite8 (\r | |
266 | IN UINTN Port,\r | |
267 | IN UINT8 Value\r | |
268 | )\r | |
269 | {\r | |
270 | __asm__ __volatile__ ("outb %b0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r | |
271 | return Value;;\r | |
272 | }\r | |
273 | \r | |
274 | /**\r | |
275 | Reads a 16-bit I/O port.\r | |
276 | \r | |
277 | Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r | |
278 | This function must guarantee that all I/O read and write operations are\r | |
279 | serialized.\r | |
280 | \r | |
281 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
282 | \r | |
283 | @param Port The I/O port to read.\r | |
284 | \r | |
285 | @return The value read.\r | |
286 | \r | |
287 | **/\r | |
288 | __inline__\r | |
289 | UINT16\r | |
290 | EFIAPI\r | |
291 | IoRead16 (\r | |
292 | IN UINTN Port\r | |
293 | )\r | |
294 | {\r | |
295 | UINT16 Data;\r | |
296 | \r | |
297 | ASSERT ((Port & 1) == 0);\r | |
298 | __asm__ __volatile__ ("inw %w1,%w0" : "=a" (Data) : "d" ((UINT16)Port));\r | |
299 | return Data;\r | |
300 | }\r | |
301 | \r | |
302 | /**\r | |
303 | Writes a 16-bit I/O port.\r | |
304 | \r | |
305 | Writes the 16-bit I/O port specified by Port with the value specified by Value\r | |
306 | and returns Value. This function must guarantee that all I/O read and write\r | |
307 | operations are serialized.\r | |
308 | \r | |
309 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
310 | \r | |
311 | @param Port The I/O port to write.\r | |
312 | @param Value The value to write to the I/O port.\r | |
313 | \r | |
314 | @return The value written the I/O port.\r | |
315 | \r | |
316 | **/\r | |
317 | __inline__\r | |
318 | UINT16\r | |
319 | EFIAPI\r | |
320 | IoWrite16 (\r | |
321 | IN UINTN Port,\r | |
322 | IN UINT16 Value\r | |
323 | )\r | |
324 | {\r | |
325 | ASSERT ((Port & 1) == 0);\r | |
326 | __asm__ __volatile__ ("outw %w0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r | |
327 | return Value;;\r | |
328 | }\r | |
329 | \r | |
330 | /**\r | |
331 | Reads a 32-bit I/O port.\r | |
332 | \r | |
333 | Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r | |
334 | This function must guarantee that all I/O read and write operations are\r | |
335 | serialized.\r | |
336 | \r | |
337 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
338 | \r | |
339 | @param Port The I/O port to read.\r | |
340 | \r | |
341 | @return The value read.\r | |
342 | \r | |
343 | **/\r | |
344 | __inline__\r | |
345 | UINT32\r | |
346 | EFIAPI\r | |
347 | IoRead32 (\r | |
348 | IN UINTN Port\r | |
349 | )\r | |
350 | {\r | |
351 | UINT32 Data;\r | |
352 | \r | |
353 | ASSERT ((Port & 3) == 0);\r | |
354 | __asm__ __volatile__ ("inl %w1,%0" : "=a" (Data) : "d" ((UINT16)Port));\r | |
355 | return Data;\r | |
356 | }\r | |
357 | \r | |
358 | /**\r | |
359 | Writes a 32-bit I/O port.\r | |
360 | \r | |
361 | Writes the 32-bit I/O port specified by Port with the value specified by Value\r | |
362 | and returns Value. This function must guarantee that all I/O read and write\r | |
363 | operations are serialized.\r | |
364 | \r | |
365 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
366 | \r | |
367 | @param Port The I/O port to write.\r | |
368 | @param Value The value to write to the I/O port.\r | |
369 | \r | |
370 | @return The value written the I/O port.\r | |
371 | \r | |
372 | **/\r | |
373 | __inline__\r | |
374 | UINT32\r | |
375 | EFIAPI\r | |
376 | IoWrite32 (\r | |
377 | IN UINTN Port,\r | |
378 | IN UINT32 Value\r | |
379 | )\r | |
380 | {\r | |
381 | ASSERT ((Port & 3) == 0);\r | |
382 | __asm__ __volatile__ ("outl %0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r | |
383 | return Value;\r | |
384 | }\r | |
385 | \r | |
386 | #endif\r |