src/: Remove g_ prefixes and _g suffixes from variables

These were often used to distinguish CAR_GLOBAL variables that weren't
directly usable. Since we're getting rid of this special case, also get
rid of the marker.

This change was created using coccinelle and the following script:
	@match@
	type T;
	identifier old =~ "^(g_.*|.*_g)$";
	@@
	old

	@script:python global_marker@
	old << match.old;
	new;
	@@
	new = old
	if old[0:2] == "g_":
	  new = new[2:]

	if new[-2:] == "_g":
	  new = new[:-2]

	coccinelle.new = new

	@@
	identifier match.old, global_marker.new;
	@@
	- old
	+ new

	@@
	type T;
	identifier match.old, global_marker.new;
	@@
	- T old;
	+ T new;

	@@
	type T;
	identifier match.old, global_marker.new;
	@@
	- T old
	+ T new
	 = ...;

There were some manual fixups: Some code still uses the global/local
variable naming scheme, so keep g_* there, and some variable names
weren't completely rewritten.

Change-Id: I4936ff9780a0d3ed9b8b539772bc48887f8d5eed
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/37358
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-by: HAOUAS Elyes <ehaouas@noos.fr>
This commit is contained in:
Patrick Georgi
2019-11-29 11:47:47 +01:00
parent ae64f22e8d
commit c9b13594eb
17 changed files with 301 additions and 298 deletions

View File

