devmgr.c
6.98 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/**************************************************************************
* *
* 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. *
* *
**************************************************************************/
/**************************************************************************
*
* Module: devicemgr.c
*
* $Revision: 1.1.1.2 $
* $Date: 2002/10/29 08:06:43 $
* $Author: blythe $
* $Source: /root/leakn64/depot/rf/sw/n64os20l/libultra/nintendo/pi/devmgr.c,v $
*
* Description:
* This file contains the main routine for a Device Manager (GDM).
*
**************************************************************************/
#include <os.h>
#include "osint.h"
#include "rcp.h"
#include "piint.h"
#include "leodrive.h"
#include "leoappli.h"
/*
* Name: __osDevMgrMain
*
* Description:
* This is the main loop for the device manager.
*
* Note:
* As a policy, all messages sent to the command queue are pointers to
* an I/O message block.
*
* Pseudo-code:
* // The idea here is to alternately listen between 2 message queues,
* // one for command and one for event notification.
* while always {
* Listen (w/ blocking) on input command queue
* Check for valid message type
* Decode message type
* Process message type (i.e., DMA ROM->DRAM)
* Listen (w/ blocking) on input event queue
* // Note that only registered event is sent to this queue
* Send message back to I/O requestor
* }
*
* Globals Referenced:
* None
*/
void
__osDevMgrMain(void *arg)
{
OSIoMesg *mb;
OSMesg em, dummy;
s32 ret;
OSDevMgr *dm;
s32 messageSend = 0;
dm = (OSDevMgr *)arg;
mb = NULL;
ret = 0;
while (1) {
/* We assume that all messages in this queue are pointers to
* I/O message blocks (OSIoMesg)
*/
(void)osRecvMesg(dm->cmdQueue, (OSMesg *)&mb, OS_MESG_BLOCK);
if ((mb->piHandle != NULL) &&
(mb->piHandle->type == DEVICE_TYPE_64DD) &&
((mb->piHandle->transferInfo.cmdType == OS_READ) ||
(mb->piHandle->transferInfo.cmdType == OS_WRITE))) {
__OSBlockInfo *blockInfo;
__OSTranxInfo *info;
/* prepare for Disk Dma */
info = &(mb->piHandle->transferInfo);
blockInfo = &(info->block[info->blockNum]);
info->sectorNum = -1;
if (info->transferMode != LEO_SECTOR_MODE)
blockInfo->dramAddr = (void *)
((u32)blockInfo->dramAddr - blockInfo->sectorSize);
if ((info->transferMode == LEO_TRACK_MODE) &&
(mb->piHandle->transferInfo.cmdType == OS_READ)){
messageSend = 1;
} else
messageSend = 0;
/* Block to get resource token */
(void)osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK);
/* Leo Disk, turn off PI interrupt during DMA */
__osResetGlobalIntMask(OS_IM_PI);
/* start sequencer */
__osEPiRawWriteIo(mb->piHandle, ASIC_BM_CTL,
(info->bmCtlShadow|START_BM));
readblock1:
/*
* Listen on the Event Queue
*/
(void)osRecvMesg(dm->evtQueue, &em, OS_MESG_BLOCK);
/*
* This signals an I/O completion (i.e., DMA request) from
* device. Device generates interrupt which is caught by
* the exception handler and sends us an event.
*/
/*
* Handle disk over run case
*/
info = &(mb->piHandle->transferInfo);
blockInfo = &(info->block[info->blockNum]);
if (blockInfo->errStatus == SC_OVERRUN_ERROR) {
u32 stat;
/* Stop_sequencer */
__osEPiRawWriteIo(mb->piHandle, ASIC_BM_CTL,
info->bmCtlShadow|BM_RESET);
__osEPiRawWriteIo(mb->piHandle, ASIC_BM_CTL,
info->bmCtlShadow);
/* clear CART interrupt */
__osEPiRawReadIo(mb->piHandle, ASIC_STATUS, &stat);
if (stat & LEO_STAT_MECHA_INT)
/* clear MECHA interrupt */
__osEPiRawWriteIo(mb->piHandle, ASIC_BM_CTL,
info->bmCtlShadow|BM_MECHA_INT_RESET);
blockInfo->errStatus = LEO_SENSE_DATA_PHASE_ERROR;
/* clear PI interrupt */
IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR);
/* Enable CART and PI interrupt */
__osSetGlobalIntMask(OS_IM_CART | OS_IM_PI);
}
/* Send I/O request message back to requestor */
osSendMesg(mb->hdr.retQueue, (OSMesg)mb, OS_MESG_NOBLOCK);
if ((messageSend == 1)
&& (mb->piHandle->transferInfo.block[0].errStatus == 0)) {
messageSend = 0;
goto readblock1;
}
/* Return resource token */
(void)osSendMesg(dm->acsQueue, (OSMesg)0, OS_MESG_NOBLOCK);
/*
* Yield the PI manager at the end of block1 DMA.
* So, command thread can issue seek command before
* PI manager serve next PI DMA.
*/
if (mb->piHandle->transferInfo.blockNum == 1)
osYieldThread();
} else {
switch (mb->hdr.type) {
case OS_MESG_TYPE_DMAREAD: {
/* Block to get resource token */
(void)osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK);
ret = dm->dma(OS_READ, mb->devAddr, mb->dramAddr,
mb->size);
break;
}
case OS_MESG_TYPE_DMAWRITE: {
/* Block to get resource token */
(void)osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK);
ret = dm->dma(OS_WRITE, mb->devAddr, mb->dramAddr,
mb->size);
break;
}
case OS_MESG_TYPE_EDMAREAD: {
/* Block to get resource token */
(void)osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK);
ret = dm->edma(mb->piHandle, OS_READ, mb->devAddr,
mb->dramAddr, mb->size);
break;
}
case OS_MESG_TYPE_EDMAWRITE: {
/* Block to get resource token */
(void)osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK);
ret = dm->edma(mb->piHandle, OS_WRITE, mb->devAddr,
mb->dramAddr, mb->size);
break;
}
case OS_MESG_TYPE_LOOPBACK: {
/* Special message type to loopback to caller */
(void)osSendMesg(mb->hdr.retQueue, (OSMesg)mb,
OS_MESG_NOBLOCK);
ret = -1;
break;
}
default: { /* NOT REACHED */
ret = -1;
break;
}
}
if (ret == 0) {
/*
* Listen on the Event Queue
*/
(void)osRecvMesg(dm->evtQueue, &em, OS_MESG_BLOCK);
/*
* This signals an I/O completion (i.e., DMA request)
* from device. Device generates interrupt which
* is caught by the exception handler and sends us
* an event.
*/
/* Send I/O request message back to requestor */
osSendMesg(mb->hdr.retQueue, (OSMesg)mb,
OS_MESG_NOBLOCK);
/* Return resource token */
(void)osSendMesg(dm->acsQueue, (OSMesg)0, OS_MESG_NOBLOCK);
} /* if */
}
} /* while */
} /* __osDevMgrMain */