Add backend_adjust_offset to avoid the windows overlap

In mihawk, the windows overlap will cause the cache coherence.
Hostboot writes the SPD data to BMC through a window and read it
back with another window. It causes the data missed and DIMM lost.

Hostboot log
   23.80714|<<DBG-956|SPD::getMemType() - MemType: 0xff, Error: NoHUID: 0x30008.

BMC log: The overlaped windows
  Window @ 0x756e0000 for size 0x00046000 maps flash offset 0x000e7000
  Window @ 0x757e0000 for size 0x00048000 maps flash offset 0x000e5000

Tested: 1. In mihawk, it can fix the SPD cache coherence issue
        2. Add unit test to verify VPNOR offset alignment

Change-Id: I92670ade4e2a91b5c49a0acabfc0456f90d49b93
Signed-off-by: Alvin Wang <alvinwang@msn.com>
[AJ: Remove some MSG_INFO() spam, fix whitespace issues]
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/backend.h b/backend.h
index f7b56b4..fadc94b 100644
--- a/backend.h
+++ b/backend.h
@@ -123,6 +123,17 @@
 	 * Return:      0 on success otherwise negative error code
 	 */
 	int	(*reset)(struct backend *backend, void *buf, uint32_t count);
+
+	/*
+	 * align_offset() - Align the offset to avoid overlap
+	 * @context:	The backend context pointer
+	 * @offset:	The flash offset
+	 * @window_size:The window size
+	 *
+	 * Return:      0 on success otherwise negative error code
+	 */
+	int	(*align_offset)(struct backend *backend, uint32_t *offset,
+				uint32_t window_size);
 };
 
 /* Make this better */
@@ -222,6 +233,26 @@
 	return backend->ops->reset(backend, buf, count);
 }
 
+
+static inline int backend_align_offset(struct backend *backend, uint32_t *offset, uint32_t window_size)
+{
+	assert(backend);
+	if (backend->ops->align_offset){
+		return  backend->ops->align_offset(backend, offset, window_size);
+	}else{
+		/*
+		 * It would be nice to align the offsets which we map to window
+		 * size, this will help prevent overlap which would be an
+		 * inefficient use of our reserved memory area (we would like
+		 * to "cache" as much of the acutal flash as possible in
+		 * memory). If we're protocol V1 however we must ensure the
+		 * offset requested is exactly mapped.
+		 */
+		*offset &= ~(window_size - 1);
+		return 0;
+	}
+}
+
 struct backend backend_get_mtd(void);
 int backend_probe_mtd(struct backend *master, const char *path);