timer: generic udelay()

Add GENERIC_UDELAY Kconfig option so that a generic
udelay() implementation is provided utilizing the
monotonic timer. That way each board/chipset doesn't
need to duplicate the same udelay(). Additionally,
assume that GENERIC_UDELAY implies init_timer()
is not required.

BUG=None
BRANCH=None
TEST=Built nyan, ryu, and rambi. May need help testing.

Change-Id: Idd26de19eefc91ee3b0ceddfb1bc2152e19fd8ab
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/219719
Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
This commit is contained in:
Aaron Durbin 2014-09-25 10:05:15 -05:00 committed by chrome-internal-fetch
commit 1a85fbcad7
19 changed files with 24 additions and 243 deletions

View file

@ -22,6 +22,8 @@ bootblock-$(CONFIG_COMMON_CBFS_SPI_WRAPPER) += cbfs_spi.c
bootblock-y += memchr.c
bootblock-y += memcmp.c
bootblock-$(CONFIG_GENERIC_UDELAY) += timer.c
ifeq ($(CONFIG_BOOTBLOCK_CONSOLE),y)
bootblock-$(CONFIG_CONSOLE_SERIAL8250) += uart8250.c
bootblock-$(CONFIG_CONSOLE_SERIAL8250MEM) += uart8250mem.c
@ -40,6 +42,7 @@ verstage-y += cbfs.c
verstage-y += memcmp.c
verstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
verstage-y += tlcl.c
verstage-$(CONFIG_GENERIC_UDELAY) += timer.c
romstage-y += delay.c
romstage-y += cbfs.c
@ -58,6 +61,7 @@ romstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
romstage-$(CONFIG_EARLY_CBMEM_INIT) += cbmem.c
romstage-y += compute_ip_checksum.c
romstage-$(CONFIG_ARCH_ROMSTAGE_X86_32) += gcc.c
romstage-$(CONFIG_GENERIC_UDELAY) += timer.c
ramstage-y += hardwaremain.c
ramstage-y += selfboot.c
@ -90,6 +94,7 @@ ramstage-y += memrange.c
ramstage-$(CONFIG_COOP_MULTITASKING) += thread.c
ramstage-$(CONFIG_TIMER_QUEUE) += timer_queue.c
ramstage-$(CONFIG_TERTIARY_BOARD_ID) += tristate_gpios.c
ramstage-$(CONFIG_GENERIC_UDELAY) += timer.c
# The CBMEM implementations are chosen based on CONFIG_DYNAMIC_CBMEM.
ifeq ($(CONFIG_DYNAMIC_CBMEM),y)

42
src/lib/timer.c Normal file
View file

@ -0,0 +1,42 @@
/*
* This file is part of the coreboot project.
*
* Copyright 2014 Google Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <console/console.h>
#include <timer.h>
#include <delay.h>
#include <thread.h>
void udelay(unsigned usec)
{
struct stopwatch sw;
/*
* As the timer granularity is in microseconds pad the
* requested delay by one to get at least >= requested usec delay.
*/
usec += 1;
if (!thread_yield_microseconds(usec))
return;
stopwatch_init_usecs_expire(&sw, usec);
while (!stopwatch_expired(&sw))
;
}