Commit 1a73661bc7a7ad2d741f7d7519872ca18231598c

Authored by Simon Glass
1 parent 481922f14a

dm: Add a new header for block devices

At present block devices are tied up with partitions. But not all block
devices have partitions within them. They are in fact separate concepts.

Create a separate blk.h header file for block devices.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

Showing 3 changed files with 74 additions and 58 deletions Side-by-side Diff

  1 +/*
  2 + * (C) Copyright 2000-2004
  3 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4 + *
  5 + * SPDX-License-Identifier: GPL-2.0+
  6 + */
  7 +
  8 +#ifndef BLK_H
  9 +#define BLK_H
  10 +
  11 +#ifdef CONFIG_SYS_64BIT_LBA
  12 +typedef uint64_t lbaint_t;
  13 +#define LBAFlength "ll"
  14 +#else
  15 +typedef ulong lbaint_t;
  16 +#define LBAFlength "l"
  17 +#endif
  18 +#define LBAF "%" LBAFlength "x"
  19 +#define LBAFU "%" LBAFlength "u"
  20 +
  21 +/* Interface types: */
  22 +#define IF_TYPE_UNKNOWN 0
  23 +#define IF_TYPE_IDE 1
  24 +#define IF_TYPE_SCSI 2
  25 +#define IF_TYPE_ATAPI 3
  26 +#define IF_TYPE_USB 4
  27 +#define IF_TYPE_DOC 5
  28 +#define IF_TYPE_MMC 6
  29 +#define IF_TYPE_SD 7
  30 +#define IF_TYPE_SATA 8
  31 +#define IF_TYPE_HOST 9
  32 +#define IF_TYPE_MAX 10 /* Max number of IF_TYPE_* supported */
  33 +
  34 +struct blk_desc {
  35 + int if_type; /* type of the interface */
  36 + int dev; /* device number */
  37 + unsigned char part_type; /* partition type */
  38 + unsigned char target; /* target SCSI ID */
  39 + unsigned char lun; /* target LUN */
  40 + unsigned char hwpart; /* HW partition, e.g. for eMMC */
  41 + unsigned char type; /* device type */
  42 + unsigned char removable; /* removable device */
  43 +#ifdef CONFIG_LBA48
  44 + /* device can use 48bit addr (ATA/ATAPI v7) */
  45 + unsigned char lba48;
  46 +#endif
  47 + lbaint_t lba; /* number of blocks */
  48 + unsigned long blksz; /* block size */
  49 + int log2blksz; /* for convenience: log2(blksz) */
  50 + char vendor[40+1]; /* IDE model, SCSI Vendor */
  51 + char product[20+1]; /* IDE Serial no, SCSI product */
  52 + char revision[8+1]; /* firmware revision */
  53 + unsigned long (*block_read)(struct blk_desc *block_dev,
  54 + lbaint_t start,
  55 + lbaint_t blkcnt,
  56 + void *buffer);
  57 + unsigned long (*block_write)(struct blk_desc *block_dev,
  58 + lbaint_t start,
  59 + lbaint_t blkcnt,
  60 + const void *buffer);
  61 + unsigned long (*block_erase)(struct blk_desc *block_dev,
  62 + lbaint_t start,
  63 + lbaint_t blkcnt);
  64 + void *priv; /* driver private struct pointer */
  65 +};
  66 +
  67 +#define BLOCK_CNT(size, blk_desc) (PAD_COUNT(size, blk_desc->blksz))
  68 +#define PAD_TO_BLOCKSIZE(size, blk_desc) \
  69 + (PAD_SIZE(size, blk_desc->blksz))
  70 +
  71 +#endif
... ... @@ -8,6 +8,8 @@
8 8 #ifndef _IDE_H
9 9 #define _IDE_H
10 10  
  11 +#include <blk.h>
  12 +
11 13 #define IDE_BUS(dev) (dev / (CONFIG_SYS_IDE_MAXDEVICE / CONFIG_SYS_IDE_MAXBUS))
12 14  
13 15 #define ATA_CURR_BASE(dev) (CONFIG_SYS_ATA_BASE_ADDR+ide_bus_offset[IDE_BUS(dev)])
... ... @@ -25,16 +27,6 @@
25 27  
26 28 void ide_led(uchar led, uchar status);
27 29 #endif /* CONFIG_IDE_LED */
28   -
29   -#ifdef CONFIG_SYS_64BIT_LBA
30   -typedef uint64_t lbaint_t;
31   -#define LBAFlength "ll"
32   -#else
33   -typedef ulong lbaint_t;
34   -#define LBAFlength "l"
35   -#endif
36   -#define LBAF "%" LBAFlength "x"
37   -#define LBAFU "%" LBAFlength "u"
38 30  
39 31 /*
40 32 * Function Prototypes
... ... @@ -7,60 +7,13 @@
7 7 #ifndef _PART_H
8 8 #define _PART_H
9 9  
  10 +#include <blk.h>
10 11 #include <ide.h>
11 12  
12   -struct blk_desc {
13   - int if_type; /* type of the interface */
14   - int dev; /* device number */
15   - unsigned char part_type; /* partition type */
16   - unsigned char target; /* target SCSI ID */
17   - unsigned char lun; /* target LUN */
18   - unsigned char hwpart; /* HW partition, e.g. for eMMC */
19   - unsigned char type; /* device type */
20   - unsigned char removable; /* removable device */
21   -#ifdef CONFIG_LBA48
22   - unsigned char lba48; /* device can use 48bit addr (ATA/ATAPI v7) */
23   -#endif
24   - lbaint_t lba; /* number of blocks */
25   - unsigned long blksz; /* block size */
26   - int log2blksz; /* for convenience: log2(blksz) */
27   - char vendor [40+1]; /* IDE model, SCSI Vendor */
28   - char product[20+1]; /* IDE Serial no, SCSI product */
29   - char revision[8+1]; /* firmware revision */
30   - unsigned long (*block_read)(struct blk_desc *block_dev,
31   - lbaint_t start,
32   - lbaint_t blkcnt,
33   - void *buffer);
34   - unsigned long (*block_write)(struct blk_desc *block_dev,
35   - lbaint_t start,
36   - lbaint_t blkcnt,
37   - const void *buffer);
38   - unsigned long (*block_erase)(struct blk_desc *block_dev,
39   - lbaint_t start,
40   - lbaint_t blkcnt);
41   - void *priv; /* driver private struct pointer */
42   -};
43   -
44   -#define BLOCK_CNT(size, blk_desc) (PAD_COUNT(size, blk_desc->blksz))
45   -#define PAD_TO_BLOCKSIZE(size, blk_desc) \
46   - (PAD_SIZE(size, blk_desc->blksz))
47 13 #define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \
48 14 ((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \
49 15 ((x & 0xffff0000) ? 16 : 0))
50 16 #define LOG2_INVALID(type) ((type)((sizeof(type)<<3)-1))
51   -
52   -/* Interface types: */
53   -#define IF_TYPE_UNKNOWN 0
54   -#define IF_TYPE_IDE 1
55   -#define IF_TYPE_SCSI 2
56   -#define IF_TYPE_ATAPI 3
57   -#define IF_TYPE_USB 4
58   -#define IF_TYPE_DOC 5
59   -#define IF_TYPE_MMC 6
60   -#define IF_TYPE_SD 7
61   -#define IF_TYPE_SATA 8
62   -#define IF_TYPE_HOST 9
63   -#define IF_TYPE_MAX 10 /* Max number of IF_TYPE_* supported */
64 17  
65 18 /* Part types */
66 19 #define PART_TYPE_UNKNOWN 0x00