]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/CpuRuntimeDxe/CpuIo.c
1. remove FirmwareVolumeBlock.h for IntelFrameworkPkg
[mirror_edk2.git] / Nt32Pkg / CpuRuntimeDxe / CpuIo.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 CpuIo.c
15
16 Abstract:
17
18 This is the code that publishes the CPU I/O Protocol.
19 The intent herein is to have a single I/O service that can load
20 as early as possible, extend into runtime, and be layered upon by
21 the implementations of architectural protocols and the PCI Root
22 Bridge I/O Protocol.
23
24 --*/
25
26 //
27 // Include common header file for this module.
28 //
29 #include "CommonHeader.h"
30
31 #include <CpuDriver.h>
32
33 #define IA32_MAX_IO_ADDRESS 0xFFFF
34 #define IA32_MAX_MEM_ADDRESS 0xFFFFFFFF
35
36 EFI_CPU_IO_PROTOCOL mCpuIoProtocol;
37
38 EFI_STATUS
39 CpuIoCheckAddressRange (
40 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
41 IN UINT64 Address,
42 IN UINTN Count,
43 IN VOID *Buffer,
44 IN UINT64 Limit
45 );
46
47 EFI_STATUS
48 EFIAPI
49 CpuMemoryServiceRead (
50 IN EFI_CPU_IO_PROTOCOL *This,
51 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
52 IN UINT64 Address,
53 IN UINTN Count,
54 IN OUT VOID *Buffer
55 )
56 /*++
57
58 Routine Description:
59
60 Perform the Memory Access Read service for the CPU I/O Protocol
61
62 Arguments:
63
64 Pointer to an instance of the CPU I/O Protocol
65 Width of the Memory Access
66 Address of the Memory access
67 Count of the number of accesses to perform
68 Pointer to the buffer to read or write from memory
69
70 Returns:
71
72 Status
73
74 EFI_SUCCESS - The data was read from or written to the EFI
75 System.
76 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
77 EFI_INVALID_PARAMETER - Buffer is NULL.
78 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
79 EFI_UNSUPPORTED - The address range specified by Address, Width,
80 and Count is not valid for this EFI System.
81
82 --*/
83 // TODO: This - add argument and description to function comment
84 {
85 EFI_STATUS Status;
86
87 if (!Buffer) {
88 return EFI_INVALID_PARAMETER;
89 }
90
91 Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);
92 if (EFI_ERROR (Status)) {
93 return Status;
94 }
95
96 //
97 // Do nothing for Nt32 version
98 //
99 return EFI_SUCCESS;
100 }
101
102 EFI_STATUS
103 EFIAPI
104 CpuMemoryServiceWrite (
105 IN EFI_CPU_IO_PROTOCOL *This,
106 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
107 IN UINT64 Address,
108 IN UINTN Count,
109 IN OUT VOID *Buffer
110 )
111 /*++
112
113 Routine Description:
114
115 Perform the Memory Access Read service for the CPU I/O Protocol
116
117 Arguments:
118
119 Pointer to an instance of the CPU I/O Protocol
120 Width of the Memory Access
121 Address of the Memory access
122 Count of the number of accesses to perform
123 Pointer to the buffer to read or write from memory
124
125 Returns:
126
127 Status
128
129 EFI_SUCCESS - The data was read from or written to the EFI System.
130 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
131 EFI_INVALID_PARAMETER - Buffer is NULL.
132 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
133 EFI_UNSUPPORTED - The address range specified by Address, Width, and
134 Count is not valid for this EFI System.
135
136 --*/
137 // TODO: This - add argument and description to function comment
138 {
139 EFI_STATUS Status;
140
141 if (!Buffer) {
142 return EFI_INVALID_PARAMETER;
143 }
144
145 Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);
146 if (EFI_ERROR (Status)) {
147 return Status;
148 }
149
150 //
151 // Do nothing for Nt32 version
152 //
153 return EFI_SUCCESS;
154 }
155
156 EFI_STATUS
157 EFIAPI
158 CpuIoServiceRead (
159 IN EFI_CPU_IO_PROTOCOL *This,
160 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
161 IN UINT64 UserAddress,
162 IN UINTN Count,
163 IN OUT VOID *UserBuffer
164 )
165 /*++
166
167 Routine Description:
168
169 This is the service that implements the I/O read
170
171 Arguments:
172
173 Pointer to an instance of the CPU I/O Protocol
174 Width of the Memory Access
175 Address of the I/O access
176 Count of the number of accesses to perform
177 Pointer to the buffer to read or write from I/O space
178
179 Returns:
180
181 Status
182 EFI_SUCCESS - The data was read from or written to the EFI System.
183 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
184 EFI_INVALID_PARAMETER - Buffer is NULL.
185 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
186 EFI_UNSUPPORTED - The address range specified by Address, Width, and
187 Count is not valid for this EFI System.
188 --*/
189 // TODO: This - add argument and description to function comment
190 // TODO: UserAddress - add argument and description to function comment
191 // TODO: UserBuffer - add argument and description to function comment
192 {
193 UINTN Address;
194 EFI_STATUS Status;
195
196 if (!UserBuffer) {
197 return EFI_INVALID_PARAMETER;
198 }
199
200 Address = (UINTN) UserAddress;
201
202 if (Width >= EfiCpuIoWidthMaximum) {
203 return EFI_INVALID_PARAMETER;
204 }
205
206 Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);
207 if (EFI_ERROR (Status)) {
208 return Status;
209 }
210
211 //
212 // Do nothing for Nt32 version
213 //
214 return EFI_SUCCESS;
215 }
216
217 EFI_STATUS
218 EFIAPI
219 CpuIoServiceWrite (
220 IN EFI_CPU_IO_PROTOCOL *This,
221 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
222 IN UINT64 UserAddress,
223 IN UINTN Count,
224 IN OUT VOID *UserBuffer
225 )
226 /*++
227
228 Routine Description:
229
230
231 This is the service that implements the I/O Write
232
233 Arguments:
234
235 Pointer to an instance of the CPU I/O Protocol
236 Width of the Memory Access
237 Address of the I/O access
238 Count of the number of accesses to perform
239 Pointer to the buffer to read or write from I/O space
240
241 Returns:
242
243 Status
244
245 Status
246 EFI_SUCCESS - The data was read from or written to the EFI System.
247 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
248 EFI_INVALID_PARAMETER - Buffer is NULL.
249 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
250 EFI_UNSUPPORTED - The address range specified by Address, Width, and
251 Count is not valid for this EFI System.
252
253 --*/
254 // TODO: This - add argument and description to function comment
255 // TODO: UserAddress - add argument and description to function comment
256 // TODO: UserBuffer - add argument and description to function comment
257 {
258 UINTN Address;
259 EFI_STATUS Status;
260
261 if (!UserBuffer) {
262 return EFI_INVALID_PARAMETER;
263 }
264
265 Address = (UINTN) UserAddress;
266
267 if (Width >= EfiCpuIoWidthMaximum) {
268 return EFI_INVALID_PARAMETER;
269 }
270
271 Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);
272 if (EFI_ERROR (Status)) {
273 return Status;
274 }
275
276 //
277 // Do nothing for Nt32 version
278 //
279 return EFI_SUCCESS;
280 }
281
282
283 EFI_STATUS
284 CpuIoCheckAddressRange (
285 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
286 IN UINT64 Address,
287 IN UINTN Count,
288 IN VOID *Buffer,
289 IN UINT64 Limit
290 )
291 /*++
292
293 Routine Description:
294
295 TODO: Add function description
296
297 Arguments:
298
299 Width - TODO: add argument description
300 Address - TODO: add argument description
301 Count - TODO: add argument description
302 Buffer - TODO: add argument description
303 Limit - TODO: add argument description
304
305 Returns:
306
307 EFI_UNSUPPORTED - TODO: Add description for return value
308 EFI_UNSUPPORTED - TODO: Add description for return value
309 EFI_UNSUPPORTED - TODO: Add description for return value
310 EFI_SUCCESS - TODO: Add description for return value
311
312 --*/
313 {
314 UINTN AlignMask;
315
316 if (Address > Limit) {
317 return EFI_UNSUPPORTED;
318 }
319
320 //
321 // For FiFo type, the target address won't increase during the access, so treat count as 1
322 //
323 if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {
324 Count = 1;
325 }
326
327 Width = Width & 0x03;
328 if (Address - 1 + (1 << Width) * Count > Limit) {
329 return EFI_UNSUPPORTED;
330 }
331
332 AlignMask = (1 << Width) - 1;
333 if ((UINTN) Buffer & AlignMask) {
334 return EFI_UNSUPPORTED;
335 }
336
337 return EFI_SUCCESS;
338 }
339
340