Make more functions reentrant

Reduces compile time DSEG usage.

Signed-off-by: Michał Kopeć <michal.kopec@3mdeb.com>
This commit is contained in:
Michał Kopeć
2026-03-05 22:14:00 +01:00
committed by Michał Kopeć
parent ad7e15ce2b
commit 6893591169
9 changed files with 43 additions and 22 deletions
+3 -2
View File
@@ -94,13 +94,14 @@ uint8_t dgpu_get_d_notify_level(bool ac) {
return 0;
}
int16_t dgpu_set_fan_curve(uint8_t count, struct FanPoint *points) {
int16_t dgpu_set_fan_curve(uint8_t count, struct FanPoint *points) __reentrant {
int i;
if (count != FAN.points_size) {
TRACE("DGPU: Incorrect number of fan points: %d, expected %d\n", count, FAN.points_size);
return -1;
}
for (int i = 0; i < count; ++i) {
for (i = 0; i < count; ++i) {
TRACE("DGPU: fan curve t%d: %d, d%d: %d\n", i, points[i].temp, i, points[i].duty);
FAN.points[i].temp = points[i].temp;
FAN.points[i].duty = points[i].duty;
+3 -2
View File
@@ -159,12 +159,13 @@ uint8_t fan_smooth(uint8_t last_duty, uint8_t duty) __reentrant {
return next_duty;
}
uint8_t fan_points_are_valid(uint8_t count, struct FanPoint *points) {
uint8_t fan_points_are_valid(uint8_t count, struct FanPoint *points) __reentrant {
int i;
/*
* Fan curve speeds have to be non-decreasing.
* Fan curve temperatures have to be increasing.
*/
for (int i = 1; i < count; i++) {
for (i = 1; i < count; i++) {
if (points[i].temp <= points[i - 1].temp || points[i].duty < points[i - 1].duty)
return false;
}
@@ -19,7 +19,7 @@ extern int16_t dgpu_temp;
#endif // HAVE_DGPU
void dgpu_init(void);
int16_t dgpu_set_fan_curve(uint8_t count, struct FanPoint *points);
int16_t dgpu_set_fan_curve(uint8_t count, struct FanPoint *points) __reentrant;
uint8_t dgpu_get_fan_duty(void);
uint8_t dgpu_get_d_notify_level(bool ac);
void set_mux_ctrl(void);
@@ -64,6 +64,6 @@ void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant;
uint8_t fan_heatup(const struct Fan *fan, uint8_t duty) __reentrant;
uint8_t fan_cooldown(const struct Fan *fan, uint8_t duty) __reentrant;
uint8_t fan_smooth(uint8_t last_duty, uint8_t duty) __reentrant;
uint8_t fan_points_are_valid(uint8_t count, struct FanPoint *points);
uint8_t fan_points_are_valid(uint8_t count, struct FanPoint *points) __reentrant;
#endif // _BOARD_FAN_H
@@ -29,9 +29,9 @@ extern uint8_t t_junction;
void peci_init(void);
bool peci_available(void);
int16_t peci_set_fan_curve(uint8_t count, struct FanPoint *points);
int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data);
int16_t peci_rd_pkg_config(uint8_t index, uint16_t param, uint32_t *value);
int16_t peci_set_fan_curve(uint8_t count, struct FanPoint *points) __reentrant;
int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) __reentrant;
int16_t peci_rd_pkg_config(uint8_t index, uint16_t param, uint32_t *value) __reentrant;
uint8_t peci_get_fan_duty(void);
#endif // _BOARD_PECI_H
+11 -7
View File
@@ -61,13 +61,14 @@ static struct Fan FAN = {
.interpolate = SMOOTH_FANS != 0,
};
int16_t peci_set_fan_curve(uint8_t count, struct FanPoint *points) {
int16_t peci_set_fan_curve(uint8_t count, struct FanPoint *points) __reentrant {
int i;
if (count != FAN.points_size) {
TRACE("PECI: Incorrect number of fan points: %d, expected %d\n", count, FAN.points_size);
return -1;
}
for (int i = 0; i < count; ++i) {
for (i = 0; i < count; ++i) {
TRACE("PECI: fan curve t%d: %d, d%d: %d\n", i, points[i].temp, i, points[i].duty);
FAN.points[i].temp = points[i].temp;
FAN.points[i].duty = points[i].duty;
@@ -347,9 +348,10 @@ bool peci_get_temp(int16_t *data) {
// Returns positive completion code on success, negative completion code or
// negative (0x1000 | status register) on PECI hardware error
int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) __reentrant {
int retry = 50; // TODO how many retries are appropriate?
uint8_t cc = HORDDR;
uint8_t status;
// Wait for any in-progress transaction to complete
while (HOSTAR & BIT(0)) {}
@@ -387,7 +389,7 @@ int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
// Wait for command completion
while (!(HOSTAR & BIT(1))) {}
uint8_t status = HOSTAR;
status = HOSTAR;
if (status & 0xEC) {
ERROR("peci_wr_pkg_config: hardware error: 0x%02X\n", status);
// Clear status
@@ -411,9 +413,11 @@ int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
return -((int16_t)cc);
}
int16_t peci_rd_pkg_config(uint8_t index, uint16_t param, uint32_t *value) {
int16_t peci_rd_pkg_config(uint8_t index, uint16_t param, uint32_t *value) __reentrant {
int retry = 50; // TODO how many retries are appropriate?
uint8_t cc = HORDDR;
uint8_t status;
int i;
*value = 0;
// Wait for any in-progress transaction to complete
@@ -447,7 +451,7 @@ int16_t peci_rd_pkg_config(uint8_t index, uint16_t param, uint32_t *value) {
// Wait for command completion
while (!(HOSTAR & BIT(1))) {}
uint8_t status = HOSTAR;
status = HOSTAR;
if (status & 0xEC) {
ERROR("peci_rd_pkg_config: hardware error: 0x%02X\n", status);
// Clear status
@@ -466,7 +470,7 @@ int16_t peci_rd_pkg_config(uint8_t index, uint16_t param, uint32_t *value) {
return -((int16_t)cc);
} else {
// Read data if finished successfully
for (int i = 0; i < 4; ++i) {
for (i = 0; i < 4; ++i) {
*value |= (((uint32_t)HORDDR) << (8 * i));
}
+1 -1
View File
@@ -65,7 +65,7 @@ enum {
#define PDO_CURRENT_MA(pdo) (((pdo) & 0x3FF) * 10)
static int16_t usbpd_current_limit(uint8_t address) {
static int16_t usbpd_current_limit(uint8_t address) __reentrant {
uint8_t value[7] = { 0 };
int16_t res = i2c_get(&I2C_USBPD, address, REG_ACTIVE_CONTRACT_PDO, value, sizeof(value));
if (res == 7) {
+14 -4
View File
@@ -34,8 +34,13 @@ int16_t i2c_send(struct I2C *i2c, uint8_t addr, uint8_t *data, uint16_t length)
return res;
}
int16_t i2c_get(struct I2C *i2c, uint8_t addr, uint8_t reg, uint8_t *data, uint16_t length)
__reentrant {
int16_t i2c_get(
struct I2C *i2c,
uint8_t addr,
uint8_t reg,
uint8_t *data,
uint16_t length
) __reentrant {
int16_t res = 0;
res = i2c_start(i2c, addr, false);
@@ -49,8 +54,13 @@ int16_t i2c_get(struct I2C *i2c, uint8_t addr, uint8_t reg, uint8_t *data, uint1
return i2c_recv(i2c, addr, data, length);
}
int16_t i2c_set(struct I2C *i2c, uint8_t addr, uint8_t reg, uint8_t *data, uint16_t length)
__reentrant {
int16_t i2c_set(
struct I2C *i2c,
uint8_t addr,
uint8_t reg,
uint8_t *data,
uint16_t length
) __reentrant {
int16_t res = 0;
res = i2c_start(i2c, addr, false);
+6 -1
View File
@@ -95,7 +95,12 @@ void i2c_stop(struct I2C *i2c) {
i2c_reset(i2c, false);
}
static int16_t i2c_transaction(struct I2C *i2c, uint8_t *data, uint16_t length, bool read) {
static int16_t i2c_transaction(
struct I2C *i2c,
uint8_t *data,
uint16_t length,
bool read
) __reentrant {
uint16_t i;
for (i = 0; i < length; i++) {
if (read) {