Evgeny Zinoviev has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/38349 )
Change subject: util/pmh7tool: support OpenBSD ......................................................................
util/pmh7tool: support OpenBSD
Change-Id: I8aeee4009fb38204b1bdbe6712d759ab17b2cbd9 Signed-off-by: Evgeny Zinoviev me@ch1p.io --- M util/pmh7tool/Makefile M util/pmh7tool/pmh7tool.c 2 files changed, 33 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/49/38349/1
diff --git a/util/pmh7tool/Makefile b/util/pmh7tool/Makefile index 034ed40..0df7984 100644 --- a/util/pmh7tool/Makefile +++ b/util/pmh7tool/Makefile @@ -19,6 +19,10 @@ INSTALL = /usr/bin/env install PREFIX = /usr/local
+ifeq ($(shell uname -s 2>/dev/null), OpenBSD) +LDFLAGS = -lamd64 +endif + all: $(PROGRAM)
$(PROGRAM): pmh7tool.o diff --git a/util/pmh7tool/pmh7tool.c b/util/pmh7tool/pmh7tool.c index f03d97e..b268f9b 100644 --- a/util/pmh7tool/pmh7tool.c +++ b/util/pmh7tool/pmh7tool.c @@ -16,13 +16,36 @@ #include <stdio.h> #include <stdlib.h> #include <getopt.h> +#if !defined __OpenBSD__ #include <sys/io.h> +#endif #include <errno.h> #include <string.h> #include <unistd.h> #include <stdint.h> #include "pmh7tool.h"
+#if defined __OpenBSD__ +#include <machine/sysarch.h> +static uint8_t inb(unsigned port) +{ + uint8_t data; + __asm volatile("inb %w1,%0" : "=a" (data) : "d" (port)); + return data; +} +static __inline void outb(uint8_t data, unsigned port) +{ + __asm volatile("outb %0,%w1" : : "a" (data), "d" (port)); +} + +#if defined __i386__ +#define iopl i386_iopl +#else +#define iopl amd64_iopl +#endif + +#endif + uint8_t pmh7_register_read(uint16_t reg) { outb(reg & 0xff, EC_LENOVO_PMH7_ADDR_L); @@ -85,7 +108,7 @@ int main(int argc, char *argv[]) { enum action act = HELP; - int opt, option_index = 0; + int i, opt, option_index = 0; long input_addr = 0, input_data = 0;
static struct option long_options[] = { @@ -185,15 +208,18 @@ fprintf(stderr, "You must be root.\n"); exit(1); } - +#if !defined __OpenBSD__ if (ioperm(EC_LENOVO_PMH7_BASE, 0x10, 1)) { +#else + if (iopl(3)) { +#endif fprintf(stderr, "ioperm: %s\n", strerror(errno)); exit(1); }
switch (act) { case DUMP: - for (int i = 0; i < 0x200; i++) { + for (i = 0; i < 0x200; i++) { if ((i % 0x10) == 0) { if (i != 0) printf("\n");