Skip to contentSkip to conversation

esp: add Tekram DC-390 emulation (PC SCSI adapter)

PATCH Superseded Hervé Poussineau 2 participants 6 messages Aug 2, 2012 Kbuild

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 esp: add Tekram DC-390 emulation (PC SCSI adapter)

Difference with AMD PCscsi is that DC-390 contains a EEPROM, and that a romfile is available to add INT13 support.

This has been successfully tested on:
- MS DOS 6.22 (using DC390 ASPI driver)
- MS Windows 98 SE (using DC390 driver)
- MS Windows NT 3.1 (using DC390 driver)
- MS Windows NT 4.0 (using DC390 driver)
- hard disk and cdrom boot

---

You're now able to install MS Windows NT 3.1 (which does not support IDE cdroms) directly on an empty VM, without installing MS-DOS first!

Changes v1->v2:
- use QOM casts
- add const on TypeInfo structure
- remove rom filename

 hw/esp.c |  124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 123 insertions(+), 1 deletion(-)
hw/esp.c +123 -1
index 4b00889..a6f426a 100644
@@ -26,6 +26,7 @@
 #include "sysbus.h"
 #include "pci.h"
 #include "scsi.h"
+#include "eeprom93xx.h"
 #include "esp.h"
 #include "trace.h"
 #include "qemu-log.h"
@@ -823,6 +824,8 @@ static const TypeInfo sysbus_esp_info = {
     .class_init    = sysbus_esp_class_init,
 };
 
+#define TYPE_AM53C974_DEVICE "am53c974"
+
 #define DMA_CMD   0x0
 #define DMA_STC   0x1
 #define DMA_SPA   0x2
@@ -1179,16 +1182,135 @@ static void esp_pci_class_init(ObjectClass *klass, void *data)
 }
 
 static TypeInfo esp_pci_info = {
-    .name = "am53c974",
+    .name = TYPE_AM53C974_DEVICE,
     .parent = TYPE_PCI_DEVICE,
     .instance_size = sizeof(PCIESPState),
     .class_init = esp_pci_class_init,
 };
 
+typedef struct {
+    PCIESPState pci;
+    eeprom_t *eeprom;
+} DC390State;
+
+#define TYPE_DC390_DEVICE "dc390"
+#define DC390(obj) \
+    OBJECT_CHECK(DC390State, obj, TYPE_DC390_DEVICE)
+
+#define EE_ADAPT_SCSI_ID 64
+#define EE_MODE2         65
+#define EE_DELAY         66
+#define EE_TAG_CMD_NUM   67
+#define EE_ADAPT_OPTIONS 68
+#define EE_BOOT_SCSI_ID  69
+#define EE_BOOT_SCSI_LUN 70
+#define EE_CHKSUM1       126
+#define EE_CHKSUM2       127
+
+#define EE_ADAPT_OPTION_F6_F8_AT_BOOT   0x01
+#define EE_ADAPT_OPTION_BOOT_FROM_CDROM 0x02
+#define EE_ADAPT_OPTION_INT13           0x04
+#define EE_ADAPT_OPTION_SCAM_SUPPORT    0x08
+
+
+static uint32_t dc390_read_config(PCIDevice *dev, uint32_t addr, int l)
+{
+    DC390State *pci = DC390(dev);
+    uint32_t val;
+
+    val = pci_default_read_config(dev, addr, l);
+
+    if (addr == 0x00 && l == 1) {
+        /* First byte of address space is AND-ed with EEPROM DO line */
+        if (!eeprom93xx_read(pci->eeprom)) {
+            val &= ~0xff;
+        }
+    }
+
+    return val;
+}
+
+static void dc390_write_config(PCIDevice *dev,
+                               uint32_t addr, uint32_t val, int l)
+{
+    DC390State *pci = DC390(dev);
+    if (addr == 0x80) {
+        /* EEPROM write */
+        int eesk = val & 0x80 ? 1 : 0;
+        int eedi = val & 0x40 ? 1 : 0;
+        eeprom93xx_write(pci->eeprom, 1, eesk, eedi);
+    } else if (addr == 0xc0) {
+        /* EEPROM CS low */
+        eeprom93xx_write(pci->eeprom, 0, 0, 0);
+    } else {
+        pci_default_write_config(dev, addr, val, l);
+    }
+}
+
+static int dc390_scsi_init(PCIDevice *dev)
+{
+    DC390State *pci = DC390(dev);
+    uint8_t *contents;
+    uint16_t chksum = 0;
+    int i, ret;
+
+    /* init base class */
+    ret = esp_pci_scsi_init(dev);
+    if (ret < 0) {
+        return ret;
+    }
+
+    /* EEPROM */
+    pci->eeprom = eeprom93xx_new(DEVICE(dev), 64);
+
+    /* set default eeprom values */
+    contents = (uint8_t *)eeprom93xx_data(pci->eeprom);
+
+    for (i = 0; i < 16; i++) {
+        contents[i * 2] = 0x57;
+        contents[i * 2 + 1] = 0x00;
+    }
+    contents[EE_ADAPT_SCSI_ID] = 7;
+    contents[EE_MODE2] = 0x0f;
+    contents[EE_TAG_CMD_NUM] = 0x04;
+    contents[EE_ADAPT_OPTIONS] = EE_ADAPT_OPTION_F6_F8_AT_BOOT
+                               | EE_ADAPT_OPTION_BOOT_FROM_CDROM
+                               | EE_ADAPT_OPTION_INT13;
+
+    /* update eeprom checksum */
+    for (i = 0; i < EE_CHKSUM1; i += 2) {
+        chksum += contents[i] + (((uint16_t)contents[i + 1]) << 8);
+    }
+    chksum = 0x1234 - chksum;
+    contents[EE_CHKSUM1] = chksum & 0xff;
+    contents[EE_CHKSUM2] = chksum >> 8;
+
+    return 0;
+}
+
+static void dc390_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = dc390_scsi_init;
+    k->config_read = dc390_read_config;
+    k->config_write = dc390_write_config;
+    dc->desc = "Tekram DC-390 SCSI adapter";
+}
+
+static const TypeInfo dc390_info = {
+    .name = "dc390",
+    .parent = TYPE_AM53C974_DEVICE,
+    .instance_size = sizeof(DC390State),
+    .class_init = dc390_class_init,
+};
+
 static void esp_register_types(void)
 {
     type_register_static(&sysbus_esp_info);
     type_register_static(&esp_pci_info);
+    type_register_static(&dc390_info);
 }
 
 type_init(esp_register_types)
