timer: Change timer util functions to 64-bit

Since mono_time is now 64-bit, the utility functions interfacing with
mono_time should also be 64-bit so precision isn't lost.

Fixed build errors related to printing the now int64_t result of
stopwatch_duration_[m|u]secs in various places.

BUG=b:237082996
BRANCH=All
TEST=Boot dewatt

Change-Id: I169588f5e14285557f2d03270f58f4c07c0154d5
Signed-off-by: Rob Barnes <robbarnes@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/66170
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Werner Zeh <werner.zeh@siemens.com>
Reviewed-by: Raul Rangel <rrangel@chromium.org>
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
diff --git a/src/cpu/x86/mp_init.c b/src/cpu/x86/mp_init.c
index 3f80694..0d9cd41 100644
--- a/src/cpu/x86/mp_init.c
+++ b/src/cpu/x86/mp_init.c
@@ -525,7 +525,7 @@
 		release_barrier(&rec->barrier);
 	}
 
-	printk(BIOS_INFO, "%s done after %ld msecs.\n", __func__,
+	printk(BIOS_INFO, "%s done after %lld msecs.\n", __func__,
 	       stopwatch_duration_msecs(&sw));
 	return ret;
 }
diff --git a/src/drivers/i2c/tpm/cr50.c b/src/drivers/i2c/tpm/cr50.c
index 6965339..b5cb32c 100644
--- a/src/drivers/i2c/tpm/cr50.c
+++ b/src/drivers/i2c/tpm/cr50.c
@@ -173,7 +173,7 @@
 			continue;
 		}
 
-		printk(BIOS_INFO, "TPM ready after %ld ms\n",
+		printk(BIOS_INFO, "TPM ready after %lld ms\n",
 		       stopwatch_duration_msecs(&sw));
 
 		return 0;
@@ -183,7 +183,7 @@
 		printk(BIOS_ERR, "Failed to read TPM\n");
 	else
 		printk(BIOS_ERR,
-			"TPM failed to reset after %ld ms, status: %#x\n",
+			"TPM failed to reset after %lld ms, status: %#x\n",
 			stopwatch_duration_msecs(&sw), access);
 
 	return -1;
diff --git a/src/drivers/spi/spi_flash.c b/src/drivers/spi/spi_flash.c
index 9934f55..5d78b61 100644
--- a/src/drivers/spi/spi_flash.c
+++ b/src/drivers/spi/spi_flash.c
@@ -212,7 +212,7 @@
 			return 0;
 	} while (!stopwatch_expired(&sw));
 
-	printk(BIOS_WARNING, "SF: timeout at %ld msec after %d attempts\n",
+	printk(BIOS_WARNING, "SF: timeout at %lld msec after %d attempts\n",
 	       stopwatch_duration_msecs(&sw), attempt);
 
 	return -1;
diff --git a/src/drivers/spi/tpm/tpm.c b/src/drivers/spi/tpm/tpm.c
index 5645e57..68f9588 100644
--- a/src/drivers/spi/tpm/tpm.c
+++ b/src/drivers/spi/tpm/tpm.c
@@ -390,14 +390,14 @@
 			break;
 		}
 
-		printk(BIOS_INFO, "TPM ready after %ld ms\n",
+		printk(BIOS_INFO, "TPM ready after %lld ms\n",
 		       stopwatch_duration_msecs(&sw));
 
 		return CB_SUCCESS;
 	} while (!stopwatch_expired(&sw));
 
 	printk(BIOS_ERR,
-	       "Failed to claim locality 0 after %ld ms, status: %#x\n",
+	       "Failed to claim locality 0 after %lld ms, status: %#x\n",
 	       stopwatch_duration_msecs(&sw), access);
 
 	return CB_ERR;
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c
index 7ee2300..1fa5906 100644
--- a/src/ec/google/chromeec/ec.c
+++ b/src/ec/google/chromeec/ec.c
@@ -1651,7 +1651,7 @@
 		}
 		mdelay(200);
 	}
