Patchwork Do not require PCI code for RayeR SPI driver

login
register
about
Submitter Carl-Daniel Hailfinger
Date 2016-02-20 21:42:44
Message ID <56C8DDD4.7010704@gmx.net>
Download mbox | patch
Permalink /patch/4390/
State Accepted
Headers show

Comments

Carl-Daniel Hailfinger - 2016-02-20 21:42:44
On 20.02.2016 22:35, Stefan Tauner wrote:
> On Sat, 20 Feb 2016 22:23:06 +0100
> Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> wrote:
>
>> New version, include sys/types.h on FreeBSD specifically instead of for
>> all OS.
>>
> liar! At least it is still in there below :)
>>  ifneq ($(NEED_LIBUSB0), )
>> Index: flashrom-rayer_do_not_require_libpci/hwaccess.h
>> ===================================================================
>> --- flashrom-rayer_do_not_require_libpci/hwaccess.h	(Revision 1931)
>> +++ flashrom-rayer_do_not_require_libpci/hwaccess.h	(Arbeitskopie)
>> @@ -24,6 +24,8 @@
>>  #ifndef __HWACCESS_H__
>>  #define __HWACCESS_H__ 1
>>  
>> +#include <sys/types.h>
>> +
>>  #include "platform.h"
>>  
>>  #if NEED_PCI == 1
>> @@ -196,7 +198,7 @@
>>  #define le_to_cpu32 cpu_to_le32
>>  #define le_to_cpu64 cpu_to_le64
>>  
>> -#if NEED_PCI == 1
>> +#if NEED_RAW_ACCESS == 1
>>  #if IS_X86
>>  
>>  /* sys/io.h provides iopl(2) and x86 I/O port access functions (inb, outb etc).
>> @@ -376,6 +378,6 @@
>>  #error Unknown architecture, please check if it supports PCI port IO.
>>  
>>  #endif /* IS_* */
>> -#endif /* NEED_PCI == 1 */
>> +#endif /* NEED_RAW_ACCESS == 1 */
>>  
>>  #endif /* !__HWACCESS_H__ */
> But with that mentioned fix this is
> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
> Thanks!

Indeed. I sent the wrong version. Correct version follows:

CONFIG_RAYER_SPI only needs raw hardware access, but not libpci.
Disable CONFIG_RAYER_SPI on Android because of missing inb/outb.
Introduce NEED_RAW_ACCESS for raw memory access, PCI port I/O
and MSR access.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Carl-Daniel Hailfinger - 2016-02-20 21:44:32
On 20.02.2016 22:42, Carl-Daniel Hailfinger wrote:
> CONFIG_RAYER_SPI only needs raw hardware access, but not libpci.
> Disable CONFIG_RAYER_SPI on Android because of missing inb/outb.
> Introduce NEED_RAW_ACCESS for raw memory access, PCI port I/O
> and MSR access.
>
> Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>

Thanks for the review, committed in r1934.

Regards,
Carl-Daniel

Patch

Index: flashrom-rayer_do_not_require_libpci/Makefile
===================================================================
--- flashrom-rayer_do_not_require_libpci/Makefile	(Revision 1933)
+++ flashrom-rayer_do_not_require_libpci/Makefile	(Arbeitskopie)
@@ -349,6 +349,15 @@ 
 endif
 endif
 
+ifeq ($(TARGET_OS), Android)
+# Android on x86 (currently) does not provide raw PCI port I/O operations
+ifeq ($(CONFIG_RAYER_SPI), yes)
+UNSUPPORTED_FEATURES += CONFIG_RAYER_SPI=yes
+else
+override CONFIG_RAYER_SPI = no
+endif
+endif
+
 ###############################################################################
 # General architecture-specific settings.
 # Like above for the OS, below we verify user-supplied options depending on the target architecture.
