0001
0002
0003 #ifndef __QCOM_APR_H_
0004 #define __QCOM_APR_H_
0005
0006 #include <linux/spinlock.h>
0007 #include <linux/device.h>
0008 #include <linux/mod_devicetable.h>
0009 #include <dt-bindings/soc/qcom,apr.h>
0010 #include <dt-bindings/soc/qcom,gpr.h>
0011
0012 extern struct bus_type aprbus;
0013
0014 #define APR_HDR_LEN(hdr_len) ((hdr_len)/4)
0015
0016
0017
0018
0019
0020
0021
0022
0023 #define APR_HDR_FIELD(msg_type, hdr_len, ver)\
0024 (((msg_type & 0x3) << 8) | ((hdr_len & 0xF) << 4) | (ver & 0xF))
0025
0026 #define APR_HDR_SIZE sizeof(struct apr_hdr)
0027 #define APR_SEQ_CMD_HDR_FIELD APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
0028 APR_HDR_LEN(APR_HDR_SIZE), \
0029 APR_PKT_VER)
0030
0031 #define APR_PKT_VER 0x0
0032
0033
0034 #define APR_MSG_TYPE_EVENT 0x0
0035 #define APR_MSG_TYPE_CMD_RSP 0x1
0036 #define APR_MSG_TYPE_SEQ_CMD 0x2
0037 #define APR_MSG_TYPE_NSEQ_CMD 0x3
0038 #define APR_MSG_TYPE_MAX 0x04
0039
0040
0041 #define APR_BASIC_RSP_RESULT 0x000110E8
0042 #define APR_RSP_ACCEPTED 0x000100BE
0043
0044 struct aprv2_ibasic_rsp_result_t {
0045 uint32_t opcode;
0046 uint32_t status;
0047 };
0048
0049
0050 #define APR_HDR_FIELD_VER(h) (h & 0x000F)
0051 #define APR_HDR_FIELD_SIZE(h) ((h & 0x00F0) >> 4)
0052 #define APR_HDR_FIELD_SIZE_BYTES(h) (((h & 0x00F0) >> 4) * 4)
0053 #define APR_HDR_FIELD_MT(h) ((h & 0x0300) >> 8)
0054
0055 struct apr_hdr {
0056 uint16_t hdr_field;
0057 uint16_t pkt_size;
0058 uint8_t src_svc;
0059 uint8_t src_domain;
0060 uint16_t src_port;
0061 uint8_t dest_svc;
0062 uint8_t dest_domain;
0063 uint16_t dest_port;
0064 uint32_t token;
0065 uint32_t opcode;
0066 } __packed;
0067
0068 struct apr_pkt {
0069 struct apr_hdr hdr;
0070 uint8_t payload[];
0071 };
0072
0073 struct apr_resp_pkt {
0074 struct apr_hdr hdr;
0075 void *payload;
0076 int payload_size;
0077 };
0078
0079 struct gpr_hdr {
0080 uint32_t version:4;
0081 uint32_t hdr_size:4;
0082 uint32_t pkt_size:24;
0083 uint32_t dest_domain:8;
0084 uint32_t src_domain:8;
0085 uint32_t reserved:16;
0086 uint32_t src_port;
0087 uint32_t dest_port;
0088 uint32_t token;
0089 uint32_t opcode;
0090 } __packed;
0091
0092 struct gpr_pkt {
0093 struct gpr_hdr hdr;
0094 uint32_t payload[];
0095 };
0096
0097 struct gpr_resp_pkt {
0098 struct gpr_hdr hdr;
0099 void *payload;
0100 int payload_size;
0101 };
0102
0103 #define GPR_HDR_SIZE sizeof(struct gpr_hdr)
0104 #define GPR_PKT_VER 0x0
0105 #define GPR_PKT_HEADER_WORD_SIZE ((sizeof(struct gpr_pkt) + 3) >> 2)
0106 #define GPR_PKT_HEADER_BYTE_SIZE (GPR_PKT_HEADER_WORD_SIZE << 2)
0107
0108 #define GPR_BASIC_RSP_RESULT 0x02001005
0109
0110 struct gpr_ibasic_rsp_result_t {
0111 uint32_t opcode;
0112 uint32_t status;
0113 };
0114
0115 #define GPR_BASIC_EVT_ACCEPTED 0x02001006
0116
0117 struct gpr_ibasic_rsp_accepted_t {
0118 uint32_t opcode;
0119 };
0120
0121
0122 #define APR_SVC_MAJOR_VERSION(v) ((v >> 16) & 0xFF)
0123 #define APR_SVC_MINOR_VERSION(v) (v & 0xFF)
0124
0125 typedef int (*gpr_port_cb) (struct gpr_resp_pkt *d, void *priv, int op);
0126 struct packet_router;
0127 struct pkt_router_svc {
0128 struct device *dev;
0129 gpr_port_cb callback;
0130 struct packet_router *pr;
0131 spinlock_t lock;
0132 int id;
0133 void *priv;
0134 };
0135
0136 typedef struct pkt_router_svc gpr_port_t;
0137
0138 struct apr_device {
0139 struct device dev;
0140 uint16_t svc_id;
0141 uint16_t domain_id;
0142 uint32_t version;
0143 char name[APR_NAME_SIZE];
0144 const char *service_path;
0145 struct pkt_router_svc svc;
0146 struct list_head node;
0147 };
0148
0149 typedef struct apr_device gpr_device_t;
0150
0151 #define to_apr_device(d) container_of(d, struct apr_device, dev)
0152 #define svc_to_apr_device(d) container_of(d, struct apr_device, svc)
0153
0154 struct apr_driver {
0155 int (*probe)(struct apr_device *sl);
0156 int (*remove)(struct apr_device *sl);
0157 int (*callback)(struct apr_device *a,
0158 struct apr_resp_pkt *d);
0159 int (*gpr_callback)(struct gpr_resp_pkt *d, void *data, int op);
0160 struct device_driver driver;
0161 const struct apr_device_id *id_table;
0162 };
0163
0164 typedef struct apr_driver gpr_driver_t;
0165 #define to_apr_driver(d) container_of(d, struct apr_driver, driver)
0166
0167
0168
0169
0170 #define apr_driver_register(drv) __apr_driver_register(drv, THIS_MODULE)
0171
0172 int __apr_driver_register(struct apr_driver *drv, struct module *owner);
0173 void apr_driver_unregister(struct apr_driver *drv);
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184 #define module_apr_driver(__apr_driver) \
0185 module_driver(__apr_driver, apr_driver_register, \
0186 apr_driver_unregister)
0187 #define module_gpr_driver(__gpr_driver) module_apr_driver(__gpr_driver)
0188
0189 int apr_send_pkt(struct apr_device *adev, struct apr_pkt *pkt);
0190
0191 gpr_port_t *gpr_alloc_port(gpr_device_t *gdev, struct device *dev,
0192 gpr_port_cb cb, void *priv);
0193 void gpr_free_port(gpr_port_t *port);
0194 int gpr_send_port_pkt(gpr_port_t *port, struct gpr_pkt *pkt);
0195 int gpr_send_pkt(gpr_device_t *gdev, struct gpr_pkt *pkt);
0196
0197 #endif