Signature · 1 line
1.7.10.4
#1 lore raw

Il 02/08/2012 10:37, Hervé Poussineau ha scritto:

Quoted 11 lines

Difference with AMD PCscsi is that DC-390 contains a EEPROM, and that a romfile is available to add INT13 support.

This has been successfully tested on:
- MS DOS 6.22 (using DC390 ASPI driver)
- MS Windows 98 SE (using DC390 driver)
- MS Windows NT 3.1 (using DC390 driver)
- MS Windows NT 4.0 (using DC390 driver)
- hard disk and cdrom boot

I can take this patch in the SCSI tree, but... do we really need two models, considering that the PCI id is the same and that (for the coolness factor of installing NT 3.1 onto an empty VM) we can just add ESP support to SeaBIOS? Does the option ROM not work without the EEPROM?

(Regarding ESP support in SeaBIOS, I have an almost working patch; however, Windows XP setup fails at "Starting Windows" and I don't have any older images nor time to investigate... I attach both the QEMU and SeaBIOS changes, feel free to pick them up).

Paolo

Quoted 1 line

From f384abfbd201393f29f561f9af06b5af598cea78 Mon Sep 17 00:00:00 2001

From: Paolo Bonzini <[email protected]>
Date: Thu, 2 Aug 2012 15:43:39 +0200
Subject: [PATCH] esp: support 24-bit DMA?

---
 hw/esp.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
hw/esp.c +11 -5
index a011347..3224e4a 100644
@@ -197,7 +197,9 @@ static uint32_t get_cmd(ESPState *s, uint8_t *buf)
 
     target = s->wregs[ESP_WBUSID] & BUSID_DID;
     if (s->dma) {
-        dmalen = s->rregs[ESP_TCLO] | (s->rregs[ESP_TCMID] << 8);
+        dmalen = s->rregs[ESP_TCLO];
+        dmalen |= s->rregs[ESP_TCMID] << 8;
+        dmalen |= s->rregs[ESP_TCHI] << 16;
         s->dma_memory_read(s->dma_opaque, buf, dmalen);
     } else {
         dmalen = s->ti_size;
@@ -336,6 +338,7 @@ static void esp_dma_done(ESPState *s)
     s->rregs[ESP_RFLAGS] = 0;
     s->rregs[ESP_TCLO] = 0;
     s->rregs[ESP_TCMID] = 0;
+    s->rregs[ESP_TCHI] = 0;
     esp_raise_irq(s);
 }
 
@@ -438,7 +441,9 @@ static void handle_ti(ESPState *s)
         return;
     }
 