@@ -599,8 +608,7 @@ 
 ifeq ($(CONFIG_RAYER_SPI), yes)
 FEATURE_CFLAGS += -D'CONFIG_RAYER_SPI=1'
 PROGRAMMER_OBJS += rayer_spi.o
-# Actually, NEED_LIBPCI is wrong. NEED_IOPORT_ACCESS would be more correct.
-NEED_LIBPCI += CONFIG_RAYER_SPI
+NEED_RAW_ACCESS += CONFIG_RAYER_SPI
 endif
 
 ifeq ($(CONFIG_PONY_SPI), yes)
@@ -782,19 +790,31 @@ 
 
 ifneq ($(NEED_LIBPCI), )
 CHECK_LIBPCI = yes
+# This is a dirty hack, but it saves us from checking all PCI drivers and all platforms manually.
+# libpci may need raw memory, MSR or PCI port I/O on some platforms.
+# Individual drivers might have the same needs as well.
+NEED_RAW_ACCESS += $(NEED_LIBPCI)
 FEATURE_CFLAGS += -D'NEED_PCI=1'
 FEATURE_CFLAGS += $(call debug_shell,grep -q "OLD_PCI_GET_DEV := yes" .libdeps && printf "%s" "-D'OLD_PCI_GET_DEV=1'")
 
-PROGRAMMER_OBJS += pcidev.o physmap.o hwaccess.o
+PROGRAMMER_OBJS += pcidev.o
 ifeq ($(TARGET_OS), NetBSD)
 # The libpci we want is called libpciutils on NetBSD and needs NetBSD libpci.
 PCILIBS += -lpciutils -lpci
+else
+PCILIBS += -lpci
+endif
+endif
+
+ifneq ($(NEED_RAW_ACCESS), )
+# Raw memory, MSR or PCI port I/O access.
+FEATURE_CFLAGS += -D'NEED_RAW_ACCESS=1'
+PROGRAMMER_OBJS += physmap.o hwaccess.o
+
+ifeq ($(TARGET_OS), NetBSD)
 # For (i386|x86_64)_iopl(2).
 PCILIBS += -l$(shell uname -p)
 else
-
-PCILIBS += -lpci
-
 ifeq ($(TARGET_OS), OpenBSD)
 # For (i386|amd64)_iopl(2).
 PCILIBS += -l$(shell uname -m)
@@ -805,6 +825,7 @@ 
 endif
 endif
 endif
+
 endif
 
 ifneq ($(NEED_LIBUSB0), )
Index: flashrom-rayer_do_not_require_libpci/hwaccess.h
===================================================================
--- flashrom-rayer_do_not_require_libpci/hwaccess.h	(Revision 1933)
+++ flashrom-rayer_do_not_require_libpci/hwaccess.h	(Arbeitskopie)
@@ -196,7 +196,7 @@ 
 #define le_to_cpu32 cpu_to_le32
 #define le_to_cpu64 cpu_to_le64
 
-#if NEED_PCI == 1
+#if NEED_RAW_ACCESS == 1
 #if IS_X86
 
 /* sys/io.h provides iopl(2) and x86 I/O port access functions (inb, outb etc).
@@ -230,6 +230,7 @@ 
    * out[bwl] definitions in machine/cpufunc.h and sys/io.h at least in some
    * versions. Use machine/cpufunc.h only for plain FreeBSD/DragonFlyBSD.
    */
+  #include <sys/types.h>
   #include <machine/cpufunc.h>
   #define OUTB(x, y) do { u_int outb_tmp = (y); outb(outb_tmp, (x)); } while (0)
   #define OUTW(x, y) do { u_int outw_tmp = (y); outw(outw_tmp, (x)); } while (0)
@@ -382,6 +383,6 @@ 
 #error Unknown architecture, please check if it supports PCI port IO.
 
 #endif /* IS_* */
-#endif /* NEED_PCI == 1 */
+#endif /* NEED_RAW_ACCESS == 1 */
 
 #endif /* !__HWACCESS_H__ */