Commit Graph

103 Commits

Author SHA1 Message Date
David Arcari b33628638e ACPI: CPPC: Modify cppc_get_auto_sel_caps() to cppc_get_auto_sel()
JIRA: https://issues.redhat.com/browse/RHEL-105422

commit 2605e4ab6615ef43361b18fc6d08dd884896aad8
Author: Lifeng Zheng <zhenglifeng1@huawei.com>
Date:   Fri Apr 11 17:38:54 2025 +0800

    ACPI: CPPC: Modify cppc_get_auto_sel_caps() to cppc_get_auto_sel()

    Modify cppc_get_auto_sel_caps() to cppc_get_auto_sel(). Using a
    cppc_perf_caps to carry the value is unnecessary.

    Add a check to ensure the pointer 'enable' is not null.

    Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
    Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
    Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
    Link: https://patch.msgid.link/20250411093855.982491-8-zhenglifeng1@huawei.com
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2025-08-29 07:11:22 -04:00
David Arcari 8f91629029 ACPI: CPPC: Refactor register value get and set ABIs
JIRA: https://issues.redhat.com/browse/RHEL-105422

commit ab482f1bac6b128b8fe910b6663a4f74a3a9796c
Author: Lifeng Zheng <zhenglifeng1@huawei.com>
Date:   Fri Apr 11 17:38:53 2025 +0800

    ACPI: CPPC: Refactor register value get and set ABIs

    Refactor register value get and set ABIs by using cppc_get_reg_val(),
    cppc_set_reg_val() and CPPC_REG_VAL_READ().

    Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
    Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
    Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
    Link: https://patch.msgid.link/20250411093855.982491-7-zhenglifeng1@huawei.com
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2025-08-29 07:11:22 -04:00
David Arcari 60e9778fc2 ACPI: CPPC: Add cppc_set_reg_val()
JIRA: https://issues.redhat.com/browse/RHEL-105422

commit e05c75072c2eaa6e0b152a558b3be5cbcf79a587
Author: Lifeng Zheng <zhenglifeng1@huawei.com>
Date:   Fri Apr 11 17:38:52 2025 +0800

    ACPI: CPPC: Add cppc_set_reg_val()

    Add cppc_set_reg_val() as a generic function for setting CPPC register
    values, with this features:

     1. Check register. If a register is writeable, it must be a buffer and
        can not be null.

     2. Extract the operations if register is in PCC out as
        cppc_set_reg_val_in_pcc().

    This function can be used to reduce some existing code duplication.

    Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
    Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
    Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
    Link: https://patch.msgid.link/20250411093855.982491-6-zhenglifeng1@huawei.com
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2025-08-29 07:11:22 -04:00
David Arcari d01088157c ACPI: CPPC: Extract cppc_get_reg_val_in_pcc()
JIRA: https://issues.redhat.com/browse/RHEL-105422

commit b5ef45e6a1777fe4e857a1cd48631dc14064eae4
Author: Lifeng Zheng <zhenglifeng1@huawei.com>
Date:   Fri Apr 11 17:38:51 2025 +0800

    ACPI: CPPC: Extract cppc_get_reg_val_in_pcc()

    Extract the operations if register is in pcc out from cppc_get_reg_val()
    as cppc_get_reg_val_in_pcc().

    Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
    Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
    Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
    Link: https://patch.msgid.link/20250411093855.982491-5-zhenglifeng1@huawei.com
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2025-08-29 07:11:22 -04:00
David Arcari ce246914c4 ACPI: CPPC: Rename cppc_get_perf() to cppc_get_reg_val()
JIRA: https://issues.redhat.com/browse/RHEL-105422

commit 714d103ce868cd0718d0e5262cbc76384a2eb03a
Author: Lifeng Zheng <zhenglifeng1@huawei.com>
Date:   Fri Apr 11 17:38:50 2025 +0800

    ACPI: CPPC: Rename cppc_get_perf() to cppc_get_reg_val()

    Rename cppc_get_perf() to cppc_get_reg_val() as a generic function to
    read CPPC registers.

    Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
    Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
    Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
    Link: https://patch.msgid.link/20250411093855.982491-4-zhenglifeng1@huawei.com
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2025-08-29 07:11:22 -04:00
David Arcari 0d7b888854 ACPI: CPPC: Optimize cppc_get_perf()
JIRA: https://issues.redhat.com/browse/RHEL-105422

commit 45f3763a2122553e548fa0430b77605dc23f00cc
Author: Lifeng Zheng <zhenglifeng1@huawei.com>
Date:   Fri Apr 11 17:38:49 2025 +0800

    ACPI: CPPC: Optimize cppc_get_perf()

    Optimize cppc_get_perf() with three changes:

     1. Change the error kind to "no such device" when pcc_ss_id < 0, as
        other register value getting functions.

     2. Add a check to ensure the pointer 'perf' is no null.

     3. Add a check to verify if the register is supported to be read before
        using it. The logic is:

        (1) If the register is of the integer type, check whether the
            register is optional and its value is 0. If yes, the register
            is not supported.

        (2) If the register is of other types, a null one is not supported.

     4. Return the result of cpc_read() instead of 0.

    Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
    Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
    Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
    Link: https://patch.msgid.link/20250411093855.982491-3-zhenglifeng1@huawei.com
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2025-08-29 07:11:22 -04:00
David Arcari 68c04eacd5 ACPI: CPPC: Add IS_OPTIONAL_CPC_REG macro to judge if a cpc_reg is optional
JIRA: https://issues.redhat.com/browse/RHEL-105422

commit e3d7935a6c6138da51626d2b956a079dd0e6671b
Author: Lifeng Zheng <zhenglifeng1@huawei.com>
Date:   Fri Apr 11 17:38:48 2025 +0800

    ACPI: CPPC: Add IS_OPTIONAL_CPC_REG macro to judge if a cpc_reg is optional

    In ACPI 6.5, s8.4.6.1 _CPC (Continuous Performance Control), whether
    each of the per-cpu cpc_regs[] is mandatory or optional is defined.

    Since the CPC_SUPPORTED() check is only for optional _CPC fields,
    another macro to check if the field is optional is needed.

    Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
    Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
    Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
    Link: https://patch.msgid.link/20250411093855.982491-2-zhenglifeng1@huawei.com
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2025-08-29 07:11:22 -04:00
David Arcari b326fd86fb ACPI: processor: Move arch_init_invariance_cppc() call later
JIRA: https://issues.redhat.com/browse/RHEL-75923

