Use dentry_path() to create full path to inode object
[pohmelfs.git] / drivers / acpi / acpica / hwxface.c
blob9d38eb6c0d0b9107866f355c4aa9419937ebb883
2 /******************************************************************************
4 * Module Name: hwxface - Public ACPICA hardware interfaces
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2012, Intel Corp.
10 * All rights reserved.
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.
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.
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.
45 #include <linux/export.h>
46 #include <acpi/acpi.h>
47 #include "accommon.h"
48 #include "acnamesp.h"
50 #define _COMPONENT ACPI_HARDWARE
51 ACPI_MODULE_NAME("hwxface")
53 /******************************************************************************
55 * FUNCTION: acpi_reset
57 * PARAMETERS: None
59 * RETURN: Status
61 * DESCRIPTION: Set reset register in memory or IO space. Note: Does not
62 * support reset register in PCI config space, this must be
63 * handled separately.
65 ******************************************************************************/
66 acpi_status acpi_reset(void)
68 struct acpi_generic_address *reset_reg;
69 acpi_status status;
71 ACPI_FUNCTION_TRACE(acpi_reset);
73 reset_reg = &acpi_gbl_FADT.reset_register;
75 /* Check if the reset register is supported */
77 if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) ||
78 !reset_reg->address) {
79 return_ACPI_STATUS(AE_NOT_EXIST);
82 if (reset_reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
84 * For I/O space, write directly to the OSL. This
85 * bypasses the port validation mechanism, which may
86 * block a valid write to the reset register. Spec
87 * section 4.7.3.6 requires register width to be 8.
89 status =
90 acpi_os_write_port((acpi_io_address) reset_reg->address,
91 acpi_gbl_FADT.reset_value, 8);
92 } else {
93 /* Write the reset value to the reset register */
95 status = acpi_hw_write(acpi_gbl_FADT.reset_value, reset_reg);
98 return_ACPI_STATUS(status);
101 ACPI_EXPORT_SYMBOL(acpi_reset)
103 /******************************************************************************
105 * FUNCTION: acpi_read
107 * PARAMETERS: Value - Where the value is returned
108 * Reg - GAS register structure
110 * RETURN: Status
112 * DESCRIPTION: Read from either memory or IO space.
114 * LIMITATIONS: <These limitations also apply to acpi_write>
115 * bit_width must be exactly 8, 16, 32, or 64.
116 * space_iD must be system_memory or system_iO.
117 * bit_offset and access_width are currently ignored, as there has
118 * not been a need to implement these.
120 ******************************************************************************/
121 acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg)
123 u32 value;
124 u32 width;
125 u64 address;
126 acpi_status status;
128 ACPI_FUNCTION_NAME(acpi_read);
130 if (!return_value) {
131 return (AE_BAD_PARAMETER);
134 /* Validate contents of the GAS register. Allow 64-bit transfers */
136 status = acpi_hw_validate_register(reg, 64, &address);
137 if (ACPI_FAILURE(status)) {
138 return (status);
141 width = reg->bit_width;
142 if (width == 64) {
143 width = 32; /* Break into two 32-bit transfers */
146 /* Initialize entire 64-bit return value to zero */
148 *return_value = 0;
149 value = 0;
152 * Two address spaces supported: Memory or IO. PCI_Config is
153 * not supported here because the GAS structure is insufficient
155 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
156 status = acpi_os_read_memory((acpi_physical_address)
157 address, &value, width);
158 if (ACPI_FAILURE(status)) {
159 return (status);
161 *return_value = value;
163 if (reg->bit_width == 64) {
165 /* Read the top 32 bits */
167 status = acpi_os_read_memory((acpi_physical_address)
168 (address + 4), &value, 32);
169 if (ACPI_FAILURE(status)) {
170 return (status);
172 *return_value |= ((u64)value << 32);
174 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
176 status = acpi_hw_read_port((acpi_io_address)
177 address, &value, width);
178 if (ACPI_FAILURE(status)) {
179 return (status);
181 *return_value = value;
183 if (reg->bit_width == 64) {
185 /* Read the top 32 bits */
187 status = acpi_hw_read_port((acpi_io_address)
188 (address + 4), &value, 32);
189 if (ACPI_FAILURE(status)) {
190 return (status);
192 *return_value |= ((u64)value << 32);
196 ACPI_DEBUG_PRINT((ACPI_DB_IO,
197 "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n",
198 ACPI_FORMAT_UINT64(*return_value), reg->bit_width,
199 ACPI_FORMAT_UINT64(address),
200 acpi_ut_get_region_name(reg->space_id)));
202 return (status);
205 ACPI_EXPORT_SYMBOL(acpi_read)
207 /******************************************************************************
209 * FUNCTION: acpi_write
211 * PARAMETERS: Value - Value to be written
212 * Reg - GAS register structure
214 * RETURN: Status
216 * DESCRIPTION: Write to either memory or IO space.
218 ******************************************************************************/
219 acpi_status acpi_write(u64 value, struct acpi_generic_address *reg)
221 u32 width;
222 u64 address;
223 acpi_status status;
225 ACPI_FUNCTION_NAME(acpi_write);
227 /* Validate contents of the GAS register. Allow 64-bit transfers */
229 status = acpi_hw_validate_register(reg, 64, &address);
230 if (ACPI_FAILURE(status)) {
231 return (status);
234 width = reg->bit_width;
235 if (width == 64) {
236 width = 32; /* Break into two 32-bit transfers */
240 * Two address spaces supported: Memory or IO. PCI_Config is
241 * not supported here because the GAS structure is insufficient
243 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
244 status = acpi_os_write_memory((acpi_physical_address)
245 address, ACPI_LODWORD(value),
246 width);
247 if (ACPI_FAILURE(status)) {
248 return (status);
251 if (reg->bit_width == 64) {
252 status = acpi_os_write_memory((acpi_physical_address)
253 (address + 4),
254 ACPI_HIDWORD(value), 32);
255 if (ACPI_FAILURE(status)) {
256 return (status);
259 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
261 status = acpi_hw_write_port((acpi_io_address)
262 address, ACPI_LODWORD(value),
263 width);
264 if (ACPI_FAILURE(status)) {
265 return (status);
268 if (reg->bit_width == 64) {
269 status = acpi_hw_write_port((acpi_io_address)
270 (address + 4),
271 ACPI_HIDWORD(value), 32);
272 if (ACPI_FAILURE(status)) {
273 return (status);
278 ACPI_DEBUG_PRINT((ACPI_DB_IO,
279 "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n",
280 ACPI_FORMAT_UINT64(value), reg->bit_width,
281 ACPI_FORMAT_UINT64(address),
282 acpi_ut_get_region_name(reg->space_id)));
284 return (status);
287 ACPI_EXPORT_SYMBOL(acpi_write)
289 /*******************************************************************************
291 * FUNCTION: acpi_read_bit_register
293 * PARAMETERS: register_id - ID of ACPI Bit Register to access
294 * return_value - Value that was read from the register,
295 * normalized to bit position zero.
297 * RETURN: Status and the value read from the specified Register. Value
298 * returned is normalized to bit0 (is shifted all the way right)
300 * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock.
302 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
303 * PM2 Control.
305 * Note: The hardware lock is not required when reading the ACPI bit registers
306 * since almost all of them are single bit and it does not matter that
307 * the parent hardware register can be split across two physical
308 * registers. The only multi-bit field is SLP_TYP in the PM1 control
309 * register, but this field does not cross an 8-bit boundary (nor does
310 * it make much sense to actually read this field.)
312 ******************************************************************************/
313 acpi_status acpi_read_bit_register(u32 register_id, u32 *return_value)
315 struct acpi_bit_register_info *bit_reg_info;
316 u32 register_value;
317 u32 value;
318 acpi_status status;
320 ACPI_FUNCTION_TRACE_U32(acpi_read_bit_register, register_id);
322 /* Get the info structure corresponding to the requested ACPI Register */
324 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
325 if (!bit_reg_info) {
326 return_ACPI_STATUS(AE_BAD_PARAMETER);
329 /* Read the entire parent register */
331 status = acpi_hw_register_read(bit_reg_info->parent_register,
332 &register_value);
333 if (ACPI_FAILURE(status)) {
334 return_ACPI_STATUS(status);
337 /* Normalize the value that was read, mask off other bits */
339 value = ((register_value & bit_reg_info->access_bit_mask)
340 >> bit_reg_info->bit_position);
342 ACPI_DEBUG_PRINT((ACPI_DB_IO,
343 "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
344 register_id, bit_reg_info->parent_register,
345 register_value, value));
347 *return_value = value;
348 return_ACPI_STATUS(AE_OK);
351 ACPI_EXPORT_SYMBOL(acpi_read_bit_register)
353 /*******************************************************************************
355 * FUNCTION: acpi_write_bit_register
357 * PARAMETERS: register_id - ID of ACPI Bit Register to access
358 * Value - Value to write to the register, in bit
359 * position zero. The bit is automatically
360 * shifted to the correct position.
362 * RETURN: Status
364 * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
365 * since most operations require a read/modify/write sequence.
367 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
368 * PM2 Control.
370 * Note that at this level, the fact that there may be actually two
371 * hardware registers (A and B - and B may not exist) is abstracted.
373 ******************************************************************************/
374 acpi_status acpi_write_bit_register(u32 register_id, u32 value)
376 struct acpi_bit_register_info *bit_reg_info;
377 acpi_cpu_flags lock_flags;
378 u32 register_value;
379 acpi_status status = AE_OK;
381 ACPI_FUNCTION_TRACE_U32(acpi_write_bit_register, register_id);
383 /* Get the info structure corresponding to the requested ACPI Register */
385 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
386 if (!bit_reg_info) {
387 return_ACPI_STATUS(AE_BAD_PARAMETER);
390 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
393 * At this point, we know that the parent register is one of the
394 * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
396 if (bit_reg_info->parent_register != ACPI_REGISTER_PM1_STATUS) {
398 * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
400 * Perform a register read to preserve the bits that we are not
401 * interested in
403 status = acpi_hw_register_read(bit_reg_info->parent_register,
404 &register_value);
405 if (ACPI_FAILURE(status)) {
406 goto unlock_and_exit;
410 * Insert the input bit into the value that was just read
411 * and write the register
413 ACPI_REGISTER_INSERT_VALUE(register_value,
414 bit_reg_info->bit_position,
415 bit_reg_info->access_bit_mask,
416 value);
418 status = acpi_hw_register_write(bit_reg_info->parent_register,
419 register_value);
420 } else {
422 * 2) Case for PM1 Status
424 * The Status register is different from the rest. Clear an event
425 * by writing 1, writing 0 has no effect. So, the only relevant
426 * information is the single bit we're interested in, all others
427 * should be written as 0 so they will be left unchanged.
429 register_value = ACPI_REGISTER_PREPARE_BITS(value,
430 bit_reg_info->
431 bit_position,
432 bit_reg_info->
433 access_bit_mask);
435 /* No need to write the register if value is all zeros */
437 if (register_value) {
438 status =
439 acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
440 register_value);
444 ACPI_DEBUG_PRINT((ACPI_DB_IO,
445 "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
446 register_id, bit_reg_info->parent_register, value,
447 register_value));
449 unlock_and_exit:
451 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
452 return_ACPI_STATUS(status);
455 ACPI_EXPORT_SYMBOL(acpi_write_bit_register)
457 /*******************************************************************************
459 * FUNCTION: acpi_get_sleep_type_data
461 * PARAMETERS: sleep_state - Numeric sleep state
462 * *sleep_type_a - Where SLP_TYPa is returned
463 * *sleep_type_b - Where SLP_TYPb is returned
465 * RETURN: Status - ACPI status
467 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
468 * state.
470 ******************************************************************************/
471 acpi_status
472 acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
474 acpi_status status = AE_OK;
475 struct acpi_evaluate_info *info;
477 ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data);
479 /* Validate parameters */
481 if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) {
482 return_ACPI_STATUS(AE_BAD_PARAMETER);
485 /* Allocate the evaluation information block */
487 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
488 if (!info) {
489 return_ACPI_STATUS(AE_NO_MEMORY);
492 info->pathname =
493 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]);
495 /* Evaluate the namespace object containing the values for this state */
497 status = acpi_ns_evaluate(info);
498 if (ACPI_FAILURE(status)) {
499 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
500 "%s while evaluating SleepState [%s]\n",
501 acpi_format_exception(status),
502 info->pathname));
504 goto cleanup;
507 /* Must have a return object */
509 if (!info->return_object) {
510 ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
511 info->pathname));
512 status = AE_NOT_EXIST;
515 /* It must be of type Package */
517 else if (info->return_object->common.type != ACPI_TYPE_PACKAGE) {
518 ACPI_ERROR((AE_INFO,
519 "Sleep State return object is not a Package"));
520 status = AE_AML_OPERAND_TYPE;
524 * The package must have at least two elements. NOTE (March 2005): This
525 * goes against the current ACPI spec which defines this object as a
526 * package with one encoded DWORD element. However, existing practice
527 * by BIOS vendors seems to be to have 2 or more elements, at least
528 * one per sleep type (A/B).
530 else if (info->return_object->package.count < 2) {
531 ACPI_ERROR((AE_INFO,
532 "Sleep State return package does not have at least two elements"));
533 status = AE_AML_NO_OPERAND;
536 /* The first two elements must both be of type Integer */
538 else if (((info->return_object->package.elements[0])->common.type
539 != ACPI_TYPE_INTEGER) ||
540 ((info->return_object->package.elements[1])->common.type
541 != ACPI_TYPE_INTEGER)) {
542 ACPI_ERROR((AE_INFO,
543 "Sleep State return package elements are not both Integers "
544 "(%s, %s)",
545 acpi_ut_get_object_type_name(info->return_object->
546 package.elements[0]),
547 acpi_ut_get_object_type_name(info->return_object->
548 package.elements[1])));
549 status = AE_AML_OPERAND_TYPE;
550 } else {
551 /* Valid _Sx_ package size, type, and value */
553 *sleep_type_a = (u8)
554 (info->return_object->package.elements[0])->integer.value;
555 *sleep_type_b = (u8)
556 (info->return_object->package.elements[1])->integer.value;
559 if (ACPI_FAILURE(status)) {
560 ACPI_EXCEPTION((AE_INFO, status,
561 "While evaluating SleepState [%s], bad Sleep object %p type %s",
562 info->pathname, info->return_object,
563 acpi_ut_get_object_type_name(info->
564 return_object)));
567 acpi_ut_remove_reference(info->return_object);
569 cleanup:
570 ACPI_FREE(info);
571 return_ACPI_STATUS(status);
574 ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data)