Skip to content

Commit 5636919

Browse files
committed
MIPS: Outline udelay and fix a few issues.
Outlining fixes the issue were on certain CPUs such as the R10000 family the delay loop would need an extra cycle if it overlaps a cacheline boundary. The rewrite also fixes build errors with GCC 4.4 which was changed in way incompatible with the kernel's inline assembly. Relying on pure C for computation of the delay value removes the need for explicit. The price we pay is a slight slowdown of the computation - to be fixed on another day. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 3a55314 commit 5636919

5 files changed

Lines changed: 66 additions & 92 deletions

File tree

‎arch/mips/include/asm/cpu-info.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ struct cache_desc {
3939
#define MIPS_CACHE_PINDEX 0x00000020 /* Physically indexed cache */
4040

4141
struct cpuinfo_mips {
42-
unsigned long udelay_val;
43-
unsigned long asid_cache;
42+
unsigned int udelay_val;
43+
unsigned int asid_cache;
4444

4545
/*
4646
* Capability and feature descriptor structure for MIPS CPU

‎arch/mips/include/asm/delay.h‎

Lines changed: 5 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -11,94 +11,12 @@
1111
#ifndef _ASM_DELAY_H
1212
#define _ASM_DELAY_H
1313

14-
#include <linux/param.h>
15-
#include <linux/smp.h>
14+
extern void __delay(unsigned int loops);
15+
extern void __ndelay(unsigned int ns);
16+
extern void __udelay(unsigned int us);
1617

17-
#include <asm/compiler.h>
18-
#include <asm/war.h>
19-
20-
static inline void __delay(unsigned long loops)
21-
{
22-
if (sizeof(long) == 4)
23-
__asm__ __volatile__ (
24-
" .set noreorder \n"
25-
" .align 3 \n"
26-
"1: bnez %0, 1b \n"
27-
" subu %0, 1 \n"
28-
" .set reorder \n"
29-
: "=r" (loops)
30-
: "0" (loops));
31-
else if (sizeof(long) == 8 && !DADDI_WAR)
32-
__asm__ __volatile__ (
33-
" .set noreorder \n"
34-
" .align 3 \n"
35-
"1: bnez %0, 1b \n"
36-
" dsubu %0, 1 \n"
37-
" .set reorder \n"
38-
: "=r" (loops)
39-
: "0" (loops));
40-
else if (sizeof(long) == 8 && DADDI_WAR)
41-
__asm__ __volatile__ (
42-
" .set noreorder \n"
43-
" .align 3 \n"
44-
"1: bnez %0, 1b \n"
45-
" dsubu %0, %2 \n"
46-
" .set reorder \n"
47-
: "=r" (loops)
48-
: "0" (loops), "r" (1));
49-
}
50-
51-
52-
/*
53-
* Division by multiplication: you don't have to worry about
54-
* loss of precision.
55-
*
56-
* Use only for very small delays ( < 1 msec). Should probably use a
57-
* lookup table, really, as the multiplications take much too long with
58-
* short delays. This is a "reasonable" implementation, though (and the
59-
* first constant multiplications gets optimized away if the delay is
60-
* a constant)
61-
*/
62-
63-
static inline void __udelay(unsigned long usecs, unsigned long lpj)
64-
{
65-
unsigned long hi, lo;
66-
67-
/*
68-
* The rates of 128 is rounded wrongly by the catchall case
69-
* for 64-bit. Excessive precission? Probably ...
70-
*/
71-
#if defined(CONFIG_64BIT) && (HZ == 128)
72-
usecs *= 0x0008637bd05af6c7UL; /* 2**64 / (1000000 / HZ) */
73-
#elif defined(CONFIG_64BIT)
74-
usecs *= (0x8000000000000000UL / (500000 / HZ));
75-
#else /* 32-bit junk follows here */
76-
usecs *= (unsigned long) (((0x8000000000000000ULL / (500000 / HZ)) +
77-
0x80000000ULL) >> 32);
78-
#endif
79-
80-
if (sizeof(long) == 4)
81-
__asm__("multu\t%2, %3"
82-
: "=h" (usecs), "=l" (lo)
83-
: "r" (usecs), "r" (lpj)
84-
: GCC_REG_ACCUM);
85-
else if (sizeof(long) == 8 && !R4000_WAR)
86-
__asm__("dmultu\t%2, %3"
87-
: "=h" (usecs), "=l" (lo)
88-
: "r" (usecs), "r" (lpj)
89-
: GCC_REG_ACCUM);
90-
else if (sizeof(long) == 8 && R4000_WAR)
91-
__asm__("dmultu\t%3, %4\n\tmfhi\t%0"
92-
: "=r" (usecs), "=h" (hi), "=l" (lo)
93-
: "r" (usecs), "r" (lpj)
94-
: GCC_REG_ACCUM);
95-
96-
__delay(usecs);
97-
}
98-
99-
#define __udelay_val cpu_data[raw_smp_processor_id()].udelay_val
100-
101-
#define udelay(usecs) __udelay((usecs), __udelay_val)
18+
#define ndelay(ns) __udelay(ns)
19+
#define udelay(us) __udelay(us)
10220

10321
/* make sure "usecs *= ..." in udelay do not overflow. */
10422
#if HZ >= 1000

‎arch/mips/kernel/proc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
4242
seq_printf(m, fmt, __cpu_name[n],
4343
(version >> 4) & 0x0f, version & 0x0f,
4444
(fp_vers >> 4) & 0x0f, fp_vers & 0x0f);
45-
seq_printf(m, "BogoMIPS\t\t: %lu.%02lu\n",
45+
seq_printf(m, "BogoMIPS\t\t: %u.%02u\n",
4646
cpu_data[n].udelay_val / (500000/HZ),
4747
(cpu_data[n].udelay_val / (5000/HZ)) % 100);
4848
seq_printf(m, "wait instruction\t: %s\n", cpu_wait ? "yes" : "no");

‎arch/mips/lib/Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# Makefile for MIPS-specific library files..
33
#
44

5-
lib-y += csum_partial.o memcpy.o memcpy-inatomic.o memset.o strlen_user.o \
6-
strncpy_user.o strnlen_user.o uncached.o
5+
lib-y += csum_partial.o delay.o memcpy.o memcpy-inatomic.o memset.o \
6+
strlen_user.o strncpy_user.o strnlen_user.o uncached.o
77

88
obj-y += iomap.o
99
obj-$(CONFIG_PCI) += iomap-pci.o

‎arch/mips/lib/delay.c‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* This file is subject to the terms and conditions of the GNU General Public
3+
* License. See the file "COPYING" in the main directory of this archive
4+
* for more details.
5+
*
6+
* Copyright (C) 1994 by Waldorf Electronics
7+
* Copyright (C) 1995 - 2000, 01, 03 by Ralf Baechle
8+
* Copyright (C) 1999, 2000 Silicon Graphics, Inc.
9+
* Copyright (C) 2007 Maciej W. Rozycki
10+
*/
11+
#include <linux/module.h>
12+
#include <linux/param.h>
13+
#include <linux/smp.h>
14+
15+
#include <asm/compiler.h>
16+
#include <asm/war.h>
17+
18+
inline void __delay(unsigned int loops)
19+
{
20+
__asm__ __volatile__ (
21+
" .set noreorder \n"
22+
" .align 3 \n"
23+
"1: bnez %0, 1b \n"
24+
" subu %0, 1 \n"
25+
" .set reorder \n"
26+
: "=r" (loops)
27+
: "0" (loops));
28+
}
29+
EXPORT_SYMBOL(__delay);
30+
31+
/*
32+
* Division by multiplication: you don't have to worry about
33+
* loss of precision.
34+
*
35+
* Use only for very small delays ( < 1 msec). Should probably use a
36+
* lookup table, really, as the multiplications take much too long with
37+
* short delays. This is a "reasonable" implementation, though (and the
38+
* first constant multiplications gets optimized away if the delay is
39+
* a constant)
40+
*/
41+
42+
void __udelay(unsigned long us)
43+
{
44+
unsigned int lpj = current_cpu_data.udelay_val;
45+
46+
__delay((us * 0x000010c7 * HZ * lpj) >> 32);
47+
}
48+
EXPORT_SYMBOL(__udelay);
49+
50+
void __ndelay(unsigned long ns)
51+
{
52+
unsigned int lpj = current_cpu_data.udelay_val;
53+
54+
__delay((us * 0x00000005 * HZ * lpj) >> 32);
55+
}
56+
EXPORT_SYMBOL(__ndelay);

0 commit comments

Comments
 (0)