VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS/scsi.c@ 81851

Last change on this file since 81851 was 81412, checked in by vboxsync, 5 years ago

PC/BIOS: Move the generic SCSI definitions out of scsi.c into a separate header

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.5 KB
Line 
1/* $Id: scsi.c 81412 2019-10-21 13:29:39Z vboxsync $ */
2/** @file
3 * SCSI host adapter driver to boot from SCSI disks
4 */
5
6/*
7 * Copyright (C) 2004-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include <stdint.h>
19#include <string.h>
20#include "biosint.h"
21#include "inlines.h"
22#include "pciutil.h"
23#include "ebda.h"
24#include "scsi.h"
25
26
27#if DEBUG_SCSI
28# define DBG_SCSI(...) BX_INFO(__VA_ARGS__)
29#else
30# define DBG_SCSI(...)
31#endif
32
33#define VBSCSI_BUSY (1 << 0)
34#define VBSCSI_ERROR (1 << 1)
35
36/* The I/O port of the BusLogic SCSI adapter. */
37#define BUSLOGIC_BIOS_IO_PORT 0x430
38/* The I/O port of the LsiLogic SCSI adapter. */
39#define LSILOGIC_BIOS_IO_PORT 0x434
40/* The I/O port of the LsiLogic SAS adapter. */
41#define LSILOGIC_SAS_BIOS_IO_PORT 0x438
42
43#define VBSCSI_REGISTER_STATUS 0
44#define VBSCSI_REGISTER_COMMAND 0
45#define VBSCSI_REGISTER_DATA_IN 1
46#define VBSCSI_REGISTER_IDENTIFY 2
47#define VBSCSI_REGISTER_RESET 3
48#define VBSCSI_REGISTER_DEVSTAT 3
49
50#define VBSCSI_MAX_DEVICES 16 /* Maximum number of devices a SCSI device can have. */
51
52/* Data transfer direction. */
53#define SCSI_TXDIR_FROM_DEVICE 0
54#define SCSI_TXDIR_TO_DEVICE 1
55
56#pragma pack(1)
57
58/* READ_10/WRITE_10 CDB layout. */
59typedef struct {
60 uint16_t command; /* Command. */
61 uint32_t lba; /* LBA, MSB first! */
62 uint8_t pad1; /* Unused. */
63 uint16_t nsect; /* Sector count, MSB first! */
64 uint8_t pad2; /* Unused. */
65} cdb_rw10;
66
67/* READ_16/WRITE_16 CDB layout. */
68typedef struct {
69 uint16_t command; /* Command. */
70 uint64_t lba; /* LBA, MSB first! */
71 uint32_t nsect32; /* Sector count, MSB first! */
72 uint8_t pad1; /* Unused. */
73 uint8_t pad2; /* Unused. */
74} cdb_rw16;
75
76#pragma pack()
77
78ct_assert(sizeof(cdb_rw10) == 10);
79ct_assert(sizeof(cdb_rw16) == 16);
80
81void insb_discard(unsigned nbytes, unsigned port);
82#pragma aux insb_discard = \
83 ".286" \
84 "again:" \
85 "in al,dx" \
86 "loop again" \
87 parm [cx] [dx] modify exact [cx ax] nomemory;
88
89
90int scsi_cmd_data_in(uint16_t io_base, uint8_t target_id, uint8_t __far *aCDB,
91 uint8_t cbCDB, uint8_t __far *buffer, uint32_t length)
92{
93 /* Check that the adapter is ready. */
94 uint8_t status, sizes;
95 uint16_t i;
96
97 do
98 status = inb(io_base + VBSCSI_REGISTER_STATUS);
99 while (status & VBSCSI_BUSY);
100
101 sizes = ((length >> 12) & 0xF0) | ((cbCDB == 16) ? 0 : cbCDB);
102 outb(io_base + VBSCSI_REGISTER_COMMAND, target_id); /* Write the target ID. */
103 outb(io_base + VBSCSI_REGISTER_COMMAND, SCSI_TXDIR_FROM_DEVICE); /* Write the transfer direction. */
104 outb(io_base + VBSCSI_REGISTER_COMMAND, sizes); /* Write CDB size and top bufsize bits. */
105 outb(io_base + VBSCSI_REGISTER_COMMAND, length); /* Write the buffer size. */
106 outb(io_base + VBSCSI_REGISTER_COMMAND, (length >> 8));
107 for (i = 0; i < cbCDB; i++) /* Write the CDB. */
108 outb(io_base + VBSCSI_REGISTER_COMMAND, aCDB[i]);
109
110 /* Now wait for the command to complete. */
111 do
112 status = inb(io_base + VBSCSI_REGISTER_STATUS);
113 while (status & VBSCSI_BUSY);
114
115 /* If any error occurred, inform the caller and don't bother reading the data. */
116 if (status & VBSCSI_ERROR) {
117 outb(io_base + VBSCSI_REGISTER_RESET, 0);
118
119 status = inb(io_base + VBSCSI_REGISTER_DEVSTAT);
120 DBG_SCSI("%s: read failed, device status %02X\n", __func__, status);
121 return 4; /* Sector not found */
122 }
123
124 /* Read in the data. The transfer length may be exactly 64K or more,
125 * which needs a bit of care when we're using 16-bit 'rep ins'.
126 */
127 while (length > 32768) {
128 DBG_SCSI("%s: reading 32K to %X:%X\n", __func__, FP_SEG(buffer), FP_OFF(buffer));
129 rep_insb(buffer, 32768, io_base + VBSCSI_REGISTER_DATA_IN);
130 length -= 32768;
131 buffer = (FP_SEG(buffer) + (32768 >> 4)) :> FP_OFF(buffer);
132 }
133
134 DBG_SCSI("%s: reading %ld bytes to %X:%X\n", __func__, length, FP_SEG(buffer), FP_OFF(buffer));
135 rep_insb(buffer, length, io_base + VBSCSI_REGISTER_DATA_IN);
136
137 return 0;
138}
139
140int scsi_cmd_data_out(uint16_t io_base, uint8_t target_id, uint8_t __far *aCDB,
141 uint8_t cbCDB, uint8_t __far *buffer, uint32_t length)
142{
143 /* Check that the adapter is ready. */
144 uint8_t status, sizes;
145 uint16_t i;
146
147 do
148 status = inb(io_base + VBSCSI_REGISTER_STATUS);
149 while (status & VBSCSI_BUSY);
150
151
152 sizes = ((length >> 12) & 0xF0) | ((cbCDB == 16) ? 0 : cbCDB);
153 outb(io_base + VBSCSI_REGISTER_COMMAND, target_id); /* Write the target ID. */
154 outb(io_base + VBSCSI_REGISTER_COMMAND, SCSI_TXDIR_TO_DEVICE); /* Write the transfer direction. */
155 outb(io_base + VBSCSI_REGISTER_COMMAND, sizes); /* Write CDB size and top bufsize bits. */
156 outb(io_base + VBSCSI_REGISTER_COMMAND, length); /* Write the buffer size. */
157 outb(io_base + VBSCSI_REGISTER_COMMAND, (length >> 8));
158 for (i = 0; i < cbCDB; i++) /* Write the CDB. */
159 outb(io_base + VBSCSI_REGISTER_COMMAND, aCDB[i]);
160
161 /* Write out the data. The transfer length may be exactly 64K or more,
162 * which needs a bit of care when we're using 16-bit 'rep outs'.
163 */
164 while (length > 32768) {
165 DBG_SCSI("%s: writing 32K from %X:%X\n", __func__, FP_SEG(buffer), FP_OFF(buffer));
166 rep_outsb(buffer, 32768, io_base + VBSCSI_REGISTER_DATA_IN);
167 length -= 32768;
168 buffer = (FP_SEG(buffer) + (32768 >> 4)) :> FP_OFF(buffer);
169 }
170
171 DBG_SCSI("%s: writing %ld bytes from %X:%X\n", __func__, length, FP_SEG(buffer), FP_OFF(buffer));
172 rep_outsb(buffer, length, io_base + VBSCSI_REGISTER_DATA_IN);
173
174 /* Now wait for the command to complete. */
175 do
176 status = inb(io_base + VBSCSI_REGISTER_STATUS);
177 while (status & VBSCSI_BUSY);
178
179 /* If any error occurred, inform the caller. */
180 if (status & VBSCSI_ERROR) {
181 outb(io_base + VBSCSI_REGISTER_RESET, 0);
182
183 status = inb(io_base + VBSCSI_REGISTER_DEVSTAT);
184 DBG_SCSI("%s: write failed, device status %02X\n", __func__, status);
185 return 4; /* Sector not found */
186 }
187
188 return 0;
189}
190
191/**
192 * Read sectors from an attached SCSI device.
193 *
194 * @returns status code.
195 * @param bios_dsk Pointer to disk request packet (in the
196 * EBDA).
197 */
198int scsi_read_sectors(bio_dsk_t __far *bios_dsk)
199{
200 uint8_t rc;
201 cdb_rw16 cdb;
202 uint32_t count;
203 uint16_t io_base;
204 uint8_t target_id;
205 uint8_t device_id;
206
207 device_id = VBOX_GET_SCSI_DEVICE(bios_dsk->drqp.dev_id);
208 if (device_id > BX_MAX_SCSI_DEVICES)
209 BX_PANIC("%s: device_id out of range %d\n", __func__, device_id);
210
211 count = bios_dsk->drqp.nsect;
212
213 /* Prepare a CDB. */
214 cdb.command = SCSI_READ_16;
215 cdb.lba = swap_64(bios_dsk->drqp.lba);
216 cdb.pad1 = 0;
217 cdb.nsect32 = swap_32(count);
218 cdb.pad2 = 0;
219
220
221 io_base = bios_dsk->scsidev[device_id].io_base;
222 target_id = bios_dsk->scsidev[device_id].target_id;
223
224 DBG_SCSI("%s: reading %u sectors, device %d, target %d\n", __func__,
225 count, device_id, bios_dsk->scsidev[device_id].target_id);
226
227 rc = scsi_cmd_data_in(io_base, target_id, (void __far *)&cdb, 16,
228 bios_dsk->drqp.buffer, (count * 512L));
229
230 if (!rc)
231 {
232 bios_dsk->drqp.trsfsectors = count;
233 bios_dsk->drqp.trsfbytes = count * 512L;
234 }
235 DBG_SCSI("%s: transferred %u sectors\n", __func__, bios_dsk->drqp.nsect);
236
237 return rc;
238}
239
240/**
241 * Write sectors to an attached SCSI device.
242 *
243 * @returns status code.
244 * @param bios_dsk Pointer to disk request packet (in the
245 * EBDA).
246 */
247int scsi_write_sectors(bio_dsk_t __far *bios_dsk)
248{
249 uint8_t rc;
250 cdb_rw16 cdb;
251 uint32_t count;
252 uint16_t io_base;
253 uint8_t target_id;
254 uint8_t device_id;
255
256 device_id = VBOX_GET_SCSI_DEVICE(bios_dsk->drqp.dev_id);
257 if (device_id > BX_MAX_SCSI_DEVICES)
258 BX_PANIC("%s: device_id out of range %d\n", __func__, device_id);
259
260 count = bios_dsk->drqp.nsect;
261
262 /* Prepare a CDB. */
263 cdb.command = SCSI_WRITE_16;
264 cdb.lba = swap_64(bios_dsk->drqp.lba);
265 cdb.pad1 = 0;
266 cdb.nsect32 = swap_32(count);
267 cdb.pad2 = 0;
268
269 io_base = bios_dsk->scsidev[device_id].io_base;
270 target_id = bios_dsk->scsidev[device_id].target_id;
271
272 DBG_SCSI("%s: writing %u sectors, device %d, target %d\n", __func__,
273 count, device_id, bios_dsk->scsidev[device_id].target_id);
274
275 rc = scsi_cmd_data_out(io_base, target_id, (void __far *)&cdb, 16,
276 bios_dsk->drqp.buffer, (count * 512L));
277
278 if (!rc)
279 {
280 bios_dsk->drqp.trsfsectors = count;
281 bios_dsk->drqp.trsfbytes = (count * 512L);
282 }
283 DBG_SCSI("%s: transferred %u sectors\n", __func__, bios_dsk->drqp.nsect);
284
285 return rc;
286}
287
288
289/// @todo move
290#define ATA_DATA_NO 0x00
291#define ATA_DATA_IN 0x01
292#define ATA_DATA_OUT 0x02
293
294/**
295 * Perform a "packet style" read with supplied CDB.
296 *
297 * @returns status code.
298 * @param device_id ID of the device to access.
299 * @param cmdlen Length of the CDB.
300 * @param cmdbuf The CDB buffer.
301 * @param before How much to skip before reading into the provided data buffer.
302 * @param length How much to transfer.
303 * @param inout Read/Write direction indicator.
304 * @param buffer Data buffer to store the data from the device in.
305 */
306uint16_t scsi_cmd_packet(uint16_t device_id, uint8_t cmdlen, char __far *cmdbuf,
307 uint16_t before, uint32_t length, uint8_t inout, char __far *buffer)
308{
309 bio_dsk_t __far *bios_dsk = read_word(0x0040, 0x000E) :> &EbdaData->bdisk;
310 uint32_t read_len;
311 uint8_t status, sizes;
312 uint16_t i;
313 uint16_t io_base;
314 uint8_t target_id;
315
316 /* Data out is currently not supported. */
317 if (inout == ATA_DATA_OUT) {
318 BX_INFO("%s: DATA_OUT not supported yet\n", __func__);
319 return 1;
320 }
321
322 /* Convert to SCSI specific device number. */
323 device_id = VBOX_GET_SCSI_DEVICE(device_id);
324
325 DBG_SCSI("%s: reading %lu bytes, skip %u/%u, device %d, target %d\n", __func__,
326 length, bios_dsk->drqp.skip_b, bios_dsk->drqp.skip_a,
327 device_id, bios_dsk->scsidev[device_id].target_id);
328 DBG_SCSI("%s: reading %u %u-byte sectors\n", __func__,
329 bios_dsk->drqp.nsect, bios_dsk->drqp.sect_sz);
330
331 cmdlen -= 2; /* ATAPI uses 12-byte command packets for a READ 10. */
332
333 io_base = bios_dsk->scsidev[device_id].io_base;
334 target_id = bios_dsk->scsidev[device_id].target_id;
335
336 /* Wait until the adapter is ready. */
337 do
338 status = inb(io_base + VBSCSI_REGISTER_STATUS);
339 while (status & VBSCSI_BUSY);
340
341 /* On the SCSI level, we have to transfer whole sectors. */
342 /* NB: With proper residual length support, this should not be necessary; we should
343 * be able to avoid transferring the 'after' part of the sector.
344 */
345 read_len = length + before + bios_dsk->drqp.skip_a;
346
347 sizes = (((read_len) >> 12) & 0xF0) | cmdlen;
348 outb(io_base + VBSCSI_REGISTER_COMMAND, target_id); /* Write the target ID. */
349 outb(io_base + VBSCSI_REGISTER_COMMAND, SCSI_TXDIR_FROM_DEVICE); /* Write the transfer direction. */
350 outb(io_base + VBSCSI_REGISTER_COMMAND, sizes); /* Write the CDB size. */
351 outb(io_base + VBSCSI_REGISTER_COMMAND, read_len); /* Write the buffer size. */
352 outb(io_base + VBSCSI_REGISTER_COMMAND, (read_len) >> 8);
353 for (i = 0; i < cmdlen; i++) /* Write the CDB. */
354 outb(io_base + VBSCSI_REGISTER_COMMAND, cmdbuf[i]);
355
356 /* Now wait for the command to complete. */
357 do
358 status = inb(io_base + VBSCSI_REGISTER_STATUS);
359 while (status & VBSCSI_BUSY);
360
361 /* If any error occurred, inform the caller and don't bother reading the data. */
362 if (status & VBSCSI_ERROR) {
363 outb(io_base + VBSCSI_REGISTER_RESET, 0);
364
365 status = inb(io_base + VBSCSI_REGISTER_DEVSTAT);
366 DBG_SCSI("%s: read failed, device status %02X\n", __func__, status);
367 return 3;
368 }
369
370 /* Transfer the data read from the device. */
371
372 if (before) /* If necessary, throw away data which needs to be skipped. */
373 insb_discard(before, io_base + VBSCSI_REGISTER_DATA_IN);
374
375 bios_dsk->drqp.trsfbytes = length;
376
377 /* The requested length may be exactly 64K or more, which needs
378 * a bit of care when we're using 16-bit 'rep ins'.
379 */
380 while (length > 32768) {
381 DBG_SCSI("%s: reading 32K to %X:%X\n", __func__, FP_SEG(buffer), FP_OFF(buffer));
382 rep_insb(buffer, 32768, io_base + VBSCSI_REGISTER_DATA_IN);
383 length -= 32768;
384 buffer = (FP_SEG(buffer) + (32768 >> 4)) :> FP_OFF(buffer);
385 }
386
387 DBG_SCSI("%s: reading %ld bytes to %X:%X\n", __func__, length, FP_SEG(buffer), FP_OFF(buffer));
388 rep_insb(buffer, length, io_base + VBSCSI_REGISTER_DATA_IN);
389
390 if (bios_dsk->drqp.skip_a) /* If necessary, throw away more data. */
391 insb_discard(bios_dsk->drqp.skip_a, io_base + VBSCSI_REGISTER_DATA_IN);
392
393 return 0;
394}
395
396/**
397 * Enumerate attached devices.
398 *
399 * @returns nothing.
400 * @param io_base The I/O base port of the controller.
401 */
402void scsi_enumerate_attached_devices(uint16_t io_base)
403{
404 int i;
405 uint8_t buffer[0x0200];
406 bio_dsk_t __far *bios_dsk;
407
408 bios_dsk = read_word(0x0040, 0x000E) :> &EbdaData->bdisk;
409
410 /* Go through target devices. */
411 for (i = 0; i < VBSCSI_MAX_DEVICES; i++)
412 {
413 uint8_t rc;
414 uint8_t aCDB[16];
415 uint8_t hd_index, devcount_scsi;
416
417 aCDB[0] = SCSI_INQUIRY;
418 aCDB[1] = 0;
419 aCDB[2] = 0;
420 aCDB[3] = 0;
421 aCDB[4] = 5; /* Allocation length. */
422 aCDB[5] = 0;
423
424 rc = scsi_cmd_data_in(io_base, i, aCDB, 6, buffer, 5);
425 if (rc != 0)
426 BX_PANIC("%s: SCSI_INQUIRY failed\n", __func__);
427
428 devcount_scsi = bios_dsk->scsi_devcount;
429
430 /* Check the attached device. */
431 if ( ((buffer[0] & 0xe0) == 0)
432 && ((buffer[0] & 0x1f) == 0x00))
433 {
434 DBG_SCSI("%s: Disk detected at %d\n", __func__, i);
435
436 /* We add the disk only if the maximum is not reached yet. */
437 if (devcount_scsi < BX_MAX_SCSI_DEVICES)
438 {
439 uint64_t sectors, t;
440 uint32_t sector_size, cylinders;
441 uint16_t heads, sectors_per_track;
442 uint8_t hdcount;
443 uint8_t cmos_base;
444
445 /* Issue a read capacity command now. */
446 _fmemset(aCDB, 0, sizeof(aCDB));
447 aCDB[0] = SCSI_SERVICE_ACT;
448 aCDB[1] = SCSI_READ_CAP_16;
449 aCDB[13] = 32; /* Allocation length. */
450
451 rc = scsi_cmd_data_in(io_base, i, aCDB, 16, buffer, 32);
452 if (rc != 0)
453 BX_PANIC("%s: SCSI_READ_CAPACITY failed\n", __func__);
454
455 /* The value returned is the last addressable LBA, not
456 * the size, which what "+ 1" is for.
457 */
458 sectors = swap_64(*(uint64_t *)buffer) + 1;
459
460 sector_size = ((uint32_t)buffer[8] << 24)
461 | ((uint32_t)buffer[9] << 16)
462 | ((uint32_t)buffer[10] << 8)
463 | ((uint32_t)buffer[11]);
464
465 /* We only support the disk if sector size is 512 bytes. */
466 if (sector_size != 512)
467 {
468 /* Leave a log entry. */
469 BX_INFO("Disk %d has an unsupported sector size of %u\n", i, sector_size);
470 continue;
471 }
472
473 /* Get logical CHS geometry. */
474 switch (devcount_scsi)
475 {
476 case 0:
477 cmos_base = 0x90;
478 break;
479 case 1:
480 cmos_base = 0x98;
481 break;
482 case 2:
483 cmos_base = 0xA0;
484 break;
485 case 3:
486 cmos_base = 0xA8;
487 break;
488 default:
489 cmos_base = 0;
490 }
491
492 if (cmos_base && inb_cmos(cmos_base + 7))
493 {
494 /* If provided, grab the logical geometry from CMOS. */
495 cylinders = inb_cmos(cmos_base + 0) + (inb_cmos(cmos_base + 1) << 8);
496 heads = inb_cmos(cmos_base + 2);
497 sectors_per_track = inb_cmos(cmos_base + 7);
498 }
499 else
500 {
501 /* Calculate default logical geometry. NB: Very different
502 * from default ATA/SATA logical geometry!
503 */
504 if (sectors >= (uint32_t)4 * 1024 * 1024)
505 {
506 heads = 255;
507 sectors_per_track = 63;
508 /* Approximate x / (255 * 63) using shifts */
509 t = (sectors >> 6) + (sectors >> 12);
510 cylinders = (t >> 8) + (t >> 16);
511 }
512 else if (sectors >= (uint32_t)2 * 1024 * 1024)
513 {
514 heads = 128;
515 sectors_per_track = 32;
516 cylinders = sectors >> 12;
517 }
518 else
519 {
520 heads = 64;
521 sectors_per_track = 32;
522 cylinders = sectors >> 11;
523 }
524 }
525
526 /* Calculate index into the generic disk table. */
527 hd_index = devcount_scsi + BX_MAX_ATA_DEVICES;
528
529 bios_dsk->scsidev[devcount_scsi].io_base = io_base;
530 bios_dsk->scsidev[devcount_scsi].target_id = i;
531 bios_dsk->devices[hd_index].type = DSK_TYPE_SCSI;
532 bios_dsk->devices[hd_index].device = DSK_DEVICE_HD;
533 bios_dsk->devices[hd_index].removable = 0;
534 bios_dsk->devices[hd_index].lock = 0;
535 bios_dsk->devices[hd_index].blksize = sector_size;
536 bios_dsk->devices[hd_index].translation = GEO_TRANSLATION_LBA;
537
538 /* Write LCHS/PCHS values. */
539 bios_dsk->devices[hd_index].lchs.heads = heads;
540 bios_dsk->devices[hd_index].lchs.spt = sectors_per_track;
541 bios_dsk->devices[hd_index].pchs.heads = heads;
542 bios_dsk->devices[hd_index].pchs.spt = sectors_per_track;
543
544 if (cylinders > 1024) {
545 bios_dsk->devices[hd_index].lchs.cylinders = 1024;
546 bios_dsk->devices[hd_index].pchs.cylinders = 1024;
547 } else {
548 bios_dsk->devices[hd_index].lchs.cylinders = (uint16_t)cylinders;
549 bios_dsk->devices[hd_index].pchs.cylinders = (uint16_t)cylinders;
550 }
551
552 BX_INFO("SCSI %d-ID#%d: LCHS=%lu/%u/%u 0x%llx sectors\n", devcount_scsi,
553 i, (uint32_t)cylinders, heads, sectors_per_track, sectors);
554
555 bios_dsk->devices[hd_index].sectors = sectors;
556
557 /* Store the id of the disk in the ata hdidmap. */
558 hdcount = bios_dsk->hdcount;
559 bios_dsk->hdidmap[hdcount] = devcount_scsi + BX_MAX_ATA_DEVICES;
560 hdcount++;
561 bios_dsk->hdcount = hdcount;
562
563 /* Update hdcount in the BDA. */
564 hdcount = read_byte(0x40, 0x75);
565 hdcount++;
566 write_byte(0x40, 0x75, hdcount);
567
568 devcount_scsi++;
569 }
570 else
571 {
572 /* We reached the maximum of SCSI disks we can boot from. We can quit detecting. */
573 break;
574 }
575 }
576 else if ( ((buffer[0] & 0xe0) == 0)
577 && ((buffer[0] & 0x1f) == 0x05))
578 {
579 uint8_t cdcount;
580 uint8_t removable;
581
582 BX_INFO("SCSI %d-ID#%d: CD/DVD-ROM\n", devcount_scsi, i);
583
584 /* Calculate index into the generic device table. */
585 hd_index = devcount_scsi + BX_MAX_ATA_DEVICES;
586
587 removable = buffer[1] & 0x80 ? 1 : 0;
588
589 bios_dsk->scsidev[devcount_scsi].io_base = io_base;
590 bios_dsk->scsidev[devcount_scsi].target_id = i;
591 bios_dsk->devices[hd_index].type = DSK_TYPE_SCSI;
592 bios_dsk->devices[hd_index].device = DSK_DEVICE_CDROM;
593 bios_dsk->devices[hd_index].removable = removable;
594 bios_dsk->devices[hd_index].blksize = 2048;
595 bios_dsk->devices[hd_index].translation = GEO_TRANSLATION_NONE;
596
597 /* Store the ID of the device in the BIOS cdidmap. */
598 cdcount = bios_dsk->cdcount;
599 bios_dsk->cdidmap[cdcount] = devcount_scsi + BX_MAX_ATA_DEVICES;
600 cdcount++;
601 bios_dsk->cdcount = cdcount;
602
603 devcount_scsi++;
604 }
605 else
606 DBG_SCSI("%s: No supported device detected at %d\n", __func__, i);
607
608 bios_dsk->scsi_devcount = devcount_scsi;
609 }
610}
611
612void scsi_pci_init(uint16_t vendor_id, uint16_t device_id)
613{
614 uint16_t bus_dev_fn;
615
616 bus_dev_fn = pci_find_device(vendor_id, device_id);
617 if (bus_dev_fn == -1) {
618 DBG_SCSI("%s: Adapter %x:%x not found, how come?!\n", __func__, vendor_id, device_id);
619 return;
620 }
621
622 DBG_SCSI("%s: Adapter %x:%x found at %x, enabling BM\n", __func__, vendor_id, device_id, bus_dev_fn);
623 /* Enable PCI memory, I/O, bus mastering access in command register. */
624 pci_write_config_word(bus_dev_fn >> 8, (uint8_t)bus_dev_fn, 4, 0x7);
625}
626
627/**
628 * Init the SCSI driver and detect attached disks.
629 */
630void BIOSCALL scsi_init(void)
631{
632 uint8_t identifier;
633 bio_dsk_t __far *bios_dsk;
634
635 bios_dsk = read_word(0x0040, 0x000E) :> &EbdaData->bdisk;
636
637 bios_dsk->scsi_devcount = 0;
638
639 identifier = 0;
640
641 /* Detect the BusLogic adapter. */
642 outb(BUSLOGIC_BIOS_IO_PORT+VBSCSI_REGISTER_IDENTIFY, 0x55);
643 identifier = inb(BUSLOGIC_BIOS_IO_PORT+VBSCSI_REGISTER_IDENTIFY);
644
645 if (identifier == 0x55)
646 {
647 /* Detected - Enumerate attached devices. */
648 DBG_SCSI("%s: BusLogic SCSI adapter detected\n", __func__);
649 outb(BUSLOGIC_BIOS_IO_PORT+VBSCSI_REGISTER_RESET, 0);
650 scsi_enumerate_attached_devices(BUSLOGIC_BIOS_IO_PORT);
651 scsi_pci_init(0x104B, 0x1040);
652 }
653 else
654 {
655 DBG_SCSI("%s: BusLogic SCSI adapter not detected\n", __func__);
656 }
657
658 /* Detect the LSI Logic parallel SCSI adapter. */
659 outb(LSILOGIC_BIOS_IO_PORT+VBSCSI_REGISTER_IDENTIFY, 0x55);
660 identifier = inb(LSILOGIC_BIOS_IO_PORT+VBSCSI_REGISTER_IDENTIFY);
661
662 if (identifier == 0x55)
663 {
664 /* Detected - Enumerate attached devices. */
665 DBG_SCSI("%s: LSI Logic SCSI adapter detected\n", __func__);
666 outb(LSILOGIC_BIOS_IO_PORT+VBSCSI_REGISTER_RESET, 0);
667 scsi_enumerate_attached_devices(LSILOGIC_BIOS_IO_PORT);
668 scsi_pci_init(0x1000, 0x0030);
669 }
670 else
671 {
672 DBG_SCSI("%s: LSI Logic SCSI adapter not detected\n", __func__);
673 }
674
675 /* Detect the LSI Logic SAS adapter. */
676 outb(LSILOGIC_SAS_BIOS_IO_PORT+VBSCSI_REGISTER_IDENTIFY, 0x55);
677 identifier = inb(LSILOGIC_SAS_BIOS_IO_PORT+VBSCSI_REGISTER_IDENTIFY);
678
679 if (identifier == 0x55)
680 {
681 /* Detected - Enumerate attached devices. */
682 DBG_SCSI("%s: LSI Logic SAS adapter detected\n", __func__);
683 outb(LSILOGIC_SAS_BIOS_IO_PORT+VBSCSI_REGISTER_RESET, 0);
684 scsi_enumerate_attached_devices(LSILOGIC_SAS_BIOS_IO_PORT);
685 scsi_pci_init(0x1000, 0x0054);
686 }
687 else
688 {
689 DBG_SCSI("%s: LSI Logic SAS adapter not detected\n", __func__);
690 }
691}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette