Commit graph

238 commits

Author SHA1 Message Date
Linus Torvalds
3062a9879a ACPI fix for 6.7-rc1
Fix the acpi_thermal_add() error path that may do a double-free
 in some cases after recent changes (Dan Carpenter).
 -----BEGIN PGP SIGNATURE-----
 
 iQJGBAABCAAwFiEE4fcc61cGeeHD/fCwgsRv/nhiVHEFAmVFBpgSHHJqd0Byand5
 c29ja2kubmV0AAoJEILEb/54YlRx7y4P/j8xXFy5HbP+Qd5qNGTNPhmdhpC0OB72
 cqbWujNv0EK6OhryK54qI5gh4z7NoX7QBb6vmGPHNsKCtPdrOY/+IU1YfYAx6o6W
 00jcDr08iPqr1CNxpwn+4OSCH6cJualQCAtD+7MGmFwh2OlH0GsohlZEeti0bzt7
 +2uEK1M7zGP7K0UBGeNs/epynWlikmgDX8g6rxFbjtyyTdbWwvi7Vkq9WV+09MUj
 lMirq3Pmzc9kesoGEFJXSySugfGL1YWwDme8xOX9cjsIcX32KbcutbH7sMqBWiB9
 nQePTF/S1gXbcQ+pXrO/KJnueOOkMgPBiqahAEVNSjfgd/KbscLaWAlMGfSzyvqo
 UCWu2jN2WdnRv7B+RS3SAVejTBR4OYjHAHkTRIk+0JvbzD4tNaVdbK0zp2zxVphh
 tNB2hbD3mJA5DMbqP9nbcUvkWoYcwLFUgTGKyAzp4fKSq7ct+80ove8D5eJOf94Z
 YLgiMDpPjLYxboPz5JiwNk70CHQkqiMF9hQVYHmHfAPO36lcoo8zcu5vnmJaKUAz
 HdrGksgs5quuYZfRYexaSB5995nr7E72g5HBkCCu4t0vTGoJ5fN8c8cepRGSWCKp
 WNmPR/DGrc4y1CcJo4MnPvAMvCcExhgbpD++rLBew5AD4q663bkzB9FPghqehHIr
 nFAtlS4l57WE
 =LLgE
 -----END PGP SIGNATURE-----

Merge tag 'acpi-6.7-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm

Pull ACPI fix from Rafael Wysocki:
 "Fix the acpi_thermal_add() error path that may do a double-free in
  some cases after recent changes (Dan Carpenter)"

* tag 'acpi-6.7-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm:
  ACPI: thermal: Fix acpi_thermal_unregister_thermal_zone() cleanup
