Leroy P Leahy (leroy.p.leahy@intel.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/14553
-gerrit
commit a04af463740f77f8fabe76800babc0c1e0cb1a1b Author: Lee Leahy leroy.p.leahy@intel.com Date: Fri Apr 29 15:07:19 2016 -0700
lib/reg_script: Add display support
Add the ability to enable the display of the script.
TEST=Build and run on Galileo Gen2
Change-Id: If0d4d61ed8ef48ec20082b327f358fd1987e3fb9 Signed-off-by: Lee Leahy leroy.p.leahy@intel.com --- src/include/reg_script.h | 20 +++++++ src/lib/reg_script.c | 141 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 150 insertions(+), 11 deletions(-)
diff --git a/src/include/reg_script.h b/src/include/reg_script.h index da01481..a6e9f94 100644 --- a/src/include/reg_script.h +++ b/src/include/reg_script.h @@ -47,6 +47,11 @@ enum { REG_SCRIPT_COMMAND_POLL, REG_SCRIPT_COMMAND_SET_DEV, REG_SCRIPT_COMMAND_NEXT, + REG_SCRIPT_COMMAND_DISPLAY_ON, + REG_SCRIPT_COMMAND_DISPLAY_OFF, + + /* Insert new types above this comment */ + REG_SCRIPT_COMMAND_END, };
@@ -132,6 +137,19 @@ 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 \ + _REG_SCRIPT_ENCODE_RAW(REG_SCRIPT_COMMAND_DISPLAY_OFF, \ + REG_SCRIPT_TYPE_PCI, 0, 0, 0, 0, 0, 0) +#define REG_SCRIPT_DISPLAY_ON \ + _REG_SCRIPT_ENCODE_RAW(REG_SCRIPT_COMMAND_DISPLAY_ON, \ + REG_SCRIPT_TYPE_PCI, 0, 0, 0, 0, 0, 0) + /* * PCI */ @@ -416,5 +434,7 @@ IS_ENABLED(CONFIG_SOC_INTEL_FSP_BAYTRAIL)
void reg_script_run(const struct reg_script *script); void reg_script_run_on_dev(device_t dev, const struct reg_script *step); +uint8_t reg_script_get_display_features(void); +void reg_script_set_display_features(uint8_t display_features);
#endif /* REG_SCRIPT_H */ diff --git a/src/lib/reg_script.c b/src/lib/reg_script.c index 9e20134..f2b92ce 100644 --- a/src/lib/reg_script.c +++ b/src/lib/reg_script.c @@ -13,6 +13,7 @@ * GNU General Public License for more details. */
+#include <arch/early_variables.h> #include <arch/io.h> #include <console/console.h> #include <delay.h> @@ -40,6 +41,20 @@ #define EMPTY_DEV NULL #endif
+static uint8_t reg_script_display_features CAR_GLOBAL; + +uint8_t reg_script_get_display_features(void) +{ + /* Enable the read/write routines to perserve the display settings */ + return car_get_var(reg_script_display_features); +} + +void reg_script_set_display_features(uint8_t display_features) +{ + /* Allow register routines to override the default display behavior */ + car_set_var(reg_script_display_features, display_features); +} + static inline void reg_script_set_dev(struct reg_script_context *ctx, device_t dev) { @@ -417,22 +432,44 @@ static const struct reg_script_bus_entry
static uint64_t reg_script_read(struct reg_script_context *ctx) { + /* Save the default display behavior */ + uint8_t display = reg_script_get_display_features(); const struct reg_script *step = reg_script_get_step(ctx); + uint8_t updated_display; + uint64_t value = 0;
switch (step->type) { case REG_SCRIPT_TYPE_PCI: - return reg_script_read_pci(ctx); + if (display) + printk(BIOS_INFO, "PCI: "); + value = reg_script_read_pci(ctx); + break; case REG_SCRIPT_TYPE_IO: - return reg_script_read_io(ctx); + if (display) + printk(BIOS_INFO, "IO: "); + value = reg_script_read_io(ctx); + break; case REG_SCRIPT_TYPE_MMIO: - return reg_script_read_mmio(ctx); + if (display) + printk(BIOS_INFO, "MMIO: "); + value = reg_script_read_mmio(ctx); + break; case REG_SCRIPT_TYPE_RES: - return reg_script_read_res(ctx); + if (display) + printk(BIOS_INFO, "RES: "); + value = reg_script_read_res(ctx); + break; case REG_SCRIPT_TYPE_MSR: - return reg_script_read_msr(ctx); + if (display) + printk(BIOS_INFO, "MSR: "); + value = reg_script_read_msr(ctx); + break; #if HAS_IOSF case REG_SCRIPT_TYPE_IOSF: - return reg_script_read_iosf(ctx); + if (display) + printk(BIOS_INFO, "IOSF: "); + value = reg_script_read_iosf(ctx); + break; #endif /* HAS_IOSF */ default: { @@ -441,38 +478,82 @@ 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; + + /* Determine the display behavior as modified by the register routine */ + updated_display = reg_script_get_display_features(); + + /* Display the register address and data */ + if (updated_display) { + if (updated_display & REG_SCRIPT_DISPLAY_REGISTER) + printk(BIOS_INFO, "0x%08x --> ", step->reg); + if (updated_display & 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; + } + } + + /* Restore the default display behavior */ + reg_script_set_display_features(display); + return value; }
static void reg_script_write(struct reg_script_context *ctx) { + /* Save the default display behavior */ + uint8_t display = reg_script_get_display_features(); const struct reg_script *step = reg_script_get_step(ctx); + uint8_t updated_display; + uint64_t value;
switch (step->type) { case REG_SCRIPT_TYPE_PCI: + if (display) + printk(BIOS_INFO, "PCI: "); reg_script_write_pci(ctx); break; case REG_SCRIPT_TYPE_IO: + if (display) + printk(BIOS_INFO, "IO: "); reg_script_write_io(ctx); break; case REG_SCRIPT_TYPE_MMIO: + if (display) + printk(BIOS_INFO, "MMIO: "); reg_script_write_mmio(ctx); break; case REG_SCRIPT_TYPE_RES: + if (display) + printk(BIOS_INFO, "RES: "); reg_script_write_res(ctx); break; case REG_SCRIPT_TYPE_MSR: + if (display) + printk(BIOS_INFO, "MSR: "); reg_script_write_msr(ctx); break; #if HAS_IOSF case REG_SCRIPT_TYPE_IOSF: + if (display) + printk(BIOS_INFO, "IOSF: "); reg_script_write_iosf(ctx); break; #endif /* HAS_IOSF */ @@ -484,14 +565,42 @@ 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; + } + + /* Determine the display behavior as modified by the register routine */ + updated_display = reg_script_get_display_features(); + + /* Display the register address and data */ + if (updated_display) { + if (updated_display & REG_SCRIPT_DISPLAY_REGISTER) + printk(BIOS_INFO, "0x%08x <-- ", step->reg); + value = step->value; + if (updated_display & 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", (uint16_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; + } } + + /* Restore the default display behavior */ + reg_script_set_display_features(display); }
static void reg_script_rmw(struct reg_script_context *ctx) @@ -589,6 +698,13 @@ 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_ON: + reg_script_set_display_features(REG_SCRIPT_DISPLAY_ALL); + break; + case REG_SCRIPT_COMMAND_DISPLAY_OFF: + reg_script_set_display_features(REG_SCRIPT_DISPLAY_NOTHING); + break; + default: printk(BIOS_WARNING, "Invalid command: %08x\n", step->command); @@ -607,6 +723,9 @@ static void reg_script_run_with_context(struct reg_script_context *ctx) reg_script_run_step(ctx, step); reg_script_set_step(ctx, step + 1); } + + /* Turn off the display at the end of the script */ + reg_script_set_display_features(REG_SCRIPT_DISPLAY_NOTHING); }
static void reg_script_run_next(struct reg_script_context *prev_ctx,