aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/hardware/hwregs.c
diff options
context:
space:
mode:
authorBob Moore <robert.moore@intel.com>2008-12-29 22:04:48 -0500
committerLen Brown <len.brown@intel.com>2008-12-31 01:14:08 -0500
commit7db5d82d0278b506441ab6025f0c6ce2f2aa3019 (patch)
tree55b54c221851c0912f9dda9958a77c3b7ccf15d3 /drivers/acpi/hardware/hwregs.c
parentecfbbc7b46f74ca48b9f42132739114c9e70f8e4 (diff)
ACPICA: Move all public H/W interfaces to new hwxface
Move public interfaces from hwregs.c to new file, hwxface.c - similar to the structure of the other ACPICA components. Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Lin Ming <ming.m.lin@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/acpi/hardware/hwregs.c')
-rw-r--r--drivers/acpi/hardware/hwregs.c498
1 files changed, 2 insertions, 496 deletions
diff --git a/drivers/acpi/hardware/hwregs.c b/drivers/acpi/hardware/hwregs.c
index d6d2ec6969f4..981e5db21a3b 100644
--- a/drivers/acpi/hardware/hwregs.c
+++ b/drivers/acpi/hardware/hwregs.c
@@ -56,7 +56,7 @@ ACPI_MODULE_NAME("hwregs")
56 * 56 *
57 * PARAMETERS: None 57 * PARAMETERS: None
58 * 58 *
59 * RETURN: None 59 * RETURN: Status
60 * 60 *
61 * DESCRIPTION: Clears all fixed and general purpose status bits 61 * DESCRIPTION: Clears all fixed and general purpose status bits
62 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED 62 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
@@ -102,125 +102,6 @@ acpi_status acpi_hw_clear_acpi_status(void)
102 102
103/******************************************************************************* 103/*******************************************************************************
104 * 104 *
105 * FUNCTION: acpi_get_sleep_type_data
106 *
107 * PARAMETERS: sleep_state - Numeric sleep state
108 * *sleep_type_a - Where SLP_TYPa is returned
109 * *sleep_type_b - Where SLP_TYPb is returned
110 *
111 * RETURN: Status - ACPI status
112 *
113 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
114 * state.
115 *
116 ******************************************************************************/
117
118acpi_status
119acpi_get_sleep_type_data(u8 sleep_state, u8 * sleep_type_a, u8 * sleep_type_b)
120{
121 acpi_status status = AE_OK;
122 struct acpi_evaluate_info *info;
123
124 ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data);
125
126 /* Validate parameters */
127
128 if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) {
129 return_ACPI_STATUS(AE_BAD_PARAMETER);
130 }
131
132 /* Allocate the evaluation information block */
133
134 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
135 if (!info) {
136 return_ACPI_STATUS(AE_NO_MEMORY);
137 }
138
139 info->pathname =
140 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]);
141
142 /* Evaluate the namespace object containing the values for this state */
143
144 status = acpi_ns_evaluate(info);
145 if (ACPI_FAILURE(status)) {
146 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
147 "%s while evaluating SleepState [%s]\n",
148 acpi_format_exception(status),
149 info->pathname));
150
151 goto cleanup;
152 }
153
154 /* Must have a return object */
155
156 if (!info->return_object) {
157 ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
158 info->pathname));
159 status = AE_NOT_EXIST;
160 }
161
162 /* It must be of type Package */
163
164 else if (ACPI_GET_OBJECT_TYPE(info->return_object) != ACPI_TYPE_PACKAGE) {
165 ACPI_ERROR((AE_INFO,
166 "Sleep State return object is not a Package"));
167 status = AE_AML_OPERAND_TYPE;
168 }
169
170 /*
171 * The package must have at least two elements. NOTE (March 2005): This
172 * goes against the current ACPI spec which defines this object as a
173 * package with one encoded DWORD element. However, existing practice
174 * by BIOS vendors seems to be to have 2 or more elements, at least
175 * one per sleep type (A/B).
176 */
177 else if (info->return_object->package.count < 2) {
178 ACPI_ERROR((AE_INFO,
179 "Sleep State return package does not have at least two elements"));
180 status = AE_AML_NO_OPERAND;
181 }
182
183 /* The first two elements must both be of type Integer */
184
185 else if ((ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[0])
186 != ACPI_TYPE_INTEGER) ||
187 (ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[1])
188 != ACPI_TYPE_INTEGER)) {
189 ACPI_ERROR((AE_INFO,
190 "Sleep State return package elements are not both Integers (%s, %s)",
191 acpi_ut_get_object_type_name(info->return_object->
192 package.elements[0]),
193 acpi_ut_get_object_type_name(info->return_object->
194 package.elements[1])));
195 status = AE_AML_OPERAND_TYPE;
196 } else {
197 /* Valid _Sx_ package size, type, and value */
198
199 *sleep_type_a = (u8)
200 (info->return_object->package.elements[0])->integer.value;
201 *sleep_type_b = (u8)
202 (info->return_object->package.elements[1])->integer.value;
203 }
204
205 if (ACPI_FAILURE(status)) {
206 ACPI_EXCEPTION((AE_INFO, status,
207 "While evaluating SleepState [%s], bad Sleep object %p type %s",
208 info->pathname, info->return_object,
209 acpi_ut_get_object_type_name(info->
210 return_object)));
211 }
212
213 acpi_ut_remove_reference(info->return_object);
214
215 cleanup:
216 ACPI_FREE(info);
217 return_ACPI_STATUS(status);
218}
219
220ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data)
221
222/*******************************************************************************
223 *
224 * FUNCTION: acpi_hw_get_register_bit_mask 105 * FUNCTION: acpi_hw_get_register_bit_mask
225 * 106 *
226 * PARAMETERS: register_id - Index of ACPI Register to access 107 * PARAMETERS: register_id - Index of ACPI Register to access
@@ -230,6 +111,7 @@ ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data)
230 * DESCRIPTION: Map register_id into a register bitmask. 111 * DESCRIPTION: Map register_id into a register bitmask.
231 * 112 *
232 ******************************************************************************/ 113 ******************************************************************************/
114
233struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id) 115struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
234{ 116{
235 ACPI_FUNCTION_ENTRY(); 117 ACPI_FUNCTION_ENTRY();
@@ -243,223 +125,6 @@ struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
243 return (&acpi_gbl_bit_register_info[register_id]); 125 return (&acpi_gbl_bit_register_info[register_id]);
244} 126}
245 127
246ACPI_EXPORT_SYMBOL(acpi_get_register_unlocked)
247
248/*******************************************************************************
249 *
250 * FUNCTION: acpi_get_register
251 *
252 * PARAMETERS: register_id - ID of ACPI bit_register to access
253 * return_value - Value that was read from the register
254 *
255 * RETURN: Status and the value read from specified Register. Value
256 * returned is normalized to bit0 (is shifted all the way right)
257 *
258 * DESCRIPTION: ACPI bit_register read function.
259 *
260 ******************************************************************************/
261
262acpi_status acpi_get_register_unlocked(u32 register_id, u32 * return_value)
263{
264 u32 register_value = 0;
265 struct acpi_bit_register_info *bit_reg_info;
266 acpi_status status;
267
268 ACPI_FUNCTION_TRACE(acpi_get_register);
269
270 /* Get the info structure corresponding to the requested ACPI Register */
271
272 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
273 if (!bit_reg_info) {
274 return_ACPI_STATUS(AE_BAD_PARAMETER);
275 }
276
277 /* Read from the register */
278
279 status = acpi_hw_register_read(bit_reg_info->parent_register,
280 &register_value);
281
282 if (ACPI_SUCCESS(status)) {
283
284 /* Normalize the value that was read */
285
286 register_value =
287 ((register_value & bit_reg_info->access_bit_mask)
288 >> bit_reg_info->bit_position);
289
290 *return_value = register_value;
291
292 ACPI_DEBUG_PRINT((ACPI_DB_IO, "Read value %8.8X register %X\n",
293 register_value,
294 bit_reg_info->parent_register));
295 }
296
297 return_ACPI_STATUS(status);
298}
299
300acpi_status acpi_get_register(u32 register_id, u32 * return_value)
301{
302 acpi_status status;
303 acpi_cpu_flags flags;
304 flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
305 status = acpi_get_register_unlocked(register_id, return_value);
306 acpi_os_release_lock(acpi_gbl_hardware_lock, flags);
307 return status;
308}
309
310ACPI_EXPORT_SYMBOL(acpi_get_register)
311
312/*******************************************************************************
313 *
314 * FUNCTION: acpi_set_register
315 *
316 * PARAMETERS: register_id - ID of ACPI bit_register to access
317 * Value - (only used on write) value to write to the
318 * Register, NOT pre-normalized to the bit pos
319 *
320 * RETURN: Status
321 *
322 * DESCRIPTION: ACPI Bit Register write function.
323 *
324 ******************************************************************************/
325acpi_status acpi_set_register(u32 register_id, u32 value)
326{
327 u32 register_value = 0;
328 struct acpi_bit_register_info *bit_reg_info;
329 acpi_status status;
330 acpi_cpu_flags lock_flags;
331
332 ACPI_FUNCTION_TRACE_U32(acpi_set_register, register_id);
333
334 /* Get the info structure corresponding to the requested ACPI Register */
335
336 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
337 if (!bit_reg_info) {
338 ACPI_ERROR((AE_INFO, "Bad ACPI HW RegisterId: %X",
339 register_id));
340 return_ACPI_STATUS(AE_BAD_PARAMETER);
341 }
342
343 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
344
345 /* Always do a register read first so we can insert the new bits */
346
347 status = acpi_hw_register_read(bit_reg_info->parent_register,
348 &register_value);
349 if (ACPI_FAILURE(status)) {
350 goto unlock_and_exit;
351 }
352
353 /*
354 * Decode the Register ID
355 * Register ID = [Register block ID] | [bit ID]
356 *
357 * Check bit ID to fine locate Register offset.
358 * Check Mask to determine Register offset, and then read-write.
359 */
360 switch (bit_reg_info->parent_register) {
361 case ACPI_REGISTER_PM1_STATUS:
362
363 /*
364 * Status Registers are different from the rest. Clear by
365 * writing 1, and writing 0 has no effect. So, the only relevant
366 * information is the single bit we're interested in, all others should
367 * be written as 0 so they will be left unchanged.
368 */
369 value = ACPI_REGISTER_PREPARE_BITS(value,
370 bit_reg_info->bit_position,
371 bit_reg_info->
372 access_bit_mask);
373 if (value) {
374 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
375 (u16) value);
376 register_value = 0;
377 }
378 break;
379
380 case ACPI_REGISTER_PM1_ENABLE:
381
382 ACPI_REGISTER_INSERT_VALUE(register_value,
383 bit_reg_info->bit_position,
384 bit_reg_info->access_bit_mask,
385 value);
386
387 status = acpi_hw_register_write(ACPI_REGISTER_PM1_ENABLE,
388 (u16) register_value);
389 break;
390
391 case ACPI_REGISTER_PM1_CONTROL:
392
393 /*
394 * Write the PM1 Control register.
395 * Note that at this level, the fact that there are actually TWO
396 * registers (A and B - and B may not exist) is abstracted.
397 */
398 ACPI_DEBUG_PRINT((ACPI_DB_IO, "PM1 control: Read %X\n",
399 register_value));
400
401 ACPI_REGISTER_INSERT_VALUE(register_value,
402 bit_reg_info->bit_position,
403 bit_reg_info->access_bit_mask,
404 value);
405
406 status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL,
407 (u16) register_value);
408 break;
409
410 case ACPI_REGISTER_PM2_CONTROL:
411
412 status = acpi_hw_register_read(ACPI_REGISTER_PM2_CONTROL,
413 &register_value);
414 if (ACPI_FAILURE(status)) {
415 goto unlock_and_exit;
416 }
417
418 ACPI_DEBUG_PRINT((ACPI_DB_IO,
419 "PM2 control: Read %X from %8.8X%8.8X\n",
420 register_value,
421 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
422 xpm2_control_block.
423 address)));
424
425 ACPI_REGISTER_INSERT_VALUE(register_value,
426 bit_reg_info->bit_position,
427 bit_reg_info->access_bit_mask,
428 value);
429
430 ACPI_DEBUG_PRINT((ACPI_DB_IO,
431 "About to write %4.4X to %8.8X%8.8X\n",
432 register_value,
433 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
434 xpm2_control_block.
435 address)));
436
437 status = acpi_hw_register_write(ACPI_REGISTER_PM2_CONTROL,
438 (u8) (register_value));
439 break;
440
441 default:
442 break;
443 }
444
445 unlock_and_exit:
446
447 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
448
449 /* Normalize the value that was read */
450
451 ACPI_DEBUG_EXEC(register_value =
452 ((register_value & bit_reg_info->access_bit_mask) >>
453 bit_reg_info->bit_position));
454
455 ACPI_DEBUG_PRINT((ACPI_DB_IO,
456 "Set bits: %8.8X actual %8.8X register %X\n", value,
457 register_value, bit_reg_info->parent_register));
458 return_ACPI_STATUS(status);
459}
460
461ACPI_EXPORT_SYMBOL(acpi_set_register)
462
463/****************************************************************************** 128/******************************************************************************
464 * 129 *
465 * FUNCTION: acpi_hw_register_read 130 * FUNCTION: acpi_hw_register_read
@@ -685,162 +350,3 @@ acpi_status acpi_hw_register_write(u32 register_id, u32 value)
685 exit: 350 exit:
686 return_ACPI_STATUS(status); 351 return_ACPI_STATUS(status);
687} 352}
688
689/******************************************************************************
690 *
691 * FUNCTION: acpi_read
692 *
693 * PARAMETERS: Value - Where the value is returned
694 * Reg - GAS register structure
695 *
696 * RETURN: Status
697 *
698 * DESCRIPTION: Read from either memory or IO space.
699 *
700 ******************************************************************************/
701
702acpi_status acpi_read(u32 *value, struct acpi_generic_address *reg)
703{
704 u32 width;
705 u64 address;
706 acpi_status status;
707
708 ACPI_FUNCTION_NAME(acpi_read);
709
710 /*
711 * Must have a valid pointer to a GAS structure, and
712 * a non-zero address within. However, don't return an error
713 * because the PM1A/B code must not fail if B isn't present.
714 */
715 if (!reg) {
716 return (AE_OK);
717 }
718
719 /* Get a local copy of the address. Handles possible alignment issues */
720
721 ACPI_MOVE_64_TO_64(&address, &reg->address);
722 if (!address) {
723 return (AE_OK);
724 }
725
726 /* Supported widths are 8/16/32 */
727
728 width = reg->bit_width;
729 if ((width != 8) && (width != 16) && (width != 32)) {
730 return (AE_SUPPORT);
731 }
732
733 /* Initialize entire 32-bit return value to zero */
734
735 *value = 0;
736
737 /*
738 * Two address spaces supported: Memory or IO.
739 * PCI_Config is not supported here because the GAS struct is insufficient
740 */
741 switch (reg->space_id) {
742 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
743
744 status = acpi_os_read_memory((acpi_physical_address) address,
745 value, width);
746 break;
747
748 case ACPI_ADR_SPACE_SYSTEM_IO:
749
750 status =
751 acpi_os_read_port((acpi_io_address) address, value, width);
752 break;
753
754 default:
755 ACPI_ERROR((AE_INFO,
756 "Unsupported address space: %X", reg->space_id));
757 return (AE_BAD_PARAMETER);
758 }
759
760 ACPI_DEBUG_PRINT((ACPI_DB_IO,
761 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
762 *value, width, ACPI_FORMAT_UINT64(address),
763 acpi_ut_get_region_name(reg->space_id)));
764
765 return (status);
766}
767
768ACPI_EXPORT_SYMBOL(acpi_read)
769
770/******************************************************************************
771 *
772 * FUNCTION: acpi_write
773 *
774 * PARAMETERS: Value - To be written
775 * Reg - GAS register structure
776 *
777 * RETURN: Status
778 *
779 * DESCRIPTION: Write to either memory or IO space.
780 *
781 ******************************************************************************/
782
783acpi_status
784acpi_write(u32 value, struct acpi_generic_address *reg)
785{
786 u32 width;
787 u64 address;
788 acpi_status status;
789
790 ACPI_FUNCTION_NAME(acpi_write);
791
792 /*
793 * Must have a valid pointer to a GAS structure, and
794 * a non-zero address within. However, don't return an error
795 * because the PM1A/B code must not fail if B isn't present.
796 */
797 if (!reg) {
798 return (AE_OK);
799 }
800
801 /* Get a local copy of the address. Handles possible alignment issues */
802
803 ACPI_MOVE_64_TO_64(&address, &reg->address);
804 if (!address) {
805 return (AE_OK);
806 }
807
808 /* Supported widths are 8/16/32 */
809
810 width = reg->bit_width;
811 if ((width != 8) && (width != 16) && (width != 32)) {
812 return (AE_SUPPORT);
813 }
814
815 /*
816 * Two address spaces supported: Memory or IO.
817 * PCI_Config is not supported here because the GAS struct is insufficient
818 */
819 switch (reg->space_id) {
820 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
821
822 status = acpi_os_write_memory((acpi_physical_address) address,
823 value, width);
824 break;
825
826 case ACPI_ADR_SPACE_SYSTEM_IO:
827
828 status = acpi_os_write_port((acpi_io_address) address, value,
829 width);
830 break;
831
832 default:
833 ACPI_ERROR((AE_INFO,
834 "Unsupported address space: %X", reg->space_id));
835 return (AE_BAD_PARAMETER);
836 }
837
838 ACPI_DEBUG_PRINT((ACPI_DB_IO,
839 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
840 value, width, ACPI_FORMAT_UINT64(address),
841 acpi_ut_get_region_name(reg->space_id)));
842
843 return (status);
844}
845
846ACPI_EXPORT_SYMBOL(acpi_write)