2023-11-04 07:54:21 -10:00
Linus Torvalds
d4b671d4c6 ACPI updates for 6.7-rc1
- Add symbol definitions related to CDAT to the ACPICA code (Dave
    Jiang).
 
  - Use the acpi_device_is_present() helper in more places and rename
    acpi_scan_device_not_present() to be about enumeration (James Morse).
 
  - Add __printf format attribute to acpi_os_vprintf() (Su Hui).
 
  - Clean up departures from kernel coding style in the low-level
    interface for ACPICA (Jonathan Bergh).
 
  - Replace strncpy() with strscpy() in acpi_osi_setup() (Justin Stitt).
 
  - Fail FPDT parsing on zero length records and add proper handling for
    fpdt_process_subtable() to acpi_init_fpdt() (Vasily Khoruzhick).
 
  - Rework acpi_handle_list handling so as to manage it dynamically,
    including size computation (Rafael Wysocki).
 
  - Clean up ACPI utilities code so as to make it follow the kernel
    coding style (Jonathan Bergh).
 
  - Consolidate IRQ trigger-type override DMI tables and drop .ident
    values from dmi_system_id tables used for ACPI resources management
    quirks (Hans de Goede).
 
  - Add ACPI IRQ override for TongFang GMxXGxx (Werner Sembach).
 
  - Allow _DSD buffer data only for byte accessors and document the _DSD
    data buffer GUID (Andy Shevchenko).
 
  - Drop BayTrail and Lynxpoint pinctrl device IDs from the ACPI LPSS
    driver, because it does not need them (Raag Jadav).
 
  - Add acpi_backlight=vendor quirk for Toshiba Portégé R100 (Ondrej
    Zary).
 
  - Add "vendor" backlight quirks for 3 Lenovo x86 Android tablets (Hans
    de Goede).
 
  - Move Xiaomi Mi Pad 2 backlight quirk to its own section (Hans de
    Goede).
 
  - Annotate struct prm_module_info with __counted_by (Kees Cook).
 
  - Fix AER info corruption in aer_recover_queue() when error status data
    has multiple sections (Shiju Jose).
 
  - Make APEI use ERST maximum execution time for slow devices (Jeshua
    Smith).
 
  - Add support for platform notification handling to the PCC mailbox
    driver and modify it to support shared interrupts for multiple
    subspaces (Huisong Li).
 
  - Define common macros to use when referring to various bitfields in the
    PCC generic communications channel command and status fields and use
    them in some drivers (Sudeep Holla).
 
  - Add EC GPE detection quirk for HP 250 G7 Notebook PC (Jonathan
    Denose).
 
  - Fix and clean up create_pnp_modalias() and create_of_modalias()
    (Christophe JAILLET).
 
  - Modify 2 pieces of code to use acpi_evaluate_dsm_typed() (Andy
    Shevchenko).
 
  - Define acpi_dev_uid_match() for matching _UID and use it in several
    places (Raag Jadav).
 
  - Use acpi_device_uid() for fetching _UID in 2 places (Raag Jadav).
 
  - Add context argument to acpi_dev_install_notify_handler() (Rafael
    Wysocki).
 
  - Clarify ACPI bus concepts in the ACPI device enumeration
    documentation (Rafael Wysocki).
 
  - Switch over the ACPI AC and ACPI PAD drivers to using the platform
    driver interface which, is more logically consistent than binding a
    driver directly to an ACPI device object, and clean them up (Michal
    Wilczynski).
 
  - Replace strncpy() in the PNP code with either memcpy() or strscpy()
    as appropriate (Justin Stitt).
 
  - Clean up coding style in pnp.h (GuoHua Cheng).
 -----BEGIN PGP SIGNATURE-----
 
 iQJGBAABCAAwFiEE4fcc61cGeeHD/fCwgsRv/nhiVHEFAmU6bTISHHJqd0Byand5
 c29ja2kubmV0AAoJEILEb/54YlRxQ4AQALW9JR9te3ohnm77rpoODP5UQlfJwTYw
 xppbSqfVfJbckqJArbjWXCmv1vUHLth/q8Ojd7+shkAQ4nU9v91gWKXkG/pXFnHa
 PcIT8OAwverqI0fVomxSipQS/tiA0HMLz9uUa62yjRXagyvuQW0xfhToe0NU9BBx
 kEXLOMztpsgfzxZtxmTcYgkzDW8/87FVR9PuBAa+vf4p46QoYAS+AXhXUlYT3guA
 VRT54cwyaNxKa4PecoIcr3FvabCrtKCyNvZrKf6/xxM3XepWp7pW8RINwNy6B+lZ
 X/dDLHf0XVN2h21GydfB/StPNssSIjpZZUOrJ5kv+VnOBeRTLt8kPKFdo3ZiqjT8
 VUTq4aj4qmJO6A8K32bxFs7Bb/tWVviIKX2O+EVPjNSUHu0yMG5UbkcR03yRXvdy
 L6cijuXZwCvSsPiOTGXRya3Ea1yGNgPEf3iAaFPMUjE064KjZb6+emtPk1JeYzDg
 qGRhuwD0wuckSAUkpB3SNoWqD2fTEaRSWCCivakRbCCp0mG6QWvDT2JBlx/YRKqq
 Wxg+oYXE2PJTuVc1DF1xUW7K45h9l0DhIejFKqm4cibfMdkA+MQI24frX5Dvj8hy
 RW3IKGrqsgARC6oVf6oWQodrp9zxAn1XEHE43sppPvgh4tcJqxy/0Aqti+XeONQp
 7/niL9+zn7FM
 =p4Yo
 -----END PGP SIGNATURE-----

Merge tag 'acpi-6.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm

