Linux Audio

Check our new training course

Loading...
v3.1
  1
  2/******************************************************************************
  3 *
  4 * Module Name: exregion - ACPI default op_region (address space) handlers
  5 *
 
 
  6 *****************************************************************************/
  7
  8/*
  9 * Copyright (C) 2000 - 2011, Intel Corp.
 10 * All rights reserved.
 11 *
 12 * Redistribution and use in source and binary forms, with or without
 13 * modification, are permitted provided that the following conditions
 14 * are met:
 15 * 1. Redistributions of source code must retain the above copyright
 16 *    notice, this list of conditions, and the following disclaimer,
 17 *    without modification.
 18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 19 *    substantially similar to the "NO WARRANTY" disclaimer below
 20 *    ("Disclaimer") and any redistribution must be conditioned upon
 21 *    including a substantially similar Disclaimer requirement for further
 22 *    binary redistribution.
 23 * 3. Neither the names of the above-listed copyright holders nor the names
 24 *    of any contributors may be used to endorse or promote products derived
 25 *    from this software without specific prior written permission.
 26 *
 27 * Alternatively, this software may be distributed under the terms of the
 28 * GNU General Public License ("GPL") version 2 as published by the Free
 29 * Software Foundation.
 30 *
 31 * NO WARRANTY
 32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 42 * POSSIBILITY OF SUCH DAMAGES.
 43 */
 44
 45#include <acpi/acpi.h>
 46#include "accommon.h"
 47#include "acinterp.h"
 48
 49#define _COMPONENT          ACPI_EXECUTER
 50ACPI_MODULE_NAME("exregion")
 51
 52/*******************************************************************************
 53 *
 54 * FUNCTION:    acpi_ex_system_memory_space_handler
 55 *
 56 * PARAMETERS:  Function            - Read or Write operation
 57 *              Address             - Where in the space to read or write
 58 *              bit_width           - Field width in bits (8, 16, or 32)
 59 *              Value               - Pointer to in or out value
 60 *              handler_context     - Pointer to Handler's context
 61 *              region_context      - Pointer to context specific to the
 62 *                                    accessed region
 63 *
 64 * RETURN:      Status
 65 *
 66 * DESCRIPTION: Handler for the System Memory address space (Op Region)
 67 *
 68 ******************************************************************************/
 69acpi_status
 70acpi_ex_system_memory_space_handler(u32 function,
 71				    acpi_physical_address address,
 72				    u32 bit_width,
 73				    u64 *value,
 74				    void *handler_context, void *region_context)
 75{
 76	acpi_status status = AE_OK;
 77	void *logical_addr_ptr = NULL;
 78	struct acpi_mem_space_context *mem_info = region_context;
 
 79	u32 length;
 80	acpi_size map_length;
 81	acpi_size page_boundary_map_length;
 82#ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
 83	u32 remainder;
 84#endif
 85
 86	ACPI_FUNCTION_TRACE(ex_system_memory_space_handler);
 87
 88	/* Validate and translate the bit width */
 89
 90	switch (bit_width) {
 91	case 8:
 
 92		length = 1;
 93		break;
 94
 95	case 16:
 
 96		length = 2;
 97		break;
 98
 99	case 32:
 
100		length = 4;
101		break;
102
103	case 64:
 
104		length = 8;
105		break;
106
107	default:
 
108		ACPI_ERROR((AE_INFO, "Invalid SystemMemory width %u",
109			    bit_width));
110		return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
111	}
112
113#ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
114	/*
115	 * Hardware does not support non-aligned data transfers, we must verify
116	 * the request.
117	 */
118	(void)acpi_ut_short_divide((u64) address, length, NULL, &remainder);
119	if (remainder != 0) {
120		return_ACPI_STATUS(AE_AML_ALIGNMENT);
121	}
122#endif
123
124	/*
125	 * Does the request fit into the cached memory mapping?
126	 * Is 1) Address below the current mapping? OR
127	 *    2) Address beyond the current mapping?
128	 */
129	if ((address < mem_info->mapped_physical_address) ||
130	    (((u64) address + length) > ((u64)
131					 mem_info->mapped_physical_address +
132					 mem_info->mapped_length))) {
133		/*
134		 * The request cannot be resolved by the current memory mapping;
135		 * Delete the existing mapping and create a new one.
 
 
 
136		 */
137		if (mem_info->mapped_length) {
 
 
 
 
 
 
 
 
 
138
139			/* Valid mapping, delete it */
 
 
140
141			acpi_os_unmap_memory(mem_info->mapped_logical_address,
142					     mem_info->mapped_length);
 
 
 
 
 
143		}
144
145		/*
146		 * Attempt to map from the requested address to the end of the region.
147		 * However, we will never map more than one page, nor will we cross
148		 * a page boundary.
149		 */
150		map_length = (acpi_size)
151		    ((mem_info->address + mem_info->length) - address);
152
153		/*
154		 * If mapping the entire remaining portion of the region will cross
155		 * a page boundary, just map up to the page boundary, do not cross.
156		 * On some systems, crossing a page boundary while mapping regions
157		 * can cause warnings if the pages have different attributes
158		 * due to resource management
 
 
 
 
159		 */
160		page_boundary_map_length =
161		    ACPI_ROUND_UP(address, ACPI_DEFAULT_PAGE_SIZE) - address;
162
163		if (!page_boundary_map_length) {
164			page_boundary_map_length = ACPI_DEFAULT_PAGE_SIZE;
165		}
166
167		if (map_length > page_boundary_map_length) {
168			map_length = page_boundary_map_length;
169		}
170
171		/* Create a new mapping starting at the address given */
172
173		mem_info->mapped_logical_address = acpi_os_map_memory((acpi_physical_address) address, map_length);
174		if (!mem_info->mapped_logical_address) {
175			ACPI_ERROR((AE_INFO,
176				    "Could not map memory at 0x%8.8X%8.8X, size %u",
177				    ACPI_FORMAT_NATIVE_UINT(address),
178				    (u32) map_length));
179			mem_info->mapped_length = 0;
180			return_ACPI_STATUS(AE_NO_MEMORY);
181		}
182
183		/* Save the physical address and mapping size */
184
185		mem_info->mapped_physical_address = address;
186		mem_info->mapped_length = map_length;
 
 
 
 
 
 
 
 
 
 
187	}
188
 
189	/*
190	 * Generate a logical pointer corresponding to the address we want to
191	 * access
192	 */
193	logical_addr_ptr = mem_info->mapped_logical_address +
194	    ((u64) address - (u64) mem_info->mapped_physical_address);
195
196	ACPI_DEBUG_PRINT((ACPI_DB_INFO,
197			  "System-Memory (width %u) R/W %u Address=%8.8X%8.8X\n",
198			  bit_width, function,
199			  ACPI_FORMAT_NATIVE_UINT(address)));
200
201	/*
202	 * Perform the memory read or write
203	 *
204	 * Note: For machines that do not support non-aligned transfers, the target
205	 * address was checked for alignment above.  We do not attempt to break the
206	 * transfer up into smaller (byte-size) chunks because the AML specifically
207	 * asked for a transfer width that the hardware may require.
208	 */
209	switch (function) {
210	case ACPI_READ:
211
212		*value = 0;
213		switch (bit_width) {
214		case 8:
215			*value = (u64) ACPI_GET8(logical_addr_ptr);
 
216			break;
217
218		case 16:
219			*value = (u64) ACPI_GET16(logical_addr_ptr);
 
220			break;
221
222		case 32:
223			*value = (u64) ACPI_GET32(logical_addr_ptr);
 
224			break;
225
226		case 64:
227			*value = (u64) ACPI_GET64(logical_addr_ptr);
 
228			break;
229
230		default:
 
231			/* bit_width was already validated */
 
232			break;
233		}
234		break;
235
236	case ACPI_WRITE:
237
238		switch (bit_width) {
239		case 8:
240			ACPI_SET8(logical_addr_ptr) = (u8) * value;
 
241			break;
242
243		case 16:
244			ACPI_SET16(logical_addr_ptr) = (u16) * value;
 
245			break;
246
247		case 32:
248			ACPI_SET32(logical_addr_ptr) = (u32) * value;
 
249			break;
250
251		case 64:
252			ACPI_SET64(logical_addr_ptr) = (u64) * value;
 
253			break;
254
255		default:
 
256			/* bit_width was already validated */
 
257			break;
258		}
259		break;
260
261	default:
 
262		status = AE_BAD_PARAMETER;
263		break;
264	}
265
266	return_ACPI_STATUS(status);
267}
268
269/*******************************************************************************
270 *
271 * FUNCTION:    acpi_ex_system_io_space_handler
272 *
273 * PARAMETERS:  Function            - Read or Write operation
274 *              Address             - Where in the space to read or write
275 *              bit_width           - Field width in bits (8, 16, or 32)
276 *              Value               - Pointer to in or out value
277 *              handler_context     - Pointer to Handler's context
278 *              region_context      - Pointer to context specific to the
279 *                                    accessed region
280 *
281 * RETURN:      Status
282 *
283 * DESCRIPTION: Handler for the System IO address space (Op Region)
284 *
285 ******************************************************************************/
286
287acpi_status
288acpi_ex_system_io_space_handler(u32 function,
289				acpi_physical_address address,
290				u32 bit_width,
291				u64 *value,
292				void *handler_context, void *region_context)
293{
294	acpi_status status = AE_OK;
295	u32 value32;
296
297	ACPI_FUNCTION_TRACE(ex_system_io_space_handler);
298
299	ACPI_DEBUG_PRINT((ACPI_DB_INFO,
300			  "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n",
301			  bit_width, function,
302			  ACPI_FORMAT_NATIVE_UINT(address)));
303
304	/* Decode the function parameter */
305
306	switch (function) {
307	case ACPI_READ:
308
309		status = acpi_hw_read_port((acpi_io_address) address,
310					   &value32, bit_width);
311		*value = value32;
312		break;
313
314	case ACPI_WRITE:
315
316		status = acpi_hw_write_port((acpi_io_address) address,
317					    (u32) * value, bit_width);
318		break;
319
320	default:
 
321		status = AE_BAD_PARAMETER;
322		break;
323	}
324
325	return_ACPI_STATUS(status);
326}
327
 