-	printk(BIOS_INFO, "DisplayPort ready after %lu ms\n",
+	printk(BIOS_INFO, "DisplayPort ready after %lld ms\n",
 	       stopwatch_duration_msecs(&sw));
 
 	return ret;
@@ -1671,7 +1671,7 @@
 		}
 		mdelay(100);
 	} while (!(mux_flags & USB_PD_MUX_HPD_LVL) || !(mux_flags & USB_PD_MUX_DP_ENABLED));
-	printk(BIOS_INFO, "HPD ready after %lu ms\n", stopwatch_duration_msecs(&sw));
+	printk(BIOS_INFO, "HPD ready after %lld ms\n", stopwatch_duration_msecs(&sw));
 
 	return 0;
 }
diff --git a/src/include/timer.h b/src/include/timer.h
index 0e7104b..0f49ec6 100644
--- a/src/include/timer.h
+++ b/src/include/timer.h
@@ -47,28 +47,28 @@
 
 /* Schedule a callback to be ran microseconds from time of invocation.
  * 0 returned on success, < 0 on error. */
-int timer_sched_callback(struct timeout_callback *tocb, unsigned long us);
+int timer_sched_callback(struct timeout_callback *tocb, uint64_t us);
 
 /* Set an absolute time to a number of microseconds. */
-static inline void mono_time_set_usecs(struct mono_time *mt, long us)
+static inline void mono_time_set_usecs(struct mono_time *mt, uint64_t us)
 {
 	mt->microseconds = us;
 }
 
 /* Set an absolute time to a number of milliseconds. */
-static inline void mono_time_set_msecs(struct mono_time *mt, long ms)
+static inline void mono_time_set_msecs(struct mono_time *mt, uint64_t ms)
 {
 	mt->microseconds = ms * USECS_PER_MSEC;
 }
 
 /* Add microseconds to an absolute time. */
-static inline void mono_time_add_usecs(struct mono_time *mt, long us)
+static inline void mono_time_add_usecs(struct mono_time *mt, int64_t us)
 {
 	mt->microseconds += us;
 }
 
 /* Add milliseconds to an absolute time. */
-static inline void mono_time_add_msecs(struct mono_time *mt, long ms)
+static inline void mono_time_add_msecs(struct mono_time *mt, int64_t ms)
 {
 	mono_time_add_usecs(mt, ms * USECS_PER_MSEC);
 }
@@ -102,8 +102,8 @@
 }
 
 /* Return time difference between t1 and t2. i.e. t2 - t1. */
-static inline long mono_time_diff_microseconds(const struct mono_time *t1,
-					       const struct mono_time *t2)
+static inline int64_t mono_time_diff_microseconds(const struct mono_time *t1,
+						  const struct mono_time *t2)
 {
 	return t2->microseconds - t1->microseconds;
 }
@@ -124,13 +124,13 @@
 	sw->current = sw->expires = sw->start;
 }
 
-static inline void stopwatch_init_usecs_expire(struct stopwatch *sw, long us)
+static inline void stopwatch_init_usecs_expire(struct stopwatch *sw, uint64_t us)
 {
 	stopwatch_init(sw);
 	mono_time_add_usecs(&sw->expires, us);
 }
 
-static inline void stopwatch_init_msecs_expire(struct stopwatch *sw, long ms)
+static inline void stopwatch_init_msecs_expire(struct stopwatch *sw, uint64_t ms)
 {
 	stopwatch_init_usecs_expire(sw, USECS_PER_MSEC * ms);
 }
@@ -167,7 +167,7 @@
 /*
  * Return number of microseconds since starting the stopwatch.
  */
