]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sandbox: Convert to use driver model for SCSI
authorSimon Glass <sjg@chromium.org>
Wed, 21 Sep 2022 14:21:46 +0000 (16:21 +0200)
committerSimon Glass <sjg@chromium.org>
Sun, 25 Sep 2022 19:59:50 +0000 (13:59 -0600)
At present sandbox is producing a warning about SCSI migration. Drop the
legacy code and replace it with a new implementation.

Also drop the SATA command, which does not work with driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/Kconfig
configs/sandbox64_defconfig
configs/sandbox_defconfig
configs/sandbox_flattree_defconfig
configs/sandbox_noinst_defconfig
configs/sandbox_spl_defconfig
configs/sandbox_vpl_defconfig
configs/tools-only_defconfig
drivers/scsi/sandbox_scsi.c

index 994fd3b7f86191f470cc6356c06f13c8a34b1f82..1ffd77c0f4f82e87a08dd84bc91bb46a527f676c 100644 (file)
@@ -166,7 +166,6 @@ config SANDBOX
        imply CMD_IO
        imply CMD_IOTRACE
        imply CMD_LZMADEC
-       imply CMD_SATA
        imply CMD_SF
        imply CMD_SF_TEST
        imply CRC32_VERIFY
index 9dab89a999f5dc802fd1c527c2682f156c10f941..b20b181ab1f88d6a5c6975d38ddb96bbbe1ba882 100644 (file)
@@ -52,7 +52,6 @@ CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_READ=y
 CONFIG_CMD_REMOTEPROC=y
-# CONFIG_CMD_SATA is not set
 CONFIG_CMD_SPI=y
 CONFIG_CMD_USB=y
 CONFIG_BOOTP_DNS2=y
@@ -204,9 +203,7 @@ CONFIG_SANDBOX_RESET=y
 CONFIG_DM_RTC=y
 CONFIG_RTC_RV8803=y
 CONFIG_SCSI=y
-CONFIG_SCSI_AHCI_PLAT=y
-CONFIG_SYS_SCSI_MAX_SCSI_ID=8
-CONFIG_SYS_SCSI_MAX_LUN=4
+CONFIG_DM_SCSI=y
 CONFIG_SANDBOX_SERIAL=y
 CONFIG_SMEM=y
 CONFIG_SANDBOX_SMEM=y
index caecb50ad962787d3834d91501fe2f783bc336a9..df6a28ef249f40f7317dc3f7c0d21cd4203ccfed 100644 (file)
@@ -137,7 +137,6 @@ CONFIG_DEBUG_DEVRES=y
 CONFIG_SIMPLE_PM_BUS=y
 CONFIG_ADC=y
 CONFIG_ADC_SANDBOX=y
-CONFIG_SYS_SATA_MAX_DEVICE=2
 CONFIG_AXI=y
 CONFIG_AXI_SANDBOX=y
 CONFIG_SYS_IDE_MAXBUS=1
@@ -264,9 +263,7 @@ CONFIG_RESET_SCMI=y
 CONFIG_DM_RTC=y
 CONFIG_RTC_RV8803=y
 CONFIG_SCSI=y
-CONFIG_SCSI_AHCI_PLAT=y
-CONFIG_SYS_SCSI_MAX_SCSI_ID=8
-CONFIG_SYS_SCSI_MAX_LUN=4
+CONFIG_DM_SCSI=y
 CONFIG_SANDBOX_SERIAL=y
 CONFIG_SMEM=y
 CONFIG_SANDBOX_SMEM=y
index a8344029f47f5eccc95dcbb0c4007ae263e1b156..a2eb7afcf9bd3f7cf1b3f2487c3373b29302aa25 100644 (file)
@@ -85,7 +85,6 @@ CONFIG_DEVRES=y
 CONFIG_DEBUG_DEVRES=y
 CONFIG_ADC=y
 CONFIG_ADC_SANDBOX=y
-CONFIG_SYS_SATA_MAX_DEVICE=2
 CONFIG_AXI=y
 CONFIG_AXI_SANDBOX=y
 CONFIG_CLK=y
@@ -175,9 +174,7 @@ CONFIG_DM_RESET=y
 CONFIG_SANDBOX_RESET=y
 CONFIG_DM_RTC=y
 CONFIG_SCSI=y
-CONFIG_SCSI_AHCI_PLAT=y
-CONFIG_SYS_SCSI_MAX_SCSI_ID=8
-CONFIG_SYS_SCSI_MAX_LUN=4
+CONFIG_DM_SCSI=y
 CONFIG_SANDBOX_SERIAL=y
 CONFIG_SOUND=y
 CONFIG_SOUND_SANDBOX=y
index da83165a4d72350290959b31744dfbc0186a19ef..8bf10bb3ee10d139cc54a4b15e25b81a4127c9f4 100644 (file)
@@ -108,7 +108,6 @@ CONFIG_DEBUG_DEVRES=y
 # CONFIG_SPL_SIMPLE_BUS is not set
 CONFIG_ADC=y
 CONFIG_ADC_SANDBOX=y
-CONFIG_SYS_SATA_MAX_DEVICE=2
 CONFIG_AXI=y
 CONFIG_AXI_SANDBOX=y
 CONFIG_SYS_IDE_MAXBUS=1
@@ -201,9 +200,7 @@ CONFIG_SANDBOX_RESET=y
 CONFIG_DM_RTC=y
 CONFIG_SPL_DM_RTC=y
 CONFIG_SCSI=y
-CONFIG_SCSI_AHCI_PLAT=y
-CONFIG_SYS_SCSI_MAX_SCSI_ID=8
-CONFIG_SYS_SCSI_MAX_LUN=4
+CONFIG_DM_SCSI=y
 CONFIG_SANDBOX_SERIAL=y
 CONFIG_SOUND=y
 CONFIG_SOUND_SANDBOX=y
index 0d7c5972d8360ebfbc1a55e9ff8c7d93f0c74653..c33f17186de2c429d9e18760711bff85fbea2096 100644 (file)
@@ -61,7 +61,6 @@ CONFIG_CMD_I2C=y
 CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_REMOTEPROC=y
-# CONFIG_CMD_SATA is not set
 CONFIG_CMD_SPI=y
 CONFIG_CMD_USB=y
 CONFIG_BOOTP_DNS2=y
@@ -204,9 +203,7 @@ CONFIG_SANDBOX_RESET=y
 CONFIG_DM_RTC=y
 CONFIG_SPL_DM_RTC=y
 CONFIG_SCSI=y
-CONFIG_SCSI_AHCI_PLAT=y
-CONFIG_SYS_SCSI_MAX_SCSI_ID=8
-CONFIG_SYS_SCSI_MAX_LUN=4
+CONFIG_DM_SCSI=y
 CONFIG_SANDBOX_SERIAL=y
 CONFIG_SOUND=y
 CONFIG_SOUND_SANDBOX=y
index 7bddac619878b2fad35ae79973397545abeb366a..be8186ead3215a98c6362b05d72e330bcf848be2 100644 (file)
@@ -124,7 +124,6 @@ CONFIG_DEBUG_DEVRES=y
 # CONFIG_SPL_SIMPLE_BUS is not set
 CONFIG_ADC=y
 CONFIG_ADC_SANDBOX=y
-CONFIG_SYS_SATA_MAX_DEVICE=2
 CONFIG_AXI=y
 CONFIG_AXI_SANDBOX=y
 CONFIG_CLK=y
@@ -210,9 +209,7 @@ CONFIG_DM_RTC=y
 CONFIG_SPL_DM_RTC=y
 CONFIG_TPL_DM_RTC=y
 CONFIG_SCSI=y
-CONFIG_SCSI_AHCI_PLAT=y
-CONFIG_SYS_SCSI_MAX_SCSI_ID=8
-CONFIG_SYS_SCSI_MAX_LUN=4
+CONFIG_DM_SCSI=y
 CONFIG_SANDBOX_SERIAL=y
 CONFIG_SOUND=y
 CONFIG_SOUND_SANDBOX=y
index 211acc77740417d4e21513fee3dceb3388fdce1c..2c418f5dbb2f7ae546839c0079e162fea8d3ac41 100644 (file)
@@ -18,7 +18,6 @@ CONFIG_OF_CONTROL=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 # CONFIG_NET is not set
 # CONFIG_ACPIGEN is not set
-CONFIG_SYS_SATA_MAX_DEVICE=2
 CONFIG_AXI=y
 CONFIG_AXI_SANDBOX=y
 CONFIG_SANDBOX_GPIO=y
index 39b969a4b2f1b359ccba98879f3f4f062e257416..a7ac33cb1c4b17f8f2163bcb553bd7c8c4f4ca6a 100644 (file)
  * that CONFIG_SCSI can be enabled for sandbox.
  */
 
+#define LOG_CATEGORY UCLASS_SCSI
+
 #include <common.h>
+#include <dm.h>
+#include <os.h>
+#include <malloc.h>
 #include <scsi.h>
