summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorLee Leahy <leroy.p.leahy@intel.com>2016-04-29 15:07:19 -0700
committerLeroy P Leahy <leroy.p.leahy@intel.com>2016-05-04 19:21:40 +0200
commit564dc9c7c89a94ff1b7803ef9937ca4f0dd95809 (patch)
tree93b3d344c243d8a0c48bdd8f7b23d0e8a45cfdc5 /src/lib
parentd3fccfbc41988b110d6861f53ee3b8908e90e422 (diff)
downloadcoreboot-564dc9c7c89a94ff1b7803ef9937ca4f0dd95809.tar.xz
lib/reg_script: Add display support
Add the ability to enable the display of the script: * Added REG_SCRIPT_COMMAND_DISPLAY to enable and disable display output * Added context values to manage display support * display_state - Updated by the command to enable or disable display * display_features - May be updated by step routine to control what the step displays for register and value * display_prefix - Prefix to display before register data * Added REG_SCRIPT_DISPLAY_ON and REG_SCRIPT_DISPLAY_OFF macros to control the display from the register script * Added REG_SCRIPT_DISPLAY_REGISTER and REG_SCRIPT_DISPLAY_VALUE as two features of the common display. With these features enabled the following is output: * Write: <optional prefix> register <-- value * Read: <optional prefix> register --> value TEST=Build and run on Galileo Gen2 Change-Id: If0d4d61ed8ef48ec20082b327f358fd1987e3fb9 Signed-off-by: Lee Leahy <leroy.p.leahy@intel.com> Reviewed-on: https://review.coreboot.org/14553 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/reg_script.c82
1 files changed, 71 insertions, 11 deletions
diff --git a/src/lib/reg_script.c b/src/lib/reg_script.c
index 9e20134e85..ace9325f13 100644
--- a/src/lib/reg_script.c
+++ b/src/lib/reg_script.c
@@ -415,24 +415,62 @@ static const struct reg_script_bus_entry
return NULL;
}
+static void reg_script_display(struct reg_script_context *ctx,
+ const struct reg_script *step, const char *arrow, uint64_t value)
+{
+ /* Display the register address and data */
+ if (ctx->display_prefix != NULL)
+ printk(BIOS_INFO, "%s: ", ctx->display_prefix);
+ if (ctx->display_features & REG_SCRIPT_DISPLAY_REGISTER)
+ printk(BIOS_INFO, "0x%08x %s ", step->reg, arrow);
+ if (ctx->display_features & REG_SCRIPT_DISPLAY_VALUE)
+ switch (step->size) {
+ case REG_SCRIPT_SIZE_8:
+ printk(BIOS_INFO, "0x%02x\n", (uint8_t)value);
+ break;
+ case REG_SCRIPT_SIZE_16:
+ printk(BIOS_INFO, "0x%04x\n", (int16_t)value);
+ break;
+ case REG_SCRIPT_SIZE_32:
+ printk(BIOS_INFO, "0x%08x\n", (uint32_t)value);
+ break;
+ default:
+ printk(BIOS_INFO, "0x%016llx\n", value);
+ break;
+ }
+}
+
static uint64_t reg_script_read(struct reg_script_context *ctx)
{
const struct reg_script *step = reg_script_get_step(ctx);
+ uint64_t value = 0;
switch (step->type) {
case REG_SCRIPT_TYPE_PCI:
- return reg_script_read_pci(ctx);
+ ctx->display_prefix = "PCI";
+ value = reg_script_read_pci(ctx);
+ break;
case REG_SCRIPT_TYPE_IO:
- return reg_script_read_io(ctx);
+ ctx->display_prefix = "IO";
+ value = reg_script_read_io(ctx);
+ break;
case REG_SCRIPT_TYPE_MMIO:
- return reg_script_read_mmio(ctx);
+ ctx->display_prefix = "MMIO";
+ value = reg_script_read_mmio(ctx);
+ break;
case REG_SCRIPT_TYPE_RES:
- return reg_script_read_res(ctx);
+ ctx->display_prefix = "RES";
+ value = reg_script_read_res(ctx);
+ break;
case REG_SCRIPT_TYPE_MSR:
- return reg_script_read_msr(ctx);
+ ctx->display_prefix = "MSR";
+ value = reg_script_read_msr(ctx);
+ break;
#if HAS_IOSF
case REG_SCRIPT_TYPE_IOSF:
- return reg_script_read_iosf(ctx);
+ ctx->display_prefix = "IOSF";
+ value = reg_script_read_iosf(ctx);
+ break;
#endif /* HAS_IOSF */
default:
{
@@ -441,14 +479,19 @@ static uint64_t reg_script_read(struct reg_script_context *ctx)
/* Read from the platform specific bus */
bus = find_bus(step);
if (NULL != bus)
- return bus->reg_script_read(ctx);
+ value = bus->reg_script_read(ctx);
+ break;
}
printk(BIOS_ERR,
"Unsupported read type (0x%x) for this device!\n",
step->type);
- break;
+ return 0;
}
- return 0;
+
+ /* Display the register address and data */
+ if (ctx->display_features)
+ reg_script_display(ctx, step, "-->", value);
+ return value;
}
static void reg_script_write(struct reg_script_context *ctx)
@@ -457,22 +500,28 @@ static void reg_script_write(struct reg_script_context *ctx)
switch (step->type) {
case REG_SCRIPT_TYPE_PCI:
+ ctx->display_prefix = "PCI";
reg_script_write_pci(ctx);
break;
case REG_SCRIPT_TYPE_IO:
+ ctx->display_prefix = "IO";
reg_script_write_io(ctx);
break;
case REG_SCRIPT_TYPE_MMIO:
+ ctx->display_prefix = "MMIO";
reg_script_write_mmio(ctx);
break;
case REG_SCRIPT_TYPE_RES:
+ ctx->display_prefix = "RES";
reg_script_write_res(ctx);
break;
case REG_SCRIPT_TYPE_MSR:
+ ctx->display_prefix = "MSR";
reg_script_write_msr(ctx);
break;
#if HAS_IOSF
case REG_SCRIPT_TYPE_IOSF:
+ ctx->display_prefix = "IOSF";
reg_script_write_iosf(ctx);
break;
#endif /* HAS_IOSF */
@@ -484,14 +533,18 @@ static void reg_script_write(struct reg_script_context *ctx)
bus = find_bus(step);
if (NULL != bus) {
bus->reg_script_write(ctx);
- return;
+ break;
}
}
printk(BIOS_ERR,
"Unsupported write type (0x%x) for this device!\n",
step->type);
- break;
+ return;
}
+
+ /* Display the register address and data */
+ if (ctx->display_features)
+ reg_script_display(ctx, step, "<--", step->value);
}
static void reg_script_rmw(struct reg_script_context *ctx)
@@ -557,6 +610,8 @@ static void reg_script_run_step(struct reg_script_context *ctx,
{
uint64_t value = 0, try;
+ ctx->display_features = ctx->display_state;
+ ctx->display_prefix = NULL;
switch (step->command) {
case REG_SCRIPT_COMMAND_READ:
(void)reg_script_read(ctx);
@@ -589,6 +644,10 @@ static void reg_script_run_step(struct reg_script_context *ctx,
case REG_SCRIPT_COMMAND_NEXT:
reg_script_run_next(ctx, step->next);
break;
+ case REG_SCRIPT_COMMAND_DISPLAY:
+ ctx->display_state = step->value;
+ break;
+
default:
printk(BIOS_WARNING, "Invalid command: %08x\n",
step->command);
@@ -624,6 +683,7 @@ void reg_script_run_on_dev(device_t dev, const struct reg_script *step)
{
struct reg_script_context ctx;
+ ctx.display_state = REG_SCRIPT_DISPLAY_NOTHING;
reg_script_set_dev(&ctx, dev);
reg_script_set_step(&ctx, step);
reg_script_run_with_context(&ctx);