]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLib.c
126457a7e59be4dd013db32abf86b361b7837233
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLib.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: IoLib.c
14
15 **/
16
17 /**
18 Reads a 64-bit I/O port.
19
20 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
21 This function must guarantee that all I/O read and write operations are
22 serialized.
23
24 If 64-bit I/O port operations are not supported, then ASSERT().
25
26 @param Port The I/O port to read.
27
28 @return The value read.
29
30 **/
31 UINT64
32 EFIAPI
33 IoRead64 (
34 IN UINTN Port
35 )
36 {
37 ASSERT (FALSE);
38 return 0;
39 }
40
41 /**
42 Writes a 64-bit I/O port.
43
44 Writes the 64-bit I/O port specified by Port with the value specified by Value
45 and returns Value. This function must guarantee that all I/O read and write
46 operations are serialized.
47
48 If 64-bit I/O port operations are not supported, then ASSERT().
49
50 @param Port The I/O port to write.
51 @param Value The value to write to the I/O port.
52
53 @return The value written the I/O port.
54
55 **/
56 UINT64
57 EFIAPI
58 IoWrite64 (
59 IN UINTN Port,
60 IN UINT64 Value
61 )
62 {
63 ASSERT (FALSE);
64 return 0;
65 }
66
67 /**
68 Reads an 8-bit MMIO register.
69
70 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
71 returned. This function must guarantee that all MMIO read and write
72 operations are serialized.
73
74 If 8-bit MMIO register operations are not supported, then ASSERT().
75
76 @param Address The MMIO register to read.
77
78 @return The value read.
79
80 **/
81 UINT8
82 EFIAPI
83 MmioRead8 (
84 IN UINTN Address
85 )
86 {
87 return *(volatile UINT8*)Address;
88 }
89
90 /**
91 Writes an 8-bit MMIO register.
92
93 Writes the 8-bit MMIO register specified by Address with the value specified
94 by Value and returns Value. This function must guarantee that all MMIO read
95 and write operations are serialized.
96
97 If 8-bit MMIO register operations are not supported, then ASSERT().
98
99 @param Address The MMIO register to write.
100 @param Value The value to write to the MMIO register.
101
102 **/
103 UINT8
104 EFIAPI
105 MmioWrite8 (
106 IN UINTN Address,
107 IN UINT8 Value
108 )
109 {
110 return *(volatile UINT8*)Address = Value;
111 }
112
113 /**
114 Reads a 16-bit MMIO register.
115
116 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
117 returned. This function must guarantee that all MMIO read and write
118 operations are serialized.
119
120 If 16-bit MMIO register operations are not supported, then ASSERT().
121
122 @param Address The MMIO register to read.
123
124 @return The value read.
125
126 **/
127 UINT16
128 EFIAPI
129 MmioRead16 (
130 IN UINTN Address
131 )
132 {
133 ASSERT ((Address & 1) == 0);
134 return *(volatile UINT16*)Address;
135 }
136
137 /**
138 Writes a 16-bit MMIO register.
139
140 Writes the 16-bit MMIO register specified by Address with the value specified
141 by Value and returns Value. This function must guarantee that all MMIO read
142 and write operations are serialized.
143
144 If 16-bit MMIO register operations are not supported, then ASSERT().
145
146 @param Address The MMIO register to write.
147 @param Value The value to write to the MMIO register.
148
149 **/
150 UINT16
151 EFIAPI
152 MmioWrite16 (
153 IN UINTN Address,
154 IN UINT16 Value
155 )
156 {
157 ASSERT ((Address & 1) == 0);
158 return *(volatile UINT16*)Address = Value;
159 }
160
161 /**
162 Reads a 32-bit MMIO register.
163
164 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
165 returned. This function must guarantee that all MMIO read and write
166 operations are serialized.
167
168 If 32-bit MMIO register operations are not supported, then ASSERT().
169
170 @param Address The MMIO register to read.
171
172 @return The value read.
173
174 **/
175 UINT32
176 EFIAPI
177 MmioRead32 (
178 IN UINTN Address
179 )
180 {
181 ASSERT ((Address & 3) == 0);
182 return *(volatile UINT32*)Address;
183 }
184
185 /**
186 Writes a 32-bit MMIO register.
187
188 Writes the 32-bit MMIO register specified by Address with the value specified
189 by Value and returns Value. This function must guarantee that all MMIO read
190 and write operations are serialized.
191
192 If 32-bit MMIO register operations are not supported, then ASSERT().
193
194 @param Address The MMIO register to write.
195 @param Value The value to write to the MMIO register.
196
197 **/
198 UINT32
199 EFIAPI
200 MmioWrite32 (
201 IN UINTN Address,
202 IN UINT32 Value
203 )
204 {
205 ASSERT ((Address & 3) == 0);
206 return *(volatile UINT32*)Address = Value;
207 }
208
209 /**
210 Reads a 64-bit MMIO register.
211
212 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
213 returned. This function must guarantee that all MMIO read and write
214 operations are serialized.
215
216 If 64-bit MMIO register operations are not supported, then ASSERT().
217
218 @param Address The MMIO register to read.
219
220 @return The value read.
221
222 **/
223 UINT64
224 EFIAPI
225 MmioRead64 (
226 IN UINTN Address
227 )
228 {
229 ASSERT ((Address & 7) == 0);
230 return *(volatile UINT64*)Address;
231 }
232
233 /**
234 Writes a 64-bit MMIO register.
235
236 Writes the 64-bit MMIO register specified by Address with the value specified
237 by Value and returns Value. This function must guarantee that all MMIO read
238 and write operations are serialized.
239
240 If 64-bit MMIO register operations are not supported, then ASSERT().
241
242 @param Address The MMIO register to write.
243 @param Value The value to write to the MMIO register.
244
245 **/
246 UINT64
247 EFIAPI
248 MmioWrite64 (
249 IN UINTN Address,
250 IN UINT64 Value
251 )
252 {
253 ASSERT ((Address & 7) == 0);
254 return *(volatile UINT64*)Address = Value;
255 }