Skip to content

Commit 6f043e7

Browse files
niklas88arndb
authored andcommitted
asm-generic/io.h: Remove I/O port accessors for HAS_IOPORT=n
With all subsystems and drivers either declaring their dependence on HAS_IOPORT or fencing I/O port specific code sections we can finally make inb()/outb() and friends compile-time dependent on HAS_IOPORT as suggested by Linus in the linked mail. The main benefit of this is that on platforms such as s390 which have no meaningful way of implementing inb()/outb() their use without the proper HAS_IOPORT dependency will result in easy to catch and fix compile-time errors instead of compiling code that can never work. Link: https://lore.kernel.org/lkml/CAHk-=wg80je=K7madF4e7WrRNp37e3qh6y10Svhdc7O8SZ_-8g@mail.gmail.com/ Co-developed-by: Arnd Bergmann <arnd@kernel.org> Signed-off-by: Arnd Bergmann <arnd@kernel.org> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com> Reviewed-by: Takashi Iwai <tiwai@suse.de> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Acked-by: Lucas De Marchi <lucas.demarchi@intel.com> Acked-by: Maciej W. Rozycki <macro@orcam.me.uk> Acked-by: Damien Le Moal <dlemoal@kernel.org> Acked-by: Jaroslav Kysela <perex@perex.cz> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Johannes Berg <johannes@sipsolutions.net> # for ARCH=um Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> Acked-by: Kalle Valo <kvalo@kernel.org> Acked-by: Jakub Kicinski <kuba@kernel.org> Acked-by: Corey Minyard <cminyard@mvista.com> Acked-by: Guenter Roeck <linux@roeck-us.net> Acked-by: Damien Le Moal <damien.lemoal@opensource.wdc.com> Acked-by: Sebastian Reichel <sre@kernel.org> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
1 parent 7c7e6c8 commit 6f043e7

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

  • include/asm-generic

