Patrick Georgi (patrick@georgi-clan.de) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6494
-gerrit
commit 5b1d7cbcd898acb685146f41deb95a73930b8399 Author: Patrick Georgi patrick@georgi-clan.de Date: Mon Aug 4 18:49:52 2014 +0200
add poll-with-timeout macro
A new poll.h provides a macro to wait for a certain event to happen with a timeout.
Use: POLL(statement, expected value, max time in usecs)
Change-Id: Icbb57a47d8ca1cff504f01954c0693fb60b77656 Signed-off-by: Patrick Georgi patrick@georgi-clan.de --- src/include/poll.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
diff --git a/src/include/poll.h b/src/include/poll.h new file mode 100644 index 0000000..1084731 --- /dev/null +++ b/src/include/poll.h @@ -0,0 +1,45 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2013 Google Inc. + * 2014 Patrick Georgi + * + * 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 + */ + +#ifndef _POLL_H_ +#define _POLL_H_ + +#include <delay.h> + +#define POLL_DELAY 100 /* 100us */ + +#define POLL(insn, exp_val, timeout) \ + ({\ + u64 _try, _value; \ + u64 _timeout = (timeout); \ + u64 _exp_val = (exp_val); \ + for (_try = 0; _try < (_timeout); _try += POLL_DELAY) { \ + _value = insn; \ + if (_value == _exp_val) \ + break; \ + udelay(POLL_DELAY); \ + } \ + if (_try >= _timeout) \ + printk(BIOS_WARNING, "%s: POLL timeout waiting for " #insn \ + " to return 0x%llx, got 0x%llx\n", \ + __func__, _exp_val, _value); \ + }) + +#endif