1 /** @addtogroup MCD_MCDIMPL_DAEMON_DEV 2 * @{ 3 * @file 4 * 5 * Class for TrustZone Devices. 6 * TrustZone device implements communication functions needed for 7 * accessing MobiCore located in an TrustZone environment. 8 * 9 * <!-- Copyright Giesecke & Devrient GmbH 2009 - 2012 --> 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. The name of the author may not be used to endorse or promote 20 * products derived from this software without specific prior 21 * written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 24 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 29 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 #ifndef TRUSTZONEDEVICE_H_ 36 #define TRUSTZONEDEVICE_H_ 37 38 39 #include <stdint.h> 40 41 #include "McTypes.h" 42 43 #include "CSemaphore.h" 44 #include "CMcKMod.h" 45 #include "CWsm.h" 46 47 #include "ExcDevice.h" 48 #include "MobiCoreDevice.h" 49 50 51 #define SCHEDULING_FREQ 5 /**< N-SIQ every n-th time */ 52 53 class TrustZoneDevice : public MobiCoreDevice 54 { 55 56 protected: 57 bool schedulerEnabled; /**< NQ IRQ Scheduler enabling */ 58 CSemaphore schedSync; /**< Semaphore to synchronize S-SIQs with scheduler thread */ 59 CMcKMod_ptr pMcKMod; /**< kernel module */ 60 CWsm_ptr pWsmMcp; /**< WSM use for MCP */ 61 CWsm_ptr mobicoreInDDR; /**< WSM used for Mobicore binary */ 62 63 /** Access functions to the MC Linux kernel module 64 */ 65 bool yield(void); 66 67 bool nsiq(void); 68 69 bool waitSsiq(void); 70 71 public: 72 73 TrustZoneDevice(void); 74 75 virtual ~TrustZoneDevice(void); 76 77 // static MobiCoreDevice* getDeviceInstance( 78 // void 79 // ); 80 /** Set up MCI and wait till MC is initialized 81 * 82 * @param devFile the device node to speak to. 83 * @param loadMobiCore 84 * @param mobicoreImage 85 * @param enableScheduler 86 * 87 * @return true if mobicore is initialized 88 * @trows ExcDevice 89 */ 90 bool initDevice( 91 const char *devFile, 92 bool loadMobiCore, 93 const char *mobicoreImage, 94 bool enableScheduler 95 ); 96 97 void initDeviceStep2(void); 98 99 void notify(uint32_t sessionId); 100 101 void dumpMobicoreStatus(void); 102 103 uint32_t getMobicoreStatus(void); 104 105 bool checkMciVersion(void); 106 107 /** Memory allocation functions */ 108 bool getMciInstance(uint32_t len, CWsm_ptr *mci, bool *reused); 109 110 //bool freeWsm(CWsm_ptr pWsm); 111 112 CWsm_ptr registerWsmL2(addr_t buffer, uint32_t len, uint32_t pid); 113 114 bool unregisterWsmL2(CWsm_ptr pWsm); 115 116 bool lockWsmL2(uint32_t handle); 117 118 bool unlockWsmL2(uint32_t handle); 119 120 addr_t findWsmL2(uint32_t handle); 121 122 bool findContiguousWsm(uint32_t handle, addr_t *phys, uint32_t *len); 123 124 /** 125 * Cleanup all orphaned bulk buffers. 126 */ 127 bool cleanupWsmL2(void); 128 129 /** 130 * Allocates persistent WSM memory for TL (won't be fried when TLC exits). 131 */ 132 CWsm_ptr allocateContiguousPersistentWsm(uint32_t len); 133 134 bool schedulerAvailable(void); 135 136 void schedule(void); 137 138 void handleIrq(void); 139 }; 140 141 #endif /* TRUSTZONEDEVICE_H_ */ 142 143 /** @} */ 144