summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Heijligen <thomas.heijligen@secunet.com>2021-12-14 16:36:05 +0100
committerNico Huber <nico.h@gmx.de>2021-12-22 12:35:00 +0000
commit49d758698a0dd166679c48b1a2785e50e9b0cc83 (patch)
treeb48b29bd4ccdc13543fab9685dc410a6a5be6613
parent88c871e74cb9d8b6f6f38747d1caae916364e2a2 (diff)
downloadflashrom-49d758698a0dd166679c48b1a2785e50e9b0cc83.tar.gz
flashrom-49d758698a0dd166679c48b1a2785e50e9b0cc83.tar.bz2
flashrom-49d758698a0dd166679c48b1a2785e50e9b0cc83.zip
hwaccess: move x86 port I/O related code into own files
Allow port I/O related code to be compiled independent from memory mapping functionality. This enables for a better selection of needed hardware access types. Change-Id: I372b4a409f036da766c42bc406b596bc41b0f75a Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/60110 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de>
-rw-r--r--Makefile13
-rw-r--r--amd_imc.c2
-rw-r--r--atahpt.c2
-rw-r--r--atapromise.c1
-rw-r--r--atavia.c2
-rw-r--r--board_enable.c1
-rw-r--r--chipset_enable.c1
-rw-r--r--drkaiser.c1
-rw-r--r--gfxnvidia.c1
-rw-r--r--hwaccess.c62
-rw-r--r--hwaccess.h2
-rw-r--r--hwaccess_x86_io.c87
-rw-r--r--hwaccess_x86_io.h4
-rw-r--r--internal.c1
-rw-r--r--it8212.c1
-rw-r--r--it85spi.c2
-rw-r--r--it87spi.c1
-rw-r--r--meson.build2
-rw-r--r--nic3com.c2
-rw-r--r--nicintel.c1
-rw-r--r--nicintel_eeprom.c1
-rw-r--r--nicintel_spi.c1
-rw-r--r--nicnatsemi.c2
-rw-r--r--nicrealtek.c2
-rw-r--r--ogp_spi.c1
-rw-r--r--programmer.h1
-rw-r--r--rayer_spi.c2
-rw-r--r--satamv.c1
-rw-r--r--satasii.c1
-rw-r--r--tests/hwaccess_x86_io_unittest.h2
-rw-r--r--wbsio_spi.c1
31 files changed, 122 insertions, 82 deletions
diff --git a/Makefile b/Makefile
index 9bc9bf8fc..8de6234b1 100644
--- a/Makefile
+++ b/Makefile
@@ -804,24 +804,23 @@ ifneq ($(NEED_RAW_ACCESS), )
FEATURE_CFLAGS += -D'NEED_RAW_ACCESS=1'
PROGRAMMER_OBJS += physmap.o hwaccess.o
-ifeq ($(TARGET_OS), NetBSD)
ifeq ($(ARCH), x86)
+FEATURE_CFLAGS += -D'__FLASHROM_HAVE_OUTB__=1'
+PROGRAMMER_OBJS += hwaccess_x86_io.o
+
+ifeq ($(TARGET_OS), NetBSD)
PCILIBS += -l$(shell uname -p)
endif
-else
ifeq ($(TARGET_OS), OpenBSD)
-ifeq ($(ARCH), x86)
PCILIBS += -l$(shell uname -m)
endif
-else
+endif
+
ifeq ($(TARGET_OS), Darwin)
# DirectHW framework can be found in the DirectHW library.
PCILIBS += -framework IOKit -framework DirectHW
endif
endif
-endif
-
-endif
USE_LIBUSB1 := $(if $(call filter_deps,$(DEPENDS_ON_LIBUSB1)),yes,no)
ifeq ($(USE_LIBUSB1), yes)
diff --git a/amd_imc.c b/amd_imc.c
index f2f09728f..4d3715e85 100644
--- a/amd_imc.c
+++ b/amd_imc.c
@@ -17,7 +17,7 @@
#include "flash.h"
#include "programmer.h"
-#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "spi.h"
#include "platform/pci.h"
diff --git a/atahpt.c b/atahpt.c
index d2712b86d..15bcd61b3 100644
--- a/atahpt.c
+++ b/atahpt.c
@@ -18,7 +18,7 @@
#include <string.h>
#include "flash.h"
#include "programmer.h"
-#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
#define BIOS_ROM_ADDR 0x90
diff --git a/atapromise.c b/atapromise.c
index 92eba0c2b..56abc26b4 100644
--- a/atapromise.c
+++ b/atapromise.c
@@ -19,6 +19,7 @@
#include "flash.h"
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
#define MAX_ROM_DECODE (32 * 1024)
diff --git a/atavia.c b/atavia.c
index 6370d91e9..8109768a7 100644
--- a/atavia.c
+++ b/atavia.c
@@ -20,7 +20,7 @@
#include <string.h>
#include "flash.h"
#include "programmer.h"
-#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
#define PCI_VENDOR_ID_VIA 0x1106
diff --git a/board_enable.c b/board_enable.c
index 339408a55..4ca7101a9 100644
--- a/board_enable.c
+++ b/board_enable.c
@@ -26,6 +26,7 @@
#include "flash.h"
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
#if defined(__i386__) || defined(__x86_64__)
diff --git a/chipset_enable.c b/chipset_enable.c
index 858844318..517918e52 100644
--- a/chipset_enable.c
+++ b/chipset_enable.c
@@ -34,6 +34,7 @@
#include "flash.h"
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
#define NOT_DONE_YET 1
diff --git a/drkaiser.c b/drkaiser.c
index 34b204e68..565a45ed6 100644
--- a/drkaiser.c
+++ b/drkaiser.c
@@ -18,6 +18,7 @@
#include "flash.h"
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
#define PCI_VENDOR_ID_DRKAISER 0x1803
diff --git a/gfxnvidia.c b/gfxnvidia.c
index e85ce68c7..0d3ef39e1 100644
--- a/gfxnvidia.c
+++ b/gfxnvidia.c
@@ -19,6 +19,7 @@
#include "flash.h"
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
#define PCI_VENDOR_ID_NVIDIA 0x10de
diff --git a/hwaccess.c b/hwaccess.c
index 9bfd8ea55..4e8a274d5 100644
--- a/hwaccess.c
+++ b/hwaccess.c
@@ -25,17 +25,8 @@
#include <fcntl.h>
#endif
#include "flash.h"
-#include "programmer.h"
#include "hwaccess.h"
-#if USE_IOPERM
-#include <sys/io.h>
-#endif
-
-#if (defined (__i386__) || defined (__x86_64__) || defined(__amd64__)) && USE_DEV_IO
-int io_fd;
-#endif
-
/* Prevent reordering and/or merging of reads/writes to hardware.
* Such reordering and/or merging would break device accesses which depend on the exact access order.
*/
@@ -70,59 +61,6 @@ static inline void sync_primitive(void)
#endif
}
-#if (defined (__i386__) || defined (__x86_64__) || defined(__amd64__)) && !(defined(__DJGPP__) || defined(__LIBPAYLOAD__))
-static int release_io_perms(void *p)
-{
-#if defined (__sun)
- sysi86(SI86V86, V86SC_IOPL, 0);
-#elif USE_DEV_IO
- close(io_fd);
-#elif USE_IOPERM
- ioperm(0, 65536, 0);
-#elif USE_IOPL
- iopl(0);
-#endif
- return 0;
-}
-
-/* Get I/O permissions with automatic permission release on shutdown. */
-int rget_io_perms(void)
-{
- #if defined (__sun)
- if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) {
-#elif USE_DEV_IO
- if ((io_fd = open("/dev/io", O_RDWR)) < 0) {
-#elif USE_IOPERM
- if (ioperm(0, 65536, 1) != 0) {
-#elif USE_IOPL
- if (iopl(3) != 0) {
-#endif
- msg_perr("ERROR: Could not get I/O privileges (%s).\n", strerror(errno));
- msg_perr("You need to be root.\n");
-#if defined (__OpenBSD__)
- msg_perr("If you are root already please set securelevel=-1 in /etc/rc.securelevel and\n"
- "reboot, or reboot into single user mode.\n");
-#elif defined(__NetBSD__)
- msg_perr("If you are root already please reboot into single user mode or make sure\n"
- "that your kernel configuration has the option INSECURE enabled.\n");
-#endif
- return 1;
- } else {
- register_shutdown(release_io_perms, NULL);
- }
- return 0;
-}
-
-#else
-
-/* DJGPP and libpayload environments have full PCI port I/O permissions by default. */
-/* PCI port I/O support is unimplemented on PPC/MIPS and unavailable on ARM. */
-int rget_io_perms(void)
-{
- return 0;
-}
-#endif
-
void mmio_writeb(uint8_t val, void *addr)
{
*(volatile uint8_t *) addr = val;
diff --git a/hwaccess.h b/hwaccess.h
index e5edcfa96..5b7b079fb 100644
--- a/hwaccess.h
+++ b/hwaccess.h
@@ -124,8 +124,6 @@ cpu_to_be(64)
#if NEED_RAW_ACCESS == 1 && (defined (__i386__) || defined (__x86_64__) || defined(__amd64__))
-#include "hwaccess_x86_io.h"
-
#if !(defined(__MACH__) && defined(__APPLE__)) && !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__) && !defined(__LIBPAYLOAD__)
typedef struct { uint32_t hi, lo; } msr_t;
msr_t rdmsr(int addr);
diff --git a/hwaccess_x86_io.c b/hwaccess_x86_io.c
new file mode 100644
index 000000000..3152bfe51
--- /dev/null
+++ b/hwaccess_x86_io.c
@@ -0,0 +1,87 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2009,2010 Carl-Daniel Hailfinger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <errno.h>
+#include <string.h>
+#if !defined (__DJGPP__) && !defined(__LIBPAYLOAD__)
+/* No file access needed/possible to get hardware access permissions. */
+#include <unistd.h>
+#include <fcntl.h>
+#endif
+
+#include "hwaccess_x86_io.h"
+#include "flash.h"
+
+#if USE_IOPERM
+#include <sys/io.h>
+#endif
+
+#if USE_DEV_IO
+int io_fd;
+#endif
+
+#if !(defined(__DJGPP__) || defined(__LIBPAYLOAD__))
+static int release_io_perms(void *p)
+{
+#if defined (__sun)
+ sysi86(SI86V86, V86SC_IOPL, 0);
+#elif USE_DEV_IO
+ close(io_fd);
+#elif USE_IOPERM
+ ioperm(0, 65536, 0);
+#elif USE_IOPL
+ iopl(0);
+#endif
+ return 0;
+}
+
+/* Get I/O permissions with automatic permission release on shutdown. */
+int rget_io_perms(void)
+{
+ #if defined (__sun)
+ if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) {
+#elif USE_DEV_IO
+ if ((io_fd = open("/dev/io", O_RDWR)) < 0) {
+#elif USE_IOPERM
+ if (ioperm(0, 65536, 1) != 0) {
+#elif USE_IOPL
+ if (iopl(3) != 0) {
+#endif
+ msg_perr("ERROR: Could not get I/O privileges (%s).\n", strerror(errno));
+ msg_perr("You need to be root.\n");
+#if defined (__OpenBSD__)
+ msg_perr("If you are root already please set securelevel=-1 in /etc/rc.securelevel and\n"
+ "reboot, or reboot into single user mode.\n");
+#elif defined(__NetBSD__)
+ msg_perr("If you are root already please reboot into single user mode or make sure\n"
+ "that your kernel configuration has the option INSECURE enabled.\n");
+#endif
+ return 1;
+ } else {
+ register_shutdown(release_io_perms, NULL);
+ }
+ return 0;
+}
+
+#else
+
+/* DJGPP and libpayload environments have full PCI port I/O permissions by default. */
+/* PCI port I/O support is unimplemented on PPC/MIPS and unavailable on ARM. */
+int rget_io_perms(void)
+{
+ return 0;
+}
+#endif
diff --git a/hwaccess_x86_io.h b/hwaccess_x86_io.h
index 63692b8dd..0d16fdde4 100644
--- a/hwaccess_x86_io.h
+++ b/hwaccess_x86_io.h
@@ -29,8 +29,6 @@
#include <sys/io.h>
#endif
-#define __FLASHROM_HAVE_OUTB__ 1
-
/* for iopl and outb under Solaris */
#if defined (__sun)
#include <sys/sysi86.h>
@@ -38,6 +36,8 @@
#include <asm/sunddi.h>
#endif
+int rget_io_perms(void);
+
/* Clarification about OUTB/OUTW/OUTL argument order:
* OUT[BWL](val, port)
*/
diff --git a/internal.c b/internal.c
index 4a8e27b23..7de1d6a8b 100644
--- a/internal.c
+++ b/internal.c
@@ -20,6 +20,7 @@
#include "flash.h"
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
int is_laptop = 0;
diff --git a/it8212.c b/it8212.c
index 60997f743..80da2b15a 100644
--- a/it8212.c
+++ b/it8212.c
@@ -18,6 +18,7 @@
#include "flash.h"
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
static uint8_t *it8212_bar = NULL;
diff --git a/it85spi.c b/it85spi.c
index 17e4e109d..574e03af8 100644
--- a/it85spi.c
+++ b/it85spi.c
@@ -26,7 +26,7 @@
#include "flash.h"
#include "spi.h"
#include "programmer.h"
-#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#define MAX_TIMEOUT 100000
#define MAX_TRY 5
diff --git a/it87spi.c b/it87spi.c
index 5f6fb6599..09449153c 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -26,6 +26,7 @@
#include "chipdrivers.h"
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "spi.h"
#define ITE_SUPERIO_PORT1 0x2e
diff --git a/meson.build b/meson.build
index 85f40ba56..5cbcac221 100644
--- a/meson.build
+++ b/meson.build
@@ -347,8 +347,10 @@ endif
# raw memory, MSR or PCI port I/O access
if need_raw_access
srcs += 'hwaccess.c'
+ srcs += 'hwaccess_x86_io.c'
srcs += 'physmap.c'
cargs += '-DNEED_RAW_ACCESS=1'
+ cargs += '-D__FLASHROM_HAVE_OUTB__=1'
endif
# raw serial IO
diff --git a/nic3com.c b/nic3com.c
index f7d2a9776..3ef607d2c 100644
--- a/nic3com.c
+++ b/nic3com.c
@@ -17,7 +17,7 @@
#include <stdlib.h>
#include "flash.h"
#include "programmer.h"
-#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
#define BIOS_ROM_ADDR 0x04
diff --git a/nicintel.c b/nicintel.c
index 1730ca463..7f4eb24f1 100644
--- a/nicintel.c
+++ b/nicintel.c
@@ -19,6 +19,7 @@
#include "flash.h"
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
static uint8_t *nicintel_bar;
diff --git a/nicintel_eeprom.c b/nicintel_eeprom.c
index ab7534349..fc2ef4084 100644
--- a/nicintel_eeprom.c
+++ b/nicintel_eeprom.c
@@ -35,6 +35,7 @@
#include "spi.h"
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
#define PCI_VENDOR_ID_INTEL 0x8086
diff --git a/nicintel_spi.c b/nicintel_spi.c
index f1ed12941..25a665165 100644
--- a/nicintel_spi.c
+++ b/nicintel_spi.c
@@ -35,6 +35,7 @@
#include "flash.h"
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
#define PCI_VENDOR_ID_INTEL 0x8086
diff --git a/nicnatsemi.c b/nicnatsemi.c
index 9dd39158f..bac650259 100644
--- a/nicnatsemi.c
+++ b/nicnatsemi.c
@@ -17,7 +17,7 @@
#include <stdlib.h>
#include "flash.h"
#include "programmer.h"
-#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
#define PCI_VENDOR_ID_NATSEMI 0x100b
diff --git a/nicrealtek.c b/nicrealtek.c
index 0bf60fd2d..71f9aaf0e 100644
--- a/nicrealtek.c
+++ b/nicrealtek.c
@@ -17,7 +17,7 @@
#include <stdlib.h>
#include "flash.h"
#include "programmer.h"
-#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
#define PCI_VENDOR_ID_REALTEK 0x10ec
diff --git a/ogp_spi.c b/ogp_spi.c
index 105f46813..4a4934ec0 100644
--- a/ogp_spi.c
+++ b/ogp_spi.c
@@ -19,6 +19,7 @@
#include "flash.h"
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
#define PCI_VENDOR_ID_OGP 0x1227
diff --git a/programmer.h b/programmer.h
index b4f04e7ad..b8b5bbcb2 100644
--- a/programmer.h
+++ b/programmer.h
@@ -271,7 +271,6 @@ struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
uint16_t card_vendor, uint16_t card_device);
#endif
-int rget_io_perms(void);
#if CONFIG_INTERNAL == 1
extern int is_laptop;
extern int laptop_ok;
diff --git a/rayer_spi.c b/rayer_spi.c
index e65eb78d0..6cf918a80 100644
--- a/rayer_spi.c
+++ b/rayer_spi.c
@@ -28,7 +28,7 @@
#include <string.h>
#include "flash.h"
#include "programmer.h"
-#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
/* We have two sets of pins, out and in. The numbers for both sets are
* independent and are bitshift values, not real pin numbers.
diff --git a/satamv.c b/satamv.c
index b69350feb..8543f5309 100644
--- a/satamv.c
+++ b/satamv.c
@@ -20,6 +20,7 @@
#include "flash.h"
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
static uint8_t *mv_bar;
diff --git a/satasii.c b/satasii.c
index d015f7fa0..2f220d154 100644
--- a/satasii.c
+++ b/satasii.c
@@ -18,6 +18,7 @@
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "platform/pci.h"
#define PCI_VENDOR_ID_SII 0x1095
diff --git a/tests/hwaccess_x86_io_unittest.h b/tests/hwaccess_x86_io_unittest.h
index 2a4cd5f3c..14f3caa90 100644
--- a/tests/hwaccess_x86_io_unittest.h
+++ b/tests/hwaccess_x86_io_unittest.h
@@ -39,6 +39,8 @@
#include <stdint.h>
+int rget_io_perms(void);
+
/*
* Dummy implementation of iopl from sys/io.h.
* sys/io.h by itself is platform-specific, so instead of including
diff --git a/wbsio_spi.c b/wbsio_spi.c
index 60b725f19..805abf78e 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -20,6 +20,7 @@
#include "chipdrivers.h"
#include "programmer.h"
#include "hwaccess.h"
+#include "hwaccess_x86_io.h"
#include "spi.h"
#define WBSIO_PORT1 0x2e