efi_loader: type of efi_secure_mode
[oweals/u-boot.git] / include / blk.h
index 547c3b48dcac41e386492f50f11d0e811ba2d3ba..abcd4bedbbbd3fae6620f39525c616ecb1b721cf 100644 (file)
@@ -1,13 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
 /*
  * (C) Copyright 2000-2004
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #ifndef BLK_H
 #define BLK_H
 
+#include <efi.h>
+
 #ifdef CONFIG_SYS_64BIT_LBA
 typedef uint64_t lbaint_t;
 #define LBAFlength "ll"
@@ -30,11 +31,28 @@ enum if_type {
        IF_TYPE_SD,
        IF_TYPE_SATA,
        IF_TYPE_HOST,
-       IF_TYPE_SYSTEMACE,
+       IF_TYPE_NVME,
+       IF_TYPE_EFI,
+       IF_TYPE_VIRTIO,
 
        IF_TYPE_COUNT,                  /* Number of interface types */
 };
 
+#define BLK_VEN_SIZE           40
+#define BLK_PRD_SIZE           20
+#define BLK_REV_SIZE           8
+
+/*
+ * Identifies the partition table type (ie. MBR vs GPT GUID) signature
+ */
+enum sig_type {
+       SIG_TYPE_NONE,
+       SIG_TYPE_MBR,
+       SIG_TYPE_GUID,
+
+       SIG_TYPE_COUNT                  /* Number of signature types */
+};
+
 /*
  * With driver model (CONFIG_BLK) this is uclass platform data, accessible
  * with dev_get_uclass_platdata(dev)
@@ -59,10 +77,20 @@ struct blk_desc {
        lbaint_t        lba;            /* number of blocks */
        unsigned long   blksz;          /* block size */
        int             log2blksz;      /* for convenience: log2(blksz) */
