Commit 8fb370dd authored by Haoran.Wang's avatar Haoran.Wang Committed by Jason Liu

[iot] Import ql-tipc lib for Trusty OS

The lib provided ql-tipc communication channel with
Trusty OS.
Also the AVB, Keymaster and SecureStorage service
tipc client implement in this lib.

Change-Id: I0ab1ec9ee1b6f272b960c2e944008283c2c9249a
Signed-off-by: default avatarHaoran.Wang <elven.wang@nxp.com>
parent a22f7fb6
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef TRUSTY_INTERFACE_AVB_H_
#define TRUSTY_INTERFACE_AVB_H_
#include <trusty/sysdeps.h>
#define AVB_PORT "com.android.trusty.avb"
#define AVB_MAX_BUFFER_LENGTH 2048
enum avb_command {
AVB_REQ_SHIFT = 1,
AVB_RESP_BIT = 1,
READ_ROLLBACK_INDEX = (0 << AVB_REQ_SHIFT),
WRITE_ROLLBACK_INDEX = (1 << AVB_REQ_SHIFT),
AVB_GET_VERSION = (2 << AVB_REQ_SHIFT),
READ_PERMANENT_ATTRIBUTES = (3 << AVB_REQ_SHIFT),
WRITE_PERMANENT_ATTRIBUTES = (4 << AVB_REQ_SHIFT),
READ_LOCK_STATE = (5 << AVB_REQ_SHIFT),
WRITE_LOCK_STATE = (6 << AVB_REQ_SHIFT),
LOCK_BOOT_STATE = (7 << AVB_REQ_SHIFT),
};
/**
* enum avb_error - error codes for AVB protocol
* @AVB_ERROR_NONE: All OK
* @AVB_ERROR_INVALID: Invalid input
* @AVB_ERROR_INTERNAL: Error occurred during an operation in Trusty
*/
enum avb_error {
AVB_ERROR_NONE = 0,
AVB_ERROR_INVALID = 1,
AVB_ERROR_INTERNAL = 2,
};
/**
* avb_message - Serial header for communicating with AVB server
* @cmd: the command. Payload must be a serialized buffer of the
* corresponding request object.
* @result: resulting error code for message, one of avb_error.
* @payload: start of the serialized command specific payload
*/
struct avb_message {
uint32_t cmd;
uint32_t result;
uint8_t payload[0];
};
/**
* avb_rollback_req - request format for [READ|WRITE]_ROLLBACK_INDEX
* @value: value to write to rollback index. Ignored for read.
* @slot: slot number of rollback index to write
*/
struct avb_rollback_req {
uint64_t value;
uint32_t slot;
} TRUSTY_ATTR_PACKED;
/**
* avb_rollback_resp - response format for [READ|WRITE]_ROLLBACK_INDEX.
* @value: value of the requested rollback index.
*/
struct avb_rollback_resp {
uint64_t value;
};
/**
* avb_get_version_resp - response format for AVB_GET_VERSION.
* @version: version of AVB message format
*/
struct avb_get_version_resp {
uint32_t version;
};
#endif /* TRUSTY_INTERFACE_AVB_H_ */
This diff is collapsed.
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef TRUSTY_INTERFACE_STORAGE_H_
#define TRUSTY_INTERFACE_STORAGE_H_
/*
* The contents of this file are copied from
* trusty/lib/interface/storage/include/interface/storage/storage.h.
* It is required to stay in sync for struct formats and enum values.
*/
#include <trusty/sysdeps.h>
/*
* @STORAGE_DISK_PROXY_PORT: Port used by non-secure proxy server
*/
#define STORAGE_DISK_PROXY_PORT "com.android.trusty.storage.proxy"
enum storage_cmd {
STORAGE_REQ_SHIFT = 1,
STORAGE_RESP_BIT = 1,
STORAGE_RESP_MSG_ERR = STORAGE_RESP_BIT,
STORAGE_FILE_DELETE = 1 << STORAGE_REQ_SHIFT,
STORAGE_FILE_OPEN = 2 << STORAGE_REQ_SHIFT,
STORAGE_FILE_CLOSE = 3 << STORAGE_REQ_SHIFT,
STORAGE_FILE_READ = 4 << STORAGE_REQ_SHIFT,
STORAGE_FILE_WRITE = 5 << STORAGE_REQ_SHIFT,
STORAGE_FILE_GET_SIZE = 6 << STORAGE_REQ_SHIFT,
STORAGE_FILE_SET_SIZE = 7 << STORAGE_REQ_SHIFT,
STORAGE_RPMB_SEND = 8 << STORAGE_REQ_SHIFT,
/* transaction support */
STORAGE_END_TRANSACTION = 9 << STORAGE_REQ_SHIFT,
};
/**
* enum storage_err - error codes for storage protocol
* @STORAGE_NO_ERROR: all OK
* @STORAGE_ERR_GENERIC: unknown error. Can occur when there's an internal server
* error, e.g. the server runs out of memory or is in a bad state.
* @STORAGE_ERR_NOT_VALID: input not valid. May occur if the arguments passed
* into the command are not valid, for example if the file handle
* passed in is not a valid one.
* @STORAGE_ERR_UNIMPLEMENTED: the command passed in is not recognized
* @STORAGE_ERR_ACCESS: the file is not accessible in the requested mode
* @STORAGE_ERR_NOT_FOUND: the file was not found
* @STORAGE_ERR_EXIST the file exists when it shouldn't as in with OPEN_CREATE | OPEN_EXCLUSIVE.
* @STORAGE_ERR_TRANSACT returned by various operations to indicate that current transaction
* is in error state. Such state could be only cleared by sending
* STORAGE_END_TRANSACTION message.
*/
enum storage_err {
STORAGE_NO_ERROR = 0,
STORAGE_ERR_GENERIC = 1,
STORAGE_ERR_NOT_VALID = 2,
STORAGE_ERR_UNIMPLEMENTED = 3,
STORAGE_ERR_ACCESS = 4,
STORAGE_ERR_NOT_FOUND = 5,
STORAGE_ERR_EXIST = 6,
STORAGE_ERR_TRANSACT = 7,
};
/**
* enum storage_msg_flag - protocol-level flags in struct storage_msg
* @STORAGE_MSG_FLAG_BATCH: if set, command belongs to a batch transaction.
* No response will be sent by the server until
* it receives a command with this flag unset, at
* which point a cummulative result for all messages
* sent with STORAGE_MSG_FLAG_BATCH will be sent.
* This is only supported by the non-secure disk proxy
* server.
* @STORAGE_MSG_FLAG_PRE_COMMIT: if set, indicates that server need to commit
* pending changes before processing this message.
* @STORAGE_MSG_FLAG_POST_COMMIT: if set, indicates that server need to commit
* pending changes after processing this message.
* @STORAGE_MSG_FLAG_TRANSACT_COMPLETE: if set, indicates that server need to commit
* current transaction after processing this message.
* It is an alias for STORAGE_MSG_FLAG_POST_COMMIT.
*/
enum storage_msg_flag {
STORAGE_MSG_FLAG_BATCH = 0x1,
STORAGE_MSG_FLAG_PRE_COMMIT = 0x2,
STORAGE_MSG_FLAG_POST_COMMIT = 0x4,
STORAGE_MSG_FLAG_TRANSACT_COMPLETE = STORAGE_MSG_FLAG_POST_COMMIT,
};
/*
* The following declarations are the message-specific contents of
* the 'payload' element inside struct storage_msg.
*/
/**
* struct storage_rpmb_send_req - request format for STORAGE_RPMB_SEND
* @reliable_write_size: size in bytes of reliable write region
* @write_size: size in bytes of write region
* @read_size: number of bytes to read for a read request
* @__reserved: unused, must be set to 0
* @payload: start of reliable write region, followed by
* write region.
*
* Only used in proxy<->server interface.
*/
struct storage_rpmb_send_req {
uint32_t reliable_write_size;
uint32_t write_size;
uint32_t read_size;
uint32_t __reserved;
uint8_t payload[0];
};
/**
* struct storage_rpmb_send_resp: response type for STORAGE_RPMB_SEND
* @data: the data frames frames retrieved from the MMC.
*/
struct storage_rpmb_send_resp {
uint8_t data[0];
};
/**
* struct storage_msg - generic req/resp format for all storage commands
* @cmd: one of enum storage_cmd
* @op_id: client chosen operation identifier for an instance
* of a command or atomic grouping of commands (transaction).
* @flags: one or many of enum storage_msg_flag or'ed together.
* @size: total size of the message including this header
* @result: one of enum storage_err
* @__reserved: unused, must be set to 0.
* @payload: beginning of command specific message format
*/
struct storage_msg {
uint32_t cmd;
uint32_t op_id;
uint32_t flags;
uint32_t size;
int32_t result;
uint32_t __reserved;
uint8_t payload[0];
};
#endif /* TRUSTY_INTERFACE_STORAGE_H_ */
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef TRUSTY_AVB_H_
#define TRUSTY_AVB_H_
#include <trusty/sysdeps.h>
#include <trusty/trusty_ipc.h>
#include <interface/avb/avb.h>
/*
* Initialize AVB TIPC client. Returns one of trusty_err.
*
* @dev: initialized with trusty_ipc_dev_create
*/
int avb_tipc_init(struct trusty_ipc_dev *dev);
/*
* Shutdown AVB TIPC client.
*
* @dev: initialized with trusty_ipc_dev_create
*/
void avb_tipc_shutdown(struct trusty_ipc_dev *dev);
/*
* Send request to secure side to read rollback index.
* Returns one of trusty_err.
*
* @slot: rollback index slot
* @value: rollback index value stored here
*/
int trusty_read_rollback_index(uint32_t slot, uint64_t *value);
/*
* Send request to secure side to write rollback index
* Returns one of trusty_err.
*
* @slot: rollback index slot
* @value: rollback index value to write
*/
int trusty_write_rollback_index(uint32_t slot, uint64_t value);
/*
* Send request to secure side to read permanent attributes. When permanent
* attributes are stored in RPMB, a hash of the permanent attributes which is
* given to AVB during verification MUST still be backed by write-once hardware.
*
* Copies attributes received by secure side to |attributes|. If |size| does not
* match the size returned by the secure side, an error is returned. Returns one
* of trusty_err.
*
* @attributes: caller allocated buffer
* @size: size of |attributes|
*/
int trusty_read_permanent_attributes(uint8_t *attributes, uint32_t size);
/*
* Send request to secure side to write permanent attributes. Permanent
* attributes can only be written to storage once.
*
* Returns one of trusty_err.
*/
int trusty_write_permanent_attributes(uint8_t *attributes, uint32_t size);
/*
* Send request to secure side to read device lock state from RPMB.
*
* Returns one of trusty_err.
*/
int trusty_read_lock_state(uint8_t *lock_state);
/*
* Send request to secure side to write device lock state to RPMB. If the lock
* state is changed, all rollback index data will be cleared.
*
* Returns one of trusty_err.
*/
int trusty_write_lock_state(uint8_t lock_state);
/*
* Send request to secure side to lock the boot state. After this is invoked,
* the non-secure side will not be able to write to data managed by the AVB
* service until next boot.
*
* Returns one of trusty_err.
*/
int trusty_lock_boot_state(void);
#endif /* TRUSTY_AVB_H_ */
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef TRUSTY_KEYMASTER_H_
#define TRUSTY_KEYMASTER_H_
#include <trusty/sysdeps.h>
#include <trusty/trusty_ipc.h>
#include <interface/keymaster/keymaster.h>
/*
* Initialize Keymaster TIPC client. Returns one of trusty_err.
*
* @dev: initialized with trusty_ipc_dev_create
*/
int km_tipc_init(struct trusty_ipc_dev *dev);
/*
* Shutdown Keymaster TIPC client.
*
* @dev: initialized with trusty_ipc_dev_create
*/
void km_tipc_shutdown(struct trusty_ipc_dev *dev);
/*
* Set Keymaster boot parameters. Returns one of trusty_err.
*
* @os_version: OS version from Android image header
* @os_patchlevel: OS patch level from Android image header
* @verified_boot_state: one of keymaster_verified_boot_t
* @device_locked: nonzero if device is locked
* @verified_boot_key_hash: hash of key used to verify Android image
* @verified_boot_key_hash_size: size of verified_boot_key_hash
* @verified_boot_hash: cumulative hash of all images verified thus far.
* May be NULL if not computed.
* @verified_boot_hash_size: size of verified_boot_hash
*/
int trusty_set_boot_params(uint32_t os_version, uint32_t os_patchlevel,
keymaster_verified_boot_t verified_boot_state,
bool device_locked,
const uint8_t *verified_boot_key_hash,
uint32_t verified_boot_key_hash_size,
const uint8_t *verified_boot_hash,
uint32_t verified_boot_hash_size);
/*
* Set Keymaster attestation key. Returns one of trusty_err.
*
* @key: buffer containing key
* @key_size: size of key in bytes
* @algorithm: one of KM_ALGORITHM_RSA or KM_ALGORITHM_EC
*/
int trusty_set_attestation_key(const uint8_t *key, uint32_t key_size,
keymaster_algorithm_t algorithm);
/*
* Append certificate to Keymaster attestation certificate chain. Returns
* one of trusty_err.
*
* @cert: buffer containing certificate
* @cert_size: size of certificate in bytes
* @algorithm: one of KM_ALGORITHM_RSA or KM_ALGORITHM_EC
*/
int trusty_append_attestation_cert_chain(const uint8_t *cert,
uint32_t cert_size,
keymaster_algorithm_t algorithm);
#endif /* TRUSTY_KEYMASTER_H_ */
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef TRUSTY_LIBTIPC_H_
#define TRUSTY_LIBTIPC_H_
#include <trusty/avb.h>
#include <trusty/keymaster.h>
#include <trusty/sysdeps.h>
/*
* Initialize TIPC library
*/
void trusty_ipc_init(void);
/*
* Shutdown TIPC library
*/
void trusty_ipc_shutdown(void);
#endif /* TRUSTY_LIBTIPC_H_ */
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef TRUSTY_RPMB_H_
#define TRUSTY_RPMB_H_
#include <trusty/sysdeps.h>
#include <trusty/trusty_ipc.h>
#define MMC_BLOCK_SIZE 512
/*
* Initialize RPMB storage proxy. Returns one of trusty_err.
*
* @dev: initialized with trusty_ipc_dev_create
* @rpmb_dev: Context of RPMB device, initialized with rpmb_storage_get_ctx
*/
int rpmb_storage_proxy_init(struct trusty_ipc_dev *dev, void *rpmb_dev);
/*
* Poll for and handle RPMB storange events. Returns one of trusty_err.
*/
int rpmb_storage_proxy_poll(void);
/*
* Shutdown RPMB storage proxy
*
* @dev: initialized with trusty_ipc_dev_create
*/
void rpmb_storage_proxy_shutdown(struct trusty_ipc_dev *dev);
/*
* Execute RPMB command. Implementation is platform specific.
* Returns one of trusty_err.
*
* @rpmb_dev: Context of RPMB device, initialized with
* rpmb_storage_get_ctx
* @reliable_write_data: Buffer containing RPMB structs for reliable write
* @reliable_write_size: Size of reliable_write_data
* @write_data: Buffer containing RPMB structs for write
* @write_size: Size of write_data
* @read_data: Buffer to be filled with RPMB structs read from RPMB
* partition
* @read_size: Size of read_data
*/
int rpmb_storage_send(void *rpmb_dev,
const void *reliable_write_data,
size_t reliable_write_size,
const void *write_data, size_t write_size,
void *read_buf, size_t read_size);
/*
* Return context for RPMB device. This is called when the RPMB storage proxy is
* initialized, and subsequently used when issuing RPMB storage requests.
* Implementation is platform specific.
*/
void *rpmb_storage_get_ctx(void);
#endif /* TRUSTY_RPMB_H_ */
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef TRUSTY_SYSDEPS_H_
#define TRUSTY_SYSDEPS_H_
/*
* Change these includes to match your platform to bring in the equivalent
* types available in a normal C runtime. At least things like uint64_t,
* uintptr_t, and bool (with |false|, |true| keywords) must be present.
*/
#include <compiler.h>
#include <stdarg.h>
#include <stdbool.h>
#include <linux/types.h>
/*
* These attribute macros may need to be adjusted if not using gcc or clang.
*/
#define TRUSTY_ATTR_PACKED __attribute__((packed))
#define TRUSTY_ATTR_NO_RETURN __attribute__((noreturn))
#define TRUSTY_ATTR_SENTINEL __attribute__((__sentinel__))
#define TRUSTY_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#define PAGE_SIZE 4096
/*
* Struct containing attributes for memory to be shared with secure size.
*/
struct ns_mem_page_info {
uint64_t attr;
};
struct trusty_dev;
/*
* Lock/unlock mutex associated with @dev. These can be safely empty in a single
* threaded environment.
*
* @dev: Trusty device initialized with trusty_dev_init
*/
void trusty_lock(struct trusty_dev *dev);
void trusty_unlock(struct trusty_dev *dev);
/*
* Disable/enable IRQ interrupts and save/restore @state
*/
void trusty_local_irq_disable(unsigned long *state);
void trusty_local_irq_restore(unsigned long *state);
/*
* Put in standby state waiting for interrupt.
*
* @dev: Trusty device initialized with trusty_dev_init
*/
void trusty_idle(struct trusty_dev *dev);
/*
* Aborts the program or reboots the device.
*/
void trusty_abort(void) TRUSTY_ATTR_NO_RETURN;
/*
* Print a formatted string. @format must point to a NULL-terminated UTF-8
* string, and is followed by arguments to be printed.
*/
void trusty_printv(const char *format, ...);
/*
* Copy @n bytes from @src to @dest.
*/
void *trusty_memcpy(void *dest, const void *src, size_t n);
/*
* Set @n bytes starting at @dest to @c. Returns @dest.
*/
void *trusty_memset(void *dest, const int c, size_t n);
/*
* Copy string from @src to @dest, including the terminating NULL byte.
*
* The size of the array at @dest should be long enough to contain the string
* at @src, and should not overlap in memory with @src.
*/
char *trusty_strcpy(char *dest, const char *src);
/*
* Returns the length of @str, excluding the terminating NULL byte.
*/
size_t trusty_strlen(const char *str);
/*
* Allocate @n elements of size @size. Initializes memory to 0, returns pointer
* to it.
*/
void *trusty_calloc(size_t n, size_t size) TRUSTY_ATTR_WARN_UNUSED_RESULT;
/*
* Free memory at @addr allocated with trusty_calloc.
*/
void trusty_free(void *addr);
/*
* Allocate @size bytes of page aligned memory to be shared with secure side.
*
* @mem_inf: Stores cache attributes
* Returns: vaddr of allocated memory
*/
void *trusty_membuf_alloc(struct ns_mem_page_info *mem_inf,
size_t size) TRUSTY_ATTR_WARN_UNUSED_RESULT;
/*
* Frees memory at @vaddr allocated by trusty_membuf_alloc
*/
void trusty_membuf_free(void *vaddr);
#endif /* TRUSTY_SYSDEPS_H_ */
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef TRUSTY_TRUSTY_DEV_H_
#define TRUSTY_TRUSTY_DEV_H_
#include <trusty/sysdeps.h>
/*
* Architecture specific Trusty device struct.
*
* @priv_data: system dependent data, may be unused
* @api_version: TIPC version
*/
struct trusty_dev {
void *priv_data;
uint32_t api_version;
};
/*
* Initializes @dev with @priv, and gets the API version by calling
* into Trusty. Returns negative on error.
*/
int trusty_dev_init(struct trusty_dev *dev, void *priv);
/*
* Cleans up anything related to @dev. Returns negative on error.
*/
int trusty_dev_shutdown(struct trusty_dev *dev);