diff options
author | Aurora zuma automerger <aurora-zuma-automerger@google.com> | 2023-03-12 10:56:17 +0000 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-03-12 22:17:07 -0700 |
commit | f12c18aa9d19fb142475e5bdc3cba671491ba033 (patch) | |
tree | 0396d73220b38249ace6ce1517fa000a2a880d16 | |
parent | 19425405130ee51277b94acf9e5599f00b5c014a (diff) | |
download | zuma-f12c18aa9d19fb142475e5bdc3cba671491ba033.tar.gz |
gxp: [Copybara Auto Merge] Merge branch 'zuma' into 'android14-gs-pixel-5.15'
gxp: bump version 1.11
Bugs:
gxp: fix panic on buffer flushing
Bug: 268389591
gxp: Do not put core in reset if already in ACG
Bug: 272664140
gxp: add cached core telemetry desc
Bug: 265748027
gxp: Adpot GCIP thermal
Bug: 264729080
Bug: 213272324
gxp: Acquire PM lock before power state transition
Bug: 264729080 (repeat)
gxp: remove core_boot parameter
Bug: 251612313
gcip: Add gcip_pm_lock
Bug: 264729080 (repeat)
GCIP_HEADERS_REV_ID: 126a2bd1e5ac72231c88425fbddb4b9fe2fd85b1
GitOrigin-RevId: 0016adcc63d0c67e605cfee179041d15d26cf861
Change-Id: I156cc4b83564d06049764ee15510571305f84f74
-rw-r--r-- | gcip-kernel-driver/include/gcip/gcip-pm.h | 16 | ||||
-rw-r--r-- | gxp-common-platform.c | 14 | ||||
-rw-r--r-- | gxp-firmware-data.c | 31 | ||||
-rw-r--r-- | gxp-firmware-data.h | 13 | ||||
-rw-r--r-- | gxp-firmware.c | 9 | ||||
-rw-r--r-- | gxp-firmware.h | 5 | ||||
-rw-r--r-- | gxp-internal.h | 4 | ||||
-rw-r--r-- | gxp-mapping.c | 19 | ||||
-rw-r--r-- | gxp-mcu-firmware.c | 36 | ||||
-rw-r--r-- | gxp-thermal.c | 357 | ||||
-rw-r--r-- | gxp-thermal.h | 33 | ||||
-rw-r--r-- | gxp-vd.c | 24 | ||||
-rw-r--r-- | gxp.h | 2 |
13 files changed, 164 insertions, 399 deletions
diff --git a/gcip-kernel-driver/include/gcip/gcip-pm.h b/gcip-kernel-driver/include/gcip/gcip-pm.h index af0fb31..4842598 100644 --- a/gcip-kernel-driver/include/gcip/gcip-pm.h +++ b/gcip-kernel-driver/include/gcip/gcip-pm.h @@ -117,10 +117,22 @@ static inline void gcip_pm_lockdep_assert_held(struct gcip_pm *pm) /* * Lock the PM lock. - * Returns 1 if the lock has been acquired successfully, and 0 on contention. * Since all the PM requests will be blocked until gcip_pm_unlock is called, one should use the * gcip_pm_{get,get_if_powered,put} if possible and uses this only if a power state transition can - * not be triggered, e.g., in a workqueue that will be canceled during power off. + * not be triggered, e.g., in a workqueue that will be canceled during power off or crash handler. + */ +static inline void gcip_pm_lock(struct gcip_pm *pm) +{ + if (!pm) + return; + + mutex_lock(&pm->lock); +} + +/* + * Lock the PM lock. + * Same as gcip_pm_lock, but returns 1 if the lock has been acquired successfully, and 0 on + * contention. */ static inline int gcip_pm_trylock(struct gcip_pm *pm) { diff --git a/gxp-common-platform.c b/gxp-common-platform.c index 694a2a8..baa8707 100644 --- a/gxp-common-platform.c +++ b/gxp-common-platform.c @@ -2090,11 +2090,10 @@ static int gxp_common_platform_probe(struct platform_device *pdev, struct gxp_de dev_err(dev, "Failed to initialize core telemetry (ret=%d)", ret); goto err_fw_data_destroy; } - gxp->thermal_mgr = gxp_thermal_init(gxp); - if (IS_ERR(gxp->thermal_mgr)) { - ret = PTR_ERR(gxp->thermal_mgr); + + ret = gxp_thermal_init(gxp); + if (ret) dev_warn(dev, "Failed to init thermal driver: %d\n", ret); - } gxp->gfence_mgr = gcip_dma_fence_manager_create(gxp->dev); if (IS_ERR(gxp->gfence_mgr)) { @@ -2132,7 +2131,7 @@ err_before_remove: err_dma_fence_destroy: /* DMA fence manager creation doesn't need revert */ err_thermal_destroy: - /* thermal init doesn't need revert */ + gxp_thermal_exit(gxp); gxp_core_telemetry_exit(gxp); err_fw_data_destroy: gxp_fw_data_destroy(gxp); @@ -2163,6 +2162,11 @@ static int gxp_common_platform_remove(struct platform_device *pdev) { struct gxp_dev *gxp = platform_get_drvdata(pdev); + /* + * Call gxp_thermal_exit before gxp_remove_debugdir since it will + * remove its own debugfs. + */ + gxp_thermal_exit(gxp); gxp_remove_debugdir(gxp); misc_deregister(&gxp->misc_dev); if (gxp->before_remove) diff --git a/gxp-firmware-data.c b/gxp-firmware-data.c index 0ba2c7b..09c1326 100644 --- a/gxp-firmware-data.c +++ b/gxp-firmware-data.c @@ -93,6 +93,8 @@ struct gxp_fw_data_manager { struct fw_memory core_telemetry_mem; struct fw_memory debug_dump_mem; + /* Cached core telemetry descriptors. */ + struct gxp_core_telemetry_descriptor core_telemetry_desc; /* * A host-view of the System configuration descriptor. This same desc * is provided to all VDs and all cores. This is the R/O section. @@ -585,7 +587,7 @@ static void set_system_cfg_region(struct gxp_dev *gxp, void *sys_cfg) struct gxp_system_descriptor_ro *des_ro = sys_cfg; struct gxp_system_descriptor_rw *des_rw = sys_cfg + PAGE_SIZE; struct gxp_core_telemetry_descriptor *descriptor = - gxp->data_mgr->core_telemetry_mem.host_addr; + &gxp->data_mgr->core_telemetry_desc; struct telemetry_descriptor_ro *tel_ro; struct telemetry_descriptor_rw *tel_rw; struct core_telemetry_descriptor *tel_des; @@ -883,18 +885,13 @@ int gxp_fw_data_set_core_telemetry_descriptors(struct gxp_dev *gxp, u8 type, struct gxp_coherent_buf *buffers, u32 per_buffer_size) { - struct gxp_core_telemetry_descriptor *descriptor = - gxp->data_mgr->core_telemetry_mem.host_addr; struct core_telemetry_descriptor *core_descriptors; uint core; bool enable; - if (type == GXP_TELEMETRY_TYPE_LOGGING) - core_descriptors = descriptor->per_core_loggers; - else if (type == GXP_TELEMETRY_TYPE_TRACING) - core_descriptors = descriptor->per_core_tracers; - else - return -EINVAL; + core_descriptors = gxp_fw_data_get_core_telemetry_descriptor(gxp, type); + if (IS_ERR(core_descriptors)) + return PTR_ERR(core_descriptors); enable = (host_status & GXP_CORE_TELEMETRY_HOST_STATUS_ENABLED); @@ -923,12 +920,26 @@ int gxp_fw_data_set_core_telemetry_descriptors(struct gxp_dev *gxp, u8 type, return 0; } +struct core_telemetry_descriptor * +gxp_fw_data_get_core_telemetry_descriptor(struct gxp_dev *gxp, u8 type) +{ + struct gxp_core_telemetry_descriptor *descriptor = + &gxp->data_mgr->core_telemetry_desc; + + if (type == GXP_TELEMETRY_TYPE_LOGGING) + return descriptor->per_core_loggers; + else if (type == GXP_TELEMETRY_TYPE_TRACING) + return descriptor->per_core_tracers; + else + return ERR_PTR(-EINVAL); +} + static u32 gxp_fw_data_get_core_telemetry_device_status_legacy(struct gxp_dev *gxp, uint core, u8 type) { struct gxp_core_telemetry_descriptor *descriptor = - gxp->data_mgr->core_telemetry_mem.host_addr; + &gxp->data_mgr->core_telemetry_desc; switch (type) { case GXP_TELEMETRY_TYPE_LOGGING: diff --git a/gxp-firmware-data.h b/gxp-firmware-data.h index e2296bd..edff4af 100644 --- a/gxp-firmware-data.h +++ b/gxp-firmware-data.h @@ -84,6 +84,19 @@ int gxp_fw_data_set_core_telemetry_descriptors(struct gxp_dev *gxp, u8 type, u32 host_status, struct gxp_coherent_buf *buffers, u32 per_buffer_size); +/** + * gxp_fw_data_get_core_telemetry_descriptor() - Returns the pointer of core + * telemetry descriptor of given + * type. + * @gxp: The GXP device to get buffer descriptors for + * @type: Either `GXP_TELEMETRY_TYPE_LOGGING` or `GXP_TELEMETRY_TYPE_TRACING` + * + * Return: + * A pointer to the descriptor. + * -EINVAL - If @type is invalid. + */ +struct core_telemetry_descriptor * +gxp_fw_data_get_core_telemetry_descriptor(struct gxp_dev *gxp, u8 type); /** * gxp_fw_data_get_core_telemetry_device_status() - Returns a bitfield diff --git a/gxp-firmware.c b/gxp-firmware.c index 2f9a585..d532fdf 100644 --- a/gxp-firmware.c +++ b/gxp-firmware.c @@ -45,9 +45,6 @@ static int gxp_dsp_fw_auth_disable; module_param_named(dsp_fw_auth_disable, gxp_dsp_fw_auth_disable, int, 0660); -static bool gxp_core_boot_flag = true; -module_param_named(core_boot, gxp_core_boot_flag, bool, 0660); - static int request_dsp_firmware(struct gxp_dev *gxp, char *name_prefix, const struct firmware *out_firmwares[GXP_NUM_CORES]) @@ -759,7 +756,7 @@ static void enable_core_interrupts(struct gxp_dev *gxp, uint core) gxp_write_32(gxp, GXP_CORE_REG_DEDICATED_INT_MASK(core), 0xffffffff); } -static void disable_core_interrupts(struct gxp_dev *gxp, uint core) +void gxp_firmware_disable_ext_interrupts(struct gxp_dev *gxp, uint core) { gxp_write_32(gxp, GXP_CORE_REG_COMMON_INT_MASK_0(core), 0); gxp_write_32(gxp, GXP_CORE_REG_COMMON_INT_MASK_1(core), 0); @@ -908,7 +905,7 @@ static void gxp_firmware_stop_core(struct gxp_dev *gxp, * Disable interrupts to prevent cores from being woken up * unexpectedly. */ - disable_core_interrupts(gxp, phys_core); + gxp_firmware_disable_ext_interrupts(gxp, phys_core); gxp_pm_core_off(gxp, phys_core); } } @@ -1076,5 +1073,5 @@ u32 gxp_firmware_get_boot_status(struct gxp_dev *gxp, bool gxp_core_boot(struct gxp_dev *gxp) { - return gxp_core_boot_flag; + return gxp_is_direct_mode(gxp); } diff --git a/gxp-firmware.h b/gxp-firmware.h index 6dde831..e1f44ce 100644 --- a/gxp-firmware.h +++ b/gxp-firmware.h @@ -154,4 +154,9 @@ u32 gxp_firmware_get_boot_status(struct gxp_dev *gxp, /* Returns whether the core firmware running states are managed by us. */ bool gxp_core_boot(struct gxp_dev *gxp); +/* + * Disable external interrupts to core. + */ +void gxp_firmware_disable_ext_interrupts(struct gxp_dev *gxp, uint core); + #endif /* __GXP_FIRMWARE_H__ */ diff --git a/gxp-internal.h b/gxp-internal.h index a0f2f0c..e00401b 100644 --- a/gxp-internal.h +++ b/gxp-internal.h @@ -23,6 +23,8 @@ #include <linux/rwsem.h> #include <linux/spinlock.h> +#include <gcip/gcip-thermal.h> + #include "gxp-config.h" #define IS_GXP_TEST IS_ENABLED(CONFIG_GXP_TEST) @@ -105,12 +107,12 @@ struct gxp_dev { struct gxp_client *debugfs_client; struct mutex debugfs_client_lock; bool debugfs_wakelock_held; - struct gxp_thermal_manager *thermal_mgr; struct gxp_dma_manager *dma_mgr; struct gxp_fw_data_manager *data_mgr; struct gxp_tpu_dev tpu_dev; struct gxp_core_telemetry_manager *core_telemetry_mgr; struct gxp_iommu_domain *default_domain; + struct gcip_thermal *thermal; /* * Pointer to GSA device for firmware authentication. * May be NULL if the chip does not support firmware authentication diff --git a/gxp-mapping.c b/gxp-mapping.c index 398ff05..1a89b1c 100644 --- a/gxp-mapping.c +++ b/gxp-mapping.c @@ -272,6 +272,13 @@ int gxp_mapping_sync(struct gxp_mapping *mapping, u32 offset, u32 size, } /* + * Since the scatter-gather list of the mapping is modified while it is + * being synced, only one sync for a given mapping can occur at a time. + * Rather than maintain a mutex for every mapping, lock the mapping list + * mutex, making all syncs mutually exclusive. + */ + mutex_lock(&mapping->sync_lock); + /* * Mappings are created at a PAGE_SIZE granularity, however other data * which is not part of the mapped buffer may be present in the first * and last pages of the buffer's scattergather list. @@ -302,17 +309,9 @@ int gxp_mapping_sync(struct gxp_mapping *mapping, u32 offset, u32 size, /* Make sure a valid starting scatterlist was found for the start */ if (!start_sg) { ret = -EINVAL; - goto out; + goto out_unlock; } - /* - * Since the scatter-gather list of the mapping is modified while it is - * being synced, only one sync for a given mapping can occur at a time. - * Rather than maintain a mutex for every mapping, lock the mapping list - * mutex, making all syncs mutually exclusive. - */ - mutex_lock(&mapping->sync_lock); - start_sg->offset += start_diff; start_sg->dma_address += start_diff; start_sg->length -= start_diff; @@ -336,8 +335,8 @@ int gxp_mapping_sync(struct gxp_mapping *mapping, u32 offset, u32 size, start_sg->length += start_diff; start_sg->dma_length += start_diff; +out_unlock: mutex_unlock(&mapping->sync_lock); - out: gxp_mapping_put(mapping); diff --git a/gxp-mcu-firmware.c b/gxp-mcu-firmware.c index 56b0550..b0bf0dd 100644 --- a/gxp-mcu-firmware.c +++ b/gxp-mcu-firmware.c @@ -18,6 +18,7 @@ #include <gcip/gcip-common-image-header.h> #include <gcip/gcip-image-config.h> #include <gcip/gcip-pm.h> +#include <gcip/gcip-thermal.h> #include "gxp-bpm.h" #include "gxp-config.h" @@ -205,14 +206,9 @@ static int gxp_mcu_firmware_handshake(struct gxp_mcu_firmware *mcu_fw) if (ret) dev_warn(gxp->dev, "telemetry KCI error: %d", ret); - if (gxp->power_mgr->thermal_limit && - gxp->power_mgr->thermal_limit != aur_power_state2rate[AUR_NOM]) { - ret = gxp_kci_notify_throttling(&mcu->kci, - gxp->power_mgr->thermal_limit); - if (ret) - dev_warn(gxp->dev, - "error setting gxp cooling state: %d\n", ret); - } + ret = gcip_thermal_restore_on_powering(gxp->thermal); + if (ret) + dev_warn(gxp->dev, "thermal restore error: %d", ret); return 0; } @@ -486,6 +482,7 @@ void gxp_mcu_firmware_crash_handler(struct gxp_dev *gxp, { struct gxp_mcu_firmware *mcu_fw = gxp_mcu_firmware_of(gxp); struct gxp_client *client; + struct gcip_pm *pm = gxp->power_mgr->pm; int ret; dev_err(gxp->dev, "MCU firmware is crashed, crash_type=%d", crash_type); @@ -527,20 +524,23 @@ void gxp_mcu_firmware_crash_handler(struct gxp_dev *gxp, down_write(&gxp->vd_semaphore); /* - * As we are recovering the MCU firmware, we should prevent power state transition caused by - * clients acquiring or releasing the block wakelock until the rescuing is finished. - * - * The runtime can still acquire or release the block wakelock, but commands issued to the - * firmware might not be handled properly. - * + * Holding the PM lock due to the reasons listed below. + * 1. As we are recovering the MCU firmware, we should block the PM requests (e.g., + * acquiring or releasing the block wakelock) until the rescuing is finished. + * 2. Restarting the MCU firmware might involve restore functions (e.g., + * gcip_thermal_restore_on_powering) which require the caller to hold the PM lock. + */ + gcip_pm_lock(pm); + + /* * By the race, if all clients left earlier than this handler, all block wakleock should be * already released and the BLK is turned off. We don't have to rescue the MCU firmware. */ - if (gcip_pm_get_if_powered(gxp->power_mgr->pm, false)) { + if (!gcip_pm_is_powered(pm)) { dev_info( gxp->dev, "The block wakelock is already released, skip restarting MCU firmware"); - goto out_unlock_client_semaphore; + goto out_unlock_pm; } /* @@ -576,8 +576,8 @@ void gxp_mcu_firmware_crash_handler(struct gxp_dev *gxp, out: mutex_unlock(&mcu_fw->lock); - gcip_pm_put(gxp->power_mgr->pm); -out_unlock_client_semaphore: +out_unlock_pm: + gcip_pm_unlock(pm); up_write(&gxp->vd_semaphore); list_for_each_entry (client, &gxp->client_list, list_entry) { up_write(&client->semaphore); diff --git a/gxp-thermal.c b/gxp-thermal.c index 8a9c24b..e7b9fc5 100644 --- a/gxp-thermal.c +++ b/gxp-thermal.c @@ -2,358 +2,93 @@ /* * Platform thermal driver for GXP. * - * Copyright (C) 2021 Google LLC + * Copyright (C) 2021-2023 Google LLC */ #include <linux/acpm_dvfs.h> -#include <linux/debugfs.h> #include <linux/device.h> -#include <linux/gfp.h> -#include <linux/kernel.h> -#include <linux/mutex.h> -#include <linux/of.h> -#include <linux/platform_device.h> -#include <linux/pm_runtime.h> -#include <linux/slab.h> -#include <linux/thermal.h> -#include <linux/version.h> +#include <linux/minmax.h> #include <gcip/gcip-pm.h> +#include <gcip/gcip-thermal.h> -/* - * thermal_cdev_update is moved to drivers/thermal/thermal_core.h in kernel - * 5.12. The symbol is still exported, manually declare the function prototype - * to get rid of the implicit declaration compilation error. - */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) -void thermal_cdev_update(struct thermal_cooling_device *cdev); -#endif - +#include "gxp-config.h" #include "gxp-internal.h" #include "gxp-pm.h" #include "gxp-thermal.h" -#include "gxp-lpm.h" - #if GXP_HAS_MCU #include "gxp-kci.h" #include "gxp-mcu.h" #endif /* GXP_HAS_MCU */ -/* - * Value comes from internal measurement - * b/229623553 - */ -static struct gxp_state_pwr state_pwr_map[] = { - { AUR_NOM_RATE, 78 }, - { AUR_UD_PLUS_RATE, 58 }, - { AUR_UD_RATE, 40 }, - { AUR_SUD_PLUS_RATE, 27 }, - { AUR_SUD_RATE, 20 }, - { AUR_UUD_PLUS_RATE, 16 }, - { AUR_UUD_RATE, 13 }, -}; - -static int gxp_get_max_state(struct thermal_cooling_device *cdev, - unsigned long *state) +static int gxp_thermal_get_rate(void *data, unsigned long *rate) { - struct gxp_thermal_manager *thermal = cdev->devdata; - - if (!thermal->gxp_num_states) - return -EIO; + *rate = exynos_acpm_get_rate(AUR_DVFS_DOMAIN, 0); - *state = thermal->gxp_num_states - 1; return 0; } -/* - * Set cooling state. - */ -static int gxp_set_cur_state(struct thermal_cooling_device *cdev, - unsigned long cooling_state) +static int gxp_thermal_set_rate(void *data, unsigned long rate) { - int ret = 0; - struct gxp_thermal_manager *thermal = cdev->devdata; - struct gxp_dev *gxp = thermal->gxp; - struct device *dev = gxp->dev; - unsigned long pwr_state; - - if (cooling_state >= thermal->gxp_num_states) { - dev_err(dev, "%s: invalid cooling state %lu\n", __func__, - cooling_state); - return -EINVAL; - } + struct gxp_dev *gxp = data; + int ret; - mutex_lock(&thermal->lock); - cooling_state = max(thermal->sysfs_req, cooling_state); - if (cooling_state >= ARRAY_SIZE(state_pwr_map)) { - dev_err(dev, "Unsupported cooling state: %lu\n", cooling_state); - ret = -EINVAL; - goto out; - } - pwr_state = state_pwr_map[cooling_state].state; - dev_dbg(dev, "setting state %ld\n", pwr_state); - if (cooling_state != thermal->cooling_state) { - if (!gxp_is_direct_mode(gxp)) { + if (!gxp_is_direct_mode(gxp)) { #if GXP_HAS_MCU - struct gxp_mcu *mcu = gxp_mcu_of(gxp); - - ret = gcip_pm_get_if_powered(mcu->gxp->power_mgr->pm, - false); - if (ret) { - dev_err(dev, - "Can't acquire wakelock when powered down: %d\n", - ret); - goto out; - } + struct gxp_mcu *mcu = gxp_mcu_of(gxp); - ret = gxp_kci_notify_throttling(&mcu->kci, pwr_state); - gcip_pm_put(gxp->power_mgr->pm); + ret = gxp_kci_notify_throttling(&mcu->kci, rate); #endif /* GXP_HAS_MCU */ - } else { - ret = gxp_pm_blk_set_rate_acpm( - gxp, - max(pwr_state, - (unsigned long) - aur_power_state2rate[AUR_UUD])); - } - - if (ret) { - dev_err(dev, "error setting gxp cooling state: %d\n", - ret); - ret = -ENODEV; - goto out; - } - thermal->cooling_state = cooling_state; - gxp_pm_set_thermal_limit(thermal->gxp, pwr_state); } else { - ret = -EALREADY; + rate = max_t(unsigned long, rate, + aur_power_state2rate[AUR_UUD]); + ret = gxp_pm_blk_set_rate_acpm(gxp, rate); } -out: - mutex_unlock(&thermal->lock); - return ret; -} - -static int gxp_get_cur_state(struct thermal_cooling_device *cdev, - unsigned long *state) -{ - int ret = 0; - struct gxp_thermal_manager *thermal = cdev->devdata; - - mutex_lock(&thermal->lock); - *state = thermal->cooling_state; - if (*state >= thermal->gxp_num_states) { - dev_err(thermal->gxp->dev, - "Unknown cooling state: %lu, resetting\n", *state); - ret = -EINVAL; - goto out; - } -out: - mutex_unlock(&thermal->lock); - return ret; -} - -static int gxp_state2power_internal(unsigned long state, u32 *power, - struct gxp_thermal_manager *thermal) -{ - int i; - - for (i = 0; i < thermal->gxp_num_states; i++) { - if (state == state_pwr_map[i].state) { - *power = state_pwr_map[i].power; - return 0; - } - } - dev_err(thermal->gxp->dev, "Unknown state req for: %lu\n", state); - *power = 0; - return -EINVAL; -} - -static int gxp_get_requested_power(struct thermal_cooling_device *cdev, - u32 *power) -{ - unsigned long power_state; - struct gxp_thermal_manager *cooling = cdev->devdata; - - power_state = exynos_acpm_get_rate(AUR_DVFS_DOMAIN, 0); - return gxp_state2power_internal(power_state, power, cooling); -} - -/* TODO(b/213272324): Move state2power table to dts */ -static int gxp_state2power(struct thermal_cooling_device *cdev, - unsigned long state, u32 *power) -{ - struct gxp_thermal_manager *thermal = cdev->devdata; - - if (state >= thermal->gxp_num_states) { - dev_err(thermal->gxp->dev, "%s: invalid state: %lu\n", __func__, - state); - return -EINVAL; + if (ret) { + dev_err(gxp->dev, "error setting gxp cooling state: %d\n", ret); + return ret; } - return gxp_state2power_internal(state_pwr_map[state].state, power, - thermal); -} + gxp_pm_set_thermal_limit(gxp, rate); -static int gxp_power2state(struct thermal_cooling_device *cdev, - u32 power, unsigned long *state) -{ - int i, penultimate_throttle_state; - struct gxp_thermal_manager *thermal = cdev->devdata; - - *state = 0; - /* Less than 2 state means we cannot really throttle */ - if (thermal->gxp_num_states < 2) - return thermal->gxp_num_states == 1 ? 0 : -EIO; - - penultimate_throttle_state = thermal->gxp_num_states - 2; - /* - * argument "power" is the maximum allowed power consumption in mW as - * defined by the PID control loop. Check for the first state that is - * less than or equal to the current allowed power. state_pwr_map is - * descending, so lowest power consumption is last value in the array - * return lowest state even if it consumes more power than allowed as - * not all platforms can handle throttling below an active state - */ - for (i = penultimate_throttle_state; i >= 0; --i) { - if (power < state_pwr_map[i].power) { - *state = i + 1; - break; - } - } return 0; } -static struct thermal_cooling_device_ops gxp_cooling_ops = { - .get_max_state = gxp_get_max_state, - .get_cur_state = gxp_get_cur_state, - .set_cur_state = gxp_set_cur_state, - .get_requested_power = gxp_get_requested_power, - .state2power = gxp_state2power, - .power2state = gxp_power2state, -}; - -static void gxp_thermal_exit(struct gxp_thermal_manager *thermal) -{ - if (!IS_ERR_OR_NULL(thermal->cdev)) - thermal_cooling_device_unregister(thermal->cdev); -} - -static void devm_gxp_thermal_release(struct device *dev, void *res) -{ - struct gxp_thermal_manager *thermal = res; - - gxp_thermal_exit(thermal); -} - -static ssize_t -user_vote_show(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct thermal_cooling_device *cdev = - container_of(dev, struct thermal_cooling_device, - device); - struct gxp_thermal_manager *cooling = cdev->devdata; - - if (!cooling) - return -ENODEV; - - return sysfs_emit(buf, "%lu\n", cooling->sysfs_req); -} - -static ssize_t user_vote_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct thermal_cooling_device *cdev = - container_of(dev, struct thermal_cooling_device, - device); - struct gxp_thermal_manager *cooling = cdev->devdata; - int ret; - unsigned long state; - - if (!cooling) - return -ENODEV; - - ret = kstrtoul(buf, 0, &state); - if (ret) - return ret; - - if (state >= cooling->gxp_num_states) - return -EINVAL; - - mutex_lock(&cdev->lock); - cooling->sysfs_req = state; - cdev->updated = false; - mutex_unlock(&cdev->lock); - thermal_cdev_update(cdev); - return count; -} - -static DEVICE_ATTR_RW(user_vote); - -static int -gxp_thermal_cooling_register(struct gxp_thermal_manager *thermal, char *type) +static int gxp_thermal_control(void *data, bool enable) { - struct device_node *cooling_node = NULL; - - thermal->op_data = NULL; - thermal->gxp_num_states = ARRAY_SIZE(state_pwr_map); - - mutex_init(&thermal->lock); - cooling_node = of_find_node_by_name(NULL, GXP_COOLING_NAME); - - /* TODO: Change this to fatal error once dts change is merged */ - if (!cooling_node) - dev_warn(thermal->gxp->dev, "failed to find cooling node\n"); - /* Initialize the cooling state as 0, means "no cooling" */ - thermal->cooling_state = 0; - thermal->cdev = thermal_of_cooling_device_register( - cooling_node, type, thermal, &gxp_cooling_ops); - if (IS_ERR(thermal->cdev)) - return PTR_ERR(thermal->cdev); - - return device_create_file(&thermal->cdev->device, &dev_attr_user_vote); + return -EOPNOTSUPP; } -static int cooling_init(struct gxp_thermal_manager *thermal, struct device *dev) +int gxp_thermal_init(struct gxp_dev *gxp) { - int err; - struct dentry *d; + const struct gcip_thermal_args args = { + .dev = gxp->dev, + .pm = gxp->power_mgr->pm, + .dentry = gxp->d_entry, + .node_name = GXP_COOLING_NAME, + .type = GXP_COOLING_NAME, + .data = gxp, + .get_rate = gxp_thermal_get_rate, + .set_rate = gxp_thermal_set_rate, + .control = gxp_thermal_control, + }; + struct gcip_thermal *thermal; + + if (gxp->thermal) + return -EEXIST; + + thermal = gcip_thermal_create(&args); + if (IS_ERR(thermal)) + return PTR_ERR(thermal); + + gxp->thermal = thermal; - d = debugfs_create_dir("cooling", thermal->gxp->d_entry); - /* don't let debugfs creation failure abort the init procedure */ - if (IS_ERR_OR_NULL(d)) - dev_warn(dev, "failed to create debug fs for cooling"); - thermal->cooling_root = d; - - err = gxp_thermal_cooling_register(thermal, GXP_COOLING_NAME); - if (err) { - dev_err(dev, "failed to initialize external cooling\n"); - gxp_thermal_exit(thermal); - return err; - } return 0; } -struct gxp_thermal_manager -*gxp_thermal_init(struct gxp_dev *gxp) +void gxp_thermal_exit(struct gxp_dev *gxp) { - struct device *dev = gxp->dev; - struct gxp_thermal_manager *thermal; - int err; - - thermal = devres_alloc(devm_gxp_thermal_release, sizeof(*thermal), - GFP_KERNEL); - if (!thermal) - return ERR_PTR(-ENOMEM); - - thermal->gxp = gxp; - err = cooling_init(thermal, dev); - if (err) { - devres_free(thermal); - return ERR_PTR(err); - } - - devres_add(dev, thermal); - return thermal; + gcip_thermal_destroy(gxp->thermal); + gxp->thermal = NULL; } diff --git a/gxp-thermal.h b/gxp-thermal.h index c1939ef..aa4fe3a 100644 --- a/gxp-thermal.h +++ b/gxp-thermal.h @@ -2,43 +2,18 @@ /* * Platform thermal driver for GXP. * - * Copyright (C) 2021 Google LLC + * Copyright (C) 2021-2023 Google LLC */ #ifndef __GXP_THERMAL_H__ #define __GXP_THERMAL_H__ -#include <linux/debugfs.h> -#include <linux/device.h> -#include <linux/mutex.h> -#include <linux/thermal.h> +#include <gcip/gcip-thermal.h> #include "gxp-internal.h" -#include "gxp-pm.h" #define GXP_COOLING_NAME "gxp-cooling" -struct gxp_thermal_manager { - struct dentry *cooling_root; - struct thermal_cooling_device *cdev; - struct mutex lock; - void *op_data; - unsigned long cooling_state; - unsigned long sysfs_req; - unsigned int gxp_num_states; - struct gxp_dev *gxp; - bool thermal_suspended; /* GXP thermal suspended state */ -}; - -/* - * Internal structure to do the state/pwr mapping - * state: kHz that AUR is running - * power: mW that the state consume - */ -struct gxp_state_pwr { - unsigned long state; - u32 power; -}; - -struct gxp_thermal_manager *gxp_thermal_init(struct gxp_dev *gxp); +int gxp_thermal_init(struct gxp_dev *gxp); +void gxp_thermal_exit(struct gxp_dev *gxp); #endif /* __GXP_THERMAL_H__ */ @@ -975,15 +975,27 @@ void gxp_vd_stop(struct gxp_virtual_device *vd) (vd->state == GXP_VD_OFF || vd->state == GXP_VD_READY || vd->state == GXP_VD_RUNNING) && gxp_pm_get_blk_state(gxp) != AUR_OFF) { - /* - * Put all cores in the VD into reset so they can not wake each other up - */ + for (phys_core = 0; phys_core < GXP_NUM_CORES; phys_core++) { if (core_list & BIT(phys_core)) { - lpm_state = gxp_lpm_get_state( - gxp, CORE_TO_PSM(phys_core)); - if (lpm_state != LPM_PG_STATE) + + lpm_state = gxp_lpm_get_state(gxp, CORE_TO_PSM(phys_core)); + + if (lpm_state == LPM_ACTIVE_STATE) { + /* + * If the core is in PS0 (not idle), it should + * be held in reset before attempting SW PG. + */ hold_core_in_reset(gxp, phys_core); + } else { + /* + * If the core is idle and has already transtioned to PS1, + * we can attempt HW PG. In this case, we should ensure + * that the core doesn't get awakened by an external + * interrupt source before we attempt to HW PG the core. + */ + gxp_firmware_disable_ext_interrupts(gxp, phys_core); + } } } } @@ -13,7 +13,7 @@ /* Interface Version */ #define GXP_INTERFACE_VERSION_MAJOR 1 -#define GXP_INTERFACE_VERSION_MINOR 10 +#define GXP_INTERFACE_VERSION_MINOR 11 #define GXP_INTERFACE_VERSION_BUILD 0 /* |