qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Hervé Poussineau" <hpoussin@reactos.org>
Subject: [Qemu-devel] [PATCH 09/10] esp: add Tekram DC-390 emulation (PC SCSI adapter)
Date: Fri,  3 Aug 2012 10:06:19 +0200	[thread overview]
Message-ID: <1343981180-23817-10-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1343981180-23817-1-git-send-email-pbonzini@redhat.com>

From: Hervé Poussineau <hpoussin@reactos.org>

Difference with AMD PCscsi is that DC-390 contains a EEPROM.

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

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/esp.c |  126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 125 insertions(+), 1 deletion(-)

diff --git a/hw/esp.c b/hw/esp.c
index 77f5707..0bdc8be 100644
--- a/hw/esp.c
+++ b/hw/esp.c
@@ -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,9 @@ 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
@@ -1177,16 +1181,136 @@ static void esp_pci_class_init(ObjectClass *klass, void *data)
 }
 
 static const 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)
-- 
1.7.10.4

  parent reply	other threads:[~2012-08-03  8:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-03  8:06 [Qemu-devel] [PULL 00/10] SCSI patches for 2012-08-03 Paolo Bonzini
2012-08-03  8:06 ` [Qemu-devel] [PATCH 01/10] SCSI: Update the sense code for PREVENT REMOVAL errors Paolo Bonzini
2012-08-03  8:06 ` [Qemu-devel] [PATCH 02/10] SCSI: STARTSTOPUNIT only eject/load media if powercondition is 0 Paolo Bonzini
2012-08-03  8:06 ` [Qemu-devel] [PATCH 03/10] megasas: Update function megasys_scsi_uninit Paolo Bonzini
2012-08-03  8:06 ` [Qemu-devel] [PATCH 04/10] scsi-disk: fix compilation with DEBUG_SCSI Paolo Bonzini
2012-08-03  8:06 ` [Qemu-devel] [PATCH 05/10] megasas: static SAS addresses Paolo Bonzini
2012-08-03  8:06 ` [Qemu-devel] [PATCH 06/10] Revert "megasas: disable due to build breakage" Paolo Bonzini
2012-08-03  8:06 ` [Qemu-devel] [PATCH 07/10] esp: enable for all PCI machines Paolo Bonzini
2012-08-03  8:06 ` [Qemu-devel] [PATCH 08/10] esp: add missing const on TypeInfo structures Paolo Bonzini
2012-08-03  8:06 ` Paolo Bonzini [this message]
2012-08-03  8:06 ` [Qemu-devel] [PATCH 10/10] scsi: add support for ATA_PASSTHROUGH_xx scsi command Paolo Bonzini
2012-08-03 19:27 ` [Qemu-devel] [PULL 00/10] SCSI patches for 2012-08-03 Anthony Liguori
2012-08-03 19:56   ` Paolo Bonzini
2012-08-03 20:04     ` Anthony Liguori
2012-08-03 20:14     ` Hervé Poussineau
2012-08-03 20:37       ` Anthony Liguori
2012-08-03 20:59         ` Blue Swirl
2012-08-03 21:43     ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1343981180-23817-10-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=hpoussin@reactos.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).