-    dmalen = s->rregs[ESP_TCLO] | (s->rregs[ESP_TCMID] << 8);
+    dmalen = s->rregs[ESP_TCLO];
+    dmalen |= s->rregs[ESP_TCMID] << 8;
+    dmalen |= s->rregs[ESP_TCHI] << 16;
     if (dmalen==0) {
       dmalen=0x10000;
     }
@@ -539,6 +544,7 @@ static void esp_reg_write(ESPState *s, uint32_t saddr, uint64_t val)
     switch (saddr) {
     case ESP_TCLO:
     case ESP_TCMID:
+    case ESP_TCHI:
         s->rregs[ESP_RSTAT] &= ~STAT_TC;
         break;
     case ESP_FIFO:
@@ -558,6 +564,7 @@ static void esp_reg_write(ESPState *s, uint32_t saddr, uint64_t val)
             /* Reload DMA counter.  */
             s->rregs[ESP_TCLO] = s->wregs[ESP_TCLO];
             s->rregs[ESP_TCMID] = s->wregs[ESP_TCMID];
+            s->rregs[ESP_TCHI] = s->wregs[ESP_TCHI];
         } else {
             s->dma = 0;
         }
@@ -640,13 +647,12 @@ static void esp_reg_write(ESPState *s, uint32_t saddr, uint64_t val)
     case ESP_WBUSID ... ESP_WSYNO:
         break;
     case ESP_CFG1:
+    case ESP_CFG2: case ESP_CFG3:
+    case ESP_RES3: case ESP_RES4:
         s->rregs[saddr] = val;
         break;
     case ESP_WCCF ... ESP_WTEST:
         break;
-    case ESP_CFG2 ... ESP_RES4:
-        s->rregs[saddr] = val;
-        break;
     default:
         trace_esp_error_invalid_write(val, saddr);
         return;
Signature · 1 line
1.7.10.4
Quoted 1 line

From 59d5f4c18187a0b20ab4e1b93f4619e48f909df8 Mon Sep 17 00:00:00 2001

From: Paolo Bonzini <[email protected]>
Date: Thu, 2 Aug 2012 14:56:05 +0200
Subject: [PATCH] scsi: add AMD PCscsi driver
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is a driver for an AMD PCscsi (am53c974) SCSI card. It can be used together with DOS or old operating systems such as Windows NT 3.1, Windows 3.1 or Windows 98.

Cc Hervé Poussineau <[email protected]>
---
 Makefile       |    2 +-
 src/Kconfig    |    6 ++
 src/block.c    |    1 +
 src/blockcmd.c |    3 +
 src/disk.h     |    1 +
 src/esp-scsi.c |  231 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/post.c     |    2 +
 7 files changed, 245 insertions(+), 1 deletion(-)
 create mode 100644 src/esp-scsi.c
Makefile +1 -1
index 1167799..4dce77b 100644
@@ -13,7 +13,7 @@ SRCBOTH=misc.c stacks.c pmm.c output.c util.c block.c floppy.c ata.c mouse.c \
     pnpbios.c pirtable.c vgahooks.c ramdisk.c pcibios.c blockcmd.c \
     usb.c usb-uhci.c usb-ohci.c usb-ehci.c usb-hid.c usb-msc.c \
     virtio-ring.c virtio-pci.c virtio-blk.c virtio-scsi.c apm.c ahci.c \
-    usb-uas.c lsi-scsi.c
+    usb-uas.c lsi-scsi.c esp-scsi.c
 SRC16=$(SRCBOTH) system.c disk.c font.c
 SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \
     acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \
src/Kconfig +6 -0
index bc343ee..6de3e71 100644
@@ -119,6 +119,12 @@ menu "Hardware support"
         default y
         help
             Support boot from virtio-scsi storage.
