Author: uwe Date: 2009-05-14 22:41:57 +0200 (Thu, 14 May 2009) New Revision: 511
Modified: trunk/flash.h trunk/internal.c trunk/nic3com.c Log: Factor out portable iopl()-style code into a global function which all programmers can use, add missing close() call (trivial).
Signed-off-by: Uwe Hermann uwe@hermann-uwe.de Acked-by: Uwe Hermann uwe@hermann-uwe.de
Modified: trunk/flash.h =================================================================== --- trunk/flash.h 2009-05-14 18:57:26 UTC (rev 510) +++ trunk/flash.h 2009-05-14 20:41:57 UTC (rev 511) @@ -593,6 +593,9 @@ uint8_t internal_chip_readb(const volatile void *addr); uint16_t internal_chip_readw(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 */ int dummy_init(void);
Modified: trunk/internal.c =================================================================== --- trunk/internal.c 2009-05-14 18:57:26 UTC (rev 510) +++ trunk/internal.c 2009-05-14 20:41:57 UTC (rev 511) @@ -83,11 +83,8 @@ 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 (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) { #elif defined(__FreeBSD__) || defined (__DragonFly__) @@ -95,10 +92,18 @@ #else if (iopl(3) != 0) { #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); } +}
+int internal_init(void) +{ + int ret = 0; + + get_io_perms(void); + /* Initialize PCI access for flash enables */ pacc = pci_alloc(); /* Get the pci_access structure */ /* Set all options you want -- here we stick with the defaults */
Modified: trunk/nic3com.c =================================================================== --- trunk/nic3com.c 2009-05-14 18:57:26 UTC (rev 510) +++ trunk/nic3com.c 2009-05-14 20:41:57 UTC (rev 511) @@ -39,10 +39,6 @@ struct pci_access *pacc; struct pci_filter filter;
-#if defined(__FreeBSD__) || defined(__DragonFly__) -int io_fd; -#endif - #define OK 0 #define NT 1 /* Not tested */
@@ -102,17 +98,7 @@ struct pci_dev *dev; char *msg = NULL;
-#if defined (__sun) && (defined(__i386) || defined(__amd64)) - 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); - } + get_io_perms();
pacc = pci_alloc(); /* Get the pci_access structure */ pci_init(pacc); /* Initialize the PCI library */ @@ -155,6 +141,9 @@ { free(nic_pcidev); pci_cleanup(pacc); +#if defined(__FreeBSD__) || defined(__DragonFly__) + close(io_fd); +#endif return 0; }