-static inline long stopwatch_duration_usecs(struct stopwatch *sw)
+static inline int64_t stopwatch_duration_usecs(struct stopwatch *sw)
 {
 	/*
 	 * If the stopwatch hasn't been ticked (current == start) tick
@@ -179,7 +179,7 @@
 	return mono_time_diff_microseconds(&sw->start, &sw->current);
 }
 
-static inline long stopwatch_duration_msecs(struct stopwatch *sw)
+static inline int64_t stopwatch_duration_msecs(struct stopwatch *sw)
 {
 	return stopwatch_duration_usecs(sw) / USECS_PER_MSEC;
 }
@@ -197,7 +197,7 @@
  */
 #define wait_us(timeout_us, condition)					\
 ({									\
-	long __ret = 0;							\
+	int64_t __ret = 0;							\
 	struct stopwatch __sw;						\
 	stopwatch_init_usecs_expire(&__sw, timeout_us);			\
 	do {								\
diff --git a/src/lib/hardwaremain.c b/src/lib/hardwaremain.c
index e45ac9f..714452d 100644
--- a/src/lib/hardwaremain.c
+++ b/src/lib/hardwaremain.c
@@ -283,7 +283,7 @@
 			bscb->callback(bscb->arg);
 			if (CONFIG(DEBUG_BOOT_STATE)) {
 				timer_monotonic_get(&mt_stop);
-				printk(BIOS_DEBUG, "BS: callback (%p) @ %s (%ld ms).\n", bscb,
+				printk(BIOS_DEBUG, "BS: callback (%p) @ %s (%lld ms).\n", bscb,
 				       bscb_location(bscb),
 				       mono_time_diff_microseconds(&mt_start, &mt_stop)
 					       / USECS_PER_MSEC);
diff --git a/src/lib/thread.c b/src/lib/thread.c
index dc83df0..a0d4311 100644
--- a/src/lib/thread.c
+++ b/src/lib/thread.c
@@ -400,7 +400,7 @@
 	while (handle->state != THREAD_DONE)
 		assert(thread_yield() == 0);
 
-	printk(BIOS_SPEW, "took %lu us\n", stopwatch_duration_usecs(&sw));
+	printk(BIOS_SPEW, "took %lld us\n", stopwatch_duration_usecs(&sw));
 
 	return handle->error;
 }
@@ -415,7 +415,7 @@
 		assert(thread_yield() == 0);
 	mutex->locked = true;
 
-	printk(BIOS_SPEW, "took %lu us to acquire mutex\n", stopwatch_duration_usecs(&sw));
+	printk(BIOS_SPEW, "took %lld us to acquire mutex\n", stopwatch_duration_usecs(&sw));
 }
 
 void thread_mutex_unlock(struct thread_mutex *mutex)
diff --git a/src/mainboard/google/fizz/mainboard.c b/src/mainboard/google/fizz/mainboard.c
index 13bc9b7..15be049 100644
--- a/src/mainboard/google/fizz/mainboard.c
+++ b/src/mainboard/google/fizz/mainboard.c
@@ -245,7 +245,7 @@
 		}
 		mdelay(200);
 	}
-	printk(BIOS_INFO, "HPD ready after %lu ms\n",
+	printk(BIOS_INFO, "HPD ready after %lld ms\n",
 	       stopwatch_duration_msecs(&sw));
 }
 
diff --git a/src/mainboard/google/hatch/variants/baseboard/mainboard.c b/src/mainboard/google/hatch/variants/baseboard/mainboard.c
index c78ad5b..e0c3440 100644
--- a/src/mainboard/google/hatch/variants/baseboard/mainboard.c
+++ b/src/mainboard/google/hatch/variants/baseboard/mainboard.c
@@ -32,7 +32,7 @@
 		}
 		mdelay(200);
 	}
-	printk(BIOS_INFO, "HPD ready after %lu ms\n",
+	printk(BIOS_INFO, "HPD ready after %lld ms\n",
 	       stopwatch_duration_msecs(&sw));
 }
 
diff --git a/src/security/vboot/ec_sync.c b/src/security/vboot/ec_sync.c
index 56e6c44..5b3287e 100644
--- a/src/security/vboot/ec_sync.c
+++ b/src/security/vboot/ec_sync.c
@@ -174,7 +174,7 @@
 		return VB2_ERROR_UNKNOWN;
 	}
 