commit b79276dcac9124a79c8cf7cc8fbdd3d4c3c9a7c7
Author: Mario Limonciello <mario.limonciello@amd.com>
Date:   Mon Nov 4 16:28:55 2024 -0600

    ACPI: processor: Move arch_init_invariance_cppc() call later

    arch_init_invariance_cppc() is called at the end of
    acpi_cppc_processor_probe() in order to configure frequency invariance
    based upon the values from _CPC.

    This however doesn't work on AMD CPPC shared memory designs that have
    AMD preferred cores enabled because _CPC needs to be analyzed from all
    cores to judge if preferred cores are enabled.

    This issue manifests to users as a warning since commit 21fb59ab4b97
    ("ACPI: CPPC: Adjust debug messages in amd_set_max_freq_ratio() to warn"):
    ```
    Could not retrieve highest performance (-19)
    ```

    However the warning isn't the cause of this, it was actually
    commit 279f838a61f9 ("x86/amd: Detect preferred cores in
    amd_get_boost_ratio_numerator()") which exposed the issue.

    To fix this problem, change arch_init_invariance_cppc() into a new weak
    symbol that is called at the end of acpi_processor_driver_init().
    Each architecture that supports it can declare the symbol to override
    the weak one.

    Define it for x86, in arch/x86/kernel/acpi/cppc.c, and for all of the
    architectures using the generic arch_topology.c code.

    Fixes: 279f838a61f9 ("x86/amd: Detect preferred cores in amd_get_boost_ratio_numerator()")
    Reported-by: Ivan Shapovalov <intelfx@intelfx.name>
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219431
    Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
    Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
    Link: https://patch.msgid.link/20241104222855.3959267-1-superm1@kernel.org
    [ rjw: Changelog edit ]
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2025-02-18 07:30:14 -05:00
Mark Langsdorf ca198757c7 ACPI: CPPC: Fix access width used for PCC registers
JIRA: https://issues.redhat.com/browse/RHEL-37532
CVE: CVE-2024-35995

commit f489c948028b69cea235d9c0de1cc10eeb26a172
Author: Vanshidhar Konda <vanshikonda@os.amperecomputing.com>
Date:   Thu Apr 11 16:18:44 2024 -0700

commit 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for system
memory accesses") modified cpc_read()/cpc_write() to use access_width to
read CPC registers.

However, for PCC registers the access width field in the ACPI register
macro specifies the PCC subspace ID.  For non-zero PCC subspace ID it is
incorrectly treated as access width. This causes errors when reading
from PCC registers in the CPPC driver.

For PCC registers, base the size of read/write on the bit width field.
The debug message in cpc_read()/cpc_write() is updated to print relevant
information for the address space type used to read the register.

Fixes: 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for system memory accesses")
Signed-off-by: Vanshidhar Konda <vanshikonda@os.amperecomputing.com>
Tested-by: Jarred White <jarredwhite@linux.microsoft.com>
Reviewed-by: Jarred White <jarredwhite@linux.microsoft.com>
Reviewed-by: Easwar Hariharan <eahariha@linux.microsoft.com>
Cc: 5.15+ <stable@vger.kernel.org> # 5.15+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2024-06-28 15:08:12 -04:00
Mark Langsdorf 46c6a90937 ACPI: CPPC: Fix bit_offset shift in MASK_VAL() macro
JIRA: https://issues.redhat.com/browse/RHEL-37532
CVE: CVE-2024-35995

commit 05d92ee782eeb7b939bdd0189e6efcab9195bf95
Author: Jarred White <jarredwhite@linux.microsoft.com>
Date:   Mon Apr 8 22:23:09 2024 -0700

Commit 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for
system memory accesses") neglected to properly wrap the bit_offset shift
when it comes to applying the mask. This may cause incorrect values to be
read and may cause the cpufreq module not be loaded.

[   11.059751] cpu_capacity: CPU0 missing/invalid highest performance.
[   11.066005] cpu_capacity: partial information: fallback to 1024 for all CPUs

Also, corrected the bitmask generation in GENMASK (extra bit being added).

Fixes: 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for system memory accesses")
Signed-off-by: Jarred White <jarredwhite@linux.microsoft.com>
Cc: 5.15+ <stable@vger.kernel.org> # 5.15+
Reviewed-by: Vanshidhar Konda <vanshikonda@os.amperecomputing.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2024-06-28 15:07:44 -04:00
Mark Langsdorf 701c4f665b ACPI: CPPC: Use access_width over bit_width for system memory accesses
JIRA: https://issues.redhat.com/browse/RHEL-37532
CVE: CVE-2024-35995

commit 2f4a4d63a193be6fd530d180bb13c3592052904c
Author: Jarred White <jarredwhite@linux.microsoft.com>
Date:   Fri Mar 1 11:25:59 2024 -0800

To align with ACPI 6.3+, since bit_width can be any 8-bit value, it
cannot be depended on to be always on a clean 8b boundary. This was
uncovered on the Cobalt 100 platform.

SError Interrupt on CPU26, code 0xbe000011 -- SError
 CPU: 26 PID: 1510 Comm: systemd-udevd Not tainted 5.15.2.1-13 #1
 Hardware name: MICROSOFT CORPORATION, BIOS MICROSOFT CORPORATION
 pstate: 62400009 (nZCv daif +PAN -UAO +TCO -DIT -SSBS BTYPE=--)
 pc : cppc_get_perf_caps+0xec/0x410
 lr : cppc_get_perf_caps+0xe8/0x410
 sp : ffff8000155ab730
 x29: ffff8000155ab730 x28: ffff0080139d0038 x27: ffff0080139d0078
 x26: 0000000000000000 x25: ffff0080139d0058 x24: 00000000ffffffff
 x23: ffff0080139d0298 x22: ffff0080139d0278 x21: 0000000000000000
 x20: ffff00802b251910 x19: ffff0080139d0000 x18: ffffffffffffffff
 x17: 0000000000000000 x16: ffffdc7e111bad04 x15: ffff00802b251008
 x14: ffffffffffffffff x13: ffff013f1fd63300 x12: 0000000000000006
 x11: ffffdc7e128f4420 x10: 0000000000000000 x9 : ffffdc7e111badec
 x8 : ffff00802b251980 x7 : 0000000000000000 x6 : ffff0080139d0028
 x5 : 0000000000000000 x4 : ffff0080139d0018 x3 : 00000000ffffffff
 x2 : 0000000000000008 x1 : ffff8000155ab7a0 x0 : 0000000000000000
 Kernel panic - not syncing: Asynchronous SError Interrupt
 CPU: 26 PID: 1510 Comm: systemd-udevd Not tainted
5.15.2.1-13 #1
 Hardware name: MICROSOFT CORPORATION, BIOS MICROSOFT CORPORATION
 Call trace:
  dump_backtrace+0x0/0x1e0
  show_stack+0x24/0x30
  dump_stack_lvl+0x8c/0xb8
  dump_stack+0x18/0x34
  panic+0x16c/0x384
  add_taint+0x0/0xc0
  arm64_serror_panic+0x7c/0x90
  arm64_is_fatal_ras_serror+0x34/0xa4
  do_serror+0x50/0x6c
  el1h_64_error_handler+0x40/0x74
  el1h_64_error+0x7c/0x80
  cppc_get_perf_caps+0xec/0x410
  cppc_cpufreq_cpu_init+0x74/0x400 [cppc_cpufreq]
  cpufreq_online+0x2dc/0xa30
  cpufreq_add_dev+0xc0/0xd4
  subsys_interface_register+0x134/0x14c
  cpufreq_register_driver+0x1b0/0x354
  cppc_cpufreq_init+0x1a8/0x1000 [cppc_cpufreq]
  do_one_initcall+0x50/0x250
  do_init_module+0x60/0x27c
  load_module+0x2300/0x2570
  __do_sys_finit_module+0xa8/0x114
  __arm64_sys_finit_module+0x2c/0x3c
  invoke_syscall+0x78/0x100
  el0_svc_common.constprop.0+0x180/0x1a0
  do_el0_svc+0x84/0xa0
  el0_svc+0x2c/0xc0
  el0t_64_sync_handler+0xa4/0x12c
  el0t_64_sync+0x1a4/0x1a8

Instead, use access_width to determine the size and use the offset and
width to shift and mask the bits to read/write out. Make sure to add a
check for system memory since pcc redefines the access_width to
subspace id.

If access_width is not set, then fall back to using bit_width.

Signed-off-by: Jarred White <jarredwhite@linux.microsoft.com>
Reviewed-by: Easwar Hariharan <eahariha@linux.microsoft.com>
Cc: 5.15+ <stable@vger.kernel.org> # 5.15+
[ rjw: Subject and changelog edits, comment adjustments ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2024-06-28 14:46:01 -04:00
David Arcari ae703fe8b8 ACPI: CPPC: Add helper to get the highest performance value
JIRA: https://issues.redhat.com/browse/RHEL-34751

commit 12753d71e8c5c3e716cedba23ddeed508da0bdc4
Author: Meng Li <li.meng@amd.com>
Date:   Fri Jan 19 17:04:57 2024 +0800

    ACPI: CPPC: Add helper to get the highest performance value

    Add support for getting the highest performance to the
    generic CPPC driver. This enables downstream drivers
    such as amd-pstate to discover and use these values.

    Refer to Chapter 8.4.6.1.1.1. Highest Performance of ACPI
    Specification 6.5 for details on continuous performance control
    of CPPC (linked below).

    Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
    Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
    Reviewed-by: Wyes Karny <wyes.karny@amd.com>
    Reviewed-by: Perry Yuan <perry.yuan@amd.com>
    Acked-by: Huang Rui <ray.huang@amd.com>
    Signed-off-by: Meng Li <li.meng@amd.com>
    Link: https://uefi.org/specs/ACPI/6.5/08_Processor_Configuration_and_Control.html?highlight=cppc#highest-performance
    [ rjw: Subject and changelog edits ]
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-06-06 12:28:10 -04:00
Lucas Zampieri d23522d08a Merge: Sched: schedutil/cpufreq updates
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/3935

JIRA: https://issues.redhat.com/browse/RHEL-29020  
  
Bring schedutil code up to about v6.8. This includes some fixes for  
code in rhel9 from the 5.14 rebase.  There are few pieces in cpufreq  
driver code and the arm architectures needed to make it complete.  
Tested: Ran stress tests with schedutil governor. Ran general scheduler  
stress and performance tests.  
  
Signed-off-by: Phil Auld <pauld@redhat.com>

Approved-by: Mark Langsdorf <mlangsdo@redhat.com>
Approved-by: Waiman Long <longman@redhat.com>

Merged-by: Lucas Zampieri <lzampier@redhat.com>
2024-04-26 12:34:20 +00:00
Phil Auld 4b1ca2bcc2 cpufreq/cppc: Move and rename cppc_cpufreq_{perf_to_khz|khz_to_perf}()
JIRA: https://issues.redhat.com/browse/RHEL-29020

commit 50b813b147e9eb6546a1fc49d4e703e6d23691f2
Author: Vincent Guittot <vincent.guittot@linaro.org>
Date:   Mon Dec 11 11:48:53 2023 +0100

    cpufreq/cppc: Move and rename cppc_cpufreq_{perf_to_khz|khz_to_perf}()

    Move and rename cppc_cpufreq_perf_to_khz() and cppc_cpufreq_khz_to_perf() to
    use them outside cppc_cpufreq in topology_init_cpu_capacity_cppc().

    Modify the interface to use struct cppc_perf_caps *caps instead of
    struct cppc_cpudata *cpu_data as we only use the fields of cppc_perf_caps.

    cppc_cpufreq was converting the lowest and nominal freq from MHz to kHz
    before using them. We move this conversion inside cppc_perf_to_khz and
    cppc_khz_to_perf to make them generic and usable outside cppc_cpufreq.

    No functional change

    Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Tested-by: Pierre Gondois <pierre.gondois@arm.com>
    Acked-by: Rafael J. Wysocki <rafael@kernel.org>
    Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
    Link: https://lore.kernel.org/r/20231211104855.558096-6-vincent.guittot@linaro.org

Signed-off-by: Phil Auld <pauld@redhat.com>
2024-04-05 09:43:59 -04:00
Mark Langsdorf 9cb86ffc8d ACPI: CPPC: Add min and max perf register writing support
JIRA: https://issues.redhat.com/browse/RHEL-26871

commit 76531df5e13b5b997a17940d6980a168c616e962
Author: Wyes Karny <wyes.karny@amd.com>
Date: Fri, 17 Mar 2023 19:06:23 +0000

Currently writing of min and max perf register is deferred in
cppc_set_perf function. In CPPC guided mode, these registers needed to
be written to guide the platform about min and max perf levels. Add this support
to make guided mode work properly on AMD shared memory systems.

Acked-by: Huang Rui <ray.huang@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Wyes Karny <wyes.karny@amd.com>
[ rjw: Fixed up a multiline comment, subject edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2024-03-27 11:39:36 -04:00
David Arcari 97c96f8521 ACPI: CPPC: Add auto select register read/write support
Bugzilla: https://bugzilla.redhat.com/2218689

commit c984f5d5d45bd5f80d6a9d8541e809300c963aca
Author: Wyes Karny <wyes.karny@amd.com>
Date:   Tue Mar 7 11:27:36 2023 +0000

    ACPI: CPPC: Add auto select register read/write support

    For some AMD shared memory based systems, the autonomous selection bit
    needed to be set explicitly. Add autonomous selection register related
    APIs to acpi driver, which amd_pstate driver uses later.

    Acked-by: Huang Rui <ray.huang@amd.com>
    Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
    Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
    Signed-off-by: Wyes Karny <wyes.karny@amd.com>
    [ rjw: Fixed up kerneldoc comments, white space adjustment, subject edits ]
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-07-18 08:45:07 -04:00
Mark Langsdorf 07e560f955 ACPI: make kobj_type structures constant
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2176554

commit a527b0111798ed7b9f49830989eaabfe537e09ef
Author: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <linux@weissschuh.net>
Date: Tue, 14 Feb 2023 03:23:52 +0000

Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.")
the driver core allows the usage of const struct kobj_type.

Take advantage of this to constify the structure definitions to prevent
modification at runtime.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-05-18 15:46:35 -04:00
Mark Langsdorf 55d65fb888 ACPI: CPPC: Fix some kernel-doc comments
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2176554

commit fda7be2068973195343d14c1f760adcd481455c9
Author: Yang Li <yang.lee@linux.alibaba.com>
Date: Wed, 8 Feb 2023 10:31:58 +0800

Add the description of @pcc_ss_id in pcc_data_alloc().
Add the description of @cpu_num in cppc_get_transition_latency().

clear the below warnings:
drivers/acpi/cppc_acpi.c:607: warning: Function parameter or member 'pcc_ss_id' not described in 'pcc_data_alloc'
drivers/acpi/cppc_acpi.c:1616: warning: Function parameter or member 'cpu_num' not described in 'cppc_get_transition_latency'

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=3983
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
[ rjw: Dropped redundant empty code lines, minor edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-05-18 15:46:35 -04:00
Mark Langsdorf af243c6e92 ACPI: CPPC: Add AMD pstate energy performance preference cppc control
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2176554

commit 7bc1fcd399018245575974508c26e882da0bd915
Author: Perry Yuan <Perry.Yuan@amd.com>
Date: Tue, 31 Jan 2023 17:00:06 +0800

Add support for setting and querying EPP preferences to the generic
CPPC driver.  This enables downstream drivers such as amd-pstate to discover
and use these values.

Downstream drivers that want to use the new symbols cppc_get_epp_caps
and cppc_set_epp_perf for querying and setting EPP preferences will need
to call cppc_set_epp_perf to enable the EPP function firstly.

Acked-by: Huang Rui <ray.huang@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Reviewed-by: Wyes Karny <wyes.karny@amd.com>
Tested-by: Wyes Karny <wyes.karny@amd.com>
Signed-off-by: Perry Yuan <Perry.Yuan@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-05-18 15:46:35 -04:00
Mark Langsdorf 3093477238 ACPI: use sysfs_emit() instead of scnprintf()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2176554

commit 92266c65e08793fda74d1d71edfbe25000807f39
Author: ye xingchen <ye.xingchen@zte.com.cn>
Date: Wed, 30 Nov 2022 16:16:08 +0800

Replace the open-code with sysfs_emit() to simplify the code.

Signed-off-by: ye xingchen <ye.xingchen@zte.com.cn>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-05-18 15:46:33 -04:00
Mark Langsdorf 3bba1ec6d3 ACPI: CPPC: Disable FIE if registers in PCC regions
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2153646

commit ae2df912d1a557a3548be83da20851ac55f42ab3
Author: Jeremy Linton <jeremy.linton@arm.com>
Date:   Mon Sep 12 15:37:22 2022 -0500

PCC regions utilize a mailbox to set/retrieve register values used by
the CPPC code. This is fine as long as the operations are
infrequent. With the FIE code enabled though the overhead can range
from 2-11% of system CPU overhead (ex: as measured by top) on Arm
based machines.

So, before enabling FIE assure none of the registers used by
cppc_get_perf_ctrs() are in the PCC region. Finally, add a module
parameter which can override the PCC region detection at boot or
module reload.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Ionela Voinescu <ionela.voinescu@arm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-02-13 16:25:35 -05:00
Mark Langsdorf 45852ee5a0 ACPI: CPPC: Only probe for _CPC if CPPC v2 is acked
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2164217
Conflicts:
	drivers/acpi/bus.c - minor conflict differences in
removing the osc_sb_cppc_not_supported assignment, but since
upstream completely removed the assignment I did the same.

commit 7feec7430edddb87c24b0a86b08a03d0b496a755
Author: Mario Limonciello <mario.limonciello@amd.com>
Date:   Tue Jul 5 13:29:14 2022 -0500

Previously the kernel used to ignore whether the firmware masked CPPC
or CPPCv2 and would just pretend that it worked.

When support for the USB4 bit in _OSC was introduced from commit
9e1f561afb ("ACPI: Execute platform _OSC also with query bit clear")
the kernel began to look at the return when the query bit was clear.

This caused regressions that were misdiagnosed and attempted to be solved
as part of commit 2ca8e6285250 ("Revert "ACPI: Pass the same capabilities
to the _OSC regardless of the query flag""). This caused a different
regression where non-Intel systems weren't able to negotiate _OSC
properly.

This was reverted in commit 2ca8e6285250 ("Revert "ACPI: Pass the same
capabilities to the _OSC regardless of the query flag"") and attempted to
be fixed by commit c42fa24b4475 ("ACPI: bus: Avoid using CPPC if not
supported by firmware") but the regression still returned.

These systems with the regression only load support for CPPC from an SSDT
dynamically when _OSC reports CPPC v2.  Avoid the problem by not letting
CPPC satisfy the requirement in `acpi_cppc_processor_probe`.

Reported-by: CUI Hao <cuihao.leo@gmail.com>
Reported-by: maxim.novozhilov@gmail.com
Reported-by: lethe.tree@protonmail.com
Reported-by: garystephenwright@gmail.com
Reported-by: galaxyking0419@gmail.com
Fixes: c42fa24b4475 ("ACPI: bus: Avoid using CPPC if not supported by firmware")
Fixes: 2ca8e6285250 ("Revert "ACPI Pass the same capabilities to the _OSC regardless of the query flag"")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=213023
Link: https://bugzilla.redhat.com/show_bug.cgi?id=2075387
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Tested-by: CUI Hao <cuihao.leo@gmail.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-01-28 11:51:28 -05:00
Mark Langsdorf 22e8a0acd4 Revert "ACPI: CPPC: Only probe for _CPC if CPPC v2 is acked"
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2164217
Upstream Status: RHEL Only

This reverts commit 19f75aafa1. The
upstream commit was backported incorrectly and needs to be reapplied.

Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-01-28 11:50:11 -05:00
David Arcari 1d4db43db3 ACPI: CPPC: Add ACPI disabled check to acpi_cpc_valid()
Bugzilla: https://bugzilla.redhat.com/2150425

commit a2a9d1850060e5d995136561d76e81d61414f076
Author: Perry Yuan <Perry.Yuan@amd.com>
Date:   Mon Aug 15 00:35:48 2022 +0800

    ACPI: CPPC: Add ACPI disabled check to acpi_cpc_valid()

    Make acpi_cpc_valid() check if ACPI is disabled, so that its callers
    don't need to check that separately.  This will also cause the AMD
    pstate driver to refuse to load right away when ACPI is disabled.

    Also update the warning message in amd_pstate_init() to mention the
    ACPI disabled case for completeness.

    Signed-off-by: Perry Yuan <Perry.Yuan@amd.com>
    [ rjw: Subject edits, new changelog ]
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2022-12-06 09:02:56 -05:00
Mark Langsdorf be6342ca03 ACPI: CPPC: Do not prevent CPPC from working in the future
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122317

commit 4f4179fcf420873002035cf1941d844c9e0e7cb3
Author: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Date: Thu, 21 Jul 2022 19:41:10 +0200

There is a problem with the current revision checks in
is_cppc_supported() that they essentially prevent the CPPC support
from working if a new _CPC package format revision being a proper
superset of the v3 and only causing _CPC to return a package with more
entries (while retaining the types and meaning of the entries defined by
the v3) is introduced in the future and used by the platform firmware.

In that case, as long as the number of entries in the _CPC return
package is at least CPPC_V3_NUM_ENT, it should be perfectly fine to
use the v3 support code and disregard the additional package entries
added by the new package format revision.

For this reason, drop is_cppc_supported() altogether, put the revision
checks directly into acpi_cppc_processor_probe() so they are easier to
follow and rework them to take the case mentioned above into account.

Fixes: 4773e77cdc ("ACPI / CPPC: Add support for CPPC v3")
Cc: 4.18+ <stable@vger.kernel.org> # 4.18+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-11-01 11:04:40 -04:00
Mark Langsdorf 7024e1b464 ACPI: CPPC: Don't require flexible address space if X86_FEATURE_CPPC is supported
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122317

commit 09073396ea62d0a10b03f5661dcabfd8eca3f098
Author: Mario Limonciello <mario.limonciello@amd.com>
Date: Fri, 15 Jul 2022 12:33:25 -0500

Commit 0651ab90e4ad ("ACPI: CPPC: Check _OSC for flexible address space")
changed _CPC probing to require flexible address space to be negotiated
for CPPC to work.

However it was observed that this caused a regression for Arek's ROG
Zephyrus G15 GA503QM which previously CPPC worked, but now it stopped
working.

To avoid causing a regression waive this failure when the CPU is known
to support CPPC.

Cc: Pierre Gondois <pierre.gondois@arm.com>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=216248
Fixes: 0651ab90e4ad ("ACPI: CPPC: Check _OSC for flexible address space")
Reported-and-tested-by: Arek Ruśniak <arek.rusi@gmail.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-11-01 11:04:40 -04:00
Mark Langsdorf de53e7cb47 ACPI: CPPC: Don't require _OSC if X86_FEATURE_CPPC is supported
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122317

Conflicts:
	arch/x86/kernel/acpi/cppc.c - changes applied
to arch/x86/kernel/acpi/cppc_msr.c as that file has not
been renamed in centos-9

commit 8b356e536e69f3a4d6778ae9f0858a1beadabb1f
Author: Mario Limonciello <mario.limonciello@amd.com>
Date: Tue, 5 Jul 2022 13:29:15 -0500

commit 72f2ecb7ece7 ("ACPI: bus: Set CPPC _OSC bits for all and
when CPPC_LIB is supported") added support for claiming to
support CPPC in _OSC on non-Intel platforms.

This unfortunately caused a regression on a vartiety of AMD
platforms in the field because a number of AMD platforms don't set
the `_OSC` bit 5 or 6 to indicate CPPC or CPPC v2 support.

As these AMD platforms already claim CPPC support via a dedicated
MSR from `X86_FEATURE_CPPC`, use this enable this feature rather
than requiring the `_OSC` on platforms with a dedicated MSR.

If there is additional breakage on the shared memory designs also
missing this _OSC, additional follow up changes may be needed.

Fixes: 72f2ecb7ece7 ("Set CPPC _OSC bits for all and when CPPC_LIB is supported")
Reported-by: Perry Yuan <perry.yuan@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-11-01 11:04:40 -04:00
Mark Langsdorf 12b386d8ae ACPI: CPPC: fix typo in comment
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122317

commit 9e12eb8231496682525b6f9ba04131132d139759
Author: Julia Lawall <Julia.Lawall@inria.fr>
Date: Sat, 21 May 2022 13:10:13 +0200

Spelling mistake (triple letters) in comment.
Detected with the help of Coccinelle.

Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-11-01 11:04:40 -04:00
Mark Langsdorf ae81c25b25 cpufreq: CPPC: Enable fast_switch
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122317

commit 3cc30dd00a580ca0c9c0b01639841cfd72d10129
Author: Pierre Gondois <Pierre.Gondois@arm.com>
Date: Wed, 18 May 2022 11:09:00 +0200

The communication mean of the _CPC desired performance can be
PCC, System Memory, System IO, or Functional Fixed Hardware.

commit b7898fda5b ("cpufreq: Support for fast frequency switching")
fast_switching is 'for switching CPU frequencies from interrupt
context'.
Writes to SystemMemory and SystemIo are fast and suitable this.
This is not the case for PCC and might not be the case for FFH.

Enable fast_switching for the cppc_cpufreq driver in above cases.

Add cppc_allow_fast_switch() to check the desired performance
register address space and set fast_switching accordingly.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-11-01 11:04:40 -04:00
Mark Langsdorf 9742c57ed2 ACPI: CPPC: Assume no transition latency if no PCCT
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122317

commit 6380b7b2b29da9d9c5ab2d4a265901cd93ba3696
Author: Pierre Gondois <Pierre.Gondois@arm.com>
Date: Wed, 18 May 2022 11:08:59 +0200

The transition_delay_us (struct cpufreq_policy) is currently defined
as:
  Preferred average time interval between consecutive invocations of
  the driver to set the frequency for this policy.  To be set by the
  scaling driver (0, which is the default, means no preference).
The transition_latency represents the amount of time necessary for a
CPU to change its frequency.

A PCCT table advertises mutliple values:
- pcc_nominal: Expected latency to process a command, in microseconds
- pcc_mpar: The maximum number of periodic requests that the subspace
  channel can support, reported in commands per minute. 0 indicates no
  limitation.
- pcc_mrtt: The minimum amount of time that OSPM must wait after the
  completion of a command before issuing the next command,
  in microseconds.
cppc_get_transition_latency() allows to get the max of them.

commit d4f3388afd ("cpufreq / CPPC: Set platform specific
transition_delay_us") allows to select transition_delay_us based on
the platform, and fallbacks to cppc_get_transition_latency()
otherwise.

If _CPC objects are not using PCC channels (no PPCT table), the
transition_delay_us is set to CPUFREQ_ETERNAL, leading to really long
periods between frequency updates (~4s).

If the desired_reg, where performance requests are written, is in
SystemMemory or SystemIo ACPI address space, there is no delay
in requests. So return 0 instead of CPUFREQ_ETERNAL, leading to
transition_delay_us being set to LATENCY_MULTIPLIER us (1000 us).

This patch also adds two macros to check the address spaces.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-11-01 11:04:40 -04:00
Mark Langsdorf 79ce2b1d66 ACPI: CPPC: Check _OSC for flexible address space
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122317

Conflicts:
	include/linux/acpi.h - some of the CPPC fix patches have
been applied out of order, so adding osc_cpc_flexible_adr_space_confirmed
did not have the correct context.

commit 0651ab90e4ade17f1d4f4367b70f6120480410f3
Author: Pierre Gondois <pierre.gondois@arm.com>
Date: Wed, 18 May 2022 11:08:57 +0200

ACPI 6.2 Section 6.2.11.2 'Platform-Wide OSPM Capabilities':
  Starting with ACPI Specification 6.2, all _CPC registers can be in
  PCC, System Memory, System IO, or Functional Fixed Hardware address
  spaces. OSPM support for this more flexible register space scheme is
  indicated by the “Flexible Address Space for CPPC Registers” _OSC bit

Otherwise (cf ACPI 6.1, s8.4.7.1.1.X), _CPC registers must be in:
- PCC or Functional Fixed Hardware address space if defined
- SystemMemory address space (NULL register) if not defined

Add the corresponding _OSC bit and check it when parsing _CPC objects.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-11-01 11:04:40 -04:00
Mark Langsdorf 19f75aafa1 ACPI: CPPC: Only probe for _CPC if CPPC v2 is acked
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2067297
Conflicts:
       drivers/acpi/bus.c - We're missing the commit that converts
CONFIG_X86 to CONFIG_ACPI_CPPC_LIB, so fixup failed on the differing
context. Applied the changes by hand, except to change
CONFIG_ACPI_CPPC_LIB back to CONFIG_X86 for consistency.
       include/linux/acpi.h - context differences prevented
fixup from working, so I applied the change by hand.
Previously the kernel used to ignore whether the firmware masked CPPC
or CPPCv2 and would just pretend that it worked.

commit 7feec7430edddb87c24b0a86b08a03d0b496a755
Author: Mario Limonciello <mario.limonciello@amd.com>
Date:   Tue Jul 5 13:29:14 2022 -0500

When support for the USB4 bit in _OSC was introduced from commit
9e1f561afb ("ACPI: Execute platform _OSC also with query bit clear")
the kernel began to look at the return when the query bit was clear.

This caused regressions that were misdiagnosed and attempted to be solved
as part of commit 2ca8e6285250 ("Revert "ACPI: Pass the same capabilities
to the _OSC regardless of the query flag""). This caused a different
regression where non-Intel systems weren't able to negotiate _OSC
properly.

This was reverted in commit 2ca8e6285250 ("Revert "ACPI: Pass the same
capabilities to the _OSC regardless of the query flag"") and attempted to
be fixed by commit c42fa24b4475 ("ACPI: bus: Avoid using CPPC if not
supported by firmware") but the regression still returned.

These systems with the regression only load support for CPPC from an SSDT
dynamically when _OSC reports CPPC v2.  Avoid the problem by not letting
CPPC satisfy the requirement in `acpi_cppc_processor_probe`.

Reported-by: CUI Hao <cuihao.leo@gmail.com>
Reported-by: maxim.novozhilov@gmail.com
Reported-by: lethe.tree@protonmail.com
Reported-by: garystephenwright@gmail.com
Reported-by: galaxyking0419@gmail.com
Fixes: c42fa24b4475 ("ACPI: bus: Avoid using CPPC if not supported by firmware")
Fixes: 2ca8e6285250 ("Revert "ACPI Pass the same capabilities to the _OSC regardless of the query flag"")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=213023
Link: https://bugzilla.redhat.com/show_bug.cgi?id=2075387
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Tested-by: CUI Hao <cuihao.leo@gmail.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-08-01 14:19:24 -04:00
Mark Langsdorf 3b3092ce6a ACPI: CPPC: Change default error code and clean up debug messages in probe
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2067297

commit f21a3509842294565eec63a4332096cccab610ae
Author: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Date: Tue, 22 Mar 2022 17:03:23 +0100

Change the default error code returned by acpi_cppc_processor_probe()
from -EFAULT (which is completely inadequate) to -ENODATA and change
the debug messages printed by it to contain more information and be
more consistent.

While at it, format some white space to follow the coding style.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-08-01 14:19:24 -04:00
Mark Langsdorf 639e99f44c ACPI: CPPC: Avoid out of bounds access when parsing _CPC data
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2067297

commit 40d8abf364bcab23bc715a9221a3c8623956257b
Author: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Date: Tue, 22 Mar 2022 17:02:05 +0100

If the NumEntries field in the _CPC return package is less than 2, do
not attempt to access the "Revision" element of that package, because
it may not be present then.

Fixes: 337aadff8e ("ACPI: Introduce CPU performance controls using CPPC")
BugLink: https://lore.kernel.org/lkml/20220322143534.GC32582@xsang-OptiPlex-9020/
Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-08-01 14:19:24 -04:00
Mark Langsdorf 7e7e534fbe ACPI: bus: Avoid using CPPC if not supported by firmware
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2067297

commit c42fa24b44751c62c86e98430ef915c0609a2ab8
Author: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Date: Wed, 16 Mar 2022 13:39:03 +0100

If the platform firmware indicates that it does not support CPPC by
clearing the OSC_SB_CPC_SUPPORT and OSC_SB_CPCV2_SUPPORT bits in the
platform _OSC capabilities mask, avoid attempting to evaluate _CPC
which may fail in that case.

Because the OSC_SB_CPC_SUPPORT and OSC_SB_CPCV2_SUPPORT bits are only
added to the supported platform capabilities mask on x86, when
X86_FEATURE_HWP is supported, allow _CPC to be evaluated regardless
in the other cases.

Link: https://lore.kernel.org/linux-acpi/CAJZ5v0i=ecAksq0TV+iLVObm-=fUfdqPABzzkgm9K6KxO1ZCcg@mail.gmail.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mario Limonciello <mario.limonciello@amd.com>
Acked-by: Huang Rui <ray.huang@amd.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-08-01 14:19:23 -04:00
Mark Langsdorf ae7721672a x86, ACPI: rename init_freq_invariance_cppc() to arch_init_invariance_cppc()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2067297
Conflicts:
	arch/x86/include/asm/topology.h - fixup failed because of
an extra line in upstream, but the only change was to rename a
function to I renamed the function

commit 1132e6de11cfc334b44f609792664f1bc3055c52
Author: Ionela Voinescu <ionela.voinescu@arm.com>
Date: Thu, 10 Mar 2022 14:54:49 +0000

init_freq_invariance_cppc() was called in acpi_cppc_processor_probe(),
after CPU performance information and controls were populated from the
per-cpu _CPC objects.

But these _CPC objects provide information that helps with both CPU
(u-arch) and frequency invariance. Therefore, change the function name
to a more generic one, while adding the arch_ prefix, as this function
is expected to be defined differently by different architectures.

Signed-off-by: Ionela Voinescu <ionela.voinescu@arm.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-08-01 14:19:23 -04:00
Mark Langsdorf a0306e4503 ACPI: sysfs: use default_groups in kobj_type
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2067294

commit 17f18417d6da07bbaafce84f80fa25d860b6e6d1
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Tue, 28 Dec 2021 14:14:23 +0100

There are currently 2 ways to create a set of sysfs files for a
kobj_type, through the default_attrs field, and the default_groups
field.  Move the ACPI sysfs code to use default_groups field which has
been the preferred way since aa30f47cf6 ("kobject: Add support for
default attribute groups to kobj_type") so that we can soon get rid of
the obsolete default_attrs field.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-06-07 10:50:25 -04:00
Mark Langsdorf 883488e180 mailbox: pcc: Use PCC mailbox channel pointer instead of standard
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1998271

commit 7b6da7fe7bba1cdccdda871bf393b855e59404c3
Author: Sudeep Holla <sudeep.holla@arm.com>
Date:   Fri Sep 17 14:33:50 2021 +0100

Now that we have all the shared memory region information populated in
the pcc_mbox_chan, let us propagate the pointer to the same as the
return value to pcc_mbox_request channel.

This eliminates the need for the individual users of PCC mailbox to
parse the PCCT subspace entries and fetch the shmem information. This
also eliminates the need for PCC mailbox controller to set con_priv to
PCCT subspace entries. This is required as con_priv is private to the
controller driver to attach private data associated with the channel and
not meant to be used by the mailbox client/users.

Let us convert all the users of pcc_mbox_{request,free}_channel to use
new interface.

Cc: Jean Delvare <jdelvare@suse.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Acked-by: Wolfram Sang <wsa@kernel.org>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
(cherry picked from commit 7b6da7fe7bba1cdccdda871bf393b855e59404c3)
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-05-05 14:57:11 -04:00
David Arcari ce8c71f92a ACPI: CPPC: Amend documentation in the comments
Bugzilla: https://bugzilla.redhat.com/1961725

commit 1a901c914dfbee04f20200a116dc9d30679c8cc6
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date:   Wed Dec 22 16:04:45 2021 +0200

    ACPI: CPPC: Amend documentation in the comments

    Currently it's too hard to read the _CPC structure as it's commented.
    Reshuffle indentation and style to make it readable.

    Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2022-03-25 07:48:43 -04:00
David Arcari 7200b5356e ACPI: CPPC: Drop redundant local variable from cpc_read()
Bugzilla: https://bugzilla.redhat.com/1961725

commit f684b10751287e8b7e15e8f10ae40bdd74149bba
Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Date:   Wed Jan 12 19:27:22 2022 +0100

    ACPI: CPPC: Drop redundant local variable from cpc_read()

    The ret_val local variable in cpc_read() is not necessary, so
    eliminate it.

    No functional impact.

    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Acked-by: Huang Rui <ray.huang@amd.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2022-03-24 07:13:06 -04:00
David Arcari 520141053b ACPI: CPPC: Fix up I/O port access in cpc_read()
Bugzilla: https://bugzilla.redhat.com/1961725

commit 5f51c7ce1dc36565296b3ef342585f70ec72a2a9
Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Date:   Wed Jan 12 19:26:32 2022 +0100

    ACPI: CPPC: Fix up I/O port access in cpc_read()

    The code as currently implemented does not work on big endian systems,
    so fix it up.

    Fixes: a2c8f92bea5f ("ACPI: CPPC: Implement support for SystemIO registers")
    Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
    Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
    Link: https://lore.kernel.org/linux-acpi/20220111092928.GA24968@kili/
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Acked-by: Huang Rui <ray.huang@amd.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2022-03-24 07:13:06 -04:00
David Arcari 86611b91c5 ACPI: CPPC: Add CPPC enable register function
Bugzilla: https://bugzilla.redhat.com/1961725

commit fb0b00af04d083770d6e2762b2838357519f7d2d
Author: Jinzhou Su <Jinzhou.Su@amd.com>
Date:   Fri Dec 24 09:04:59 2021 +0800

    ACPI: CPPC: Add CPPC enable register function

    Add a new function to enable CPPC feature. This function
    will write Continuous Performance Control package
    EnableRegister field on the processor.

    CPPC EnableRegister register described in section 8.4.7.1 of ACPI 6.4:
    This element is optional. If supported, contains a resource descriptor
    with a single Register() descriptor that describes a register to which
    OSPM writes a One to enable CPPC on this processor. Before this register
    is set, the processor will be controlled by legacy mechanisms (ACPI
    Pstates, firmware, etc.).

    This register will be used for AMD processors to enable AMD P-State
    function instead of legacy ACPI P-States.

    Signed-off-by: Jinzhou Su <Jinzhou.Su@amd.com>
    Signed-off-by: Huang Rui <ray.huang@amd.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2022-03-16 10:48:17 -04:00
David Arcari 2ac9d663a5 ACPI: CPPC: Check present CPUs for determining _CPC is valid
Bugzilla: https://bugzilla.redhat.com/1961725

commit 2aeca6bd02776d7f56a49a32be0dd184f204d888
Author: Mario Limonciello <mario.limonciello@amd.com>
Date:   Fri Dec 24 09:04:58 2021 +0800

    ACPI: CPPC: Check present CPUs for determining _CPC is valid

    As this is a static check, it should be based upon what is currently
    present on the system. This makes probeing more deterministic.

    While local APIC flags field (lapic_flags) of cpu core in MADT table is
    0, then the cpu core won't be enabled. In this case, _CPC won't be found
    in this core, and return back to _CPC invalid with walking through
    possible cpus (include disable cpus). This is not expected, so switch to
    check present CPUs instead.

    Reported-by: Jinzhou Su <Jinzhou.Su@amd.com>
    Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
    Signed-off-by: Huang Rui <ray.huang@amd.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2022-03-16 10:48:13 -04:00
David Arcari f404eea663 ACPI: CPPC: Implement support for SystemIO registers
Bugzilla: https://bugzilla.redhat.com/1961725

commit a2c8f92bea5f8f1a87fc3caf063d67876dbf5d47
Author: Steven Noonan <steven@valvesoftware.com>
Date:   Fri Dec 24 09:04:57 2021 +0800

    ACPI: CPPC: Implement support for SystemIO registers

    According to the ACPI v6.2 (and later) specification, SystemIO can be
    used for _CPC registers. This teaches cppc_acpi how to handle such
    registers.

    This patch was tested using the amd_pstate driver on my Zephyrus G15
    (model GA503QS) using the current version 410 BIOS, which uses
    a SystemIO register for the HighestPerformance element in _CPC.

    Signed-off-by: Steven Noonan <steven@valvesoftware.com>
    Signed-off-by: Huang Rui <ray.huang@amd.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2022-03-16 10:21:58 -04:00
David Arcari b093b02e74 ACPI: CPPC: Add NULL pointer check to cppc_get_perf()
Bugzilla: http://bugzilla.redhat.com/2025291

commit 935dff305da2be7957a5ce8f07f45d6c4c1c6984
Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Date:   Thu Nov 18 14:37:38 2021 +0100

    ACPI: CPPC: Add NULL pointer check to cppc_get_perf()

    Check cpc_desc against NULL in cppc_get_perf(), so it doesn't crash
    down the road if cpc_desc is NULL.

    Fixes: 0654cf05d17b ("ACPI: CPPC: Introduce cppc_get_nominal_perf()")
    Reported-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Cc: 5.15+ <stable@vger.kernel.org> # 5.15+
    Tested-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2021-11-29 14:41:29 -05:00
David Arcari 20f474f47f ACPI: CPPC: Introduce cppc_get_nominal_perf()
Bugzilla: http://bugzilla.redhat.com/2025291

commit 0654cf05d17bc4d296a53a8bc7d107bc8a795f2e
Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Date:   Sat Sep 4 15:51:45 2021 +0200

    ACPI: CPPC: Introduce cppc_get_nominal_perf()

    On some systems the nominal_perf value retrieved via CPPC is just
    a constant and fetching it doesn't require accessing any registers,
    so if it is the only CPPC capability that's needed, it is wasteful
    to run cppc_get_perf_caps() in order to get just that value alone,
    especially when this is done for CPUs other than the one running
    the code.

    For this reason, introduce cppc_get_nominal_perf() allowing
    nominal_perf to be obtained individually, by generalizing the
    existing cppc_get_desired_perf() (and renaming it) so it can be
    used to retrieve any specific CPPC capability value.

    While at it, clean up the cppc_get_desired_perf() kerneldoc comment
    a bit.

    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2021-11-21 10:22:32 -05:00
Rafael J. Wysocki b6237f61fc Merge branch 'acpi-misc'
* acpi-misc:
  ACPI: dock: fix some coding style issues
  ACPI: sysfs: fix some coding style issues
  ACPI: PM: add a missed blank line after declarations
  ACPI: custom_method: fix a coding style issue
  ACPI: CPPC: fix some coding style issues
  ACPI: button: fix some coding style issues
  ACPI: battery: fix some coding style issues
  ACPI: acpi_pad: add a missed blank line after declarations
  ACPI: LPSS: add a missed blank line after declarations
  ACPI: ipmi: remove useless return statement for void function
  ACPI: processor: fix some coding style issues
  ACPI: APD: fix a block comment align issue
  ACPI: AC: fix some coding style issues
  ACPI: fix various typos in comments
2021-04-26 17:04:41 +02:00
Nathan Chancellor 2bc6262c61 ACPI: CPPC: Replace cppc_attr with kobj_attribute
All of the CPPC sysfs show functions are called via indirect call in
kobj_attr_show(), where they should be of type

ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr, char *buf);

because that is the type of the ->show() member in
'struct kobj_attribute' but they are actually of type

ssize_t (*show)(struct kobject *kobj, struct attribute *attr, char *buf);

because of the ->show() member in 'struct cppc_attr', resulting in a
Control Flow Integrity violation [1].

$ cat /sys/devices/system/cpu/cpu0/acpi_cppc/highest_perf
3400

$ dmesg | grep "CFI failure"
[  175.970559] CFI failure (target: show_highest_perf+0x0/0x8):

As far as I can tell, the only difference between 'struct cppc_attr'
and 'struct kobj_attribute' aside from the type of the attr parameter
is the type of the count parameter in the ->store() member (ssize_t vs.
size_t), which does not actually matter because all of these nodes are
read-only.

Eliminate 'struct cppc_attr' in favor of 'struct kobj_attribute' to fix
the violation.

[1]: https://lore.kernel.org/r/20210401233216.2540591-1-samitolvanen@google.com/

Fixes: 158c998ea4 ("ACPI / CPPC: add sysfs support to compute delivered performance")
Link: https://github.com/ClangBuiltLinux/linux/issues/1343
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2021-04-08 19:58:12 +02:00
Xiaofei Tan e69ae67587 ACPI: CPPC: fix some coding style issues
Fix some coding style issues reported by checkpatch.pl, including the
following types:

WARNING: Missing a blank line after declarations
WARNING: unnecessary whitespace before a quoted newline
ERROR: spaces required around that '>='
ERROR: switch and case should be at the same indent

Signed-off-by: Xiaofei Tan <tanxiaofei@huawei.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2021-04-08 16:27:02 +02:00
Rafael J. Wysocki 8a02d99876 ACPI: CPPC: Add emtpy stubs of functions for CONFIG_ACPI_CPPC_LIB unset
For convenience, add empty stubs of library functions defined in
cppc_acpi.c for the CONFIG_ACPI_CPPC_LIB unset case.

Because one of them needs to return CPUFREQ_ETERNAL, include
linux/cpufreq.h into the CPPC library header file and drop the
direct inclusion of it from cppc_acpi.c.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Chen Yu <yu.c.chen@intel.com>
2021-03-23 19:44:17 +01:00