Evgeny Zinoviev has uploaded this change for review. ( https://review.coreboot.org/27776
Change subject: util/pmh7tool ......................................................................
util/pmh7tool
A tool that dumps PMH7 registers.
Change-Id: I05ccb5a9a861fe44efec794aafe1805062543d53 Signed-off-by: Evgeny Zinoviev me@ch1p.com --- A util/pmh7tool/Makefile A util/pmh7tool/pmh7tool.c A util/pmh7tool/pmh7tool.h 3 files changed, 96 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/76/27776/1
diff --git a/util/pmh7tool/Makefile b/util/pmh7tool/Makefile new file mode 100644 index 0000000..07a7a28 --- /dev/null +++ b/util/pmh7tool/Makefile @@ -0,0 +1,23 @@ +CC = gcc +CFLAGS = -O2 -Wall -W -Werror +PROGRAM = pmh7tool +INSTALL = /usr/bin/install +PREFIX = /usr/local + +all: $(PROGRAM) + +$(PROGRAM): pmh7tool.o + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) + +install: $(PROGRAM) + $(INSTALL) $(PROGRAM) $(PREFIX)/sbin + +clean: + rm -f *.o $(PROGRAM) + +distclean: clean + +%.o: %.c + $(CC) $(CFLAGS) -c $^ -I. -o $@ + +.PHONY: all install clean distclean diff --git a/util/pmh7tool/pmh7tool.c b/util/pmh7tool/pmh7tool.c new file mode 100644 index 0000000..26807de7 --- /dev/null +++ b/util/pmh7tool/pmh7tool.c @@ -0,0 +1,62 @@ +#include <stdio.h> +#include <stdlib.h> +#include <getopt.h> +#include <sys/io.h> +#include "pmh7tool.h" + +unsigned char pmh7_register_read(int reg) +{ + outb(reg, EC_LENOVO_PMH7_ADDR); + return inb(EC_LENOVO_PMH7_DATA); +} + +void pmh7_register_write(int reg, int val) +{ + outb(reg, EC_LENOVO_PMH7_ADDR); + outb(val, EC_LENOVO_PMH7_DATA); +} + +void print_usage(const char *name) +{ + printf("usage: %s\n", name); + printf("\n" + " -h | --help: print this help\n" + " -d | --dump: print registers\n" + "\n"); + exit(1); +} + +int main(int argc, char *argv[]) +{ + int opt, option_index = 0; + static struct option long_options[] = { + {"help", 0, 0, 'h'}, + {"dump", 0, 0, 'd'}, + {0, 0, 0, 0} + }; + + while ((opt = getopt_long(argc, argv, "hd", + long_options, &option_index)) != EOF) { + switch (opt) { + case 'd': + break; + case 'h': + default: + print_usage(argv[0]); + break; + } + } + + ioperm(EC_LENOVO_PMH7_BASE, 0x100, 1); + for (int i = 0; i < 0x100; i++) { + if ((i % 0x10) == 0) { + if (i != 0) + printf("\n"); + printf("%02x: ", i); + } + printf("%02x ", pmh7_register_read(i)); + } + printf("\n"); + + return 0; +} diff --git a/util/pmh7tool/pmh7tool.h b/util/pmh7tool/pmh7tool.h new file mode 100644 index 0000000..651526f --- /dev/null +++ b/util/pmh7tool/pmh7tool.h @@ -0,0 +1,11 @@ +#ifndef PMH7TOOL_H +#define PMH7TOOL_H + +#define EC_LENOVO_PMH7_BASE 0x15e0 +#define EC_LENOVO_PMH7_ADDR (EC_LENOVO_PMH7_BASE + 0x0c) +#define EC_LENOVO_PMH7_DATA (EC_LENOVO_PMH7_BASE + 0x0e) + +unsigned char pmh7_register_read(int reg); +void pmh7_register_write(int reg, int val); + +#endif /* PMH7TOOL_H */