[lib] Use dual_cc_library for core mockable libraries

Signed-off-by: Miguel Young de la Sota <mcyoung@google.com>
diff --git a/sw/device/lib/base/BUILD b/sw/device/lib/base/BUILD
index da24441..3e212c6 100644
--- a/sw/device/lib/base/BUILD
+++ b/sw/device/lib/base/BUILD
@@ -4,6 +4,7 @@
 
 package(default_visibility = ["//visibility:public"])
 
+load("//rules:cross_platform.bzl", "dual_cc_library", "dual_inputs")
 load("//rules:opentitan.bzl", "OPENTITAN_CPU")
 
 cc_library(
@@ -96,13 +97,42 @@
     ],
 )
 
-cc_library(
+# TODO: Until Meson is removed, these files need to stay in a different
+# directory, but eventually they will be hoisted to live alongside the
+# targets they mock.
+dual_cc_library(
     name = "csr",
-    hdrs = [
-        "csr.h",
-        "csr_registers.h",
+    srcs = dual_inputs(
+        host = ["//sw/device/silicon_creator/lib/base:mock_csr.cc"],
+    ),
+    hdrs = dual_inputs(
+        host = [
+            "//sw/device/silicon_creator/lib/base:mock_csr.h",
+        ],
+        shared = [
+            "csr.h",
+            "csr_registers.h",
+        ],
+    ),
+    deps = dual_inputs(
+        host = [
+            "//sw/device/lib/base/testing:global_mock",
+            "@googletest//:gtest",
+        ],
+        shared = [
+            ":macros",
+            ":stdasm",
+        ],
+    ),
+)
+
+cc_test(
+    name = "mock_csr_unittest",
+    srcs = ["//sw/device/silicon_creator/lib/base:mock_csr_test.cc"],
+    deps = [
+        ":csr",
+        "@googletest//:gtest_main",
     ],
-    deps = [":stdasm"],
 )
 
 cc_library(
@@ -113,23 +143,67 @@
     ],
 )
 
-cc_library(
+# TODO: Until Meson is removed, these files need to stay in a different
+# directory, but eventually they will be hoisted to live alongside the
+# targets they mock.
+dual_cc_library(
     name = "mmio",
-    srcs = ["mmio.c"],
-    hdrs = ["mmio.h"],
+    srcs = dual_inputs(
+        host = ["//sw/device/lib/base/testing:mock_mmio.cc"],
+        # NOTE: mmio.c is shared because it provides mmio_memcpy and friends.
+        shared = ["mmio.c"],
+    ),
+    hdrs = dual_inputs(
+        host = [
+            "//sw/device/lib/base/testing:mock_mmio.h",
+            "//sw/device/lib/base/testing:mock_mmio_test_utils.h",
+        ],
+        shared = ["mmio.h"],
+    ),
+    deps = dual_inputs(
+        host = [
+            "@googletest//:gtest",
+        ],
+        shared = [
+            ":bitfield",
+            ":macros",
+            ":memory",
+        ],
+    ),
+)
+
+cc_test(
+    name = "mmio_unittest",
+    srcs = ["//sw/device/lib/base/testing:mock_mmio_test.cc"],
     deps = [
-        ":bitfield",
-        ":macros",
-        ":memory",
+        ":mmio",
+        "@googletest//:gtest_main",
     ],
 )
 
-cc_library(
+# TODO: Until Meson is removed, these files need to stay in a different
+# directory, but eventually they will be hoisted to live alongside the
+# targets they mock.
+dual_cc_library(
     name = "abs_mmio",
-    srcs = ["abs_mmio.c"],
-    hdrs = ["abs_mmio.h"],
-    deps = [
-        ":macros",
-        ":mmio",
-    ],
+    srcs = dual_inputs(
+        device = ["abs_mmio.c"],
+        host = ["//sw/device/lib/base/testing:mock_abs_mmio.cc"],
+    ),
+    hdrs = dual_inputs(
+        host = [
+            "//sw/device/lib/base/testing:mock_abs_mmio.h",
+        ],
+        shared = ["abs_mmio.h"],
+    ),
+    deps = dual_inputs(
+        host = [
+            "//sw/device/lib/base/testing:global_mock",
+            "@googletest//:gtest",
+        ],
+        shared = [
+            ":mmio",
+            ":macros",
+        ],
+    ),
 )
diff --git a/sw/device/lib/base/abs_mmio.h b/sw/device/lib/base/abs_mmio.h
index 97c7c55..bf3e442 100644
--- a/sw/device/lib/base/abs_mmio.h
+++ b/sw/device/lib/base/abs_mmio.h
@@ -27,7 +27,7 @@
  * MMIO accesses.
  */
 
-#ifndef MOCK_ABS_MMIO
+#ifdef OT_PLATFORM_RV32
 
 /**
  * Reads uint8_t from MMIO `addr`.
@@ -95,7 +95,7 @@
   *((volatile uint32_t *)addr) = value;
 }
 
-#else  // MOCK_ABS_MMIO
+#else  // OT_PLATFORM_RV32
 
 extern uint8_t abs_mmio_read8(uint32_t addr);
 extern void abs_mmio_write8(uint32_t addr, uint8_t value);
@@ -104,7 +104,7 @@
 extern void abs_mmio_write32(uint32_t addr, uint32_t value);
 extern void abs_mmio_write32_shadowed(uint32_t addr, uint32_t value);
 
-#endif  // MOCK_ABS_MMIO
+#endif  // OT_PLATFORM_RV32
 
 #ifdef __cplusplus
 }
diff --git a/sw/device/lib/base/csr.h b/sw/device/lib/base/csr.h
index 454f8d6..e5154c1 100644
--- a/sw/device/lib/base/csr.h
+++ b/sw/device/lib/base/csr.h
@@ -10,6 +10,7 @@
 #include <stdint.h>
 
 #include "sw/device/lib/base/csr_registers.h"
+#include "sw/device/lib/base/macros.h"
 #include "sw/device/lib/base/stdasm.h"
 
 #ifdef __cplusplus
@@ -32,7 +33,7 @@
  * The implementation used depends on whether the CSR library is providing a
  * real or a mocked interface.
  */
-#ifdef MOCK_CSR
+#ifndef OT_PLATFORM_RV32
 
 /**
  * Macro to check that an argument is a constant expression at compile time.
@@ -87,7 +88,7 @@
     mock_csr_clear_bits(csr, mask);                 \
   } while (false)
 
-#else  // MOCK_CSR
+#else  // OT_PLATFORM_RV32
 
 #define CSR_READ_IMPL(csr, dest)                           \
   do {                                                     \
@@ -117,7 +118,7 @@
     asm volatile("csrc %0, %1;" ::"i"(csr), "r"(mask)); \
   } while (false)
 
-#endif  // MOCK_CSR
+#endif  // OT_PLATFORM_RV32
 
 /**
  * Read the value of a CSR and place the result into the location pointed to by
diff --git a/sw/device/lib/base/mmio.h b/sw/device/lib/base/mmio.h
index b4d8fcd..cec2dce 100644
--- a/sw/device/lib/base/mmio.h
+++ b/sw/device/lib/base/mmio.h
@@ -42,7 +42,7 @@
  */
 #define MMIO_DEPRECATED
 
-#ifndef MOCK_MMIO
+#ifdef OT_PLATFORM_RV32
 /**
  * An mmio_region_t is an opaque handle to an MMIO region; it should only be
  * modified using the functions provided in this header.
@@ -161,7 +161,7 @@
   ((volatile uint32_t *)base.base)[offset / sizeof(uint32_t)] = value;
   ((volatile uint32_t *)base.base)[offset / sizeof(uint32_t)] = value;
 }
-#else   // MOCK_MMIO
+#else   // OT_PLATFORM_RV32
 /**
  * "Instrumented" mmio_region_t.
  *
@@ -190,7 +190,7 @@
                                  uint8_t value);
 void mmio_region_write32_shadowed(mmio_region_t base, ptrdiff_t offset,
                                   uint32_t value);
-#endif  // MOCK_MMIO
+#endif  // OT_PLATFORM_RV32
 
 /**
  * Reads the bits in `mask` from the MMIO region `base` at the given offset.
diff --git a/sw/device/lib/base/testing/BUILD b/sw/device/lib/base/testing/BUILD
index dc3102b..2dd2600 100644
--- a/sw/device/lib/base/testing/BUILD
+++ b/sw/device/lib/base/testing/BUILD
@@ -4,53 +4,9 @@
 
 package(default_visibility = ["//visibility:public"])
 
+exports_files(glob(["*"]))
+
 cc_library(
     name = "global_mock",
     hdrs = ["global_mock.h"],
 )
-
-cc_library(
-    name = "mock_mmio",
-    srcs = ["mock_mmio.cc"],
-    hdrs = [
-        "mock_mmio.h",
-        "mock_mmio_test_utils.h",
-    ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
-    deps = [
-        "//sw/device/lib/base:mmio",
-        "@googletest//:gtest",
-    ],
-)
-
-cc_library(
-    name = "mock_abs_mmio",
-    testonly = True,
-    hdrs = [
-        "mock_abs_mmio.h",
-        "mock_mmio_test_utils.h",
-    ],
-    defines = ["MOCK_ABS_MMIO"],
-    deps = [
-        ":global_mock",
-        ":mock_mmio",
-        "//sw/device/lib/base:abs_mmio",
-        "@googletest//:gtest",
-    ],
-)
-
-cc_test(
-    name = "mock_mmio_test",
-    srcs = [
-        "mock_mmio_test.cc",
-    ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
-    deps = [
-        ":mock_mmio",
-        "@googletest//:gtest_main",
-    ],
-)
diff --git a/sw/device/lib/base/testing/mock_abs_mmio.cc b/sw/device/lib/base/testing/mock_abs_mmio.cc
new file mode 100644
index 0000000..53b53c4
--- /dev/null
+++ b/sw/device/lib/base/testing/mock_abs_mmio.cc
@@ -0,0 +1,33 @@
+// Copyright lowRISC contributors.
+// Licensed under the Apache License, Version 2.0, see LICENSE for details.
+// SPDX-License-Identifier: Apache-2.0
+
+#include "sw/device/lib/base/testing/mock_abs_mmio.h"
+
+namespace mask_rom_test {
+extern "C" {
+uint8_t abs_mmio_read8(uint32_t addr) {
+  return MockAbsMmio::Instance().Read8(addr);
+}
+
+void abs_mmio_write8(uint32_t addr, uint8_t value) {
+  MockAbsMmio::Instance().Write8(addr, value);
+}
+
+void abs_mmio_write8_shadowed(uint32_t addr, uint8_t value) {
+  MockAbsMmio::Instance().Write8Shadowed(addr, value);
+}
+
+uint32_t abs_mmio_read32(uint32_t addr) {
+  return MockAbsMmio::Instance().Read32(addr);
+}
+
+void abs_mmio_write32(uint32_t addr, uint32_t value) {
+  MockAbsMmio::Instance().Write32(addr, value);
+}
+
+void abs_mmio_write32_shadowed(uint32_t addr, uint32_t value) {
+  MockAbsMmio::Instance().Write32Shadowed(addr, value);
+}
+}  // extern "C"
+}  // namespace mask_rom_test
diff --git a/sw/device/lib/base/testing/mock_abs_mmio.h b/sw/device/lib/base/testing/mock_abs_mmio.h
index 2caaf43..f4a5f1d 100644
--- a/sw/device/lib/base/testing/mock_abs_mmio.h
+++ b/sw/device/lib/base/testing/mock_abs_mmio.h
@@ -97,6 +97,7 @@
   EXPECT_CALL(::mask_rom_test::MockAbsMmio::Instance(), \
               Write32Shadowed(addr, mock_mmio::ToInt<uint32_t>(__VA_ARGS__)));
 
+#ifdef IS_MESON_FOR_MIGRATIONS_ONLY
 extern "C" {
 
 uint8_t abs_mmio_read8(uint32_t addr) {
@@ -124,6 +125,7 @@
 }
 
 }  // extern "C"
+#endif
 }  // namespace mask_rom_test
 
 #endif  // OPENTITAN_SW_DEVICE_LIB_BASE_TESTING_MOCK_ABS_MMIO_H_
diff --git a/sw/device/lib/dif/BUILD b/sw/device/lib/dif/BUILD
index 383cea0..492880a 100644
--- a/sw/device/lib/dif/BUILD
+++ b/sw/device/lib/dif/BUILD
@@ -55,9 +55,6 @@
         "dif_adc_ctrl.h",
         "dif_adc_ctrl_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -67,7 +64,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -101,9 +97,6 @@
         "dif_clkmgr.h",
         "dif_clkmgr_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -113,7 +106,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -149,9 +141,6 @@
         "dif_csrng.h",
         "dif_csrng_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -161,7 +150,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -196,9 +184,6 @@
         "dif_edn.c",
         "dif_edn.h",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -208,7 +193,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -243,9 +227,6 @@
         "dif_uart.h",
         "dif_uart_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -256,7 +237,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -292,9 +272,6 @@
         "dif_rv_plic.h",
         "dif_rv_plic_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -304,7 +281,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -340,9 +316,6 @@
         "dif_gpio.h",
         "dif_gpio_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -352,7 +325,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -388,9 +360,6 @@
         "dif_spi_device.h",
         "dif_spi_device_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -400,7 +369,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -436,9 +404,6 @@
         "dif_spi_host.h",
         "dif_spi_host_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -449,7 +414,6 @@
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
         "//sw/device/lib/base/testing:global_mock",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -486,9 +450,6 @@
         "dif_rv_timer.h",
         "dif_rv_timer_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -499,7 +460,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -535,9 +495,6 @@
         "dif_i2c.h",
         "dif_i2c_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -547,7 +504,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -582,9 +538,6 @@
         "dif_usbdev.c",
         "dif_usbdev.h",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -594,7 +547,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -629,9 +581,6 @@
         "dif_hmac.c",
         "dif_hmac.h",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -641,7 +590,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -677,9 +625,6 @@
         "dif_kmac.h",
         "dif_kmac_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -689,7 +634,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -725,9 +669,6 @@
         "dif_otbn.h",
         "dif_otbn_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -737,7 +678,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -773,9 +713,6 @@
         "dif_rstmgr.h",
         "dif_rstmgr_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -785,7 +722,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -821,9 +757,6 @@
         "dif_alert_handler.h",
         "dif_alert_handler_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -833,7 +766,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -869,9 +801,6 @@
         "dif_pwrmgr.h",
         "dif_pwrmgr_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -881,7 +810,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -917,9 +845,6 @@
         "dif_keymgr.h",
         "dif_keymgr_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -929,7 +854,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -965,9 +889,6 @@
         "dif_otp_ctrl.h",
         "dif_otp_ctrl_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -977,7 +898,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -1013,9 +933,6 @@
         "dif_pattgen.h",
         "dif_pattgen_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -1025,7 +942,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -1061,9 +977,6 @@
         "dif_lc_ctrl.h",
         "dif_lc_ctrl_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -1073,7 +986,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -1109,9 +1021,6 @@
         "dif_aon_timer.h",
         "dif_aon_timer_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -1121,7 +1030,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -1157,9 +1065,6 @@
         "dif_entropy_src.h",
         "dif_entropy_src_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -1169,7 +1074,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -1203,9 +1107,6 @@
         "dif_flash_ctrl.h",
         "dif_flash_ctrl_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -1215,7 +1116,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -1251,9 +1151,6 @@
         "dif_aes.h",
         "dif_aes_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -1263,7 +1160,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -1298,9 +1194,6 @@
         "dif_pinmux.c",
         "dif_pinmux.h",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -1310,7 +1203,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -1345,9 +1237,6 @@
         "dif_pwm.c",
         "dif_pwm.h",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -1357,7 +1246,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -1393,9 +1281,6 @@
         "dif_sram_ctrl.h",
         "dif_sram_ctrl_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -1405,7 +1290,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
@@ -1437,9 +1321,6 @@
         "autogen/dif_sysrst_ctrl_autogen.h",
         "autogen/dif_sysrst_ctrl_autogen_unittest.cc",
     ],
-    defines = [
-        "MOCK_MMIO=1",
-    ],
     deps = [
         ":base",
         ":test_base",
@@ -1449,7 +1330,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_mmio",
         "@googletest//:gtest_main",
     ],
 )
diff --git a/sw/device/lib/runtime/BUILD b/sw/device/lib/runtime/BUILD
index 192f391..9dab284 100644
--- a/sw/device/lib/runtime/BUILD
+++ b/sw/device/lib/runtime/BUILD
@@ -91,8 +91,6 @@
     srcs = ["print_unittest.cc"],
     deps = [
         ":print",
-        "//sw/device/lib/base/testing:mock_mmio",
-        "@googletest//:gtest",
         "@googletest//:gtest_main",
     ],
 )
diff --git a/sw/device/silicon_creator/lib/BUILD b/sw/device/silicon_creator/lib/BUILD
index 365525c..a8c94fd 100644
--- a/sw/device/silicon_creator/lib/BUILD
+++ b/sw/device/silicon_creator/lib/BUILD
@@ -107,7 +107,7 @@
         ":epmp_intf",
         ":error",
         "//sw/device/lib/base:bitfield",
-        "//sw/device/silicon_creator/lib/base:mock_csr",
+        "//sw/device/lib/base:csr",
         "//sw/device/silicon_creator/testing:mask_rom_test",
         "@googletest//:gtest_main",
     ],
@@ -246,7 +246,6 @@
     srcs = [
         "manifest_unittest.cc",
     ],
-    defines = ["MOCK_CSR"],
     deps = [
         ":epmp_intf",
         ":error",
@@ -254,7 +253,7 @@
         ":manifest_intf",
         ":sigverify_internal",
         "//hw/top_earlgrey/sw/autogen:top_earlgrey",
-        "//sw/device/silicon_creator/lib/base:mock_csr",
+        "//sw/device/lib/base:csr",
         "//sw/device/silicon_creator/lib/drivers:lifecycle",
         "//sw/device/silicon_creator/testing:mask_rom_test",
         "@googletest//:gtest_main",
@@ -347,6 +346,7 @@
         "//hw/top_earlgrey/ip/rstmgr/data/autogen:rstmgr_regs",
         "//hw/top_earlgrey/sw/autogen:top_earlgrey",
         "//sw/device/lib/arch:device",
+        "//sw/device/lib/base:abs_mmio",
         "//sw/device/lib/base:bitfield",
         "//sw/device/lib/base:csr",
         "//sw/device/lib/base:hardened",
@@ -354,7 +354,6 @@
         "//sw/device/lib/base:memory",
         "//sw/device/lib/base:multibits",
         "//sw/device/lib/base:stdasm",
-        "//sw/device/lib/base/testing:mock_abs_mmio",
         "//sw/device/silicon_creator/lib/drivers:mock_alert",
         "//sw/device/silicon_creator/lib/drivers:mock_lifecycle",
         "//sw/device/silicon_creator/lib/drivers:mock_otp",
diff --git a/sw/device/silicon_creator/lib/base/BUILD b/sw/device/silicon_creator/lib/base/BUILD
index 6b88ac3..6c1c765 100644
--- a/sw/device/silicon_creator/lib/base/BUILD
+++ b/sw/device/silicon_creator/lib/base/BUILD
@@ -4,30 +4,12 @@
 load("//rules:opentitan.bzl", "OPENTITAN_CPU")
 
 package(default_visibility = ["//visibility:public"])
-
-exports_files(["static_critical.ld"])
-
-cc_library(
-    name = "mock_csr",
-    testonly = True,
-    srcs = ["mock_csr.cc"],
-    hdrs = ["mock_csr.h"],
-    defines = ["MOCK_CSR"],
-    deps = [
-        "//sw/device/lib/base:csr",
-        "//sw/device/lib/base/testing:global_mock",
-        "@googletest//:gtest",
-    ],
-)
-
-cc_test(
-    name = "mock_csr_test",
-    srcs = ["mock_csr_test.cc"],
-    deps = [
-        ":mock_csr",
-        "@googletest//:gtest_main",
-    ],
-)
+exports_files([
+    "static_critical.ld",
+    "mock_csr.h",
+    "mock_csr.cc",
+    "mock_csr_test.cc",
+])
 
 cc_library(
     name = "sec_mmio",
@@ -49,8 +31,8 @@
         "sec_mmio.h",
     ],
     deps = [
+        "//sw/device/lib/base:mmio",
         "//sw/device/lib/base/testing:global_mock",
-        "//sw/device/lib/base/testing:mock_mmio",
         "//sw/device/silicon_creator/testing:mask_rom_test",
         "@googletest//:gtest",
     ],
@@ -67,7 +49,7 @@
     deps = [
         "//sw/device/lib/base:hardened",
         "//sw/device/lib/base:macros",
-        "//sw/device/lib/base/testing:mock_abs_mmio",
+        "//sw/device/lib/base:abs_mmio",
         "//sw/device/silicon_creator/lib:error",
         "//sw/device/silicon_creator/testing:mask_rom_test",
         "@googletest//:gtest_main",
diff --git a/sw/device/silicon_creator/lib/drivers/BUILD b/sw/device/silicon_creator/lib/drivers/BUILD
index 9b9d16d..9e3061b 100644
--- a/sw/device/silicon_creator/lib/drivers/BUILD
+++ b/sw/device/silicon_creator/lib/drivers/BUILD
@@ -107,9 +107,8 @@
         "//sw/device/lib/base:bitfield",
         "//sw/device/lib/base:hardened",
         "//sw/device/lib/base:memory",
+        "//sw/device/lib/base:mmio",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_abs_mmio",
-        "//sw/device/lib/base/testing:mock_mmio",
         "//sw/device/silicon_creator/lib:error",
         "//sw/device/silicon_creator/lib/base:mock_sec_mmio",
         "//sw/device/silicon_creator/lib/drivers:mock_otp",
@@ -150,8 +149,8 @@
     deps = [
         ":hmac",
         "//hw/top_earlgrey/sw/autogen:top_earlgrey",
+        "//sw/device/lib/base:abs_mmio",
         "//sw/device/lib/base:mmio",
-        "//sw/device/lib/base/testing:mock_abs_mmio",
         "//sw/device/silicon_creator/lib:error",
         "//sw/device/silicon_creator/testing:mask_rom_test",
         "@googletest//:gtest_main",
@@ -195,7 +194,7 @@
     deps = [
         "//hw/ip/keymgr/data:keymgr_regs",
         "//hw/top_earlgrey/sw/autogen:top_earlgrey",
-        "//sw/device/lib/base/testing:mock_abs_mmio",
+        "//sw/device/lib/base:abs_mmio",
         "//sw/device/silicon_creator/lib:error",
         "//sw/device/silicon_creator/lib:keymgr_binding",
         "//sw/device/silicon_creator/lib/base:mock_sec_mmio",
@@ -305,8 +304,8 @@
     deps = [
         "//hw/ip/otbn/data:otbn_regs",
         "//hw/top_earlgrey/sw/autogen:top_earlgrey",
+        "//sw/device/lib/base:abs_mmio",
         "//sw/device/lib/base:bitfield",
-        "//sw/device/lib/base/testing:mock_abs_mmio",
         "//sw/device/silicon_creator/lib:error",
         "//sw/device/silicon_creator/testing:mask_rom_test",
         "@googletest//:gtest_main",
@@ -379,8 +378,8 @@
     deps = [
         ":pinmux",
         "//hw/top_earlgrey/sw/autogen:top_earlgrey",
+        "//sw/device/lib/base:abs_mmio",
         "//sw/device/lib/base:macros",
-        "//sw/device/lib/base/testing:mock_abs_mmio",
         "//sw/device/silicon_creator/testing:mask_rom_test",
         "@googletest//:gtest_main",
     ],
@@ -405,7 +404,7 @@
     deps = [
         ":retention_sram",
         "//hw/top_earlgrey/sw/autogen:top_earlgrey",
-        "//sw/device/lib/base/testing:mock_abs_mmio",
+        "//sw/device/lib/base:abs_mmio",
         "//sw/device/silicon_creator/testing:mask_rom_test",
         "@googletest//:gtest_main",
     ],
@@ -495,10 +494,10 @@
     deps = [
         "//hw/top_earlgrey/ip/rstmgr/data/autogen:rstmgr_regs",
         "//hw/top_earlgrey/sw/autogen:top_earlgrey",
+        "//sw/device/lib/base:abs_mmio",
         "//sw/device/lib/base:bitfield",
         "//sw/device/lib/base:macros",
         "//sw/device/lib/base:multibits",
-        "//sw/device/lib/base/testing:mock_abs_mmio",
         "//sw/device/silicon_creator/lib:error",
         "//sw/device/silicon_creator/testing:mask_rom_test",
         "@googletest//:gtest_main",
@@ -525,8 +524,8 @@
     deps = [
         ":uart",
         "//hw/top_earlgrey/sw/autogen:top_earlgrey",
+        "//sw/device/lib/base:abs_mmio",
         "//sw/device/lib/base:mmio",
-        "//sw/device/lib/base/testing:mock_abs_mmio",
         "//sw/device/silicon_creator/testing:mask_rom_test",
         "@googletest//:gtest_main",
     ],
@@ -570,7 +569,7 @@
         "//hw/ip/aon_timer/data:aon_timer_regs",
         "//hw/ip/otp_ctrl/data:otp_ctrl_regs",
         "//hw/top_earlgrey/sw/autogen:top_earlgrey",
-        "//sw/device/lib/base/testing:mock_abs_mmio",
+        "//sw/device/lib/base:abs_mmio",
         "//sw/device/silicon_creator/lib/base:mock_sec_mmio",
         "//sw/device/silicon_creator/lib/drivers:mock_otp",
         "//sw/device/silicon_creator/testing:mask_rom_test",
@@ -619,7 +618,7 @@
         ":spi_device",
         "//hw/ip/spi_device/data:spi_device_regs",
         "//hw/top_earlgrey/sw/autogen:top_earlgrey",
-        "//sw/device/lib/base/testing:mock_abs_mmio",
+        "//sw/device/lib/base:abs_mmio",
         "//sw/device/silicon_creator/lib:error",
         "//sw/device/silicon_creator/testing:mask_rom_test",
         "@googletest//:gtest_main",