328/*******************************************************************************
329 *
330 * FUNCTION:    acpi_ex_pci_config_space_handler
331 *
332 * PARAMETERS:  Function            - Read or Write operation
333 *              Address             - Where in the space to read or write
334 *              bit_width           - Field width in bits (8, 16, or 32)
335 *              Value               - Pointer to in or out value
336 *              handler_context     - Pointer to Handler's context
337 *              region_context      - Pointer to context specific to the
338 *                                    accessed region
339 *
340 * RETURN:      Status
341 *
342 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
343 *
344 ******************************************************************************/
345
346acpi_status
347acpi_ex_pci_config_space_handler(u32 function,
348				 acpi_physical_address address,
349				 u32 bit_width,
350				 u64 *value,
351				 void *handler_context, void *region_context)
352{
353	acpi_status status = AE_OK;
354	struct acpi_pci_id *pci_id;
355	u16 pci_register;
356
357	ACPI_FUNCTION_TRACE(ex_pci_config_space_handler);
358
359	/*
360	 *  The arguments to acpi_os(Read|Write)pci_configuration are:
361	 *
362	 *  pci_segment is the PCI bus segment range 0-31
363	 *  pci_bus     is the PCI bus number range 0-255
364	 *  pci_device  is the PCI device number range 0-31
365	 *  pci_function is the PCI device function number
366	 *  pci_register is the Config space register range 0-255 bytes
367	 *
368	 *  Value - input value for write, output address for read
369	 *
370	 */
371	pci_id = (struct acpi_pci_id *)region_context;
372	pci_register = (u16) (u32) address;
373
374	ACPI_DEBUG_PRINT((ACPI_DB_INFO,
375			  "Pci-Config %u (%u) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
 
376			  function, bit_width, pci_id->segment, pci_id->bus,
377			  pci_id->device, pci_id->function, pci_register));
378
379	switch (function) {
380	case ACPI_READ:
381
382		status = acpi_os_read_pci_configuration(pci_id, pci_register,
383							value, bit_width);
 
 
384		break;
385
386	case ACPI_WRITE:
387
388		status = acpi_os_write_pci_configuration(pci_id, pci_register,
389							 *value, bit_width);
 
390		break;
391
392	default:
393
394		status = AE_BAD_PARAMETER;
395		break;
396	}
397
398	return_ACPI_STATUS(status);
399}
 