-	printk(BIOS_INFO, "EC took %luus to calculate image hash\n",
+	printk(BIOS_INFO, "EC took %lldus to calculate image hash\n",
 		stopwatch_duration_usecs(&sw));
 
 	*hash = resp.hash_digest;
@@ -460,7 +460,7 @@
 		       "EC requests limited power usage. Request shutdown.\n");
 		return VB2_REQUEST_SHUTDOWN;
 	} else {
-		printk(BIOS_INFO, "Waited %luus to clear limit power flag.\n",
+		printk(BIOS_INFO, "Waited %lldus to clear limit power flag.\n",
 			stopwatch_duration_usecs(&sw));
 	}
 
@@ -541,7 +541,7 @@
 	mdelay(50);
 	while (google_chromeec_hello()) {
 		if (stopwatch_expired(&sw)) {
-			printk(BIOS_ERR, "EC did not return from reboot after %luus\n",
+			printk(BIOS_ERR, "EC did not return from reboot after %lldus\n",
 			       stopwatch_duration_usecs(&sw));
 			return VB2_ERROR_UNKNOWN;
 		}
@@ -549,7 +549,7 @@
 		mdelay(5);
 	}
 
-	printk(BIOS_INFO, "\nEC returned from reboot after %luus\n",
+	printk(BIOS_INFO, "\nEC returned from reboot after %lldus\n",
 	       stopwatch_duration_usecs(&sw));
 
 	return VB2_SUCCESS;
diff --git a/src/soc/amd/common/block/smu/smu.c b/src/soc/amd/common/block/smu/smu.c
index d68867c..a44ff06 100644
--- a/src/soc/amd/common/block/smu/smu.c
+++ b/src/soc/amd/common/block/smu/smu.c
@@ -23,7 +23,7 @@
 		result = smn_read32(SMN_SMU_MESG_RESP);
 		if (result) {
 			if (print_command_duration)
-				printk(BIOS_SPEW, "SMU command consumed %ld usecs\n",
+				printk(BIOS_SPEW, "SMU command consumed %lld usecs\n",
 					stopwatch_duration_usecs(&sw));
 			return result;
 		}
diff --git a/src/soc/intel/apollolake/chip.c b/src/soc/intel/apollolake/chip.c
index bbf0564..da2d00a 100644
--- a/src/soc/intel/apollolake/chip.c
+++ b/src/soc/intel/apollolake/chip.c
@@ -800,7 +800,7 @@
 		}
 	}
 
-	printk(BIOS_INFO, "xHCI port 0 host switch over took %lu ms\n",
+	printk(BIOS_INFO, "xHCI port 0 host switch over took %lld ms\n",
 		stopwatch_duration_msecs(&sw));
 }
 
diff --git a/src/soc/intel/apollolake/reset.c b/src/soc/intel/apollolake/reset.c
index 186a546..25b5bde 100644
--- a/src/soc/intel/apollolake/reset.c
+++ b/src/soc/intel/apollolake/reset.c
@@ -44,5 +44,5 @@
 		}
 		mdelay(1);
 	}
-	printk(BIOS_SPEW, "CSE took %lu ms\n", stopwatch_duration_msecs(&sw));
+	printk(BIOS_SPEW, "CSE took %lld ms\n", stopwatch_duration_msecs(&sw));
 }
diff --git a/src/soc/intel/apollolake/xdci.c b/src/soc/intel/apollolake/xdci.c
index 5903e34..086bbfd 100644
--- a/src/soc/intel/apollolake/xdci.c
+++ b/src/soc/intel/apollolake/xdci.c
@@ -67,7 +67,7 @@
 		}
 	}
 
-	printk(BIOS_INFO, "XDCI port 0 host switch over took %lu ms\n",
+	printk(BIOS_INFO, "XDCI port 0 host switch over took %lld ms\n",
 		stopwatch_duration_msecs(&sw));
 }
 
diff --git a/src/soc/intel/common/block/cse/cse.c b/src/soc/intel/common/block/cse/cse.c
index a68c982..1e223c7 100644
--- a/src/soc/intel/common/block/cse/cse.c
+++ b/src/soc/intel/common/block/cse/cse.c
@@ -315,7 +315,7 @@
 			return 0;
 		}
 	}
-	printk(BIOS_DEBUG, "HECI: CSE took %lu ms to enter security override mode\n",
+	printk(BIOS_DEBUG, "HECI: CSE took %lld ms to enter security override mode\n",
 			stopwatch_duration_msecs(&sw));
 	return 1;
 }
@@ -335,7 +335,7 @@
 			return 0;
 		}
 	}
-	printk(BIOS_SPEW, "HECI: CSE took %lu ms to boot from RO\n",
+	printk(BIOS_SPEW, "HECI: CSE took %lld ms to boot from RO\n",
 			stopwatch_duration_msecs(&sw));
 	return 1;
 }
diff --git a/src/soc/intel/elkhartlake/tsn_gbe.c b/src/soc/intel/elkhartlake/tsn_gbe.c
index 50e9e16..ea2ef0e 100644
--- a/src/soc/intel/elkhartlake/tsn_gbe.c
+++ b/src/soc/intel/elkhartlake/tsn_gbe.c
@@ -39,7 +39,7 @@
 
 	} while (!stopwatch_expired(&sw));
 
-	printk(BIOS_ERR, "%s Timeout after %ld msec\n", __func__,
+	printk(BIOS_ERR, "%s Timeout after %lld msec\n", __func__,
 			stopwatch_duration_msecs(&sw));
 	return CB_ERR;
 }
diff --git a/src/soc/mediatek/common/mcu.c b/src/soc/mediatek/common/mcu.c
index d0a1107..42b3124 100644
--- a/src/soc/mediatek/common/mcu.c
+++ b/src/soc/mediatek/common/mcu.c
@@ -31,7 +31,7 @@
 	if (mcu->reset)
 		mcu->reset(mcu);
 
-	printk(BIOS_DEBUG, "%s: Loaded (and reset) %s in %ld msecs (%zd bytes)\n",
+	printk(BIOS_DEBUG, "%s: Loaded (and reset) %s in %lld msecs (%zd bytes)\n",
 	       __func__, mcu->firmware_name, stopwatch_duration_msecs(&sw), mcu->run_size);
 
 	return CB_SUCCESS;
diff --git a/src/soc/mediatek/common/memory.c b/src/soc/mediatek/common/memory.c
index f3f784e..e420722 100644
--- a/src/soc/mediatek/common/memory.c
+++ b/src/soc/mediatek/common/memory.c
@@ -265,7 +265,7 @@
 		ret = dram_run_fast_calibration(dparam);
 		if (ret != 0) {
 			printk(BIOS_ERR, "DRAM-K: Failed to run fast calibration "
-			       "in %ld msecs, error: %d\n",
+			       "in %lld msecs, error: %d\n",
 			       stopwatch_duration_msecs(&sw), ret);
 
 			/* Erase flash data after fast calibration failed */
@@ -274,7 +274,7 @@
 					     DRAMC_PARAM_HEADER_VERSION,
 					     dparam, mrc_cache_size);
 		} else {
-			printk(BIOS_INFO, "DRAM-K: Fast calibration passed in %ld msecs\n",
+			printk(BIOS_INFO, "DRAM-K: Fast calibration passed in %lld msecs\n",
 			       stopwatch_duration_msecs(&sw));
 			return;
 		}
@@ -290,13 +290,13 @@
 	stopwatch_init(&sw);
 	int err = dram_run_full_calibration(dparam);
 	if (err == 0) {
-		printk(BIOS_INFO, "DRAM-K: Full calibration passed in %ld msecs\n",
+		printk(BIOS_INFO, "DRAM-K: Full calibration passed in %lld msecs\n",
 		       stopwatch_duration_msecs(&sw));
 		mrc_cache_stash_data(MRC_TRAINING_DATA,
 				     DRAMC_PARAM_HEADER_VERSION,
 				     dparam, mrc_cache_size);
 	} else {
-		printk(BIOS_ERR, "DRAM-K: Full calibration failed in %ld msecs\n",
+		printk(BIOS_ERR, "DRAM-K: Full calibration failed in %lld msecs\n",
 		       stopwatch_duration_msecs(&sw));
 	}
 }
diff --git a/src/soc/mediatek/common/mt6359p.c b/src/soc/mediatek/common/mt6359p.c
index 580079e..de22b3e 100644
--- a/src/soc/mediatek/common/mt6359p.c
+++ b/src/soc/mediatek/common/mt6359p.c
@@ -141,7 +141,7 @@
 		mt6359p_write(PMIC_BUCK_VPA_DLC_CON1, 0x800);
 	}
 
-	printk(BIOS_DEBUG, "%s: Set efuses in %ld msecs\n",
+	printk(BIOS_DEBUG, "%s: Set efuses in %lld msecs\n",
 	       __func__, stopwatch_duration_msecs(&sw));
 }
 
diff --git a/src/soc/mediatek/common/spm.c b/src/soc/mediatek/common/spm.c
index 71cad48..e39f3da 100644
--- a/src/soc/mediatek/common/spm.c
+++ b/src/soc/mediatek/common/spm.c
@@ -209,7 +209,7 @@
 		return -1;
 	}
 
-	printk(BIOS_INFO, "SPM: %s done in %ld msecs, spm pc = %#x\n",
+	printk(BIOS_INFO, "SPM: %s done in %lld msecs, spm pc = %#x\n",
 	       __func__, stopwatch_duration_msecs(&sw),
 	       read32(&mtk_spm->md32pcm_pc));
 
diff --git a/src/soc/mediatek/mt8183/spm.c b/src/soc/mediatek/mt8183/spm.c
index e35fc57..5fba84d 100644
--- a/src/soc/mediatek/mt8183/spm.c
+++ b/src/soc/mediatek/mt8183/spm.c
@@ -264,7 +264,7 @@
 	assert(offset < file_size);
 	printk(BIOS_DEBUG, "SPM: version = %s\n", spm_bin + offset);
 
-	printk(BIOS_INFO, "SPM binary loaded in %ld msecs\n",
+	printk(BIOS_INFO, "SPM binary loaded in %lld msecs\n",
 	       stopwatch_duration_msecs(&sw));
 
 	return 0;
@@ -330,7 +330,7 @@
 	spm_init_event_vector(pcmdesc);
 	spm_kick_pcm_to_run();
 
-	printk(BIOS_INFO, "SPM: %s done in %ld msecs\n", __func__,
+	printk(BIOS_INFO, "SPM: %s done in %lld msecs\n", __func__,
 	       stopwatch_duration_msecs(&sw));
 
 	return 0;
diff --git a/src/soc/nvidia/tegra210/ccplex.c b/src/soc/nvidia/tegra210/ccplex.c
index 0bc8fe9..b26eb8e 100644
--- a/src/soc/nvidia/tegra210/ccplex.c
+++ b/src/soc/nvidia/tegra210/ccplex.c
@@ -64,7 +64,7 @@
 	while ((read32(&flow->ram_repair) & sts) != sts)
 		;
 
-	printk(BIOS_DEBUG, "RAM repair complete in %ld usecs.\n",
+	printk(BIOS_DEBUG, "RAM repair complete in %lld usecs.\n",
 		stopwatch_duration_usecs(&sw));
 }
 
diff --git a/src/soc/samsung/exynos5250/fb.c b/src/soc/samsung/exynos5250/fb.c
index 9166b02..1fc926a 100644
--- a/src/soc/samsung/exynos5250/fb.c
+++ b/src/soc/samsung/exynos5250/fb.c
@@ -174,7 +174,7 @@
 	} while (!stopwatch_expired(&sw));
 
 	if (!timeout) {
-		printk(BIOS_ERR, "Video Clock Not ok after %ldus.\n",
+		printk(BIOS_ERR, "Video Clock Not ok after %lldus.\n",
 				stopwatch_duration_usecs(&sw));
 		return -ERR_VIDEO_CLOCK_BAD;
 	}
diff --git a/src/southbridge/intel/bd82x6x/me_common.c b/src/southbridge/intel/bd82x6x/me_common.c
index 96fc6c2..a48d4128 100644
--- a/src/southbridge/intel/bd82x6x/me_common.c
+++ b/src/southbridge/intel/bd82x6x/me_common.c
@@ -478,7 +478,7 @@
 	if (!hfs.fw_init_complete)
 		printk(BIOS_ERR, "ME: giving up on waiting for fw_init_complete\n");
 	else
-		printk(BIOS_NOTICE, "ME: took %lums to complete initialization\n",
+		printk(BIOS_NOTICE, "ME: took %lldms to complete initialization\n",
 		       stopwatch_duration_msecs(&sw));
 }