mboxd: Add a backend abstraction layer to mboxd.

Introduce a backend abstraction, enabling multiple implementations to be
compiled in at once. This change formally abstracts the two existing
backends, mtd and vpnor.

With the backend abstraction in place, subsequent backends are easier to
implement.

This change is based of Evan's work and he retains authorship credit. I
(AJ) have reworked the patch to pass the vpnor tests, refactored some
parts to enable broader use of const structures and others to clarify
the initialisation sequences.

Due to the existing lack of abstraction the patch has unfortunately
wide-ranging impacts. I've whittled it down as much as I consider
reasonable.

Change-Id: I29984a36dae4ea86ec00b853d2a756f0b9afb3ec
Signed-off-by: Evan Lojewski <github@meklort.com>
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/vpnor/pnor_partition.hpp b/vpnor/pnor_partition.hpp
index 95d4309..c91f22e 100644
--- a/vpnor/pnor_partition.hpp
+++ b/vpnor/pnor_partition.hpp
@@ -3,7 +3,8 @@
 #pragma once
 
 extern "C" {
-#include "mboxd.h"
+#include "backend.h"
+#include "mboxd_pnor_partition_table.h"
 };
 
 #include "pnor_partition_table.hpp"
@@ -14,8 +15,6 @@
 #include <experimental/filesystem>
 #include <string>
 
-#include "mboxd_pnor_partition_table.h"
-
 namespace openpower
 {
 namespace virtual_pnor
@@ -28,7 +27,7 @@
   public:
     /** @brief Construct a flash access request
      *
-     *  @param[in] ctx - The mbox context used to process the request
+     *  @param[in] backend - The backend context used to process the request
      *  @param[in] offset - The absolute offset into the flash device as
      *                      provided by the mbox message associated with the
      *                      request
@@ -37,9 +36,10 @@
      *  the ctx pointer must strictly exceed the lifetime of the class
      *  instance.
      */
-    Request(struct mbox_context* ctx, size_t offset) :
-        ctx(ctx), partition(ctx->vpnor->table->partition(offset)),
-        base(partition.data.base << ctx->block_size_shift),
+    Request(struct backend* backend, size_t offset) :
+        backend(backend), partition(((struct vpnor_data*)backend->priv)
+                                        ->vpnor->table->partition(offset)),
+        base(partition.data.base << backend->block_size_shift),
         offset(offset - base)
     {
     }
@@ -64,7 +64,8 @@
             std::stringstream err;
             err << "Request size 0x" << std::hex << len << " from offset 0x"
                 << std::hex << offset << " exceeds the partition size 0x"
-                << std::hex << (partition.data.size << ctx->block_size_shift);
+                << std::hex
+                << (partition.data.size << backend->block_size_shift);
             throw OutOfBoundsOffset(err.str());
         }
         constexpr auto flags = O_RDWR;
@@ -132,7 +133,7 @@
     size_t fulfil(const std::experimental::filesystem::path& path, int flags,
                   void* dst, size_t len);
 
-    struct mbox_context* ctx;
+    struct backend* backend;
     const pnor_partition& partition;
     size_t base;
     size_t offset;