JianyuWang0623 commented on code in PR #12824: URL: https://github.com/apache/nuttx/pull/12824#discussion_r1763867206
########## drivers/thermal/thermal_cpufreq_cooling.c: ########## @@ -0,0 +1,234 @@ +/**************************************************************************** + * drivers/thermal/thermal_cpufreq_cooling.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/cpufreq.h> +#include <nuttx/kmalloc.h> + +#include "thermal_core.h" + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct cpufreq_cooling_device_s +{ + FAR const struct cpufreq_frequency_table *table; + FAR struct cpufreq_policy *policy; + FAR struct cpufreq_qos *qos; + unsigned int cur_state; + unsigned int max_state; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int cpufreq_get_max_state(FAR struct thermal_cooling_device_s *cdev, + FAR unsigned int *state); +static int cpufreq_get_state (FAR struct thermal_cooling_device_s *cdev, + FAR unsigned int *state); +static int cpufreq_set_state (FAR struct thermal_cooling_device_s *cdev, + unsigned int state); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct thermal_cooling_device_ops_s g_cpufreq_cdev_ops = +{ + .set_state = cpufreq_set_state, + .get_state = cpufreq_get_state, + .get_max_state = cpufreq_get_max_state, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int cpufreq_get_max_state(FAR struct thermal_cooling_device_s *cdev, + FAR unsigned int *state) +{ + struct cpufreq_cooling_device_s *cpufreq_cdev = cdev->devdata; + + *state = cpufreq_cdev->max_state; + return OK; +} + +static int cpufreq_get_state(FAR struct thermal_cooling_device_s *cdev, + FAR unsigned int *state) +{ + struct cpufreq_cooling_device_s *cpufreq_cdev = cdev->devdata; + + *state = cpufreq_cdev->cur_state; + return OK; +} + +static int cpufreq_set_state(FAR struct thermal_cooling_device_s *cdev, + unsigned int state) +{ + struct cpufreq_cooling_device_s *cpufreq_cdev = cdev->devdata; + unsigned int index = cpufreq_cdev->max_state - state; Review Comment: > If `state > max_state` then `index` will be out of bounds of `cpufreq_cdev->table`. Is there some logic elsewhere to prevent this? > > (If not, can `index` be clamped to the range 0 through max_state (inclusive) here?) It\`s updated by core/governor, please simply refer to [drivers/thermal/thermal_step_wise.c +54](https://github.com/apache/nuttx/pull/12824/files/d40b702de07c7e3af5af1a1dbe58c35d6b66498f#diff-b9e4ae8c8db0ca7b37552a812f5d882584c5e99079aad771c0ff7158ef32f219R54), range from `instance->lower` to `instance->upper`. The currently dependent module - “cpufreq” has not been uploaded yet. This PR will be updated in the near future to resolve the dependencies and add detailed instructions. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
