Patrick Venture | 22e3875 | 2018-11-21 08:52:49 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 17 | #include "lpc_handler.hpp" |
| 18 | |
| 19 | #include <cstdint> |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 20 | #include <cstring> |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
| 23 | namespace blobs |
| 24 | { |
| 25 | |
Patrick Venture | 0d2a813 | 2018-11-09 11:34:21 -0800 | [diff] [blame] | 26 | bool LpcDataHandler::open() |
| 27 | { |
| 28 | /* For the ASPEED LPC CTRL driver, the ioctl is required to set up the |
| 29 | * window, with information from write() below. |
| 30 | */ |
| 31 | return true; |
| 32 | } |
| 33 | |
Patrick Venture | 0fbabf2 | 2018-11-09 11:54:12 -0800 | [diff] [blame] | 34 | bool LpcDataHandler::close() |
| 35 | { |
| 36 | /* TODO: implement ioctl call to close window. */ |
| 37 | return false; |
| 38 | } |
| 39 | |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 40 | std::vector<std::uint8_t> LpcDataHandler::copyFrom(std::uint32_t length) |
| 41 | { |
Patrick Venture | f904750 | 2018-11-15 08:44:14 -0800 | [diff] [blame] | 42 | /* TODO: implement this -- in an earlier and different version of this that |
| 43 | * didn't use BLOBs, the region was memory-mapped and the writes to the data |
| 44 | * were just done directly from the memory-mapped region instead of a |
| 45 | * copyFrom() first call. The idea with this change is that we may not be |
| 46 | * able to get a memory-mapped handle from the driver from which to |
| 47 | * automatically read data, but rather must perform some ioctl or other |
| 48 | * access to get the data from the driver. |
| 49 | */ |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 50 | return {}; |
| 51 | } |
| 52 | |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 53 | bool LpcDataHandler::write(const std::vector<std::uint8_t>& configuration) |
| 54 | { |
Patrick Venture | 043bafa | 2018-11-15 08:41:04 -0800 | [diff] [blame] | 55 | struct LpcRegion lpcRegion; |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 56 | |
Patrick Venture | 043bafa | 2018-11-15 08:41:04 -0800 | [diff] [blame] | 57 | if (configuration.size() != sizeof(lpcRegion)) |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 58 | { |
| 59 | return false; |
| 60 | } |
| 61 | |
Patrick Venture | 043bafa | 2018-11-15 08:41:04 -0800 | [diff] [blame] | 62 | std::memcpy(&lpcRegion, configuration.data(), configuration.size()); |
| 63 | |
| 64 | std::uint32_t windowOffset; |
| 65 | std::uint32_t windowSize; |
| 66 | |
| 67 | /* TODO: LpcRegion sanity checking. */ |
| 68 | |
| 69 | std::tie(windowOffset, windowSize) = |
| 70 | mapper->mapWindow(lpcRegion.address, lpcRegion.length); |
| 71 | if (windowSize == 0) |
| 72 | { |
| 73 | /* Failed to map region. */ |
| 74 | } |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 75 | |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | std::vector<std::uint8_t> LpcDataHandler::read() |
| 80 | { |
| 81 | return {}; |
| 82 | } |
| 83 | |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 84 | } // namespace blobs |