summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2022-12-27 11:00:13 +1100
committerEdward O'Callaghan <quasisec@chromium.org>2023-03-28 00:36:36 +0000
commit50f812cfc705743a46132f54057b42e71d0f6350 (patch)
treefe3d339625df343fcd859b85d4da895dc4235f7a
parentc65379cba274fe4c6fd1054079d19ebb628e04d3 (diff)
downloadflashrom-git-50f812cfc705743a46132f54057b42e71d0f6350.tar.gz
dmi.c: Pass is_laptop by ref into dmi
Prefix the remaining global cases with `g_` to avoid shadowing issues and for easy greping. Change-Id: I3d5ad6c0623269492d775a99a947fd6fe26c5f91 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/71622 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Sam McNally <sammc@google.com>
-rw-r--r--board_enable.c4
-rw-r--r--dmi.c37
-rw-r--r--include/programmer.h4
-rw-r--r--internal.c17
4 files changed, 31 insertions, 31 deletions
diff --git a/board_enable.c b/board_enable.c
index f0df211e..0531fab2 100644
--- a/board_enable.c
+++ b/board_enable.c
@@ -2282,7 +2282,7 @@ static int it8718f_gpio63_raise(void)
static int p2_not_a_laptop(void)
{
/* label this board as not a laptop */
- is_laptop = 0;
+ g_is_laptop = 0;
msg_pdbg("Laptop detection overridden by P2 board enable.\n");
return 0;
}
@@ -2292,7 +2292,7 @@ static int p2_not_a_laptop(void)
*/
static int p2_whitelist_laptop(void)
{
- is_laptop = 1;
+ g_is_laptop = 1;
g_laptop_ok = true;
msg_pdbg("Whitelisted laptop detected.\n");
return 0;
diff --git a/dmi.c b/dmi.c
index beeb10f3..94e47fb4 100644
--- a/dmi.c
+++ b/dmi.c
@@ -151,11 +151,11 @@ static char *dmi_string(const char *buf, uint8_t string_id, const char *limit)
return newbuf;
}
-static void dmi_chassis_type(uint8_t code)
+static int dmi_chassis_type(uint8_t code)
{
unsigned int i;
code &= 0x7f; /* bits 6:0 are chassis type, 7th bit is the lock bit */
- is_laptop = 2;
+ int is_laptop = 2;
for (i = 0; i < ARRAY_SIZE(dmi_chassis_types); i++) {
if (code == dmi_chassis_types[i].type) {
msg_pdbg("DMI string chassis-type: \"%s\"\n", dmi_chassis_types[i].name);
@@ -163,9 +163,10 @@ static void dmi_chassis_type(uint8_t code)
break;
}
}
+ return is_laptop;
}
-static void dmi_table(uint32_t base, uint16_t len, uint16_t num)
+static void dmi_table(uint32_t base, uint16_t len, uint16_t num, int *is_laptop)
{
unsigned int i = 0, j = 0;
@@ -198,7 +199,7 @@ static void dmi_table(uint32_t base, uint16_t len, uint16_t num)
if(data[0] == 3) {
if (data + 5 < limit)
- dmi_chassis_type(data[5]);
+ *is_laptop = dmi_chassis_type(data[5]);
else /* the table is broken, but laptop detection is optional, hence continue. */
msg_pwarn("DMI table is broken (chassis_type out of bounds)!\n");
} else
@@ -232,7 +233,7 @@ out:
}
#if SM_SUPPORT
-static int smbios_decode(uint8_t *buf)
+static int smbios_decode(uint8_t *buf, int *is_laptop)
{
/* TODO: other checks mentioned in the conformance guidelines? */
if (!dmi_checksum(buf, buf[0x05]) ||
@@ -240,23 +241,23 @@ static int smbios_decode(uint8_t *buf)
!dmi_checksum(buf + 0x10, 0x0F))
return 0;
- dmi_table(mmio_readl(buf + 0x18), mmio_readw(buf + 0x16), mmio_readw(buf + 0x1C));
+ dmi_table(mmio_readl(buf + 0x18), mmio_readw(buf + 0x16), mmio_readw(buf + 0x1C), is_laptop);
return 1;
}
#endif
-static int legacy_decode(uint8_t *buf)
+static int legacy_decode(uint8_t *buf, int *is_laptop)
{
if (!dmi_checksum(buf, 0x0F))
return 1;
- dmi_table(mmio_readl(buf + 0x08), mmio_readw(buf + 0x06), mmio_readw(buf + 0x0C));
+ dmi_table(mmio_readl(buf + 0x08), mmio_readw(buf + 0x06), mmio_readw(buf + 0x0C), is_laptop);
return 0;
}
-static int dmi_fill(void)
+static int dmi_fill(int *is_laptop)
{
size_t fp;
uint8_t *dmi_mem;
@@ -274,12 +275,12 @@ static int dmi_fill(void)
for (fp = 0; fp <= 0xFFF0; fp += 16) {
#if SM_SUPPORT
if (memcmp(dmi_mem + fp, "_SM_", 4) == 0 && fp <= 0xFFE0) {
- if (smbios_decode(dmi_mem + fp)) // FIXME: length check
+ if (smbios_decode(dmi_mem + fp), is_laptop) // FIXME: length check
goto out;
} else
#endif
if (memcmp(dmi_mem + fp, "_DMI_", 5) == 0)
- if (legacy_decode(dmi_mem + fp) == 0) {
+ if (legacy_decode(dmi_mem + fp, is_laptop) == 0) {
ret = 0;
goto out;
}
@@ -350,7 +351,7 @@ static char *get_dmi_string(const char *string_name)
return result;
}
-static int dmi_fill(void)
+static int dmi_fill(int *is_laptop)
{
unsigned int i;
char *chassis_type;
@@ -367,10 +368,10 @@ static int dmi_fill(void)
return 0; /* chassis-type handling is optional anyway */
msg_pdbg("DMI string chassis-type: \"%s\"\n", chassis_type);
- is_laptop = 2;
+ *is_laptop = 2;
for (i = 0; i < ARRAY_SIZE(dmi_chassis_types); i++) {
if (strcasecmp(chassis_type, dmi_chassis_types[i].name) == 0) {
- is_laptop = dmi_chassis_types[i].is_laptop;
+ *is_laptop = dmi_chassis_types[i].is_laptop;
break;
}
}
@@ -391,7 +392,7 @@ static int dmi_shutdown(void *data)
return 0;
}
-void dmi_init(void)
+void dmi_init(int *is_laptop)
{
/* Register shutdown function before we allocate anything. */
if (register_shutdown(dmi_shutdown, NULL)) {
@@ -399,11 +400,11 @@ void dmi_init(void)
return;
}
- /* dmi_fill fills the dmi_strings array, and if possible sets the global is_laptop variable. */
- if (dmi_fill() != 0)
+ /* dmi_fill fills the dmi_strings array, and if possible set the is_laptop parameter. */
+ if (dmi_fill(is_laptop) != 0)
return;
- switch (is_laptop) {
+ switch (*is_laptop) {
case 1:
msg_pdbg("Laptop detected via DMI.\n");
break;
diff --git a/include/programmer.h b/include/programmer.h
index 304a2166..ab482e68 100644
--- a/include/programmer.h
+++ b/include/programmer.h
@@ -244,7 +244,7 @@ int cb_check_image(const uint8_t *bios, unsigned int size);
/* dmi.c */
#if defined(__i386__) || defined(__x86_64__)
-void dmi_init(void);
+void dmi_init(int *is_laptop);
bool dmi_is_supported(void);
int dmi_match(const char *pattern);
#endif // defined(__i386__) || defined(__x86_64__)
@@ -263,7 +263,7 @@ extern int superio_count;
#endif
#if CONFIG_INTERNAL == 1
-extern int is_laptop;
+extern int g_is_laptop;
extern bool g_laptop_ok;
extern bool force_boardmismatch;
void probe_superio(void);
diff --git a/internal.c b/internal.c
index 0c23326a..5d836e50 100644
--- a/internal.c
+++ b/internal.c
@@ -27,7 +27,7 @@
#include "hwaccess_x86_io.h"
#endif
-int is_laptop = 0;
+int g_is_laptop = 0;
bool g_laptop_ok = false;
bool force_boardmismatch = false;
@@ -108,12 +108,11 @@ static int get_params(const struct programmer_cfg *cfg,
return 0;
}
-// FIXME: remove '_' suffix from parameters once global shadowing is fixed.
-static void report_nonwl_laptop_detected(int is_laptop_, bool laptop_ok)
+static void report_nonwl_laptop_detected(int is_laptop, bool laptop_ok)
{
- if (is_laptop_ && !laptop_ok) {
+ if (is_laptop && !laptop_ok) {
msg_pinfo("========================================================================\n");
- if (is_laptop_ == 1) {
+ if (is_laptop == 1) {
msg_pinfo("You seem to be running flashrom on an unknown laptop. Some\n"
"internal buses have been disabled for safety reasons.\n\n");
} else {
@@ -204,9 +203,9 @@ static int internal_init(const struct programmer_cfg *cfg)
}
}
- is_laptop = 2; /* Assume that we don't know by default. */
+ g_is_laptop = 2; /* Assume that we don't know by default. */
- dmi_init();
+ dmi_init(&g_is_laptop);
/* In case Super I/O probing would cause pretty explosions. */
board_handle_before_superio(force_boardenable);
@@ -229,7 +228,7 @@ static int internal_init(const struct programmer_cfg *cfg)
* this isn't a laptop. Board-enables may override this,
* non-legacy buses (SPI and opaque atm) are probed anyway.
*/
- if (is_laptop && !(g_laptop_ok || force_laptop || (not_a_laptop && is_laptop == 2)))
+ if (g_is_laptop && !(g_laptop_ok || force_laptop || (not_a_laptop && g_is_laptop == 2)))
internal_buses_supported = BUS_NONE;
/* try to enable it. Failure IS an option, since not all motherboards
@@ -258,7 +257,7 @@ static int internal_init(const struct programmer_cfg *cfg)
internal_par_init(internal_buses_supported);
/* Report if a non-whitelisted laptop is detected that likely uses a legacy bus. */
- report_nonwl_laptop_detected(is_laptop, g_laptop_ok);
+ report_nonwl_laptop_detected(g_is_laptop, g_laptop_ok);
ret = 0;