Pull ACPI updates from Rafael Wysocki:
 "These fix issues, add new quirks, rearrange the IRQ override quirk
  definitions, add new helpers and switch over code to using them,
  rework a couple of interfaces to be more flexible, eliminate strncpy()
  usage from PNP, extend the ACPI PCC mailbox driver and clean up code.

  This is based on ACPI thermal driver changes that are present in the
  thermal control updates for 6.7-rc1 pull request (they are depended on
  by the ACPI utilities updates). However, the ACPI thermal driver
  changes are not included in the list of specific ACPI changes below.

  Specifics:

   - Add symbol definitions related to CDAT to the ACPICA code (Dave
     Jiang)

   - Use the acpi_device_is_present() helper in more places and rename
     acpi_scan_device_not_present() to be about enumeration (James
     Morse)

   - Add __printf format attribute to acpi_os_vprintf() (Su Hui)

   - Clean up departures from kernel coding style in the low-level
     interface for ACPICA (Jonathan Bergh)

   - Replace strncpy() with strscpy() in acpi_osi_setup() (Justin Stitt)

   - Fail FPDT parsing on zero length records and add proper handling
     for fpdt_process_subtable() to acpi_init_fpdt() (Vasily Khoruzhick)

   - Rework acpi_handle_list handling so as to manage it dynamically,
     including size computation (Rafael Wysocki)

   - Clean up ACPI utilities code so as to make it follow the kernel
     coding style (Jonathan Bergh)

   - Consolidate IRQ trigger-type override DMI tables and drop .ident
     values from dmi_system_id tables used for ACPI resources management
     quirks (Hans de Goede)

   - Add ACPI IRQ override for TongFang GMxXGxx (Werner Sembach)

   - Allow _DSD buffer data only for byte accessors and document the
     _DSD data buffer GUID (Andy Shevchenko)

   - Drop BayTrail and Lynxpoint pinctrl device IDs from the ACPI LPSS
     driver, because it does not need them (Raag Jadav)

   - Add acpi_backlight=vendor quirk for Toshiba Portégé R100 (Ondrej
     Zary)

   - Add "vendor" backlight quirks for 3 Lenovo x86 Android tablets
     (Hans de Goede)

   - Move Xiaomi Mi Pad 2 backlight quirk to its own section (Hans de
     Goede)

   - Annotate struct prm_module_info with __counted_by (Kees Cook)

   - Fix AER info corruption in aer_recover_queue() when error status
     data has multiple sections (Shiju Jose)

   - Make APEI use ERST maximum execution time for slow devices (Jeshua
     Smith)

   - Add support for platform notification handling to the PCC mailbox
     driver and modify it to support shared interrupts for multiple
     subspaces (Huisong Li)

   - Define common macros to use when referring to various bitfields in
     the PCC generic communications channel command and status fields
     and use them in some drivers (Sudeep Holla)

   - Add EC GPE detection quirk for HP 250 G7 Notebook PC (Jonathan
     Denose)

   - Fix and clean up create_pnp_modalias() and create_of_modalias()
     (Christophe JAILLET)

   - Modify 2 pieces of code to use acpi_evaluate_dsm_typed() (Andy
     Shevchenko)

   - Define acpi_dev_uid_match() for matching _UID and use it in several
     places (Raag Jadav)

   - Use acpi_device_uid() for fetching _UID in 2 places (Raag Jadav)

   - Add context argument to acpi_dev_install_notify_handler() (Rafael
     Wysocki)

   - Clarify ACPI bus concepts in the ACPI device enumeration
     documentation (Rafael Wysocki)

   - Switch over the ACPI AC and ACPI PAD drivers to using the platform
     driver interface which, is more logically consistent than binding a
     driver directly to an ACPI device object, and clean them up (Michal
     Wilczynski)

   - Replace strncpy() in the PNP code with either memcpy() or strscpy()
     as appropriate (Justin Stitt)

   - Clean up coding style in pnp.h (GuoHua Cheng)"

* tag 'acpi-6.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (54 commits)
  ACPI: resource: Do IRQ override on TongFang GMxXGxx
  perf: arm_cspmu: use acpi_dev_hid_uid_match() for matching _HID and _UID
  ACPI: EC: Add quirk for HP 250 G7 Notebook PC
  ACPI: x86: use acpi_dev_uid_match() for matching _UID
  ACPI: utils: use acpi_dev_uid_match() for matching _UID
  pinctrl: intel: use acpi_dev_uid_match() for matching _UID
  ACPI: utils: Introduce acpi_dev_uid_match() for matching _UID
  ACPI: sysfs: Clean up create_pnp_modalias() and create_of_modalias()
  ACPI: sysfs: Fix create_pnp_modalias() and create_of_modalias()
  ACPI: acpi_pad: Rename ACPI device from device to adev
  ACPI: acpi_pad: Use dev groups for sysfs
  ACPI: acpi_pad: Replace acpi_driver with platform_driver
  ACPI: APEI: Use ERST timeout for slow devices
  ACPI: scan: Rename acpi_scan_device_not_present() to be about enumeration
  PNP: replace deprecated strncpy() with memcpy()
  PNP: ACPI: replace deprecated strncpy() with strscpy()
  perf: qcom: use acpi_device_uid() for fetching _UID
  ACPI: sysfs: use acpi_device_uid() for fetching _UID
  ACPI: scan: Use the acpi_device_is_present() helper in more places
  ACPI: AC: Rename ACPI device from device to adev
  ...
