Add support for building flashrom against libpayload

This doesn't include changes to the frontend which must be
done separately, so this won't work out of the box.
This code was tested on hardware.

Corresponding to flashrom svn r1184.

Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
diff --git a/physmap.c b/physmap.c
index 7ac8ae0..011c8d1 100644
--- a/physmap.c
+++ b/physmap.c
@@ -28,7 +28,7 @@
 #include "flash.h"
 
 /* Do we need any file access or ioctl for physmap or MSR? */
-#if !defined(__DJGPP__)
+#if !defined(__DJGPP__) && !defined(__LIBPAYLOAD__)
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -104,6 +104,31 @@
 	__dpmi_free_physical_address_mapping(&mi);
 }
 
+#elif defined(__LIBPAYLOAD__)
+#include <arch/virtual.h>
+
+#define MEM_DEV ""
+
+void *sys_physmap(unsigned long phys_addr, size_t len)
+{
+	return (void*)phys_to_virt(phys_addr);
+}
+
+#define sys_physmap_rw_uncached	sys_physmap
+#define sys_physmap_ro_cached	sys_physmap
+
+void physunmap(void *virt_addr, size_t len)
+{
+}
+
+int setup_cpu_msr(int cpu)
+{
+	return 0;
+}
+
+void cleanup_cpu_msr(void)
+{
+}
 #elif defined(__DARWIN__)
 
 #include <DirectIO/darwinio.h>
@@ -453,6 +478,20 @@
 {
 	// Nothing, yet.
 }
+#elif defined(__LIBPAYLOAD__)
+msr_t libpayload_rdmsr(int addr)
+{
+	msr_t msr;
+	unsigned long long val = _rdmsr(addr);
+	msr.lo = val & 0xffffffff;
+	msr.hi = val >> 32;
+	return msr;
+}
+
+int libpayload_wrmsr(int addr, msr_t msr)
+{
+	_wrmsr(addr, msr.lo | ((unsigned long long)msr.hi << 32));
+}
 #else
 msr_t rdmsr(int addr)
 {