include/asm-generic/io.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ static inline void writesq(volatile void __iomem *addr, const void *buffer,
540540

541541
#if !defined(inb) && !defined(_inb)
542542
#define _inb _inb
543+
#ifdef CONFIG_HAS_IOPORT
543544
static inline u8 _inb(unsigned long addr)
544545
{
545546
u8 val;
@@ -549,10 +550,15 @@ static inline u8 _inb(unsigned long addr)
549550
__io_par(val);
550551
return val;
551552
}
553+
#else
554+
u8 _inb(unsigned long addr)
555+
__compiletime_error("inb()) requires CONFIG_HAS_IOPORT");
556+
#endif
552557
#endif
553558

554559
#if !defined(inw) && !defined(_inw)
555560
#define _inw _inw
561+
#ifdef CONFIG_HAS_IOPORT
556562
static inline u16 _inw(unsigned long addr)
557563
{
558564
u16 val;
@@ -562,10 +568,15 @@ static inline u16 _inw(unsigned long addr)
562568
__io_par(val);
563569
return val;
564570
}
571+
#else
572+
u16 _inw(unsigned long addr)
573+
__compiletime_error("inw() requires CONFIG_HAS_IOPORT");
574+
#endif
565575
#endif
566576

567577
#if !defined(inl) && !defined(_inl)
568578
#define _inl _inl
579+
#ifdef CONFIG_HAS_IOPORT
569580
static inline u32 _inl(unsigned long addr)
570581
{
571582
u32 val;
@@ -575,36 +586,55 @@ static inline u32 _inl(unsigned long addr)
575586
__io_par(val);
576587
return val;
577588
}
589+
#else
590+
u32 _inl(unsigned long addr)
591+
__compiletime_error("inl() requires CONFIG_HAS_IOPORT");
592+
#endif
578593
#endif
579594

580595
#if !defined(outb) && !defined(_outb)
581596
#define _outb _outb
597+
#ifdef CONFIG_HAS_IOPORT
582598
static inline void _outb(u8 value, unsigned long addr)
583599
{
584600
__io_pbw();
585601
__raw_writeb(value, PCI_IOBASE + addr);
586602
__io_paw();
587603
}
604+
#else
605+
void _outb(u8 value, unsigned long addr)
606+
__compiletime_error("outb() requires CONFIG_HAS_IOPORT");
607+
#endif
588608
#endif
589609

590610
#if !defined(outw) && !defined(_outw)
591611
#define _outw _outw
612+
#ifdef CONFIG_HAS_IOPORT
592613
static inline void _outw(u16 value, unsigned long addr)
593614
{
594615
__io_pbw();
595616
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
596617
__io_paw();
597618
}
619+
#else
620+
void _outw(u16 value, unsigned long addr)
621+
__compiletime_error("outw() requires CONFIG_HAS_IOPORT");
622+
#endif
598623
#endif
599624

600625
#if !defined(outl) && !defined(_outl)
601626
#define _outl _outl
627+
#ifdef CONFIG_HAS_IOPORT
602628
static inline void _outl(u32 value, unsigned long addr)
603629
{
604630
__io_pbw();
605631
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
606632
__io_paw();
607633
}
634+
#else
635+
void _outl(u32 value, unsigned long addr)
636+
__compiletime_error("outl() requires CONFIG_HAS_IOPORT");
637+
#endif
608638
#endif
609639

610640
#include <linux/logic_pio.h>
@@ -688,53 +718,83 @@ static inline void outl_p(u32 value, unsigned long addr)
688718

689719
#ifndef insb
690720
#define insb insb
721+
#ifdef CONFIG_HAS_IOPORT
691722
static inline void insb(unsigned long addr, void *buffer, unsigned int count)
692723
{
693724
readsb(PCI_IOBASE + addr, buffer, count);
694725
}
726+
#else
727+
void insb(unsigned long addr, void *buffer, unsigned int count)
728+
__compiletime_error("insb() requires HAS_IOPORT");
729+
#endif
695730
#endif
696731

697732
#ifndef insw
698733
#define insw insw
734+
#ifdef CONFIG_HAS_IOPORT
699735
static inline void insw(unsigned long addr, void *buffer, unsigned int count)
700736
{
701737
readsw(PCI_IOBASE + addr, buffer, count);
702738
}
739+
#else
740+
void insw(unsigned long addr, void *buffer, unsigned int count)
741+
__compiletime_error("insw() requires HAS_IOPORT");
742+
#endif
703743
#endif
704744

705745
#ifndef insl
706746
#define insl insl
747+
#ifdef CONFIG_HAS_IOPORT
707748
static inline void insl(unsigned long addr, void *buffer, unsigned int count)
708749
{
709750
readsl(PCI_IOBASE + addr, buffer, count);
710751
}
752+
#else
753+
void insl(unsigned long addr, void *buffer, unsigned int count)
754+
__compiletime_error("insl() requires HAS_IOPORT");
755+
#endif
711756
#endif
712757

713758
#ifndef outsb
714759
#define outsb outsb
760+
#ifdef CONFIG_HAS_IOPORT
715761
static inline void outsb(unsigned long addr, const void *buffer,
716762
unsigned int count)
717763
{
718764
writesb(PCI_IOBASE + addr, buffer, count);
719765
}
766+
#else
767+
void outsb(unsigned long addr, const void *buffer, unsigned int count)
768+
__compiletime_error("outsb() requires HAS_IOPORT");
769+
#endif
720770
#endif
721771

722772
#ifndef outsw
723773
#define outsw outsw
774+
#ifdef CONFIG_HAS_IOPORT
724775
static inline void outsw(unsigned long addr, const void *buffer,
725776
unsigned int count)
726777
{
727778
writesw(PCI_IOBASE + addr, buffer, count);
728779
}
780+
#else
781+
void outsw(unsigned long addr, const void *buffer, unsigned int count)
782+
__compiletime_error("outsw() requires HAS_IOPORT");
783+
#endif
729784
#endif
730785

731786
#ifndef outsl
732787
#define outsl outsl
788+
#ifdef CONFIG_HAS_IOPORT
733789
static inline void outsl(unsigned long addr, const void *buffer,
734790
unsigned int count)
735791
{
736792
writesl(PCI_IOBASE + addr, buffer, count);
737793
}
794+
#else
795+
void outsl(unsigned long addr, const void *buffer, unsigned int count)
796+
__compiletime_error("outsl() requires HAS_IOPORT");
797+
#endif
738798
#endif
739799

740800
#ifndef insb_p

0 commit comments

Comments
 (0)