lpc_aspeed: implement mapRegion as part of copyFrom
For the lpc aspeed ctrl driver, it'll use mmap to map the memory region
instead of using an ioctl.
Change-Id: I884fb5713b4c853cc84c8e994969b385392bdc95
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/lpc_aspeed.cpp b/lpc_aspeed.cpp
index 50ce2a9..7531382 100644
--- a/lpc_aspeed.cpp
+++ b/lpc_aspeed.cpp
@@ -102,8 +102,44 @@
return std::make_pair(offset, length);
}
+bool LpcMapperAspeed::mapRegion()
+{
+ /* Open the file to map. */
+ mappedFd = sys->open(lpcControlPath.c_str(), O_RDONLY | O_SYNC);
+
+ mappedRegion = reinterpret_cast<uint8_t*>(
+ sys->mmap(0, regionSize, PROT_READ, MAP_SHARED, mappedFd, 0));
+
+ if (mappedRegion == MAP_FAILED)
+ {
+ sys->close(mappedFd);
+ mappedFd = -1;
+ std::fprintf(stderr, "Mmap failure: '%s'\n", std::strerror(errno));
+ return false;
+ }
+
+ /* TOOD: There is no close() method here, to close mappedFd, or mappedRegion
+ * -- therefore, a good next step will be to evaluate whether or not the
+ * other pieces should go here...
+ */
+ return true;
+}
+
std::vector<std::uint8_t> LpcMapperAspeed::copyFrom(std::uint32_t length)
{
+ if (mappedFd < 0)
+ {
+ /* NOTE: may make more sense to do this in the open() */
+ if (!mapRegion())
+ {
+ /* Was unable to map region -- this call only required if using mmap
+ * and not ioctl.
+ */
+ /* TODO: have a better failure. */
+ return {};
+ }
+ }
+
/* TODO: Implement this. */
return {};
}