mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 15:12:36 +02:00
Unify usage of iopl-like code by introducing get_io_perms()
Factor out portable iopl()-style code into a global function which all programmers can use, add missing close() call. Corresponding to flashrom svn r511. Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
This commit is contained in:
parent
0cdb0313f1
commit
a086932cf9
3
flash.h
3
flash.h
@ -593,6 +593,9 @@ void internal_chip_writel(uint32_t val, volatile void *addr);
|
|||||||
uint8_t internal_chip_readb(const volatile void *addr);
|
uint8_t internal_chip_readb(const volatile void *addr);
|
||||||
uint16_t internal_chip_readw(const volatile void *addr);
|
uint16_t internal_chip_readw(const volatile void *addr);
|
||||||
uint32_t internal_chip_readl(const volatile void *addr);
|
uint32_t internal_chip_readl(const volatile void *addr);
|
||||||
|
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
|
extern int io_fd;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* dummyflasher.c */
|
/* dummyflasher.c */
|
||||||
int dummy_init(void);
|
int dummy_init(void);
|
||||||
|
15
internal.c
15
internal.c
@ -83,11 +83,8 @@ struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int internal_init(void)
|
void get_io_perms(void)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
/* First get full io access */
|
|
||||||
#if defined (__sun) && (defined(__i386) || defined(__amd64))
|
#if defined (__sun) && (defined(__i386) || defined(__amd64))
|
||||||
if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) {
|
if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) {
|
||||||
#elif defined(__FreeBSD__) || defined (__DragonFly__)
|
#elif defined(__FreeBSD__) || defined (__DragonFly__)
|
||||||
@ -95,9 +92,17 @@ int internal_init(void)
|
|||||||
#else
|
#else
|
||||||
if (iopl(3) != 0) {
|
if (iopl(3) != 0) {
|
||||||
#endif
|
#endif
|
||||||
fprintf(stderr, "ERROR: Could not get IO privileges (%s).\nYou need to be root.\n", strerror(errno));
|
fprintf(stderr, "ERROR: Could not get I/O privileges (%s).\n"
|
||||||
|
"You need to be root.\n", strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int internal_init(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
get_io_perms(void);
|
||||||
|
|
||||||
/* Initialize PCI access for flash enables */
|
/* Initialize PCI access for flash enables */
|
||||||
pacc = pci_alloc(); /* Get the pci_access structure */
|
pacc = pci_alloc(); /* Get the pci_access structure */
|
||||||
|
19
nic3com.c
19
nic3com.c
@ -39,10 +39,6 @@ uint32_t io_base_addr;
|
|||||||
struct pci_access *pacc;
|
struct pci_access *pacc;
|
||||||
struct pci_filter filter;
|
struct pci_filter filter;
|
||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
|
||||||
int io_fd;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define OK 0
|
#define OK 0
|
||||||
#define NT 1 /* Not tested */
|
#define NT 1 /* Not tested */
|
||||||
|
|
||||||
@ -102,17 +98,7 @@ int nic3com_init(void)
|
|||||||
struct pci_dev *dev;
|
struct pci_dev *dev;
|
||||||
char *msg = NULL;
|
char *msg = NULL;
|
||||||
|
|
||||||
#if defined (__sun) && (defined(__i386) || defined(__amd64))
|
get_io_perms();
|
||||||
if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) {
|
|
||||||
#elif defined(__FreeBSD__) || defined (__DragonFly__)
|
|
||||||
if ((io_fd = open("/dev/io", O_RDWR)) < 0) {
|
|
||||||
#else
|
|
||||||
if (iopl(3) != 0) {
|
|
||||||
#endif
|
|
||||||
fprintf(stderr, "ERROR: Could not get IO privileges (%s).\n"
|
|
||||||
"You need to be root.\n", strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
pacc = pci_alloc(); /* Get the pci_access structure */
|
pacc = pci_alloc(); /* Get the pci_access structure */
|
||||||
pci_init(pacc); /* Initialize the PCI library */
|
pci_init(pacc); /* Initialize the PCI library */
|
||||||
@ -155,6 +141,9 @@ int nic3com_shutdown(void)
|
|||||||
{
|
{
|
||||||
free(nic_pcidev);
|
free(nic_pcidev);
|
||||||
pci_cleanup(pacc);
|
pci_cleanup(pacc);
|
||||||
|
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
|
close(io_fd);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user