+#include <scsi_emul.h>
+
+enum {
+       SANDBOX_SCSI_BLOCK_LEN          = 512,
+       SANDBOX_SCSI_BUF_SIZE           = 512,
+};
+
+/**
+ * struct sandbox_scsi_priv
+ *
+ * @eminfo: emulator state
+ * @pathanme: Path to the backing file, e.g. 'scsi.img'
+ * @fd: File descriptor of backing file
+ */
+struct sandbox_scsi_priv {
+       struct scsi_emul_info eminfo;
+       const char *pathname;
+       int fd;
+};
 
-int scsi_bus_reset(struct udevice *dev)
+static int sandbox_scsi_exec(struct udevice *dev, struct scsi_cmd *req)
 {
+       struct sandbox_scsi_priv *priv = dev_get_priv(dev);
+       struct scsi_emul_info *info = &priv->eminfo;
+       int ret;
+
+       if (req->lun || req->target)
+               return -EIO;
+       ret = sb_scsi_emul_command(info, req, req->cmdlen);
+       if (ret < 0) {
+               log_debug("SCSI command 0x%02x ret errno %d\n", req->cmd[0],
+                         ret);
+               return ret;
+       } else if (ret == SCSI_EMUL_DO_READ && priv->fd != -1) {
+               long bytes_read;
+
+               log_debug("read %x %x\n", info->seek_block, info->read_len);
+               os_lseek(priv->fd, info->seek_block * info->block_size,
+                        OS_SEEK_SET);
+               bytes_read = os_read(priv->fd, req->pdata, info->buff_used);
+               if (bytes_read < 0)
+                       return bytes_read;
+               if (bytes_read != info->buff_used)
+                       return -EIO;
+       } else if (!ret) {
+               req->pdata = info->buff;
+               info->phase = SCSIPH_STATUS;
+               log_debug("sending buf\n");
+       } else {
+               log_debug("error\n");
+               return -EIO;
+       }
+
        return 0;
 }
 
-void scsi_init(void)
+static int sandbox_scsi_bus_reset(struct udevice *dev)
 {
+       /* Not implemented */
+
+       return 0;
 }
 
-int scsi_exec(struct udevice *dev, struct scsi_cmd *pccb)
+static int sandbox_scsi_of_to_plat(struct udevice *dev)
 {
+       struct sandbox_scsi_priv *priv = dev_get_priv(dev);
+
+       priv->pathname = dev_read_string(dev, "sandbox,filepath");
+
        return 0;
 }
+
+static int sandbox_scsi_probe(struct udevice *dev)
+{
+       struct scsi_plat *scsi_plat = dev_get_uclass_plat(dev);
+       struct sandbox_scsi_priv *priv = dev_get_priv(dev);
+       struct scsi_emul_info *info = &priv->eminfo;
+       int ret;
+
+       scsi_plat->max_id = 2;
+       scsi_plat->max_lun = 3;
+       scsi_plat->max_bytes_per_req = 1 << 20;
+
+       info->vendor = "SANDBOX";
+       info->product = "FAKE DISK";
+       info->buff = malloc(SANDBOX_SCSI_BUF_SIZE);
+       if (!info->buff)
+               return log_ret(-ENOMEM);
+       info->block_size = SANDBOX_SCSI_BLOCK_LEN;
+
+       if (priv->pathname) {
+               priv->fd = os_open(priv->pathname, OS_O_RDONLY);
+               if (priv->fd != -1) {
+                       ret = os_get_filesize(priv->pathname, &info->file_size);
+                       if (ret)
+                               return log_msg_ret("sz", ret);
+               }
+       } else {
+               priv->fd = -1;
+       }
+       log_debug("filename: %s, fd %d\n", priv->pathname, priv->fd);
+
+       return 0;
+}
+
+static int sandbox_scsi_remove(struct udevice *dev)
+{
+       struct sandbox_scsi_priv *priv = dev_get_priv(dev);
+       struct scsi_emul_info *info = &priv->eminfo;
+
+       free(info->buff);
+
+       return 0;
+}
+
+struct scsi_ops sandbox_scsi_ops = {
+       .exec           = sandbox_scsi_exec,
+       .bus_reset      = sandbox_scsi_bus_reset,
+};
+
+static const struct udevice_id sanbox_scsi_ids[] = {
+       { .compatible = "sandbox,scsi" },
+       { }
+};
+
+U_BOOT_DRIVER(sandbox_scsi) = {
+       .name           = "sandbox_scsi",
+       .id             = UCLASS_SCSI,
+       .ops            = &sandbox_scsi_ops,
+       .of_match       = sanbox_scsi_ids,
+       .of_to_plat     = sandbox_scsi_of_to_plat,
+       .probe          = sandbox_scsi_probe,
+       .remove         = sandbox_scsi_remove,
+       .priv_auto      = sizeof(struct sandbox_scsi_priv),
+};