400
401/*******************************************************************************
402 *
403 * FUNCTION:    acpi_ex_cmos_space_handler
404 *
405 * PARAMETERS:  Function            - Read or Write operation
406 *              Address             - Where in the space to read or write
407 *              bit_width           - Field width in bits (8, 16, or 32)
408 *              Value               - Pointer to in or out value
409 *              handler_context     - Pointer to Handler's context
410 *              region_context      - Pointer to context specific to the
411 *                                    accessed region
412 *
413 * RETURN:      Status
414 *
415 * DESCRIPTION: Handler for the CMOS address space (Op Region)
416 *
417 ******************************************************************************/
418
419acpi_status
420acpi_ex_cmos_space_handler(u32 function,
421			   acpi_physical_address address,
422			   u32 bit_width,
423			   u64 *value,
424			   void *handler_context, void *region_context)
425{
426	acpi_status status = AE_OK;
427
428	ACPI_FUNCTION_TRACE(ex_cmos_space_handler);
429
430	return_ACPI_STATUS(status);
431}
432
 
433/*******************************************************************************
434 *
435 * FUNCTION:    acpi_ex_pci_bar_space_handler
436 *
437 * PARAMETERS:  Function            - Read or Write operation
438 *              Address             - Where in the space to read or write
439 *              bit_width           - Field width in bits (8, 16, or 32)
440 *              Value               - Pointer to in or out value
441 *              handler_context     - Pointer to Handler's context
442 *              region_context      - Pointer to context specific to the
443 *                                    accessed region
444 *
445 * RETURN:      Status
446 *
447 * DESCRIPTION: Handler for the PCI bar_target address space (Op Region)
448 *
449 ******************************************************************************/
450
451acpi_status
452acpi_ex_pci_bar_space_handler(u32 function,
453			      acpi_physical_address address,
454			      u32 bit_width,
455			      u64 *value,
456			      void *handler_context, void *region_context)
457{
458	acpi_status status = AE_OK;
459
460	ACPI_FUNCTION_TRACE(ex_pci_bar_space_handler);
461
462	return_ACPI_STATUS(status);
463}
 
