1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 07:02:34 +02:00
flashrom/hwaccess_x86_io.c
Peter Marheine 36f87376a3 hwaccess: fix build on non-x86 targets
The changes to hwaccess in commit 49d758698a0dd166679c48b1a2785e50e9b0cc83
cause build failure on non-x86 systems because the hwaccess_x86_*
headers are included in some files that are built for all platforms
(particularly those in the internal programmer) and those headers in
turn include <sys/io.h> which only exists on x86.

This change avoids including those headers on non-x86 platforms so
the internal programmer can be built without errors.

The comment on the stub implementation of rget_io_perms() is also
modified to remove references to non-x86 platforms, since that file is
only built on x86 now.

BUG=None
TEST=meson build succeeds for both x86 and ARM targets

Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Change-Id: I20f122679c30340b2c73afd7419e79644ddc3c4e
Reviewed-on: https://review.coreboot.org/c/flashrom/+/61194
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Thomas Heijligen <src@posteo.de>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2022-01-25 17:31:42 +00:00

87 lines
2.2 KiB
C

/*
* 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. */
int rget_io_perms(void)
{
return 0;
}
#endif