ACPI: Use _TSS for throttling control, when present. Add error checks.
_TSS was erroneously ignored, in favor of the FADT. When TSS is used, the access width is included in the PTC control/status register. So it is unnecessary that the access bit width is multiplied by 8. At the same time the bit_offset should be considered for system I/O Access. It should be checked the bit_width and bit_offset of PTC regsiter in order to avoid the failure of system I/O access. It means that bit_width plus bit_offset can't be greater than 32. Signed-off-by: Zhao Yakui <yakui.zhao@intel.com> Signed-off-by: Li Shaohua <shaohua.li@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
parent
0753f6e0a3
commit
9bcb272173
|
@ -131,6 +131,7 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
|
||||||
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
|
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
|
||||||
union acpi_object *ptc = NULL;
|
union acpi_object *ptc = NULL;
|
||||||
union acpi_object obj = { 0 };
|
union acpi_object obj = { 0 };
|
||||||
|
struct acpi_processor_throttling *throttling;
|
||||||
|
|
||||||
status = acpi_evaluate_object(pr->handle, "_PTC", NULL, &buffer);
|
status = acpi_evaluate_object(pr->handle, "_PTC", NULL, &buffer);
|
||||||
if (ACPI_FAILURE(status)) {
|
if (ACPI_FAILURE(status)) {
|
||||||
|
@ -182,6 +183,22 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
|
||||||
memcpy(&pr->throttling.status_register, obj.buffer.pointer,
|
memcpy(&pr->throttling.status_register, obj.buffer.pointer,
|
||||||
sizeof(struct acpi_ptc_register));
|
sizeof(struct acpi_ptc_register));
|
||||||
|
|
||||||
|
throttling = &pr->throttling;
|
||||||
|
|
||||||
|
if ((throttling->control_register.bit_width +
|
||||||
|
throttling->control_register.bit_offset) > 32) {
|
||||||
|
printk(KERN_ERR PREFIX "Invalid _PTC control register\n");
|
||||||
|
result = -EFAULT;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((throttling->status_register.bit_width +
|
||||||
|
throttling->status_register.bit_offset) > 32) {
|
||||||
|
printk(KERN_ERR PREFIX "Invalid _PTC status register\n");
|
||||||
|
result = -EFAULT;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
kfree(buffer.pointer);
|
kfree(buffer.pointer);
|
||||||
|
|
||||||
|
@ -379,7 +396,9 @@ static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr)
|
||||||
static int acpi_read_throttling_status(struct acpi_processor *pr,
|
static int acpi_read_throttling_status(struct acpi_processor *pr,
|
||||||
acpi_integer *value)
|
acpi_integer *value)
|
||||||
{
|
{
|
||||||
|
u32 bit_width, bit_offset;
|
||||||
u64 ptc_value;
|
u64 ptc_value;
|
||||||
|
u64 ptc_mask;
|
||||||
struct acpi_processor_throttling *throttling;
|
struct acpi_processor_throttling *throttling;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
|
@ -387,11 +406,14 @@ static int acpi_read_throttling_status(struct acpi_processor *pr,
|
||||||
switch (throttling->status_register.space_id) {
|
switch (throttling->status_register.space_id) {
|
||||||
case ACPI_ADR_SPACE_SYSTEM_IO:
|
case ACPI_ADR_SPACE_SYSTEM_IO:
|
||||||
ptc_value = 0;
|
ptc_value = 0;
|
||||||
|
bit_width = throttling->status_register.bit_width;
|
||||||
|
bit_offset = throttling->status_register.bit_offset;
|
||||||
|
|
||||||
acpi_os_read_port((acpi_io_address) throttling->status_register.
|
acpi_os_read_port((acpi_io_address) throttling->status_register.
|
||||||
address, (u32 *) &ptc_value,
|
address, (u32 *) &ptc_value,
|
||||||
(u32) throttling->status_register.bit_width *
|
(u32) (bit_width + bit_offset));
|
||||||
8);
|
ptc_mask = (1 << bit_width) - 1;
|
||||||
*value = (acpi_integer) ptc_value;
|
*value = (acpi_integer) ((ptc_value >> bit_offset) & ptc_mask);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
case ACPI_ADR_SPACE_FIXED_HARDWARE:
|
case ACPI_ADR_SPACE_FIXED_HARDWARE:
|
||||||
|
@ -408,18 +430,24 @@ static int acpi_read_throttling_status(struct acpi_processor *pr,
|
||||||
static int acpi_write_throttling_state(struct acpi_processor *pr,
|
static int acpi_write_throttling_state(struct acpi_processor *pr,
|
||||||
acpi_integer value)
|
acpi_integer value)
|
||||||
{
|
{
|
||||||
|
u32 bit_width, bit_offset;
|
||||||
u64 ptc_value;
|
u64 ptc_value;
|
||||||
|
u64 ptc_mask;
|
||||||
struct acpi_processor_throttling *throttling;
|
struct acpi_processor_throttling *throttling;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
throttling = &pr->throttling;
|
throttling = &pr->throttling;
|
||||||
switch (throttling->control_register.space_id) {
|
switch (throttling->control_register.space_id) {
|
||||||
case ACPI_ADR_SPACE_SYSTEM_IO:
|
case ACPI_ADR_SPACE_SYSTEM_IO:
|
||||||
ptc_value = value;
|
bit_width = throttling->control_register.bit_width;
|
||||||
|
bit_offset = throttling->control_register.bit_offset;
|
||||||
|
ptc_mask = (1 << bit_width) - 1;
|
||||||
|
ptc_value = value & ptc_mask;
|
||||||
|
|
||||||
acpi_os_write_port((acpi_io_address) throttling->
|
acpi_os_write_port((acpi_io_address) throttling->
|
||||||
control_register.address, (u32) ptc_value,
|
control_register.address,
|
||||||
(u32) throttling->control_register.
|
(u32) (ptc_value << bit_offset),
|
||||||
bit_width * 8);
|
(u32) (bit_width + bit_offset));
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
case ACPI_ADR_SPACE_FIXED_HARDWARE:
|
case ACPI_ADR_SPACE_FIXED_HARDWARE:
|
||||||
|
|
Loading…
Reference in a new issue