2023-10-31 15:33:26 -10:00
Dan Carpenter
4b27d5c420 ACPI: thermal: Fix acpi_thermal_unregister_thermal_zone() cleanup
The acpi_thermal_unregister_thermal_zone() is paired with
acpi_thermal_register_thermal_zone() so it should mirror it.  It should
clean up all the resources that the register function allocated and
leave the stuff that was allocated elsewhere.

Unfortunately, it doesn't call thermal_zone_device_disable().  Also it
calls kfree(tz->trip_table) when it shouldn't.  That was allocated in
acpi_thermal_add().  Putting the kfree() here leads to a double free
in the acpi_thermal_add() clean up function.

Likewise, the acpi_thermal_remove() should mirror acpi_thermal_add() so
it should have an explicit kfree(tz->trip_table) as well.

Fixes: ec23c1c462 ("ACPI: thermal: Use trip point table to register thermal zones")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-10-31 17:50:00 +01:00
Rafael J. Wysocki
3660e641ef Merge branch 'acpi-bus'
Merge ACPI bus type driver updates for 6.7-rc1:

 - Add context argument to acpi_dev_install_notify_handler() (Rafael
   Wysocki).

 - Clarify ACPI bus concepts in the ACPI device enumeration
   documentation (Rafael Wysocki).

* acpi-bus:
  ACPI: bus: Add context argument to acpi_dev_install_notify_handler()
  ACPI: docs: enumeration: Clarify ACPI bus concepts
2023-10-26 15:04:49 +02:00
Rafael J. Wysocki
470508f63a ACPI: bus: Add context argument to acpi_dev_install_notify_handler()
Add void *context arrgument to the list of arguments of
acpi_dev_install_notify_handler() and modify it to pass that argument
as context to acpi_install_notify_handler() instead of its first
argument which is problematic in general (for example, if platform
drivers used it, they would rather get struct platform_device pointers
or pointers to their private data from the context arguments of their
notify handlers).

Make all of the current callers of acpi_dev_install_notify_handler()
take this change into account so as to avoid altering the general
functionality.

Co-developed-by: Michal Wilczynski <michal.wilczynski@intel.com>
Signed-off-by: Michal Wilczynski <michal.wilczynski@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-10-06 17:32:51 +02:00
Rafael J. Wysocki
b251ab28ca ACPI: thermal: Use thermal_zone_for_each_trip() for updating trips
Rearrange the code handling notifications from the platform firmware
regarding trip point updates to carry out one loop over trip points
instead of two of them by using thermal_zone_for_each_trip() for that,
which is more straightforward than using a combination of
thermal_zone_device_exec() and for_each_thermal_trip(), each with its
own callback function.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-10-05 13:32:35 +02:00
Rafael J. Wysocki
4f9cf91e41 ACPI: thermal: Combine passive and active trip update functions
Combine acpi_thermal_update_passive_trip() and
acpi_thermal_update_active_trip() into one common function called
acpi_thermal_update_trip(), so as to reduce code duplication and
prepare the code in question for subsequent changes.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-10-05 13:20:57 +02:00
Rafael J. Wysocki
44babd829a ACPI: thermal: Move get_active_temp()
Put the get_active_temp() function next to the analogous
get_passive_temp() one to allow subsequent changes to be easier to
follow.

No functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-10-05 13:20:57 +02:00
Jonathan Bergh
1dd72ce0c1 ACPI: thermal: Fix up function header formatting in two places
Fix up the following formatting issues:
 * braces following function declarations should be on a new line
 * empty line should be present between function declarations

