summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2020-06-11 07:35:39 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-06-11 07:35:39 +0200
commit1fb15fcfe9ecb079b88df7eb01f1e29144cd8f96 (patch)
tree651ae01bac7ed264934baccd0fccbfeec6905da6
parentd6757bacf8180b17692682c58dd6a9938d0c3c1d (diff)
parentaa2cd910c7465eaf6de04da1b4d110205ad63c77 (diff)
downloadbarebox-1fb15fcfe9ecb079b88df7eb01f1e29144cd8f96.tar.gz
barebox-1fb15fcfe9ecb079b88df7eb01f1e29144cd8f96.tar.xz
Merge branch 'for-next/sandbox-compile-test'
-rw-r--r--arch/arm/include/asm/atomic.h108
-rw-r--r--arch/arm/include/asm/io.h58
-rw-r--r--arch/sandbox/Kconfig17
-rw-r--r--arch/sandbox/Makefile12
-rw-r--r--arch/sandbox/include/asm/atomic.h2
-rw-r--r--arch/sandbox/include/asm/bitsperlong.h11
-rw-r--r--arch/sandbox/include/asm/dma.h53
-rw-r--r--arch/sandbox/include/asm/io.h11
-rw-r--r--arch/sandbox/os/Makefile2
-rw-r--r--arch/sandbox/os/common.c2
-rw-r--r--commands/test.c1
-rw-r--r--commands/tftp.c8
-rw-r--r--drivers/clocksource/arm_global_timer.c1
-rw-r--r--drivers/ddr/fsl/Kconfig1
-rw-r--r--drivers/mtd/nand/Kconfig2
-rw-r--r--drivers/mtd/nand/nand_base.c1
-rw-r--r--drivers/net/Kconfig2
-rw-r--r--drivers/usb/host/xhci.h14
-rw-r--r--include/asm-generic/atomic.h73
-rw-r--r--include/asm-generic/bitio.h145
-rw-r--r--include/asm-generic/bitops/ffs.h4
-rw-r--r--include/asm-generic/bitops/fls.h4
-rw-r--r--scripts/Kconfig.include53
-rwxr-xr-xscripts/gcc-64bitptr.sh9
-rwxr-xr-xscripts/gcc-version.sh20
25 files changed, 412 insertions, 202 deletions
diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
index 9b79506b59..cfc359a5ce 100644
--- a/arch/arm/include/asm/atomic.h
+++ b/arch/arm/include/asm/atomic.h
@@ -1,111 +1,9 @@
-/*
- * linux/include/asm-arm/atomic.h
- *
- * Copyright (c) 1996 Russell King.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Changelog:
- * 27-06-1996 RMK Created
- * 13-04-1997 RMK Made functions atomic!
- * 07-12-1997 RMK Upgraded for v2.1.
- * 26-08-1998 PJB Added #ifdef __KERNEL__
- */
+// SPDX-License-Identifier: GPL-2.0-only
+
#ifndef __ASM_ARM_ATOMIC_H
#define __ASM_ARM_ATOMIC_H
-#ifdef CONFIG_SMP
-#error SMP not supported
-#endif
-
-typedef struct { volatile int counter; } atomic_t;
-
-#define ATOMIC_INIT(i) { (i) }
-
-#ifdef __KERNEL__
#include <asm/proc-armv/system.h>
+#include <asm-generic/atomic.h>
-#define atomic_read(v) ((v)->counter)
-#define atomic_set(v,i) (((v)->counter) = (i))
-
-static inline void atomic_add(int i, volatile atomic_t *v)
-{
- unsigned long flags = 0;
-
- local_irq_save(flags);
- v->counter += i;
- local_irq_restore(flags);
-}
-
-static inline void atomic_sub(int i, volatile atomic_t *v)
-{
- unsigned long flags = 0;
-
- local_irq_save(flags);
- v->counter -= i;
- local_irq_restore(flags);
-}
-
-static inline void atomic_inc(volatile atomic_t *v)
-{
- unsigned long flags = 0;
-
- local_irq_save(flags);
- v->counter += 1;
- local_irq_restore(flags);
-}
-
-static inline void atomic_dec(volatile atomic_t *v)
-{
- unsigned long flags = 0;
-
- local_irq_save(flags);
- v->counter -= 1;
- local_irq_restore(flags);
-}
-
-static inline int atomic_dec_and_test(volatile atomic_t *v)
-{
- unsigned long flags = 0;
- int val;
-
- local_irq_save(flags);
- val = v->counter;
- v->counter = val -= 1;
- local_irq_restore(flags);
-
- return val == 0;
-}
-
-static inline int atomic_add_negative(int i, volatile atomic_t *v)
-{
- unsigned long flags = 0;
- int val;
-
- local_irq_save(flags);
- val = v->counter;
- v->counter = val += i;
- local_irq_restore(flags);
-
- return val < 0;
-}
-
-static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
-{
- unsigned long flags = 0;
-
- local_irq_save(flags);
- *addr &= ~mask;
- local_irq_restore(flags);
-}
-
-/* Atomic operations are already serializing on ARM */
-#define smp_mb__before_atomic_dec() barrier()
-#define smp_mb__after_atomic_dec() barrier()
-#define smp_mb__before_atomic_inc() barrier()
-#define smp_mb__after_atomic_inc() barrier()
-
-#endif
#endif
diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index 56db546341..072b47317c 100644
--- a/arch/arm/include/asm/io.h
+++ b/arch/arm/include/asm/io.h
@@ -4,6 +4,7 @@
#define IO_SPACE_LIMIT 0
#include <asm-generic/io.h>
+#include <asm-generic/bitio.h>
/*
* String version of IO memory access ops:
@@ -12,63 +13,6 @@ extern void memcpy_fromio(void *, const volatile void __iomem *, size_t);
extern void memcpy_toio(volatile void __iomem *, const void *, size_t);
extern void memset_io(volatile void __iomem *, int, size_t);
-/*
- * Clear and set bits in one shot. These macros can be used to clear and
- * set multiple bits in a register using a single call. These macros can
- * also be used to set a multiple-bit bit pattern using a mask, by
- * specifying the mask in the 'clear' parameter and the new bit pattern
- * in the 'set' parameter.
- */
-
-#define out_arch(type,endian,a,v) __raw_write##type(cpu_to_##endian(v),a)
-#define in_arch(type,endian,a) endian##_to_cpu(__raw_read##type(a))
-
-#define out_le64(a,v) out_arch(q,le64,a,v)
-#define out_le32(a,v) out_arch(l,le32,a,v)
-#define out_le16(a,v) out_arch(w,le16,a,v)
-
-#define in_le64(a) in_arch(q,le64,a)
-#define in_le32(a) in_arch(l,le32,a)
-#define in_le16(a) in_arch(w,le16,a)
-
-#define out_be32(a,v) out_arch(l,be32,a,v)
-#define out_be16(a,v) out_arch(w,be16,a,v)
-
-#define in_be32(a) in_arch(l,be32,a)
-#define in_be16(a) in_arch(w,be16,a)
-
-#define out_8(a,v) __raw_writeb(v,a)
-#define in_8(a) __raw_readb(a)
-
-#define clrbits(type, addr, clear) \
- out_##type((addr), in_##type(addr) & ~(clear))
-
-#define setbits(type, addr, set) \
- out_##type((addr), in_##type(addr) | (set))
-
-#define clrsetbits(type, addr, clear, set) \
- out_##type((addr), (in_##type(addr) & ~(clear)) | (set))
-
-#define clrbits_be32(addr, clear) clrbits(be32, addr, clear)
-#define setbits_be32(addr, set) setbits(be32, addr, set)
-#define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set)
-
-#define clrbits_le32(addr, clear) clrbits(le32, addr, clear)
-#define setbits_le32(addr, set) setbits(le32, addr, set)
-#define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set)
-
-#define clrbits_be16(addr, clear) clrbits(be16, addr, clear)
-#define setbits_be16(addr, set) setbits(be16, addr, set)
-#define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set)
-
-#define clrbits_le16(addr, clear) clrbits(le16, addr, clear)
-#define setbits_le16(addr, set) setbits(le16, addr, set)
-#define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set)
-
-#define clrbits_8(addr, clear) clrbits(8, addr, clear)
-#define setbits_8(addr, set) setbits(8, addr, set)
-#define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
-
static inline void *phys_to_virt(unsigned long phys)
{
return (void *)phys;
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index 6ec71a99e5..3f10709021 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -1,9 +1,12 @@
+source "scripts/Kconfig.include"
+
config SANDBOX
bool
select OFTREE
select GPIOLIB
select ARCH_HAS_UBSAN_SANITIZE_ALL
select HAVE_ARCH_KASAN
+ select HAS_DMA
default y
config ARCH_TEXT_BASE
@@ -20,3 +23,17 @@ config SANDBOX_UNWIND
default y
select ARCH_HAS_STACK_DUMP
depends on UBSAN || KASAN
+
+config CC_IS_64BIT
+ def_bool $(success,$(srctree)/scripts/gcc-64bitptr.sh $(CC))
+
+config CC_HAS_LINUX_I386_SUPPORT
+ def_bool $(cc-option,-m32) && $(ld-option,-m elf_i386)
+
+config 64BIT
+ bool
+ default n if SANDBOX_LINUX_I386
+ default CC_IS_64BIT
+
+config SANDBOX_LINUX_I386
+ bool "32-bit x86 barebox" if CC_HAS_LINUX_I386_SUPPORT
diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile
index 3917cade94..c08ea0cf83 100644
--- a/arch/sandbox/Makefile
+++ b/arch/sandbox/Makefile
@@ -52,11 +52,21 @@ ifeq ($(CONFIG_UBSAN),y)
SANITIZER_LIBS += -fsanitize=undefined
endif
-cmd_barebox__ = $(CC) -o $@ -Wl,-T,$(BAREBOX_LDS) \
+ifeq ($(CONFIG_SANDBOX_LINUX_I386),y)
+KBUILD_CFLAGS += -m32
+KBUILD_LDFLAGS += -m elf_i386
+KBUILD_AFLAGS += -m32
+BAREBOX_LDFLAGS += -m32
+endif
+
+BAREBOX_LDFLAGS += \
+ -Wl,-T,$(BAREBOX_LDS) \
-Wl,--whole-archive $(BAREBOX_OBJS) -Wl,--no-whole-archive \
-lrt -lpthread $(SDL_LIBS) $(FTDI1_LIBS) \
$(SANITIZER_LIBS)
+cmd_barebox__ = $(CC) -o $@ $(BAREBOX_LDFLAGS)
+
common-y += $(BOARD) arch/sandbox/os/ arch/sandbox/lib/
common-$(CONFIG_OFTREE) += arch/sandbox/dts/
diff --git a/arch/sandbox/include/asm/atomic.h b/arch/sandbox/include/asm/atomic.h
new file mode 100644
index 0000000000..af12dee130
--- /dev/null
+++ b/arch/sandbox/include/asm/atomic.h
@@ -0,0 +1,2 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <asm-generic/atomic.h>
diff --git a/arch/sandbox/include/asm/bitsperlong.h b/arch/sandbox/include/asm/bitsperlong.h
index 00c1fc2625..6dc0bb0c13 100644
--- a/arch/sandbox/include/asm/bitsperlong.h
+++ b/arch/sandbox/include/asm/bitsperlong.h
@@ -1,10 +1 @@
-#ifndef __ASM_BITSPERLONG_H
-#define __ASM_BITSPERLONG_H
-
-#ifdef __x86_64__
-#define BITS_PER_LONG 64
-#else
-#define BITS_PER_LONG 32
-#endif
-
-#endif /* __ASM_BITSPERLONG_H */
+#include <asm-generic/bitsperlong.h>
diff --git a/arch/sandbox/include/asm/dma.h b/arch/sandbox/include/asm/dma.h
index 459536779e..5e72d8e7df 100644
--- a/arch/sandbox/include/asm/dma.h
+++ b/arch/sandbox/include/asm/dma.h
@@ -8,6 +8,57 @@
#ifndef __ASM_DMA_H
#define __ASM_DMA_H
-/* empty*/
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <driver.h>
+
+#define dma_alloc dma_alloc
+static inline void *dma_alloc(size_t size)
+{
+ return xmemalign(64, ALIGN(size, 64));
+}
+
+static inline void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle)
+{
+ void *ret = xmemalign(4096, size);
+ if (dma_handle)
+ *dma_handle = (dma_addr_t)ret;
+
+ memset(ret, 0, size);
+
+ return ret;
+}
+
+static inline void *dma_alloc_writecombine(size_t size, dma_addr_t *dma_handle)
+{
+ return dma_alloc_coherent(size, dma_handle);
+}
+
+static inline void dma_free_coherent(void *mem, dma_addr_t dma_handle,
+ size_t size)
+{
+ free(mem);
+}
+
+static inline dma_addr_t dma_map_single(struct device_d *dev, void *ptr, size_t size,
+ enum dma_data_direction dir)
+{
+ return (dma_addr_t)ptr;
+}
+
+static inline void dma_unmap_single(struct device_d *dev, dma_addr_t addr, size_t size,
+ enum dma_data_direction dir)
+{
+}
+
+static inline void dma_sync_single_for_cpu(dma_addr_t address, size_t size,
+ enum dma_data_direction dir)
+{
+}
+
+static inline void dma_sync_single_for_device(dma_addr_t address, size_t size,
+ enum dma_data_direction dir)
+{
+}
#endif /* __ASM_DMA_H */
diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h
index cb891df5c8..6a0e77aead 100644
--- a/arch/sandbox/include/asm/io.h
+++ b/arch/sandbox/include/asm/io.h
@@ -4,5 +4,16 @@
#define IO_SPACE_LIMIT 0
#include <asm-generic/io.h>
+#include <asm-generic/bitio.h>
+
+static inline void *phys_to_virt(unsigned long phys)
+{
+ return (void *)phys;
+}
+
+static inline unsigned long virt_to_phys(volatile void *mem)
+{
+ return (unsigned long)mem;
+}
#endif /* __ASM_SANDBOX_IO_H */
diff --git a/arch/sandbox/os/Makefile b/arch/sandbox/os/Makefile
index c012c9cf01..ed921443e0 100644
--- a/arch/sandbox/os/Makefile
+++ b/arch/sandbox/os/Makefile
@@ -6,7 +6,7 @@ KBUILD_CPPFLAGS = $(patsubst %,-I$(srctree)/%include,$(machdirs))
KBUILD_CPPFLAGS += -DCONFIG_MALLOC_SIZE=$(CONFIG_MALLOC_SIZE)
-KBUILD_CFLAGS := -Wall
+KBUILD_CFLAGS += -Wall
NOSTDINC_FLAGS :=
obj-y = common.o tap.o
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index e67ea14138..382a923040 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -236,7 +236,7 @@ static int add_image(char *str, char *devname_template, int *devname_number)
filename = devname;
snprintf(tmp, sizeof(tmp),
devname_template, (*devname_number)++);
- devname = strdup(tmp);
+ devname = tmp;
}
printf("add %s backed by file %s%s\n", devname,
diff --git a/commands/test.c b/commands/test.c
index 505b7c56b1..c845cec017 100644
--- a/commands/test.c
+++ b/commands/test.c
@@ -86,7 +86,6 @@ static int do_test(int argc, char *argv[])
if (argc < 2)
return 1;
- last_expr = 0;
left = argc - 1;
ap = argv + 1;
diff --git a/commands/tftp.c b/commands/tftp.c
index 1569819844..48ff00c621 100644
--- a/commands/tftp.c
+++ b/commands/tftp.c
@@ -20,7 +20,6 @@ static int do_tftpb(int argc, char *argv[])
{
char *source, *dest, *freep;
int opt;
- unsigned long flags;
int tftp_push = 0;
int ret;
IPaddr_t ip;
@@ -46,13 +45,10 @@ static int do_tftpb(int argc, char *argv[])
else
dest = argv[optind];
- if (tftp_push) {
+ if (tftp_push)
dest = freep = basprintf("%s/%s", TFTP_MOUNT_PATH, dest);
- flags = O_RDONLY;
- } else {
+ else
source = freep = basprintf("%s/%s", TFTP_MOUNT_PATH, source);
- flags = O_WRONLY | O_CREAT;
- }
if (!freep)
return -ENOMEM;
diff --git a/drivers/clocksource/arm_global_timer.c b/drivers/clocksource/arm_global_timer.c
index 44e3a3c762..78cd72d3eb 100644
--- a/drivers/clocksource/arm_global_timer.c
+++ b/drivers/clocksource/arm_global_timer.c
@@ -20,7 +20,6 @@
#include <clock.h>
#include <linux/clk.h>
#include <io.h>
-#include <asm/system.h>
#define GT_COUNTER0 0x00
#define GT_COUNTER1 0x04
diff --git a/drivers/ddr/fsl/Kconfig b/drivers/ddr/fsl/Kconfig
index 09920bb863..b12bf8f777 100644
--- a/drivers/ddr/fsl/Kconfig
+++ b/drivers/ddr/fsl/Kconfig
@@ -1,5 +1,6 @@
config DDR_FSL
bool "Freescale DDR support" if COMPILE_TEST
+ depends on ARM
if DDR_FSL
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index fff9903d1d..b81e72d6b7 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -98,7 +98,7 @@ config MTD_NAND_OMAP_ELM
config NAND_ORION
bool
prompt "Marvell Orion NAND driver"
- depends on ARCH_KIRKWOOD || COMPILE_TEST
+ depends on ARM && (ARCH_KIRKWOOD || COMPILE_TEST)
help
Support for the Orion NAND controller, present in Kirkwood SoCs.
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 00f0f75884..3f4c787f49 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1688,6 +1688,7 @@ static int nand_read(struct mtd_info *mtd, loff_t from, size_t len,
nand_get_device(mtd, FL_READING);
ops.len = len;
ops.datbuf = buf;
+ ops.ooblen = 0;
ops.oobbuf = NULL;
ops.mode = MTD_OPS_PLACE_OOB;
ret = nand_do_read_ops(mtd, from, &ops);
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 9bb4985275..76509a52a1 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -155,6 +155,7 @@ config DRIVER_NET_ETHOC
config DRIVER_NET_FEC_IMX
bool "i.MX FEC Ethernet driver"
depends on ARCH_HAS_FEC_IMX || COMPILE_TEST
+ depends on HAS_DMA
select PHYLIB
config DRIVER_NET_FSL_FMAN
@@ -180,6 +181,7 @@ config DRIVER_NET_KS8851_MLL
config DRIVER_NET_MACB
bool "macb Ethernet driver"
depends on HAS_MACB || COMPILE_TEST
+ depends on HAS_DMA
select PHYLIB
config DRIVER_NET_MICREL
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 886cbef14c..9ffbb103d5 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -17,8 +17,8 @@
#define HOST_XHCI_H_
#include <asm/types.h>
-#include <asm/cache.h>
#include <io.h>
+#include <io-64-nonatomic-lo-hi.h>
#include <linux/list.h>
#define MAX_EP_CTX_NUM 31
@@ -1113,10 +1113,7 @@ static inline u64 xhci_readq(__le64 volatile *regs)
#if BITS_PER_LONG == 64
return readq(regs);
#else
- __u32 *ptr = (__u32 *)regs;
- u64 val_lo = readl(ptr);
- u64 val_hi = readl(ptr + 1);
- return val_lo + (val_hi << 32);
+ return lo_hi_readq(regs);
#endif
}
@@ -1125,12 +1122,7 @@ static inline void xhci_writeq(__le64 volatile *regs, const u64 val)
#if BITS_PER_LONG == 64
writeq(val, regs);
#else
- __u32 *ptr = (__u32 *)regs;
- u32 val_lo = lower_32_bits(val);
- /* FIXME */
- u32 val_hi = upper_32_bits(val);
- writel(val_lo, ptr);
- writel(val_hi, ptr + 1);
+ lo_hi_writeq(val, regs);
#endif
}
diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
new file mode 100644
index 0000000000..449cecaabc
--- /dev/null
+++ b/include/asm-generic/atomic.h
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * based on linux/include/asm-arm/atomic.h
+ *
+ * Copyright (c) 1996 Russell King.
+ */
+
+#ifndef __ASM_GENERIC_ATOMIC_H
+#define __ASM_GENERIC_ATOMIC_H
+
+#ifdef CONFIG_SMP
+#error SMP not supported
+#endif
+
+typedef struct { volatile int counter; } atomic_t;
+
+#define ATOMIC_INIT(i) { (i) }
+
+#define atomic_read(v) ((v)->counter)
+#define atomic_set(v,i) (((v)->counter) = (i))
+
+static inline void atomic_add(int i, volatile atomic_t *v)
+{
+ v->counter += i;
+}
+
+static inline void atomic_sub(int i, volatile atomic_t *v)
+{
+ v->counter -= i;
+}
+
+static inline void atomic_inc(volatile atomic_t *v)
+{
+ v->counter += 1;
+}
+
+static inline void atomic_dec(volatile atomic_t *v)
+{
+ v->counter -= 1;
+}
+
+static inline int atomic_dec_and_test(volatile atomic_t *v)
+{
+ int val;
+
+ val = v->counter;
+ v->counter = val -= 1;
+
+ return val == 0;
+}
+
+static inline int atomic_add_negative(int i, volatile atomic_t *v)
+{
+ int val;
+
+ val = v->counter;
+ v->counter = val += i;
+
+ return val < 0;
+}
+
+static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
+{
+ *addr &= ~mask;
+}
+
+/* Atomic operations are already serializing on ARM */
+#define smp_mb__before_atomic_dec() barrier()
+#define smp_mb__after_atomic_dec() barrier()
+#define smp_mb__before_atomic_inc() barrier()
+#define smp_mb__after_atomic_inc() barrier()
+
+#endif
diff --git a/include/asm-generic/bitio.h b/include/asm-generic/bitio.h
new file mode 100644
index 0000000000..e88dbd7b85
--- /dev/null
+++ b/include/asm-generic/bitio.h
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#ifndef __ASM_GENERIC_BITIO_H
+#define __ASM_GENERIC_BITIO_H
+
+#include <asm-generic/io.h>
+
+/*
+ * Clear and set bits in one shot. These macros can be used to clear and
+ * set multiple bits in a register using a single call. These macros can
+ * also be used to set a multiple-bit bit pattern using a mask, by
+ * specifying the mask in the 'clear' parameter and the new bit pattern
+ * in the 'set' parameter.
+ */
+
+#ifndef out_arch
+#define out_arch(type,endian,a,v) __raw_write##type(cpu_to_##endian(v),a)
+#endif
+
+#ifndef in_arch
+#define in_arch(type,endian,a) endian##_to_cpu(__raw_read##type(a))
+#endif
+
+#ifndef out_le64
+#define out_le64(a,v) out_arch(q,le64,a,v)
+#endif
+
+#ifndef out_le32
+#define out_le32(a,v) out_arch(l,le32,a,v)
+#endif
+
+#ifndef out_le16
+#define out_le16(a,v) out_arch(w,le16,a,v)
+#endif
+
+#ifndef in_le64
+#define in_le64(a) in_arch(q,le64,a)
+#endif
+
+#ifndef in_le32
+#define in_le32(a) in_arch(l,le32,a)
+#endif
+
+#ifndef in_le16
+#define in_le16(a) in_arch(w,le16,a)
+#endif
+
+#ifndef out_be32
+#define out_be32(a,v) out_arch(l,be32,a,v)
+#endif
+
+#ifndef out_be16
+#define out_be16(a,v) out_arch(w,be16,a,v)
+#endif
+
+#ifndef in_be32
+#define in_be32(a) in_arch(l,be32,a)
+#endif
+
+#ifndef in_be16
+#define in_be16(a) in_arch(w,be16,a)
+#endif
+
+#ifndef out_8
+#define out_8(a,v) __raw_writeb(v,a)
+#endif
+
+#ifndef in_8
+#define in_8(a) __raw_readb(a)
+#endif
+
+#ifndef clrbits
+#define clrbits(type, addr, clear) \
+ out_##type((addr), in_##type(addr) & ~(clear))
+#endif
+
+#ifndef setbits
+#define setbits(type, addr, set) \
+ out_##type((addr), in_##type(addr) | (set))
+#endif
+
+#define clrsetbits(type, addr, clear, set) \
+ out_##type((addr), (in_##type(addr) & ~(clear)) | (set))
+
+#ifndef clrbits_be32
+#define clrbits_be32(addr, clear) clrbits(be32, addr, clear)
+#endif
+
+#ifndef setbits_be32
+#define setbits_be32(addr, set) setbits(be32, addr, set)
+#endif
+
+#ifndef clrsetbits_be32
+#define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set)
+#endif
+
+#ifndef clrbits_le32
+#define clrbits_le32(addr, clear) clrbits(le32, addr, clear)
+#endif
+
+#ifndef setbits_le32
+#define setbits_le32(addr, set) setbits(le32, addr, set)
+#endif
+
+#ifndef clrsetbits_le32
+#define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set)
+#endif
+
+#ifndef clrbits_be16
+#define clrbits_be16(addr, clear) clrbits(be16, addr, clear)
+#endif
+
+#ifndef setbits_be16
+#define setbits_be16(addr, set) setbits(be16, addr, set)
+#endif
+
+#ifndef clrsetbits_be16
+#define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set)
+#endif
+
+#ifndef clrbits_le16
+#define clrbits_le16(addr, clear) clrbits(le16, addr, clear)
+#endif
+
+#ifndef setbits_le16
+#define setbits_le16(addr, set) setbits(le16, addr, set)
+#endif
+
+#ifndef clrsetbits_le16
+#define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set)
+#endif
+
+#ifndef clrbits_8
+#define clrbits_8(addr, clear) clrbits(8, addr, clear)
+#endif
+
+#ifndef setbits_8
+#define setbits_8(addr, set) setbits(8, addr, set)
+#endif
+
+#ifndef clrsetbits_8
+#define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
+#endif
+
+#endif /* __ASM_GENERIC_IO_H */
diff --git a/include/asm-generic/bitops/ffs.h b/include/asm-generic/bitops/ffs.h
index fbbb43af7d..0ff1b8b7c7 100644
--- a/include/asm-generic/bitops/ffs.h
+++ b/include/asm-generic/bitops/ffs.h
@@ -31,10 +31,8 @@ static inline int ffs(int x)
x >>= 2;
r += 2;
}
- if (!(x & 1)) {
- x >>= 1;
+ if (!(x & 1))
r += 1;
- }
return r;
}
diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
index 850859bc50..cc0d3ca95a 100644
--- a/include/asm-generic/bitops/fls.h
+++ b/include/asm-generic/bitops/fls.h
@@ -31,10 +31,8 @@ static inline int fls(int x)
x <<= 2;
r -= 2;
}
- if (!(x & 0x80000000u)) {
- x <<= 1;
+ if (!(x & 0x80000000u))
r -= 1;
- }
return r;
}
diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include
new file mode 100644
index 0000000000..496d11c92c
--- /dev/null
+++ b/scripts/Kconfig.include
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# Kconfig helper macros
+
+# Convenient variables
+comma := ,
+quote := "
+squote := '
+empty :=
+space := $(empty) $(empty)
+dollar := $
+right_paren := )
+left_paren := (
+
+# $(if-success,<command>,<then>,<else>)
+# Return <then> if <command> exits with 0, <else> otherwise.
+if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)")
+
+# $(success,<command>)
+# Return y if <command> exits with 0, n otherwise
+success = $(if-success,$(1),y,n)
+
+# $(failure,<command>)
+# Return n if <command> exits with 0, y otherwise
+failure = $(if-success,$(1),n,y)
+
+# $(cc-option,<flag>)
+# Return y if the compiler supports <flag>, n otherwise
+cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -S -x c /dev/null -o /dev/null)
+
+# $(ld-option,<flag>)
+# Return y if the linker supports <flag>, n otherwise
+ld-option = $(success,$(LD) -v $(1))
+
+# $(as-instr,<instr>)
+# Return y if the assembler supports <instr>, n otherwise
+as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -)
+
+# check if $(CC) and $(LD) exist
+$(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found)
+$(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
+
+# Fail if the linker is gold as it's not capable of linking the kernel proper
+$(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supported)
+
+# gcc version including patch level
+gcc-version := $(shell,$(srctree)/scripts/gcc-version.sh $(CC))
+
+# machine bit flags
+# $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
+# $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
+cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
+m32-flag := $(cc-option-bit,-m32)
+m64-flag := $(cc-option-bit,-m64)
diff --git a/scripts/gcc-64bitptr.sh b/scripts/gcc-64bitptr.sh
new file mode 100755
index 0000000000..7fb05703b8
--- /dev/null
+++ b/scripts/gcc-64bitptr.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-only
+
+cat << "END" | $@ -x c - -c -o /dev/null
+int main(void)
+{
+ return sizeof(struct { int:-!(sizeof(void *) == 8); });
+}
+END
diff --git a/scripts/gcc-version.sh b/scripts/gcc-version.sh
new file mode 100755
index 0000000000..ae35343253
--- /dev/null
+++ b/scripts/gcc-version.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# gcc-version gcc-command
+#
+# Print the gcc version of `gcc-command' in a 5 or 6-digit form
+# such as `29503' for gcc-2.95.3, `30301' for gcc-3.3.1, etc.
+
+compiler="$*"
+
+if [ ${#compiler} -eq 0 ]; then
+ echo "Error: No compiler specified." >&2
+ printf "Usage:\n\t$0 <gcc-command>\n" >&2
+ exit 1
+fi
+
+MAJOR=$(echo __GNUC__ | $compiler -E -x c - | tail -n 1)
+MINOR=$(echo __GNUC_MINOR__ | $compiler -E -x c - | tail -n 1)
+PATCHLEVEL=$(echo __GNUC_PATCHLEVEL__ | $compiler -E -x c - | tail -n 1)
+printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL