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.1.1.1 by cebix, 1999-10-03T14:16:25Z vs.
Revision 1.9 by gbeauche, 2008-01-01T09:40:31Z

# Line 1 | Line 1
1   /*
2   *  scsi_amiga.cpp - SCSI Manager, Amiga specific stuff
3   *
4 < *  Basilisk II (C) 1997-1999 Christian Bauer
4 > *  Basilisk II (C) 1997-2008 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 44 | Line 46 | static struct MsgPort *the_port = NULL;
46  
47   static ULONG buffer_size;                               // Size of data buffer
48   static UBYTE *buffer = NULL;                    // Pointer to data buffer
49 + static ULONG buffer_memf;                               // Buffer memory flags
50  
51   static UBYTE cmd_buffer[12];                    // Buffer for SCSI command
52  
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 59 | Line 64 | void SCSIInit(void)
64   {
65          int id, lun;
66  
67 +        int memtype = PrefsFindInt32("scsimemtype");
68 +        switch (memtype) {
69 +                case 1:
70 +                        buffer_memf = MEMF_24BITDMA | MEMF_PUBLIC;
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;
78 +                        break;
79 +        }
80 +
81          // Create port and buffers
82          the_port = CreateMsgPort();
83 <        buffer = (UBYTE *)AllocMem(buffer_size = 0x10000, MEMF_CHIP | MEMF_PUBLIC);
83 >        buffer = (UBYTE *)AllocMem(buffer_size = 0x10000, buffer_memf);
84          sense_buffer = (UBYTE *)AllocMem(SENSE_LENGTH, MEMF_CHIP | MEMF_PUBLIC);
85          if (the_port == NULL || buffer == NULL || sense_buffer == NULL) {
86 <                ErrorAlert(GetString(STR_NO_MEM_ERR));
86 >                ErrorAlert(STR_NO_MEM_ERR);
87                  QuitEmulator();
88          }
89  
# Line 83 | 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 142 | Line 161 | static bool try_buffer(int size)
161          if (size <= buffer_size)
162                  return true;
163  
164 <        UBYTE *new_buffer = (UBYTE *)AllocMem(size, MEMF_CHIP | MEMF_PUBLIC);
164 >        UBYTE *new_buffer = (UBYTE *)AllocMem(size, buffer_memf);
165          if (new_buffer == NULL)
166                  return false;
167          FreeMem(buffer, buffer_size);
# Line 196 | 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);
203 <                ErrorAlert(str);
204 <                return false;
205 <        }
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 <        // Process S/G table when writing
224 <        if (!reading) {
225 <                D(bug(" writing to buffer\n"));
226 <                uint8 *buffer_ptr = buffer;
227 <                for (int i=0; i<sg_size; i++) {
228 <                        uint32 len = sg_len[i];
229 <                        D(bug("  %d bytes from %08lx\n", len, sg_ptr[i]));
230 <                        memcpy(buffer_ptr, sg_ptr[i], len);
231 <                        buffer_ptr += len;
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;
240 >                        }
241                  }
242          }
243  
# Line 224 | 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 240 | 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 (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