changeset 876341add7be in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=876341add7be
description:
        arm, dev: Add a UFS device

        This patch introduces a UFS host controller and a UFS device. More
        information about the UFS standard can be found at the JEDEC site:
        http://www.jedec.org/standards-documents/results/jesd220

        Note that the model does not implement the complete standard, and as
        such is not an actual implementation of UFS. The following SCSI
        commands are implemented: inquiry, read, read capacity, report LUNs,
        start/stop, test unit ready, verify, write, format unit, send
        diagnostic, synchronize cache, mode select, mode sense, request sense,
        unmap, write buffer and read buffer. This is sufficient for usage with
        Linux and Android.

        To interact with this model a kernel version 3.9 or above is
        needed.

diffstat:

 src/dev/arm/SConscript       |     3 +
 src/dev/arm/UFSHostDevice.py |    66 +
 src/dev/arm/ufs_device.cc    |  2363 ++++++++++++++++++++++++++++++++++++++++++
 src/dev/arm/ufs_device.hh    |  1230 +++++++++++++++++++++
 4 files changed, 3662 insertions(+), 0 deletions(-)

diffs (truncated from 3696 to 300 lines):

diff -r 049eb85e8ea2 -r 876341add7be src/dev/arm/SConscript
--- a/src/dev/arm/SConscript    Thu Apr 23 13:37:49 2015 -0400
+++ b/src/dev/arm/SConscript    Thu Apr 23 13:37:50 2015 -0400
@@ -44,6 +44,7 @@
     SimObject('FlashDevice.py')
     SimObject('Gic.py')
     SimObject('RealView.py')
+    SimObject('UFSHostDevice.py')
     SimObject('EnergyCtrl.py')
 
     Source('a9scu.cc')
@@ -64,6 +65,7 @@
     Source('rtc_pl031.cc')
     Source('timer_cpulocal.cc')
     Source('vgic.cc')
+    Source('ufs_device.cc')
     Source('energy_ctrl.cc')
 
     DebugFlag('AMBA')
@@ -75,4 +77,5 @@
     DebugFlag('GIC')
     DebugFlag('RVCTRL')
     DebugFlag('EnergyCtrl')
+    DebugFlag('UFSHostDevice')
     DebugFlag('VGIC')
diff -r 049eb85e8ea2 -r 876341add7be src/dev/arm/UFSHostDevice.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/dev/arm/UFSHostDevice.py      Thu Apr 23 13:37:50 2015 -0400
@@ -0,0 +1,66 @@
+# Copyright (c) 2013-2015 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder.  You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Rene de Jong
+#
+import sys
+from m5.params import *
+from m5.proxy import *
+from Device import DmaDevice
+from AbstractNVM import *
+
+class UFSHostDevice(DmaDevice):
+    type = 'UFSHostDevice'
+    cxx_header = "dev/arm/ufs_device.hh"
+    pio_addr = Param.Addr("Address for SCSI configuration slave interface")
+    pio_latency = Param.Latency("10ns", "Time between action and write/read \
+       result by AMBA DMA Device")
+    gic = Param.BaseGic(Parent.any, "Gic to use for interrupting")
+    int_num = Param.UInt32("Interrupt number that connects to GIC")
+    img_blk_size = Param.UInt32(512, "Size of one image block in bytes")
+    # Every image that is added to the vector will generate a new logic unit
+    # in the UFS device; Theoretically (when using the driver from Linux
+    # kernel 3.9 onwards), this can be as many as eigth. Up to two have been
+    # tested.
+    image = VectorParam.DiskImage("Disk images")
+    # Every logic unit can have its own flash dimensions. So the number of
+    # images that have been provided in the image vector, should be equal to
+    # the number of flash objects that are created. Each logic unit can have
+    # its own flash dimensions; to allow the system to define a hetrogeneous
+    # storage system.
+    internalflash = VectorParam.AbstractNVM("Describes the internal flash")
+    ufs_slots = Param.UInt32(32, "Number of commands that can be queued in \
+        the Host controller (min: 1, max: 32)")
+
diff -r 049eb85e8ea2 -r 876341add7be src/dev/arm/ufs_device.cc
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/dev/arm/ufs_device.cc Thu Apr 23 13:37:50 2015 -0400
@@ -0,0 +1,2363 @@
+/*
+ * Copyright (c) 2013-2015 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Rene de Jong
+ */
+
+/** @file
+ * This is a simulation model for a UFS interface
+ * The UFS interface consists of a host controller and (at least) one device.
+ * The device can contain multiple logic units.
+ * To make this interface as usefull as possible for future development, the
+ * decision has been made to split the UFS functionality from the SCSI
+ * functionality. The class UFS SCSIDevice can therefor be used as a starting
+ * point for creating a more generic SCSI device. This has as a consequence
+ * that the UFSHostDevice class contains functionality from both the host
+ * controller and the device. The current UFS standard (1.1) allows only one
+ * device, and up to 8 logic units. the logic units only handle the SCSI part
+ * of the command, and the device mainly the UFS part. Yet the split between
+ * the SCSIresume function and the SCSICMDHandle might seem a bit awkward.
+ * The SCSICMDHandle function is in essence a SCSI reply generator, and it
+ * distils the essential information from the command. A disktransfer cannot
+ * be made from this position because the scatter gather list is not included
+ * in the SCSI command, but in the Transfer Request descriptor. The device
+ * needs to manage the data transfer. This file is build up as follows: first
+ * the UFSSCSIDevice functions will be presented; then the UFSHostDevice
+ * functions. The UFSHostDevice functions are split in three parts: UFS
+ * transaction flow, data write transfer and data read transfer. The
+ * functions are then ordered in the order in which a transfer takes place.
+ */
+
+/**
+ * Reference material can be found at the JEDEC website:
+ * UFS standard
+ * http://www.jedec.org/standards-documents/results/jesd220
+ * UFS HCI specification
+ * http://www.jedec.org/standards-documents/results/jesd223
+ */
+
+#include "dev/arm/ufs_device.hh"
+
+/**
+ * Constructor and destructor functions of UFSHCM device
+ */
+UFSHostDevice::UFSSCSIDevice::UFSSCSIDevice(const UFSHostDeviceParams* p,
+                             uint32_t lun_id, Callback *transfer_cb,
+                             Callback *read_cb):
+    SimObject(p),
+    flashDisk(p->image[lun_id]),
+    flashDevice(p->internalflash[lun_id]),
+    blkSize(p->img_blk_size),
+    lunAvail(p->image.size()),
+    diskSize(flashDisk->size()),
+    capacityLower((diskSize - 1) & 0xffffffff),
+    capacityUpper((diskSize - SectorSize) >> 32),
+    lunID(lun_id),
+    transferCompleted(false),
+    readCompleted(false),
+    totalRead(0),
+    totalWrite(0),
+    amountOfWriteTransfers(0),
+    amountOfReadTransfers(0)
+{
+    /**
+     * These callbacks are used to communicate the events that are
+     * triggered upstream; e.g. from the Memory Device to the UFS SCSI Device
+     * or from the UFS SCSI device to the UFS host.
+     */
+    signalDone = transfer_cb;
+    memReadCallback = new MakeCallback<UFSSCSIDevice,
+        &UFSHostDevice::UFSSCSIDevice::readCallback>(this);
+    deviceReadCallback = read_cb;
+    memWriteCallback = new MakeCallback<UFSSCSIDevice,
+        &UFSHostDevice::UFSSCSIDevice::SSDWriteDone>(this);
+
+    /**
+     * make ascii out of lun_id (and add more characters)
+     * UFS allows up to 8 logic units, so the numbering should work out
+     */
+    uint32_t temp_id = ((lun_id | 0x30) << 24) | 0x3A4449;
+    lunInfo.dWord0 = 0x02060000;   //data
+    lunInfo.dWord1 = 0x0200001F;
+    lunInfo.vendor0 = 0x484D5241;  //ARMH (HMRA)
+    lunInfo.vendor1 = 0x424D4143;  //CAMB (BMAC)
+    lunInfo.product0 = 0x356D6567; //gem5  (5meg)
+    lunInfo.product1 = 0x4D534655; //UFSM (MSFU)
+    lunInfo.product2 = 0x4C45444F; //ODEL (LEDO)
+    lunInfo.product3 = temp_id;    // ID:"lun_id" ("lun_id":DI)
+    lunInfo.productRevision = 0x01000000; //0x01
+
+    DPRINTF(UFSHostDevice, "Logic unit %d assumes that %d logic units are"
+            " present in the system\n", lunID, lunAvail);
+    DPRINTF(UFSHostDevice,"The disksize of lun: %d should be %d blocks\n",
+            lunID, diskSize);
+    flashDevice->initializeMemory(diskSize, SectorSize);
+}
+
+
+/**
+ * These pages are SCSI specific. For more information refer to:
+ * Universal Flash Storage (UFS) JESD220 FEB 2011 (JEDEC)
+ * http://www.jedec.org/standards-documents/results/jesd220
+ */
+const unsigned int UFSHostDevice::UFSSCSIDevice::controlPage[3] =
+                                                {0x01400A0A, 0x00000000,
+                                                 0x0000FFFF};
+const unsigned int UFSHostDevice::UFSSCSIDevice::recoveryPage[3] =
+                                                {0x03800A01, 0x00000000,
+                                                 0xFFFF0003};
+const unsigned int UFSHostDevice::UFSSCSIDevice::cachingPage[5] =
+                                                {0x00011208, 0x00000000,
+                                                 0x00000000, 0x00000020,
+                                                 0x00000000};
+
+UFSHostDevice::UFSSCSIDevice::~UFSSCSIDevice() {}
+
+/**
+ * UFS specific SCSI handling function.
+ * The following attributes may still be added: SCSI format unit,
+ * Send diagnostic and UNMAP;
+ * Synchronize Cache and buffer read/write could not be tested yet
+ * All parameters can be found in:
+ * Universal Flash Storage (UFS) JESD220 FEB 2011 (JEDEC)
+ * http://www.jedec.org/standards-documents/results/jesd220
+ * (a JEDEC acount may be required {free of charge})
+ */
+
+struct UFSHostDevice::SCSIReply
+UFSHostDevice::UFSSCSIDevice::SCSICMDHandle(uint32_t* SCSI_msg)
+{
+    struct SCSIReply scsi_out;
+    memset(&scsi_out, 0, sizeof(struct SCSIReply));
+
+    /**
+     * Create the standard SCSI reponse information
+     * These values might changes over the course of a transfer
+     */
+    scsi_out.message.header.dWord0 = UPIUHeaderDataIndWord0 |
+        lunID << 16;
+    scsi_out.message.header.dWord1 = UPIUHeaderDataIndWord1;
+    scsi_out.message.header.dWord2 = UPIUHeaderDataIndWord2;
+    statusCheck(SCSIGood, scsi_out.senseCode);
+    scsi_out.senseSize = scsi_out.senseCode[0];
+    scsi_out.LUN = lunID;
+    scsi_out.status = SCSIGood;
+
+    DPRINTF(UFSHostDevice, "SCSI command:%2x\n", SCSI_msg[4]);
+    /**Determine what the message is and fill the response packet*/
+
+    switch (SCSI_msg[4] & 0xFF) {
+
+      case SCSIInquiry: {
+          /**
+           * SCSI inquiry: tell about this specific logic unit
+           */
+          scsi_out.msgSize = 36;
+          scsi_out.message.dataMsg.resize(9);
+
+          for (uint8_t count = 0; count < 9; count++)
+              scsi_out.message.dataMsg[count] =
+                  (reinterpret_cast<uint32_t*> (&lunInfo))[count];
+      } break;
+
+      case SCSIRead6: {
+          /**
+           * Read command. Number indicates the length of the command.
+           */
+          scsi_out.expectMore = 0x02;
+          scsi_out.msgSize = 0;
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to