Signed-off-by: Jonathan Bergh <bergh.jonathan@gmail.com>
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-10-03 20:55:22 +02:00
Rafael J. Wysocki
c676733418 ACPI: thermal: Drop list of device ACPI handles from struct acpi_thermal
Notice that the list of device ACPI handles in struct acpi_thermal is not
used and drop it.

No functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-29 12:43:34 +02:00
Rafael J. Wysocki
2e57d10a65 ACPI: utils: Dynamically determine acpi_handle_list size
Address a long-standing "TBD" comment in the ACPI headers regarding the
number of handles in struct acpi_handle_list.

The number 10, which along with the comment dates back to 2.4.23, seems
like it may have been arbitrarily chosen and isn't sufficient in all
cases [1].

Finally change the code to dynamically determine the size of the handles
table in struct acpi_handle_list and allocate it accordingly.

Update the users of to struct acpi_handle_list to take the additional
dynamic allocation into account.

Link: https://lore.kernel.org/linux-acpi/20230809094451.15473-1-ivan.hu@canonical.com # [1]
Co-developed-by: Vicki Pfau <vi@endrift.com>
Signed-off-by: Vicki Pfau <vi@endrift.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-09-29 12:40:35 +02:00
Rafael J. Wysocki
03a6d5986c ACPI: thermal: Rename structure fields holding temperature in deci-Kelvin
Rename structure fields holding temperature values in deci-Kelvin so as
to avoid temperature units confusion.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-28 19:27:19 +02:00
Rafael J. Wysocki
c8f46f43a1 ACPI: thermal: Drop critical_valid and hot_valid trip flags
The critical_valid and hot_valid flags in struct acpi_thermal_trips are
only used during initialization and they are only false if the
corresponding trip temperatures are equal to THERMAL_TEMP_INVALID, so
drop them and use THERMAL_TEMP_INVALID checks instead of them where
applicable.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-28 19:27:19 +02:00
Rafael J. Wysocki
d5ea889246 ACPI: thermal: Do not use trip indices for cooling device binding
Rearrange the ACPI thermal driver's callback functions used for cooling
device binding and unbinding, acpi_thermal_bind_cooling_device() and
acpi_thermal_unbind_cooling_device(), respectively, so that they use trip
pointers instead of trip indices which is more straightforward and allows
the driver to become independent of the ordering of trips in the thermal
zone structure.

The general functionality is not expected to be changed.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-28 19:27:19 +02:00
Rafael J. Wysocki
2713b83cb3 ACPI: thermal: Mark uninitialized active trips as invalid
After removing the valid flag from struct acpi_thermal_trip, the trip
temperature value is used in validity checks, so it must be
THERMAL_TEMP_INVALID for the active trip entries in struct acpi_thermal_trips
that are not going to be used (because the corresponding objects are not
present in the ACPI tables, for example).

Accordingly, modify acpi_thermal_get_trip_points() to set the temperature
value to THERMAL_TEMP_INVALID for trip point entries skipped by it after
acpi_thermal_init_trip() has returned 'false' for an active trip.

Fixes: 058f5e407d ("ACPI: thermal: Drop valid flag from struct acpi_thermal_trip")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-09-28 19:06:36 +02:00
Rafael J. Wysocki
3e7d6f396d ACPI: thermal: Merge trip initialization functions
In order to reduce code duplicationeve further, merge
acpi_thermal_init_passive/active_trip() into one function called
acpi_thermal_init_trip() that will be used for initializing both
the passive and active trip points.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-28 12:54:16 +02:00
Rafael J. Wysocki
54fc61a106 ACPI: thermal: Collapse trip devices update function wrappers
In order to reduce code duplicationeve further, merge
acpi_thermal_update_passive/active_devices() into one function
called acpi_thermal_update_trip_devices() that will be used for
updating both the passive and active trip points.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-28 12:54:16 +02:00
Rafael J. Wysocki
317508c65f ACPI: thermal: Collapse trip devices update functions
In order to reduce code duplication, merge update_passive_devices() and
update_active_devices() into one function called update_trip_devices()
that will be used for updating both the passive and active trip points.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-28 12:54:16 +02:00
Rafael J. Wysocki
0fa1bf3498 ACPI: thermal: Add device list to struct acpi_thermal_trip
The device lists present in struct acpi_thermal_passive and struct
acpi_thermal_active can be located in struct acpi_thermal_trip which
then will allow the same code to be used for handling both the passive
and active trip points, so make that change.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-28 12:54:16 +02:00
Dan Carpenter
0d9741abd1 ACPI: thermal: Fix a small leak in acpi_thermal_add()
Free "tz" if the "trip" allocation fails.

