revert the change on BdsConsole. when doing minimal boot, the ConsoleIn variable...
[edk2.git] / Nt32Pkg / CpuRuntimeDxe / CpuIo.c
blobb513c7242d79e6fb5e248ba5a63c4a069aa25a28
1 /**@file
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
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.
12 Module Name:
14 CpuIo.c
16 Abstract:
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.
24 **/
26 #include <CpuDriver.h>
28 #define IA32_MAX_IO_ADDRESS 0xFFFF
29 #define IA32_MAX_MEM_ADDRESS 0xFFFFFFFF
31 EFI_CPU_IO_PROTOCOL mCpuIoProtocol;
33 EFI_STATUS
34 CpuIoCheckAddressRange (
35 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
36 IN UINT64 Address,
37 IN UINTN Count,
38 IN VOID *Buffer,
39 IN UINT64 Limit
42 EFI_STATUS
43 EFIAPI
44 CpuMemoryServiceRead (
45 IN EFI_CPU_IO_PROTOCOL *This,
46 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
47 IN UINT64 Address,
48 IN UINTN Count,
49 IN OUT VOID *Buffer
51 /*++
53 Routine Description:
55 Perform the Memory Access Read service for the CPU I/O Protocol
57 Arguments:
59 Pointer to an instance of the CPU I/O Protocol
60 Width of the Memory Access
61 Address of the Memory access
62 Count of the number of accesses to perform
63 Pointer to the buffer to read or write from memory
65 Returns:
67 Status
69 EFI_SUCCESS - The data was read from or written to the EFI
70 System.
71 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
72 EFI_INVALID_PARAMETER - Buffer is NULL.
73 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
74 EFI_UNSUPPORTED - The address range specified by Address, Width,
75 and Count is not valid for this EFI System.
77 --*/
78 // TODO: This - add argument and description to function comment
80 EFI_STATUS Status;
82 if (!Buffer) {
83 return EFI_INVALID_PARAMETER;
86 Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);
87 if (EFI_ERROR (Status)) {
88 return Status;
92 // Do nothing for Nt32 version
94 return EFI_SUCCESS;
97 EFI_STATUS
98 EFIAPI
99 CpuMemoryServiceWrite (
100 IN EFI_CPU_IO_PROTOCOL *This,
101 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
102 IN UINT64 Address,
103 IN UINTN Count,
104 IN OUT VOID *Buffer
106 /*++
108 Routine Description:
110 Perform the Memory Access Read service for the CPU I/O Protocol
112 Arguments:
114 Pointer to an instance of the CPU I/O Protocol
115 Width of the Memory Access
116 Address of the Memory access
117 Count of the number of accesses to perform
118 Pointer to the buffer to read or write from memory
120 Returns:
122 Status
124 EFI_SUCCESS - The data was read from or written to the EFI System.
125 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
126 EFI_INVALID_PARAMETER - Buffer is NULL.
127 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
128 EFI_UNSUPPORTED - The address range specified by Address, Width, and
129 Count is not valid for this EFI System.
131 --*/
132 // TODO: This - add argument and description to function comment
134 EFI_STATUS Status;
136 if (!Buffer) {
137 return EFI_INVALID_PARAMETER;
140 Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);
141 if (EFI_ERROR (Status)) {
142 return Status;
146 // Do nothing for Nt32 version
148 return EFI_SUCCESS;
151 EFI_STATUS
152 EFIAPI
153 CpuIoServiceRead (
154 IN EFI_CPU_IO_PROTOCOL *This,
155 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
156 IN UINT64 UserAddress,
157 IN UINTN Count,
158 IN OUT VOID *UserBuffer
160 /*++
162 Routine Description:
164 This is the service that implements the I/O read
166 Arguments:
168 Pointer to an instance of the CPU I/O Protocol
169 Width of the Memory Access
170 Address of the I/O access
171 Count of the number of accesses to perform
172 Pointer to the buffer to read or write from I/O space
174 Returns:
176 Status
177 EFI_SUCCESS - The data was read from or written to the EFI System.
178 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
179 EFI_INVALID_PARAMETER - Buffer is NULL.
180 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
181 EFI_UNSUPPORTED - The address range specified by Address, Width, and
182 Count is not valid for this EFI System.
183 --*/
184 // TODO: This - add argument and description to function comment
185 // TODO: UserAddress - add argument and description to function comment
186 // TODO: UserBuffer - add argument and description to function comment
188 UINTN Address;
189 EFI_STATUS Status;
191 if (!UserBuffer) {
192 return EFI_INVALID_PARAMETER;
195 Address = (UINTN) UserAddress;
197 if (Width >= EfiCpuIoWidthMaximum) {
198 return EFI_INVALID_PARAMETER;
201 Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);
202 if (EFI_ERROR (Status)) {
203 return Status;
207 // Do nothing for Nt32 version
209 return EFI_SUCCESS;
212 EFI_STATUS
213 EFIAPI
214 CpuIoServiceWrite (
215 IN EFI_CPU_IO_PROTOCOL *This,
216 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
217 IN UINT64 UserAddress,
218 IN UINTN Count,
219 IN OUT VOID *UserBuffer
221 /*++
223 Routine Description:
226 This is the service that implements the I/O Write
228 Arguments:
230 Pointer to an instance of the CPU I/O Protocol
231 Width of the Memory Access
232 Address of the I/O access
233 Count of the number of accesses to perform
234 Pointer to the buffer to read or write from I/O space
236 Returns:
238 Status
240 Status
241 EFI_SUCCESS - The data was read from or written to the EFI System.
242 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
243 EFI_INVALID_PARAMETER - Buffer is NULL.
244 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
245 EFI_UNSUPPORTED - The address range specified by Address, Width, and
246 Count is not valid for this EFI System.
248 --*/
249 // TODO: This - add argument and description to function comment
250 // TODO: UserAddress - add argument and description to function comment
251 // TODO: UserBuffer - add argument and description to function comment
253 UINTN Address;
254 EFI_STATUS Status;
256 if (!UserBuffer) {
257 return EFI_INVALID_PARAMETER;
260 Address = (UINTN) UserAddress;
262 if (Width >= EfiCpuIoWidthMaximum) {
263 return EFI_INVALID_PARAMETER;
266 Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);
267 if (EFI_ERROR (Status)) {
268 return Status;
272 // Do nothing for Nt32 version
274 return EFI_SUCCESS;
278 EFI_STATUS
279 CpuIoCheckAddressRange (
280 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
281 IN UINT64 Address,
282 IN UINTN Count,
283 IN VOID *Buffer,
284 IN UINT64 Limit
286 /*++
288 Routine Description:
290 TODO: Add function description
292 Arguments:
294 Width - TODO: add argument description
295 Address - TODO: add argument description
296 Count - TODO: add argument description
297 Buffer - TODO: add argument description
298 Limit - TODO: add argument description
300 Returns:
302 EFI_UNSUPPORTED - TODO: Add description for return value
303 EFI_UNSUPPORTED - TODO: Add description for return value
304 EFI_UNSUPPORTED - TODO: Add description for return value
305 EFI_SUCCESS - TODO: Add description for return value
307 --*/
309 UINTN AlignMask;
311 if (Address > Limit) {
312 return EFI_UNSUPPORTED;
316 // For FiFo type, the target address won't increase during the access, so treat count as 1
318 if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {
319 Count = 1;
322 Width = (EFI_CPU_IO_PROTOCOL_WIDTH)(Width & 0x03);
323 if (Address - 1 + (1 << Width) * Count > Limit) {
324 return EFI_UNSUPPORTED;
327 AlignMask = (1 << Width) - 1;
328 if ((UINTN) Buffer & AlignMask) {
329 return EFI_UNSUPPORTED;
332 return EFI_SUCCESS;