conteepwrite.c
5.33 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/**************************************************************************
* *
* Copyright (C) 1995, Silicon Graphics, Inc. *
* *
* These coded instructions, statements, and computer programs contain *
* unpublished proprietary information of Silicon Graphics, Inc., and *
* are protected by Federal copyright law. They may not be disclosed *
* to third parties or copied or duplicated in any form, in whole or *
* in part, without the prior written consent of Silicon Graphics, Inc. *
* *
**************************************************************************/
#include "osint.h"
#include "controller.h"
#include "siint.h"
static void __osPackEepWriteData(u8, u8 *);
/*
* This call issues a write eeprom command to pif to write
* 8 bytes to eeprom.
* A value of 0 is returned if the calls succeed, otherwise
* -1 is returned
*/
s32
osEepromWrite(OSMesgQueue *mq, u8 address, u8 *buffer)
{
s32 ret = 0;
u16 type;
u8 *ptr = (u8 *)(&__osEepPifRam);
__OSContEepromFormat eepromformat;
OSContStatus sdata;
u8 temp[8];
/* Block to get resource token */
__osSiGetAccess();
/* Need to make sure EEPROM is not busy before write */
ret = __osEepStatus(mq, &sdata);
type = (u16)(sdata.type & (u16)(CONT_EEPROM | CONT_EEP16K));
if (ret == 0) {
switch(type) {
case (u16)CONT_EEPROM :
if(address >= EEPROM_MAXBLOCKS) {
ret = -1;
}
break;
case (u16)(CONT_EEPROM | CONT_EEP16K) :
if(address >= EEP16K_MAXBLOCKS) {
ret = -1;
} else if (__osEepromRead16K != 0) {
/* dummy read for EEPROM-16K bug */
__osEepromRead16K = 0;
__osSiRelAccess();
osEepromRead(mq, (address^1), temp);
__osSiGetAccess();
}
break;
default:
ret = CONT_NO_RESPONSE_ERROR;
}
}
if (ret != 0) {
__osSiRelAccess();
return(ret);
}
while (sdata.status & CONT_EEPROM_BUSY) {
__osEepStatus(mq, &sdata);
}
/* Set up request command format for eeprom */
__osPackEepWriteData(address, buffer);
ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam);
(void)osRecvMesg(mq, (OSMesg *)NULL, OS_MESG_BLOCK);
/* trigger pifmacro */
ret = __osSiRawStartDma(OS_READ, &__osEepPifRam);
__osContLastCmd = CONT_EEPROM_WRITE;
(void)osRecvMesg(mq, (OSMesg *)NULL, OS_MESG_BLOCK);
ptr += MAXCONTROLLERS;
eepromformat = *((__OSContEepromFormat *)ptr);
#ifndef _HW_VERSION_1
ret = (s32)((eepromformat.rxsize & CON_ERR_MASK) >> 4);
#endif
__osSiRelAccess();
return(ret);
}
static void
__osPackEepWriteData(u8 address, u8* buffer)
{
u8 *ptr = (u8 *)(&__osEepPifRam);
__OSContEepromFormat eepromformat;
int i;
/* clear pif ram */
#if 0
for (i = 0; i < PIFRAMSIZE-1 ; i++)
__osEepPifRam.ramarray[i] = 0xff;
#endif
#ifndef _HW_VERSION_1
__osEepPifRam.pifstatus = CONT_FORMAT;
#else
__osEepPifRam.pifstatus = 0;
#endif
/* Setup eeprom format */
eepromformat.txsize = 10;
eepromformat.rxsize = 1;
eepromformat.cmd = CONT_EEPROM_WRITE;
eepromformat.address = address;
for (i = 0; i < EEPROM_BLOCK_SIZE ; i++)
eepromformat.data[i] = *buffer++;
for (i = 0; i < MAXCONTROLLERS; i++)
*ptr++ = 0;
*((__OSContEepromFormat *)ptr) = eepromformat;
#ifndef _HW_VERSION_1
ptr += sizeof(eepromformat);
*((u8 *)ptr) = FORMAT_END;
#endif
}
s32
__osEepStatus(OSMesgQueue *mq, OSContStatus *data)
{
s32 ret = 0;
int i;
u8 *ptr = (u8 *)(&__osEepPifRam);
__OSContRequesFormat requestformat;
/* Set up request command format for channel 5 */
for (i = 0; i < PIFRAMSIZE ; i++)
__osEepPifRam.ramarray[i] = 0;
#ifndef _HW_VERSION_1
__osEepPifRam.pifstatus = CONT_FORMAT;
#else
__osEepPifRam.pifstatus = 0;
#endif
ptr = (u8 *)(&__osEepPifRam);
for (i = 0; i < MAXCONTROLLERS; i++)
*ptr++ = 0;
requestformat.dummy = 0xff;
requestformat.txsize = 1;
requestformat.rxsize = 3;
requestformat.cmd = CONT_REQUEST;
requestformat.typeh = 0xff;
requestformat.typel = 0xff;
requestformat.status = 0xff;
requestformat.dummy1 = 0xff;
*((__OSContRequesFormat *)ptr) = requestformat;
ptr += sizeof(requestformat);
#ifndef _HW_VERSION_1
*((u8 *)ptr) = FORMAT_END;
#endif
ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam);
(void)osRecvMesg(mq, (OSMesg *)NULL, OS_MESG_BLOCK);
__osContLastCmd = CONT_ETC; /* NOT CONT_REQUEST!! */
/* trigger pifmacro */
ret = __osSiRawStartDma(OS_READ, &__osEepPifRam);
(void)osRecvMesg(mq, (OSMesg *)NULL, OS_MESG_BLOCK);
if (ret)
return(ret);
/* Reformat the 64 bytes RAM data into RequestData format */
ptr = (u8 *)(&__osEepPifRam);
for (i = 0; i < MAXCONTROLLERS; i++)
*ptr++ = 0;
requestformat = *((__OSContRequesFormat *)ptr);
#ifndef _HW_VERSION_1
data->errno = (u8)((requestformat.rxsize & CON_ERR_MASK) >> 4);
#else
data->errno = (u8)(((requestformat.txsize & CON_ERR_MASK) >> 4)
| ((requestformat.rxsize & CON_ERR_MASK) >> 6));
#endif
data->type =(u16)((requestformat.typel<<8)|requestformat.typeh);
data->status = requestformat.status;
if (data->errno)
return((s32)(data->errno));
return(0);
}