From f42d2f72cccdbcd454a79424fdb998842f7754d6 Mon Sep 17 00:00:00 2001 From: Thomas Heijligen Date: Tue, 12 Oct 2021 20:31:45 +0200 Subject: [PATCH] hwaccess: replace flashrom specific macros by compiler defines Replace the remaining IS_* macros with the associated compiler defines Change-Id: Ia0f022d12390722816066d292e1878824adc613c Signed-off-by: Thomas Heijligen Reviewed-on: https://review.coreboot.org/c/flashrom/+/58280 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber --- dediprog.c | 2 -- developerbox_spi.c | 2 -- dmi.c | 1 - flash.h | 2 -- hwaccess.c | 31 ++++++++++++++----------- hwaccess.h | 31 ++----------------------- internal.c | 1 - pickit2_spi.c | 2 -- platform.h | 57 ---------------------------------------------- serial.c | 2 -- serprog.c | 2 -- 11 files changed, 20 insertions(+), 113 deletions(-) delete mode 100644 platform.h diff --git a/dediprog.c b/dediprog.c index 85b78c860..939673cca 100644 --- a/dediprog.c +++ b/dediprog.c @@ -15,8 +15,6 @@ * GNU General Public License for more details. */ -#include "platform.h" - #include #include #include diff --git a/developerbox_spi.c b/developerbox_spi.c index 5573d6fc6..8c4a8df82 100644 --- a/developerbox_spi.c +++ b/developerbox_spi.c @@ -31,8 +31,6 @@ * should be turned on). */ -#include "platform.h" - #include #include #include "programmer.h" diff --git a/dmi.c b/dmi.c index e449cd9f5..5d709f1be 100644 --- a/dmi.c +++ b/dmi.c @@ -30,7 +30,6 @@ #include #include -#include "platform.h" #include "flash.h" #include "programmer.h" diff --git a/flash.h b/flash.h index 3baa07655..391a2d42f 100644 --- a/flash.h +++ b/flash.h @@ -20,8 +20,6 @@ #ifndef __FLASH_H__ #define __FLASH_H__ 1 -#include "platform.h" - #include #include #include diff --git a/hwaccess.c b/hwaccess.c index 13bacd7f8..9bfd8ea55 100644 --- a/hwaccess.c +++ b/hwaccess.c @@ -14,8 +14,6 @@ * GNU General Public License for more details. */ -#include "platform.h" - #include #include #include @@ -34,7 +32,7 @@ #include #endif -#if IS_X86 && USE_DEV_IO +#if (defined (__i386__) || defined (__x86_64__) || defined(__amd64__)) && USE_DEV_IO int io_fd; #endif @@ -50,9 +48,12 @@ static inline void sync_primitive(void) * * See also https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/memory-barriers.txt */ -#if IS_PPC // cf. http://lxr.free-electrons.com/source/arch/powerpc/include/asm/barrier.h +// cf. http://lxr.free-electrons.com/source/arch/powerpc/include/asm/barrier.h +#if defined(__powerpc) || defined(__powerpc__) || defined(__powerpc64__) || defined(__POWERPC__) || \ + defined(__ppc__) || defined(__ppc64__) || defined(_M_PPC) || defined(_ARCH_PPC) || \ + defined(_ARCH_PPC64) || defined(__ppc) asm("eieio" : : : "memory"); -#elif IS_SPARC +#elif (__sparc__) || defined (__sparc) #if defined(__sparc_v9__) || defined(__sparcv9) /* Sparc V9 CPUs support three different memory orderings that range from x86-like TSO to PowerPC-like * RMO. The modes can be switched at runtime thus to make sure we maintain the right order of access we @@ -69,7 +70,7 @@ static inline void sync_primitive(void) #endif } -#if IS_X86 && !(defined(__DJGPP__) || defined(__LIBPAYLOAD__)) +#if (defined (__i386__) || defined (__x86_64__) || defined(__amd64__)) && !(defined(__DJGPP__) || defined(__LIBPAYLOAD__)) static int release_io_perms(void *p) { #if defined (__sun) @@ -83,13 +84,11 @@ static int release_io_perms(void *p) #endif return 0; } -#endif /* Get I/O permissions with automatic permission release on shutdown. */ int rget_io_perms(void) { -#if IS_X86 && !(defined(__DJGPP__) || defined(__LIBPAYLOAD__)) -#if defined (__sun) + #if defined (__sun) if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) { #elif USE_DEV_IO if ((io_fd = open("/dev/io", O_RDWR)) < 0) { @@ -111,13 +110,19 @@ int rget_io_perms(void) } else { register_shutdown(release_io_perms, NULL); } -#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. */ -#endif 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 5097ac99b..56c2d1e5f 100644 --- a/hwaccess.h +++ b/hwaccess.h @@ -20,8 +20,6 @@ #ifndef __HWACCESS_H__ #define __HWACCESS_H__ 1 -#include "platform.h" - #if NEED_PCI == 1 /* * libpci headers use the variable name "index" which triggers shadowing @@ -109,8 +107,7 @@ cpu_to_be(64) #define le_to_cpu32 cpu_to_le32 #define le_to_cpu64 cpu_to_le64 -#if NEED_RAW_ACCESS == 1 -#if IS_X86 +#if NEED_RAW_ACCESS == 1 && (defined (__i386__) || defined (__x86_64__) || defined(__amd64__)) #include "hwaccess_x86_io.h" @@ -140,31 +137,7 @@ int libpayload_wrmsr(int addr, msr_t msr); #define wrmsr libpayload_wrmsr #endif -#elif IS_PPC -/* PCI port I/O is not yet implemented on PowerPC. */ - -#elif IS_MIPS - -/* PCI port I/O is not yet implemented on MIPS. */ - -#elif IS_SPARC - -/* PCI port I/O is not yet implemented on SPARC. */ - -#elif IS_ARM - -/* Non memory mapped I/O is not supported on ARM. */ - -#elif IS_ARC - -/* Non memory mapped I/O is not supported on ARC. */ - -#else - -#error Unknown architecture, please check if it supports PCI port IO. - -#endif /* IS_* */ -#endif /* NEED_RAW_ACCESS == 1 */ +#endif #endif /* !__HWACCESS_H__ */ diff --git a/internal.c b/internal.c index b9d17b47a..43bed9e2a 100644 --- a/internal.c +++ b/internal.c @@ -18,7 +18,6 @@ #include #include #include "flash.h" -#include "platform.h" #include "programmer.h" #include "hwaccess.h" diff --git a/pickit2_spi.c b/pickit2_spi.c index 17da1d991..c090efe80 100644 --- a/pickit2_spi.c +++ b/pickit2_spi.c @@ -32,8 +32,6 @@ * PICkit2 code: https://github.com/steve-m/avrdude/blob/master/pickit2.c */ -#include "platform.h" - #include #include #include diff --git a/platform.h b/platform.h deleted file mode 100644 index e0f8a7314..000000000 --- a/platform.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is part of the flashrom project. - * - * Copyright (C) 2011 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; version 2 of the License. - * - * 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. - */ - -/* - * Header file to determine target OS and CPU architecture. - */ - -#ifndef __PLATFORM_H__ -#define __PLATFORM_H__ 1 - -// Likewise for target architectures -#if defined (__i386__) || defined (__x86_64__) || defined(__amd64__) - #define IS_X86 1 -#elif defined (__mips) || defined (__mips__) || defined (__MIPS__) || defined (mips) - #define IS_MIPS 1 -#elif defined(__powerpc) || defined(__powerpc__) || defined(__powerpc64__) || defined(__POWERPC__) || \ - defined(__ppc__) || defined(__ppc64__) || defined(_M_PPC) || defined(_ARCH_PPC) || \ - defined(_ARCH_PPC64) || defined(__ppc) - #define IS_PPC 1 -#elif defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_ARM) || defined(_M_ARM) || defined(__arm) || \ - defined(__aarch64__) - #define IS_ARM 1 -#elif defined (__sparc__) || defined (__sparc) - #define IS_SPARC 1 -#elif defined (__alpha__) - #define IS_ALPHA 1 -#elif defined (__hppa__) || defined (__hppa) - #define IS_HPPA 1 -#elif defined (__m68k__) - #define IS_M68K 1 -#elif defined (__riscv) - #define IS_RISCV 1 -#elif defined (__sh__) - #define IS_SH 1 -#elif defined(__s390__) || defined(__s390x__) || defined(__zarch__) - #define IS_S390 1 -#elif defined(__arc__) - #define IS_ARC 1 -#endif - -#if !(IS_X86 || IS_MIPS || IS_PPC || IS_ARM || IS_SPARC || IS_ALPHA || IS_HPPA || IS_M68K || IS_RISCV || IS_SH || IS_S390 || IS_ARC) -#error Unknown architecture -#endif - -#endif /* !__PLATFORM_H__ */ diff --git a/serial.c b/serial.c index 76d34a263..72f9ef686 100644 --- a/serial.c +++ b/serial.c @@ -15,8 +15,6 @@ * GNU General Public License for more details. */ -#include "platform.h" - #include #include #include diff --git a/serprog.c b/serprog.c index f142b492e..2bbf44b31 100644 --- a/serprog.c +++ b/serprog.c @@ -15,8 +15,6 @@ * GNU General Public License for more details. */ -#include "platform.h" - #include #if ! IS_WINDOWS /* stuff (presumably) needed for sockets only */ #include