Merge tag 'u-boot-at91-2022.04-a' of https://source.denx.de/u-boot/custodians/u-boot...
[platform/kernel/u-boot.git] / drivers / block / sandbox.c
index 9d7d68c..53925ce 100644 (file)
 DECLARE_GLOBAL_DATA_PTR;
 
 #ifndef CONFIG_BLK
-static struct host_block_dev host_devices[CONFIG_HOST_MAX_DEVICES];
+static struct host_block_dev host_devices[SANDBOX_HOST_MAX_DEVICES];
 
 static struct host_block_dev *find_host_device(int dev)
 {
-       if (dev >= 0 && dev < CONFIG_HOST_MAX_DEVICES)
+       if (dev >= 0 && dev < SANDBOX_HOST_MAX_DEVICES)
                return &host_devices[dev];
 
        return NULL;
@@ -89,7 +89,7 @@ static unsigned long host_block_write(struct blk_desc *block_dev,
 }
 
 #ifdef CONFIG_BLK
-int host_dev_bind(int devnum, char *filename)
+int host_dev_bind(int devnum, char *filename, bool removable)
 {
        struct host_block_dev *host_dev;
        struct udevice *dev;
@@ -146,7 +146,7 @@ int host_dev_bind(int devnum, char *filename)
        }
 
        desc = blk_get_devnum_by_type(IF_TYPE_HOST, devnum);
-       desc->removable = 1;
+       desc->removable = removable;
        snprintf(desc->vendor, BLK_VEN_SIZE, "U-Boot");
        snprintf(desc->product, BLK_PRD_SIZE, "hostfile");
        snprintf(desc->revision, BLK_REV_SIZE, "1.0");
@@ -160,7 +160,7 @@ err:
        return ret;
 }
 #else
-int host_dev_bind(int dev, char *filename)
+int host_dev_bind(int dev, char *filename, bool removable)
 {
        struct host_block_dev *host_dev = find_host_device(dev);
 
@@ -195,7 +195,7 @@ int host_dev_bind(int dev, char *filename)
        blk_dev->block_write = host_block_write;
        blk_dev->devnum = dev;
        blk_dev->part_type = PART_TYPE_UNKNOWN;
-       blk_dev->removable = 1;
+       blk_dev->removable = removable;
        snprintf(blk_dev->vendor, BLK_VEN_SIZE, "U-Boot");
        snprintf(blk_dev->product, BLK_PRD_SIZE, "hostfile");
        snprintf(blk_dev->revision, BLK_REV_SIZE, "1.0");
@@ -231,6 +231,18 @@ int host_get_dev_err(int devnum, struct blk_desc **blk_devp)
 }
 
 #ifdef CONFIG_BLK
+
+int sandbox_host_unbind(struct udevice *dev)
+{
+       struct host_block_dev *host_dev;
+
+       /* Data validity is checked in host_dev_bind() */
+       host_dev = dev_get_plat(dev);
+       os_close(host_dev->fd);
+
+       return 0;
+}
+
 static const struct blk_ops sandbox_host_blk_ops = {
        .read   = host_block_read,
        .write  = host_block_write,
@@ -240,13 +252,14 @@ U_BOOT_DRIVER(sandbox_host_blk) = {
        .name           = "sandbox_host_blk",
        .id             = UCLASS_BLK,
        .ops            = &sandbox_host_blk_ops,
+       .unbind         = sandbox_host_unbind,
        .plat_auto      = sizeof(struct host_block_dev),
 };
 #else
 U_BOOT_LEGACY_BLK(sandbox_host) = {
        .if_typename    = "host",
        .if_type        = IF_TYPE_HOST,
-       .max_devs       = CONFIG_HOST_MAX_DEVICES,
+       .max_devs       = SANDBOX_HOST_MAX_DEVICES,
        .get_dev        = host_get_dev_err,
 };
 #endif