aeregion.c revision 1.1.1.9 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1.1.6 christos * Module Name: aeregion - Handler for operation regions
4 1.1 christos *
5 1.1 christos *****************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.1.1.7 christos * Copyright (C) 2000 - 2018, 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 static AE_DEBUG_REGIONS AeRegions;
51 1.1 christos
52 1.1 christos
53 1.1 christos /******************************************************************************
54 1.1 christos *
55 1.1 christos * FUNCTION: AeRegionHandler
56 1.1 christos *
57 1.1 christos * PARAMETERS: Standard region handler parameters
58 1.1 christos *
59 1.1 christos * RETURN: Status
60 1.1 christos *
61 1.1 christos * DESCRIPTION: Test handler - Handles some dummy regions via memory that can
62 1.1 christos * be manipulated in Ring 3. Simulates actual reads and writes.
63 1.1 christos *
64 1.1 christos *****************************************************************************/
65 1.1 christos
66 1.1 christos ACPI_STATUS
67 1.1 christos AeRegionHandler (
68 1.1 christos UINT32 Function,
69 1.1 christos ACPI_PHYSICAL_ADDRESS Address,
70 1.1 christos UINT32 BitWidth,
71 1.1 christos UINT64 *Value,
72 1.1 christos void *HandlerContext,
73 1.1 christos void *RegionContext)
74 1.1 christos {
75 1.1 christos
76 1.1 christos ACPI_OPERAND_OBJECT *RegionObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, RegionContext);
77 1.1 christos UINT8 *Buffer = ACPI_CAST_PTR (UINT8, Value);
78 1.1 christos UINT8 *OldBuffer;
79 1.1 christos UINT8 *NewBuffer;
80 1.1 christos ACPI_PHYSICAL_ADDRESS BaseAddress;
81 1.1 christos ACPI_PHYSICAL_ADDRESS BaseAddressEnd;
82 1.1 christos ACPI_PHYSICAL_ADDRESS RegionAddress;
83 1.1 christos ACPI_PHYSICAL_ADDRESS RegionAddressEnd;
84 1.1.1.9 christos UINT32 Length;
85 1.1.1.9 christos UINT8 DataLength;
86 1.1.1.9 christos UINT8 *DataBuffer;
87 1.1 christos BOOLEAN BufferExists;
88 1.1 christos BOOLEAN BufferResize;
89 1.1 christos AE_REGION *RegionElement;
90 1.1 christos void *BufferValue;
91 1.1 christos ACPI_STATUS Status;
92 1.1 christos UINT32 ByteWidth;
93 1.1 christos UINT32 RegionLength;
94 1.1 christos UINT32 i;
95 1.1 christos UINT8 SpaceId;
96 1.1 christos ACPI_CONNECTION_INFO *MyContext;
97 1.1 christos UINT32 Value1;
98 1.1 christos UINT32 Value2;
99 1.1 christos ACPI_RESOURCE *Resource;
100 1.1 christos
101 1.1 christos
102 1.1 christos ACPI_FUNCTION_NAME (AeRegionHandler);
103 1.1 christos
104 1.1.1.9 christos
105 1.1.1.9 christos /* If the object is not a region, simply return */
106 1.1.1.9 christos
107 1.1 christos if (RegionObject->Region.Type != ACPI_TYPE_REGION)
108 1.1 christos {
109 1.1 christos return (AE_OK);
110 1.1 christos }
111 1.1 christos
112 1.1 christos /* Check that we actually got back our context parameter */
113 1.1 christos
114 1.1 christos if (HandlerContext != &AeMyContext)
115 1.1 christos {
116 1.1.1.9 christos AcpiOsPrintf (
117 1.1.1.9 christos "Region handler received incorrect context %p, should be %p\n",
118 1.1 christos HandlerContext, &AeMyContext);
119 1.1 christos }
120 1.1 christos
121 1.1 christos MyContext = ACPI_CAST_PTR (ACPI_CONNECTION_INFO, HandlerContext);
122 1.1 christos
123 1.1 christos /*
124 1.1 christos * Find the region's address space and length before searching
125 1.1 christos * the linked list.
126 1.1 christos */
127 1.1 christos BaseAddress = RegionObject->Region.Address;
128 1.1.1.9 christos Length = RegionObject->Region.Length;
129 1.1 christos SpaceId = RegionObject->Region.SpaceId;
130 1.1 christos
131 1.1.1.4 christos ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
132 1.1.1.8 christos "Operation Region request on %s at 0x%X, BitWidth 0x%X, RegionLength 0x%X\n",
133 1.1.1.4 christos AcpiUtGetRegionName (RegionObject->Region.SpaceId),
134 1.1.1.8 christos (UINT32) Address, BitWidth, (UINT32) Length));
135 1.1 christos
136 1.1 christos /*
137 1.1 christos * Region support can be disabled with the -do option.
138 1.1 christos * We use this to support dynamically loaded tables where we pass a valid
139 1.1 christos * address to the AML.
140 1.1 christos */
141 1.1 christos if (AcpiGbl_DbOpt_NoRegionSupport)
142 1.1 christos {
143 1.1 christos BufferValue = ACPI_TO_POINTER (Address);
144 1.1 christos ByteWidth = (BitWidth / 8);
145 1.1 christos
146 1.1 christos if (BitWidth % 8)
147 1.1 christos {
148 1.1 christos ByteWidth += 1;
149 1.1 christos }
150 1.1 christos goto DoFunction;
151 1.1 christos }
152 1.1 christos
153 1.1 christos switch (SpaceId)
154 1.1 christos {
155 1.1 christos case ACPI_ADR_SPACE_SYSTEM_IO:
156 1.1 christos /*
157 1.1 christos * For I/O space, exercise the port validation
158 1.1 christos * Note: ReadPort currently always returns all ones, length=BitLength
159 1.1 christos */
160 1.1 christos switch (Function & ACPI_IO_MASK)
161 1.1 christos {
162 1.1 christos case ACPI_READ:
163 1.1 christos
164 1.1 christos if (BitWidth == 64)
165 1.1 christos {
166 1.1 christos /* Split the 64-bit request into two 32-bit requests */
167 1.1 christos
168 1.1 christos Status = AcpiHwReadPort (Address, &Value1, 32);
169 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwReadPort, Status);
170 1.1 christos Status = AcpiHwReadPort (Address+4, &Value2, 32);
171 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwReadPort, Status);
172 1.1 christos
173 1.1 christos *Value = Value1 | ((UINT64) Value2 << 32);
174 1.1 christos }
175 1.1 christos else
176 1.1 christos {
177 1.1 christos Status = AcpiHwReadPort (Address, &Value1, BitWidth);
178 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwReadPort, Status);
179 1.1 christos *Value = (UINT64) Value1;
180 1.1 christos }
181 1.1 christos break;
182 1.1 christos
183 1.1 christos case ACPI_WRITE:
184 1.1 christos
185 1.1 christos if (BitWidth == 64)
186 1.1 christos {
187 1.1 christos /* Split the 64-bit request into two 32-bit requests */
188 1.1 christos
189 1.1 christos Status = AcpiHwWritePort (Address, ACPI_LODWORD (*Value), 32);
190 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwWritePort, Status);
191 1.1 christos Status = AcpiHwWritePort (Address+4, ACPI_HIDWORD (*Value), 32);
192 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwWritePort, Status);
193 1.1 christos }
194 1.1 christos else
195 1.1 christos {
196 1.1 christos Status = AcpiHwWritePort (Address, (UINT32) *Value, BitWidth);
197 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwWritePort, Status);
198 1.1 christos }
199 1.1 christos break;
200 1.1 christos
201 1.1 christos default:
202 1.1 christos
203 1.1 christos Status = AE_BAD_PARAMETER;
204 1.1 christos break;
205 1.1 christos }
206 1.1 christos
207 1.1 christos if (ACPI_FAILURE (Status))
208 1.1 christos {
209 1.1 christos return (Status);
210 1.1 christos }
211 1.1 christos
212 1.1 christos /* Now go ahead and simulate the hardware */
213 1.1 christos break;
214 1.1 christos
215 1.1 christos /*
216 1.1 christos * SMBus and GenericSerialBus support the various bidirectional
217 1.1 christos * protocols.
218 1.1 christos */
219 1.1 christos case ACPI_ADR_SPACE_SMBUS:
220 1.1 christos case ACPI_ADR_SPACE_GSBUS: /* ACPI 5.0 */
221 1.1 christos
222 1.1.1.9 christos Status = AcpiExGetProtocolBufferLength ((Function >> 16), &Length);
223 1.1.1.9 christos if (ACPI_FAILURE (Status))
224 1.1 christos {
225 1.1.1.9 christos AcpiOsPrintf ("AcpiExec: Invalid SMbus/GSbus protocol ID: 0x%X\n",
226 1.1.1.9 christos (Function >> 16));
227 1.1.1.9 christos return (Status);
228 1.1.1.9 christos }
229 1.1 christos
230 1.1.1.9 christos /* Adjust for fixed SMBus buffer size */
231 1.1 christos
232 1.1.1.9 christos if ((SpaceId == ACPI_ADR_SPACE_SMBUS) &&
233 1.1.1.9 christos (Length > ACPI_SMBUS_DATA_SIZE))
234 1.1.1.9 christos {
235 1.1.1.9 christos Length = ACPI_SMBUS_DATA_SIZE; /* SMBus buffer is fixed-length */
236 1.1 christos }
237 1.1 christos
238 1.1 christos if (AcpiGbl_DisplayRegionAccess)
239 1.1 christos {
240 1.1 christos AcpiOsPrintf ("AcpiExec: %s "
241 1.1.1.9 christos "%s: Attr %X Addr %.4X BaseAddr %.4X Length %.2X BitWidth %X BufLen %X\n",
242 1.1 christos AcpiUtGetRegionName (SpaceId),
243 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ",
244 1.1 christos (UINT32) (Function >> 16),
245 1.1 christos (UINT32) Address, (UINT32) BaseAddress,
246 1.1 christos Length, BitWidth, Buffer[1]);
247 1.1 christos
248 1.1 christos /* GenericSerialBus has a Connection() parameter */
249 1.1 christos
250 1.1.1.9 christos if ((SpaceId == ACPI_ADR_SPACE_GSBUS) && MyContext)
251 1.1 christos {
252 1.1 christos Status = AcpiBufferToResource (MyContext->Connection,
253 1.1 christos MyContext->Length, &Resource);
254 1.1.1.9 christos if (ACPI_SUCCESS (Status))
255 1.1.1.9 christos {
256 1.1.1.9 christos ACPI_FREE (Resource);
257 1.1.1.9 christos }
258 1.1 christos
259 1.1.1.8 christos AcpiOsPrintf (" [AccessLength %.2X Connnection %p]",
260 1.1 christos MyContext->AccessLength, MyContext->Connection);
261 1.1 christos }
262 1.1.1.9 christos
263 1.1 christos AcpiOsPrintf ("\n");
264 1.1 christos }
265 1.1 christos
266 1.1.1.9 christos DataBuffer = &Buffer[2];
267 1.1.1.9 christos DataLength = (UINT8) Length;
268 1.1.1.9 christos
269 1.1 christos /* Setup the return buffer. Note: ASLTS depends on these fill values */
270 1.1 christos
271 1.1.1.9 christos if (Length == ACPI_MAX_GSBUS_DATA_SIZE)
272 1.1.1.9 christos {
273 1.1.1.9 christos DataLength = 0x20; /* For ASLTS only */
274 1.1.1.9 christos }
275 1.1.1.9 christos
276 1.1 christos for (i = 0; i < Length; i++)
277 1.1 christos {
278 1.1.1.9 christos DataBuffer[i] = (UINT8) (0xA0 + i);
279 1.1 christos }
280 1.1 christos
281 1.1.1.9 christos Buffer[0] = 0; /* Return Status, OK */
282 1.1.1.9 christos Buffer[1] = DataLength; /* Length of valid data */
283 1.1 christos return (AE_OK);
284 1.1 christos
285 1.1 christos case ACPI_ADR_SPACE_IPMI: /* ACPI 4.0 */
286 1.1 christos
287 1.1 christos if (AcpiGbl_DisplayRegionAccess)
288 1.1 christos {
289 1.1 christos AcpiOsPrintf ("AcpiExec: IPMI "
290 1.1 christos "%s: Attr %X Addr %.4X BaseAddr %.4X Len %.2X Width %X BufLen %X\n",
291 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ",
292 1.1 christos (UINT32) (Function >> 16), (UINT32) Address, (UINT32) BaseAddress,
293 1.1 christos Length, BitWidth, Buffer[1]);
294 1.1 christos }
295 1.1 christos
296 1.1 christos /*
297 1.1 christos * Regardless of a READ or WRITE, this handler is passed a 66-byte
298 1.1 christos * buffer in which to return the IPMI status/length/data.
299 1.1 christos *
300 1.1 christos * Return some example data to show use of the bidirectional buffer
301 1.1 christos */
302 1.1.1.9 christos Buffer[0] = 0; /* Status byte */
303 1.1.1.9 christos Buffer[1] = ACPI_IPMI_DATA_SIZE; /* Return buffer data length */
304 1.1.1.9 christos Buffer[2] = 0; /* Completion code */
305 1.1.1.9 christos Buffer[3] = 0; /* Reserved */
306 1.1 christos
307 1.1 christos /*
308 1.1 christos * Fill the 66-byte buffer with the return data.
309 1.1 christos * Note: ASLTS depends on these fill values.
310 1.1 christos */
311 1.1.1.9 christos for (i = 4; i < ACPI_IPMI_BUFFER_SIZE; i++)
312 1.1 christos {
313 1.1 christos Buffer[i] = (UINT8) (i);
314 1.1 christos }
315 1.1 christos return (AE_OK);
316 1.1 christos
317 1.1 christos /*
318 1.1 christos * GPIO has some special semantics:
319 1.1 christos * 1) Address is the pin number index into the Connection() pin list
320 1.1 christos * 2) BitWidth is the actual number of bits (pins) defined by the field
321 1.1 christos */
322 1.1 christos case ACPI_ADR_SPACE_GPIO: /* ACPI 5.0 */
323 1.1 christos
324 1.1 christos if (AcpiGbl_DisplayRegionAccess)
325 1.1 christos {
326 1.1 christos AcpiOsPrintf ("AcpiExec: GPIO "
327 1.1.1.9 christos "%s: Address %.4X Length %X BitWidth %X Conn %p\n",
328 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ",
329 1.1.1.9 christos (UINT32) Address, Length, BitWidth, MyContext->Connection);
330 1.1 christos }
331 1.1.1.9 christos
332 1.1.1.9 christos /* Now perform the "normal" SystemMemory handling, for AcpiExec only */
333 1.1.1.9 christos break;
334 1.1 christos
335 1.1 christos default:
336 1.1 christos break;
337 1.1 christos }
338 1.1 christos
339 1.1 christos /*
340 1.1 christos * Search through the linked list for this region's buffer
341 1.1 christos */
342 1.1 christos BufferExists = FALSE;
343 1.1 christos BufferResize = FALSE;
344 1.1 christos RegionElement = AeRegions.RegionList;
345 1.1 christos
346 1.1 christos if (AeRegions.NumberOfRegions)
347 1.1 christos {
348 1.1 christos BaseAddressEnd = BaseAddress + Length - 1;
349 1.1 christos while (!BufferExists && RegionElement)
350 1.1 christos {
351 1.1 christos RegionAddress = RegionElement->Address;
352 1.1 christos RegionAddressEnd = RegionElement->Address + RegionElement->Length - 1;
353 1.1 christos RegionLength = RegionElement->Length;
354 1.1 christos
355 1.1 christos /*
356 1.1 christos * Overlapping Region Support
357 1.1 christos *
358 1.1 christos * While searching through the region buffer list, determine if an
359 1.1 christos * overlap exists between the requested buffer space and the current
360 1.1 christos * RegionElement space. If there is an overlap then replace the old
361 1.1 christos * buffer with a new buffer of increased size before continuing to
362 1.1 christos * do the read or write
363 1.1 christos */
364 1.1 christos if (RegionElement->SpaceId != SpaceId ||
365 1.1 christos BaseAddressEnd < RegionAddress ||
366 1.1 christos BaseAddress > RegionAddressEnd)
367 1.1 christos {
368 1.1 christos /*
369 1.1 christos * Requested buffer is outside of the current RegionElement
370 1.1 christos * bounds
371 1.1 christos */
372 1.1 christos RegionElement = RegionElement->NextRegion;
373 1.1 christos }
374 1.1 christos else
375 1.1 christos {
376 1.1 christos /*
377 1.1 christos * Some amount of buffer space sharing exists. There are 4 cases
378 1.1 christos * to consider:
379 1.1 christos *
380 1.1 christos * 1. Right overlap
381 1.1 christos * 2. Left overlap
382 1.1 christos * 3. Left and right overlap
383 1.1 christos * 4. Fully contained - no resizing required
384 1.1 christos */
385 1.1 christos BufferExists = TRUE;
386 1.1 christos
387 1.1 christos if ((BaseAddress >= RegionAddress) &&
388 1.1 christos (BaseAddress <= RegionAddressEnd) &&
389 1.1 christos (BaseAddressEnd > RegionAddressEnd))
390 1.1 christos {
391 1.1 christos /* Right overlap */
392 1.1 christos
393 1.1.1.2 christos RegionElement->Length = (UINT32) (BaseAddress -
394 1.1.1.2 christos RegionAddress + Length);
395 1.1 christos BufferResize = TRUE;
396 1.1 christos }
397 1.1 christos
398 1.1 christos else if ((BaseAddressEnd >= RegionAddress) &&
399 1.1 christos (BaseAddressEnd <= RegionAddressEnd) &&
400 1.1 christos (BaseAddress < RegionAddress))
401 1.1 christos {
402 1.1 christos /* Left overlap */
403 1.1 christos
404 1.1 christos RegionElement->Address = BaseAddress;
405 1.1.1.2 christos RegionElement->Length = (UINT32) (RegionAddress -
406 1.1.1.2 christos BaseAddress + RegionElement->Length);
407 1.1 christos BufferResize = TRUE;
408 1.1 christos }
409 1.1 christos
410 1.1 christos else if ((BaseAddress < RegionAddress) &&
411 1.1 christos (BaseAddressEnd > RegionAddressEnd))
412 1.1 christos {
413 1.1 christos /* Left and right overlap */
414 1.1 christos
415 1.1 christos RegionElement->Address = BaseAddress;
416 1.1 christos RegionElement->Length = Length;
417 1.1 christos BufferResize = TRUE;
418 1.1 christos }
419 1.1 christos
420 1.1 christos /*
421 1.1 christos * only remaining case is fully contained for which we don't
422 1.1 christos * need to do anything
423 1.1 christos */
424 1.1 christos if (BufferResize)
425 1.1 christos {
426 1.1 christos NewBuffer = AcpiOsAllocate (RegionElement->Length);
427 1.1 christos if (!NewBuffer)
428 1.1 christos {
429 1.1 christos return (AE_NO_MEMORY);
430 1.1 christos }
431 1.1 christos
432 1.1 christos OldBuffer = RegionElement->Buffer;
433 1.1 christos RegionElement->Buffer = NewBuffer;
434 1.1 christos NewBuffer = NULL;
435 1.1 christos
436 1.1 christos /* Initialize the region with the default fill value */
437 1.1 christos
438 1.1.1.3 christos memset (RegionElement->Buffer,
439 1.1 christos AcpiGbl_RegionFillValue, RegionElement->Length);
440 1.1 christos
441 1.1 christos /*
442 1.1 christos * Get BufferValue to point (within the new buffer) to the
443 1.1 christos * base address of the old buffer
444 1.1 christos */
445 1.1 christos BufferValue = (UINT8 *) RegionElement->Buffer +
446 1.1 christos (UINT64) RegionAddress -
447 1.1 christos (UINT64) RegionElement->Address;
448 1.1 christos
449 1.1 christos /*
450 1.1 christos * Copy the old buffer to its same location within the new
451 1.1 christos * buffer
452 1.1 christos */
453 1.1.1.3 christos memcpy (BufferValue, OldBuffer, RegionLength);
454 1.1 christos AcpiOsFree (OldBuffer);
455 1.1 christos }
456 1.1 christos }
457 1.1 christos }
458 1.1 christos }
459 1.1 christos
460 1.1 christos /*
461 1.1 christos * If the Region buffer does not exist, create it now
462 1.1 christos */
463 1.1 christos if (!BufferExists)
464 1.1 christos {
465 1.1 christos /* Do the memory allocations first */
466 1.1 christos
467 1.1 christos RegionElement = AcpiOsAllocate (sizeof (AE_REGION));
468 1.1 christos if (!RegionElement)
469 1.1 christos {
470 1.1 christos return (AE_NO_MEMORY);
471 1.1 christos }
472 1.1 christos
473 1.1 christos RegionElement->Buffer = AcpiOsAllocate (Length);
474 1.1 christos if (!RegionElement->Buffer)
475 1.1 christos {
476 1.1 christos AcpiOsFree (RegionElement);
477 1.1 christos return (AE_NO_MEMORY);
478 1.1 christos }
479 1.1 christos
480 1.1 christos /* Initialize the region with the default fill value */
481 1.1 christos
482 1.1.1.3 christos memset (RegionElement->Buffer, AcpiGbl_RegionFillValue, Length);
483 1.1 christos
484 1.1 christos RegionElement->Address = BaseAddress;
485 1.1 christos RegionElement->Length = Length;
486 1.1 christos RegionElement->SpaceId = SpaceId;
487 1.1 christos RegionElement->NextRegion = NULL;
488 1.1 christos
489 1.1 christos /*
490 1.1 christos * Increment the number of regions and put this one
491 1.1 christos * at the head of the list as it will probably get accessed
492 1.1 christos * more often anyway.
493 1.1 christos */
494 1.1 christos AeRegions.NumberOfRegions += 1;
495 1.1 christos
496 1.1 christos if (AeRegions.RegionList)
497 1.1 christos {
498 1.1 christos RegionElement->NextRegion = AeRegions.RegionList;
499 1.1 christos }
500 1.1 christos
501 1.1 christos AeRegions.RegionList = RegionElement;
502 1.1 christos }
503 1.1 christos
504 1.1 christos /* Calculate the size of the memory copy */
505 1.1 christos
506 1.1 christos ByteWidth = (BitWidth / 8);
507 1.1 christos if (BitWidth % 8)
508 1.1 christos {
509 1.1 christos ByteWidth += 1;
510 1.1 christos }
511 1.1 christos
512 1.1 christos /*
513 1.1 christos * The buffer exists and is pointed to by RegionElement.
514 1.1 christos * We now need to verify the request is valid and perform the operation.
515 1.1 christos *
516 1.1 christos * NOTE: RegionElement->Length is in bytes, therefore it we compare against
517 1.1 christos * ByteWidth (see above)
518 1.1 christos */
519 1.1 christos if ((RegionObject->Region.SpaceId != ACPI_ADR_SPACE_GPIO) &&
520 1.1 christos ((UINT64) Address + ByteWidth) >
521 1.1 christos ((UINT64)(RegionElement->Address) + RegionElement->Length))
522 1.1 christos {
523 1.1 christos ACPI_WARNING ((AE_INFO,
524 1.1.1.4 christos "Request on [%4.4s] is beyond region limit "
525 1.1.1.4 christos "Req-0x%X+0x%X, Base=0x%X, Len-0x%X",
526 1.1 christos (RegionObject->Region.Node)->Name.Ascii, (UINT32) Address,
527 1.1 christos ByteWidth, (UINT32)(RegionElement->Address),
528 1.1 christos RegionElement->Length));
529 1.1 christos
530 1.1 christos return (AE_AML_REGION_LIMIT);
531 1.1 christos }
532 1.1 christos
533 1.1 christos /*
534 1.1 christos * Get BufferValue to point to the "address" in the buffer
535 1.1 christos */
536 1.1 christos BufferValue = ((UINT8 *) RegionElement->Buffer +
537 1.1.1.4 christos ((UINT64) Address - (UINT64) RegionElement->Address));
538 1.1 christos
539 1.1 christos DoFunction:
540 1.1 christos /*
541 1.1 christos * Perform a read or write to the buffer space
542 1.1 christos */
543 1.1 christos switch (Function)
544 1.1 christos {
545 1.1 christos case ACPI_READ:
546 1.1 christos /*
547 1.1 christos * Set the pointer Value to whatever is in the buffer
548 1.1 christos */
549 1.1.1.3 christos memcpy (Value, BufferValue, ByteWidth);
550 1.1 christos break;
551 1.1 christos
552 1.1 christos case ACPI_WRITE:
553 1.1 christos /*
554 1.1 christos * Write the contents of Value to the buffer
555 1.1 christos */
556 1.1.1.3 christos memcpy (BufferValue, Value, ByteWidth);
557 1.1 christos break;
558 1.1 christos
559 1.1 christos default:
560 1.1 christos
561 1.1 christos return (AE_BAD_PARAMETER);
562 1.1 christos }
563 1.1 christos
564 1.1 christos if (AcpiGbl_DisplayRegionAccess)
565 1.1 christos {
566 1.1 christos switch (SpaceId)
567 1.1 christos {
568 1.1 christos case ACPI_ADR_SPACE_SYSTEM_MEMORY:
569 1.1 christos
570 1.1 christos AcpiOsPrintf ("AcpiExec: SystemMemory "
571 1.1.1.9 christos "%s: Val %.8X Addr %.4X BitWidth %X [REGION: BaseAddr %.4X Len %.2X]\n",
572 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ",
573 1.1 christos (UINT32) *Value, (UINT32) Address, BitWidth, (UINT32) BaseAddress, Length);
574 1.1 christos break;
575 1.1 christos
576 1.1.1.9 christos case ACPI_ADR_SPACE_GSBUS:
577 1.1.1.9 christos
578 1.1.1.9 christos AcpiOsPrintf ("AcpiExec: GenericSerialBus\n");
579 1.1.1.9 christos break;
580 1.1.1.9 christos
581 1.1 christos case ACPI_ADR_SPACE_GPIO: /* ACPI 5.0 */
582 1.1 christos
583 1.1 christos /* This space is required to always be ByteAcc */
584 1.1 christos
585 1.1 christos Status = AcpiBufferToResource (MyContext->Connection,
586 1.1 christos MyContext->Length, &Resource);
587 1.1 christos
588 1.1 christos AcpiOsPrintf ("AcpiExec: GeneralPurposeIo "
589 1.1.1.9 christos "%s: %.8X Addr %.4X BaseAddr %.4X Length %.2X "
590 1.1.1.9 christos "BitWidth %X AccLen %.2X Conn %p\n",
591 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ", (UINT32) *Value,
592 1.1 christos (UINT32) Address, (UINT32) BaseAddress, Length, BitWidth,
593 1.1 christos MyContext->AccessLength, MyContext->Connection);
594 1.1.1.9 christos if (ACPI_SUCCESS (Status))
595 1.1.1.9 christos {
596 1.1.1.9 christos ACPI_FREE (Resource);
597 1.1.1.9 christos }
598 1.1 christos break;
599 1.1 christos
600 1.1 christos default:
601 1.1 christos
602 1.1.1.9 christos AcpiOsPrintf ("AcpiExec: Region access on SpaceId %2.2X\n", SpaceId);
603 1.1 christos break;
604 1.1 christos }
605 1.1 christos }
606 1.1 christos
607 1.1 christos return (AE_OK);
608 1.1 christos }
609