Fixes: 5fc2189f9335 ("ACPI: thermal: Create and populate trip points table earlier")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-09-27 14:58:14 +02:00
Rafael J. Wysocki
058f5e407d ACPI: thermal: Drop valid flag from struct acpi_thermal_trip
Notice that the valid flag in struct acpi_thermal_trip is in fact
redundant, because the temperature field of invalid trips is always
equal to THERMAL_TEMP_INVALID, so drop it from there and adjust the
code accordingly.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-26 17:58:59 +02:00
Rafael J. Wysocki
4175a24f01 ACPI: thermal: Drop redundant trip point flags
Trip point flags previously used by the driver need not be used any more
after the preceding changes, so drop them and adjust the code accordingly.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-26 17:58:34 +02:00
Rafael J. Wysocki
cdfe09df04 ACPI: thermal: Untangle initialization and updates of active trips
Separate the code needed to update active trips (in a response to a
notification from the platform firmware) as well as to initialize them
from the code that is only necessary for their initialization and
cleanly divide it into functions that each carry out a specific action.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-26 17:58:03 +02:00
Rafael J. Wysocki
64c512edf9 ACPI: thermal: Untangle initialization and updates of the passive trip
Separate the code needed to update the passive trip (in a response to a
notification from the platform firmware) as well as to initialize it
from the code that is only necessary for its initialization and cleanly
divide it into functions that each carry out a specific action.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-26 17:57:45 +02:00
Rafael J. Wysocki
30f04c7535 ACPI: thermal: Simplify critical and hot trips representation
Notice that the only piece of information regarding the critical and hot
trips that needs to be stored in the driver's local data structures is
whether or not these trips are valid, so drop all of the redundant
information from there and adjust the code accordingly.

Among other things, this requires acpi_thermal_add() to be rearranged
so as to obtain the critical trip temperature before populating the trip
points table and for symmetry, the hot trip temperature is obtained
earlier too.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-26 17:57:28 +02:00
Rafael J. Wysocki
06a5f76ee1 ACPI: thermal: Create and populate trip points table earlier
Create and populate the driver's trip points table in acpi_thermal_add()
so as to allow the its data structures to be simplified going forward.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-26 17:57:10 +02:00
Rafael J. Wysocki
f04256a8f7 ACPI: thermal: Determine the number of trip points earlier
Compute the number of trip points in acpi_thermal_add() so as to allow the
driver's data structures to be simplified going forward.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-26 17:56:53 +02:00
Rafael J. Wysocki
b09872a652 ACPI: thermal: Fold acpi_thermal_get_info() into its caller
There is only one caller of acpi_thermal_get_info() and the code from
it can be folded into its caller just fine, so do that.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-26 17:56:35 +02:00
Rafael J. Wysocki
4be32333d9 ACPI: thermal: Simplify initialization of critical and hot trips
Use the observation that the critical and hot trip points are never
updated by the ACPI thermal driver, because the flags passed from
acpi_thermal_notify() to acpi_thermal_trips_update() do not include
ACPI_TRIPS_CRITICAL or ACPI_TRIPS_HOT, to move the initialization
of those trip points directly into acpi_thermal_get_trip_points() and
reduce the size of __acpi_thermal_trips_update().

Also make the critical and hot trip points initialization code more
straightforward and drop the flags that are not needed any more.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-09-26 17:56:12 +02:00
Rafael J. Wysocki
ebc7abb35b thermal: Constify the trip argument of the .get_trend() zone callback
Add 'const' to the definition of the 'trip' argument of the
.get_trend() thermal zone callback to indicate that the trip point
passed to it should not be modified by it and adjust the
callback functions implementing it, thermal_get_trend() in the
ACPI thermal driver and __ti_thermal_get_trend(), accordingly.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Michal Wilczynski <michal.wilczynski@intel.com>
2023-09-11 17:16:40 +02:00
Rafael J. Wysocki
8289d810ea thermal: core: Rework .get_trend() thermal zone callback
Passing a struct thermal_trip pointer instead of a trip index to the
.get_trend() thermal zone callback allows one of its 2 implementations,
the thermal_get_trend() function in the ACPI thermal driver, to be
simplified quite a bit, and the other implementation of it in the
ti-soc-thermal driver does not even use the relevant callback argument.