-       char            vendor[40+1];   /* IDE model, SCSI Vendor */
-       char            product[20+1];  /* IDE Serial no, SCSI product */
-       char            revision[8+1];  /* firmware revision */
-#ifdef CONFIG_BLK
+       char            vendor[BLK_VEN_SIZE + 1]; /* device vendor string */
+       char            product[BLK_PRD_SIZE + 1]; /* device product number */
+       char            revision[BLK_REV_SIZE + 1]; /* firmware revision */
+       enum sig_type   sig_type;       /* Partition table signature type */
+       union {
+               uint32_t mbr_sig;       /* MBR integer signature */
+               efi_guid_t guid_sig;    /* GPT GUID Signature */
+       };
+#if CONFIG_IS_ENABLED(BLK)
+       /*
+        * For now we have a few functions which take struct blk_desc as a
+        * parameter. This field allows them to look up the associated
+        * device. Once these functions are removed we can drop this field.
+        */
        struct udevice *bdev;
 #else
        unsigned long   (*block_read)(struct blk_desc *block_dev,
@@ -84,7 +112,13 @@ struct blk_desc {
 #define PAD_TO_BLOCKSIZE(size, blk_desc) \
        (PAD_SIZE(size, blk_desc->blksz))
 
-#ifdef CONFIG_BLOCK_CACHE
+#if CONFIG_IS_ENABLED(BLOCK_CACHE)
+
+/**
+ * blkcache_init() - initialize the block cache list pointers
+ */
+int blkcache_init(void);
+
 /**
  * blkcache_read() - attempt to read a set of blocks from cache
  *
@@ -95,7 +129,7 @@ struct blk_desc {
  * @param blksz - size in bytes of each block
  * @param buf - buffer to contain cached data
  *
- * @return - '1' if block returned from cache, '0' otherwise.
+ * @return - 1 if block returned from cache, 0 otherwise.
  */
 int blkcache_read(int iftype, int dev,
                  lbaint_t start, lbaint_t blkcnt,
@@ -169,7 +203,7 @@ static inline void blkcache_invalidate(int iftype, int dev) {}
 
 #endif
 
-#ifdef CONFIG_BLK
+#if CONFIG_IS_ENABLED(BLK)
 struct udevice;
 
 /* Operations on block devices */
@@ -211,6 +245,25 @@ struct blk_ops {
         */
        unsigned long (*erase)(struct udevice *dev, lbaint_t start,
                               lbaint_t blkcnt);
+
+       /**
+        * select_hwpart() - select a particular hardware partition
+        *
+        * Some devices (e.g. MMC) can support partitioning at the hardware
+        * level. This is quite separate from the normal idea of
+        * software-based partitions. MMC hardware partitions must be
+        * explicitly selected. Once selected only the region of the device
+        * covered by that partition is accessible.
+        *
+        * The MMC standard provides for two boot partitions (numbered 1 and 2),
+        * rpmb (3), and up to 4 addition general-purpose partitions (4-7).
+        *
+        * @desc:       Block device to update
+        * @hwpart:     Hardware partition number to select. 0 means the raw
+        *              device, 1 is the first partition, 2 is the second, etc.
+        * @return 0 if OK, -ve on error
+        */
+       int (*select_hwpart)(struct udevice *dev, int hwpart);
 };
 
 #define blk_get_ops(dev)       ((struct blk_ops *)(dev)->driver->ops)
@@ -228,13 +281,26 @@ unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
 unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
                         lbaint_t blkcnt);
 
+/**
+ * blk_find_device() - Find a block device
+ *
+ * This function does not activate the device. The device will be returned
+ * whether or not it is activated.
+ *
+ * @if_type:   Interface type (enum if_type_t)
+ * @devnum:    Device number (specific to each interface type)
+ * @devp:      the device, if found
+ * @return 0 if found, -ENODEV if no device found, or other -ve error value
+ */
+int blk_find_device(int if_type, int devnum, struct udevice **devp);
+
 /**
  * blk_get_device() - Find and probe a block device ready for use
  *
  * @if_type:   Interface type (enum if_type_t)
  * @devnum:    Device number (specific to each interface type)
  * @devp:      the device, if found
- * @return - if found, -ENODEV if no device found, or other -ve error value
+ * @return 0 if found, -ENODEV if no device found, or other -ve error value
  */
 int blk_get_device(int if_type, int devnum, struct udevice **devp);
 
@@ -273,22 +339,29 @@ int blk_next_device(struct udevice **devp);
  * @devnum:    Device number, specific to the interface type, or -1 to
  *             allocate the next available number
  * @blksz:     Block size of the device in bytes (typically 512)
- * @size:      Total size of the device in bytes
+ * @lba:       Total number of blocks of the device
  * @devp:      the new device (which has not been probed)
  */
 int blk_create_device(struct udevice *parent, const char *drv_name,
                      const char *name, int if_type, int devnum, int blksz,
-                     lbaint_t size, struct udevice **devp);
+                     lbaint_t lba, struct udevice **devp);
 
 /**
- * blk_prepare_device() - Prepare a block device for use
- *
- * This reads partition information from the device if supported.
+ * blk_create_devicef() - Create a new named block device
  *
- * @dev:       Device to prepare
- * @return 0 if ok, -ve on error
+ * @parent:    Parent of the new device
+ * @drv_name:  Driver name to use for the block device
+ * @name:      Name for the device (parent name is prepended)
+ * @if_type:   Interface type (enum if_type_t)
+ * @devnum:    Device number, specific to the interface type, or -1 to
+ *             allocate the next available number
+ * @blksz:     Block size of the device in bytes (typically 512)
+ * @lba:       Total number of blocks of the device
+ * @devp:      the new device (which has not been probed)
  */
-int blk_prepare_device(struct udevice *dev);
+int blk_create_devicef(struct udevice *parent, const char *drv_name,
+                      const char *name, int if_type, int devnum, int blksz,
+                      lbaint_t lba, struct udevice **devp);
 
 /**
  * blk_unbind_all() - Unbind all device of the given interface type
@@ -312,6 +385,44 @@ int blk_unbind_all(int if_type);
  */
 int blk_find_max_devnum(enum if_type if_type);
 
+/**
+ * blk_next_free_devnum() - get the next device number for an interface type
+ *
+ * Finds the next number that is safe to use for a newly allocated device for
+ * an interface type @if_type.
+ *
+ * @if_type:   Interface type to scan
+ * @return next device number safe to use, or -ve on error
+ */
+int blk_next_free_devnum(enum if_type if_type);
+
+/**
+ * blk_select_hwpart() - select a hardware partition
+ *
+ * Select a hardware partition if the device supports it (typically MMC does)
+ *
+ * @dev:       Device to update
+ * @hwpart:    Partition number to select
+ * @return 0 if OK, -ve on error
+ */
+int blk_select_hwpart(struct udevice *dev, int hwpart);
+
+/**
+ * blk_get_from_parent() - obtain a block device by looking up its parent
+ *
+ * All devices with
+ */
+int blk_get_from_parent(struct udevice *parent, struct udevice **devp);
+
+/**
+ * blk_get_by_device() - Get the block device descriptor for the given device
+ * @dev:       Instance of a storage device
+ *
+ * Return: With block device descriptor on success , NULL if there is no such
+ *        block device.
+ */
+struct blk_desc *blk_get_by_device(struct udevice *dev);
+
 #else
 #include <errno.h>
 /*
@@ -551,4 +662,24 @@ ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,
  */
 int blk_select_hwpart_devnum(enum if_type if_type, int devnum, int hwpart);
 
+/**
+ * blk_get_if_type_name() - Get the name of an interface type
+ *
+ * @if_type: Interface type to check
+ * @return name of interface, or NULL if none
+ */
+const char *blk_get_if_type_name(enum if_type if_type);
+
+/**
+ * blk_common_cmd() - handle common commands with block devices
+ *
+ * @args: Number of arguments to the command (argv[0] is the command itself)
+ * @argv: Command arguments
+ * @if_type: Interface type
+ * @cur_devnump: Current device number for this interface type
+ * @return 0 if OK, CMD_RET_ERROR on error
+ */
+int blk_common_cmd(int argc, char *const argv[], enum if_type if_type,
+                  int *cur_devnump);
+
 #endif