aeregion.c revision 1.1.1.4 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: aeregion - Operation region support for acpiexec
4 1.1 christos *
5 1.1 christos *****************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.1.1.4 christos * Copyright (C) 2000 - 2016, Intel Corp.
9 1.1 christos * All rights reserved.
10 1.1 christos *
11 1.1 christos * Redistribution and use in source and binary forms, with or without
12 1.1 christos * modification, are permitted provided that the following conditions
13 1.1 christos * are met:
14 1.1 christos * 1. Redistributions of source code must retain the above copyright
15 1.1 christos * notice, this list of conditions, and the following disclaimer,
16 1.1 christos * without modification.
17 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1 christos * including a substantially similar Disclaimer requirement for further
21 1.1 christos * binary redistribution.
22 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1 christos * of any contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * Alternatively, this software may be distributed under the terms of the
27 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1 christos * Software Foundation.
29 1.1 christos *
30 1.1 christos * NO WARRANTY
31 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.1 christos */
43 1.1 christos
44 1.1 christos #include "aecommon.h"
45 1.1 christos
46 1.1 christos #define _COMPONENT ACPI_TOOLS
47 1.1 christos ACPI_MODULE_NAME ("aeregion")
48 1.1 christos
49 1.1 christos
50 1.1 christos /* Local prototypes */
51 1.1 christos
52 1.1 christos static ACPI_STATUS
53 1.1 christos AeRegionInit (
54 1.1 christos ACPI_HANDLE RegionHandle,
55 1.1 christos UINT32 Function,
56 1.1 christos void *HandlerContext,
57 1.1 christos void **RegionContext);
58 1.1 christos
59 1.1 christos static ACPI_STATUS
60 1.1 christos AeInstallEcHandler (
61 1.1 christos ACPI_HANDLE ObjHandle,
62 1.1 christos UINT32 Level,
63 1.1 christos void *Context,
64 1.1 christos void **ReturnValue);
65 1.1 christos
66 1.1 christos static ACPI_STATUS
67 1.1 christos AeInstallPciHandler (
68 1.1 christos ACPI_HANDLE ObjHandle,
69 1.1 christos UINT32 Level,
70 1.1 christos void *Context,
71 1.1 christos void **ReturnValue);
72 1.1 christos
73 1.1 christos
74 1.1 christos static AE_DEBUG_REGIONS AeRegions;
75 1.1 christos BOOLEAN AcpiGbl_DisplayRegionAccess = FALSE;
76 1.1 christos ACPI_CONNECTION_INFO AeMyContext;
77 1.1 christos
78 1.1 christos
79 1.1 christos /*
80 1.1 christos * We will override some of the default region handlers, especially
81 1.1 christos * the SystemMemory handler, which must be implemented locally.
82 1.1 christos * These handlers are installed "early" - before any _REG methods
83 1.1 christos * are executed - since they are special in the sense that the ACPI spec
84 1.1 christos * declares that they must "always be available". Cannot override the
85 1.1 christos * DataTable region handler either -- needed for test execution.
86 1.1 christos *
87 1.1 christos * NOTE: The local region handler will simulate access to these address
88 1.1 christos * spaces by creating a memory buffer behind each operation region.
89 1.1 christos */
90 1.1 christos static ACPI_ADR_SPACE_TYPE DefaultSpaceIdList[] =
91 1.1 christos {
92 1.1 christos ACPI_ADR_SPACE_SYSTEM_MEMORY,
93 1.1 christos ACPI_ADR_SPACE_SYSTEM_IO,
94 1.1 christos ACPI_ADR_SPACE_PCI_CONFIG,
95 1.1 christos ACPI_ADR_SPACE_EC
96 1.1 christos };
97 1.1 christos
98 1.1 christos /*
99 1.1 christos * We will install handlers for some of the various address space IDs.
100 1.1 christos * Test one user-defined address space (used by aslts).
101 1.1 christos */
102 1.1 christos #define ACPI_ADR_SPACE_USER_DEFINED1 0x80
103 1.1 christos #define ACPI_ADR_SPACE_USER_DEFINED2 0xE4
104 1.1 christos
105 1.1 christos static ACPI_ADR_SPACE_TYPE SpaceIdList[] =
106 1.1 christos {
107 1.1 christos ACPI_ADR_SPACE_SMBUS,
108 1.1 christos ACPI_ADR_SPACE_CMOS,
109 1.1 christos ACPI_ADR_SPACE_PCI_BAR_TARGET,
110 1.1 christos ACPI_ADR_SPACE_IPMI,
111 1.1 christos ACPI_ADR_SPACE_GPIO,
112 1.1 christos ACPI_ADR_SPACE_GSBUS,
113 1.1 christos ACPI_ADR_SPACE_FIXED_HARDWARE,
114 1.1 christos ACPI_ADR_SPACE_USER_DEFINED1,
115 1.1 christos ACPI_ADR_SPACE_USER_DEFINED2
116 1.1 christos };
117 1.1 christos
118 1.1 christos
119 1.1 christos /******************************************************************************
120 1.1 christos *
121 1.1 christos * FUNCTION: AeRegionInit
122 1.1 christos *
123 1.1 christos * PARAMETERS: Region init handler
124 1.1 christos *
125 1.1 christos * RETURN: Status
126 1.1 christos *
127 1.1 christos * DESCRIPTION: Opregion init function.
128 1.1 christos *
129 1.1 christos *****************************************************************************/
130 1.1 christos
131 1.1 christos static ACPI_STATUS
132 1.1 christos AeRegionInit (
133 1.1 christos ACPI_HANDLE RegionHandle,
134 1.1 christos UINT32 Function,
135 1.1 christos void *HandlerContext,
136 1.1 christos void **RegionContext)
137 1.1 christos {
138 1.1 christos
139 1.1 christos if (Function == ACPI_REGION_DEACTIVATE)
140 1.1 christos {
141 1.1 christos *RegionContext = NULL;
142 1.1 christos }
143 1.1 christos else
144 1.1 christos {
145 1.1 christos *RegionContext = RegionHandle;
146 1.1 christos }
147 1.1 christos
148 1.1 christos return (AE_OK);
149 1.1 christos }
150 1.1 christos
151 1.1 christos
152 1.1.1.4 christos /******************************************************************************
153 1.1.1.4 christos *
154 1.1.1.4 christos * FUNCTION: AeOverrideRegionHandlers
155 1.1.1.4 christos *
156 1.1.1.4 christos * PARAMETERS: None
157 1.1.1.4 christos *
158 1.1.1.4 christos * RETURN: None
159 1.1.1.4 christos *
160 1.1.1.4 christos * DESCRIPTION: Override the default region handlers for memory, i/o, and
161 1.1.1.4 christos * pci_config. Also install a handler for EC. This is part of
162 1.1.1.4 christos * the "install early handlers" functionality.
163 1.1.1.4 christos *
164 1.1.1.4 christos *****************************************************************************/
165 1.1.1.4 christos
166 1.1 christos void
167 1.1.1.4 christos AeOverrideRegionHandlers (
168 1.1 christos void)
169 1.1 christos {
170 1.1 christos UINT32 i;
171 1.1 christos ACPI_STATUS Status;
172 1.1 christos
173 1.1 christos /*
174 1.1.1.4 christos * Install handlers that will override the default handlers for some of
175 1.1.1.4 christos * the space IDs.
176 1.1 christos */
177 1.1.1.4 christos for (i = 0; i < ACPI_ARRAY_LENGTH (DefaultSpaceIdList); i++)
178 1.1 christos {
179 1.1 christos /* Install handler at the root object */
180 1.1 christos
181 1.1 christos Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT,
182 1.1.1.4 christos DefaultSpaceIdList[i], AeRegionHandler,
183 1.1.1.4 christos AeRegionInit, &AeMyContext);
184 1.1.1.4 christos
185 1.1 christos if (ACPI_FAILURE (Status))
186 1.1 christos {
187 1.1 christos ACPI_EXCEPTION ((AE_INFO, Status,
188 1.1 christos "Could not install an OpRegion handler for %s space(%u)",
189 1.1.1.4 christos AcpiUtGetRegionName ((UINT8) DefaultSpaceIdList[i]),
190 1.1.1.4 christos DefaultSpaceIdList[i]));
191 1.1 christos }
192 1.1 christos }
193 1.1 christos }
194 1.1 christos
195 1.1 christos
196 1.1.1.4 christos /******************************************************************************
197 1.1.1.4 christos *
198 1.1.1.4 christos * FUNCTION: AeInstallRegionHandlers
199 1.1.1.4 christos *
200 1.1.1.4 christos * PARAMETERS: None
201 1.1.1.4 christos *
202 1.1.1.4 christos * RETURN: None
203 1.1.1.4 christos *
204 1.1.1.4 christos * DESCRIPTION: Install handlers for the address spaces other than memory,
205 1.1.1.4 christos * i/o, and pci_config.
206 1.1.1.4 christos *
207 1.1.1.4 christos *****************************************************************************/
208 1.1.1.4 christos
209 1.1 christos void
210 1.1.1.4 christos AeInstallRegionHandlers (
211 1.1 christos void)
212 1.1 christos {
213 1.1 christos UINT32 i;
214 1.1 christos ACPI_STATUS Status;
215 1.1 christos
216 1.1 christos /*
217 1.1.1.4 christos * Install handlers for some of the "device driver" address spaces
218 1.1.1.4 christos * such as SMBus, etc.
219 1.1 christos */
220 1.1.1.4 christos for (i = 0; i < ACPI_ARRAY_LENGTH (SpaceIdList); i++)
221 1.1 christos {
222 1.1 christos /* Install handler at the root object */
223 1.1 christos
224 1.1 christos Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT,
225 1.1.1.4 christos SpaceIdList[i], AeRegionHandler,
226 1.1.1.4 christos AeRegionInit, &AeMyContext);
227 1.1.1.4 christos
228 1.1 christos if (ACPI_FAILURE (Status))
229 1.1 christos {
230 1.1 christos ACPI_EXCEPTION ((AE_INFO, Status,
231 1.1.1.4 christos "Could not install an OpRegion handler for %s space(%u)",
232 1.1.1.4 christos AcpiUtGetRegionName((UINT8) SpaceIdList[i]), SpaceIdList[i]));
233 1.1 christos return;
234 1.1 christos }
235 1.1 christos }
236 1.1 christos }
237 1.1 christos
238 1.1 christos
239 1.1 christos /*******************************************************************************
240 1.1 christos *
241 1.1 christos * FUNCTION: AeInstallDeviceHandlers,
242 1.1 christos * AeInstallEcHandler,
243 1.1 christos * AeInstallPciHandler
244 1.1 christos *
245 1.1 christos * PARAMETERS: ACPI_WALK_NAMESPACE callback
246 1.1 christos *
247 1.1 christos * RETURN: Status
248 1.1 christos *
249 1.1 christos * DESCRIPTION: Walk entire namespace, install a handler for every EC
250 1.1 christos * and PCI device found.
251 1.1 christos *
252 1.1 christos ******************************************************************************/
253 1.1 christos
254 1.1 christos static ACPI_STATUS
255 1.1 christos AeInstallEcHandler (
256 1.1 christos ACPI_HANDLE ObjHandle,
257 1.1 christos UINT32 Level,
258 1.1 christos void *Context,
259 1.1 christos void **ReturnValue)
260 1.1 christos {
261 1.1 christos ACPI_STATUS Status;
262 1.1 christos
263 1.1 christos
264 1.1 christos /* Install the handler for this EC device */
265 1.1 christos
266 1.1 christos Status = AcpiInstallAddressSpaceHandler (ObjHandle, ACPI_ADR_SPACE_EC,
267 1.1 christos AeRegionHandler, AeRegionInit, &AeMyContext);
268 1.1 christos if (ACPI_FAILURE (Status))
269 1.1 christos {
270 1.1 christos ACPI_EXCEPTION ((AE_INFO, Status,
271 1.1 christos "Could not install an OpRegion handler for EC device (%p)",
272 1.1 christos ObjHandle));
273 1.1 christos }
274 1.1 christos
275 1.1 christos return (Status);
276 1.1 christos }
277 1.1 christos
278 1.1 christos
279 1.1 christos static ACPI_STATUS
280 1.1 christos AeInstallPciHandler (
281 1.1 christos ACPI_HANDLE ObjHandle,
282 1.1 christos UINT32 Level,
283 1.1 christos void *Context,
284 1.1 christos void **ReturnValue)
285 1.1 christos {
286 1.1 christos ACPI_STATUS Status;
287 1.1 christos
288 1.1 christos
289 1.1 christos /* Install memory and I/O handlers for the PCI device */
290 1.1 christos
291 1.1 christos Status = AcpiInstallAddressSpaceHandler (ObjHandle, ACPI_ADR_SPACE_SYSTEM_IO,
292 1.1 christos AeRegionHandler, AeRegionInit, &AeMyContext);
293 1.1 christos if (ACPI_FAILURE (Status))
294 1.1 christos {
295 1.1 christos ACPI_EXCEPTION ((AE_INFO, Status,
296 1.1 christos "Could not install an OpRegion handler for PCI device (%p)",
297 1.1 christos ObjHandle));
298 1.1 christos }
299 1.1 christos
300 1.1 christos Status = AcpiInstallAddressSpaceHandler (ObjHandle, ACPI_ADR_SPACE_SYSTEM_MEMORY,
301 1.1 christos AeRegionHandler, AeRegionInit, &AeMyContext);
302 1.1 christos if (ACPI_FAILURE (Status))
303 1.1 christos {
304 1.1 christos ACPI_EXCEPTION ((AE_INFO, Status,
305 1.1 christos "Could not install an OpRegion handler for PCI device (%p)",
306 1.1 christos ObjHandle));
307 1.1 christos }
308 1.1 christos
309 1.1 christos return (AE_CTRL_TERMINATE);
310 1.1 christos }
311 1.1 christos
312 1.1 christos
313 1.1 christos ACPI_STATUS
314 1.1 christos AeInstallDeviceHandlers (
315 1.1 christos void)
316 1.1 christos {
317 1.1 christos
318 1.1 christos /* Find all Embedded Controller devices */
319 1.1 christos
320 1.1 christos AcpiGetDevices ("PNP0C09", AeInstallEcHandler, NULL, NULL);
321 1.1 christos
322 1.1 christos /* Install a PCI handler */
323 1.1 christos
324 1.1 christos AcpiGetDevices ("PNP0A08", AeInstallPciHandler, NULL, NULL);
325 1.1 christos return (AE_OK);
326 1.1 christos }
327 1.1 christos
328 1.1 christos
329 1.1 christos /******************************************************************************
330 1.1 christos *
331 1.1 christos * FUNCTION: AeRegionHandler
332 1.1 christos *
333 1.1 christos * PARAMETERS: Standard region handler parameters
334 1.1 christos *
335 1.1 christos * RETURN: Status
336 1.1 christos *
337 1.1 christos * DESCRIPTION: Test handler - Handles some dummy regions via memory that can
338 1.1 christos * be manipulated in Ring 3. Simulates actual reads and writes.
339 1.1 christos *
340 1.1 christos *****************************************************************************/
341 1.1 christos
342 1.1 christos ACPI_STATUS
343 1.1 christos AeRegionHandler (
344 1.1 christos UINT32 Function,
345 1.1 christos ACPI_PHYSICAL_ADDRESS Address,
346 1.1 christos UINT32 BitWidth,
347 1.1 christos UINT64 *Value,
348 1.1 christos void *HandlerContext,
349 1.1 christos void *RegionContext)
350 1.1 christos {
351 1.1 christos
352 1.1 christos ACPI_OPERAND_OBJECT *RegionObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, RegionContext);
353 1.1 christos UINT8 *Buffer = ACPI_CAST_PTR (UINT8, Value);
354 1.1 christos UINT8 *OldBuffer;
355 1.1 christos UINT8 *NewBuffer;
356 1.1 christos ACPI_PHYSICAL_ADDRESS BaseAddress;
357 1.1 christos ACPI_PHYSICAL_ADDRESS BaseAddressEnd;
358 1.1 christos ACPI_PHYSICAL_ADDRESS RegionAddress;
359 1.1 christos ACPI_PHYSICAL_ADDRESS RegionAddressEnd;
360 1.1 christos ACPI_SIZE Length;
361 1.1 christos BOOLEAN BufferExists;
362 1.1 christos BOOLEAN BufferResize;
363 1.1 christos AE_REGION *RegionElement;
364 1.1 christos void *BufferValue;
365 1.1 christos ACPI_STATUS Status;
366 1.1 christos UINT32 ByteWidth;
367 1.1 christos UINT32 RegionLength;
368 1.1 christos UINT32 i;
369 1.1 christos UINT8 SpaceId;
370 1.1 christos ACPI_CONNECTION_INFO *MyContext;
371 1.1 christos UINT32 Value1;
372 1.1 christos UINT32 Value2;
373 1.1 christos ACPI_RESOURCE *Resource;
374 1.1 christos
375 1.1 christos
376 1.1 christos ACPI_FUNCTION_NAME (AeRegionHandler);
377 1.1 christos
378 1.1 christos /*
379 1.1 christos * If the object is not a region, simply return
380 1.1 christos */
381 1.1 christos if (RegionObject->Region.Type != ACPI_TYPE_REGION)
382 1.1 christos {
383 1.1 christos return (AE_OK);
384 1.1 christos }
385 1.1 christos
386 1.1 christos /* Check that we actually got back our context parameter */
387 1.1 christos
388 1.1 christos if (HandlerContext != &AeMyContext)
389 1.1 christos {
390 1.1 christos printf ("Region handler received incorrect context %p, should be %p\n",
391 1.1 christos HandlerContext, &AeMyContext);
392 1.1 christos }
393 1.1 christos
394 1.1 christos MyContext = ACPI_CAST_PTR (ACPI_CONNECTION_INFO, HandlerContext);
395 1.1 christos
396 1.1 christos /*
397 1.1 christos * Find the region's address space and length before searching
398 1.1 christos * the linked list.
399 1.1 christos */
400 1.1 christos BaseAddress = RegionObject->Region.Address;
401 1.1 christos Length = (ACPI_SIZE) RegionObject->Region.Length;
402 1.1 christos SpaceId = RegionObject->Region.SpaceId;
403 1.1 christos
404 1.1.1.4 christos ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
405 1.1.1.4 christos "Operation Region request on %s at 0x%X\n",
406 1.1.1.4 christos AcpiUtGetRegionName (RegionObject->Region.SpaceId),
407 1.1.1.4 christos (UINT32) Address));
408 1.1 christos
409 1.1 christos /*
410 1.1 christos * Region support can be disabled with the -do option.
411 1.1 christos * We use this to support dynamically loaded tables where we pass a valid
412 1.1 christos * address to the AML.
413 1.1 christos */
414 1.1 christos if (AcpiGbl_DbOpt_NoRegionSupport)
415 1.1 christos {
416 1.1 christos BufferValue = ACPI_TO_POINTER (Address);
417 1.1 christos ByteWidth = (BitWidth / 8);
418 1.1 christos
419 1.1 christos if (BitWidth % 8)
420 1.1 christos {
421 1.1 christos ByteWidth += 1;
422 1.1 christos }
423 1.1 christos goto DoFunction;
424 1.1 christos }
425 1.1 christos
426 1.1 christos switch (SpaceId)
427 1.1 christos {
428 1.1 christos case ACPI_ADR_SPACE_SYSTEM_IO:
429 1.1 christos /*
430 1.1 christos * For I/O space, exercise the port validation
431 1.1 christos * Note: ReadPort currently always returns all ones, length=BitLength
432 1.1 christos */
433 1.1 christos switch (Function & ACPI_IO_MASK)
434 1.1 christos {
435 1.1 christos case ACPI_READ:
436 1.1 christos
437 1.1 christos if (BitWidth == 64)
438 1.1 christos {
439 1.1 christos /* Split the 64-bit request into two 32-bit requests */
440 1.1 christos
441 1.1 christos Status = AcpiHwReadPort (Address, &Value1, 32);
442 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwReadPort, Status);
443 1.1 christos Status = AcpiHwReadPort (Address+4, &Value2, 32);
444 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwReadPort, Status);
445 1.1 christos
446 1.1 christos *Value = Value1 | ((UINT64) Value2 << 32);
447 1.1 christos }
448 1.1 christos else
449 1.1 christos {
450 1.1 christos Status = AcpiHwReadPort (Address, &Value1, BitWidth);
451 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwReadPort, Status);
452 1.1 christos *Value = (UINT64) Value1;
453 1.1 christos }
454 1.1 christos break;
455 1.1 christos
456 1.1 christos case ACPI_WRITE:
457 1.1 christos
458 1.1 christos if (BitWidth == 64)
459 1.1 christos {
460 1.1 christos /* Split the 64-bit request into two 32-bit requests */
461 1.1 christos
462 1.1 christos Status = AcpiHwWritePort (Address, ACPI_LODWORD (*Value), 32);
463 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwWritePort, Status);
464 1.1 christos Status = AcpiHwWritePort (Address+4, ACPI_HIDWORD (*Value), 32);
465 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwWritePort, Status);
466 1.1 christos }
467 1.1 christos else
468 1.1 christos {
469 1.1 christos Status = AcpiHwWritePort (Address, (UINT32) *Value, BitWidth);
470 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwWritePort, Status);
471 1.1 christos }
472 1.1 christos break;
473 1.1 christos
474 1.1 christos default:
475 1.1 christos
476 1.1 christos Status = AE_BAD_PARAMETER;
477 1.1 christos break;
478 1.1 christos }
479 1.1 christos
480 1.1 christos if (ACPI_FAILURE (Status))
481 1.1 christos {
482 1.1 christos return (Status);
483 1.1 christos }
484 1.1 christos
485 1.1 christos /* Now go ahead and simulate the hardware */
486 1.1 christos break;
487 1.1 christos
488 1.1 christos /*
489 1.1 christos * SMBus and GenericSerialBus support the various bidirectional
490 1.1 christos * protocols.
491 1.1 christos */
492 1.1 christos case ACPI_ADR_SPACE_SMBUS:
493 1.1 christos case ACPI_ADR_SPACE_GSBUS: /* ACPI 5.0 */
494 1.1 christos
495 1.1 christos Length = 0;
496 1.1 christos
497 1.1 christos switch (Function & ACPI_IO_MASK)
498 1.1 christos {
499 1.1 christos case ACPI_READ:
500 1.1 christos
501 1.1 christos switch (Function >> 16)
502 1.1 christos {
503 1.1 christos case AML_FIELD_ATTRIB_QUICK:
504 1.1 christos
505 1.1 christos Length = 0;
506 1.1 christos break;
507 1.1 christos
508 1.1 christos case AML_FIELD_ATTRIB_SEND_RCV:
509 1.1 christos case AML_FIELD_ATTRIB_BYTE:
510 1.1 christos
511 1.1 christos Length = 1;
512 1.1 christos break;
513 1.1 christos
514 1.1 christos case AML_FIELD_ATTRIB_WORD:
515 1.1 christos case AML_FIELD_ATTRIB_WORD_CALL:
516 1.1 christos
517 1.1 christos Length = 2;
518 1.1 christos break;
519 1.1 christos
520 1.1 christos case AML_FIELD_ATTRIB_BLOCK:
521 1.1 christos case AML_FIELD_ATTRIB_BLOCK_CALL:
522 1.1 christos
523 1.1 christos Length = 32;
524 1.1 christos break;
525 1.1 christos
526 1.1 christos case AML_FIELD_ATTRIB_MULTIBYTE:
527 1.1 christos case AML_FIELD_ATTRIB_RAW_BYTES:
528 1.1 christos case AML_FIELD_ATTRIB_RAW_PROCESS:
529 1.1 christos
530 1.1 christos Length = MyContext->AccessLength;
531 1.1 christos break;
532 1.1 christos
533 1.1 christos default:
534 1.1 christos
535 1.1 christos break;
536 1.1 christos }
537 1.1 christos break;
538 1.1 christos
539 1.1 christos case ACPI_WRITE:
540 1.1 christos
541 1.1 christos switch (Function >> 16)
542 1.1 christos {
543 1.1 christos case AML_FIELD_ATTRIB_QUICK:
544 1.1 christos case AML_FIELD_ATTRIB_SEND_RCV:
545 1.1 christos case AML_FIELD_ATTRIB_BYTE:
546 1.1 christos case AML_FIELD_ATTRIB_WORD:
547 1.1 christos case AML_FIELD_ATTRIB_BLOCK:
548 1.1 christos
549 1.1 christos Length = 0;
550 1.1 christos break;
551 1.1 christos
552 1.1 christos case AML_FIELD_ATTRIB_WORD_CALL:
553 1.1 christos Length = 2;
554 1.1 christos break;
555 1.1 christos
556 1.1 christos case AML_FIELD_ATTRIB_BLOCK_CALL:
557 1.1 christos Length = 32;
558 1.1 christos break;
559 1.1 christos
560 1.1 christos case AML_FIELD_ATTRIB_MULTIBYTE:
561 1.1 christos case AML_FIELD_ATTRIB_RAW_BYTES:
562 1.1 christos case AML_FIELD_ATTRIB_RAW_PROCESS:
563 1.1 christos
564 1.1 christos Length = MyContext->AccessLength;
565 1.1 christos break;
566 1.1 christos
567 1.1 christos default:
568 1.1 christos
569 1.1 christos break;
570 1.1 christos }
571 1.1 christos break;
572 1.1 christos
573 1.1 christos default:
574 1.1 christos
575 1.1 christos break;
576 1.1 christos }
577 1.1 christos
578 1.1 christos if (AcpiGbl_DisplayRegionAccess)
579 1.1 christos {
580 1.1 christos AcpiOsPrintf ("AcpiExec: %s "
581 1.1 christos "%s: Attr %X Addr %.4X BaseAddr %.4X Len %.2X Width %X BufLen %X",
582 1.1 christos AcpiUtGetRegionName (SpaceId),
583 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ",
584 1.1 christos (UINT32) (Function >> 16),
585 1.1 christos (UINT32) Address, (UINT32) BaseAddress,
586 1.1 christos Length, BitWidth, Buffer[1]);
587 1.1 christos
588 1.1 christos /* GenericSerialBus has a Connection() parameter */
589 1.1 christos
590 1.1 christos if (SpaceId == ACPI_ADR_SPACE_GSBUS)
591 1.1 christos {
592 1.1 christos Status = AcpiBufferToResource (MyContext->Connection,
593 1.1 christos MyContext->Length, &Resource);
594 1.1 christos
595 1.1 christos AcpiOsPrintf (" [AccLen %.2X Conn %p]",
596 1.1 christos MyContext->AccessLength, MyContext->Connection);
597 1.1 christos }
598 1.1 christos AcpiOsPrintf ("\n");
599 1.1 christos }
600 1.1 christos
601 1.1 christos /* Setup the return buffer. Note: ASLTS depends on these fill values */
602 1.1 christos
603 1.1 christos for (i = 0; i < Length; i++)
604 1.1 christos {
605 1.1 christos Buffer[i+2] = (UINT8) (0xA0 + i);
606 1.1 christos }
607 1.1 christos
608 1.1 christos Buffer[0] = 0x7A;
609 1.1 christos Buffer[1] = (UINT8) Length;
610 1.1 christos return (AE_OK);
611 1.1 christos
612 1.1 christos
613 1.1 christos case ACPI_ADR_SPACE_IPMI: /* ACPI 4.0 */
614 1.1 christos
615 1.1 christos if (AcpiGbl_DisplayRegionAccess)
616 1.1 christos {
617 1.1 christos AcpiOsPrintf ("AcpiExec: IPMI "
618 1.1 christos "%s: Attr %X Addr %.4X BaseAddr %.4X Len %.2X Width %X BufLen %X\n",
619 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ",
620 1.1 christos (UINT32) (Function >> 16), (UINT32) Address, (UINT32) BaseAddress,
621 1.1 christos Length, BitWidth, Buffer[1]);
622 1.1 christos }
623 1.1 christos
624 1.1 christos /*
625 1.1 christos * Regardless of a READ or WRITE, this handler is passed a 66-byte
626 1.1 christos * buffer in which to return the IPMI status/length/data.
627 1.1 christos *
628 1.1 christos * Return some example data to show use of the bidirectional buffer
629 1.1 christos */
630 1.1 christos Buffer[0] = 0; /* Status byte */
631 1.1 christos Buffer[1] = 64; /* Return buffer data length */
632 1.1 christos Buffer[2] = 0; /* Completion code */
633 1.1 christos Buffer[3] = 0; /* Reserved */
634 1.1 christos
635 1.1 christos /*
636 1.1 christos * Fill the 66-byte buffer with the return data.
637 1.1 christos * Note: ASLTS depends on these fill values.
638 1.1 christos */
639 1.1 christos for (i = 4; i < 66; i++)
640 1.1 christos {
641 1.1 christos Buffer[i] = (UINT8) (i);
642 1.1 christos }
643 1.1 christos return (AE_OK);
644 1.1 christos
645 1.1 christos /*
646 1.1 christos * GPIO has some special semantics:
647 1.1 christos * 1) Address is the pin number index into the Connection() pin list
648 1.1 christos * 2) BitWidth is the actual number of bits (pins) defined by the field
649 1.1 christos */
650 1.1 christos case ACPI_ADR_SPACE_GPIO: /* ACPI 5.0 */
651 1.1 christos
652 1.1 christos if (AcpiGbl_DisplayRegionAccess)
653 1.1 christos {
654 1.1 christos AcpiOsPrintf ("AcpiExec: GPIO "
655 1.1 christos "%s: Addr %.4X Width %X Conn %p\n",
656 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ",
657 1.1 christos (UINT32) Address, BitWidth, MyContext->Connection);
658 1.1 christos }
659 1.1 christos return (AE_OK);
660 1.1 christos
661 1.1 christos default:
662 1.1 christos break;
663 1.1 christos }
664 1.1 christos
665 1.1 christos /*
666 1.1 christos * Search through the linked list for this region's buffer
667 1.1 christos */
668 1.1 christos BufferExists = FALSE;
669 1.1 christos BufferResize = FALSE;
670 1.1 christos RegionElement = AeRegions.RegionList;
671 1.1 christos
672 1.1 christos if (AeRegions.NumberOfRegions)
673 1.1 christos {
674 1.1 christos BaseAddressEnd = BaseAddress + Length - 1;
675 1.1 christos while (!BufferExists && RegionElement)
676 1.1 christos {
677 1.1 christos RegionAddress = RegionElement->Address;
678 1.1 christos RegionAddressEnd = RegionElement->Address + RegionElement->Length - 1;
679 1.1 christos RegionLength = RegionElement->Length;
680 1.1 christos
681 1.1 christos /*
682 1.1 christos * Overlapping Region Support
683 1.1 christos *
684 1.1 christos * While searching through the region buffer list, determine if an
685 1.1 christos * overlap exists between the requested buffer space and the current
686 1.1 christos * RegionElement space. If there is an overlap then replace the old
687 1.1 christos * buffer with a new buffer of increased size before continuing to
688 1.1 christos * do the read or write
689 1.1 christos */
690 1.1 christos if (RegionElement->SpaceId != SpaceId ||
691 1.1 christos BaseAddressEnd < RegionAddress ||
692 1.1 christos BaseAddress > RegionAddressEnd)
693 1.1 christos {
694 1.1 christos /*
695 1.1 christos * Requested buffer is outside of the current RegionElement
696 1.1 christos * bounds
697 1.1 christos */
698 1.1 christos RegionElement = RegionElement->NextRegion;
699 1.1 christos }
700 1.1 christos else
701 1.1 christos {
702 1.1 christos /*
703 1.1 christos * Some amount of buffer space sharing exists. There are 4 cases
704 1.1 christos * to consider:
705 1.1 christos *
706 1.1 christos * 1. Right overlap
707 1.1 christos * 2. Left overlap
708 1.1 christos * 3. Left and right overlap
709 1.1 christos * 4. Fully contained - no resizing required
710 1.1 christos */
711 1.1 christos BufferExists = TRUE;
712 1.1 christos
713 1.1 christos if ((BaseAddress >= RegionAddress) &&
714 1.1 christos (BaseAddress <= RegionAddressEnd) &&
715 1.1 christos (BaseAddressEnd > RegionAddressEnd))
716 1.1 christos {
717 1.1 christos /* Right overlap */
718 1.1 christos
719 1.1.1.2 christos RegionElement->Length = (UINT32) (BaseAddress -
720 1.1.1.2 christos RegionAddress + Length);
721 1.1 christos BufferResize = TRUE;
722 1.1 christos }
723 1.1 christos
724 1.1 christos else if ((BaseAddressEnd >= RegionAddress) &&
725 1.1 christos (BaseAddressEnd <= RegionAddressEnd) &&
726 1.1 christos (BaseAddress < RegionAddress))
727 1.1 christos {
728 1.1 christos /* Left overlap */
729 1.1 christos
730 1.1 christos RegionElement->Address = BaseAddress;
731 1.1.1.2 christos RegionElement->Length = (UINT32) (RegionAddress -
732 1.1.1.2 christos BaseAddress + RegionElement->Length);
733 1.1 christos BufferResize = TRUE;
734 1.1 christos }
735 1.1 christos
736 1.1 christos else if ((BaseAddress < RegionAddress) &&
737 1.1 christos (BaseAddressEnd > RegionAddressEnd))
738 1.1 christos {
739 1.1 christos /* Left and right overlap */
740 1.1 christos
741 1.1 christos RegionElement->Address = BaseAddress;
742 1.1 christos RegionElement->Length = Length;
743 1.1 christos BufferResize = TRUE;
744 1.1 christos }
745 1.1 christos
746 1.1 christos /*
747 1.1 christos * only remaining case is fully contained for which we don't
748 1.1 christos * need to do anything
749 1.1 christos */
750 1.1 christos if (BufferResize)
751 1.1 christos {
752 1.1 christos NewBuffer = AcpiOsAllocate (RegionElement->Length);
753 1.1 christos if (!NewBuffer)
754 1.1 christos {
755 1.1 christos return (AE_NO_MEMORY);
756 1.1 christos }
757 1.1 christos
758 1.1 christos OldBuffer = RegionElement->Buffer;
759 1.1 christos RegionElement->Buffer = NewBuffer;
760 1.1 christos NewBuffer = NULL;
761 1.1 christos
762 1.1 christos /* Initialize the region with the default fill value */
763 1.1 christos
764 1.1.1.3 christos memset (RegionElement->Buffer,
765 1.1 christos AcpiGbl_RegionFillValue, RegionElement->Length);
766 1.1 christos
767 1.1 christos /*
768 1.1 christos * Get BufferValue to point (within the new buffer) to the
769 1.1 christos * base address of the old buffer
770 1.1 christos */
771 1.1 christos BufferValue = (UINT8 *) RegionElement->Buffer +
772 1.1 christos (UINT64) RegionAddress -
773 1.1 christos (UINT64) RegionElement->Address;
774 1.1 christos
775 1.1 christos /*
776 1.1 christos * Copy the old buffer to its same location within the new
777 1.1 christos * buffer
778 1.1 christos */
779 1.1.1.3 christos memcpy (BufferValue, OldBuffer, RegionLength);
780 1.1 christos AcpiOsFree (OldBuffer);
781 1.1 christos }
782 1.1 christos }
783 1.1 christos }
784 1.1 christos }
785 1.1 christos
786 1.1 christos /*
787 1.1 christos * If the Region buffer does not exist, create it now
788 1.1 christos */
789 1.1 christos if (!BufferExists)
790 1.1 christos {
791 1.1 christos /* Do the memory allocations first */
792 1.1 christos
793 1.1 christos RegionElement = AcpiOsAllocate (sizeof (AE_REGION));
794 1.1 christos if (!RegionElement)
795 1.1 christos {
796 1.1 christos return (AE_NO_MEMORY);
797 1.1 christos }
798 1.1 christos
799 1.1 christos RegionElement->Buffer = AcpiOsAllocate (Length);
800 1.1 christos if (!RegionElement->Buffer)
801 1.1 christos {
802 1.1 christos AcpiOsFree (RegionElement);
803 1.1 christos return (AE_NO_MEMORY);
804 1.1 christos }
805 1.1 christos
806 1.1 christos /* Initialize the region with the default fill value */
807 1.1 christos
808 1.1.1.3 christos memset (RegionElement->Buffer, AcpiGbl_RegionFillValue, Length);
809 1.1 christos
810 1.1 christos RegionElement->Address = BaseAddress;
811 1.1 christos RegionElement->Length = Length;
812 1.1 christos RegionElement->SpaceId = SpaceId;
813 1.1 christos RegionElement->NextRegion = NULL;
814 1.1 christos
815 1.1 christos /*
816 1.1 christos * Increment the number of regions and put this one
817 1.1 christos * at the head of the list as it will probably get accessed
818 1.1 christos * more often anyway.
819 1.1 christos */
820 1.1 christos AeRegions.NumberOfRegions += 1;
821 1.1 christos
822 1.1 christos if (AeRegions.RegionList)
823 1.1 christos {
824 1.1 christos RegionElement->NextRegion = AeRegions.RegionList;
825 1.1 christos }
826 1.1 christos
827 1.1 christos AeRegions.RegionList = RegionElement;
828 1.1 christos }
829 1.1 christos
830 1.1 christos /* Calculate the size of the memory copy */
831 1.1 christos
832 1.1 christos ByteWidth = (BitWidth / 8);
833 1.1 christos
834 1.1 christos if (BitWidth % 8)
835 1.1 christos {
836 1.1 christos ByteWidth += 1;
837 1.1 christos }
838 1.1 christos
839 1.1 christos /*
840 1.1 christos * The buffer exists and is pointed to by RegionElement.
841 1.1 christos * We now need to verify the request is valid and perform the operation.
842 1.1 christos *
843 1.1 christos * NOTE: RegionElement->Length is in bytes, therefore it we compare against
844 1.1 christos * ByteWidth (see above)
845 1.1 christos */
846 1.1 christos if ((RegionObject->Region.SpaceId != ACPI_ADR_SPACE_GPIO) &&
847 1.1 christos ((UINT64) Address + ByteWidth) >
848 1.1 christos ((UINT64)(RegionElement->Address) + RegionElement->Length))
849 1.1 christos {
850 1.1 christos ACPI_WARNING ((AE_INFO,
851 1.1.1.4 christos "Request on [%4.4s] is beyond region limit "
852 1.1.1.4 christos "Req-0x%X+0x%X, Base=0x%X, Len-0x%X",
853 1.1 christos (RegionObject->Region.Node)->Name.Ascii, (UINT32) Address,
854 1.1 christos ByteWidth, (UINT32)(RegionElement->Address),
855 1.1 christos RegionElement->Length));
856 1.1 christos
857 1.1 christos return (AE_AML_REGION_LIMIT);
858 1.1 christos }
859 1.1 christos
860 1.1 christos /*
861 1.1 christos * Get BufferValue to point to the "address" in the buffer
862 1.1 christos */
863 1.1 christos BufferValue = ((UINT8 *) RegionElement->Buffer +
864 1.1.1.4 christos ((UINT64) Address - (UINT64) RegionElement->Address));
865 1.1 christos
866 1.1 christos DoFunction:
867 1.1 christos /*
868 1.1 christos * Perform a read or write to the buffer space
869 1.1 christos */
870 1.1 christos switch (Function)
871 1.1 christos {
872 1.1 christos case ACPI_READ:
873 1.1 christos /*
874 1.1 christos * Set the pointer Value to whatever is in the buffer
875 1.1 christos */
876 1.1.1.3 christos memcpy (Value, BufferValue, ByteWidth);
877 1.1 christos break;
878 1.1 christos
879 1.1 christos case ACPI_WRITE:
880 1.1 christos /*
881 1.1 christos * Write the contents of Value to the buffer
882 1.1 christos */
883 1.1.1.3 christos memcpy (BufferValue, Value, ByteWidth);
884 1.1 christos break;
885 1.1 christos
886 1.1 christos default:
887 1.1 christos
888 1.1 christos return (AE_BAD_PARAMETER);
889 1.1 christos }
890 1.1 christos
891 1.1 christos if (AcpiGbl_DisplayRegionAccess)
892 1.1 christos {
893 1.1 christos switch (SpaceId)
894 1.1 christos {
895 1.1 christos case ACPI_ADR_SPACE_SYSTEM_MEMORY:
896 1.1 christos
897 1.1 christos AcpiOsPrintf ("AcpiExec: SystemMemory "
898 1.1 christos "%s: Val %.8X Addr %.4X Width %X [REGION: BaseAddr %.4X Len %.2X]\n",
899 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ",
900 1.1 christos (UINT32) *Value, (UINT32) Address, BitWidth, (UINT32) BaseAddress, Length);
901 1.1 christos break;
902 1.1 christos
903 1.1 christos case ACPI_ADR_SPACE_GPIO: /* ACPI 5.0 */
904 1.1 christos
905 1.1 christos /* This space is required to always be ByteAcc */
906 1.1 christos
907 1.1 christos Status = AcpiBufferToResource (MyContext->Connection,
908 1.1 christos MyContext->Length, &Resource);
909 1.1 christos
910 1.1 christos AcpiOsPrintf ("AcpiExec: GeneralPurposeIo "
911 1.1 christos "%s: Val %.8X Addr %.4X BaseAddr %.4X Len %.2X Width %X AccLen %.2X Conn %p\n",
912 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ", (UINT32) *Value,
913 1.1 christos (UINT32) Address, (UINT32) BaseAddress, Length, BitWidth,
914 1.1 christos MyContext->AccessLength, MyContext->Connection);
915 1.1 christos break;
916 1.1 christos
917 1.1 christos default:
918 1.1 christos
919 1.1 christos break;
920 1.1 christos }
921 1.1 christos }
922 1.1 christos
923 1.1 christos return (AE_OK);
924 1.1 christos }
925