For this reason, change the .get_trend() thermal zone callback
definition and adjust the related code accordingly.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-08-29 20:48:35 +02:00
Rafael J. Wysocki
4ab4b3b11d ACPI: thermal: Eliminate code duplication from acpi_thermal_notify()
Move the acpi_bus_generate_netlink_event() invocation into
acpi_thermal_trips_update() which allows the code duplication in
acpi_thermal_notify() to be cleaned up, but for this purpose the
event value needs to be passed to acpi_thermal_trips_update() and
from there to acpi_thermal_adjust_thermal_zone() which has to
determine the flag value for __acpi_thermal_trips_update() by
itself.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-08-17 11:25:29 +02:00
Rafael J. Wysocki
2a74c4aca1 ACPI: thermal: Drop unnecessary thermal zone callbacks
Drop the .get_trip_type(), .get_trip_temp() and .get_crit_temp() thermal
zone callbacks that are not necessary any more from the ACPI thermal
driver along with the corresponding callback functions.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-08-17 11:25:22 +02:00
Rafael J. Wysocki
9caaad2ca0 ACPI: thermal: Rework thermal_get_trend()
Rework the ACPI thermal driver's .get_trend() callback function,
thermal_get_trend(), so that it does not call thermal_get_trip_type()
and thermal_get_trip_temp() which are going to be dropped.

This reduces the overhead of the function too, because it will always
carry out a trip point lookup once after the change.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-08-17 11:25:22 +02:00
Rafael J. Wysocki
ec23c1c462 ACPI: thermal: Use trip point table to register thermal zones
Make the ACPI thermal driver use thermal_zone_device_register_with_trips()
to register its thermal zones.

For this purpose, make it create a trip point table that will be passed to
thermal_zone_device_register_with_trips() as an argument.

Also use the thermal_zone_update_trip_temp() helper introduced
previously to update temperatures of the passive and active trip
points after a trip points change notification from the platform
firmware.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-08-17 11:25:22 +02:00
Rafael J. Wysocki
68b77785a1 ACPI: thermal: Introduce struct acpi_thermal_trip
Add struct acpi_thermal_trip to contain the temperature and valid flag
of each trip point in the driver's local data structures.

This helps to make the subsequent changes more straightforward.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-08-17 11:25:22 +02:00
Rafael J. Wysocki
68f4f0378c ACPI: thermal: Carry out trip point updates under zone lock
There is a race condition between acpi_thermal_trips_update() and
acpi_thermal_check_fn(), because the trip points may get updated while
the latter is running which in theory may lead to inconsistent results.
For example, if two trips are updated together, using the temperature
value of one of them from before the update and the temperature value
of the other one from after the update may not lead to the expected
outcome.

Moreover, if thermal_get_trend() runs when a trip points update is in
progress, it may end up using stale trip point temperatures.

To address this, make acpi_thermal_trips_update() call
thermal_zone_device_exec() to carry out the trip points update and
use a new  acpi_thermal_adjust_thermal_zone() wrapper around
__acpi_thermal_trips_update() as the callback function for the latter.

