]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/CpuRuntimeDxe/CpuIo.c
Update the copyright notice format
[mirror_edk2.git] / UnixPkg / CpuRuntimeDxe / CpuIo.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 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 #include <FrameworkDxe.h>
26 #include <Protocol/Cpu.h>
27 #include <Protocol/DataHub.h>
28 #include <Guid/DataHubRecords.h>
29 #include <Protocol/CpuIo2.h>
30 #include <Protocol/FrameworkHii.h>
31
32 #include <Library/BaseLib.h>
33 #include <Library/DebugLib.h>
34 #include <Library/HiiLib.h>
35 #include <Library/UefiLib.h>
36 #include <Library/UefiDriverEntryPoint.h>
37 #include <Library/BaseMemoryLib.h>
38 #include <Library/MemoryAllocationLib.h>
39 #include <Library/UefiBootServicesTableLib.h>
40 #include <CpuDriver.h>
41
42 #define IA32_MAX_IO_ADDRESS 0xFFFF
43 #define IA32_MAX_MEM_ADDRESS 0xFFFFFFFF
44
45 EFI_STATUS
46 CpuIoCheckAddressRange (
47 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
48 IN UINT64 Address,
49 IN UINTN Count,
50 IN VOID *Buffer,
51 IN UINT64 Limit
52 );
53
54 EFI_STATUS
55 EFIAPI
56 CpuMemoryServiceRead (
57 IN EFI_CPU_IO2_PROTOCOL *This,
58 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
59 IN UINT64 Address,
60 IN UINTN Count,
61 IN OUT VOID *Buffer
62 )
63 /*++
64
65 Routine Description:
66
67 Perform the Memory Access Read service for the CPU I/O Protocol
68
69 Arguments:
70
71 Pointer to an instance of the CPU I/O Protocol
72 Width of the Memory Access
73 Address of the Memory access
74 Count of the number of accesses to perform
75 Pointer to the buffer to read or write from memory
76
77 Returns:
78
79 Status
80
81 EFI_SUCCESS - The data was read from or written to the EFI
82 System.
83 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
84 EFI_INVALID_PARAMETER - Buffer is NULL.
85 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
86 EFI_UNSUPPORTED - The address range specified by Address, Width,
87 and Count is not valid for this EFI System.
88
89 --*/
90 // TODO: This - add argument and description to function comment
91 {
92 EFI_STATUS Status;
93
94 if (!Buffer) {
95 return EFI_INVALID_PARAMETER;
96 }
97
98 Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);
99 if (EFI_ERROR (Status)) {
100 return Status;
101 }
102
103 //
104 // Do nothing for Nt32 version
105 //
106 return EFI_SUCCESS;
107 }
108
109 EFI_STATUS
110 EFIAPI
111 CpuMemoryServiceWrite (
112 IN EFI_CPU_IO2_PROTOCOL *This,
113 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
114 IN UINT64 Address,
115 IN UINTN Count,
116 IN OUT VOID *Buffer
117 )
118 /*++
119
120 Routine Description:
121
122 Perform the Memory Access Read service for the CPU I/O Protocol
123
124 Arguments:
125
126 Pointer to an instance of the CPU I/O Protocol
127 Width of the Memory Access
128 Address of the Memory access
129 Count of the number of accesses to perform
130 Pointer to the buffer to read or write from memory
131
132 Returns:
133
134 Status
135
136 EFI_SUCCESS - The data was read from or written to the EFI System.
137 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
138 EFI_INVALID_PARAMETER - Buffer is NULL.
139 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
140 EFI_UNSUPPORTED - The address range specified by Address, Width, and
141 Count is not valid for this EFI System.
142
143 --*/
144 // TODO: This - add argument and description to function comment
145 {
146 EFI_STATUS Status;
147
148 if (!Buffer) {
149 return EFI_INVALID_PARAMETER;
150 }
151
152 Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);
153 if (EFI_ERROR (Status)) {
154 return Status;
155 }
156
157 //
158 // Do nothing for Nt32 version
159 //
160 return EFI_SUCCESS;
161 }
162
163 EFI_STATUS
164 EFIAPI
165 CpuIoServiceRead (
166 IN EFI_CPU_IO2_PROTOCOL *This,
167 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
168 IN UINT64 UserAddress,
169 IN UINTN Count,
170 IN OUT VOID *UserBuffer
171 )
172 /*++
173
174 Routine Description:
175
176 This is the service that implements the I/O read
177
178 Arguments:
179
180 Pointer to an instance of the CPU I/O Protocol
181 Width of the Memory Access
182 Address of the I/O access
183 Count of the number of accesses to perform
184 Pointer to the buffer to read or write from I/O space
185
186 Returns:
187
188 Status
189 EFI_SUCCESS - The data was read from or written to the EFI System.
190 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
191 EFI_INVALID_PARAMETER - Buffer is NULL.
192 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
193 EFI_UNSUPPORTED - The address range specified by Address, Width, and
194 Count is not valid for this EFI System.
195 --*/
196 // TODO: This - add argument and description to function comment
197 // TODO: UserAddress - add argument and description to function comment
198 // TODO: UserBuffer - add argument and description to function comment
199 {
200 UINTN Address;
201 EFI_STATUS Status;
202
203 if (!UserBuffer) {
204 return EFI_INVALID_PARAMETER;
205 }
206
207 Address = (UINTN) UserAddress;
208
209 if (Width >= EfiCpuIoWidthMaximum) {
210 return EFI_INVALID_PARAMETER;
211 }
212
213 Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);
214 if (EFI_ERROR (Status)) {
215 return Status;
216 }
217
218 //
219 // Do nothing for Nt32 version
220 //
221 return EFI_SUCCESS;
222 }
223
224 EFI_STATUS
225 EFIAPI
226 CpuIoServiceWrite (
227 IN EFI_CPU_IO2_PROTOCOL *This,
228 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
229 IN UINT64 UserAddress,
230 IN UINTN Count,
231 IN OUT VOID *UserBuffer
232 )
233 /*++
234
235 Routine Description:
236
237
238 This is the service that implements the I/O Write
239
240 Arguments:
241
242 Pointer to an instance of the CPU I/O Protocol
243 Width of the Memory Access
244 Address of the I/O access
245 Count of the number of accesses to perform
246 Pointer to the buffer to read or write from I/O space
247
248 Returns:
249
250 Status
251
252 Status
253 EFI_SUCCESS - The data was read from or written to the EFI System.
254 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
255 EFI_INVALID_PARAMETER - Buffer is NULL.
256 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
257 EFI_UNSUPPORTED - The address range specified by Address, Width, and
258 Count is not valid for this EFI System.
259
260 --*/
261 // TODO: This - add argument and description to function comment
262 // TODO: UserAddress - add argument and description to function comment
263 // TODO: UserBuffer - add argument and description to function comment
264 {
265 UINTN Address;
266 EFI_STATUS Status;
267
268 if (!UserBuffer) {
269 return EFI_INVALID_PARAMETER;
270 }
271
272 Address = (UINTN) UserAddress;
273
274 if (Width >= EfiCpuIoWidthMaximum) {
275 return EFI_INVALID_PARAMETER;
276 }
277
278 Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);
279 if (EFI_ERROR (Status)) {
280 return Status;
281 }
282
283 //
284 // Do nothing for Nt32 version
285 //
286 return EFI_SUCCESS;
287 }
288
289
290 EFI_STATUS
291 CpuIoCheckAddressRange (
292 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
293 IN UINT64 Address,
294 IN UINTN Count,
295 IN VOID *Buffer,
296 IN UINT64 Limit
297 )
298 /*++
299
300 Routine Description:
301
302 TODO: Add function description
303
304 Arguments:
305
306 Width - TODO: add argument description
307 Address - TODO: add argument description
308 Count - TODO: add argument description
309 Buffer - TODO: add argument description
310 Limit - TODO: add argument description
311
312 Returns:
313
314 EFI_UNSUPPORTED - TODO: Add description for return value
315 EFI_UNSUPPORTED - TODO: Add description for return value
316 EFI_UNSUPPORTED - TODO: Add description for return value
317 EFI_SUCCESS - TODO: Add description for return value
318
319 --*/
320 {
321 UINTN AlignMask;
322
323 if (Address > Limit) {
324 return EFI_UNSUPPORTED;
325 }
326
327 //
328 // For FiFo type, the target address won't increase during the access, so treat count as 1
329 //
330 if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {
331 Count = 1;
332 }
333
334 Width = Width & 0x03;
335 if (Address - 1 + (1 << Width) * Count > Limit) {
336 return EFI_UNSUPPORTED;
337 }
338
339 AlignMask = (1 << Width) - 1;
340 if ((UINTN) Buffer & AlignMask) {
341 return EFI_UNSUPPORTED;
342 }
343
344 return EFI_SUCCESS;
345 }
346
347