Skip to content

Commit 5e98aa3

Browse files
committed
Make more functions reentrant
Reduces compile time DSEG usage. Signed-off-by: Michał Kopeć <michal.kopec@3mdeb.com>
1 parent ad7e15c commit 5e98aa3

File tree

8 files changed

+24
-18
lines changed

8 files changed

+24
-18
lines changed

src/board/system76/common/dgpu.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,14 @@ uint8_t dgpu_get_d_notify_level(bool ac) {
9494
return 0;
9595
}
9696

97-
int16_t dgpu_set_fan_curve(uint8_t count, struct FanPoint *points) {
97+
int16_t dgpu_set_fan_curve(uint8_t count, struct FanPoint *points) __reentrant {
98+
int i;
9899
if (count != FAN.points_size) {
99100
TRACE("DGPU: Incorrect number of fan points: %d, expected %d\n", count, FAN.points_size);
100101
return -1;
101102
}
102103

103-
for (int i = 0; i < count; ++i) {
104+
for (i = 0; i < count; ++i) {
104105
TRACE("DGPU: fan curve t%d: %d, d%d: %d\n", i, points[i].temp, i, points[i].duty);
105106
FAN.points[i].temp = points[i].temp;
106107
FAN.points[i].duty = points[i].duty;

src/board/system76/common/fan.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,13 @@ uint8_t fan_smooth(uint8_t last_duty, uint8_t duty) __reentrant {
159159
return next_duty;
160160
}
161161

162-
uint8_t fan_points_are_valid(uint8_t count, struct FanPoint *points) {
162+
uint8_t fan_points_are_valid(uint8_t count, struct FanPoint *points) __reentrant {
163+
int i;
163164
/*
164165
* Fan curve speeds have to be non-decreasing.
165166
* Fan curve temperatures have to be increasing.
166167
*/
167-
for (int i = 1; i < count; i++) {
168+
for (i = 1; i < count; i++) {
168169
if (points[i].temp <= points[i - 1].temp || points[i].duty < points[i - 1].duty)
169170
return false;
170171
}

src/board/system76/common/include/board/dgpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern int16_t dgpu_temp;
1919
#endif // HAVE_DGPU
2020

2121
void dgpu_init(void);
22-
int16_t dgpu_set_fan_curve(uint8_t count, struct FanPoint *points);
22+
int16_t dgpu_set_fan_curve(uint8_t count, struct FanPoint *points) __reentrant;
2323
uint8_t dgpu_get_fan_duty(void);
2424
uint8_t dgpu_get_d_notify_level(bool ac);
2525
void set_mux_ctrl(void);

src/board/system76/common/include/board/fan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant;
6464
uint8_t fan_heatup(const struct Fan *fan, uint8_t duty) __reentrant;
6565
uint8_t fan_cooldown(const struct Fan *fan, uint8_t duty) __reentrant;
6666
uint8_t fan_smooth(uint8_t last_duty, uint8_t duty) __reentrant;
67-
uint8_t fan_points_are_valid(uint8_t count, struct FanPoint *points);
67+
uint8_t fan_points_are_valid(uint8_t count, struct FanPoint *points) __reentrant;
6868

6969
#endif // _BOARD_FAN_H

src/board/system76/common/include/board/peci.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ extern uint8_t t_junction;
2929

3030
void peci_init(void);
3131
bool peci_available(void);
32-
int16_t peci_set_fan_curve(uint8_t count, struct FanPoint *points);
33-
int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data);
34-
int16_t peci_rd_pkg_config(uint8_t index, uint16_t param, uint32_t *value);
32+
int16_t peci_set_fan_curve(uint8_t count, struct FanPoint *points) __reentrant;
33+
int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) __reentrant;
34+
int16_t peci_rd_pkg_config(uint8_t index, uint16_t param, uint32_t *value) __reentrant;
3535
uint8_t peci_get_fan_duty(void);
3636

3737
#endif // _BOARD_PECI_H

src/board/system76/common/peci.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ static struct Fan FAN = {
6161
.interpolate = SMOOTH_FANS != 0,
6262
};
6363

64-
int16_t peci_set_fan_curve(uint8_t count, struct FanPoint *points) {
64+
int16_t peci_set_fan_curve(uint8_t count, struct FanPoint *points) __reentrant {
65+
int i;
6566
if (count != FAN.points_size) {
6667
TRACE("PECI: Incorrect number of fan points: %d, expected %d\n", count, FAN.points_size);
6768
return -1;
6869
}
6970

70-
for (int i = 0; i < count; ++i) {
71+
for (i = 0; i < count; ++i) {
7172
TRACE("PECI: fan curve t%d: %d, d%d: %d\n", i, points[i].temp, i, points[i].duty);
7273
FAN.points[i].temp = points[i].temp;
7374
FAN.points[i].duty = points[i].duty;
@@ -347,9 +348,10 @@ bool peci_get_temp(int16_t *data) {
347348

348349
// Returns positive completion code on success, negative completion code or
349350
// negative (0x1000 | status register) on PECI hardware error
350-
int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
351+
int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) __reentrant {
351352
int retry = 50; // TODO how many retries are appropriate?
352353
uint8_t cc = HORDDR;
354+
uint8_t status;
353355

354356
// Wait for any in-progress transaction to complete
355357
while (HOSTAR & BIT(0)) {}
@@ -387,7 +389,7 @@ int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
387389
// Wait for command completion
388390
while (!(HOSTAR & BIT(1))) {}
389391

390-
uint8_t status = HOSTAR;
392+
status = HOSTAR;
391393
if (status & 0xEC) {
392394
ERROR("peci_wr_pkg_config: hardware error: 0x%02X\n", status);
393395
// Clear status
@@ -411,9 +413,11 @@ int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
411413
return -((int16_t)cc);
412414
}
413415

414-
int16_t peci_rd_pkg_config(uint8_t index, uint16_t param, uint32_t *value) {
416+
int16_t peci_rd_pkg_config(uint8_t index, uint16_t param, uint32_t *value) __reentrant {
415417
int retry = 50; // TODO how many retries are appropriate?
416418
uint8_t cc = HORDDR;
419+
uint8_t status;
420+
int i;
417421
*value = 0;
418422

419423
// 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) {
447451
// Wait for command completion
448452
while (!(HOSTAR & BIT(1))) {}
449453

450-
uint8_t status = HOSTAR;
454+
status = HOSTAR;
451455
if (status & 0xEC) {
452456
ERROR("peci_rd_pkg_config: hardware error: 0x%02X\n", status);
453457
// Clear status
@@ -466,7 +470,7 @@ int16_t peci_rd_pkg_config(uint8_t index, uint16_t param, uint32_t *value) {
466470
return -((int16_t)cc);
467471
} else {
468472
// Read data if finished successfully
469-
for (int i = 0; i < 4; ++i) {
473+
for (i = 0; i < 4; ++i) {
470474
*value |= (((uint32_t)HORDDR) << (8 * i));
471475
}
472476

src/board/system76/common/usbpd/tps65987.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ enum {
6565

6666
#define PDO_CURRENT_MA(pdo) (((pdo) & 0x3FF) * 10)
6767

68-
static int16_t usbpd_current_limit(uint8_t address) {
68+
static int16_t usbpd_current_limit(uint8_t address) __reentrant {
6969
uint8_t value[7] = { 0 };
7070
int16_t res = i2c_get(&I2C_USBPD, address, REG_ACTIVE_CONTRACT_PDO, value, sizeof(value));
7171
if (res == 7) {

src/ec/ite/i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void i2c_stop(struct I2C *i2c) {
9595
i2c_reset(i2c, false);
9696
}
9797

98-
static int16_t i2c_transaction(struct I2C *i2c, uint8_t *data, uint16_t length, bool read) {
98+
static int16_t i2c_transaction(struct I2C *i2c, uint8_t *data, uint16_t length, bool read) __reentrant {
9999
uint16_t i;
100100
for (i = 0; i < length; i++) {
101101
if (read) {

0 commit comments

Comments
 (0)