blob: 982586a80799647d511b2df0a6faabbcdeab7950 [file] [log] [blame]
Maria Yu4c12e922018-05-10 16:18:20 +08001/* Copyright (c) 2014-2015, 2018, The Linux Foundation. All rights reserved.
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -07002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Fundation, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#include <rpm-smd.h>
31#include <smd.h>
32#include <stdint.h>
33#include <sys/types.h>
34#include <arch/defines.h>
35#include <debug.h>
36#include <stdlib.h>
Sridhar Parasuramf2348af2014-11-18 16:16:57 -080037#include <platform/timer.h>
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -070038
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -070039static uint32_t msg_id;
40smd_channel_info_t ch;
41
42void rpm_smd_init()
43{
44 smd_init(&ch, SMD_APPS_RPM);
45}
46
47void rpm_smd_uninit()
48{
49 smd_uninit(&ch);
50}
51
Sridhar Parasuram58b1f382015-02-05 09:55:37 -080052int rpm_smd_send_data(uint32_t *data, uint32_t len, msg_type type)
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -070053{
54 rpm_req req;
55 rpm_cmd cmd;
56 uint32_t len_to_smd = 0;
57 int ret = 0;
58 uint32_t ack_msg_len = 0;
59 uint32_t rlen = 0;
60 void *smd_data = NULL;
61
62 switch(type)
63 {
64 case RPM_REQUEST_TYPE:
65 req.hdr.type = RPM_REQ_MAGIC;
66 req.hdr.len = len + REQ_MSG_LENGTH;//20
67 req.req_hdr.id = ++msg_id;
68 req.req_hdr.set = 0;//assume active set. check sleep set.
69 req.req_hdr.resourceType = data[RESOURCETYPE];
70 req.req_hdr.resourceId = data[RESOURCEID];
71 req.req_hdr.dataLength = len;
72
73 fill_kvp_object(&req.data, data, len);
74 len_to_smd = req.req_hdr.dataLength + 0x28;
75
76 smd_data = (void*) malloc(len_to_smd);
77 ASSERT(smd_data);
78
79 memcpy(smd_data, &req.hdr, sizeof(rpm_gen_hdr));
80 memcpy(smd_data + sizeof(rpm_gen_hdr), &req.req_hdr, sizeof(rpm_req_hdr));
81 memcpy(smd_data + sizeof(rpm_gen_hdr)+ sizeof(rpm_req_hdr), req.data, len);
82
83 ret = smd_write(&ch, smd_data, len_to_smd, SMD_APPS_RPM);
84
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -070085 /* Read the response */
Sridhar Parasuram58b1f382015-02-05 09:55:37 -080086 ack_msg_len = rpm_smd_recv_data(&rlen);
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -070087
88 smd_signal_read_complete(&ch, ack_msg_len);
89
90 free(smd_data);
91 free_kvp_object(&req.data);
92 break;
93 case RPM_CMD_TYPE:
94 cmd.hdr.type = RPM_CMD_MAGIC;
95 cmd.hdr.len = CMD_MSG_LENGTH;//0x8;
Lijuan Gao9de5c432014-10-22 14:09:20 +080096 len_to_smd = sizeof(rpm_cmd);
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -070097
98 fill_kvp_object(&cmd.data, data, len);
99 ret = smd_write(&ch, (void *)&cmd, len_to_smd, SMD_APPS_RPM);
100
101 free_kvp_object(&cmd.data);
102 break;
103 default:
104 break;
105 }
106
107 return ret;
108}
109
Sridhar Parasuram58b1f382015-02-05 09:55:37 -0800110uint32_t rpm_smd_recv_data(uint32_t* len)
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -0700111{
112 rpm_ack_msg *resp;
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -0700113 uint32_t ret = 0;
Channagoud Kadabi637683d2014-11-26 14:51:14 -0800114 /* As per the current design rpm response does not exceed 20 bytes */
115 uint32_t response[5];
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -0700116
Channagoud Kadabi637683d2014-11-26 14:51:14 -0800117 smd_read(&ch, len, SMD_APPS_RPM, response);
118
119 resp = (rpm_ack_msg *)response;
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -0700120
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -0700121
Smita Ghoshfc6f64b2015-05-07 15:57:36 -0700122 if(resp->hdr.type == RPM_CMD_MAGIC && resp->hdr.len == ACK_MSG_LENGTH)
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -0700123 {
124 dprintf(SPEW, "Received SUCCESS CMD ACK\n");
125 }
Smita Ghoshfc6f64b2015-05-07 15:57:36 -0700126 else if (resp->hdr.type == RPM_REQ_MAGIC && resp->hdr.len == ACK_MSG_LENGTH)
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -0700127 {
Smita Ghoshfc6f64b2015-05-07 15:57:36 -0700128 dprintf(SPEW, "Received SUCCESS CMD ACK\n");
Sundarajan Srinivasanae6ece02014-07-01 14:01:29 -0700129 }
130 else
131 {
132 ret = 1;
133 dprintf(CRITICAL, "Received ERROR ACK \n");
134 }
135
136 if(!ret)
137 {
138 ret = sizeof(rpm_gen_hdr) + sizeof(kvp_data);
139 }
140
141 return ret;
142}