arm: Translate delay.S into (mostly) C
In the next patch we're going to allow machines to override the __delay() implementation at runtime so they can implement a timer based __delay() routine. It's easier to do this using C, so lets write udelay and friends in C. We lose the #if 0 code, which according to Russell is used "to make the delay loop more stable and predictable on older CPUs" (see http://article.gmane.org/gmane.linux.kernel/888867 for more info). We shouldn't be too worried though, since the next patch adds functionality to allow a machine to set the __delay() loop themselves, therefore allowing machines to resurrect the commented out code if they need it. bloat-o-meter shows an increase of 12 bytes. Further inspection of the assembly shows GCC copying the loops_per_jiffy pointer and the magic HZ value to the ends of __const_udelay() and _delay() thus contributing an extra 4 and 8 bytes of data to each function. These two values weren't taken into account in the delay.S version since they weren't part of the function in nm's eyes. This means we only really gained an extra 4 bytes due to GCC's decision to duplicate the loops_per_jiffy pointer in __const_udelay. $ scripts/bloat-o-meter vmlinux.orig vmlinux.new add/remove: 0/0 grow/shrink: 2/0 up/down: 12/0 (12) function old new delta __udelay 48 56 +8 __const_udelay 40 44 +4 Change-Id: Ibfaab52d0f5e09471571be082232db04726d5532 Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Reviewed-by: Saravana Kannan <skannan@codeaurora.org> (cherry picked from commit 8d5868d8205d10a0a8e423f53e9cc9bb3e9d1a34) Conflicts: arch/arm/kernel/armksyms.c arch/arm/lib/delay.S
This commit is contained in:
57
arch/arm/lib/delay.c
Normal file
57
arch/arm/lib/delay.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Originally from linux/arch/arm/lib/delay.S
|
||||
*
|
||||
* Copyright (C) 1995, 1996 Russell King
|
||||
* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include <linux/module.h>
|
||||
#include <linux/delay.h>
|
||||
|
||||
/*
|
||||
* loops = usecs * HZ * loops_per_jiffy / 1000000
|
||||
*
|
||||
* Oh, if only we had a cycle counter...
|
||||
*/
|
||||
void __delay(unsigned long loops)
|
||||
{
|
||||
asm volatile(
|
||||
"1: subs %0, %0, #1 \n"
|
||||
" bhi 1b \n"
|
||||
: /* No output */
|
||||
: "r" (loops)
|
||||
);
|
||||
}
|
||||
EXPORT_SYMBOL(__delay);
|
||||
|
||||
/*
|
||||
* 0 <= xloops <= 0x7fffff06
|
||||
* loops_per_jiffy <= 0x01ffffff (max. 3355 bogomips)
|
||||
*/
|
||||
void __const_udelay(unsigned long xloops)
|
||||
{
|
||||
unsigned long lpj;
|
||||
unsigned long loops;
|
||||
|
||||
xloops >>= 14; /* max = 0x01ffffff */
|
||||
lpj = loops_per_jiffy >> 10; /* max = 0x0001ffff */
|
||||
loops = lpj * xloops; /* max = 0x00007fff */
|
||||
loops >>= 6; /* max = 2^32-1 */
|
||||
|
||||
if (loops)
|
||||
__delay(loops);
|
||||
}
|
||||
EXPORT_SYMBOL(__const_udelay);
|
||||
|
||||
/*
|
||||
* usecs <= 2000
|
||||
* HZ <= 1000
|
||||
*/
|
||||
void __udelay(unsigned long usecs)
|
||||
{
|
||||
__const_udelay(usecs * ((2199023*HZ)>>11));
|
||||
}
|
||||
EXPORT_SYMBOL(__udelay);
|
||||
Reference in New Issue
Block a user