@@ -22,11 +22,11 @@
#define LINE_BUFFER_SIZE 128
#define READ_BUFFER_SIZE 0x100
static const struct region_device *g_rdev_ptr;
static struct region_device g_rdev;
static uint8_t g_line_buffer[LINE_BUFFER_SIZE];
static size_t g_offset;
static size_t g_line_offset;
static const struct region_device *rdev_ptr;
static struct region_device rdev;
static uint8_t line_buffer[LINE_BUFFER_SIZE];
static size_t offset;
static size_t line_offset;
void flashconsole_init(void)
{
@@ -36,11 +36,11 @@ void flashconsole_init(void)
size_t len = READ_BUFFER_SIZE;
size_t i;
if (fmap_locate_area_as_rdev_rw("CONSOLE", &g_rdev)) {
if (fmap_locate_area_as_rdev_rw("CONSOLE", &rdev)) {
printk(BIOS_INFO, "Can't find 'CONSOLE' area in FMAP\n");
return;
}
size = region_device_sz(&g_rdev);
size = region_device_sz(&rdev);
/*
* We need to check the region until we find a 0xff indicating
@@ -56,7 +56,7 @@ void flashconsole_init(void)
// Fill the buffer on first iteration
if (i == 0) {
len = min(READ_BUFFER_SIZE, size - offset);
if (rdev_readat(&g_rdev, buffer, offset, len) != len)
if (rdev_readat(&rdev, buffer, offset, len) != len)
return;
}
if (buffer[i] == 0xff) {
@@ -75,29 +75,29 @@ void flashconsole_init(void)
return;
}
g_offset = offset;
g_rdev_ptr = &g_rdev;
offset = offset;
rdev_ptr = &rdev;
}
void flashconsole_tx_byte(unsigned char c)
{
if (!g_rdev_ptr)
if (!rdev_ptr)
return;
size_t region_size = region_device_sz(g_rdev_ptr);
size_t region_size = region_device_sz(rdev_ptr);
g_line_buffer[g_line_offset++] = c;
line_buffer[line_offset++] = c;
if (g_line_offset >= LINE_BUFFER_SIZE ||
g_offset + g_line_offset >= region_size || c == '\n') {
if (line_offset >= LINE_BUFFER_SIZE ||
offset + line_offset >= region_size || c == '\n') {
flashconsole_tx_flush();
}
}
void flashconsole_tx_flush(void)
{
size_t offset = g_offset;
size_t len = g_line_offset;
size_t offset = offset;
size_t len = line_offset;
size_t region_size;
static int busy;
@@ -107,23 +107,23 @@ void flashconsole_tx_flush(void)
if (busy)
return;
if (!g_rdev_ptr)
if (!rdev_ptr)
return;
busy = 1;
region_size = region_device_sz(g_rdev_ptr);
region_size = region_device_sz(rdev_ptr);
if (offset + len >= region_size)
len = region_size - offset;
if (rdev_writeat(&g_rdev, g_line_buffer, offset, len) != len)
if (rdev_writeat(&rdev, line_buffer, offset, len) != len)
return;
// If the region is full, stop future write attempts
if (offset + len >= region_size)
return;
g_offset = offset + len;
g_line_offset = 0;
offset = offset + len;
line_offset = 0;
busy = 0;
}

View File

@@ -39,10 +39,10 @@
#define CR50_TIMEOUT_INIT_MS 30000 /* Very long timeout for TPM init */
/* SPI slave structure for TPM device. */
static struct spi_slave g_spi_slave;
static struct spi_slave spi_slave;
/* Cached TPM device identification. */
static struct tpm2_info g_tpm_info;
static struct tpm2_info tpm_info;
/*
* TODO(vbendeb): make CONFIG_DEBUG_TPM an int to allow different level of
@@ -60,7 +60,7 @@ typedef struct {
void tpm2_get_info(struct tpm2_info *info)
{
*info = g_tpm_info;
*info = tpm_info;
}
__weak int tis_plat_irq_status(void)
@@ -133,9 +133,9 @@ static int start_transaction(int read_write, size_t bytes, unsigned int addr)
if (wakeup_needed) {
/* Just in case Cr50 is asleep. */
spi_claim_bus(&g_spi_slave);
spi_claim_bus(&spi_slave);
udelay(1);
spi_release_bus(&g_spi_slave);
spi_release_bus(&spi_slave);
udelay(100);
}
@@ -158,7 +158,7 @@ static int start_transaction(int read_write, size_t bytes, unsigned int addr)
header.body[i + 1] = (addr >> (8 * (2 - i))) & 0xff;
/* CS assert wakes up the slave. */
spi_claim_bus(&g_spi_slave);
spi_claim_bus(&spi_slave);
/*
* The TCG TPM over SPI specification introduces the notion of SPI
@@ -185,7 +185,7 @@ static int start_transaction(int read_write, size_t bytes, unsigned int addr)
* to require to stall the master, this would present an issue.
* crosbug.com/p/52132 has been opened to track this.
*/
spi_xfer(&g_spi_slave, header.body, sizeof(header.body), NULL, 0);
spi_xfer(&spi_slave, header.body, sizeof(header.body), NULL, 0);
/*
* Now poll the bus until TPM removes the stall bit. Give it up to 100
@@ -196,10 +196,10 @@ static int start_transaction(int read_write, size_t bytes, unsigned int addr)
do {
if (stopwatch_expired(&sw)) {
printk(BIOS_ERR, "TPM flow control failure\n");
spi_release_bus(&g_spi_slave);
spi_release_bus(&spi_slave);
return 0;
}
spi_xfer(&g_spi_slave, NULL, 0, &byte, 1);
spi_xfer(&spi_slave, NULL, 0, &byte, 1);
} while (!(byte & 1));
return 1;
}
@@ -267,7 +267,7 @@ static void trace_dump(const char *prefix, uint32_t reg,
*/
static void write_bytes(const void *buffer, size_t bytes)
{
spi_xfer(&g_spi_slave, buffer, bytes, NULL, 0);
spi_xfer(&spi_slave, buffer, bytes, NULL, 0);
}
/*
@@ -276,7 +276,7 @@ static void write_bytes(const void *buffer, size_t bytes)
*/
static void read_bytes(void *buffer, size_t bytes)
{
spi_xfer(&g_spi_slave, NULL, 0, buffer, bytes);
spi_xfer(&spi_slave, NULL, 0, buffer, bytes);
}
/*
@@ -291,7 +291,7 @@ static int tpm2_write_reg(unsigned int reg_number, const void *buffer, size_t by
if (!start_transaction(false, bytes, reg_number))
return 0;
write_bytes(buffer, bytes);
spi_release_bus(&g_spi_slave);
spi_release_bus(&spi_slave);
return 1;
}
@@ -309,7 +309,7 @@ static int tpm2_read_reg(unsigned int reg_number, void *buffer, size_t bytes)
return 0;
}
read_bytes(buffer, bytes);
spi_release_bus(&g_spi_slave);
spi_release_bus(&spi_slave);
trace_dump("R", reg_number, bytes, buffer, 0);
return 1;
}
@@ -417,7 +417,7 @@ int tpm2_init(struct spi_slave *spi_if)
uint8_t cmd;
int retries;
memcpy(&g_spi_slave, spi_if, sizeof(*spi_if));
memcpy(&spi_slave, spi_if, sizeof(*spi_if));
/* clear any pending IRQs */
tis_plat_irq_status();
@@ -474,15 +474,15 @@ int tpm2_init(struct spi_slave *spi_if)
* structure.
*/
tpm2_read_reg(TPM_RID_REG, &cmd, sizeof(cmd));
g_tpm_info.vendor_id = did_vid & 0xffff;
g_tpm_info.device_id = did_vid >> 16;
g_tpm_info.revision = cmd;
tpm_info.vendor_id = did_vid & 0xffff;
tpm_info.device_id = did_vid >> 16;
tpm_info.revision = cmd;
printk(BIOS_INFO, "Connected to device vid:did:rid of %4.4x:%4.4x:%2.2x\n",
g_tpm_info.vendor_id, g_tpm_info.device_id, g_tpm_info.revision);
tpm_info.vendor_id, tpm_info.device_id, tpm_info.revision);
/* Let's report device FW version if available. */
if (g_tpm_info.vendor_id == 0x1ae0) {
if (tpm_info.vendor_id == 0x1ae0) {
int chunk_count = 0;
size_t chunk_size;
/*
@@ -611,7 +611,7 @@ size_t tpm2_process_command(const void *tpm2_command, size_t command_size,
const int HEADER_SIZE = 6;
/* Do not try using an uninitialized TPM. */
if (!g_tpm_info.vendor_id)
if (!tpm_info.vendor_id)
return 0;
/* Skip the two byte tag, read the size field. */