Skip to content

Commit 7655146

Browse files
Eugeniy Paltsevvineetgarc
authored andcommitted
ARCv2: Add explcit unaligned access support (and ability to disable too)
As of today we enable unaligned access unconditionally on ARCv2. Do this under a Kconfig option to allow disable it for test, benchmarking etc. Also while at it - Select HAVE_EFFICIENT_UNALIGNED_ACCESS - Although gcc defaults to unaligned access (since GNU 2018.03), add the right toggles for enabling or disabling as appropriate - update bootlog to prints both HW feature status (exists, enabled/disabled) and SW status (used / not used). - wire up the relaxed memcpy for unaligned access Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com> Signed-off-by: Vineet Gupta <vgupta@synopsys.com> [vgupta: squashed patches, handle gcc -mno-unaligned-access quick]
1 parent 4d1e791 commit 7655146

File tree

9 files changed

+56
-13
lines changed

9 files changed

+56
-13
lines changed

arch/arc/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,15 @@ config ARC_HAS_SWAPE
386386

387387
if ISA_ARCV2
388388

389+
config ARC_USE_UNALIGNED_MEM_ACCESS
390+
bool "Enable unaligned access in HW"
391+
default y
392+
select HAVE_EFFICIENT_UNALIGNED_ACCESS
393+
help
394+
The ARC HS architecture supports unaligned memory access
395+
which is disabled by default. Enable unaligned access in
396+
hardware and use software to use it
397+
389398
config ARC_HAS_LL64
390399
bool "Insn: 64bit LDD/STD"
391400
help

arch/arc/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ cflags-$(CONFIG_ARC_HAS_SWAPE) += -mswape
2828

2929
ifdef CONFIG_ISA_ARCV2
3030

31+
ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
32+
cflags-y += -munaligned-access
33+
else
34+
cflags-y += -mno-unaligned-access
35+
endif
36+
3137
ifndef CONFIG_ARC_HAS_LL64
3238
cflags-y += -mno-ll64
3339
endif

arch/arc/include/asm/arcregs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#define ECR_V_DTLB_MISS 0x05
8383
#define ECR_V_PROTV 0x06
8484
#define ECR_V_TRAP 0x09
85+
#define ECR_V_MISALIGN 0x0d
8586
#endif
8687

8788
/* DTLB Miss and Protection Violation Cause Codes */

arch/arc/include/asm/irqflags-arcv2.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@
4444
#define ARCV2_IRQ_DEF_PRIO 1
4545

4646
/* seed value for status register */
47-
#define ISA_INIT_STATUS_BITS (STATUS_IE_MASK | STATUS_AD_MASK | \
47+
#ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
48+
#define __AD_ENB STATUS_AD_MASK
49+
#else
50+
#define __AD_ENB 0
51+
#endif
52+
53+
#define ISA_INIT_STATUS_BITS (STATUS_IE_MASK | __AD_ENB | \
4854
(ARCV2_IRQ_DEF_PRIO << 1))
4955

5056
#ifndef __ASSEMBLY__

arch/arc/kernel/head.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@
5454
; gcc 7.3.1 (ARC GNU 2018.03) onwards generates unaligned access
5555
; by default
5656
lr r5, [status32]
57+
#ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
5758
bset r5, r5, STATUS_AD_BIT
59+
#else
60+
; Although disabled at reset, bootloader might have enabled it
61+
bclr r5, r5, STATUS_AD_BIT
62+
#endif
5863
kflag r5
5964
#endif
6065
.endm

arch/arc/kernel/intc-arcv2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void arc_init_IRQ(void)
9595

9696
/* setup status32, don't enable intr yet as kernel doesn't want */
9797
tmp = read_aux_reg(ARC_REG_STATUS32);
98-
tmp |= STATUS_AD_MASK | (ARCV2_IRQ_DEF_PRIO << 1);
98+
tmp |= ARCV2_IRQ_DEF_PRIO << 1;
9999
tmp &= ~STATUS_IE_MASK;
100100
asm volatile("kflag %0 \n"::"r"(tmp));
101101
}

