bcp_si.c
4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*************************************************************************
*
* File: bcp_si.c
*
* Whatever platform it is:
* MSB --- bit 31
* LSB --- bit 0
*
*/
#include <stdlib.h>
#include <stdio.h>
#include "simipc.h"
#include "iotest.h"
#include "trace.h"
#include <errno.h>
#include <memory.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <fcntl.h>
#include "iomap.h"
#include "bcp_util.h"
int linux_IO_Request(IpcPkt *req, IpcPkt *rsp);
#define BDSIDBG 1
int bd_si_ctrl_setup(int ctrl, int func, int data, int extra)
{
IpcPkt req, rsp;
//assert((ctrl >= LOCAL_CTRL) && (ctrl <= JCTRL_3));
//assert((func >= CRTL_ENALE) && (ctrl <= CTRL_FRAMEERR));
memset(&req, 0, sizeof(IpcPkt));
memset(&rsp, 0, sizeof(IpcPkt));
req.length = htonl(sizeof(IpcPkt));
req.code = htonl(BD_REQ_SI_CTRL);
req.size = htonl(func);
req.address = htonl(ctrl);
req.data[0] = htonl(data);
if (linux_IO_Request(&req, &rsp) < 0) {
fprintf(LogFp, "Fatal error: Cannot Write to BCP SI Backdoor!\n");
return -1;
}
if ((ntohl(rsp.code) & 0x1ff) != RSP_OK) {
fprintf(LogFp, "bd_si_ctrl_setup Fatal error: rsp.code %d\n", ntohl(rsp.code));
return -1;
}
return 0;
}
int bd_si_ctrl_rd(unsigned int *result, int bytes)
{
/* this routine only works for MJCTRL response data reads
* use bd_si_ctrl_rd_pkd for general si bd reads
*
* returns 1st transmited byte in most significant byte of result
*/
IpcPkt req, rsp;
int i;
u8 data[8];
memset(&req, 0, sizeof(IpcPkt));
memset(&rsp, 0, sizeof(IpcPkt));
req.length = htonl(sizeof(IpcPkt));
req.code = htonl(BD_RD_SI_CTRL);
req.size = htonl(bytes);
if (linux_IO_Request(&req, &rsp) < 0) {
fprintf(LogFp, "bd_si_ctrl_rd Fatal error: Cannot get data!\n");
return -1;
}
if ((ntohl(rsp.code) & 0x1ff) != RSP_DATA) {
fprintf(LogFp, "bd_si_ctrl_rd Fatal error: rsp.code %d\n", ntohl(rsp.code));
return -1;
}
for(i=0; i<4; i++)
*((u32*)&data[i]) = ntohl(rsp.data[i]);
*result = htonl(*((u32*)&data[0]));
#if BDSIDBG
fprintf(LogFp,"\nbd_si_ctrl_rd: rsp.data[0]=%08x ntohl=%08x",rsp.data[0], ntohl(rsp.data[0]));
fprintf(LogFp,"\nbd_si_ctrl_rd: rsp.data[1]=%08x ntohl=%08x",rsp.data[1], ntohl(rsp.data[1]));
fprintf(LogFp,"\nbd_si_ctrl_rd: rsp.data[2]=%08x ntohl=%08x",rsp.data[2], ntohl(rsp.data[2]));
fprintf(LogFp,"\nbd_si_ctrl_rd: rsp.data[3]=%08x ntohl=%08x",rsp.data[3], ntohl(rsp.data[3]));
fprintf(LogFp,"\nbd_si_ctrl_rd: result=%08x",*result);
#endif
return 0;
}
int bd_si_ctrl_wr_pkd(int ctrl, int func, unsigned char *data, int bytes)
{
IpcPkt req, rsp;
int i;
memset(&req, 0, sizeof(IpcPkt));
memset(&rsp, 0, sizeof(IpcPkt));
req.length = htonl(sizeof(IpcPkt));
req.code = htonl(BD_REQ_SI_CTRL);
req.size = htonl(func);
req.address = htonl(ctrl);
for(i=0; i<bytes && i/4<8; i+=4) {
req.data[i/4] = htonl(*((u32*)(&data[i])));
#if BDSIDBG
fprintf(LogFp,"\nbd_si_ctrl_wr_pkd: req.data[%d]=%08x *((u32*)(&data[%d]))=%08lx",i/4,req.data[i/4],i,*((u32*)(&data[i])));
#endif
}
if (linux_IO_Request(&req, &rsp) < 0) {
fprintf(LogFp, "bd_si_ctrl_bsetup Fatal error: Cannot Write to BCP SI Backdoor!\n");
return -1;
}
if ((ntohl(rsp.code) & 0x1ff) != RSP_OK) {
fprintf(LogFp, "bd_si_ctrl_bsetup Fatal error: rsp.code %d\n", ntohl(rsp.code));
return -1;
}
return 0;
}
int bd_si_ctrl_set_mm_tx_data(unsigned char mm_tx_data[SI_MM_TX_DATA_SIZE])
{
int ret;
ret = bd_si_ctrl_wr_pkd(JCTRL_1, CTRL_TX_DATA_0_7, &mm_tx_data[0], 8);
if(!ret) ret=bd_si_ctrl_wr_pkd(JCTRL_1, CTRL_TX_DATA_8_35, &mm_tx_data[8], 28);
return ret;
}
int bd_si_ctrl_rd_pkd(int ctrl, int func, unsigned char *result, int bytes)
{
IpcPkt req, rsp;
int i, j;
memset(&req, 0, sizeof(IpcPkt));
memset(&rsp, 0, sizeof(IpcPkt));
req.length = htonl(sizeof(IpcPkt));
req.code = htonl(BD_RD_SI_CTRL_PKD);
req.size = htonl(func);
req.address = htonl(ctrl);
if (linux_IO_Request(&req, &rsp) < 0) {
fprintf(LogFp, "bd_si_ctrl_rd Fatal error: Cannot get data!\n");
return -1;
}
if ((ntohl(rsp.code) & 0x1ff) != RSP_DATA) {
fprintf(LogFp, "bd_si_ctrl_rd Fatal error: rsp.code %d\n", ntohl(rsp.code));
return -1;
}
for(i=0; i*4<bytes && i<8; i++) {
u8 data[4];
#if BDSIDBG
fprintf(LogFp,"\nbd_si_ctrl_rd_pkd: rsp.data[%d]=%08x ntohl=%08x",i,rsp.data[i],ntohl(rsp.data[i]));
#endif
*((u32*)&data[0]) = ntohl(rsp.data[i]);
for(j=0; j<4 && i*4+j<bytes; j++) {
result[i*4+j] = data[j];
}
}
return 0;
}