ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/AmigaOS/scsi_amiga.cpp
(Generate patch)

Comparing BasiliskII/src/AmigaOS/scsi_amiga.cpp (file contents):
Revision 1.6 by cebix, 2002-01-15T14:58:34Z vs.
Revision 1.8 by cebix, 2002-09-01T12:01:46Z

# Line 1 | Line 1
1   /*
2   *  scsi_amiga.cpp - SCSI Manager, Amiga specific stuff
3   *
4 < *  Basilisk II (C) 1997-2002 Christian Bauer
4 > *  Basilisk II (C) 1997-2001 Christian Bauer
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 22 | Line 22
22   #include <exec/memory.h>
23   #include <devices/trackdisk.h>
24   #include <devices/scsidisk.h>
25 + #define __USE_SYSBASE
26   #include <proto/exec.h>
27 + #include <inline/exec.h>
28  
29   #include "sysdeps.h"
30   #include "main.h"
# Line 51 | Line 53 | static UBYTE cmd_buffer[12];                   // Buffer
53   const int SENSE_LENGTH = 256;
54   static UBYTE *sense_buffer = NULL;              // Buffer for autosense data
55  
56 + static bool direct_transfers_supported = false; // Direct data transfers (bypassing the buffer) are supported
57 +
58  
59   /*
60   *  Initialization
# Line 67 | Line 71 | void SCSIInit(void)
71                          break;
72                  case 2:
73                          buffer_memf = MEMF_ANY | MEMF_PUBLIC;
74 +                        direct_transfers_supported = true;
75                          break;
76                  default:
77                          buffer_memf = MEMF_CHIP | MEMF_PUBLIC;
# Line 97 | Line 102 | void SCSIInit(void)
102                                          struct IOStdReq *io = (struct IOStdReq *)CreateIORequest(the_port, sizeof(struct IOStdReq));
103                                          if (io == NULL)
104                                                  continue;
105 <                                        if (OpenDevice((UBYTE *)dev_name, dev_unit + lun * 10, (struct IORequest *)io, 0)) {
105 >                                        if (OpenDevice((UBYTE *) dev_name, dev_unit + lun * 10, (struct IORequest *)io, 0)) {
106                                                  DeleteIORequest(io);
107                                                  continue;
108                                          }
# Line 210 | Line 215 | bool scsi_set_target(int id, int lun)
215  
216   bool scsi_send_cmd(size_t data_length, bool reading, int sg_size, uint8 **sg_ptr, uint32 *sg_len, uint16 *stat, uint32 timeout)
217   {
218 <        // Check if buffer is large enough, allocate new buffer if needed
219 <        if (!try_buffer(data_length)) {
220 <                char str[256];
221 <                sprintf(str, GetString(STR_SCSI_BUFFER_ERR), data_length);
222 <                ErrorAlert(str);
223 <                return false;
224 <        }
218 >        // Bypass the buffer if there's only one S/G table entry
219 >        bool do_direct_transfer = (sg_size == 1 && ((uint32)sg_ptr[0] & 1) == 0 && direct_transfers_supported);
220 >
221 >        if (!do_direct_transfer) {
222 >
223 >                // Check if buffer is large enough, allocate new buffer if needed
224 >                if (!try_buffer(data_length)) {
225 >                        char str[256];
226 >                        sprintf(str, GetString(STR_SCSI_BUFFER_ERR), data_length);
227 >                        ErrorAlert(str);
228 >                        return false;
229 >                }
230  
231 <        // Process S/G table when writing
232 <        if (!reading) {
233 <                D(bug(" writing to buffer\n"));
234 <                uint8 *buffer_ptr = buffer;
235 <                for (int i=0; i<sg_size; i++) {
236 <                        uint32 len = sg_len[i];
237 <                        D(bug("  %d bytes from %08lx\n", len, sg_ptr[i]));
238 <                        memcpy(buffer_ptr, sg_ptr[i], len);
239 <                        buffer_ptr += len;
231 >                // Process S/G table when writing
232 >                if (!reading) {
233 >                        D(bug(" writing to buffer\n"));
234 >                        uint8 *buffer_ptr = buffer;
235 >                        for (int i=0; i<sg_size; i++) {
236 >                                uint32 len = sg_len[i];
237 >                                D(bug("  %d bytes from %08lx\n", len, sg_ptr[i]));
238 >                                memcpy(buffer_ptr, sg_ptr[i], len);
239 >                                buffer_ptr += len;
240 >                        }
241                  }
242          }
243  
# Line 238 | Line 249 | bool scsi_send_cmd(size_t data_length, b
249                  D(bug(" autosense\n"));
250                  memcpy(buffer, sense_buffer, scsi.scsi_SenseActual);
251                  scsi.scsi_Status = 0;
252 +                do_direct_transfer = false;
253  
254          } else {
255  
256                  // No, send regular command
257                  D(bug(" sending command, length %ld\n", data_length));
258 <                scsi.scsi_Data = (UWORD *)buffer;
259 <                scsi.scsi_Length = data_length;
258 >                if (do_direct_transfer) {
259 >                        scsi.scsi_Data = (UWORD *)sg_ptr[0];
260 >                        scsi.scsi_Length = sg_len[0];
261 >                } else {
262 >                        scsi.scsi_Data = (UWORD *)buffer;
263 >                        scsi.scsi_Length = data_length;
264 >                }
265                  scsi.scsi_Actual = 0;
266                  scsi.scsi_Flags = (reading ? SCSIF_READ : SCSIF_WRITE) | SCSIF_AUTOSENSE;
267                  scsi.scsi_SenseActual = 0;
# Line 254 | Line 271 | bool scsi_send_cmd(size_t data_length, b
271                  *stat = scsi.scsi_Status;
272          }
273  
274 <        // Process S/G table when reading
275 <        if (reading && res == 0) {
276 <                D(bug(" reading from buffer\n"));
277 <                uint8 *buffer_ptr = buffer;
278 <                for (int i=0; i<sg_size; i++) {
279 <                        uint32 len = sg_len[i];
280 <                        D(bug("  %d bytes to %08lx\n", len, sg_ptr[i]));
281 <                        memcpy(sg_ptr[i], buffer_ptr, len);
282 <                        buffer_ptr += len;
274 >        if (!do_direct_transfer) {
275 >
276 >                // Process S/G table when reading
277 >                if (reading && res == 0) {
278 >                        D(bug(" reading from buffer\n"));
279 >                        uint8 *buffer_ptr = buffer;
280 >                        for (int i=0; i<sg_size; i++) {
281 >                                uint32 len = sg_len[i];
282 >                                D(bug("  %d bytes to %08lx\n", len, sg_ptr[i]));
283 >                                memcpy(sg_ptr[i], buffer_ptr, len);
284 >                                buffer_ptr += len;
285 >                        }
286                  }
287          }
288          return res == 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines