Skip to contentSkip to conversation

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

PATCH Applied Hervé Poussineau 2 participants 7 messages Aug 4, 2012 – Aug 9, 2012

lore
Share & tools
lore
#0 lore raw

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

This patch cleans up esp SCSI adapter emulation, by moving to a new file the esp PCI emulation (patches 1 to 3). Patch 4 adds a DC-390 emulation, which is not compiled on sparc.

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 v2->v3:
- move esp PCI emulation to a new file
- do not compile esp PCI emulation on sparc
- (DC-390 patch is left unchanged)

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

Hervé Poussineau (4):
esp: move some definitions to header file
esp: move PCI emulation to a new file esp-pci.c Revert "pci: add some stubs"
esp: add Tekram DC-390 emulation (PC SCSI adapter)

 default-configs/pci.mak |    1 +
 hw/Makefile.objs        |    1 +
 hw/esp-pci.c            |  518 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/esp.c                |  487 +-------------------------------------------
 hw/esp.h                |  119 +++++++++++
 hw/pci-stub.c           |   15 --
 6 files changed, 647 insertions(+), 494 deletions(-)
 create mode 100644 hw/esp-pci.c
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v3 1/4 esp: move some definitions to header file

These will be used by next commits.

---
 hw/esp.c |  125 ++++----------------------------------------------------------
 hw/esp.h |  119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 127 insertions(+), 117 deletions(-)
hw/esp.c +8 -117
index 77f5707..60c2221 100644
@@ -25,7 +25,6 @@
 
 #include "sysbus.h"
 #include "pci.h"
-#include "scsi.h"
 #include "esp.h"
 #include "trace.h"
 #include "qemu-log.h"
@@ -38,114 +37,6 @@
  * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR53C9X.txt
  */
 
-#define ESP_REGS 16
-#define TI_BUFSZ 16
-
-typedef struct ESPState ESPState;
-
-struct ESPState {
-    uint8_t rregs[ESP_REGS];
-    uint8_t wregs[ESP_REGS];
-    qemu_irq irq;
-    uint8_t chip_id;
-    int32_t ti_size;
-    uint32_t ti_rptr, ti_wptr;
-    uint32_t status;
-    uint32_t dma;
-    uint8_t ti_buf[TI_BUFSZ];
-    SCSIBus bus;
-    SCSIDevice *current_dev;
-    SCSIRequest *current_req;
-    uint8_t cmdbuf[TI_BUFSZ];
-    uint32_t cmdlen;
-    uint32_t do_cmd;
-
-    /* The amount of data left in the current DMA transfer.  */
-    uint32_t dma_left;
-    /* The size of the current DMA transfer.  Zero if no transfer is in
-       progress.  */
-    uint32_t dma_counter;
-    int dma_enabled;
-
-    uint32_t async_len;
-    uint8_t *async_buf;
-
-    ESPDMAMemoryReadWriteFunc dma_memory_read;
-    ESPDMAMemoryReadWriteFunc dma_memory_write;
-    void *dma_opaque;
-    void (*dma_cb)(ESPState *s);
-};
-
-#define ESP_TCLO   0x0
-#define ESP_TCMID  0x1
-#define ESP_FIFO   0x2
-#define ESP_CMD    0x3
-#define ESP_RSTAT  0x4
-#define ESP_WBUSID 0x4
-#define ESP_RINTR  0x5
-#define ESP_WSEL   0x5
-#define ESP_RSEQ   0x6
-#define ESP_WSYNTP 0x6
-#define ESP_RFLAGS 0x7
-#define ESP_WSYNO  0x7
-#define ESP_CFG1   0x8
-#define ESP_RRES1  0x9
-#define ESP_WCCF   0x9
-#define ESP_RRES2  0xa
-#define ESP_WTEST  0xa
-#define ESP_CFG2   0xb
-#define ESP_CFG3   0xc
-#define ESP_RES3   0xd
-#define ESP_TCHI   0xe
-#define ESP_RES4   0xf
-
-#define CMD_DMA 0x80
-#define CMD_CMD 0x7f
-
-#define CMD_NOP      0x00
-#define CMD_FLUSH    0x01
-#define CMD_RESET    0x02
-#define CMD_BUSRESET 0x03
-#define CMD_TI       0x10
-#define CMD_ICCS     0x11
-#define CMD_MSGACC   0x12
-#define CMD_PAD      0x18
-#define CMD_SATN     0x1a
-#define CMD_RSTATN   0x1b
-#define CMD_SEL      0x41
-#define CMD_SELATN   0x42
-#define CMD_SELATNS  0x43
-#define CMD_ENSEL    0x44
-#define CMD_DISSEL   0x45
-
-#define STAT_DO 0x00
-#define STAT_DI 0x01
-#define STAT_CD 0x02
-#define STAT_ST 0x03
-#define STAT_MO 0x06
-#define STAT_MI 0x07
-#define STAT_PIO_MASK 0x06
-
-#define STAT_TC 0x10
-#define STAT_PE 0x20
-#define STAT_GE 0x40
-#define STAT_INT 0x80
-
-#define BUSID_DID 0x07
-
-#define INTR_FC 0x08
-#define INTR_BS 0x10
-#define INTR_DC 0x20
-#define INTR_RST 0x80
-
-#define SEQ_0 0x0
-#define SEQ_CD 0x4
-
-#define CFG1_RESREPT 0x40
-
-#define TCHI_FAS100A 0x4
-#define TCHI_AM53C974 0x12
-
 static void esp_raise_irq(ESPState *s)
 {
     if (!(s->rregs[ESP_RSTAT] & STAT_INT)) {
@@ -164,7 +55,7 @@ static void esp_lower_irq(ESPState *s)
     }
 }
 
-static void esp_dma_enable(ESPState *s, int irq, int level)
+void esp_dma_enable(ESPState *s, int irq, int level)
 {
     if (level) {
         s->dma_enabled = 1;
@@ -179,7 +70,7 @@ static void esp_dma_enable(ESPState *s, int irq, int level)
     }
 }
 
-static void esp_request_cancelled(SCSIRequest *req)
+void esp_request_cancelled(SCSIRequest *req)
 {
     ESPState *s = req->hba_private;
 
@@ -388,7 +279,7 @@ static void esp_do_dma(ESPState *s)
     esp_dma_done(s);
 }
 
-static void esp_command_complete(SCSIRequest *req, uint32_t status,
+void esp_command_complete(SCSIRequest *req, uint32_t status,
                                  size_t resid)
 {
     ESPState *s = req->hba_private;
@@ -413,7 +304,7 @@ static void esp_command_complete(SCSIRequest *req, uint32_t status,
     }
 }
 
-static void esp_transfer_data(SCSIRequest *req, uint32_t len)
+void esp_transfer_data(SCSIRequest *req, uint32_t len)
 {
     ESPState *s = req->hba_private;
 
@@ -465,7 +356,7 @@ static void handle_ti(ESPState *s)
     }
 }
 
-static void esp_hard_reset(ESPState *s)
+void esp_hard_reset(ESPState *s)
 {
     memset(s->rregs, 0, ESP_REGS);
     memset(s->wregs, 0, ESP_REGS);
@@ -493,7 +384,7 @@ static void parent_esp_reset(ESPState *s, int irq, int level)
     }
 }
 
-static uint64_t esp_reg_read(ESPState *s, uint32_t saddr)
+uint64_t esp_reg_read(ESPState *s, uint32_t saddr)
 {
     uint32_t old_val;
 
@@ -533,7 +424,7 @@ static uint64_t esp_reg_read(ESPState *s, uint32_t saddr)
     return s->rregs[saddr];
 }
 