464
465/*******************************************************************************
466 *
467 * FUNCTION:    acpi_ex_data_table_space_handler
468 *
469 * PARAMETERS:  Function            - Read or Write operation
470 *              Address             - Where in the space to read or write
471 *              bit_width           - Field width in bits (8, 16, or 32)
472 *              Value               - Pointer to in or out value
473 *              handler_context     - Pointer to Handler's context
474 *              region_context      - Pointer to context specific to the
475 *                                    accessed region
476 *
477 * RETURN:      Status
478 *
479 * DESCRIPTION: Handler for the Data Table address space (Op Region)
480 *
481 ******************************************************************************/
482
483acpi_status
484acpi_ex_data_table_space_handler(u32 function,
485				 acpi_physical_address address,
486				 u32 bit_width,
487				 u64 *value,
488				 void *handler_context, void *region_context)
489{
 
 
 
490	ACPI_FUNCTION_TRACE(ex_data_table_space_handler);
491
 
 
 
 
492	/*
493	 * Perform the memory read or write. The bit_width was already
494	 * validated.
495	 */
496	switch (function) {
497	case ACPI_READ:
498
499		ACPI_MEMCPY(ACPI_CAST_PTR(char, value),
500			    ACPI_PHYSADDR_TO_PTR(address),
501			    ACPI_DIV_8(bit_width));
502		break;
503
504	case ACPI_WRITE:
505
506		ACPI_MEMCPY(ACPI_PHYSADDR_TO_PTR(address),
507			    ACPI_CAST_PTR(char, value), ACPI_DIV_8(bit_width));
508		break;
509
510	default:
511
512		return_ACPI_STATUS(AE_BAD_PARAMETER);
513	}
514
515	return_ACPI_STATUS(AE_OK);
516}
v6.2
  1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2/******************************************************************************
  3 *
  4 * Module Name: exregion - ACPI default op_region (address space) handlers
  5 *
  6 * Copyright (C) 2000 - 2022, Intel Corp.
  7 *
  8 *****************************************************************************/
  9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 10#include <acpi/acpi.h>
 11#include "accommon.h"
 12#include "acinterp.h"
 13
 14#define _COMPONENT          ACPI_EXECUTER
 15ACPI_MODULE_NAME("exregion")
 16
 17/*******************************************************************************
 18 *
 19 * FUNCTION:    acpi_ex_system_memory_space_handler
 20 *
 21 * PARAMETERS:  function            - Read or Write operation
 22 *              address             - Where in the space to read or write
 23 *              bit_width           - Field width in bits (8, 16, or 32)
 24 *              value               - Pointer to in or out value
 25 *              handler_context     - Pointer to Handler's context
 26 *              region_context      - Pointer to context specific to the
 27 *                                    accessed region
 28 *
 29 * RETURN:      Status
 30 *
 31 * DESCRIPTION: Handler for the System Memory address space (Op Region)
 32 *
 33 ******************************************************************************/
 34acpi_status
 35acpi_ex_system_memory_space_handler(u32 function,
 36				    acpi_physical_address address,
 37				    u32 bit_width,
 38				    u64 *value,
 39				    void *handler_context, void *region_context)
 40{
 41	acpi_status status = AE_OK;
 42	void *logical_addr_ptr = NULL;
 43	struct acpi_mem_space_context *mem_info = region_context;
 44	struct acpi_mem_mapping *mm = mem_info->cur_mm;
 45	u32 length;
 46	acpi_size map_length;
 47	acpi_size page_boundary_map_length;
 48#ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
 49	u32 remainder;
 50#endif
 51
 52	ACPI_FUNCTION_TRACE(ex_system_memory_space_handler);
 53
 54	/* Validate and translate the bit width */
 55
 56	switch (bit_width) {
 57	case 8:
 58
 59		length = 1;
 60		break;
 61
 62	case 16:
 63
 64		length = 2;
 65		break;
 66
 67	case 32:
 68
 69		length = 4;
 70		break;
 71
 72	case 64:
 73
 74		length = 8;
 75		break;
 76
 77	default:
 78
 79		ACPI_ERROR((AE_INFO, "Invalid SystemMemory width %u",
 80			    bit_width));
 81		return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
 82	}
 83
 84#ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
 85	/*
 86	 * Hardware does not support non-aligned data transfers, we must verify
 87	 * the request.
 88	 */
 89	(void)acpi_ut_short_divide((u64) address, length, NULL, &remainder);
 90	if (remainder != 0) {
 91		return_ACPI_STATUS(AE_AML_ALIGNMENT);
 92	}
 93#endif
 94
 95	/*
 96	 * Does the request fit into the cached memory mapping?
 97	 * Is 1) Address below the current mapping? OR
 98	 *    2) Address beyond the current mapping?
 99	 */
100	if (!mm || (address < mm->physical_address) ||
101	    ((u64) address + length > (u64) mm->physical_address + mm->length)) {
 
 
102		/*
103		 * The request cannot be resolved by the current memory mapping.
104		 *
105		 * Look for an existing saved mapping covering the address range
106		 * at hand.  If found, save it as the current one and carry out
107		 * the access.
108		 */
109		for (mm = mem_info->first_mm; mm; mm = mm->next_mm) {
110			if (mm == mem_info->cur_mm)
111				continue;
112
113			if (address < mm->physical_address)
114				continue;
115
116			if ((u64) address + length >
117					(u64) mm->physical_address + mm->length)
118				continue;
119
120			mem_info->cur_mm = mm;
121			goto access;
122		}
123
124		/* Create a new mappings list entry */
125		mm = ACPI_ALLOCATE_ZEROED(sizeof(*mm));
126		if (!mm) {
127			ACPI_ERROR((AE_INFO,
128				    "Unable to save memory mapping at 0x%8.8X%8.8X, size %u",
129				    ACPI_FORMAT_UINT64(address), length));
130			return_ACPI_STATUS(AE_NO_MEMORY);
131		}
132
133		/*
134		 * October 2009: Attempt to map from the requested address to the
135		 * end of the region. However, we will never map more than one
136		 * page, nor will we cross a page boundary.
137		 */
138		map_length = (acpi_size)
139		    ((mem_info->address + mem_info->length) - address);
140
141		/*
142		 * If mapping the entire remaining portion of the region will cross
143		 * a page boundary, just map up to the page boundary, do not cross.
144		 * On some systems, crossing a page boundary while mapping regions
145		 * can cause warnings if the pages have different attributes
146		 * due to resource management.
147		 *
148		 * This has the added benefit of constraining a single mapping to
149		 * one page, which is similar to the original code that used a 4k
150		 * maximum window.
151		 */
152		page_boundary_map_length = (acpi_size)
153		    (ACPI_ROUND_UP(address, ACPI_DEFAULT_PAGE_SIZE) - address);
154		if (page_boundary_map_length == 0) {
 
155			page_boundary_map_length = ACPI_DEFAULT_PAGE_SIZE;
156		}
157
158		if (map_length > page_boundary_map_length) {
159			map_length = page_boundary_map_length;
160		}
161
162		/* Create a new mapping starting at the address given */
163
164		logical_addr_ptr = acpi_os_map_memory(address, map_length);
165		if (!logical_addr_ptr) {
166			ACPI_ERROR((AE_INFO,
167				    "Could not map memory at 0x%8.8X%8.8X, size %u",
168				    ACPI_FORMAT_UINT64(address),
169				    (u32)map_length));
170			ACPI_FREE(mm);
171			return_ACPI_STATUS(AE_NO_MEMORY);
172		}
173
174		/* Save the physical address and mapping size */
175
176		mm->logical_address = logical_addr_ptr;
177		mm->physical_address = address;
178		mm->length = map_length;
179
180		/*
181		 * Add the new entry to the mappigs list and save it as the
182		 * current mapping.
183		 */
184		mm->next_mm = mem_info->first_mm;
185		mem_info->first_mm = mm;
186
187		mem_info->cur_mm = mm;
188	}
189
190access:
191	/*
192	 * Generate a logical pointer corresponding to the address we want to
193	 * access
194	 */
195	logical_addr_ptr = mm->logical_address +
196		((u64) address - (u64) mm->physical_address);
197
198	ACPI_DEBUG_PRINT((ACPI_DB_INFO,
199			  "System-Memory (width %u) R/W %u Address=%8.8X%8.8X\n",
200			  bit_width, function, ACPI_FORMAT_UINT64(address)));
 
201
202	/*
203	 * Perform the memory read or write
204	 *
205	 * Note: For machines that do not support non-aligned transfers, the target
206	 * address was checked for alignment above. We do not attempt to break the
207	 * transfer up into smaller (byte-size) chunks because the AML specifically
208	 * asked for a transfer width that the hardware may require.
209	 */
210	switch (function) {
211	case ACPI_READ:
212
213		*value = 0;
214		switch (bit_width) {
215		case 8:
216
217			*value = (u64)ACPI_GET8(logical_addr_ptr);
218			break;
219
220		case 16:
221
222			*value = (u64)ACPI_GET16(logical_addr_ptr);
223			break;
224
225		case 32:
226
227			*value = (u64)ACPI_GET32(logical_addr_ptr);
228			break;
229
230		case 64:
231
232			*value = (u64)ACPI_GET64(logical_addr_ptr);
233			break;
234
235		default:
236
237			/* bit_width was already validated */
238
239			break;
240		}
241		break;
242
243	case ACPI_WRITE:
244
245		switch (bit_width) {
246		case 8:
247
248			ACPI_SET8(logical_addr_ptr, *value);
249			break;
250
251		case 16:
252
253			ACPI_SET16(logical_addr_ptr, *value);
254			break;
255
256		case 32:
257
258			ACPI_SET32(logical_addr_ptr, *value);
259			break;
260
261		case 64:
262
263			ACPI_SET64(logical_addr_ptr, *value);
264			break;
265
266		default:
267
268			/* bit_width was already validated */
269
270			break;
271		}
272		break;
273
274	default:
275
276		status = AE_BAD_PARAMETER;
277		break;
278	}
279
280	return_ACPI_STATUS(status);
281}
282
283/*******************************************************************************
284 *
285 * FUNCTION:    acpi_ex_system_io_space_handler
286 *
287 * PARAMETERS:  function            - Read or Write operation
288 *              address             - Where in the space to read or write
289 *              bit_width           - Field width in bits (8, 16, or 32)
290 *              value               - Pointer to in or out value
291 *              handler_context     - Pointer to Handler's context
292 *              region_context      - Pointer to context specific to the
293 *                                    accessed region
294 *
295 * RETURN:      Status
296 *
297 * DESCRIPTION: Handler for the System IO address space (Op Region)
298 *
299 ******************************************************************************/
300
301acpi_status
302acpi_ex_system_io_space_handler(u32 function,
303				acpi_physical_address address,
304				u32 bit_width,
305				u64 *value,
306				void *handler_context, void *region_context)
307{
308	acpi_status status = AE_OK;
309	u32 value32;
310
311	ACPI_FUNCTION_TRACE(ex_system_io_space_handler);
312
313	ACPI_DEBUG_PRINT((ACPI_DB_INFO,
314			  "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n",
315			  bit_width, function, ACPI_FORMAT_UINT64(address)));
 
316
317	/* Decode the function parameter */
318
319	switch (function) {
320	case ACPI_READ:
321
322		status = acpi_hw_read_port((acpi_io_address)address,
323					   &value32, bit_width);
324		*value = value32;
325		break;
326
327	case ACPI_WRITE:
328
329		status = acpi_hw_write_port((acpi_io_address)address,
330					    (u32)*value, bit_width);
331		break;
332
333	default:
334
335		status = AE_BAD_PARAMETER;
336		break;
337	}
338
339	return_ACPI_STATUS(status);
340}
341
342#ifdef ACPI_PCI_CONFIGURED
343/*******************************************************************************
344 *
345 * FUNCTION:    acpi_ex_pci_config_space_handler
346 *
347 * PARAMETERS:  function            - Read or Write operation
348 *              address             - Where in the space to read or write
349 *              bit_width           - Field width in bits (8, 16, or 32)
350 *              value               - Pointer to in or out value
351 *              handler_context     - Pointer to Handler's context
352 *              region_context      - Pointer to context specific to the
353 *                                    accessed region
354 *
355 * RETURN:      Status
356 *
357 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
358 *
359 ******************************************************************************/
360
361acpi_status
362acpi_ex_pci_config_space_handler(u32 function,
363				 acpi_physical_address address,
364				 u32 bit_width,
365				 u64 *value,
366				 void *handler_context, void *region_context)
367{
368	acpi_status status = AE_OK;
369	struct acpi_pci_id *pci_id;
370	u16 pci_register;
371
372	ACPI_FUNCTION_TRACE(ex_pci_config_space_handler);
373
374	/*
375	 *  The arguments to acpi_os(Read|Write)pci_configuration are:
376	 *
377	 *  pci_segment is the PCI bus segment range 0-31
378	 *  pci_bus     is the PCI bus number range 0-255
379	 *  pci_device  is the PCI device number range 0-31
380	 *  pci_function is the PCI device function number
381	 *  pci_register is the Config space register range 0-255 bytes
382	 *
383	 *  value - input value for write, output address for read
384	 *
385	 */
386	pci_id = (struct acpi_pci_id *)region_context;
387	pci_register = (u16) (u32) address;
388
389	ACPI_DEBUG_PRINT((ACPI_DB_INFO,
390			  "Pci-Config %u (%u) Seg(%04x) Bus(%04x) "
391			  "Dev(%04x) Func(%04x) Reg(%04x)\n",
392			  function, bit_width, pci_id->segment, pci_id->bus,
393			  pci_id->device, pci_id->function, pci_register));
394
395	switch (function) {
396	case ACPI_READ:
397
398		*value = 0;
399		status =
400		    acpi_os_read_pci_configuration(pci_id, pci_register, value,
401						   bit_width);
402		break;
403
404	case ACPI_WRITE:
405
406		status =
407		    acpi_os_write_pci_configuration(pci_id, pci_register,
408						    *value, bit_width);
409		break;
410
411	default:
412
413		status = AE_BAD_PARAMETER;
414		break;
415	}
416
417	return_ACPI_STATUS(status);
418}
419#endif
420
421/*******************************************************************************
422 *
423 * FUNCTION:    acpi_ex_cmos_space_handler
424 *
425 * PARAMETERS:  function            - Read or Write operation
426 *              address             - Where in the space to read or write
427 *              bit_width           - Field width in bits (8, 16, or 32)
428 *              value               - Pointer to in or out value
429 *              handler_context     - Pointer to Handler's context
430 *              region_context      - Pointer to context specific to the
431 *                                    accessed region
432 *
433 * RETURN:      Status
434 *
435 * DESCRIPTION: Handler for the CMOS address space (Op Region)
436 *
437 ******************************************************************************/
438
439acpi_status
440acpi_ex_cmos_space_handler(u32 function,
441			   acpi_physical_address address,
442			   u32 bit_width,
443			   u64 *value,
444			   void *handler_context, void *region_context)
445{
446	acpi_status status = AE_OK;
447
448	ACPI_FUNCTION_TRACE(ex_cmos_space_handler);
449
450	return_ACPI_STATUS(status);
451}
452
453#ifdef ACPI_PCI_CONFIGURED
454/*******************************************************************************
455 *
456 * FUNCTION:    acpi_ex_pci_bar_space_handler
457 *
458 * PARAMETERS:  function            - Read or Write operation
459 *              address             - Where in the space to read or write
460 *              bit_width           - Field width in bits (8, 16, or 32)
461 *              value               - Pointer to in or out value
462 *              handler_context     - Pointer to Handler's context
463 *              region_context      - Pointer to context specific to the
464 *                                    accessed region
465 *
466 * RETURN:      Status
467 *
468 * DESCRIPTION: Handler for the PCI bar_target address space (Op Region)
469 *
470 ******************************************************************************/
471
472acpi_status
473acpi_ex_pci_bar_space_handler(u32 function,
474			      acpi_physical_address address,
475			      u32 bit_width,
476			      u64 *value,
477			      void *handler_context, void *region_context)
478{
479	acpi_status status = AE_OK;
480
481	ACPI_FUNCTION_TRACE(ex_pci_bar_space_handler);
482
483	return_ACPI_STATUS(status);
484}
485#endif
486
487/*******************************************************************************
488 *
489 * FUNCTION:    acpi_ex_data_table_space_handler
490 *
491 * PARAMETERS:  function            - Read or Write operation
492 *              address             - Where in the space to read or write
493 *              bit_width           - Field width in bits (8, 16, or 32)
494 *              value               - Pointer to in or out value
495 *              handler_context     - Pointer to Handler's context
496 *              region_context      - Pointer to context specific to the
497 *                                    accessed region
498 *
499 * RETURN:      Status
500 *
501 * DESCRIPTION: Handler for the Data Table address space (Op Region)
502 *
503 ******************************************************************************/
504
505acpi_status
506acpi_ex_data_table_space_handler(u32 function,
507				 acpi_physical_address address,
508				 u32 bit_width,
509				 u64 *value,
510				 void *handler_context, void *region_context)
511{
512	struct acpi_data_table_space_context *mapping;
513	char *pointer;
514
515	ACPI_FUNCTION_TRACE(ex_data_table_space_handler);
516
517	mapping = (struct acpi_data_table_space_context *) region_context;
518	pointer = ACPI_CAST_PTR(char, mapping->pointer) +
519	    (address - ACPI_PTR_TO_PHYSADDR(mapping->pointer));
520
521	/*
522	 * Perform the memory read or write. The bit_width was already
523	 * validated.
524	 */
525	switch (function) {
526	case ACPI_READ:
527
528		memcpy(ACPI_CAST_PTR(char, value), pointer,
529		       ACPI_DIV_8(bit_width));
 
530		break;
531
532	case ACPI_WRITE:
533
534		memcpy(pointer, ACPI_CAST_PTR(char, value),
535		       ACPI_DIV_8(bit_width));
536		break;
537
538	default:
539
540		return_ACPI_STATUS(AE_BAD_PARAMETER);
541	}
542
543	return_ACPI_STATUS(AE_OK);
544}