arch/arc/kernel/setup.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
263263
{
264264
struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
265265
struct bcr_identity *core = &cpu->core;
266-
int i, n = 0, ua = 0;
266+
int n = 0;
267267

268268
FIX_PTR(cpu);
269269

@@ -283,16 +283,23 @@ static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
283283
IS_AVAIL2(cpu->extn.rtc, "RTC [UP 64-bit] ", CONFIG_ARC_TIMERS_64BIT),
284284
IS_AVAIL2(cpu->extn.gfrc, "GFRC [SMP 64-bit] ", CONFIG_ARC_TIMERS_64BIT));
285285

286-
#ifdef __ARC_UNALIGNED__
287-
ua = 1;
286+
n += scnprintf(buf + n, len - n, "%s%s%s%s%s%s",
287+
IS_AVAIL2(cpu->isa.atomic, "atomic ", CONFIG_ARC_HAS_LLSC),
288+
IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64),
289+
IS_AVAIL2(cpu->isa.unalign, "unalign ", CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS));
290+
291+
#if defined(__ARC_UNALIGNED__) && !defined(CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS)
292+
/*
293+
* gcc 7.3.1 (GNU 2018.03) onwards generate unaligned access by default
294+
* but -mno-unaligned-access to disable that didn't work until gcc 8.2.1
295+
* (GNU 2019.03). So landing here implies the interim period, when
296+
* despite Kconfig being off, gcc is generating unaligned accesses which
297+
* could bomb later on. So better to disallow such broken builds
298+
*/
299+
BUILD_BUG_ON_MSG(1, "gcc doesn't support -mno-unaligned-access");
288300
#endif
289-
n += i = scnprintf(buf + n, len - n, "%s%s%s%s%s%s",
290-
IS_AVAIL2(cpu->isa.atomic, "atomic ", CONFIG_ARC_HAS_LLSC),
291-
IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64),
292-
IS_AVAIL1(cpu->isa.unalign, "unalign "), IS_USED_RUN(ua));
293301

294-
if (i)
295-
n += scnprintf(buf + n, len - n, "\n\t\t: ");
302+
n += scnprintf(buf + n, len - n, "\n\t\t: ");
296303

297304
if (cpu->extn_mpy.ver) {
298305
if (cpu->extn_mpy.ver <= 0x2) { /* ARCompact */

arch/arc/kernel/troubleshoot.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ static void show_ecr_verbose(struct pt_regs *regs)
145145
} else if (vec == ECR_V_PROTV) {
146146
if (cause_code == ECR_C_PROTV_INST_FETCH)
147147
pr_cont("Execute from Non-exec Page\n");
148-
else if (cause_code == ECR_C_PROTV_MISALIG_DATA)
148+
else if (cause_code == ECR_C_PROTV_MISALIG_DATA &&
149+
IS_ENABLED(CONFIG_ISA_ARCOMPACT))
149150
pr_cont("Misaligned r/w from 0x%08lx\n", address);
150151
else
151152
pr_cont("%s access not allowed on page\n",
@@ -161,6 +162,8 @@ static void show_ecr_verbose(struct pt_regs *regs)
161162
pr_cont("Bus Error from Data Mem\n");
162163
else
163164
pr_cont("Bus Error, check PRM\n");
165+
} else if (vec == ECR_V_MISALIGN) {
166+
pr_cont("Misaligned r/w from 0x%08lx\n", address);
164167
#endif
165168
} else if (vec == ECR_V_TRAP) {
166169
if (regs->ecr_param == 5)

arch/arc/lib/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@
88
lib-y := strchr-700.o strcpy-700.o strlen.o memcmp.o
99

1010
lib-$(CONFIG_ISA_ARCOMPACT) += memcpy-700.o memset.o strcmp.o
11-
lib-$(CONFIG_ISA_ARCV2) += memcpy-archs.o memset-archs.o strcmp-archs.o
11+
lib-$(CONFIG_ISA_ARCV2) += memset-archs.o strcmp-archs.o
12+
13+
ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
14+
lib-$(CONFIG_ISA_ARCV2) +=memcpy-archs-unaligned.o
15+
else
16+
lib-$(CONFIG_ISA_ARCV2) +=memcpy-archs.o
17+
endif

0 commit comments

Comments
 (0)