Skip to content

Commit f06011a

Browse files
committed
ACPICA: Introduce acpi_hw_gpe_read() and acpi_hw_gpe_write()
Now that GPE blocks are validated at the initialization time, accesses to GPE registers can be made more straightforward by ommitting all of the redundant checks in acpi_hw_read() and acpi_hw_write() and only invoking the OS-provided helper for the given type of access (read or write) and the address space holding these registers. For this reason, introduce simplified routines for accessing GPE registers, acpi_hw_gpe_read() and acpi_hw_gpe_write(), designed in accordance with the above observation, and modify all of the code accessing GPE registers to use them instead of acpi_hw_read() and acpi_hw_write(), respectively. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 84b4328 commit f06011a

4 files changed

Lines changed: 84 additions & 20 deletions

File tree

drivers/acpi/acpica/achware.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ acpi_status acpi_hw_validate_io_block(u64 address, u32 bit_width, u32 count);
7878
/*
7979
* hwgpe - GPE support
8080
*/
81+
acpi_status acpi_hw_gpe_read(u64 *value, struct acpi_generic_address *reg);
82+
83+
acpi_status acpi_hw_gpe_write(u64 value, struct acpi_generic_address *reg);
84+
8185
u32 acpi_hw_get_gpe_register_bit(struct acpi_gpe_event_info *gpe_event_info);
8286

8387
acpi_status

drivers/acpi/acpica/evgpe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,14 +656,14 @@ acpi_ev_detect_gpe(struct acpi_namespace_node *gpe_device,
656656

657657
/* GPE currently enabled (enable bit == 1)? */
658658

659-
status = acpi_hw_read(&enable_reg, &gpe_register_info->enable_address);
659+
status = acpi_hw_gpe_read(&enable_reg, &gpe_register_info->enable_address);
660660
if (ACPI_FAILURE(status)) {
661661
goto error_exit;
662662
}
663663

664664
/* GPE currently active (status bit == 1)? */
665665

666-
status = acpi_hw_read(&status_reg, &gpe_register_info->status_address);
666+
status = acpi_hw_gpe_read(&status_reg, &gpe_register_info->status_address);
667667
if (ACPI_FAILURE(status)) {
668668
goto error_exit;
669669
}

drivers/acpi/acpica/evgpeblk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,14 @@ acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
251251

252252
/* Disable all GPEs within this register */
253253

254-
status = acpi_hw_write(0x00, &this_register->enable_address);
254+
status = acpi_hw_gpe_write(0x00, &this_register->enable_address);
255255
if (ACPI_FAILURE(status)) {
256256
goto error_exit;
257257
}
258258

259259
/* Clear any pending GPE events within this register */
260260

261-
status = acpi_hw_write(0xFF, &this_register->status_address);
261+
status = acpi_hw_gpe_write(0xFF, &this_register->status_address);
262262
if (ACPI_FAILURE(status)) {
263263
goto error_exit;
264264
}

drivers/acpi/acpica/hwgpe.c

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,66 @@ static acpi_status
2424
acpi_hw_gpe_enable_write(u8 enable_mask,
2525
struct acpi_gpe_register_info *gpe_register_info);
2626

27+
/******************************************************************************
28+
*
29+
* FUNCTION: acpi_hw_gpe_read
30+
*
31+
* PARAMETERS: value - Where the value is returned
32+
* reg - GAS register structure
33+
*
34+
* RETURN: Status
35+
*
36+
* DESCRIPTION: Read from a GPE register in either memory or IO space.
37+
*
38+
* LIMITATIONS: <These limitations also apply to acpi_hw_gpe_write>
39+
* space_ID must be system_memory or system_IO.
40+
*
41+
******************************************************************************/
42+
43+
acpi_status acpi_hw_gpe_read(u64 *value, struct acpi_generic_address *reg)
44+
{
45+
acpi_status status;
46+
u32 value32;
47+
48+
if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
49+
return acpi_os_read_memory((acpi_physical_address)reg->address,
50+
value, ACPI_GPE_REGISTER_WIDTH);
51+
}
52+
53+
status = acpi_os_read_port((acpi_io_address)reg->address,
54+
&value32, ACPI_GPE_REGISTER_WIDTH);
55+
if (ACPI_FAILURE(status))
56+
return_ACPI_STATUS(status);
57+
58+
*value = (u64)value32;
59+
60+
return_ACPI_STATUS(AE_OK);
61+
}
62+
63+
/******************************************************************************
64+
*
65+
* FUNCTION: acpi_hw_gpe_write
66+
*
67+
* PARAMETERS: value - Value to be written
68+
* reg - GAS register structure
69+
*
70+
* RETURN: Status
71+
*
72+
* DESCRIPTION: Write to a GPE register in either memory or IO space.
73+
*
74+
******************************************************************************/
75+
76+
acpi_status acpi_hw_gpe_write(u64 value, struct acpi_generic_address *reg)
77+
{
78+
if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
79+
return acpi_os_write_memory((acpi_physical_address)reg->address,
80+
value, ACPI_GPE_REGISTER_WIDTH);
81+
}
82+
83+
return acpi_os_write_port((acpi_io_address)reg->address, (u32)value,
84+
ACPI_GPE_REGISTER_WIDTH);
85+
}
86+
2787
/******************************************************************************
2888
*
2989
* FUNCTION: acpi_hw_get_gpe_register_bit
@@ -79,7 +139,8 @@ acpi_hw_low_set_gpe(struct acpi_gpe_event_info *gpe_event_info, u32 action)
79139

80140
/* Get current value of the enable register that contains this GPE */
81141

82-
status = acpi_hw_read(&enable_mask, &gpe_register_info->enable_address);
142+
status = acpi_hw_gpe_read(&enable_mask,
143+
&gpe_register_info->enable_address);
83144
if (ACPI_FAILURE(status)) {
84145
return (status);
85146
}
@@ -118,9 +179,8 @@ acpi_hw_low_set_gpe(struct acpi_gpe_event_info *gpe_event_info, u32 action)
118179

119180
/* Write the updated enable mask */
120181

121-
status =
122-
acpi_hw_write(enable_mask,
123-
&gpe_register_info->enable_address);
182+
status = acpi_hw_gpe_write(enable_mask,
183+
&gpe_register_info->enable_address);
124184
}
125185
return (status);
126186
}
@@ -158,8 +218,8 @@ acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info *gpe_event_info)
158218
*/
159219
register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
160220

161-
status =
162-
acpi_hw_write(register_bit, &gpe_register_info->status_address);
221+
status = acpi_hw_gpe_write(register_bit,
222+
&gpe_register_info->status_address);
163223
return (status);
164224
}
165225

@@ -227,7 +287,7 @@ acpi_hw_get_gpe_status(struct acpi_gpe_event_info *gpe_event_info,
227287

228288
/* GPE currently enabled (enable bit == 1)? */
229289

230-
status = acpi_hw_read(&in_byte, &gpe_register_info->enable_address);
290+
status = acpi_hw_gpe_read(&in_byte, &gpe_register_info->enable_address);
231291
if (ACPI_FAILURE(status)) {
232292
return (status);
233293
}
@@ -238,7 +298,7 @@ acpi_hw_get_gpe_status(struct acpi_gpe_event_info *gpe_event_info,
238298

239299
/* GPE currently active (status bit == 1)? */
240300

241-
status = acpi_hw_read(&in_byte, &gpe_register_info->status_address);
301+
status = acpi_hw_gpe_read(&in_byte, &gpe_register_info->status_address);
242302
if (ACPI_FAILURE(status)) {
243303
return (status);
244304
}
@@ -274,7 +334,8 @@ acpi_hw_gpe_enable_write(u8 enable_mask,
274334

275335
gpe_register_info->enable_mask = enable_mask;
276336

277-
status = acpi_hw_write(enable_mask, &gpe_register_info->enable_address);
337+
status = acpi_hw_gpe_write(enable_mask,
338+
&gpe_register_info->enable_address);
278339
return (status);
279340
}
280341

@@ -341,9 +402,8 @@ acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
341402

342403
/* Clear status on all GPEs in this register */
343404

344-
status =
345-
acpi_hw_write(0xFF,
346-
&gpe_block->register_info[i].status_address);
405+
status = acpi_hw_gpe_write(0xFF,
406+
&gpe_block->register_info[i].status_address);
347407
if (ACPI_FAILURE(status)) {
348408
return (status);
349409
}
@@ -481,14 +541,14 @@ acpi_hw_get_gpe_block_status(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
481541
for (i = 0; i < gpe_block->register_count; i++) {
482542
gpe_register_info = &gpe_block->register_info[i];
483543

484-
status = acpi_hw_read(&in_enable,
485-
&gpe_register_info->enable_address);
544+
status = acpi_hw_gpe_read(&in_enable,
545+
&gpe_register_info->enable_address);
486546
if (ACPI_FAILURE(status)) {
487547
continue;
488548
}
489549

490-
status = acpi_hw_read(&in_status,
491-
&gpe_register_info->status_address);
550+
status = acpi_hw_gpe_read(&in_status,
551+
&gpe_register_info->status_address);
492552
if (ACPI_FAILURE(status)) {
493553
continue;
494554
}

0 commit comments

Comments
 (0)