diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/reg_script.h | 22 | ||||
-rw-r--r-- | src/lib/reg_script.c | 82 |
2 files changed, 93 insertions, 11 deletions
diff --git a/src/include/reg_script.h b/src/include/reg_script.h index da01481c3f..d7ed326af3 100644 --- a/src/include/reg_script.h +++ b/src/include/reg_script.h @@ -47,6 +47,10 @@ enum { REG_SCRIPT_COMMAND_POLL, REG_SCRIPT_COMMAND_SET_DEV, REG_SCRIPT_COMMAND_NEXT, + REG_SCRIPT_COMMAND_DISPLAY, + + /* Insert new types above this comment */ + REG_SCRIPT_COMMAND_END, }; @@ -92,6 +96,9 @@ struct reg_script_context { device_t dev; struct resource *res; const struct reg_script *step; + uint8_t display_state; /* Only modified by reg_script_run_step */ + uint8_t display_features; /* Step routine modifies to control display */ + const char *display_prefix; /* Prefix tag to display */ }; struct reg_script_bus_entry { @@ -132,6 +139,21 @@ struct reg_script_bus_entry { .res_index = res_index_, \ } +/* Display control */ +#define REG_SCRIPT_DISPLAY_ALL 0xff +#define REG_SCRIPT_DISPLAY_REGISTER 0x02 +#define REG_SCRIPT_DISPLAY_VALUE 0x01 +#define REG_SCRIPT_DISPLAY_NOTHING 0 + +#define REG_SCRIPT_DISPLAY_OFF \ + { .command = REG_SCRIPT_COMMAND_DISPLAY, \ + .value = REG_SCRIPT_DISPLAY_NOTHING, \ + } +#define REG_SCRIPT_DISPLAY_ON \ + { .command = REG_SCRIPT_COMMAND_DISPLAY, \ + .value = REG_SCRIPT_DISPLAY_ALL, \ + } + /* * PCI */ 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); |