1 /* 2 * Copyright (C) 2017 The Android Open Source Project 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 #ifndef NOS_DEVICE_H 17 #define NOS_DEVICE_H 18 19 #ifdef ANDROID 20 #include <stdbool.h> 21 #endif 22 #include <stdint.h> 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* Max data size for read/write. 29 * Yes, it's a magic number. See b/37675056#comment8. */ 30 #define MAX_DEVICE_TRANSFER 2044 31 32 struct nos_device_ops { 33 /** 34 * Read a datagram from the device. 35 * 36 * Return 0 on success and a negative value on failure. 37 */ 38 int (*read)(void* ctx, uint32_t command, uint8_t *buf, uint32_t len); 39 40 /** 41 * Write a datagram to the device. 42 * 43 * Return 0 on success and a negative value on failure. 44 */ 45 int (*write)(void *ctx, uint32_t command, const uint8_t *buf, uint32_t len); 46 47 /** 48 * Block until an event has happened on the device, or until timed out. 49 * 50 * Values for msecs 51 * <0 wait forever 52 * 0 return immediately (why?) 53 * >0 timeout after this many milliseconds 54 * 55 * Returns: 56 * <0 on error 57 * 0 timed out 58 * >0 interrupt occurred 59 */ 60 int (*wait_for_interrupt)(void *ctx, int msecs); 61 62 /** 63 * Reset the device. 64 * 65 * Return 0 on success and a negative value on failure. 66 */ 67 int (*reset)(void *ctx); 68 69 /** 70 * Close the connection to the device. 71 * 72 * The device must not be used after closing. 73 */ 74 void (*close)(void *ctx); 75 76 #ifdef ANDROID 77 /** 78 * one_pass_call: sending whole data payload directly to GSA FW 79 * and rely on GSA libnos_transport library to communicate with GSC. 80 * 81 * Return 0 on success. A negative value on I/O failure. 82 */ 83 int (*one_pass_call)(void *ctx, uint8_t app_id, uint16_t params, 84 const uint8_t *args, uint32_t arg_len, 85 uint8_t *reply, uint32_t *reply_len, 86 uint32_t *status_code); 87 #endif 88 }; 89 90 struct nos_device { 91 void *ctx; 92 struct nos_device_ops ops; 93 uint32_t config; 94 #ifdef ANDROID 95 bool use_one_pass_call; 96 #endif 97 }; 98 99 /* 100 * Open a connection to a Nugget device. 101 * 102 * The name parameter identifies which Nugget device to connect to. Passing 103 * NULL connects to the default device. 104 * 105 * This function is implemented by the host specific variants of this library. 106 * 107 * Returns 0 on success or negative on failure. 108 */ 109 int nos_device_open(const char *name, struct nos_device *device); 110 111 #ifdef __cplusplus 112 } 113 #endif 114 115 #endif /* NOS_DEVICE_H */ 116