1 
2 /*******************************************************************************
3  *
4  * Module Name: hwregs - Read/write access functions for the various ACPI
5  *                       control and status registers.
6  *
7  ******************************************************************************/
8 
9 /*
10  * Copyright (C) 2000 - 2004, R. Byron Moore
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions, and the following disclaimer,
18  *    without modification.
19  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
20  *    substantially similar to the "NO WARRANTY" disclaimer below
21  *    ("Disclaimer") and any redistribution must be conditioned upon
22  *    including a substantially similar Disclaimer requirement for further
23  *    binary redistribution.
24  * 3. Neither the names of the above-listed copyright holders nor the names
25  *    of any contributors may be used to endorse or promote products derived
26  *    from this software without specific prior written permission.
27  *
28  * Alternatively, this software may be distributed under the terms of the
29  * GNU General Public License ("GPL") version 2 as published by the Free
30  * Software Foundation.
31  *
32  * NO WARRANTY
33  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
36  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
37  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
41  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
42  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43  * POSSIBILITY OF SUCH DAMAGES.
44  */
45 
46 
47 #include <acpi/acpi.h>
48 #include <acpi/acnamesp.h>
49 #include <acpi/acevents.h>
50 
51 #define _COMPONENT          ACPI_HARDWARE
52 	 ACPI_MODULE_NAME    ("hwregs")
53 
54 
55 /*******************************************************************************
56  *
57  * FUNCTION:    acpi_hw_clear_acpi_status
58  *
59  * PARAMETERS:  Flags           - Lock the hardware or not
60  *
61  * RETURN:      none
62  *
63  * DESCRIPTION: Clears all fixed and general purpose status bits
64  *
65  ******************************************************************************/
66 
67 acpi_status
acpi_hw_clear_acpi_status(u32 flags)68 acpi_hw_clear_acpi_status (
69 	u32                             flags)
70 {
71 	acpi_status                     status;
72 
73 
74 	ACPI_FUNCTION_TRACE ("hw_clear_acpi_status");
75 
76 
77 	ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %04X to %04X\n",
78 		ACPI_BITMASK_ALL_FIXED_STATUS,
79 		(u16) acpi_gbl_FADT->xpm1a_evt_blk.address));
80 
81 	if (flags & ACPI_MTX_LOCK) {
82 		status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
83 		if (ACPI_FAILURE (status)) {
84 			return_ACPI_STATUS (status);
85 		}
86 	}
87 
88 	status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS,
89 			  ACPI_BITMASK_ALL_FIXED_STATUS);
90 	if (ACPI_FAILURE (status)) {
91 		goto unlock_and_exit;
92 	}
93 
94 	/* Clear the fixed events */
95 
96 	if (acpi_gbl_FADT->xpm1b_evt_blk.address) {
97 		status = acpi_hw_low_level_write (16, ACPI_BITMASK_ALL_FIXED_STATUS,
98 				 &acpi_gbl_FADT->xpm1b_evt_blk);
99 		if (ACPI_FAILURE (status)) {
100 			goto unlock_and_exit;
101 		}
102 	}
103 
104 	/* Clear the GPE Bits in all GPE registers in all GPE blocks */
105 
106 	status = acpi_ev_walk_gpe_list (acpi_hw_clear_gpe_block);
107 
108 unlock_and_exit:
109 	if (flags & ACPI_MTX_LOCK) {
110 		(void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
111 	}
112 	return_ACPI_STATUS (status);
113 }
114 
115 
116 /*******************************************************************************
117  *
118  * FUNCTION:    acpi_get_sleep_type_data
119  *
120  * PARAMETERS:  sleep_state         - Numeric sleep state
121  *              *sleep_type_a        - Where SLP_TYPa is returned
122  *              *sleep_type_b        - Where SLP_TYPb is returned
123  *
124  * RETURN:      Status - ACPI status
125  *
126  * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
127  *              state.
128  *
129  ******************************************************************************/
130 
131 acpi_status
acpi_get_sleep_type_data(u8 sleep_state,u8 * sleep_type_a,u8 * sleep_type_b)132 acpi_get_sleep_type_data (
133 	u8                              sleep_state,
134 	u8                              *sleep_type_a,
135 	u8                              *sleep_type_b)
136 {
137 	acpi_status                     status = AE_OK;
138 	union acpi_operand_object       *obj_desc;
139 
140 
141 	ACPI_FUNCTION_TRACE ("acpi_get_sleep_type_data");
142 
143 
144 	/*
145 	 * Validate parameters
146 	 */
147 	if ((sleep_state > ACPI_S_STATES_MAX) ||
148 		!sleep_type_a || !sleep_type_b) {
149 		return_ACPI_STATUS (AE_BAD_PARAMETER);
150 	}
151 
152 	/*
153 	 * Evaluate the namespace object containing the values for this state
154 	 */
155 	status = acpi_ns_evaluate_by_name ((char *) acpi_gbl_sleep_state_names[sleep_state],
156 			  NULL, &obj_desc);
157 	if (ACPI_FAILURE (status)) {
158 		ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s while evaluating sleep_state [%s]\n",
159 			acpi_format_exception (status), acpi_gbl_sleep_state_names[sleep_state]));
160 
161 		return_ACPI_STATUS (status);
162 	}
163 
164 	/* Must have a return object */
165 
166 	if (!obj_desc) {
167 		ACPI_REPORT_ERROR (("Missing Sleep State object\n"));
168 		status = AE_NOT_EXIST;
169 	}
170 
171 	/* It must be of type Package */
172 
173 	else if (ACPI_GET_OBJECT_TYPE (obj_desc) != ACPI_TYPE_PACKAGE) {
174 		ACPI_REPORT_ERROR (("Sleep State object not a Package\n"));
175 		status = AE_AML_OPERAND_TYPE;
176 	}
177 
178 	/* The package must have at least two elements */
179 
180 	else if (obj_desc->package.count < 2) {
181 		ACPI_REPORT_ERROR (("Sleep State package does not have at least two elements\n"));
182 		status = AE_AML_NO_OPERAND;
183 	}
184 
185 	/* The first two elements must both be of type Integer */
186 
187 	else if ((ACPI_GET_OBJECT_TYPE (obj_desc->package.elements[0]) != ACPI_TYPE_INTEGER) ||
188 			 (ACPI_GET_OBJECT_TYPE (obj_desc->package.elements[1]) != ACPI_TYPE_INTEGER)) {
189 		ACPI_REPORT_ERROR (("Sleep State package elements are not both Integers (%s, %s)\n",
190 			acpi_ut_get_object_type_name (obj_desc->package.elements[0]),
191 			acpi_ut_get_object_type_name (obj_desc->package.elements[1])));
192 		status = AE_AML_OPERAND_TYPE;
193 	}
194 	else {
195 		/*
196 		 * Valid _Sx_ package size, type, and value
197 		 */
198 		*sleep_type_a = (u8) (obj_desc->package.elements[0])->integer.value;
199 		*sleep_type_b = (u8) (obj_desc->package.elements[1])->integer.value;
200 	}
201 
202 	if (ACPI_FAILURE (status)) {
203 		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "While evaluating sleep_state [%s], bad Sleep object %p type %s\n",
204 			acpi_gbl_sleep_state_names[sleep_state], obj_desc, acpi_ut_get_object_type_name (obj_desc)));
205 	}
206 
207 	acpi_ut_remove_reference (obj_desc);
208 	return_ACPI_STATUS (status);
209 }
210 
211 
212 /*******************************************************************************
213  *
214  * FUNCTION:    acpi_hw_get_register_bit_mask
215  *
216  * PARAMETERS:  register_id         - Index of ACPI Register to access
217  *
218  * RETURN:      The bit mask to be used when accessing the register
219  *
220  * DESCRIPTION: Map register_id into a register bit mask.
221  *
222  ******************************************************************************/
223 
224 struct acpi_bit_register_info *
acpi_hw_get_bit_register_info(u32 register_id)225 acpi_hw_get_bit_register_info (
226 	u32                             register_id)
227 {
228 	ACPI_FUNCTION_NAME ("hw_get_bit_register_info");
229 
230 
231 	if (register_id > ACPI_BITREG_MAX) {
232 		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid bit_register ID: %X\n", register_id));
233 		return (NULL);
234 	}
235 
236 	return (&acpi_gbl_bit_register_info[register_id]);
237 }
238 
239 
240 /*******************************************************************************
241  *
242  * FUNCTION:    acpi_get_register
243  *
244  * PARAMETERS:  register_id     - ID of ACPI bit_register to access
245  *              return_value    - Value that was read from the register
246  *              Flags           - Lock the hardware or not
247  *
248  * RETURN:      Value is read from specified Register.  Value returned is
249  *              normalized to bit0 (is shifted all the way right)
250  *
251  * DESCRIPTION: ACPI bit_register read function.
252  *
253  ******************************************************************************/
254 
255 acpi_status
acpi_get_register(u32 register_id,u32 * return_value,u32 flags)256 acpi_get_register (
257 	u32                             register_id,
258 	u32                             *return_value,
259 	u32                             flags)
260 {
261 	u32                             register_value = 0;
262 	struct acpi_bit_register_info   *bit_reg_info;
263 	acpi_status                     status;
264 
265 
266 	ACPI_FUNCTION_TRACE ("acpi_get_register");
267 
268 
269 	/* Get the info structure corresponding to the requested ACPI Register */
270 
271 	bit_reg_info = acpi_hw_get_bit_register_info (register_id);
272 	if (!bit_reg_info) {
273 		return_ACPI_STATUS (AE_BAD_PARAMETER);
274 	}
275 
276 	if (flags & ACPI_MTX_LOCK) {
277 		status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
278 		if (ACPI_FAILURE (status)) {
279 			return_ACPI_STATUS (status);
280 		}
281 	}
282 
283 	status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
284 			  bit_reg_info->parent_register, &register_value);
285 
286 	if (flags & ACPI_MTX_LOCK) {
287 		(void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
288 	}
289 
290 	if (ACPI_SUCCESS (status)) {
291 		/* Normalize the value that was read */
292 
293 		register_value = ((register_value & bit_reg_info->access_bit_mask)
294 				   >> bit_reg_info->bit_position);
295 
296 		*return_value = register_value;
297 
298 		ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read value %8.8X register %X\n",
299 				register_value, bit_reg_info->parent_register));
300 	}
301 
302 	return_ACPI_STATUS (status);
303 }
304 
305 
306 /*******************************************************************************
307  *
308  * FUNCTION:    acpi_set_register
309  *
310  * PARAMETERS:  register_id     - ID of ACPI bit_register to access
311  *              Value           - (only used on write) value to write to the
312  *                                Register, NOT pre-normalized to the bit pos.
313  *              Flags           - Lock the hardware or not
314  *
315  * RETURN:      None
316  *
317  * DESCRIPTION: ACPI Bit Register write function.
318  *
319  ******************************************************************************/
320 
321 acpi_status
acpi_set_register(u32 register_id,u32 value,u32 flags)322 acpi_set_register (
323 	u32                             register_id,
324 	u32                             value,
325 	u32                             flags)
326 {
327 	u32                             register_value = 0;
328 	struct acpi_bit_register_info   *bit_reg_info;
329 	acpi_status                     status;
330 
331 
332 	ACPI_FUNCTION_TRACE_U32 ("acpi_set_register", register_id);
333 
334 
335 	/* Get the info structure corresponding to the requested ACPI Register */
336 
337 	bit_reg_info = acpi_hw_get_bit_register_info (register_id);
338 	if (!bit_reg_info) {
339 		ACPI_REPORT_ERROR (("Bad ACPI HW register_id: %X\n", register_id));
340 		return_ACPI_STATUS (AE_BAD_PARAMETER);
341 	}
342 
343 	if (flags & ACPI_MTX_LOCK) {
344 		status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
345 		if (ACPI_FAILURE (status)) {
346 			return_ACPI_STATUS (status);
347 		}
348 	}
349 
350 	/* Always do a register read first so we can insert the new bits  */
351 
352 	status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
353 			  bit_reg_info->parent_register, &register_value);
354 	if (ACPI_FAILURE (status)) {
355 		goto unlock_and_exit;
356 	}
357 
358 	/*
359 	 * Decode the Register ID
360 	 * Register ID = [Register block ID] | [bit ID]
361 	 *
362 	 * Check bit ID to fine locate Register offset.
363 	 * Check Mask to determine Register offset, and then read-write.
364 	 */
365 	switch (bit_reg_info->parent_register) {
366 	case ACPI_REGISTER_PM1_STATUS:
367 
368 		/*
369 		 * Status Registers are different from the rest.  Clear by
370 		 * writing 1, and writing 0 has no effect.  So, the only relevant
371 		 * information is the single bit we're interested in, all others should
372 		 * be written as 0 so they will be left unchanged.
373 		 */
374 		value = ACPI_REGISTER_PREPARE_BITS (value,
375 				 bit_reg_info->bit_position, bit_reg_info->access_bit_mask);
376 		if (value) {
377 			status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
378 					 ACPI_REGISTER_PM1_STATUS, (u16) value);
379 			register_value = 0;
380 		}
381 		break;
382 
383 
384 	case ACPI_REGISTER_PM1_ENABLE:
385 
386 		ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
387 				bit_reg_info->access_bit_mask, value);
388 
389 		status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
390 				  ACPI_REGISTER_PM1_ENABLE, (u16) register_value);
391 		break;
392 
393 
394 	case ACPI_REGISTER_PM1_CONTROL:
395 
396 		/*
397 		 * Write the PM1 Control register.
398 		 * Note that at this level, the fact that there are actually TWO
399 		 * registers (A and B - and B may not exist) is abstracted.
400 		 */
401 		ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM1 control: Read %X\n", register_value));
402 
403 		ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
404 				bit_reg_info->access_bit_mask, value);
405 
406 		status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
407 				  ACPI_REGISTER_PM1_CONTROL, (u16) register_value);
408 		break;
409 
410 
411 	case ACPI_REGISTER_PM2_CONTROL:
412 
413 		status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
414 				 ACPI_REGISTER_PM2_CONTROL, &register_value);
415 		if (ACPI_FAILURE (status)) {
416 			goto unlock_and_exit;
417 		}
418 
419 		ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM2 control: Read %X from %8.8X%8.8X\n",
420 			register_value,
421 			ACPI_FORMAT_UINT64 (acpi_gbl_FADT->xpm2_cnt_blk.address)));
422 
423 		ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
424 				bit_reg_info->access_bit_mask, value);
425 
426 		ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %4.4X to %8.8X%8.8X\n",
427 			register_value,
428 			ACPI_FORMAT_UINT64 (acpi_gbl_FADT->xpm2_cnt_blk.address)));
429 
430 		status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
431 				   ACPI_REGISTER_PM2_CONTROL, (u8) (register_value));
432 		break;
433 
434 
435 	default:
436 		break;
437 	}
438 
439 
440 unlock_and_exit:
441 
442 	if (flags & ACPI_MTX_LOCK) {
443 		(void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
444 	}
445 
446 	/* Normalize the value that was read */
447 
448 	ACPI_DEBUG_EXEC (register_value = ((register_value & bit_reg_info->access_bit_mask) >> bit_reg_info->bit_position));
449 
450 	ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Set bits: %8.8X actual %8.8X register %X\n",
451 			value, register_value, bit_reg_info->parent_register));
452 	return_ACPI_STATUS (status);
453 }
454 
455 
456 /******************************************************************************
457  *
458  * FUNCTION:    acpi_hw_register_read
459  *
460  * PARAMETERS:  use_lock               - Mutex hw access.
461  *              register_id            - register_iD + Offset.
462  *
463  * RETURN:      Value read or written.
464  *
465  * DESCRIPTION: Acpi register read function.  Registers are read at the
466  *              given offset.
467  *
468  ******************************************************************************/
469 
470 acpi_status
acpi_hw_register_read(u8 use_lock,u32 register_id,u32 * return_value)471 acpi_hw_register_read (
472 	u8                              use_lock,
473 	u32                             register_id,
474 	u32                             *return_value)
475 {
476 	u32                             value1 = 0;
477 	u32                             value2 = 0;
478 	acpi_status                     status;
479 
480 
481 	ACPI_FUNCTION_TRACE ("hw_register_read");
482 
483 
484 	if (ACPI_MTX_LOCK == use_lock) {
485 		status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
486 		if (ACPI_FAILURE (status)) {
487 			return_ACPI_STATUS (status);
488 		}
489 	}
490 
491 	switch (register_id) {
492 	case ACPI_REGISTER_PM1_STATUS:           /* 16-bit access */
493 
494 		status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_FADT->xpm1a_evt_blk);
495 		if (ACPI_FAILURE (status)) {
496 			goto unlock_and_exit;
497 		}
498 
499 		/* PM1B is optional */
500 
501 		status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_FADT->xpm1b_evt_blk);
502 		value1 |= value2;
503 		break;
504 
505 
506 	case ACPI_REGISTER_PM1_ENABLE:           /* 16-bit access */
507 
508 		status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_xpm1a_enable);
509 		if (ACPI_FAILURE (status)) {
510 			goto unlock_and_exit;
511 		}
512 
513 		/* PM1B is optional */
514 
515 		status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_xpm1b_enable);
516 		value1 |= value2;
517 		break;
518 
519 
520 	case ACPI_REGISTER_PM1_CONTROL:          /* 16-bit access */
521 
522 		status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_FADT->xpm1a_cnt_blk);
523 		if (ACPI_FAILURE (status)) {
524 			goto unlock_and_exit;
525 		}
526 
527 		status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_FADT->xpm1b_cnt_blk);
528 		value1 |= value2;
529 		break;
530 
531 
532 	case ACPI_REGISTER_PM2_CONTROL:          /* 8-bit access */
533 
534 		status = acpi_hw_low_level_read (8, &value1, &acpi_gbl_FADT->xpm2_cnt_blk);
535 		break;
536 
537 
538 	case ACPI_REGISTER_PM_TIMER:             /* 32-bit access */
539 
540 		status = acpi_hw_low_level_read (32, &value1, &acpi_gbl_FADT->xpm_tmr_blk);
541 		break;
542 
543 	case ACPI_REGISTER_SMI_COMMAND_BLOCK:    /* 8-bit access */
544 
545 		status = acpi_os_read_port (acpi_gbl_FADT->smi_cmd, &value1, 8);
546 		break;
547 
548 	default:
549 		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Register ID: %X\n", register_id));
550 		status = AE_BAD_PARAMETER;
551 		break;
552 	}
553 
554 unlock_and_exit:
555 	if (ACPI_MTX_LOCK == use_lock) {
556 		(void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
557 	}
558 
559 	if (ACPI_SUCCESS (status)) {
560 		*return_value = value1;
561 	}
562 
563 	return_ACPI_STATUS (status);
564 }
565 
566 
567 /******************************************************************************
568  *
569  * FUNCTION:    acpi_hw_register_write
570  *
571  * PARAMETERS:  use_lock               - Mutex hw access.
572  *              register_id            - register_iD + Offset.
573  *
574  * RETURN:      Value read or written.
575  *
576  * DESCRIPTION: Acpi register Write function.  Registers are written at the
577  *              given offset.
578  *
579  ******************************************************************************/
580 
581 acpi_status
acpi_hw_register_write(u8 use_lock,u32 register_id,u32 value)582 acpi_hw_register_write (
583 	u8                              use_lock,
584 	u32                             register_id,
585 	u32                             value)
586 {
587 	acpi_status                     status;
588 
589 
590 	ACPI_FUNCTION_TRACE ("hw_register_write");
591 
592 
593 	if (ACPI_MTX_LOCK == use_lock) {
594 		status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
595 		if (ACPI_FAILURE (status)) {
596 			return_ACPI_STATUS (status);
597 		}
598 	}
599 
600 	switch (register_id) {
601 	case ACPI_REGISTER_PM1_STATUS:           /* 16-bit access */
602 
603 		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_evt_blk);
604 		if (ACPI_FAILURE (status)) {
605 			goto unlock_and_exit;
606 		}
607 
608 		/* PM1B is optional */
609 
610 		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_evt_blk);
611 		break;
612 
613 
614 	case ACPI_REGISTER_PM1_ENABLE:           /* 16-bit access*/
615 
616 		status = acpi_hw_low_level_write (16, value, &acpi_gbl_xpm1a_enable);
617 		if (ACPI_FAILURE (status)) {
618 			goto unlock_and_exit;
619 		}
620 
621 		/* PM1B is optional */
622 
623 		status = acpi_hw_low_level_write (16, value, &acpi_gbl_xpm1b_enable);
624 		break;
625 
626 
627 	case ACPI_REGISTER_PM1_CONTROL:          /* 16-bit access */
628 
629 		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_cnt_blk);
630 		if (ACPI_FAILURE (status)) {
631 			goto unlock_and_exit;
632 		}
633 
634 		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_cnt_blk);
635 		break;
636 
637 
638 	case ACPI_REGISTER_PM1A_CONTROL:         /* 16-bit access */
639 
640 		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_cnt_blk);
641 		break;
642 
643 
644 	case ACPI_REGISTER_PM1B_CONTROL:         /* 16-bit access */
645 
646 		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_cnt_blk);
647 		break;
648 
649 
650 	case ACPI_REGISTER_PM2_CONTROL:          /* 8-bit access */
651 
652 		status = acpi_hw_low_level_write (8, value, &acpi_gbl_FADT->xpm2_cnt_blk);
653 		break;
654 
655 
656 	case ACPI_REGISTER_PM_TIMER:             /* 32-bit access */
657 
658 		status = acpi_hw_low_level_write (32, value, &acpi_gbl_FADT->xpm_tmr_blk);
659 		break;
660 
661 
662 	case ACPI_REGISTER_SMI_COMMAND_BLOCK:    /* 8-bit access */
663 
664 		/* SMI_CMD is currently always in IO space */
665 
666 		status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd, value, 8);
667 		break;
668 
669 
670 	default:
671 		status = AE_BAD_PARAMETER;
672 		break;
673 	}
674 
675 unlock_and_exit:
676 	if (ACPI_MTX_LOCK == use_lock) {
677 		(void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
678 	}
679 
680 	return_ACPI_STATUS (status);
681 }
682 
683 
684 /******************************************************************************
685  *
686  * FUNCTION:    acpi_hw_low_level_read
687  *
688  * PARAMETERS:  Width               - 8, 16, or 32
689  *              Value               - Where the value is returned
690  *              Register            - GAS register structure
691  *
692  * RETURN:      Status
693  *
694  * DESCRIPTION: Read from either memory, IO, or PCI config space.
695  *
696  ******************************************************************************/
697 
698 acpi_status
acpi_hw_low_level_read(u32 width,u32 * value,struct acpi_generic_address * reg)699 acpi_hw_low_level_read (
700 	u32                             width,
701 	u32                             *value,
702 	struct acpi_generic_address     *reg)
703 {
704 	struct acpi_pci_id              pci_id;
705 	u16                             pci_register;
706 	acpi_status                     status;
707 
708 
709 	ACPI_FUNCTION_NAME ("hw_low_level_read");
710 
711 
712 	/*
713 	 * Must have a valid pointer to a GAS structure, and
714 	 * a non-zero address within. However, don't return an error
715 	 * because the PM1A/B code must not fail if B isn't present.
716 	 */
717 	if ((!reg) ||
718 		(!reg->address)) {
719 		return (AE_OK);
720 	}
721 	*value = 0;
722 
723 	/*
724 	 * Three address spaces supported:
725 	 * Memory, IO, or PCI_Config.
726 	 */
727 	switch (reg->address_space_id) {
728 	case ACPI_ADR_SPACE_SYSTEM_MEMORY:
729 
730 		status = acpi_os_read_memory (
731 				 (acpi_physical_address) reg->address,
732 				 value, width);
733 		break;
734 
735 
736 	case ACPI_ADR_SPACE_SYSTEM_IO:
737 
738 		status = acpi_os_read_port ((acpi_io_address) reg->address,
739 				 value, width);
740 		break;
741 
742 
743 	case ACPI_ADR_SPACE_PCI_CONFIG:
744 
745 		pci_id.segment = 0;
746 		pci_id.bus     = 0;
747 		pci_id.device  = ACPI_PCI_DEVICE (reg->address);
748 		pci_id.function = ACPI_PCI_FUNCTION (reg->address);
749 		pci_register   = (u16) ACPI_PCI_REGISTER (reg->address);
750 
751 		status = acpi_os_read_pci_configuration (&pci_id, pci_register,
752 				 value, width);
753 		break;
754 
755 
756 	default:
757 		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
758 			"Unsupported address space: %X\n", reg->address_space_id));
759 		return (AE_BAD_PARAMETER);
760 	}
761 
762 	ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read:  %8.8X width %2d from %8.8X%8.8X (%s)\n",
763 			*value, width,
764 			ACPI_FORMAT_UINT64 (reg->address),
765 			acpi_ut_get_region_name (reg->address_space_id)));
766 
767 	return (status);
768 }
769 
770 
771 /******************************************************************************
772  *
773  * FUNCTION:    acpi_hw_low_level_write
774  *
775  * PARAMETERS:  Width               - 8, 16, or 32
776  *              Value               - To be written
777  *              Register            - GAS register structure
778  *
779  * RETURN:      Status
780  *
781  * DESCRIPTION: Write to either memory, IO, or PCI config space.
782  *
783  ******************************************************************************/
784 
785 acpi_status
acpi_hw_low_level_write(u32 width,u32 value,struct acpi_generic_address * reg)786 acpi_hw_low_level_write (
787 	u32                             width,
788 	u32                             value,
789 	struct acpi_generic_address     *reg)
790 {
791 	struct acpi_pci_id              pci_id;
792 	u16                             pci_register;
793 	acpi_status                     status;
794 
795 
796 	ACPI_FUNCTION_NAME ("hw_low_level_write");
797 
798 
799 	/*
800 	 * Must have a valid pointer to a GAS structure, and
801 	 * a non-zero address within. However, don't return an error
802 	 * because the PM1A/B code must not fail if B isn't present.
803 	 */
804 	if ((!reg) ||
805 		(!reg->address)) {
806 		return (AE_OK);
807 	}
808 
809 	/*
810 	 * Three address spaces supported:
811 	 * Memory, IO, or PCI_Config.
812 	 */
813 	switch (reg->address_space_id) {
814 	case ACPI_ADR_SPACE_SYSTEM_MEMORY:
815 
816 		status = acpi_os_write_memory (
817 				 (acpi_physical_address) reg->address,
818 				 value, width);
819 		break;
820 
821 
822 	case ACPI_ADR_SPACE_SYSTEM_IO:
823 
824 		status = acpi_os_write_port ((acpi_io_address) reg->address,
825 				 value, width);
826 		break;
827 
828 
829 	case ACPI_ADR_SPACE_PCI_CONFIG:
830 
831 		pci_id.segment = 0;
832 		pci_id.bus     = 0;
833 		pci_id.device  = ACPI_PCI_DEVICE (reg->address);
834 		pci_id.function = ACPI_PCI_FUNCTION (reg->address);
835 		pci_register   = (u16) ACPI_PCI_REGISTER (reg->address);
836 
837 		status = acpi_os_write_pci_configuration (&pci_id, pci_register,
838 				 (acpi_integer) value, width);
839 		break;
840 
841 
842 	default:
843 		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
844 			"Unsupported address space: %X\n", reg->address_space_id));
845 		return (AE_BAD_PARAMETER);
846 	}
847 
848 	ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Wrote: %8.8X width %2d   to %8.8X%8.8X (%s)\n",
849 			value, width,
850 			ACPI_FORMAT_UINT64 (reg->address),
851 			acpi_ut_get_region_name (reg->address_space_id)));
852 
853 	return (status);
854 }
855