2 This is the code that publishes the CPU I/O Protocol.
3 The intent herein is to have a single I/O service that can load
4 as early as possible, extend into runtime, and be layered upon by
5 the implementations of architectural protocols and the PCI Root
9 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
10 Portions copyright (c) 2011, Apple Inc. All rights reserved.
11 This program and the accompanying materials
12 are licensed and made available under the terms and conditions of the BSD License
13 which accompanies this distribution. The full text of the license may be found at
14 http://opensource.org/licenses/bsd-license.php
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include <Protocol/Cpu.h>
23 #include <Protocol/CpuIo2.h>
25 #include <Library/BaseLib.h>
26 #include <Library/DebugLib.h>
27 #include <Library/HiiLib.h>
28 #include <Library/UefiLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/MemoryAllocationLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <CpuDriver.h>
35 #define IA32_MAX_IO_ADDRESS 0xFFFF
36 #define IA32_MAX_MEM_ADDRESS 0xFFFFFFFF
39 CpuIoCheckAddressRange (
40 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
49 CpuMemoryServiceRead (
50 IN EFI_CPU_IO2_PROTOCOL
*This
,
51 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
60 Perform the Memory Access Read service for the CPU I/O Protocol
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
74 EFI_SUCCESS - The data was read from or written to the EFI
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.
87 return EFI_INVALID_PARAMETER
;
90 Status
= CpuIoCheckAddressRange (Width
, Address
, Count
, Buffer
, IA32_MAX_MEM_ADDRESS
);
91 if (EFI_ERROR (Status
)) {
96 // Do nothing for Nt32 version
103 CpuMemoryServiceWrite (
104 IN EFI_CPU_IO2_PROTOCOL
*This
,
105 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
114 Perform the Memory Access Read service for the CPU I/O Protocol
118 Pointer to an instance of the CPU I/O Protocol
119 Width of the Memory Access
120 Address of the Memory access
121 Count of the number of accesses to perform
122 Pointer to the buffer to read or write from memory
128 EFI_SUCCESS - The data was read from or written to the EFI System.
129 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
130 EFI_INVALID_PARAMETER - Buffer is NULL.
131 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
132 EFI_UNSUPPORTED - The address range specified by Address, Width, and
133 Count is not valid for this EFI System.
140 return EFI_INVALID_PARAMETER
;
143 Status
= CpuIoCheckAddressRange (Width
, Address
, Count
, Buffer
, IA32_MAX_MEM_ADDRESS
);
144 if (EFI_ERROR (Status
)) {
149 // Do nothing for Nt32 version
157 IN EFI_CPU_IO2_PROTOCOL
*This
,
158 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
159 IN UINT64 UserAddress
,
161 IN OUT VOID
*UserBuffer
167 This is the service that implements the I/O read
171 Pointer to an instance of the CPU I/O Protocol
172 Width of the Memory Access
173 Address of the I/O access
174 Count of the number of accesses to perform
175 Pointer to the buffer to read or write from I/O space
180 EFI_SUCCESS - The data was read from or written to the EFI System.
181 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
182 EFI_INVALID_PARAMETER - Buffer is NULL.
183 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
184 EFI_UNSUPPORTED - The address range specified by Address, Width, and
185 Count is not valid for this EFI System.
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
)) {
207 // Do nothing for Nt32 version
215 IN EFI_CPU_IO2_PROTOCOL
*This
,
216 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
217 IN UINT64 UserAddress
,
219 IN OUT VOID
*UserBuffer
226 This is the service that implements the I/O Write
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
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.
254 return EFI_INVALID_PARAMETER
;
257 Address
= (UINTN
) UserAddress
;
259 if (Width
>= EfiCpuIoWidthMaximum
) {
260 return EFI_INVALID_PARAMETER
;
263 Status
= CpuIoCheckAddressRange (Width
, Address
, Count
, UserBuffer
, IA32_MAX_IO_ADDRESS
);
264 if (EFI_ERROR (Status
)) {
269 // Do nothing for Nt32 version
281 Width - TODO: add argument description
282 Address - TODO: add argument description
283 Count - TODO: add argument description
284 Buffer - TODO: add argument description
285 Limit - TODO: add argument description
289 EFI_UNSUPPORTED - TODO: Add description for return value
290 EFI_UNSUPPORTED - TODO: Add description for return value
291 EFI_UNSUPPORTED - TODO: Add description for return value
292 EFI_SUCCESS - TODO: Add description for return value
296 CpuIoCheckAddressRange (
297 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
306 if (Address
> Limit
) {
307 return EFI_UNSUPPORTED
;
311 // For FiFo type, the target address won't increase during the access, so treat count as 1
313 if (Width
>= EfiCpuIoWidthFifoUint8
&& Width
<= EfiCpuIoWidthFifoUint64
) {
317 Width
= Width
& 0x03;
318 if ((Address
- 1 + LShiftU64 (Count
, Width
)) > Limit
) {
319 return EFI_UNSUPPORTED
;
322 AlignMask
= (1 << Width
) - 1;
323 if ((UINTN
) Buffer
& AlignMask
) {
324 return EFI_UNSUPPORTED
;