-static void esp_reg_write(ESPState *s, uint32_t saddr, uint64_t val)
+void esp_reg_write(ESPState *s, uint32_t saddr, uint64_t val)
 {
     trace_esp_mem_writeb(saddr, s->wregs[saddr], val);
     switch (saddr) {
@@ -660,7 +551,7 @@ static bool esp_mem_accepts(void *opaque, target_phys_addr_t addr,
     return (size == 1) || (is_write && size == 4);
 }
 
-static const VMStateDescription vmstate_esp = {
+const VMStateDescription vmstate_esp = {
     .name ="esp",
     .version_id = 3,
     .minimum_version_id = 3,
hw/esp.h +119 -0

129 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

PATCH v3 2/4 esp: move PCI emulation to a new file esp-pci.c

In reply to Hervé Poussineau

sparc machines loose ability to instanciate PCI ESP SCSI adapter, which is not a big loose as they don't have PCI bus support.

---
 default-configs/pci.mak |    1 +
 hw/Makefile.objs        |    1 +
 hw/esp-pci.c            |  396 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/esp.c                |  362 -------------------------------------------
 4 files changed, 398 insertions(+), 362 deletions(-)
 create mode 100644 hw/esp-pci.c
default-configs/pci.mak +1 -0
index 9febb47..69e18f1 100644
@@ -18,3 +18,4 @@ CONFIG_IDE_QDEV=y
 CONFIG_IDE_PCI=y
 CONFIG_AHCI=y
 CONFIG_ESP=y
+CONFIG_ESP_PCI=y
hw/Makefile.objs +1 -0
index 8327e55..12cc141 100644
@@ -88,6 +88,7 @@ hw-obj-$(CONFIG_OPENCORES_ETH) += opencores_eth.o
 hw-obj-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o
 hw-obj-$(CONFIG_MEGASAS_SCSI_PCI) += megasas.o
 hw-obj-$(CONFIG_ESP) += esp.o
+hw-obj-$(CONFIG_ESP_PCI) += esp-pci.o
 
 hw-obj-y += sysbus.o isa-bus.o
 hw-obj-y += qdev-addr.o
hw/esp-pci.c new file +396 -0

396 lines not on this page · raw message

hw/esp.c +0 -362

377 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#3 lore raw

PATCH v3 3/4 Revert "pci: add some stubs"

In reply to Hervé Poussineau

This reverts commit 0883c5159f1df05d8761014f65451c3c3b77ebcf.

Those stubs were only used by PCI ESP emulation, which is now not compiled on architectures which have no PCI bus support.

---
 hw/pci-stub.c |   15 ---------------
 1 file changed, 15 deletions(-)
hw/pci-stub.c +0 -15
index e083191..134c448 100644
@@ -34,21 +34,6 @@ static void pci_error_message(Monitor *mon)
     monitor_printf(mon, "PCI devices not supported\n");
 }
 
-void pci_register_bar(PCIDevice *pci_dev, int region_num,
-                      uint8_t type, MemoryRegion *memory)
-{
-}
-
-const VMStateDescription vmstate_pci_device = {
-    .name = "PCIDeviceStub",
-    .version_id = 1,
-    .minimum_version_id = 1,
-    .minimum_version_id_old = 1,
-    .fields      = (VMStateField[]) {
-        VMSTATE_END_OF_LIST()
-    }
-};
-
 int do_pcie_aer_inject_error(Monitor *mon,
                              const QDict *qdict, QObject **ret_data)
 {
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH v3 4/4 esp: add Tekram DC-390 emulation (PC SCSI adapter)

In reply to Hervé Poussineau

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

---
 hw/esp-pci.c |  124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 123 insertions(+), 1 deletion(-)
hw/esp-pci.c +123 -1
index f633a18..170e007 100644
@@ -24,10 +24,13 @@
  */
 
 #include "pci.h"
+#include "eeprom93xx.h"
 #include "esp.h"
 #include "trace.h"
 #include "qemu-log.h"
 
+#define TYPE_AM53C974_DEVICE "am53c974"
+
 #define DMA_CMD   0x0
 #define DMA_STC   0x1
 #define DMA_SPA   0x2
@@ -382,15 +385,134 @@ 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_pci_register_types(void)
 {
     type_register_static(&esp_pci_info);
+    type_register_static(&dc390_info);
 }
 
 type_init(esp_pci_register_types)
Signature · 1 line
1.7.10.4
#5 lore raw
In reply to Hervé Poussineau

Ping.

Quoted 32 lines · Hervé Poussineau

This patch cleans up esp SCSI adapter emulation, by moving to a new file the esp PCI emulation (patches 1 to 3). Patch 4 adds a DC-390 emulation, which is not compiled on sparc.

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 v2->v3:
- move esp PCI emulation to a new file
- do not compile esp PCI emulation on sparc
- (DC-390 patch is left unchanged)

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

Hervé Poussineau (4):
esp: move some definitions to header file
esp: move PCI emulation to a new file esp-pci.c Revert "pci: add some stubs"
esp: add Tekram DC-390 emulation (PC SCSI adapter)

 default-configs/pci.mak |    1 +
 hw/Makefile.objs        |    1 +
 hw/esp-pci.c            |  518 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/esp.c                |  487 +-------------------------------------------
 hw/esp.h                |  119 +++++++++++
 hw/pci-stub.c           |   15 --
 6 files changed, 647 insertions(+), 494 deletions(-)
 create mode 100644 hw/esp-pci.c
Applied
#6 lore raw
In reply to Hervé Poussineau
Quoted 6 lines · Hervé Poussineau

This patch cleans up esp SCSI adapter emulation, by moving to a new file the esp PCI emulation (patches 1 to 3). Patch 4 adds a DC-390 emulation, which is not compiled on sparc.

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!

Thanks, applied all.

Quoted 29 lines

Changes v2->v3:
- move esp PCI emulation to a new file
- do not compile esp PCI emulation on sparc
- (DC-390 patch is left unchanged)

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

Hervé Poussineau (4):
esp: move some definitions to header file
esp: move PCI emulation to a new file esp-pci.c Revert "pci: add some stubs"
esp: add Tekram DC-390 emulation (PC SCSI adapter)

 default-configs/pci.mak |    1 +
 hw/Makefile.objs        |    1 +
 hw/esp-pci.c            |  518 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/esp.c                |  487 +-------------------------------------------
 hw/esp.h                |  119 +++++++++++
 hw/pci-stub.c           |   15 --
 6 files changed, 647 insertions(+), 494 deletions(-)
 create mode 100644 hw/esp-pci.c

--
1.7.10.4