+    config ESP_SCSI
+        depends on DRIVES && !COREBOOT
+        bool "AMD PCscsi controllers"
+        default y
+        help
+            Support boot from AMD PCscsi storage.
     config LSI_SCSI
         depends on DRIVES && !COREBOOT
         bool "lsi53c895a scsi controllers"
src/block.c +1 -0
index 1c200cc..243428e 100644
@@ -335,6 +335,7 @@ process_op(struct disk_op_s *op)
     case DTYPE_UAS:
     case DTYPE_VIRTIO_SCSI:
     case DTYPE_LSI_SCSI:
+    case DTYPE_ESP_SCSI:
         return process_scsi_op(op);
     default:
         op->count = 0;
src/blockcmd.c +3 -0
index 4365650..97c72a6 100644
@@ -15,6 +15,7 @@
 #include "usb-uas.h" // usb_cmd_data
 #include "virtio-scsi.h" // virtio_scsi_cmd_data
 #include "lsi-scsi.h" // lsi_scsi_cmd_data
+#include "esp-scsi.h" // esp_scsi_cmd_data
 #include "boot.h" // boot_add_hd
 
 // Route command to low-level handler.
@@ -35,6 +36,8 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize)
         return virtio_scsi_cmd_data(op, cdbcmd, blocksize);
     case DTYPE_LSI_SCSI:
         return lsi_scsi_cmd_data(op, cdbcmd, blocksize);
+    case DTYPE_ESP_SCSI:
+        return esp_scsi_cmd_data(op, cdbcmd, blocksize);
     default:
         op->count = 0;
         return DISK_RET_EPARAM;
