Hi,
On Mon, May 22, 2017 at 08:48:32PM +0800, Shaokun Zhang wrote:
+/*
+ * hisi_djtag_lock_v2: djtag lock to avoid djtag access conflict b/w kernel
+ * and UEFI.
The mention of UEFI here worries me somewhat, and I have a number of
questions specifically relating to how we interact with UEFI here.
When precisely does UEFI need to touch the djtag hardware? e.g. does
this happen in runtime services? ... or completely asynchronously?
What does UEFI do with djtag when it holds the lock?
Are there other software agents (e.g. secure firmware) which try to
take this lock?
Can you explain how the locking scheme works? e.g. is this an advisory
software-only policy, or does the hardware prohibit accesses from other
agents somehow?
What happens if the kernel takes the lock, but doesn't release it?
What happens if UEFI takes the lock, but doesn't release it?
Are there any points at which UEFI needs to hold the locks of several
djtag units simultaneously?
+ * @reg_base: djtag register base address
+ *
+ * Return - none.
+ */
+static void hisi_djtag_lock_v2(void __iomem *regs_base)
+{
+ u32 rd, wr, mod_sel;
+
+ /* Continuously poll to ensure the djtag is free */
+ while (1) {
+ rd = readl(regs_base + SC_DJTAG_MSTR_CFG_EX);
+ mod_sel = ((rd >> DEBUG_MODULE_SEL_SHIFT_EX) & 0xFF);
+ if (mod_sel == SC_DJTAG_V2_UNLOCK) {
+ wr = ((rd & SC_DJTAG_V2_MODULE_SEL_MASK) |
+ (SC_DJTAG_V2_KERNEL_LOCK <<
+ DEBUG_MODULE_SEL_SHIFT_EX));
+ writel(wr, regs_base + SC_DJTAG_MSTR_CFG_EX);
+ udelay(10); /* 10us */
+
+ rd = readl(regs_base + SC_DJTAG_MSTR_CFG_EX);
+ mod_sel = ((rd >> DEBUG_MODULE_SEL_SHIFT_EX) & 0xFF);
+ if (mod_sel == SC_DJTAG_V2_KERNEL_LOCK)
+ break;
+ }
+ udelay(10); /* 10us */
+ }
+}
+
+/*