While at it, change the acpi_thermal_trips_update() return data type
to void as that function always returns 0 anyway.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-08-17 11:24:27 +02:00
Rafael J. Wysocki
bf07b4a3ba ACPI: thermal: Clean up acpi_thermal_register_thermal_zone()
Rename the trips variable in acpi_thermal_register_thermal_zone() to
trip_count so its name better reflects the purpose, rearrange white
space in the loop over active trips for clarity and reduce code
duplication related to calling thermal_zone_device_register() by
using an extra local variable to store the passive delay value.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-08-17 11:24:18 +02:00
Rafael J. Wysocki
1996e9d732 Merge 'acpi-bus' material for v6.6 to satisfy dependencies. 2023-08-10 20:56:51 +02:00
Rafael J. Wysocki
eca3f0a8ff ACPI: thermal: Drop redundant local variable from acpi_thermal_resume()
Commit dabc621a31 ("ACPI: thermal: Drop enabled flag from struct
acpi_thermal_active") left behind a variable that is only assigned to
and never read, so drop it now.

Fixes: dabc621a31 ("ACPI: thermal: Drop enabled flag from struct acpi_thermal_active")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-08-10 20:55:29 +02:00
Rafael J. Wysocki
868a4715a8 ACPI: thermal: Do not attach private data to ACPI handles
The ACPI thermal driver uses acpi_bus_attach_private_data() to attach
the thermal zone object to the ACPI handle of the thermal zone and
acpi_bus_detach_private_data() to clean that up, but it never uses
acpi_bus_get_private_data() to retrieve that object.

Drop the unneded acpi_bus_attach_private_data() and
acpi_bus_detach_private_data() calls from the ACPI thermal driver and
clean up the related code.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
2023-08-09 10:53:06 +02:00
Rafael J. Wysocki
dabc621a31 ACPI: thermal: Drop enabled flag from struct acpi_thermal_active
The enabled field of struct acpi_thermal_active is only updated and never
read, so drop it along with the related code.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-08-01 14:04:30 +02:00
Mario Limonciello
5f641174a1 ACPI: thermal: Drop nocrt parameter
The `nocrt` module parameter has no code associated with it and does
nothing.  As `crt=-1` has same functionality as what nocrt should be
doing drop `nocrt` and associated documentation.

This should fix a quirk for Gigabyte GA-7ZX that used `nocrt` and
thus didn't function properly.

Fixes: 8c99fdce30 ("ACPI: thermal: set "thermal.nocrt" via DMI on Gigabyte GA-7ZX")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-07-17 15:24:53 +02:00
Michal Wilczynski
9d67b6acf1 ACPI: thermal: Install Notify() handler directly
Modify the ACPI thermal driver to install its own Notify() handler
directly instead of providing an ACPI driver .notify() callback.

This will allow the ACPI driver .notify() callback to be eliminated and
it will allow the thermal driver to be switched over to a platform one
in the future.

While at it, fix up whitespaces in acpi_thermal_remove().

Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Michal Wilczynski <michal.wilczynski@intel.com>
[ rjw: Subject and changelog edits, whitespace adjustments ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-07-14 19:08:52 +02:00
Rafael J. Wysocki
c31b3a1b00 ACPI: thermal: Drop struct acpi_thermal_flags
Drop struct acpi_thermal_flags which is not really used (only one
flag in it is ever set, but it is never read) and call
acpi_execute_simple_method() directly to evaluate _SCP instead of
using acpi_thermal_set_cooling_mode(), which has no callers after
that change, so drop it.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-06-16 20:16:44 +02:00
Rafael J. Wysocki
f75fbe28e8 ACPI: thermal: Drop struct acpi_thermal_state
Drop struct acpi_thermal_state which is not really used.

No functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-06-16 20:16:25 +02:00
Rafael J. Wysocki
7266c88cba ACPI: thermal: Eliminate struct acpi_thermal_state_flags
Notice that the enabled flag is only needed for active trip points,
so drop struct acpi_thermal_state_flags, add a simple "bool valid" field
to the definitions of all trip point structures instead of flags and
add a "bool enabled" field to struct acpi_thermal_active.

Adjust the code using the modified structures accordingly.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Michal Wilczynski <michal.wilczynski@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-06-12 19:35:15 +02:00
Rafael J. Wysocki
607d265fc1 ACPI: thermal: Move acpi_thermal_driver definition
Move the definition of the acpi_thermal_driver structure closer to the
initialization code that registes the driver, so some function forward
declarations can be dropped.

Also move the module information to the end of the file where it is
usually located.

No functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-06-12 19:35:15 +02:00
Rafael J. Wysocki
bb5ab1fd61 ACPI: thermal: Move symbol definitions to one place
Move all of the symbol definitions to the initial part of the code so
they all can be found in one place.

While at it, consolidate white space used in there.

No functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Michal Wilczynski <michal.wilczynski@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-06-12 19:35:15 +02:00
Rafael J. Wysocki
a809560469 ACPI: thermal: Drop redundant ACPI_TRIPS_REFRESH_DEVICES symbol
Drop the ACPI_TRIPS_REFRESH_DEVICES symbol which is redundant, because
ACPI_TRIPS_DEVICES can be used directly instead of it without any
drawbacks and rename the ACPI_TRIPS_REFRESH_THRESHOLDS to
ACPI_TRIPS_THRESHOLDS to make the code a bit more consistent.

While at it, fix up some formatting white space used in the symbol
definitions.

No functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Michal Wilczynski <michal.wilczynski@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-06-12 19:35:14 +02:00