/*
 * graphite.h
 *
 * This header contains structure and other definitions for Graphite
 * client and server communication (commands and responses)
 *
 * Copyright (c) 2016 Qualcomm Technologies, Inc.
 * All Rights Reserved.
 * Confidential and Proprietary - Qualcomm Technologies, Inc.
 */

#ifndef __GRAPHITE_H__
#define __GRAPHITE_H__

#include <graphite_errorcodes.h>
#include <graphite_common.h>
/*
 * Graphite Module IDs and PARAM IDs.
 * These are defined by Graphite and used by GCS to
 * send commands to Graphite server.
 */

#define GRAPHITE_MODULE_FWK                            0x00020001
#define GRAPHITE_PARAM_ID_MODULE_LIST                  0x00020002
#define GRAPHITE_PARAM_ID_CONNECT                      0x00020003
#define GRAPHITE_PARAM_ID_DISCONNECT                   0x00020004
#define GRAPHITE_PARAM_ID_INDIRECT_CALIB_DATA          0x00020005
#define GRAPHITE_PARAM_ID_EVENT_REGISTER               0x00020006
#define GRAPHITE_PARAM_ID_EVENT_DEREGISTER             0x00020007

#define GRAPHITE_METADATA_ISLAND_FLAG_MASK             (0x0001)
#define GRAPHITE_METADATA_ISLAND_FLAG_SHIFT            0

/*
 * Graphite command structures.
 * These structures are defined by Graphite and used by entities to
 * create command payload/header to send to Graphite server.
 */

/* Graphite Event header */
#include <osal_pack_start.h>
struct graphite_event_header {
    /*
     * Any non-zero value.
     * A unique identifier for a particular module
     */
    uint32_t module_id;

    /*
     * Instance ID of the particular module.
     * instance_id is not applicable to framework modules, and will be
     * ignored.
     */
    uint16_t instance_id;

    /* Reserved field, must be set to 0. */
    uint16_t reserved;

    /* Indicates a particular event that is raised by Graphite */
    uint32_t param_id;
}
#include <osal_pack_end.h>
;

/* Graphite module header */
#include <osal_pack_start.h>
struct graphite_module {
    /* Module ID of a particular module */
    uint32_t module_id;

    /* Instance ID of the particular module. */
    uint16_t instance_id;

    /*
     * Bits 15:1 - Reserved, must be set to 0.
     * Bits 0    - 0: module needs to be instantiated in non-Island heap.
     *             1: module needs to be instantiated in Island heap if
     *                possible, but if Island heap is full, the module
     *                will be instantiated in non-Island heap instead.
     *
     * Metadata gives more information on how this module needs to be
     * instantiated.
     *
     * Note: this field is ignored for GRAPHITE_CMD_CLOSE.
     */
    uint16_t metadata;

    /*
     * The maximum number of input streams that the module can accept.
     * Note that the active number of incoming connections can be less
     * than this value.
     *
     * Note: this field is ignored for GRAPHITE_CMD_CLOSE.
     */
    uint16_t max_input_pins;

    /*
     * The maximum number of output streams generated by the module.
     * Note that the active number of outputs for the module can be less
     * than this value
     *
     * Note: this field is ignored for GRAPHITE_CMD_CLOSE.
     */
    uint16_t max_output_pins;
}
#include <osal_pack_end.h>
;

/* Graphite indirect calibration header (for persist data) */
#include <osal_pack_start.h>
struct graphite_indirect_cal_data {
    /*
     * This is the address of a calibration payload previously sent by a
     * client to the Graphite server through the GRAPHITE_CMD_LOAD_DATA
     * command.
     */
    uint32_t addr;

    /*
     * This is the size of the payload pointed to by the addr field
     */
    uint32_t size;
}
#include <osal_pack_end.h>
;

/* Graphite GRAPHITE_CMD_UNLOAD_DATA header */
#include <osal_pack_start.h>
struct graphite_unload_data {
    /*
     * This is the address of the data blob that should be freed.
     * This address is where GRAPHITE_CMD_LOAD_DATA payload was previously
     * loaded at, and returned to the client via the
     * #GRAPHITE_CMDRSP_LOAD_DATA command response.
     */
    uint32_t addr;
}
#include <osal_pack_end.h>
;

/* Graphite header for defining edge of source module */
#include <osal_pack_start.h>
struct graphite_edge_src_module {
    /* Module ID of a particular module */
    uint32_t module_id;

    /* Instance ID of the particular module. */
    uint16_t instance_id;

    /*
     * Number of destination modules for connections/edges originating from
     * this module.
     */
    uint16_t num_destination_modules;
}
#include <osal_pack_end.h>
;

/* Graphite header for defining edge of destination module */
#include <osal_pack_start.h>
struct graphite_edge_dest_module {
    /* Module ID of a particular module */
    uint32_t module_id;

    /* Instance ID of the particular module. */
    uint16_t instance_id;

    /*
     * Number of connections/edges specified between the given source and
     * destination modules.
     */
    uint16_t num_edges;
}
#include <osal_pack_end.h>
;

/* Graphite header to define an edge */
#include <osal_pack_start.h>
struct graphite_edge {
    /*
     * Pin ID specifying the origin of this edge.
     */
    uint16_t source_pin_id;

    /*
     * Pin ID specifying the termination of this edge.
     */
    uint16_t destination_pin_id;
}
#include <osal_pack_end.h>
;

/*
 * Graphite command responses
 * These structures are defined by Graphite and used by Graphite
 * server to respond back a command sent from GCS.
 */

/* Graphite command basic response */
#include <osal_pack_start.h>
struct graphite_basic_rsp_result {
    /* Valid Graphite error code or completion status */
    uint32_t status;
}
#include <osal_pack_end.h>
;

/* Graphite GRAPHITE_CMDRSP_LOAD_DATA header */
#include <osal_pack_start.h>
struct graphite_load_data_rsp {
    /*
     * If addr is NULL, then #GRAPHITE_CMD_LOAD_DATA command failed.
     * This is the address at which the GRAPHITE_CMD_LOAD_DATA payload was
     * deposited at. The client should pass this address back to the Graphite
     * server in the future when it wants this payload to be processed.
     */
    uint32_t addr;
}
#include <osal_pack_end.h>
;

#endif /* __GRAPHITE_H__ */