src/disk.h +1 -0
index 2b2511f..3d07372 100644
@@ -234,6 +234,7 @@ struct drive_s {
 #define DTYPE_USB          0x0a
 #define DTYPE_UAS          0x0b
 #define DTYPE_LSI_SCSI     0x0c
+#define DTYPE_ESP_SCSI     0x0d
 
 #define MAXDESCSIZE 80
 
src/esp-scsi.c new file +231 -0

231 lines not on this page · raw message

src/post.c +2 -0
index 0f31b4c..924b311 100644
@@ -28,6 +28,7 @@
 #include "virtio-blk.h" // virtio_blk_setup
 #include "virtio-scsi.h" // virtio_scsi_setup
 #include "lsi-scsi.h" // lsi_scsi_setup
+#include "esp-scsi.h" // esp_scsi_setup
 
 
 /****************************************************************
@@ -196,6 +197,7 @@ init_hw(void)
     virtio_blk_setup();
     virtio_scsi_setup();
     lsi_scsi_setup();
+    esp_scsi_setup();
 }
 
 // Begin the boot process by invoking an int0x19 in 16bit mode.
Signature · 1 line
1.7.10.4
#2 lore raw
Quoted 11 lines · Paolo Bonzini

Il 02/08/2012 10:37, Hervé Poussineau ha scritto:

Quoted 10 lines

Difference with AMD PCscsi is that DC-390 contains a EEPROM, and that a romfile is available to add INT13 support.

This has been successfully tested on:
- MS DOS 6.22 (using DC390 ASPI driver)
- MS Windows 98 SE (using DC390 driver)
- MS Windows NT 3.1 (using DC390 driver)
- MS Windows NT 4.0 (using DC390 driver)
- hard disk and cdrom boot

Quoted 6 lines
Quoted 1 line

I can take this patch in the SCSI tree, but... do we really need two models, considering that the PCI id is the same and that (for the coolness factor of installing NT 3.1 onto an empty VM) we can just add ESP support to SeaBIOS? Does the option ROM not work without the EEPROM?

No, the option ROM requires the EEPROM.

DC-390 also has a very broad support with (at least):
- SCO Unix 3.2/v4.x
- SCO OpenServer 5.0.x
- NetWare 3.11/3.12/SFT-III
- NetWare 4.00/4.01/4.02/4.1x
- OS/2 v2.0/2.1/2.11/WARP 3.0 & 4.0
- Windows NT 3.51/4.x
- Windows NT 3.1/3.5
- Windows 3.x & WFWG 3.x
- Windows 95 (OSR2) & Windows 98
where a driver is provided by Tekram, but the ones I tried require the EEPROM too.
I'm not sure you'll be able to find as much drivers for this card, which don't require the EEPROM (except the default driver on Windows 98 SE and NT 4.0)

Quoted 5 lines

(Regarding ESP support in SeaBIOS, I have an almost working patch; however, Windows XP setup fails at "Starting Windows" and I don't have any older images nor time to investigate... I attach both the QEMU and SeaBIOS changes, feel free to pick them up).

BTW, ack for your QEMU changes, if you want to put them in your tree...

Regards,

Hervé

#3 lore raw

Il 02/08/2012 17:09, Hervé Poussineau ha scritto:

Quoted 12 lines
Quoted 11 lines · Paolo Bonzini

Il 02/08/2012 10:37, Hervé Poussineau ha scritto:

Quoted 10 lines

Difference with AMD PCscsi is that DC-390 contains a EEPROM, and that a romfile is available to add INT13 support.

This has been successfully tested on:
- MS DOS 6.22 (using DC390 ASPI driver)
- MS Windows 98 SE (using DC390 driver)
- MS Windows NT 3.1 (using DC390 driver)
- MS Windows NT 4.0 (using DC390 driver)
- hard disk and cdrom boot

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

I can take this patch in the SCSI tree, but... do we really need two models, considering that the PCI id is the same and that (for the coolness factor of installing NT 3.1 onto an empty VM) we can just add ESP support to SeaBIOS? Does the option ROM not work without the EEPROM?

No, the option ROM requires the EEPROM.

Ok, then let's add the EEPROM unconditionally?

Quoted 6 lines
Quoted 4 lines

(Regarding ESP support in SeaBIOS, I have an almost working patch; however, Windows XP setup fails at "Starting Windows" and I don't have any older images nor time to investigate... I attach both the QEMU and SeaBIOS changes, feel free to pick them up).

BTW, ack for your QEMU changes, if you want to put them in your tree...

Thanks. I must have an NT 4.0 CD somewhere, just need to find it... :)

Paolo

#4 lore raw

Il 02/08/2012 17:12, Paolo Bonzini ha scritto:

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

I can take this patch in the SCSI tree, but... do we really need two models, considering that the PCI id is the same and that (for the coolness factor of installing NT 3.1 onto an empty VM) we can just add ESP support to SeaBIOS? Does the option ROM not work without the EEPROM?

No, the option ROM requires the EEPROM.

Ok, then let's add the EEPROM unconditionally?

Nah, applied to scsi-next branch as is. Thanks!

Paolo

#5 lore raw
In reply to Paolo Bonzini
Quoted 11 lines · Paolo Bonzini

Il 02/08/2012 10:37, Hervé Poussineau ha scritto:

Quoted 10 lines

Difference with AMD PCscsi is that DC-390 contains a EEPROM, and that a romfile is available to add INT13 support.

This has been successfully tested on:
- MS DOS 6.22 (using DC390 ASPI driver)
- MS Windows 98 SE (using DC390 driver)
- MS Windows NT 3.1 (using DC390 driver)
- MS Windows NT 4.0 (using DC390 driver)
- hard disk and cdrom boot

Quoted 6 lines
Quoted 1 line

I can take this patch in the SCSI tree, but... do we really need two models, considering that the PCI id is the same and that (for the coolness factor of installing NT 3.1 onto an empty VM) we can just add ESP support to SeaBIOS? Does the option ROM not work without the EEPROM?

No, the option ROM requires the EEPROM.

DC-390 also has a very broad support with (at least):
- SCO Unix 3.2/v4.x
- SCO OpenServer 5.0.x
- NetWare 3.11/3.12/SFT-III
- NetWare 4.00/4.01/4.02/4.1x
- OS/2 v2.0/2.1/2.11/WARP 3.0 & 4.0
- Windows NT 3.51/4.x
- Windows NT 3.1/3.5
- Windows 3.x & WFWG 3.x
- Windows 95 (OSR2) & Windows 98
where a driver is provided by Tekram, but the ones I tried require the EEPROM too.
I'm not sure you'll be able to find as much drivers for this card, which don't require the EEPROM (except the default driver on Windows 98 SE and NT 4.0)

Quoted 5 lines

(Regarding ESP support in SeaBIOS, I have an almost working patch; however, Windows XP setup fails at "Starting Windows" and I don't have any older images nor time to investigate... I attach both the QEMU and SeaBIOS changes, feel free to pick them up).

BTW, ack for your QEMU changes, if you want to commit them via your tree...

Regards,

Hervé